Webmastersite.net

Search    Register    Log In   

Details

Gravitars
By
Aug 16, 2015 pm31 11:14 PM

Gravatars are centrally-stored avatars used by wordpress and many other scripts. The latest WSN release ads an "autoload gravitars" switch, which finds the gravatar for anyone who doesn't upload their own avatar when registering.

If you have a lot of current avatarless members, you may want to go back and load gravatars for them to make your site and especially the comments threads a bit more colorful/personalized. To do that, copy this script to a text file and save it as loadgravatars.php:

<?php
require 'start.php';
if (!$start) $start = 0;
if (!$perpage) $perpage = 50;
$q = $db->select('all', 'memberstable', "1=1", "ORDER BY id DESC", "LIMIT $start,$perpage");
$n = $db->numrows($q);
for($x=0;$x<$n;$x++)
{
$m = new member('row', $db->row($q));
if ($m->avatarname == '' && $m->email != '')
{
$filename = md5(strtolower(trim($m->email))).'.png';
$gravatarurl = "http://www.gravatar.com/avatar/".$filename;
$checkurl = $gravatarurl.'?d=404';
$test = urlheaders($checkurl);
$exists = true;
foreach($test as $t) { if (strstr($t, '404 Not Found')) $exists = false; }
if ($exists)
{
$m->avatarname = uploadurl($gravatarurl, $filename, false, 'avatars');
$m->update('avatarname');
$msg .= 'Added gravatar for '.$m->profileurl().'...';
}
}
}
$start += $perpage;
if ($n) indirectredirect($msg." Continuing to next batch...", "loadgravatars.php?start=$start");
else die("Done!");
require 'end.php';
?>


Upload that to your WSN installation's main directory and visit it in your web browser to start loading gravatars.




Tags , ,
Views 260 views. Averaging 260 views per day.

Sorry, you don't have permission to post. Log in, or register if you haven't yet.

Please login or register.