array( 'controller' => 'links_admin_ui', 'path' => null, 'ui' => 'links_admin_form_ui', 'uipath' => null ) ); protected $adminMenu = array( 'main/list' => array('caption'=> LAN_MANAGE, 'perm' => 'I'), 'main/create' => array('caption'=> LAN_CREATE, 'perm' => 'I'), 'main/prefs' => array('caption'=> LAN_OPTIONS, 'perm' => 'I'), 'main/tools' => array('caption'=> LINKLAN_4, 'perm' => 'I') ); protected $adminMenuAliases = array( 'main/edit' => 'main/list' ); protected $menuTitle = LAN_NAVIGATION; protected $adminMenuIcon = 'e-links-24'; } class links_admin_ui extends e_admin_ui { protected $pluginTitle = LAN_NAVIGATION; protected $pluginName = 'core'; protected $table = "links"; protected $listQry = ''; protected $pid = "link_id"; protected $perPage = 0; protected $batchDelete = true; protected $batchCopy = true; protected $listOrder = 'link_category,link_order ASC'; protected $sortField = 'link_order'; //FIXME TOOD - Filter out 'unassigned' entries by default. public $current_parent = 0; public $sublink_data = null; protected $fields = array( 'checkboxes' => array('title'=> '', 'width' => '3%', 'forced' => true, 'thclass'=>'center first', 'class'=>'center first'), 'link_button' => array('title'=> LAN_ICON, 'type'=>'icon', 'width'=>'5%', 'thclass'=>'center', 'class'=>'center', 'readParms'=>array('legacy'=>'{e_IMAGE}icons/'), 'writeParms'=>'glyphs=1'), 'link_id' => array('title'=> LAN_ID, 'type'=>'method', 'readParms'=>'', 'noedit'=>TRUE), 'link_name' => array('title'=> LAN_NAME, 'type'=>'text', 'inline'=>true, 'required'=>false, 'validate'=>false, 'width'=>'auto', 'writeParms'=>array('size'=>'xlarge')), // not required as only an icon may be used. 'link_category' => array('title'=> LAN_TEMPLATE, 'type'=>'dropdown', 'inline'=>true, 'batch'=>true, 'filter'=>true, 'width'=>'auto', 'writeParms'=>array('size'=>'xlarge')), 'link_parent' => array('title'=> LAN_PARENT, 'type' => 'method', 'data'=>'int', 'width'=>'auto', 'batch'=>true, 'filter'=>true, 'thclass'=>'left first', 'writeParms'=>array('size'=>'xlarge')), 'link_url' => array('title'=> LAN_URL, 'width'=>'auto', 'type'=>'method', 'inline'=>true, 'required'=>true,'validate' => true, 'writeParms'=>'size=xxlarge'), 'link_sefurl' => array('title'=> LAN_SEFURL, 'type' => 'method', 'inline'=>false, 'width' => 'auto', 'help'=>LCLAN_107), 'link_class' => array('title'=> LAN_USERCLASS, 'type' => 'userclass','inline'=>true, 'writeParms' => 'classlist=public,guest,nobody,member,classes,admin,main', 'batch'=>true, 'filter'=>true, 'width' => 'auto'), 'link_description' => array('title'=> LAN_DESCRIPTION, 'type' => 'textarea', 'width' => 'auto'), // 'method'=>'tinymce_plugins', ? 'link_order' => array('title'=> LAN_ORDER, 'type' => 'number', 'width' => 'auto', 'nolist'=>false, 'inline' => true), 'link_open' => array('title'=> LCLAN_19, 'type' => 'dropdown', 'inline'=>true, 'width' => 'auto', 'batch'=>true, 'filter'=>true, 'thclass' => 'left first', 'writeParms'=>array('size'=>'xlarge')), 'link_function' => array('title'=> LCLAN_105, 'type' => 'method', 'data'=>'str', 'width' => 'auto', 'thclass' => 'left first'), 'link_owner' => array('title'=> LCLAN_106, 'type' => 'hidden', 'data'=>'str'), 'options' => array('title'=> LAN_OPTIONS, 'type' => null, 'forced'=>TRUE, 'width' => '10%', 'thclass' => 'center last', 'class'=>'center','readParms'=>'sort=1') // quick workaround ); protected $fieldpref = array('checkboxes','link_button', 'link_id','link_name','link_sefurl','link_class','link_category','options'); protected $prefs = array( 'linkpage_screentip' => array('title'=>LCLAN_78, 'type'=>'boolean', 'help'=>LCLAN_79), 'sitelinks_expandsub' => array('title'=>LCLAN_80, 'type'=>'boolean', 'help'=>LCLAN_81) ); /** * Runtime cache of all links array * @var array */ protected $_link_array = null; function afterCreate($new_data, $old_data, $id) //FIXME needs to work after inline editing too. { e107::getCache()->clearAll('content'); } function afterUpdate($new_data, $old_data, $id) //FIXME needs to work after inline editing too. { e107::getCache()->clearAll('content'); } function init() { $this->fields['link_category']['writeParms']['optArray'] = array( 1 => "1 - Main", 2 => "2 - Sidebar", 3 => "3 - Footer", 4 => "4 - Alt", 5 => "5 - Alt", 6 => "6 - Alt", // If more than 6 are required, then something is not right with the themeing method. // 7 => "7 - Alt", // 8 => "8 - Alt", // 9 => "9 - Alt", // 10 => "10 - Alt" 255 => "(Unassigned)", ); $this->fields['link_open']['writeParms']['optArray'] = array( 0 => LCLAN_20, // 0 = same window 1 => LCLAN_23, // new window 4 => LCLAN_24, // 4 = miniwindow 600x400 5 => LINKLAN_1 // 5 = miniwindow 800x600 ); } public function handleListLinkParentBatch($selected, $value) { $field = 'link_parent'; $ui = $this->getUI(); $found = false; foreach ($selected as $k => $id) { // var_dump($ui->_has_parent($value, $id, $this->getLinkArray())); if($ui->_has_parent($value, $id, $this->getLinkArray())) { unset($selected[$k]); $found = true; } } if($found) e107::getMessage()->addWarning(LCLAN_108); if(!$selected) return; if(parent::handleListBatch($selected, $field, $value)) { $this->_link_array = null; // reset batch/filters return true; } return false; } public function ListObserver() { $searchFilter = $this->_parseFilterRequest($this->getRequest()->getQuery('filter_options', '')); if($searchFilter && in_array('link_parent', $searchFilter)) { $this->getTreeModel()->current_id = intval($searchFilter[1]); $this->current_parent = intval($searchFilter[1]); } parent::ListObserver(); } public function ListAjaxObserver() { $searchFilter = $this->_parseFilterRequest($this->getRequest()->getQuery('filter_options', '')); if($searchFilter && in_array('link_parent', $searchFilter)) { $this->getTreeModel()->current_id = intval($searchFilter[1]); $this->current_parent = intval($searchFilter[1]); } parent::ListAjaxObserver(); } /** * Form submitted - 'etrigger_generate_sublinks' POST variable caught *//* public function SublinksGenerateSublinksTrigger() { $this->generateSublinks(); } public function sublinksObserver() { $this->getTreeModel()->load(); }*/ /** * Sublinks generator */ public function toolsPage() { if(!empty($_POST['etrigger_generate_sublinks'])) { $this->generateSublinks($_POST); } $sublinks = $this->sublink_data(); $ui = $this->getUI(); // TODO - use UI create form $sql = e107::getDb(); $text = "
"; //$e107->ns->tablerender(LINKLAN_4, $emessage->render().$text); // $this->addTitle(LINKLAN_4); return $text; } function sublink_data($name = "") { if(null !== $this->sublink_data) return ($name ? $this->sublink_data[$name] : $this->sublink_data); $sublink_type = array(); $sublink_type['news']['title'] = LINKLAN_8; // "News Categories"; $sublink_type['news']['table'] = "news_category"; $sublink_type['news']['query'] = "category_id !='-2' ORDER BY category_name ASC"; $sublink_type['news']['url'] = "news.php?list.#"; $sublink_type['news']['fieldid'] = "category_id"; $sublink_type['news']['fieldname'] = "category_name"; $sublink_type['news']['fieldicon'] = "category_icon"; $sublink_type['news']['sef'] = "news/list/category"; $sublink_type['newsalt'] = $sublink_type['news']; $sublink_type['newsalt']['url'] = "news.php?cat.#"; $sublink_type['newsalt']['title'] = LINKLAN_8." (".LAN_LIST.")"; // "News Categories"; $sublink_type['newsalt']['sef'] = "news/list/short"; $sublink_type['downloads']['title'] = LINKLAN_9; //"Download Categories"; $sublink_type['downloads']['table'] = "download_category"; $sublink_type['downloads']['query'] = "download_category_parent ='0' ORDER BY download_category_name ASC"; $sublink_type['downloads']['url'] = "download.php?list.#"; $sublink_type['downloads']['fieldid'] = "download_category_id"; $sublink_type['downloads']['fieldname'] = "download_category_name"; $sublink_type['downloads']['fieldicon'] = "download_category_icon"; // fixed - sql query not needed $plugins = array_keys(e107::getConfig()->get('plug_installed')); foreach ($plugins as $plugin) { if(is_readable(e_PLUGIN.$plugin.'/e_linkgen.php')) { require_once (e_PLUGIN.$plugin.'/e_linkgen.php'); } } $this->sublink_data = $sublink_type; if($name) { return $sublink_type[$name]; } return $sublink_type; } function generateSublinks($sublink) { $mes = e107::getMessage(); $subtype = $this->getPosted('sublink_type');//$_POST['sublink_type']; $pid = intval($this->getPosted('link_parent')); $sublink = $this->sublink_data($subtype); // if(!$pid) // { // $mes->addWarning(LCLAN_109); // return; // } if(!$subtype) { $mes->addWarning(LCLAN_110); return; } if(!$sublink) { $mes->addError(LCLAN_111); return; } $sublink = $this->sublink_data($subtype); $sql = e107::getDb(); $sql2 = e107::getDb('sql2'); $sql->select("links", "*", "link_id=".$pid); $par = $sql->fetch(); //extract($par); // Added option for passing of result array if(vartrue($sublink['result'])) { $count = 1; foreach ($sublink['result'] as $row) { $subcat = $row[($sublink['fieldid'])]; $name = $row[($sublink['fieldname'])]; $subname = $name; // eliminate old embedded hierarchy from names. (e.g. 'submenu.TopName.name') if(!empty($sublink['sef'])) { $suburl = e107::url($sublink['sef'], $row); } else { $suburl = str_replace("#", $subcat, $sublink['url']); } $subicon = ($sublink['fieldicon']) ? $row[($sublink['fieldicon'])] : $par['link_button']; $subdiz = ($sublink['fielddiz']) ? $row[($sublink['fielddiz'])] : $par['link_description']; $subparent = $pid; $insert_array = array( 'link_name' => $subname, 'link_url' => $suburl, 'link_description' => $subdiz, 'link_button' => $subicon, 'link_category' => $par['link_category'], 'link_order' => $count, 'link_parent' => $subparent, 'link_open' => $par['link_open'], 'link_class' => $par['link_class'], 'link_function' => '' ); $count++; } } else { $sql->select($sublink['table'], "*", $sublink['query']); $count = 1; while($row = $sql->fetch()) { $subcat = $row[($sublink['fieldid'])]; $name = $row[($sublink['fieldname'])]; $subname = $name; // eliminate old embedded hierarchy from names. (e.g. 'submenu.TopName.name') if(!empty($sublink['sef'])) { $suburl = e107::url($sublink['sef'], $row); } else { $suburl = str_replace("#", $subcat, $sublink['url']); } $subicon = ($sublink['fieldicon']) ? $row[($sublink['fieldicon'])] : $par['link_button']; $subdiz = ($sublink['fielddiz']) ? $row[($sublink['fielddiz'])] : $par['link_description']; $subparent = $pid; $insert_array = array( 'link_name' => $subname, 'link_url' => $suburl, 'link_description' => $subdiz, 'link_button' => $subicon, 'link_category' => vartrue($par['link_category'],1), 'link_order' => $count, 'link_parent' => $subparent, 'link_open' => $par['link_open'], 'link_class' => intval($par['link_class']), 'link_function' => '' ); e107::getMessage()->addDebug(print_a($insert_array,true)); if($sql2->insert("links",$insert_array)) { $message = LAN_CREATED." ({$name})[!br!]"; $mes->addSuccess(LAN_CREATED." ({$name})"); } else { $message = LAN_CREATED_FAILED." ({$name})[!br!]"; $mes->addError(LAN_CREATED_FAILED." ({$name})"); } $count++; } } } /** * Product tree model * @return links_admin_ui|links_model_admin_tree */ public function _setTreeModel() { $this->_tree_model = new links_model_admin_tree(); return $this; } /** * Link ordered array * @return array */ public function getLinkArray($current_id = 0) { if(null === $this->_link_array) { if($this->getAction() != 'list') { $this->getTreeModel()->setParam('order', 'ORDER BY '.$this->listOrder)->loadBatch(); } /** @var e_tree_modell $tree */ $tree = $this->getTreeModel()->getTree(); $this->_link_array = array(); foreach ($tree as $id => $model) { if($current_id == $id) continue; $this->_link_array[$model->get('link_parent')][$id] = $model->get('link_name'); } asort($this->_link_array); } return $this->_link_array; } } class links_model_admin_tree extends e_admin_tree_model { public $modify = false; public $current_id = 0; protected $_db_table = 'links'; protected $_link_array = null; protected $_link_array_modified = null; protected $_field_id = 'link_id'; /** * Get array of models * Custom tree order * @return array */ function getTree($force = false) { return $this->getOrderedTree($this->modify); } /** * Get ordered by their parents models * @return array */ function getOrderedTree($modified = false) { $var = !$modified ? '_link_array' : '_link_array_modified'; if(null === $this->$var) { $tree = $this->get('__tree', array()); $this->$var = array(); $search = array(); foreach ($tree as $id => $model) { $search[$model->get('link_parent')][$id] = $model; } asort($search); $this->_tree_order($this->current_id, $search, $this->$var, 0, $modified); } //$this->buildTreeIndex(); return $this->$var; } /** * Reorder current tree * @param $parent_id * @param $search * @param $src * @param $level * @return void */ function _tree_order($parent_id, $search, &$src, $level = 0, $modified = false) { if(!isset($search[$parent_id])) { return; } $level_image = $level ? '