source: extensions/GooglePlusOne/main.inc.php @ 16859

Last change on this file since 16859 was 16310, checked in by mistic100, 12 years ago

another fix for stripped

File size: 3.3 KB
Line 
1<?php
2/*
3Plugin Name: Google+1
4Version: auto
5Description: Add a "+1" Google button
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=562
7Author: Mistic
8Author URI: http://www.strangeplanet.fr
9*/
10
11if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
12
13define('GPLUS1_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
14
15load_language('plugin.lang', GPLUS1_PATH);
16add_event_handler('loc_end_picture', 'gplus1_add_button');
17add_event_handler('loc_end_index', 'gplus1_add_button');
18
19
20function gplus1_add_button() 
21{
22  global $conf, $template, $user;
23 
24  $conf['GooglePlusOne'] = unserialize($conf['GooglePlusOne']);
25  $conf['GooglePlusOne']['lang'] = array(
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',
29    );
30 
31  // position for index
32  if (script_basename() == 'index')
33  {
34    $conf['GooglePlusOne']['position'] = 'index';
35  }
36 
37  // if the link is in the toolbar, we must use smallier buttons
38  if ( script_basename() == 'index' OR  $conf['GooglePlusOne']['position'] == 'toolbar')
39  {
40    if ($conf['GooglePlusOne']['size'] == 'tall' AND $conf['GooglePlusOne']['annotation'] == 'bubble')
41    {
42      $conf['GooglePlusOne']['size'] = 'standard';
43    }
44  }
45 
46  // config
47  $template->assign(array(
48    'GPLUS1_SIZE' => $conf['GooglePlusOne']['size'],
49    'GPLUS1_ANNO' => $conf['GooglePlusOne']['annotation'],
50    'GPLUS1_POSITON' => $conf['GooglePlusOne']['position'],
51  ));
52 
53  // button language
54  if ( in_array(str_replace('_','-',$user['language']), $conf['GooglePlusOne']['lang']) )
55  {
56    $template->assign('GPLUS1_LANG', str_replace('_','-',$user['language']));
57  }
58  if ( in_array(substr($user['language'],0,2), $conf['GooglePlusOne']['lang']) )
59  {
60    $template->assign('GPLUS1_LANG', substr($user['language'],0,2));
61  }
62  else
63  {
64    $template->assign('GPLUS1_LANG', 'en-GB');
65  }
66 
67 
68  $template->set_filename('gplus1_button', dirname(__FILE__).'/button.tpl');
69  $button = $template->parse('gplus1_button', true);
70 
71  switch ($conf['GooglePlusOne']['position'])
72  {
73    case 'index':
74      $template->concat('PLUGIN_INDEX_ACTIONS', '<li>'.$button.'</li>');
75      break;
76    case 'toolbar':
77      $template->concat('PLUGIN_PICTURE_ACTIONS', $button);
78      break;
79    default;
80      $template->assign('GPLUS1_BUTTON', $button);
81      $template->set_prefilter('picture', 'gplus1_add_button_prefilter');
82  }
83}
84
85function gplus1_add_button_prefilter($content, &$smarty)
86{
87  global $template;
88 
89  switch ($template->get_template_vars('GPLUS1_POSITON'))
90  {
91    case 'top':
92      $search = '<div id="theImage">';
93      $replace = '<div>{$GPLUS1_BUTTON}</div>';
94      break;
95     
96    case 'bottom':
97      $search = '{$ELEMENT_CONTENT}';
98      $replace = '{$GPLUS1_BUTTON}';
99      break;
100  }
101
102  return str_replace($search, $search.$replace, $content);
103}
104
105
106if (script_basename() == 'admin')
107{
108  add_event_handler('get_admin_plugin_menu_links', 'gplus1_plugin_admin_menu');
109
110  function gplus1_plugin_admin_menu($menu)
111  {
112    array_push($menu, array(
113      'NAME' => 'Google+1',
114      'URL' => get_root_url().'admin.php?page=plugin-'.basename(dirname(__FILE__))
115      ));
116    return $menu;
117  }
118}
119
120?>
Note: See TracBrowser for help on using the repository browser.