| [ Index ] |
PHP Cross Reference of YOURLS |
[Summary view] [Print] [Text view]
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 — Your Own URL Shortener | ' . yourls_link(); 81 $_title = empty($_title_page) ? $_title : $_title_page . ' — ' . $_title; 82 $title = $title ? $title . " « " . $_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 $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 » 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 $context; ?> <?php echo $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 = ' – '. 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 void 182 */ 183 function yourls_html_addnew( $url = '', $keyword = '' ) { 184 $pre = yourls_apply_filter( 'shunt_html_addnew', false, $url, $keyword ); 185 if ( false !== $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 $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 $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( $params = array() ) { 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 "–\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 "–\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="' . $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="' . $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="' . $date_first . '" />'; 330 $_and = '<span id="date_and"' . ( $date_filter === 'between' ? ' style="display:inline"' : '' ) . '> & </span>'; 331 $_input2 = '<input aria-label="' .yourls__('Select an end date') . '" type="text" name="date_second" id="date_second" class="text" size="12" value="' . $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 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__( '« 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 »' ) . '</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( $name, $options, $selected = '', $display = false, $label = '' ) { 407 // Allow plugins to filter the options -- see #3262 408 $options = yourls_apply_filter( 'html_select_options', $options, $name, $selected, $display, $label ); 409 $html = "<select aria-label='$label' name='$name' id='$name' size='1'>\n"; 410 foreach( $options as $value => $text ) { 411 $html .= "<option value='$value' "; 412 $html .= $selected == $value ? ' selected="selected"' : ''; 413 $html .= ">$text</option>\n"; 414 } 415 $html .= "</select>\n"; 416 $html = yourls_apply_filter( 'html_select', $html, $name, $options, $selected, $display ); 417 if( $display ) 418 echo $html; 419 return $html; 420 } 421 422 423 /** 424 * Display the Quick Share box 425 * 426 * @param string $longurl Long URL 427 * @param string $shorturl Short URL 428 * @param string $title Title 429 * @param string $text Text to display 430 * @param string $shortlink_title Optional replacement for 'Your short link' 431 * @param string $share_title Optional replacement for 'Quick Share' 432 * @param bool $hidden Optional. Hide the box by default (with css "display:none") 433 * @return void 434 */ 435 function yourls_share_box( $longurl, $shorturl, $title = '', $text='', $shortlink_title = '', $share_title = '', $hidden = false ) { 436 if ( $shortlink_title == '' ) 437 $shortlink_title = '<h2>' . yourls__( 'Your short link' ) . '</h2>'; 438 if ( $share_title == '' ) 439 $share_title = '<h2>' . yourls__( 'Quick Share' ) . '</h2>'; 440 441 // Allow plugins to short-circuit the whole function 442 $pre = yourls_apply_filter( 'shunt_share_box', false ); 443 if ( false !== $pre ) 444 return $pre; 445 446 // Make sure IDN domains are in their UTF8 form 447 $shorturl = yourls_normalize_uri($shorturl); 448 449 $text = ( $text ? '"'.$text.'" ' : '' ); 450 $title = ( $title ? "$title " : '' ); 451 $share = yourls_esc_textarea( $title.$text.$shorturl ); 452 $count = 280 - strlen( $share ); 453 $hidden = ( $hidden ? 'style="display:none;"' : '' ); 454 455 // Allow plugins to filter all data 456 $data = compact( 'longurl', 'shorturl', 'title', 'text', 'shortlink_title', 'share_title', 'share', 'count', 'hidden' ); 457 $data = yourls_apply_filter( 'share_box_data', $data ); 458 extract( $data ); 459 460 $_share = rawurlencode( $share ); 461 $_url = rawurlencode( $shorturl ); 462 ?> 463 464 <div id="shareboxes" <?php echo $hidden; ?>> 465 466 <?php yourls_do_action( 'shareboxes_before', $longurl, $shorturl, $title, $text ); ?> 467 468 <div id="copybox" class="share"> 469 <?php echo $shortlink_title; ?> 470 <p><input id="copylink" class="text" size="32" value="<?php echo yourls_esc_url( $shorturl ); ?>" /></p> 471 <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> 472 <?php if( yourls_do_log_redirect() ) { ?> 473 <br/><small><?php yourls_e( 'Stats' ); ?>: <a id="statlink" href="<?php echo yourls_esc_url( $shorturl ); ?>+"><?php echo yourls_esc_url( $shorturl ); ?>+</a></small> 474 <input type="hidden" id="titlelink" value="<?php echo yourls_esc_attr( $title ); ?>" /> 475 <?php } ?> 476 </p> 477 </div> 478 479 <?php yourls_do_action( 'shareboxes_middle', $longurl, $shorturl, $title, $text ); ?> 480 481 <div id="sharebox" class="share"> 482 <?php echo $share_title; ?> 483 <div id="tweet"> 484 <span id="charcount" class="hide-if-no-js"><?php echo $count; ?></span> 485 <textarea id="tweet_body"><?php echo $share; ?></textarea> 486 </div> 487 <p id="share_links"><?php yourls_e( 'Share with' ); ?> 488 <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> 489 <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> 490 <?php 491 yourls_do_action( 'share_links', $longurl, $shorturl, $title, $text ); 492 // Note: on the main admin page, there are no parameters passed to the sharebox when it's drawn. 493 ?> 494 </p> 495 </div> 496 497 <?php yourls_do_action( 'shareboxes_after', $longurl, $shorturl, $title, $text ); ?> 498 499 </div> 500 501 <?php 502 } 503 504 /** 505 * Die die die 506 * 507 * @see https://www.youtube.com/watch?v=zSiKETBjARk 508 * @param string $message 509 * @param string $title 510 * @param int $header_code 511 * @return void 512 */ 513 function yourls_die( $message = '', $title = '', $header_code = 200 ) { 514 yourls_do_action( 'pre_yourls_die', $message, $title, $header_code ); 515 516 yourls_status_header( $header_code ); 517 518 if( !yourls_did_action( 'html_head' ) ) { 519 yourls_html_head(); 520 yourls_html_logo(); 521 } 522 echo yourls_apply_filter( 'die_title', "<h2>$title</h2>" ); 523 echo yourls_apply_filter( 'die_message', "<p>$message</p>" ); 524 // Hook into 'yourls_die' to add more elements or messages to that page 525 yourls_do_action( 'yourls_die' ); 526 if( !yourls_did_action( 'html_footer' ) ) { 527 yourls_html_footer(false); 528 } 529 530 // die with a value in case we're running tests, so PHPUnit doesn't exit with 0 as if success 531 die(1); 532 } 533 534 /** 535 * Return an "Edit" row for the main table 536 * 537 * @param string $keyword Keyword to edit 538 * @param string $id 539 * @return string HTML of the edit row 540 */ 541 function yourls_table_edit_row( $keyword, $id ) { 542 $keyword = yourls_sanitize_keyword($keyword); 543 $url = yourls_get_keyword_longurl( $keyword ); 544 $title = htmlspecialchars( yourls_get_keyword_title( $keyword ) ); 545 $safe_url = yourls_esc_attr( $url ); 546 $safe_title = yourls_esc_attr( $title ); 547 $safe_keyword = yourls_esc_attr( $keyword ); 548 549 // Make strings sprintf() safe: '%' -> '%%' 550 $safe_url = str_replace( '%', '%%', $safe_url ); 551 $safe_title = str_replace( '%', '%%', $safe_title ); 552 553 $www = yourls_link(); 554 555 $nonce = yourls_create_nonce( 'edit-save_'.$id ); 556 557 if( $url ) { 558 $return = <<<RETURN 559 <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');" /> <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> 560 RETURN; 561 $return = sprintf( $return, yourls__( 'Long URL' ), yourls__( 'Short URL' ), yourls__( 'Title' ), yourls__( 'Save' ), yourls__( 'Save new values' ), yourls__( 'Cancel' ), yourls__( 'Cancel editing' ) ); 562 } else { 563 $return = '<tr class="edit-row notfound"><td colspan="6" class="edit-row notfound">' . yourls__( 'Error, URL not found' ) . '</td></tr>'; 564 } 565 566 $return = yourls_apply_filter( 'table_edit_row', $return, $keyword, $url, $title ); 567 568 return $return; 569 } 570 571 /** 572 * Return an "Add" row for the main table 573 * 574 * @param string $keyword Keyword (short URL) 575 * @param string $url URL (long URL) 576 * @param string $title Title 577 * @param string $ip IP 578 * @param string|int $clicks Number of clicks 579 * @param string $timestamp Timestamp 580 * @param int $row_id Numeric value used to form row IDs, defaults to one 581 * @return string HTML of the row 582 */ 583 function yourls_table_add_row( $keyword, $url, $title, $ip, $clicks, $timestamp, $row_id = 1 ) { 584 $keyword = yourls_sanitize_keyword($keyword); 585 $id = yourls_unique_element_id('yid', $row_id); 586 $shorturl = yourls_link( $keyword ); 587 588 $statlink = yourls_statlink( $keyword ); 589 590 $delete_link = yourls_nonce_url( 'delete-link_'.$id, 591 yourls_add_query_arg( array( 'id' => $id, 'action' => 'delete', 'keyword' => $keyword ), yourls_admin_url( 'admin-ajax.php' ) ) 592 ); 593 594 $edit_link = yourls_nonce_url( 'edit-link_'.$id, 595 yourls_add_query_arg( array( 'id' => $id, 'action' => 'edit', 'keyword' => $keyword ), yourls_admin_url( 'admin-ajax.php' ) ) 596 ); 597 598 // Action link buttons: the array 599 $actions = array( 600 'stats' => array( 601 'href' => $statlink, 602 'id' => "statlink-$id", 603 'title' => yourls_esc_attr__( 'Stats' ), 604 'anchor' => yourls__( 'Stats' ), 605 ), 606 'share' => array( 607 'href' => '', 608 'id' => "share-button-$id", 609 'title' => yourls_esc_attr__( 'Share' ), 610 'anchor' => yourls__( 'Share' ), 611 'onclick' => "toggle_share('$id');return false;", 612 ), 613 'edit' => array( 614 'href' => $edit_link, 615 'id' => "edit-button-$id", 616 'title' => yourls_esc_attr__( 'Edit' ), 617 'anchor' => yourls__( 'Edit' ), 618 'onclick' => "edit_link_display('$id');return false;", 619 ), 620 'delete' => array( 621 'href' => $delete_link, 622 'id' => "delete-button-$id", 623 'title' => yourls_esc_attr__( 'Delete' ), 624 'anchor' => yourls__( 'Delete' ), 625 'onclick' => "remove_link('$id');return false;", 626 ) 627 ); 628 $actions = yourls_apply_filter( 'table_add_row_action_array', $actions, $keyword ); 629 630 // Action link buttons: the HTML 631 $action_links = ''; 632 foreach( $actions as $key => $action ) { 633 $onclick = isset( $action['onclick'] ) ? 'onclick="' . $action['onclick'] . '"' : '' ; 634 $action_links .= sprintf( '<a href="%s" id="%s" title="%s" class="%s" %s>%s</a>', 635 $action['href'], $action['id'], $action['title'], 'button button_'.$key, $onclick, $action['anchor'] 636 ); 637 } 638 $action_links = yourls_apply_filter( 'action_links', $action_links, $keyword, $url, $ip, $clicks, $timestamp ); 639 640 if( ! $title ) 641 $title = $url; 642 643 $protocol_warning = ''; 644 if( ! in_array( yourls_get_protocol( $url ) , array( 'http://', 'https://' ) ) ) 645 $protocol_warning = yourls_apply_filter( 'add_row_protocol_warning', '<span class="warning" title="' . yourls__( 'Not a common link' ) . '">★</span>' ); 646 647 // Row cells: the array 648 $cells = array( 649 'keyword' => array( 650 'template' => '<a href="%shorturl%">%keyword_html%</a>', 651 'shorturl' => yourls_esc_url( $shorturl ), 652 'keyword_html' => yourls_esc_html( $keyword ), 653 ), 654 'url' => array( 655 'template' => '<a href="%long_url%" title="%title_attr%">%title_html%</a><br/><small>%warning%<a href="%long_url%">%long_url_html%</a></small>', 656 'long_url' => yourls_esc_url( $url ), 657 'title_attr' => yourls_esc_attr( $title ), 658 'title_html' => yourls_esc_html( yourls_trim_long_string( $title ) ), 659 'long_url_html' => yourls_esc_html( yourls_trim_long_string( urldecode( $url ) ) ), 660 'warning' => $protocol_warning, 661 ), 662 'timestamp' => array( 663 'template' => '<span class="timestamp" aria-hidden="true">%timestamp%</span> %date%', 664 'timestamp' => $timestamp, 665 'date' => yourls_date_i18n( yourls_get_datetime_format('M d, Y H:i'), yourls_get_timestamp( $timestamp )), 666 ), 667 'ip' => array( 668 'template' => '%ip%', 669 'ip' => $ip, 670 ), 671 'clicks' => array( 672 'template' => '%clicks%', 673 'clicks' => yourls_number_format_i18n( $clicks, 0 ), 674 ), 675 'actions' => array( 676 'template' => '%actions% <input type="hidden" id="keyword_%id%" value="%keyword%"/>', 677 'actions' => $action_links, 678 'id' => $id, 679 'keyword' => $keyword, 680 ), 681 ); 682 $cells = yourls_apply_filter( 'table_add_row_cell_array', $cells, $keyword, $url, $title, $ip, $clicks, $timestamp ); 683 684 // Row cells: the HTML. Replace every %stuff% in 'template' with 'stuff' value. 685 $row = "<tr id=\"id-$id\">"; 686 foreach( $cells as $cell_id => $elements ) { 687 $row .= sprintf( '<td class="%s" id="%s">', $cell_id, $cell_id . '-' . $id ); 688 $row .= preg_replace_callback( '/%([^%]+)?%/', function( $match ) use ( $elements ) { return $elements[ $match[1] ]; }, $elements['template'] ); 689 $row .= '</td>'; 690 } 691 $row .= "</tr>"; 692 $row = yourls_apply_filter( 'table_add_row', $row, $keyword, $url, $title, $ip, $clicks, $timestamp ); 693 694 return $row; 695 } 696 697 /** 698 * Echo the main table head 699 * 700 * @return void 701 */ 702 function yourls_table_head() { 703 $start = '<table id="main_table" class="tblSorter" cellpadding="0" cellspacing="1"><thead><tr>'."\n"; 704 echo yourls_apply_filter( 'table_head_start', $start ); 705 706 $cells = yourls_apply_filter( 'table_head_cells', array( 707 'shorturl' => yourls__( 'Short URL' ), 708 'longurl' => yourls__( 'Original URL' ), 709 'date' => yourls__( 'Date' ), 710 'ip' => yourls__( 'IP' ), 711 'clicks' => yourls__( 'Clicks' ), 712 'actions' => yourls__( 'Actions' ) 713 ) ); 714 foreach( $cells as $k => $v ) { 715 echo "<th id='main_table_head_$k'><span>$v</span></th>\n"; 716 } 717 718 $end = "</tr></thead>\n"; 719 echo yourls_apply_filter( 'table_head_end', $end ); 720 } 721 722 /** 723 * Echo the tbody start tag 724 * 725 * @return void 726 */ 727 function yourls_table_tbody_start() { 728 echo yourls_apply_filter( 'table_tbody_start', '<tbody>' ); 729 } 730 731 /** 732 * Echo the tbody end tag 733 * 734 * @return void 735 */ 736 function yourls_table_tbody_end() { 737 echo yourls_apply_filter( 'table_tbody_end', '</tbody>' ); 738 } 739 740 /** 741 * Echo the table start tag 742 * 743 * @return void 744 */ 745 function yourls_table_end() { 746 echo yourls_apply_filter( 'table_end', '</table></main>' ); 747 } 748 749 750 751 /** 752 * Echo HTML tag for a link 753 * 754 * @param string $href URL to link to 755 * @param string $anchor Anchor text 756 * @param string $element Element id 757 * @return void 758 */ 759 function yourls_html_link( $href, $anchor = '', $element = '' ) { 760 if( !$anchor ) 761 $anchor = $href; 762 if( $element ) 763 $element = sprintf( 'id="%s"', yourls_esc_attr( $element ) ); 764 $link = sprintf( '<a href="%s" %s>%s</a>', yourls_esc_url( $href ), $element, yourls_esc_html( $anchor ) ); 765 echo yourls_apply_filter( 'html_link', $link ); 766 } 767 768 /** 769 * Display the login screen. Nothing past this point. 770 * 771 * @param string $error_msg Optional error message to display 772 * @return void 773 */ 774 function yourls_login_screen( $error_msg = '' ) { 775 yourls_html_head( 'login' ); 776 777 $action = ( isset( $_GET['action'] ) && $_GET['action'] == 'logout' ? '?' : '' ); 778 779 yourls_html_logo(); 780 ?> 781 <main role="main"> 782 <div id="login"> 783 <form method="post" action="<?php echo $action; ?>"> <?php // reset any QUERY parameters ?> 784 <?php 785 if( !empty( $error_msg ) ) { 786 echo '<p id="error-message" class="error">'.$error_msg.'</p>'; 787 } 788 yourls_do_action( 'login_form_top' ); 789 ?> 790 <p> 791 <label for="username"><?php yourls_e( 'Username' ); ?></label><br /> 792 <input type="text" id="username" aria-describedby="error-message" name="username" class="text" autocomplete="username" /> 793 </p> 794 <p> 795 <label for="password"><?php yourls_e( 'Password' ); ?></label><br /> 796 <input type="password" id="password" name="password" class="text" autocomplete="current-password" /> 797 </p> 798 <?php 799 yourls_do_action( 'login_form_bottom' ); 800 ?> 801 <p style="text-align: right;"> 802 <?php yourls_nonce_field('admin_login'); ?> 803 <input type="submit" id="submit" name="submit" value="<?php yourls_e( 'Login' ); ?>" class="button" /> 804 </p> 805 <?php 806 yourls_do_action( 'login_form_end' ); 807 ?> 808 </form> 809 <script type="text/javascript">$('#username').focus();</script> 810 </div> 811 </main> 812 <?php 813 yourls_html_footer(); 814 die(); 815 } 816 817 818 /** 819 * Display the admin menu 820 * 821 * @return void 822 */ 823 function yourls_html_menu() { 824 // Build menu links 825 if( defined( 'YOURLS_USER' ) ) { 826 // Create a logout link with a nonce associated to fake user 'logout' : the user is not yet defined 827 // when the logout check is done -- see yourls_is_valid_user() 828 $logout_url = yourls_nonce_url( 'admin_logout', 829 yourls_add_query_arg(['action' => 'logout'], yourls_admin_url('index.php')), 'nonce', 'logout'); 830 $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>)' ); 831 } else { 832 $logout_link = yourls_apply_filter( 'logout_link', '' ); 833 } 834 $help_link = yourls_apply_filter( 'help_link', '<a href="' . yourls_site_url( false ) .'/readme.html">' . yourls__( 'Help' ) . '</a>' ); 835 836 $admin_links = array(); 837 $admin_sublinks = array(); 838 839 $admin_links['admin'] = array( 840 'url' => yourls_admin_url( 'index.php' ), 841 'title' => yourls__( 'Go to the admin interface' ), 842 'anchor' => yourls__( 'Admin interface' ) 843 ); 844 845 if( yourls_is_admin() ) { 846 $admin_links['tools'] = array( 847 'url' => yourls_admin_url( 'tools.php' ), 848 'anchor' => yourls__( 'Tools' ) 849 ); 850 $admin_links['plugins'] = array( 851 'url' => yourls_admin_url( 'plugins.php' ), 852 'anchor' => yourls__( 'Manage Plugins' ) 853 ); 854 $admin_sublinks['plugins'] = yourls_list_plugin_admin_pages(); 855 } 856 857 $admin_links = yourls_apply_filter( 'admin_links', $admin_links ); 858 $admin_sublinks = yourls_apply_filter( 'admin_sublinks', $admin_sublinks ); 859 860 // Now output menu 861 echo '<nav role="navigation"><ul id="admin_menu">'."\n"; 862 if ( yourls_is_private() && !empty( $logout_link ) ) 863 echo '<li id="admin_menu_logout_link">' . $logout_link .'</li>'; 864 865 foreach( (array)$admin_links as $link => $ar ) { 866 if( isset( $ar['url'] ) ) { 867 $anchor = isset( $ar['anchor'] ) ? $ar['anchor'] : $link; 868 $title = isset( $ar['title'] ) ? 'title="' . $ar['title'] . '"' : ''; 869 printf( '<li id="admin_menu_%s_link" class="admin_menu_toplevel"><a href="%s" %s>%s</a>', $link, $ar['url'], $title, $anchor ); 870 } 871 // Output submenu if any. TODO: clean up, too many code duplicated here 872 if( isset( $admin_sublinks[$link] ) ) { 873 echo "<ul>\n"; 874 foreach( $admin_sublinks[$link] as $link => $ar ) { 875 if( isset( $ar['url'] ) ) { 876 $anchor = isset( $ar['anchor'] ) ? $ar['anchor'] : $link; 877 $title = isset( $ar['title'] ) ? 'title="' . $ar['title'] . '"' : ''; 878 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 ); 879 } 880 } 881 echo "</ul>\n"; 882 } 883 } 884 885 if ( isset( $help_link ) ) 886 echo '<li id="admin_menu_help_link">' . $help_link .'</li>'; 887 888 yourls_do_action( 'admin_menu' ); 889 echo "</ul></nav>\n"; 890 yourls_do_action( 'admin_notices' ); 891 yourls_do_action( 'admin_notice' ); // because I never remember if it's 'notices' or 'notice' 892 /* 893 To display a notice: 894 $message = "<div>OMG, dude, I mean!</div>" ); 895 yourls_add_action( 'admin_notices', function() use ( $message ) { echo (string) $message; } ); 896 */ 897 } 898 899 /** 900 * Wrapper function to display admin notices 901 * 902 * @param string $message Message to display 903 * @param string $style Message style (default: 'notice') 904 * @return void 905 */ 906 function yourls_add_notice( $message, $style = 'notice' ) { 907 // Escape single quotes in $message to avoid breaking the anonymous function 908 $message = yourls_notice_box( strtr( $message, array( "'" => "\'" ) ), $style ); 909 yourls_add_action( 'admin_notices', function() use ( $message ) { echo (string) $message; } ); 910 } 911 912 /** 913 * Return a formatted notice 914 * 915 * @param string $message Message to display 916 * @param string $style CSS class to use for the notice 917 * @return string HTML of the notice 918 */ 919 function yourls_notice_box( $message, $style = 'notice' ) { 920 return <<<HTML 921 <div class="$style"> 922 <p>$message</p> 923 </div> 924 HTML; 925 } 926 927 /** 928 * Display a page 929 * 930 * Includes content of a PHP file from the YOURLS_PAGEDIR directory, as if it 931 * were a standard short URL (ie http://sho.rt/$page) 932 * 933 * @since 1.0 934 * @param string $page PHP file to display 935 * @return void 936 */ 937 function yourls_page( $page ) { 938 if( !yourls_is_page($page)) { 939 yourls_die( yourls_s('Page "%1$s" not found', $page), yourls__('Not found'), 404 ); 940 } 941 942 yourls_do_action( 'pre_page', $page ); 943 $load = yourls_include_file_sandbox(YOURLS_PAGEDIR . "/$page.php"); 944 if (is_string($load)) { 945 yourls_die( $load, yourls__('Not found'), 404 ); 946 } 947 yourls_do_action( 'post_page', $page ); 948 } 949 950 /** 951 * Display the language attributes for the HTML tag. 952 * 953 * Builds up a set of html attributes containing the text direction and language 954 * information for the page. Stolen from WP. 955 * 956 * @since 1.6 957 * @return void 958 */ 959 function yourls_html_language_attributes() { 960 $attributes = array(); 961 $output = ''; 962 963 $attributes[] = ( yourls_is_rtl() ? 'dir="rtl"' : 'dir="ltr"' ); 964 965 $doctype = yourls_apply_filter( 'html_language_attributes_doctype', 'html' ); 966 // Experimental: get HTML lang from locale. Should work. Convert fr_FR -> fr-FR 967 if ( $lang = str_replace( '_', '-', yourls_get_locale() ) ) { 968 if( $doctype == 'xhtml' ) { 969 $attributes[] = "xml:lang=\"$lang\""; 970 } else { 971 $attributes[] = "lang=\"$lang\""; 972 } 973 } 974 975 $output = implode( ' ', $attributes ); 976 $output = yourls_apply_filter( 'html_language_attributes', $output ); 977 echo $output; 978 } 979 980 /** 981 * Output translated strings used by the Javascript calendar 982 * 983 * @since 1.6 984 * @return void 985 */ 986 function yourls_l10n_calendar_strings() { 987 echo "\n<script>\n"; 988 echo "var l10n_cal_month = " . json_encode( array_values( yourls_l10n_months() ) ) . ";\n"; 989 echo "var l10n_cal_days = " . json_encode( array_values( yourls_l10n_weekday_initial() ) ) . ";\n"; 990 echo "var l10n_cal_today = \"" . yourls_esc_js( yourls__( 'Today' ) ) . "\";\n"; 991 echo "var l10n_cal_close = \"" . yourls_esc_js( yourls__( 'Close' ) ) . "\";\n"; 992 echo "</script>\n"; 993 994 // Dummy returns, to initialize l10n strings used in the calendar 995 yourls__( 'Today' ); 996 yourls__( 'Close' ); 997 } 998 999 1000 /** 1001 * Display a notice if there is a newer version of YOURLS available 1002 * 1003 * @since 1.7 1004 * @param string $compare_with Optional, YOURLS version to compare to 1005 * @return void 1006 */ 1007 function yourls_new_core_version_notice($compare_with = null) { 1008 $compare_with = $compare_with ?: YOURLS_VERSION; 1009 1010 $checks = yourls_get_option( 'core_version_checks' ); 1011 $latest = isset($checks->last_result->latest) ? yourls_sanitize_version($checks->last_result->latest) : false; 1012 1013 if( $latest AND version_compare( $latest, $compare_with, '>' ) ) { 1014 yourls_do_action('new_core_version_notice', $latest); 1015 $msg = yourls_s( '<a href="%s">YOURLS version %s</a> is available. Please update!', 'http://yourls.org/download', $latest ); 1016 yourls_add_notice( $msg ); 1017 } 1018 } 1019 1020 /** 1021 * Display or return HTML for a bookmarklet link 1022 * 1023 * @since 1.7.1 1024 * @param string $href bookmarklet link (presumably minified code with "javascript:" scheme) 1025 * @param string $anchor link anchor 1026 * @param bool $echo true to display, false to return the HTML 1027 * @return string the HTML for a bookmarklet link 1028 */ 1029 function yourls_bookmarklet_link( $href, $anchor, $echo = true ) { 1030 $alert = yourls_esc_attr__( 'Drag to your toolbar!' ); 1031 $link = <<<LINK 1032 <a href="$href" class="bookmarklet" onclick="alert('$alert');return false;">$anchor</a> 1033 LINK; 1034 1035 if( $echo ) 1036 echo $link; 1037 return $link; 1038 } 1039 1040 /** 1041 * Set HTML context (stats, index, infos, ...) 1042 * 1043 * @since 1.7.3 1044 * @param string $context 1045 * @return void 1046 */ 1047 function yourls_set_html_context($context) { 1048 yourls_get_db()->set_html_context($context); 1049 } 1050 1051 /** 1052 * Get HTML context (stats, index, infos, ...) 1053 * 1054 * @since 1.7.3 1055 * @return string 1056 */ 1057 function yourls_get_html_context() { 1058 return yourls_get_db()->get_html_context(); 1059 } 1060 1061 /** 1062 * Print HTML link for favicon 1063 * 1064 * @since 1.7.10 1065 * @return mixed|void 1066 */ 1067 function yourls_html_favicon() { 1068 // Allow plugins to short-circuit the whole function 1069 $pre = yourls_apply_filter( 'shunt_html_favicon', false ); 1070 if ( false !== $pre ) { 1071 return $pre; 1072 } 1073 1074 printf( '<link rel="shortcut icon" href="%s" />', yourls_get_yourls_favicon_url(false) ); 1075 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Jan 6 05:10:29 2026 | Cross-referenced by PHPXref 0.7.1 |