Dotclear

source: inc/admin/lib.dc.page.php @ 3294:6b3d608280b5

Revision 3294:6b3d608280b5, 34.0 KB checked in by franck <carnet.franck.paul@…>, 9 years ago (diff)

Go top button for long admin pages - closes #2192

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

Sites map