My Blogroll script
August 20th, 2005, 11:13 am
I was recently asked about my blogroll script which updates automatically. So this post is about that.
First off, I signed up at Blo.gs and started adding people to my favorites list. When you are done doing that, go into your settings and make it so that your favorites can be shared. Once that has been done, in the sidebar you’ll see a link named Shared, go there. Click on the favorites.xml file and take note of the number that is in the url. Should be something like http://blo.gs/12345/favorites.xml.
If you want, you can save this file to your computer and then upload it to your blog. It isn’t required but you may need to so you can chmod the favorites.xml file to atleast 666.
Next, change this script (you can also find it below, under Read More) so that it uses the number that I mentioned before. Upload it to the root directory of your blog. I’d name it blogroll.php.
Once it has been uploaded, put the following code on your site where ever you want your blogroll to be displayed.
[php]< ?php
include('blogroll.php');
?>[/php]
Now you will have a blogroll on your site that will update every hour. Be sure to edit it so that it is styled to match your site.
[php]< ?php
//
// Script was originally written by SHS` (http://lambcutlet.org/)
// Modified by wGEric (http://www.best-dev.com/)
//
//
// To use the script, can the url on line 49 to your XML file on
// http://blo.gs/ and where ever you want the list to show up
// add include('blogroll.php'); with the proper PHP opening
// and closing tags of course
//
$currentTime = time();
function calcElapsedTime($elapsedTime)
{
$yearDiff = 0; $mnthDiff = 0; $weekDiff = 0; $daysDiff = 0; $hrsDiff = 0; $minsDiff = 0; $secsDiff = 0;
$sec_in_a_year = 31536000;
while($elapsedTime >= $sec_in_a_year){$yearDiff++; $elapsedTime -= $sec_in_a_year;}
$sec_in_a_month = 2592000;
while($elapsedTime >= $sec_in_a_month){$mnthDiff++; $elapsedTime -= $sec_in_a_month;}
$sec_in_a_week = 604800;
while($elapsedTime >= $sec_in_a_week){$weekDiff++; $elapsedTime -= $sec_in_a_week;}
$sec_in_a_day = 86400;
while($elapsedTime >= $sec_in_a_day){$daysDiff++; $elapsedTime -= $sec_in_a_day;}
$sec_in_an_hour = 3600;
while($elapsedTime >= $sec_in_an_hour){$hrsDiff++; $elapsedTime -= $sec_in_an_hour;}
$sec_in_a_min = 60;
while($elapsedTime >= $sec_in_a_min){$minsDiff++; $elapsedTime -= $sec_in_a_min;}
$secsDiff = $elapsedTime;
$yearText = ($yearDiff == 0)?”:(($yearDiff == 1)?’1 year’:$yearDiff . ‘ years’);
$mnthText = ($mnthDiff == 0)?”:(($mnthDiff == 1)?’1 month’:$mnthDiff . ‘ months’);
$weekText = ($weekDiff == 0)?”:(($weekDiff == 1)?’1 week’:$weekDiff . ‘ weeks’);
$daysText = ($daysDiff == 0)?”:(($daysDiff == 1)?’1 day’:$daysDiff . ‘ days’);
$hrsText = ($hrsDiff == 0)?”:(($hrsDiff == 1)?’1 hour’:$hrsDiff . ‘ hours’);
$minsText = ($minsDiff == 0)?”:(($minsDiff == 1)?’1 minute’:$minsDiff . ‘ minutes’);
$secsText = ($secsDiff == 0)?”:(($secsDiff == 1)?’1 second’:$secsDiff . ‘ seconds’);
$timeText = preg_replace(array(’/(, ){2,}/’, ‘/^, /’), array(’, ‘, ”), ($yearText.’, ‘.$mnthText.’, ‘.$weekText.’, ‘.$daysText.’, ‘.$hrsText.’, ‘.$minsText.’, ‘.$secsText));
$timeTextA = explode(”, “, $timeText);
return $timeTextA[0] . (($timeTextA[1] != ”)?”, ” . $timeTextA[1]:”);
}
if ( filemtime(’favorites.xml’) < (time()-3600) )
{
$favorites = file_get_contents('http://blo.gs/1234/favorites.xml');
$fop = fopen('favorites.xml', 'w');
fwrite($fop, $favorites);
fclose($fop);
}
else
{
$favorites = file_get_contents('favorites.xml');
}
if (!empty($favorites)) {
$xml = xml_parser_create();
xml_parser_set_option($xml, XML_OPTION_CASE_FOLDING, false);
xml_parse_into_struct($xml, $favorites, $weblogData);
xml_parser_free($xml);
$favTimeStamp = $weblogData[0]['attributes']['count'];
array_shift($weblogData);
for ($i = 0, $total = count($weblogData); $i < $total; $i++)
{
if ( $weblogData[$i]['type'] != 'complete' )
{
continue;
}
if ( !empty($weblogData[$i]['attributes']['when']) && $weblogData[$i]['attributes']['when'] != 0)
{
$weblogData[$i]['attributes']['fromnow'] = ($currentTime - $favTimeStamp) + $weblogData[$i]['attributes']['when'];
$weblogData[$i]['attributes']['fromnow'] = calcElapsedTime($weblogData[$i]['attributes']['fromnow']);
}
else
{
$weblogData[$i]['attributes']['fromnow'] = '';
}
echo "\t
if ( !empty($weblogData[$i]['attributes']['fromnow']) )
{
echo $weblogData[$i]['attributes']['fromnow'] . “\n\t\n”;
}
}
}
else
{
echo “\t
\n”;
}
?>[/php]









By smithy_dll on August 30th, 2005 at 4:26 am
Eric, can you link to the php file, it’s not copying and pasting correctly from your blog, cheers.
By Eric on August 30th, 2005 at 7:02 pm
Uploaded. You can find it here.
By Markus on November 17th, 2005 at 4:27 am
I was using this blogroll script on my sidebar, but sudenly my blo.gs account disappeared. I’m too lazy to create another blo.gs account, if there was an alternative.
By Fountain of Apples on January 3rd, 2006 at 8:30 pm
Now can you just get that script to update itself? I swear that my website has been updated more recently than 4 months 8 hours ago.
By Fountain of Apples on March 8th, 2006 at 7:08 pm
I can’t get blo.gs to work…