function gravatar_cron_run() { global $gravatar_cron_options; if (!isset($gravatar_cron_options)) { $gravatar_cron_options = gravatar_cron_options(); } if (gravatar_cache_refresh()) { $gravatar_cron_options['last_run'] = time(); } update_option('gravatar_cron_options', $gravatar_cron_options); }
function gravatar_manage_cache() { global $wpdb, $gravatar_expire, $gravatar_options, $gravatar_local; // check to see if we can cache gravatars $CANCACHE = gravatar_cache_capable(1); gravatar_default_options(); $gravatar_options = get_option('gravatar_options'); if (!isset($gravatar_expire)) { $gravatar_expire = get_option('gravatar_expire'); } if (!isset($gravatar_local)) { $gravatar_local = get_option('gravatar_local'); } if (isset($_POST['delete_local'])) { // delete local gravatar $who = $_POST['delete_local']; if ('ALL_LOCAL' == $who) { // delete all local gravatars $gravatar_local = ''; update_option('gravatar_local', ''); $message = "All Local Gravatars Deleted"; if ($d = opendir(ABSPATH . "wp-content/gravatars/local/")) { $count = 0; while (($file = readdir($d)) !== false) { if (is_file(ABSPATH . "wp-content/gravatars/local/{$file}")) { unlink(ABSPATH . "wp-content/gravatars/local/{$file}"); $count++; } } closedir($d); $message .= ". <strong>{$count}</strong> Cached Images Deleted."; } gravatar_message($message); } else { // delete just one local gravatar unset($gravatar_local[$who]); update_option('gravatar_local', $gravatar_local); $message = "Local Gravatar Deleted"; if (is_file(ABSPATH . 'wp-content/gravatars/local/' . md5($who))) { unlink(ABSPATH . 'wp-content/gravatars/local/' . md5($who)); $message .= ". Cached Image Deleted."; } gravatar_message($message); } } elseif (isset($_POST['refresh_cache']) && $CANCACHE) { // check gravatar cache list($cached, $updated, $errors) = gravatar_cache_refresh(); $message = "Gravatar Cache Refreshed."; $message .= " <strong>{$updated}</strong> Gravatars Updated."; if ($updated) { $message .= " <strong>{$cached}</strong> Images Cached."; if ($errors) { $message .= " <strong>{$errors}</strong> Caching Errors."; } } gravatar_message($message); } elseif (isset($_POST['load_cache']) && $CANCACHE) { // reload cached images into system // for when a local cached image exists, but gravatar.com sucks $loaded = gravatar_cache_reload("global"); $message = "Gravatar Cache Reloaded from Local Filesystem."; $message .= " <strong>{$loaded}</strong> Gravatar Images Loaded."; gravatar_message($message); } elseif (isset($_POST['delete_cache']) && $CANCACHE) { // delete cached gravatar $who = $_POST['delete_cache']; if ('ALL_CACHE' == $who) { // delete all cached gravatars $gravatar_expire = ''; update_option('gravatar_expire', ''); $message = "All Gravatars Deleted"; if ($d = opendir(ABSPATH . "wp-content/gravatars/global/")) { $count = 0; while (($file = readdir($d)) !== false) { if (is_file(ABSPATH . "wp-content/gravatars/global/{$file}")) { unlink(ABSPATH . "wp-content/gravatars/global/{$file}"); $count++; } } closedir($d); $message .= ". <strong>{$count}</strong> Cached Images Deleted."; } gravatar_message($message); } else { // delete just one cached gravatar $gravatar_expire = get_option('gravatar_expire'); unset($gravatar_expire[$who]); update_option('gravatar_expire', $gravatar_expire); $message = "Gravatar Deleted"; if (is_file(ABSPATH . 'wp-content/gravatars/global/' . md5($who))) { unlink(ABSPATH . 'wp-content/gravatars/global/' . md5($who)); $message .= ". Cached Image Deleted."; } gravatar_message($message); } } echo "<div class='wrap'>"; echo "<table width='100%' cellpadding='0' cellspacing='0'><tr><td><h2>"; _e('Gravatar Cache', 'gravatars'); echo "</h2></td>"; echo "<td align='right'><h2><span style='font-size: 75%;'><a href='./options-general.php?page=gravatars2.php'>Gravatar Options</a></span></h2></td>"; echo "</tr></table>"; if (!$CANCACHE) { gravatar_message("Caching Not Available", "error"); echo "<div style='clear: both;'> </div>"; echo "<div style='width: 100%; text-align: center;'>" . gravatar_version("html") . "</div>"; echo "</div>"; die; } // first, collect all the people who have commented $commenters = $wpdb->get_results("SELECT DISTINCT comment_author, comment_author_email, comment_author_url, COUNT(*) as count FROM {$wpdb->comments} WHERE {$wpdb->comments}.comment_approved = '1' AND {$wpdb->comments}.comment_type = '' AND {$wpdb->comments}.comment_author_email != '' GROUP BY comment_author_email ORDER BY comment_ID DESC"); $locals = array(); $cached = array(); // $gravatar_local = get_option('gravatar_local'); foreach ($commenters as $commenter) { $who = $commenter->comment_author_email; if (empty($who)) { continue; } $gravatar = ''; $name = $commenter->comment_author; $url = $commenter->comment_author_url; $count = $commenter->count; if ('' != $gravatar_local[$who]) { $gravatar = get_settings('siteurl') . "/wp-content/gravatars/local/" . md5($who); // let's make these into relative links $gravatar = str_replace("http://" . $_SERVER['SERVER_NAME'], '', $gravatar); $gravatar = "<img src='{$gravatar}' alt='{$name}' title='{$url}' />"; $foo = "<div style='float: left; text-align: center; margin: 2px; padding: 2px; border: 2px solid #9cf;'><form method='POST'>"; $foo .= "{$gravatar} <br />"; $foo .= $url ? "<a href='{$url}' title='{$url}'>{$name}</a>" : "{$name}"; $foo .= "<br />{$who}<br />{$count} comments<br /><input type='hidden' name='delete_local' value='{$who}' /><input type='submit' name='gravatar_admin' value='[ X ]' /></form></div>\r\n"; $locals[] = $foo; } elseif ($date = $gravatar_expire[$who]) { switch (substr($date, 0, 1)) { case "*": $gravatar = get_settings('siteurl') . "/wp-content/gravatars/global/" . md5($who); // let's make these into relative links $gravatar = str_replace("http://" . $_SERVER['SERVER_NAME'], '', $gravatar); $gravatar = "<img src='{$gravatar}' alt='{$name}' title='{$url}' />"; break; default: $gravatar = 'NO GRAVATAR'; } $status = substr($date, 0, 2); $date = substr($date, 2); $date = date(DATE_W3C, $date); $date = $date . " (" . $status . ")"; $foo = "<div style='float: left; text-align: center; margin: 2px; padding: 2px; border: 2px solid #f90;'><form method='POST'>"; $foo .= "{$gravatar} <br />"; $foo .= $url ? "<a href='{$url}' title='{$url}'>{$name}</a>" : "{$name}"; $foo .= "<br />{$who}<br />"; $md5 = md5($who); $foo .= "<a href='"; $foo .= gravatar_query($md5); $foo .= "'>"; $foo .= "{$md5}</a><br />"; $foo .= $date . "<br />{$count} comments<br /><input type='hidden' name='delete_cache' value='{$who}' /><input type='submit' name='gravatar_admin' value='[ X ]' /></form></div>\r\n"; $cached[] = $foo; } } echo '<h2><span style="font-size: 75%;">'; _e('Local Gravatars', 'gravatars'); echo "</span></h2><fieldset class='options'>\r\n"; if (count($locals) > 0) { echo '<p>'; _e("Deleting a local gravatar causes your blog to use that user's global gravatar (if they have one) or your site's default gravatar", 'gravatars'); echo '.</p>'; foreach ($locals as $local) { echo $local; } echo "<div style='clear: both;'> </div>"; echo "<form method='POST'><table width='100%' class='editform'><tr><td class='alternate' align='right'>Delete all local gravatars: <input type='hidden' name='delete_local' value='ALL_LOCAL' /><input type='submit' name='gravatar_admin' value='DELETE' /></td></tr></table></form>"; } else { echo "<p align='center'><strong>"; _e('No local gravatars', 'gravatars'); echo '</strong></p>'; } echo "</fieldset>"; echo '<h2><span style="font-size: 75%;">'; _e('Cached Gravatars', 'gravatars'); echo "</span></h2><fieldset class='options'>\r\n<p>"; _e('Deleting a cached gravatar will force your blog to request the latest version (if any) from <code>gravatar.com</code>', 'gravatars'); echo '.<br />Current Time: ' . date(DATE_W3C, time()) . '</p>'; echo "<div style='clear: both;'> </div>"; echo "<form method='POST'><table width='100%' class='editform'><tr><td class='alternate' align='right'>Refresh Gravatar Cache: <input type='hidden' name='refresh_cache' value='ALL_CACHE' /><input type='submit' name='gravatar_admin' value='REFRESH CACHE' /></td></tr></table></form>"; echo "<div style='clear: both;'> </div>"; if (count($cached) > 0) { foreach ($cached as $cache) { echo $cache; } } else { echo "<p align='center'><strong>"; _e('No cached gravatars', 'gravatars'); echo '</strong></p>'; } echo "<div style='clear: both;'> </div>"; echo "<table width='100%' class='editform' cellpadding='0' cellspacing='0'><tr>"; echo "<td><form method='POST'><table width='100%' class='editform' cellpadding='0' cellspacing='0'><tr>"; echo "<td class='alternate' align='left'><input type='hidden' name='load_cache' value='load_cache' /><input type='submit' name='gravatar_admin' value='LOAD SAVED CACHE' /> Reload cache from filesystem</td></tr></table></form></td>"; echo "<td><form method='POST'><table width='100%' class='editform' cellpadding='0' cellspacing='0'><tr>"; echo "<td class='alternate' align='right'>Delete all cached gravatars: <input type='hidden' name='delete_cache' value='ALL_CACHE' /><input type='submit' name='gravatar_admin' value='DELETE CACHE' /></td></tr></table></form></td>"; echo "</tr></table>"; echo "</fieldset>\r\n"; echo "<div style='width: 100%; text-align: center;'>" . gravatar_version("html") . "</div>"; echo "</div>"; include ABSPATH . 'wp-admin/admin-footer.php'; // just to be sure die; }