1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: ShareThis |
---|
4 | Version: 1.0.0 |
---|
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.0'); |
---|
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 | |
---|
85 | // pinterest &media=<logo> |
---|
86 | |
---|
87 | $metadata[] = array( |
---|
88 | "id" => "sharethis", |
---|
89 | "icon_class" => "fa fa-share-alt", |
---|
90 | "title" => "{'Share This'|@translate}", |
---|
91 | "content" => '<span>{\'Share This:\'|@translate}</span>' |
---|
92 | . '{if $sharethis_facebook}<a href="http://www.facebook.com/share.php?u={$CUR_PAGE}" title="{\'Share on Facebook\'|@translate}" target="_blank"><i class="fa fa-facebook-square"></i> <span>{\'Facebook\'|@translate}</span></a>{/if}' |
---|
93 | . '{if $sharethis_pinterest}<a href="http://pinterest.com/pin/create/button/?url={$CUR_PAGE}" title="{\'Share on Pinterest\'|@translate}" target="_blank"><i class="fa fa-pinterest"></i> <span>{\'Pinterest\'|@translate}</span></a>{/if}' |
---|
94 | . '{if $sharethis_twitter}<a href="https://twitter.com/intent/tweet?text={$PAGE_TITLE|escape:\'url\'}&url={$CUR_PAGE}" title="{\'Share on Twitter\'|@translate}" target="_blank"><i class="fa fa-twitter"></i> <span>{\'Twitter\'|@translate}</span></a>{/if}' |
---|
95 | . '{if $sharethis_googleplus}<a href="https://plus.google.com/share?url={$CUR_PAGE}" title="{\'Share on Google+\'|@translate}" target="_blank"><i class="fa fa-google-plus-square"></i> <span>{\'Google+\'|@translate}</span></a>{/if}', |
---|
96 | "combine" => '{combine_css id=\'fa\' path=$SHARETHIS_PATH|cat:"/css/font-awesome.min.css"}' |
---|
97 | . '{combine_css id=\'sharethis\' path=$SHARETHIS_PATH|cat:"/css/styles.css"}', |
---|
98 | "no_overlay" => TRUE |
---|
99 | ); |
---|
100 | |
---|
101 | return $metadata; |
---|
102 | } |
---|
103 | |
---|
104 | function sharethis_append_content($tpl_source, &$smarty){ |
---|
105 | |
---|
106 | $metadata = array(); |
---|
107 | $metadata = sharethis_get_tab_metadata($metadata); |
---|
108 | |
---|
109 | $pattern = '#<div id=\"imageTitle\".*>#'; |
---|
110 | |
---|
111 | if (!preg_match($pattern, $tpl_source)): |
---|
112 | $pattern = '#<div id=\"imageInfos\".*>#'; |
---|
113 | $replacement = '$0 |
---|
114 | <dl class="imageInfoTable" id="static-sharethis" > |
---|
115 | ' . $metadata[0]["content"] . ' |
---|
116 | </dl> |
---|
117 | ' . $metadata[0]["combine"] . ' |
---|
118 | |
---|
119 | '; |
---|
120 | else: |
---|
121 | $replacement = ' |
---|
122 | <div id="static-sharethis"> |
---|
123 | ' . $metadata[0]["content"] . ' |
---|
124 | </div> |
---|
125 | ' . $metadata[0]["combine"] . ' |
---|
126 | $0 |
---|
127 | '; |
---|
128 | endif; |
---|
129 | |
---|
130 | return preg_replace($pattern, $replacement, $tpl_source, 1); |
---|
131 | } |
---|