[19361] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Plugin Name: tumblr.share |
---|
| 4 | Version: auto |
---|
| 5 | Description: Add a "Share on Tumblr" button on picture pages |
---|
| 6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=658 |
---|
| 7 | Author: Mistic |
---|
| 8 | Author URI: http://www.strangeplanet.fr |
---|
| 9 | */ |
---|
| 10 | |
---|
| 11 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 12 | |
---|
| 13 | define('TUMBLR_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/'); |
---|
| 14 | |
---|
| 15 | load_language('plugin.lang', TUMBLR_PATH); |
---|
| 16 | add_event_handler('loc_end_picture', 'tumblr_add_button'); |
---|
| 17 | add_event_handler('loc_end_index', 'tumblr_add_button'); |
---|
| 18 | |
---|
[20362] | 19 | add_event_handler('loc_begin_admin_page', 'tumblr_depreciated'); |
---|
[19361] | 20 | |
---|
[20360] | 21 | function tumblr_depreciated() |
---|
| 22 | { |
---|
| 23 | global $page; |
---|
| 24 | $page['warnings'][] = 'tumblr.share is depreciated, please use <a href="http://piwigo.org/ext/extension_view.php?eid=673">Social Buttons</a> instead.'; |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | |
---|
[19361] | 28 | function tumblr_add_button() |
---|
| 29 | { |
---|
| 30 | global $conf, $template, $page; |
---|
| 31 | |
---|
| 32 | $conf['TumblrShare'] = unserialize($conf['TumblrShare']); |
---|
| 33 | $conf['TumblrShare']['css'] = array( |
---|
| 34 | 'share_1' => 'width:81px; height:20px;', |
---|
| 35 | 'share_2' => 'width:61px; height:20px;', |
---|
| 36 | 'share_3' => 'width:129px; height:20px;', |
---|
| 37 | 'share_4' => 'width:20px; height:20px;', |
---|
| 38 | 'share_1T' => 'width:81px; height:20px;', |
---|
| 39 | 'share_2T' => 'width:61px; height:20px;', |
---|
| 40 | 'share_3T' => 'width:129px; height:20px;', |
---|
| 41 | 'share_4T' => 'width:20px; height:20px;', |
---|
| 42 | ); |
---|
| 43 | |
---|
| 44 | $root_url = get_absolute_root_url(); |
---|
| 45 | |
---|
| 46 | // button on piture page |
---|
| 47 | if (script_basename() == 'picture') |
---|
| 48 | { |
---|
[19394] | 49 | global $picture; |
---|
[19361] | 50 | |
---|
| 51 | $template->assign(array( |
---|
| 52 | 'TUMBLR_MODE' => 'photo', |
---|
[19394] | 53 | 'TUMBLR_URL' => $root_url.ltrim(duplicate_picture_url(), './'), |
---|
| 54 | 'TUMBLR_TITLE' => $picture['current']['TITLE'], |
---|
[19361] | 55 | )); |
---|
| 56 | |
---|
[19394] | 57 | if ($conf['TumblrShare']['img_size'] == 'Original') |
---|
[19361] | 58 | { |
---|
[19394] | 59 | $template->assign('TUMBLR_SOURCE', $root_url.ltrim($picture['current']['src_image']->get_url(), './')); |
---|
[19361] | 60 | } |
---|
| 61 | else |
---|
| 62 | { |
---|
[19394] | 63 | $template->assign('TUMBLR_SOURCE', $root_url.ltrim(DerivativeImage::url($conf['TumblrShare']['img_size'], $picture['current']['src_image']), './')); |
---|
[19361] | 64 | } |
---|
| 65 | } |
---|
| 66 | // button on other pages |
---|
| 67 | else if (script_basename() == 'index') |
---|
| 68 | { |
---|
| 69 | $conf['TumblrShare']['position'] = 'index'; |
---|
| 70 | $template->assign(array( |
---|
| 71 | 'TUMBLR_MODE' => 'link', |
---|
[19394] | 72 | 'TUMBLR_URL' => $root_url.ltrim(duplicate_index_url(), './'), |
---|
[19361] | 73 | 'TUMBLR_TITLE' => strip_tags($page['title']), |
---|
| 74 | )); |
---|
| 75 | } |
---|
| 76 | else |
---|
| 77 | { |
---|
| 78 | return; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | // config |
---|
| 82 | $template->assign(array( |
---|
| 83 | 'TUMBLR_POSITION' => $conf['TumblrShare']['position'], |
---|
| 84 | 'TUMBLR_TYPE' => $conf['TumblrShare']['type'], |
---|
| 85 | 'TUMBLR_CSS' => $conf['TumblrShare']['css'][ $conf['TumblrShare']['type'] ], |
---|
| 86 | 'TUMBLR_COPY' => ' (from <a href="'.$root_url.'">'.$conf['gallery_title'].'</a>)', |
---|
| 87 | )); |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | $template->set_filename('tumblr_button', dirname(__FILE__).'/button.tpl'); |
---|
| 91 | $button = $template->parse('tumblr_button', true); |
---|
| 92 | |
---|
| 93 | switch ($conf['TumblrShare']['position']) |
---|
| 94 | { |
---|
| 95 | case 'index': |
---|
| 96 | // $template->add_index_button('<li>'.$button.'</li>', 100); |
---|
| 97 | $template->concat('PLUGIN_INDEX_ACTIONS', '<li>'.$button.'</li>'); |
---|
| 98 | break; |
---|
| 99 | case 'toolbar': |
---|
| 100 | // $template->add_picture_button($button, 100); |
---|
| 101 | $template->concat('PLUGIN_PICTURE_ACTIONS', $button); |
---|
| 102 | break; |
---|
| 103 | default; |
---|
| 104 | $template->assign('TUMBLR_BUTTON', $button); |
---|
| 105 | $template->set_prefilter('picture', 'tumblr_add_button_prefilter'); |
---|
| 106 | } |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | function tumblr_add_button_prefilter($content, &$smarty) |
---|
| 110 | { |
---|
| 111 | global $template; |
---|
| 112 | |
---|
| 113 | switch ($template->get_template_vars('TUMBLR_POSITION')) |
---|
| 114 | { |
---|
| 115 | case 'top': |
---|
| 116 | $search = '<div id="theImage">'; |
---|
| 117 | $replace = '<div>{$TUMBLR_BUTTON}</div>'; |
---|
| 118 | break; |
---|
| 119 | |
---|
| 120 | case 'bottom': |
---|
| 121 | $search = '{$ELEMENT_CONTENT}'; |
---|
| 122 | $replace = '{$TUMBLR_BUTTON}'; |
---|
| 123 | break; |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | return str_replace($search, $search.$replace, $content); |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | |
---|
| 130 | if (script_basename() == 'admin') |
---|
| 131 | { |
---|
| 132 | add_event_handler('get_admin_plugin_menu_links', 'tumblr_plugin_admin_menu'); |
---|
| 133 | |
---|
| 134 | function tumblr_plugin_admin_menu($menu) |
---|
| 135 | { |
---|
| 136 | array_push($menu, array( |
---|
| 137 | 'NAME' => 'tumblr.share', |
---|
| 138 | 'URL' => get_root_url().'admin.php?page=plugin-'.basename(dirname(__FILE__)) |
---|
| 139 | )); |
---|
| 140 | return $menu; |
---|
| 141 | } |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | ?> |
---|