This repository was archived by the owner on Apr 16, 2024. It is now read-only.
forked from drmonkeyninja/TXP-Tweet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharc_twitter_intents.php
More file actions
304 lines (211 loc) · 8.65 KB
/
arc_twitter_intents.php
File metadata and controls
304 lines (211 loc) · 8.65 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<?php
$plugin['name'] = 'arc_twitter_intents';
$plugin['version'] = '1.1';
$plugin['author'] = 'Andy Carter';
$plugin['author_uri'] = 'http://redhotchilliproject.com/';
$plugin['description'] = 'Twitter Web Intents';
$plugin['order'] = '5';
$plugin['type'] = '0';
// Plugin "flags" signal the presence of optional capabilities to the core plugin loader.
// Use an appropriately OR-ed combination of these flags.
// The four high-order bits 0xf000 are available for this plugin's private use
if (!defined('PLUGIN_HAS_PREFS')) define('PLUGIN_HAS_PREFS', 0x0001); // This plugin wants to receive "plugin_prefs.{$plugin['name']}" events
if (!defined('PLUGIN_LIFECYCLE_NOTIFY')) define('PLUGIN_LIFECYCLE_NOTIFY', 0x0002); // This plugin wants to receive "plugin_lifecycle.{$plugin['name']}" events
$plugin['flags'] = '3';
@include_once('zem_tpl.php');
# --- BEGIN PLUGIN CODE ---
global $prefs,$txpcfg;
// arc_twitter_intents requires arc_twitter v3.1 or higher
require_plugin('arc_twitter');
if (@txpinterface == 'admin') {
register_callback('_arc_twitter_auto_enable', 'plugin_lifecycle.arc_twitter_intents', 'installed');
}
function arc_twitter_intent_follow($atts, $thing=null)
{
global $prefs;
extract(lAtts(array(
'user' => $prefs['arc_twitter_user'],
'user_id' => '',
'lang' => '',
'include_js'=> true,
'optimise_js' => false,
'class' => ''
),$atts));
$q = ($user_id) ? 'user_id='.$user_id : 'screen_name='.$user;
$lang = _arc_twitter_intents_lang($lang);
$q .= '&lang='.urlencode($lang);
$thing = ($thing===null) ? 'Follow' : parse($thing);
$html = href($thing,'http://twitter.com/intent/user?'.$q
, ' class="'.$class.'"');
$js = ($include_js) ? _arc_twitter_widget_js($optimise_js?true:false) : '';
return $js.$html;
}
function arc_twitter_intent_favorite($atts, $thing=null)
{
global $prefs, $thisarticle;
extract(lAtts(array(
'user' => $prefs['arc_twitter_user'],
'related' => '',
'include_js'=> true,
'optimise_js' => false,
'lang' => '',
'id' => '',
'class' => ''
),$atts));
if ($id || $thisarticle['thisid']) {
$q = 'related='.$user;
if ($related) $q .= urlencode(($q?',':'related=').$related);
if (!$id) {
$row = safe_row("tweet_id"
, 'arc_twitter', "article_id={$thisarticle['thisid']}");
if (!$id = $row['tweet_id']) return false;
}
$q .= '&tweet_id='.$id;
$lang = _arc_twitter_intents_lang($lang);
$q .= '&lang='.urlencode($lang);
$thing = ($thing===null) ? 'Favorite' : parse($thing);
$html = href($thing,'http://twitter.com/intent/favorite?'.$q
, ' class="'.$class.'"');
$js = ($include_js) ? _arc_twitter_widget_js($optimise_js?true:false) : '';
return $js.$html;
}
return false;
}
function arc_twitter_intent_retweet($atts, $thing=null)
{
global $prefs, $thisarticle;
extract(lAtts(array(
'user' => $prefs['arc_twitter_user'],
'related' => '',
'include_js'=> true,
'optimise_js' => false,
'lang' => '',
'id' => '',
'class' => ''
),$atts));
if ($id || $thisarticle['thisid']) {
$q = 'related='.$user;
if ($related) $q .= urlencode(($q?',':'related=').$related);
if (!$id) {
$row = safe_row("tweet_id"
, 'arc_twitter', "article_id={$thisarticle['thisid']}");
if (!$id = $row['tweet_id']) return false;
}
$q .= '&tweet_id='.$id;
$lang = _arc_twitter_intents_lang($lang);
$q .= '&lang='.urlencode($lang);
$thing = ($thing===null) ? 'Retweet' : parse($thing);
$html = href($thing,'http://twitter.com/intent/retweet?'.$q
, ' class="'.$class.'"');
$js = ($include_js) ? _arc_twitter_widget_js($optimise_js?true:false) : '';
return $js.$html;
}
return false;
}
function arc_twitter_intent_reply($atts, $thing=null)
{
global $prefs, $thisarticle;
extract(lAtts(array(
'user' => $prefs['arc_twitter_user'],
'related' => '',
'text' => '',
'include_js'=> true,
'optimise_js' => false,
'lang' => '',
'id' => '',
'class' => ''
),$atts));
if ($id || $thisarticle['thisid']) {
if (!$id) {
$row = safe_row("tweet_id"
, 'arc_twitter', "article_id={$thisarticle['thisid']}");
if (!$id = $row['tweet_id']) return false;
}
$q = 'in_reply_to='.$id;
if ($user) {
$q .= '&related='.urlencode($user);
}
if ($related) {
$q .= urlencode(($user?',':'&related=').$related);
}
if ($text) {
$q .= '&text='.urlencode($text);
}
$lang = _arc_twitter_intents_lang($lang);
$q .= '&lang='.urlencode($lang);
$thing = ($thing===null) ? 'Reply' : parse($thing);
$html = href($thing,'http://twitter.com/intent/tweet?'.$q
, ' class="'.$class.'"');
$js = ($include_js) ? _arc_twitter_widget_js($optimise_js?true:false) : '';
return $js.$html;
}
return false;
}
/*
* Set the intent language
*/
function _arc_twitter_intents_lang($lang='en')
{
$lang = strtolower($lang);
$langs = array('en', 'it', 'es', 'fr', 'ko', 'jp');
return (in_array($lang,$langs)) ? $lang : 'en';
}
# --- END PLUGIN CODE ---
if (0) {
?>
<!--
# --- BEGIN PLUGIN HELP ---
h1(title). TXP Tweet Intents
arc_twitter_intents requires arc_twitter v3.1 or higher to work.
h2(section). The arc_twitter_intent_follow tag
h3. Syntax
<txp:arc_twitter_intent_follow>Follow</txp:arc_twitter_intent_follow>
h3. Usage
|_. Attribute|_. Description|_. Default|_. Example|
|user|Twitter user name to follow| _arc_twitter username_|user="drmonkeyninja"|
|user_id|Twitter user id to follow (overrides the user attribute)| _arc_twitter username_|user="drmonkeyninja"|
h2(section). The arc_twitter_intent_favorite tag
h3. Syntax
<txp:arc_twitter_intent_favorite>Favorite</txp:arc_twitter_intent_favorite>
h3. Usage
|_. Attribute|_. Description|_. Default|_. Example|
|id|Tweet id to favourite| _article's associated tweet from arc_twitter_| |
|user|Twitter user name related to tweet| _arc_twitter username_|user="drmonkeyninja"|
|related|Comma separated list of related Twitter users to recommend following| _unset_|related="textpattern, twitter"|
h2(section). The arc_twitter_intent_retweet tag
h3. Syntax
<txp:arc_twitter_intent_retweet>Retweet</txp:arc_twitter_intent_retweet>
h3. Usage
|_. Attribute|_. Description|_. Default|_. Example|
|id|Tweet id to retweet| _article's associated tweet from arc_twitter_| |
|user|Twitter user name related to tweet| _arc_twitter username_|user="drmonkeyninja"|
|related|Comma separated list of related Twitter users to recommend following| _unset_|related="textpattern, twitter"|
h2(section). The arc_twitter_intent_reply tag
h3. Syntax
<txp:arc_twitter_intent_reply>Reply</txp:arc_twitter_intent_reply>
h3. Usage
|_. Attribute|_. Description|_. Default|_. Example|
|id|Tweet id to reply to| _article's associated tweet from arc_twitter_| |
|user|Twitter user name related to tweet (used for recommended accounts)| _arc_twitter username_|user="drmonkeyninja"|
|related|Comma separated list of related Twitter users to recommend following| _unset_|related="textpattern, twitter"|
|text|Set some text for the reply tweet| _unset_| |
h2(section). Language
All the arc_twitter_intents tags have an optional "lang" attribute for setting the language of the Twitter interface. The following values/languages are available:-
|_. Attribute value|_. Language|
|en|English (default)|
|fr|French|
|it|Italian|
|es|Spanish|
|ko|Korean|
|jp|Japanese|
h2(section). JavaScript
All the arc_twitter_intents tags have two optional attributes that relate to the inclusion of the Twitter widget JavaScript.
|_. Attribute|_. Description|_. Default|_. Example|
|include_js|Include the Twitter widget JavaScript|true|include_js="false"|
|optimise_js|Optimise the JavaScript by using a local script rather than that hosted on the Twitter site|false|optimise_js="true"|
TXP Tweet will only include the widget JavaScript once on a page regardless of the number of tags used that include it.
# --- END PLUGIN HELP ---
-->
<?php
}
?>