header and logo * * @return void */ function yourls_html_logo() { yourls_do_action( 'pre_html_logo' ); ?>

YOURLS: Your Own URL Shortener

tag * * @param string $context Context of the page (stats, index, infos, ...) * @param string $title HTML title of the page * @return void */ function yourls_html_head( $context = 'index', $title = '' ) { yourls_do_action( 'pre_html_head', $context, $title ); // All components to false, except when specified true $share = $insert = $tablesorter = $tabs = $cal = $charts = false; // Load components as needed switch ( $context ) { case 'infos': $share = $tabs = $charts = true; break; case 'bookmark': $share = $insert = $tablesorter = true; break; case 'index': $insert = $tablesorter = $cal = $share = true; break; case 'plugins': case 'tools': $tablesorter = true; break; case 'login': $_title_page = 'Login'; break; case 'install': case 'new': case 'upgrade': break; } // Force no cache for all admin pages if( yourls_is_admin() && !headers_sent() ) { yourls_no_cache_headers(); yourls_no_frame_header(); yourls_content_type_header( yourls_apply_filter( 'html_head_content-type', 'text/html' ) ); yourls_do_action( 'admin_headers', $context, $title ); } // Store page context yourls_set_html_context($context); // Body class $bodyclass = yourls_apply_filter( 'bodyclass', '' ); $bodyclass .= ( yourls_is_mobile_device() ? 'mobile' : 'desktop' ); // Page title $_title = 'YOURLS — Your Own URL Shortener | ' . yourls_link(); $_title = empty($_title_page) ? $_title : $_title_page . ' — ' . $_title; $title = $title ? $title . " « " . $_title : $_title; $title = yourls_apply_filter( 'html_title', $title, $context ); ?> > <?php echo $title ?>
';
		echo join( "\n", yourls_get_debug_log() );
		echo '
'; } ?>
: :
'; $_options = array( 'all' => yourls__( 'All fields' ), 'keyword' => yourls__( 'Short URL' ), 'url' => yourls__( 'URL' ), 'title' => yourls__( 'Title' ), 'ip' => yourls__( 'IP' ), ); $_select = yourls_html_select( 'search_in', $_options, $search_in, false, yourls__( 'Search in' ) ); /* //translators: "Search for in '; yourls_se( 'Show %s rows', $_input ); echo "
\n"; // Fourth search control: Show links with more than XX clicks $_options = array( 'more' => yourls__( 'more' ), 'less' => yourls__( 'less' ), ); $_select = yourls_html_select( 'click_filter', $_options, $click_filter, false, yourls__( 'Show links with' ) ); $_input = ' '; /* //translators: "Show links with than clicks" */ yourls_se( 'Show links with %1$s than %2$s clicks', $_select, $_input ); echo "
\n"; // Fifth search control: Show links created before/after/between ... $_options = array( 'before' => yourls__('before'), 'after' => yourls__('after'), 'between' => yourls__('between'), ); $_select = yourls_html_select( 'date_filter', $_options, $date_filter, false, yourls__('Show links created') ); $_input = ''; $_and = ' & '; $_input2 = ''; /* //translators: "Show links created <"and" if applicable> " */ yourls_se( 'Show links created %1$s %2$s %3$s %4$s', $_select, $_input, $_and, $_input2 ); ?>
 
'Text displayed' * @param string $selected optional 'value' from the $options array that will be highlighted * @param boolean $display false (default) to return, true to echo * @param string $label ARIA label of the element * @return string HTML content of the select element */ function yourls_html_select( $name, $options, $selected = '', $display = false, $label = '' ) { // Allow plugins to filter the options -- see #3262 $options = yourls_apply_filter( 'html_select_options', $options, $name, $selected, $display, $label ); $html = "

:
: +

$title" ); echo yourls_apply_filter( 'die_message', "

$message

" ); // Hook into 'yourls_die' to add more elements or messages to that page yourls_do_action( 'yourls_die' ); if( !yourls_did_action( 'html_footer' ) ) { yourls_html_footer(false); } // die with a value in case we're running tests, so PHPUnit doesn't exit with 0 as if success die(1); } /** * Return an "Edit" row for the main table * * @param string $keyword Keyword to edit * @param string $id * @return string HTML of the edit row */ function yourls_table_edit_row( $keyword, $id ) { $keyword = yourls_sanitize_keyword($keyword); $url = yourls_get_keyword_longurl( $keyword ); $title = htmlspecialchars( yourls_get_keyword_title( $keyword ) ); $safe_url = yourls_esc_attr( $url ); $safe_title = yourls_esc_attr( $title ); $safe_keyword = yourls_esc_attr( $keyword ); // Make strings sprintf() safe: '%' -> '%%' $safe_url = str_replace( '%', '%%', $safe_url ); $safe_title = str_replace( '%', '%%', $safe_title ); $www = yourls_link(); $nonce = yourls_create_nonce( 'edit-save_'.$id ); if( $url ) { $return = <<%s:
%s: $www
%s:   RETURN; $return = sprintf( $return, yourls__( 'Long URL' ), yourls__( 'Short URL' ), yourls__( 'Title' ), yourls__( 'Save' ), yourls__( 'Save new values' ), yourls__( 'Cancel' ), yourls__( 'Cancel editing' ) ); } else { $return = '' . yourls__( 'Error, URL not found' ) . ''; } $return = yourls_apply_filter( 'table_edit_row', $return, $keyword, $url, $title ); return $return; } /** * Return an "Add" row for the main table * * @param string $keyword Keyword (short URL) * @param string $url URL (long URL) * @param string $title Title * @param string $ip IP * @param string|int $clicks Number of clicks * @param string $timestamp Timestamp * @param int $row_id Numeric value used to form row IDs, defaults to one * @return string HTML of the row */ function yourls_table_add_row( $keyword, $url, $title, $ip, $clicks, $timestamp, $row_id = 1 ) { $keyword = yourls_sanitize_keyword($keyword); $id = yourls_unique_element_id('yid', $row_id); $shorturl = yourls_link( $keyword ); $statlink = yourls_statlink( $keyword ); $delete_link = yourls_nonce_url( 'delete-link_'.$id, yourls_add_query_arg( array( 'id' => $id, 'action' => 'delete', 'keyword' => $keyword ), yourls_admin_url( 'admin-ajax.php' ) ) ); $edit_link = yourls_nonce_url( 'edit-link_'.$id, yourls_add_query_arg( array( 'id' => $id, 'action' => 'edit', 'keyword' => $keyword ), yourls_admin_url( 'admin-ajax.php' ) ) ); // Action link buttons: the array $actions = array( 'stats' => array( 'href' => $statlink, 'id' => "statlink-$id", 'title' => yourls_esc_attr__( 'Stats' ), 'anchor' => yourls__( 'Stats' ), ), 'share' => array( 'href' => '', 'id' => "share-button-$id", 'title' => yourls_esc_attr__( 'Share' ), 'anchor' => yourls__( 'Share' ), 'onclick' => "toggle_share('$id');return false;", ), 'edit' => array( 'href' => $edit_link, 'id' => "edit-button-$id", 'title' => yourls_esc_attr__( 'Edit' ), 'anchor' => yourls__( 'Edit' ), 'onclick' => "edit_link_display('$id');return false;", ), 'delete' => array( 'href' => $delete_link, 'id' => "delete-button-$id", 'title' => yourls_esc_attr__( 'Delete' ), 'anchor' => yourls__( 'Delete' ), 'onclick' => "remove_link('$id');return false;", ) ); $actions = yourls_apply_filter( 'table_add_row_action_array', $actions, $keyword ); // Action link buttons: the HTML $action_links = ''; foreach( $actions as $key => $action ) { $onclick = isset( $action['onclick'] ) ? 'onclick="' . $action['onclick'] . '"' : '' ; $action_links .= sprintf( '%s', $action['href'], $action['id'], $action['title'], 'button button_'.$key, $onclick, $action['anchor'] ); } $action_links = yourls_apply_filter( 'action_links', $action_links, $keyword, $url, $ip, $clicks, $timestamp ); if( ! $title ) $title = $url; $protocol_warning = ''; if( ! in_array( yourls_get_protocol( $url ) , array( 'http://', 'https://' ) ) ) $protocol_warning = yourls_apply_filter( 'add_row_protocol_warning', '' ); // Row cells: the array $cells = array( 'keyword' => array( 'template' => '%keyword_html%', 'shorturl' => yourls_esc_url( $shorturl ), 'keyword_html' => yourls_esc_html( $keyword ), ), 'url' => array( 'template' => '%title_html%
%warning%%long_url_html%', 'long_url' => yourls_esc_url( $url ), 'title_attr' => yourls_esc_attr( $title ), 'title_html' => yourls_esc_html( yourls_trim_long_string( $title ) ), 'long_url_html' => yourls_esc_html( yourls_trim_long_string( urldecode( $url ) ) ), 'warning' => $protocol_warning, ), 'timestamp' => array( 'template' => ' %date%', 'timestamp' => $timestamp, 'date' => yourls_date_i18n( yourls_get_datetime_format('M d, Y H:i'), yourls_get_timestamp( $timestamp )), ), 'ip' => array( 'template' => '%ip%', 'ip' => $ip, ), 'clicks' => array( 'template' => '%clicks%', 'clicks' => yourls_number_format_i18n( $clicks, 0 ), ), 'actions' => array( 'template' => '%actions% ', 'actions' => $action_links, 'id' => $id, 'keyword' => $keyword, ), ); $cells = yourls_apply_filter( 'table_add_row_cell_array', $cells, $keyword, $url, $title, $ip, $clicks, $timestamp ); // Row cells: the HTML. Replace every %stuff% in 'template' with 'stuff' value. $row = ""; foreach( $cells as $cell_id => $elements ) { $row .= sprintf( '', $cell_id, $cell_id . '-' . $id ); $row .= preg_replace_callback( '/%([^%]+)?%/', function( $match ) use ( $elements ) { return $elements[ $match[1] ]; }, $elements['template'] ); $row .= ''; } $row .= ""; $row = yourls_apply_filter( 'table_add_row', $row, $keyword, $url, $title, $ip, $clicks, $timestamp ); return $row; } /** * Echo the main table head * * @return void */ function yourls_table_head() { $start = ''."\n"; echo yourls_apply_filter( 'table_head_start', $start ); $cells = yourls_apply_filter( 'table_head_cells', array( 'shorturl' => yourls__( 'Short URL' ), 'longurl' => yourls__( 'Original URL' ), 'date' => yourls__( 'Date' ), 'ip' => yourls__( 'IP' ), 'clicks' => yourls__( 'Clicks' ), 'actions' => yourls__( 'Actions' ) ) ); foreach( $cells as $k => $v ) { echo "\n"; } $end = "\n"; echo yourls_apply_filter( 'table_head_end', $end ); } /** * Echo the tbody start tag * * @return void */ function yourls_table_tbody_start() { echo yourls_apply_filter( 'table_tbody_start', '' ); } /** * Echo the tbody end tag * * @return void */ function yourls_table_tbody_end() { echo yourls_apply_filter( 'table_tbody_end', '' ); } /** * Echo the table start tag * * @return void */ function yourls_table_end() { echo yourls_apply_filter( 'table_end', '
$v
' ); } /** * Echo HTML tag for a link * * @param string $href URL to link to * @param string $anchor Anchor text * @param string $element Element id * @return void */ function yourls_html_link( $href, $anchor = '', $element = '' ) { if( !$anchor ) $anchor = $href; if( $element ) $element = sprintf( 'id="%s"', yourls_esc_attr( $element ) ); $link = sprintf( '%s', yourls_esc_url( $href ), $element, yourls_esc_html( $anchor ) ); echo yourls_apply_filter( 'html_link', $link ); } /** * Display the login screen. Nothing past this point. * * @param string $error_msg Optional error message to display * @return void */ function yourls_login_screen( $error_msg = '' ) { yourls_html_head( 'login' ); $action = ( isset( $_GET['action'] ) && $_GET['action'] == 'logout' ? '?' : '' ); yourls_html_logo(); ?>
'.$error_msg.'

'; } yourls_do_action( 'login_form_top' ); ?>



'logout'], yourls_admin_url('index.php')), 'nonce', 'logout'); $logout_link = yourls_apply_filter('logout_link', sprintf( yourls__('Hello %s'), YOURLS_USER ) . ' (' . yourls__( 'Logout' ) . ')' ); } else { $logout_link = yourls_apply_filter( 'logout_link', '' ); } $help_link = yourls_apply_filter( 'help_link', '' . yourls__( 'Help' ) . '' ); $admin_links = array(); $admin_sublinks = array(); $admin_links['admin'] = array( 'url' => yourls_admin_url( 'index.php' ), 'title' => yourls__( 'Go to the admin interface' ), 'anchor' => yourls__( 'Admin interface' ) ); if( yourls_is_admin() ) { $admin_links['tools'] = array( 'url' => yourls_admin_url( 'tools.php' ), 'anchor' => yourls__( 'Tools' ) ); $admin_links['plugins'] = array( 'url' => yourls_admin_url( 'plugins.php' ), 'anchor' => yourls__( 'Manage Plugins' ) ); $admin_sublinks['plugins'] = yourls_list_plugin_admin_pages(); } $admin_links = yourls_apply_filter( 'admin_links', $admin_links ); $admin_sublinks = yourls_apply_filter( 'admin_sublinks', $admin_sublinks ); // Now output menu echo '\n"; yourls_do_action( 'admin_notices' ); yourls_do_action( 'admin_notice' ); // because I never remember if it's 'notices' or 'notice' /* To display a notice: $message = "
OMG, dude, I mean!
" ); yourls_add_action( 'admin_notices', function() use ( $message ) { echo (string) $message; } ); */ } /** * Wrapper function to display admin notices * * @param string $message Message to display * @param string $style Message style (default: 'notice') * @return void */ function yourls_add_notice( $message, $style = 'notice' ) { // Escape single quotes in $message to avoid breaking the anonymous function $message = yourls_notice_box( strtr( $message, array( "'" => "\'" ) ), $style ); yourls_add_action( 'admin_notices', function() use ( $message ) { echo (string) $message; } ); } /** * Return a formatted notice * * @param string $message Message to display * @param string $style CSS class to use for the notice * @return string HTML of the notice */ function yourls_notice_box( $message, $style = 'notice' ) { return <<

