Page MenuHomeMnkras Phabricator

No OneTemporary

diff --git a/controller.php b/controller.php
index e7e4b28..6e80a03 100644
--- a/controller.php
+++ b/controller.php
@@ -1,59 +1,57 @@
-<?php
-namespace Concrete\Package\CustomMenuItems;
-
-defined('C5_EXECUTE') or die("Access Denied.");
-
-/**
- *
- * Custom Menu Items Package.
- * @author Michael Krasnow <mnkras@gmail.com>
- *
- */
-
-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 for 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()) {
- /** @var $menu \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'
- )
- );
- }
- }
- }
-}
+<?php
+
+namespace Concrete\Package\CustomMenuItems;
+
+defined('C5_EXECUTE') or die("Access Denied.");
+
+/**
+ * Custom Menu Items Package.
+ *
+ * @author Michael Krasnow <mnkras@gmail.com>
+ */
+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 for 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()) {
+ /** @var $menu \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',
+ )
+ );
+ }
+ }
+ }
+}
diff --git a/controllers/single_page/dashboard/system/basics/custom_menu_items.php b/controllers/single_page/dashboard/system/basics/custom_menu_items.php
index c78cadf..65c1d48 100644
--- a/controllers/single_page/dashboard/system/basics/custom_menu_items.php
+++ b/controllers/single_page/dashboard/system/basics/custom_menu_items.php
@@ -1,87 +1,87 @@
<?php
+
namespace Concrete\Package\CustomMenuItems\Controller\SinglePage\Dashboard\System\Basics;
-use \Concrete\Core\Page\Controller\DashboardPageController;
+use Concrete\Core\Page\Controller\DashboardPageController;
class CustomMenuItems extends DashboardPageController
{
public function view($message = false)
{
if ($message) {
- switch($message) {
+ switch ($message) {
case 'deleted':
$this->set('message', t('Menu Item Deleted'));
break;
case 'added':
$this->set('message', t('Menu Item Added'));
break;
case 'no':
$this->set('message', t('Invalid Page'));
break;
case 'exists':
$this->set('message', t('This page is already in the menu!'));
break;
}
}
$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));
+ $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++) {
+ 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/menu_items/custom_menu_item/controller.php b/menu_items/custom_menu_item/controller.php
index 7721faa..846f1f8 100644
--- a/menu_items/custom_menu_item/controller.php
+++ b/menu_items/custom_menu_item/controller.php
@@ -1,38 +1,37 @@
<?php
+
namespace Concrete\Package\CustomMenuItems\MenuItem\CustomMenuItem;
-use HtmlObject\Element;
use HtmlObject\Link;
-class Controller extends \Concrete\Core\Application\UserInterface\Menu\Item\Controller {
-
+class Controller extends \Concrete\Core\Application\UserInterface\Menu\Item\Controller
+{
public $menuItem;
- public function getMenuItemLinkElement() {
+ public function getMenuItemLinkElement()
+ {
$a = new Link();
$page = \Page::getByID($this->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;');
+ $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())
- {
+ if (is_object($page) && !$page->isError()) {
$tcp = new \Permissions($page);
- if ($tcp->canRead())
- {
+ 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
index 1354e3c..ef18f16 100644
--- a/single_pages/dashboard/system/basics/custom_menu_items.php
+++ b/single_pages/dashboard/system/basics/custom_menu_items.php
@@ -1,68 +1,74 @@
<?php defined('C5_EXECUTE') or die('Access Denied');
$ps = Core::make('helper/form/page_selector');
?>
<div class="row">
<div class="col-md-8">
<?php
echo $ps->selectPage('menu_cID');
?>
</div>
<div class="col-md-4">
<a href="#" style="margin-top: 10px;" class="btn btn-primary" onclick="window.location='<?php echo $this->action('add') . '/\'+$(\'[name=menu_cID]\').val()+\'' . '/' . Core::make('helper/validation/token')->generate('add')?>'"><?php echo t('Add Menu Item')?></a>
</div>
</div>
<div class="row">
- <?php if (count($cIDs) > 0) { ?>
+ <?php if (count($cIDs) > 0) {
+ ?>
<div class="col-md-8">
<table class="table table-striped">
<?php foreach ($cIDs as $cID) {
- $page = \Page::getByID($cID);
- if (is_object($page) && !$page->isError()) {
- $name = h(t($page->getCollectionName()));
- } else {
- $name = t('Unknown Page');
- }
- ?>
+ $page = \Page::getByID($cID);
+ if (is_object($page) && !$page->isError()) {
+ $name = h(t($page->getCollectionName()));
+ } else {
+ $name = t('Unknown Page');
+ }
+ ?>
<tr data-cID="<?php echo $cID?>">
<td><a target="_blank" href="<?php echo $page->getCollectionLink()?>"><?php echo $name?></a></td>
<td><a class="btn btn-danger" href="<?php echo $this->action('delete', $cID, Core::make('helper/validation/token')->generate('delete'))?>"><?php echo t('Delete')?></a></td>
<td style="text-align:right"><i style="cursor: move" class="fa fa-arrows"></i></td>
</tr>
<?php
- } ?>
+
+}
+ ?>
</table>
</div>
<script type="text/javascript">
(function($,location){
'use strict';
$(function(){
var sortableTable = $('table.table tbody');
sortableTable.sortable({
handle: 'i.fa-arrows',
helper: function(e, ui) {
ui.children().each(function() {
var me = $(this);
me.width(me.width());
});
return ui;
},
cursor: 'move',
stop: function(e, ui) {
var order = [];
sortableTable.children().each(function() {
var me = $(this);
order.push(me.attr('data-cID'));
});
$.post('<?=$view->action('reorder')?>', {order: order});
}
});
});
})(jQuery, window.location);
</script>
- <?php } else { ?>
+ <?php
+} else {
+ ?>
<p><?php echo t("You have not added any menu items.")?></p>
- <?php } ?>
+ <?php
+} ?>
</div>
\ No newline at end of file

File Metadata

Mime Type
text/x-diff
Expires
Tue, Dec 24, 6:58 AM (1 d, 18 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
267610

Event Timeline