Dotclear

source: inc/admin/lib.dc.page.php @ 2613:014098e27ea0

Revision 2613:014098e27ea0, 33.1 KB checked in by Dsls, 12 years ago (diff)

Merge

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

Sites map