Twitter for Wordpress 1.9.7 by Ricardo González.
Author: Alexander Hofbauer
Author URI: http://derhofbauer.at/blog
*/
/* Copyright 2007 Ricardo González Castro (rick[in]jinlabs.com)
* Copyright 2010 Alexander Hofbauer
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
if (!class_exists("AJAXedTwitter")) { class AJAXedTwitter
{
private static $options = false;
private static $default_options = array(
'title' => 'Tweets',
'username' => '',
'num' => 5,
'list' => true,
'update' => true,
'linked' => '#',
'hyperlinks' => true,
'twitter-users' => true,
'encode-utf8' => false,
'error-id' => 'twitter-error',
'retries' => 2,
'animate' => true,
'cache-age' => 1800,
'timeout' => 2
);
private static $option_fields = array(
'title' => array('label' => 'Title', 'type' => 'text'),
'username' => array('label' => 'Username', 'type' => 'text'),
'num' => array('label' => 'Number of links', 'type' => 'text'),
'list' => array('label' => 'Ouput as unordered list', 'type' => 'checkbox'),
'update' => array('label' => 'Show timestamps', 'type' => 'checkbox'),
'linked' => array('label' => 'Linked', 'type' => 'text'),
'hyperlinks' => array('label' => 'Discover Hyperlinks', 'type' => 'checkbox'),
'twitter-users' => array('label' => 'Discover @replies', 'type' => 'checkbox'),
'encode-utf8' => array('label' => 'UTF8 Encode', 'type' => 'checkbox'),
'error-id' => array('label' => 'Error ID', 'type' => 'text'),
'retries' => array('label' => 'Retries', 'type' => 'text'),
'animate' => array('label' => 'Animate', 'type' => 'checkbox'),
'cache-age' => array('label' => 'Expiry of cached tweets (seconds)', 'type' => 'text')
//'timeout' => array('label' => 'Timeout for RSS download', 'type' => 'text')
);
/**
* Widget function
*/
public static function widget($args)
{
$path = get_bloginfo('wpurl').self::plugin_path();
if (!self::$options) self::get_options();
?>
';
echo $args['after_widget'];
}
/**
* Merges default and saved options
* @return array of current options
*/
private static function get_options()
{
self::$options = get_option('AJAXedTwitter');
if (is_array(self::$options)) {
self::$options = array_merge(self::$default_options, self::$options);
} else {
self::$options = self::$default_options;
}
}
public static function widget_control()
{
if (!self::$options) self::get_options();
if (is_admin() && $_POST['AJAXedTwitter-title']) {
foreach (self::$options as $option => $value) {
if ($option == 'linked') {
// linked is a hybrid and can be false or a string
self::$options['linked'] = ($_POST['AJAXedTwitter-linked'] === '') ? false : $_POST['AJAXedTwitter-linked'];
continue;
}
if (self::$option_fields[$option]['type'] == 'checkbox') {
self::$options[$option] = (isset($_POST['AJAXedTwitter-'.$option])) ? true : false;
} else {
self::$options[$option] = $_POST['AJAXedTwitter-'.$option];
}
}
update_option('AJAXedTwitter', self::$options);
}
echo '
';
}
public static function init()
{
// this will automatically add the MooTools Class "Twitter" to wp_head();
if (!is_admin()) wp_enqueue_script('ajaxed-twitter', self::plugin_path().'/js/Twitter.js');
}
/**
* Get Twitter messages
*
* If $options is passed empty, stored options are taken instead.
*/
public static function messages(array $options = array())
{
if (empty($options) && !self::$options) {
self::get_options();
}
if (!empty($options)) {
self::$options = array_merge(self::$default_options, $options);
}
$options = &self::$options;
$options['error-id'] = ($options['error-id']) ? 'id="'.$options['error-id'].'"' : '';
$output = '';
$messages = self::fetch_rss('http://twitter.com/statuses/user_timeline/'.$options['username'].'.rss');
if ($options['list']) $output = '
';
if ($options['username'] == '') {
if ($options['list']) $output .= '
';
$output .= 'RSS not configured';
if ($options['list']) $output .= '
';
} else {
if (empty($messages->items)) {
if ($options['list']) $output .= '
';
$output .= 'No public Twitter messages.';
if ($options['list']) $output .= '