Dotclear


Ignore:
Timestamp:
03/05/18 13:56:37 (7 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

simpleMenu : set title to "Active page" or add " (active page)" for current simpleMenu active item link, closes #2267

Location:
plugins/simpleMenu
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • plugins/simpleMenu/_admin.php

    r2849 r3726  
    1010# 
    1111# -- END LICENSE BLOCK ----------------------------------------- 
    12 if (!defined('DC_CONTEXT_ADMIN')) { return; } 
     12if (!defined('DC_CONTEXT_ADMIN')) {return;} 
    1313 
    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'); 
     16function simpleMenu_dashboard($core, $icons) 
    1717{ 
    18      $icons['simpleMenu'] = new ArrayObject(array(__('Simple menu'), 
    19           $core->adminurl->get('admin.plugin.simpleMenu'), 
    20           dcPage::getPF('simpleMenu/icon.png'))); 
     18    $icons['simpleMenu'] = new ArrayObject(array(__('Simple menu'), 
     19        $core->adminurl->get('admin.plugin.simpleMenu'), 
     20        dcPage::getPF('simpleMenu/icon.png'))); 
    2121} 
    22 function simpleMenu_dashboard_favs($core,$favs) 
     22function simpleMenu_dashboard_favs($core, $favs) 
    2323{ 
    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      )); 
     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    )); 
    3131} 
    3232 
    3333$_menu['Blog']->addItem(__('Simple menu'), 
    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)); 
     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)); 
    3838 
    39 require dirname(__FILE__).'/_widgets.php'; 
     39require dirname(__FILE__) . '/_widgets.php'; 
  • plugins/simpleMenu/_define.php

    r3578 r3726  
    1010# 
    1111# -- END LICENSE BLOCK ----------------------------------------- 
    12 if (!defined('DC_RC_PATH')) { return; } 
     12if (!defined('DC_RC_PATH')) {return;} 
    1313 
    1414$this->registerModule( 
    15      /* Name */               "simpleMenu", 
    16      /* Description*/         "Simple menu for Dotclear", 
    17      /* Author */             "Franck Paul", 
    18      /* Version */            '1.4', 
    19      array( 
    20           'permissions' =>    'admin', 
    21           'type'         =>        'plugin', 
    22           'settings'     =>        array( 
    23                                         'self' => '' 
    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    ) 
    2626); 
  • plugins/simpleMenu/_public.php

    r3646 r3726  
    1010# 
    1111# -- END LICENSE BLOCK ----------------------------------------- 
    12 if (!defined('DC_RC_PATH')) { return; } 
     12if (!defined('DC_RC_PATH')) {return;} 
    1313 
    14 require dirname(__FILE__).'/_widgets.php'; 
     14require dirname(__FILE__) . '/_widgets.php'; 
    1515 
    1616# Simple menu template functions 
    17 $core->tpl->addValue('SimpleMenu',array('tplSimpleMenu','simpleMenu')); 
     17$core->tpl->addValue('SimpleMenu', array('tplSimpleMenu', 'simpleMenu')); 
    1818 
    1919class tplSimpleMenu 
    2020{ 
    21      # Template function 
    22      public static function simpleMenu($attr) 
    23      { 
    24           global $core; 
     21    # Template function 
     22    public static function simpleMenu($attr) 
     23    { 
     24        global $core; 
    2525 
    26           if (!(boolean) $core->blog->settings->system->simpleMenu_active) 
    27                return ''; 
     26        if (!(boolean) $core->blog->settings->system->simpleMenu_active) { 
     27            return ''; 
     28        } 
    2829 
    29           $class = isset($attr['class']) ? trim($attr['class']) : ''; 
    30           $id = isset($attr['id']) ? trim($attr['id']) : ''; 
    31           $description = isset($attr['description']) ? trim($attr['description']) : ''; 
     30        $class      = isset($attr['class']) ? trim($attr['class']) : ''; 
     31        $id          = isset($attr['id']) ? trim($attr['id']) : ''; 
     32        $description = isset($attr['description']) ? trim($attr['description']) : ''; 
    3233 
    33           if (!preg_match('#^(title|span|both|none)$#',$description)) { 
    34                $description = ''; 
    35           } 
     34        if (!preg_match('#^(title|span|both|none)$#', $description)) { 
     35            $description = ''; 
     36        } 
    3637 
    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    } 
    4344 
    44      # Widget function 
    45      public static function simpleMenuWidget($w) 
    46      { 
    47           global $core, $_ctx; 
     45    # Widget function 
     46    public static function simpleMenuWidget($w) 
     47    { 
     48        global $core, $_ctx; 
    4849 
    49           $descr_type = array(0 => 'span',1 => 'title',2 => 'both',3 => 'none'); 
     50        $descr_type = array(0 => 'span', 1 => 'title', 2 => 'both', 3 => 'none'); 
    5051 
    51           if (!(boolean) $core->blog->settings->system->simpleMenu_active) 
    52                return; 
     52        if (!(boolean) $core->blog->settings->system->simpleMenu_active) { 
     53            return; 
     54        } 
    5355 
    54           if ($w->offline) 
    55                return; 
     56        if ($w->offline) { 
     57            return; 
     58        } 
    5659 
    57           if (($w->homeonly == 1 && $core->url->type != 'default') || 
    58                ($w->homeonly == 2 && $core->url->type == 'default')) { 
    59                return; 
    60           } 
     60        if (($w->homeonly == 1 && $core->url->type != 'default') || 
     61            ($w->homeonly == 2 && $core->url->type == 'default')) { 
     62            return; 
     63        } 
    6164 
    62           $description = 'title'; 
    63           if (isset($descr_type[$w->description])) { 
    64                $description = $descr_type[$w->description]; 
    65           } 
    66           $menu = tplSimpleMenu::displayMenu('','',$description); 
    67           if ($menu == '') { 
    68                return; 
    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        } 
    7073 
    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    } 
    7477 
    75      public static function displayMenu($class='',$id='',$description='') 
    76      { 
    77           global $core; 
     78    public static function displayMenu($class = '', $id = '', $description = '') 
     79    { 
     80        global $core; 
    7881 
    79           $ret = ''; 
     82        $ret = ''; 
    8083 
    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        } 
    8387 
    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; 
    9093 
    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            } 
    96100 
    97                // Menu items loop 
    98                foreach ($menu as $i => $m) { 
    99                     # $href = lien de l'item de menu 
    100                     $href = $m['url']; 
    101                     $href = html::escapeHTML($href); 
     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); 
    102106 
    103                     # Cope with request only URL (ie ?query_part) 
    104                     $href_part = ''; 
    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                } 
    108112 
    109                     $targetBlank = ((isset($m['targetBlank'])) && ($m['targetBlank']))? true:false; 
     113                $targetBlank = ((isset($m['targetBlank'])) && ($m['targetBlank'])) ? true : false; 
    110114 
    111                     # Active item test 
    112                     $active = false; 
    113                     if (($url == $href) || 
    114                          ($abs_url == $href) || 
    115                          ($_SERVER['URL_REQUEST_PART'] == $href) || 
    116                          (($href_part != '') && ($_SERVER['URL_REQUEST_PART'] == $href_part)) || 
    117                          (($_SERVER['URL_REQUEST_PART'] == '') && (($href == $home_url) || ($href == $home_directory)))) { 
    118                          $active = true; 
    119                     } 
    120                     $title = $span = ''; 
     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 = ''; 
    121125 
    122                     if ($m['descr']) { 
    123                          if (($description == 'title' || $description == 'both') && $targetBlank) { 
    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                          if ($description == 'span' || $description == 'both') { 
    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                } 
    133137 
    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                } 
    137144 
    138                     $label = html::escapeHTML(__($m['label'])); 
     145                $label = html::escapeHTML(__($m['label'])); 
    139146 
    140                     $item = new ArrayObject(array( 
    141                          'url' => $href,                         // URL 
    142                          'label' => $label,                 // <a> link label 
    143                          '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                )); 
    148155 
    149                     # --BEHAVIOR-- publicSimpleMenuItem 
    150                     $core->callBehavior('publicSimpleMenuItem',$i,$item); 
     156                # --BEHAVIOR-- publicSimpleMenuItem 
     157                $core->callBehavior('publicSimpleMenuItem', $i, $item); 
    151158 
    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        } 
    169177 
    170           return $ret; 
    171      } 
     178        return $ret; 
     179    } 
    172180} 
Note: See TracChangeset for help on using the changeset viewer.

Sites map