Dotclear

source: inc/admin/lib.dc.page.php @ 3903:24d6036ec025

Revision 3903:24d6036ec025, 46.0 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

dotclear js object is defined by common.js, don't try to use it before!

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

Sites map