-
Notifications
You must be signed in to change notification settings - Fork 0
/
share-center-pro.php
415 lines (319 loc) · 12.8 KB
/
share-center-pro.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
<?php
/*
Plugin Name: Share Center Pro
Plugin URI: http://bit51.com/software/share-center-pro/
Description: Add common social sharing services in a widget to be used anywhere on your page or at the bottom of your posts or other content.
Version: 2.4.6
Text Domain: share-center-pro
Domain Path: /languages
Author: Bit51
Author URI: http://bit51.com
License: GPLv2
Copyright 2013 Bit51 (email : [email protected])
*/
//Require common Bit51 library
require_once( plugin_dir_path( __FILE__ ) . 'lib/bit51/bit51.php' );
if ( ! class_exists( 'bit51_scp' )) {
class bit51_scp extends Bit51 {
public $pluginversion = '0016'; //current plugin version
//important plugin information
public $hook = 'share-center-pro';
public $pluginbase = 'share-center-pro/share-center-pro.php';
public $pluginname = 'Share Center Pro';
public $homepage = 'http://bit51.com/software/share-center-pro/';
public $supportpage = 'http://wordpress.org/support/plugin/share-center-pro';
public $wppage = 'http://wordpress.org/extend/plugins/share-center-pro/';
public $accesslvl = 'manage_options';
public $paypalcode = 'QKDGZFLN3QG68';
public $plugindata = 'bit51_scp_data';
public $primarysettings = 'bit51_scp';
public $settings = array(
'bit51_scp_options' => array(
'bit51_scp' => array(
'callback' => 'scp_val_options',
'header' => '',
'pinterest' => '0',
'pinterestweight' => '50',
'facebook' => '0',
'facebookweight' => '20',
'google' => '0',
'googleweight' => '30',
'linkedin' => '0',
'linkedinweight' => '40',
'stumbleupon' => '0',
'stumbleuponweight' => '60',
'twitter' => '0',
'twitterweight' => '70',
'buffer' => '0',
'bufferweight' => '10',
'archive' => '0',
'page' => '0',
'home' => '0',
'search' => '0',
'single' => '0',
'twitteruser' => '',
'usecss' => '1',
'fbappid' => '',
'fpog' => '0',
'tcmd' => '0',
'locationsingle' => '0',
'locationlist' => '0'
)
)
);
function __construct() {
global $scpoptions, $scpdata;
//set path information
if ( ! defined( 'SCP_PP' ) ) {
define( 'SCP_PP', plugin_dir_path( __FILE__ ) );
}
if ( ! defined( 'SCP_PU' ) ) {
define( 'SCP_PU', plugin_dir_url( $this->pluginbase, __FILE__ ) );
}
//require admin page
require_once( plugin_dir_path( __FILE__ ) . 'inc/admin.php' );
new scp_admin( $this );
//require setup information
require_once( plugin_dir_path( __FILE__ ) . 'inc/setup.php' );
register_activation_hook( __FILE__, array( 'scp_setup', 'on_activate' ) );
register_deactivation_hook( __FILE__, array( 'scp_setup', 'on_deactivate' ) );
register_uninstall_hook( __FILE__, array( 'scp_setup', 'on_uninstall' ) );
$scpoptions = get_option( $this->primarysettings );
$scpdata = get_option( $this->plugindata );
if ( $scpdata['version'] != $this->pluginversion || get_option( 'scpoptions' ) != false ) {
new scp_setup( 'activate' );
}
//require widget info
require_once( plugin_dir_path( __FILE__ ) . 'inc/widget.php' );
//register the widget
add_action( 'widgets_init', array( &$this, 'scp_loadwidget' ) );
//Enqueue javascripts
add_action( 'wp_enqueue_scripts', array( &$this, 'scp_footerscripts' ) );
//add to button output to content that isn't a widget
add_filter( 'the_content', array( &$this, 'scp_addtocontent' ), 25 );
//Enqueue the stylesheet
if ( isset( $scpoptions['usecss'] ) && $scpoptions['usecss'] == 1 ) {
add_action( 'wp_print_styles', array( &$this, 'scp_addstylesheet' ) );
}
if ( ( isset( $scpoptions['fbog'] ) && $scpoptions['fbog'] == 1 ) || ( isset( $scpoptions['tcmd'] ) && $scpoptions['tcmd'] == 1 ) ) {
//Add facebook meta to header
add_action( 'wp_head', array( &$this, 'scp_addmeta' ) );
//remove jetpack OpenGraph (if needed)
if ( isset( $scpoptions['fbog'] ) && $scpoptions['fbog'] == 1 ) {
$active_plugins = get_option( 'active_plugins', array() );
if ( in_array( 'jetpack/jetpack.php', $active_plugins ) ) {
add_filter( 'jetpack_enable_opengraph', '__return_false', 99 );
}
}
}
}
/**
* Add the facebook META data to the head
*
* @return null
**/
function scp_addmeta() {
global $scpoptions, $posts, $post;
$thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
if ( is_array( $thumbnail ) && strlen( $thumbnail[0] ) > 1 ) {
$thumbnail = $thumbnail[0];
} else { //get a thumbnail from an image in the post
$content = $posts[0]->post_content;
$output = preg_match_all( '/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $content, $matches );
if ( $output > 0 ) {
$thumbnail = $matches[1][0];
} else {
$thumbnail = '';
}
}
echo "<!--## Begin Share Center Pro Scripts ## -->\n";
//add FaceBook OpenGraph Data
if ( $scpoptions['fbog'] == 1 ) {
echo "<meta property=\"og:title\" content=\"" . get_the_title( $post->ID ) . "\"/>\n" .
"<meta property=\"og:type\" content=\"article\"/>\n" .
"<meta property=\"og:url\" content=\"" . get_permalink( $post->ID ) . "\"/>\n" .
"<meta property=\"og:locale\" content=\"" . get_bloginfo( 'language' ) . "\"/>\n";
if ( strlen( $thumbnail ) > 1 ) { //only display thumbnail if an image is used
echo "<meta property=\"og:image\" content=\"" . $thumbnail . "\"/>\n";
}
echo "<meta property=\"og:site_name\" content=\"" . get_bloginfo() . "\"/>\n";
if ( strlen( get_the_author() > 1 ) ) { //only display author if needed
echo "<meta property=\"og:author\" content=\"" . get_the_author() . "\" />\n";
}
if ( is_home() || is_front_page() ) {
echo "<meta property=\"og:description\" content=\"" . get_bloginfo( 'description' ) . "\"/>\n";
} else if ( is_singular() ) {
echo "<meta property=\"og:description\" content=\"" . strip_tags( get_the_excerpt() ) . "\"/>\n";
}
if ( strlen( $scpoptions['fbappid'] > 1 ) ) {
echo "<meta property=\"fb:app_id\" content=\"" . $scpoptions['fbappid'] . "\" />\n";
}
}
//add Twitter card Data
if ( $scpoptions['tcmd'] == 1 ) {
echo "<meta name=\"twitter:card\" content=\"summary\">\n";
if ( strlen( $scpoptions['twitteruser'] > 1 ) ) {
echo "<meta name=\"twitter:site\" content=\"@" . $scpoptions['twitteruser'] . "\">\n";
}
if ( is_home() || is_front_page() ) {
echo "<meta property=\"twitter:description\" content=\"" . get_bloginfo( 'description' ) . "\"/>\n";
} else if ( is_singular() ) {
echo "<meta property=\"twitter:description\" content=\"" . strip_tags( get_the_excerpt() ) . "\"/>\n";
}
echo "<meta property=\"twitter:title\" content=\"" . get_the_title( $post->ID ) . "\"/>\n";
echo "<meta property=\"twitter:url\" content=\"" . get_permalink( $post->ID ) . "\"/>\n";
}
echo "<!--## End Share Center Pro Scripts ## -->\n";
}
/**
* Enqueue style sheet
*
* @return null
**/
function scp_addstylesheet() {
wp_register_style( 'share-center-pro', SCP_PU . 'inc/style.css' );
wp_enqueue_style( 'share-center-pro' );
}
/**
* Create a filter to add buttons to the content if not in a widget
*
* @return Object
* @param Object
**/
function scp_addtocontent( $content ) {
global $scpoptions;
//if the buttons should be on the current content then add them to the end of it
if ( ( is_archive() && $scpoptions['archive'] == 1 ) || ( is_page() && ! is_front_page() && ! is_home() && $scpoptions['page'] == 1 ) || ( ( is_front_page() || is_home() ) && $scpoptions['home'] == 1 ) || ( is_search() && $scpoptions['search'] == 1 ) || ( is_single() && $scpoptions['single'] == 1 ) ) {
//decide which location we should pick based on page type
if ( is_page() || is_single() ) {
$location = $scpoptions['locationsingle'];
} else {
$location = $scpoptions['locationlist'];
}
//add buttons before/after/both depending on user's choice
switch ( $location ) {
case '0':
return $content . $this->scp_social_buttons();
break;
case '1':
return $this->scp_social_buttons() . $content;
break;
case '2':
return $this->scp_social_buttons() . $content . $this->scp_social_buttons();
break;
default:
return $content;
break;
}
return $content . $this->scp_social_buttons();
} else {
return $content;
}
}
/**
* Load required javascripts in the footer
*
* @return null
*/
function scp_footerscripts() {
global $scpoptions;
//load the footer script
wp_enqueue_script( 'facebook', SCP_PU . 'inc/share.js', array( 'jquery' ), false, true );
}
/**
* Load the widget
* @return Null
**/
function scp_loadwidget() {
register_widget( 'SCP_Widget' );
}
/**
* Create the social button output
*
* @return null
**/
function scp_social_buttons() {
global $scpoptions, $post;
//Get the URLs
$short_url = get_post_meta( $post->ID, '_yoast_bitlylink', true );
$full_url = get_permalink( $post->ID );
if ( strlen( $short_url ) < 1 ) {
$share_url = $full_url;
} else {
$share_url = $short_url;
}
//get the twitter username
$twitteruser = stripslashes( $scpoptions['twitteruser'] );
//initialize the buttons
$buttons = '';
//lets sort the buttons by weight
$buttonarray = array(
$scpoptions['bufferweight'] => 'Buffer',
$scpoptions['facebookweight'] => 'Facebook',
$scpoptions['googleweight'] => 'Google',
$scpoptions['linkedinweight'] => 'LinkedIn',
$scpoptions['pinterestweight'] => 'Pinterest',
$scpoptions['stumbleuponweight'] => 'StumbleUpon',
$scpoptions['twitterweight'] => 'Twitter'
);
ksort ( $buttonarray );
$buttons .= "\n<!--## Begin Share Center Pro Scripts ## -->\n";
$buttons .= "<div class=\"scpclear\"></div>\n";
$buttons .= "<div id=\"share-center-pro\">\n";
if ( $scpoptions['facebook'] == 1 ) {
$buttons .= "<div id=\"fb-root\"></div>";
}
if ( strlen( $scpoptions['header'] ) > 1 ) {
$buttons .= "<div class=\"scpHeading\">" . $scpoptions['header'] . "</div>\n";
$buttons .= "<div class=\"scpclear\"></div>\n";
}
foreach ( $buttonarray as $weight => $button ) {
switch ( $button ) {
case 'Buffer':
if ( $scpoptions['buffer'] == 1 ) {
$buttons .= "<div class=\"scpBuffer\"><a href=\"http://bufferapp.com/add\" class=\"buffer-add-button\" data-url=\"" . $share_url . "\"data-count=\"vertical\" data-via=\"" . $twitteruser . "\"></a></div>\n";
}
break;
case 'Facebook':
if ( $scpoptions['facebook'] == 1 ) {
$buttons .= "<div class=\"scpFacebook\"><div class=\"fb-like\" data-href=\"" . urldecode( $share_url ) . "\" data-send=\"false\" data-layout=\"box_count\" data-width=\"450\" data-show-faces=\"false\"></div></div>\n";
}
break;
case 'Google':
if ( $scpoptions['google'] == 1 ) {
$buttons .= "<div class=\"scpGoogle\"><g:plusone size=\"tall\" href=\"" . $share_url . "\"></g:plusone></div>\n";
}
break;
case 'LinkedIn':
if ( $scpoptions['linkedin'] == 1 ) {
$buttons .= "<div class=\"scpLinkedin\"><script type=\"in/share\" data-counter=\"top\" url=\"" . $share_url . "\"></script></div>\n";
}
break;
case 'Pinterest':
if ( $scpoptions['pinterest'] == 1 ) {
$buttons .="<div class=\"scpPinterest\"><a href=\"http://pinterest.com/pin/create/button/?url=" . urlencode( $share_url ) . "&media=" . urlencode( wp_get_attachment_url( get_post_thumbnail_id( $post->ID ) ) ) . "\" class=\"pin-it-button\" count-layout=\"vertical\"><img border=\"0\" src=\"//assets.pinterest.com/images/PinExt.png\" title=\"Pin It\" /></a></div>\n";
}
break;
case 'StumbleUpon':
if ( $scpoptions['stumbleupon'] == 1 ) {
$buttons .="<div class=\"scpStumbleupon\"><su:badge layout=\"5\" location=\"" . $share_url . "\"></su:badge></div>\n";
}
break;
case 'Twitter':
if ( $scpoptions['twitter'] == 1 ) {
$buttons .= "<div class=\"scpTwitter\"><a href=\"http://twitter.com/share\" class=\"twitter-share-button\" data-url=\"" . $share_url . "\" data-counturl=\"" . $full_url . "\" data-text=\"" . get_the_title() . "\" data-count=\"vertical\" data-via=\"" . $twitteruser . "\"></a></div>\n";
}
break;
}
}
$buttons .= "<span class=\"stretch\"></span>\n";
$buttons .= "</div>\n";
$buttons .= "<div class=\"scpclear\"></div>\n";
$buttons .= "<!--## End Share Center Pro Scripts ## -->\n";
return $buttons;
}
}
}
//create plugin object
global $bit51scp;
$bit51scp = new bit51_scp();