Adds a widget to twitter which can serve an RSS feed from Twitter in a privacy friendly and still good-locking way
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

better-twitter-widget.php 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. <?php
  2. /*
  3. Plugin Name: Better Twitter Widget
  4. Plugin URI: http://mehl.mx
  5. Description: RSS Widget optimised for Twitter RSS feeds. Enhancement of GrandSlambert's Better RSS Widget
  6. Author: Max Mehl
  7. Version: 1.0
  8. Author URI: http://mehl.mx
  9. * *************************************************************************
  10. Copyright (C) 2016 Max Mehl
  11. This program is free software: you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation, either version 3 of the License, or
  14. (at your option) any later version.
  15. This program is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. GNU General Public License for more details.
  19. You should have received a copy of the GNU General Public License
  20. along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. * *************************************************************************
  22. */
  23. /* Class Declaration */
  24. class better_twitter_widget extends WP_Widget {
  25. var $version = '2.7.1';
  26. /* Plugin settings */
  27. var $optionsName = 'better-twitter-widget-options';
  28. var $menuName = 'better-twitter-widget-settings';
  29. var $pluginName = 'Better Twitter Widget';
  30. var $options = array();
  31. var $make_link = false;
  32. /**
  33. * Plugin Constructor Method
  34. */
  35. function better_twitter_widget() {
  36. add_action('init', array($this, 'init'));
  37. /* Set the plugin name to use the selected language. */
  38. $this->pluginName = __('Better Twitter Widget', 'better-twitter-widget');
  39. $widget_ops = array('description' => __('Enhancement of Better RSS Widget, focussed on plain Twitter feeds', 'better-twitter-widget'));
  40. $control_ops = array('width' => 500, 'height' => 350);
  41. parent::WP_Widget(false, $this->pluginName, $widget_ops, $control_ops);
  42. /* Plugin paths */
  43. $this->pluginPath = WP_PLUGIN_DIR . '/' . basename(dirname(__FILE__));
  44. $this->pluginURL = WP_PLUGIN_URL . '/' . basename(dirname(__FILE__));
  45. /* Load the plugin settings */
  46. $this->load_settings();
  47. /* WordPress Actions */
  48. add_action('admin_menu', array(&$this, 'admin_menu'));
  49. add_action('admin_init', array(&$this, 'admin_init'));
  50. add_action('update_option_' . $this->optionsName, array(&$this, 'update_option'), 10);
  51. /* WordPress FIlters */
  52. add_filter('plugin_action_links', array(&$this, 'plugin_action_links'), 10, 2);
  53. /* Add shortcode_handlers */
  54. add_shortcode('better-rss', array($this, 'shortcode_handler'));
  55. }
  56. /**
  57. * Load the plugin settings.
  58. */
  59. function load_settings() {
  60. $options = get_option($this->optionsName);
  61. $defaults = array(
  62. 'link_target' => '_blank',
  63. 'allow_intro' => (is_array($options)) ? isset($options['allow_intro']) : true,
  64. 'show_summary' => true,
  65. 'show_author' => false,
  66. 'show_date' => true,
  67. 'show_time' => false,
  68. 'nofollow' => true,
  69. 'enable_cache' => (is_array($options)) ? isset($options['enable_cache']) : true,
  70. 'cache_duration' => 3600,
  71. 'items' => 5,
  72. 'title_length' => (is_array($options) && !empty($options['title_length'])) ? isset($options['title_length']) : 0,
  73. 'excerpt' => 360,
  74. 'suffix' => ' [...]'
  75. );
  76. $this->options = (object) wp_parse_args($options, $defaults);
  77. }
  78. /**
  79. * Load the language file during WordPress init.
  80. */
  81. function init() {
  82. /* Load Langague Files */
  83. $langDir = dirname(plugin_basename(__FILE__)) . '/lang';
  84. load_plugin_textdomain('better-twitter-widget', false, $langDir, $langDir);
  85. }
  86. /**
  87. * Add the admin page for the settings panel.
  88. *
  89. * @global string $wp_version
  90. */
  91. function admin_menu() {
  92. $page = add_options_page($this->pluginName . __(' Settings', 'better-twitter-widget'), $this->pluginName, 'manage_options', $this->menuName, array(&$this, 'options_panel'));
  93. add_action('admin_print_styles-' . $page, array(&$this, 'admin_print_styles'));
  94. add_action('admin_print_scripts-' . $page, array(&$this, 'admin_print_scripts'));
  95. }
  96. /**
  97. * Register the options for Wordpress MU Support
  98. */
  99. function admin_init() {
  100. register_setting($this->optionsName, $this->optionsName);
  101. wp_register_style('better-twitter-widget-admin-css', $this->pluginURL . '/includes/better-twitter-widget-admin.css');
  102. wp_register_script('better-twitter-widget-js', $this->pluginURL . '/js/better-twitter-widget.js');
  103. }
  104. /**
  105. * Print the administration styles.
  106. */
  107. function admin_print_styles() {
  108. wp_enqueue_style('better-twitter-widget-admin-css');
  109. }
  110. /**
  111. * Print the scripts needed for the admin.
  112. */
  113. function admin_print_scripts() {
  114. wp_enqueue_script('better-twitter-widget-js');
  115. }
  116. /**
  117. * Add a configuration link to the plugins list.
  118. *
  119. * @staticvar object $this_plugin
  120. * @param array $links
  121. * @param array $file
  122. * @return array
  123. */
  124. function plugin_action_links($links, $file) {
  125. static $this_plugin;
  126. if (!$this_plugin) {
  127. $this_plugin = plugin_basename(__FILE__);
  128. }
  129. if ($file == $this_plugin) {
  130. $settings_link = '<a href="' . admin_url('options-general.php?page=' . $this->menuName) . '">' . __('Settings', 'better-twitter-widget') . '</a>';
  131. array_unshift($links, $settings_link);
  132. }
  133. return $links;
  134. }
  135. /**
  136. * Check on update option to see if we need to reset the options.
  137. * @param <array> $input
  138. * @return <boolean>
  139. */
  140. function update_option($input) {
  141. if ($_REQUEST['confirm-reset-options']) {
  142. delete_option($this->optionsName);
  143. wp_redirect(admin_url('options-general.php?page=' . $this->menuName . '&tab=' . $_POST['active_tab'] . '&reset=true'));
  144. exit();
  145. } else {
  146. wp_redirect(admin_url('options-general.php?page=' . $this->menuName . '&tab=' . $_POST['active_tab'] . '&updated=true'));
  147. exit();
  148. }
  149. }
  150. /**
  151. * Settings management panel.
  152. */
  153. function options_panel() {
  154. include($this->pluginPath . '/includes/settings.php');
  155. }
  156. /**
  157. * Method to create the widget.
  158. *
  159. * @param array $args
  160. * @param array $instance
  161. * @return false
  162. */
  163. function widget($args, $instance) {
  164. $instance = $this->defaults($instance);
  165. if (isset($instance['error']) && $instance['error'])
  166. return;
  167. extract($args, EXTR_SKIP);
  168. $url = $instance['rss_url'];
  169. while (stristr($url, 'http') != $url)
  170. $url = substr($url, 1);
  171. if (empty($url)) {
  172. return;
  173. }
  174. $rss = fetch_feed($url);
  175. $desc = '';
  176. $link = '';
  177. if (!is_wp_error($rss)) {
  178. $desc = esc_attr(strip_tags(@html_entity_decode($rss->get_description(), ENT_QUOTES, get_option('blog_charset'))));
  179. if (empty($instance['title'])) {
  180. $instance['title'] = esc_html(strip_tags($rss->get_title()));
  181. }
  182. $link = esc_url(strip_tags($rss->get_permalink()));
  183. while (stristr($link, 'http') != $link) {
  184. $link = substr($link, 1);
  185. }
  186. }
  187. if (empty($instance['title'])) {
  188. $instance['title'] = empty($desc) ? __('Unknown Feed', 'better-twitter-widget') : $desc;
  189. }
  190. $instance['title'] = apply_filters('widget_title', $instance['title']);
  191. $url = esc_url(strip_tags($url));
  192. $icon = includes_url('images/rss.png');
  193. if ($instance['title_url']) {
  194. $url = $link = $instance['title_url'];
  195. }
  196. $target = '';
  197. if ($instance['link_target'] != 'none') {
  198. $target = 'target="' . $instance['link_target'] . '"';
  199. }
  200. if ($instance['title']) {
  201. if (!$instance['no_link_title']) {
  202. $instance['title'] = '<a class="rsswidget" href="' . $link . '" title="' . $desc . '" ' . $target . '>' . $instance['title'] . '</a>';
  203. }
  204. if ($instance['show_icon']) {
  205. $instance['title'] = "<a class='rsswidget' href='" . $instance[$instance['link_icon']] . "' title='" . esc_attr(__('Syndicate this content', 'better-twitter-widget')) . "' . $target . '><img style='background:orange;color:white;border:none;' width='14' height='14' src='$icon' alt='RSS' /></a> " . $instance['title'];
  206. }
  207. }
  208. print $before_widget;
  209. if ($instance['title']) {
  210. print $before_title . $instance['title'] . $after_title;
  211. }
  212. if (true == $this->options->allow_intro && !empty($instance['intro_text'])) {
  213. print '<div class="better-rss-intro-text">' . $instance['intro_text'] . '</div>';
  214. }
  215. $this->rss_output($rss, $instance);
  216. print $after_widget;
  217. }
  218. /**
  219. * Method to output the RSS for the widget and shortcode_handler
  220. *
  221. * @param string $rss
  222. * @param array $args
  223. * @return blank
  224. */
  225. function rss_output($rss, $args = array()) {
  226. if (is_string($rss)) {
  227. $rss = fetch_feed($rss);
  228. } elseif (is_array($rss) && isset($rss['url'])) {
  229. $args = $rss;
  230. $rss = fetch_feed($rss['url']);
  231. } elseif (!is_object($rss)) {
  232. return;
  233. }
  234. if (is_wp_error($rss)) {
  235. if (is_admin() || current_user_can('manage_options')) {
  236. print '<p>' . sprintf(__('<strong>RSS Error</strong>: %s', 'better-twitter-widget'), $rss->get_error_message()) . '</p>';
  237. }
  238. return;
  239. }
  240. $args = wp_parse_args($args, $this->defaults_args());
  241. extract($args, EXTR_SKIP);
  242. $items = (int) $items;
  243. if ($items < 1 || 20 < $items) {
  244. $items = 10;
  245. }
  246. $show_summary = (int) $show_summary;
  247. $show_author = (int) $show_author;
  248. $show_date = (int) $show_date;
  249. // Set the cache duration
  250. $rss->enable_cache($enable_cache);
  251. $rss->set_cache_duration($cache_duration);
  252. $rss->init();
  253. if (!$rss->get_item_quantity()) {
  254. print '<ul><li>' . __('An error has occurred; the feed is probably down. Try again later.', 'better-twitter-widget') . '</li></ul>';
  255. return;
  256. }
  257. if (strtolower($link_target) != 'none') {
  258. $target = 'target="' . $link_target . '"';
  259. } else {
  260. $target = '';
  261. }
  262. print '<' . $args['html_parent'] . '>';
  263. foreach ($rss->get_items(0, $items) as $item) {
  264. $link = $item->get_link();
  265. while (stristr($link, 'http') != $link) {
  266. $link = substr($link, 1);
  267. }
  268. $link = esc_url(strip_tags($link));
  269. $title = esc_attr(strip_tags($item->get_title()));
  270. if (empty($title)) {
  271. $title = __('Untitled', 'better-twitter-widget');
  272. }
  273. $desc = str_replace(array("\n", "\r"), ' ', esc_attr(strip_tags(@html_entity_decode($item->get_description(), ENT_QUOTES, get_option('blog_charset')))));
  274. // BUG -- CUSTOM comment out
  275. /*if (!$hide_title) {
  276. $desc = wp_html_excerpt($desc, $excerpt) . $this->options->suffix;
  277. $desc = esc_html($desc);
  278. }*/
  279. $desc = esc_html($desc);
  280. if ($show_summary) {
  281. $summary = "<div class='rssSummary'>$desc</div>";
  282. } else {
  283. $summary = '';
  284. }
  285. $date = '';
  286. if ($show_date) {
  287. $date = $item->get_date();
  288. if ($date) {
  289. if ($date_stamp = strtotime($date))
  290. $date = ' <span class="rss-date">' . date_i18n(get_option('date_format'), $date_stamp) . '</span>';
  291. else
  292. $date = '';
  293. }
  294. }
  295. $time = '';
  296. if ($show_time) {
  297. $time = $item->get_date();
  298. if ($time) {
  299. if ($date_stamp = strtotime($time)) {
  300. $time = ' <span class="rss-date">' . date_i18n(get_option('time_format'), $date_stamp) . '</span>';
  301. } else {
  302. $time = '';
  303. }
  304. }
  305. }
  306. $author = '';
  307. if ($show_author) {
  308. $author = $item->get_author();
  309. if (is_object($author)) {
  310. $author = $author->get_name();
  311. $author = ' <cite>' . esc_html(strip_tags($author)) . '</cite>';
  312. }
  313. }
  314. if ($hide_title && $item->get_description()) {
  315. $title = $item->get_description();
  316. }
  317. if (true == $args['limit_title_length'] && $args['title_length'] > 0) {
  318. $title = substr($title, 0, $args['title_length']);
  319. }
  320. if ($args['html_parent'] === 'dl') {
  321. $html_open = '<dt>';
  322. $html_after_title = '</dt>';
  323. $html_before_details = '<dd>';
  324. $html_close = '</dd>';
  325. } else {
  326. $html_open = '<' . $args['html_item'] . '>';
  327. $html_after_title = '';
  328. $html_before_details = '';
  329. $html_close = '</' . $args['html_item'] . '>';
  330. }
  331. if ($link == '' or $hide_link) {
  332. print $html_open . $title . $html_after_title;
  333. print $html_before_details . $date . $summary . $author . $html_close;
  334. } else {
  335. /* ORIG
  336. print $html_open . '<a ';
  337. if ($nofollow) {
  338. print ' rel="nofollow" ';
  339. }
  340. print 'class="rsswidget" href="' . $link . '" title="' . $desc . '"' . $target . '>' . $title . '</a>' . $html_after_title;
  341. //print $html_before_details . $date . $time . $summary . $author . $html_close;
  342. print $html_close;
  343. ======================= */
  344. $search = array();
  345. $search[0] = '/([\s>\-\.])#([[:alnum:]öäü]+)/i'; // text #hash text; >#hash text
  346. $search[1] = '/([\s>\-\.])@([[:alnum:]_]+)/'; // @user
  347. $search[2] = '/([\s>\-\.])(https?:[\/[:alnum:]\.\?\&#\=\%\+\-\_]+)/'; // http...
  348. $replace = array();
  349. $replace[0] = '$1<a target="_blank" href="http://twitter.com/search?q=%23$2">#$2</a>';
  350. $replace[1] = '$1<a target="_blank" href="http://twitter.com/$2">@$2</a>';
  351. $replace[2] = '$1<a target="_blank" href="$2">$2</a>';
  352. $extsummary = preg_replace($search, $replace, $summary);
  353. // get tweet ID
  354. $tid = preg_match('/(\d)+$/', $link, $match);
  355. $tid = $match[0];
  356. // li + text
  357. print $html_open . $extsummary ;
  358. print '<span style="opacity: 0.7;font-size: 0.9em;">' . $date . '</span>';
  359. // Action bar
  360. print '<span style="float:right;padding-right:20px;">';
  361. // reply icon
  362. print '<a rel="nofollow" title="Reply to this tweet" target="_blank" href="https://twitter.com/intent/tweet?in_reply_to=' . $tid . '" style="border:none;padding:0 5px;"><img src="' . plugins_url( 'img/reply.png', __FILE__ ) . '" style="height:15px;width:15px;opacity:0.5;"/></a>';
  363. // retweet icon
  364. print '<a rel="nofollow" title="Retweet this tweet" target="_blank" href="https://twitter.com/intent/retweet?tweet_id=' . $tid . '" style="border:none;padding:0 5px;"><img src="' . plugins_url( 'img/retweet.png', __FILE__ ) . '" style="height:15px;width:15px;opacity:0.5;"/></a>';
  365. // like icon
  366. print '<a rel="nofollow" title="Like this tweet" target="_blank" href="https://twitter.com/intent/favorite?tweet_id=' . $tid . '" style="border:none;padding:0 5px;"><img src="' . plugins_url( 'img/like.png', __FILE__ ) . '" style="height:15px;width:15px;opacity:0.5;"/></a>';
  367. // view on twitter icon
  368. print '<a rel="nofollow" title="View this tweet on Twitter" target="_blank" href="' . $link . '" style="border:none;padding:0 5px;"><img src="' . plugins_url( 'img/view.png', __FILE__ ) . '" style="height:15px;width:15px;opacity:0.5;"/></a>';
  369. print '</span>'; // close action bar
  370. // close li
  371. print $html_close;
  372. }
  373. }
  374. print '</' . $args['html_parent'] . '>';
  375. }
  376. /**
  377. * Widget Update method
  378. * @param array $new_instance
  379. * @param array $old_instance
  380. * @return array
  381. */
  382. function update($new_instance, $old_instance) {
  383. return $new_instance;
  384. }
  385. /**
  386. * Load the instance defaults.
  387. *
  388. * @param array $instance
  389. * @return array
  390. */
  391. function defaults($instance) {
  392. /* Fix any old instances to use new naming convention. */
  393. if (isset($instance['url'])) {
  394. $instance['rss-url'] = $instance['url'];
  395. $instance['title_url'] = $instance['titleurl'];
  396. $instance['show_icon'] = $instance['showicon'];
  397. $instance['show_summary'] = $instance['showsummary'];
  398. $instance['show_author'] = $instance['showauthor'];
  399. $instance['show_date'] = $instance['showdate'];
  400. $instance['show_time'] = $instance['showtime'];
  401. $instance['link_target'] = $instance['linktarget'];
  402. $instance['title_legnth'] = (isset($instance['title_length']) ? $instance['title_length'] : $this->options->title_length);
  403. }
  404. /* This is the new naming convention for the form fields */
  405. $new_defaults = array(
  406. 'rss_url' => '',
  407. 'title' => '',
  408. 'title_url' => '',
  409. 'no_link_title' => false,
  410. 'show_icon' => false,
  411. 'link_icon' => 'rss_url',
  412. 'show_summary' => $this->options->show_summary,
  413. 'show_author' => $this->options->show_author,
  414. 'show_date' => $this->options->show_date,
  415. 'show_time' => $this->options->show_time,
  416. 'link_target' => $this->options->link_target,
  417. 'nofollow' => $this->options->nofollow,
  418. 'enable_cache' => $this->options->enable_cache,
  419. 'cache_duration' => $this->options->cache_duration,
  420. 'is_home' => $this->options->is_home_default,
  421. 'is_front' => $this->options->is_front_default,
  422. 'is_archive' => $this->options->is_archive_default,
  423. 'is_search' => $this->options->is_search_default,
  424. 'is_category' => $this->options->is_category_default,
  425. 'is_tag' => $this->options->is_tag_default,
  426. 'is_single' => $this->options->is_single_default,
  427. 'is_date' => $this->options->is_date_default,
  428. 'title_length' => $this->options->title_length,
  429. 'excerpt' => $this->options->excerpt,
  430. 'items' => $this->options->items
  431. );
  432. return wp_parse_args($instance, $new_defaults);
  433. }
  434. /**
  435. * Widget form.
  436. *
  437. * @param array $instance
  438. */
  439. function form($instance) {
  440. if (count($instance) < 1) {
  441. $instance = $this->defaults($instance);
  442. }
  443. include( $this->pluginPath . '/includes/widget-form.php');
  444. }
  445. /**
  446. * Method for the [better-rss] short code.
  447. *
  448. * @param array $atts
  449. * @return string
  450. */
  451. function shortcode_handler($atts) {
  452. global $post;
  453. $atts = (object) wp_parse_args($atts, $this->defaults_args());
  454. if (!$atts->feed) {
  455. return false;
  456. }
  457. if ($atts->use_title) {
  458. $add_url[] = str_replace(' ', '+', $post->post_title);
  459. }
  460. if ($atts->use_tags) {
  461. foreach (get_the_tags() as $tag) {
  462. $add_url[] = str_replace(' ', '+', $tag->name);
  463. }
  464. }
  465. if (isset($add_url) and is_array($add_url)) {
  466. $atts->feed = $atts->feed . implode('+', $add_url);
  467. }
  468. ob_start();
  469. $this->rss_output($atts->feed, $atts);
  470. $output.= ob_get_contents();
  471. ob_end_clean();
  472. return $output;
  473. }
  474. function defaults_args() {
  475. return array(
  476. // Query Attributes
  477. 'feed' => NULL,
  478. 'use_title' => false,
  479. 'use_tags' => false,
  480. 'use_category' => false,
  481. 'items' => 10,
  482. 'hide_title' => false,
  483. 'hide_link' => false,
  484. 'show_author' => $this->options->show_author,
  485. 'show_date' => $this->options->show_author,
  486. 'show_time' => $this->options->show_time,
  487. 'show_summary' => $this->options->show_summary,
  488. 'link_target' => $this->options->link_target,
  489. 'nofollow' => $this->options->nofollow,
  490. 'cache_duration' => $this->options->cache_duration,
  491. 'excerpt' => $this->options->excerpt,
  492. 'html_parent' => 'ul',
  493. 'html_item' => 'li'
  494. );
  495. }
  496. /**
  497. * Get an object with all of the post types.
  498. *
  499. * @return object
  500. */
  501. function get_post_types($args = array()) {
  502. if (function_exists('get_post_types')) {
  503. $post_types = get_post_types(array('public' => true));
  504. unset($post_types['attachment']);
  505. } else {
  506. $post_types = array('post', 'page');
  507. }
  508. $defaults = array(
  509. 'output' => 'object',
  510. 'name' => 'post_type',
  511. 'id' => 'post_type'
  512. );
  513. $args = (object) wp_parse_args($args, $defaults);
  514. switch ($args->output) {
  515. case 'dropdown':
  516. $results = '<select name="' . $args->name . '" id="' . $args->id . '">';
  517. foreach ($post_types as $post_type) {
  518. $results.= '<option value="' . $post_type . '">' . $post_type . "</option>\n";
  519. }
  520. $results.= '</select>';
  521. break;
  522. default:
  523. $results = (object) $post_types;
  524. }
  525. return $results;
  526. }
  527. /**
  528. * Display the list of contributors.
  529. * @return boolean
  530. */
  531. function contributor_list() {
  532. if (function_exists('simplexml_load_file')) {
  533. $this->showFields = array('NAME', 'LOCATION', 'COUNTRY');
  534. print '<ul>';
  535. $items = simplexml_load_file('http://cdn.grandslambert.com/xml/better-rss-widget.xml');
  536. foreach ($items as $item) {
  537. print '<li>';
  538. if (empty($item->url)) {
  539. print $item->name;
  540. } else {
  541. print '<a href="' . $item->url . '" target="_blank">' . $item->name . '</a>';
  542. }
  543. if (!empty($item->location)) {
  544. print ' from ' . $item->location;
  545. }
  546. if (!empty($item->country)) {
  547. print ', ' . $item->country;
  548. }
  549. print ' contributed ' . $item->item . ' on ' . date('F jS, Y', strtotime($item->date)) . '</li>';
  550. }
  551. print '</ul>';
  552. } else {
  553. _e('PHP 5 Required to see a list of contributors.', 'pretty-sidebar-categories');
  554. }
  555. }
  556. /**
  557. * Displayes any data sent in textareas.
  558. *
  559. * @param <type> $input
  560. */
  561. function debug($input) {
  562. $contents = func_get_args();
  563. foreach ($contents as $content) {
  564. print '<textarea style="width:49%; height:250px; float: left;">';
  565. print_r($content);
  566. print '</textarea>';
  567. }
  568. echo '<div style="clear: both"></div>';
  569. }
  570. }
  571. /**
  572. * Add the widget code to the initialization action
  573. */
  574. add_action('widgets_init', create_function('', 'return register_widget("better_twitter_widget");'));
  575. register_activation_hook(__FILE__, 'better_twitter_activate');
  576. function better_twitter_activate() {
  577. /* Compile old options into new options Array */
  578. $new_options = '';
  579. $options = array('link_target', 'items', 'show_summary', 'show_author', 'show_date', 'show_time', 'enable_cache', 'cache_duration', 'is_home_default', 'is_front_default', 'is_archive_default', 'is_search_default', 'is_category_default', 'is_tag_default', 'is_single_default', 'is_date_default');
  580. foreach ($options as $option) {
  581. if ($old_option = get_option('better_twitter_' . $option)) {
  582. $new_options[$option] = $old_option;
  583. delete_option('better_twitter_' . $option);
  584. }
  585. }
  586. if (is_array($new_options) and ! add_option('better-twitter-widget-options', $new_options)) {
  587. update_option('better-twitter-widget-options', $new_options);
  588. }
  589. }