| 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-admin.php |
<?php
class Genesis_Club_Social_Pro_Admin extends Genesis_Club_Social_Admin {
const TOGGLE_SOCIAL = 'genesis_club_toggle_social';
private $pro_tips = array(
'show_floating' => array('heading' => 'Show Floating Panel', 'tip' => 'Control whether or not to show the floating social panel in addition to any fixed social panel you decide to place in widget areas.'),
'show_home' => array('heading' => 'Show On Home Page', 'tip' => 'Control whether or not to show the social media buttons on the home page'),
'show_category' => array('heading' => 'Show On Categories', 'tip' => 'Control whether or not to show the social media buttons on category archives'),
'show_tag' => array('heading' => 'Show On Tag Archives', 'tip' => 'Control whether or not to show the social media buttons on tag archives'),
'show_posts' => array('heading' => 'Show On Posts', 'tip' => 'Control whether or not to show the social media buttons on posts. You can override this setting for individual posts in the Post Editor.'),
'show_pages' => array('heading' => 'Show On Pages', 'tip' => 'Control whether or not to show the social media buttons on pages. You can override this setting for individual posts in the Page Editor.'),
'show_custom' => array('heading' => 'Show On %1$s', 'tip' => 'Control whether or not to show the social media buttons on %1$s custom post type pages. You can override this setting for individual custom post types in the Post Editor.'),
'style' => array('heading' => 'Panel Style', 'tip' => 'Select either a vertical or a horizontal panel.'),
'location' => array('heading' => 'Location', 'tip' => 'Location of button panel - top/bottom.'),
'offsetLocation' => array('heading' => 'Vertical Offset', 'tip' => 'Number of pixels from top/bottom of browser.'),
'align' => array('heading' => 'Alignment', 'tip' => 'Alignment of button panel - left/right of browser window.'),
'offsetAlign' => array('heading' => 'Horizontal Offset', 'tip' => 'number of pixels from left/right of browser.'),
'size' => array('heading' => 'Counter', 'tip' => 'Select whether to show the number of shares below, on the right, or not at all. Note that the count is no longer available on all social channels, notably Twitter.'),
'minimum_device_width' => array('heading' => 'Minimum Device Size', 'tip' => 'Enter the width at which the floating social panel is hidden (typically around 1000px), or leave blank to show on all devices.'),
'show' => array('heading' => 'Visibility', 'tip' => 'Criteria when panel is displayed'),
'device_width' => array('heading' => 'Device Width', 'tip' => 'Device width at which panel is displayed'),
'center' => array('heading' => 'Center', 'tip' => 'If set to zero the buttons will be positioned from the edge of the browser using the location/alignment values. If greater than zero then positioning will be based on the number of pixels from the center of the browser - use this option to prevent the button panel covering the page content in smaller browsers.'),
'total' => array('heading' => 'Total Shares', 'tip' => 'Show cumulative total of shares across all channels.'),
'skin' => array('heading' => 'Colored Icons', 'tip' => 'Use colored icons. Alternative is gray icons which have colors when the cursor is hovered over them.'),
'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'),
'css' => array('heading' => 'Custom CSS', 'tip' => 'Add any custom CSS - the CSS is not validated so it is your responsibility to get this right.'),
'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 '),
'txtPrint' => array('heading' => 'Print Text', 'tip' => 'The text to show for the print button.'),
'txtEmail' => array('heading' => 'Email Text', 'tip' => 'The text to show for the email button.'),
'email' => array('heading' => 'Email', 'tip' => 'The email address to use for the email button.'),
'twitterId' => array('heading' => 'Twitter ID', 'tip' => 'Enter your twitter ID - this will be added to any tweets.'),
'kickstart' => array('heading' => 'Kickstart', 'tip' => 'Click to enable the seeding of various networks with a number of shares.'),
'title' => array('heading' => 'Title', 'tip' => 'Widget title - only shown in admin for labelling purposes.')
);
function init() {
parent::init();
add_action('genesis_club_hiding_settings_show', array($this, 'add_page_visibility'), 20, 2);
add_action('genesis_club_hiding_settings_save', array($this, 'save_page_visibility'), 20, 1);
}
function get_keys() {
$keys = implode(',',array_keys(array_merge($this->get_tips(), $this->pro_tips)));
$custom_post_types = get_post_types(array('public' => true, '_builtin' => false));
foreach ($custom_post_types as $post_type) $keys .= ',show_'.strtolower($post_type).'s';
return $keys;
}
function load_page() {
if (isset($_POST['options_update'])) add_filter ('genesis_club_save_social_settings', array($this,'update_social_count'));
add_action('genesis_club_social_settings', array($this, 'add_social_count_metabox'));
parent::load_page();
$this->set_tooltips(array_merge($this->get_tips(), $this->pro_tips));
add_action ('admin_enqueue_scripts',array($this, 'enqueue_styles'));
add_action ('admin_enqueue_scripts',array($this, 'enqueue_scripts'));
}
function add_social_count_metabox() {
$this->add_meta_box('social', 'Social Counts', 'social_count_panel', array('options' => $this->social->get_options()));
}
function enqueue_styles() {
wp_enqueue_style('social-admin', plugins_url('styles/social-admin.css', dirname(__FILE__)), array(),GENESIS_CLUB_VERSION);
}
function enqueue_scripts() {
wp_enqueue_script('social-admin', plugins_url('scripts/jquery.social-admin.js', dirname(__FILE__)), array('jquery-ui-core','jquery-ui-sortable'));
}
function switch_button($id, $name, $v) {
$on = $this->social->check_switch($v);
return sprintf('<div class="switch-link"><a href="#" rel="true" class="link-true %4$s"></a><a href="#" rel="false"
class="link-false %5$s"></a></div><input id="%1$s" name="%2$s" class="switch-value" type="hidden" value="%3$s" />',
$id, $name, $v, $on ? 'active' : '', $on ? '' : 'active');
}
private function derive_buttons($networks) {
$buttons = array();
$list = explode(',',$networks['order']);
foreach($list as $button) if (array_key_exists($button,$networks) && $networks[$button]=='true')
$buttons[] = $button;
return implode(',',$buttons);
}
function update_social_count($new_options) {
if (empty($_POST['networks']['order'])) $_POST['networks'] = $this->social->get_pro_defaults('networks');
$new_options['networks'] = shortcode_atts($this->social->get_pro_defaults('networks'), $_POST['networks']);
$new_options['contacts'] = wp_parse_args($_POST['contacts'], $this->social->get_pro_defaults('contacts'));
$new_options['floating'] = wp_parse_args($_POST['floating'], $this->social->get_pro_defaults('floating'));
$new_options['settings'] = $this->social->get_pro_defaults('settings');
$new_options['settings']['buttons'] = $this->derive_buttons($new_options['networks']);
$new_options['styling'] = wp_parse_args($_POST['styling'], $this->social->get_pro_defaults('styling'));
$new_options['display'] = wp_parse_args($_POST['display'], $this->social->get_pro_defaults('display'));
if (isset($_POST['reset_seeds']) && $_POST['reset_seeds']) {
$this->delete_counts_cache();
delete_option(Genesis_Club_Social_Counts::SEEDING);
$new_options['seeds'] = $this->social->get_pro_defaults('seeds');
} else {
$new_options['seeds'] = wp_parse_args($_POST['seeds'], $this->social->get_pro_defaults('seeds'));
$old_seeds = $this->social->get_option('seeds');
if (isset($old_seeds['kickstart'])
&& isset($new_options['seeds']['kickstart'])
&& ($old_seeds['kickstart'] !== $new_options['seeds']['kickstart'] ))
$this->delete_counts_cache(); //delete cached results so you can see impact of changes
}
return $new_options;
}
function add_page_visibility($content, $post) {
return $content . $this->fetch_page_visibility($post);
}
function fetch_page_visibility($post) {
$key = self::TOGGLE_SOCIAL;
$meta_key = $this->social->get_toggle_meta_key($post->post_type);
return $this->form_field($key, $key,
__(strpos($meta_key, 'hide') !== FALSE ? 'Do not show the social panel on this page' : 'Show the social panel on this page'),
get_post_meta($post->ID, $meta_key, true), 'checkbox', array(), array(), 'br') ;
}
function save_page_visibility($post_id) {
$key = self::TOGGLE_SOCIAL;
$post_type = get_post_type( $post_id);
$meta_key = $this->social->get_toggle_meta_key($post_type);
update_post_meta( $post_id, $meta_key, array_key_exists($key, $_POST) ? $_POST[$key] : false);
}
function get_options_table() {
global $wpdb, $table_prefix;
$prefix = $table_prefix ? $table_prefix : $wpdb->prefix;
return $prefix.'options';
}
function delete_counts_cache() {
global $wpdb;
$table = $this->get_options_table();
$wpdb->query("DELETE FROM ".$table." WHERE option_name LIKE '_transient_" . Genesis_Club_Social_Counts::TRANSIENT_PREFIX . "%' ");
$wpdb->query("DELETE FROM ".$table." WHERE option_name LIKE '_transient_timeout_" . Genesis_Club_Social_Counts::TRANSIENT_PREFIX . "%' ");
}
private function social_form_field($id, $section, $val, $type, $options = array(), $args = array()) {
$fld_id = 'social_setting_'.$id;
$fld_name = $section . '[' . $id . ']';
$label = array_key_exists('tip', $args) ? $args['tip'] : $id;
if ('switch'==$type) $val = $this->switch_button($fld_id, $fld_name, $val);
return $this->form_field($fld_id, $fld_name, $label, $val, $type, $options, $args) ;
}
private function networks_panel($post,$networks){
$networks_order = $networks['order'];
if (empty($networks_order)) $networks_order = $this->social->get_default_order();
$ordered_networks = explode(',',$networks_order);
$ordered_networks = array_keys(array_flip($ordered_networks)+$this->social->get_pro_defaults('networks') );
$list = '';
foreach($ordered_networks as $network) if ($name = $this->social->get_network_name($network)) {
$list .= sprintf('<li rel="%1$s">',$network);
$list .= $this->switch_button('social_'.$network, 'networks['.$network.']', $networks[$network]);
$list .= sprintf ('<h4>%1$s</h4></li>',$name);
}
return sprintf ('<p>%1$s.</p><ul class="social-networks">%2$s</ul><input type="hidden" id="network-order" name="networks[order]" value="%3$s" />',
__('Enable the social media networks as required and drag the items below into your preferred order'), $list, $networks_order);
}
private function contacts_panel($post, $contacts){
return
$this->social_form_field('txtPrint', 'contacts', $contacts['txtPrint'], 'text', array(), array('size' => '15')) .
$this->social_form_field('txtEmail', 'contacts', $contacts['txtEmail'], 'text', array(), array('size' => '15')) .
$this->social_form_field('email', 'contacts', $contacts['email'], 'text', array(), array('size' => '40')) .
$this->social_form_field('twitterId', 'contacts', $contacts['twitterId'], 'text', array(), array('size' => '15'));
}
private function floating_panel($post, $floating){
$floating = wp_parse_args($floating, $this->social->get_pro_defaults('floating'));
return
$this->social_form_field('style', 'floating', $floating['style'], 'select', $this->social->get_selections('style')).
$this->social_form_field('location', 'floating', $floating['location'], 'select', $this->social->get_selections('location')) .
$this->social_form_field('offsetLocation', 'floating', $floating['offsetLocation'], 'text', array(), array('size' => 7, 'suffix' => 'px')) .
$this->social_form_field('align', 'floating', $floating['align'], 'select', $this->social->get_selections('align')) .
$this->social_form_field('offsetAlign', 'floating', $floating['offsetAlign'], 'text', array(), array('size' => 7, 'suffix' => 'px')) .
$this->social_form_field('center', 'floating', $floating['center'], 'text', array(), array('size' => 7, 'suffix' => 'px')) .
$this->social_form_field('size', 'floating', $floating['size'], 'select', $this->social->get_selections('size')) .
$this->social_form_field('total', 'floating', $floating['total'], 'switch') .
$this->social_form_field('width', 'floating', $floating['width'], 'text', array(), array('size' => 7, 'suffix' => 'px')) .
$this->social_form_field('minimum_device_width', 'floating', $floating['minimum_device_width'], 'text', array(), array('size' => 7, 'suffix' => 'px'));
}
private function styling_panel($post, $styling){
if (empty($styling['background_color'])) $styling['background_color'] = 'transparent';
return
$this->social_form_field('skin', 'styling', $styling['skin'], 'select', $this->social->get_selections('skin')) .
$this->social_form_field('background_color', 'styling', $styling['background_color'], 'text', array(), array('size' => 7, 'class'=> 'color-picker')) .
$this->social_form_field('css', 'styling', $styling['css'], 'textarea', array(), array('cols' => 50, 'rows' => 5)) ;
}
private function display_panel($post, $display){
$s = '';
$custom_post_types = get_post_types(array('public' => true, '_builtin' => false));
foreach ($custom_post_types as $post_type) {
$key = 'show_'.strtolower($post_type).'s';
if(!array_key_exists($key, $display)) $display[$key] = false;
$type = ucwords(__(strtolower($post_type).'s'));
$s .= $this->social_form_field($key, 'display', $display[$key], 'switch', array(),
array('tip' => 'show_custom', 'label_args' => $type));
}
return
$this->social_form_field('show_floating', 'display', $display['show_floating'], 'switch') .
$this->social_form_field('show_home', 'display', $display['show_home'], 'switch') .
$this->social_form_field('show_category', 'display', $display['show_category'], 'switch') .
$this->social_form_field('show_tag', 'display', $display['show_tag'], 'switch') .
$this->social_form_field('show_posts', 'display', $display['show_posts'], 'switch') .
$this->social_form_field('show_pages', 'display', $display['show_pages'], 'switch') .
$s;
}
private function seeds_panel($post, $seeds){
$intro = $this->social_form_field('kickstart', 'seeds', $seeds['kickstart'], 'switch')
. sprintf('<p>%1$s</p>', __('Kickstart the initial number of shares. Enter a single number or a range from which the plugin will choose a random value. For example, enter 10:50 to set the initial number of shares for each page using a random number in the range 10 to 50.'))
. sprintf('<p>%1$s</p>', __('Note that the "kickstart" impact decays to zero as the number of shares of the page increases so the numbers will be accurate in the medium term. This feature is just about giving each page a boost to increase its initial impact on social media'));
if (!is_array($seeds)) $seeds = $this->social->get_pro_defaults('seeds');
$s = '' ;
foreach ((array)$seeds['networks'] as $network => $range) {
$s .= $this->social_form_field($network, 'seeds[networks]', $range, 'text', array(), array('size' => '20')) ;
}
$s .= '<p><input type="hidden" id="reset_seeds" name="reset_seeds" value="0" /> Click the link to <a href="#" onclick="document.getElementById(\'reset_seeds\').value=1; document.getElementsByName(\'options_update\')[0].click()">clear</a> kickstart values for all pages on this site.</p>';
return $intro . $s;
}
function social_count_panel($post,$metabox) {
$options = $metabox['args']['options'];
print $this->tabbed_metabox( $metabox['id'], array(
'Display' => $this->display_panel($post, $options['display']),
'Floating Panel' => $this->floating_panel($post, $options['floating']),
'Styling' => $this->styling_panel($post, $options['styling']),
'Contact Info' => $this->contacts_panel($post, $options['contacts']),
'Social Networks' => $this->networks_panel($post, $options['networks']),
'Kickstart' => $this->seeds_panel($post, $options['seeds']),
'Help' => $this->help_panel(),
),1);
}
function help_panel(){
return <<< HELP_PANEL
<p>Here you can set up a Social Bar - we recommend you set it up as a floating panel for normal use.</p>
<p>Under <i>Appearance > Widgets</i> you can also set up a fixed social bar using the <i>Genesis Club Social</i> widget in the widget areas at the top and/or bottom of each post.</p>
<p>Both the floating panel and the widgets have minimum width settings so you can automatically make the widgets appear at the top and bottom of the post when the floating panel disappears. The recommended <i>Minimum Device Size</i> setting for the Floating Panel is typically in the range 960 to 1080 pixels.</p>
<p>People tend to share posts that are liked by others so we have added the <i>Kickstart</i> feature to allow you to get a temporary boost to the number of shares. </p>
HELP_PANEL;
}
}