Diem plugins syndication

dmWidgetTwitterPlugin

Display tweets in a widget

The dmWidgetTwitterPlugin allows to connect your site with twitter.
It packages a Diem front widget to display tweets searched by keywords.
Uses phptwitterbot internally.

See it in action on Diem community page & Diem homepage.

Installation

  • In a console, from your project root dir, run:
git clone git://github.com/ornicar/dmWidgetTwitterPlugin.git plugins/dmWidgetTwitterPlugin  
  • In config/ProjectConfiguration.class.php, add dmWidgetTwitterPlugin to the list of enabled plugins:
class ProjectConfiguration extends dmProjectConfiguration
{  
  public function setup()  
  {  
    parent::setup();  
 
    $this->enablePlugins(array(  
      // your enabled plugins  
      'dmWidgetTwitterPlugin'  
    ));  
  • In a console, from your project root dir, run:
php symfony dm:setup  

Twitter search widget

This widget uses twitter API to search public tweets with keywords, and display them on the page.
To use it, just drag & drop a Twitter/Search widget somewhere on your site.
See it in action on Diem community page.

Options

Configure the widget on the widget edition dialog:
- query Search query to filter tweets with. You can use simple or complex queries. To get help creating complex queries, use the twitter advanced search form.
- nb_tweets Number of tweets to display.
- life_time Duration of the cache in seconds.

Customize the template

Copy
plugins/dmWidgetTwitterPlugin/modules/dmWidget/templates/_dmWidgetTwitterSearch.php
to
apps/front/modules/dmWidget/templates/_dmWidgetTwitterSearch.php
then modify it.

Default template:

use_helper('Text');
 
/*  
 * A $tweet is an array containing:  
 * - from_user:   username of the one who posted the tweet  
 * - text:        text of the tweet  
 * - created_at:  when the tweet was posted, timestamp  
 */  
 
echo _open('ul');  
 
foreach($tweets as $tweet)  
{  
  echo _tag('li',  
 
    // link to the user page on twitter  
    _link('http://twitter.com/'.$tweet['from_user'])  
    ->text($tweet['from_user'])  
    ->set('.tweet_from_user').  
 
    // render tweet text  
    _tag('p.tweet_text', auto_link_text($tweet['text']))  
 
  );  
}  
 
echo _close('ul');  

This template uses Diem template helpers

Filter tweets with an event

You can modify the list of found tweets before they are displayed by listening the dm.widget_twitter_search.tweets event.

apps/front/frontConfiguration.class.php

class frontConfiguration extends dmFrontApplicationConfiguration
{  
 
  public function configure()  
  {  
    // connect to the dm.widget_twitter_search.tweets event  
    $this->dispatcher->connect('dm.widget_twitter_search.tweets', array($this, 'listenToTwitterSearchTweetsEvent'));  
  }  
 
  public function listenToTwitterSearchTweetsEvent(sfEvent $e, array $tweets)  
  {  
    // do something with the tweets  
    ...  
    // return the filtered tweets  
    return $tweets;  
  }  

Twitter timeline widget

This widget uses twitter API to find tweets from a user, and display them on the page.
To use it, just drag & drop a Twitter/Timeline widget somewhere on your site.
See it in action on Diem homepage.

Options

Configure the widget on the widget edition dialog:
- user Twitter username (Ex: diem_project).
- nb_tweets Number of tweets to display.
- life_time Duration of the cache in seconds.

Customize the template

Copy
plugins/dmWidgetTwitterPlugin/modules/dmWidget/templates/_dmWidgetTwitterTimeline.php
to
apps/front/modules/dmWidget/templates/_dmWidgetTwitterTimeline.php
then modify it.

Default template:

use_helper('Text');
use_helper('Date');  
 
/*  
 * A $tweet is an array containing:  
 * - text:        text of the tweet  
 * - created_at:  when the tweet was posted, timestamp  
 */  
 
echo _open('ul');  
 
foreach($tweets as $tweet)  
{  
  echo _tag('li',  
 
    // render tweet text  
    _tag('p.tweet_text', auto_link_text($tweet['text'])).  
 
    // render tweet date  
    _tag('p.tweet_date', format_date($tweet['created_at'], 'D'))  
 
  );  
}  
 
echo _close('ul');  

This template uses Diem template helpers

Filter tweets with an event

You can modify the list of found tweets before they are displayed by listening the dm.widget_twitter_timeline.tweets event.

apps/front/frontConfiguration.class.php

class frontConfiguration extends dmFrontApplicationConfiguration
{  
 
  public function configure()  
  {  
    // connect to the dm.widget_twitter_search.tweets event  
    $this->dispatcher->connect('dm.widget_twitter_timeline.tweets', array($this, 'listenToTwitterTimelineTweetsEvent'));  
  }  
 
  public function listenToTwitterTimelineTweetsEvent(sfEvent $e, array $tweets)  
  {  
    // do something with the tweets  
    ...  
    // return the filtered tweets  
    return $tweets;  
  }  
  • PikiMarch 15, 2011 3:49 PM

    The problem is... the widget does not work...

Add a comment

Create an issue
Impossible to fetch issues for this plugin.
Impossible to get this plugin changelog.
See more commits

dmWidgetTwitterPlugin, created on January 19, 2010 by Thibault D, used by 587 projects

Fork Diem on GitHub