[ Index ]

PHP Cross Reference of YOURLS

title

Body

[close]

/includes/ -> functions-html.php (source)

   1  <?php
   2  
   3  /**
   4   * Display <h1> header and logo
   5   *
   6   * @return void
   7   */
   8  function yourls_html_logo() {
   9      yourls_do_action( 'pre_html_logo' );
  10      ?>
  11      <header role="banner">
  12      <h1>
  13          <a href="<?php echo yourls_admin_url( 'index.php' ) ?>" title="YOURLS"><span>YOURLS</span>: <span>Y</span>our <span>O</span>wn <span>URL</span> <span>S</span>hortener<br/>
  14          <img src="<?php yourls_site_url(); ?>/images/yourls-logo.svg?v=<?php echo YOURLS_VERSION; ?>" id="yourls-logo" alt="YOURLS" title="YOURLS" /></a>
  15      </h1>
  16      </header>
  17      <?php
  18      yourls_do_action( 'html_logo' );
  19  }
  20  
  21  /**
  22   * Display HTML head and <body> tag
  23   *
  24   * @param string $context Context of the page (stats, index, infos, ...)
  25   * @param string $title HTML title of the page
  26   * @return void
  27   */
  28  function yourls_html_head( $context = 'index', $title = '' ) {
  29  
  30      yourls_do_action( 'pre_html_head', $context, $title );
  31  
  32      // All components to false, except when specified true
  33      $share = $insert = $tablesorter = $tabs = $cal = $charts = false;
  34  
  35      // Load components as needed
  36      switch ( $context ) {
  37          case 'infos':
  38              $share = $tabs = $charts = true;
  39              break;
  40  
  41          case 'bookmark':
  42              $share = $insert = $tablesorter = true;
  43              break;
  44  
  45          case 'index':
  46              $insert = $tablesorter = $cal = $share = true;
  47              break;
  48  
  49          case 'plugins':
  50          case 'tools':
  51              $tablesorter = true;
  52              break;
  53  
  54          case 'login':
  55              $_title_page = 'Login';
  56              break;
  57  
  58          case 'install':
  59          case 'new':
  60          case 'upgrade':
  61              break;
  62      }
  63  
  64      // Force no cache for all admin pages
  65      if( yourls_is_admin() && !headers_sent() ) {
  66          yourls_no_cache_headers();
  67          yourls_no_frame_header();
  68          yourls_content_type_header( yourls_apply_filter( 'html_head_content-type', 'text/html' ) );
  69          yourls_do_action( 'admin_headers', $context, $title );
  70      }
  71  
  72      // Store page context
  73      yourls_set_html_context($context);
  74  
  75      // Body class
  76      $bodyclass = yourls_apply_filter( 'bodyclass', '' );
  77      $bodyclass .= ( yourls_is_mobile_device() ? 'mobile' : 'desktop' );
  78  
  79      // Page title
  80      $_title = 'YOURLS &mdash; Your Own URL Shortener | ' . yourls_link();
  81      $_title = empty($_title_page) ? $_title : $_title_page . ' &mdash; ' . $_title;
  82      $title = $title ? $title . " &laquo; " . $_title : $_title;
  83      $title = yourls_apply_filter( 'html_title', $title, $context );
  84  
  85      ?>
  86  <!DOCTYPE html>
  87  <html <?php yourls_html_language_attributes(); ?>>
  88  <head>
  89      <title><?php echo yourls_esc_html($title); ?></title>
  90      <meta http-equiv="Content-Type" content="<?php echo yourls_apply_filter( 'html_head_meta_content-type', 'text/html; charset=utf-8' ); ?>" />
  91      <meta name="generator" content="YOURLS <?php echo YOURLS_VERSION ?>" />
  92      <meta name="description" content="YOURLS &raquo; Your Own URL Shortener' | <?php yourls_site_url(); ?>" />
  93      <?php yourls_do_action('html_head_meta', $context); ?>
  94      <?php yourls_html_favicon(); ?>
  95      <script src="<?php yourls_site_url(); ?>/js/jquery-3.5.1.min.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
  96      <script src="<?php yourls_site_url(); ?>/js/common.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
  97      <script src="<?php yourls_site_url(); ?>/js/jquery.notifybar.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
  98      <link rel="stylesheet" href="<?php yourls_site_url(); ?>/css/style.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" />
  99      <?php if ( $tabs ) { ?>
 100          <link rel="stylesheet" href="<?php yourls_site_url(); ?>/css/infos.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" />
 101          <script src="<?php yourls_site_url(); ?>/js/infos.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
 102      <?php } ?>
 103      <?php if ( $tablesorter ) { ?>
 104          <link rel="stylesheet" href="<?php yourls_site_url(); ?>/css/tablesorter.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" />
 105          <script src="<?php yourls_site_url(); ?>/js/jquery-3.tablesorter.min.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
 106          <script src="<?php yourls_site_url(); ?>/js/tablesorte.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
 107      <?php } ?>
 108      <?php if ( $insert ) { ?>
 109          <script src="<?php yourls_site_url(); ?>/js/insert.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
 110      <?php } ?>
 111      <?php if ( $share ) { ?>
 112          <link rel="stylesheet" href="<?php yourls_site_url(); ?>/css/share.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" />
 113          <script src="<?php yourls_site_url(); ?>/js/share.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
 114          <script src="<?php yourls_site_url(); ?>/js/clipboard.min.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
 115      <?php } ?>
 116      <?php if ( $cal ) { ?>
 117          <link rel="stylesheet" href="<?php yourls_site_url(); ?>/css/cal.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" />
 118          <?php yourls_l10n_calendar_strings(); ?>
 119          <script src="<?php yourls_site_url(); ?>/js/jquery.cal.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
 120      <?php } ?>
 121      <?php if ( $charts ) { ?>
 122              <script type="text/javascript" src="https://www.google.com/jsapi"></script>
 123              <script type="text/javascript">
 124                       google.load('visualization', '1.0', {'packages':['corechart', 'geochart']});
 125              </script>
 126      <?php } ?>
 127      <script type="text/javascript">
 128      //<![CDATA[
 129          var ajaxurl  = '<?php echo yourls_admin_url( 'admin-ajax.php' ); ?>';
 130      //]]>
 131      </script>
 132      <?php yourls_do_action( 'html_head', $context ); ?>
 133  </head>
 134  <body class="<?php echo yourls_esc_attr($context); ?> <?php echo yourls_esc_attr($bodyclass); ?>">
 135  <div id="wrap">
 136      <?php
 137  }
 138  
 139  /**
 140   * Display HTML footer (including closing body & html tags)
 141   *
 142   * Function yourls_die() will call this function with the optional param set to false: most likely, if we're using yourls_die(),
 143   * there's a problem, so don't maybe add to it by sending another SQL query
 144   *
 145   * @param  bool $can_query  If set to false, will not try to send another query to DB server
 146   * @return void
 147   */
 148  function yourls_html_footer($can_query = true) {
 149      if($can_query & yourls_get_debug_mode()) {
 150          $num_queries = yourls_get_num_queries();
 151          $num_queries = ' &ndash; '. sprintf( yourls_n( '1 query', '%s queries', $num_queries ), $num_queries );
 152      } else {
 153          $num_queries = '';
 154      }
 155  
 156      ?>
 157      </div><?php // wrap ?>
 158      <footer id="footer" role="contentinfo"><p>
 159          <?php
 160          $footer  = yourls_s( 'Powered by %s', '<a href="http://yourls.org/" title="YOURLS">YOURLS</a> v ' . YOURLS_VERSION );
 161          $footer .= $num_queries;
 162          echo yourls_apply_filter( 'html_footer_text', $footer );
 163          ?>
 164      </p></footer>
 165      <?php if( yourls_get_debug_mode() ) {
 166          echo '<div style="text-align:left"><pre>';
 167          echo join( "\n", yourls_get_debug_log() );
 168          echo '</pre></div>';
 169      } ?>
 170      <?php yourls_do_action( 'html_footer', yourls_get_html_context() ); ?>
 171      </body>
 172      </html>
 173      <?php
 174  }
 175  
 176  /**
 177   * Display "Add new URL" box
 178   *
 179   * @param string $url URL to prefill the input with
 180   * @param string $keyword Keyword to prefill the input with
 181   * @return mixed void unless the 'shunt_html_addnew' filter is used
 182   */
 183  function yourls_html_addnew( string $url = '', string $keyword = '' ) {
 184      $pre = yourls_apply_filter( 'shunt_html_addnew', yourls_shunt_default(), $url, $keyword );
 185      if ( yourls_shunt_default() !== $pre ) {
 186          return $pre;
 187      }
 188      ?>
 189      <main role="main">
 190      <div id="new_url">
 191          <div>
 192              <form id="new_url_form" action="" method="get">
 193                  <div>
 194                      <label for="add-url"><strong><?php yourls_e( 'Enter the URL' ); ?></strong></label>:
 195                      <input type="text" id="add-url" name="url" value="<?php echo yourls_esc_attr($url); ?>" class="text" size="80" placeholder="https://" />
 196                      <label for="add-keyword"><?php yourls_e( 'Optional '); ?> : <strong><?php yourls_e('Custom short URL'); ?></strong></label>:
 197                      <input type="text" id="add-keyword" name="keyword" value="<?php echo yourls_esc_attr($keyword); ?>" class="text" size="8" />
 198                      <?php yourls_nonce_field( 'add_url', 'nonce-add' ); ?>
 199                      <input type="button" id="add-button" name="add-button" value="<?php yourls_e( 'Shorten The URL' ); ?>" class="button" onclick="add_link();" />
 200                  </div>
 201              </form>
 202              <div id="feedback" style="display:none"></div>
 203          </div>
 204          <?php yourls_do_action( 'html_addnew' ); ?>
 205      </div>
 206      <?php
 207  }
 208  
 209  /**
 210   * Display hidden modal for link delete confirmation
 211   *
 212   * @since 1.10.3
 213   * @param void
 214   * @return void
 215   */
 216  function yourls_delete_link_modal() {
 217      ?>
 218      <dialog id="delete-confirm-dialog">
 219          <div name="dialog_title"><?php yourls_e( 'Delete confirmation' ) ?></div>
 220          <div class="confirm-message">
 221              <p><strong><?php yourls_e( 'Really delete?' ) ?></strong></p>
 222              <ul>
 223              <li><?php yourls_e( 'Short URL' ) ?>: <span name="short_url"></span></li>
 224              <li><?php yourls_e( 'Title' ) ?>: <span name="title"></span></li>
 225              <li><?php yourls_e( 'URL' ) ?>: <span name="url"></span></li>
 226              </ul>
 227          </div>
 228          <div class="button-group">
 229              <input type="button" class="button primary" value="<?php yourls_e( 'Delete' ) ?>" onclick="remove_link_confirmed();">
 230              <input type="reset" class="button" value="<?php yourls_e( 'Cancel' ) ?>" onclick="remove_link_canceled(); return false;">
 231              <input type="hidden" name="keyword_id" value="">
 232          </div>
 233      </dialog>
 234      <?php
 235  }
 236  
 237  /**
 238   * Display main table's footer
 239   *
 240   * The $param array is defined in /admin/index.php, check the yourls_html_tfooter() call
 241   *
 242   * @param array $params Array of all required parameters
 243   * @return void
 244   */
 245  function yourls_html_tfooter( array $params = [] ):void {
 246      // Manually extract all parameters from the array. We prefer doing it this way, over using extract(),
 247      // to make things clearer and more explicit about what var is used.
 248      $search       = $params['search'];
 249      $search_text  = $params['search_text'];
 250      $search_in    = $params['search_in'];
 251      $sort_by      = $params['sort_by'];
 252      $sort_order   = $params['sort_order'];
 253      $page         = $params['page'];
 254      $perpage      = $params['perpage'];
 255      $click_filter = $params['click_filter'];
 256      $click_limit  = $params['click_limit'];
 257      $total_pages  = $params['total_pages'];
 258      $date_filter  = $params['date_filter'];
 259      $date_first   = $params['date_first'];
 260      $date_second  = $params['date_second'];
 261  
 262      ?>
 263      <tfoot>
 264          <tr>
 265              <th colspan="6">
 266              <div id="filter_form">
 267                  <form action="" method="get">
 268                      <div id="filter_options">
 269                          <?php
 270  
 271                          // First search control: text to search
 272                          $_input = '<input aria-label="' .yourls__( 'Search for' ). '" type="text" name="search" class="text" size="12" value="' . yourls_esc_attr( $search_text ) . '" />';
 273                          $_options = array(
 274                              'all'     => yourls__( 'All fields' ),
 275                              'keyword' => yourls__( 'Short URL' ),
 276                              'url'     => yourls__( 'URL' ),
 277                              'title'   => yourls__( 'Title' ),
 278                              'ip'      => yourls__( 'IP' ),
 279                          );
 280                          $_select = yourls_html_select( 'search_in', $_options, $search_in, false, yourls__( 'Search in' ) );
 281                          /* //translators: "Search for <input field with text to search> in <select dropdown with URL, title...>" */
 282                          yourls_se( 'Search for %1$s in %2$s', $_input , $_select );
 283                          echo "&ndash;\n";
 284  
 285                          // Second search control: order by
 286                          $_options = array(
 287                              'keyword'      => yourls__( 'Short URL' ),
 288                              'url'          => yourls__( 'URL' ),
 289                              'title'        => yourls__( 'Title' ),
 290                              'timestamp'    => yourls__( 'Date' ),
 291                              'ip'           => yourls__( 'IP' ),
 292                              'clicks'       => yourls__( 'Clicks' ),
 293                          );
 294                          $_select = yourls_html_select( 'sort_by', $_options, $sort_by, false,  yourls__( 'Sort by' ) );
 295                          $sort_order = isset( $sort_order ) ? $sort_order : 'desc' ;
 296                          $_options = array(
 297                              'asc'  => yourls__( 'Ascending' ),
 298                              'desc' => yourls__( 'Descending' ),
 299                          );
 300                          $_select2 = yourls_html_select( 'sort_order', $_options, $sort_order, false,  yourls__( 'Sort order' ) );
 301                          /* //translators: "Order by <criteria dropdown (date, clicks...)> in <order dropdown (Descending or Ascending)>" */
 302                          yourls_se( 'Order by %1$s %2$s', $_select , $_select2 );
 303                          echo "&ndash;\n";
 304  
 305                          // Third search control: Show XX rows
 306                          /* //translators: "Show <text field> rows" */
 307                          $_input = '<input aria-label="' .yourls__( 'Number of rows to show' ). '" type="text" name="perpage" class="text" size="2" value="' . yourls_esc_attr($perpage) . '" />';
 308                          yourls_se( 'Show %s rows',  $_input );
 309                          echo "<br/>\n";
 310  
 311                          // Fourth search control: Show links with more than XX clicks
 312                          $_options = array(
 313                              'more' => yourls__( 'more' ),
 314                              'less' => yourls__( 'less' ),
 315                          );
 316                          $_select = yourls_html_select( 'click_filter', $_options, $click_filter, false, yourls__( 'Show links with' ) );
 317                          $_input  = '<input aria-label="' .yourls__( 'Number of clicks' ). '" type="text" name="click_limit" class="text" size="4" value="' . yourls_esc_attr($click_limit) . '" /> ';
 318                          /* //translators: "Show links with <more/less> than <text field> clicks" */
 319                          yourls_se( 'Show links with %1$s than %2$s clicks', $_select, $_input );
 320                          echo "<br/>\n";
 321  
 322                          // Fifth search control: Show links created before/after/between ...
 323                          $_options = array(
 324                              'before'  => yourls__('before'),
 325                              'after'   => yourls__('after'),
 326                              'between' => yourls__('between'),
 327                          );
 328                          $_select = yourls_html_select( 'date_filter', $_options, $date_filter, false, yourls__('Show links created') );
 329                          $_input  = '<input aria-label="' .yourls__('Select a date') . '" type="text" name="date_first" id="date_first" class="text" size="12" value="' . yourls_esc_attr($date_first) . '" />';
 330                          $_and    = '<span id="date_and"' . ( $date_filter === 'between' ? ' style="display:inline"' : '' ) . '> &amp; </span>';
 331                          $_input2 = '<input aria-label="' .yourls__('Select an end date') . '" type="text" name="date_second" id="date_second" class="text" size="12" value="' . yourls_esc_attr($date_second) . '"' . ( $date_filter === 'between' ? ' style="display:inline"' : '' ) . '/>';
 332                          /* //translators: "Show links created <before/after/between> <date input> <"and" if applicable> <date input if applicable>" */
 333                          yourls_se( 'Show links created %1$s %2$s %3$s %4$s', $_select, $_input, $_and, $_input2 );
 334                          ?>
 335  
 336                          <div id="filter_buttons">
 337                              <input type="submit" id="submit-sort" value="<?php yourls_e('Search'); ?>" class="button primary" />
 338                              &nbsp;
 339                              <input type="button" id="submit-clear-filter" value="<?php yourls_e('Clear'); ?>" class="button" onclick="window.parent.location.href = 'index.php'" />
 340                          </div>
 341  
 342                      </div>
 343                  </form>
 344              </div>
 345  
 346              <?php
 347              // Remove empty keys from the $params array so it doesn't clutter the pagination links
 348              $params = array_filter( $params, function($val){ return $val !== '';} ); // remove keys with empty values
 349  
 350              if( isset( $search_text ) ) {
 351                  $params['search'] = $search_text;
 352                  unset( $params['search_text'] );
 353              }
 354              ?>
 355  
 356              <div id="pagination">
 357                  <span class="navigation">
 358                  <?php if( $total_pages > 1 ) { ?>
 359                      <span class="nav_total"><?php echo sprintf( yourls_n( '1 page', '%s pages', $total_pages ), $total_pages ); ?></span>
 360                      <?php
 361                      $base_page = yourls_admin_url( 'index.php' );
 362                      // Pagination offsets: min( max ( zomg! ) );
 363                      $p_start = max(  min( $total_pages - 4, $page - 2 ), 1 );
 364                      $p_end = min( max( 5, $page + 2 ), $total_pages );
 365                      if( $p_start >= 2 ) {
 366                          $link = yourls_add_query_arg( array_merge( $params, array( 'page' => 1 ) ), $base_page );
 367                          echo '<span class="nav_link nav_first"><a href="' . $link . '" title="' . yourls_esc_attr__('Go to First Page') . '">' . yourls__( '&laquo; First' ) . '</a></span>';
 368                          echo '<span class="nav_link nav_prev"></span>';
 369                      }
 370                      for( $i = $p_start ; $i <= $p_end; $i++ ) {
 371                          if( $i == $page ) {
 372                              echo "<span class='nav_link nav_current'>$i</span>";
 373                          } else {
 374                              $link = yourls_add_query_arg( array_merge( $params, array( 'page' => $i ) ), $base_page );
 375                              echo '<span class="nav_link nav_goto"><a href="' . $link . '" title="' . sprintf( yourls_esc_attr( 'Page %s' ), $i ) .'">'.$i.'</a></span>';
 376                          }
 377                      }
 378                      if( ( $p_end ) < $total_pages ) {
 379                          $link = yourls_add_query_arg( array_merge( $params, array( 'page' => $total_pages ) ), $base_page );
 380                          echo '<span class="nav_link nav_next"></span>';
 381                          echo '<span class="nav_link nav_last"><a href="' . $link . '" title="' . yourls_esc_attr__('Go to Last Page') . '">' . yourls__( 'Last &raquo;' ) . '</a></span>';
 382                      }
 383                      ?>
 384                  <?php } ?>
 385                  </span>
 386              </div>
 387              </th>
 388          </tr>
 389          <?php yourls_do_action( 'html_tfooter' ); ?>
 390      </tfoot>
 391      <?php
 392  }
 393  
 394  /**
 395   * Return or display a select dropdown field
 396   *
 397   * @since 1.6
 398   *
 399   * @param  string  $name      HTML 'name' (also use as the HTML 'id')
 400   * @param  array   $options   array of 'value' => 'Text displayed'
 401   * @param  string  $selected  optional 'value' from the $options array that will be highlighted
 402   * @param  boolean $display   false (default) to return, true to echo
 403   * @param  string  $label     ARIA label of the element
 404   * @return string HTML content of the select element
 405   */
 406  function yourls_html_select( string $name, array $options, string $selected = '', bool $display = false, string $label = '' ):string {
 407      // Allow plugins to filter the options -- see #3262
 408      $options = yourls_apply_filter( 'html_select_options', $options, $name, $selected, $display, $label );
 409      $_name = yourls_esc_attr( $name );
 410      $_label = yourls_esc_attr( $label );
 411      $html = "<select aria-label='$_label' name='$_name' id='$_name' size='1'>\n";
 412      foreach( $options as $value => $text ) {
 413          $_value = yourls_esc_attr( $value );
 414          $_text = yourls_esc_html( $text );
 415          $html .= "<option value='$_value' ";
 416          $html .= $selected == $value ? ' selected="selected"' : '';
 417          $html .= ">$_text</option>\n";
 418      }
 419      $html .= "</select>\n";
 420      $html  = yourls_apply_filter( 'html_select', $html, $name, $options, $selected, $display );
 421      if( $display )
 422          echo $html;
 423      return $html;
 424  }
 425  
 426  
 427  /**
 428   * Display the Quick Share box
 429   *
 430   * @param string $longurl          Long URL
 431   * @param string $shorturl         Short URL
 432   * @param string $title            Title
 433   * @param string $text             Text to display
 434   * @param string $shortlink_title  Optional replacement for 'Your short link'
 435   * @param string $share_title      Optional replacement for 'Quick Share'
 436   * @param bool   $hidden           Optional. Hide the box by default (with css "display:none")
 437   * @return void
 438   */
 439  function yourls_share_box( $longurl, $shorturl, $title = '', $text='', $shortlink_title = '', $share_title = '', $hidden = false ) {
 440      if ( $shortlink_title == '' )
 441          $shortlink_title = '<h2>' . yourls__( 'Your short link' ) . '</h2>';
 442      if ( $share_title == '' )
 443          $share_title = '<h2>' . yourls__( 'Quick Share' ) . '</h2>';
 444  
 445      // Allow plugins to short-circuit the whole function
 446      $pre = yourls_apply_filter( 'shunt_share_box', yourls_shunt_default() );
 447      if ( yourls_shunt_default() !== $pre ) {
 448          return $pre;
 449      }
 450  
 451      // Make sure IDN domains are in their UTF8 form
 452      $shorturl = yourls_normalize_uri($shorturl);
 453  
 454      $text   = ( $text ? '"'.$text.'" ' : '' );
 455      $title  = ( $title ? "$title " : '' );
 456      $share  = yourls_esc_textarea( $title.$text.$shorturl );
 457      $count  = 280 - strlen( $share );
 458      $hidden = ( $hidden ? 'style="display:none;"' : '' );
 459  
 460      // Allow plugins to filter all data
 461      $data = compact( 'longurl', 'shorturl', 'title', 'text', 'shortlink_title', 'share_title', 'share', 'count', 'hidden' );
 462      $data = yourls_apply_filter( 'share_box_data', $data );
 463      extract( $data );
 464  
 465      $_share = rawurlencode( $share );
 466      $_url   = rawurlencode( $shorturl );
 467      ?>
 468  
 469      <div id="shareboxes" <?php echo $hidden; ?>>
 470  
 471          <?php yourls_do_action( 'shareboxes_before', $longurl, $shorturl, $title, $text ); ?>
 472  
 473          <div id="copybox" class="share">
 474          <?php echo $shortlink_title; ?>
 475              <p><input id="copylink" class="text" size="32" value="<?php echo yourls_esc_url( $shorturl ); ?>" /></p>
 476              <p><small><?php yourls_e( 'Long link' ); ?>: <a id="origlink" href="<?php echo yourls_esc_url( $longurl ); ?>"><?php echo yourls_esc_url( $longurl ); ?></a></small>
 477              <?php if( yourls_do_log_redirect() ) { ?>
 478              <br/><small><?php yourls_e( 'Stats' ); ?>: <a id="statlink" href="<?php echo yourls_esc_url( $shorturl ); ?>+"><?php echo yourls_esc_url( $shorturl ); ?>+</a></small>
 479              <input type="hidden" id="titlelink" value="<?php echo yourls_esc_attr( $title ); ?>" />
 480              <?php } ?>
 481              </p>
 482          </div>
 483  
 484          <?php yourls_do_action( 'shareboxes_middle', $longurl, $shorturl, $title, $text ); ?>
 485  
 486          <div id="sharebox" class="share">
 487              <?php echo $share_title; ?>
 488              <div id="tweet">
 489                  <span id="charcount" class="hide-if-no-js"><?php echo $count; ?></span>
 490                  <textarea id="tweet_body"><?php echo $share; ?></textarea>
 491              </div>
 492              <p id="share_links"><?php yourls_e( 'Share with' ); ?>
 493                  <a id="share_tw" href="https://twitter.com/intent/tweet?text=<?php echo $_share; ?>" title="<?php yourls_e( 'Tweet this!' ); ?>" onclick="share('tw');return false">Twitter</a>
 494                  <a id="share_fb" href="https://www.facebook.com/share.php?u=<?php echo $_url; ?>" title="<?php yourls_e( 'Share on Facebook' ); ?>" onclick="share('fb');return false;">Facebook</a>
 495                  <?php
 496                  yourls_do_action( 'share_links', $longurl, $shorturl, $title, $text );
 497                  // Note: on the main admin page, there are no parameters passed to the sharebox when it's drawn.
 498                  ?>
 499              </p>
 500          </div>
 501  
 502          <?php yourls_do_action( 'shareboxes_after', $longurl, $shorturl, $title, $text ); ?>
 503  
 504      </div>
 505  
 506      <?php
 507  }
 508  
 509  /**
 510   * Die die die
 511   *
 512   * @see https://www.youtube.com/watch?v=zSiKETBjARk
 513   * @param string $message
 514   * @param string $title
 515   * @param int $header_code
 516   * @return void
 517   */
 518  function yourls_die( string $message = '', string $title = '', int $header_code = 200 ) {
 519      yourls_do_action( 'pre_yourls_die', $message, $title, $header_code );
 520  
 521      yourls_status_header( $header_code );
 522  
 523      if( !yourls_did_action( 'html_head' ) ) {
 524          yourls_html_head();
 525          yourls_html_logo();
 526      }
 527  
 528      $title = yourls_apply_filter( 'die_title', "<h2>$title</h2>" );
 529      $message = yourls_apply_filter( 'die_message', "<p>$message</p>" );
 530      $allowed = [
 531          'strong' => [],
 532          'em'     => [],
 533          'tt'     => [],
 534          'code'   => [],
 535          'h2'     => [],
 536          'br'     => [],
 537          'p'      => ['class' => true],
 538      ];
 539      echo yourls_esc_html_with_whitelist( $title . $message, $allowed );
 540      // Hook into 'yourls_die' to add more elements or messages to that page
 541      yourls_do_action( 'yourls_die' );
 542      if( !yourls_did_action( 'html_footer' ) ) {
 543          yourls_html_footer(false);
 544      }
 545  
 546      // die with a value in case we're running tests, so PHPUnit doesn't exit with 0 as if success
 547      die(1);
 548  }
 549  
 550  /**
 551   * Return an "Edit" row for the main table
 552   *
 553   * @param string $keyword Keyword to edit
 554   * @param string $id
 555   * @return string HTML of the edit row
 556   */
 557  function yourls_table_edit_row( $keyword, $id ) {
 558      $keyword = yourls_sanitize_keyword($keyword);
 559      $url = yourls_get_keyword_longurl( $keyword );
 560      $title = htmlspecialchars( yourls_get_keyword_title( $keyword ) );
 561      $safe_url = yourls_esc_attr( $url );
 562      $safe_title = yourls_esc_attr( $title );
 563      $safe_keyword = yourls_esc_attr( $keyword );
 564  
 565      // Make strings sprintf() safe: '%' -> '%%'
 566      $safe_url = str_replace( '%', '%%', $safe_url );
 567      $safe_title = str_replace( '%', '%%', $safe_title );
 568  
 569      $www = yourls_link();
 570  
 571      $nonce = yourls_create_nonce( 'edit-save_'.$id );
 572  
 573      if( $url ) {
 574          $return = <<<RETURN
 575  <tr id="edit-$id" class="edit-row"><td colspan="5" class="edit-row"><strong>%s</strong>:<input type="text" id="edit-url-$id" name="edit-url-$id" value="$safe_url" class="text" size="70" /><br/><strong>%s</strong>: $www<input type="text" id="edit-keyword-$id" name="edit-keyword-$id" value="$safe_keyword" class="text" size="10" /><br/><strong>%s</strong>: <input type="text" id="edit-title-$id" name="edit-title-$id" value="$safe_title" class="text" size="60" /></td><td colspan="1"><input type="button" id="edit-submit-$id" name="edit-submit-$id" value="%s" title="%s" class="button" onclick="edit_link_save('$id');" />&nbsp;<input type="button" id="edit-close-$id" name="edit-close-$id" value="%s" title="%s" class="button" onclick="edit_link_hide('$id');" /><input type="hidden" id="old_keyword_$id" value="$safe_keyword"/><input type="hidden" id="nonce_$id" value="$nonce"/></td></tr>
 576  RETURN;
 577          $return = sprintf( $return, yourls__( 'Long URL' ), yourls__( 'Short URL' ), yourls__( 'Title' ), yourls__( 'Save' ), yourls__( 'Save new values' ), yourls__( 'Cancel' ), yourls__( 'Cancel editing' ) );
 578      } else {
 579          $return = '<tr class="edit-row notfound"><td colspan="6" class="edit-row notfound">' . yourls__( 'Error, URL not found' ) . '</td></tr>';
 580      }
 581  
 582      $return = yourls_apply_filter( 'table_edit_row', $return, $keyword, $url, $title );
 583  
 584      return $return;
 585  }
 586  
 587  /**
 588   * Return an "Add" row for the main table
 589   *
 590   * @param string $keyword     Keyword (short URL)
 591   * @param string $url         URL (long URL)
 592   * @param string $title       Title
 593   * @param string $ip          IP
 594   * @param int|string $clicks  Number of clicks
 595   * @param string $timestamp   Timestamp
 596   * @param int    $row_id      Numeric value used to form row IDs, defaults to one
 597   * @return string             HTML of the row
 598   */
 599  function yourls_table_add_row( string $keyword, string $url, string $title, string $ip, int|string $clicks, string $timestamp, int $row_id = 1 ):string {
 600      $keyword  = yourls_sanitize_keyword($keyword);
 601      $id       = yourls_unique_element_id('yid', $row_id);
 602      $shorturl = yourls_link( $keyword );
 603  
 604      $statlink = yourls_statlink( $keyword );
 605  
 606      $delete_link = yourls_nonce_url( 'delete-link_'.$id,
 607          yourls_add_query_arg( array( 'id' => $id, 'action' => 'delete', 'keyword' => $keyword ), yourls_admin_url( 'admin-ajax.php' ) )
 608      );
 609  
 610      $edit_link = yourls_nonce_url( 'edit-link_'.$id,
 611          yourls_add_query_arg( array( 'id' => $id, 'action' => 'edit', 'keyword' => $keyword ), yourls_admin_url( 'admin-ajax.php' ) )
 612      );
 613  
 614      // Action link buttons: the array
 615      $actions = array(
 616          'stats' => array(
 617              'href'    => $statlink,
 618              'id'      => "statlink-$id",
 619              'title'   => yourls_esc_attr__( 'Stats' ),
 620              'anchor'  => yourls__( 'Stats' ),
 621          ),
 622          'share' => array(
 623              'href'    => '',
 624              'id'      => "share-button-$id",
 625              'title'   => yourls_esc_attr__( 'Share' ),
 626              'anchor'  => yourls__( 'Share' ),
 627              'onclick' => "toggle_share('$id');return false;",
 628          ),
 629          'edit' => array(
 630              'href'    => $edit_link,
 631              'id'      => "edit-button-$id",
 632              'title'   => yourls_esc_attr__( 'Edit' ),
 633              'anchor'  => yourls__( 'Edit' ),
 634              'onclick' => "edit_link_display('$id');return false;",
 635          ),
 636          'delete' => array(
 637              'href'    => $delete_link,
 638              'id'      => "delete-button-$id",
 639              'title'   => yourls_esc_attr__( 'Delete' ),
 640              'anchor'  => yourls__( 'Delete' ),
 641              'onclick' => "remove_link('$id');return false;",
 642          )
 643      );
 644      $actions = yourls_apply_filter( 'table_add_row_action_array', $actions, $keyword );
 645  
 646      // Action link buttons: the HTML
 647      $action_links = '';
 648      foreach( $actions as $key => $action ) {
 649          $onclick = isset( $action['onclick'] ) ? 'onclick="' . $action['onclick'] . '"' : '' ;
 650          $action_links .= sprintf( '<a href="%s" id="%s" title="%s" class="%s" %s>%s</a>',
 651              $action['href'], $action['id'], $action['title'], 'button button_'.$key, $onclick, $action['anchor']
 652          );
 653      }
 654      $action_links = yourls_apply_filter( 'action_links', $action_links, $keyword, $url, $ip, $clicks, $timestamp );
 655  
 656      if( ! $title )
 657          $title = $url;
 658  
 659      $protocol_warning = '';
 660      if( ! in_array( yourls_get_protocol( $url ) , array( 'http://', 'https://' ) ) )
 661          $protocol_warning = yourls_apply_filter( 'add_row_protocol_warning', '<span class="warning" title="' . yourls__( 'Not a common link' ) . '">&#9733;</span>' );
 662  
 663      // Row cells: the array
 664      $cells = array(
 665          'keyword' => array(
 666              'template'      => '<a href="%shorturl%">%keyword_html%</a>',
 667              'shorturl'      => yourls_esc_url( $shorturl ),
 668              'keyword_html'  => yourls_esc_html( $keyword ),
 669          ),
 670          'url' => array(
 671              'template'      => '<a href="%long_url%" title="%title_attr%">%title_html%</a><br/><small>%warning%<a href="%long_url%">%long_url_html%</a></small>',
 672              'long_url'      => yourls_esc_url( $url ),
 673              'title_attr'    => yourls_esc_attr( $title ),
 674              'title_html'    => yourls_esc_html( yourls_trim_long_string( $title ) ),
 675              'long_url_html' => yourls_esc_html( yourls_trim_long_string( urldecode( $url ) ) ),
 676              'warning'       => $protocol_warning,
 677          ),
 678          'timestamp' => array(
 679              'template' => '<span class="timestamp" aria-hidden="true">%timestamp%</span> %date%',
 680              'timestamp' => $timestamp,
 681              'date'     => yourls_date_i18n( yourls_get_datetime_format(yourls__('M d, Y H:i')), yourls_get_timestamp( $timestamp )),
 682          ),
 683          'ip' => array(
 684              'template' => '%ip%',
 685              'ip'       => yourls_sanitize_ip($ip),
 686          ),
 687          'clicks' => array(
 688              'template' => '%clicks%',
 689              'clicks'   => yourls_number_format_i18n( $clicks, 0 ),
 690          ),
 691          'actions' => array(
 692              'template' => '%actions% <input type="hidden" id="keyword_%id%" value="%keyword%"/>',
 693              'actions'  => $action_links,
 694              'id'       => $id,
 695              'keyword'  => $keyword,
 696          ),
 697      );
 698      $cells = yourls_apply_filter( 'table_add_row_cell_array', $cells, $keyword, $url, $title, $ip, $clicks, $timestamp );
 699  
 700      // Row cells: the HTML. Replace every %stuff% in 'template' with 'stuff' value.
 701      $row = "<tr id=\"id-$id\">";
 702      foreach( $cells as $cell_id => $elements ) {
 703          $row .= sprintf( '<td class="%s" id="%s">', $cell_id, $cell_id . '-' . $id );
 704          $row .= preg_replace_callback( '/%([^%]+)?%/', function( $match ) use ( $elements ) { return $elements[ $match[1] ]; }, $elements['template'] );
 705          $row .= '</td>';
 706      }
 707      $row .= "</tr>";
 708      $row  = yourls_apply_filter( 'table_add_row', $row, $keyword, $url, $title, $ip, $clicks, $timestamp );
 709  
 710      return $row;
 711  }
 712  
 713  /**
 714   * Echo the main table head
 715   *
 716   * @return void
 717   */
 718  function yourls_table_head() {
 719      $start = '<table id="main_table" class="tblSorter" cellpadding="0" cellspacing="1"><thead><tr>'."\n";
 720      echo yourls_apply_filter( 'table_head_start', $start );
 721  
 722      $cells = yourls_apply_filter( 'table_head_cells', array(
 723          'shorturl' => yourls__( 'Short URL' ),
 724          'longurl'  => yourls__( 'Original URL' ),
 725          'date'     => yourls__( 'Date' ),
 726          'ip'       => yourls__( 'IP' ),
 727          'clicks'   => yourls__( 'Clicks' ),
 728          'actions'  => yourls__( 'Actions' )
 729      ) );
 730      foreach( $cells as $k => $v ) {
 731          echo "<th id='main_table_head_$k'><span>$v</span></th>\n";
 732      }
 733  
 734      $end = "</tr></thead>\n";
 735      echo yourls_apply_filter( 'table_head_end', $end );
 736  }
 737  
 738  /**
 739   * Echo the tbody start tag
 740   *
 741   * @return void
 742   */
 743  function yourls_table_tbody_start() {
 744      echo yourls_apply_filter( 'table_tbody_start', '<tbody>' );
 745  }
 746  
 747  /**
 748   * Echo the tbody end tag
 749   *
 750   * @return void
 751   */
 752  function yourls_table_tbody_end() {
 753      echo yourls_apply_filter( 'table_tbody_end', '</tbody>' );
 754  }
 755  
 756  /**
 757   * Echo the table start tag
 758   *
 759   * @return void
 760   */
 761  function yourls_table_end() {
 762      echo yourls_apply_filter( 'table_end', '</table></main>' );
 763  }
 764  
 765  
 766  
 767  /**
 768   * Echo HTML tag for a link
 769   *
 770   * @param string $href     URL to link to
 771   * @param string $anchor   Anchor text
 772   * @param string $element  Element id
 773   * @return void
 774  */
 775  function yourls_html_link( $href, $anchor = '', $element = '' ) {
 776      if( !$anchor )
 777          $anchor = $href;
 778      if( $element )
 779          $element = sprintf( 'id="%s"', yourls_esc_attr( $element ) );
 780      $link = sprintf( '<a href="%s" %s>%s</a>', yourls_esc_url( $href ), $element, yourls_esc_html( $anchor ) );
 781      echo yourls_apply_filter( 'html_link', $link );
 782  }
 783  
 784  /**
 785   * Display the login screen. Nothing past this point.
 786   *
 787   * @param string $error_msg  Optional error message to display
 788   * @return void
 789   */
 790  function yourls_login_screen( string $error_msg = '' ) {
 791      yourls_html_head( 'login' );
 792  
 793      $action = ( isset( $_GET['action'] ) && $_GET['action'] == 'logout' ? '?' : '' );
 794  
 795      yourls_html_logo();
 796      ?>
 797      <main role="main">
 798          <div id="login">
 799              <form method="post" action="<?php echo yourls_esc_attr($action); ?>"> <?php // reset any QUERY parameters ?>
 800                  <?php
 801                      if( !empty( $error_msg ) ) {
 802                          echo '<p id="error-message" class="error">'. yourls_esc_html($error_msg).'</p>';
 803                      }
 804                      yourls_do_action( 'login_form_top' );
 805                  ?>
 806                  <p>
 807                      <label for="username"><?php yourls_e( 'Username' ); ?></label><br />
 808                      <input type="text" id="username" aria-describedby="error-message" name="username" class="text" autocomplete="username" />
 809                  </p>
 810                  <p>
 811                      <label for="password"><?php yourls_e( 'Password' ); ?></label><br />
 812                      <input type="password" id="password" name="password" class="text" autocomplete="current-password" />
 813                  </p>
 814                  <?php
 815                      yourls_do_action( 'login_form_bottom' );
 816                  ?>
 817                  <p style="text-align: right;">
 818                      <?php yourls_nonce_field('admin_login'); ?>
 819                      <input type="submit" id="submit" name="submit" value="<?php yourls_e( 'Login' ); ?>" class="button" />
 820                  </p>
 821                  <?php
 822                      yourls_do_action( 'login_form_end' );
 823                  ?>
 824              </form>
 825              <script type="text/javascript">$('#username').focus();</script>
 826          </div>
 827      </main>
 828      <?php
 829      yourls_html_footer();
 830      die();
 831  }
 832  
 833  
 834  /**
 835   * Display the admin menu
 836   *
 837   * @return void
 838   */
 839  function yourls_html_menu() {
 840      // Build menu links
 841      if( defined( 'YOURLS_USER' ) ) {
 842          // Create a logout link with a nonce associated to fake user 'logout' : the user is not yet defined
 843          // when the logout check is done -- see yourls_is_valid_user()
 844          $logout_url = yourls_nonce_url( 'admin_logout',
 845          yourls_add_query_arg(['action' => 'logout'], yourls_admin_url('index.php')), 'nonce', 'logout');
 846          $logout_link = yourls_apply_filter('logout_link', sprintf( yourls__('Hello <strong>%s</strong>'), YOURLS_USER ) . ' (<a href="' . $logout_url . '" title="' . yourls_esc_attr__( 'Logout' ) . '">' . yourls__( 'Logout' ) . '</a>)' );
 847      } else {
 848          $logout_link = yourls_apply_filter( 'logout_link', '' );
 849      }
 850      $help_link   = yourls_apply_filter( 'help_link',   '<a href="' . yourls_site_url( false ) .'/readme.html">' . yourls__( 'Help' ) . '</a>' );
 851  
 852      $admin_links    = array();
 853      $admin_sublinks = array();
 854  
 855      $admin_links['admin'] = array(
 856          'url'    => yourls_admin_url( 'index.php' ),
 857          'title'  => yourls__( 'Go to the admin interface' ),
 858          'anchor' => yourls__( 'Admin interface' )
 859      );
 860  
 861      if( yourls_is_admin() ) {
 862          $admin_links['tools'] = array(
 863              'url'    => yourls_admin_url( 'tools.php' ),
 864              'anchor' => yourls__( 'Tools' )
 865          );
 866          $admin_links['plugins'] = array(
 867              'url'    => yourls_admin_url( 'plugins.php' ),
 868              'anchor' => yourls__( 'Manage Plugins' )
 869          );
 870          $admin_sublinks['plugins'] = yourls_list_plugin_admin_pages();
 871      }
 872  
 873      $admin_links    = yourls_apply_filter( 'admin_links',    $admin_links );
 874      $admin_sublinks = yourls_apply_filter( 'admin_sublinks', $admin_sublinks );
 875  
 876      // Now output menu
 877      echo '<nav role="navigation"><ul id="admin_menu">'."\n";
 878      if ( yourls_is_private() && !empty( $logout_link ) )
 879          echo '<li id="admin_menu_logout_link">' . $logout_link .'</li>';
 880  
 881      foreach( (array)$admin_links as $link => $ar ) {
 882          if( isset( $ar['url'] ) ) {
 883              $anchor = isset( $ar['anchor'] ) ? $ar['anchor'] : $link;
 884              $title  = isset( $ar['title'] ) ? 'title="' . $ar['title'] . '"' : '';
 885              printf( '<li id="admin_menu_%s_link" class="admin_menu_toplevel"><a href="%s" %s>%s</a>', $link, $ar['url'], $title, $anchor );
 886          }
 887          // Output submenu if any. TODO: clean up, too many code duplicated here
 888          if( isset( $admin_sublinks[$link] ) ) {
 889              echo "<ul>\n";
 890              foreach( $admin_sublinks[$link] as $link => $ar ) {
 891                  if( isset( $ar['url'] ) ) {
 892                      $anchor = isset( $ar['anchor'] ) ? $ar['anchor'] : $link;
 893                      $title  = isset( $ar['title'] ) ? 'title="' . $ar['title'] . '"' : '';
 894                      printf( '<li id="admin_menu_%s_link" class="admin_menu_sublevel admin_menu_sublevel_%s"><a href="%s" %s>%s</a>', $link, $link, $ar['url'], $title, $anchor );
 895                  }
 896              }
 897              echo "</ul>\n";
 898          }
 899      }
 900  
 901      if ( isset( $help_link ) )
 902          echo '<li id="admin_menu_help_link">' . $help_link .'</li>';
 903  
 904      yourls_do_action( 'admin_menu' );
 905      echo "</ul></nav>\n";
 906      yourls_do_action( 'admin_notices' );
 907      yourls_do_action( 'admin_notice' ); // because I never remember if it's 'notices' or 'notice'
 908      /*
 909      To display a notice:
 910      $message = "<div>OMG, dude, I mean!</div>" );
 911      yourls_add_action( 'admin_notices', function() use ( $message ) { echo (string) $message; } );
 912      */
 913  }
 914  
 915  /**
 916   * Wrapper function to display admin notices
 917   *
 918   * @param string $message Message to display
 919   * @param string $style    Message style (default: 'notice')
 920   * @return void
 921   */
 922  function yourls_add_notice( $message, $style = 'notice' ) {
 923      // Escape single quotes in $message to avoid breaking the anonymous function
 924      $message = yourls_notice_box( strtr( $message, array( "'" => "\'" ) ), $style );
 925      yourls_add_action( 'admin_notices', function() use ( $message ) { echo (string) $message; } );
 926  }
 927  
 928  /**
 929   * Return a formatted notice
 930   *
 931   * @param string $message  Message to display
 932   * @param string $style    CSS class to use for the notice
 933   * @return string          HTML of the notice
 934   */
 935  function yourls_notice_box( string $message, string $style = 'notice' ):string {
 936      $style = yourls_esc_attr( $style );
 937      $allowed = [
 938          'a'      => ['href' => true, 'title' => true],
 939          'strong' => [],
 940          'em'     => [],
 941          'code'   => [],
 942          'br'     => [],
 943          'p'      => ['class' => true],
 944      ];
 945      $message = yourls_esc_html_with_whitelist($message, $allowed);
 946  
 947      return <<<HTML
 948      <div class="$style">
 949      <p>$message</p>
 950      </div>
 951  HTML;
 952  }
 953  
 954  /**
 955   * Display a page
 956   *
 957   * Includes content of a PHP file from the YOURLS_PAGEDIR directory, as if it
 958   * were a standard short URL (ie http://sho.rt/$page)
 959   *
 960   * @since 1.0
 961   * @param string $page  PHP file to display
 962   * @return void
 963   */
 964  function yourls_page( $page ) {
 965      if( !yourls_is_page($page)) {
 966          yourls_die( yourls_s('Page "%1$s" not found', $page), yourls__('Not found'), 404 );
 967      }
 968  
 969      yourls_do_action( 'pre_page', $page );
 970      $load = yourls_include_file_sandbox(YOURLS_PAGEDIR . "/$page.php");
 971      if (is_string($load)) {
 972          yourls_die( $load, yourls__('Not found'), 404 );
 973      }
 974      yourls_do_action( 'post_page', $page );
 975  }
 976  
 977  /**
 978   * Display the language attributes for the HTML tag.
 979   *
 980   * Builds up a set of html attributes containing the text direction and language
 981   * information for the page. Stolen from WP.
 982   *
 983   * @since 1.6
 984   * @return void
 985   */
 986  function yourls_html_language_attributes() {
 987      $attributes = array();
 988      $output = '';
 989  
 990      $attributes[] = ( yourls_is_rtl() ? 'dir="rtl"' : 'dir="ltr"' );
 991  
 992      $doctype = yourls_apply_filter( 'html_language_attributes_doctype', 'html' );
 993      // Experimental: get HTML lang from locale. Should work. Convert fr_FR -> fr-FR
 994      if ( $lang = str_replace( '_', '-', yourls_get_locale() ) ) {
 995          if( $doctype == 'xhtml' ) {
 996              $attributes[] = "xml:lang=\"$lang\"";
 997          } else {
 998              $attributes[] = "lang=\"$lang\"";
 999          }
1000      }
1001  
1002      $output = implode( ' ', $attributes );
1003      $output = yourls_apply_filter( 'html_language_attributes', $output );
1004      echo $output;
1005  }
1006  
1007  /**
1008   * Output translated strings used by the Javascript calendar
1009   *
1010   * @since 1.6
1011   * @return void
1012   */
1013  function yourls_l10n_calendar_strings() {
1014      echo "\n<script>\n";
1015      echo "var l10n_cal_month = " . json_encode( array_values( yourls_l10n_months() ) ) . ";\n";
1016      echo "var l10n_cal_days = " . json_encode( array_values( yourls_l10n_weekday_initial() ) ) . ";\n";
1017      echo "var l10n_cal_today = \"" . yourls_esc_js( yourls__( 'Today' ) ) . "\";\n";
1018      echo "var l10n_cal_close = \"" . yourls_esc_js( yourls__( 'Close' ) ) . "\";\n";
1019      echo "</script>\n";
1020  
1021      // Dummy returns, to initialize l10n strings used in the calendar
1022      yourls__( 'Today' );
1023      yourls__( 'Close' );
1024  }
1025  
1026  
1027  /**
1028   * Display a notice if there is a newer version of YOURLS available
1029   *
1030   * @since 1.7
1031   * @param string $compare_with Optional, YOURLS version to compare to
1032   * @return void
1033   */
1034  function yourls_new_core_version_notice($compare_with = null) {
1035      $compare_with = $compare_with ?: YOURLS_VERSION;
1036  
1037      $checks = yourls_get_option( 'core_version_checks' );
1038      $latest = isset($checks->last_result->latest) ? yourls_sanitize_version($checks->last_result->latest) : false;
1039  
1040      if( $latest AND version_compare( $latest, $compare_with, '>' ) ) {
1041          yourls_do_action('new_core_version_notice', $latest);
1042          $msg = yourls_s( '<a href="%s">YOURLS version %s</a> is available. Please update!', 'http://yourls.org/download', $latest );
1043          yourls_add_notice( $msg );
1044      }
1045  }
1046  
1047  /**
1048   * Display or return HTML for a bookmarklet link
1049   *
1050   * @since 1.7.1
1051   * @param string $href    bookmarklet link (presumably minified code with "javascript:" scheme)
1052   * @param string $anchor  link anchor
1053   * @param bool   $echo    true to display, false to return the HTML
1054   * @return string         the HTML for a bookmarklet link
1055   */
1056  function yourls_bookmarklet_link( string $href, string $anchor, bool $echo = true ):string {
1057      $alert = yourls_esc_attr__( 'Drag to your toolbar!' );
1058      $href = yourls_esc_attr( $href );
1059      $anchor = yourls_esc_html( $anchor );
1060      $link = <<<LINK
1061      <a href="$href" class="bookmarklet" onclick="alert('$alert');return false;">$anchor</a>
1062  LINK;
1063  
1064      if( $echo ) {
1065          echo $link;
1066      }
1067      return $link;
1068  }
1069  
1070  /**
1071   * Set HTML context (stats, index, infos, ...)
1072   *
1073   * @since  1.7.3
1074   * @param  string  $context
1075   * @return void
1076   */
1077  function yourls_set_html_context($context) {
1078      yourls_get_db('read-set_html_context')->set_html_context($context);
1079  }
1080  
1081  /**
1082   * Get HTML context (stats, index, infos, ...)
1083   *
1084   * @since  1.7.3
1085   * @return string
1086   */
1087  function yourls_get_html_context() {
1088      return yourls_get_db('read-get_html_context')->get_html_context();
1089  }
1090  
1091  /**
1092   * Print HTML link for favicon
1093   *
1094   * @since 1.7.10
1095   * @return mixed|void
1096   */
1097  function yourls_html_favicon() {
1098      // Allow plugins to short-circuit the whole function
1099      $pre = yourls_apply_filter( 'shunt_html_favicon', yourls_shunt_default() );
1100      if ( yourls_shunt_default() !== $pre ) {
1101          return $pre;
1102      }
1103  
1104      printf( '<link rel="shortcut icon" href="%s" />', yourls_get_yourls_favicon_url(false) );
1105  }


Generated: Sun Aug 9 05:10:27 2026 Cross-referenced by PHPXref 0.7.1