Example #1
0
 function widget($args, $instance)
 {
     global $post;
     if (sizeof($args) > 0) {
         extract($args, EXTR_SKIP);
     }
     $tb_o = get_option('tweet-blender');
     // find out id/url of the archive page
     $archive_post_id = tb_get_archive_post_id();
     $archive_page_url = trim($instance['widget_view_more_url']);
     if ($archive_page_url == '' && $archive_post_id > 0) {
         $archive_page_url = get_permalink($archive_post_id) . '?source=' . urlencode(preg_replace('/[\\n\\r]/m', ',', $instance['widget_sources']));
     }
     // don't show widget on the archive page
     if ($post == null || $post->ID != $archive_post_id && $archive_page_url != "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']) {
         if (isset($before_widget)) {
             echo $before_widget;
         }
         $title = empty($instance['title']) ? '' : apply_filters('widget_title', trim($instance['title']));
         if (!empty($title)) {
             echo $before_title . $title . $after_title;
         }
         $sources = preg_split('/[\\n\\r]/m', trim($instance['widget_sources']));
         // set "view more" text
         if (isset($instance['widget_view_more_text']) && $instance['widget_view_more_text'] != '') {
             $view_more_text = $instance['widget_view_more_text'];
         } else {
             $view_more_text = __("view more", 'tweetblender');
         }
         // add configuraiton options
         echo '<form id="' . $this->id . '-f" class="tb-widget-configuration" action="#"><div>';
         echo '<input type="hidden" name="sources" value="' . esc_attr(join(',', $sources)) . '" />';
         echo '<input type="hidden" name="refreshRate" value="' . $instance['widget_refresh_rate'] . '" />';
         echo '<input type="hidden" name="tweetsNum" value="' . $instance['widget_tweets_num'] . '" />';
         echo '<input type="hidden" name="viewMoreText" value="' . esc_attr($view_more_text) . '" />';
         echo '<input type="hidden" name="viewMoreUrl" value="' . $archive_page_url . '" />';
         echo '</div></form>';
         // print out header and list of tweets
         echo '<div id="' . $this->id . '-mc">';
         echo tb_create_markup($mode = 'widget', $instance, $this->id, $tb_o);
         echo '<div class="tb_footer">';
         if (!isset($tb_o['archive_is_disabled']) || $tb_o['archive_is_disabled'] == false) {
             // indicate that using default url
             $default = '';
             if (!$instance['widget_view_more_url']) {
                 $default = ' defaultUrl';
             }
             if ($archive_page_url != '') {
                 echo '<a class="tb_archivelink' . $default . '" href="' . $archive_page_url . '">' . $view_more_text . ' &raquo;</a>';
             } elseif ($archive_post_id > 0) {
                 echo '<a class="tb_archivelink' . $default . '" href="' . get_permalink($archive_post_id) . '">' . $view_more_text . ' &raquo;</a>';
             }
         }
         echo '</div>';
         echo '</div>';
         if (isset($after_widget)) {
             echo $after_widget;
         }
     }
 }
 function widget($args, $instance)
 {
     global $post, $json;
     if (sizeof($args) > 0) {
         extract($args, EXTR_SKIP);
     }
     $tb_o = get_option('tweet-blender');
     // find out id/url of the archive page
     $archive_post_id = tb_get_archive_post_id();
     $archive_page_url = $instance['widget_view_more_url'];
     if (!$archive_page_url && $archive_post_id > 0) {
         $archive_page_url = get_permalink($archive_post_id);
     }
     // don't show widget on the archive page
     if ($post == null || $post->ID != $archive_post_id && $archive_page_url != "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']) {
         echo $before_widget;
         $instance['title'] = trim($instance['title']);
         $title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
         if (!empty($title)) {
             echo $before_title . $title . $after_title;
         }
         $sources = preg_split('/[\\s+\\n\\r]/m', trim($instance['widget_sources']));
         $private_sources = array();
         if ($instance['widget_private_sources'] != '') {
             $private_sources = split(',', $instance['widget_private_sources']);
         }
         // remove private from general sources to avoid duplicates
         $sources = array_diff($sources, $private_sources);
         // mark private sources as private by prepending ! sign
         array_walk($private_sources, create_function('&$v,$k', 'if($v != "") { $v = "!".$v; }'));
         // add configuraiton options
         echo '<form id="' . $this->id . '-f" class="tb-widget-configuration" action="#"><div>';
         echo '<input type="hidden" name="sources" value="' . join(',', array_merge($sources, $private_sources)) . '" />';
         echo '<input type="hidden" name="refreshRate" value="' . $instance['widget_refresh_rate'] . '" />';
         echo '<input type="hidden" name="tweetsNum" value="' . $instance['widget_tweets_num'] . '" />';
         echo '<input type="hidden" name="viewMoreUrl" value="' . $archive_page_url . '" />';
         echo '<input type="hidden" name="favoritesOnly" value="true" />';
         echo '</div></form>';
         // print out header and list of tweets
         echo '<div id="' . $this->id . '-mc">';
         echo tb_create_markup($mode = 'widget', $instance, $this->id, $tb_o);
         echo '<div class="tb_footer">';
         if (!$tb_o['archive_is_disabled']) {
             // indicate that using default url
             $default = '';
             if (!$instance['widget_view_more_url']) {
                 $default = ' defaultUrl';
             }
             if ($archive_page_url != '') {
                 echo '<a class="tb_archivelink' . $default . '" href="' . $archive_page_url . '">view more &raquo;</a>';
             } elseif ($archive_post_id > 0) {
                 echo '<a class="tb_archivelink' . $default . '" href="' . get_permalink($archive_post_id) . '">view more &raquo;</a>';
             }
         }
         echo '</div>';
         echo '</div>';
         echo $after_widget;
     }
 }
	function widget($args, $instance) {

		global $post;
				
		// don't show widget if we are not on a post page
		if ($post == null || $post->post_type != 'post') {
			echo '<!-- ' . __('Tweet Blender: Not shown as this is not a post', 'tweetblender') . ' -->';
			return;
		}

		// check custom tb_tags field
		$sources = array();
		$custom_fields = get_post_custom($post->ID);
 		$post_tags = get_the_tags($post->ID);
		if (isset($custom_fields['tb_tags'])) {
			foreach($custom_fields['tb_tags'] as $key => $tags) {
				$sources = array_merge($sources,explode(',',$tags));
			}			
		}
		// check general post tags
		elseif (isset($post_tags) && is_array($post_tags) && sizeof($post_tags) > 0) {
			foreach($post_tags as $tag) {
				$sources[] = trim($tag->name);			
			}
		}
		// don't show widget if there are no tags
		else {
			echo '<!-- ' . __('Tweet Blender: Not shown as there are no tags for this post', 'tweetblender') . ' -->';
			return;
		}

		if (sizeof($args) > 0) {
			extract($args, EXTR_SKIP);			
		}
		$tb_o = get_option('tweet-blender');
		
		echo $before_widget;
		$title = empty($instance['title']) ? '&nbsp;' : apply_filters('widget_title', $instance['title']);
		if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };

		$instance['widget_sources'] = join('\n\r',$sources);
			
		// add configuraiton options
		echo '<form id="' . $this->id . '-f" class="tb-widget-configuration">';
		echo '<input type="hidden" name="sources" value="' . addslashes(join(',',$sources)) . '">';
		echo '<input type="hidden" name="refreshRate" value="' . $instance['widget_refresh_rate'] . '">';
		echo '<input type="hidden" name="tweetsNum" value="' . $instance['widget_tweets_num'] . '">';
		echo '</form>';
			
		// print out header and list of tweets
		echo '<div id="'. $this->id . '-mc">';
		echo tb_create_markup($mode = 'widget',$instance,$this->id,$tb_o);

		// print out footer
		echo '<div class="tb_footer"></div>';

		echo '</div>';
		echo $after_widget;
	}
