|
6 | 6 | * @package ElggTwitter |
7 | 7 | */ |
8 | 8 |
|
9 | | -//some required params |
10 | | - |
11 | 9 | $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 | + |
12 | 25 | $num = $vars['entity']->twitter_num; |
| 26 | +if (empty($num)) { |
| 27 | + $num = 5; |
| 28 | +} |
13 | 29 |
|
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; |
16 | 33 |
|
17 | 34 | ?> |
18 | | - |
19 | 35 | <div id="twitter_widget"> |
20 | 36 | <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> |
22 | 42 | <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> |
24 | 44 | </div> |
25 | | - |
26 | | -<?php |
27 | | -} else { |
28 | | - |
29 | | - echo "<div class=\"contentWrapper\"><p>" . elgg_echo("twitter:notset") . ".</p></div>"; |
30 | | - |
31 | | -} |
|
0 commit comments