AddThis Share Plugin installed on your site. * Version: 1.0.6 * * Author: The AddThis Team * Author URI: http://www.addthis.com/blog */ define('PLUGIN_DIR_PATH', plugin_dir_url(__FILE__) ); define('ADDTHIS_TRENDING_PRODUCT_CODE', 'wptcw-1.0.6' ); define('ADDTHIS_TRENDING_AT_VERSION', 300 ); class AddThisTrendingWidget { function __construct() { add_action('widgets_init', array($this, 'widgets_init')); //wp_enqueue_script('minicolor', plugins_url('', basename(dirname(__FILE__))).'/addthis-trending/js/jquery.miniColors.js'); wp_enqueue_style('minicolor', PLUGIN_DIR_PATH . '/css/jquery.miniColors.css'); add_action('admin_print_styles-widgets.php', array($this, 'admin_print_styles')); add_action( 'admin_enqueue_scripts', array($this, 'add_this_trending_admin_enqueue_scripts') ); } function widgets_init() { register_widget('AddThisTrendingSidebarWidget'); } function add_this_trending_admin_enqueue_scripts(){ wp_enqueue_script('minicolor', PLUGIN_DIR_PATH .' /js/jquery.miniColors.js'); wp_enqueue_script('widgets-php', PLUGIN_DIR_PATH . '/js/widgets-php.js'); } function admin_print_styles() { $style_location = apply_filters('addthis_trending_files_uri', PLUGIN_DIR_PATH . '/css/widgets-php.css'); $js_location = apply_filters('addthis_trending_files_uri', PLUGIN_DIR_PATH . '/js/widgets-php.js'); wp_enqueue_style('addthis_trending', $style_location, array(), 0); wp_enqueue_script('addthis_trending', $js_location, array('jquery'), 0); } } new AddThisTrendingWidget(); /** * Basic Trending Options class shared by the Trending Plugin and Widget */ class TrendingOptions { private static $_instance = null; private $_styles = null; private function __construct() { $this->_styles = array( 'trending' => array('Trending'), 'shared' => array('Most Shared'), 'clicked' => array('Most Clicked')); $this->_timePeriod = array( 'month' => array('Last Month'), 'week' => array('Last Week'), 'day' => array('Last Day')); $this->_links = array( '1' => array('1'),'2' => array('2'),'3' => array('3'),'4' => array('4'),'5' => array('5'),'6' => array('6'), '7' => array('7'),'8' => array('8'),'9' => array('9'),'10' => array('10'),'11' => array('11'),'12' => array('12'), '13' => array('13'),'14' => array('14'),'15' => array('15'),'16' => array('16'),'17' => array('17'),'18' => array('18'), '19' => array('19'), '20' => array('20')); } public static function getInstance() { if (self::$_instance == null) { self::$_instance = new TrendingOptions(); } return self::$_instance; } public function getStyles() { return $this->_styles; } public function getDefaultStyle() { return $this->_defaultStyle; } public function getTimePeriod(){ return $this->_timePeriod; } public function getDefaultTime() { return $this->_defaultTime; } public function getLinks() { return $this->_links; } } /** * AddThis Trending Plugin and its settings */ class AddThisTrendingPlugin { private $_trendingOptions = null; public function __construct() { $this->_trendingOptions = TrendingOptions::getInstance(); add_filter('admin_menu', array($this, 'admin_menu')); add_action('admin_init', array($this, 'register_trending_settings')); } function register_trending_settings() { register_setting('addthis_trending_settings', 'addthis_trending_settings', array($this, 'save_settings')); } /** * Callback for saving the Trending plugin settings * Sanitize the options and save it * * @param array $input * @return array $options */ function save_settings($input) { $options = array(); $allowedKeys = array('title', 'style', 'time', 'height', 'width', 'links', 'repeated', 'bg_color', 'border'); foreach ($input as $key => $value) { if (in_array($key, $allowedKeys)) { $value = sanitize_text_field($value); $options[$key] = $value; } } return $options; } /** * AddThis Trending Admin menu */ function admin_menu() { if (is_admin()) { $trending = add_options_page('AddThis Plugin Options', 'AddThis Trending Content', 'manage_options', basename(__FILE__), array($this, 'options')); } } /** * AddThis Trending settings page */ function options() { wp_enqueue_style('adminstyles', PLUGIN_DIR_PATH.'css/admin-options.css'); if (version_compare(get_bloginfo('version'), '3.3', '<')) { wp_head(); } $style = $this->_trendingOptions->getDefaultStyle(); $time = $this->_trendingOptions->getDefaultTime(); $commonTrendingOptions = get_option('addthis_trending_settings'); $trendingWidgetOptions = get_option('widget_addthis-trending-widget'); /** * Restore from widget settings if possible */ if (($commonTrendingOptions == false || empty($commonTrendingOptions)) && $trendingWidgetOptions != false) { $restoreOptions = array('title' => $title, 'style' => $style, 'time' => $time); add_option('addthis_trending_settings', $restoreOptions); } $this->displayOptionsForm(); } /** * Display the Trending Options Form * @global AddThis_addjs $addthis_addjs * @param TrendingOptions $buttonOptions * @param string $style * @param string $title */ function displayOptionsForm() { global $addthis_addjs; $getOptionValues = get_option('addthis_trending_settings'); $style = $getOptionValues['style']; $title = $getOptionValues['title']; $time = $getOptionValues['time']; $height = ($getOptionValues['height'])?$getOptionValues['height']:'auto'; $width = ($getOptionValues['width'])?$getOptionValues['width']:'auto'; $links = $getOptionValues['links']; $repeated = $getOptionValues['repeated']; $bg_color = $getOptionValues['bg_color']; $border = $getOptionValues['border']; $bg_color_checked = ''; $bg_color_disabled = 'disabled="disabled"'; if($bg_color){ $bg_color_checked = 'checked="checked"'; $bg_color_disabled = ''; } $border_checked = ''; $border_disabled = 'disabled="disabled"'; if($border){ $border_checked = 'checked="checked"'; $border_disabled = ''; } ?>

