diff --git a/controller.php b/controller.php new file mode 100644 index 0000000..406b1cf --- /dev/null +++ b/controller.php @@ -0,0 +1,59 @@ + +* +*/ + +class Controller extends \Concrete\Core\Package\Package { + + protected $pkgHandle = 'custom_menu_items'; + protected $appVersionRequired = '5.7.0.4'; + protected $pkgVersion = '0.9'; + + public function getPackageDescription() { + return t("Create menu items to any page on your site."); + } + + public function getPackageName() { + return t("Custom Menu Items"); + } + + public function install() { + $pkg = parent::install(); + $sp = \SinglePage::add('/dashboard/system/basics/custom_menu_items', $pkg); + if (is_object($sp)) { + $sp->update(array('cName'=>t('Custom Menu Items'))); + } + } + + public function on_start() { + $u = new \User(); + if($u->isLoggedIn()) { + $db = \Loader::db(); + $r = $db->Execute('SELECT * FROM pkgCustomMenuItems ORDER BY DisplayOrder'); + while($row = $r->fetchRow()) + { + //$menu = new \Concrete\Core\Application\Service\UserInterface\Menu; + $menu = \Core::make('helper/concrete/ui/menu'); + $menu->addPageHeaderMenuItem( + 'custom_menu_item', + 'custom_menu_items', + array( + 'href' => $row['cID'], + 'position' => 'left' + ) + ); + } + //var_dump($menu->getPageHeaderMenuItems()); + + } + } +} diff --git a/controllers/single_page/dashboard/system/basics/custom_menu_items.php b/controllers/single_page/dashboard/system/basics/custom_menu_items.php new file mode 100644 index 0000000..5d1387c --- /dev/null +++ b/controllers/single_page/dashboard/system/basics/custom_menu_items.php @@ -0,0 +1,87 @@ +set('message', t('Menu Item Deleted')); + + case 'added': + $this->set('message', t('Menu Item Added')); + + case 'no': + $this->set('message', t('Invalid Page')); + + case 'exists': + $this->set('message', t('This page is already in the menu!')); + } + } + $db = \Loader::db(); + $r = $db->Execute('SELECT * FROM pkgCustomMenuItems ORDER BY DisplayOrder'); + $cIDs = array(); + while($row = $r->fetchRow()) + { + $cIDs[] = $row['cID']; + } + $this->set('cIDs', $cIDs); + } + + public function delete($cID = false, $toke = false) + { + if(!$this->token->validate('delete', $toke)) + { + $this->redirect('/dashboard/system/basics/custom_menu_items'); + } + $db = \Loader::db(); + $db->Execute('DELETE FROM pkgCustomMenuItems WHERE cID = ?', array($cID)); + $this->redirect('/dashboard/system/basics/custom_menu_items/deleted'); + } + + public function add($cID = false, $toke = false) + { + if(!$this->token->validate('add', $toke)) + { + $this->redirect('/dashboard/system/basics/custom_menu_items'); + } + $page = \Page::getByID($cID); + if(!is_object($page) || $page->isError()) + { + $this->redirect('/dashboard/system/basics/custom_menu_items/no'); + } + $db = \Loader::db(); + $exists = $db->getOne('SELECT cID FROM pkgCustomMenuItems WHERE cID = ?', array($cID)); + if($exists) + { + $this->redirect('/dashboard/system/basics/custom_menu_items/exists'); + } + $order = $db->GetOne('SELECT count(cID) FROM pkgCustomMenuItems'); + $db->Execute('INSERT into pkgCustomMenuItems (DisplayOrder,cID) VALUES (?,?)', array($order,$cID)); + $this->redirect('/dashboard/system/basics/custom_menu_items/added'); + } + + public function reorder() + { + if(!isset($_POST['order']) || !is_array($_POST['order'])) + { + $this->redirect('/dashboard/system/basics/custom_menu_items'); + } + $order = $this->post('order'); + $l = count($order); + for ($i = 0; $i < $l; $i++) { + try { + $db = \Loader::db(); + $db->Execute('UPDATE pkgCustomMenuItems SET DisplayOrder=? WHERE cID=?', + array($i, $order[$i])); + } catch (\Exception $e) { + } + } + exit; + + } +} \ No newline at end of file diff --git a/db.xml b/db.xml new file mode 100644 index 0000000..0e607d2 --- /dev/null +++ b/db.xml @@ -0,0 +1,9 @@ + + + + + + + +
+
\ No newline at end of file diff --git a/menu_item/custom_menu_item/controller.php b/menu_item/custom_menu_item/controller.php new file mode 100644 index 0000000..7721faa --- /dev/null +++ b/menu_item/custom_menu_item/controller.php @@ -0,0 +1,38 @@ +menuItem->getLink()); + + $a->setValue(h(t($page->getCollectionName()))); + $a->href($page->getCollectionLink()); + + $a->style('line-height: 14px;padding-top: 16px;width: '.(strlen($page->getCollectionName())*6.5+30).'px;'); + + return $a; + } + + public function displayItem() + { + $page = \Page::getByID($this->menuItem->getLink()); + if(is_object($page) && !$page->isError()) + { + $tcp = new \Permissions($page); + if ($tcp->canRead()) + { + return true; + } + } + return false; + } + +} \ No newline at end of file diff --git a/single_pages/dashboard/system/basics/custom_menu_items.php b/single_pages/dashboard/system/basics/custom_menu_items.php new file mode 100644 index 0000000..679ddcd --- /dev/null +++ b/single_pages/dashboard/system/basics/custom_menu_items.php @@ -0,0 +1,68 @@ + +
+
+ selectPage('menu_cID'); + ?> +
+
+ +
+
+ +
+ 0) { ?> +
+ + isError()) { + $name = h(t($page->getCollectionName())); + } else { + $name = t('Unknown Page'); + } + ?> + + + + + + +
+
+ + + +

+ +
\ No newline at end of file