Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Corrects encoding and other small tweaks in Twitter widget

  • Loading branch information...
commit a74a88501c41e89c8bcd7fc650ae2f8cc0a5003d 1 parent f76371b
@mrclay mrclay authored cash committed
View
9 mod/twitter/languages/en.php
@@ -4,13 +4,14 @@
*/
$english = array(
-
'twitter:title' => 'Twitter',
'twitter:info' => 'Display your latest tweets',
- 'twitter:username' => 'Enter your twitter username.',
- 'twitter:num' => 'The number of tweets to show.',
+ 'twitter:username' => 'Your twitter username',
+ 'twitter:num' => 'Number of tweets to show*',
'twitter:visit' => 'visit my twitter',
- 'twitter:notset' => 'This Twitter widget is not yet set to go. To display your latest tweets, click on - edit - and fill in your details',
+ 'twitter:notset' => 'This widget needs to be configured. To display your latest tweets, click EDIT and fill in your Twitter username.',
+ 'twitter:invalid' => 'This widget is configured with an invalid Twitter username. Click EDIT to correct it.',
+ 'twitter:apibug' => "*Due to a bug in the Twitter 1.0 API, you may see fewer tweets than you ask for.",
);
add_translation("en", $english);
View
20 mod/twitter/views/default/widgets/twitter/edit.php
@@ -8,9 +8,19 @@
?>
<p>
- <?php echo elgg_echo("twitter:username"); ?>
- <input type="text" name="params[twitter_username]" value="<?php echo htmlentities($vars['entity']->twitter_username); ?>" />
- <br /><?php echo elgg_echo("twitter:num"); ?>
- <input type="text" name="params[twitter_num]" value="<?php echo htmlentities($vars['entity']->twitter_num); ?>" />
-
+ <label><?php echo elgg_echo("twitter:username"); ?>
+ <?php echo elgg_view('input/text', array(
+ 'internalname' => 'params[twitter_username]',
+ 'value' => $vars['entity']->twitter_username,
+ )) ?>
+ </label>
+ </p>
+ <p>
+ <label><?php echo elgg_echo("twitter:num"); ?>
+ <?php echo elgg_view('input/text', array(
+ 'internalname' => 'params[twitter_num]',
+ 'value' => $vars['entity']->twitter_num,
+ )) ?>
+ </label>
+ <small><?php echo elgg_echo("twitter:apibug") ?></small>
</p>
View
41 mod/twitter/views/default/widgets/twitter/view.php
@@ -6,26 +6,39 @@
* @package ElggTwitter
*/
-//some required params
-
$username = $vars['entity']->twitter_username;
+
+if (empty($username)) {
+ echo "<div class=\"contentWrapper\"><p>" . elgg_echo("twitter:notset") . "</p></div>";
+ return;
+}
+
+$username_is_valid = preg_match('~^[a-zA-Z0-9_]{1,20}$~', $username);
+
+if (!$username_is_valid) {
+ echo "<div class=\"contentWrapper\"><p>" . elgg_echo("twitter:invalid") . "</p></div>";
+ return;
+}
+
+
+
$num = $vars['entity']->twitter_num;
+if (empty($num)) {
+ $num = 5;
+}
-// if the twitter username is empty, then do not show
-if ($username) {
+// @todo upgrade to 1.1 API https://dev.twitter.com/docs/api/1.1/get/statuses/home_timeline
+$script_url = "https://api.twitter.com/1/statuses/user_timeline/" . urlencode($username) . ".json"
+ . "?callback=twitterCallback2&count=" . (int) $num;
?>
-
<div id="twitter_widget">
<ul id="twitter_update_list"></ul>
- <p class="visit_twitter"><a href="http://twitter.com/<?php echo $username; ?>"><?php echo elgg_echo("twitter:visit"); ?></a></p>
+ <p class="visit_twitter"><?php echo elgg_view('output/url', array(
+ 'text' => elgg_echo("twitter:visit"),
+ 'href' => 'http://twitter.com/' . urlencode($username),
+ 'is_trusted' => true,
+ )) ?></p>
<script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script>
- <script type="text/javascript" src="http://twitter.com/statuses/user_timeline/<?php echo $username; ?>.json?callback=twitterCallback2&count=<?php echo $num; ?>"></script>
+ <script type="text/javascript" src="<?php echo htmlspecialchars($script_url, ENT_QUOTES, 'UTF-8') ?>"></script>
</div>
-
-<?php
-} else {
-
- echo "<div class=\"contentWrapper\"><p>" . elgg_echo("twitter:notset") . ".</p></div>";
-
-}
Please sign in to comment.
Something went wrong with that request. Please try again.