1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: ShareThis |
---|
4 | Version: 1.0.2 |
---|
5 | Description: Add "Share This" functionality to your site |
---|
6 | //Plugin URI: http://piwigo.org/ext/extension_view.php?eid=543 |
---|
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.2'); |
---|
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']): |
---|
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_PATH' => SHARETHIS_PATH, |
---|
78 | 'CUR_PAGE' => $curUrl |
---|
79 | )); |
---|
80 | |
---|
81 | } |
---|
82 | |
---|
83 | function sharethis_get_tab_metadata($metadata) { |
---|
84 | // pinterest &media=<logo> |
---|
85 | |
---|
86 | $url = '{$CUR_PAGE|escape:\'url\'}'; |
---|
87 | $image = '{if $current.selected_derivative}{$U_HOME}/{$current.selected_derivative->get_url()|escape:\'url\'}{else}{/if}'; |
---|
88 | $title = '{$PAGE_TITLE|escape:\'url\'}'; |
---|
89 | $content = '{$CONTENT_DESCRIPTION|urlencode}'; |
---|
90 | |
---|
91 | |
---|
92 | |
---|
93 | $metadata[] = array( |
---|
94 | "id" => "sharethis", |
---|
95 | "icon_class" => "fa fa-share-alt", |
---|
96 | "title" => "{'Share This'|@translate}", |
---|
97 | "content" => '<span>{\'Share This:\'|@translate}</span>' |
---|
98 | . '{if $sharethis_facebook}' |
---|
99 | . '{html_head}<meta property="og:title" content="">{"\n"}' |
---|
100 | . '<meta property="og:type" content="article">{"\n"}' |
---|
101 | . '<meta property="og:url" content="{$CUR_PAGE}">{"\n"}' |
---|
102 | . '{if $current.selected_derivative}<meta property="og:image" content="{$U_HOME}/{$current.selected_derivative->get_url()}">{"\n"}{/if}' |
---|
103 | . '{/html_head}' |
---|
104 | . '<a href="http://www.facebook.com/sharer/sharer.php?p[title]=' . $title . '&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}' |
---|
105 | . '{if $sharethis_pinterest}<a href="http://pinterest.com/pin/create/button/?url=' . $url . '" title="{\'Share on Pinterest\'|@translate}" target="_blank"><i class="fa fa-pinterest"></i> <span>{\'Pinterest\'|@translate}</span></a>{/if}' |
---|
106 | . '{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}' |
---|
107 | . '{if $sharethis_googleplus}<a href="https://plus.google.com/share?url=' . $url . '" title="{\'Share on Google+\'|@translate}" target="_blank"><i class="fa fa-google-plus-square"></i> <span>{\'Google+\'|@translate}</span></a>{/if}', |
---|
108 | "combine" => '{combine_css id=\'fa\' path=$SHARETHIS_PATH|cat:"/css/font-awesome.min.css"}' |
---|
109 | . '{combine_css id=\'sharethis\' path=$SHARETHIS_PATH|cat:"/css/styles.css"}', |
---|
110 | "no_overlay" => TRUE |
---|
111 | ); |
---|
112 | return $metadata; |
---|
113 | } |
---|
114 | |
---|
115 | function sharethis_append_content($tpl_source, &$smarty){ |
---|
116 | |
---|
117 | $metadata = array(); |
---|
118 | $metadata = sharethis_get_tab_metadata($metadata); |
---|
119 | |
---|
120 | $pattern = '#<div id=\"imageTitle\".*>#'; |
---|
121 | |
---|
122 | if (!preg_match($pattern, $tpl_source)): |
---|
123 | $pattern = '#<div id=\"imageInfos\".*>#'; |
---|
124 | $replacement = '$0 |
---|
125 | <dl class="imageInfoTable" id="static-sharethis" > |
---|
126 | ' . $metadata[0]["content"] . ' |
---|
127 | </dl> |
---|
128 | ' . $metadata[0]["combine"] . ' |
---|
129 | |
---|
130 | '; |
---|
131 | else: |
---|
132 | $replacement = ' |
---|
133 | <div id="static-sharethis"> |
---|
134 | ' . $metadata[0]["content"] . ' |
---|
135 | </div> |
---|
136 | ' . $metadata[0]["combine"] . ' |
---|
137 | $0 |
---|
138 | '; |
---|
139 | endif; |
---|
140 | |
---|
141 | return preg_replace($pattern, $replacement, $tpl_source, 1); |
---|
142 | } |
---|