[11600] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Plugin Name: Google+1 |
---|
| 4 | Version: auto |
---|
| 5 | Description: Add a "+1" Google button |
---|
| 6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=562 |
---|
| 7 | Author: Mistic |
---|
| 8 | Author URI: http://www.strangeplanet.fr |
---|
| 9 | */ |
---|
| 10 | |
---|
| 11 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 12 | |
---|
| 13 | define('GPLUS1_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/'); |
---|
| 14 | |
---|
| 15 | load_language('plugin.lang', GPLUS1_PATH); |
---|
| 16 | add_event_handler('loc_end_picture', 'gplus1_add_button'); |
---|
| 17 | add_event_handler('loc_end_index', 'gplus1_add_button'); |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | function gplus1_add_button() |
---|
| 21 | { |
---|
| 22 | global $conf, $template, $user; |
---|
| 23 | |
---|
[15121] | 24 | $conf['GooglePlusOne'] = unserialize($conf['GooglePlusOne']); |
---|
[11600] | 25 | $conf['GooglePlusOne']['lang'] = array( |
---|
[15121] | 26 | 'ar','bg','ca','zh-CN','zh-TW','hr','cs','da','nl','en-US','en-GB','et','fi','fr','de', |
---|
| 27 | 'el','iw','hi','hu','id','it','ja','ko','lv','lt','ms','no','fa','pl','pt-BR','pt-PT', |
---|
| 28 | 'ro','ru','sr','sk','sl','es','sv','th','tr','uk','vi', |
---|
[11600] | 29 | ); |
---|
| 30 | |
---|
[19396] | 31 | // urls and position |
---|
| 32 | if (script_basename() == 'picture') |
---|
[11600] | 33 | { |
---|
[19396] | 34 | $template->assign('GPLUS1_URL', get_absolute_root_url().ltrim(duplicate_picture_url(), './')); |
---|
| 35 | } |
---|
| 36 | else if (script_basename() == 'index') |
---|
| 37 | { |
---|
[16310] | 38 | $conf['GooglePlusOne']['position'] = 'index'; |
---|
[19396] | 39 | $template->assign('GPLUS1_URL', get_absolute_root_url().ltrim(duplicate_index_url(array(), array('start')), './')); |
---|
[11600] | 40 | } |
---|
[19396] | 41 | else |
---|
| 42 | { |
---|
| 43 | return; |
---|
| 44 | } |
---|
[11600] | 45 | |
---|
| 46 | // if the link is in the toolbar, we must use smallier buttons |
---|
[15121] | 47 | if ( script_basename() == 'index' OR $conf['GooglePlusOne']['position'] == 'toolbar') |
---|
[11600] | 48 | { |
---|
[15121] | 49 | if ($conf['GooglePlusOne']['size'] == 'tall' AND $conf['GooglePlusOne']['annotation'] == 'bubble') |
---|
[11600] | 50 | { |
---|
[16310] | 51 | $conf['GooglePlusOne']['size'] = 'standard'; |
---|
[11600] | 52 | } |
---|
| 53 | } |
---|
| 54 | |
---|
[16310] | 55 | // config |
---|
| 56 | $template->assign(array( |
---|
| 57 | 'GPLUS1_SIZE' => $conf['GooglePlusOne']['size'], |
---|
| 58 | 'GPLUS1_ANNO' => $conf['GooglePlusOne']['annotation'], |
---|
| 59 | 'GPLUS1_POSITON' => $conf['GooglePlusOne']['position'], |
---|
| 60 | )); |
---|
| 61 | |
---|
[11600] | 62 | // button language |
---|
[15121] | 63 | if ( in_array(str_replace('_','-',$user['language']), $conf['GooglePlusOne']['lang']) ) |
---|
| 64 | { |
---|
| 65 | $template->assign('GPLUS1_LANG', str_replace('_','-',$user['language'])); |
---|
| 66 | } |
---|
[11600] | 67 | if ( in_array(substr($user['language'],0,2), $conf['GooglePlusOne']['lang']) ) |
---|
| 68 | { |
---|
| 69 | $template->assign('GPLUS1_LANG', substr($user['language'],0,2)); |
---|
| 70 | } |
---|
| 71 | else |
---|
| 72 | { |
---|
| 73 | $template->assign('GPLUS1_LANG', 'en-GB'); |
---|
| 74 | } |
---|
[16310] | 75 | |
---|
| 76 | |
---|
| 77 | $template->set_filename('gplus1_button', dirname(__FILE__).'/button.tpl'); |
---|
| 78 | $button = $template->parse('gplus1_button', true); |
---|
| 79 | |
---|
| 80 | switch ($conf['GooglePlusOne']['position']) |
---|
| 81 | { |
---|
| 82 | case 'index': |
---|
[19363] | 83 | // $template->add_index_button('<li>'.$button.'</li>', 100); |
---|
[16310] | 84 | $template->concat('PLUGIN_INDEX_ACTIONS', '<li>'.$button.'</li>'); |
---|
| 85 | break; |
---|
| 86 | case 'toolbar': |
---|
[19363] | 87 | // $template->add_picture_button($button, 100); |
---|
[16310] | 88 | $template->concat('PLUGIN_PICTURE_ACTIONS', $button); |
---|
| 89 | break; |
---|
| 90 | default; |
---|
| 91 | $template->assign('GPLUS1_BUTTON', $button); |
---|
| 92 | $template->set_prefilter('picture', 'gplus1_add_button_prefilter'); |
---|
| 93 | } |
---|
[11600] | 94 | } |
---|
| 95 | |
---|
| 96 | function gplus1_add_button_prefilter($content, &$smarty) |
---|
| 97 | { |
---|
| 98 | global $template; |
---|
| 99 | |
---|
[19363] | 100 | switch ($template->get_template_vars('GPLUS1_POSITION')) |
---|
[11600] | 101 | { |
---|
| 102 | case 'top': |
---|
| 103 | $search = '<div id="theImage">'; |
---|
[16310] | 104 | $replace = '<div>{$GPLUS1_BUTTON}</div>'; |
---|
[11600] | 105 | break; |
---|
| 106 | |
---|
| 107 | case 'bottom': |
---|
| 108 | $search = '{$ELEMENT_CONTENT}'; |
---|
[16310] | 109 | $replace = '{$GPLUS1_BUTTON}'; |
---|
[11600] | 110 | break; |
---|
| 111 | } |
---|
| 112 | |
---|
[15121] | 113 | return str_replace($search, $search.$replace, $content); |
---|
[11600] | 114 | } |
---|
| 115 | |
---|
| 116 | |
---|
| 117 | if (script_basename() == 'admin') |
---|
| 118 | { |
---|
| 119 | add_event_handler('get_admin_plugin_menu_links', 'gplus1_plugin_admin_menu'); |
---|
| 120 | |
---|
| 121 | function gplus1_plugin_admin_menu($menu) |
---|
| 122 | { |
---|
[15121] | 123 | array_push($menu, array( |
---|
| 124 | 'NAME' => 'Google+1', |
---|
| 125 | 'URL' => get_root_url().'admin.php?page=plugin-'.basename(dirname(__FILE__)) |
---|
| 126 | )); |
---|
[11600] | 127 | return $menu; |
---|
| 128 | } |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | ?> |
---|