Dotclear

source: inc/admin/lib.dc.page.php @ 3021:4018240bced6

Revision 3021:4018240bced6, 30.3 KB checked in by Nicolas <nikrou77@…>, 10 years ago (diff)

Add css without cache counterpart : cssLoad
Use jsLoad and cssLoad for official plugins

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

Sites map