1
0
mirror of https://github.com/e107inc/e107.git synced 2025-04-20 20:51:53 +02:00

- Featurebox batch copy feature added (example implementation - page administration), plugin upgrade required

- Lost admin UI messages issue solved
- Featurebox list items view now sortable
This commit is contained in:
SecretR 2013-03-13 09:47:48 +02:00
parent 092f64bcf8
commit 064528e754
8 changed files with 123 additions and 90 deletions

View File

@ -308,7 +308,7 @@ class page_admin_ui extends e_admin_ui
//protected $url = array('profile'=>'page/view', 'name' => 'page_title', 'description' => '', 'link'=>'{e_BASE}page.php?id=[id]'); // 'link' only needed if profile not provided.
protected $url = array('route'=>'page/view/index', 'vars' => array('id' => 'page_id', 'sef' => 'page_sef'), 'name' => 'page_title', 'description' => ''); // 'link' only needed if profile not provided.
protected $tabs = array("Page","Page Options","Menu");
protected $featurebox = array('title'=>'page_title', 'text'=>'page_text');
protected $featurebox = array('name'=>'page_title', 'description'=>'page_text', 'image' => 'menu_image', 'visibility' => 'page_class', 'url' => true);
/*
* 'fb_title' => array('title'=> LAN_TITLE, 'type' => 'text', 'inline'=>true, 'width' => 'auto', 'thclass' => 'left'),

View File

@ -2342,6 +2342,13 @@ class e_admin_controller_ui extends e_admin_controller
* @var array edit/create form tabs
*/
protected $url = array();
/**
* TODO Example:
* Contains required data for mapping featurebox fields
* @var array edit/create form tabs
*/
protected $featurebox = array();
/**
* Structure same as TreeModel parameters used for building the load() SQL
@ -4038,8 +4045,8 @@ class e_admin_ui extends e_admin_controller_ui
{
if($this->_add2nav($selected))
{
//e107::getMessage()->moveToSession();
//$this->redirect();
e107::getMessage()->moveToSession();
$this->redirect();
}
}
@ -4053,14 +4060,10 @@ class e_admin_ui extends e_admin_controller_ui
{
if($this->_add2featurebox($selected))
{
//e107::getMessage()->moveToSession();
//$this->redirect();
e107::getMessage()->moveToSession();
$this->redirect();
}
}
protected function _add2nav($selected)
{
@ -4131,52 +4134,56 @@ class e_admin_ui extends e_admin_controller_ui
}
protected function _add2featurebox($selected)
{
if(empty($selected)) return false;// TODO warning message
if(!is_array($selected)) $selected = array($selected);
if(!is_array($selected)) $selected = array($selected);
$sql = e107::getDb();
//$allData = $this->getFeaturebox();
$allData = $this->getTreeModel()->featurebox($selected, array('sc' => true), true);
e107::getMessage()->addDebug('Using Featurebox Info:'.print_a($data,true));
// print_a($allData);
echo "EXIT";
exit;
$tree = $this->getTreeModel();
$urlData = $this->getTreeModel()->url($selected, array('sc' => true), false);
$data = $this->featurebox;
$scount = 0;
foreach($allData as $id => $data)
foreach($selected as $id)
{
$name = $data['name'];
$desc = $data['text'];
$fbArray = array(
'fb_title' => varset($data['name']),
'fb_text' => varset($data['text']),
'fb_image' => varset($data['image']),
'fb_imageurl' => varset($data['url']),
if(!$tree->hasNode($id))
{
e107::getMessage()->addError('Item #ID '.htmlspecialchars($id).' not found.');
continue; // TODO message
}
$model = $tree->getNode($id);
if($data['url'] === true)
{
$url = $urlData[$id];
}
else $url = $model->get($data['url']);
$name = $model->get($data['name']);
$category = e107::getDb()->retrieve('featurebox_category', 'fb_category_id', "fb_category_template='unassigned'");
$fbArray = array (
'fb_title' => $name,
'fb_text' => $model->get($data['description']),
'fb_image' => vartrue($data['image']) ? $model->get($data['image']) : '',
'fb_imageurl' => $url,
'fb_class' => isset($data['visibility']) && $data['visibility'] !== false ? $model->get($data['visibility']) : e_UC_ADMIN,
'fb_template' => 'default',
'fb_category' => $category, // TODO popup - choose category
'fb_order' => $scount,
);
$res = $sql->insert('featurebox', $fbArray);
// FIXME lans
if($res !== FALSE)
{
e107::getMessage()->addSuccess('Created Featurebox Item: <b>'.($name ? $name : 'n/a')."</b>");
$scount++;
}
else
else
{
if($sql->getLastErrorNumber())
{
@ -4193,7 +4200,7 @@ class e_admin_ui extends e_admin_controller_ui
if($scount > 0)
{
e107::getMessage()->addSuccess("<br /><strong>{$scount}</strong> new sitelinks were added but are currently unassigned. You should now modify these links to your liking.<br /><br /><a class='btn btn-small btn-primary' href='".e_ADMIN_ABS."links.php?searchquery=&filter_options=link_category__255'>Modify Links</a>");
e107::getMessage()->addSuccess("<br /><strong>{$scount}</strong> new featurebox items were added but are currently unassigned. You should now modify these items to your liking.<br /><br /><a class='btn btn-small btn-primary' href='".e_PLUGIN_ABS."featurebox/admin_config.php?searchquery=&filter_options=fb_category__{$category}'>Modify Featurebox Items</a>");
return $scount;
}

View File

@ -3561,38 +3561,4 @@ class e_admin_tree_model extends e_front_tree_model
}
return $ret;
}
/**
* Get urls/url data for given nodes
*/
public function featurebox($ids, $options = array(), $extended = false)
{
$ret = array();
foreach ($ids as $id)
{
// print_a($this->getData());
if(!$this->hasNode($id)) continue;
$model = $this->getNode($id);
;
print_a($this->getData());
// if($this->getFeaturebox()) $model->setFeaturebox($this->getFeaturebox()); // copy url config data if available
// $ret[$id] = $model->featurebox($options, $extended);
// print_a($ret);
}
return $ret;
}
}

