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

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

first commit

File size: 2.3 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');
17
18
19function tweet_add_button() 
20{
21  global $conf, $template;
22  $conf['TweetThis'] = explode(',', $conf['TweetThis']);
23 
24  $template->assign(array(
25    'TWEET_IMAGE' => $conf['TweetThis'][0],
26    'TWEET_POSITON' => $conf['TweetThis'][1],
27  ));
28     
29  $template->set_prefilter('picture', 'tweet_add_button_prefilter');
30}
31
32function tweet_add_button_prefilter($content, &$smarty)
33{
34  global $template;
35 
36  switch ($template->get_template_vars('TWEET_POSITON'))
37  {
38    case 'top':
39      $search = '<div id="theImage">';
40      $replace = '
41<a href="http://twitter.com/share" class="twitter-share-button" title="{\'Share on Twitter\'|@translate}" style="display:block;">
42  <img src="http://twitter-badges.s3.amazonaws.com/{$TWEET_IMAGE}.png"/>
43</a>
44';
45      break;
46     
47    case 'bottom':
48      $search = '{$ELEMENT_CONTENT}';
49      $replace = '
50<a href="http://twitter.com/share" class="twitter-share-button" title="{\'Share on Twitter\'|@translate}" style="display:block;">
51  <img src="http://twitter-badges.s3.amazonaws.com/{$TWEET_IMAGE}.png"/>
52</a>
53';
54      break;
55     
56    case 'toolbar':
57      $search = '{/if}{/strip}{*caddie management END*}';
58      $replace = '
59<a href="http://twitter.com/share" class="twitter-share-button pwg-button" title="{\'Share on Twitter\'|@translate}">
60  <img src="http://twitter-badges.s3.amazonaws.com/{$TWEET_IMAGE}.png"/>
61</a>
62';
63      break;
64  }
65 
66  $replace = $search . $replace . '{combine_script id=\'twitter_widgets\' path=\'http://platform.twitter.com/widgets.js\'}';
67
68  return str_replace($search, $replace, $content);
69}
70
71
72if (script_basename() == 'admin')
73{
74  add_event_handler('get_admin_plugin_menu_links', 'tweet_plugin_admin_menu');
75
76  function tweet_plugin_admin_menu($menu)
77  {
78    array_push(
79      $menu,
80      array(
81        'NAME' => 'TweetThis',
82        'URL' => get_root_url().'admin.php?page=plugin-'.basename(dirname(__FILE__))
83        )
84      );
85   
86    return $menu;
87  }
88}
89
90?>
Note: See TracBrowser for help on using the repository browser.