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 (!defined('AJAXED_TWITTER_FRAMEWORK')) define('AJAXED_TWITTER_FRAMEWORK', 'jquery');
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)
{
echo $args['before_widget'];
echo $args['before_title'].'Tweets'.$args['after_title'];
echo $args['after_widget'];
}
/**
* Merges default and saved options
* @return array of current options
*/
private static function read_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 get_options()
{
if (!self::$options) self::read_options();
return self::$options;
}
public static function widget_control()
{
if (!self::$options) self::read_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 '