/web/htdocs/www.euroroma.net/home/zenphoto/plugins/zenSocialShare.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
<?php

/*
This plugin adds the ability to include template calls for Social sharing
via Facebook, Twitter, Pinterst, and Google+. It also includes the appropriate metatags
necessary in the header.

Code Implementation - Micheal Luttrull (micheall)
*/

$plugin_is_filter   THEME_PLUGIN;
$plugin_description gettext("zenSocialShare is a plugin to ease sharing on various social networks.");
$plugin_author      "Micheal Luttrull (micheall)";
$plugin_version     "1.4.6";
$plugin_URL         "http://inthemdl.net/pages/zensocialshare";

//zenSocialShare Option Interface
$option_interface 'zenSocialShareOptions';

/*
Register OpenGraph Meta keys into theme header
*/
zp_register_filter('theme_head''zenSocialShareMeta');
zp_register_filter('theme_body_open''zenSocialShare_open');
zp_register_filter('theme_body_close''zenSocialShare_close');

/*
zenSocialShare Plugin option handling class
*/
class zenSocialShareOptions {
    function 
zenSocialShareOptions() {
        
//zenSocialShare
        
setOptionDefault('zenSocialShare_facebook'0);
        
setOptionDefault('zenSocialShare_twitter'0);
        
setOptionDefault('zenSocialShare_googleplus'0);
        
setOptionDefault('zenSocialShare_pintrest'0);
        
setOptionDefault('zenSocialShare_twitterhandle'NULL);
        
setOptionDefault('zenSocialShare_fbappid'NULL);
    }
    
    function 
getOptionsSupported() {
        
//zenSocialShare Checkboxes
        
$checkboxes = array(
            
gettext('Facebook') => 'zenSocialShare_facebook',
            
gettext('Twitter') => 'zenSocialShare_twitter',
            
gettext('Google+') => 'zenSocialShare_googleplus',
            
gettext('Pintrest') => 'zenSocialShare_pintrest'
        
);
        
// Options Interface
        
return array(
            
gettext('Social Share on:') => array(
                
'key' => 'zenSocialShare_options',
                
'type' => OPTION_TYPE_CHECKBOX_ARRAY,
                
'checkboxes' => $checkboxes,
                
'order' => 0,
                
'desc' => gettext('Which social networks would you like to share on?')
            ),
            
gettext('Twitter Handle? (without the @)') => array(
                
'key' => 'zenSocialShare_twitterhandle',
                
'type' => 0,
                
'order' => 1,
                
'desc' => gettext('If Twitter enabled, include twitter handle for twitter creator tag.')
            ),
            
gettext('Facebook App ID: (without the @)') => array(
                
'key' => 'zenSocialShare_fbappid',
                
'type' => 0,
                
'order' => 2,
                
'desc' => gettext('Enter <em>YOUR</em> Application ID from facebook here. For more information please visit <a href="http://inthemdl.net/news/creating-your-facebook-app_id" target="_blank">this page</a>.<br /><em><b>Please note:  YOU MUST ENTER AN APPLICATION ID FOR THESE PLUGINS TO FUNCTION!</b></em><br />
                                  You should be entering numbers only in this field. Failure to create and input your APP ID will result in broken plugins.'
)
            )
        );
        
    }
    
    function 
handleOption($option$currentValue) {
    }
}


