rawky

Widgets after ?php

Jun 9th, 2011
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. <?php
  2.  
  3. function widget_twitter_init() {
  4.  
  5. if (!function_exists('register_sidebar_widget'))
  6. return;
  7.  
  8. function widget_twitter($args) {
  9.  
  10. extract($args);
  11.  
  12. $options = get_option('widget_twitter');
  13.  
  14. if (!is_array($options))
  15. //Default values
  16. $options = array('title' => 'Twitter');
  17.  
  18. $title = $options['title'];
  19.  
  20. echo $before_widget . $before_title . $title . $after_title;
  21.  
  22. ?>
  23. <div class="widget_twitter_embed">
  24. <?phpphp
  25. $access_token = check_twitter_credentials();
  26. if (empty($access_token)) {
  27.  
  28. echo '<p>Could not connect to twitter. PLease check that the account is properly setup in your wordpress admin panel</p>';
  29. var_dump($access_token);
  30. }
  31. else {
  32. ?>
  33. <ul class="twitter_status"> <?phpphp
  34. $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
  35. $user = $connection->get('account/verify_credentials');
  36. $tweets = $connection->get('statuses/user_timeline', array('screen_name' => $user->screen_name, 'count' => 4));
  37. foreach($tweets as $tweet) {
  38. if(!empty($tweet->text)):
  39. ?>
  40. <li>
  41. <a href="http://twitter.com/<?phpphp echo $tweet->user->screen_name; ?>/status/<?phpphp echo $tweet->id; ?>"><?phpphp echo timeago($tweet->created_at); ?></a>
  42. <?phpphp echo $tweet->text; ?>
  43. </li>
  44. <?phpphp
  45. endif;
  46. }
  47. }
  48. ?>
  49. </div>
  50. <?phpphp
  51.  
  52. echo $after_widget;
  53. }
  54.  
  55. function widget_twitter_control() {
  56. $options = get_option('widget_twitter');
  57.  
  58. if (!is_array($options))
  59. //Default values
  60. $options = array('title' => 'Twitter');
  61.  
  62. //Save options
  63. if ($_POST['twitter_submit']) {
  64. $options['title'] = strip_tags(stripslashes($_POST['twitter_title']));
  65.  
  66. update_option('widget_twitter', $options);
  67. }
  68.  
  69. //Get options
  70. $title = htmlspecialchars($options['title'], ENT_QUOTES);
  71. $username = htmlspecialchars($options['username'], ENT_QUOTES);
  72. $password = $options['password'];
  73.  
  74. ?>
  75.  
  76. <p>
  77.  
  78. <label for="twitter_title">
  79. Title: <br />
  80. <input style="width: 300px;" id="twitter_title" name="twitter_title" type="text" value="<?php echo $title; ?>" />
  81. </label><br /><br /><br />
  82.  
  83. <?phpphp
  84. $access_token = check_twitter_credentials();
  85. if (empty($access_token)) {
  86. ?><font color="red">Could not connect to a twitter account. You can set one up from the theme's options page.</font><?php
  87. }
  88. ?>
  89.  
  90. </p>
  91.  
  92. <?php
  93. echo '<input type="hidden" id="twitter_submit" name="twitter_submit" value="1" />';
  94.  
  95. }
  96.  
  97.  
  98. register_sidebar_widget(array('[Magzimus] Twitter', 'theme-twitter'), 'widget_twitter', '');
  99. register_widget_control(array('[Magzimus] Twitter', 'theme-twitter'), 'widget_twitter_control', 360, 300);
  100. }
  101.  
  102. ?>
Advertisement
Add Comment
Please, Sign In to add comment