Changeset 3726:5e5627d21aa3 for plugins/simpleMenu
- Timestamp:
- 03/05/18 13:56:37 (7 years ago)
- Branch:
- default
- Location:
- plugins/simpleMenu
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/simpleMenu/_admin.php
r2849 r3726 10 10 # 11 11 # -- END LICENSE BLOCK ----------------------------------------- 12 if (!defined('DC_CONTEXT_ADMIN')) { return;}12 if (!defined('DC_CONTEXT_ADMIN')) {return;} 13 13 14 $core->addBehavior('adminDashboardIcons', 'simpleMenu_dashboard');15 $core->addBehavior('adminDashboardFavorites', 'simpleMenu_dashboard_favs');16 function simpleMenu_dashboard($core, $icons)14 $core->addBehavior('adminDashboardIcons', 'simpleMenu_dashboard'); 15 $core->addBehavior('adminDashboardFavorites', 'simpleMenu_dashboard_favs'); 16 function simpleMenu_dashboard($core, $icons) 17 17 { 18 19 20 18 $icons['simpleMenu'] = new ArrayObject(array(__('Simple menu'), 19 $core->adminurl->get('admin.plugin.simpleMenu'), 20 dcPage::getPF('simpleMenu/icon.png'))); 21 21 } 22 function simpleMenu_dashboard_favs($core, $favs)22 function simpleMenu_dashboard_favs($core, $favs) 23 23 { 24 25 'title'=> __('Simple menu'),26 'url'=> $core->adminurl->get('admin.plugin.simpleMenu'),27 'small-icon'=> dcPage::getPF('simpleMenu/icon-small.png'),28 'large-icon'=> dcPage::getPF('simpleMenu/icon.png'),29 30 24 $favs->register('simpleMenu', array( 25 'title' => __('Simple menu'), 26 'url' => $core->adminurl->get('admin.plugin.simpleMenu'), 27 'small-icon' => dcPage::getPF('simpleMenu/icon-small.png'), 28 'large-icon' => dcPage::getPF('simpleMenu/icon.png'), 29 'permissions' => 'usage,contentadmin' 30 )); 31 31 } 32 32 33 33 $_menu['Blog']->addItem(__('Simple menu'), 34 35 36 preg_match('/' .preg_quote($core->adminurl->get('admin.plugin.simpleMenu')).'(&.*)?$/',$_SERVER['REQUEST_URI']),37 $core->auth->check('usage,contentadmin', $core->blog->id));34 $core->adminurl->get('admin.plugin.simpleMenu'), 35 dcPage::getPF('simpleMenu/icon-small.png'), 36 preg_match('/' . preg_quote($core->adminurl->get('admin.plugin.simpleMenu')) . '(&.*)?$/', $_SERVER['REQUEST_URI']), 37 $core->auth->check('usage,contentadmin', $core->blog->id)); 38 38 39 require dirname(__FILE__) .'/_widgets.php';39 require dirname(__FILE__) . '/_widgets.php'; -
plugins/simpleMenu/_define.php
r3578 r3726 10 10 # 11 11 # -- END LICENSE BLOCK ----------------------------------------- 12 if (!defined('DC_RC_PATH')) { return;}12 if (!defined('DC_RC_PATH')) {return;} 13 13 14 14 $this->registerModule( 15 /* Name */ "simpleMenu", 16 /* Description*/ "Simple menu for Dotclear", 17 /* Author */ "Franck Paul", 18 /* Version */ '1.4', 19 20 'permissions' =>'admin',21 'type' =>'plugin',22 'settings' =>array(23 24 25 15 "simpleMenu", // Name 16 "Simple menu for Dotclear", // Description 17 "Franck Paul", // Author 18 '1.5', // Version 19 array( 20 'permissions' => 'admin', 21 'type' => 'plugin', 22 'settings' => array( 23 'self' => '' 24 ) 25 ) 26 26 ); -
plugins/simpleMenu/_public.php
r3646 r3726 10 10 # 11 11 # -- END LICENSE BLOCK ----------------------------------------- 12 if (!defined('DC_RC_PATH')) { return;}12 if (!defined('DC_RC_PATH')) {return;} 13 13 14 require dirname(__FILE__) .'/_widgets.php';14 require dirname(__FILE__) . '/_widgets.php'; 15 15 16 16 # Simple menu template functions 17 $core->tpl->addValue('SimpleMenu', array('tplSimpleMenu','simpleMenu'));17 $core->tpl->addValue('SimpleMenu', array('tplSimpleMenu', 'simpleMenu')); 18 18 19 19 class tplSimpleMenu 20 20 { 21 22 23 24 21 # Template function 22 public static function simpleMenu($attr) 23 { 24 global $core; 25 25 26 if (!(boolean) $core->blog->settings->system->simpleMenu_active) 27 return ''; 26 if (!(boolean) $core->blog->settings->system->simpleMenu_active) { 27 return ''; 28 } 28 29 29 $class= isset($attr['class']) ? trim($attr['class']) : '';30 $id= isset($attr['id']) ? trim($attr['id']) : '';31 30 $class = isset($attr['class']) ? trim($attr['class']) : ''; 31 $id = isset($attr['id']) ? trim($attr['id']) : ''; 32 $description = isset($attr['description']) ? trim($attr['description']) : ''; 32 33 33 if (!preg_match('#^(title|span|both|none)$#',$description)) {34 35 34 if (!preg_match('#^(title|span|both|none)$#', $description)) { 35 $description = ''; 36 } 36 37 37 return '<?php echo tplSimpleMenu::displayMenu('.38 "'".addslashes($class)."',".39 "'".addslashes($id)."',".40 "'".addslashes($description)."'".41 42 38 return '<?php echo tplSimpleMenu::displayMenu(' . 39 "'" . addslashes($class) . "'," . 40 "'" . addslashes($id) . "'," . 41 "'" . addslashes($description) . "'" . 42 '); ?>'; 43 } 43 44 44 45 46 47 45 # Widget function 46 public static function simpleMenuWidget($w) 47 { 48 global $core, $_ctx; 48 49 49 $descr_type = array(0 => 'span',1 => 'title',2 => 'both',3 => 'none');50 $descr_type = array(0 => 'span', 1 => 'title', 2 => 'both', 3 => 'none'); 50 51 51 if (!(boolean) $core->blog->settings->system->simpleMenu_active) 52 return; 52 if (!(boolean) $core->blog->settings->system->simpleMenu_active) { 53 return; 54 } 53 55 54 if ($w->offline) 55 return; 56 if ($w->offline) { 57 return; 58 } 56 59 57 58 59 60 60 if (($w->homeonly == 1 && $core->url->type != 'default') || 61 ($w->homeonly == 2 && $core->url->type == 'default')) { 62 return; 63 } 61 64 62 63 64 65 66 $menu = tplSimpleMenu::displayMenu('','',$description);67 68 69 65 $description = 'title'; 66 if (isset($descr_type[$w->description])) { 67 $description = $descr_type[$w->description]; 68 } 69 $menu = tplSimpleMenu::displayMenu('', '', $description); 70 if ($menu == '') { 71 return; 72 } 70 73 71 return $w->renderDiv($w->content_only,'simple-menu '.$w->class,'',72 ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '').$menu);73 74 return $w->renderDiv($w->content_only, 'simple-menu ' . $w->class, '', 75 ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') . $menu); 76 } 74 77 75 public static function displayMenu($class='',$id='',$description='')76 77 78 public static function displayMenu($class = '', $id = '', $description = '') 79 { 80 global $core; 78 81 79 82 $ret = ''; 80 83 81 if (!(boolean) $core->blog->settings->system->simpleMenu_active) 82 return $ret; 84 if (!(boolean) $core->blog->settings->system->simpleMenu_active) { 85 return $ret; 86 } 83 87 84 $menu = $core->blog->settings->system->simpleMenu; 85 if (is_array($menu)) 86 { 87 // Current relative URL 88 $url = $_SERVER['REQUEST_URI']; 89 $abs_url = http::getHost().$url; 88 $menu = $core->blog->settings->system->simpleMenu; 89 if (is_array($menu)) { 90 // Current relative URL 91 $url = $_SERVER['REQUEST_URI']; 92 $abs_url = http::getHost() . $url; 90 93 91 // Home recognition var 92 $home_url = html::stripHostURL($core->blog->url); 93 $home_directory = dirname($home_url); 94 if ($home_directory != '/') 95 $home_directory = $home_directory.'/'; 94 // Home recognition var 95 $home_url = html::stripHostURL($core->blog->url); 96 $home_directory = dirname($home_url); 97 if ($home_directory != '/') { 98 $home_directory = $home_directory . '/'; 99 } 96 100 97 98 99 100 101 101 // Menu items loop 102 foreach ($menu as $i => $m) { 103 # $href = lien de l'item de menu 104 $href = $m['url']; 105 $href = html::escapeHTML($href); 102 106 103 104 105 if ($href != '' && substr($href,0,1) == '?') {106 $href_part = substr($href,1);107 107 # Cope with request only URL (ie ?query_part) 108 $href_part = ''; 109 if ($href != '' && substr($href, 0, 1) == '?') { 110 $href_part = substr($href, 1); 111 } 108 112 109 $targetBlank = ((isset($m['targetBlank'])) && ($m['targetBlank']))? true:false;113 $targetBlank = ((isset($m['targetBlank'])) && ($m['targetBlank'])) ? true : false; 110 114 111 112 113 114 115 116 117 118 119 120 115 # Active item test 116 $active = false; 117 if (($url == $href) || 118 ($abs_url == $href) || 119 ($_SERVER['URL_REQUEST_PART'] == $href) || 120 (($href_part != '') && ($_SERVER['URL_REQUEST_PART'] == $href_part)) || 121 (($_SERVER['URL_REQUEST_PART'] == '') && (($href == $home_url) || ($href == $home_directory)))) { 122 $active = true; 123 } 124 $title = $span = ''; 121 125 122 123 124 $title = ' title="'.html::escapeHTML(__($m['descr'])).' ('.125 __("the link will open a new window").')"';126 }elseif($description == 'title' || $description == 'both'){127 $title = ' title="'.html::escapeHTML(__($m['descr'])).'"';128 129 130 $span = ' <span class="simple-menu-descr">'.html::escapeHTML(__($m['descr'])).'</span>';131 132 126 if ($m['descr']) { 127 if (($description == 'title' || $description == 'both') && $targetBlank) { 128 $title = html::escapeHTML(__($m['descr'])) . ' (' . 129 __('the link will open a new window') . ')'; 130 } elseif ($description == 'title' || $description == 'both') { 131 $title = html::escapeHTML(__($m['descr'])); 132 } 133 if ($description == 'span' || $description == 'both') { 134 $span = ' <span class="simple-menu-descr">' . html::escapeHTML(__($m['descr'])) . '</span>'; 135 } 136 } 133 137 134 if( empty($title) && $targetBlank){ 135 $title = ' title="'.__("the link will open a new window").'"'; 136 } 138 if (empty($title) && $targetBlank) { 139 $title = __('the link will open a new window'); 140 } 141 if ($active && !$targetBlank) { 142 $title = (empty($title) ? __('Active page') : $title . ' (' . __('active page') . ')'); 143 } 137 144 138 145 $label = html::escapeHTML(__($m['label'])); 139 146 140 141 'url' => $href,// URL142 'label' => $label,// <a> link label143 'title' => $title,// <a> link title (optional)144 'span' => $span,// description (will be displayed after <a> link)145 'active' => $active,// status (true/false)146 'class' => ''// additional <li> class (optional)147 147 $item = new ArrayObject(array( 148 'url' => $href, // URL 149 'label' => $label, // <a> link label 150 'title' => $title, // <a> link title (optional) 151 'span' => $span, // description (will be displayed after <a> link) 152 'active' => $active, // status (true/false) 153 'class' => '' // additional <li> class (optional) 154 )); 148 155 149 150 $core->callBehavior('publicSimpleMenuItem',$i,$item);156 # --BEHAVIOR-- publicSimpleMenuItem 157 $core->callBehavior('publicSimpleMenuItem', $i, $item); 151 158 152 $ret .= '<li class="li'.($i+1). 153 ($item['active'] ? ' active' : ''). 154 ($i == 0 ? ' li-first' : ''). 155 ($i == count($menu)-1 ? ' li-last' : ''). 156 ($item['class'] ? $item['class'] : ''). 157 '">'. 158 '<a href="'.$href.'"'.$item['title']. 159 (($targetBlank) ? 'target="_blank" rel="noopener noreferrer"': '').'>'. 160 '<span class="simple-menu-label">'.$item['label'].'</span>'. 161 $item['span'].'</a>'. 162 '</li>'; 163 } 164 // Final rendering 165 if ($ret) { 166 $ret = '<nav role="navigation"><ul '.($id ? 'id="'.$id.'"' : '').' class="simple-menu'.($class ? ' '.$class : '').'">'."\n".$ret."\n".'</ul></nav>'; 167 } 168 } 159 $ret .= '<li class="li' . ($i + 1) . 160 ($item['active'] ? ' active' : '') . 161 ($i == 0 ? ' li-first' : '') . 162 ($i == count($menu) - 1 ? ' li-last' : '') . 163 ($item['class'] ? ' ' . $item['class'] : '') . 164 '">' . 165 '<a href="' . $href . '"' . 166 (!empty($item['title']) ? ' title="' . $item['title'] . '"' : '') . 167 (($targetBlank) ? ' target="_blank" rel="noopener noreferrer"' : '') . '>' . 168 '<span class="simple-menu-label">' . $item['label'] . '</span>' . 169 $item['span'] . '</a>' . 170 '</li>'; 171 } 172 // Final rendering 173 if ($ret) { 174 $ret = '<nav role="navigation"><ul ' . ($id ? 'id="' . $id . '"' : '') . ' class="simple-menu' . ($class ? ' ' . $class : '') . '">' . "\n" . $ret . "\n" . '</ul></nav>'; 175 } 176 } 169 177 170 171 178 return $ret; 179 } 172 180 }
Note: See TracChangeset
for help on using the changeset viewer.