source: extensions/TweetThis/main.inc.php @ 11476

Last change on this file since 11476 was 11463, checked in by mistic100, 13 years ago

add button on index toolbar

File size: 3.0 KB
Line 
1<?php
2/*
3Plugin Name: TweetThis
4Version: auto
5Description: Add a "Tweet This" button on picture pages
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=560
7Author: Mistic
8Author URI: http://www.strangeplanet.fr
9*/
10
11if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
12
13define('TWEET_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
14
15load_language('plugin.lang', TWEET_PATH);
16add_event_handler('loc_end_picture', 'tweet_add_button');
17add_event_handler('loc_end_index', 'tweet_add_button');
18
19
20function tweet_add_button() 
21{
22  global $conf, $template;
23  $conf['TweetThis'] = explode(',', $conf['TweetThis']);
24 
25  if (script_basename() == 'picture')
26  {
27    $template->assign(array(
28      'TWEET_IMAGE' => $conf['TweetThis'][0],
29      'TWEET_POSITON' => $conf['TweetThis'][1],
30    ));
31       
32    $template->set_prefilter('picture', 'tweet_add_button_prefilter');
33  }
34  else if (script_basename() == 'index')
35  {
36    $template->assign(array(
37      'TWEET_IMAGE' => $conf['TweetThis'][0],
38      'TWEET_POSITON' => 'index',
39    ));
40       
41    $template->set_prefilter('index', 'tweet_add_button_prefilter');
42  }
43}
44
45function tweet_add_button_prefilter($content, &$smarty)
46{
47  global $template;
48 
49  switch ($template->get_template_vars('TWEET_POSITON'))
50  {
51    case 'top':
52      $search = '<div id="theImage">';
53      $replace = '
54<a href="http://twitter.com/share" class="twitter-share-button" title="{\'Share on Twitter\'|@translate}" style="display:block;">
55  <img src="http://twitter-badges.s3.amazonaws.com/{$TWEET_IMAGE}.png"/>
56</a>
57';
58      break;
59     
60    case 'bottom':
61      $search = '{$ELEMENT_CONTENT}';
62      $replace = '
63<a href="http://twitter.com/share" class="twitter-share-button" title="{\'Share on Twitter\'|@translate}" style="display:block;">
64  <img src="http://twitter-badges.s3.amazonaws.com/{$TWEET_IMAGE}.png"/>
65</a>
66';
67      break;
68     
69    case 'toolbar':
70      $search = '{/if}{/strip}{*caddie management END*}';
71      $replace = '
72<a href="http://twitter.com/share" class="twitter-share-button pwg-button" title="{\'Share on Twitter\'|@translate}">
73  <img src="http://twitter-badges.s3.amazonaws.com/{$TWEET_IMAGE}.png"/>
74</a>
75';
76      break;
77     
78    case 'index':
79      $search = '<ul class="categoryActions">';
80      $replace = '
81<li><a href="http://twitter.com/share" class="twitter-share-button pwg-button" title="{\'Share on Twitter\'|@translate}">
82  <img src="http://twitter-badges.s3.amazonaws.com/{$TWEET_IMAGE}.png"/>
83</a></li>
84';
85      break;
86  }
87 
88  $replace = $search . $replace . '{combine_script id=\'twitter_widgets\' path=\'http://platform.twitter.com/widgets.js\'}';
89
90  return str_replace($search, $replace, $content);
91}
92
93
94if (script_basename() == 'admin')
95{
96  add_event_handler('get_admin_plugin_menu_links', 'tweet_plugin_admin_menu');
97
98  function tweet_plugin_admin_menu($menu)
99  {
100    array_push(
101      $menu,
102      array(
103        'NAME' => 'TweetThis',
104        'URL' => get_root_url().'admin.php?page=plugin-'.basename(dirname(__FILE__))
105        )
106      );
107   
108    return $menu;
109  }
110}
111
112?>
Note: See TracBrowser for help on using the repository browser.