function tb_make_archive_html($tb_o) { $sources = array(); // by default we get tweets for all sources $archive_html = ''; if (isset($tb_o['archive_show_source_selector']) && $tb_o['archive_show_source_selector'] || isset($_GET['source'])) { if (isset($_GET['source'])) { if (is_array($_GET['source'])) { $sources = $_GET['source']; } else { $sources = array_values(array_filter(preg_split('/,/m', trim($_GET['source'])))); } } $archive_html .= '<form id="tb-source-selector">' . __('Show tweets for', 'tweetblender'); $cached_sources = tb_get_cache_stats(); foreach ((array) $cached_sources as $cache_src) { $archive_html .= '<input type="checkbox" class="tb-source" name="source[]" value="' . esc_attr($cache_src->source) . '"'; if (in_array($cache_src->source, $sources) || sizeof($sources) == 0) { $archive_html .= ' checked'; } $archive_html .= '/> '; $archive_html .= urldecode($cache_src->source); } $archive_html .= '<br /><input id="tb-update-sources" type="submit" value="Update" />'; $archive_html .= '</form>'; } $archive_html .= '<div id="tweetblender-archive">'; $archive_html .= tb_get_cached_tweets_html('archive', null, null, $sources); $archive_html .= '</div>'; // JavaScript code for mouseovers $archive_html .= tb_wrap_javascript("jQuery('document').ready(function(){\n\t\tTB_mode = 'archive';\n\t\tjQuery.each(jQuery('#tweetblender-archive').children('div'),function(i,obj){ TB_wireMouseOver(obj.id); });\n\t});"); return $archive_html; }
function tb_add_archive_page_content($content = '') { global $post; // do nothing if archive page is disabled $tb_o = get_option('tweet-blender'); if ($tb_o['archive_is_disabled']) { return $content; } else { // work with pages only, ignore blog posts if ($post->post_type != 'page') { return $content; } // if looking at archive page, apend list of tweets to content if ($post->ID == tb_get_archive_post_id()) { $archive_html = '<div id="tweetblender-archive">'; $archive_html .= tb_get_cached_tweets_html('archive', null); $archive_html .= '</div>'; // JavaScript code for mouseovers $archive_html .= tb_wrap_javascript("\n\t\t\t\tTB_mode = 'archive';\n\t\t\t\tjQuery.each(jQuery('#tweetblender-archive').children('div'),function(i,obj){ TB_wireMouseOver(obj.id); });\n\t\t\t"); return $content . $archive_html; } else { return $content; } } }
function form($instance) { global $tb_refresh_periods; $default = array('title' => __('Favorite Tweets', 'tweetblender'), 'widget_refresh_rate' => 0, 'widget_tweets_num' => 4, 'widget_sources' => ''); $instance = wp_parse_args((array) $instance, $default); // report errors if any if (isset($this->error)) { echo tb_wrap_javascript("function tAuth(url) {var tWin = window.open(url,'tWin','width=800,height=410,toolbar=0,location=1,status=0,menubar=0,resizable=1');}"); echo '<div class="error">' . $this->error . '</div>'; $instance = $this->bad_input; } // report messages if an if (isset($this->message)) { echo '<div class="updated">' . $this->message . '</div>'; } // title $field_id = $this->get_field_id('title'); $field_name = $this->get_field_name('title'); echo "\r\n" . '<p><label for="' . $field_id . '">' . __('Title', 'tweetblender') . ': <input type="text" class="widefat" id="' . $field_id . '" name="' . $field_name . '" value="' . esc_attr($instance['title']) . '" /></label></p>'; // sources $field_id = $this->get_field_id('widget_sources'); $field_name = $this->get_field_name('widget_sources'); echo "\r\n" . '<p><label for="' . $field_id . '">' . __('Sources (one per line)', 'tweetblender') . ': <textarea class="widefat" id="' . $field_id . '" name="' . $field_name . '" rows=4 cols=20 wrap="hard">' . esc_attr($instance['widget_sources']) . '</textarea></label></p>'; // specify refresh $field_id = $this->get_field_id('widget_refresh_rate'); $field_name = $this->get_field_name('widget_refresh_rate'); echo "\r\n" . '<label for="' . $field_id . '">' . __('Refresh', 'tweetblender') . '</label>'; echo "\r\n" . '<select id="' . $field_id . '" name="' . $field_name . '">'; foreach ($tb_refresh_periods as $name => $sec) { echo "\r\n" . '<option value="' . $sec . '"'; if ($sec == $instance['widget_refresh_rate']) { echo ' selected'; } echo '>' . $name . '</option>'; } echo "\r\n" . '</select><br>'; // specify number of tweets $field_id = $this->get_field_id('widget_tweets_num'); $field_name = $this->get_field_name('widget_tweets_num'); echo "\r\n" . '<br/><label for="' . $field_id . '">' . __('Show', 'tweetblender') . ' <select id="' . $field_id . '" name="' . $field_name . '">'; for ($i = 1; $i <= 15; $i++) { echo "\r\n" . '<option value="' . $i . '"'; if ($i == $instance['widget_tweets_num']) { echo ' selected'; } echo '>' . $i . '</option>'; } for ($i = 20; $i <= 100; $i += 10) { echo "\r\n" . '<option value="' . $i . '"'; if ($i == $instance['widget_tweets_num']) { echo ' selected'; } echo '>' . $i . '</option>'; } echo "\r\n" . '</select>' . __('tweets', 'tweetblender') . '</label><br>'; // specify text for "view more" link $field_id = $this->get_field_id('widget_view_more_text'); $field_name = $this->get_field_name('widget_view_more_text'); if (!isset($instance['widget_view_more_text'])) { $instance['widget_view_more_text'] = ''; } echo "\r\n" . '<br/><label for="' . $field_id . '">' . sprintf(__('Text for %s link', 'tweetblender'), '"' . __('view more', 'tweetblender') . '"') . ':</label>'; echo "\r\n" . '<input class="widefat" type="text" id="' . $field_id . '" name="' . $field_name . '" value="' . esc_attr($instance['widget_view_more_text']) . '">'; // specify URL for "view more" link $field_id = $this->get_field_id('widget_view_more_url'); $field_name = $this->get_field_name('widget_view_more_url'); if (!isset($instance['widget_view_more_url'])) { $instance['widget_view_more_url'] = ''; } echo "\r\n" . '<br/><label for="' . $field_id . '">' . sprintf(__('URL for %s link', 'tweetblender'), '"' . __('view more', 'tweetblender') . '"') . ':</label>'; echo "\r\n" . '<input class="widefat" type="text" id="' . $field_id . '" name="' . $field_name . '" value="' . esc_attr($instance['widget_view_more_url']) . '"><br/>'; if ($archive_post = tb_get_archive_post_id()) { echo '<span style="color:#777;font-style:italic;">' . __('Leave blank to use ', 'tweetblender') . '<a href="page.php?action=edit&post=' . $archive_post . '" target="_blank">' . __('existing page', 'tweetblender') . '</a></span>'; } }
function tb_get_cached_tweets_html($mode, $instance, $widget_id = '', $sources = array()) { global $wp_json; // get options $tb_o = get_option('tweet-blender'); // if no explicit sources requisted, get the ones configured for the widget if (sizeof($sources) == 0) { $sources = array_values(array_filter(preg_split('/[\\n\\r]/m', trim($instance['widget_sources'])))); } $tweets_html = ''; if ($mode == 'chart') { // get data from DB $chart_data = tb_get_chart_data($sources, $instance['widget_chart_period'], $instance['widget_chart_type']); $tweets_html .= tb_wrap_javascript('TB_chartsData["' . $widget_id . '"] = eval(\'(' . $wp_json->encode($chart_data) . ')\');'); } else { // figure out how many to get if ($mode == 'archive') { $tweets_to_show = $tb_o['archive_tweets_num']; } else { $tweets_to_show = $instance['widget_tweets_num']; } // get data from DB $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; }