-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflattr.plugin.php
92 lines (76 loc) · 2.82 KB
/
flattr.plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/**
* Flattr plugin
* adding a flattr autosubmit button to your posts
*
* @package flattr
* @author fengor <[email protected]>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link http://fengors-realm.de/habari/flattr
*/
class Flattr extends Plugin {
public function action_plugin_activation($file) {
if ( Plugins::id_from_file( $file ) != Plugins::id_from_file( __FILE__ ) ) return;
Options::set('flattr__add_button','true');
Options::set('flattr__set_hidden','0');
}
public function action_plugin_ui($plugin_id,$action) {
if ($plugin_id != $this->plugin_id()) return;
if ($action == _t('Configure')) {
$ui = new FormUI(strtolower(get_class($this)));
$flattr_uid = $ui->append('text','flattr_uid','flattr__uid',_t('Flattr username: '));
$large_icon = $ui->append('select','large_icon','option:flattr__large_icon',_t('Show large image'));
$large_icon->options = array('true'=>'Large Image','fals'=>'Small Image');
$set_hidden = $ui->append('select','set_hidden','option:flattr__set_hidden',_t('Hide flattr from public listing'));
$set_hidden->options = array('0'=>'Show flattr','1'=>'Hide flattr');
$add_button = $ui->append('select','add_button','option:flattr__add_button',_t('Auto Insert: '));
$add_button->options = array('true'=>'True','false'=>'False');
$ui->append('submit','save',_t('Save'));
$ui->out();
}
}
public function filter_plugin_config($actions, $plugin_id) {
if ($plugin_id == $this->plugin_id()) {
$actions[]= _t('Configure');
}
return $actions;
}
public function filter_post_content_out($content, $post) {
$add_button = Options::get('flattr__add_button');
if ($add_button == 'true') {
$content = $content . $this->create_autolink($post);
}
return $content;
}
public function theme_show_flattr($theme, $post) {
return $this->create_autolink($post);
}
private function create_autolink($post) {
$link = '<div class="flattr">';
$site_title = Options::get('title');
$flattr_uid = Options::get('flattr__uid');
$show_large = Options::get('flattr__large_icon');
$hide_flattr = Options::get('flattr__set_hidden');
$flattr_tags = '';
$tags = $post->tags;
foreach($tags as $tag) {
if ($flattr_tags) {
$flattr_tags .= ','.$tag;
} else {
$flattr_tags .= $tag;
}
}
$img_url = '';
if ($show_large == 'true') {
$img_url='https://api.flattr.com/button/flattr-badge-large.png';
} else {
$img_url='https://flattr.com/_img/icons/flattr_logo_16.png';
}
$link .= '<a href="https://flattr.com/submit/auto?user_id='.$flattr_uid.'&url='.urlencode($post->permalink).'&title='.urlencode($site_title.' - '.$post->title_out);
$link .= '&tags='.urlencode($flattr_tags).'&hidden='.urlencode($hide_flattr);
$link .= '"><img src="'.$img_url.'" /></a>';
$link .= '</div>';
return $link;
}
}
?>