Revision: 51729
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at October 2, 2011 20:51 by szpunk
Initial Code
//get domain from url function get_domain($url) { /* Author : Ayush URL : http://Webgarb.com */ $url = explode('/', str_replace('www.', '', str_replace('http://', '', $url))); return $url[0]; } //get favicon from google and cache it function getFavicon($var){ $cache_days = 30; $linkdomain = get_domain($var); $favicon_cache_dir = ABSPATH.'wp-content'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'favicon_cache'; $favicon_url = 'http://www.quakemachinex.com/blog/wp-content/plugins/favicon_cache/'.$linkdomain.'.png'; $fp = fopen ($favicon_cache_dir.'/'.$linkdomain.'.png', 'r'); $favicon_create_time = filectime($favicon_cache_dir.'/'.$linkdomain.'.png'); $time_now = date("Y-m-d H:i:s"); $favicon_stay_days = (strtotime($time_now)-strtotime(date("Y-m-d H:i:s",$favicon_create_time)))/86400; $favicon_stay_days = floor($favicon_stay_days); if ($fp && $favicon_stay_days < $cache_days) { return $favicon_url; } else { $remote_favicon = file_get_contents('http://www.google.com/s2/favicons?domain='.$linkdomain); $local_favicon = $favicon_cache_dir.'/'.$linkdomain.'.png'; $local_favicon_actual = fopen($local_favicon, 'w+'); fwrite($local_favicon_actual, $remote_favicon); fclose($local_favicon_actual); return $favicon_url; } }
Initial URL
http://www.quakemachinex.com/blog/
Initial Description
Initial Title
Cache favicon from google service
Initial Tags
php, google, cache
Initial Language
PHP