I have written a plugin that puts a (google) favicon in front of each link in my blog. Really simple. Just uses a simple preg_replace_callback on hrefs:
$changed_html_reference = preg_replace_callback(self::HTML_REF_REGEX,
array($this,'AddExtraHtmlToOneHref'), $strHtmlBodyText);
with a
add_filter('the_content', array($this,'ReplaceAll'), 9);
for the replacement and a default call to the google site for the icon (snip out of class) :
const GOOGLE_ICON_URL = 'http://www.google.com/s2/favicons?domain=';
function HttpDownloadFeed()
{
$parsed_url = parse_url($this->url);
$data_r = wp_remote_get(self::GOOGLE_ICON_URL . $parsed_url['host']);
$data = $data_r['body'];
return $data;
}
I now have taken the approach of making my own cache class which stores the icons in directories like e.g. /cache/com/facebook/www/f.png.
But I am now thinking about the location of that class. For easiness i placed the cache in the wp-content directory. The following questions I have:
- could i plugin an existing cache / cache plugin to do the caching for me?
- what is the best location for my own cache thing? should i put it under /wp-content/cache or /plugins/myplugin/mycache or even /themes/mytheme/cache ?
or is there even a better approach to this?
(I am using the com/facebook/www approach because i also store session date of stumbleupon, delicious etc...in there and i only want to call these pages/feeds once incl. the request for a google favicon) (and since i need to display the icon and not all browser support inline displaying of icons embedded in html i need to write them to a directory available to the client).