Dotclear

source: inc/admin/lib.dc.page.php @ 3086:743fb080a422

Revision 3086:743fb080a422, 30.2 KB checked in by franck <carnet.franck.paul@…>, 10 years ago (diff)

Let the opportunity to the module to specify their own version (rather than Dotclear version) for CSS or Js load statement in <head>.

RevLine 
[0]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
[0]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
14define('DC_AUTH_PAGE','auth.php');
15
16class dcPage
17{
[2503]18     private static $loaded_js = array();
[3021]19     private static $loaded_css = array();
[2909]20     private static $xframe_loaded = false;
[2328]21     private static $N_TYPES = array(
[2503]22          "success" => "success",
23          "warning" => "warning-msg",
24          "error" => "error",
25          "message" => "message",
[2328]26          "static" => "static-msg");
[342]27
[0]28     # Auth check
29     public static function check($permissions)
30     {
31          global $core;
[1187]32
[2503]33          if ($core->blog && $core->auth->check($permissions,$core->blog->id)) {
[0]34               return;
35          }
[1187]36
[0]37          if (session_id()) {
38               $core->session->destroy();
39          }
40          http::redirect(DC_AUTH_PAGE);
41     }
[1187]42
[0]43     # Check super admin
44     public static function checkSuper()
45     {
46          global $core;
[1187]47
[0]48          if (!$core->auth->isSuperAdmin())
49          {
50               if (session_id()) {
51                    $core->session->destroy();
52               }
53               http::redirect(DC_AUTH_PAGE);
54          }
55     }
[1187]56
[0]57     # Top of admin page
[2907]58     public static function open($title='',$head='',$breadcrumb='',$options=array())
[0]59     {
60          global $core;
[1144]61
[0]62          # List of user's blogs
[2159]63          if ($core->auth->getBlogCount() == 1 || $core->auth->getBlogCount() > 20)
[0]64          {
65               $blog_box =
[999]66               '<p>'.__('Blog:').' <strong title="'.html::escapeHTML($core->blog->url).'">'.
[0]67               html::escapeHTML($core->blog->name).'</strong>';
[1187]68
[2159]69               if ($core->auth->getBlogCount() > 20) {
[2720]70                    $blog_box .= ' - <a href="'.$core->adminurl->get("admin.blogs").'">'.__('Change blog').'</a>';
[0]71               }
[999]72               $blog_box .= '</p>';
[0]73          }
74          else
75          {
76               $rs_blogs = $core->getBlogs(array('order'=>'LOWER(blog_name)','limit'=>20));
77               $blogs = array();
78               while ($rs_blogs->fetch()) {
79                    $blogs[html::escapeHTML($rs_blogs->blog_name.' - '.$rs_blogs->blog_url)] = $rs_blogs->blog_id;
80               }
81               $blog_box =
[2005]82               '<p><label for="switchblog" class="classic">'.
[1309]83               __('Blogs:').'</label> '.
[0]84               $core->formNonce().
[454]85               form::combo('switchblog',$blogs,$core->blog->id).
[2005]86               '<input type="submit" value="'.__('ok').'" class="hidden-if-js" /></p>';
[0]87          }
[1187]88
[36]89          $safe_mode = isset($_SESSION['sess_safe_mode']) && $_SESSION['sess_safe_mode'];
[1187]90
[0]91          # Display
92          header('Content-Type: text/html; charset=UTF-8');
[2792]93
94          // Prevents Clickjacking as far as possible
[2907]95          if (isset($options['x-frame-allow'])) {
[2909]96               self::setXFrameOptions($options['x-frame-allow']);
[2907]97          } else {
[2909]98               self::setXFrameOptions();
[2907]99          }
[0]100          echo
[2760]101          '<!DOCTYPE html>'.
102          '<html lang="'.$core->auth->getInfo('user_lang').'">'."\n".
[0]103          "<head>\n".
[2760]104          '  <meta charset="UTF-8" />'."\n".
[0]105          '  <meta name="ROBOTS" content="NOARCHIVE,NOINDEX,NOFOLLOW" />'."\n".
106          '  <meta name="GOOGLEBOT" content="NOSNIPPET" />'."\n".
[1310]107          '  <meta name="viewport" content="width=device-width, initial-scale=1.0" />'."\n".
[489]108          '  <title>'.$title.' - '.html::escapeHTML($core->blog->name).' - '.html::escapeHTML(DC_VENDOR_NAME).' - '.DC_VERSION.'</title>'."\n".
[1187]109
110
[0]111          self::jsLoadIE7().
[3021]112          self::cssLoad('style/default.css');
[0]113          if (l10n::getTextDirection($GLOBALS['_lang']) == 'rtl') {
[3021]114               echo self::cssLoad('style/default-rtl.css');
[0]115          }
[237]116
[244]117          $core->auth->user_prefs->addWorkspace('interface');
118          $user_ui_hide_std_favicon = $core->auth->user_prefs->interface->hide_std_favicon;
119          if (!$user_ui_hide_std_favicon) {
[2503]120               echo
[3021]121               '<link rel="icon" type="image/png" href="images/favicon96-login.png" />'."\n".
122               '<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />'."\n";
[244]123          }
[0]124          echo
125          self::jsCommon().
[1699]126          self::jsToggles().
[0]127          $head;
[1187]128
[0]129          # --BEHAVIOR-- adminPageHTMLHead
130          $core->callBehavior('adminPageHTMLHead');
[1187]131
[0]132          echo
133          "</head>\n".
[36]134          '<body id="dotclear-admin'.
[1586]135          ($safe_mode ? ' safe-mode' : '').'" class="no-js">'."\n".
[1187]136
[1590]137          '<ul id="prelude">'.
138          '<li><a href="#content">'.__('Go to the content').'</a></li>'.
139          '<li><a href="#main-menu">'.__('Go to the menu').'</a></li>'.
140          '<li><a href="#qx">'.__('Go to search').'</a></li>'.
[2304]141          '<li><a href="#help">'.__('Go to help').'</a></li>'.
[1590]142          '</ul>'."\n".
[2784]143          '<div id="header" role="banner">'.
[2720]144          '<h1><a href="'.$core->adminurl->get("admin.home").'"><span class="hidden">'.DC_VENDOR_NAME.'</span></a></h1>'."\n";
[1187]145
[0]146          echo
[2720]147          '<form action="'.$core->adminurl->get("admin.home").'" method="post" id="top-info-blog">'.
[0]148          $blog_box.
[2225]149          '<p><a href="'.$core->blog->url.'" class="outgoing" title="'.__('Go to site').
150          '">'.__('Go to site').'<img src="images/outgoing.png" alt="" /></a>'.
[999]151          '</p></form>'.
[2005]152          '<ul id="top-info-user">'.
[2817]153          '<li><a class="'.(preg_match('/'.preg_quote($core->adminurl->get('admin.home')).'$/',$_SERVER['REQUEST_URI']) ? ' active' : '').'" href="'.$core->adminurl->get("admin.home").'">'.__('My dashboard').'</a></li>'.
154          '<li><a class="smallscreen'.(preg_match('/'.preg_quote($core->adminurl->get('admin.user.preferences')).'(\?.*)?$/',$_SERVER['REQUEST_URI']) ? ' active' : '').
[2720]155          '" href="'.$core->adminurl->get("admin.user.preferences").'">'.__('My preferences').'</a></li>'.
156          '<li><a href="'.$core->adminurl->get("admin.home",array('logout' => 1)).'" class="logout"><span class="nomobile">'.sprintf(__('Logout %s'),$core->auth->userID()).
[2034]157          '</span><img src="images/logout.png" alt="" /></a></li>'.
[2005]158          '</ul>'.
159          '</div>'; // end header
[1187]160
[0]161          echo
[1741]162          '<div id="wrapper" class="clearfix">'."\n".
[1946]163          '<div class="hidden-if-no-js collapser-box"><a href="#" id="collapser">'.
[1867]164          '<img class="collapse-mm" src="images/collapser-hide.png" alt="'.__('Hide main menu').'" />'.
165          '<img class="expand-mm" src="images/collapser-show.png" alt="'.__('Show main menu').'" />'.
166          '</a></div>'.
[2784]167          '<div id="main" role="main">'."\n".
[1741]168          '<div id="content" class="clearfix">'."\n";
[1187]169
[36]170          # Safe mode
171          if ($safe_mode)
[0]172          {
173               echo
[2787]174               '<div class="warning" role="alert"><h3>'.__('Safe mode').'</h3>'.
[37]175               '<p>'.__('You are in safe mode. All plugins have been temporarily disabled. Remind to log out then log in again normally to get back all functionalities').'</p>'.
[0]176               '</div>';
177          }
[1187]178
[3076]179          // Display breadcrumb (if given) before any error messages
[1357]180          echo $breadcrumb;
[1355]181
[3076]182          // Display notices and errors
[2199]183          echo self::notices();
184     }
185
186     public static function notices()
187     {
[3076]188          global $core;
189          static $error_displayed = false;
190          $res = '';
191
192          // return error messages if any
193          if ($core->error->flag() && !$error_displayed) {
194               $res .= '<div class="error"><p><strong>'.(count($core->error->getErrors()) > 1 ? __('Errors:') : __('Error:')).'</strong></p>'.
195               $core->error->toHTML().
196               '</div>';
197               $error_displayed = true;
198          }
199
[2199]200          // return notices if any
[2181]201          if (isset($_SESSION['notifications'])) {
[2328]202               foreach ($_SESSION['notifications'] as $notification) {
203                    $res .= self::getNotification($notification);
[2181]204               }
205               unset($_SESSION['notifications']);
206          }
[2199]207          return $res;
[0]208     }
[2191]209
[2328]210     public static function addNotice($type,$message,$options=array())
[2191]211     {
[2328]212          if (isset(self::$N_TYPES[$type])){
213               $class = self::$N_TYPES[$type];
214          } else {
215               $class=$type;
216          }
217          if (isset($_SESSION['notifications']) && is_array($_SESSION['notifications'])) {
218               $notifications = $_SESSION['notifications'];
219          } else {
220               $notifications = array();
221          }
[2503]222
[2328]223          $n = array_merge($options,array('class' => $class,'ts' => time(), 'text' => $message));
224          if ($type != "static") {
225               $notifications[] = $n;
226          } else {
227               array_unshift($notifications, $n);
228          }
229          $_SESSION['notifications'] = $notifications;
[2181]230     }
[2191]231
[2328]232     public static function addSuccessNotice($message,$options=array())
[2191]233     {
[2328]234          self::addNotice("success",$message,$options);
[2181]235     }
[2191]236
[2328]237     public static function addWarningNotice($message,$options=array())
[2191]238     {
[2328]239          self::addNotice("warning",$message,$options);
[2181]240     }
[2191]241
[2328]242     public static function addErrorNotice($message,$options=array())
[2191]243     {
[2328]244          self::addNotice("error",$message,$options);
[2191]245     }
246
[2328]247     protected static function getNotification($n)
[2191]248     {
[2181]249          global $core;
[2328]250          $tag = (isset($n['divtag'])&& $n['divtag'])?'div':'p';
251          $ts = '';
252          if (!isset($n['with_ts']) || ($n['with_ts'] == true)) {
253               $ts = dt::str(__('[%H:%M:%S]'),$n['ts'],$core->auth->getInfo('user_tz')).' ';
254          }
[2787]255          $res = '<'.$tag.' class="'.$n['class'].'" role="alert">'.$ts.$n['text'].'</'.$tag.'>';
[2191]256          return $res;
[2181]257     }
[2191]258
[0]259     public static function close()
260     {
[942]261          global $core;
262
[1933]263          if (!$GLOBALS['__resources']['ctxhelp']) {
264               echo
[2720]265               '<p id="help-button"><a href="'.$core->adminurl->get("admin.help").'" class="outgoing" title="'.
[2306]266               __('Global help').'">'.__('Global help').'</a></p>';
[1933]267          }
268
[0]269          $menu =& $GLOBALS['_menu'];
[1187]270
[0]271          echo
272          "</div>\n".         // End of #content
273          "</div>\n".         // End of #main
[1187]274
[2784]275          '<div id="main-menu" role="navigation">'."\n".
[1311]276
[2769]277          '<form id="search-menu" action="'.$core->adminurl->get("admin.search").'" method="get" role="search">'.
[1589]278          '<p><label for="qx" class="hidden">'.__('Search:').' </label>'.form::field('qx',30,255,'').
[1311]279          '<input type="submit" value="'.__('OK').'" /></p>'.
280          '</form>';
[1187]281
[0]282          foreach ($menu as $k => $v) {
283               echo $menu[$k]->draw();
284          }
[1187]285
[1140]286          $text = sprintf(__('Thank you for using %s.'),'Dotclear '.DC_VERSION);
[942]287
288          # --BEHAVIOR-- adminPageFooter
[946]289          $textAlt = $core->callBehavior('adminPageFooter',$core,$text);
[1140]290          if ($textAlt != '') {
291               $text = $textAlt;
292          }
[1142]293          $text = html::escapeHTML($text);
[942]294
[0]295          echo
296          '</div>'."\n".      // End of #main-menu
[1946]297          "</div>\n";         // End of #wrapper
[1861]298
[3060]299          $figure = "
300    @..@
301   (----)
302  ( >__< )
303  ^^ ~~ ^^
304          ";
305
[1946]306          echo
[2784]307          '<div id="footer" role="contentinfo">'.
[2296]308          '<a href="http://dotclear.org/" title="'.$text.'">'.
309          '<img src="style/dc_logos/w-dotclear90.png" alt="'.$text.'" /></a></div>'."\n".
[2796]310          "<!-- "."\n".
[3060]311          $figure.
[2796]312          " -->"."\n";
[1187]313
[0]314          if (defined('DC_DEV') && DC_DEV === true) {
315               echo self::debugInfo();
316          }
[1187]317
[0]318          echo
319          '</body></html>';
320     }
[1187]321
[1358]322     public static function openPopup($title='',$head='',$breadcrumb='')
[0]323     {
324          global $core;
[1187]325
[0]326          # Display
327          header('Content-Type: text/html; charset=UTF-8');
[2792]328
329          // Prevents Clickjacking as far as possible
330          header('X-Frame-Options: SAMEORIGIN'); // FF 3.6.9+ Chrome 4.1+ IE 8+ Safari 4+ Opera 10.5+
331
[0]332          echo
[2760]333          '<!DOCTYPE html>'.
334          '<html lang="'.$core->auth->getInfo('user_lang').'">'."\n".
[0]335          "<head>\n".
[2760]336          '  <meta charset="UTF-8" />'."\n".
[2513]337          '  <meta name="viewport" content="width=device-width, initial-scale=1.0" />'."\n".
[0]338          '  <title>'.$title.' - '.html::escapeHTML($core->blog->name).' - '.html::escapeHTML(DC_VENDOR_NAME).' - '.DC_VERSION.'</title>'."\n".
[1187]339
[0]340          '  <meta name="ROBOTS" content="NOARCHIVE,NOINDEX,NOFOLLOW" />'."\n".
341          '  <meta name="GOOGLEBOT" content="NOSNIPPET" />'."\n".
[1187]342
[0]343          self::jsLoadIE7().
[3021]344          self::cssLoad('style/default.css');
[0]345          if (l10n::getTextDirection($GLOBALS['_lang']) == 'rtl') {
[3021]346               echo self::cssLoad('style/default-rtl.css');
[0]347          }
[1187]348
[0]349          echo
350          self::jsCommon().
[1699]351          self::jsToggles().
[0]352          $head;
[1187]353
[0]354          # --BEHAVIOR-- adminPageHTMLHead
355          $core->callBehavior('adminPageHTMLHead');
[1187]356
[0]357          echo
358          "</head>\n".
359          '<body id="dotclear-admin" class="popup">'."\n".
[1187]360
[2046]361          '<h1>'.DC_VENDOR_NAME.'</h1>'."\n";
[1187]362
[0]363          echo
364          '<div id="wrapper">'."\n".
[2784]365          '<div id="main" role="main">'."\n".
[0]366          '<div id="content">'."\n";
[1187]367
[1358]368          // display breadcrumb if given
369          echo $breadcrumb;
370
[3076]371          // Display notices and errors
372          echo self::notices();
[0]373     }
[1187]374
[0]375     public static function closePopup()
376     {
377          echo
378          "</div>\n".         // End of #content
379          "</div>\n".         // End of #main
[2046]380          "</div>\n".         // End of #wrapper
[2784]381          '<div id="footer" role="contentinfo"><p>&nbsp;</p></div>'."\n".
[0]382          '</body></html>';
383     }
[907]384
[2166]385     public static function breadcrumb($elements=null,$options=array())
[1328]386     {
[2720]387          global $core;
[2166]388          $with_home_link = isset($options['home_link'])?$options['home_link']:true;
[2167]389          $hl = isset($options['hl'])?$options['hl']:true;
390          $hl_pos = isset($options['hl_pos'])?$options['hl_pos']:-1;
[1328]391          // First item of array elements should be blog's name, System or Plugins
[1340]392          $res = '<h2>'.($with_home_link ?
[2720]393               '<a class="go_home" href="'.$core->adminurl->get("admin.home").'"><img src="style/dashboard.png" alt="'.__('Go to dashboard').'" /></a>' :
[1340]394               '<img src="style/dashboard-alt.png" alt="" />');
[1328]395          $index = 0;
[2167]396          if ($hl_pos < 0) {
397               $hl_pos = count($elements)+$hl_pos;
[2166]398          }
[1328]399          foreach ($elements as $element => $url) {
[2167]400               if ($hl && $index == $hl_pos) {
[2166]401                    $element = sprintf('<span class="page-title">%s</span>',$element);
402               }
[1358]403               $res .= ($with_home_link ? ($index == 1 ? ' : ' : ' &rsaquo; ') : ($index == 0 ? ' ' : ' &rsaquo; ')).
404                    ($url ? '<a href="'.$url.'">' : '').$element.($url ? '</a>' : '');
[1328]405               $index++;
406          }
407          $res .= '</h2>';
408          return $res;
409     }
410
[1548]411     public static function message($msg,$timestamp=true,$div=false,$echo=true,$class='message')
[907]412     {
[910]413          global $core;
[1187]414
[907]415          $res = '';
416          if ($msg != '') {
[1548]417               $res = ($div ? '<div class="'.$class.'">' : '').'<p'.($div ? '' : ' class="'.$class.'"').'>'.
[2191]418               ($timestamp ? dt::str(__('[%H:%M:%S]'),null,$core->auth->getInfo('user_tz')).' ' : '').$msg.
[1161]419               '</p>'.($div ? '</div>' : '');
[907]420               if ($echo) {
421                    echo $res;
422               }
423          }
424          return $res;
425     }
[1187]426
[1548]427     public static function success($msg,$timestamp=true,$div=false,$echo=true)
428     {
[1927]429          return self::message($msg,$timestamp,$div,$echo,"success");
[1548]430     }
431
[1725]432     public static function warning($msg,$timestamp=true,$div=false,$echo=true)
433     {
[1927]434          return self::message($msg,$timestamp,$div,$echo,"warning-msg");
[1725]435     }
436
[0]437     private static function debugInfo()
438     {
439          $global_vars = implode(', ',array_keys($GLOBALS));
[1187]440
[0]441          $res =
442          '<div id="debug"><div>'.
443          '<p>memory usage: '.memory_get_usage().' ('.files::size(memory_get_usage()).')</p>';
[1187]444
[0]445          if (function_exists('xdebug_get_profiler_filename'))
446          {
447               $res .= '<p>Elapsed time: '.xdebug_time_index().' seconds</p>';
[1187]448
[0]449               $prof_file = xdebug_get_profiler_filename();
450               if ($prof_file) {
451                    $res .= '<p>Profiler file : '.xdebug_get_profiler_filename().'</p>';
452               } else {
453                    $prof_url = http::getSelfURI();
[321]454                    $prof_url .= (strpos($prof_url,'?') === false) ? '?' : '&';
[0]455                    $prof_url .= 'XDEBUG_PROFILE';
[321]456                    $res .= '<p><a href="'.html::escapeURL($prof_url).'">Trigger profiler</a></p>';
[0]457               }
[1187]458
[0]459               /* xdebug configuration:
460               zend_extension = /.../xdebug.so
461               xdebug.auto_trace = On
462               xdebug.trace_format = 0
463               xdebug.trace_options = 1
464               xdebug.show_mem_delta = On
465               xdebug.profiler_enable = 0
466               xdebug.profiler_enable_trigger = 1
467               xdebug.profiler_output_dir = /tmp
468               xdebug.profiler_append = 0
469               xdebug.profiler_output_name = timestamp
470               */
471          }
[1187]472
[0]473          $res .=
474          '<p>Global vars: '.$global_vars.'</p>'.
475          '</div></div>';
[1187]476
[0]477          return $res;
478     }
[1187]479
[0]480     public static function help($page,$index='')
481     {
482          # Deprecated but we keep this for plugins.
483     }
[1187]484
[0]485     public static function helpBlock()
486     {
[2720]487          global $core;
[0]488          $args = func_get_args();
[1458]489
490          $args = new ArrayObject($args);
491
492          # --BEHAVIOR-- adminPageHelpBlock
493          $GLOBALS['core']->callBehavior('adminPageHelpBlock',$args);
494
[0]495          if (empty($args)) {
496               return;
497          };
[1187]498
[0]499          global $__resources;
500          if (empty($__resources['help'])) {
501               return;
502          }
[1187]503
[0]504          $content = '';
505          foreach ($args as $v)
506          {
507               if (is_object($v) && isset($v->content)) {
508                    $content .= $v->content;
509                    continue;
510               }
[1187]511
[0]512               if (!isset($__resources['help'][$v])) {
513                    continue;
514               }
515               $f = $__resources['help'][$v];
516               if (!file_exists($f) || !is_readable($f)) {
517                    continue;
518               }
[1187]519
[0]520               $fc = file_get_contents($f);
521               if (preg_match('|<body[^>]*?>(.*?)</body>|ms',$fc,$matches)) {
522                    $content .= $matches[1];
523               } else {
524                    $content .= $fc;
525               }
526          }
[1187]527
[0]528          if (trim($content) == '') {
529               return;
530          }
[1187]531
[1933]532          // Set contextual help global flag
533          $GLOBALS['__resources']['ctxhelp'] = true;
534
[0]535          echo
[1573]536          '<div id="help"><hr /><div class="help-content clear"><h3>'.__('Help about this page').'</h3>'.
[0]537          $content.
[494]538          '</div>'.
539          '<div id="helplink"><hr />'.
540          '<p>'.
[2720]541          sprintf(__('See also %s'),sprintf('<a href="'.$core->adminurl->get("admin.help").'">%s</a>',__('the global help'))).
[2011]542          '.</p>'.
[0]543          '</div></div>';
544     }
[1187]545
[3086]546     public static function cssLoad($src,$media='screen',$v='')
[3021]547     {
548          $escaped_src = html::escapeHTML($src);
549          if (!isset(self::$loaded_css[$escaped_src])) {
550               self::$loaded_css[$escaped_src] = true;
[3086]551               $escaped_src = self::appendVersion($escaped_src,$v);
[3021]552
553               return '<link rel="stylesheet" href="'.$escaped_src.'" type="text/css" media="'.$media.'" />'."\n";
554          }
555     }
556
[3086]557     public static function jsLoad($src,$v='')
[0]558     {
[342]559          $escaped_src = html::escapeHTML($src);
560          if (!isset(self::$loaded_js[$escaped_src])) {
[3020]561               self::$loaded_js[$escaped_src] = true;
[3086]562               $escaped_src = self::appendVersion($escaped_src,$v);
[342]563               return '<script type="text/javascript" src="'.$escaped_src.'"></script>'."\n";
564          }
[0]565     }
[1187]566
[3086]567     private static function appendVersion($src,$v='')
[3021]568     {
[3086]569          $src .= (strpos($src,'?') === false ? '?' : '&').'v=';
[3021]570          if (defined('DC_DEV') && DC_DEV === true) {
571               $src .= md5(uniqid());
572          } else {
[3086]573               $src .= ($v === '' ? DC_VERSION : $v);
[3021]574          }
575          return $src;
576     }
577
[0]578     public static function jsVar($n,$v)
579     {
580          return $n." = '".html::escapeJS($v)."';\n";
581     }
[1187]582
[1699]583     public static function jsToggles()
584     {
585          if($GLOBALS['core']->auth->user_prefs->toggles) {
586               $unfolded_sections = explode(',',$GLOBALS['core']->auth->user_prefs->toggles->unfolded_sections);
587               foreach ($unfolded_sections as $k=>&$v) {
588                    if ($v == '') {
589                         unset($unfolded_sections[$k]);
590                    } else {
591                         $v = "'".html::escapeJS($v)."':true";
592                    }
593               }
594          } else {
595               $unfolded_sections=array();
596          }
597          return '<script type="text/javascript">'."\n".
598                         "//<![CDATA[\n".
599                         'dotclear.unfolded_sections = {'.join(",",$unfolded_sections)."};\n".
600                         "\n//]]>\n".
601                    "</script>\n";
602     }
[2503]603
[0]604     public static function jsCommon()
605     {
[1771]606          $mute_or_no = '';
[1841]607          if (empty($GLOBALS['core']->blog) || $GLOBALS['core']->blog->settings->system->jquery_migrate_mute) {
[1771]608               $mute_or_no .=
609                    '<script type="text/javascript">'."\n".
610                    "//<![CDATA[\n".
611                    'jQuery.migrateMute = true;'.
612                    "\n//]]>\n".
613                    "</script>\n";
614          }
615
[0]616          return
617          self::jsLoad('js/jquery/jquery.js').
[1771]618          $mute_or_no.
619          self::jsLoad('js/jquery/jquery-migrate-1.2.1.js').
[0]620          self::jsLoad('js/jquery/jquery.biscuit.js').
621          self::jsLoad('js/jquery/jquery.bgFade.js').
622          self::jsLoad('js/common.js').
[447]623          self::jsLoad('js/prelude.js').
[1187]624
[0]625          '<script type="text/javascript">'."\n".
626          "//<![CDATA[\n".
[2614]627          'jsToolBar = {}, jsToolBar.prototype = { elements : {} };'."\n".
[0]628          self::jsVar('dotclear.nonce',$GLOBALS['core']->getNonce()).
[1019]629          self::jsVar('dotclear.img_plus_src','images/expand.png').
[0]630          self::jsVar('dotclear.img_plus_alt',__('uncover')).
[1019]631          self::jsVar('dotclear.img_minus_src','images/hide.png').
[0]632          self::jsVar('dotclear.img_minus_alt',__('hide')).
633          self::jsVar('dotclear.img_menu_on','images/menu_on.png').
634          self::jsVar('dotclear.img_menu_off','images/menu_off.png').
[2503]635
[2195]636          self::jsVar('dotclear.img_plus_theme_src','images/plus-theme.png').
637          self::jsVar('dotclear.img_plus_theme_alt',__('uncover')).
638          self::jsVar('dotclear.img_minus_theme_src','images/minus-theme.png').
639          self::jsVar('dotclear.img_minus_theme_alt',__('hide')).
[1187]640
[0]641          self::jsVar('dotclear.msg.help',
[1933]642               __('Need help?')).
[2225]643          self::jsVar('dotclear.msg.new_window',
644               __('new window')).
[1302]645          self::jsVar('dotclear.msg.help_hide',
646               __('Hide')).
[1556]647          self::jsVar('dotclear.msg.to_select',
648               __('Select:')).
[0]649          self::jsVar('dotclear.msg.no_selection',
650               __('no selection')).
651          self::jsVar('dotclear.msg.select_all',
652               __('select all')).
653          self::jsVar('dotclear.msg.invert_sel',
[1556]654               __('Invert selection')).
[0]655          self::jsVar('dotclear.msg.website',
656               __('Web site:')).
657          self::jsVar('dotclear.msg.email',
658               __('Email:')).
659          self::jsVar('dotclear.msg.ip_address',
660               __('IP address:')).
661          self::jsVar('dotclear.msg.error',
662               __('Error:')).
663          self::jsVar('dotclear.msg.entry_created',
664               __('Entry has been successfully created.')).
665          self::jsVar('dotclear.msg.edit_entry',
666               __('Edit entry')).
667          self::jsVar('dotclear.msg.view_entry',
668               __('view entry')).
669          self::jsVar('dotclear.msg.confirm_delete_posts',
670               __("Are you sure you want to delete selected entries (%s)?")).
[2202]671          self::jsVar('dotclear.msg.confirm_delete_medias',
672               __("Are you sure you want to delete selected medias (%d)?")).
[1525]673          self::jsVar('dotclear.msg.confirm_delete_categories',
674               __("Are you sure you want to delete selected categories (%s)?")).
[0]675          self::jsVar('dotclear.msg.confirm_delete_post',
676               __("Are you sure you want to delete this entry?")).
[1395]677          self::jsVar('dotclear.msg.click_to_unlock',
[1450]678               __("Click here to unlock the field")).
[1049]679          self::jsVar('dotclear.msg.confirm_spam_delete',
680               __('Are you sure you want to delete all spams?')).
[0]681          self::jsVar('dotclear.msg.confirm_delete_comments',
682               __('Are you sure you want to delete selected comments (%s)?')).
683          self::jsVar('dotclear.msg.confirm_delete_comment',
684               __('Are you sure you want to delete this comment?')).
685          self::jsVar('dotclear.msg.cannot_delete_users',
686               __('Users with posts cannot be deleted.')).
687          self::jsVar('dotclear.msg.confirm_delete_user',
688               __('Are you sure you want to delete selected users (%s)?')).
689          self::jsVar('dotclear.msg.confirm_delete_category',
690               __('Are you sure you want to delete category "%s"?')).
691          self::jsVar('dotclear.msg.confirm_reorder_categories',
692               __('Are you sure you want to reorder all categories?')).
693          self::jsVar('dotclear.msg.confirm_delete_media',
694               __('Are you sure you want to remove media "%s"?')).
[2512]695          self::jsVar('dotclear.msg.confirm_delete_directory',
696               __('Are you sure you want to remove directory "%s"?')).
[0]697          self::jsVar('dotclear.msg.confirm_extract_current',
698               __('Are you sure you want to extract archive in current directory?')).
699          self::jsVar('dotclear.msg.confirm_remove_attachment',
700               __('Are you sure you want to remove attachment "%s"?')).
701          self::jsVar('dotclear.msg.confirm_delete_lang',
702               __('Are you sure you want to delete "%s" language?')).
703          self::jsVar('dotclear.msg.confirm_delete_plugin',
704               __('Are you sure you want to delete "%s" plugin?')).
[2487]705          self::jsVar('dotclear.msg.confirm_delete_plugins',
706               __('Are you sure you want to delete selected plugins?')).
[0]707          self::jsVar('dotclear.msg.use_this_theme',
708               __('Use this theme')).
709          self::jsVar('dotclear.msg.remove_this_theme',
710               __('Remove this theme')).
711          self::jsVar('dotclear.msg.confirm_delete_theme',
712               __('Are you sure you want to delete "%s" theme?')).
[2487]713          self::jsVar('dotclear.msg.confirm_delete_themes',
714               __('Are you sure you want to delete selected themes?')).
[1462]715          self::jsVar('dotclear.msg.confirm_delete_backup',
716               __('Are you sure you want to delete this backup?')).
[2503]717          self::jsVar('dotclear.msg.confirm_revert_backup',
718               __('Are you sure you want to revert to this backup?')).
[0]719          self::jsVar('dotclear.msg.zip_file_content',
720               __('Zip file content')).
721          self::jsVar('dotclear.msg.xhtml_validator',
722               __('XHTML markup validator')).
723          self::jsVar('dotclear.msg.xhtml_valid',
724               __('XHTML content is valid.')).
725          self::jsVar('dotclear.msg.xhtml_not_valid',
726               __('There are XHTML markup errors.')).
[1861]727          self::jsVar('dotclear.msg.warning_validate_no_save_content',
[1832]728               __('Attention: an audit of a content not yet registered.')).
[0]729          self::jsVar('dotclear.msg.confirm_change_post_format',
730               __('You have unsaved changes. Switch post format will loose these changes. Proceed anyway?')).
[1256]731          self::jsVar('dotclear.msg.confirm_change_post_format_noconvert',
732               __("Warning: post format change will not convert existing content. You will need to apply new format by yourself. Proceed anyway?")).
[224]733          self::jsVar('dotclear.msg.load_enhanced_uploader',
734               __('Loading enhanced uploader, please wait.')).
[2156]735
736          self::jsVar('dotclear.msg.module_author',
737               __('Author:')).
738          self::jsVar('dotclear.msg.module_details',
739               __('Details')).
740          self::jsVar('dotclear.msg.module_support',
[2157]741               __('Support')).
[2156]742          self::jsVar('dotclear.msg.module_help',
[2157]743               __('Help:')).
[2156]744          self::jsVar('dotclear.msg.module_section',
745               __('Section:')).
746          self::jsVar('dotclear.msg.module_tags',
747               __('Tags:')).
[1699]748               "\n//]]>\n".
[0]749          "</script>\n";
750     }
[1187]751
[0]752     public static function jsLoadIE7()
753     {
754          return
[1456]755          '<!--[if lt IE 9]>'."\n".
756          self::jsLoad('js/ie7/IE9.js').
[3021]757          self::cssLoad('style/iesucks.css').
[0]758          '<![endif]-->'."\n";
759     }
[1187]760
[0]761     public static function jsConfirmClose()
762     {
763          $args = func_get_args();
764          if (count($args) > 0) {
765               foreach ($args as $k => $v) {
766                    $args[$k] = "'".html::escapeJS($v)."'";
767               }
768               $args = implode(',',$args);
769          } else {
770               $args = '';
771          }
[1187]772
[0]773          return
774          self::jsLoad('js/confirm-close.js').
775          '<script type="text/javascript">'."\n".
776          "//<![CDATA[\n".
777          "confirmClosePage = new confirmClose(".$args."); ".
778          "confirmClose.prototype.prompt = '".html::escapeJS(__('You have unsaved changes.'))."'; ".
779          "\n//]]>\n".
780          "</script>\n";
781     }
[1187]782
[0]783     public static function jsPageTabs($default=null)
784     {
785          if ($default) {
786               $default = "'".html::escapeJS($default)."'";
787          }
[2503]788
[0]789          return
790          self::jsLoad('js/jquery/jquery.pageTabs.js').
791          '<script type="text/javascript">'."\n".
792          "//<![CDATA[\n".
[2010]793          '$(function() {'."\n".
[2054]794          '$.pageTabs('.$default.');'."\n".
[2113]795          '});'.
[0]796          "\n//]]>\n".
[2113]797          "</script>\n".
798          '<!--[if lt IE 8]>'."\n".
799          self::jsLoad('js/ie7/ie7-hashchange.js').
800          '<script type="text/javascript">'."\n".
801          "//<![CDATA[\n".
802          '$(window).hashchange();'.
803          "\n//]]>\n".
804          "</script>\n".
805          '<![endif]-->'."\n";
[2010]806     }
[1161]807
[2202]808     public static function jsModal()
809     {
810          return
[3021]811          self::cssLoad('style/modal/modal.css').
[2202]812          self::jsLoad('js/jquery/jquery.modal.js').
813          '<script type="text/javascript">'."\n".
814          "//<![CDATA[\n".
815          self::jsVar('$.modal.prototype.params.loader_img','style/modal/loader.gif').
816          self::jsVar('$.modal.prototype.params.close_img','style/modal/close.png').
817          "\n//]]>\n".
818          "</script>\n";
[0]819     }
[1187]820
[2202]821     public static function jsColorPicker()
822     {
823          return
[3021]824          self::cssLoad('style/farbtastic/farbtastic.css').
[2202]825          self::jsLoad('js/jquery/jquery.farbtastic.js').
826          self::jsLoad('js/color-picker.js');
[0]827     }
[1187]828
[2202]829     public static function jsDatePicker()
830     {
831          return
[3021]832          self::cssLoad('style/date-picker.css').
[2202]833          self::jsLoad('js/date-picker.js').
834          '<script type="text/javascript">'."\n".
835          "//<![CDATA[\n".
[1187]836
[2202]837          "datePicker.prototype.months[0] = '".html::escapeJS(__('January'))."'; ".
838          "datePicker.prototype.months[1] = '".html::escapeJS(__('February'))."'; ".
839          "datePicker.prototype.months[2] = '".html::escapeJS(__('March'))."'; ".
840          "datePicker.prototype.months[3] = '".html::escapeJS(__('April'))."'; ".
841          "datePicker.prototype.months[4] = '".html::escapeJS(__('May'))."'; ".
842          "datePicker.prototype.months[5] = '".html::escapeJS(__('June'))."'; ".
843          "datePicker.prototype.months[6] = '".html::escapeJS(__('July'))."'; ".
844          "datePicker.prototype.months[7] = '".html::escapeJS(__('August'))."'; ".
845          "datePicker.prototype.months[8] = '".html::escapeJS(__('September'))."'; ".
846          "datePicker.prototype.months[9] = '".html::escapeJS(__('October'))."'; ".
847          "datePicker.prototype.months[10] = '".html::escapeJS(__('November'))."'; ".
848          "datePicker.prototype.months[11] = '".html::escapeJS(__('December'))."'; ".
[1161]849
[2202]850          "datePicker.prototype.days[0] = '".html::escapeJS(__('Monday'))."'; ".
851          "datePicker.prototype.days[1] = '".html::escapeJS(__('Tuesday'))."'; ".
852          "datePicker.prototype.days[2] = '".html::escapeJS(__('Wednesday'))."'; ".
853          "datePicker.prototype.days[3] = '".html::escapeJS(__('Thursday'))."'; ".
854          "datePicker.prototype.days[4] = '".html::escapeJS(__('Friday'))."'; ".
855          "datePicker.prototype.days[5] = '".html::escapeJS(__('Saturday'))."'; ".
856          "datePicker.prototype.days[6] = '".html::escapeJS(__('Sunday'))."'; ".
857
858          "datePicker.prototype.img_src = 'images/date-picker.png'; ".
[2788]859          "datePicker.prototype.img_alt = '".html::escapeJS(__('Choose date'))."'; ".
[2202]860
861          "datePicker.prototype.close_msg = '".html::escapeJS(__('close'))."'; ".
862          "datePicker.prototype.now_msg = '".html::escapeJS(__('now'))."'; ".
863
864          "\n//]]>\n".
865          "</script>\n";
[0]866     }
[1187]867
[2720]868
[2202]869     public static function jsToolBar()
870     {
[2614]871          # Deprecated but we keep this for plugins.
[2202]872     }
873
874     public static function jsUpload($params=array(),$base_url=null)
875     {
876          if (!$base_url) {
877               $base_url = path::clean(dirname(preg_replace('/(\?.*$)?/','',$_SERVER['REQUEST_URI']))).'/';
878          }
879
880          $params = array_merge($params,array(
881               'sess_id='.session_id(),
882               'sess_uid='.$_SESSION['sess_browser_uid'],
883               'xd_check='.$GLOBALS['core']->getNonce()
[0]884          ));
[1187]885
[2202]886          return
887          '<script type="text/javascript">'."\n".
888          "//<![CDATA[\n".
889          "dotclear.jsUpload = {};\n".
890          "dotclear.jsUpload.msg = {};\n".
891          self::jsVar('dotclear.msg.enhanced_uploader_activate',__('Temporarily activate enhanced uploader')).
892          self::jsVar('dotclear.msg.enhanced_uploader_disable',__('Temporarily disable enhanced uploader')).
893          self::jsVar('dotclear.jsUpload.msg.limit_exceeded',__('Limit exceeded.')).
894          self::jsVar('dotclear.jsUpload.msg.size_limit_exceeded',__('File size exceeds allowed limit.')).
895          self::jsVar('dotclear.jsUpload.msg.canceled',__('Canceled.')).
896          self::jsVar('dotclear.jsUpload.msg.http_error',__('HTTP Error:')).
897          self::jsVar('dotclear.jsUpload.msg.error',__('Error:')).
898          self::jsVar('dotclear.jsUpload.msg.choose_file',__('Choose file')).
899          self::jsVar('dotclear.jsUpload.msg.choose_files',__('Choose files')).
900          self::jsVar('dotclear.jsUpload.msg.cancel',__('Cancel')).
901          self::jsVar('dotclear.jsUpload.msg.clean',__('Clean')).
902          self::jsVar('dotclear.jsUpload.msg.upload',__('Upload')).
903          self::jsVar('dotclear.jsUpload.msg.send',__('Send')).
904          self::jsVar('dotclear.jsUpload.msg.file_successfully_uploaded',__('File successfully uploaded.')).
905          self::jsVar('dotclear.jsUpload.msg.no_file_in_queue',__('No file in queue.')).
906          self::jsVar('dotclear.jsUpload.msg.file_in_queue',__('1 file in queue.')).
907          self::jsVar('dotclear.jsUpload.msg.files_in_queue',__('%d files in queue.')).
908          self::jsVar('dotclear.jsUpload.msg.queue_error',__('Queue error:')).
909          self::jsVar('dotclear.jsUpload.base_url',$base_url).
910          "\n//]]>\n".
911          "</script>\n".
[1461]912
[2202]913          self::jsLoad('js/jsUpload/vendor/jquery.ui.widget.js').
914          self::jsLoad('js/jsUpload/tmpl.js').
915          self::jsLoad('js/jsUpload/template-upload.js').
916          self::jsLoad('js/jsUpload/template-download.js').
917          self::jsLoad('js/jsUpload/load-image.js').
918          self::jsLoad('js/jsUpload/jquery.iframe-transport.js').
919          self::jsLoad('js/jsUpload/jquery.fileupload.js').
920          self::jsLoad('js/jsUpload/jquery.fileupload-process.js').
921          self::jsLoad('js/jsUpload/jquery.fileupload-resize.js').
922          self::jsLoad('js/jsUpload/jquery.fileupload-ui.js');
923     }
[1144]924
[2202]925     public static function jsToolMan()
926     {
927          return
[3021]928          self::jsLoad('js/tool-man/core.js').
929          self::jsLoad('js/tool-man/events.js').
930          self::jsLoad('js/tool-man/css.js').
931          self::jsLoad('js/tool-man/coordinates.js').
932          self::jsLoad('js/tool-man/drag.js').
933          self::jsLoad('js/tool-man/dragsort.js').
934          self::jsLoad('js/dragsort-tablerows.js');
[2202]935     }
[1144]936
[2202]937     public static function jsMetaEditor()
938     {
[3021]939          return self::jsLoad('js/meta-editor.js');
[2202]940     }
[2849]941
[3080]942     public static function getPF($file)
943     {
[2852]944          return $GLOBALS['core']->adminurl->get('load.plugin.file',array('pf' => $file));
[2849]945     }
[2909]946
[3080]947     public static function setXFrameOptions($origin = null)
948     {
[2909]949          if (self::$xframe_loaded) {
950               return;
951          }
952          if ($origin !== null) {
953               $url = parse_url($origin);
[3080]954               header(sprintf('X-Frame-Options: %s',is_array($url) ?
955                    ("ALLOW-FROM ".(isset($url['scheme']) ? $url['scheme'].':' : '' ).'//'.$url['host']) :
956                    'SAMEORIGIN'));
[2909]957          } else {
958               header('X-Frame-Options: SAMEORIGIN'); // FF 3.6.9+ Chrome 4.1+ IE 8+ Safari 4+ Opera 10.5+
959          }
960          self::$xframe_loaded = true;
961     }
[489]962}
Note: See TracBrowser for help on using the repository browser.

Sites map