View File

@ -78,7 +78,7 @@ class e_pref extends e_front_model
require_once(e_HANDLER.'cache_handler.php');
$this->prefid = preg_replace('/[^\w\-]/', '', $prefid);
e107::getMessage()->setUnique($this->prefid); // attempt to fix
if(empty($alias))
{
$alias = $prefid;
@ -502,7 +502,8 @@ class e_pref extends e_front_model
{
return false;
}
e107::getMessage()->setUnique($this->prefid); // attempt to fix
if($from_post)
{
$this->mergePostedData(); //all posted data is sanitized and filtered vs preferences/_data_fields array

View File

@ -77,13 +77,46 @@ class fb_category_ui extends e_admin_ui
'fb_category_parms' => array('title'=> 'Parameters (optional)', 'type' => 'textarea', 'data' => 'str', 'width' => 'auto', 'thclass' => 'left', 'class' => 'left','writeParms' => 'expand=Advanced&help=Optional Javascript Parameters (format subject to change)'),
'options' => array('title'=> LAN_OPTIONS, 'type' => null, 'width' => '10%', 'forced'=>TRUE, 'thclass' => 'center last', 'class' => 'center')
);
);
public function init()
{
### Prevent modification of the 'unassigned' system category
if($this->getAction() == 'edit')
{
$this->getModel()->load((int) $this->getId());
// FIXME lan
if($this->getModel()->get('fb_category_template') === 'unassigned')
{
e107::getMessage()->addError("<strong>".FBLAN_INSTALL_03."</strong> is system category and can't be modified.", 'default', true);
$this->redirect('list');
}
}
elseif($this->getAction() == 'inline')
{
$this->getModel()->load((int) $this->getId());
if($this->getModel()->get('fb_category_template') === 'unassigned')
{
$protocol = (isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0');
header($protocol.': 403 Forbidden', true, 403);
echo "'".FBLAN_INSTALL_03."' is system category and can't be modified.";
exit;
}
}
}
/**
* Prevent deletion of categories in use
*/
public function beforeDelete($data, $id)
{
// FIXME lan
if($data['fb_category_template'] === 'unassigned')
{
$this->getTreeModel()->addMessageError("<strong>".FBLAN_INSTALL_03."</strong> is system category and can't be deleted.");
return false;
}
if (e107::getDb()->db_Count('featurebox', '(*)', 'fb_category='.intval($id)))
{
$this->getTreeModel()->addMessageWarning("Can't delete <strong>{$data['fb_category_title']}</strong> - category is in use!");
@ -105,7 +138,7 @@ class fb_category_ui extends e_admin_ui
if(!varset($new_data['fb_category_template']))
{
$new_data['fb_category_template'] = 'default';
}
}var_dump($new_data);
return $new_data;
}
@ -168,7 +201,10 @@ class fb_main_ui extends e_admin_ui
protected $pid = "fb_id";
protected $perPage = 10;
protected $batchDelete = true;
protected $batchCopy = true;
protected $batchCopy = true;
protected $sortField = 'fb_order';
protected $orderStep = 1;
protected $listOrder = 'fb_order asc';
protected $fields = array(
'checkboxes' => array('title'=> '', 'type' => null, 'width' =>'5%', 'forced'=> TRUE, 'thclass'=>'center first', 'class'=>'center'),
@ -183,7 +219,7 @@ class fb_main_ui extends e_admin_ui
'fb_imageurl' => array('title'=> "Image Link", 'type' => 'url', 'width' => 'auto'),
'fb_class' => array('title'=> LAN_VISIBILITY, 'type' => 'userclass', 'data' => 'int', 'inline'=>true, 'width' => 'auto', 'filter' => true, 'batch' => true), // User id
'fb_order' => array('title'=> LAN_ORDER, 'type' => 'number', 'data'=> 'int','width' => '5%' ),
'options' => array('title'=> LAN_OPTIONS, 'type' => null, 'forced'=>TRUE, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center')
'options' => array('title'=> LAN_OPTIONS, 'type' => null, 'forced'=>TRUE, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center', 'readParms'=>'sort=1')
);
protected $fieldpref = array('checkboxes', 'fb_id', 'fb_category', 'fb_title', 'fb_template', 'fb_class', 'fb_order', 'options');

View File

@ -33,13 +33,21 @@ class featurebox_setup
$query = array();
$query['fb_category_id'] = 0;
$query['fb_category_title'] = 'General';
$query['fb_category_title'] = FBLAN_INSTALL_04;
$query['fb_category_template'] = 'default';
$query['fb_category_random'] = 0;
$query['fb_category_class'] = e_UC_PUBLIC;
$query['fb_category_limit'] = 1;
$inserted = e107::getDb()->db_Insert('featurebox_category', $query);
$status = $inserted ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR;
$query['fb_category_id'] = 0;
$query['fb_category_title'] = FBLAN_INSTALL_03;
$query['fb_category_template'] = 'unassigned';
$query['fb_category_random'] = 0;
$query['fb_category_class'] = e_UC_NOBODY;
$query['fb_category_limit'] = 0;
$inserted1 = e107::getDb()->db_Insert('featurebox_category', $query);
$status = $inserted && $inserted1 ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR;
$mes->add(FBLAN_INSTALL_01, $status);
if($inserted)
@ -75,11 +83,28 @@ class featurebox_setup
{
// print_a($var);
}
*/
function upgrade_post($var)
{
// $sql = e107::getDb();
$sql = e107::getDb();
$currentVersion = $var->current_plug['plugin_version'];
//$newVersion = $var->plug_vars['@attributes']['version'];
if($currentVersion == '1.0')
{
$query = array();
$query['fb_category_id'] = 0;
$query['fb_category_title'] = FBLAN_INSTALL_03;
$query['fb_category_template'] = 'unassigned';
$query['fb_category_random'] = 0;
$query['fb_category_class'] = e_UC_NOBODY;
$query['fb_category_limit'] = 0;
$inserted = $sql->db_Insert('featurebox_category', $query);
$status = $inserted ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR;
e107::getMessage()->add(FBLAN_INSTALL_01, $status);
if($sql->getLastErrorNumber())
{
e107::getMessage()->addDebug($sql->getLastErrorText().'<br /><pre>'.$sql->getLastQuery().'</pre>');
}
}
}
*/
}
?>

View File

@ -14,7 +14,5 @@ define("LAN_PLUGIN_FEATUREBOX_BATCH", "Create Featurebox Item");
// Install/uninstall messages
define('FBLAN_INSTALL_01', 'Adding Default category table data.'); //XXX Use Generic
define('FBLAN_INSTALL_02', 'Adding Default table data.'); //XXX Use Generic
?>
define('FBLAN_INSTALL_03', 'Unassigned');
define('FBLAN_INSTALL_04', 'General');

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Id: plugin.xml,v 1.9 2009-12-08 17:21:31 secretr Exp $ -->
<e107Plugin name="Featurebox" lan="LAN_PLUGIN_FEATUREBOX_NAME" version="1.0" date="2012-08-01" compatibility="2.0" installRequired="true">
<e107Plugin name="Featurebox" lan="LAN_PLUGIN_FEATUREBOX_NAME" version="1.1" date="2012-08-01" compatibility="2.0" installRequired="true">
<author name="e107 Inc." url="http://e107.org" />
<description lan="LAN_PLUGIN_FEATUREBOX_DESCRIPTION">Displays an animated area on the top of your page with news-items and other content you would like to feature.</description>
<category>content</category>