Created
June 7, 2011 17:44
-
-
Save smithmilner/1012730 to your computer and use it in GitHub Desktop.
A custom box plugin for twitter pull.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Custom Twitter Box | |
*/ | |
class boxes_twitter extends boxes_box { | |
/** | |
* Implementation of boxes_box::options_defaults(). | |
*/ | |
public function options_defaults() { | |
return array( | |
'prefix' => '@', | |
'twitkey' => '', | |
'use_as_title' => 1, | |
'num_tweets' => 5, | |
'morelink' => false, | |
); | |
} | |
/** | |
* Implementation of boxes_box::options_form(). | |
*/ | |
public function options_form(&$form_state) { | |
$form = array(); | |
$form['prefix'] = array( | |
'#type' => 'select', | |
'#title' => t('twitter prefix'), | |
'#default_value' => $this->options['prefix'], | |
'#description' => t('What type a twitter box is this, username or hashtag?'), | |
'#options' => array('#' => t('# - hashtag'), '@' => t('@ - username')) | |
); | |
$form['twitkey'] = array( | |
'#type' => 'textfield', | |
'#title' => t('twitter key'), | |
'#default_value' => $this->options['twitkey'], | |
'#description' => t('The twitter username or term you want to display.'), | |
); | |
$form['use_as_title'] = array( | |
'#type' => 'checkbox', | |
'#title' => t('use twitkey as box title?'), | |
'#default_value' => $this->options['use_as_title'], | |
'#description' => t('Use the @username or #term as the box title?'), | |
); | |
$form['num_tweets'] = array( | |
'#type' => 'textfield', | |
'#title' => t('The number of tweets'), | |
'#default_value' => $this->options['num_tweets'], | |
'#description' => t('The number of tweets you would like to show. Max 200') | |
); | |
$form['morelink'] = array( | |
'#type' => 'checkbox', | |
'#title' => t('more link'), | |
'#default_value' => $this->options['morelink'], | |
'#description' => t('Include a morelink at the bottom of the results.'), | |
); | |
return $form; | |
} | |
/** | |
* Implementation of boxes_box::render(). | |
*/ | |
public function render() { | |
$values = $this->options; | |
$valid = FALSE; | |
$title = isset($this->title) ? $this->title : NULL; | |
$subject = $title; | |
if (!empty($values['twitkey'])) { | |
$valid = TRUE; | |
$twitkey = $values['prefix'] . $values['twitkey']; | |
$num_tweets = $values['num_tweets']; | |
} | |
$title = $values['use_as_title'] == 1 ? $twitkey : $title; | |
$content = $valid == TRUE ? twitter_pull_render($twitkey, NULL, $num_tweets, NULL) : NULL; | |
if ($values['morelink'] == 1) { | |
if ($values['prefix'] == '#') { | |
$twitterurl = 'http://twitter.com/search/'; | |
} else if ($values['prefix'] == '@') { | |
$twitterurl = 'http://twitter.com/'; | |
} | |
$morelink = '<div class="box-footer more-link">' . l('more', $twitterurl.$twitkey) . '</div>'; | |
$content .= $morelink; | |
} | |
return array( | |
'delta' => $this->delta, // Crucial. | |
'title' => $title, | |
'subject' => $subject, | |
'content' => $content, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment