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

Last change on this file since 13256 was 12388, checked in by mistic100, 12 years ago

button on index now works

File size: 4.7 KB
RevLine 
[11419]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');
[11463]17add_event_handler('loc_end_index', 'tweet_add_button');
[11419]18
19
20function tweet_add_button() 
21{
22  global $conf, $template;
23  $conf['TweetThis'] = explode(',', $conf['TweetThis']);
24 
[11463]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  }
[11514]43 
44  // html change a bit if we use custom button, or official with counter
45  if ( in_array( $conf['TweetThis'][0], array('none','horizontal','vertical') ) )
46  {
[12388]47    $template->assign(array(
48      'TWEET_IFRAME' => true,
49      'TWEET_COUNTER' => $conf['TweetThis'][0],
50    ));
[11514]51  }
52  else
53  {
[12388]54    $template->assign(array(
55      'TWEET_IFRAME' => false,
56      'TWEET_COUNTER' => 'none',
57    ));
[11514]58  }
59 
[12388]60  // if the link is in the toolbar, we must use smallier buttons
[11514]61  if ( script_basename() == 'index' OR  $conf['TweetThis'][1] == 'toolbar')
62  {
63    switch ($conf['TweetThis'][0])
64    {
65      case 'vertical':
66        $template->assign('TWEET_COUNTER', 'horizontal'); break;
67      case 't_logo-a':
68        $template->assign('TWEET_IMAGE', 't_small-a'); break; 
69      case 't_logo-b':
70        $template->assign('TWEET_IMAGE', 't_small-b'); break; 
71      case 't_logo-c':
72        $template->assign('TWEET_IMAGE', 't_small-c'); break;
73    }
74  }
[11419]75}
76
77function tweet_add_button_prefilter($content, &$smarty)
78{
79  global $template;
80 
81  switch ($template->get_template_vars('TWEET_POSITON'))
82  {
83    case 'top':
84      $search = '<div id="theImage">';
85      $replace = '
[11514]86<div><a href="javascript:phpWGOpenWindow(\'http://twitter.com/share?count={$TWEET_COUNTER}\', \'{\'Share on Twitter\'|@translate}\', \'scrollbars=yes,width=550,height=370\')"
87        class="{if $TWEET_IFRAME}twitter-share-button{/if}" title="{\'Share on Twitter\'|@translate}">
88  {if $TWEET_IFRAME}Tweet{else}<img src="http://twitter-badges.s3.amazonaws.com/{$TWEET_IMAGE}.png"/>{/if}
89</a></div>
[11419]90';
91      break;
92     
93    case 'bottom':
94      $search = '{$ELEMENT_CONTENT}';
95      $replace = '
[11514]96<a href="javascript:phpWGOpenWindow(\'http://twitter.com/share?count={$TWEET_COUNTER}\', \'{\'Share on Twitter\'|@translate}\', \'scrollbars=yes,width=550,height=370\')"
97    class="{if $TWEET_IFRAME}twitter-share-button{/if}" title="{\'Share on Twitter\'|@translate}">
98  {if $TWEET_IFRAME}Tweet{else}<img src="http://twitter-badges.s3.amazonaws.com/{$TWEET_IMAGE}.png"/>{/if}
[11419]99</a>
100';
101      break;
102     
103    case 'toolbar':
[11514]104      $search = '{*caddie management END*}';
[11419]105      $replace = '
[11514]106<a href="javascript:phpWGOpenWindow(\'http://twitter.com/share?count={$TWEET_COUNTER}\', \'{\'Share on Twitter\'|@translate}\', \'scrollbars=yes,width=550,height=370\')"
107    class="{if $TWEET_IFRAME}twitter-share-button{/if} pwg-button" title="{\'Share on Twitter\'|@translate}">
108  {if $TWEET_IFRAME}Tweet{else}<img src="http://twitter-badges.s3.amazonaws.com/{$TWEET_IMAGE}.png"/>{/if}
[11419]109</a>
110';
111      break;
[11463]112     
[11514]113    case 'index': 
[11463]114      $search = '<ul class="categoryActions">';
115      $replace = '
[12388]116{combine_script id=\'scripts\' path=\'themes/default/js/scripts.js\'}
[11514]117<li><a href="javascript:phpWGOpenWindow(\'http://twitter.com/share?count={$TWEET_COUNTER}\', \'{\'Share on Twitter\'|@translate}\', \'scrollbars=yes,width=550,height=370\')"
118        class="{if $TWEET_IFRAME}twitter-share-button{/if} pwg-button" title="{\'Share on Twitter\'|@translate}">
119  {if $TWEET_IFRAME}Tweet{else}<img src="http://twitter-badges.s3.amazonaws.com/{$TWEET_IMAGE}.png"/>{/if}
[11463]120</a></li>
121';
122      break;
[11419]123  }
124 
[11514]125  $replace = $search . $replace . '{if $TWEET_IFRAME}{combine_script id=\'twitter_widgets\' path=\'http://platform.twitter.com/widgets.js}{/if}';
[11419]126
127  return str_replace($search, $replace, $content);
128}
129
130
131if (script_basename() == 'admin')
132{
133  add_event_handler('get_admin_plugin_menu_links', 'tweet_plugin_admin_menu');
134
135  function tweet_plugin_admin_menu($menu)
136  {
137    array_push(
138      $menu,
139      array(
140        'NAME' => 'TweetThis',
141        'URL' => get_root_url().'admin.php?page=plugin-'.basename(dirname(__FILE__))
142        )
143      );
144   
145    return $menu;
146  }
147}
148
149?>
Note: See TracBrowser for help on using the repository browser.