Skip to content
Browse files

Removed "Display Content > Edit as a submenu" option to support EE 2.4+

  • Loading branch information...
1 parent 78c69e6 commit 7554a39387baeef3b545f68dd9c2910ca57ba2a7 @amacneil amacneil committed Mar 28, 2012
View
23 README.md
@@ -2,8 +2,8 @@ CP Menu Master
==============
Take control of your control panel menus! CP Menu Master allows you to hide channels from the
-publish menu for ALL users, show channels as a sub-menu in the edit menu, and even display
-control panel menus on mouse-over instead of click. Think of all those seconds you will save!
+publish and edit menus for ALL users, and display control panel menus on mouse-over instead of
+click. Think of all those seconds you will save!
Please note: This extension does not enforce any kind of security to prevent users publishing
to channels. It simply removes links from the publish menu, to reduce clutter. Smart users
@@ -25,14 +25,27 @@ required. Your pre-2.0 module settings will be migrated to the new version.
Changelog
---------
-**2.0.0** *(2011-06-07)*
+### 2.2.0
+*March 28, 2012*
+
+* Removed "Display Content > Edit as a submenu" option to support EE 2.4+
+
+### 2.1.0
+*August 18, 2011*
+
+* Added "Hide Filter by Channel on Edit Channel Entries page" option
+
+### 2.0.0
+*June 7, 2011*
* Rewritten as an extension to take advantage of new menu hook in EE 2.1.5+
-**1.0.1** *(2011-03-25)*
+### 1.0.1
+*March 25, 2011*
* Added ability to hide channels from the edit menu independently of the publish menu
-**1.0.0** *(2011-03-16)*
+### 1.0.0
+*March 16, 2011*
* Initial release
View
143 system/expressionengine/third_party/cp_menu_master/ext.cp_menu_master.php
@@ -27,13 +27,30 @@
class Cp_menu_master_ext
{
public $name = 'CP Menu Master';
- public $version = '2.1';
+ public $version = '2.2.0';
+ public $settings;
public $settings_exist = 'y';
- public $docs_url = 'http://github.com/crescendo/cp_menu_master';
+ public $docs_url = 'http://github.com/expressodev/cp_menu_master';
- public function __construct()
+ public function __construct($settings = array())
{
$this->EE =& get_instance();
+ $this->initialize($settings);
+ }
+
+ public function initialize($settings)
+ {
+ if (empty($settings['hidden_channels']) OR ! is_array($settings['hidden_channels']))
+ {
+ $settings['hidden_channels'] = array();
+ }
+
+ if (empty($settings['hidden_edit']) OR ! is_array($settings['hidden_edit']))
+ {
+ $settings['hidden_edit'] = array();
+ }
+
+ $this->settings = $settings;
}
public function activate_extension()
@@ -80,11 +97,13 @@ public function update_extension($current = '')
return TRUE;
}
- public function settings_form()
+ public function settings_form($settings)
{
+ $this->initialize($settings);
+
$data = array(
'post_url' => 'C=addons_extensions'.AMP.'M=save_extension_settings'.AMP.'file=cp_menu_master',
- 'settings' => $this->_load_settings()
+ 'settings' => $this->settings,
);
// get channel list
@@ -114,97 +133,29 @@ public function save_settings()
}
/**
- * Why isn't this built in?
- */
- private function _load_settings()
- {
- $this->EE->db->where('class', __CLASS__);
- $row = $this->EE->db->get('extensions')->row();
- if (empty($row->settings)) $settings = array();
- else $settings = unserialize($row->settings);
-
- if (empty($settings['hidden_channels']) OR ! is_array($settings['hidden_channels']))
- {
- $settings['hidden_channels'] = array();
- }
-
- if (empty($settings['hidden_edit']) OR ! is_array($settings['hidden_edit']))
- {
- $settings['hidden_edit'] = array();
- }
-
- return $settings;
- }
-
- /**
* CP Menu Array extension function
*
* Called by EE right before the top menu is generated, so we can edit it.
*/
public function cp_menu_array($menu)
{
- $settings = $this->_load_settings();
-
- if (empty($settings['hidden_channels']) OR ! is_array($settings['hidden_channels']))
+ // alter the menu as per settings
+ if (isset($menu['content']['publish']))
{
- $settings['hidden_channels'] = array();
+ $menu['content']['publish'] = $this->_remove_hidden_channels($menu['content']['publish'], $this->settings['hidden_channels']);
+ if (empty($menu['content']['publish'])) unset($menu['content']['publish']);
}
- // alter the menu as per settings
- if (isset($menu['content']['publish']) AND is_array($menu['content']['publish']))
+ if (isset($menu['content']['edit']))
{
- $content_edit = array();
-
- foreach ($menu['content']['publish'] as $title => $link)
- {
- $channel_id = (int)substr($link, stripos($link, 'channel_id=')+11);
-
- // remove the channel from publish menu if necessary
- if (in_array($channel_id, $settings['hidden_channels']))
- {
- unset($menu['content']['publish'][$title]);
- }
-
- // add channel to edit menu if necessary
- if ( ! in_array($channel_id, $settings['hidden_edit']))
- {
- $content_edit['cpmm_'.$title] = str_ireplace('C=content_publish&M=entry_form', 'C=content_edit', $link);
- $this->EE->lang->language['nav_cpmm_'.$title] = $title;
- }
- }
-
- // display publish menu
- if (empty($menu['content']['publish']))
- {
- unset($menu['content']['publish']);
- }
- elseif (count($menu['content']['publish']) == 1)
- {
- $menu['content']['publish'] = reset($menu['content']['publish']);
- }
-
- // display edit menu
- if ( ! empty($settings['edit_submenu']))
- {
- if (empty($content_edit))
- {
- unset($menu['content']['edit']);
- }
- elseif (count($content_edit) == 1)
- {
- $menu['content']['edit'] = reset($content_edit);
- }
- else
- {
- $menu['content']['edit'] = $content_edit;
- }
- }
+ $menu['content']['edit'] = $this->_remove_hidden_channels($menu['content']['edit'], $this->settings['hidden_edit']);
+ if (empty($menu['content']['edit'])) unset($menu['content']['edit']);
}
$extra_css = '';
// do we want to show CP menus on hover instead of click?
- if ( ! empty($settings['hover_menus']))
+ if ( ! empty($this->settings['hover_menus']))
{
$extra_css .= '
#navigationTabs li.parent:hover ul,
@@ -223,7 +174,7 @@ public function cp_menu_array($menu)
}
// do we want to hide the "Filter by Channel" drop-down?
- if ( ! empty($settings['hide_filter_by_channel']))
+ if ( ! empty($this->settings['hide_filter_by_channel']))
{
$extra_css .= '
#filterMenu #f_channel_id { display: none; }
@@ -238,6 +189,34 @@ public function cp_menu_array($menu)
return $menu;
}
+
+ protected function _remove_hidden_channels($menu, $hidden_channel_ids)
+ {
+ if (empty($menu)) return NULL;
+ if ( ! is_array($menu)) return $menu;
+
+ // remove any hidden channels
+ foreach ($menu as $key => $url)
+ {
+ $channel_id = (int)substr($url, stripos($url, 'channel_id=') + 11);
+ if (in_array($channel_id, $hidden_channel_ids))
+ {
+ unset($menu[$key]);
+ }
+ }
+
+ // tidy up menu
+ if (empty($menu))
+ {
+ return NULL;
+ }
+ elseif (count($menu) == 1)
+ {
+ return reset($menu);
+ }
+
+ return $menu;
+ }
}
/* End of file ./system/expressionengine/third_party/cp_menu_master/ext.cp_menu_master.php */
View
1 system/expressionengine/third_party/cp_menu_master/language/english/cp_menu_master_lang.php
@@ -2,7 +2,6 @@
$lang = array(
'cp_menu_options' => 'Control Panel Menu Options',
- 'display_content_edit_submenu' => 'Display "Content > Edit" as a submenu',
'display_menus_on_hover' => 'Display menus on hover instead of click',
'hide_from_publish' => 'Hide from<br/>Publish menu',
'hide_from_edit' => 'Hide from<br/>Edit menu',
View
4 system/expressionengine/third_party/cp_menu_master/views/index.php
@@ -3,10 +3,6 @@
<fieldset>
<legend><?= lang('cp_menu_options') ?></legend>
<p><label>
- <?= form_checkbox('settings[edit_submenu]', 'y', ! empty($settings['edit_submenu']), 'id="settings_edit_submenu"') ?>
- <?= lang('display_content_edit_submenu') ?>
- </label></p>
- <p><label>
<?= form_checkbox('settings[hover_menus]', 'y', ! empty($settings['hover_menus'])) ?>
<?= lang('display_menus_on_hover') ?>
</label></p>

0 comments on commit 7554a39

Please sign in to comment.
Something went wrong with that request. Please try again.