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