Skip to content

Commit a74a885

Browse files
mrclaycash
authored andcommitted
Corrects encoding and other small tweaks in Twitter widget
1 parent f76371b commit a74a885

File tree

3 files changed

+47
-23
lines changed

3 files changed

+47
-23
lines changed

Diff for: mod/twitter/languages/en.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
*/
55

66
$english = array(
7-
87
'twitter:title' => 'Twitter',
98
'twitter:info' => 'Display your latest tweets',
10-
'twitter:username' => 'Enter your twitter username.',
11-
'twitter:num' => 'The number of tweets to show.',
9+
'twitter:username' => 'Your twitter username',
10+
'twitter:num' => 'Number of tweets to show*',
1211
'twitter:visit' => 'visit my twitter',
13-
'twitter:notset' => 'This Twitter widget is not yet set to go. To display your latest tweets, click on - edit - and fill in your details',
12+
'twitter:notset' => 'This widget needs to be configured. To display your latest tweets, click EDIT and fill in your Twitter username.',
13+
'twitter:invalid' => 'This widget is configured with an invalid Twitter username. Click EDIT to correct it.',
14+
'twitter:apibug' => "*Due to a bug in the Twitter 1.0 API, you may see fewer tweets than you ask for.",
1415
);
1516

1617
add_translation("en", $english);

Diff for: mod/twitter/views/default/widgets/twitter/edit.php

+15-5
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,19 @@
88

99
?>
1010
<p>
11-
<?php echo elgg_echo("twitter:username"); ?>
12-
<input type="text" name="params[twitter_username]" value="<?php echo htmlentities($vars['entity']->twitter_username); ?>" />
13-
<br /><?php echo elgg_echo("twitter:num"); ?>
14-
<input type="text" name="params[twitter_num]" value="<?php echo htmlentities($vars['entity']->twitter_num); ?>" />
15-
11+
<label><?php echo elgg_echo("twitter:username"); ?>
12+
<?php echo elgg_view('input/text', array(
13+
'internalname' => 'params[twitter_username]',
14+
'value' => $vars['entity']->twitter_username,
15+
)) ?>
16+
</label>
17+
</p>
18+
<p>
19+
<label><?php echo elgg_echo("twitter:num"); ?>
20+
<?php echo elgg_view('input/text', array(
21+
'internalname' => 'params[twitter_num]',
22+
'value' => $vars['entity']->twitter_num,
23+
)) ?>
24+
</label>
25+
<small><?php echo elgg_echo("twitter:apibug") ?></small>
1626
</p>

Diff for: mod/twitter/views/default/widgets/twitter/view.php

+27-14
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,39 @@
66
* @package ElggTwitter
77
*/
88

9-
//some required params
10-
119
$username = $vars['entity']->twitter_username;
10+
11+
if (empty($username)) {
12+
echo "<div class=\"contentWrapper\"><p>" . elgg_echo("twitter:notset") . "</p></div>";
13+
return;
14+
}
15+
16+
$username_is_valid = preg_match('~^[a-zA-Z0-9_]{1,20}$~', $username);
17+
18+
if (!$username_is_valid) {
19+
echo "<div class=\"contentWrapper\"><p>" . elgg_echo("twitter:invalid") . "</p></div>";
20+
return;
21+
}
22+
23+
24+
1225
$num = $vars['entity']->twitter_num;
26+
if (empty($num)) {
27+
$num = 5;
28+
}
1329

14-
// if the twitter username is empty, then do not show
15-
if ($username) {
30+
// @todo upgrade to 1.1 API https://dev.twitter.com/docs/api/1.1/get/statuses/home_timeline
31+
$script_url = "https://api.twitter.com/1/statuses/user_timeline/" . urlencode($username) . ".json"
32+
. "?callback=twitterCallback2&count=" . (int) $num;
1633

1734
?>
18-
1935
<div id="twitter_widget">
2036
<ul id="twitter_update_list"></ul>
21-
<p class="visit_twitter"><a href="http://twitter.com/<?php echo $username; ?>"><?php echo elgg_echo("twitter:visit"); ?></a></p>
37+
<p class="visit_twitter"><?php echo elgg_view('output/url', array(
38+
'text' => elgg_echo("twitter:visit"),
39+
'href' => 'http://twitter.com/' . urlencode($username),
40+
'is_trusted' => true,
41+
)) ?></p>
2242
<script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script>
23-
<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/<?php echo $username; ?>.json?callback=twitterCallback2&count=<?php echo $num; ?>"></script>
43+
<script type="text/javascript" src="<?php echo htmlspecialchars($script_url, ENT_QUOTES, 'UTF-8') ?>"></script>
2444
</div>
25-
26-
<?php
27-
} else {
28-
29-
echo "<div class=\"contentWrapper\"><p>" . elgg_echo("twitter:notset") . ".</p></div>";
30-
31-
}

0 commit comments

Comments
 (0)