1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: ShareThis |
---|
4 | Version: 1.0.4 |
---|
5 | Description: Add "Share This" functionality to your site |
---|
6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=793 |
---|
7 | Author: Serguei Dosyukov |
---|
8 | Author URI: http://blog.dragonsoft.us |
---|
9 | */ |
---|
10 | |
---|
11 | defined('PHPWG_ROOT_PATH') or die('Hacking attempt!'); |
---|
12 | |
---|
13 | // +-----------------------------------------------------------------------+ |
---|
14 | // | Define plugin constants | |
---|
15 | // +-----------------------------------------------------------------------+ |
---|
16 | |
---|
17 | define('SHARETHIS_VERSION', '1.0.4'); |
---|
18 | define('SHARETHIS_ID', basename(dirname(__FILE__))); |
---|
19 | define('SHARETHIS_PATH' , PHPWG_PLUGINS_PATH . SHARETHIS_ID . '/'); |
---|
20 | define('SHARETHIS_ADMIN', get_root_url() . 'admin.php?page=plugin-' . SHARETHIS_ID); |
---|
21 | define('SHARETHIS_PUBLIC', get_absolute_root_url() . make_index_url(array('section' => 'sharethis')) . '/'); |
---|
22 | define('SHARETHIS_DIR', PHPWG_ROOT_PATH . PWG_LOCAL_DIR . 'sharethis/'); |
---|
23 | if (!defined('GDTHEME_PATH')): |
---|
24 | define('GDTHEME_PATH' , PHPWG_THEMES_PATH . 'greydragon/'); |
---|
25 | endif; |
---|
26 | |
---|
27 | // +-----------------------------------------------------------------------+ |
---|
28 | // | Add event handlers | |
---|
29 | // +-----------------------------------------------------------------------+ |
---|
30 | // init the plugin |
---|
31 | add_event_handler('init', 'sharethis_init'); |
---|
32 | |
---|
33 | /* |
---|
34 | * this is the common way to define event functions: create a new function for each event you want to handle |
---|
35 | */ |
---|
36 | if (defined('IN_ADMIN')): |
---|
37 | // file containing all admin handlers functions |
---|
38 | $admin_file = SHARETHIS_PATH . 'include/admin_events.inc.php'; |
---|
39 | |
---|
40 | // admin plugins menu link |
---|
41 | add_event_handler('get_admin_plugin_menu_links', 'sharethis_admin_plugin_menu_links', EVENT_HANDLER_PRIORITY_NEUTRAL, $admin_file); |
---|
42 | endif; |
---|
43 | |
---|
44 | function sharethis_init() { |
---|
45 | global $conf; |
---|
46 | |
---|
47 | // prepare plugin configuration |
---|
48 | $conf['sharethis'] = safe_unserialize($conf['sharethis']); |
---|
49 | if ($conf['sharethis']['facebook'] || $conf['sharethis']['pinterest'] || $conf['sharethis']['twitter'] || $conf['sharethis']['googleplus'] || $conf['sharethis']['tumblr']): |
---|
50 | add_event_handler('loc_begin_picture', 'sharethis_picture_handler'); |
---|
51 | endif; |
---|
52 | } |
---|
53 | |
---|
54 | function sharethis_picture_handler() |
---|
55 | { |
---|
56 | global $template, $conf, $current; |
---|
57 | |
---|
58 | if ($template->get_themeconf("name") == "greydragon"): |
---|
59 | add_event_handler('gd_get_metadata', 'sharethis_get_tab_metadata'); |
---|
60 | else: |
---|
61 | $template->set_prefilter('picture', 'sharethis_append_content'); |
---|
62 | endif; |
---|
63 | load_language('plugin.lang', SHARETHIS_PATH); |
---|
64 | |
---|
65 | $protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https') === FALSE ? 'http' : 'https'; |
---|
66 | $host = $_SERVER['HTTP_HOST']; |
---|
67 | $script = $_SERVER['SCRIPT_NAME']; |
---|
68 | $params = $_SERVER['QUERY_STRING']; |
---|
69 | $curUrl = $protocol . '://' . $host . $script . '?' . $params; |
---|
70 | |
---|
71 | $template->assign( |
---|
72 | array( |
---|
73 | 'sharethis_facebook' => $conf['sharethis']['facebook'], |
---|
74 | 'sharethis_pinterest' => $conf['sharethis']['pinterest'], |
---|
75 | 'sharethis_twitter' => $conf['sharethis']['twitter'], |
---|
76 | 'sharethis_googleplus' => $conf['sharethis']['googleplus'], |
---|
77 | 'sharethis_tumblr' => $conf['sharethis']['tumblr'], |
---|
78 | 'SHARETHIS_PATH' => SHARETHIS_PATH, |
---|
79 | 'CUR_PAGE' => $curUrl |
---|
80 | )); |
---|
81 | |
---|
82 | } |
---|
83 | |
---|
84 | function sharethis_get_tab_metadata($metadata) { |
---|
85 | // pinterest &media=<logo> |
---|
86 | |
---|
87 | $url = '{$CUR_PAGE|escape:\'url\'}'; |
---|
88 | $image = '{if $current.selected_derivative}{$U_HOME|escape:\'url\'}{"/"|escape:\'url\'}{$current.selected_derivative->get_url()|escape:\'url\'}{/if}'; |
---|
89 | $title = '{$GALLERY_TITLE|escape:\'url\'}{" | "|escape:\'url\'}{$PAGE_TITLE|escape:\'url\'}{if $current->author}{" | by "|escape:\'url\'}{$current->author|escape:\'url\'}{/if}'; |
---|
90 | $content = '{$CONTENT_DESCRIPTION|urlencode}'; |
---|
91 | |
---|
92 | $metadata[] = array( |
---|
93 | "id" => "sharethis", |
---|
94 | "icon_class" => "fa fa-share-alt", |
---|
95 | "title" => "{'Share This'|@translate}", |
---|
96 | "content" => '<span>{\'Share This\'|@translate}:</span>' |
---|
97 | . '{html_head}<!-- START OPEN GRAPH TAGS-->{"\n"}' |
---|
98 | . '<meta property="og:title" content="{$GALLERY_TITLE} | {$PAGE_TITLE}{if $current->author} | by {$current->author}{/if}" />{"\n"}' |
---|
99 | . '<meta property="og:type" content="article" />{"\n"}' |
---|
100 | . '<meta property="og:url" content="{$CUR_PAGE}" />{"\n"}' |
---|
101 | . '{if $current.selected_derivative}<meta property="og:image" content="{$U_HOME}/{$current.selected_derivative->get_url()}" />{"\n"}{/if}' |
---|
102 | . '<meta property="og:description" content="{$CONTENT_DESCRIPTION}" />{"\n"}' |
---|
103 | . '<!-- END OPEN GRAPH TAGS-->{"\n"}' |
---|
104 | . '{if $sharethis_pinterest}<script type="text/javascript" async defer src="//assets.pinterest.com/js/pinit.js"></script>{/if}' |
---|
105 | . '{/html_head}' |
---|
106 | |
---|
107 | . '{if $sharethis_facebook}<a href="http://www.facebook.com/sharer/sharer.php?p[url]=' . $url . '{if $current.selected_derivative}&p[images][0]=' . $image . '{/if}&p[summary]=' . $content . '" onclick="window.open(this.href, \'\', \'toolbar=0,status=0,width=700,height=500\'); return false;" title="{\'Share on Facebook\'|@translate}" target="_blank"><i class="fa fa-facebook-square"></i> <span>{\'Facebook\'|@translate}</span></a>{/if}' |
---|
108 | . '{if $sharethis_pinterest}<a href="http://pinterest.com/pin/create/button/?url=' . $url . '&media=' . $image . '&description=' . $title . '" title="{\'Share on Pinterest\'|@translate}" target="_blank" data-pin-do="none" data-pin-config="none"><i class="fa fa-pinterest"></i> <span>{\'Pinterest\'|@translate}</span></a>{/if}' |
---|
109 | . '{if $sharethis_twitter}<a href="https://twitter.com/intent/tweet?text=' . $title . '&url=' . $url .'" title="{\'Share on Twitter\'|@translate}" target="_blank"><i class="fa fa-twitter"></i> <span>{\'Twitter\'|@translate}</span></a>{/if}' |
---|
110 | . '{if $sharethis_googleplus}<a href="https://plus.google.com/share?url=' . $url . '" title="{\'Share on Google+\'|@translate}" target="_blank" onclick="javascript:window.open(this.href, \'\', \'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600\');return false;"><i class="fa fa-google-plus-square"></i> <span>{\'Google+\'|@translate}</span></a>{/if}' |
---|
111 | . '{if $sharethis_tumblr}<a href="http://www.tumblr.com/share/photo?source=' . $image . '&caption=' . $title . '&click_thru=' . $url . '" title="{\'Share on Tumblr\'|@translate}" target="_blank"><i class="fa fa-tumblr"></i> <span>{\'Tumblr\'|@translate}</span></a>{/if}', |
---|
112 | |
---|
113 | "combine" => '{combine_css id=\'fa\' path=$SHARETHIS_PATH|cat:"/css/font-awesome.min.css"}' |
---|
114 | . '{combine_css id=\'sharethis\' path=$SHARETHIS_PATH|cat:"/css/styles.css"}', |
---|
115 | "no_overlay" => TRUE |
---|
116 | ); |
---|
117 | return $metadata; |
---|
118 | } |
---|
119 | |
---|
120 | function sharethis_append_content($tpl_source, &$smarty){ |
---|
121 | |
---|
122 | $metadata = array(); |
---|
123 | $metadata = sharethis_get_tab_metadata($metadata); |
---|
124 | |
---|
125 | $pattern = '#<div id=\"imageTitle\".*>#'; |
---|
126 | |
---|
127 | if (!preg_match($pattern, $tpl_source)): |
---|
128 | $pattern = '#<div id=\"imageInfos\".*>#'; |
---|
129 | $replacement = '$0 |
---|
130 | <dl class="imageInfoTable" id="static-sharethis" > |
---|
131 | ' . $metadata[0]["content"] . ' |
---|
132 | </dl> |
---|
133 | ' . $metadata[0]["combine"] . ' |
---|
134 | |
---|
135 | '; |
---|
136 | else: |
---|
137 | $replacement = ' |
---|
138 | <div id="static-sharethis"> |
---|
139 | ' . $metadata[0]["content"] . ' |
---|
140 | </div> |
---|
141 | ' . $metadata[0]["combine"] . ' |
---|
142 | $0 |
---|
143 | '; |
---|
144 | endif; |
---|
145 | |
---|
146 | return preg_replace($pattern, $replacement, $tpl_source, 1); |
---|
147 | } |
---|