Dotclear

source: inc/admin/lib.dc.page.php @ 3081:2d7b794a32c3

Revision 3081:2d7b794a32c3, 30.2 KB checked in by franck <carnet.franck.paul@…>, 10 years ago (diff)

Merge bugfix from 2.8 branch

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

Sites map