[20358] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Plugin Name: Social Buttons |
---|
| 4 | Version: auto |
---|
| 5 | Description: Sharing functions for Facebook, Twitter, Google+ and Tumblr |
---|
| 6 | Plugin URI: auto |
---|
| 7 | Author: Mistic |
---|
| 8 | Author URI: http://www.strangeplanet.fr |
---|
| 9 | */ |
---|
| 10 | |
---|
| 11 | defined('PHPWG_ROOT_PATH') or die('Hacking attempt!'); |
---|
| 12 | |
---|
| 13 | global $prefixeTable; |
---|
| 14 | |
---|
| 15 | // +-----------------------------------------------------------------------+ |
---|
| 16 | // | Define plugin constants | |
---|
| 17 | // +-----------------------------------------------------------------------+ |
---|
| 18 | defined('SOCIALBUTT_ID') or define('SOCIALBUTT_ID', basename(dirname(__FILE__))); |
---|
| 19 | define('SOCIALBUTT_PATH' , PHPWG_PLUGINS_PATH . SOCIALBUTT_ID . '/'); |
---|
| 20 | define('SOCIALBUTT_ADMIN', get_root_url() . 'admin.php?page=plugin-' . SOCIALBUTT_ID); |
---|
| 21 | define('SOCIALBUTT_VERSION', 'auto'); |
---|
| 22 | |
---|
| 23 | |
---|
| 24 | // +-----------------------------------------------------------------------+ |
---|
| 25 | // | Add event handlers | |
---|
| 26 | // +-----------------------------------------------------------------------+ |
---|
| 27 | // init the plugin |
---|
| 28 | add_event_handler('init', 'socialbutt_init'); |
---|
| 29 | |
---|
| 30 | if (defined('IN_ADMIN')) |
---|
| 31 | { |
---|
| 32 | add_event_handler('get_admin_plugin_menu_links', 'socialbutt_admin_plugin_menu_links'); |
---|
| 33 | |
---|
| 34 | function socialbutt_admin_plugin_menu_links($menu) |
---|
| 35 | { |
---|
| 36 | array_push($menu, array( |
---|
| 37 | 'NAME' => 'Social Buttons', |
---|
| 38 | 'URL' => SOCIALBUTT_ADMIN, |
---|
| 39 | )); |
---|
| 40 | return $menu; |
---|
| 41 | } |
---|
| 42 | } |
---|
| 43 | else |
---|
| 44 | { |
---|
| 45 | add_event_handler('loc_end_picture', 'socialbutt_add_button'); |
---|
| 46 | add_event_handler('loc_end_index', 'socialbutt_add_button'); |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | /** |
---|
| 51 | * plugin initialization |
---|
| 52 | */ |
---|
| 53 | function socialbutt_init() |
---|
| 54 | { |
---|
| 55 | global $conf, $pwg_loaded_plugins; |
---|
| 56 | |
---|
| 57 | // apply upgrade if needed |
---|
| 58 | if ( |
---|
| 59 | SOCIALBUTT_VERSION == 'auto' or |
---|
| 60 | $pwg_loaded_plugins[SOCIALBUTT_ID]['version'] == 'auto' or |
---|
| 61 | version_compare($pwg_loaded_plugins[SOCIALBUTT_ID]['version'], SOCIALBUTT_VERSION, '<') |
---|
| 62 | ) |
---|
| 63 | { |
---|
| 64 | // call install function |
---|
| 65 | include_once(SOCIALBUTT_PATH . 'include/install.inc.php'); |
---|
| 66 | socialbutt_install(); |
---|
| 67 | |
---|
| 68 | // update plugin version in database |
---|
| 69 | if ( $pwg_loaded_plugins[SOCIALBUTT_ID]['version'] != 'auto' and SOCIALBUTT_VERSION != 'auto' ) |
---|
| 70 | { |
---|
| 71 | $query = ' |
---|
| 72 | UPDATE '. PLUGINS_TABLE .' |
---|
| 73 | SET version = "'. SOCIALBUTT_VERSION .'" |
---|
| 74 | WHERE id = "'. SOCIALBUTT_ID .'"'; |
---|
| 75 | pwg_query($query); |
---|
| 76 | |
---|
| 77 | $pwg_loaded_plugins[SOCIALBUTT_ID]['version'] = SOCIALBUTT_VERSION; |
---|
| 78 | |
---|
| 79 | if (defined('IN_ADMIN')) |
---|
| 80 | { |
---|
| 81 | $_SESSION['page_infos'][] = 'Social Buttons updated to version '. SOCIALBUTT_VERSION; |
---|
| 82 | } |
---|
| 83 | } |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | // prepare plugin configuration |
---|
| 87 | $conf['SocialButtons'] = unserialize($conf['SocialButtons']); |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | |
---|
| 91 | /** |
---|
| 92 | * add buttons |
---|
| 93 | */ |
---|
| 94 | function socialbutt_add_button() |
---|
| 95 | { |
---|
[24788] | 96 | global $conf, $template, $picture; |
---|
[20358] | 97 | |
---|
| 98 | $basename = script_basename(); |
---|
[23201] | 99 | set_make_full_url(); |
---|
[20358] | 100 | $root_url = get_absolute_root_url(); |
---|
| 101 | |
---|
| 102 | if ($basename == 'picture') |
---|
| 103 | { |
---|
[23201] | 104 | // global $picture; |
---|
| 105 | |
---|
| 106 | // if ($picture['current']['level'] > 0) return; |
---|
| 107 | |
---|
| 108 | $share_url = duplicate_picture_url(); |
---|
[20358] | 109 | } |
---|
[21232] | 110 | else if ($basename == 'index' and $conf['SocialButtons']['on_index']) |
---|
[20358] | 111 | { |
---|
| 112 | $conf['SocialButtons']['position'] = 'index'; |
---|
[23201] | 113 | $share_url = duplicate_index_url(array(), array('start')); |
---|
[20358] | 114 | } |
---|
| 115 | else |
---|
| 116 | { |
---|
| 117 | return; |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | |
---|
| 121 | $tpl_vars = array( |
---|
| 122 | 'share_url' => $share_url, |
---|
[24788] | 123 | 'basename' => $basename, |
---|
[20358] | 124 | 'position' => $conf['SocialButtons']['position'], |
---|
[24757] | 125 | 'light' => $conf['SocialButtons']['light'], |
---|
[23201] | 126 | 'copyright' => '(from <a href="'.$share_url.'">'.$conf['gallery_title'].'</a>)', |
---|
[20358] | 127 | ); |
---|
[24788] | 128 | |
---|
| 129 | if ($basename == 'picture') |
---|
| 130 | { |
---|
| 131 | if ($conf['SocialButtons']['img_size'] == 'Original') |
---|
| 132 | { |
---|
| 133 | $tpl_vars['source'] = $picture['current']['src_image']->get_url(); |
---|
| 134 | } |
---|
| 135 | else |
---|
| 136 | { |
---|
| 137 | $tpl_vars['source'] = DerivativeImage::url($conf['SocialButtons']['img_size'], $picture['current']['src_image']); |
---|
| 138 | } |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | |
---|
[20358] | 142 | $buttons = array(); |
---|
| 143 | |
---|
| 144 | if ($conf['SocialButtons']['google']['enabled']) |
---|
| 145 | { |
---|
| 146 | include_once(SOCIALBUTT_PATH . 'include/google.inc.php'); |
---|
[20374] | 147 | socialbutt_google($basename, $root_url, $tpl_vars, $buttons); |
---|
[20358] | 148 | } |
---|
| 149 | if ($conf['SocialButtons']['twitter']['enabled']) |
---|
| 150 | { |
---|
| 151 | include_once(SOCIALBUTT_PATH . 'include/twitter.inc.php'); |
---|
[20374] | 152 | socialbutt_twitter($basename, $root_url, $tpl_vars, $buttons); |
---|
[20358] | 153 | } |
---|
| 154 | if ($conf['SocialButtons']['facebook']['enabled']) |
---|
| 155 | { |
---|
| 156 | include_once(SOCIALBUTT_PATH . 'include/facebook.inc.php'); |
---|
[20374] | 157 | socialbutt_facebook($basename, $root_url, $tpl_vars, $buttons); |
---|
[20358] | 158 | } |
---|
| 159 | if ($conf['SocialButtons']['tumblr']['enabled']) |
---|
| 160 | { |
---|
| 161 | include_once(SOCIALBUTT_PATH . 'include/tumblr.inc.php'); |
---|
[20374] | 162 | socialbutt_tumblr($basename, $root_url, $tpl_vars, $buttons); |
---|
[20358] | 163 | } |
---|
[20374] | 164 | if ($conf['SocialButtons']['pinterest']['enabled'] and $basename=='picture') |
---|
| 165 | { |
---|
| 166 | include_once(SOCIALBUTT_PATH . 'include/pinterest.inc.php'); |
---|
| 167 | socialbutt_pinterest($basename, $root_url, $tpl_vars, $buttons); |
---|
| 168 | } |
---|
[24758] | 169 | if ($conf['SocialButtons']['reddit']['enabled']) |
---|
| 170 | { |
---|
| 171 | include_once(SOCIALBUTT_PATH . 'include/reddit.inc.php'); |
---|
| 172 | socialbutt_reddit($basename, $root_url, $tpl_vars, $buttons); |
---|
| 173 | } |
---|
[20358] | 174 | |
---|
[23201] | 175 | unset_make_full_url(); |
---|
| 176 | |
---|
[20358] | 177 | if (empty($buttons)) |
---|
| 178 | { |
---|
| 179 | return; |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | |
---|
[20406] | 183 | $template->assign(array( |
---|
| 184 | 'SOCIALBUTT' => $tpl_vars, |
---|
| 185 | 'SOCIALBUTT_PATH' => SOCIALBUTT_PATH, |
---|
| 186 | )); |
---|
[20358] | 187 | |
---|
| 188 | // parse buttons |
---|
| 189 | foreach ($buttons as &$button) |
---|
| 190 | { |
---|
| 191 | $button = $template->parse($button, true); |
---|
| 192 | } |
---|
| 193 | unset($button); |
---|
| 194 | |
---|
| 195 | switch ($conf['SocialButtons']['position']) |
---|
| 196 | { |
---|
| 197 | case 'index': |
---|
[24757] | 198 | foreach ($buttons as $button) |
---|
| 199 | { |
---|
| 200 | $template->add_index_button($button, 100); |
---|
[20358] | 201 | } |
---|
| 202 | break; |
---|
| 203 | case 'toolbar': |
---|
[24757] | 204 | foreach ($buttons as $button) |
---|
| 205 | { |
---|
[21232] | 206 | $template->add_picture_button($button, 100); |
---|
[20358] | 207 | } |
---|
| 208 | break; |
---|
| 209 | default; |
---|
[24757] | 210 | define('SOCIALBUTT_POSITION', $conf['SocialButtons']['position']); |
---|
[20358] | 211 | $template->assign('SOCIALBUTT_BUTTONS', $buttons); |
---|
| 212 | $template->set_prefilter('picture', 'socialbutt_add_button_prefilter'); |
---|
| 213 | } |
---|
| 214 | } |
---|
| 215 | |
---|
| 216 | function socialbutt_add_button_prefilter($content) |
---|
| 217 | { |
---|
| 218 | switch (SOCIALBUTT_POSITION) |
---|
| 219 | { |
---|
| 220 | case 'top': |
---|
| 221 | $search = '<div id="theImage">'; |
---|
[24757] | 222 | $add = '<div id="socialButtons">{foreach from=$SOCIALBUTT_BUTTONS item=BUTTON}{$BUTTON} {/foreach}</div>'; |
---|
[20358] | 223 | break; |
---|
| 224 | |
---|
| 225 | case 'bottom': |
---|
| 226 | $search = '{$ELEMENT_CONTENT}'; |
---|
[24757] | 227 | $add = '<div id="socialButtons">{foreach from=$SOCIALBUTT_BUTTONS item=BUTTON}{$BUTTON} {/foreach}</div>'; |
---|
[20358] | 228 | break; |
---|
| 229 | } |
---|
| 230 | |
---|
| 231 | return str_replace($search, $search.$add, $content); |
---|
| 232 | } |
---|
| 233 | |
---|
| 234 | ?> |
---|