function 
zenSocialShareMeta() {
    
// Add globals for object handling.
    
global $_zp_gallery$_zp_galley_page$_zp_current_album$_zp_current_image$_zp_current_zenpage_news,
                        
$_zp_current_zenpage_page$_zp_gallery_page$_zp_current_category$_zp_authority;
    
    
// Set variables from zenSocialShare options for checks.
    
$facebook   getOption('zenSocialShare_facebook');
    
$twitter    getOption('zenSocialShare_twitter');
    
$googleplus getOption('zenSocialShare_googleplus');
    
$pinterest  getOption('zenSocialShare_pintrest');
    
    echo 
'<link href="' FULLWEBPATH '/' USER_PLUGIN_FOLDER '/zenSocialShare/zenSocialShare.css" rel="stylesheet" type="text/css" />';
    
    if ((
$facebook == 1) || ($pinterest == 1) || ($googleplus == 1)) {
        if (
$facebook == 1) {
            echo 
'<meta property="zenSocialShare Facebook" content="Enabled" />';
        } elseif (
$pinterest == 1) {
            echo 
'<meta property="zenSocialShare Pinterest" content="Enabled" />';
        } elseif (
$googleplus == 1) {
            echo 
'<meta property="zenSocialShare GooglePlus" content="Enabled" />';
        }
        
        
//Populate OpenGraph Tags for use with Facebook & Pinterest
        // OG:site_name
        
echo '<meta property="og:site_name" content="' getBareGalleryTitle() . '" />';
        
        
//OG:title
        
if (getImageThumb()) {
            echo 
'<meta property="og:title" content="' getImageTitle() . '" />';
        } else {
            echo 
'<meta property="og:title" content="' getBareGalleryTitle() . '" />';
        }
        
        
//OG:url
        
$host sanitize("http://" $_SERVER['HTTP_HOST']);
        
$url  $host getRequestURI();
        echo 
'<meta property="og:url" content="'$url '"/>';
        
        
//OG:Description
        // Set og:description to match the gallery description.
        
$desc getBareGalleryDesc();
        
// Set desc to image description if viewing an image.
        
if (is_object($_zp_current_image) AND is_object($_zp_current_album)) {
            
$desc getBareImageDesc();
        }
        
// Set desc to album description if viewing page with album thumbs.
        
if (is_object($_zp_current_album) AND !is_object($_zp_current_image)) {
            
$desc getBareAlbumDesc();
        }
        
// Set desc to contents of article or page if viewing.
        
if (function_exists("is_NewsArticle")) {
            if (
is_NewsArticle()) {
                
$desc strip_tags(getNewsContent());
            } else if (
is_NewsCategory()) {
                
$desc "";
            } else if (
is_Pages()) {
                
$desc strip_tags(getPageContent());
            }
        }
        echo 
'<meta property="og:description" content="' $desc '"/>';
        
        
// Populate OG:Type as website or article based on if at root page or not.
        
$type 'article';
        switch(
$_zp_gallery_page) {
            case 
'index.php':
                
$type 'website';
                break;
        default: 
// for all other possible none standard custom pages
                
break;
        }
        
        echo 
'<meta property="og:type" content="'.$type.'" />';
        
        
// Use the object thumbnail if viewing an item in gallery, else it will randomly choose an image
        // from your webpage.
        
if (getImageThumb()) {
            echo 
'<meta property="og:image" content="' $host getCustomImageURL(NULL560) . '" />';
        }
    }
    
    
/* 
    If Twitter enabled, add metakeys for Twitter Card sharing. To enable Twitter Card sharing from your website
    you MUST unfortunately have your site approved. For more information visit: https://dev.twitter.com/docs/cards
    */
    
if ($twitter == 1) {
        echo 
'<meta property="zenSocialShare Twitter" content="Enabled">';
        
//Pull twitter handle from options if it is set.
        
if ((getOption('zenSocialShare_twitterhandle')) != NULL) {
            
$twitterhandle getOption('zenSocialShare_twitterhandle');
        }
        
        echo 
'<meta name="twitter:card" content="photo">';
        echo 
'<meta name="twitter:site" content="' getBareGalleryTitle() . '">';
        echo 
'<meta name="twitter:creator" content="@' $twitterhandle '">';
        if (
getImageThumb()) {
            echo 
'<meta property="twitter:title" content="' getImageTitle() . '" />';
        } else {
            echo 
'<meta property="twitter:title" content="' getBareGalleryTitle() . '" />';
        }
        if (
getImageThumb()) {
            echo 
'<meta property="twitter:image" content="' $host getCustomImageURL(NULL560) . '" />';
        }
        if (
getImageThumb()) {
            echo 
'<meta name="twitter:image:width" content="' getFullWidth() . '">';
            echo 
'<meta name="twitter:image:height" content="' getFullHeight() . '">';
        }
    }
}
//Function to include Javascript requirements after body open.
function zenSocialShare_open() {
    
//Init Globals
    
global $_zp_gallery$_zp_current_album$_zp_current_image;
    
    
//Init variables for check
    
$facebook   getOption('zenSocialShare_facebook');
    
$twitter    getOption('zenSocialShare_twitter');
    
$googleplus getOption('zenSocialShare_googleplus');
    
$pinterest  getOption('zenSocialShare_pintrest');
    
$fbappid    getOption('zenSocialShare_fbappid');
    
    if (
$facebook == 1) {
        echo 
"<div id='fb-root'></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = '//connect.facebook.net/en_US/all.js#xfbml=1&appId=" 
$fbappid "';
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>"
;
    }
    
}

