';
// If "hide rss" hasn't been checked, show the linked icon
if (!$options[$number]['hiderss']) {
if ( file_exists(dirname(__FILE__) . '/rss.png') ) {
$icon = str_replace(ABSPATH, get_option('siteurl').'/', dirname(__FILE__)) . '/rss.png';
} else {
$icon = get_option('siteurl').'/wp-includes/images/rss.png';
}
$feedUrl = $this->_getFeedUrl($options[$number], 'rss', false);
$before_title .= " ";
}
$twitterLink = 'http://twitter.com/' . $options[$number]['username'];
$before_title .= "' . $after_title;
if (empty($options[$number]['title'])) {
$options[$number]['title'] = "Twitter: {$options[$number]['username']}";
}
echo $before_title . $options[$number]['title'] . $after_title;
if (is_a($tweets, 'wpTwitterWidgetException')) {
echo '
';
} else if (count($tweets) == 0) {
echo '
';
} else {
?>
';
echo $this->_getProfileImage($tweets[0]->user);
echo '';
echo '';
}
foreach ($tweets as $tweet) {
// Set our "ago" string which converts the date to "# ___(s) ago"
$tweet->ago = $this->_timeSince(strtotime($tweet->created_at), $options[$number]['showts']);
?>
-
text ); ?>
ago; ?>
from source);
if (isset($tweet->in_reply_to)) {
echo $this->_getReplyTo($tweet->in_reply_to);
} ?>
' . $after_widget;
}
/**
* Returns a "in reply to" link to the user passed
*
* @param object $replyTo - Tweet
* @return string - Link to Twitter user (XHTML)
*/
private function _getReplyTo($replyTo) {
return <<
in reply to {$replyTo->user->screen_name}
replyTo;
}
/**
* Returns the Twitter user's profile image, linked to that user's profile
*
* @param object $user - Twitter User
* @return string - Linked image (XHTML)
*/
private function _getProfileImage($user) {
return <<
profileImage;
}
/**
* Returns the user's screen name as a link inside strong tags.
*
* @param object $user - Twitter user
* @return string - Username as link (XHTML)
*/
private function _getUserName($user) {
return <<
{$user->screen_name}
profileImage;
}
/**
* Sets up admin forms to manage widgets
*
* @param array|int $widget_args - Widget Number
*/
public function control($widget_args) {
global $wp_registered_widgets;
static $updated = false;
if ( is_numeric($widget_args) )
$widget_args = array( 'number' => $widget_args );
$widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
extract( $widget_args, EXTR_SKIP );
$options = get_option('widget_twitter');
if ( !is_array($options) )
$options = array();
if ( !$updated && !empty($_POST['sidebar']) ) {
$sidebar = (string) $_POST['sidebar'];
$sidebars_widgets = wp_get_sidebars_widgets();
if ( isset($sidebars_widgets[$sidebar]) )
$this_sidebar =& $sidebars_widgets[$sidebar];
else
$this_sidebar = array();
foreach ( $this_sidebar as $_widget_id ) {
if ( array($this,'display') == $wp_registered_widgets[$_widget_id]['callback'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number']) ) {
$widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number'];
if ( !in_array( "twitter-$widget_number", $_POST['widget-id'] ) ) // the widget has been removed.
unset($options[$widget_number]);
}
}
foreach ( (array) $_POST['widget-twitter'] as $widget_number => $widget_twitter ) {
if ( !isset($widget_twitter['username']) && isset($options[$widget_number]) ) // user clicked cancel
continue;
$widget_twitter['title'] = stripslashes($widget_twitter['title']);
$widget_twitter['errmsg'] = stripslashes($widget_twitter['errmsg']);
if ( !current_user_can('unfiltered_html') ) {
$widget_twitter['title'] = strip_tags($widget_twitter['title']);
$widget_twitter['errmsg'] = strip_tags($widget_twitter['errmsg']);
}
$options[$widget_number] = $widget_twitter;
}
update_option('widget_twitter', $options);
$updated = true;
}
if ( -1 != $number ) {
$options[$number]['number'] = $number;
$options[$number]['title'] = attribute_escape($options[$number]['title']);
$options[$number]['errmsg'] = attribute_escape($options[$number]['errmsg']);
$options[$number]['fetchTimeOut'] = attribute_escape($options[$number]['fetchTimeOut']);
$options[$number]['username'] = attribute_escape($options[$number]['username']);
$options[$number]['hiderss'] = (bool) $options[$number]['hiderss'];
$options[$number]['avatar'] = (bool) $options[$number]['avatar'];
}
$this->_showForm($options[$number]);
}
/**
* Registers widget in such a way as to allow multiple instances of it
*
* @see wp-includes/widgets.php
*/
public function register() {
if ( !$options = get_option('widget_twitter') )
$options = array();
$widget_ops = array('classname' => 'widget_twitter', 'description' => __('Follow a Twitter Feed'));
$control_ops = array('width' => 400, 'height' => 350, 'id_base' => 'twitter');
$name = __('Twitter Feed');
$id = false;
foreach ( array_keys($options) as $o ) {
// Old widgets can have null values for some reason
if ( !isset($options[$o]['title']) || !isset($options[$o]['username']) )
continue;
$id = "twitter-$o"; // Never never never translate an id
wp_register_sidebar_widget($id, $name, array($this,'display'), $widget_ops, array( 'number' => $o ));
wp_register_widget_control($id, $name, array($this,'control'), $control_ops, array( 'number' => $o ));
}
// If there are none, we register the widget's existance with a generic template
if ( !$id ) {
wp_register_sidebar_widget( 'twitter-1', $name, array($this,'display'), $widget_ops, array( 'number' => -1 ) );
wp_register_widget_control( 'twitter-1', $name, array($this,'control'), $control_ops, array( 'number' => -1 ) );
}
}
/**
* Displays the actualy for that populates the widget options box in the
* admin section
*
* @param array $args - Current widget settings and widget number, gets combind with defaults
*/
private function _showForm($args) {
$defaultArgs = array( 'title' => '',
'errmsg' => '',
'fetchTimeOut' => '2',
'username' => '',
'hiderss' => false,
'avatar' => false,
'items' => 10,
'showts' => 60 * 60 * 24,
'number' => '%i%' );
$args = wp_parse_args( $args, $defaultArgs );
extract( $args );
?>
60 * 60 * 24 * 365, 'name' => 'year'),
array('seconds' => 60 * 60 * 24 * 30, 'name' => 'month'),
array('seconds' => 60 * 60 * 24 * 7, 'name' => 'week'),
array('seconds' => 60 * 60 * 24, 'name' => 'day'),
array('seconds' => 60 * 60, 'name' => 'hour'),
array('seconds' => 60, 'name' => 'minute'),
array('seconds' => 1, 'name' => 'second')
);
$since = time() - $startTimestamp;
if ($max != '-1' && $since >= $max) {
return date('h:i:s A F d, Y', $startTimestamp);
}
// $j saves performing the count function each time around the loop
for ($i = 0, $j = count($chunks); $i < $j; $i++) {
extract($chunks[$i]);
// finding the biggest chunk (if the chunk fits, break)
if (($count = floor($since / $seconds)) != 0) {
break;
}
}
$print = "{$count} {$name}";
if ($count > 1) {
$print .= 's';
}
return "about {$print} ago";
}
function activatePlugin() {
// If the wga-id has not been generated, generate one and store it.
$id = $this->get_id();
$o = get_option('twitter_widget_pro');
if (!isset($o['user_agreed_to_send_system_information'])) {
$o['user_agreed_to_send_system_information'] = 'true';
update_option('twitter_widget_pro', $o);
}
}
function get_id() {
$id = get_option('twitter_widget_pro-id');
if ($id === false) {
$id = sha1( get_bloginfo('url') . mt_rand() );
update_option('twitter_widget_pro-id', $id);
}
return $id;
}
/**
* if user agrees to send system information and the last sent info is outdated outputs a bunch of stuff that sends sysinfo without interrupting
*/
function outputSendInfoForm()
{
$o = get_option('twitter_widget_pro');
if ($o['user_agreed_to_send_system_information'] == 'true') {
$lastSent = get_option('twp-sysinfo');
$sysinfo = $this->get_sysinfo();
//if (serialize($lastSent) != serialize($sysinfo)) {
?>
get_id();
$s['version'] = TWP_VERSION;
$s['php_version'] = phpversion();
$s['mysql_version'] = @mysql_get_server_info($wpdb->dbh);
$s['server_software'] = $_SERVER["SERVER_SOFTWARE"];
$s['memory_limit'] = ini_get('memory_limit');
return $s;
}
public function addSettingLink( $links, $file ){
if ( empty($this->_pluginBasename) ) {
$this->_pluginBasename = plugin_basename(__FILE__);
}
if ( $file == $this->_pluginBasename ) {
// Add settings link to our plugin
$link = '' . __('Settings') . '';
array_unshift( $links, $link );
}
return $links;
}
}
// Instantiate our class
$wpTwitterWidget = new wpTwitterWidget();
/**
* Add filters and actions
*/
add_action( 'admin_menu', array($wpTwitterWidget,'admin_menu') );
add_action( 'widgets_init', array($wpTwitterWidget, 'register') );
add_filter( 'widget_twitter_content', array($wpTwitterWidget, 'linkTwitterUsers') );
add_filter( 'widget_twitter_content', array($wpTwitterWidget, 'linkUrls') );
add_action( 'activate_twitter-widget-pro/wp-twitter-widget.php', array($wpTwitterWidget, 'activatePlugin') );
add_action( 'admin_footer', array($wpTwitterWidget, 'outputSendInfoForm') );
add_filter( 'plugin_action_links', array($wpTwitterWidget, 'addSettingLink'), 10, 2 );