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

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

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

File size: 3.9 KB
RevLine 
[11600]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
[20362]19add_event_handler('loc_begin_admin_page', 'gplus1_depreciated');
[11600]20
[20359]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
[11600]28function gplus1_add_button() 
29{
30  global $conf, $template, $user;
31 
[15121]32  $conf['GooglePlusOne'] = unserialize($conf['GooglePlusOne']);
[11600]33  $conf['GooglePlusOne']['lang'] = array(
[15121]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',
[11600]37    );
38 
[19396]39  // urls and position
40  if (script_basename() == 'picture')
[11600]41  {
[19396]42    $template->assign('GPLUS1_URL', get_absolute_root_url().ltrim(duplicate_picture_url(), './'));
43  }
44  else if (script_basename() == 'index')
45  {
[16310]46    $conf['GooglePlusOne']['position'] = 'index';
[19396]47    $template->assign('GPLUS1_URL', get_absolute_root_url().ltrim(duplicate_index_url(array(), array('start')), './'));
[11600]48  }
[19396]49  else
50  {
51    return;
52  }
[11600]53 
54  // if the link is in the toolbar, we must use smallier buttons
[15121]55  if ( script_basename() == 'index' OR  $conf['GooglePlusOne']['position'] == 'toolbar')
[11600]56  {
[15121]57    if ($conf['GooglePlusOne']['size'] == 'tall' AND $conf['GooglePlusOne']['annotation'] == 'bubble')
[11600]58    {
[16310]59      $conf['GooglePlusOne']['size'] = 'standard';
[11600]60    }
61  }
62 
[16310]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 
[11600]70  // button language
[15121]71  if ( in_array(str_replace('_','-',$user['language']), $conf['GooglePlusOne']['lang']) )
72  {
73    $template->assign('GPLUS1_LANG', str_replace('_','-',$user['language']));
74  }
[11600]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  }
[16310]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':
[19363]91      // $template->add_index_button('<li>'.$button.'</li>', 100);
[16310]92      $template->concat('PLUGIN_INDEX_ACTIONS', '<li>'.$button.'</li>');
93      break;
94    case 'toolbar':
[19363]95      // $template->add_picture_button($button, 100);
[16310]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  }
[11600]102}
103
104function gplus1_add_button_prefilter($content, &$smarty)
105{
106  global $template;
107 
[19363]108  switch ($template->get_template_vars('GPLUS1_POSITION'))
[11600]109  {
110    case 'top':
111      $search = '<div id="theImage">';
[16310]112      $replace = '<div>{$GPLUS1_BUTTON}</div>';
[11600]113      break;
114     
115    case 'bottom':
116      $search = '{$ELEMENT_CONTENT}';
[16310]117      $replace = '{$GPLUS1_BUTTON}';
[11600]118      break;
119  }
120
[15121]121  return str_replace($search, $search.$replace, $content);
[11600]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  {
[15121]131    array_push($menu, array(
132      'NAME' => 'Google+1',
133      'URL' => get_root_url().'admin.php?page=plugin-'.basename(dirname(__FILE__))
134      ));
[11600]135    return $menu;
136  }
137}
138
139?>
Note: See TracBrowser for help on using the repository browser.