forked from davidsneal/simplesharebuttons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple-share-buttons-adder.php
executable file
·1406 lines (1077 loc) · 50.9 KB
/
simple-share-buttons-adder.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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
Plugin Name: Simple Share Buttons Adder
Plugin URI: http://www.simplesharebuttons.com
Description: A simple plugin that enables you to add share buttons to all of your posts and/or pages.
Version: 4.6
Author: David S. Neal
Author URI: http://www.davidsneal.co.uk/
License: GPLv2
Copyright 2014 Simple Share Buttons admin@simplesharebuttons.com
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
if(WP_DEBUG !== true){
// turn error reporting off
error_reporting(0);
}
// make sure we have settings ready
// this has been introduced to exclude from excerpts
$arrSettings = get_ssba_settings();
// --------- INSTALLATION ------------ //
// run the activation function upon acitvation of the plugin
register_activation_hook( __FILE__,'ssba_activate');
// register deactivation hook
register_uninstall_hook(__FILE__,'ssba_uninstall');
// activate ssba function
function ssba_activate() {
// insert default options for ssba
add_option('ssba_version', '4.6');
add_option('ssba_image_set', 'somacro');
add_option('ssba_size', '35');
add_option('ssba_pages', '');
add_option('ssba_posts', '');
add_option('ssba_cats_archs', '');
add_option('ssba_homepage', '');
add_option('ssba_excerpts', '');
add_option('ssba_align', 'left');
add_option('ssba_padding', '6');
add_option('ssba_before_or_after', 'after');
add_option('ssba_custom_styles', '');
add_option('ssba_email_message', '');
add_option('ssba_twitter_text', '');
add_option('ssba_buffer_text', '');
add_option('ssba_flattr_user_id', '');
add_option('ssba_flattr_url', '');
add_option('ssba_share_new_window', 'Y');
add_option('ssba_link_to_ssb', 'N');
add_option('ssba_show_share_count', '');
add_option('ssba_share_count_style', 'default');
add_option('ssba_share_count_css', '');
add_option('ssba_share_count_once', 'Y');
add_option('ssba_widget_text', '');
add_option('ssba_rel_nofollow', '');
// share container
add_option('ssba_div_padding', '');
add_option('ssba_div_rounded_corners', '');
add_option('ssba_border_width', '');
add_option('ssba_div_border', '#59625c');
add_option('ssba_div_background', '');
// share text
add_option('ssba_share_text', "Don't be shellfish...");
add_option('ssba_text_placement', 'left');
add_option('ssba_font_family', 'Indie Flower');
add_option('ssba_font_color', '');
add_option('ssba_font_size', '20');
add_option('ssba_font_weight', '');
// include
add_option('ssba_selected_buttons', '');
// custom images
add_option('ssba_custom_email', '');
add_option('ssba_custom_google', '');
add_option('ssba_custom_facebook', '');
add_option('ssba_custom_twitter', '');
add_option('ssba_custom_diggit', '');
add_option('ssba_custom_linkedin', '');
add_option('ssba_custom_reddit', '');
add_option('ssba_custom_stumbleupon', '');
add_option('ssba_custom_pinterest', '');
add_option('ssba_custom_buffer', '');
add_option('ssba_custom_flattr', '');
add_option('ssba_custom_tumblr', '');
add_option('ssba_custom_print', '');
}
// uninstall ssba
function ssba_uninstall() {
//if uninstall not called from WordPress exit
if (defined('WP_UNINSTALL_PLUGIN')) {
exit();
}
// delete all options
delete_option('ssba_version');
delete_option('ssba_image_set');
delete_option('ssba_size');
delete_option('ssba_pages');
delete_option('ssba_posts');
delete_option('ssba_cats_archs');
delete_option('ssba_homepage');
delete_option('ssba_excerpts');
delete_option('ssba_align');
delete_option('ssba_padding');
delete_option('ssba_before_or_after');
delete_option('ssba_custom_styles');
delete_option('ssba_email_message');
delete_option('ssba_buffer_text');
delete_option('ssba_twitter_text');
delete_option('ssba_flattr_user_id');
delete_option('ssba_flattr_url');
delete_option('ssba_share_new_window');
delete_option('ssba_link_to_ssb');
delete_option('ssba_show_share_count');
delete_option('ssba_share_count_style');
delete_option('ssba_share_count_css');
delete_option('ssba_share_count_once');
delete_option('ssba_widget_text');
delete_option('ssba_rel_nofollow');
// share container
delete_option('ssba_div_padding');
delete_option('ssba_div_rounded_corners');
delete_option('ssba_border_width');
delete_option('ssba_div_border');
delete_option('ssba_div_background');
// share text
delete_option('ssba_share_text');
delete_option('ssba_text_placement');
delete_option('ssba_font_family');
delete_option('ssba_font_color');
delete_option('ssba_font_size');
delete_option('ssba_font_weight');
// include
delete_option('ssba_selected_buttons');
// custom images
delete_option('ssba_custom_email');
delete_option('ssba_custom_google');
delete_option('ssba_custom_facebook');
delete_option('ssba_custom_twitter');
delete_option('ssba_custom_diggit');
delete_option('ssba_custom_linkedin');
delete_option('ssba_custom_reddit');
delete_option('ssba_custom_stumbleupon');
delete_option('ssba_custom_pinterest');
delete_option('ssba_custom_buffer');
delete_option('ssba_custom_flattr');
delete_option('ssba_custom_tumblr');
delete_option('ssba_custom_print');
}
// --------- ADMIN BITS ------------ //
// add settings link on plugin page
function ssba_settings_link($links) {
// add to plugins links
array_unshift($links, '<a href="options-general.php?page=simple-share-buttons-adder">Settings</a>');
// return all links
return $links;
}
// add filter hook for plugin action links
add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'ssba_settings_link' );
// add menu to dashboard
add_action( 'admin_menu', 'ssba_menu' );
// widget class
class ssba_widget extends WP_Widget {
// construct the widget
public function __construct() {
parent::__construct(
'ssba_widget', // Base ID
'Share Buttons', // Name
array( 'description' => __( 'Simple Share Buttons Adder', 'text_domain' ), ) // Args
);
}
// extract required arguments and run the shortcode
public function widget( $args, $instance ) {
extract( $args );
$title = apply_filters( 'widget_title', $instance['title'] );
$url = $instance['url'];
$pagetitle = $instance['pagetitle'];
echo $before_widget;
if (!empty($title))
echo $before_title . $title . $after_title;
$shortcode = '[ssba';
($url != '' ? $shortcode .= ' url="' . $url . '"' : NULL);
($pagetitle != '' ? $shortcode .= ' title="' . $pagetitle . '"' : NULL);
$shortcode .= ' widget="Y"]';
echo do_shortcode($shortcode, 'text_domain' );
echo $after_widget;
}
public function form( $instance ) {
if ( isset( $instance[ 'title' ] ) ) {
$title = $instance[ 'title' ];
} else {
$title = __( 'Share Buttons', 'text_domain' );
}
$url = esc_url( $instance['url'] );
$pagetitle = esc_attr( $instance['pagetitle'] );
# Title
echo '<p><label for="' . $this->get_field_id('title') . '">' . 'Title:' . '</label><input class="widefat" id="' . $this->get_field_id('title') . '" name="' . $this->get_field_name('title') . '" type="text" value="' . $title . '" /></p>';
# URL
echo '<p><label for="' . $this->get_field_id('url') . '">' . 'URL:' . '</label><input class="widefat" id="' . $this->get_field_id('url') . '" name="' . $this->get_field_name('url') . '" type="text" value="' . $url . '" /></p>';
echo '<p class="description">Leave this blank to share the current page, or enter a URL to force one URL for all pages.</p>';
# Page title
echo '<p><label for="' . $this->get_field_id('pagetitle') . '">' . 'Page title:' . '</label><input class="widefat" id="' . $this->get_field_id('pagetitle') . '" name="' . $this->get_field_name('pagetitle') . '" type="text" value="' . $pagetitle . '" /></p>';
echo '<p class="description">Set a page title for the page being shared, leave this blank if you have not set a URL.</p>';
}
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['url'] = strip_tags( $new_instance['url'] );
$instance['pagetitle'] = strip_tags( $new_instance['pagetitle'] );
return $instance;
}
}
// add ssba to available widgets
add_action( 'widgets_init', create_function( '', 'register_widget( "ssba_widget" );' ) );
function mywidget_init() {
register_sidebar_widget('Share Buttons Widget', 'ssba_widget');
register_widget_control('Share Buttons Widget', 'ssba_widget_control');
}
// include js files and upload script
function ssba_admin_scripts() {
// all extra scripts needed
wp_enqueue_script('media-upload');
wp_enqueue_script('thickbox');
wp_enqueue_script('wp-color-picker');
wp_register_script('my-upload', plugins_url('/js/ssba_admin.js', __FILE__ ));
wp_enqueue_script('my-upload');
wp_enqueue_script('jquery-ui-sortable');
wp_enqueue_script('jquery-ui');
}
// include styles for the ssba admin panel
function ssba_admin_styles() {
// admin styles
wp_enqueue_style('thickbox');
wp_enqueue_style('wp-color-picker');
wp_register_style('ssba-styles', plugins_url('/css/style.css', __FILE__ ));
wp_enqueue_style('ssba-styles');
}
// check if viewing the admin page
if (isset($_GET['page']) && $_GET['page'] == 'simple-share-buttons-adder') {
// add the registered scripts
add_action('admin_print_styles', 'ssba_admin_styles');
add_action('admin_print_scripts', 'ssba_admin_scripts');
}
// add css scripts for page/post use
function ssba_page_scripts() {
// get settings
$arrSettings = get_ssba_settings();
// only include CSS if needed
//if (is_page() && $arrSettings['ssba_pages'] == 'Y' || is_single() && $arrSettings['ssba_posts'] == 'Y' || is_category() && $arrSettings['ssba_cats_archs'] == 'Y' || is_archive() && $arrSettings['ssba_cats_archs'] == 'Y' || is_home() && $arrSettings['ssba_homepage'] == 'Y' || $booShortCode == TRUE) {
// if reenie beenie font is selected
if ($arrSettings['ssba_font_family'] == 'Indie Flower') {
// font scripts
wp_register_style('ssbaFont', '//fonts.googleapis.com/css?family=Indie+Flower');
wp_enqueue_style( 'ssbaFont');
} else if ($arrSettings['ssba_font_family'] == 'Reenie Beanie') {
// font scripts
wp_register_style('ssbaFont', '//fonts.googleapis.com/css?family=Reenie+Beanie');
wp_enqueue_style( 'ssbaFont');
}
//}
}
// call scripts add function
add_action( 'wp_enqueue_scripts', 'ssba_page_scripts' );
// menu settings
function ssba_menu() {
// add menu page
add_options_page( 'Simple Share Buttons Adder', 'Share Buttons', 'manage_options', 'simple-share-buttons-adder', 'ssba_settings');
// query the db for current ssba settings
$arrSettings = get_ssba_settings();
// check if not yet updated to 4.6
if ($arrSettings['ssba_version'] != '4.6') {
// run the upgrade function
upgrade_ssba($arrSettings);
}
// check if any buttons have been selected
if ($arrSettings['ssba_selected_buttons'] == '' && $_GET['page'] != 'simple-share-buttons-adder') {
// output a warning that buttons need configuring and provide a link to settings
echo '<div id="ssba-warning" class="updated fade"><p>Your <strong>Simple Share Buttons</strong> need <a href="admin.php?page=simple-share-buttons-adder"><strong>configuration</strong></a> before they will appear. <strong>View the tutorial video <a href="http://www.youtube.com/watch?v=p03B4C3QMzs" target="_blank">here</a></strong></p></div>';
}
}
// the upgrade function
function upgrade_ssba($arrSettings) {
// add print button
add_option('ssba_custom_print', '');
// new for 3.8
add_option('ssba_widget_text', '');
add_option('ssba_rel_nofollow', '');
// added pre 4.5, added in 4.6 to fix notice
add_option('ssba_rel_nofollow', '');
// update version number
update_option('ssba_version', '4.6');
}
// --------- SETTINGS PAGE ------------ //
// answer form
function ssba_settings() {
//' check if user has the rights to manage options
if ( !current_user_can( 'manage_options' ) ) {
// permissions message
wp_die( __('You do not have sufficient permissions to access this page.'));
}
// variables
$htmlSettingsSaved = '';
// check for submitted form
if (isset($_POST['ssba_options'])) {
// if the nonce doesn't check out...
if (!isset($_POST['ssba_save_nonce']) || !wp_verify_nonce($_POST['ssba_save_nonce'], 'ssba_save_settings')) {
// don't save data
print 'Sorry, your nonce did not verify.';
exit;
} else { // everything seems to check out
// update existing ssba settings
update_option('ssba_image_set', $_POST['ssba_image_set']);
update_option('ssba_size', $_POST['ssba_size']);
update_option('ssba_pages', (isset($_POST['ssba_pages']) ? $_POST['ssba_pages'] : NULL));
update_option('ssba_posts', (isset($_POST['ssba_posts']) ? $_POST['ssba_posts'] : NULL));
update_option('ssba_cats_archs', (isset($_POST['ssba_cats_archs']) ? $_POST['ssba_cats_archs'] : NULL));
update_option('ssba_homepage', (isset($_POST['ssba_homepage']) ? $_POST['ssba_homepage'] : NULL));
update_option('ssba_excerpts', (isset($_POST['ssba_excerpts']) ? $_POST['ssba_excerpts'] : NULL));
update_option('ssba_align', (isset($_POST['ssba_align']) ? $_POST['ssba_align'] : NULL));
update_option('ssba_padding', $_POST['ssba_padding']);
update_option('ssba_before_or_after', $_POST['ssba_before_or_after']);
update_option('ssba_custom_styles', $_POST['ssba_custom_styles']);
update_option('ssba_email_message', stripslashes_deep($_POST['ssba_email_message']));
update_option('ssba_twitter_text', stripslashes_deep($_POST['ssba_twitter_text']));
update_option('ssba_buffer_text', stripslashes_deep($_POST['ssba_buffer_text']));
update_option('ssba_flattr_user_id', stripslashes_deep($_POST['ssba_flattr_user_id']));
update_option('ssba_flattr_url', stripslashes_deep($_POST['ssba_flattr_url']));
update_option('ssba_share_new_window', (isset($_POST['ssba_share_new_window']) ? $_POST['ssba_share_new_window'] : NULL));
update_option('ssba_link_to_ssb', (isset($_POST['ssba_link_to_ssb']) ? $_POST['ssba_link_to_ssb'] : NULL));
update_option('ssba_show_share_count', (isset($_POST['ssba_show_share_count']) ? $_POST['ssba_show_share_count'] : NULL));
update_option('ssba_share_count_style', $_POST['ssba_share_count_style']);
update_option('ssba_share_count_css', $_POST['ssba_share_count_css']);
update_option('ssba_share_count_once', (isset($_POST['ssba_share_count_once']) ? $_POST['ssba_share_count_once'] : NULL));
update_option('ssba_widget_text', $_POST['ssba_widget_text']);
update_option('ssba_rel_nofollow', (isset($_POST['ssba_rel_nofollow']) ? $_POST['ssba_rel_nofollow'] : NULL));
// share container
update_option('ssba_div_padding', $_POST['ssba_div_padding']);
update_option('ssba_div_rounded_corners', (isset($_POST['ssba_div_rounded_corners']) ? $_POST['ssba_div_rounded_corners'] : NULL));
update_option('ssba_border_width', $_POST['ssba_border_width']);
update_option('ssba_div_border', $_POST['ssba_div_border']);
update_option('ssba_div_background', $_POST['ssba_div_background']);
// text
update_option('ssba_share_text', stripslashes_deep($_POST['ssba_share_text']));
update_option('ssba_text_placement', $_POST['ssba_text_placement']);
update_option('ssba_font_family', $_POST['ssba_font_family']);
update_option('ssba_font_color', $_POST['ssba_font_color']);
update_option('ssba_font_size', $_POST['ssba_font_size']);
update_option('ssba_font_weight', $_POST['ssba_font_weight']);
// include
update_option('ssba_selected_buttons', $_POST['ssba_selected_buttons']);
// custom images
update_option('ssba_custom_email', $_POST['ssba_custom_email']);
update_option('ssba_custom_google', $_POST['ssba_custom_google']);
update_option('ssba_custom_facebook', $_POST['ssba_custom_facebook']);
update_option('ssba_custom_twitter', $_POST['ssba_custom_twitter']);
update_option('ssba_custom_diggit', $_POST['ssba_custom_diggit']);
update_option('ssba_custom_linkedin', $_POST['ssba_custom_linkedin']);
update_option('ssba_custom_reddit', $_POST['ssba_custom_reddit']);
update_option('ssba_custom_stumbleupon', $_POST['ssba_custom_stumbleupon']);
update_option('ssba_custom_pinterest', $_POST['ssba_custom_pinterest']);
update_option('ssba_custom_buffer', $_POST['ssba_custom_buffer']);
update_option('ssba_custom_flattr', $_POST['ssba_custom_flattr']);
update_option('ssba_custom_tumblr', $_POST['ssba_custom_tumblr']);
update_option('ssba_custom_print', $_POST['ssba_custom_print']);
// show settings saved message
$htmlSettingsSaved = '<div id="setting-error-settings_updated" class="updated settings-error"><p><strong>Your settings have been saved. <a href="' . site_url() . '">Visit your site</a> to see how your buttons look!</strong></p></div>';
}
}
// include then run the upgrade script
include_once (plugin_dir_path(__FILE__) . '/inc/ssba_admin_panel.php');
// query the db for current ssba settings
$arrSettings = get_ssba_settings();
// --------- ADMIN PANEL ------------ //
ssba_admin_panel($arrSettings, $htmlSettingsSaved);
}
// add CSS to the head
add_action( 'wp_head', 'get_ssba_style' );
// generate style
function get_ssba_style() {
// query the db for current ssba settings
$arrSettings = get_ssba_settings();
// only include CSS if needed
//if () {
// css style
$htmlSSBAStyle = '<style type="text/css">';
// check if custom styles haven't been set
if ($arrSettings['ssba_custom_styles'] == '') {
// use set options
$htmlSSBAStyle .= ' .ssba {
' . ($arrSettings['ssba_div_padding'] != '' ? 'padding: ' . $arrSettings['ssba_div_padding'] . 'px;' : NULL) . '
' . ($arrSettings['ssba_border_width'] != '' ? 'border: ' . $arrSettings['ssba_border_width'] . 'px solid ' . $arrSettings['ssba_div_border'] . ';' : NULL) . '
' . ($arrSettings['ssba_div_background'] != '' ? 'background-color: ' . $arrSettings['ssba_div_background'] . ';' : NULL) . '
' . ($arrSettings['ssba_div_rounded_corners'] == 'Y' ? '-moz-border-radius: 10px; -webkit-border-radius: 10px; -khtml-border-radius: 10px; border-radius: 10px; -o-border-radius: 10px;' : NULL) . '
}
.ssba img
{
width: ' . $arrSettings['ssba_size'] . 'px !important;
padding: ' . $arrSettings['ssba_padding'] . 'px;
border: 0;
box-shadow: none !important;
display: inline !important;
vertical-align: middle;
}
.ssba, .ssba a
{
text-decoration:none;
' . ($arrSettings['ssba_div_background'] == '' ? 'background: none;' : NULL) . '
' . ($arrSettings['ssba_font_family'] != '' ? 'font-family: ' . $arrSettings['ssba_font_family'] . ';' : NULL) . '
' . ($arrSettings['ssba_font_size'] != '' ? 'font-size: ' . $arrSettings['ssba_font_size'] . 'px;' : NULL) . '
' . ($arrSettings['ssba_font_color'] != '' ? 'color: ' . $arrSettings['ssba_font_color'] . '!important;' : NULL) . '
' . ($arrSettings['ssba_font_weight'] != '' ? 'font-weight: ' . $arrSettings['ssba_font_weight'] . ';' : NULL) . '
}';
}
// else use set options
else {
// use custom styles
$htmlSSBAStyle .= $arrSettings['ssba_custom_styles'];
}
// if counters option is set to Y
if ($arrSettings['ssba_show_share_count'] == 'Y') {
// if no custom share count css is set
if ($arrSettings['ssba_share_count_css'] == '') {
// styles that apply to all counter css sets
$htmlSSBAStyle .= '.ssba_sharecount:after, .ssba_sharecount:before {
right: 100%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
}
.ssba_sharecount:after {
border-color: rgba(224, 221, 221, 0);
border-right-color: #f5f5f5;
border-width: 5px;
top: 50%;
margin-top: -5px;
}
.ssba_sharecount:before {
border-color: rgba(85, 94, 88, 0);
border-right-color: #e0dddd;
border-width: 6px;
top: 50%;
margin-top: -6px;
}
.ssba_sharecount {
font: 11px Arial, Helvetica, sans-serif;
padding: 5px;
-khtml-border-radius: 6px;
-o-border-radius: 6px;
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
border-radius: 6px;
position: relative;
border: 1px solid #e0dddd;';
// if default counter style has been chosen
if ($arrSettings['ssba_share_count_style'] == 'default') {
// style share count
$htmlSSBAStyle .= 'color: #555e58;
background: #f5f5f5;
}
.ssba_sharecount:after {
border-right-color: #f5f5f5;
}';
} elseif ($arrSettings['ssba_share_count_style'] == 'white') {
// show white style share counts
$htmlSSBAStyle .= 'color: #555e58;
background: #ffffff;
}
.ssba_sharecount:after {
border-right-color: #ffffff;
}';
} elseif ($arrSettings['ssba_share_count_style'] == 'blue') {
// show blue style share counts
$htmlSSBAStyle .= 'color: #ffffff;
background: #42a7e2;
}
.ssba_sharecount:after {
border-right-color: #42a7e2;
}';
}
} else {
// custom style
$htmlSSBAStyle .= $arrSettings['ssba_share_count_css'];
}
}
// close style tag
$htmlSSBAStyle .= '</style>';
// return
echo $htmlSSBAStyle;
//} // end conditional CSS
}
// --------- SHARE BUTTONS ------------ //
// return ssba settings
function get_ssba_settings() {
// globals
global $wpdb;
// query the db for current ssba settings
$arrSettings = $wpdb->get_results("SELECT option_name, option_value
FROM $wpdb->options
WHERE option_name LIKE 'ssba_%'");
// loop through each setting in the array
foreach ($arrSettings as $setting) {
// add each setting to the array by name
$arrSettings[$setting->option_name] = $setting->option_value;
}
// return
return $arrSettings;
}
// get and show share buttons
function show_share_buttons($content, $booShortCode = FALSE, $atts = '') {
// globals
global $post;
// variables
$htmlContent = $content;
$htmlShareButtons = '';
$strIsWhatFunction = '';
$pattern = get_shortcode_regex();
// ssba_hide shortcode is in the post content and instance is not called by shortcode ssba
if (preg_match_all( '/'. $pattern .'/s', $post->post_content, $matches )
&& array_key_exists( 2, $matches )
&& in_array('ssba_hide', $matches[2])
&& $booShortCode == FALSE) {
// exit the function returning the content without the buttons
return $content;
}
// get sbba settings
$arrSettings = get_ssba_settings();
// placement on pages/posts/categories/archives/homepage
if ((!is_home() && !is_front_page() && is_page() && $arrSettings['ssba_pages'] == 'Y') || (is_single() && $arrSettings['ssba_posts'] == 'Y') || (is_category() && $arrSettings['ssba_cats_archs'] == 'Y') || (is_archive() && $arrSettings['ssba_cats_archs'] == 'Y') || ( (is_home() || is_front_page() ) && $arrSettings['ssba_homepage'] == 'Y') || $booShortCode == TRUE) {
// if not shortcode
if (isset($atts['widget']) && $atts['widget'] == 'Y')
// use widget share text
$strShareText = $arrSettings['ssba_widget_text'];
else
// use normal share text
$strShareText = $arrSettings['ssba_share_text'];
// ssba div
$htmlShareButtons = '<!-- Simple Share Buttons Adder (4.6) simplesharebuttons.com --><div class="ssba">';
// center if set so
$htmlShareButtons.= '<div style="text-align:'.$arrSettings['ssba_align'].'">';
// add custom text if set and set to placement above or left
if (($strShareText != '') && ($arrSettings['ssba_text_placement'] == 'above' || $arrSettings['ssba_text_placement'] == 'left')) {
// check if user has left share link box checked
if ($arrSettings['ssba_link_to_ssb'] == 'Y') {
// share text with link
$htmlShareButtons .= '<a href="http://www.simplesharebuttons.com" target="_blank">' . $strShareText . '</a>';
}
// just display the share text
else {
// share text
$htmlShareButtons .= $strShareText;
}
// add a line break if set to above
($arrSettings['ssba_text_placement'] == 'above' ? $htmlShareButtons .= '<br/>' : NULL);
}
// if running standard
if ($booShortCode == FALSE) {
// use wordpress functions for page/post details
$urlCurrentPage = get_permalink($post->ID);
$strPageTitle = get_the_title($post->ID);
} else { // using shortcode
// set page URL and title as set by user or get if needed
$urlCurrentPage = (isset($atts['url']) ? $atts['url'] : ssba_current_url());
$strPageTitle = (isset($atts['title']) ? $atts['title'] : get_the_title());
}
// the buttons!
$htmlShareButtons.= get_share_buttons($arrSettings, $urlCurrentPage, $strPageTitle);
// add custom text if set and set to placement right or below
if (($strShareText != '') && ($arrSettings['ssba_text_placement'] == 'right' || $arrSettings['ssba_text_placement'] =='below')) {
// add a line break if set to above
($arrSettings['ssba_text_placement'] == 'below' ? $htmlShareButtons .= '<br/>' : NULL);
// check if user has left share link box checked
if ($arrSettings['ssba_link_to_ssb'] == 'Y') {
// share text with link
$htmlShareButtons .= '<a href="http://www.simplesharebuttons.com" target="_blank">' . $strShareText . '</a>';
}
// just display the share text
else {
// share text
$htmlShareButtons .= $strShareText;
}
}
// close center if set
$htmlShareButtons.= '</div>';
$htmlShareButtons.= '</div>';
// if not using shortcode
if ($booShortCode == FALSE) {
// switch for placement of ssba
switch ($arrSettings['ssba_before_or_after']) {
case 'before': // before the content
$htmlContent = $htmlShareButtons . $content;
break;
case 'after': // after the content
$htmlContent = $content . $htmlShareButtons;
break;
case 'both': // before and after the content
$htmlContent = $htmlShareButtons . $content . $htmlShareButtons;
break;
}
}
// if using shortcode
else {
// just return buttons
$htmlContent = $htmlShareButtons;
}
}
// return content and share buttons
return $htmlContent;
}
// add share buttons to content
add_filter( 'the_content', 'show_share_buttons');
// if we wish to add to excerpts
if($arrSettings['ssba_excerpts'] == 'Y') {
// add a hook
add_filter( 'the_excerpt', 'show_share_buttons');
}
// shortcode for adding buttons
function ssba_buttons($atts) {
// get buttons - NULL for $content, TRUE for shortcode flag
$htmlShareButtons = show_share_buttons(NULL, TRUE, $atts);
//return buttons
return $htmlShareButtons;
}
// shortcode for hiding buttons
function ssba_hide($content) {
// no need to do anything here!
}
// get URL function
function ssba_current_url() {
// add http
$urlCurrentPage = 'http';
// add s to http if required
if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {$urlCurrentPage .= "s";}
// add colon and forward slashes
$urlCurrentPage .= "://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
// return url
return $urlCurrentPage;
}
// shorten URL with bit.ly
function ssba_shorten($urlLong) {
// get results from bitly and return short url
$hmtlBitly = file_get_contents('http://api.bit.ly/v3/shorten?login=simplesharebuttons&apiKey=R_555eddf50da1370b8ab75670a3de2fe6&longUrl=' . $urlLong);
$arrBitly = json_decode($hmtlBitly, true);
$urlShort = $arrBitly['data'];
$urlShort = $urlShort['url'];
$hmtlBitly = str_replace('[\]', '', $hmtlBitly);
if ($urlShort != '') {
return $urlShort;
} else {
return $urlLong;
};
}
// get set share buttons
function get_share_buttons($arrSettings, $urlCurrentPage, $strPageTitle) {
// variables
$htmlShareButtons = '';
// explode saved include list and add to a new array
$arrSelectedSSBA = explode(',', $arrSettings['ssba_selected_buttons']);
// check if array is not empty
if ($arrSettings['ssba_selected_buttons'] != '') {
// if show counters option is selected
if ($arrSettings['ssba_show_share_count'] == 'Y') {
// set show flag to true
$booShowShareCount = true;
// if show counters once option is selected
if ($arrSettings['ssba_share_count_once'] == 'Y') {
// if not a page or post
if (!is_page() && !is_single()) {
// set show flag to false
$booShowShareCount = false;
}
}
} else {
// set show flag to false
$booShowShareCount = false;
}
// for each included button
foreach ($arrSelectedSSBA as $strSelected) {
$strGetButton = 'ssba_' . $strSelected;
// add a list item for each selected option
$htmlShareButtons .= $strGetButton($arrSettings, $urlCurrentPage, $strPageTitle, $booShowShareCount);
}
}
// return share buttons
return $htmlShareButtons;
}
// get facebook button
function ssba_facebook($arrSettings, $urlCurrentPage, $strPageTitle, $booShowShareCount) {
// facebook share link
$htmlShareButtons = '<a class="ssba_facebook_share" href="http://www.facebook.com/sharer.php?u=' . $urlCurrentPage . '" ' . ($arrSettings['ssba_share_new_window'] == 'Y' ? 'target="_blank"' : NULL) . ($arrSettings['ssba_rel_nofollow'] == 'Y' ? ' rel="nofollow"' : NULL) .'>';
// if not using custom
if ($arrSettings['ssba_image_set'] != 'custom') {
// show selected ssba image
$htmlShareButtons .= '<img src="' . WP_PLUGIN_URL . '/simple-share-buttons-adder/buttons/' . $arrSettings['ssba_image_set'] . '/facebook.png" title="Facebook" class="ssba" alt="Share on Facebook" />';
}
// if using custom images
else {
// show custom image
$htmlShareButtons .= '<img src="' . $arrSettings['ssba_custom_facebook'] . '" title="Facebook" class="ssba" alt="Share on Facebook" />';
}
// close href
$htmlShareButtons .= '</a>';
// if show share count is set to Y
if ($arrSettings['ssba_show_share_count'] == 'Y' && $booShowShareCount == true) {
$htmlShareButtons .= '<span class="ssba_sharecount">' . number_format(getFacebookShareCount($urlCurrentPage)) . '</span>';
}
// return share buttons
return $htmlShareButtons;
}
// get facebook share count
function getFacebookShareCount($urlCurrentPage) {
// get results from facebook and return the number of shares
$htmlFacebookShareDetails = file_get_contents('http://graph.facebook.com/' . $urlCurrentPage);
$arrFacebookShareDetails = json_decode($htmlFacebookShareDetails, true);
$intFacebookShareCount = (isset($arrFacebookShareDetails['shares']) ? $arrFacebookShareDetails['shares'] : 0);
return ($intFacebookShareCount ) ? $intFacebookShareCount : '0';
}
// get twitter button
function ssba_twitter($arrSettings, $urlCurrentPage, $strPageTitle, $booShowShareCount) {
// format the URL into friendly code
$twitterShareText = urlencode(html_entity_decode($strPageTitle . ' ' . $arrSettings['ssba_twitter_text'], ENT_COMPAT, 'UTF-8'));
// twitter share link
$htmlShareButtons = '<a class="ssba_twitter_share" href="http://twitter.com/share?url=' . $urlCurrentPage . '&text=' . $twitterShareText . '" ' . ($arrSettings['ssba_share_new_window'] == 'Y' ? 'target="_blank"' : NULL) . ($arrSettings['ssba_rel_nofollow'] == 'Y' ? 'rel="nofollow"' : NULL) . '>';
// if image set is not custom
if ($arrSettings['ssba_image_set'] != 'custom') {
// show ssba image
$htmlShareButtons .= '<img src="' . WP_PLUGIN_URL . '/simple-share-buttons-adder/buttons/' . $arrSettings['ssba_image_set'] . '/twitter.png" title="Twitter" class="ssba" alt="Tweet about this on Twitter" />';
}
// if using custom images
else {
// show custom image
$htmlShareButtons .= '<img src="' . $arrSettings['ssba_custom_twitter'] . '" title="Twitter" class="ssba" alt="Tweet about this on Twitter" />';
}
// close href
$htmlShareButtons .= '</a>';
// if show share count is set to Y
if ($arrSettings['ssba_show_share_count'] == 'Y' && $booShowShareCount == true) {
$htmlShareButtons .= '<span class="ssba_sharecount">' . number_format(getTwitterShareCount($urlCurrentPage)) . '</span>';
}
// return share buttons
return $htmlShareButtons;
}
// get twitter share count
function getTwitterShareCount($urlCurrentPage) {
// get results from twitter and return the number of shares
$htmlTwitterShareDetails = file_get_contents('http://urls.api.twitter.com/1/urls/count.json?url=' . $urlCurrentPage);
$arrTwitterShareDetails = json_decode($htmlTwitterShareDetails, true);
$intTwitterShareCount = $arrTwitterShareDetails['count'];
return ($intTwitterShareCount ) ? $intTwitterShareCount : '0';
}
// get google+ button
function ssba_google($arrSettings, $urlCurrentPage, $strPageTitle, $booShowShareCount) {
// google share link
$htmlShareButtons = '<a class="ssba_google_share" href="https://plus.google.com/share?url=' . $urlCurrentPage . '" ' . ($arrSettings['ssba_share_new_window'] == 'Y' ? 'target="_blank"' : NULL) . ($arrSettings['ssba_rel_nofollow'] == 'Y' ? 'rel="nofollow"' : NULL) . '>';
// if image set is not custom
if ($arrSettings['ssba_image_set'] != 'custom') {
// show ssba image
$htmlShareButtons .= '<img src="' . WP_PLUGIN_URL . '/simple-share-buttons-adder/buttons/' . $arrSettings['ssba_image_set'] . '/google.png" title="Google+" class="ssba" alt="Share on Google+" />';
}
// if using custom images
else {
// show custom image
$htmlShareButtons .= '<img src="' . $arrSettings['ssba_custom_google'] . '" title="Share on Google+" class="ssba" alt="Google+" />';
}
// close href
$htmlShareButtons .= '</a>';
// if show share count is set to Y
if ($arrSettings['ssba_show_share_count'] == 'Y' && $booShowShareCount == true) {
$htmlShareButtons .= '<span class="ssba_sharecount">' . number_format(getGoogleShareCount($urlCurrentPage)) . '</span>';
}
// return share buttons
return $htmlShareButtons;
}
// get google share count
function getGoogleShareCount($urlCurrentPage) {