Dotclear

source: inc/admin/lib.dc.page.php @ 3319:6a9ba28a243f

Revision 3319:6a9ba28a243f, 34.5 KB checked in by franck <carnet.franck.paul@…>, 9 years ago (diff)

Cope with external sources used in editor's iframe to preview public external content (Youtube video, Flickr images, …)

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

Sites map