Enthropia Labs

Please login or register.

Login with username, password and session length
Advanced search  

News:

Welcome to the new iBegin Labs forum!

Author Topic: Customizing Your Lifestream Output  (Read 3214 times)

David Cramer

  • Developer
  • Administrator
  • Sr. Member
  • *****
  • Posts: 444
    • View Profile
    • Email
Customizing Your Lifestream Output
« on: March 30, 2009, 12:44:43 am »
One of the many requests is changing your lifestream output to something other than what the widget can provide. I do this on my personal site, and there are also several other people doing this. However, there was/is no real documentation or guide for it.

So, we're going to give you a quick rundown. Keep in mind, this requires writing PHP code.

Lifestream wraps all of its events, and its groups of events in to several classes. There's one common function call which will return instances of these classes:

Code: [Select]
function lifestream_get_events($_=array())
{
    $defaults = array(
         // number of events
        'number_of_results' => get_option('lifestream_number_of_items'),
        // offset of events (e.g. pagination)
        'offset'            => 0,
        // array of feed ids
        'feed_ids'          => array(),
        // array of user ids
        'user_ids'          => array(),
        // array of feed type identifiers
        'feed_types'        => array(),
        // interval for date cutoff (see mysql INTERVAL)
        'date_interval'     => get_option('lifestream_date_interval'),
        // start date of events
        'start_date'        => -1,
        // end date
        'end_date'          => -1,
        // minimum number of events in group
        'event_total_min'   => -1,
        // maximum
        'event_total_max'   => -1,
        // break groups into single events
        'break_groups'      => false,
    );
}

Now, the way this works is pretty simple:

Code: [Select]
// this will return results 20-40 from your lifestream, perfect for pagination
$results = lifestream_get_events(array(
  'offset' = 20,
  'number_of_results' = 20,
  'date_interval' = -1,
));

Let's take a look at what lifestream_twitter_status() does:

Code: [Select]
// this is a shortcut method which the twitter event handler returns
function lifestream_get_single_event($feed_type)
{
    $events = lifestream_get_events(array('feed_types'=>array($feed_type), 'number_of_results'=>1, 'break_groups'=>true));
    $event = $events[0];

    return $event;
}

/**
 * Displays your latest Twitter status.
 * @param {Boolean} $links Parse user links.
 */
function lifestream_twitter_status($links=true)
{
    $event = lifestream_get_single_event('twitter');
    if (!$event) return;
    if ($links)
    {
        // to render it with links
        echo $event->feed->render_item($event, $event->data);
    }
    else
    {
        // or render just the text
        echo $event->data['title'];
    }
}

As you can see all of the internal methods are calling one global function, and that is the lifestream_get_events. It has a number of defaults, which typically are set within your options, but you can override any option by passing it into the initial array.

There's one more important option to talk about, and that's the break_groups option. If you set this to true, instead of getting a LifeStream_EventGroup instance, you're going to get a LifeStream_Event instance. This allows you to show every single event, even if it was within a batch, in the order it happened. Both of these classes function very similar, and have render methods on them.

I will eventually write up more documentation for this, but hopefully this is enough to get some of you started.
« Last Edit: March 31, 2009, 12:39:09 am by David Cramer »
Logged

thekaitlin

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Customizing Your Lifestream Output
« Reply #1 on: March 30, 2009, 06:00:38 pm »
thank you for starting on this :)  Very useful to know.
Logged

Balou

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Customizing Your Lifestream Output
« Reply #2 on: April 07, 2009, 03:25:14 pm »
Hello!

I put this plugin in my sidebar, and I have a question/problem. I need a "one line title" trick... e.g.: 2009. April 4. Saturday  00:17 thistitleistoslongfor[...] So, how can I cut off the title's ends, when its too long? (sorry my bad english, but I'm a little tired :) )
Logged

David Cramer

  • Developer
  • Administrator
  • Sr. Member
  • *****
  • Posts: 444
    • View Profile
    • Email
Re: Customizing Your Lifestream Output
« Reply #3 on: April 07, 2009, 03:51:34 pm »
If you're doing php code you could use $lifestream->truncate($string, $length) but it's gonna be really iffy.
Logged

alexherder

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Customizing Your Lifestream Output
« Reply #4 on: May 06, 2009, 10:05:47 am »
Would this help me?

I have a Lifestream that I've set to only record loved tracks from Last.fm, but I'd prefer it to output: "Loved <Song Title> - <Song Artist>" instead of "Listened to <Song Title> - <Song Artist>"

