[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 | // +-----------------------------------------------------------------------+ |
---|
| 14 | // | Define plugin constants | |
---|
| 15 | // +-----------------------------------------------------------------------+ |
---|
[26100] | 16 | define('SOCIALBUTT_ID', basename(dirname(__FILE__))); |
---|
[20358] | 17 | define('SOCIALBUTT_PATH' , PHPWG_PLUGINS_PATH . SOCIALBUTT_ID . '/'); |
---|
| 18 | define('SOCIALBUTT_ADMIN', get_root_url() . 'admin.php?page=plugin-' . SOCIALBUTT_ID); |
---|
| 19 | define('SOCIALBUTT_VERSION', 'auto'); |
---|
| 20 | |
---|
| 21 | |
---|
| 22 | // +-----------------------------------------------------------------------+ |
---|
| 23 | // | Add event handlers | |
---|
| 24 | // +-----------------------------------------------------------------------+ |
---|
| 25 | // init the plugin |
---|
| 26 | add_event_handler('init', 'socialbutt_init'); |
---|
| 27 | |
---|
| 28 | if (defined('IN_ADMIN')) |
---|
| 29 | { |
---|
| 30 | add_event_handler('get_admin_plugin_menu_links', 'socialbutt_admin_plugin_menu_links'); |
---|
| 31 | |
---|
| 32 | function socialbutt_admin_plugin_menu_links($menu) |
---|
| 33 | { |
---|
[26100] | 34 | $menu[] = array( |
---|
[20358] | 35 | 'NAME' => 'Social Buttons', |
---|
| 36 | 'URL' => SOCIALBUTT_ADMIN, |
---|
[26100] | 37 | ); |
---|
[20358] | 38 | return $menu; |
---|
| 39 | } |
---|
| 40 | } |
---|
| 41 | else |
---|
| 42 | { |
---|
| 43 | add_event_handler('loc_end_picture', 'socialbutt_add_button'); |
---|
| 44 | add_event_handler('loc_end_index', 'socialbutt_add_button'); |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | /** |
---|
| 49 | * plugin initialization |
---|
| 50 | */ |
---|
| 51 | function socialbutt_init() |
---|
| 52 | { |
---|
| 53 | global $conf, $pwg_loaded_plugins; |
---|
[26100] | 54 | |
---|
| 55 | include_once(SOCIALBUTT_PATH . 'maintain.inc.php'); |
---|
| 56 | $maintain = new SocialButtons_maintain(SOCIALBUTT_ID); |
---|
| 57 | $maintain->autoUpdate(SOCIALBUTT_VERSION, 'install'); |
---|
| 58 | |
---|
[20358] | 59 | $conf['SocialButtons'] = unserialize($conf['SocialButtons']); |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | |
---|
| 63 | /** |
---|
| 64 | * add buttons |
---|
| 65 | */ |
---|
| 66 | function socialbutt_add_button() |
---|
| 67 | { |
---|
[24788] | 68 | global $conf, $template, $picture; |
---|
[20358] | 69 | |
---|
[25473] | 70 | set_make_full_url(); |
---|
[20358] | 71 | $basename = script_basename(); |
---|
| 72 | $root_url = get_absolute_root_url(); |
---|
| 73 | |
---|
| 74 | if ($basename == 'picture') |
---|
| 75 | { |
---|
[23201] | 76 | // global $picture; |
---|
| 77 | |
---|
| 78 | // if ($picture['current']['level'] > 0) return; |
---|
| 79 | |
---|
| 80 | $share_url = duplicate_picture_url(); |
---|
[20358] | 81 | } |
---|
[21232] | 82 | else if ($basename == 'index' and $conf['SocialButtons']['on_index']) |
---|
[20358] | 83 | { |
---|
| 84 | $conf['SocialButtons']['position'] = 'index'; |
---|
[23201] | 85 | $share_url = duplicate_index_url(array(), array('start')); |
---|
[20358] | 86 | } |
---|
| 87 | else |
---|
| 88 | { |
---|
| 89 | return; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | $tpl_vars = array( |
---|
| 94 | 'share_url' => $share_url, |
---|
[24788] | 95 | 'basename' => $basename, |
---|
[20358] | 96 | 'position' => $conf['SocialButtons']['position'], |
---|
[24757] | 97 | 'light' => $conf['SocialButtons']['light'], |
---|
[23201] | 98 | 'copyright' => '(from <a href="'.$share_url.'">'.$conf['gallery_title'].'</a>)', |
---|
[20358] | 99 | ); |
---|
[24788] | 100 | |
---|
| 101 | if ($basename == 'picture') |
---|
| 102 | { |
---|
| 103 | if ($conf['SocialButtons']['img_size'] == 'Original') |
---|
| 104 | { |
---|
| 105 | $tpl_vars['source'] = $picture['current']['src_image']->get_url(); |
---|
| 106 | } |
---|
| 107 | else |
---|
| 108 | { |
---|
| 109 | $tpl_vars['source'] = DerivativeImage::url($conf['SocialButtons']['img_size'], $picture['current']['src_image']); |
---|
| 110 | } |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | |
---|
[20358] | 114 | $buttons = array(); |
---|
[25473] | 115 | $services = array('google', 'twitter', 'facebook', 'tumblr', 'pinterest', 'reddit', 'linkedin'); |
---|
[20358] | 116 | |
---|
[25473] | 117 | foreach ($services as $service) |
---|
[20358] | 118 | { |
---|
[25473] | 119 | if ($conf['SocialButtons'][$service]['enabled']) |
---|
| 120 | { |
---|
[26100] | 121 | if ($service=='pinterest' && $basename!='picture') |
---|
| 122 | { |
---|
| 123 | continue; |
---|
| 124 | } |
---|
[25473] | 125 | include_once(SOCIALBUTT_PATH . 'include/'. $service .'.inc.php'); |
---|
| 126 | call_user_func_array('socialbutt_'.$service, array($basename, $root_url, &$tpl_vars, &$buttons)); |
---|
| 127 | } |
---|
[20358] | 128 | } |
---|
| 129 | |
---|
[23201] | 130 | unset_make_full_url(); |
---|
| 131 | |
---|
[20358] | 132 | if (empty($buttons)) |
---|
| 133 | { |
---|
| 134 | return; |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | |
---|
[20406] | 138 | $template->assign(array( |
---|
| 139 | 'SOCIALBUTT' => $tpl_vars, |
---|
| 140 | 'SOCIALBUTT_PATH' => SOCIALBUTT_PATH, |
---|
| 141 | )); |
---|
[20358] | 142 | |
---|
| 143 | // parse buttons |
---|
| 144 | foreach ($buttons as &$button) |
---|
| 145 | { |
---|
| 146 | $button = $template->parse($button, true); |
---|
| 147 | } |
---|
| 148 | unset($button); |
---|
| 149 | |
---|
| 150 | switch ($conf['SocialButtons']['position']) |
---|
| 151 | { |
---|
| 152 | case 'index': |
---|
[24757] | 153 | foreach ($buttons as $button) |
---|
| 154 | { |
---|
| 155 | $template->add_index_button($button, 100); |
---|
[20358] | 156 | } |
---|
| 157 | break; |
---|
| 158 | case 'toolbar': |
---|
[24757] | 159 | foreach ($buttons as $button) |
---|
| 160 | { |
---|
[21232] | 161 | $template->add_picture_button($button, 100); |
---|
[20358] | 162 | } |
---|
| 163 | break; |
---|
| 164 | default; |
---|
[24757] | 165 | define('SOCIALBUTT_POSITION', $conf['SocialButtons']['position']); |
---|
[20358] | 166 | $template->assign('SOCIALBUTT_BUTTONS', $buttons); |
---|
| 167 | $template->set_prefilter('picture', 'socialbutt_add_button_prefilter'); |
---|
| 168 | } |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | function socialbutt_add_button_prefilter($content) |
---|
| 172 | { |
---|
| 173 | switch (SOCIALBUTT_POSITION) |
---|
| 174 | { |
---|
| 175 | case 'top': |
---|
| 176 | $search = '<div id="theImage">'; |
---|
[24757] | 177 | $add = '<div id="socialButtons">{foreach from=$SOCIALBUTT_BUTTONS item=BUTTON}{$BUTTON} {/foreach}</div>'; |
---|
[20358] | 178 | break; |
---|
| 179 | |
---|
| 180 | case 'bottom': |
---|
| 181 | $search = '{$ELEMENT_CONTENT}'; |
---|
[24757] | 182 | $add = '<div id="socialButtons">{foreach from=$SOCIALBUTT_BUTTONS item=BUTTON}{$BUTTON} {/foreach}</div>'; |
---|
[20358] | 183 | break; |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | return str_replace($search, $search.$add, $content); |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | ?> |
---|