//Function to include Javascript requirements before body close.
function zenSocialShare_close() {
    
//Init Globals
    
global $_zp_gallery$_zp_current_album$_zp_current_image;
    
    
//Init variables for check
    
$facebook   getOption('zenSocialShare_facebook');
    
$twitter    getOption('zenSocialShare_twitter');
    
$googleplus getOption('zenSocialShare_googleplus');
    
$pinterest  getOption('zenSocialShare_pintrest');
    
    
//Pinterest PinIt requires Javascript.
    
if ($pinterest == 1) {
        echo 
"<script type='text/javascript'>
(function(d){
    var f = d.getElementsByTagName('SCRIPT')[0], p = d.createElement('SCRIPT');
    p.type = 'text/javascript';
    p.async = true;
    p.src = '//assets.pinterest.com/js/pinit.js';
    f.parentNode.insertBefore(p, f);
}(document));
</script>"
;
    }
    if (
$googleplus == 1) {
        echo 
"<script type='text/javascript'>
  (function() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/platform.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  })();
</script>"
;
    }
    if (
$twitter == 1) {
        echo 
'<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="https://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>';
    }
}

function 
zenSocialShare_buttons() {
    
//Init Globals
    
global $_zp_gallery$_zp_current_album$_zp_current_image;
    
    
//Init variables for check
    
$facebook   getOption('zenSocialShare_facebook');
    
$twitter    getOption('zenSocialShare_twitter');
    
$googleplus getOption('zenSocialShare_googleplus');
    
$pinterest  getOption('zenSocialShare_pintrest');
    if ((
getOption('zenSocialShare_twitterhandle')) != NULL) {
            
$twitterhandle getOption('zenSocialShare_twitterhandle');
    }
    
    
//Url Init
    
$host sanitize("http://" $_SERVER['HTTP_HOST']);
    
$url  $host getRequestURI();
    
    
//Description Init
    
$desc getBareGalleryDesc();
    
// Set desc to image description if viewing an image.
    
if (is_object($_zp_current_image) AND is_object($_zp_current_album)) {
        
$desc getBareImageDesc();
    }
    
// Set desc to album description if viewing page with album thumbs.
    
if (is_object($_zp_current_album) AND !is_object($_zp_current_image)) {
        
$desc getBareAlbumDesc();
    }
    
// Set desc to contents of article or page if viewing.
    
if (function_exists("is_NewsArticle")) {
        if (
is_NewsArticle()) {
            
$desc strip_tags(getNewsContent());
        } else if (
is_NewsCategory()) {
            
$desc "";
        } else if (
is_Pages()) {
            
$desc strip_tags(getPageContent());
        }
    }
    
    echo 
'<div id="zenSocialShare">';
    
    
//If Google+ button Enabled, display it.
    
if ($googleplus == 1) {
        echo 
'<div class="zenSocialGoogle"><div class="g-plus" data-action="share" data-annotation="bubble"></div></div>';
    }
    
    
//If Facebook Share button Enabled, display it.
    
if ($facebook == 1) {
        echo 
'<div class="zenSocialFacebook"><div class="fb-share-button" data-href="' $url '&fb=SI " data-type="button_count"></div></div>';
    }
    
    
//If Pintress button Enabled, display it.
    
if ($pinterest == 1) {
        echo 
'<div class="zenSocialPintrest"><a href="//www.pinterest.com/pin/create/button/
        ?url=' 
urlencode($url) . '
        &media=' 
urlencode($host getCustomImageURL(NULL560)) . '
        &description=' 
$desc '" 
        data-pin-do="buttonPin" data-pin-config="beside">
        <img src="//assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png" /></a></div>'
;
    }
    
    
//If Twitter button eneabled, display it.
    
if ($twitter == 1){
        echo 
'<div class="zenSocialTwitter"><a href="https://twitter.com/share" class="twitter-share-button" data-via="'.$twitterhandle.'" data-lang="en">Tweet</a></div>';
    }
    
    echo 
'</div>';
    
}
?>