From 1bb7edfd041c5af916f9135d7797b4ce43bdeaef Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 1 Dec 2009 07:11:06 -0500 Subject: [PATCH] start work on converting social widget --- test/widgets/SocialWidgetTest.php | 23 +++++++++ widgets/SocialWidget.inc | 85 +++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 test/widgets/SocialWidgetTest.php create mode 100644 widgets/SocialWidget.inc diff --git a/test/widgets/SocialWidgetTest.php b/test/widgets/SocialWidgetTest.php new file mode 100644 index 0000000..824c395 --- /dev/null +++ b/test/widgets/SocialWidgetTest.php @@ -0,0 +1,23 @@ +w = new SocialWidget(); + } + + function testUpdate() { + $this->assertEquals(array( + 'title' => 'title', + 'urlstr' => 'urlstr', + 'image' => 'image', + ), $this->w->update(array( + 'title' => 'title', + 'urlstr' => 'urlstr', + 'image' => 'image', + ), array())); + } +} \ No newline at end of file diff --git a/widgets/SocialWidget.inc b/widgets/SocialWidget.inc new file mode 100644 index 0000000..c9addf1 --- /dev/null +++ b/widgets/SocialWidget.inc @@ -0,0 +1,85 @@ + 'SocialWidget', 'description' => __('Display a user defined social button, with translated URL','comicpress') ); + $this->WP_Widget('social', __('ComicPress Social','comicpress'), $widget_ops); + } + + function widget($args, $instance) { + global $post; + extract($args, EXTR_SKIP); + + /* Get the info necessary */ + $permalink = get_permalink($post->ID); + $posttitle = $post->post_title; + $posttitle = str_replace(' ', '%20', $posttitle); + $title = $instance['title']; + if (empty($title)) $title = $posttitle; + + $rss = get_bloginfo('rss2_url'); + $blogname = urlencode(get_bloginfo('name')." ".get_bloginfo('description')); + // Grab the excerpt, if there is no excerpt, create one + $excerpt = urlencode(strip_tags(strip_shortcodes($post->post_excerpt))); + if ($excerpt == "") { + $excerpt = urlencode(substr(strip_tags(strip_shortcodes($post->post_content)),0,250)); + } + // Clean the excerpt for use with links + $excerpt = str_replace('+','%20',$excerpt); + + echo $before_widget; + $url = $instance['urlstr']; + $url = str_replace('[URL]', $permalink, $url); + $url = str_replace('[TITLE]', $posttitle, $url); + $url = str_replace('[RSS]', $rss, $url); + $url = str_replace('[BLOGNAME]', $blogname, $url); + $url = str_replace('[EXCERPT]', $excerpt, $url); ?> + +
+ + + + + +
+ 'Share This!', 'urlstr' => '', 'image' => '') ); + $title = strip_tags($instance['title']); + if (empty($title)) $title = 'Share This!'; + $urlstr = strip_tags($instance['urlstr']); + $image = strip_tags($instance['image']); + ?> + + Translated Strings: [URL] [TITLE] [RSS] [BLOGNAME] [EXCERPT]
+ Examples:
+ http://twitter.com/home?status=[TITLE]%20-%20[URL]
+ http://www.stumbleupon.com/submit?url=[URL]&title=[TITLE]
+
+
+

+

+

+