" );
yourls_add_action( 'admin_notices', function() use ( $message ) { echo (string) $message; } );
*/
}
/**
* Wrapper function to display admin notices
*
*/
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
*
*/
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 $page PHP file to display
*/
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 );
include_once( YOURLS_PAGEDIR . "/$page.php" );
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
*/
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
*/
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
*/
function yourls_new_core_version_notice($compare_with = false) {
$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() {
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) );
}