[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 | ); |
---|
[15121] | 30 | |
---|
| 31 | $template->assign(array( |
---|
| 32 | 'GPLUS1_SIZE' => $conf['GooglePlusOne']['size'], |
---|
| 33 | 'GPLUS1_ANNO' => $conf['GooglePlusOne']['annotation'], |
---|
| 34 | )); |
---|
[11600] | 35 | |
---|
| 36 | if (script_basename() == 'picture') |
---|
| 37 | { |
---|
[15121] | 38 | $template->assign('GPLUS1_POSITON', $conf['GooglePlusOne']['position']); |
---|
[11600] | 39 | $template->set_prefilter('picture', 'gplus1_add_button_prefilter'); |
---|
| 40 | } |
---|
| 41 | else if (script_basename() == 'index') |
---|
| 42 | { |
---|
[15121] | 43 | $template->assign('GPLUS1_POSITON', 'index'); |
---|
[11600] | 44 | $template->set_prefilter('index', 'gplus1_add_button_prefilter'); |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | // if the link is in the toolbar, we must use smallier buttons |
---|
[15121] | 48 | if ( script_basename() == 'index' OR $conf['GooglePlusOne']['position'] == 'toolbar') |
---|
[11600] | 49 | { |
---|
[15121] | 50 | if ($conf['GooglePlusOne']['size'] == 'tall' AND $conf['GooglePlusOne']['annotation'] == 'bubble') |
---|
[11600] | 51 | { |
---|
| 52 | $template->assign('GPLUS1_SIZE', 'standard'); |
---|
| 53 | } |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | // button language |
---|
[15121] | 57 | if ( in_array(str_replace('_','-',$user['language']), $conf['GooglePlusOne']['lang']) ) |
---|
| 58 | { |
---|
| 59 | $template->assign('GPLUS1_LANG', str_replace('_','-',$user['language'])); |
---|
| 60 | } |
---|
[11600] | 61 | if ( in_array(substr($user['language'],0,2), $conf['GooglePlusOne']['lang']) ) |
---|
| 62 | { |
---|
| 63 | $template->assign('GPLUS1_LANG', substr($user['language'],0,2)); |
---|
| 64 | } |
---|
| 65 | else |
---|
| 66 | { |
---|
| 67 | $template->assign('GPLUS1_LANG', 'en-GB'); |
---|
| 68 | } |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | function gplus1_add_button_prefilter($content, &$smarty) |
---|
| 72 | { |
---|
| 73 | global $template; |
---|
| 74 | |
---|
[15121] | 75 | $replace = '{combine_script id=\'google_plusone\' path=\'https://apis.google.com/js/plusone.js\'} |
---|
| 76 | <script type="text/javascript">window.___gcfg = {ldelim}lang: \'{$GPLUS1_LANG}\'};</script> |
---|
| 77 | <g:plusone size="{$GPLUS1_SIZE}" annotation="{$GPLUS1_ANNO}"></g:plusone>'; |
---|
| 78 | |
---|
[11600] | 79 | switch ($template->get_template_vars('GPLUS1_POSITON')) |
---|
| 80 | { |
---|
| 81 | case 'top': |
---|
| 82 | $search = '<div id="theImage">'; |
---|
[15121] | 83 | $replace = '<div>'.$replace.'</div>'; |
---|
[11600] | 84 | break; |
---|
| 85 | |
---|
| 86 | case 'bottom': |
---|
| 87 | $search = '{$ELEMENT_CONTENT}'; |
---|
| 88 | break; |
---|
| 89 | |
---|
| 90 | case 'toolbar': |
---|
[15121] | 91 | $search = '<div class="actionButtons">'; |
---|
[11600] | 92 | break; |
---|
| 93 | |
---|
| 94 | case 'index': |
---|
| 95 | $search = '<ul class="categoryActions">'; |
---|
[15121] | 96 | $replace = '<li>'.$replace.'</li>'; |
---|
[11600] | 97 | break; |
---|
| 98 | } |
---|
| 99 | |
---|
[15121] | 100 | return str_replace($search, $search.$replace, $content); |
---|
[11600] | 101 | } |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | if (script_basename() == 'admin') |
---|
| 105 | { |
---|
| 106 | add_event_handler('get_admin_plugin_menu_links', 'gplus1_plugin_admin_menu'); |
---|
| 107 | |
---|
| 108 | function gplus1_plugin_admin_menu($menu) |
---|
| 109 | { |
---|
[15121] | 110 | array_push($menu, array( |
---|
| 111 | 'NAME' => 'Google+1', |
---|
| 112 | 'URL' => get_root_url().'admin.php?page=plugin-'.basename(dirname(__FILE__)) |
---|
| 113 | )); |
---|
[11600] | 114 | return $menu; |
---|
| 115 | } |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | ?> |
---|