Skip to content

Commit

Permalink
[Twitter] Made plugin's output customizable.
Browse files Browse the repository at this point in the history
  • Loading branch information
aldesantis committed Oct 25, 2011
1 parent 14543b4 commit 7a2a23e
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions Phergie/Plugin/Twitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,27 +158,35 @@ public function onCommandTwitter($tweeter = null, $num = 1)
/**
* Formats a Tweet into a message suitable for output.
*
* @param object $tweet JSON-decoded tweet object from Twitter
* @param bool $includeUrl whether or not to include the URL in the
* formatted output
* @param object $tweet JSON-decoded tweet object from Twitter
*
* @return string
*/
protected function formatTweet(StdClass $tweet, $includeUrl = true)
protected function formatTweet(StdClass $tweet)
{
$ts = $this->plugins->time->getCountDown($tweet->created_at);
$out = '<@' . $tweet->user->screen_name .'> '
. preg_replace('/\s+/', ' ', $tweet->text)
. ' - ' . $ts . ' ago';
if ($includeUrl) {
$out .= ' (' . $this->twitter->getUrlOutputStatus($tweet) . ')';
}
$format = $this->getConfig('twitter.format', '<@{screen_name}> {text} - '
. '{countdown} ago ({url})');

$out = str_replace(array(
'{screen_name}',
'{text}',
'{time}',
'{countdown}',
'{url}',
), array(
$tweet->user->screen_name,
$tweet->text,
$tweet->created_at,
$this->plugins->time->getCountDown($tweet->created_at),
$this->twitter->getUrlOutputStatus($tweet),
), $format);

$encode = $this->getPluginHandler()->getPlugin('Encoding');

return $encode->decodeEntities($out);
}


/**
* Renders Twitter URLs.
*
Expand Down

0 comments on commit 7a2a23e

Please sign in to comment.