AddThis Pro now available - start your trial at www.addthis.com and get premium widgets, personalized content recommendations, advanced customization options and priority support.


getAtPluginPromoText(); ?> addthis AddThis Trending
Please make sure that you have the Share plugin installed on your site. "; } ?>

'; echo '

 

 

'; echo '

'; ?>  

' . __('AddThis Profile ID:', 'addthis') . '

Preview

This is an example of what it will look like.
To show AddThis Trending Contents in your website, please drag and drop AddThis Trending Content widget from Appearance > Widget.
For detailed instructions on how to get your Profile ID and enable Content Feeds, refer AddThis Support.
'; } } add_action('init', 'initialize_addthis_trending_plugin'); register_deactivation_hook(__FILE__, 'addthis_trending_remove'); /** * Deactivation callback */ function addthis_trending_remove() { delete_option('addthis_trending_settings'); } /** * Plugin initialization callback */ function initialize_addthis_trending_plugin() { new AddThisTrendingPlugin(); } class AddThisTrendingSidebarWidget extends WP_Widget { function __construct() { $widget_ops = array('classname' => 'attrendingwidget', 'description' => 'Connect fans and trendingers with your profiles on top social services'); /* Widget control settings. */ $control_ops = array('width' => 260); /* Create the widget. */ parent::__construct('addthis-trending-widget', 'AddThis Trending Content', $widget_ops, $control_ops); } /** * Echo's out the content of our widget */ function widget($args, $instance) { extract($args); $bg_code = ''; $border_code = ''; $title = apply_filters('widget_title', $instance['title']); echo $before_widget; if ($title) echo $before_title . $title . $after_title; unset($instance['profile']); unset($instance['title']); $styles = TrendingOptions::getInstance()->getStyles(); $class = $styles[$instance['style']][1]; echo '
'; echo '
'; if('on' == $instance['bg_check']) $bg_code = ('' != $instance['bg_color'])?'background: "'.$instance['bg_color'].'",':''; if('on' == $instance['border_check']) $border_code = ('' != $instance['border_check'])?'border: "'.$instance['border'].'",':''; echo ''; // end the div echo '
'; echo $after_widget; } /** * Update this instance */ function update($new_instance, $old_instance) { $instance = array(); $styles = TrendingOptions::getInstance()->getStyles(); $time = TrendingOptions::getInstance()->getTimePeriod(); global $addthis_addjs; if (isset($new_instance['profile']) && substr($new_instance['profile'], 0, 2) != 'wp-') { $addthis_addjs->setProfileId($new_instance['profile']); } $style = $new_instance['style']; if (isset($styles[$style])) { $instance['style'] = $style; } else { $instance['style'] = isset($styles[$style]); } $timep = $new_instance['time']; if(isset($timep[$time])) { $instance['time'] = $timep; } else { $instance['time'] = isset($timep[$time]); } print_r($new_instance); $title = sanitize_text_field($new_instance['title']); $instance['title'] = $title; $height = sanitize_text_field($new_instance['height']); $instance['height'] = ($height)?$height:'auto'; $width = sanitize_text_field($new_instance['width']); $instance['width'] = ($width)?$width:'auto'; $links = $new_instance['links']; $instance['links'] = $links; $repeated = sanitize_text_field($new_instance['repeated']); $instance['repeated'] = $repeated; $bg_color = $new_instance['bg_color']; if('on' != $new_instance['bg_check']){ $instance['bg_color'] = 'none'; }else{ $instance['bg_color'] = $bg_color; } $border = $new_instance['border']; if('on' != $new_instance['border_check']){ $instance['border'] = 'none'; }else{ $instance['border'] = $border; } $instance['bg_check'] = $new_instance['bg_check']; $instance['border_check'] = $new_instance['border_check']; return $instance; } /** * The form with the widget options */ function form($instance) { global $addthis_addjs; $title = $instance['title']; $style = $instance['style']; $time = $instance['time']; $height = $instance['height']; $width = $instance['width']; $links = $instance['links']; $repeated = $instance['repeated']; $bg_color = $instance['bg_color']; $border = $instance['border']; $bg_check = $instance['bg_check']; $border_check = $instance['border_check']; $addthis_trending_options = get_option('addthis_trending_settings'); $trendingOptions = TrendingOptions::getInstance(); $title = ($title) ? $title : $addthis_trending_options['title']; $style = ($style) ? $style : $addthis_trending_options['style']; $time = ($time) ? $time : $addthis_trending_options['time']; $height = ($height) ? $height : $addthis_trending_options['height']; $width = ($width) ? $width : $addthis_trending_options['width']; $links = ($links) ? $links : $addthis_trending_options['links']; $repeated = ($repeated) ? $repeated : $addthis_trending_options['repeated']; $bg_color = ($bg_color) ? $bg_color : $addthis_trending_options['bg_color']; $border = ($border) ? $border : $addthis_trending_options['border']; $bg_check = ($bg_check) ? $bg_check : $addthis_trending_options['bg_check']; $border_check = ($border_check) ? $border_check : $addthis_trending_options['border_check']; $bg_color_checked = ''; $bg_color_disabled = 'disabled="disabled"'; if($bg_color && ('on' == $bg_check)){ $bg_color_checked = 'checked="checked"'; $bg_color_disabled = ''; } $border_checked = ''; $border_disabled = 'disabled="disabled"'; if($border && ('on' == $border_check)){ $border_checked = 'checked="checked"'; $border_disabled = ''; } // enable colorpicker if already color is seleccted $enable_bg_cp = ''; $enable_border_cp = ''; // bg color picker if($bg_color_checked){ $enable_bg_cp = 'enablePicker("'.$this->get_field_name('bg_check').'", "'.$this->get_field_id('bg_color').'", 1);'; } if($border_checked){ $enable_border_cp = 'enablePicker("'.$this->get_field_name('border_check').'", "'.$this->get_field_id('border').'", 1);'; } echo $addthis_addjs->getAtPluginPromoText(); echo ' '; echo ' '; echo ' '; echo '"; } } // Setup our shared resources early add_action('init', 'addthis_trending_early', 1); function addthis_trending_early() { wp_enqueue_script("jquery"); global $addthis_addjs; if (!isset($addthis_addjs)) { require('includes/addthis_addjs.php'); $addthis_options = get_option('addthis_settings'); $addthis_addjs = new AddThis_addjs($addthis_options); } elseif (!method_exists($addthis_addjs, 'getAtPluginPromoText')) { require('includes/addthis_addjs_extender.php'); $addthis_addjs = new AddThis_addjs_extender($addthis_options); } } // check for pro user function at_trending_content_is_pro_user() { $isPro = false; $options = get_option('addthis_settings'); $profile = $options['profile']; if ($profile) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://q.addthis.com/feeds/1.0/config.json?pubid=" . $profile); // receive server response ... curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // further processing .... $server_output = curl_exec($ch); curl_close($ch); $array = json_decode($server_output); // check for pro user if (array_key_exists('_default',$array)) { $isPro = true; } else { $isPro = false; } } return $isPro; }