I'm not a php wizard or even an initiate.  Any help would be really appreciated.  Thanks~
Logged

jyan

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Customizing Your Lifestream Output
« Reply #5 on: June 13, 2009, 02:34:28 pm »
I'm hoping to be able to actually output the results of lifestream into a real post within wordpress. Is that something I can use lifestream_get_events for?

Jeff
Logged

ts10

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Customizing Your Lifestream Output
« Reply #6 on: August 25, 2009, 05:08:56 pm »
I'm so frustrated...I don't know what I'm doing wrong! I am trying to edit my wordpress template, because I need my front page to display a set of RSS feeds. I've tried everything I can think of with lifestream() but get nothing. When I finally found this post, I edited the place where I need my results to appear and it just gives me blank. Nothing at all - no errors (finally got past all those!) but no results either.

Here's my code... what am I missing? Thanks so much! This is right where I need the results to show:

Code: [Select]
function lifestream_get_events($_=array())
{
$defaults = array(
// number of events
'number_of_results' => get_option('lifestream_number_of_items'),
// offset of events (e.g. pagination)
'offset'            => 0,
// array of feed ids
'feed_ids'          => array(),
// array of user ids
'user_ids'          => array(),
// array of feed type identifiers
'feed_types'        => array(),
// interval for date cutoff (see mysql INTERVAL)
'date_interval'     => get_option('lifestream_date_interval'),
// start date of events
'start_date'        => -1,
// end date
'end_date'          => -1,
// minimum number of events in group
'event_total_min'   => -1,
// maximum
'event_total_max'   => -1,
// break groups into single events
'break_groups'      => false,
);
}

$mylifestream = lifestream_get_events(array(
  'offset' => 20,
  'number_of_results' => 20,
  'date_interval' => -1,
  'feed_ids' => 2,
));

It shows nothing even without the 'feed_ids'. Not sure why it's not pulling my data from the database.
Logged

David Cramer

  • Developer
  • Administrator
  • Sr. Member
  • *****
  • Posts: 444
    • View Profile
    • Email
Re: Customizing Your Lifestream Output
« Reply #7 on: August 25, 2009, 07:58:57 pm »
Ok, well two things:

offset should be the start position (did you mean 0?)

feed_ids should be an array, so feed_ids=>array(1)

Also, this is going to return a set of events, not actually render them if you using lifestream_get_events.

You can, however, pass these exact arguments to lifestream().
Logged

Dedos

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Customizing Your Lifestream Output
« Reply #8 on: September 24, 2009, 11:13:40 am »
Hello there, I just started using lifestream and I think its a great plugin, but I can't seem to find how to customize the output. I've read this tutorial but can't find a way to display it in a way like

ICON "Message from RSS Feed"
Date - Hour.

How can I get these values from the event I am calling?
Logged

berfarah

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Customizing Your Lifestream Output
« Reply #9 on: September 25, 2009, 08:46:08 pm »
Hey, I've been using lifestream for about a month now, and I'm doing a complete overhaul of my site, and I want to display the last track I've listened to on one page. So I tried taking the advice you gave above, and - through 99.9% copy/paste - made this:
Code: [Select]
function lifestream_lastfm_song($links=true)
{
    $event = lifestream_get_single_event('lastfm');
    if (!$event) return;
    if ($links)
    {
        // to render it with links
        echo $event->feed->render_item($event, $event->data);
    }
    else
    {
        // or render just the text
        echo $event->data['title'];
    }
}
?>

However, all this returns me is " - ". How can I get this working?

Oh, and here's a bit of shameless self-promotion.
Logged

David Cramer

  • Developer
  • Administrator
  • Sr. Member
  • *****
  • Posts: 444
    • View Profile
    • Email
Re: Customizing Your Lifestream Output
« Reply #10 on: September 27, 2009, 08:54:50 pm »
When I implemented labels I had to slightly tweak how things are rendered. You could do $event->render() but that might not give you the desired output.

Check the Lifestream_SongLabel or whatever its called, and see what it does.
Logged

berfarah

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Customizing Your Lifestream Output
« Reply #11 on: September 29, 2009, 06:36:20 pm »
When I implemented labels I had to slightly tweak how things are rendered. You could do $event->render() but that might not give you the desired output.

Check the Lifestream_SongLabel or whatever its called, and see what it does.
Awesome, implemented it. :) I'll try to gather a few and release it as an extension to your plugin.
Logged