Dotclear

source: inc/admin/lib.dc.page.php @ 3368:bb25979b0371

Revision 3368:bb25979b0371, 34.2 KB checked in by franck <carnet.franck.paul@…>, 9 years ago (diff)

Replace old jQuery modal js code by the Magnific-Popup responsive jQuery plugin ( http://dimsemenov.com/plugins/magnific-popup/, MIT Licence)

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

Sites map