Dotclear

source: plugins/simpleMenu/_public.php @ 3600:f9ab70453f48

Revision 3600:f9ab70453f48, 4.8 KB checked in by franck <carnet.franck.paul@…>, 8 years ago (diff)

Fix target="blank" vulnerability, thanks DaScritch? for report

RevLine 
[532]1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
[1179]6# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
[532]7# Licensed under the GPL version 2.0 license.
8# See LICENSE file or
9# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10#
11# -- END LICENSE BLOCK -----------------------------------------
12if (!defined('DC_RC_PATH')) { return; }
13
[587]14require dirname(__FILE__).'/_widgets.php';
15
[532]16# Simple menu template functions
17$core->tpl->addValue('SimpleMenu',array('tplSimpleMenu','simpleMenu'));
18
19class tplSimpleMenu
20{
[587]21     # Template function
[532]22     public static function simpleMenu($attr)
23     {
[2773]24          global $core;
25
26          if (!(boolean) $core->blog->settings->system->simpleMenu_active)
27               return '';
28
[532]29          $class = isset($attr['class']) ? trim($attr['class']) : '';
[538]30          $id = isset($attr['id']) ? trim($attr['id']) : '';
[566]31          $description = isset($attr['description']) ? trim($attr['description']) : '';
[2566]32
[2928]33          if (!preg_match('#^(title|span|both|none)$#',$description)) {
[567]34               $description = '';
35          }
[2566]36
[532]37          return '<?php echo tplSimpleMenu::displayMenu('.
[538]38                    "'".addslashes($class)."',".
[566]39                    "'".addslashes($id)."',".
40                    "'".addslashes($description)."'".
[532]41               '); ?>';
42     }
[2566]43
[587]44     # Widget function
45     public static function simpleMenuWidget($w)
46     {
47          global $core, $_ctx;
[2566]48
[2928]49          $descr_type = array(0 => 'span',1 => 'title',2 => 'both',3 => 'none');
50
[2773]51          if (!(boolean) $core->blog->settings->system->simpleMenu_active)
52               return;
53
[2778]54          if ($w->offline)
55               return;
56
[945]57          if (($w->homeonly == 1 && $core->url->type != 'default') ||
58               ($w->homeonly == 2 && $core->url->type == 'default')) {
[587]59               return;
60          }
61
[2928]62          $description = 'title';
63          if (isset($descr_type[$w->description])) {
64               $description = $descr_type[$w->description];
65          }
66          $menu = tplSimpleMenu::displayMenu('','',$description);
[587]67          if ($menu == '') {
68               return;
69          }
70
[2667]71          return $w->renderDiv($w->content_only,'simple-menu '.$w->class,'',
72               ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '').$menu);
[587]73     }
[2566]74
[566]75     public static function displayMenu($class='',$id='',$description='')
[532]76     {
[1062]77          global $core;
78
[532]79          $ret = '';
[534]80
[2773]81          if (!(boolean) $core->blog->settings->system->simpleMenu_active)
82               return $ret;
83
[3159]84          $menu = $core->blog->settings->system->simpleMenu;
[2566]85          if (is_array($menu))
[534]86          {
87               // Current relative URL
88               $url = $_SERVER['REQUEST_URI'];
89               $abs_url = http::getHost().$url;
[2566]90
[534]91               // Home recognition var
[3159]92               $home_url = html::stripHostURL($core->blog->url);
[534]93               $home_directory = dirname($home_url);
94               if ($home_directory != '/')
95                    $home_directory = $home_directory.'/';
[532]96
[534]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);
102
[3583]103                    $targetBlank = ((isset($m['targetBlank'])) && ($m['targetBlank']))? true:false;
[3600]104
[534]105                    # Active item test
106                    $active = false;
[2566]107                    if (($url == $href) ||
108                         ($abs_url == $href) ||
109                         ($_SERVER['URL_REQUEST_PART'] == $href) ||
[534]110                         (($_SERVER['URL_REQUEST_PART'] == '') && (($href == $home_url) || ($href == $home_directory)))) {
111                         $active = true;
112                    }
[566]113                    $title = $span = '';
[3600]114
[566]115                    if ($m['descr']) {
[3583]116                         if (($description == 'title' || $description == 'both') && $targetBlank) {
117                              $title = ' title="'.html::escapeHTML(__($m['descr'])).' ('.
118                              __("the link will open a new window").')"';
119                         }elseif($description == 'title' || $description == 'both'){
[2576]120                              $title = ' title="'.html::escapeHTML(__($m['descr'])).'"';
[2928]121                         }
122                         if ($description == 'span' || $description == 'both') {
[3427]123                              $span = ' <span class="simple-menu-descr">'.html::escapeHTML(__($m['descr'])).'</span>';
[566]124                         }
125                    }
[3600]126
[3583]127                    if( empty($title) && $targetBlank){
128                         $title = ' title="'.__("the link will open a new window").'"';
129                    }
[3600]130
[2576]131                    $label = html::escapeHTML(__($m['label']));
[1062]132
133                    $item = new ArrayObject(array(
134                         'url' => $href,                         // URL
[2576]135                         'label' => $label,                 // <a> link label
[1062]136                         'title' => $title,                 // <a> link title (optional)
137                         'span' => $span,                   // description (will be displayed after <a> link)
138                         'active' => $active,               // status (true/false)
139                         'class' => ''                      // additional <li> class (optional)
140                         ));
141
142                    # --BEHAVIOR-- publicSimpleMenuItem
143                    $core->callBehavior('publicSimpleMenuItem',$i,$item);
144
[538]145                    $ret .= '<li class="li'.($i+1).
[1062]146                                   ($item['active'] ? ' active' : '').
[538]147                                   ($i == 0 ? ' li-first' : '').
148                                   ($i == count($menu)-1 ? ' li-last' : '').
[1062]149                                   ($item['class'] ? $item['class'] : '').
[538]150                              '">'.
[3578]151                              '<a href="'.$href.'"'.$item['title'].
[3600]152                              (($targetBlank) ? 'target="_blank" rel="noopener noreferrer"': '').'>'.
[3427]153                              '<span class="simple-menu-label">'.$item['label'].'</span>'.
154                              $item['span'].'</a>'.
[534]155                              '</li>';
156               }
157               // Final rendering
158               if ($ret) {
[3019]159                    $ret = '<nav role="navigation"><ul '.($id ? 'id="'.$id.'"' : '').' class="simple-menu'.($class ? ' '.$class : '').'">'."\n".$ret."\n".'</ul></nav>';
[534]160               }
[532]161          }
[534]162
[532]163          return $ret;
164     }
165}
Note: See TracBrowser for help on using the repository browser.

Sites map