Changeset 1091838
- Timestamp:
- 02/16/2015 10:05:54 PM (11 years ago)
- Location:
- osd-social-media-sharing
- Files:
-
- 17 added
- 8 edited
-
tags/3.3 (added)
-
tags/3.3/images (added)
-
tags/3.3/images/icon.png (added)
-
tags/3.3/images/icons.png (added)
-
tags/3.3/images/icons.svg (added)
-
tags/3.3/includes (added)
-
tags/3.3/includes/OSDSocialShare.php (added)
-
tags/3.3/includes/admin_js.js (added)
-
tags/3.3/includes/admin_style.css (added)
-
tags/3.3/includes/global_settings.php (added)
-
tags/3.3/includes/installation_actions.php (added)
-
tags/3.3/includes/js.php (added)
-
tags/3.3/includes/post_settings.php (added)
-
tags/3.3/includes/style.css (added)
-
tags/3.3/osd_social_media_sharing.php (added)
-
tags/3.3/readme.txt (added)
-
tags/3.3/uninstall.php (added)
-
trunk/images/icons.png (modified) (previous)
-
trunk/includes/OSDSocialShare.php (modified) (4 diffs)
-
trunk/includes/global_settings.php (modified) (6 diffs)
-
trunk/includes/installation_actions.php (modified) (1 diff)
-
trunk/includes/js.php (modified) (3 diffs)
-
trunk/includes/style.css (modified) (1 diff)
-
trunk/osd_social_media_sharing.php (modified) (3 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
osd-social-media-sharing/trunk/includes/OSDSocialShare.php
r1088465 r1091838 3 3 defined('ABSPATH') or die("No script kiddies please!"); 4 4 5 $osd_social_media_sharing = new OSDSocialShare;6 7 5 class OSDSocialShare { 8 6 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 ); 10 50 11 function __construct($args = NULL) { 51 52 // Constructor 53 function __construct($args = NULL) { 12 54 $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; 14 57 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 } 18 69 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 } 21 86 } 22 87 88 89 // Retrieve options from this class 90 public function get_options() { 91 return $this->options; 92 } 93 94 95 // Filter the content 23 96 public function filter_the_content() { 24 97 if(is_main_query() && is_singular()) { 25 98 global $post; 26 $options = $this->user_settings;27 99 $hide = get_post_meta($post->ID, 'osd_remove_sms_icons', true); 28 100 29 101 if ($hide != 1 30 && isset($ options['post_types'])31 && count($ options['post_types']) > 032 && 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])) { 33 105 $post->post_content .= "[osd_social_media_sharing]"; 34 106 } … … 36 108 } 37 109 110 111 // Adds styling for the front-end 38 112 public function add_style() { 39 113 wp_enqueue_style('osd_sms_css', plugins_url('osd-social-media-sharing/includes/style.css')); 40 114 } 41 115 116 117 // Creates a HTML share link 42 118 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); 44 142 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 }70 143 // Put the url in an attribute to prevent Pinterest's official pinit script from hijacking the image 71 144 return "<a class='osd-sms-link' data-platform='{$platform}' target='{$target}' title='{$button_title}' href='#' data-url='{$url}' rel='nofollow'>"; 72 145 } 146 73 147 74 148 // Shortcode implementation … … 77 151 } 78 152 153 154 // Shortcode function (everything runs on the shortcode) 79 155 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'] : ''; 84 161 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>"; 104 166 } else { 105 167 $html .= "<div class='osd-sms-icon-button osd-no-custom-icon'>".$this->share_link($platform, $button_title, $custom_url)."</a></div>"; 106 168 } 107 169 } 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>"; 110 172 } else { 111 173 $html .= "<div class='osd-sms-text-button'>".$this->share_link($platform, $button_title, $custom_url).ucfirst($platform)."</a></div>"; … … 119 181 } 120 182 } 183 184 $osd_social_media_sharing = new OSDSocialShare(); -
osd-social-media-sharing/trunk/includes/global_settings.php
r1074385 r1091838 3 3 defined('ABSPATH') or die("No script kiddies please!"); 4 4 5 // SETTINGS PAGE6 $settingsPage = new OSDSocialShareSettings( );5 // SETTINGS PAGE 6 $settingsPage = new OSDSocialShareSettings($osd_social_media_sharing->get_options()); 7 7 8 8 class OSDSocialShareSettings { 9 9 private $options; 10 10 11 public function __construct() { 11 public function __construct($options) { 12 $this->options = $options; 12 13 add_action('admin_menu', array($this, 'add_submenu_page')); 13 14 add_action('admin_init', array($this, 'page_init')); … … 32 33 //create options page 33 34 public function create_admin_page() { 34 // Set class property35 $this->options = get_option('osd_social_share_options');36 35 ?> 37 36 <div class="wrap"> … … 169 168 printf( 170 169 '<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' 172 171 ); 173 172 } 174 173 175 174 public function services_callback() { 175 global $osd_social_media_sharing; 176 176 // Put the services in order 177 177 $sortBy = array(); … … 179 179 $sortBy[] = $service['order']; 180 180 } 181 array_multisort($sortBy, SORT_ASC, $this->options['services']); 181 array_multisort($sortBy, SORT_ASC, $this->options['services']); 182 182 183 183 echo … … 199 199 200 200 $counter = 0; 201 $stock_services = array('facebook', 'twitter', 'google', 'linkedIn', 'pinterest', 'email');202 201 foreach ($this->options['services'] as $id => $val) { 203 202 $counter++; 204 $stock_service = (i n_array($id, $stock_services)) ? true : false;203 $stock_service = (isset($osd_social_media_sharing->defaults["services"][$id])) ? true : false; 205 204 $service_name = ($stock_service) ? $id : $val['service-name']; 206 205 $icon_selected = ' selected="selected"'; … … 216 215 } 217 216 218 $enabled_checked = (isset($val[ 'enabled'])) ? ' checked="checked"' : '';217 $enabled_checked = (isset($val["enabled"]) && $val["enabled"] == "1") ? ' checked="checked"' : ''; 219 218 $url = (isset($val['url'])) ? $val['url'] : ''; 220 219 $icon = (isset($val['icon'])) ? $val['icon'] : ''; 221 // $order = (isset($val['order']) && $val['order'] != "") ? $val['order'] : $counter;222 220 $order = $counter; 223 221 $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 1 1 <?php 2 2 // Prevent direct access to file 3 defined( 'ABSPATH') or die("No script kiddies please!");3 defined("ABSPATH") or die("No script kiddies please!"); 4 4 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"); 6 if ($options === false || !isset($options["services"]["email"])) { 52 7 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"); 54 9 } else { 55 update_option( 'osd_social_share_options', $default_options);10 update_option("osd_social_share_options", $osd_social_media_sharing->defaults); 56 11 } 57 12 } -
osd-social-media-sharing/trunk/includes/js.php
r1088465 r1091838 2 2 // Injects the OSD Social Sharing JavaScript into the footer of non-admin pages 3 3 function osd_sms_js() { 4 global $osd_social_media_sharing; 5 $options = $osd_social_media_sharing->get_options(); 4 6 ?> 5 7 <script> … … 10 12 "linkedIn": [520, 475], 11 13 "pinterest": [850, 700], 14 "reddit": [600, 500], 12 15 "default": [520, 300], 13 16 } … … 47 50 document.querySelector('.osd-image-picker-modal').className += " osd-sms-show"; 48 51 } 49 } else if (platform !== "email" && platform !== "print"){52 } else { 50 53 open_link(this, ev); 51 54 } -
osd-social-media-sharing/trunk/includes/style.css
r1074385 r1091838 49 49 display: block; 50 50 } 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%; } 58 59 59 60 -
osd-social-media-sharing/trunk/osd_social_media_sharing.php
r1088465 r1091838 4 4 Plugin URI: http://outsidesource.com 5 5 Description: Add buttons to share any of your content on facebook, twitter, google plus, pinterest, email and more. 6 Version: 3. 26 Version: 3.3 7 7 Author: OSD Web Development Team 8 8 Author URI: http://outsidesource.com … … 13 13 defined('ABSPATH') or die("No script kiddies please!"); 14 14 15 // Include the core 16 include_once("includes/OSDSocialShare.php"); 17 15 18 if (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"); 18 21 } else { 19 include_once('includes/OSDSocialShare.php'); 20 include_once('includes/js.php'); 22 include_once("includes/js.php"); 21 23 } 24 22 25 23 26 // Activation functions 24 27 function osd_social_share_activate() { 25 include_once( 'includes/installation_actions.php');28 include_once("includes/installation_actions.php"); 26 29 } 27 register_activation_hook(__FILE__, 'osd_social_share_activate'); 30 register_activation_hook(__FILE__, "osd_social_share_activate"); 31 28 32 29 33 // Add settings page link to plugins page … … 33 37 return $links; 34 38 } 35 add_filter("plugin_action_links_".plugin_basename(__FILE__), 'osd_social_share_settings_link_generate');39 add_filter("plugin_action_links_".plugin_basename(__FILE__), "osd_social_share_settings_link_generate"); -
osd-social-media-sharing/trunk/readme.txt
r1088465 r1091838 4 4 Requires at least: 3.4 5 5 Tested up to: 4.1 6 Stable tag: 3. 26 Stable tag: 3.3 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 40 40 41 41 == Changelog == 42 43 = 3.3 = 44 * Fixed bug with email link 45 * Added Reddit share link 46 * General maintainability improvements 42 47 43 48 = 3.2 =
Note: See TracChangeset
for help on using the changeset viewer.