| Current Path : /home/ereika83/www/wp-content/plugins/genesis-club-pro/classes/ |
| Current File : /home/ereika83/www/wp-content/plugins/genesis-club-pro/classes/class-social-pro.php |
<?php
class Genesis_Club_Social_Pro extends Genesis_Club_Social {
const HIDE_SOCIAL_METAKEY = '_genesis_club_social_hide';
const SHOW_SOCIAL_METAKEY = '_genesis_club_social_show';
protected $is_social_page;
private $social_scripts_enqueued;
private $css;
private $count = 0;
private $social_url;
private $social_title;
private $social_desc;
private $social_image;
private $social_email;
private $social_twitter;
private $networks = array(
'twitter' => 'Twitter', 'facebook' => 'Facebook', 'plusone' => 'Google +1',
'linkedin' => 'LinkedIn', 'pinterest' => 'Pinterest',
'buffer' => 'Buffer', 'stumbleupon' => 'Stumbleupon',
'print' => 'Print', 'email' => 'Email');
private $networks_links = array(
'twitter' => array('class' => 'socicon socicon-twitter', 'action' => 'Tweet', 'title'=> 'Share on Twitter'),
'facebook' => array('class' => 'socicon socicon-facebook', 'action' => 'Share', 'title'=> 'Share on Facebook'),
'plusone' => array('class' => 'socicon socicon-google', 'action' => '+1','title'=> 'Share on Google Plus'),
'pinterest' => array('class' => 'socicon socicon-pinterest', 'action'=> 'Pin It', 'title'=> 'Pin It'),
'stumbleupon' => array('class' => 'socicon socicon-stumbleupon', 'action'=> 'Stumble', 'title'=> 'Stumble Upon It'),
'linkedin' => array('class' => 'socicon socicon-linkedin', 'action'=> 'Share', 'title'=> 'Share on LinkedIn'),
'buffer' => array('class' => 'socicon socicon-buffer', 'action'=> 'Buffer', 'title'=> 'Buffer It' ),
'email' => array('class' => 'socicon socicon-mail', 'action'=> 'Email', 'title' => 'Share on email' ),
'print' => array('class' => 'dashicons dashicons-media-text', 'action'=> 'Print', 'title'=> 'Print' )
);
private $seeds = array(
'kickstart' => 'false',
'networks' => array('twitter' => 0,'facebook' => 0,'plusone' => 0,'pinterest' => 0, 'stumbleupon' => 0, 'linkedin' => 0, 'buffer' => 0)
);
private $contacts = array(
'txtPrint' => 'Print',
'txtEmail' => 'Email',
'email' => '',
'twitterId' => '');
private $floating = array(
'style' => 'floating', //floating means vertical orientation, toolbar means horizontal
'location' => 'top',
'offsetLocation' => 20,
'align' => 'left',
'offsetAlign' => 20,
'center' => 0,
'size' => 'vertical', //button type and orientation
'total' => 'false',
'width' => '60',
'minimum_device_width' => ''
);
private $display = array(
'show_floating' => 'true',
'show_home' => 'true',
'show_category' => 'true',
'show_tag' => 'true',
'show_posts' => 'true',
'show_pages' => 'false'
);
private $styling = array(
'id' => '',
'background_color' => 'transparent',
'classWrapper' => 'gcpps-panel',
'skin' => 'colors', //use colors
'css' => '',
);
private $settings = array(
'id' => '', //set by the widget
'buttons' => '', //derived from list of social networks
'style' => 'toolbar', //floating means vertical orientation, toolbar means horizontal
'size' => 'horizontal', //button type and orientation
'inline' => 'true',
'shortcode' => 'true',
'total' => 'false');
private $selections = array(
'align' => array('left' => 'Left','right'=> 'Right'),
'location' => array('top' => 'Top','bottom'=> 'Bottom'),
'size' => array('vertical' => 'below', 'horizontal'=> 'right', 'none' => 'no counter' ),
'style' => array('floating' => 'Vertical Panel','toolbar'=> 'Horizontal Panel'),
'skin' => array('colors' => 'Default Colors','gray'=> 'Gray with Colors On Hover', 'custom' => 'Your Own Custom Colors'),
);
function get_default_order() {
return implode(',',array_keys($this->networks));
}
function get_instance_defaults() {
$defaults = array(
'id' => '',
'inline' => true,
'shortcode' => true,
'title' => 'Share this',
'style' => 'toolbar',
'background_color' => 'transparent',
'border' => '0',
'width' => '100%',
'padding' => '10px',
'margin' => '10px 0px',
'align' => 'left',
'size' => 'horizontal',
'total' => 'false',
'show' => 'always',
'device_width' => 960);
$floating = $this->get_option('floating');
$minimum_device_width = isset($floating['minimum_device_width']) ? $floating['minimum_device_width'] : 0;
if (!empty($minimum_device_width)) $defaults['device_width'] = $minimum_device_width;
return $defaults;
}
function get_pro_defaults($option = '') {
$defaults = array (
'networks' => array_fill_keys ( array_keys($this->networks), 'false'),
'contacts' => $this->contacts,
'floating' => $this->floating,
'settings' => $this->settings,
'display' => $this->display,
'styling' => $this->styling,
'seeds' => $this->seeds);
$defaults['networks']['order'] = $this->get_default_order();
$defaults['styling']['id'] = GENESIS_CLUB_PLUGIN_NAME.'-social-panel';
if ($option && array_key_exists($option, $defaults))
return $defaults[$option];
else
return $defaults;
}
function get_defaults() {
return array_merge($this->defaults, $this->get_pro_defaults());
}
function get_network_name($network) {
return array_key_exists($network, $this->networks) ? $this->networks[$network] : '';
}
function get_selections($type) {
return array_key_exists($type, $this->selections) ? $this->selections[$type] : array();
}
function init() {
parent::init();
if (!is_admin()) add_action('wp', array($this, 'prepare'));
}
function register_widgets() {
parent::register_widgets();
register_widget( 'Genesis_Club_Social_Widget' );
}
function prepare() {
add_shortcode ('genesis_club_social', array($this, 'display'));
if (($settings = $this->get_option('settings') ) && ! empty($settings['buttons'])
&& ($display = $this->get_option('display'))
&& $this->is_social_page()
&& $this->check_switch($display['show_floating'])) {
add_action('wp_footer', array($this, 'floating_bar'));
$this->add_css($this->floating_css());
}
}
function is_social_page() {
if ($display = $this->get_option('display')) {
if (is_front_page()) $this->is_social_page = $this->check_switch($display['show_home']);
elseif (is_category()) $this->is_social_page = $this->check_switch($display['show_category']);
elseif (is_tag()) $this->is_social_page = $this->check_switch($display['show_tag']);
elseif (is_singular() && $this->utils->post_has_shortcode('genesis_club_social'))
$this->is_social_page = true;
elseif (is_singular('post'))
if ($this->check_switch($display['show_posts']))
$this->is_social_page = ! get_post_meta(get_queried_object_id(), self::HIDE_SOCIAL_METAKEY,true);
else
$this->is_social_page = get_post_meta(get_queried_object_id(), self::SHOW_SOCIAL_METAKEY,true);
elseif (is_singular('page'))
if ($this->check_switch($display['show_pages']))
$this->is_social_page = ! get_post_meta(get_queried_object_id(), self::HIDE_SOCIAL_METAKEY,true);
else
$this->is_social_page = get_post_meta(get_queried_object_id(), self::SHOW_SOCIAL_METAKEY,true);
else {
$custom_post_types = get_post_types(array('public' => true, '_builtin' => false));
if ((count($custom_post_types) > 0) && is_singular($custom_post_types)) {
$post_id = get_queried_object_id();
if ($this->get_display_switch(get_post_type($post_id)))
$this->is_social_page = ! get_post_meta($post_id, self::HIDE_SOCIAL_METAKEY,true);
else
$this->is_social_page = get_post_meta($post_id, self::SHOW_SOCIAL_METAKEY,true);
} else {
$this->is_social_page = false;
}
}
} else {
$this->is_social_page = false;
}
return $this->is_social_page;
}
function is_social_enabled() {
return $this->is_social_page;
}
function add_css($css_or_instance) {
$css = is_string($css_or_instance) ? $css_or_instance: $this->build_css($css_or_instance) ;
if (!$this->social_scripts_enqueued) { //set up the following just once per page
$this->social_scripts_enqueued = true;
$this->set_social_data(); //title, description and URL of page to share
add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'));
add_action('wp_enqueue_scripts', array($this, 'enqueue_styles'));
add_action('wp_enqueue_scripts', array($this, 'early_inline_styles'));
add_action('wp_print_footer_scripts', array($this, 'late_inline_styles'));
}
$this->css .= $css; //always add the CSS
}
private function set_social_data() {
global $wp_query;
$title = $url = $desc = $image = $email = $twitter = '';
if (is_singular()) {
$object_id = get_queried_object_id();
$title = get_the_title($object_id );
$url = get_the_permalink($object_id );
} elseif ( is_tax() || is_tag() || is_category() ) {
$term = $wp_query->get_queried_object();
if ($term) {
$title = $term->name;
$desc = $term->description;
$url = get_term_link( $term);
}
} elseif ( is_author() ) {
$author = $wp_query->get_queried_object();
if ($author) {
$title = trim($author->first_name . ' ' . $author->last_name);
$desc = get_the_author_meta( 'description', $author->ID );
$url = get_author_posts_url( $author->ID);
}
}
if ($contacts = $this->get_option('contacts')) {
if (isset($contacts['email'])) $email = $contacts['email'];
if (!empty($contacts['twitterId'])) $twitter = str_replace('@','',$contacts['twitterId']);
if (isset($contacts['txtEmail'])) $this->networks_links['email']['action'] = $contacts['txtEmail'];
if (isset($contacts['txtPrint'])) $this->networks_links['print']['action'] = $contacts['txtPrint'];
}
if (empty($url)) $url = site_url();
if (empty($title)) $title = get_bloginfo();
if (empty($desc)) $desc = get_bloginfo('description');
if (empty($email)) $email = get_option('admin_email');
/* Allow application of overrides */
$this->social_url = apply_filters('genesis_club_social_url', $url);
$this->social_title = apply_filters('genesis_club_social_title', htmlspecialchars(strip_tags($title)));
$this->social_desc = apply_filters('genesis_club_social_desc', htmlspecialchars(strip_tags($desc)));
$this->social_image = apply_filters('genesis_club_social_image', $image);
$this->social_email = apply_filters('genesis_club_social_email', $email);
$this->social_twitter = apply_filters('genesis_club_social_twitter', $twitter);
}
function check_switch($switch) {
return ('true'==$switch) || ('1'==$switch) || ('on'==$switch) || (1==$switch) || (true===$switch);
}
function get_display_switch ($post_type) {
$switch = 'show_'.$post_type.'s';
if ($display = $this->get_option('display'))
return array_key_exists($switch, $display) && $this->check_switch($display[$switch]);
else
return false;
}
function get_toggle_meta_key($post_type) {
return $this->get_display_switch($post_type) ? self::HIDE_SOCIAL_METAKEY : self::SHOW_SOCIAL_METAKEY;
}
function list_options($selected, $options) {
$s = '';
foreach ($options as $val => $desc) $s .=
sprintf('<option %1$s value="%2$s">%3$s</option>', selected($val, $selected, false), $val, $desc);
return $s;
}
function size_options($selected) {
return $this->list_options( $selected,
array('vertical' => 'below','horizontal'=> 'right','none' => 'no counter' ));
}
function style_options($selected) {
return $this->list_options($selected,
array('floating' => 'Vertical Panel','toolbar'=> 'Horizontal Panel') );
}
function check_unit($item) {
$str = str_replace(' ','',trim($item));
$suffix='';
if (empty($str) || ('auto'==$str)
|| (strstr($str, 'px') !== false)
|| (strstr($str, '%') !== false))
return $str;
else
return $str. 'px';
}
function display($atts = array()) {
$styling = $this->get_option('styling');
$atts = wp_parse_args((array)$atts, $this->get_instance_defaults());
if (empty($atts['id'])) {
$this->count++;
$atts['id'] = sprintf('%1$s-s%2$s', $styling['id'], $this->count); //make sure ID is unique if there are multiple shortcodes on the same page
}
$settings = array_merge( $this->get_option('settings'), $this->get_option('contacts')) ;
if ( ! $atts['inline']) $settings = array_merge($settings, $this->get_option('floating'));
$params = wp_parse_args( $atts, $settings);
$class = sprintf('%1$s%2$s %3$s%4$s', $styling['classWrapper'], $params['inline'] ? '' : ' gcpps-floating', $params['style'] =='toolbar' ? 'gcpps-horizontal' : 'gcpps-vertical',
str_replace(array('vertical','horizontal','none'), array('below','right', 'none'), ' counter-' . $params['size'] ) );
$skin = $this->check_switch($styling['skin']) ? 'colors' : $styling['skin'];
$counts = $params['size'] == 'none' ? ($params['total'] ? 'true' : 'false') : 'true';
$s = '';
$buttons = explode(',', $params['buttons']);
foreach ($buttons as $button) $s .= $this->build_social_link($button, $this->social_url);
if ($this->check_switch($params['total'])) $s .= '<li class="total"><a title="Total Shares" href="#"><span class="dashicons dashicons-groups"></span><span class="count">Total</span></a></li>';
if ($params['shortcode']) $this->add_css($params); //Generate any custom CSS if using a shortcode
return sprintf('<div id="%1$s" class="%2$s"><ul class="socialcount %3$s" data-counts="%4$s" data-url="%5$s" data-share-text="%6$s" data-description="%7$s" data-media="%8$s" data-email="%9$s" data-twitter="%10$s">%11$s</ul></div>',
$params['id'], $class, $skin, $counts,
$this->social_url, $this->social_title, $this->social_desc, $this->social_image, $this->social_email, $this->social_twitter, $s);
}
function build_social_link($network) {
$email = '';
if (array_key_exists($network,$this->networks_links)) {
$link_info = $this->networks_links[$network];
return sprintf('<li class="%1$s"><a title="%2$s" href="#"><span class="%3$s"></span><span class="count">%4$s</span></a></li>',
$network, $link_info['title'], $link_info['class'], $link_info['action']);
}
}
function floating_bar() {
$styling = $this->get_option('styling');
$floating = $this->get_option('floating');
print "\n" .$this->display(array( 'id' => $styling['id'], 'total' => $floating['total'], 'inline' => false, 'shortcode' => false, 'style' => $floating['style'], 'size' => $floating['size'])) . "\n";
}
function floating_css() {
$floating = wp_parse_args($this->get_option('floating'), $this->get_pro_defaults('floating'));
$styling = $this->get_option('styling');
$id = $styling['id'];
$containerClass = $styling['classWrapper'];
if ($floating['center']) {
$offsetAlign = '50%';
$margin = sprintf('margin-%1$s: -%2$spx;', $floating['align'], $floating['center']);
} else {
$offsetAlign = sprintf('%1$spx',$floating['offsetAlign']);
$margin = '';
}
if (($background_color = $styling['background_color']) && ($background_color != 'transparent'))
$background = sprintf('background-color: %1$s; text-align:center; padding: 5px; border-radius: 5px;', $background_color);
else
$background = '';
if ($width = $this->check_unit($floating['width']))
$width = sprintf('width: %1$s;', $width);
else
$width = '';
$css = sprintf(' #%1$s.%2$s{%3$s: %4$spx; %5$s: %6$s;%7$s%8$s%9$s } ',
$id, $containerClass, $floating['location'], $floating['offsetLocation'], $floating['align'], $offsetAlign, $margin, $background, $width);
if ($minimum_device_width = $this->check_unit($floating['minimum_device_width']))
$css .= sprintf(' @media only screen and (max-width: %1$s) { .gcpps-floating{display:none;} }', $minimum_device_width, $containerClass );
if ($custom_css = $styling['css'])
$css .= $custom_css;
return $css;
}
function build_css($instance) {
$instance = wp_parse_args($instance, $this->get_instance_defaults());
$element = sprintf('#%1$s', $instance['id']);
$min_dev_width = $this->check_unit($instance['device_width']);
if ($instance['show']=='under')
$resp = sprintf('@media only screen and (min-width: %1$s) { %2$s { display: none; } }', $min_dev_width, $element );
elseif ($instance['show']=='over')
$resp = sprintf('@media only screen and (max-width: %1$s) { %2$s { display: none; } }', $min_dev_width, $element );
else
$resp = '';
return sprintf ('%1$s { margin: %2$s; width: %3$s; border: %4$s; padding: %5$s; text-align: %6$s; background-color : %7$s; }',
$element, $instance['margin'], $instance['width'], $instance['border'], $instance['padding'], $instance['align'], $instance['background_color']).$resp;
}
function enqueue_scripts() {
wp_enqueue_script('genesis-club-social', plugins_url('scripts/jquery.social.js', dirname(__FILE__)), array('jquery'), '0.1.10', true);
wp_localize_script('genesis-club-social', 'GCPPURL', array( 'url' => plugins_url('',dirname(__FILE__ ))));
}
function enqueue_styles() {
wp_enqueue_style( 'genesis-club-social', plugins_url('styles/social.css', dirname(__FILE__)));
}
function early_inline_styles() {
if (!empty($this->css) && wp_add_inline_style( 'genesis-club-social', $this->css)) $this->css = '';
}
function late_inline_styles() {
$this->utils->late_inline_styles($this->css);
}
}
class Genesis_Club_Social_Widget extends Genesis_Club_Widget {
private $social;
private $tooltips;
private $tips = array(
'title' => array('heading' => 'Title', 'tip' => 'Widget title - only shown in admin for labelling purposes.'),
'style' => array('heading' => 'Panel Style', 'tip' => 'Select either a vertical or a horizontal panel.'),
'width' => array('heading' => 'Panel Width', 'tip' => 'Enter the desired width of the panel in pixels if the default width is not to your taste.'),
'background_color' => array('heading' => 'Background', 'tip' => 'Choose a background color for the panel if you do not want a transparent background'),
'padding' => array('heading' => 'Padding', 'tip' => 'Padding e.g. 10px'),
'margin' => array('heading' => 'Margins', 'tip' => 'Margins e,g 10px 0 for a a top/bottom margin of 10px and no left/right margin.'),
'border' => array('heading' => 'Border', 'tip' => 'Border e.g. solid black 1px '),
'align' => array('heading' => 'Alignment', 'tip' => 'Alignment of button panel - left/right of browser window.'),
'size' => array('heading' => 'Counter', 'tip' => 'Select whether to show the number of shares below, on the right, or not at all.'),
'device_width' => array('heading' => 'Device Width', 'tip' => 'Device width at which panel is displayed'),
'total' => array('heading' => 'Total Shares', 'tip' => 'Show cumulative total of shares across all channels.'),
'show' => array('heading' => 'Visibility', 'tip' => 'Criteria when panel is displayed'),
'skin' => array('heading' => 'Colored Icons', 'tip' => 'Use colored icons. Alternative is gray icons which have colors when the cursor is hovered over them.'),
);
function __construct() {
$widget_ops = array('description' => __('Displays a Social Panel showing numbers of likes', GENESIS_CLUB_DOMAIN) );
$control_ops = array();
parent::__construct('genesis-club-social', __('Genesis Club Social', GENESIS_CLUB_DOMAIN), $widget_ops, $control_ops);
$this->social = $this->plugin->get_module('social');
$this->set_defaults($this->social->get_instance_defaults());
add_action('wp', array($this, 'add_css_if_active'), 15);
}
function add_css_if_active() {
if ($this->social->is_social_enabled() && $this->is_widget_instance_active()) {
$instance = $this->instance;
$instance['id'] = $this->get_id($this->key);
$this->social->add_css($instance);
}
}
function get_id ($suffix) {
return $this->id_base . '-w' . $suffix;
}
function widget( $args, $instance ) {
if (!$this->social->is_social_enabled()) return; //skip if no social on this page
$args = $this->override_args($args, $instance) ;
extract($args);
echo $before_widget;
echo $this->social->display( array ( 'id' => $this->get_id($this->number), 'inline' => true, 'shortcode' => false,
'size' => $instance['size'], 'style' => $instance['style'], 'total' => $instance['total']));
echo $after_widget;
}
function update( $new_instance, $old_instance ) {
$instance = $this->update_instance( $new_instance, $old_instance );
$instance['style'] = $new_instance['style'];
$instance['size'] = $new_instance['size'];
$instance['width'] = $new_instance['width'];
$instance['padding'] = $new_instance['padding'] ;
$instance['margin'] = $new_instance['margin'] ;
$instance['align'] = $new_instance['align'];
$instance['border'] = $new_instance['border'];
$instance['background_color'] = strtoupper(trim($new_instance['background_color'])) ;
$instance['total'] = $new_instance['total'];
$instance['show'] = $new_instance['show'];
$instance['device_width'] = $new_instance['device_width'];
return $instance;
}
private function check_color($color) {
return (('transparent'==$color) || ('#'==substr($color,0,1)) ? '' : '#').$color;
}
function form( $instance ) {
print ('<div class="diy-wrap">');
$this->form_init ($instance, $this->tips);
$this->print_form_field('style', 'select', array('floating' => 'Vertical','toolbar'=> 'Horizontal '));
$this->print_form_field('width', 'text', array(), array('size' => 6));
$this->print_form_field('padding', 'text', array(), array('size' => 6 ));
$this->print_form_field('margin', 'text', array(), array('size' => 6 ));
$this->print_form_field('border', 'text', array(), array('size' => 12));
$this->print_form_field('background_color', 'text', array(), array('size' => 8, 'class' => 'color-picker'));
$this->print_form_field('align', 'select', array('left' => 'Left', 'center' => 'Center','right'=> 'Right'));
$this->print_form_field('size', 'select', array('vertical' => 'below','horizontal'=> 'right','none' => 'no counter' ));
$this->print_form_field('total', 'radio', array('true' => 'Show Total', 'false'=> 'Hide Total' ));
$this->print_form_field('show', 'select', array('always' => 'Show always','under'=> 'Show under ', 'over'=> 'Show over '));
$this->print_form_field('device_width', 'text', array(), array('size' => 4, 'suffix' => 'px'));
print('</div>');
}
}
class Genesis_Club_Social_Counts {
const SEEDING = 'genesis_club_social_seeding';
const TRANSIENT_PREFIX = 'gcsocial';
const TRANSIENT_TIMEOUT = 3600;
const EMPTY_RESULT = '""';
const REQUIRE_LOCAL_URL = FALSE;
private $services = array();
private $url;
private $key;
private $seeding = false;
private $defaults = false;
private $social;
function __construct($url='') {
if (empty($url) && isset($_GET['url'])) $url = $_GET['url'];
if(empty($url)) {
throw new Exception('"url" required.');
}
$this->url = htmlspecialchars($url);
if ( self::REQUIRE_LOCAL_URL && ! $this->is_local_url()) {
throw new Exception( 'URL'. $this->URL. ' not authorized on ' . $_SERVER['HTTP_HOST']);
}
$this->social = Genesis_Club_Plugin::get_instance()->get_module('social');
$this->set_key();
$this->set_seeding();
}
public function add_network(Genesis_Club_Social_Network $network) {
$this->services[] = $network;
}
private function is_local_url() {
return preg_match('/^http(s?):\/\/' . $_SERVER['HTTP_HOST'] . '(:\d+)?\//', $this->url );
}
public function get_counts() {
if ($vals = $this->get_cache())
$services = unserialize($vals);
else {
$total = 0;
$services = array();
foreach($this->services as $service) {
$count = $service->get_share_count($this->url);
if (is_array($this->seeding)) $count = $this->process_count($service->get_key(), $count);
$services[] = '"' . $service->get_key() . '": ' . (is_null($count) ? self::EMPTY_RESULT : $count);
$total = $total + (is_null($count) ? 0 : $count);
}
$services[] = '"total": ' . (is_null($total) ? self::EMPTY_RESULT : $total);
$this->set_cache(serialize($services));
}
return '{' . implode(',', $services) . '}';
}
private function process_count ($network_key, $count) {
if (is_null($count)) return NULL;
$seed = $this->get_seed($network_key);
if (is_null($seed)) $seed = $this->set_seed($network_key);
if (is_null($seed)) return $count;
if ($count >= ($seed*2))
return $count;
else
return $seed + floor($count/2);
}
private function get_seed($network_key) {
if(is_array($this->seeding)
&& array_key_exists($this->key,$this->seeding )
&& is_array($this->seeding[$this->key])
&& array_key_exists($network_key,$this->seeding[$this->key] ))
return $this->seeding[$this->key][$network_key];
else
return NULL;
}
private function set_seed($network_key) {
foreach ($this->defaults as $network => $range) {
if (strpos($range, ':') === FALSE)
$new_seed = $range;
else {
$vals = explode(':',$range);
if (is_numeric($vals[0]) && is_numeric($vals[1]))
$new_seed = rand($vals[0], $vals[1]);
else
$new_seed = $vals[0];
}
if (!is_array($this->seeding) || !array_key_exists($this->key, $this->seeding) || !array_key_exists($network, $this->seeding[$this->key]))
$this->seeding[$this->key][$network] = $new_seed;
}
update_option(self::SEEDING, $this->seeding );
return $this->get_seed($network_key);
}
private function set_seeding() {
if (($seeds = $this->social->get_option('seeds'))
&& is_array($seeds)
&& array_key_exists('kickstart', $seeds) && array_key_exists('networks', $seeds)
&& ($seeds['kickstart'] == 'true') && is_array($seeds['networks'])) {
$this->defaults = $seeds['networks'];
if (!($this->seeding = get_option(self::SEEDING))) $this->seeding = array();
} else {
$this->seeding = false;
}
}
private function set_key() {
$this->key = self::TRANSIENT_PREFIX . md5($this->url);
}
private function set_cache($vals) {
set_transient($this->key, $vals, self::TRANSIENT_TIMEOUT);
}
private function get_cache() {
return get_transient($this->key);
}
}
abstract class Genesis_Club_Social_Network {
abstract function get_key();
abstract function get_share_count($url);
public function curl_get_contents($url) {
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
try {
$data = curl_exec($curl);
} catch (Exception $e) {
$data = false;
}
curl_close($curl);
return $data;
}
}
class Genesis_Club_Twitter extends Genesis_Club_Social_Network {
public function get_key() {
return 'twitter';
}
public function get_share_count($url) {
$contents = @file_get_contents('https://urls.api.twitter.com/1/urls/count.json?url=' . $url);
if($contents) {
return json_decode($contents)->count;
} else {
return NULL;
}
}
}
class Genesis_Club_Facebook extends Genesis_Club_Social_Network {
public function get_key(){
return 'facebook';
}
function get_share_count($url) {
$xml = file_get_contents("http://api.facebook.com/restserver.php?method=links.getStats&urls=".urlencode($url));
$xml = simplexml_load_string($xml);
$shares = $xml->link_stat->share_count;
$likes = $xml->link_stat->like_count;
$comments = $xml->link_stat->comment_count;
return $likes + $shares + $comments;
}
function get_fql($url){
$contents = @file_get_contents("http://graph.facebook.com/fql?q=SELECT%20url,%20total_count%20FROM%20link_stat%20WHERE%20url='".$url."'");
if($contents) {
$json = json_decode($contents);
return isset($json->data[0]->total_count) ? $json->data[0]->total_count : 0;
} else {
return NULL;
}
}
}
class Genesis_Club_GooglePlus extends Genesis_Club_Social_Network {
public function get_key() {
return 'plusone';
}
public function get_share_count($url) {
$html = $this->curl_get_contents( "https://plusone.google.com/_/+1/fastbutton?url=".urlencode($url));
$doc = new DOMDocument();
libxml_use_internal_errors(true);
$doc->loadHTML($html);
libxml_use_internal_errors(false);
$counter=$doc->getElementById('aggregateCount');
$c = $counter->nodeValue;
$c = str_replace(array(' ','M','k'), array('','000000','000'), $c);
return $c;
}
}
class Genesis_Club_ShareThis extends Genesis_Club_Social_Network {
const PUB_KEY = 'a3cce920-3a6b-47a8-a890-d27d55cbc9e8';
const ACCESS_KEY = '512db7bf2cce2acb63fad31b31067e27';
public function get_key()
{
return 'sharethis';
}
public function get_share_count($url)
{
$contents = @file_get_contents('http://rest.sharethis.com/reach/getUrlInfo.php?url=' . $url . '&pub_key=' . self::PUB_KEY . '&access_key=' . self::ACCESS_KEY);
if($contents) {
$json = json_decode($contents);
return $json->total->inbound;
} else {
return NULL;
}
}
}
class Genesis_Club_Pinterest extends Genesis_Club_Social_Network {
public function get_key()
{
return 'pinterest';
}
public function get_share_count($url)
{
$contents = @file_get_contents('http://api.pinterest.com/v1/urls/count.json?callback=receiveCount&url=' . $url);
if($contents) {
$contents = preg_replace('/.+?({.+}).+/','$1', $contents);
$json = json_decode($contents);
return $json->count !== '-' ? $json->count : NULL;
} else {
return NULL;
}
}
}
class Genesis_Club_LinkedIn extends Genesis_Club_Social_Network {
public function get_key(){
return 'linkedin';
}
public function get_share_count($url)
{
$contents = $this->curl_get_contents(sprintf('https://www.linkedin.com/countserv/count/share?url=%1$s&format=json',$url));
if($contents) {
return json_decode($contents)->count;
} else {
return NULL;
}
}
}
class Genesis_Club_StumbleUpon extends Genesis_Club_Social_Network {
public function get_key(){
return 'stumbleupon';
}
public function get_share_count($url)
{
$contents = $this->curl_get_contents(sprintf('http://www.stumbleupon.com/services/1.01/badge.getinfo?url=%1$s',$url));
if($contents) {
$json = json_decode($contents, true);
return isset($json['result']['views'])?intval($json['result']['views']):0;
} else {
return NULL;
}
}
}
class Genesis_Club_Delicious extends Genesis_Club_Social_Network {
public function get_key(){
return 'delicious';
}
public function get_share_count($url)
{
$contents = $this->curl_get_contents(sprintf('http://feeds.delicious.com/v2/json/urlinfo/data?url=%1$s',$url));
if($contents) {
$json = json_decode($contents);
return isset($json->total_posts)?intval($json->total_posts):0;
} else {
return NULL;
}
}
}
class Genesis_Club_Buffer extends Genesis_Club_Social_Network {
public function get_key(){
return 'buffer';
}
public function get_share_count($url)
{
$contents = $this->curl_get_contents(sprintf('https://api.bufferapp.com/1/links/shares.json?url=%1$s',$url));
if($contents) {
$json = json_decode($contents);
return isset($json->shares)?intval($json->shares):0;
} else {
return NULL;
}
}
}