Dotclear

source: inc/admin/lib.dc.page.php @ 3639:fe9f4d94f86b

Revision 3639:fe9f4d94f86b, 36.6 KB checked in by franck <carnet.franck.paul@…>, 8 years ago (diff)

Add required attribute for mandatory fields

RevLine 
[0]1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
[1179]6# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
[0]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{
[2503]18     private static $loaded_js = array();
[3021]19     private static $loaded_css = array();
[2909]20     private static $xframe_loaded = false;
[2328]21     private static $N_TYPES = array(
[2503]22          "success" => "success",
23          "warning" => "warning-msg",
24          "error" => "error",
25          "message" => "message",
[2328]26          "static" => "static-msg");
[342]27
[0]28     # Auth check
29     public static function check($permissions)
30     {
31          global $core;
[1187]32
[2503]33          if ($core->blog && $core->auth->check($permissions,$core->blog->id)) {
[0]34               return;
35          }
[1187]36
[0]37          if (session_id()) {
38               $core->session->destroy();
39          }
40          http::redirect(DC_AUTH_PAGE);
41     }
[1187]42
[0]43     # Check super admin
44     public static function checkSuper()
45     {
46          global $core;
[1187]47
[0]48          if (!$core->auth->isSuperAdmin())
49          {
50               if (session_id()) {
51                    $core->session->destroy();
52               }
53               http::redirect(DC_AUTH_PAGE);
54          }
55     }
[1187]56
[0]57     # Top of admin page
[2907]58     public static function open($title='',$head='',$breadcrumb='',$options=array())
[0]59     {
60          global $core;
[1144]61
[0]62          # List of user's blogs
[2159]63          if ($core->auth->getBlogCount() == 1 || $core->auth->getBlogCount() > 20)
[0]64          {
65               $blog_box =
[999]66               '<p>'.__('Blog:').' <strong title="'.html::escapeHTML($core->blog->url).'">'.
[0]67               html::escapeHTML($core->blog->name).'</strong>';
[1187]68
[2159]69               if ($core->auth->getBlogCount() > 20) {
[2720]70                    $blog_box .= ' - <a href="'.$core->adminurl->get("admin.blogs").'">'.__('Change blog').'</a>';
[0]71               }
[999]72               $blog_box .= '</p>';
[0]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 =
[2005]82               '<p><label for="switchblog" class="classic">'.
[1309]83               __('Blogs:').'</label> '.
[0]84               $core->formNonce().
[454]85               form::combo('switchblog',$blogs,$core->blog->id).
[2005]86               '<input type="submit" value="'.__('ok').'" class="hidden-if-js" /></p>';
[0]87          }
[1187]88
[36]89          $safe_mode = isset($_SESSION['sess_safe_mode']) && $_SESSION['sess_safe_mode'];
[1187]90
[0]91          # Display
[3292]92          $headers = new ArrayObject(array());
[2792]93
[3279]94          # Content-Type
95          $headers['content-type'] = 'Content-Type: text/html; charset=UTF-8';
96
[3619]97          # Referrer Policy for admin pages
98          $headers['referrer'] = 'Referrer-Policy: strict-origin';
99
[3279]100          # Prevents Clickjacking as far as possible
[2907]101          if (isset($options['x-frame-allow'])) {
[3279]102               self::setXFrameOptions($headers,$options['x-frame-allow']);
[2907]103          } else {
[3279]104               self::setXFrameOptions($headers);
[2907]105          }
[3276]106
[3492]107          # Content-Security-Policy (only if safe mode if not active, it may help)
108          if (!$safe_mode && $core->blog->settings->system->csp_admin_on) {
[3292]109               // Get directives from settings if exist, else set defaults
110               $csp = new ArrayObject(array());
[3432]111
112               // SQlite Clearbricks driver does not allow using single quote at beginning or end of a field value
113               // so we have to use neutral values (localhost and 127.0.0.1) for some CSP directives
114               $csp_prefix = $core->con->driver() == 'sqlite' ? 'localhost ' : '';   // Hack for SQlite Clearbricks driver
115               $csp_suffix = $core->con->driver() == 'sqlite' ? ' 127.0.0.1' : '';   // Hack for SQlite Clearbricks driver
116
117               $csp['default-src'] = $core->blog->settings->system->csp_admin_default ?:
118                    $csp_prefix."'self'".$csp_suffix;
119               $csp['script-src'] = $core->blog->settings->system->csp_admin_script ?:
120                    $csp_prefix."'self' 'unsafe-inline' 'unsafe-eval'".$csp_suffix;
121               $csp['style-src'] = $core->blog->settings->system->csp_admin_style ?:
122                    $csp_prefix."'self' 'unsafe-inline'".$csp_suffix;
123               $csp['img-src'] = $core->blog->settings->system->csp_admin_img ?:
[3599]124                    $csp_prefix."'self' data: http://media.dotaddict.org blob:";
[3292]125
[3307]126               # Cope with blog post preview (via public URL in iframe)
127               if (!is_null($core->blog->host)) {
128                    $csp['default-src'] .= ' '.parse_url($core->blog->host,PHP_URL_HOST);
[3509]129                    $csp['script-src'] .= ' '.parse_url($core->blog->host,PHP_URL_HOST);
130                    $csp['style-src'] .= ' '.parse_url($core->blog->host,PHP_URL_HOST);
[3307]131               }
132               # Cope with media display in media manager (via public URL)
133               if (!is_null($core->media)) {
134                    $csp['img-src'] .= ' '.parse_url($core->media->root_url,PHP_URL_HOST);
135               }
[3319]136               # Allow everything in iframe (used by editors to preview public content)
137               $csp['child-src'] = "*";
[3307]138
[3292]139               # --BEHAVIOR-- adminPageHTTPHeaderCSP
140               $core->callBehavior('adminPageHTTPHeaderCSP',$csp);
141
142               // Construct CSP header
143               $directives = array();
144               foreach ($csp as $key => $value) {
145                    if ($value) {
146                         $directives[] = $key.' '.$value;
147                    }
148               }
149               if (count($directives)) {
150                    if (version_compare(phpversion(),'5.4','>=')) {
151                         // csp_report.php needs PHP ≥ 5.4
152                         $directives[] = "report-uri ".DC_ADMIN_URL."csp_report.php";
153                    }
[3326]154                    $report_only = ($core->blog->settings->system->csp_admin_report_only) ? '-Report-Only' : '';
155                    $headers['csp'] = "Content-Security-Policy".$report_only.": ".implode(" ; ",$directives);
[3292]156               }
[3291]157          }
[3279]158
159          # --BEHAVIOR-- adminPageHTTPHeaders
160          $core->callBehavior('adminPageHTTPHeaders',$headers);
161          foreach ($headers as $key => $value) {
162               header($value);
163          }
[3276]164
[0]165          echo
[2760]166          '<!DOCTYPE html>'.
167          '<html lang="'.$core->auth->getInfo('user_lang').'">'."\n".
[0]168          "<head>\n".
[2760]169          '  <meta charset="UTF-8" />'."\n".
[0]170          '  <meta name="ROBOTS" content="NOARCHIVE,NOINDEX,NOFOLLOW" />'."\n".
171          '  <meta name="GOOGLEBOT" content="NOSNIPPET" />'."\n".
[1310]172          '  <meta name="viewport" content="width=device-width, initial-scale=1.0" />'."\n".
[489]173          '  <title>'.$title.' - '.html::escapeHTML($core->blog->name).' - '.html::escapeHTML(DC_VENDOR_NAME).' - '.DC_VERSION.'</title>'."\n".
[1187]174
175
[3021]176          self::cssLoad('style/default.css');
[0]177          if (l10n::getTextDirection($GLOBALS['_lang']) == 'rtl') {
[3021]178               echo self::cssLoad('style/default-rtl.css');
[0]179          }
[237]180
[244]181          $core->auth->user_prefs->addWorkspace('interface');
[3639]182          if (!$core->auth->user_prefs->interface->hide_std_favicon) {
[2503]183               echo
[3021]184               '<link rel="icon" type="image/png" href="images/favicon96-login.png" />'."\n".
185               '<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />'."\n";
[244]186          }
[3408]187
188          if ($core->auth->user_prefs->interface->htmlfontsize) {
189               echo
190               '<script type="text/javascript">'."\n".
[3421]191               self::jsVar('dotclear_htmlFontSize',$core->auth->user_prefs->interface->htmlfontsize)."\n".
[3408]192               "</script>\n";
193          }
194
[0]195          echo
196          self::jsCommon().
[1699]197          self::jsToggles().
[0]198          $head;
[1187]199
[3398]200          if ($core->auth->user_prefs->interface->hidemoreinfo) {
201               echo
202               '<script type="text/javascript">'."\n".
[3421]203               'dotclear.hideMoreInfo = true;'."\n".
[3398]204               "</script>\n";
205          }
[3637]206          if ($core->auth->user_prefs->interface->showajaxloader) {
207               echo
208               '<script type="text/javascript">'."\n".
209               'dotclear.showAjaxLoader = true;'."\n".
210               "</script>\n";
211          }
[3398]212
[0]213          # --BEHAVIOR-- adminPageHTMLHead
214          $core->callBehavior('adminPageHTMLHead');
[1187]215
[0]216          echo
217          "</head>\n".
[36]218          '<body id="dotclear-admin'.
[3499]219          ($safe_mode ? ' safe-mode' : '').'" class="no-js'.
220          ($core->auth->user_prefs->interface->dynfontsize ? ' responsive-font' : '').'">'."\n".
[1187]221
[1590]222          '<ul id="prelude">'.
223          '<li><a href="#content">'.__('Go to the content').'</a></li>'.
224          '<li><a href="#main-menu">'.__('Go to the menu').'</a></li>'.
225          '<li><a href="#qx">'.__('Go to search').'</a></li>'.
[2304]226          '<li><a href="#help">'.__('Go to help').'</a></li>'.
[1590]227          '</ul>'."\n".
[2784]228          '<div id="header" role="banner">'.
[2720]229          '<h1><a href="'.$core->adminurl->get("admin.home").'"><span class="hidden">'.DC_VENDOR_NAME.'</span></a></h1>'."\n";
[1187]230
[0]231          echo
[2720]232          '<form action="'.$core->adminurl->get("admin.home").'" method="post" id="top-info-blog">'.
[0]233          $blog_box.
[2225]234          '<p><a href="'.$core->blog->url.'" class="outgoing" title="'.__('Go to site').
235          '">'.__('Go to site').'<img src="images/outgoing.png" alt="" /></a>'.
[999]236          '</p></form>'.
[2005]237          '<ul id="top-info-user">'.
[2817]238          '<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>'.
239          '<li><a class="smallscreen'.(preg_match('/'.preg_quote($core->adminurl->get('admin.user.preferences')).'(\?.*)?$/',$_SERVER['REQUEST_URI']) ? ' active' : '').
[2720]240          '" href="'.$core->adminurl->get("admin.user.preferences").'">'.__('My preferences').'</a></li>'.
241          '<li><a href="'.$core->adminurl->get("admin.home",array('logout' => 1)).'" class="logout"><span class="nomobile">'.sprintf(__('Logout %s'),$core->auth->userID()).
[2034]242          '</span><img src="images/logout.png" alt="" /></a></li>'.
[2005]243          '</ul>'.
244          '</div>'; // end header
[1187]245
[0]246          echo
[1741]247          '<div id="wrapper" class="clearfix">'."\n".
[3445]248          '<div class="hidden-if-no-js collapser-box"><button type="button" id="collapser" class="void-btn">'.
[3355]249          '<img class="collapse-mm visually-hidden" src="images/collapser-hide.png" alt="'.__('Hide main menu').'" />'.
250          '<img class="expand-mm visually-hidden" src="images/collapser-show.png" alt="'.__('Show main menu').'" />'.
[3434]251          '</button></div>'.
[2784]252          '<div id="main" role="main">'."\n".
[1741]253          '<div id="content" class="clearfix">'."\n";
[1187]254
[36]255          # Safe mode
256          if ($safe_mode)
[0]257          {
258               echo
[2787]259               '<div class="warning" role="alert"><h3>'.__('Safe mode').'</h3>'.
[37]260               '<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>'.
[0]261               '</div>';
262          }
[1187]263
[3076]264          // Display breadcrumb (if given) before any error messages
[1357]265          echo $breadcrumb;
[1355]266
[3076]267          // Display notices and errors
[2199]268          echo self::notices();
269     }
270
271     public static function notices()
272     {
[3076]273          global $core;
274          static $error_displayed = false;
[3457]275
[3076]276          $res = '';
277
278          // return error messages if any
279          if ($core->error->flag() && !$error_displayed) {
[3457]280
281               # --BEHAVIOR-- adminPageNotificationError
[3459]282               $notice_error = $core->callBehavior('adminPageNotificationError',$core,$core->error);
[3457]283
[3458]284               if (isset($notice_error) && !empty($notice_error)) {
[3457]285                    $res .= $notice_error;
286               } else {
287                    $res .= '<div class="error"><p>'.
288                         '<strong>'.(count($core->error->getErrors()) > 1 ? __('Errors:') : __('Error:')).'</strong>'.
289                         '</p>'.$core->error->toHTML().'</div>';
290               }
[3076]291               $error_displayed = true;
292          }
293
[2199]294          // return notices if any
[2181]295          if (isset($_SESSION['notifications'])) {
[2328]296               foreach ($_SESSION['notifications'] as $notification) {
[3457]297
298                    # --BEHAVIOR-- adminPageNotification
[3459]299                    $notice = $core->callBehavior('adminPageNotification',$core,$notification);
[3457]300
[3458]301                    $res .= (isset($notice) && !empty($notice) ? $notice : self::getNotification($notification));
[2181]302               }
303               unset($_SESSION['notifications']);
304          }
[2199]305          return $res;
[0]306     }
[2191]307
[2328]308     public static function addNotice($type,$message,$options=array())
[2191]309     {
[2328]310          if (isset(self::$N_TYPES[$type])){
311               $class = self::$N_TYPES[$type];
312          } else {
313               $class=$type;
314          }
315          if (isset($_SESSION['notifications']) && is_array($_SESSION['notifications'])) {
316               $notifications = $_SESSION['notifications'];
317          } else {
318               $notifications = array();
319          }
[2503]320
[2328]321          $n = array_merge($options,array('class' => $class,'ts' => time(), 'text' => $message));
322          if ($type != "static") {
323               $notifications[] = $n;
324          } else {
325               array_unshift($notifications, $n);
326          }
327          $_SESSION['notifications'] = $notifications;
[2181]328     }
[2191]329
[2328]330     public static function addSuccessNotice($message,$options=array())
[2191]331     {
[2328]332          self::addNotice("success",$message,$options);
[2181]333     }
[2191]334
[2328]335     public static function addWarningNotice($message,$options=array())
[2191]336     {
[2328]337          self::addNotice("warning",$message,$options);
[2181]338     }
[2191]339
[2328]340     public static function addErrorNotice($message,$options=array())
[2191]341     {
[2328]342          self::addNotice("error",$message,$options);
[2191]343     }
344
[2328]345     protected static function getNotification($n)
[2191]346     {
[2181]347          global $core;
[3340]348          $tag = (isset($n['divtag']) && $n['divtag']) ? 'div' : 'p';
[2328]349          $ts = '';
350          if (!isset($n['with_ts']) || ($n['with_ts'] == true)) {
351               $ts = dt::str(__('[%H:%M:%S]'),$n['ts'],$core->auth->getInfo('user_tz')).' ';
352          }
[2787]353          $res = '<'.$tag.' class="'.$n['class'].'" role="alert">'.$ts.$n['text'].'</'.$tag.'>';
[2191]354          return $res;
[2181]355     }
[2191]356
[0]357     public static function close()
358     {
[942]359          global $core;
360
[1933]361          if (!$GLOBALS['__resources']['ctxhelp']) {
[3566]362               if (!$core->auth->user_prefs->interface->hidehelpbutton) {
363                    echo
364                    '<p id="help-button"><a href="'.$core->adminurl->get("admin.help").'" class="outgoing" title="'.
365                    __('Global help').'">'.__('Global help').'</a></p>';
366               }
[1933]367          }
368
[0]369          $menu =& $GLOBALS['_menu'];
[1187]370
[0]371          echo
372          "</div>\n".         // End of #content
373          "</div>\n".         // End of #main
[1187]374
[2784]375          '<div id="main-menu" role="navigation">'."\n".
[1311]376
[2769]377          '<form id="search-menu" action="'.$core->adminurl->get("admin.search").'" method="get" role="search">'.
[1589]378          '<p><label for="qx" class="hidden">'.__('Search:').' </label>'.form::field('qx',30,255,'').
[1311]379          '<input type="submit" value="'.__('OK').'" /></p>'.
380          '</form>';
[1187]381
[0]382          foreach ($menu as $k => $v) {
383               echo $menu[$k]->draw();
384          }
[1187]385
[1140]386          $text = sprintf(__('Thank you for using %s.'),'Dotclear '.DC_VERSION);
[942]387
388          # --BEHAVIOR-- adminPageFooter
[946]389          $textAlt = $core->callBehavior('adminPageFooter',$core,$text);
[1140]390          if ($textAlt != '') {
391               $text = $textAlt;
392          }
[1142]393          $text = html::escapeHTML($text);
[942]394
[0]395          echo
396          '</div>'."\n".      // End of #main-menu
[1946]397          "</div>\n";         // End of #wrapper
[1861]398
[3294]399          echo '<p id="gototop"><a href="#wrapper">'.__('Page top').'</a></p>'."\n";
400
[3060]401          $figure = "
[3224]402   /\_/\
403  (='.'=)
[3454]404  (\")-(\")";
[3060]405
[1946]406          echo
[2784]407          '<div id="footer" role="contentinfo">'.
[2296]408          '<a href="http://dotclear.org/" title="'.$text.'">'.
409          '<img src="style/dc_logos/w-dotclear90.png" alt="'.$text.'" /></a></div>'."\n".
[2796]410          "<!-- "."\n".
[3060]411          $figure.
[2796]412          " -->"."\n";
[1187]413
[0]414          if (defined('DC_DEV') && DC_DEV === true) {
415               echo self::debugInfo();
416          }
[1187]417
[0]418          echo
419          '</body></html>';
420     }
[1187]421
[1358]422     public static function openPopup($title='',$head='',$breadcrumb='')
[0]423     {
424          global $core;
[1187]425
[0]426          # Display
427          header('Content-Type: text/html; charset=UTF-8');
[2792]428
[3619]429          # Referrer Policy for admin pages
430          header('Referrer-Policy: strict-origin');
431
432          # Prevents Clickjacking as far as possible
[2792]433          header('X-Frame-Options: SAMEORIGIN'); // FF 3.6.9+ Chrome 4.1+ IE 8+ Safari 4+ Opera 10.5+
434
[0]435          echo
[2760]436          '<!DOCTYPE html>'.
437          '<html lang="'.$core->auth->getInfo('user_lang').'">'."\n".
[0]438          "<head>\n".
[2760]439          '  <meta charset="UTF-8" />'."\n".
[2513]440          '  <meta name="viewport" content="width=device-width, initial-scale=1.0" />'."\n".
[0]441          '  <title>'.$title.' - '.html::escapeHTML($core->blog->name).' - '.html::escapeHTML(DC_VENDOR_NAME).' - '.DC_VERSION.'</title>'."\n".
[1187]442
[0]443          '  <meta name="ROBOTS" content="NOARCHIVE,NOINDEX,NOFOLLOW" />'."\n".
444          '  <meta name="GOOGLEBOT" content="NOSNIPPET" />'."\n".
[1187]445
[3021]446          self::cssLoad('style/default.css');
[0]447          if (l10n::getTextDirection($GLOBALS['_lang']) == 'rtl') {
[3021]448               echo self::cssLoad('style/default-rtl.css');
[0]449          }
[1187]450
[3408]451          $core->auth->user_prefs->addWorkspace('interface');
452          if ($core->auth->user_prefs->interface->htmlfontsize) {
453               echo
454               '<script type="text/javascript">'."\n".
[3421]455               self::jsVar('dotclear_htmlFontSize',$core->auth->user_prefs->interface->htmlfontsize)."\n".
[3408]456               "</script>\n";
457          }
458
[0]459          echo
460          self::jsCommon().
[1699]461          self::jsToggles().
[0]462          $head;
[1187]463
[3398]464          if ($core->auth->user_prefs->interface->hidemoreinfo) {
465               echo
466               '<script type="text/javascript">'."\n".
[3421]467               'dotclear.hideMoreInfo = true;'."\n".
[3398]468               "</script>\n";
469          }
[3637]470          if ($core->auth->user_prefs->interface->showajaxloader) {
471               echo
472               '<script type="text/javascript">'."\n".
473               'dotclear.showAjaxLoader = true;'."\n".
474               "</script>\n";
475          }
[3398]476
[0]477          # --BEHAVIOR-- adminPageHTMLHead
478          $core->callBehavior('adminPageHTMLHead');
[1187]479
[0]480          echo
481          "</head>\n".
[3499]482          '<body id="dotclear-admin" class="popup'.
483          ($core->auth->user_prefs->interface->dynfontsize ? ' responsive-font' : '').'">'."\n".
[1187]484
[2046]485          '<h1>'.DC_VENDOR_NAME.'</h1>'."\n";
[1187]486
[0]487          echo
488          '<div id="wrapper">'."\n".
[2784]489          '<div id="main" role="main">'."\n".
[0]490          '<div id="content">'."\n";
[1187]491
[1358]492          // display breadcrumb if given
493          echo $breadcrumb;
494
[3076]495          // Display notices and errors
496          echo self::notices();
[0]497     }
[1187]498
[0]499     public static function closePopup()
500     {
501          echo
502          "</div>\n".         // End of #content
503          "</div>\n".         // End of #main
[2046]504          "</div>\n".         // End of #wrapper
[3294]505
506          '<p id="gototop"><a href="#wrapper">'.__('Page top').'</a></p>'."\n".
507
[2784]508          '<div id="footer" role="contentinfo"><p>&nbsp;</p></div>'."\n".
[0]509          '</body></html>';
510     }
[907]511
[2166]512     public static function breadcrumb($elements=null,$options=array())
[1328]513     {
[2720]514          global $core;
[3340]515          $with_home_link = isset($options['home_link']) ? $options['home_link'] : true;
516          $hl = isset($options['hl']) ? $options['hl'] : true;
517          $hl_pos = isset($options['hl_pos']) ? $options['hl_pos'] : -1;
[1328]518          // First item of array elements should be blog's name, System or Plugins
[1340]519          $res = '<h2>'.($with_home_link ?
[2720]520               '<a class="go_home" href="'.$core->adminurl->get("admin.home").'"><img src="style/dashboard.png" alt="'.__('Go to dashboard').'" /></a>' :
[1340]521               '<img src="style/dashboard-alt.png" alt="" />');
[1328]522          $index = 0;
[2167]523          if ($hl_pos < 0) {
524               $hl_pos = count($elements)+$hl_pos;
[2166]525          }
[1328]526          foreach ($elements as $element => $url) {
[2167]527               if ($hl && $index == $hl_pos) {
[2166]528                    $element = sprintf('<span class="page-title">%s</span>',$element);
529               }
[1358]530               $res .= ($with_home_link ? ($index == 1 ? ' : ' : ' &rsaquo; ') : ($index == 0 ? ' ' : ' &rsaquo; ')).
531                    ($url ? '<a href="'.$url.'">' : '').$element.($url ? '</a>' : '');
[1328]532               $index++;
533          }
534          $res .= '</h2>';
535          return $res;
536     }
537
[1548]538     public static function message($msg,$timestamp=true,$div=false,$echo=true,$class='message')
[907]539     {
[910]540          global $core;
[1187]541
[907]542          $res = '';
543          if ($msg != '') {
[1548]544               $res = ($div ? '<div class="'.$class.'">' : '').'<p'.($div ? '' : ' class="'.$class.'"').'>'.
[2191]545               ($timestamp ? dt::str(__('[%H:%M:%S]'),null,$core->auth->getInfo('user_tz')).' ' : '').$msg.
[1161]546               '</p>'.($div ? '</div>' : '');
[907]547               if ($echo) {
548                    echo $res;
549               }
550          }
551          return $res;
552     }
[1187]553
[1548]554     public static function success($msg,$timestamp=true,$div=false,$echo=true)
555     {
[1927]556          return self::message($msg,$timestamp,$div,$echo,"success");
[1548]557     }
558
[1725]559     public static function warning($msg,$timestamp=true,$div=false,$echo=true)
560     {
[1927]561          return self::message($msg,$timestamp,$div,$echo,"warning-msg");
[1725]562     }
563
[0]564     private static function debugInfo()
565     {
566          $global_vars = implode(', ',array_keys($GLOBALS));
[1187]567
[0]568          $res =
569          '<div id="debug"><div>'.
570          '<p>memory usage: '.memory_get_usage().' ('.files::size(memory_get_usage()).')</p>';
[1187]571
[0]572          if (function_exists('xdebug_get_profiler_filename'))
573          {
574               $res .= '<p>Elapsed time: '.xdebug_time_index().' seconds</p>';
[1187]575
[0]576               $prof_file = xdebug_get_profiler_filename();
577               if ($prof_file) {
578                    $res .= '<p>Profiler file : '.xdebug_get_profiler_filename().'</p>';
579               } else {
580                    $prof_url = http::getSelfURI();
[321]581                    $prof_url .= (strpos($prof_url,'?') === false) ? '?' : '&';
[0]582                    $prof_url .= 'XDEBUG_PROFILE';
[321]583                    $res .= '<p><a href="'.html::escapeURL($prof_url).'">Trigger profiler</a></p>';
[0]584               }
[1187]585
[0]586               /* xdebug configuration:
587               zend_extension = /.../xdebug.so
588               xdebug.auto_trace = On
589               xdebug.trace_format = 0
590               xdebug.trace_options = 1
591               xdebug.show_mem_delta = On
592               xdebug.profiler_enable = 0
593               xdebug.profiler_enable_trigger = 1
594               xdebug.profiler_output_dir = /tmp
595               xdebug.profiler_append = 0
596               xdebug.profiler_output_name = timestamp
597               */
598          }
[1187]599
[0]600          $res .=
601          '<p>Global vars: '.$global_vars.'</p>'.
602          '</div></div>';
[1187]603
[0]604          return $res;
605     }
[1187]606
[0]607     public static function help($page,$index='')
608     {
609          # Deprecated but we keep this for plugins.
610     }
[1187]611
[0]612     public static function helpBlock()
613     {
[2720]614          global $core;
[3566]615
616          if ($core->auth->user_prefs->interface->hidehelpbutton) {
617               return;
618          }
619
[0]620          $args = func_get_args();
[1458]621          $args = new ArrayObject($args);
622
623          # --BEHAVIOR-- adminPageHelpBlock
624          $GLOBALS['core']->callBehavior('adminPageHelpBlock',$args);
625
[0]626          if (empty($args)) {
627               return;
628          };
[1187]629
[0]630          global $__resources;
631          if (empty($__resources['help'])) {
632               return;
633          }
[1187]634
[0]635          $content = '';
636          foreach ($args as $v)
637          {
638               if (is_object($v) && isset($v->content)) {
639                    $content .= $v->content;
640                    continue;
641               }
[1187]642
[0]643               if (!isset($__resources['help'][$v])) {
644                    continue;
645               }
646               $f = $__resources['help'][$v];
647               if (!file_exists($f) || !is_readable($f)) {
648                    continue;
649               }
[1187]650
[0]651               $fc = file_get_contents($f);
652               if (preg_match('|<body[^>]*?>(.*?)</body>|ms',$fc,$matches)) {
653                    $content .= $matches[1];
654               } else {
655                    $content .= $fc;
656               }
657          }
[1187]658
[0]659          if (trim($content) == '') {
660               return;
661          }
[1187]662
[1933]663          // Set contextual help global flag
664          $GLOBALS['__resources']['ctxhelp'] = true;
665
[0]666          echo
[1573]667          '<div id="help"><hr /><div class="help-content clear"><h3>'.__('Help about this page').'</h3>'.
[0]668          $content.
[494]669          '</div>'.
670          '<div id="helplink"><hr />'.
671          '<p>'.
[2720]672          sprintf(__('See also %s'),sprintf('<a href="'.$core->adminurl->get("admin.help").'">%s</a>',__('the global help'))).
[2011]673          '.</p>'.
[0]674          '</div></div>';
675     }
[1187]676
[3086]677     public static function cssLoad($src,$media='screen',$v='')
[3021]678     {
679          $escaped_src = html::escapeHTML($src);
680          if (!isset(self::$loaded_css[$escaped_src])) {
681               self::$loaded_css[$escaped_src] = true;
[3086]682               $escaped_src = self::appendVersion($escaped_src,$v);
[3021]683
684               return '<link rel="stylesheet" href="'.$escaped_src.'" type="text/css" media="'.$media.'" />'."\n";
685          }
686     }
687
[3086]688     public static function jsLoad($src,$v='')
[0]689     {
[342]690          $escaped_src = html::escapeHTML($src);
691          if (!isset(self::$loaded_js[$escaped_src])) {
[3020]692               self::$loaded_js[$escaped_src] = true;
[3086]693               $escaped_src = self::appendVersion($escaped_src,$v);
[342]694               return '<script type="text/javascript" src="'.$escaped_src.'"></script>'."\n";
695          }
[0]696     }
[1187]697
[3086]698     private static function appendVersion($src,$v='')
[3021]699     {
[3129]700          $src .= (strpos($src,'?') === false ? '?' : '&amp;').'v=';
[3021]701          if (defined('DC_DEV') && DC_DEV === true) {
702               $src .= md5(uniqid());
703          } else {
[3086]704               $src .= ($v === '' ? DC_VERSION : $v);
[3021]705          }
706          return $src;
707     }
708
[0]709     public static function jsVar($n,$v)
710     {
711          return $n." = '".html::escapeJS($v)."';\n";
712     }
[1187]713
[1699]714     public static function jsToggles()
715     {
716          if($GLOBALS['core']->auth->user_prefs->toggles) {
717               $unfolded_sections = explode(',',$GLOBALS['core']->auth->user_prefs->toggles->unfolded_sections);
718               foreach ($unfolded_sections as $k=>&$v) {
719                    if ($v == '') {
720                         unset($unfolded_sections[$k]);
721                    } else {
722                         $v = "'".html::escapeJS($v)."':true";
723                    }
724               }
725          } else {
726               $unfolded_sections=array();
727          }
728          return '<script type="text/javascript">'."\n".
[3421]729                    'dotclear.unfolded_sections = {'.join(",",$unfolded_sections)."};\n".
[1699]730                    "</script>\n";
731     }
[2503]732
[0]733     public static function jsCommon()
734     {
[1771]735          $mute_or_no = '';
[1841]736          if (empty($GLOBALS['core']->blog) || $GLOBALS['core']->blog->settings->system->jquery_migrate_mute) {
[1771]737               $mute_or_no .=
738                    '<script type="text/javascript">'."\n".
[3421]739                    'jQuery.migrateMute = true;'."\n".
[1771]740                    "</script>\n";
741          }
742
[0]743          return
744          self::jsLoad('js/jquery/jquery.js').
[1771]745          $mute_or_no.
[3178]746          self::jsLoad('js/jquery/jquery-migrate.js').
[0]747          self::jsLoad('js/jquery/jquery.biscuit.js').
748          self::jsLoad('js/jquery/jquery.bgFade.js').
749          self::jsLoad('js/common.js').
[447]750          self::jsLoad('js/prelude.js').
[1187]751
[0]752          '<script type="text/javascript">'."\n".
[2614]753          'jsToolBar = {}, jsToolBar.prototype = { elements : {} };'."\n".
[3460]754
[0]755          self::jsVar('dotclear.nonce',$GLOBALS['core']->getNonce()).
[3460]756
[1019]757          self::jsVar('dotclear.img_plus_src','images/expand.png').
[0]758          self::jsVar('dotclear.img_plus_alt',__('uncover')).
[1019]759          self::jsVar('dotclear.img_minus_src','images/hide.png').
[0]760          self::jsVar('dotclear.img_minus_alt',__('hide')).
761          self::jsVar('dotclear.img_menu_on','images/menu_on.png').
762          self::jsVar('dotclear.img_menu_off','images/menu_off.png').
[2503]763
[2195]764          self::jsVar('dotclear.img_plus_theme_src','images/plus-theme.png').
765          self::jsVar('dotclear.img_plus_theme_alt',__('uncover')).
766          self::jsVar('dotclear.img_minus_theme_src','images/minus-theme.png').
767          self::jsVar('dotclear.img_minus_theme_alt',__('hide')).
[1187]768
[0]769          self::jsVar('dotclear.msg.help',
[1933]770               __('Need help?')).
[2225]771          self::jsVar('dotclear.msg.new_window',
772               __('new window')).
[1302]773          self::jsVar('dotclear.msg.help_hide',
774               __('Hide')).
[1556]775          self::jsVar('dotclear.msg.to_select',
776               __('Select:')).
[0]777          self::jsVar('dotclear.msg.no_selection',
778               __('no selection')).
779          self::jsVar('dotclear.msg.select_all',
780               __('select all')).
781          self::jsVar('dotclear.msg.invert_sel',
[1556]782               __('Invert selection')).
[0]783          self::jsVar('dotclear.msg.website',
784               __('Web site:')).
785          self::jsVar('dotclear.msg.email',
786               __('Email:')).
787          self::jsVar('dotclear.msg.ip_address',
788               __('IP address:')).
789          self::jsVar('dotclear.msg.error',
790               __('Error:')).
791          self::jsVar('dotclear.msg.entry_created',
792               __('Entry has been successfully created.')).
793          self::jsVar('dotclear.msg.edit_entry',
794               __('Edit entry')).
795          self::jsVar('dotclear.msg.view_entry',
796               __('view entry')).
797          self::jsVar('dotclear.msg.confirm_delete_posts',
798               __("Are you sure you want to delete selected entries (%s)?")).
[2202]799          self::jsVar('dotclear.msg.confirm_delete_medias',
800               __("Are you sure you want to delete selected medias (%d)?")).
[1525]801          self::jsVar('dotclear.msg.confirm_delete_categories',
802               __("Are you sure you want to delete selected categories (%s)?")).
[0]803          self::jsVar('dotclear.msg.confirm_delete_post',
804               __("Are you sure you want to delete this entry?")).
[1395]805          self::jsVar('dotclear.msg.click_to_unlock',
[1450]806               __("Click here to unlock the field")).
[1049]807          self::jsVar('dotclear.msg.confirm_spam_delete',
808               __('Are you sure you want to delete all spams?')).
[0]809          self::jsVar('dotclear.msg.confirm_delete_comments',
810               __('Are you sure you want to delete selected comments (%s)?')).
811          self::jsVar('dotclear.msg.confirm_delete_comment',
812               __('Are you sure you want to delete this comment?')).
813          self::jsVar('dotclear.msg.cannot_delete_users',
814               __('Users with posts cannot be deleted.')).
815          self::jsVar('dotclear.msg.confirm_delete_user',
816               __('Are you sure you want to delete selected users (%s)?')).
[3403]817          self::jsVar('dotclear.msg.confirm_delete_blog',
818               __('Are you sure you want to delete selected blogs (%s)?')).
[0]819          self::jsVar('dotclear.msg.confirm_delete_category',
820               __('Are you sure you want to delete category "%s"?')).
821          self::jsVar('dotclear.msg.confirm_reorder_categories',
822               __('Are you sure you want to reorder all categories?')).
823          self::jsVar('dotclear.msg.confirm_delete_media',
824               __('Are you sure you want to remove media "%s"?')).
[2512]825          self::jsVar('dotclear.msg.confirm_delete_directory',
826               __('Are you sure you want to remove directory "%s"?')).
[0]827          self::jsVar('dotclear.msg.confirm_extract_current',
828               __('Are you sure you want to extract archive in current directory?')).
829          self::jsVar('dotclear.msg.confirm_remove_attachment',
830               __('Are you sure you want to remove attachment "%s"?')).
831          self::jsVar('dotclear.msg.confirm_delete_lang',
832               __('Are you sure you want to delete "%s" language?')).
833          self::jsVar('dotclear.msg.confirm_delete_plugin',
834               __('Are you sure you want to delete "%s" plugin?')).
[2487]835          self::jsVar('dotclear.msg.confirm_delete_plugins',
836               __('Are you sure you want to delete selected plugins?')).
[0]837          self::jsVar('dotclear.msg.use_this_theme',
838               __('Use this theme')).
839          self::jsVar('dotclear.msg.remove_this_theme',
840               __('Remove this theme')).
841          self::jsVar('dotclear.msg.confirm_delete_theme',
842               __('Are you sure you want to delete "%s" theme?')).
[2487]843          self::jsVar('dotclear.msg.confirm_delete_themes',
844               __('Are you sure you want to delete selected themes?')).
[1462]845          self::jsVar('dotclear.msg.confirm_delete_backup',
846               __('Are you sure you want to delete this backup?')).
[2503]847          self::jsVar('dotclear.msg.confirm_revert_backup',
848               __('Are you sure you want to revert to this backup?')).
[0]849          self::jsVar('dotclear.msg.zip_file_content',
850               __('Zip file content')).
851          self::jsVar('dotclear.msg.xhtml_validator',
852               __('XHTML markup validator')).
853          self::jsVar('dotclear.msg.xhtml_valid',
854               __('XHTML content is valid.')).
855          self::jsVar('dotclear.msg.xhtml_not_valid',
856               __('There are XHTML markup errors.')).
[1861]857          self::jsVar('dotclear.msg.warning_validate_no_save_content',
[1832]858               __('Attention: an audit of a content not yet registered.')).
[0]859          self::jsVar('dotclear.msg.confirm_change_post_format',
860               __('You have unsaved changes. Switch post format will loose these changes. Proceed anyway?')).
[1256]861          self::jsVar('dotclear.msg.confirm_change_post_format_noconvert',
862               __("Warning: post format change will not convert existing content. You will need to apply new format by yourself. Proceed anyway?")).
[224]863          self::jsVar('dotclear.msg.load_enhanced_uploader',
864               __('Loading enhanced uploader, please wait.')).
[2156]865
866          self::jsVar('dotclear.msg.module_author',
867               __('Author:')).
868          self::jsVar('dotclear.msg.module_details',
869               __('Details')).
870          self::jsVar('dotclear.msg.module_support',
[2157]871               __('Support')).
[2156]872          self::jsVar('dotclear.msg.module_help',
[2157]873               __('Help:')).
[2156]874          self::jsVar('dotclear.msg.module_section',
875               __('Section:')).
876          self::jsVar('dotclear.msg.module_tags',
877               __('Tags:')).
[3460]878
879          self::jsVar('dotclear.msg.close_notice',
880               __('Hide this notice')).
881
[3421]882               "\n".
[0]883          "</script>\n";
884     }
[1187]885
[3418]886     /**
887     @deprecated since version 2.11
888     */
[0]889     public static function jsLoadIE7()
890     {
[3418]891          return '';
[0]892     }
[1187]893
[0]894     public static function jsConfirmClose()
895     {
896          $args = func_get_args();
897          if (count($args) > 0) {
898               foreach ($args as $k => $v) {
899                    $args[$k] = "'".html::escapeJS($v)."'";
900               }
901               $args = implode(',',$args);
902          } else {
903               $args = '';
904          }
[1187]905
[0]906          return
907          self::jsLoad('js/confirm-close.js').
908          '<script type="text/javascript">'."\n".
909          "confirmClosePage = new confirmClose(".$args."); ".
910          "confirmClose.prototype.prompt = '".html::escapeJS(__('You have unsaved changes.'))."'; ".
911          "</script>\n";
912     }
[1187]913
[0]914     public static function jsPageTabs($default=null)
915     {
916          if ($default) {
917               $default = "'".html::escapeJS($default)."'";
918          }
[2503]919
[0]920          return
921          self::jsLoad('js/jquery/jquery.pageTabs.js').
922          '<script type="text/javascript">'."\n".
[2010]923          '$(function() {'."\n".
[3421]924          '    $.pageTabs('.$default.');'."\n".
[2113]925          '});'.
[3418]926          "</script>\n";
[2010]927     }
[1161]928
[2202]929     public static function jsModal()
930     {
931          return
[3368]932          self::jsLoad('js/jquery/jquery.magnific-popup.js');
[0]933     }
[1187]934
[2202]935     public static function jsColorPicker()
936     {
937          return
[3021]938          self::cssLoad('style/farbtastic/farbtastic.css').
[2202]939          self::jsLoad('js/jquery/jquery.farbtastic.js').
940          self::jsLoad('js/color-picker.js');
[0]941     }
[1187]942
[2202]943     public static function jsDatePicker()
944     {
945          return
[3021]946          self::cssLoad('style/date-picker.css').
[2202]947          self::jsLoad('js/date-picker.js').
948          '<script type="text/javascript">'."\n".
[1187]949
[2202]950          "datePicker.prototype.months[0] = '".html::escapeJS(__('January'))."'; ".
951          "datePicker.prototype.months[1] = '".html::escapeJS(__('February'))."'; ".
952          "datePicker.prototype.months[2] = '".html::escapeJS(__('March'))."'; ".
953          "datePicker.prototype.months[3] = '".html::escapeJS(__('April'))."'; ".
954          "datePicker.prototype.months[4] = '".html::escapeJS(__('May'))."'; ".
955          "datePicker.prototype.months[5] = '".html::escapeJS(__('June'))."'; ".
956          "datePicker.prototype.months[6] = '".html::escapeJS(__('July'))."'; ".
957          "datePicker.prototype.months[7] = '".html::escapeJS(__('August'))."'; ".
958          "datePicker.prototype.months[8] = '".html::escapeJS(__('September'))."'; ".
959          "datePicker.prototype.months[9] = '".html::escapeJS(__('October'))."'; ".
960          "datePicker.prototype.months[10] = '".html::escapeJS(__('November'))."'; ".
961          "datePicker.prototype.months[11] = '".html::escapeJS(__('December'))."'; ".
[1161]962
[2202]963          "datePicker.prototype.days[0] = '".html::escapeJS(__('Monday'))."'; ".
964          "datePicker.prototype.days[1] = '".html::escapeJS(__('Tuesday'))."'; ".
965          "datePicker.prototype.days[2] = '".html::escapeJS(__('Wednesday'))."'; ".
966          "datePicker.prototype.days[3] = '".html::escapeJS(__('Thursday'))."'; ".
967          "datePicker.prototype.days[4] = '".html::escapeJS(__('Friday'))."'; ".
968          "datePicker.prototype.days[5] = '".html::escapeJS(__('Saturday'))."'; ".
969          "datePicker.prototype.days[6] = '".html::escapeJS(__('Sunday'))."'; ".
970
971          "datePicker.prototype.img_src = 'images/date-picker.png'; ".
[2788]972          "datePicker.prototype.img_alt = '".html::escapeJS(__('Choose date'))."'; ".
[2202]973
974          "datePicker.prototype.close_msg = '".html::escapeJS(__('close'))."'; ".
975          "datePicker.prototype.now_msg = '".html::escapeJS(__('now'))."'; ".
976
977          "</script>\n";
[0]978     }
[1187]979
[2720]980
[2202]981     public static function jsToolBar()
982     {
[2614]983          # Deprecated but we keep this for plugins.
[2202]984     }
985
986     public static function jsUpload($params=array(),$base_url=null)
987     {
988          if (!$base_url) {
989               $base_url = path::clean(dirname(preg_replace('/(\?.*$)?/','',$_SERVER['REQUEST_URI']))).'/';
990          }
991
992          $params = array_merge($params,array(
993               'sess_id='.session_id(),
994               'sess_uid='.$_SESSION['sess_browser_uid'],
995               'xd_check='.$GLOBALS['core']->getNonce()
[0]996          ));
[1187]997
[2202]998          return
999          '<script type="text/javascript">'."\n".
1000          "dotclear.jsUpload = {};\n".
1001          "dotclear.jsUpload.msg = {};\n".
1002          self::jsVar('dotclear.msg.enhanced_uploader_activate',__('Temporarily activate enhanced uploader')).
1003          self::jsVar('dotclear.msg.enhanced_uploader_disable',__('Temporarily disable enhanced uploader')).
1004          self::jsVar('dotclear.jsUpload.msg.limit_exceeded',__('Limit exceeded.')).
1005          self::jsVar('dotclear.jsUpload.msg.size_limit_exceeded',__('File size exceeds allowed limit.')).
1006          self::jsVar('dotclear.jsUpload.msg.canceled',__('Canceled.')).
1007          self::jsVar('dotclear.jsUpload.msg.http_error',__('HTTP Error:')).
1008          self::jsVar('dotclear.jsUpload.msg.error',__('Error:')).
1009          self::jsVar('dotclear.jsUpload.msg.choose_file',__('Choose file')).
1010          self::jsVar('dotclear.jsUpload.msg.choose_files',__('Choose files')).
1011          self::jsVar('dotclear.jsUpload.msg.cancel',__('Cancel')).
1012          self::jsVar('dotclear.jsUpload.msg.clean',__('Clean')).
1013          self::jsVar('dotclear.jsUpload.msg.upload',__('Upload')).
1014          self::jsVar('dotclear.jsUpload.msg.send',__('Send')).
1015          self::jsVar('dotclear.jsUpload.msg.file_successfully_uploaded',__('File successfully uploaded.')).
1016          self::jsVar('dotclear.jsUpload.msg.no_file_in_queue',__('No file in queue.')).
1017          self::jsVar('dotclear.jsUpload.msg.file_in_queue',__('1 file in queue.')).
1018          self::jsVar('dotclear.jsUpload.msg.files_in_queue',__('%d files in queue.')).
1019          self::jsVar('dotclear.jsUpload.msg.queue_error',__('Queue error:')).
1020          self::jsVar('dotclear.jsUpload.base_url',$base_url).
1021          "</script>\n".
[1461]1022
[3218]1023          self::jsLoad('js/jquery/jquery-ui.custom.js').
[2202]1024          self::jsLoad('js/jsUpload/tmpl.js').
1025          self::jsLoad('js/jsUpload/template-upload.js').
1026          self::jsLoad('js/jsUpload/template-download.js').
1027          self::jsLoad('js/jsUpload/load-image.js').
1028          self::jsLoad('js/jsUpload/jquery.iframe-transport.js').
1029          self::jsLoad('js/jsUpload/jquery.fileupload.js').
1030          self::jsLoad('js/jsUpload/jquery.fileupload-process.js').
1031          self::jsLoad('js/jsUpload/jquery.fileupload-resize.js').
1032          self::jsLoad('js/jsUpload/jquery.fileupload-ui.js');
1033     }
[1144]1034
[2202]1035     public static function jsMetaEditor()
1036     {
[3021]1037          return self::jsLoad('js/meta-editor.js');
[2202]1038     }
[2849]1039
[3397]1040     public static function jsFilterControl($show=true)
1041     {
1042          return
1043          self::jsLoad('js/filter-controls.js').
1044          '<script type="text/javascript">'."\n".
1045          self::jsVar('dotclear.msg.show_filters', $show ? 'true':'false')."\n".
1046          self::jsVar('dotclear.msg.filter_posts_list',__('Show filters and display options'))."\n".
1047          self::jsVar('dotclear.msg.cancel_the_filter',__('Cancel filters and display options'))."\n".
1048          "</script>";
1049     }
1050
[3256]1051     public static function jsLoadCodeMirror($theme = '',$multi = true,$modes = array('css','htmlmixed','javascript','php','xml'))
[3251]1052     {
1053          $ret =
1054               self::cssLoad('js/codemirror/lib/codemirror.css').
1055               self::jsLoad('js/codemirror/lib/codemirror.js');
1056          if ($multi) {
1057               $ret .= self::jsLoad('js/codemirror/addon/mode/multiplex.js');
1058          }
1059          foreach ($modes as $mode) {
1060               $ret .= self::jsLoad('js/codemirror/mode/'.$mode.'/'.$mode.'.js');
1061          }
1062          $ret .=
1063               self::jsLoad('js/codemirror/addon/edit/closebrackets.js').
[3253]1064               self::jsLoad('js/codemirror/addon/edit/matchbrackets.js').
1065               self::cssLoad('js/codemirror/addon/display/fullscreen.css').
1066               self::jsLoad('js/codemirror/addon/display/fullscreen.js');
[3251]1067          if ($theme != '') {
1068               $ret .= self::cssLoad('js/codemirror/theme/'.$theme.'.css');
1069          }
1070          return $ret;
1071     }
1072
[3256]1073     public static function jsRunCodeMirror($name,$id,$mode,$theme = '')
1074     {
1075          $ret =
[3421]1076               '<script type="text/javascript">'."\n".
[3256]1077               'var '.$name.' = CodeMirror.fromTextArea('.$id.',{'."\n".
1078               '    mode: "'.$mode.'",'."\n".
1079               '    tabMode: "indent",'."\n".
1080               '    lineWrapping: "true",'."\n".
1081               '    lineNumbers: "true",'."\n".
1082               '    matchBrackets: "true",'."\n".
1083               '    autoCloseBrackets: "true",'."\n".
1084               '    extraKeys: {"F11": function(cm) {cm.setOption("fullScreen",!cm.getOption("fullScreen"));}}';
[3421]1085          if ($theme) {
1086               $ret .=
1087                    ','."\n".
1088                    '    theme: "'.$theme.'"';
1089          }
1090          $ret .= "\n".
1091               '});'."\n".
[3256]1092               '</script>';
1093          return $ret;
1094     }
1095
[3251]1096     public static function getCodeMirrorThemes()
1097     {
1098          $themes = array();
1099          $themes_root = dirname(__FILE__).'/../../admin'.'/js/codemirror/theme/';
1100          if (is_dir($themes_root) && is_readable($themes_root)) {
1101               if (($d = @dir($themes_root)) !== false) {
1102                    while (($entry = $d->read()) !== false) {
1103                         if ($entry != '.' && $entry != '..' && substr($entry, 0, 1) != '.' && is_readable($themes_root.'/'.$entry)) {
1104                              $themes[] = substr($entry,0,-4); // remove .css extension
1105                         }
1106                    }
[3313]1107                    sort($themes);
[3251]1108               }
1109          }
1110          return $themes;
1111     }
1112
[3080]1113     public static function getPF($file)
1114     {
[2852]1115          return $GLOBALS['core']->adminurl->get('load.plugin.file',array('pf' => $file));
[2849]1116     }
[2909]1117
[3262]1118     public static function getVF($file)
1119     {
1120          return $GLOBALS['core']->adminurl->get('load.var.file',array('vf' => $file));
1121     }
1122
[3279]1123     public static function setXFrameOptions($headers,$origin = null)
[3080]1124     {
[2909]1125          if (self::$xframe_loaded) {
1126               return;
1127          }
[3490]1128
[2909]1129          if ($origin !== null) {
1130               $url = parse_url($origin);
[3490]1131               $headers['x-frame-options'] = sprintf('X-Frame-Options: %s',is_array($url) && isset($url['host']) ?
[3080]1132                    ("ALLOW-FROM ".(isset($url['scheme']) ? $url['scheme'].':' : '' ).'//'.$url['host']) :
[3279]1133                    'SAMEORIGIN');
[2909]1134          } else {
[3279]1135               $headers['x-frame-options'] = 'X-Frame-Options: SAMEORIGIN'; // FF 3.6.9+ Chrome 4.1+ IE 8+ Safari 4+ Opera 10.5+
[2909]1136          }
1137          self::$xframe_loaded = true;
1138     }
[489]1139}
Note: See TracBrowser for help on using the repository browser.

Sites map