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

Last change on this file since 30904 was 20362, checked in by mistic100, 12 years ago

[googleplusone][tumblrshare][tweetthis] trigger not working in 2.4

File size: 3.9 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
19add_event_handler('loc_begin_admin_page', 'gplus1_depreciated');
20
21function gplus1_depreciated()
22{
23  global $page;
24  $page['warnings'][] = 'Google+1 is depreciated, please use <a href="http://piwigo.org/ext/extension_view.php?eid=673">Social Buttons</a> instead.';
25}
26
27
28function gplus1_add_button() 
29{
30  global $conf, $template, $user;
31 
32  $conf['GooglePlusOne'] = unserialize($conf['GooglePlusOne']);
33  $conf['GooglePlusOne']['lang'] = array(
34    'ar','bg','ca','zh-CN','zh-TW','hr','cs','da','nl','en-US','en-GB','et','fi','fr','de',
35    'el','iw','hi','hu','id','it','ja','ko','lv','lt','ms','no','fa','pl','pt-BR','pt-PT',
36    'ro','ru','sr','sk','sl','es','sv','th','tr','uk','vi',
37    );
38 
39  // urls and position
40  if (script_basename() == 'picture')
41  {
42    $template->assign('GPLUS1_URL', get_absolute_root_url().ltrim(duplicate_picture_url(), './'));
43  }
44  else if (script_basename() == 'index')
45  {
46    $conf['GooglePlusOne']['position'] = 'index';
47    $template->assign('GPLUS1_URL', get_absolute_root_url().ltrim(duplicate_index_url(array(), array('start')), './'));
48  }
49  else
50  {
51    return;
52  }
53 
54  // if the link is in the toolbar, we must use smallier buttons
55  if ( script_basename() == 'index' OR  $conf['GooglePlusOne']['position'] == 'toolbar')
56  {
57    if ($conf['GooglePlusOne']['size'] == 'tall' AND $conf['GooglePlusOne']['annotation'] == 'bubble')
58    {
59      $conf['GooglePlusOne']['size'] = 'standard';
60    }
61  }
62 
63  // config
64  $template->assign(array(
65    'GPLUS1_SIZE' => $conf['GooglePlusOne']['size'],
66    'GPLUS1_ANNO' => $conf['GooglePlusOne']['annotation'],
67    'GPLUS1_POSITON' => $conf['GooglePlusOne']['position'],
68  ));
69 
70  // button language
71  if ( in_array(str_replace('_','-',$user['language']), $conf['GooglePlusOne']['lang']) )
72  {
73    $template->assign('GPLUS1_LANG', str_replace('_','-',$user['language']));
74  }
75  if ( in_array(substr($user['language'],0,2), $conf['GooglePlusOne']['lang']) )
76  {
77    $template->assign('GPLUS1_LANG', substr($user['language'],0,2));
78  }
79  else
80  {
81    $template->assign('GPLUS1_LANG', 'en-GB');
82  }
83 
84 
85  $template->set_filename('gplus1_button', dirname(__FILE__).'/button.tpl');
86  $button = $template->parse('gplus1_button', true);
87 
88  switch ($conf['GooglePlusOne']['position'])
89  {
90    case 'index':
91      // $template->add_index_button('<li>'.$button.'</li>', 100);
92      $template->concat('PLUGIN_INDEX_ACTIONS', '<li>'.$button.'</li>');
93      break;
94    case 'toolbar':
95      // $template->add_picture_button($button, 100);
96      $template->concat('PLUGIN_PICTURE_ACTIONS', $button);
97      break;
98    default;
99      $template->assign('GPLUS1_BUTTON', $button);
100      $template->set_prefilter('picture', 'gplus1_add_button_prefilter');
101  }
102}
103
104function gplus1_add_button_prefilter($content, &$smarty)
105{
106  global $template;
107 
108  switch ($template->get_template_vars('GPLUS1_POSITION'))
109  {
110    case 'top':
111      $search = '<div id="theImage">';
112      $replace = '<div>{$GPLUS1_BUTTON}</div>';
113      break;
114     
115    case 'bottom':
116      $search = '{$ELEMENT_CONTENT}';
117      $replace = '{$GPLUS1_BUTTON}';
118      break;
119  }
120
121  return str_replace($search, $search.$replace, $content);
122}
123
124
125if (script_basename() == 'admin')
126{
127  add_event_handler('get_admin_plugin_menu_links', 'gplus1_plugin_admin_menu');
128
129  function gplus1_plugin_admin_menu($menu)
130  {
131    array_push($menu, array(
132      'NAME' => 'Google+1',
133      'URL' => get_root_url().'admin.php?page=plugin-'.basename(dirname(__FILE__))
134      ));
135    return $menu;
136  }
137}
138
139?>
Note: See TracBrowser for help on using the repository browser.