$message

HTML; } /** * Display a page * * Includes content of a PHP file from the YOURLS_PAGEDIR directory, as if it * were a standard short URL (ie http://sho.rt/$page) * * @since 1.0 * @param string $page PHP file to display * @return void */ function yourls_page( $page ) { if( !yourls_is_page($page)) { yourls_die( yourls_s('Page "%1$s" not found', $page), yourls__('Not found'), 404 ); } yourls_do_action( 'pre_page', $page ); $load = yourls_include_file_sandbox(YOURLS_PAGEDIR . "/$page.php"); if (is_string($load)) { yourls_die( $load, yourls__('Not found'), 404 ); } yourls_do_action( 'post_page', $page ); } /** * Display the language attributes for the HTML tag. * * Builds up a set of html attributes containing the text direction and language * information for the page. Stolen from WP. * * @since 1.6 * @return void */ function yourls_html_language_attributes() { $attributes = array(); $output = ''; $attributes[] = ( yourls_is_rtl() ? 'dir="rtl"' : 'dir="ltr"' ); $doctype = yourls_apply_filter( 'html_language_attributes_doctype', 'html' ); // Experimental: get HTML lang from locale. Should work. Convert fr_FR -> fr-FR if ( $lang = str_replace( '_', '-', yourls_get_locale() ) ) { if( $doctype == 'xhtml' ) { $attributes[] = "xml:lang=\"$lang\""; } else { $attributes[] = "lang=\"$lang\""; } } $output = implode( ' ', $attributes ); $output = yourls_apply_filter( 'html_language_attributes', $output ); echo $output; } /** * Output translated strings used by the Javascript calendar * * @since 1.6 * @return void */ function yourls_l10n_calendar_strings() { echo "\n\n"; // Dummy returns, to initialize l10n strings used in the calendar yourls__( 'Today' ); yourls__( 'Close' ); } /** * Display a notice if there is a newer version of YOURLS available * * @since 1.7 * @param string $compare_with Optional, YOURLS version to compare to * @return void */ function yourls_new_core_version_notice($compare_with = null) { $compare_with = $compare_with ?: YOURLS_VERSION; $checks = yourls_get_option( 'core_version_checks' ); $latest = isset($checks->last_result->latest) ? yourls_sanitize_version($checks->last_result->latest) : false; if( $latest AND version_compare( $latest, $compare_with, '>' ) ) { yourls_do_action('new_core_version_notice', $latest); $msg = yourls_s( 'YOURLS version %s is available. Please update!', 'http://yourls.org/download', $latest ); yourls_add_notice( $msg ); } } /** * Display or return HTML for a bookmarklet link * * @since 1.7.1 * @param string $href bookmarklet link (presumably minified code with "javascript:" scheme) * @param string $anchor link anchor * @param bool $echo true to display, false to return the HTML * @return string the HTML for a bookmarklet link */ function yourls_bookmarklet_link( $href, $anchor, $echo = true ) { $alert = yourls_esc_attr__( 'Drag to your toolbar!' ); $link = <<$anchor LINK; if( $echo ) echo $link; return $link; } /** * Set HTML context (stats, index, infos, ...) * * @since 1.7.3 * @param string $context * @return void */ function yourls_set_html_context($context) { yourls_get_db()->set_html_context($context); } /** * Get HTML context (stats, index, infos, ...) * * @since 1.7.3 * @return string */ function yourls_get_html_context() { return yourls_get_db()->get_html_context(); } /** * Print HTML link for favicon * * @since 1.7.10 * @return mixed|void */ function yourls_html_favicon() { // Allow plugins to short-circuit the whole function $pre = yourls_apply_filter( 'shunt_html_favicon', false ); if ( false !== $pre ) { return $pre; } printf( '', yourls_get_yourls_favicon_url(false) ); }