From 152eaa21add4687c9963e83953b7e47c44fcdc84 Mon Sep 17 00:00:00 2001 From: ozhozh Date: Wed, 4 Jul 2012 21:37:16 +0000 Subject: [PATCH] Detect any favicon dropped in the /user directory and use it. Fixes issue 391. git-svn-id: http://yourls.googlecode.com/svn/trunk@728 12232710-3e20-11de-b438-597f59cd7555 --- includes/functions-html.php | 5 ++-- includes/functions.php | 47 ++++++++++++++++++++++++++++++------- 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/includes/functions-html.php b/includes/functions-html.php index e8eb4b0..ab0c7b5 100644 --- a/includes/functions-html.php +++ b/includes/functions-html.php @@ -73,7 +73,7 @@ function yourls_html_head( $context = 'index', $title = '' ) { <?php echo $title ?> - + @@ -622,5 +622,4 @@ function yourls_page( $page ) { include($include); yourls_do_action( 'post_page', $page ); die(); -} - +} \ No newline at end of file diff --git a/includes/functions.php b/includes/functions.php index 47af416..1204260 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -1459,16 +1459,22 @@ function yourls_admin_url( $page = '' ) { return yourls_apply_filter( 'admin_url', $admin, $page ); } -// Return YOURLS_SITE, with SSL preference -function yourls_site_url( $echo = true ) { - $site = YOURLS_SITE; +// Return YOURLS_SITE or URL under YOURLS setup, with SSL preference +function yourls_site_url( $echo = true, $url = '' ) { + if( !$url ) { + $url = YOURLS_SITE; + } else { + // make $url relative to YOURLS base in case a full URL has been provided. Will break if user mixes https/http. + $url = str_replace( YOURLS_SITE, '', $url ); + $url = YOURLS_SITE . '/' . ltrim( $url, '/' ); + } // Do not enforce (checking yourls_need_ssl() ) but check current usage so it won't force SSL on non-admin pages if( yourls_is_ssl() ) - $site = str_replace( 'http://', 'https://', $site ); - $site = yourls_apply_filter( 'site_url', $site ); + $url = str_replace( 'http://', 'https://', $url ); + $url = yourls_apply_filter( 'site_url', $url ); if( $echo ) - echo $site; - return $site; + echo $url; + return $url; } // Check if SSL is used, returns bool. Stolen from WP. @@ -1670,4 +1676,29 @@ function yourls_fix_request_uri() { // Shutdown function, runs just before PHP shuts down execution. Stolen from WP function yourls_shutdown() { yourls_do_action( 'shutdown' ); -} \ No newline at end of file +} + +// Auto detect custom favicon in /user directory, fallback to YOURLS favicon, and echo/return its URL +function yourls_favicon( $echo = true ) { + static $favicon = null; + if( $favicon !== null ) + return $favicon; + + $custom = null; + // search for favicon.(gif|ico|png|jpg|svg) + foreach( array( 'gif', 'ico', 'png', 'jpg', 'svg' ) as $ext ) { + if( file_exists( YOURLS_USERDIR. '/favicon.' . $ext ) ) { + $custom = 'favicon.' . $ext; + break; + } + } + + if( $custom ) { + $favicon = yourls_site_url( false, YOURLS_USERURL . '/' . $custom ); + } else { + $favicon = yourls_site_url( false ) . '/images/favicon.gif'; + } + if( $echo ) + echo $favicon; + return $favicon; +} -- 2.45.0