• Home
  • Contact
bogge.info

The brain dump of bogge.

  • Contact
  • Blog
    • Computer
    • Food
    • Fun stuff
    • Graphic
    • msi
    • Pirate
      • Scripting
        • AutoIT
        • Crystal syntax
        • Etomite CMS
        • HTML
        • PHP
        • VBScript
    • Software
  • Photo
    • Interior
    • Landscape
    • Nature
    • Sky

Lifestream Script for Etomite CMS

Posted on January 21, 2010 by bogge

Lifestream is a chronological aggregated view of your life activities online. It is only limited by the content and sources that you use to define it.

This snippet generates a lifestream with the Etomite CMS. You must have a working SimplePie “installation” for this snippet to work.

If you not use Etomite CMS, it will be easy to convert to a regular PHP script.

/*
 lifestream v1.0
 A Etomite script by bogge, bogge.com
 I take no responsibility for any thing, even if I'm to blame.

 "Installing"
 1. Download SimplePie (http://simplepie.org/downloads/), it´s tested with 1.1.3.
 2. Extract and Upload to webserver, upload everything. (http://simplepie.org/wiki/setup/setup)

 Usage
 [ [lifestream]] Shows lifestream
 [ [lifestream?limit=20m&cachelen=3600]] Shows lifestream fetching 20 posts from each feed and with 1h cache.
  I think you get it...

 Settings
*/
$cachelen = isset($cachelen)? $cachelen: "5400"; //Set the minimum time (in seconds) for which a feed will be cached.
$limit = isset($limit)? $limit: "10"; //Set the maximum number of items to return per feed
$path = isset($path)? $path: "/external/simplepie"; //path to simplepie folder, must not end with /, You may need to change this to match the location of simplepie.
$iscontentking = isset($iscontentking)? $iscontentking: "2"; //0=No (no content) 1=Yes (show content), 2=Yes (show descriptions)
$showfav = isset($showfav)? $showfav: "1"; //Show favicon? 1=Yes, 0=No
$addto = isset($addto)? $addto: "1"; //Show "add to" section? 1=Yes, 0=No
$subscribeto = isset($subscribeto)? $subscribeto: "1"; //Show "subscribe" section? 1=Yes, 0=No
$oldpost = mktime(0, 0, 0, date("n")-1, date("j"), date("Y")); // This sets that no post in lifestream is older than today -1 month.

/*
Feeds, add all feed that you would like to show in lifestream.
This sets an array of URLs that you want to parse.
If there is not a feed at this location, auto-discovery is used.
Tested with: Delicious, WordPress blog, Twitter, Flickr, Last.fm, YouTube
Twitter needs more work read more http://simplepie.org/wiki/faq/problematic_feeds
*/
$feedurls = array(
	'http://feeds.delicious.com/v2/rss/bogge',
	'http://feedproxy.google.com/bogge/blog'
);

//No editing below

require_once($_SERVER['DOCUMENT_ROOT'].$path.'/simplepie.inc'); // Make sure SimplePie is included.

$feed = new SimplePie(); // Create a new SimplePie object
$feed->set_feed_url($feedurls); // Passing feeds
$feed->set_item_limit($limit); //Set the maximum number of items to return per feed with Multifeeds.
$feed->set_output_encoding('UTF-8'); //Allows you to override SimplePie's output to match that of your webpage.
$feed->set_cache_duration($cachelen); //Set the minimum time (in seconds) for which a feed will be cached.
$feed->init(); // Initialize the feed object. This is what makes everything happen.
$feed->handle_content_type(); // This method ensures that the SimplePie-enabled page is being served with the correct mime-type and character encoding HTTP headers (character encoding determined by the set_output_encoding() config option.

// If a SimplePie error was thrown, it will display it here.
if ($feed->error) {
	$output = '

'.$feed->error().'

';
}

function getClass($url)
{
	//This is a modified version that was orginaly written by http://github.com/trey.
	preg_match('/https{0,1}:\/\/([^\/]*)\/*.*/i', $url, $matches);
	$class = $matches[1];
	$class = preg_replace("/www./", "", $class); // Remove `www.`.
	$class = preg_replace("/.(com|org|net)/", "", $class); // Remove top level domains. Add more as you see fit.
	$class = preg_replace("/./", "_", $class); // Replace `.`s with `_`s.
	return $class;
}

