Textpattern PHP Cross Reference Content Management Systems

Source: /textpattern/lib/txplib_head.php - 391 lines - 11060 bytes - Summary - Text - Print

Description: Used for generating admin-side headers.

   1  <?php
   2  
   3  /*
   4   * Textpattern Content Management System
   5   * https://textpattern.com/
   6   *
   7   * Copyright (C) 2020 The Textpattern Development Team
   8   *
   9   * This file is part of Textpattern.
  10   *
  11   * Textpattern is free software; you can redistribute it and/or
  12   * modify it under the terms of the GNU General Public License
  13   * as published by the Free Software Foundation, version 2.
  14   *
  15   * Textpattern is distributed in the hope that it will be useful,
  16   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18   * GNU General Public License for more details.
  19   *
  20   * You should have received a copy of the GNU General Public License
  21   * along with Textpattern. If not, see <https://www.gnu.org/licenses/>.
  22   */
  23  
  24  /**
  25   * Used for generating admin-side headers.
  26   *
  27   * @package HTML
  28   */
  29  
  30  /**
  31   * Creates and outputs an admin-side header.
  32   *
  33   * The output contains HTML &lt;head&gt; section and the main navigation.
  34   * The results are echoed as opposed to returned.
  35   *
  36   * This function offers a way to invoke modal activity messages and set the
  37   * page title.
  38   *
  39   * Output will automatically become silent on asynchronous script responses
  40   * that do not want HTML headers.
  41   *
  42   * @param  string       $pagetitle The page title
  43   * @param  string|array $message   A message show to the user
  44   * @example
  45   * pagetop('Title', array('My error message', E_ERROR));
  46   * echo 'My page contents.';
  47   */
  48  
  49  function pagetop($pagetitle = '', $message = '')
  50  {
  51      global $siteurl, $sitename, $txp_user, $event, $step, $app_mode, $theme, $textarray_script, $file_max_upload_size;
  52  
  53      header('Content-Security-Policy: '.CONTENT_SECURITY_POLICY);
  54      header('X-Frame-Options: '.X_FRAME_OPTIONS);
  55  
  56      if ($app_mode == 'async') {
  57          return;
  58      }
  59  
  60      $area = gps('area');
  61      $event = (!$event) ? 'article' : $event;
  62      $bm = gps('bm');
  63  
  64      $areas = areas();
  65      $area = false;
  66  
  67      foreach ($areas as $k => $v) {
  68          if (in_array($event, $v)) {
  69              $area = $k;
  70              break;
  71          }
  72      }
  73  
  74      if (gps('logout')) {
  75          $body_id = 'page-logout';
  76          $area = 'login';
  77      } elseif (!$txp_user) {
  78          $body_id = 'page-login';
  79          $area = 'login';
  80      } else {
  81          $body_id = 'page-'.txpspecialchars($event);
  82      }
  83  
  84      gTxtScript(array(
  85          'are_you_sure',
  86          'close',
  87          'cookies_must_be_enabled',
  88          'documentation',
  89          'form_submission_error',
  90          'help',
  91          'list_options',
  92          'ok',
  93          'plugin_help',
  94          'publish',
  95          'save',
  96          'select',
  97          'toggle_all_selected',
  98          'upload_err_form_size',
  99          'with_selected_option',
 100      ));
 101  
 102      $lang_direction = gTxt('lang_dir');
 103      $lang_ui = get_pref('language_ui', LANG);
 104  
 105      if (!in_array($lang_direction, array('ltr', 'rtl'))) {
 106          // Apply biased default for missing translations.
 107          $lang_direction = 'ltr';
 108      } ?><!DOCTYPE html>
 109  <html lang="<?php echo txpspecialchars($lang_ui); ?>" dir="<?php echo $lang_direction; ?>">
 110  <head>
 111  <meta charset="utf-8">
 112  <meta name="robots" content="noindex, nofollow">
 113  <title><?php echo admin_title($pagetitle)?></title><?php echo
 114      script_js('vendors/jquery/jquery/jquery.js', TEXTPATTERN_SCRIPT_URL).
 115      script_js('vendors/jquery/jquery-ui/jquery-ui.js', TEXTPATTERN_SCRIPT_URL).
 116      script_js('vendors/blueimp/fileupload/jquery.fileupload.js', TEXTPATTERN_SCRIPT_URL, array("file, image")).
 117      script_js(
 118          'var textpattern = '.json_encode(
 119              array(
 120                  '_txp_uid' => get_pref('blog_uid'),
 121                  'event' => $event,
 122                  'step' => $step,
 123                  '_txp_token' => form_token(),
 124                  'ajax_timeout' => (int) AJAX_TIMEOUT,
 125                  'prefs' => array(
 126                      'max_file_size' => $file_max_upload_size,
 127                      'max_upload_size' => real_max_upload_size(0),
 128                      'production_status' => get_pref('production_status'),
 129                      'do_spellcheck' => get_pref(
 130                          'do_spellcheck',
 131                          '#page-article #body, #page-article #title,'.
 132                          '#page-image #image_alt_text, #page-image #caption,'.
 133                          '#page-file #description,'.
 134                          '#page-link #link-title, #page-link #link-description'
 135                      ),
 136                      'language_ui' => get_pref(
 137                          'language_ui',
 138                          TEXTPATTERN_DEFAULT_LANG
 139                      ),
 140                      'message' => '<span class="ui-icon ui-icon-{status}"></span> {message}',
 141                      'messagePane' => '<span class="messageflash {status}" role="alert" aria-live="assertive">
 142      {message}
 143      <a class="close" role="button" title="{close}" href="#close"><span class="ui-icon ui-icon-close">{close}</span></a>
 144  </span>'
 145                  ),
 146                  'textarray' => (object) null,
 147              ),
 148              TEXTPATTERN_JSON
 149          ).';'
 150      ).
 151      script_js('textpattern.js', TEXTPATTERN_SCRIPT_URL).n;
 152  
 153  echo script_js("
 154      $(function() {
 155          if (!textpattern.version || !'".txp_version."'.match(textpattern.version)) {
 156              alert('Please force-reload the page or clear your browser caches.')
 157          }
 158      })", false);
 159  echo $theme->html_head();
 160  echo $theme->html_head_custom();
 161      callback_event('admin_side', 'head_end'); ?>
 162  </head>
 163  <body class="not-ready <?php echo $area; ?>" id="<?php echo $body_id; ?>">
 164  <noscript>Please enable JavaScript in your browser to use this application.</noscript>
 165  <a class="txp-skip-link" href="#txp-main"><?php echo gTxt('go_content') ?></a>
 166  <header class="txp-header">
 167  <?php callback_event('admin_side', 'pagetop');
 168      $theme->set_state($area, $event, $bm, $message);
 169      echo pluggable_ui('admin_side', 'header', $theme->header());
 170      callback_event('admin_side', 'pagetop_end');
 171      echo n.'</header><!-- /txp-header -->'.
 172          n.'<main id="txp-main" class="txp-body">'.
 173          n.'<div class="messagepane" id="messagepane">'.$theme->announce($message).'</div>';
 174      callback_event('admin_side', 'main_content');
 175  }
 176  
 177  /**
 178   * Return the HTML &lt;title&gt; contents for an admin-side page.
 179   *
 180   * The rendered title can be customised via a 'admin_side > html_title'
 181   * pluggable UI callback event.
 182   *
 183   * @param  string $pagetitle Specific page title part
 184   * @return string
 185   * @since  4.6.0
 186   */
 187  
 188  function admin_title($pagetitle)
 189  {
 190      global $sitename;
 191  
 192      if ((string) $pagetitle === '') {
 193          $title = gTxt('untitled');
 194      } else {
 195          $title = $pagetitle;
 196      }
 197  
 198      $title = escape_title($title).' - '.txpspecialchars($sitename).' &#124; Textpattern CMS';
 199  
 200      return pluggable_ui('admin_side', 'html_title', $title, compact('pagetitle'));
 201  }
 202  
 203  /**
 204   * Creates an area tab.
 205   *
 206   * This can be used to create table based navigation bars.
 207   *
 208   * @param      string $label
 209   * @param      string $event
 210   * @param      string $tarea
 211   * @param      string $area
 212   * @return     string HTML table column
 213   * @deprecated in 4.6.0
 214   */
 215  
 216  function areatab($label, $event, $tarea, $area)
 217  {
 218      $tc = ($area == $event) ? 'tabup' : 'tabdown';
 219      $atts = ' class="'.$tc.'"';
 220      $hatts = ' href="?event='.$tarea.'"';
 221  
 222      return tda(tag($label, 'a', $hatts), $atts);
 223  }
 224  
 225  /**
 226   * Creates a secondary area tab.
 227   *
 228   * This can be used to create table based navigation bars.
 229   *
 230   * @param      string $label
 231   * @param      string $tabevent
 232   * @param      string $event
 233   * @return     string HTML table column
 234   * @deprecated in 4.6.0
 235   */
 236  
 237  function tabber($label, $tabevent, $event)
 238  {
 239      $tc = ($event == $tabevent) ? 'tabup' : 'tabdown2';
 240      $out = '<td class="'.$tc.'"><a href="?event='.$tabevent.'">'.$label.'</a></td>';
 241  
 242      return $out;
 243  }
 244  
 245  /**
 246   * Creates a table based navigation bar row.
 247   *
 248   * This can be used to create table based navigation bars.
 249   *
 250   * @param      string $area
 251   * @param      string $event
 252   * @return     string HTML table columns
 253   * @deprecated in 4.6.0
 254   */
 255  
 256  function tabsort($area, $event)
 257  {
 258      if ($area) {
 259          $areas = areas();
 260  
 261          $out = array();
 262  
 263          foreach ($areas[$area] as $a => $b) {
 264              if (has_privs($b)) {
 265                  $out[] = tabber($a, $b, $event, 2);
 266              }
 267          }
 268  
 269          return ($out) ? join('', $out) : '';
 270      }
 271  
 272      return '';
 273  }
 274  
 275  /**
 276   * Gets the main menu structure as an array.
 277   *
 278   * @return array
 279   * @example
 280   * print_r(
 281   *     areas()
 282   * );
 283   */
 284  
 285  function areas()
 286  {
 287      global $plugin_areas;
 288  
 289      $adminString = has_privs('admin.list') ? gTxt('tab_site_admin') : gTxt('tab_site_account');
 290  
 291      $areas['start'] = array(
 292      );
 293  
 294      $areas['content'] = array(
 295          gTxt('tab_write')    => 'article',
 296          gTxt('tab_list')     => 'list',
 297          gTxt('tab_image')    => 'image',
 298          gTxt('tab_file')     => 'file',
 299          gTxt('tab_link')     => 'link',
 300          gTxt('tab_organise') => 'category',
 301      );
 302  
 303      $areas['presentation'] = array(
 304          gTxt('tab_skin')     => 'skin',
 305          gTxt('tab_sections') => 'section',
 306          gTxt('tab_pages')    => 'page',
 307          gTxt('tab_forms')    => 'form',
 308          gTxt('tab_style')    => 'css',
 309      );
 310  
 311      $areas['admin'] = array(
 312          gTxt('tab_diagnostics') => 'diag',
 313          gTxt('tab_preferences') => 'prefs',
 314          gTxt('tab_languages')   => 'lang',
 315          $adminString            => 'admin',
 316          gTxt('tab_plugins')     => 'plugin',
 317      );
 318  
 319      $areas['extensions'] = array(
 320      );
 321  
 322      if (get_pref('use_comments', 1)) {
 323          $areas['content'][gTxt('tab_comments')] = 'discuss';
 324      }
 325  
 326      if (get_pref('logging') !== 'none' && get_pref('expire_logs_after')) {
 327          $areas['admin'][gTxt('tab_logs')] = 'log';
 328      }
 329  
 330      if (is_array($plugin_areas)) {
 331          $areas = array_merge_recursive($areas, $plugin_areas);
 332      }
 333  
 334      return $areas;
 335  }
 336  
 337  /**
 338   * Creates an admin-side main menu as a &lt;select&gt; dropdown.
 339   *
 340   * @param  mixed  $inline Is not used.
 341   * @return string A HTML form
 342   * @example
 343   * echo navPop();
 344   */
 345  
 346  function navPop($inline = '')
 347  {
 348      $areas = areas();
 349  
 350      $out = array();
 351  
 352      foreach ($areas as $a => $b) {
 353          if (!has_privs('tab.'.$a)) {
 354              continue;
 355          }
 356  
 357          if (count($b) > 0) {
 358              $out[] = n.'<optgroup label="'.gTxt('tab_'.$a).'">';
 359  
 360              foreach ($b as $c => $d) {
 361                  if (has_privs($d)) {
 362                      $out[] = n.'<option value="'.txpspecialchars($d).'">'.strip_tags($c).'</option>';
 363                  }
 364              }
 365  
 366              $out[] = n.'</optgroup>';
 367          }
 368      }
 369  
 370      if ($out) {
 371          return n.'<form class="navpop" method="get" action="index.php">'.
 372              n.'<select name="event" data-submit-on="change">'.
 373              n.'<option>'.gTxt('go').'&#8230;</option>'.
 374              join('', $out).
 375              n.'</select>'.
 376              n.'</form>';
 377      }
 378  }
 379  
 380  /**
 381   * Generates a button link.
 382   *
 383   * @param      string $label
 384   * @param      string $link
 385   * @deprecated in 4.6.0
 386   */
 387  
 388  function button($label, $link)
 389  {
 390      return '<span style="margin-right:2em"><a href="?event='.$link.'">'.$label.'</a></span>';
 391  }

title

Description

title

Description

title

Description

title

title

Body