0, __('Only once (on load)', 'tweetblender') => 1, sprintf(__('Every %d seconds', 'tweetblender'),5) => 5, sprintf(__('Every %d seconds', 'tweetblender'),10) => 10, sprintf(__('Every %d seconds', 'tweetblender'),15) => 15, sprintf(__('Every %d seconds', 'tweetblender'),20) => 20, sprintf(__('Every %d seconds', 'tweetblender'),30) => 30, __('Every minute', 'tweetblender') => 60, sprintf(__('Every %d minutes', 'tweetblender'),2) => 120, ); $tb_throttle_time_options = array( __('all time', 'tweetblender') => 0, '1 ' . __('minute', 'tweetblender') => 60, '5 ' . __('minutes', 'tweetblender') => 300, '10 ' . __('minutes', 'tweetblender') => 600, '20 ' . __('minutes', 'tweetblender') => 1200, '30 ' . __('minutes', 'tweetblender') => 1800, '60 ' . __('minutes', 'tweetblender') => 3600, '90 ' . __('minutes', 'tweetblender') => 5400, '120 ' . __('minutes', 'tweetblender') => 7200 ); $tb_keep_tweets_options = array( __('Do not delete them', 'tweetblender') => 0, '1 ' . __('day', 'tweetblender') => 1, '2 ' . __('days', 'tweetblender') => 2, '3 ' . __('days', 'tweetblender') => 3, '1 ' . __('week', 'tweetblender') => 7, '2 ' . __('weeks', 'tweetblender') => 14, '1 ' . __('month', 'tweetblender') => 30 ); $tb_languages = array( ' ' => __('any language', 'tweetblender'), 'ab' => 'Abkhazian', 'ae' => 'Avestan', 'af' => 'Afrikaans', 'ak' => 'Akan', 'am' => 'Amharic', 'an' => 'Aragonese', 'ar' => 'Arabic', 'as' => 'Assamese', 'av' => 'Avaric', 'ay' => 'Aymara', 'az' => 'Azerbaijani', 'ba' => 'Bashkir', 'be' => 'Belarusian', 'bg' => 'Bulgarian', 'bh' => 'Bihari', 'bi' => 'Bislama', 'bm' => 'Bambara', 'bn' => 'Bengali', 'bo' => 'Tibetan', 'br' => 'Breton', 'bs' => 'Bosnian', 'ca' => 'Catalan; Valencian', 'ce' => 'Chechen', 'ch' => 'Chamorro', 'co' => 'Corsican', 'cr' => 'Cree', 'cs' => 'Czech', 'cv' => 'Chuvash', 'cy' => 'Welsh', 'da' => 'Danish', 'de' => 'German', 'en' => 'English', 'eo' => 'Esperanto', 'es' => 'Spanish; Castilian', 'et' => 'Estonian', 'eu' => 'Basque', 'fa' => 'Persian', 'ff' => 'Fulah', 'fi' => 'Finnish', 'fj' => 'Fijian', 'fo' => 'Faroese', 'fr' => 'French', 'fy' => 'Western Frisian', 'ga' => 'Irish', 'gl' => 'Galician', 'gn' => 'Guarani', 'gu' => 'Gujarati', 'gv' => 'Manx', 'ha' => 'Hausa', 'he' => 'Hebrew', 'hi' => 'Hindi', 'ho' => 'Hiri Motu', 'hr' => 'Croatian', 'ht' => 'Haitian; Haitian Creole', 'hu' => 'Hungarian', 'hy' => 'Armenian', 'hz' => 'Herero', 'id' => 'Indonesian', 'ie' => 'Interlingue; Occidental', 'ig' => 'Igbo', 'ii' => 'Sichuan Yi; Nuosu', 'ik' => 'Inupiaq', 'io' => 'Ido', 'is' => 'Icelandic', 'it' => 'Italian', 'iu' => 'Inuktitut', 'ja' => 'Japanese', 'jv' => 'Javanese', 'ka' => 'Georgian', 'kg' => 'Kongo', 'ki' => 'Kikuyu; Gikuyu', 'kj' => 'Kuanyama; Kwanyama', 'kk' => 'Kazakh', 'kl' => 'Kalaallisut; Greenlandic', 'km' => 'Central Khmer', 'kn' => 'Kannada', 'ko' => 'Korean', 'kr' => 'Kanuri', 'ks' => 'Kashmiri', 'ku' => 'Kurdish', 'kv' => 'Komi', 'kw' => 'Cornish', 'ky' => 'Kirghiz; Kyrgyz', 'la' => 'Latin', 'lb' => 'Luxembourgish; Letzeburgesch', 'lg' => 'Ganda', 'li' => 'Limburgan; Limburger; Limburgish', 'ln' => 'Lingala', 'lo' => 'Lao', 'lt' => 'Lithuanian', 'lu' => 'Luba-Katanga', 'lv' => 'Latvian', 'mg' => 'Malagasy', 'mh' => 'Marshallese', 'mi' => 'Maori', 'mk' => 'Macedonian', 'ml' => 'Malayalam', 'mn' => 'Mongolian', 'mr' => 'Marathi', 'ms' => 'Malay', 'mt' => 'Maltese', 'my' => 'Burmese', 'na' => 'Nauru', 'ne' => 'Nepali', 'ng' => 'Ndonga', 'nl' => 'Dutch; Flemish', 'no' => 'Norwegian', 'oj' => 'Ojibwa', 'om' => 'Oromo', 'or' => 'Oriya', 'os' => 'Ossetian; Ossetic', 'pa' => 'Panjabi; Punjabi', 'pi' => 'Pali', 'pl' => 'Polish', 'ps' => 'Pushto; Pashto', 'pt' => 'Portuguese', 'qu' => 'Quechua', 'rm' => 'Romansh', 'rn' => 'Rundi', 'ro' => 'Romanian; Moldavian; Moldovan', 'ru' => 'Russian', 'rw' => 'Kinyarwanda', 'sa' => 'Sanskrit', 'sc' => 'Sardinian', 'sd' => 'Sindhi', 'se' => 'Northern Sami', 'sg' => 'Sango', 'si' => 'Sinhala; Sinhalese', 'sk' => 'Slovak', 'sl' => 'Slovenian', 'sm' => 'Samoan', 'sn' => 'Shona', 'so' => 'Somali', 'sq' => 'Albanian', 'sr' => 'Serbian', 'ss' => 'Swati', 'su' => 'Sundanese', 'sv' => 'Swedish', 'sw' => 'Swahili', 'ta' => 'Tamil', 'te' => 'Telugu', 'tg' => 'Tajik', 'th' => 'Thai', 'ti' => 'Tigrinya', 'tk' => 'Turkmen', 'tl' => 'Tagalog', 'tn' => 'Tswana', 'to' => 'Tonga (Tonga Islands)', 'tr' => 'Turkish', 'ts' => 'Tsonga', 'tt' => 'Tatar', 'tw' => 'Twi', 'ty' => 'Tahitian', 'ug' => 'Uighur; Uyghur', 'uk' => 'Ukrainian', 'ur' => 'Urdu', 'uz' => 'Uzbek', 've' => 'Venda', 'vi' => 'Vietnamese', 'yi' => 'Yiddish', 'yo' => 'Yoruba', 'za' => 'Zhuang; Chuang', 'zh' => 'Chinese', 'zu' => 'Zulu' ); $tb_addons = array( '1' => array( 'name' => __('Cache Manager', 'tweetblender'), 'slug' => 'tweet-blender-cache-manager' ), '2' => array( 'name' => __('nStyle', 'tweetblender'), 'slug' => 'tweet-blender-nstyle' ), '3' => array( 'name' => __('Tweet Injector', 'tweetblender'), 'slug' => 'tweet-blender-injector' ) ); $tb_package_names = array( '1' => __('Cache Manager', 'tweetblender'), '2' => __('nStyle', 'tweetblender'), '3' => __('Tweet Injector', 'tweetblender'), ); $js_labels = array( 'no_config' => __('No configuration settings found', 'tweetblender'), 'twitter_logo' => __('Twitter Logo', 'tweetblender'), 'kino' => __('Development by Kirill Novitchenko', 'tweetblender'), 'refresh' => __('Refresh', 'tweetblender'), 'no_sources' => __('Twitter sources to blend are not defined', 'tweetblender'), 'no_global_config' => __('Cannot retrieve Tweet Blender configuration options', 'tweetblender'), 'version_msg' => __('Powered by Tweet Blender plugin v{0} blending {1}', 'tweetblender'), 'limit_msg' => __('You reached Twitter API connection limit', 'tweetblender'), 'no_tweets_msg' => __('No tweets found for {0}', 'tweetblender'), 'loading_msg' => __('Loading tweets...', 'tweetblender'), 'time_past' => __('{0} {1} ago', 'tweetblender'), 'time_future' => __('in {0} {1}', 'tweetblender'), 'second' => __('second', 'tweetblender'), 'seconds' => __('seconds', 'tweetblender'), 'minute' => __('minute', 'tweetblender'), 'minutes' => __('minutes', 'tweetblender'), 'hour' => __('hour', 'tweetblender'), 'hours' => __('hours', 'tweetblender'), 'day' => __('day', 'tweetblender'), 'days' => __('days', 'tweetblender'), 'week' => __('week', 'tweetblender'), 'weeks' => __('weeks', 'tweetblender'), 'month' => __('month', 'tweetblender'), 'months' => __('months', 'tweetblender'), 'year' => __('year', 'tweetblender'), 'years' => __('years', 'tweetblender'), 'check_fail' => __('Check failed', 'tweetblender'), 'limit_num' => __('Max is {0}/hour', 'tweetblender'), 'limit_left' => __('You have {0} left', 'tweetblender'), 'from' => __('from', 'tweetblender'), 'reply' => __('reply', 'tweetblender'), 'follow' => __('follow', 'tweetblender'), 'limit_reset' => __('Next reset','tweetblender'), 'view_more' => __('view more','tweetblender') ); // if we don't have json class, get own PHP4 compatible library if (!isset($wp_json) || !is_a($wp_json, 'Services_JSON')) { if (!class_exists('Services_JSON')) { require_once( dirname(__FILE__) . '/JSON.php' ); } $wp_json = new Services_JSON(); } function tb_get_url_content($url) { $string = ''; # preferred way is to use curl if (function_exists('curl_init')){ $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_HEADER, 0); ob_start(); curl_exec ($ch); curl_close ($ch); $string = ob_get_contents(); ob_end_clean(); } # plan B is to use file_get_contents elseif (function_exists('file_get_contents')) { $string = @file_get_contents($url); } # fallback is to use fopen else { if ($fh = fopen($url, 'rb')) { clearstatcache(); if ($fsize = @filesize($url)) { $string = fread($fh, $fsize); } else { while (!feof($fh)) { $string .= fread($fh, 8192); } } fclose($fh); } } return $string; } function tb_verbal_time($timestamp) { $periods = array(__("second",'tweetblender'), __("minute",'tweetblender'), __("hour",'tweetblender'), __("day",'tweetblender'), __("week",'tweetblender'), __("month",'tweetblender'), __("year",'tweetblender')); $periods_plural = array(__("seconds",'tweetblender'), __("minutes",'tweetblender'), __("hours",'tweetblender'), __("days",'tweetblender'), __("weeks",'tweetblender'), __("months",'tweetblender'), __("years",'tweetblender')); $lengths = array("60","60","24","7","4.35","12"); $now = time(); $difference = abs($now - $timestamp); for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) { $difference /= $lengths[$j]; } $difference = round($difference); if($difference != 1) { $units = $periods_plural[$j]; } else { $units = $periods[$j]; } if ($timestamp < $now) { return sprintf(__("%d %s ago",'tweetblender'), $difference, $units); } else { return sprintf(__("in %d %s",'tweetblender'), $difference, $units); } } // search: Wed, 27 May 2009 15:52:40 +0000 // user feed: Thu May 21 00:09:16 +0000 2009 function tb_str2time($date_string) { $mnum = array('Jan' => 1,'Feb' => 2, 'Mar' => 3, 'Apr' => 4, 'May' => 5, 'Jun' => 6, 'Jul' => 7, 'Aug' => 8, 'Sep' => 9, 'Oct' => 10, 'Nov' => 11, 'Dec' => 12); if (strpos($date_string, ',') !== false) { list($wday,$mday, $mon, $year, $hour,$min,$sec,$offset) = preg_split('/[\s\:]/',$date_string); } else { list($wday,$mon,$mday,$hour,$min,$sec,$offset,$year) = preg_split('/[\s\:]/',$date_string); } return gmmktime($hour,$min,$sec,$mnum[$mon],$mday,$year); } function tb_wrap_javascript($script_content) { return "\n\r".''."\n\r"; } function tb_get_server_rate_limit_json($tb_o) { $url = 'http://twitter.com/account/rate_limit_status.json'; $params = array('rand' => rand()); // check if it's a private source or if we are rerouting with oAuth if (isset($tb_o['advanced_reroute_on']) && $tb_o['advanced_reroute_on'] && $tb_o['advanced_reroute_type'] == 'oauth') { // check to make sure we have the class if (!class_exists('TwitterOAuth')) { return false; } // make sure we have oAuth info if (!isset($tb_o['oauth_access_token'])){ return false; } else { // try to get it directly $oAuth = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $tb_o['oauth_access_token']['oauth_token'],$tb_o['oauth_access_token']['oauth_token_secret']); $json_data = $oAuth->OAuthRequest($url, 'GET', $params); if ($oAuth->http_code == 200) { return $json_data; } else { return false; } } } // if not rerouting, access directly else { // for WP3 we need to explicitly include the class if (version_compare(get_bloginfo('version'),'3.0.0','>=')) { require_once ABSPATH . '/wp-includes/class-http.php'; } $http = new WP_Http; $result = $http->request($url); // if we could get it, return data if (is_array($result)) { if ($result['response']['code'] == 200) { $json_data = $result['body']; return $json_data; } else { return false; } } elseif (is_object($result)) { if ($result->response->code == 200) { $json_data = $result->body; return $json_data; } else { return false; } } else { return false; } } } function tb_get_cached_tweets_json($sources) { global $wp_json; $tweets = array(); $tweets = tb_get_cached_tweets($sources, 500); foreach ($tweets as $t){ $tweet = $wp_json->decode($t->tweet_json); $tweet['div_id'] = $t->div_id; $tweets[] = $tweet; } return $wp_json->encode($tweets); } function tb_save_cache($tweets) { global $wpdb, $wp_json; if (is_object($tweets)) { $tweets = (array)$tweets; } if (is_array($tweets)) { $table_name = $wpdb->prefix . "tweetblender"; $inserted_cache = false; // process each tweet foreach ($tweets as $div_id => $tweet) { $t = $tweet->t; $source = urldecode($tweet->s); // if there are commas then we have multiple keywords and/or hashtags if (strpos($source,',') > 0) { $tweet_sources = split(',',$source); } // else it's an array with just one element else { $tweet_sources = array($source); } // insert the tweet for each source foreach($tweet_sources as $src) { // TODO: make sure source is in the admin defined set // store the tweet only if it matches this particular keyword or hashtag or if this is for list/username if (strpos(strtolower($t->text),strtolower($src)) !== false || strpos($src, '@') === 0 || strtolower($src) == strtolower($t->from_user)) { $wpdb->query("INSERT IGNORE INTO $table_name (div_id,source,tweet_text,tweet_json) VALUES ('" . $wpdb->escape($div_id) . "','" . $wpdb->escape($src) . "','" . $wpdb->escape($t->text) . "','" . $wpdb->escape($wp_json->encode($t)) . "')" ); $inserted_cache = true; } } } return $inserted_cache; } else { return false; } } // creates HTML for the list of tweets using cached tweets function tb_get_cached_tweets_html($mode,$instance,$widget_id = '') { global $wp_json; // get options $tb_o = get_option('tweet-blender'); // figure out how many to get if ($mode == 'archive') { $tweets_to_show = $tb_o['archive_tweets_num']; // get data for all sources $sources = array(); } else { $tweets_to_show = $instance['widget_tweets_num']; // get data for this widget's sources only $sources = preg_split('/[\n\r]/m', trim($instance['widget_sources'])); } // get data from DB $tweets_html = ''; $tweets = tb_get_cached_tweets($sources, $tweets_to_show,$widget_id); foreach ($tweets as $t){ $tweet = $wp_json->decode($t->tweet_json); $tweet->{'div_id'} = $t->div_id; $tweets_html .= tb_tweet_html($tweet,$mode,$tb_o); } return $tweets_html; } function tb_get_cached_tweets($sources,$tweets_num,$widget_id = '') { global $wpdb; $table_name = $wpdb->prefix . "tweetblender"; // TODO: if widget_id contains "favorites" pull out only favorite tweets for the given sources $sources_sql = ""; if (sizeof($sources) > 0) { array_walk($sources,'tb_process_sources'); $sources_sql = "WHERE source IN ('" . join("','",$sources) . "')"; } // get data from DB return $wpdb->get_results("SELECT DISTINCT div_id, tweet_json FROM $table_name $sources_sql ORDER BY div_id DESC LIMIT $tweets_num"); } function tb_process_sources(&$src, $key) { global $TB_sourceNames; $src = trim($src); if(strpos($src,':') > 0 ) { list($src,$alias) = explode(':',$src); $source = substr($src,1); if (strpos($src,'|') > 0) { $parts = explode('|',$src); $source = substr($parts[0],1); } $TB_sourceNames[$source] = $alias; } } // creates all HTML for a tweet using current configuration function tb_tweet_html($tweet,$mode = 'widget',$tb_o) { // add screen name if from_user is given if (!isset($tweet->user)) { $user = new stdClass(); if (isset($tweet->from_user)) { $user->screen_name = $tweet->from_user; $tweet->user = $user; } else { $user->screen_name = ''; $tweet->user = $user; } } // see if there in alias for this screen name if (isset($tb_o['alt_source_names'])) { $TB_sourceNames = $tb_o['alt_source_names']; } if (isset($TB_sourceNames[strtolower($tweet->user->screen_name)])) { $tweet->user->alias = $TB_sourceNames[strtolower($tweet->user->screen_name)]; } else { $tweet->user->alias = null; } // image url if (!isset($tweet->user->profile_image_url) && isset($tweet->profile_image_url)) { $tweet->user->profile_image_url = $tweet->profile_image_url; } $patterns = array(); $replacements = array(); // link URLs if requested if ($tb_o['general_link_urls']) { $patterns[] = '/(https?:\/\/\S+)/'; $replacements[] = '$1'; } // link screen names if requested if ($tb_o['general_link_screen_names']) { $patterns[] = '/\@([\w]+)/'; $replacements[] = '@$1'; } // link hashtags if requested if ($tb_o['general_link_hash_tags']) { $patterns[] = '/\#(\S+)/'; $replacements[] = '#$1'; } if (sizeof($patterns) > 0) { $tweet->text = preg_replace($patterns,$replacements,$tweet->text); } // date $tweet_date = tb_str2time($tweet->created_at); if ($tb_o['general_timestamp_format']) { if(!version_compare(PHP_VERSION, '5.1.0', '<')) { date_default_timezone_set(get_option('timezone_string')); } $date_html = date($tb_o['general_timestamp_format'],$tweet_date); } else { $date_html = tb_verbal_time($tweet_date); } // if source is not url encoded -> use as is if (isset($tweet->source) && strpos($tweet->source,'<') === false) { $source_html = $tweet->source; } // else decode else { $source_html = html_entity_decode($tweet->source); } $tweet_template = ''; $tweet_template .= '