function doRelativeDate($posted_date) {
    /**
        This function returns either a relative date or a formatted date depending
        on the difference between the current datetime and the datetime passed.
            $posted_date should be in the following format: YYYYMMDDHHMMSS

        Relative dates look something like this:
            3 weeks, 4 days ago
        Formatted dates look like this:
            on 02/18/2004

        The function includes 'ago' or 'on' and assumes you'll properly add a word
        like 'Posted ' before the function output.

        By Garrett Murray, http://graveyard.maniacalrage.net/etc/relative/
    **/
    $in_seconds = strtotime(substr($posted_date,0,8).' '.
                  substr($posted_date,8,2).':'.
                  substr($posted_date,10,2).':'.
                  substr($posted_date,12,2));
    $diff = time()-$in_seconds;
    $months = floor($diff/2592000);
    $diff -= $months*2419200;
    $weeks = floor($diff/604800);
    $diff -= $weeks*604800;
    $days = floor($diff/86400);
    $diff -= $days*86400;
    $hours = floor($diff/3600);
    $diff -= $hours*3600;
    $minutes = floor($diff/60);
    $diff -= $minutes*60;
    $seconds = $diff;

    if ($months>0) {
        // over a month old, just show date (yyyy-mm-dd format)
        return 'on '.substr($posted_date,0,4).'-'.substr($posted_date,4,2).'-'.substr($posted_date,6,2);
    } else {
        if ($weeks>0) {
            // weeks and days
            $relative_date .= ($relative_date?', ':'').$weeks.' week'.($weeks>1?'s':'');
            $relative_date .= $days>0?($relative_date?', ':'').$days.' day'.($days>1?'s':''):'';
        } elseif ($days>0) {
            // days and hours
            $relative_date .= ($relative_date?', ':'').$days.' day'.($days>1?'s':'');
            $relative_date .= $hours>0?($relative_date?', ':'').$hours.' hour'.($hours>1?'s':''):'';
        } elseif ($hours>0) {
            // hours and minutes
            $relative_date .= ($relative_date?', ':'').$hours.' hour'.($hours>1?'s':'');
            $relative_date .= $minutes>0?($relative_date?', ':'').$minutes.' minute'.($minutes>1?'s':''):'';
        } elseif ($minutes>0) {
            // minutes only
            $relative_date .= ($relative_date?', ':'').$minutes.' minute'.($minutes>1?'s':'');
        } else {
            // seconds only
            $relative_date .= ($relative_date?', ':'').$seconds.' second'.($seconds>1?'s':'');
        }
    }
    // show relative date and add proper verbiage
    return $relative_date.' ago';
}

$output .= '
<div id="lifestream">
<ul>'; //Start outputing
$stored_date = ''; //Make sure variable is empty

