Plugin Directory

Changeset 1091838


Ignore:
Timestamp:
02/16/2015 10:05:54 PM (11 years ago)
Author:
osdwebdev
Message:

3.3 Release

Location:
osd-social-media-sharing
Files:
17 added
8 edited

Legend:

Unmodified
Added
Removed
  • osd-social-media-sharing/trunk/includes/OSDSocialShare.php

    r1088465 r1091838  
    33defined('ABSPATH') or die("No script kiddies please!");
    44
    5 $osd_social_media_sharing = new OSDSocialShare;
    6 
    75class OSDSocialShare {
    86    private $args = null;
    9     private $user_settings = array("services" => array());
     7    private $options = null;
     8    public $defaults = array(
     9        "label" => "Share this:",
     10        "target" => "new",
     11        "emailTo" => "someone@example.com",
     12        "post_types" => array("post" => "1"),
     13        "services" => array(
     14            "facebook" => array(
     15                "url" => "https://www.facebook.com/sharer/sharer.php?u={{CURRENT_URL}}",
     16                "enabled" => 1,
     17                "button-type" => "icon",
     18            ),
     19            "twitter" => array(
     20                "url" => "https://twitter.com/intent/tweet?text={{POST_TITLE}}&url={{CURRENT_URL}}",
     21                "enabled" => 1,
     22                "button-type" => "icon",
     23            ),
     24            "google" => array(
     25                "url" => "https://plus.google.com/share?url={{CURRENT_URL}}",
     26                "enabled" => 1,
     27                "button-type" => "icon",
     28            ),
     29            "linkedIn" => array(
     30                "url" => "https://www.linkedin.com/shareArticle?mini=true&url={{CURRENT_URL}}&title={{POST_TITLE}}&summary=&source={{SITE_NAME}}",
     31                "enabled" => 1,
     32                "button-type" => "icon",
     33            ),
     34            "pinterest" => array(
     35                "url" => "http://www.pinterest.com/pin/create/button/?url={{CURRENT_URL}}&description={{POST_TITLE}}&media=",
     36                "enabled" => 1,
     37                "button-type" => "icon",
     38            ),
     39            "email" => array(
     40                "url" => "mailto:{{EMAIL_TO}}?subject={{EMAIL_SUBJECT}}&body={{EMAIL_BODY}}",
     41                "enabled" => 1,
     42                "button-type" => "icon",
     43            ),
     44            "reddit" => array(
     45                "url" => "http://www.reddit.com/submit/?url={{CURRENT_URL}}",
     46                "button-type" => "icon",
     47            )
     48        )
     49    );
    1050
    11     function __construct($args = NULL) {
     51
     52    // Constructor
     53    function __construct($args = NULL) {
    1254        $this->args = $args;
    13         $this->user_settings = get_option('osd_social_share_options');
     55        $this->options = get_option("osd_social_share_options");
     56        $this->options = ($this->options == false) ? array() : $this->options;
    1457
    15         add_action('wp', array($this, 'filter_the_content'));
    16         add_filter('widget_text', array($this, 'filter_text_widgets'));
    17         add_shortcode('osd_social_media_sharing', array($this, 'replace_shortcode'));
     58        // Populate the default services classes (this makes sure anything newly added to the service arrays will show up in updates)
     59        foreach ($this->defaults["services"] as $name => $service) {
     60            foreach ($service as $key => $value) {
     61                if (!isset($this->options["services"][$name][$key]) || $this->options["services"][$name][$key] == "") {
     62                    $this->options["services"][$name][$key] = $this->defaults["services"][$name][$key];
     63                }
     64            }
     65            if (!isset($this->options["services"][$name]) || $this->options["services"][$name] == "") {
     66                $this->options["services"][$name] = $this->defaults["services"][$name];
     67            }
     68        }
    1869
    19         // Load style sheet
    20         add_action('wp_enqueue_scripts', array($this, 'add_style'));       
     70        // Populate the other defaults
     71        foreach ($this->defaults as $key => $value) {
     72            if (!isset($this->options[$key]) || $this->options[$key] == "") {
     73                $this->options[$key] = $this->defaults[$key];
     74            }
     75        }
     76
     77        // Add front-end filters
     78        if (!is_admin()) {
     79            add_action("wp", array($this, "filter_the_content"));
     80            add_filter("widget_text", array($this, "filter_text_widgets"));
     81            add_shortcode("osd_social_media_sharing", array($this, "replace_shortcode"));
     82
     83            // Load style sheet
     84            add_action("wp_enqueue_scripts", array($this, "add_style"));
     85        }
    2186    }
    2287
     88
     89    // Retrieve options from this class
     90    public function get_options() {
     91        return $this->options;
     92    }
     93
     94
     95    // Filter the content
    2396    public function filter_the_content() {
    2497        if(is_main_query() && is_singular()) {
    2598            global $post;
    26             $options = $this->user_settings;
    2799            $hide = get_post_meta($post->ID, 'osd_remove_sms_icons', true);
    28100
    29101            if ($hide != 1
    30                 && isset($options['post_types'])
    31                 && count($options['post_types']) > 0
    32                 && isset($options['post_types'][$post->post_type])) {
     102                && isset($this->options['post_types'])
     103                && count($this->options['post_types']) > 0
     104                && isset($this->options['post_types'][$post->post_type])) {
    33105                $post->post_content .= "[osd_social_media_sharing]";
    34106            }
     
    36108    }
    37109
     110
     111    // Adds styling for the front-end
    38112    public function add_style() {
    39113        wp_enqueue_style('osd_sms_css', plugins_url('osd-social-media-sharing/includes/style.css'));
    40114    }
    41115
     116
     117    // Creates a HTML share link
    42118    private function share_link($platform, $button_title, $custom_url) {
    43         $target = ($this->user_settings['target'] == 'new' && $platform != "email") ? "_blank" : "_self";
     119        $target = ($this->options["target"] == "new" && $platform != "email") ? "_blank" : "_self";
     120        $protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != '') ? "https://" : "http://";
     121        $searches = array(
     122            "{{SITE_NAME}}",
     123            "{{CURRENT_URL}}",
     124            "[page]",
     125            "{{POST_TITLE}}",
     126            "[title]",
     127            "{{EMAIL_TO}}",
     128            "{{EMAIL_SUBJECT}}",
     129            "{{EMAIL_BODY}}",
     130        );
     131        $replacements = array(
     132            urlencode(get_bloginfo("name")),
     133            urlencode($protocol.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']),
     134            urlencode($protocol.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']),
     135            urlencode(get_the_title()),
     136            urlencode(get_the_title()),
     137            rawurlencode($this->options['emailTo']),
     138            rawurlencode(get_the_title()),
     139            rawurlencode(get_permalink()),
     140        );
     141        $url = str_replace($searches, $replacements, $custom_url);
    44142
    45         switch ($platform) {
    46             case 'facebook':
    47                 $url = "https://www.facebook.com/sharer/sharer.php?u={$this->current_url}";
    48                 break;
    49             case 'twitter':
    50                 $url = "https://twitter.com/intent/tweet?text={$this->post_title}&url={$this->current_url}";
    51                 break;
    52             case 'google':
    53                 $url = "https://plus.google.com/share?url={$this->current_url}";
    54                 break;
    55             case 'linkedIn':
    56                 $url = "https://www.linkedin.com/shareArticle?mini=true&url={$this->current_url}&title={$this->post_title}&summary={$this->text}&source={$this->site_name}";
    57                 break;
    58             case 'pinterest':
    59                 $url = "http://www.pinterest.com/pin/create/button/?url={$this->current_url}&description={$this->post_title}&media=";
    60                 break;
    61             case 'email':
    62                 $url = "mailto:{$this->email_to}?subject={$this->email_subject}&body={$this->email_body}";
    63                 break;
    64             default:
    65                 $search = array("[page]", "[title]");
    66                 $replacements = array($this->current_url, $this->post_title);
    67                 $url = str_replace($search, $replacements, $custom_url);
    68                 break;
    69         }
    70143        // Put the url in an attribute to prevent Pinterest's official pinit script from hijacking the image
    71144        return "<a class='osd-sms-link' data-platform='{$platform}' target='{$target}' title='{$button_title}' href='#' data-url='{$url}' rel='nofollow'>";
    72145    }
     146
    73147
    74148    // Shortcode implementation
     
    77151    }
    78152
     153
     154    // Shortcode function (everything runs on the shortcode)
    79155    function replace_shortcode($atts = array()) {
    80         if (!$options = $this->user_settings) {
    81             return;
    82         }
    83         $html = "<div class='osd-sms-title'>{$options['label']}</div>";
     156        $html = "<div class='osd-sms-title'>{$this->options['label']}</div>";
     157        foreach ($this->options["services"] as $platform => $link) {
     158            $button_title = (isset($link['service-name'])) ? $link['service-name'] : ucfirst($platform);
     159            $button_title = "Click to share on ".$button_title;
     160            $custom_url = (isset($link['url'])) ? $link['url'] : '';
    84161
    85         //set vars for share_link here
    86         $this->site_name = urlencode(get_bloginfo('name'));
    87         $protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != '') ? "https://" : "http://";
    88         $this->current_url = urlencode($protocol.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
    89         $this->text = '';
    90         $this->post_title = urlencode(get_the_title());
    91         $this->email_to = rawurlencode($options['emailTo']);
    92         $this->email_subject = rawurlencode(get_the_title());
    93         $this->email_body = rawurlencode(get_permalink());
    94 
    95         foreach ($options['services'] as $platform => $option) {
    96             $button_title = (isset($option['service-name'])) ? $option['service-name'] : ucfirst($platform);
    97             $button_title = "Click to share on ".$button_title;
    98             $custom_url = (isset($option['url'])) ? $option['url'] : '';
    99 
    100             if (isset($option['enabled']) && $option['enabled'] == 1) {
    101                 if (isset($option['button-type']) && $option['button-type'] == 'icon') {
    102                     if (isset($option['icon']) && $option['icon'] != '') {
    103                         $html .= "<div class='osd-sms-icon-button'>".$this->share_link($platform, $button_title, $custom_url)."<img src='".wp_get_attachment_url($option['icon'])."' /></a></div>";
     162            if (isset($link['enabled']) && $link['enabled'] == 1) {
     163                if (isset($link['button-type']) && $link['button-type'] == 'icon') {
     164                    if (isset($link["icon"]) && $link["icon"] != "") {
     165                        $html .= "<div class='osd-sms-icon-button'>".$this->share_link($platform, $button_title, $custom_url)."<img src='".wp_get_attachment_url($link['icon'])."' /></a></div>";
    104166                    } else {
    105167                        $html .= "<div class='osd-sms-icon-button osd-no-custom-icon'>".$this->share_link($platform, $button_title, $custom_url)."</a></div>";
    106168                    }
    107169                } else {
    108                     if (isset($option['service-name'])) {
    109                         $html .= "<div class='osd-sms-text-button'>".$this->share_link($platform, $button_title, $custom_url).$option['service-name']."</a></div>";
     170                    if (isset($link["service-name"])) {
     171                        $html .= "<div class='osd-sms-text-button'>".$this->share_link($platform, $button_title, $custom_url).$link['service-name']."</a></div>";
    110172                    } else {
    111173                        $html .= "<div class='osd-sms-text-button'>".$this->share_link($platform, $button_title, $custom_url).ucfirst($platform)."</a></div>";
     
    119181    }
    120182}
     183
     184$osd_social_media_sharing = new OSDSocialShare();
  • osd-social-media-sharing/trunk/includes/global_settings.php

    r1074385 r1091838  
    33defined('ABSPATH') or die("No script kiddies please!");
    44
    5 //SETTINGS PAGE
    6 $settingsPage = new OSDSocialShareSettings();
     5// SETTINGS PAGE
     6$settingsPage = new OSDSocialShareSettings($osd_social_media_sharing->get_options());
    77
    88class OSDSocialShareSettings {
    99    private $options;
    1010
    11     public function __construct() {
     11    public function __construct($options) {
     12        $this->options = $options;
    1213        add_action('admin_menu', array($this, 'add_submenu_page'));
    1314        add_action('admin_init', array($this, 'page_init'));
     
    3233    //create options page
    3334    public function create_admin_page() {
    34         // Set class property
    35         $this->options = get_option('osd_social_share_options');
    3635        ?>
    3736        <div class="wrap">
     
    169168        printf(
    170169            '<input type="text" id="emailTo" name="osd_social_share_options[emailTo]" value="%s" />',
    171             isset($this->options['emailTo']) ? esc_attr($this->options['emailTo']) : 'someone@example.com'
     170            isset($options['emailTo']) ? esc_attr($options['emailTo']) : 'someone@example.com'
    172171        );
    173172    }
    174173
    175174    public function services_callback() {
     175        global $osd_social_media_sharing;
    176176        // Put the services in order
    177177        $sortBy = array();
     
    179179             $sortBy[] = $service['order'];
    180180        }
    181         array_multisort($sortBy, SORT_ASC, $this->options['services']);       
     181        array_multisort($sortBy, SORT_ASC, $this->options['services']);
    182182
    183183        echo
     
    199199
    200200        $counter = 0;
    201         $stock_services = array('facebook', 'twitter', 'google', 'linkedIn', 'pinterest', 'email');
    202201        foreach ($this->options['services'] as $id => $val) {
    203202            $counter++;
    204             $stock_service = (in_array($id, $stock_services)) ? true : false;
     203            $stock_service = (isset($osd_social_media_sharing->defaults["services"][$id])) ? true : false;
    205204            $service_name = ($stock_service) ? $id : $val['service-name'];
    206205            $icon_selected = ' selected="selected"';
     
    216215            }
    217216
    218             $enabled_checked = (isset($val['enabled'])) ? ' checked="checked"' : '';
     217            $enabled_checked = (isset($val["enabled"]) && $val["enabled"] == "1") ? ' checked="checked"' : '';
    219218            $url = (isset($val['url'])) ? $val['url'] : '';
    220219            $icon = (isset($val['icon'])) ? $val['icon'] : '';
    221             // $order = (isset($val['order']) && $val['order'] != "") ? $val['order'] : $counter;
    222220            $order = $counter;
    223221            $icon_url = ($icon != '') ? "<img src='".wp_get_attachment_url($icon)."' />" : "<div class='osd-sms-icon-button osd-no-custom-icon'><div class='osd-sms-link' data-platform='{$id}'></div></div>";
  • osd-social-media-sharing/trunk/includes/installation_actions.php

    r1074931 r1091838  
    11<?php
    22// Prevent direct access to file
    3 defined('ABSPATH') or die("No script kiddies please!");
     3defined("ABSPATH") or die("No script kiddies please!");
    44
    5 $options = get_option('osd_social_share_options');
    6 if ($options === false || !isset($options['services']['email'])) {
    7     $default_options = array(
    8         'label' => 'Share this:',
    9         'target' => 'new',
    10         'emailTo' => 'someone@example.com',
    11         'post_types' => array('post' => '1'),
    12         'services' => array(
    13             'email' => array(
    14                     'order' => '1',
    15                     'button-type' => 'icon',
    16                     'icon' => '',
    17                     'enabled' => '1'
    18             ),
    19             'twitter' => array(
    20                     'order' => '2',
    21                     'button-type' => 'icon',
    22                     'icon' => '',
    23                     'enabled' => '1'
    24                 ),
    25             'linkedIn' => array(
    26                     'order' => '3',
    27                     'button-type' => 'icon',
    28                     'icon' => '',
    29                     'enabled' => '1'
    30             ),
    31             'google' => array(
    32                     'order' => '4',
    33                     'button-type' => 'icon',
    34                     'icon' => '',
    35                     'enabled' => '1'
    36             ),
    37             'pinterest' => array(
    38                     'order' => '5',
    39                     'button-type' => 'icon',
    40                     'icon' => '',
    41                     'enabled' => '1'
    42             ),
    43             'facebook' => array(
    44                     'order' => '6',
    45                     'button-type' => 'icon',
    46                     'icon' => '',
    47                     'enabled' => '1'
    48             )
    49         )
    50     );
    51 
     5$options = get_option("osd_social_share_options");
     6if ($options === false || !isset($options["services"]["email"])) {
    527    if ($options === false) {
    53         add_option('osd_social_share_options', $default_options, '', 'yes');
     8        add_option("osd_social_share_options", $osd_social_media_sharing->defaults, "", "yes");
    549    } else {
    55         update_option('osd_social_share_options', $default_options);
     10        update_option("osd_social_share_options", $osd_social_media_sharing->defaults);
    5611    }
    5712}
  • osd-social-media-sharing/trunk/includes/js.php

    r1088465 r1091838  
    22// Injects the OSD Social Sharing JavaScript into the footer of non-admin pages
    33function osd_sms_js() {
     4    global $osd_social_media_sharing;
     5    $options = $osd_social_media_sharing->get_options();
    46    ?>
    57    <script>
     
    1012                "linkedIn": [520, 475],
    1113                "pinterest": [850, 700],
     14                "reddit": [600, 500],
    1215                "default": [520, 300],
    1316            }
     
    4750                        document.querySelector('.osd-image-picker-modal').className += " osd-sms-show";
    4851                    }
    49                 } else if (platform !== "email" && platform !== "print") {
     52                } else {
    5053                    open_link(this, ev);
    5154                }
  • osd-social-media-sharing/trunk/includes/style.css

    r1074385 r1091838  
    4949    display: block;
    5050}
    51 .osd-sms-icon-button.osd-no-custom-icon > .osd-sms-link { width: 32px; height: 32px; background-image: url("../images/icons.png"); background-repeat: no-repeat; background-size: 100% auto; background-position: 0px 0%; }
    52 .osd-sms-icon-button.osd-no-custom-icon > [data-platform=email] { background-position: 0px 16.666666%; }
    53 .osd-sms-icon-button.osd-no-custom-icon > [data-platform=twitter] { background-position: 0px 33.333333%; }
    54 .osd-sms-icon-button.osd-no-custom-icon > [data-platform=pinterest] { background-position: 0px 50%; }
    55 .osd-sms-icon-button.osd-no-custom-icon > [data-platform=linkedIn] { background-position: 0px 66.666666%; }
    56 .osd-sms-icon-button.osd-no-custom-icon > [data-platform=google] { background-position: 0px 83.333333%; }
    57 .osd-sms-icon-button.osd-no-custom-icon > [data-platform=facebook] { background-position: 0px 100%; }
     51.osd-sms-icon-button.osd-no-custom-icon > .osd-sms-link { width: 32px; height: 32px; background-image: url("../images/icons.png"); background-repeat: no-repeat; background-size: 100% auto; background-position: 0px 0px; }
     52.osd-sms-icon-button.osd-no-custom-icon > [data-platform=email] { background-position: 0px 14.285714%; }
     53.osd-sms-icon-button.osd-no-custom-icon > [data-platform=twitter] { background-position: 0px 28.57142858%; }
     54.osd-sms-icon-button.osd-no-custom-icon > [data-platform=pinterest] { background-position: 0px 42.857142%; }
     55.osd-sms-icon-button.osd-no-custom-icon > [data-platform=linkedIn] { background-position: 0px 57.142857%; }
     56.osd-sms-icon-button.osd-no-custom-icon > [data-platform=google] { background-position: 0px 71.428571%; }
     57.osd-sms-icon-button.osd-no-custom-icon > [data-platform=facebook] { background-position: 0px 85.714285%; }
     58.osd-sms-icon-button.osd-no-custom-icon > [data-platform=reddit] { background-position: 0px 100%; }
    5859
    5960
  • osd-social-media-sharing/trunk/osd_social_media_sharing.php

    r1088465 r1091838  
    44Plugin URI: http://outsidesource.com
    55Description: Add buttons to share any of your content on facebook, twitter, google plus, pinterest, email and more.
    6 Version: 3.2
     6Version: 3.3
    77Author: OSD Web Development Team
    88Author URI: http://outsidesource.com
     
    1313defined('ABSPATH') or die("No script kiddies please!");
    1414
     15// Include the core
     16include_once("includes/OSDSocialShare.php");
     17
    1518if (is_admin()) {
    16     include_once('includes/global_settings.php');
    17     include_once('includes/post_settings.php');
     19    include_once("includes/global_settings.php");
     20    include_once("includes/post_settings.php");
    1821} else {
    19     include_once('includes/OSDSocialShare.php');
    20     include_once('includes/js.php');
     22    include_once("includes/js.php");
    2123}
     24
    2225
    2326// Activation functions
    2427function osd_social_share_activate() {
    25     include_once('includes/installation_actions.php');
     28    include_once("includes/installation_actions.php");
    2629}
    27 register_activation_hook(__FILE__, 'osd_social_share_activate');
     30register_activation_hook(__FILE__, "osd_social_share_activate");
     31
    2832
    2933// Add settings page link to plugins page
     
    3337    return $links;
    3438}
    35 add_filter("plugin_action_links_".plugin_basename(__FILE__), 'osd_social_share_settings_link_generate');
     39add_filter("plugin_action_links_".plugin_basename(__FILE__), "osd_social_share_settings_link_generate");
  • osd-social-media-sharing/trunk/readme.txt

    r1088465 r1091838  
    44Requires at least: 3.4
    55Tested up to: 4.1
    6 Stable tag: 3.2
     6Stable tag: 3.3
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    4040
    4141== Changelog ==
     42
     43= 3.3 =
     44* Fixed bug with email link
     45* Added Reddit share link
     46* General maintainability improvements
    4247
    4348= 3.2 =
Note: See TracChangeset for help on using the changeset viewer.