Example #4
0
 function widget($args, $instance)
 {
     global $post, $json;
     // don't show widget if we are not on a post page
     if ($post == null || $post->post_type != 'post') {
         echo '<!-- Tweet Blender: Not shown as this is not a post -->';
         return;
     }
     // don't show widget if there are no tags
     $sources = array();
     $post_tags = get_the_tags($post->ID);
     if (is_object($post_tags) || sizeof($post_tags) == 0) {
         echo '<!-- Tweet Blender: Not shown as there are no tags for this post -->';
         return;
     }
     if (sizeof($args) > 0) {
         extract($args, EXTR_SKIP);
     }
     $tb_o = get_option('tweet-blender');
     echo $before_widget;
     $title = empty($instance['title']) ? '&nbsp;' : apply_filters('widget_title', $instance['title']);
     if (!empty($title)) {
         echo $before_title . $title . $after_title;
     }
     foreach ($post_tags as $tag) {
         $src = trim($tag->name);
         // skip tags with spaces in them
         if (strpos($src, ' ') === false) {
             $sources[] = $src;
         }
     }
     $instance['widget_sources'] = join('\\n\\r', $sources);
     // add configuraiton options
     echo '<form id="' . $this->id . '-f" class="tb-widget-configuration">';
     echo '<input type="hidden" name="sources" value="' . addslashes(join(',', $sources)) . '">';
     echo '<input type="hidden" name="refreshRate" value="' . $instance['widget_refresh_rate'] . '">';
     echo '<input type="hidden" name="tweetsNum" value="' . $instance['widget_tweets_num'] . '">';
     echo '</form>';
     // print out header and list of tweets
     echo '<div id="' . $this->id . '-mc">';
     echo tb_create_markup($mode = 'widget', $instance, $this->id, $tb_o);
     // print out footer
     echo '<div class="tb_footer"></div>';
     echo '</div>';
     echo $after_widget;
 }