Dotclear

source: inc/admin/lib.dc.page.php @ 1107:3943962d69b8

Revision 1107:3943962d69b8, 18.0 KB checked in by JcDenis, 12 years ago (diff)

merge with default branch in 2.5-RC

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2011 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
20     # Auth check
21     public static function check($permissions)
22     {
23          global $core;
24         
25          if ($core->blog && $core->auth->check($permissions,$core->blog->id))
26          {
27               return;
28          }
29         
30          if (session_id()) {
31               $core->session->destroy();
32          }
33          http::redirect(DC_AUTH_PAGE);
34     }
35     
36     # Check super admin
37     public static function checkSuper()
38     {
39          global $core;
40         
41          if (!$core->auth->isSuperAdmin())
42          {
43               if (session_id()) {
44                    $core->session->destroy();
45               }
46               http::redirect(DC_AUTH_PAGE);
47          }
48     }
49     
50     # Top of admin page
51     public static function open($title='', $head='')
52     {
53          global $core;
54         
55          # List of user's blogs
56          if ($core->auth->blog_count == 1 || $core->auth->blog_count > 20)
57          {
58               $blog_box =
59               '<p>'.__('Blog:').' <strong title="'.html::escapeHTML($core->blog->url).'">'.
60               html::escapeHTML($core->blog->name).'</strong>';
61               
62               if ($core->auth->blog_count > 20) {
63                    $blog_box .= ' - <a href="blogs.php">'.__('Change blog').'</a>';
64               }
65               $blog_box .= '</p>';
66          }
67          else
68          {
69               $rs_blogs = $core->getBlogs(array('order'=>'LOWER(blog_name)','limit'=>20));
70               $blogs = array();
71               foreach ($rs_blogs as $rs_blog) {
72                    $blogs[html::escapeHTML($rs_blog->blog_name.' - '.$rs_blog->blog_url)] = $rs_blog->blog_id;
73               }
74               $blog_box =
75               '<p><label for="switchblog" class="classic">'.
76               __('Blogs:').' '.
77               $core->formNonce().
78               form::combo('switchblog',$blogs,$core->blog->id).
79               '</label></p>'.
80               '<noscript><p><input type="submit" value="'.__('ok').'" /></p></noscript>';
81          }
82         
83          $safe_mode = isset($_SESSION['sess_safe_mode']) && $_SESSION['sess_safe_mode'];
84         
85          # Display
86          header('Content-Type: text/html; charset=UTF-8');
87          echo
88          '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" '.
89          ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'."\n".
90          '<html xmlns="http://www.w3.org/1999/xhtml" '.
91          'xml:lang="'.$core->auth->getInfo('user_lang').'" '.
92          'lang="'.$core->auth->getInfo('user_lang').'">'."\n".
93          "<head>\n".
94          '  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />'."\n".
95          '  <title>'.$title.' - '.html::escapeHTML($core->blog->name).' - '.html::escapeHTML(DC_VENDOR_NAME).' - '.DC_VERSION.'</title>'."\n".
96         
97          '  <meta name="ROBOTS" content="NOARCHIVE,NOINDEX,NOFOLLOW" />'."\n".
98          '  <meta name="GOOGLEBOT" content="NOSNIPPET" />'."\n".
99         
100          self::jsLoadIE7().
101          '    <link rel="stylesheet" href="style/default.css" type="text/css" media="screen" />'."\n"; 
102          if (l10n::getTextDirection($GLOBALS['_lang']) == 'rtl') {
103               echo
104          '    <link rel="stylesheet" href="style/default-rtl.css" type="text/css" media="screen" />'."\n"; 
105          }
106
107          $core->auth->user_prefs->addWorkspace('interface');
108          $user_ui_hide_std_favicon = $core->auth->user_prefs->interface->hide_std_favicon;
109          if (!$user_ui_hide_std_favicon) {
110               echo '<link rel="icon" type="image/png" href="images/favicon.png" />';
111          }
112         
113          echo
114          self::jsCommon().
115          $head;
116         
117          # --BEHAVIOR-- adminPageHTMLHead
118          $core->callBehavior('adminPageHTMLHead');
119         
120          echo
121          "</head>\n".
122          '<body id="dotclear-admin'.
123          ($safe_mode ? ' safe-mode' : '').
124          '">'."\n".
125         
126          '<div id="header">'.
127          '<ul id="prelude"><li><a href="#content">'.__('Go to the content').'</a></li><li><a href="#main-menu">'.__('Go to the menu').'</a></li></ul>'."\n".
128          '<div id="top"><h1><a href="index.php">'.DC_VENDOR_NAME.'</a></h1></div>'."\n"; 
129         
130          echo
131          '<div id="info-boxes">'.
132          '<div id="info-box1">'.
133          '<form action="index.php" method="post">'.
134          $blog_box.
135          '<p><a href="'.$core->blog->url.'" onclick="window.open(this.href);return false;" title="'.__('Go to site').' ('.__('new window').')'.'">'.__('Go to site').' <img src="images/outgoing.png" alt="" /></a>'.
136          '</p></form>'.
137          '</div>'.
138          '<div id="info-box2">'.
139          '<a'.(preg_match('/index.php$/',$_SERVER['REQUEST_URI']) ? ' class="active"' : '').' href="index.php">'.__('My dashboard').'</a>'.
140          '<span> | </span><a'.(preg_match('/preferences.php(\?.*)?$/',$_SERVER['REQUEST_URI']) ? ' class="active"' : '').' href="preferences.php">'.__('My preferences').'</a>'.
141          '<span> | </span><a href="index.php?logout=1" class="logout">'.sprintf(__('Logout %s'),$core->auth->userID()).' <img src="images/logout.png" alt="" /></a>'.
142          '</div>'.
143          '</div>'.
144          '</div>';
145         
146          echo
147          '<div id="wrapper">'."\n".
148          '<div id="main">'."\n".
149          '<div id="content">'."\n";
150         
151          # Safe mode
152          if ($safe_mode)
153          {
154               echo
155               '<div class="error"><h3>'.__('Safe mode').'</h3>'.
156               '<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>'.
157               '</div>';
158          }
159         
160          if ($core->error->flag()) {
161               echo
162               '<div class="error"><p><strong>'.(count($core->error->getErrors()) > 1 ? __('Errors:') : __('Error:')).'</p></strong>'.
163               $core->error->toHTML().
164               '</div>';
165          }
166     }
167     
168     public static function close()
169     {
170          global $core;
171
172          $menu =& $GLOBALS['_menu'];
173         
174          echo
175          "</div>\n".         // End of #content
176          "</div>\n".         // End of #main
177         
178          '<div id="main-menu">'."\n";
179         
180          foreach ($menu as $k => $v) {
181               echo $menu[$k]->draw();
182          }
183         
184          $text = sprintf(__('Thank you for using %s.'),'<a href="http://dotclear.org/">Dotclear '.DC_VERSION.'</a>');
185
186          # --BEHAVIOR-- adminPageFooter
187          $textAlt = $core->callBehavior('adminPageFooter',$core,$text);
188
189          echo
190          '</div>'."\n".      // End of #main-menu
191          '<div id="footer"><p>'.($textAlt != '' ? $textAlt : $text).'</p></div>'."\n".
192          "</div>\n";         // End of #wrapper
193         
194          if (defined('DC_DEV') && DC_DEV === true) {
195               echo self::debugInfo();
196          }
197         
198          echo
199          '</body></html>';
200     }
201     
202     public static function openPopup($title='', $head='')
203     {
204          global $core;
205         
206          # Display
207          header('Content-Type: text/html; charset=UTF-8');
208          echo
209          '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" '.
210          ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'."\n".
211          '<html xmlns="http://www.w3.org/1999/xhtml" '.
212          'xml:lang="'.$core->auth->getInfo('user_lang').'" '.
213          'lang="'.$core->auth->getInfo('user_lang').'">'."\n".
214          "<head>\n".
215          '  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />'."\n".
216          '  <title>'.$title.' - '.html::escapeHTML($core->blog->name).' - '.html::escapeHTML(DC_VENDOR_NAME).' - '.DC_VERSION.'</title>'."\n".
217         
218          '  <meta name="ROBOTS" content="NOARCHIVE,NOINDEX,NOFOLLOW" />'."\n".
219          '  <meta name="GOOGLEBOT" content="NOSNIPPET" />'."\n".
220         
221          self::jsLoadIE7().
222          '    <link rel="stylesheet" href="style/default.css" type="text/css" media="screen" />'."\n"; 
223          if (l10n::getTextDirection($GLOBALS['_lang']) == 'rtl') {
224               echo
225               '    <link rel="stylesheet" href="style/default-rtl.css" type="text/css" media="screen" />'."\n"; 
226          }
227         
228          echo
229          self::jsCommon().
230          $head;
231         
232          # --BEHAVIOR-- adminPageHTMLHead
233          $core->callBehavior('adminPageHTMLHead');
234         
235          echo
236          "</head>\n".
237          '<body id="dotclear-admin" class="popup">'."\n".
238         
239          '<div id="top"><h1>'.DC_VENDOR_NAME.'</h1></div>'."\n";
240         
241          echo
242          '<div id="wrapper">'."\n".
243          '<div id="main">'."\n".
244          '<div id="content">'."\n";
245         
246          if ($core->error->flag()) {
247               echo
248               '<div class="error"><strong>'.__('Errors:').'</strong>'.
249               $core->error->toHTML().
250               '</div>';
251          }
252     }
253     
254     public static function closePopup()
255     {
256          echo
257          "</div>\n".         // End of #content
258          "</div>\n".         // End of #main
259          '<div id="footer"><p>&nbsp;</p></div>'."\n".
260          "</div>\n".         // End of #wrapper
261          '</body></html>';
262     }
263
264     public static function message($msg,$timestamp=true,$div=false,$echo=true)
265     {
266          global $core;
267         
268          $res = '';
269          if ($msg != '') {
270               $res = ($div ? '<div class="message">' : '').'<p'.($div ? '' : ' class="message"').'>'.
271                    ($timestamp ? dt::str(__('%H:%M:%S:'),null,$core->auth->getInfo('user_tz')).' ' : '').$msg.
272                    '</p>'.($div ? '</div>' : '');
273               if ($echo) {
274                    echo $res;
275               }
276          }
277          return $res;
278     }
279     
280     private static function debugInfo()
281     {
282          $global_vars = implode(', ',array_keys($GLOBALS));
283         
284          $res =
285          '<div id="debug"><div>'.
286          '<p>memory usage: '.memory_get_usage().' ('.files::size(memory_get_usage()).')</p>';
287         
288          if (function_exists('xdebug_get_profiler_filename'))
289          {
290               $res .= '<p>Elapsed time: '.xdebug_time_index().' seconds</p>';
291               
292               $prof_file = xdebug_get_profiler_filename();
293               if ($prof_file) {
294                    $res .= '<p>Profiler file : '.xdebug_get_profiler_filename().'</p>';
295               } else {
296                    $prof_url = http::getSelfURI();
297                    $prof_url .= (strpos($prof_url,'?') === false) ? '?' : '&';
298                    $prof_url .= 'XDEBUG_PROFILE';
299                    $res .= '<p><a href="'.html::escapeURL($prof_url).'">Trigger profiler</a></p>';
300               }
301               
302               /* xdebug configuration:
303               zend_extension = /.../xdebug.so
304               xdebug.auto_trace = On
305               xdebug.trace_format = 0
306               xdebug.trace_options = 1
307               xdebug.show_mem_delta = On
308               xdebug.profiler_enable = 0
309               xdebug.profiler_enable_trigger = 1
310               xdebug.profiler_output_dir = /tmp
311               xdebug.profiler_append = 0
312               xdebug.profiler_output_name = timestamp
313               */
314          }
315         
316          $res .=
317          '<p>Global vars: '.$global_vars.'</p>'.
318          '</div></div>';
319         
320          return $res;
321     }
322     
323     public static function help($page,$index='')
324     {
325          # Deprecated but we keep this for plugins.
326     }
327     
328     public static function helpBlock()
329     {
330          $args = func_get_args();
331          if (empty($args)) {
332               return;
333          };
334         
335          global $__resources;
336          if (empty($__resources['help'])) {
337               return;
338          }
339         
340          $content = '';
341          foreach ($args as $v)
342          {
343               if (is_object($v) && isset($v->content)) {
344                    $content .= $v->content;
345                    continue;
346               }
347               
348               if (!isset($__resources['help'][$v])) {
349                    continue;
350               }
351               $f = $__resources['help'][$v];
352               if (!file_exists($f) || !is_readable($f)) {
353                    continue;
354               }
355               
356               $fc = file_get_contents($f);
357               if (preg_match('|<body[^>]*?>(.*?)</body>|ms',$fc,$matches)) {
358                    $content .= $matches[1];
359               } else {
360                    $content .= $fc;
361               }
362          }
363         
364          if (trim($content) == '') {
365               return;
366          }
367         
368          echo
369          '<div id="help"><hr /><div class="help-content clear"><h2>'.__('Help').'</h2>'.
370          $content.
371          '</div></div>';
372     }
373     
374     public static function jsLoad($src)
375     {
376          $escaped_src = html::escapeHTML($src);
377          if (!isset(self::$loaded_js[$escaped_src])) {
378               self::$loaded_js[$escaped_src]=true;
379               return '<script type="text/javascript" src="'.$escaped_src.'"></script>'."\n";
380          }
381     }
382     
383     public static function jsVar($n,$v)
384     {
385          return $n." = '".html::escapeJS($v)."';\n";
386     }
387     
388     public static function jsCommon()
389     {
390          return
391          self::jsLoad('js/jquery/jquery.js').
392          self::jsLoad('js/jquery/jquery.biscuit.js').
393          self::jsLoad('js/jquery/jquery.bgFade.js').
394          self::jsLoad('js/jquery/jquery.constantfooter.js').
395          self::jsLoad('js/common.js').
396          self::jsLoad('js/prelude.js').
397         
398          '<script type="text/javascript">'."\n".
399          "//<![CDATA[\n".
400          self::jsVar('dotclear.nonce',$GLOBALS['core']->getNonce()).
401         
402          self::jsVar('dotclear.img_plus_src','images/expand.png').
403          self::jsVar('dotclear.img_plus_alt',__('uncover')).
404          self::jsVar('dotclear.img_minus_src','images/hide.png').
405          self::jsVar('dotclear.img_minus_alt',__('hide')).
406          self::jsVar('dotclear.img_menu_on','images/menu_on.png').
407          self::jsVar('dotclear.img_menu_off','images/menu_off.png').
408         
409          self::jsVar('dotclear.msg.help',
410               __('help')).
411          self::jsVar('dotclear.msg.no_selection',
412               __('no selection')).
413          self::jsVar('dotclear.msg.select_all',
414               __('select all')).
415          self::jsVar('dotclear.msg.invert_sel',
416               __('invert selection')).
417          self::jsVar('dotclear.msg.website',
418               __('Web site:')).
419          self::jsVar('dotclear.msg.email',
420               __('Email:')).
421          self::jsVar('dotclear.msg.ip_address',
422               __('IP address:')).
423          self::jsVar('dotclear.msg.error',
424               __('Error:')).
425          self::jsVar('dotclear.msg.entry_created',
426               __('Entry has been successfully created.')).
427          self::jsVar('dotclear.msg.edit_entry',
428               __('Edit entry')).
429          self::jsVar('dotclear.msg.view_entry',
430               __('view entry')).
431          self::jsVar('dotclear.msg.confirm_delete_posts',
432               __("Are you sure you want to delete selected entries (%s)?")).
433          self::jsVar('dotclear.msg.confirm_delete_post',
434               __("Are you sure you want to delete this entry?")).
435          self::jsVar('dotclear.msg.confirm_spam_delete',
436               __('Are you sure you want to delete all spams?')).
437          self::jsVar('dotclear.msg.cannot_delete_users',
438               __('Users with posts cannot be deleted.')).
439          self::jsVar('dotclear.msg.confirm_delete_user',
440               __('Are you sure you want to delete selected users (%s)?')).
441          self::jsVar('dotclear.msg.confirm_extract_current',
442               __('Are you sure you want to extract archive in current directory?')).
443          self::jsVar('dotclear.msg.confirm_remove_attachment',
444               __('Are you sure you want to remove attachment "%s"?')).
445          self::jsVar('dotclear.msg.confirm_delete_lang',
446               __('Are you sure you want to delete "%s" language?')).
447          self::jsVar('dotclear.msg.confirm_delete_plugin',
448               __('Are you sure you want to delete "%s" plugin?')).
449          self::jsVar('dotclear.msg.use_this_theme',
450               __('Use this theme')).
451          self::jsVar('dotclear.msg.remove_this_theme',
452               __('Remove this theme')).
453          self::jsVar('dotclear.msg.confirm_delete_theme',
454               __('Are you sure you want to delete "%s" theme?')).
455          self::jsVar('dotclear.msg.zip_file_content',
456               __('Zip file content')).
457          self::jsVar('dotclear.msg.xhtml_validator',
458               __('XHTML markup validator')).
459          self::jsVar('dotclear.msg.xhtml_valid',
460               __('XHTML content is valid.')).
461          self::jsVar('dotclear.msg.xhtml_not_valid',
462               __('There are XHTML markup errors.')).
463          self::jsVar('dotclear.msg.confirm_change_post_format',
464               __('You have unsaved changes. Switch post format will loose these changes. Proceed anyway?')).
465          self::jsVar('dotclear.msg.load_enhanced_uploader',
466               __('Loading enhanced uploader, please wait.')).
467          "\n//]]>\n".
468          "</script>\n";
469     }
470     
471     public static function jsLoadIE7()
472     {
473          return
474          '<!--[if lt IE 8]>'."\n".
475          self::jsLoad('js/ie7/IE8.js').
476          '<link rel="stylesheet" type="text/css" href="style/iesucks.css" />'."\n".
477          '<![endif]-->'."\n";
478     }
479     
480     public static function jsConfirmClose()
481     {
482          $args = func_get_args();
483          if (count($args) > 0) {
484               foreach ($args as $k => $v) {
485                    $args[$k] = "'".html::escapeJS($v)."'";
486               }
487               $args = implode(',',$args);
488          } else {
489               $args = '';
490          }
491         
492          return
493          self::jsLoad('js/confirm-close.js').
494          '<script type="text/javascript">'."\n".
495          "//<![CDATA[\n".
496          "confirmClosePage = new confirmClose(".$args."); ".
497          "confirmClose.prototype.prompt = '".html::escapeJS(__('You have unsaved changes.'))."'; ".
498          "\n//]]>\n".
499          "</script>\n";
500     }
501     
502     public static function jsPageTabs($default=null)
503     {
504          if ($default) {
505               $default = "'".html::escapeJS($default)."'";
506          }
507         
508          return
509          self::jsLoad('js/jquery/jquery.pageTabs.js').
510          '<script type="text/javascript">'."\n".
511          "//<![CDATA[\n".
512          "\$(function() {\n".
513          "    \$.pageTabs(".$default.");\n".
514          "});\n".
515          "\n//]]>\n".
516          "</script>\n";
517     }
518     
519     public static function jsModal()
520     {
521          return
522          '<link rel="stylesheet" type="text/css" href="style/modal/modal.css" />'."\n".
523          self::jsLoad('js/jquery/jquery.modal.js').
524          '<script type="text/javascript">'."\n".
525          "//<![CDATA[\n".
526          self::jsVar('$.modal.prototype.params.loader_img','style/modal/loader.gif').
527          self::jsVar('$.modal.prototype.params.close_img','style/modal/close.png').
528          "\n//]]>\n".
529          "</script>\n";
530     }
531     
532     public static function jsColorPicker()
533     {
534          return
535          '<link rel="stylesheet" type="text/css" href="style/farbtastic/farbtastic.css" />'."\n".
536          self::jsLoad('js/jquery/jquery.farbtastic.js').
537          self::jsLoad('js/color-picker.js');
538     }
539     
540     public static function jsDatePicker()
541     {
542          return
543          '<link rel="stylesheet" type="text/css" href="style/date-picker.css" />'."\n".
544          self::jsLoad('js/date-picker.js').
545          '<script type="text/javascript">'."\n".
546          "//<![CDATA[\n".
547         
548          "datePicker.prototype.months[0] = '".html::escapeJS(__('January'))."'; ".
549          "datePicker.prototype.months[1] = '".html::escapeJS(__('February'))."'; ".
550          "datePicker.prototype.months[2] = '".html::escapeJS(__('March'))."'; ".
551          "datePicker.prototype.months[3] = '".html::escapeJS(__('April'))."'; ".
552          "datePicker.prototype.months[4] = '".html::escapeJS(__('May'))."'; ".
553          "datePicker.prototype.months[5] = '".html::escapeJS(__('June'))."'; ".
554          "datePicker.prototype.months[6] = '".html::escapeJS(__('July'))."'; ".
555          "datePicker.prototype.months[7] = '".html::escapeJS(__('August'))."'; ".
556          "datePicker.prototype.months[8] = '".html::escapeJS(__('September'))."'; ".
557          "datePicker.prototype.months[9] = '".html::escapeJS(__('October'))."'; ".
558          "datePicker.prototype.months[10] = '".html::escapeJS(__('November'))."'; ".
559          "datePicker.prototype.months[11] = '".html::escapeJS(__('December'))."'; ".
560         
561          "datePicker.prototype.days[0] = '".html::escapeJS(__('Monday'))."'; ".
562          "datePicker.prototype.days[1] = '".html::escapeJS(__('Tuesday'))."'; ".
563          "datePicker.prototype.days[2] = '".html::escapeJS(__('Wednesday'))."'; ".
564          "datePicker.prototype.days[3] = '".html::escapeJS(__('Thursday'))."'; ".
565          "datePicker.prototype.days[4] = '".html::escapeJS(__('Friday'))."'; ".
566          "datePicker.prototype.days[5] = '".html::escapeJS(__('Saturday'))."'; ".
567          "datePicker.prototype.days[6] = '".html::escapeJS(__('Sunday'))."'; ".
568         
569          "datePicker.prototype.img_src = 'images/date-picker.png'; ".
570         
571          "datePicker.prototype.close_msg = '".html::escapeJS(__('close'))."'; ".
572          "datePicker.prototype.now_msg = '".html::escapeJS(__('now'))."'; ".
573         
574          "\n//]]>\n".
575          "</script>\n";
576     }
577     
578     
579     public static function jsToolMan()
580     {
581          return
582          '<script type="text/javascript" src="js/tool-man/core.js"></script>'.
583          '<script type="text/javascript" src="js/tool-man/events.js"></script>'.
584          '<script type="text/javascript" src="js/tool-man/css.js"></script>'.
585          '<script type="text/javascript" src="js/tool-man/coordinates.js"></script>'.
586          '<script type="text/javascript" src="js/tool-man/drag.js"></script>'.
587          '<script type="text/javascript" src="js/tool-man/dragsort.js"></script>'.
588          '<script type="text/javascript" src="js/dragsort-tablerows.js"></script>';
589     }
590     
591     public static function jsMetaEditor()
592     {
593          return
594          '<script type="text/javascript" src="js/meta-editor.js"></script>';
595     }
596}
597?>
Note: See TracBrowser for help on using the repository browser.

Sites map