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