Dotclear

source: inc/admin/lib.dc.page.php @ 3566:9effe026362c

Revision 3566:9effe026362c, 36.2 KB checked in by franck <carnet.franck.paul@…>, 8 years ago (diff)

Add an option to hide the Help button

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
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{
18     private static $loaded_js = array();
19     private static $loaded_css = array();
20     private static $xframe_loaded = false;
21     private static $N_TYPES = array(
22          "success" => "success",
23          "warning" => "warning-msg",
24          "error" => "error",
25          "message" => "message",
26          "static" => "static-msg");
27
28     # Auth check
29     public static function check($permissions)
30     {
31          global $core;
32
33          if ($core->blog && $core->auth->check($permissions,$core->blog->id)) {
34               return;
35          }
36
37          if (session_id()) {
38               $core->session->destroy();
39          }
40          http::redirect(DC_AUTH_PAGE);
41     }
42
43     # Check super admin
44     public static function checkSuper()
45     {
46          global $core;
47
48          if (!$core->auth->isSuperAdmin())
49          {
50               if (session_id()) {
51                    $core->session->destroy();
52               }
53               http::redirect(DC_AUTH_PAGE);
54          }
55     }
56
57     # Top of admin page
58     public static function open($title='',$head='',$breadcrumb='',$options=array())
59     {
60          global $core;
61
62          # List of user's blogs
63          if ($core->auth->getBlogCount() == 1 || $core->auth->getBlogCount() > 20)
64          {
65               $blog_box =
66               '<p>'.__('Blog:').' <strong title="'.html::escapeHTML($core->blog->url).'">'.
67               html::escapeHTML($core->blog->name).'</strong>';
68
69               if ($core->auth->getBlogCount() > 20) {
70                    $blog_box .= ' - <a href="'.$core->adminurl->get("admin.blogs").'">'.__('Change blog').'</a>';
71               }
72               $blog_box .= '</p>';
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 =
82               '<p><label for="switchblog" class="classic">'.
83               __('Blogs:').'</label> '.
84               $core->formNonce().
85               form::combo('switchblog',$blogs,$core->blog->id).
86               '<input type="submit" value="'.__('ok').'" class="hidden-if-js" /></p>';
87          }
88
89          $safe_mode = isset($_SESSION['sess_safe_mode']) && $_SESSION['sess_safe_mode'];
90
91          # Display
92          $headers = new ArrayObject(array());
93
94          # Content-Type
95          $headers['content-type'] = 'Content-Type: text/html; charset=UTF-8';
96
97          # Prevents Clickjacking as far as possible
98          if (isset($options['x-frame-allow'])) {
99               self::setXFrameOptions($headers,$options['x-frame-allow']);
100          } else {
101               self::setXFrameOptions($headers);
102          }
103
104          # Content-Security-Policy (only if safe mode if not active, it may help)
105          if (!$safe_mode && $core->blog->settings->system->csp_admin_on) {
106               // Get directives from settings if exist, else set defaults
107               $csp = new ArrayObject(array());
108
109               // SQlite Clearbricks driver does not allow using single quote at beginning or end of a field value
110               // so we have to use neutral values (localhost and 127.0.0.1) for some CSP directives
111               $csp_prefix = $core->con->driver() == 'sqlite' ? 'localhost ' : '';   // Hack for SQlite Clearbricks driver
112               $csp_suffix = $core->con->driver() == 'sqlite' ? ' 127.0.0.1' : '';   // Hack for SQlite Clearbricks driver
113
114               $csp['default-src'] = $core->blog->settings->system->csp_admin_default ?:
115                    $csp_prefix."'self'".$csp_suffix;
116               $csp['script-src'] = $core->blog->settings->system->csp_admin_script ?:
117                    $csp_prefix."'self' 'unsafe-inline' 'unsafe-eval'".$csp_suffix;
118               $csp['style-src'] = $core->blog->settings->system->csp_admin_style ?:
119                    $csp_prefix."'self' 'unsafe-inline'".$csp_suffix;
120               $csp['img-src'] = $core->blog->settings->system->csp_admin_img ?:
121                    $csp_prefix."'self' data: media.dotaddict.org blob:";
122
123               # Cope with blog post preview (via public URL in iframe)
124               if (!is_null($core->blog->host)) {
125                    $csp['default-src'] .= ' '.parse_url($core->blog->host,PHP_URL_HOST);
126                    $csp['script-src'] .= ' '.parse_url($core->blog->host,PHP_URL_HOST);
127                    $csp['style-src'] .= ' '.parse_url($core->blog->host,PHP_URL_HOST);
128               }
129               # Cope with media display in media manager (via public URL)
130               if (!is_null($core->media)) {
131                    $csp['img-src'] .= ' '.parse_url($core->media->root_url,PHP_URL_HOST);
132               }
133               # Allow everything in iframe (used by editors to preview public content)
134               $csp['child-src'] = "*";
135
136               # --BEHAVIOR-- adminPageHTTPHeaderCSP
137               $core->callBehavior('adminPageHTTPHeaderCSP',$csp);
138
139               // Construct CSP header
140               $directives = array();
141               foreach ($csp as $key => $value) {
142                    if ($value) {
143                         $directives[] = $key.' '.$value;
144                    }
145               }
146               if (count($directives)) {
147                    if (version_compare(phpversion(),'5.4','>=')) {
148                         // csp_report.php needs PHP ≥ 5.4
149                         $directives[] = "report-uri ".DC_ADMIN_URL."csp_report.php";
150                    }
151                    $report_only = ($core->blog->settings->system->csp_admin_report_only) ? '-Report-Only' : '';
152                    $headers['csp'] = "Content-Security-Policy".$report_only.": ".implode(" ; ",$directives);
153               }
154          }
155
156          # --BEHAVIOR-- adminPageHTTPHeaders
157          $core->callBehavior('adminPageHTTPHeaders',$headers);
158          foreach ($headers as $key => $value) {
159               header($value);
160          }
161
162          echo
163          '<!DOCTYPE html>'.
164          '<html lang="'.$core->auth->getInfo('user_lang').'">'."\n".
165          "<head>\n".
166          '  <meta charset="UTF-8" />'."\n".
167          '  <meta name="ROBOTS" content="NOARCHIVE,NOINDEX,NOFOLLOW" />'."\n".
168          '  <meta name="GOOGLEBOT" content="NOSNIPPET" />'."\n".
169          '  <meta name="viewport" content="width=device-width, initial-scale=1.0" />'."\n".
170          '  <title>'.$title.' - '.html::escapeHTML($core->blog->name).' - '.html::escapeHTML(DC_VENDOR_NAME).' - '.DC_VERSION.'</title>'."\n".
171
172
173          self::cssLoad('style/default.css');
174          if (l10n::getTextDirection($GLOBALS['_lang']) == 'rtl') {
175               echo self::cssLoad('style/default-rtl.css');
176          }
177
178          $core->auth->user_prefs->addWorkspace('interface');
179          $user_ui_hide_std_favicon = $core->auth->user_prefs->interface->hide_std_favicon;
180          if (!$user_ui_hide_std_favicon) {
181               echo
182               '<link rel="icon" type="image/png" href="images/favicon96-login.png" />'."\n".
183               '<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />'."\n";
184          }
185
186          if ($core->auth->user_prefs->interface->htmlfontsize) {
187               echo
188               '<script type="text/javascript">'."\n".
189               self::jsVar('dotclear_htmlFontSize',$core->auth->user_prefs->interface->htmlfontsize)."\n".
190               "</script>\n";
191          }
192
193          echo
194          self::jsCommon().
195          self::jsToggles().
196          $head;
197
198          if ($core->auth->user_prefs->interface->hidemoreinfo) {
199               echo
200               '<script type="text/javascript">'."\n".
201               'dotclear.hideMoreInfo = true;'."\n".
202               "</script>\n";
203          }
204
205          # --BEHAVIOR-- adminPageHTMLHead
206          $core->callBehavior('adminPageHTMLHead');
207
208          echo
209          "</head>\n".
210          '<body id="dotclear-admin'.
211          ($safe_mode ? ' safe-mode' : '').'" class="no-js'.
212          ($core->auth->user_prefs->interface->dynfontsize ? ' responsive-font' : '').'">'."\n".
213
214          '<ul id="prelude">'.
215          '<li><a href="#content">'.__('Go to the content').'</a></li>'.
216          '<li><a href="#main-menu">'.__('Go to the menu').'</a></li>'.
217          '<li><a href="#qx">'.__('Go to search').'</a></li>'.
218          '<li><a href="#help">'.__('Go to help').'</a></li>'.
219          '</ul>'."\n".
220          '<div id="header" role="banner">'.
221          '<h1><a href="'.$core->adminurl->get("admin.home").'"><span class="hidden">'.DC_VENDOR_NAME.'</span></a></h1>'."\n";
222
223          echo
224          '<form action="'.$core->adminurl->get("admin.home").'" method="post" id="top-info-blog">'.
225          $blog_box.
226          '<p><a href="'.$core->blog->url.'" class="outgoing" title="'.__('Go to site').
227          '">'.__('Go to site').'<img src="images/outgoing.png" alt="" /></a>'.
228          '</p></form>'.
229          '<ul id="top-info-user">'.
230          '<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>'.
231          '<li><a class="smallscreen'.(preg_match('/'.preg_quote($core->adminurl->get('admin.user.preferences')).'(\?.*)?$/',$_SERVER['REQUEST_URI']) ? ' active' : '').
232          '" href="'.$core->adminurl->get("admin.user.preferences").'">'.__('My preferences').'</a></li>'.
233          '<li><a href="'.$core->adminurl->get("admin.home",array('logout' => 1)).'" class="logout"><span class="nomobile">'.sprintf(__('Logout %s'),$core->auth->userID()).
234          '</span><img src="images/logout.png" alt="" /></a></li>'.
235          '</ul>'.
236          '</div>'; // end header
237
238          echo
239          '<div id="wrapper" class="clearfix">'."\n".
240          '<div class="hidden-if-no-js collapser-box"><button type="button" id="collapser" class="void-btn">'.
241          '<img class="collapse-mm visually-hidden" src="images/collapser-hide.png" alt="'.__('Hide main menu').'" />'.
242          '<img class="expand-mm visually-hidden" src="images/collapser-show.png" alt="'.__('Show main menu').'" />'.
243          '</button></div>'.
244          '<div id="main" role="main">'."\n".
245          '<div id="content" class="clearfix">'."\n";
246
247          # Safe mode
248          if ($safe_mode)
249          {
250               echo
251               '<div class="warning" role="alert"><h3>'.__('Safe mode').'</h3>'.
252               '<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>'.
253               '</div>';
254          }
255
256          // Display breadcrumb (if given) before any error messages
257          echo $breadcrumb;
258
259          // Display notices and errors
260          echo self::notices();
261     }
262
263     public static function notices()
264     {
265          global $core;
266          static $error_displayed = false;
267
268          $res = '';
269
270          // return error messages if any
271          if ($core->error->flag() && !$error_displayed) {
272
273               # --BEHAVIOR-- adminPageNotificationError
274               $notice_error = $core->callBehavior('adminPageNotificationError',$core,$core->error);
275
276               if (isset($notice_error) && !empty($notice_error)) {
277                    $res .= $notice_error;
278               } else {
279                    $res .= '<div class="error"><p>'.
280                         '<strong>'.(count($core->error->getErrors()) > 1 ? __('Errors:') : __('Error:')).'</strong>'.
281                         '</p>'.$core->error->toHTML().'</div>';
282               }
283               $error_displayed = true;
284          }
285
286          // return notices if any
287          if (isset($_SESSION['notifications'])) {
288               foreach ($_SESSION['notifications'] as $notification) {
289
290                    # --BEHAVIOR-- adminPageNotification
291                    $notice = $core->callBehavior('adminPageNotification',$core,$notification);
292
293                    $res .= (isset($notice) && !empty($notice) ? $notice : self::getNotification($notification));
294               }
295               unset($_SESSION['notifications']);
296          }
297          return $res;
298     }
299
300     public static function addNotice($type,$message,$options=array())
301     {
302          if (isset(self::$N_TYPES[$type])){
303               $class = self::$N_TYPES[$type];
304          } else {
305               $class=$type;
306          }
307          if (isset($_SESSION['notifications']) && is_array($_SESSION['notifications'])) {
308               $notifications = $_SESSION['notifications'];
309          } else {
310               $notifications = array();
311          }
312
313          $n = array_merge($options,array('class' => $class,'ts' => time(), 'text' => $message));
314          if ($type != "static") {
315               $notifications[] = $n;
316          } else {
317               array_unshift($notifications, $n);
318          }
319          $_SESSION['notifications'] = $notifications;
320     }
321
322     public static function addSuccessNotice($message,$options=array())
323     {
324          self::addNotice("success",$message,$options);
325     }
326
327     public static function addWarningNotice($message,$options=array())
328     {
329          self::addNotice("warning",$message,$options);
330     }
331
332     public static function addErrorNotice($message,$options=array())
333     {
334          self::addNotice("error",$message,$options);
335     }
336
337     protected static function getNotification($n)
338     {
339          global $core;
340          $tag = (isset($n['divtag']) && $n['divtag']) ? 'div' : 'p';
341          $ts = '';
342          if (!isset($n['with_ts']) || ($n['with_ts'] == true)) {
343               $ts = dt::str(__('[%H:%M:%S]'),$n['ts'],$core->auth->getInfo('user_tz')).' ';
344          }
345          $res = '<'.$tag.' class="'.$n['class'].'" role="alert">'.$ts.$n['text'].'</'.$tag.'>';
346          return $res;
347     }
348
349     public static function close()
350     {
351          global $core;
352
353          if (!$GLOBALS['__resources']['ctxhelp']) {
354               if (!$core->auth->user_prefs->interface->hidehelpbutton) {
355                    echo
356                    '<p id="help-button"><a href="'.$core->adminurl->get("admin.help").'" class="outgoing" title="'.
357                    __('Global help').'">'.__('Global help').'</a></p>';
358               }
359          }
360
361          $menu =& $GLOBALS['_menu'];
362
363          echo
364          "</div>\n".         // End of #content
365          "</div>\n".         // End of #main
366
367          '<div id="main-menu" role="navigation">'."\n".
368
369          '<form id="search-menu" action="'.$core->adminurl->get("admin.search").'" method="get" role="search">'.
370          '<p><label for="qx" class="hidden">'.__('Search:').' </label>'.form::field('qx',30,255,'').
371          '<input type="submit" value="'.__('OK').'" /></p>'.
372          '</form>';
373
374          foreach ($menu as $k => $v) {
375               echo $menu[$k]->draw();
376          }
377
378          $text = sprintf(__('Thank you for using %s.'),'Dotclear '.DC_VERSION);
379
380          # --BEHAVIOR-- adminPageFooter
381          $textAlt = $core->callBehavior('adminPageFooter',$core,$text);
382          if ($textAlt != '') {
383               $text = $textAlt;
384          }
385          $text = html::escapeHTML($text);
386
387          echo
388          '</div>'."\n".      // End of #main-menu
389          "</div>\n";         // End of #wrapper
390
391          echo '<p id="gototop"><a href="#wrapper">'.__('Page top').'</a></p>'."\n";
392
393          $figure = "
394   /\_/\
395  (='.'=)
396  (\")-(\")";
397
398          echo
399          '<div id="footer" role="contentinfo">'.
400          '<a href="http://dotclear.org/" title="'.$text.'">'.
401          '<img src="style/dc_logos/w-dotclear90.png" alt="'.$text.'" /></a></div>'."\n".
402          "<!-- "."\n".
403          $figure.
404          " -->"."\n";
405
406
407
408          if (defined('DC_DEV') && DC_DEV === true) {
409               echo self::debugInfo();
410          }
411
412          echo
413          '</body></html>';
414     }
415
416     public static function openPopup($title='',$head='',$breadcrumb='')
417     {
418          global $core;
419
420          # Display
421          header('Content-Type: text/html; charset=UTF-8');
422
423          // Prevents Clickjacking as far as possible
424          header('X-Frame-Options: SAMEORIGIN'); // FF 3.6.9+ Chrome 4.1+ IE 8+ Safari 4+ Opera 10.5+
425
426          echo
427          '<!DOCTYPE html>'.
428          '<html lang="'.$core->auth->getInfo('user_lang').'">'."\n".
429          "<head>\n".
430          '  <meta charset="UTF-8" />'."\n".
431          '  <meta name="viewport" content="width=device-width, initial-scale=1.0" />'."\n".
432          '  <title>'.$title.' - '.html::escapeHTML($core->blog->name).' - '.html::escapeHTML(DC_VENDOR_NAME).' - '.DC_VERSION.'</title>'."\n".
433
434          '  <meta name="ROBOTS" content="NOARCHIVE,NOINDEX,NOFOLLOW" />'."\n".
435          '  <meta name="GOOGLEBOT" content="NOSNIPPET" />'."\n".
436
437          self::cssLoad('style/default.css');
438          if (l10n::getTextDirection($GLOBALS['_lang']) == 'rtl') {
439               echo self::cssLoad('style/default-rtl.css');
440          }
441
442          $core->auth->user_prefs->addWorkspace('interface');
443          if ($core->auth->user_prefs->interface->htmlfontsize) {
444               echo
445               '<script type="text/javascript">'."\n".
446               self::jsVar('dotclear_htmlFontSize',$core->auth->user_prefs->interface->htmlfontsize)."\n".
447               "</script>\n";
448          }
449
450          echo
451          self::jsCommon().
452          self::jsToggles().
453          $head;
454
455          if ($core->auth->user_prefs->interface->hidemoreinfo) {
456               echo
457               '<script type="text/javascript">'."\n".
458               'dotclear.hideMoreInfo = true;'."\n".
459               "</script>\n";
460          }
461
462          # --BEHAVIOR-- adminPageHTMLHead
463          $core->callBehavior('adminPageHTMLHead');
464
465          echo
466          "</head>\n".
467          '<body id="dotclear-admin" class="popup'.
468          ($core->auth->user_prefs->interface->dynfontsize ? ' responsive-font' : '').'">'."\n".
469
470          '<h1>'.DC_VENDOR_NAME.'</h1>'."\n";
471
472          echo
473          '<div id="wrapper">'."\n".
474          '<div id="main" role="main">'."\n".
475          '<div id="content">'."\n";
476
477          // display breadcrumb if given
478          echo $breadcrumb;
479
480          // Display notices and errors
481          echo self::notices();
482     }
483
484     public static function closePopup()
485     {
486          echo
487          "</div>\n".         // End of #content
488          "</div>\n".         // End of #main
489          "</div>\n".         // End of #wrapper
490
491          '<p id="gototop"><a href="#wrapper">'.__('Page top').'</a></p>'."\n".
492
493          '<div id="footer" role="contentinfo"><p>&nbsp;</p></div>'."\n".
494          '</body></html>';
495     }
496
497     public static function breadcrumb($elements=null,$options=array())
498     {
499          global $core;
500          $with_home_link = isset($options['home_link']) ? $options['home_link'] : true;
501          $hl = isset($options['hl']) ? $options['hl'] : true;
502          $hl_pos = isset($options['hl_pos']) ? $options['hl_pos'] : -1;
503          // First item of array elements should be blog's name, System or Plugins
504          $res = '<h2>'.($with_home_link ?
505               '<a class="go_home" href="'.$core->adminurl->get("admin.home").'"><img src="style/dashboard.png" alt="'.__('Go to dashboard').'" /></a>' :
506               '<img src="style/dashboard-alt.png" alt="" />');
507          $index = 0;
508          if ($hl_pos < 0) {
509               $hl_pos = count($elements)+$hl_pos;
510          }
511          foreach ($elements as $element => $url) {
512               if ($hl && $index == $hl_pos) {
513                    $element = sprintf('<span class="page-title">%s</span>',$element);
514               }
515               $res .= ($with_home_link ? ($index == 1 ? ' : ' : ' &rsaquo; ') : ($index == 0 ? ' ' : ' &rsaquo; ')).
516                    ($url ? '<a href="'.$url.'">' : '').$element.($url ? '</a>' : '');
517               $index++;
518          }
519          $res .= '</h2>';
520          return $res;
521     }
522
523     public static function message($msg,$timestamp=true,$div=false,$echo=true,$class='message')
524     {
525          global $core;
526
527          $res = '';
528          if ($msg != '') {
529               $res = ($div ? '<div class="'.$class.'">' : '').'<p'.($div ? '' : ' class="'.$class.'"').'>'.
530               ($timestamp ? dt::str(__('[%H:%M:%S]'),null,$core->auth->getInfo('user_tz')).' ' : '').$msg.
531               '</p>'.($div ? '</div>' : '');
532               if ($echo) {
533                    echo $res;
534               }
535          }
536          return $res;
537     }
538
539     public static function success($msg,$timestamp=true,$div=false,$echo=true)
540     {
541          return self::message($msg,$timestamp,$div,$echo,"success");
542     }
543
544     public static function warning($msg,$timestamp=true,$div=false,$echo=true)
545     {
546          return self::message($msg,$timestamp,$div,$echo,"warning-msg");
547     }
548
549     private static function debugInfo()
550     {
551          $global_vars = implode(', ',array_keys($GLOBALS));
552
553          $res =
554          '<div id="debug"><div>'.
555          '<p>memory usage: '.memory_get_usage().' ('.files::size(memory_get_usage()).')</p>';
556
557          if (function_exists('xdebug_get_profiler_filename'))
558          {
559               $res .= '<p>Elapsed time: '.xdebug_time_index().' seconds</p>';
560
561               $prof_file = xdebug_get_profiler_filename();
562               if ($prof_file) {
563                    $res .= '<p>Profiler file : '.xdebug_get_profiler_filename().'</p>';
564               } else {
565                    $prof_url = http::getSelfURI();
566                    $prof_url .= (strpos($prof_url,'?') === false) ? '?' : '&';
567                    $prof_url .= 'XDEBUG_PROFILE';
568                    $res .= '<p><a href="'.html::escapeURL($prof_url).'">Trigger profiler</a></p>';
569               }
570
571               /* xdebug configuration:
572               zend_extension = /.../xdebug.so
573               xdebug.auto_trace = On
574               xdebug.trace_format = 0
575               xdebug.trace_options = 1
576               xdebug.show_mem_delta = On
577               xdebug.profiler_enable = 0
578               xdebug.profiler_enable_trigger = 1
579               xdebug.profiler_output_dir = /tmp
580               xdebug.profiler_append = 0
581               xdebug.profiler_output_name = timestamp
582               */
583          }
584
585          $res .=
586          '<p>Global vars: '.$global_vars.'</p>'.
587          '</div></div>';
588
589          return $res;
590     }
591
592     public static function help($page,$index='')
593     {
594          # Deprecated but we keep this for plugins.
595     }
596
597     public static function helpBlock()
598     {
599          global $core;
600
601          if ($core->auth->user_prefs->interface->hidehelpbutton) {
602               return;
603          }
604
605          $args = func_get_args();
606          $args = new ArrayObject($args);
607
608          # --BEHAVIOR-- adminPageHelpBlock
609          $GLOBALS['core']->callBehavior('adminPageHelpBlock',$args);
610
611          if (empty($args)) {
612               return;
613          };
614
615          global $__resources;
616          if (empty($__resources['help'])) {
617               return;
618          }
619
620          $content = '';
621          foreach ($args as $v)
622          {
623               if (is_object($v) && isset($v->content)) {
624                    $content .= $v->content;
625                    continue;
626               }
627
628               if (!isset($__resources['help'][$v])) {
629                    continue;
630               }
631               $f = $__resources['help'][$v];
632               if (!file_exists($f) || !is_readable($f)) {
633                    continue;
634               }
635
636               $fc = file_get_contents($f);
637               if (preg_match('|<body[^>]*?>(.*?)</body>|ms',$fc,$matches)) {
638                    $content .= $matches[1];
639               } else {
640                    $content .= $fc;
641               }
642          }
643
644          if (trim($content) == '') {
645               return;
646          }
647
648          // Set contextual help global flag
649          $GLOBALS['__resources']['ctxhelp'] = true;
650
651          echo
652          '<div id="help"><hr /><div class="help-content clear"><h3>'.__('Help about this page').'</h3>'.
653          $content.
654          '</div>'.
655          '<div id="helplink"><hr />'.
656          '<p>'.
657          sprintf(__('See also %s'),sprintf('<a href="'.$core->adminurl->get("admin.help").'">%s</a>',__('the global help'))).
658          '.</p>'.
659          '</div></div>';
660     }
661
662     public static function cssLoad($src,$media='screen',$v='')
663     {
664          $escaped_src = html::escapeHTML($src);
665          if (!isset(self::$loaded_css[$escaped_src])) {
666               self::$loaded_css[$escaped_src] = true;
667               $escaped_src = self::appendVersion($escaped_src,$v);
668
669               return '<link rel="stylesheet" href="'.$escaped_src.'" type="text/css" media="'.$media.'" />'."\n";
670          }
671     }
672
673     public static function jsLoad($src,$v='')
674     {
675          $escaped_src = html::escapeHTML($src);
676          if (!isset(self::$loaded_js[$escaped_src])) {
677               self::$loaded_js[$escaped_src] = true;
678               $escaped_src = self::appendVersion($escaped_src,$v);
679               return '<script type="text/javascript" src="'.$escaped_src.'"></script>'."\n";
680          }
681     }
682
683     private static function appendVersion($src,$v='')
684     {
685          $src .= (strpos($src,'?') === false ? '?' : '&amp;').'v=';
686          if (defined('DC_DEV') && DC_DEV === true) {
687               $src .= md5(uniqid());
688          } else {
689               $src .= ($v === '' ? DC_VERSION : $v);
690          }
691          return $src;
692     }
693
694     public static function jsVar($n,$v)
695     {
696          return $n." = '".html::escapeJS($v)."';\n";
697     }
698
699     public static function jsToggles()
700     {
701          if($GLOBALS['core']->auth->user_prefs->toggles) {
702               $unfolded_sections = explode(',',$GLOBALS['core']->auth->user_prefs->toggles->unfolded_sections);
703               foreach ($unfolded_sections as $k=>&$v) {
704                    if ($v == '') {
705                         unset($unfolded_sections[$k]);
706                    } else {
707                         $v = "'".html::escapeJS($v)."':true";
708                    }
709               }
710          } else {
711               $unfolded_sections=array();
712          }
713          return '<script type="text/javascript">'."\n".
714                    'dotclear.unfolded_sections = {'.join(",",$unfolded_sections)."};\n".
715                    "</script>\n";
716     }
717
718     public static function jsCommon()
719     {
720          $mute_or_no = '';
721          if (empty($GLOBALS['core']->blog) || $GLOBALS['core']->blog->settings->system->jquery_migrate_mute) {
722               $mute_or_no .=
723                    '<script type="text/javascript">'."\n".
724                    'jQuery.migrateMute = true;'."\n".
725                    "</script>\n";
726          }
727
728          return
729          self::jsLoad('js/jquery/jquery.js').
730          $mute_or_no.
731          self::jsLoad('js/jquery/jquery-migrate.js').
732          self::jsLoad('js/jquery/jquery.biscuit.js').
733          self::jsLoad('js/jquery/jquery.bgFade.js').
734          self::jsLoad('js/common.js').
735          self::jsLoad('js/prelude.js').
736
737          '<script type="text/javascript">'."\n".
738          'jsToolBar = {}, jsToolBar.prototype = { elements : {} };'."\n".
739
740          self::jsVar('dotclear.nonce',$GLOBALS['core']->getNonce()).
741
742          self::jsVar('dotclear.img_plus_src','images/expand.png').
743          self::jsVar('dotclear.img_plus_alt',__('uncover')).
744          self::jsVar('dotclear.img_minus_src','images/hide.png').
745          self::jsVar('dotclear.img_minus_alt',__('hide')).
746          self::jsVar('dotclear.img_menu_on','images/menu_on.png').
747          self::jsVar('dotclear.img_menu_off','images/menu_off.png').
748
749          self::jsVar('dotclear.img_plus_theme_src','images/plus-theme.png').
750          self::jsVar('dotclear.img_plus_theme_alt',__('uncover')).
751          self::jsVar('dotclear.img_minus_theme_src','images/minus-theme.png').
752          self::jsVar('dotclear.img_minus_theme_alt',__('hide')).
753
754          self::jsVar('dotclear.msg.help',
755               __('Need help?')).
756          self::jsVar('dotclear.msg.new_window',
757               __('new window')).
758          self::jsVar('dotclear.msg.help_hide',
759               __('Hide')).
760          self::jsVar('dotclear.msg.to_select',
761               __('Select:')).
762          self::jsVar('dotclear.msg.no_selection',
763               __('no selection')).
764          self::jsVar('dotclear.msg.select_all',
765               __('select all')).
766          self::jsVar('dotclear.msg.invert_sel',
767               __('Invert selection')).
768          self::jsVar('dotclear.msg.website',
769               __('Web site:')).
770          self::jsVar('dotclear.msg.email',
771               __('Email:')).
772          self::jsVar('dotclear.msg.ip_address',
773               __('IP address:')).
774          self::jsVar('dotclear.msg.error',
775               __('Error:')).
776          self::jsVar('dotclear.msg.entry_created',
777               __('Entry has been successfully created.')).
778          self::jsVar('dotclear.msg.edit_entry',
779               __('Edit entry')).
780          self::jsVar('dotclear.msg.view_entry',
781               __('view entry')).
782          self::jsVar('dotclear.msg.confirm_delete_posts',
783               __("Are you sure you want to delete selected entries (%s)?")).
784          self::jsVar('dotclear.msg.confirm_delete_medias',
785               __("Are you sure you want to delete selected medias (%d)?")).
786          self::jsVar('dotclear.msg.confirm_delete_categories',
787               __("Are you sure you want to delete selected categories (%s)?")).
788          self::jsVar('dotclear.msg.confirm_delete_post',
789               __("Are you sure you want to delete this entry?")).
790          self::jsVar('dotclear.msg.click_to_unlock',
791               __("Click here to unlock the field")).
792          self::jsVar('dotclear.msg.confirm_spam_delete',
793               __('Are you sure you want to delete all spams?')).
794          self::jsVar('dotclear.msg.confirm_delete_comments',
795               __('Are you sure you want to delete selected comments (%s)?')).
796          self::jsVar('dotclear.msg.confirm_delete_comment',
797               __('Are you sure you want to delete this comment?')).
798          self::jsVar('dotclear.msg.cannot_delete_users',
799               __('Users with posts cannot be deleted.')).
800          self::jsVar('dotclear.msg.confirm_delete_user',
801               __('Are you sure you want to delete selected users (%s)?')).
802          self::jsVar('dotclear.msg.confirm_delete_blog',
803               __('Are you sure you want to delete selected blogs (%s)?')).
804          self::jsVar('dotclear.msg.confirm_delete_category',
805               __('Are you sure you want to delete category "%s"?')).
806          self::jsVar('dotclear.msg.confirm_reorder_categories',
807               __('Are you sure you want to reorder all categories?')).
808          self::jsVar('dotclear.msg.confirm_delete_media',
809               __('Are you sure you want to remove media "%s"?')).
810          self::jsVar('dotclear.msg.confirm_delete_directory',
811               __('Are you sure you want to remove directory "%s"?')).
812          self::jsVar('dotclear.msg.confirm_extract_current',
813               __('Are you sure you want to extract archive in current directory?')).
814          self::jsVar('dotclear.msg.confirm_remove_attachment',
815               __('Are you sure you want to remove attachment "%s"?')).
816          self::jsVar('dotclear.msg.confirm_delete_lang',
817               __('Are you sure you want to delete "%s" language?')).
818          self::jsVar('dotclear.msg.confirm_delete_plugin',
819               __('Are you sure you want to delete "%s" plugin?')).
820          self::jsVar('dotclear.msg.confirm_delete_plugins',
821               __('Are you sure you want to delete selected plugins?')).
822          self::jsVar('dotclear.msg.use_this_theme',
823               __('Use this theme')).
824          self::jsVar('dotclear.msg.remove_this_theme',
825               __('Remove this theme')).
826          self::jsVar('dotclear.msg.confirm_delete_theme',
827               __('Are you sure you want to delete "%s" theme?')).
828          self::jsVar('dotclear.msg.confirm_delete_themes',
829               __('Are you sure you want to delete selected themes?')).
830          self::jsVar('dotclear.msg.confirm_delete_backup',
831               __('Are you sure you want to delete this backup?')).
832          self::jsVar('dotclear.msg.confirm_revert_backup',
833               __('Are you sure you want to revert to this backup?')).
834          self::jsVar('dotclear.msg.zip_file_content',
835               __('Zip file content')).
836          self::jsVar('dotclear.msg.xhtml_validator',
837               __('XHTML markup validator')).
838          self::jsVar('dotclear.msg.xhtml_valid',
839               __('XHTML content is valid.')).
840          self::jsVar('dotclear.msg.xhtml_not_valid',
841               __('There are XHTML markup errors.')).
842          self::jsVar('dotclear.msg.warning_validate_no_save_content',
843               __('Attention: an audit of a content not yet registered.')).
844          self::jsVar('dotclear.msg.confirm_change_post_format',
845               __('You have unsaved changes. Switch post format will loose these changes. Proceed anyway?')).
846          self::jsVar('dotclear.msg.confirm_change_post_format_noconvert',
847               __("Warning: post format change will not convert existing content. You will need to apply new format by yourself. Proceed anyway?")).
848          self::jsVar('dotclear.msg.load_enhanced_uploader',
849               __('Loading enhanced uploader, please wait.')).
850
851          self::jsVar('dotclear.msg.module_author',
852               __('Author:')).
853          self::jsVar('dotclear.msg.module_details',
854               __('Details')).
855          self::jsVar('dotclear.msg.module_support',
856               __('Support')).
857          self::jsVar('dotclear.msg.module_help',
858               __('Help:')).
859          self::jsVar('dotclear.msg.module_section',
860               __('Section:')).
861          self::jsVar('dotclear.msg.module_tags',
862               __('Tags:')).
863
864          self::jsVar('dotclear.msg.close_notice',
865               __('Hide this notice')).
866
867               "\n".
868          "</script>\n";
869     }
870
871     /**
872     @deprecated since version 2.11
873     */
874     public static function jsLoadIE7()
875     {
876          return '';
877     }
878
879     public static function jsConfirmClose()
880     {
881          $args = func_get_args();
882          if (count($args) > 0) {
883               foreach ($args as $k => $v) {
884                    $args[$k] = "'".html::escapeJS($v)."'";
885               }
886               $args = implode(',',$args);
887          } else {
888               $args = '';
889          }
890
891          return
892          self::jsLoad('js/confirm-close.js').
893          '<script type="text/javascript">'."\n".
894          "confirmClosePage = new confirmClose(".$args."); ".
895          "confirmClose.prototype.prompt = '".html::escapeJS(__('You have unsaved changes.'))."'; ".
896          "</script>\n";
897     }
898
899     public static function jsPageTabs($default=null)
900     {
901          if ($default) {
902               $default = "'".html::escapeJS($default)."'";
903          }
904
905          return
906          self::jsLoad('js/jquery/jquery.pageTabs.js').
907          '<script type="text/javascript">'."\n".
908          '$(function() {'."\n".
909          '    $.pageTabs('.$default.');'."\n".
910          '});'.
911          "</script>\n";
912     }
913
914     public static function jsModal()
915     {
916          return
917          self::jsLoad('js/jquery/jquery.magnific-popup.js');
918     }
919
920     public static function jsColorPicker()
921     {
922          return
923          self::cssLoad('style/farbtastic/farbtastic.css').
924          self::jsLoad('js/jquery/jquery.farbtastic.js').
925          self::jsLoad('js/color-picker.js');
926     }
927
928     public static function jsDatePicker()
929     {
930          return
931          self::cssLoad('style/date-picker.css').
932          self::jsLoad('js/date-picker.js').
933          '<script type="text/javascript">'."\n".
934
935          "datePicker.prototype.months[0] = '".html::escapeJS(__('January'))."'; ".
936          "datePicker.prototype.months[1] = '".html::escapeJS(__('February'))."'; ".
937          "datePicker.prototype.months[2] = '".html::escapeJS(__('March'))."'; ".
938          "datePicker.prototype.months[3] = '".html::escapeJS(__('April'))."'; ".
939          "datePicker.prototype.months[4] = '".html::escapeJS(__('May'))."'; ".
940          "datePicker.prototype.months[5] = '".html::escapeJS(__('June'))."'; ".
941          "datePicker.prototype.months[6] = '".html::escapeJS(__('July'))."'; ".
942          "datePicker.prototype.months[7] = '".html::escapeJS(__('August'))."'; ".
943          "datePicker.prototype.months[8] = '".html::escapeJS(__('September'))."'; ".
944          "datePicker.prototype.months[9] = '".html::escapeJS(__('October'))."'; ".
945          "datePicker.prototype.months[10] = '".html::escapeJS(__('November'))."'; ".
946          "datePicker.prototype.months[11] = '".html::escapeJS(__('December'))."'; ".
947
948          "datePicker.prototype.days[0] = '".html::escapeJS(__('Monday'))."'; ".
949          "datePicker.prototype.days[1] = '".html::escapeJS(__('Tuesday'))."'; ".
950          "datePicker.prototype.days[2] = '".html::escapeJS(__('Wednesday'))."'; ".
951          "datePicker.prototype.days[3] = '".html::escapeJS(__('Thursday'))."'; ".
952          "datePicker.prototype.days[4] = '".html::escapeJS(__('Friday'))."'; ".
953          "datePicker.prototype.days[5] = '".html::escapeJS(__('Saturday'))."'; ".
954          "datePicker.prototype.days[6] = '".html::escapeJS(__('Sunday'))."'; ".
955
956          "datePicker.prototype.img_src = 'images/date-picker.png'; ".
957          "datePicker.prototype.img_alt = '".html::escapeJS(__('Choose date'))."'; ".
958
959          "datePicker.prototype.close_msg = '".html::escapeJS(__('close'))."'; ".
960          "datePicker.prototype.now_msg = '".html::escapeJS(__('now'))."'; ".
961
962          "</script>\n";
963     }
964
965
966     public static function jsToolBar()
967     {
968          # Deprecated but we keep this for plugins.
969     }
970
971     public static function jsUpload($params=array(),$base_url=null)
972     {
973          if (!$base_url) {
974               $base_url = path::clean(dirname(preg_replace('/(\?.*$)?/','',$_SERVER['REQUEST_URI']))).'/';
975          }
976
977          $params = array_merge($params,array(
978               'sess_id='.session_id(),
979               'sess_uid='.$_SESSION['sess_browser_uid'],
980               'xd_check='.$GLOBALS['core']->getNonce()
981          ));
982
983          return
984          '<script type="text/javascript">'."\n".
985          "dotclear.jsUpload = {};\n".
986          "dotclear.jsUpload.msg = {};\n".
987          self::jsVar('dotclear.msg.enhanced_uploader_activate',__('Temporarily activate enhanced uploader')).
988          self::jsVar('dotclear.msg.enhanced_uploader_disable',__('Temporarily disable enhanced uploader')).
989          self::jsVar('dotclear.jsUpload.msg.limit_exceeded',__('Limit exceeded.')).
990          self::jsVar('dotclear.jsUpload.msg.size_limit_exceeded',__('File size exceeds allowed limit.')).
991          self::jsVar('dotclear.jsUpload.msg.canceled',__('Canceled.')).
992          self::jsVar('dotclear.jsUpload.msg.http_error',__('HTTP Error:')).
993          self::jsVar('dotclear.jsUpload.msg.error',__('Error:')).
994          self::jsVar('dotclear.jsUpload.msg.choose_file',__('Choose file')).
995          self::jsVar('dotclear.jsUpload.msg.choose_files',__('Choose files')).
996          self::jsVar('dotclear.jsUpload.msg.cancel',__('Cancel')).
997          self::jsVar('dotclear.jsUpload.msg.clean',__('Clean')).
998          self::jsVar('dotclear.jsUpload.msg.upload',__('Upload')).
999          self::jsVar('dotclear.jsUpload.msg.send',__('Send')).
1000          self::jsVar('dotclear.jsUpload.msg.file_successfully_uploaded',__('File successfully uploaded.')).
1001          self::jsVar('dotclear.jsUpload.msg.no_file_in_queue',__('No file in queue.')).
1002          self::jsVar('dotclear.jsUpload.msg.file_in_queue',__('1 file in queue.')).
1003          self::jsVar('dotclear.jsUpload.msg.files_in_queue',__('%d files in queue.')).
1004          self::jsVar('dotclear.jsUpload.msg.queue_error',__('Queue error:')).
1005          self::jsVar('dotclear.jsUpload.base_url',$base_url).
1006          "</script>\n".
1007
1008          self::jsLoad('js/jquery/jquery-ui.custom.js').
1009          self::jsLoad('js/jsUpload/tmpl.js').
1010          self::jsLoad('js/jsUpload/template-upload.js').
1011          self::jsLoad('js/jsUpload/template-download.js').
1012          self::jsLoad('js/jsUpload/load-image.js').
1013          self::jsLoad('js/jsUpload/jquery.iframe-transport.js').
1014          self::jsLoad('js/jsUpload/jquery.fileupload.js').
1015          self::jsLoad('js/jsUpload/jquery.fileupload-process.js').
1016          self::jsLoad('js/jsUpload/jquery.fileupload-resize.js').
1017          self::jsLoad('js/jsUpload/jquery.fileupload-ui.js');
1018     }
1019
1020     public static function jsMetaEditor()
1021     {
1022          return self::jsLoad('js/meta-editor.js');
1023     }
1024
1025     public static function jsFilterControl($show=true)
1026     {
1027          return
1028          self::jsLoad('js/filter-controls.js').
1029          '<script type="text/javascript">'."\n".
1030          self::jsVar('dotclear.msg.show_filters', $show ? 'true':'false')."\n".
1031          self::jsVar('dotclear.msg.filter_posts_list',__('Show filters and display options'))."\n".
1032          self::jsVar('dotclear.msg.cancel_the_filter',__('Cancel filters and display options'))."\n".
1033          "</script>";
1034     }
1035
1036     public static function jsLoadCodeMirror($theme = '',$multi = true,$modes = array('css','htmlmixed','javascript','php','xml'))
1037     {
1038          $ret =
1039               self::cssLoad('js/codemirror/lib/codemirror.css').
1040               self::jsLoad('js/codemirror/lib/codemirror.js');
1041          if ($multi) {
1042               $ret .= self::jsLoad('js/codemirror/addon/mode/multiplex.js');
1043          }
1044          foreach ($modes as $mode) {
1045               $ret .= self::jsLoad('js/codemirror/mode/'.$mode.'/'.$mode.'.js');
1046          }
1047          $ret .=
1048               self::jsLoad('js/codemirror/addon/edit/closebrackets.js').
1049               self::jsLoad('js/codemirror/addon/edit/matchbrackets.js').
1050               self::cssLoad('js/codemirror/addon/display/fullscreen.css').
1051               self::jsLoad('js/codemirror/addon/display/fullscreen.js');
1052          if ($theme != '') {
1053               $ret .= self::cssLoad('js/codemirror/theme/'.$theme.'.css');
1054          }
1055          return $ret;
1056     }
1057
1058     public static function jsRunCodeMirror($name,$id,$mode,$theme = '')
1059     {
1060          $ret =
1061               '<script type="text/javascript">'."\n".
1062               'var '.$name.' = CodeMirror.fromTextArea('.$id.',{'."\n".
1063               '    mode: "'.$mode.'",'."\n".
1064               '    tabMode: "indent",'."\n".
1065               '    lineWrapping: "true",'."\n".
1066               '    lineNumbers: "true",'."\n".
1067               '    matchBrackets: "true",'."\n".
1068               '    autoCloseBrackets: "true",'."\n".
1069               '    extraKeys: {"F11": function(cm) {cm.setOption("fullScreen",!cm.getOption("fullScreen"));}}';
1070          if ($theme) {
1071               $ret .=
1072                    ','."\n".
1073                    '    theme: "'.$theme.'"';
1074          }
1075          $ret .= "\n".
1076               '});'."\n".
1077               '</script>';
1078          return $ret;
1079     }
1080
1081     public static function getCodeMirrorThemes()
1082     {
1083          $themes = array();
1084          $themes_root = dirname(__FILE__).'/../../admin'.'/js/codemirror/theme/';
1085          if (is_dir($themes_root) && is_readable($themes_root)) {
1086               if (($d = @dir($themes_root)) !== false) {
1087                    while (($entry = $d->read()) !== false) {
1088                         if ($entry != '.' && $entry != '..' && substr($entry, 0, 1) != '.' && is_readable($themes_root.'/'.$entry)) {
1089                              $themes[] = substr($entry,0,-4); // remove .css extension
1090                         }
1091                    }
1092                    sort($themes);
1093               }
1094          }
1095          return $themes;
1096     }
1097
1098     public static function getPF($file)
1099     {
1100          return $GLOBALS['core']->adminurl->get('load.plugin.file',array('pf' => $file));
1101     }
1102
1103     public static function getVF($file)
1104     {
1105          return $GLOBALS['core']->adminurl->get('load.var.file',array('vf' => $file));
1106     }
1107
1108     public static function setXFrameOptions($headers,$origin = null)
1109     {
1110          if (self::$xframe_loaded) {
1111               return;
1112          }
1113
1114          if ($origin !== null) {
1115               $url = parse_url($origin);
1116               $headers['x-frame-options'] = sprintf('X-Frame-Options: %s',is_array($url) && isset($url['host']) ?
1117                    ("ALLOW-FROM ".(isset($url['scheme']) ? $url['scheme'].':' : '' ).'//'.$url['host']) :
1118                    'SAMEORIGIN');
1119          } else {
1120               $headers['x-frame-options'] = 'X-Frame-Options: SAMEORIGIN'; // FF 3.6.9+ Chrome 4.1+ IE 8+ Safari 4+ Opera 10.5+
1121          }
1122          self::$xframe_loaded = true;
1123     }
1124}
Note: See TracBrowser for help on using the repository browser.

Sites map