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

Last change on this file since 11604 was 11600, checked in by mistic100, 13 years ago

Create GooglePlusOne (Google+1) extension
(based on TweetThis)

File size: 3.2 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'] = explode(',', $conf['GooglePlusOne']);
25  $conf['GooglePlusOne']['lang'] = array(
26    'ar','bg','ca','hr','cs','da','nl','et','fi','fr','de','el','iw','hi',
27    'hu','id','it','ja','ko','lv','lt','ms','no','fa','pl','ro','ru','sr',
28    'sk','sl','es','sv','th','tr','uk','vi'
29    );
30 
31  if (script_basename() == 'picture')
32  {
33    $template->assign(array(
34      'GPLUS1_SIZE' => $conf['GooglePlusOne'][0],
35      'GPLUS1_POSITON' => $conf['GooglePlusOne'][1],
36    ));
37       
38    $template->set_prefilter('picture', 'gplus1_add_button_prefilter');
39  }
40  else if (script_basename() == 'index')
41  {
42    $template->assign(array(
43      'GPLUS1_SIZE' => $conf['GooglePlusOne'][0],
44      'GPLUS1_POSITON' => 'index',
45    ));
46       
47    $template->set_prefilter('index', 'gplus1_add_button_prefilter');
48  }
49 
50  // if the link is in the toolbar, we must use smallier buttons
51  if ( script_basename() == 'index' OR  $conf['GooglePlusOne'][1] == 'toolbar')
52  {
53    if ($conf['GooglePlusOne'][0] == 'tall')
54    {
55        $template->assign('GPLUS1_SIZE', 'standard');
56    }
57  }
58 
59  // button language
60  if ( in_array(substr($user['language'],0,2), $conf['GooglePlusOne']['lang']) )
61  {
62    $template->assign('GPLUS1_LANG', substr($user['language'],0,2));
63  }
64  else
65  {
66    $template->assign('GPLUS1_LANG', 'en-GB');
67  }
68}
69
70function gplus1_add_button_prefilter($content, &$smarty)
71{
72  global $template;
73 
74  switch ($template->get_template_vars('GPLUS1_POSITON'))
75  {
76    case 'top':
77      $search = '<div id="theImage">';
78      $replace = '<div><g:plusone size="{$GPLUS1_SIZE}"></g:plusone></div>';
79      break;
80     
81    case 'bottom':
82      $search = '{$ELEMENT_CONTENT}';
83      $replace = '<g:plusone size="{$GPLUS1_SIZE}"></g:plusone>';
84      break;
85     
86    case 'toolbar':
87      $search = '{*caddie management END*}';
88      $replace = '<g:plusone size="{$GPLUS1_SIZE}"></g:plusone>';
89      break;
90     
91    case 'index': 
92      $search = '<ul class="categoryActions">';
93      $replace = '<li><g:plusone size="{$GPLUS1_SIZE}"></g:plusone></li>';
94      break;
95  }
96  $replace = $search.$replace.'
97{combine_script id=\'google_plusone\' path=\'https://apis.google.com/js/plusone.js\'}
98<script type="text/javascript">{ldelim}lang: \'{$GPLUS1_LANG}\'}</script>';
99
100  return str_replace($search, $replace, $content);
101}
102
103
104if (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  {
110    array_push(
111      $menu,
112      array(
113        'NAME' => 'Google+1',
114        'URL' => get_root_url().'admin.php?page=plugin-'.basename(dirname(__FILE__))
115        )
116      );
117   
118    return $menu;
119  }
120}
121
122?>
Note: See TracBrowser for help on using the repository browser.