// Here, we'll loop through all of the items in the feed, and $item represents the current item in the loop.
foreach($feed-&gt;get_items() as $item) {

	//Check if item is older than the $oldpost, if older break and stop outputing.
	$currentdate = mktime(0, 0, 0, $item-&gt;get_date('n'), $item-&gt;get_date('j'), $item-&gt;get_date('Y'));
	if ($currentdate &lt; $oldpost) { 		break; 	}   	//Creates the date headers that is used to group items by date. 	$item_date = $item-&gt;get_date('F jS');
	if ($stored_date != $item_date) {
		$stored_date = $item_date;
		$output .= '</ul>
<h2>'.$stored_date.'</h2>
<ul>';
	}

	//Get information about the feed (not the item) and create a CSS class name. ex a feed from flickr.com gets class name "flickr" and the CSS sould me ".flickr".
	$feed = $item-&gt;get_feed();
	$class = getClass($feed-&gt;get_permalink());
	$output .= '
	<li class="'.$class.'">';

	if ($showfav == 1) {
		//Returns the favicon image for the feed's website. If there is no favicon an alternate is shown.
		if (!$favicon = $feed-&gt;get_favicon()) {
			$favicon = $path.'/demo/for_the_demo/favicons/alternate.png';
		}
		//The favicon is linked to the website and the item is linked to the item.
		$output .= '<a href="'.$feed-&gt;get_permalink().'"><img title="'.$feed-&gt;get_title().'" src="'.$favicon.'" alt="'.$feed-&gt;get_title().'" width="16" height="16" /></a>';
	}

	//Link entire item
	$output .= '<a href="'.$item-&gt;get_permalink().'">';

	//Format and output the item title
	if ($title = $item-&gt;get_title()) {
		$output .= '<strong>'.html_entity_decode($title, ENT_QUOTES, "UTF-8").'</strong>';
	}

	//check if Content Is King or should we output description.
	if ($iscontentking == 1) {
		$output .= ' — '.$item-&gt;get_content();
	}elseif ($iscontentking == 2) {
		$output .= ' — '.$item-&gt;get_description();
	}else {}

	//Create and output the relative date for the item. instead of showing "12/01/2009" it shows "2 weeks, 6 days ago". If date over a month old, just show date (yyyy-mm-dd format).
	$reldate = doRelativeDate($item-&gt;get_date("YmdHis"));
	$output .= '<span class="small"> — '.$reldate.'</span></a>';

	//All the Add to code.
	if ($addto == 1) {
		$output .= '

<strong>Add to:</strong> ';
		$output .= '<a href="' . $item-&gt;add_to_delicious() . '"><img title="Add to del.icio.us" src="'.$path.'/demo/for_the_demo/favicons/delicious.png" alt="Add to del.icio.us" width="16" height="16" /></a>';
		$output .= '<a href="' . $item-&gt;add_to_digg() . '"><img title="Digg It!" src="'.$path.'/demo/for_the_demo/favicons/digg.png" alt="Digg It!" width="16" height="16" /></a>';
		$output .= '<a href="' . $item-&gt;add_to_blinklist() . '"><img title="Add to Blinklist" src="'.$path.'/demo/for_the_demo/favicons/blinklist.png" alt="Add to Blinklist" width="16" height="16" /></a>';
		$output .= '<a href="' . $item-&gt;add_to_blogmarks() . '"><img title="Add to Blogmarks" src="'.$path.'/demo/for_the_demo/favicons/blogmarks.png" alt="Add to Blogmarks" width="16" height="16" /></a>';
//		$output .= '<a href="' . $item-&gt;add_to_furl() . '"><img title="Add to Furl" src="'.$path.'/demo/for_the_demo/favicons/furl.png" alt="Add to Furl" width="16" height="16" /></a>';
		$output .= '<a href="' . $item-&gt;add_to_magnolia() . '"><img title="Add to Ma.gnolia" src="'.$path.'/demo/for_the_demo/favicons/magnolia.png" alt="Add to Ma.gnolia" width="16" height="16" /></a>';
		$output .= '<a href="' . $item-&gt;add_to_myweb20() . '"><img title="Add to My Web 2.0" src="'.$path.'/demo/for_the_demo/favicons/myweb2.png" alt="Add to My Web 2.0" width="16" height="16" /></a>';
		$output .= '<a href="' . $item-&gt;add_to_newsvine() . '"><img title="Add to Newsvine" src="'.$path.'/demo/for_the_demo/favicons/newsvine.png" alt="Add to Newsvine" width="16" height="16" /></a>';
		$output .= '<a href="' . $item-&gt;add_to_reddit() . '"><img title="Add to Reddit" src="'.$path.'/demo/for_the_demo/favicons/reddit.png" alt="Add to Reddit" width="16" height="16" /></a>';
		$output .= '<a href="' . $item-&gt;add_to_simpy() . '"><img title="Add to Simpy" src="'.$path.'/demo/for_the_demo/favicons/simpy.png" alt="Add to Simpy" width="16" height="16" /></a>';
		$output .= '<a href="' . $item-&gt;add_to_spurl() . '"><img title="Add to Spurl" src="'.$path.'/demo/for_the_demo/favicons/spurl.png" alt="Add to Spurl" width="16" height="16" /></a>';
		$output .= '<a href="' . $item-&gt;add_to_wists() . '"><img title="Add to Wists" src="'.$path.'/demo/for_the_demo/favicons/wists.png" alt="Add to Wists" width="16" height="16" /></a>';
		$output .= '

';
	}

	//All the Subscribe code and One-Click Subscriptions.
	if ($subscribeto == 1) {
		$output .= '

<strong>Subscribe to this feed:</strong> <a href="' . $feed-&gt;subscribe_url() . '"><img title="Subscribe to this feed" src="'.$path.'/demo/for_the_demo/feed.png" alt="Subscribe to this feed" width="16" height="16" /></a>';
		$output .= ' | <a href="'.$feed-&gt;subscribe_google().'">Subscribe in Google Reader</a>';
		$output .= '

';
	}

	$output .= '</li>
';
}
$output .= '</ul>
<span style="float:right; font-size:9px; color:#888;"><a title="Lifestream script coded by bogge" href="http://www.bogge.com/info/scripting-language/etomitecms/lifestream-script">Script</a> by <a title="You can find tv series information, scripts, services and torrents at Bogge.com" href="http://www.bogge.com/">Bogge</a></span></div>
';

return $output;</pre>

<pre lang="css">
#lifestream {
font-size:12px;
width:620px;
margin:15px auto auto;
padding:5px;
}
 
#lifestream ul {
list-style-position:inside;
list-style-type:none;
margin-left:0;
padding-left:0;
}
 
#lifestream li {
margin-bottom:3px;
margin-left:0;
padding:5px;
}
 
#lifestream li a {
text-decoration:none;
color:#111;
}
 
#lifestream li img {
margin-right:5px;
border: 0;
vertical-align: middle;
}
 
#lifestream h2 {
font-family:Arial,'Trebuchet MS',Sans-Serif;
font-weight:700;
font-size:120%;
margin:10px 0;
color:#fff;
background-color:#000;
letter-spacing:0.5px;
padding:4px 0 4px 0;
text-align: center
}
 
.twitter {
background-color:#FF8000;
}
 
.flickr {
background-color:#f8d8e9;
}
 
.delicious {
background-color:#CCCCFF;
}
 
.last_fm {
background-color:#FFCC99;
}
 
.bogge {
background-color:#ECFDCE;
}
 
.youtube {
background-color:#FFAFAF;
}
 
.small {
font-size:10px;
color:#888;
}
This entry was posted in Etomite CMS. Bookmark the permalink
  • Connect with us:
  • RSS
  • © 2021 www.bogge.com
  • bogge.com | bogge.eu | bogge.tv