PageRenderTime 23ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/textpattern/lib/txplib_head.php

http://textpattern.googlecode.com/
PHP | 354 lines | 189 code | 52 blank | 113 comment | 19 complexity | 0986ff96e6fc68809e0f348f247892fe MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, GPL-2.0
  1. <?php
  2. /*
  3. * Textpattern Content Management System
  4. * http://textpattern.com
  5. *
  6. * Copyright (C) 2014 The Textpattern Development Team
  7. *
  8. * This file is part of Textpattern.
  9. *
  10. * Textpattern is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation, version 2.
  13. *
  14. * Textpattern is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with Textpattern. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * Used for generating admin-side headers.
  24. *
  25. * @package HTML
  26. */
  27. /**
  28. * Creates and outputs an admin-side header.
  29. *
  30. * The output contains HTML &lt;head&gt; section and the main
  31. * navigation. The results are echoed as opposed to returned.
  32. *
  33. * This function offers a way to invoke modal activity messages
  34. * and set the page title.
  35. *
  36. * Output will automatically become silent on asynchronous
  37. * script responses that do not want HTML headers.
  38. *
  39. * @param string $pagetitle The page title
  40. * @param string|array $message A message show to the user
  41. * @example
  42. * pagetop('Title', array('My error message', E_ERROR));
  43. * echo 'My page contents.';
  44. */
  45. function pagetop($pagetitle, $message = '')
  46. {
  47. global $siteurl, $sitename, $txp_user, $event, $step, $app_mode, $theme, $privs;
  48. if ($app_mode == 'async') {
  49. return;
  50. }
  51. $area = gps('area');
  52. $event = (!$event) ? 'article' : $event;
  53. $bm = gps('bm');
  54. $privs = safe_field("privs", "txp_users", "name = '".doSlash($txp_user)."'");
  55. $areas = areas();
  56. $area = false;
  57. foreach ($areas as $k => $v) {
  58. if (in_array($event, $v)) {
  59. $area = $k;
  60. break;
  61. }
  62. }
  63. if (gps('logout')) {
  64. $body_id = 'page-logout';
  65. } elseif (!$txp_user) {
  66. $body_id = 'page-login';
  67. } else {
  68. $body_id = 'page-'.txpspecialchars($event);
  69. }
  70. header('X-Frame-Options: '.X_FRAME_OPTIONS);
  71. header('X-UA-Compatible: '.X_UA_COMPATIBLE);
  72. $lang_direction = gTxt('lang_dir');
  73. if (!in_array($lang_direction, array('ltr', 'rtl'))) {
  74. // Apply biased default for missing translations
  75. $lang_direction = 'ltr';
  76. }
  77. ?><!DOCTYPE html>
  78. <html lang="<?php echo LANG; ?>" dir="<?php echo $lang_direction; ?>">
  79. <head>
  80. <meta charset="utf-8">
  81. <meta name="robots" content="noindex, nofollow">
  82. <title><?php echo admin_title($pagetitle)?></title><?php echo
  83. script_js('vendors/jquery/jquery/jquery.js', TEXTPATTERN_SCRIPT_URL).
  84. script_js('vendors/jquery/ui/js/jquery-ui.js', TEXTPATTERN_SCRIPT_URL).
  85. // TODO: Remove jQuery migrate plugin before release
  86. script_js('//code.jquery.com/jquery-migrate-1.2.1.js', TEXTPATTERN_SCRIPT_URL).
  87. script_js(
  88. 'var textpattern = ' . json_encode(array(
  89. 'event' => $event,
  90. 'step' => $step,
  91. '_txp_token' => form_token(),
  92. 'ajax_timeout' => (int) AJAX_TIMEOUT,
  93. 'textarray' => (object) null,
  94. 'do_spellcheck' => get_pref('do_spellcheck',
  95. '#page-article #body, #page-article #title,'.
  96. '#page-image #alt-text, #page-image #caption,'.
  97. '#page-file #description,'.
  98. '#page-link #link-title, #page-link #link-description'),
  99. 'production_status' => get_pref('production_status'),
  100. )).';').
  101. script_js('textpattern.js', TEXTPATTERN_SCRIPT_URL).n;
  102. gTxtScript(array('form_submission_error', 'are_you_sure', 'cookies_must_be_enabled', 'ok', 'save', 'publish'));
  103. // Mandatory un-themable Textpattern core styles ?>
  104. <style>
  105. .not-ready .doc-ready,
  106. .not-ready form.async input[type="submit"],
  107. .not-ready a.async
  108. {
  109. visibility: hidden;
  110. }
  111. </style>
  112. <?php
  113. echo $theme->html_head();
  114. callback_event('admin_side', 'head_end');
  115. ?>
  116. </head>
  117. <body id="<?php echo $body_id; ?>" class="not-ready <?php echo $area; ?>">
  118. <header role="banner" class="txp-header">
  119. <?php callback_event('admin_side', 'pagetop');
  120. $theme->set_state($area, $event, $bm, $message);
  121. echo pluggable_ui('admin_side', 'header', $theme->header());
  122. callback_event('admin_side', 'pagetop_end');
  123. echo n.'</header><!-- /txp-header -->'.
  124. n.'<main role="main" class="txp-body" aria-label="'.gTxt('main_content').'">';
  125. callback_event('admin_side', 'main_content');
  126. }
  127. /**
  128. * Return the HTML &lt;title&gt; contents for an admin-side page.
  129. *
  130. * The rendered title can be customised via a 'admin_side > html_title'
  131. * pluggable UI callback event.
  132. *
  133. * @param string $pagetitle Specific page title part
  134. * @return string
  135. * @since 4.6.0
  136. */
  137. function admin_title($pagetitle)
  138. {
  139. global $sitename;
  140. if ((string) $pagetitle === '') {
  141. $title = gTxt('untitled');
  142. } else {
  143. $title = $pagetitle;
  144. }
  145. $title = escape_title($title).' - '.txpspecialchars($sitename).' &#124; Textpattern CMS';
  146. return pluggable_ui('admin_side', 'html_title', $title, compact('pagetitle'));
  147. }
  148. /**
  149. * Creates an area tab.
  150. *
  151. * This can be used to create table based navigation bars.
  152. *
  153. * @param string $label
  154. * @param string $event
  155. * @param string $tarea
  156. * @param string $area
  157. * @return string HTML table column
  158. * @deprecated in 4.6.0
  159. */
  160. function areatab($label,$event,$tarea,$area)
  161. {
  162. $tc = ($area == $event) ? 'tabup' : 'tabdown';
  163. $atts=' class="'.$tc.'"';
  164. $hatts=' href="?event='.$tarea.'"';
  165. return tda(tag($label,'a',$hatts),$atts);
  166. }
  167. /**
  168. * Creates a secondary area tab.
  169. *
  170. * This can be used to create table based navigation bars.
  171. *
  172. * @param string $label
  173. * @param string $tabevent
  174. * @param string $event
  175. * @return string HTML table column
  176. * @deprecated in 4.6.0
  177. */
  178. function tabber($label,$tabevent,$event)
  179. {
  180. $tc = ($event==$tabevent) ? 'tabup' : 'tabdown2';
  181. $out = '<td class="'.$tc.'"><a href="?event='.$tabevent.'">'.$label.'</a></td>';
  182. return $out;
  183. }
  184. /**
  185. * Creates a table based navigation bar row.
  186. *
  187. * This can be used to create table based navigation bars.
  188. *
  189. * @param string $area
  190. * @param string $event
  191. * @return string HTML table columns
  192. * @deprecated in 4.6.0
  193. */
  194. function tabsort($area, $event)
  195. {
  196. if ($area) {
  197. $areas = areas();
  198. $out = array();
  199. foreach ($areas[$area] as $a => $b) {
  200. if (has_privs($b)) {
  201. $out[] = tabber($a, $b, $event, 2);
  202. }
  203. }
  204. return ($out) ? join('', $out) : '';
  205. }
  206. return '';
  207. }
  208. /**
  209. * Gets the main menu structure as an array.
  210. *
  211. * @return array
  212. * @example
  213. * print_r(
  214. * areas()
  215. * );
  216. */
  217. function areas()
  218. {
  219. global $privs, $plugin_areas;
  220. $areas['start'] = array(
  221. );
  222. $areas['content'] = array(
  223. gTxt('tab_organise') => 'category',
  224. gTxt('tab_write') => 'article',
  225. gTxt('tab_list') => 'list',
  226. gTxt('tab_image') => 'image',
  227. gTxt('tab_file') => 'file',
  228. gTxt('tab_link') => 'link',
  229. );
  230. $areas['presentation'] = array(
  231. gTxt('tab_sections') => 'section',
  232. gTxt('tab_pages') => 'page',
  233. gTxt('tab_forms') => 'form',
  234. gTxt('tab_style') => 'css',
  235. );
  236. $areas['admin'] = array(
  237. gTxt('tab_diagnostics') => 'diag',
  238. gTxt('tab_preferences') => 'prefs',
  239. gTxt('tab_languages') => 'lang',
  240. gTxt('tab_site_admin') => 'admin',
  241. gTxt('tab_plugins') => 'plugin',
  242. gTxt('tab_import') => 'import',
  243. );
  244. $areas['extensions'] = array(
  245. );
  246. if (get_pref('use_comments', 1)) {
  247. $areas['content'][gTxt('tab_comments')] = 'discuss';
  248. }
  249. if (get_pref('logging') !== 'none' && get_pref('expire_logs_after')) {
  250. $areas['admin'][gTxt('tab_logs')] = 'log';
  251. }
  252. if (is_array($plugin_areas)) {
  253. $areas = array_merge_recursive($areas, $plugin_areas);
  254. }
  255. return $areas;
  256. }
  257. /**
  258. * Creates an admin-side main menu as a &lt;select&gt; dropdown.
  259. *
  260. * @param mixed $inline Is not used.
  261. * @return string A HTML form
  262. * @example
  263. * echo navPop();
  264. */
  265. function navPop($inline = '')
  266. {
  267. $areas = areas();
  268. $out = array();
  269. foreach ($areas as $a => $b) {
  270. if (!has_privs( 'tab.'.$a)) {
  271. continue;
  272. }
  273. if (count($b) > 0) {
  274. $out[] = n.'<optgroup label="'.gTxt('tab_'.$a).'">';
  275. foreach ($b as $c => $d) {
  276. if (has_privs($d)) {
  277. $out[] = n.'<option value="'.txpspecialchars($d).'">'.strip_tags($c).'</option>';
  278. }
  279. }
  280. $out[] = n.'</optgroup>';
  281. }
  282. }
  283. if ($out) {
  284. return n.'<form method="get" action="index.php" class="navpop">'.
  285. n.'<select name="event" data-submit-on="change">'.
  286. n.'<option>'.gTxt('go').'&#8230;</option>'.
  287. join('', $out).
  288. n.'</select>'.
  289. n.'</form>';
  290. }
  291. }
  292. /**
  293. * Generates a button link.
  294. *
  295. * @param string $label
  296. * @param string $link
  297. * @deprecated in 4.6.0
  298. */
  299. function button($label,$link)
  300. {
  301. return '<span style="margin-right:2em"><a href="?event='.$link.'">'.$label.'</a></span>';
  302. }