Changeset 534405
- Timestamp:
- 04/21/2012 09:57:05 AM (14 years ago)
- Location:
- tweet-deets/trunk/tweet-deets
- Files:
-
- 2 edited
-
readme.txt (modified) (5 diffs)
-
tweetdeets.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tweet-deets/trunk/tweet-deets/readme.txt
r531993 r534405 1 1 === Plugin Name === 2 2 Tags: twitter, social media, buzz, trend, topic, tweet 3 Tested up to: 3.1.13 Tested on: 3.3.1 4 4 5 Tweet Deets allow you to see at a glance the twitter buzz about a topic.5 Tweet Deets allows you to see the twitter buzz about a topic at a glance. 6 6 7 7 == Changelog == … … 9 9 = 1.0 = 10 10 * First public release 11 = 1.1 = 12 * Admin page added, allowing users to customise how many pages of tweets are returned, what is searched for and what to display. 11 13 12 14 == Description == … … 14 16 "Hotness Percentage", which shows how current the discussion of the topic is. 15 17 16 Tweet Deets find s tweets based on the URL,Page Title and Post title of current pages.18 Tweet Deets find tweets based on the URL of the current page, and can also be configured to find tweets based on Page Title and Post title of current pages. 17 19 18 20 == Installation == … … 21 23 Then activate the plugin from the WP-Admin Dashboard. 22 24 23 Usage: 25 Once activated, you should visit the Options page, which is found under the Settings menu in the dashboard. Here, you can set the scope of the search, 26 how many pages of tweets to gather and which elements you wish to display. 27 28 == Usage == 24 29 To use, simply call the tweet_deets() function. Here is an example of how to call it on all pages except the home page 25 30 and any archives: … … 30 35 the look and feel of your Tweet Deets, or hide sections you do not wish to see. 31 36 32 In the future there will be updates and hopefully the addition of an admin page for easier customisation of what 33 is displayed and ignored. Feel free to send me feedback! 37 In the future there will be updates - Feel free to send me feedback if you have any good ideas! -
tweet-deets/trunk/tweet-deets/tweetdeets.php
r531997 r534405 28 28 ?> 29 29 <?php 30 31 //Admin menu 32 function tweetdeet_admin(){ 33 echo "<h2>Tweet Deets Options</h2>"; 34 35 //How many pages of tweets 36 echo '<h3>Pages</h3><p>Select how many pages of tweets to search. Each page will return a maximum of 100 results.</p> 37 <p>Note: The higher this number is, the slower the page containing your plugin may become</p> 38 <form method="post" action="options.php">'; 39 settings_fields( 'tweetdeet-group' ); 40 41 echo '<label for="num-pages">Number of pages:</label><select id="num-pages" name="num-tweet-pages">'; 42 $i = 1; 43 while ($i < 16){ 44 ?><option value="<?php echo $i; ?>" <?php if(get_option('num-tweet-pages') == $i){ echo "selected"; } ?>><?php echo $i; ?></option><?php 45 $i++; 46 } 47 echo '</select>'; 48 49 //Checkbox for page title, post title, URL 50 if(get_option('inc-page-title') == 1){ 51 $incpagetitle = "checked='checked'"; 52 } else { 53 $incpagetitle = ""; 54 } 55 if(get_option('inc-post-title') == 1){ 56 $incposttitle = "checked='checked'"; 57 } else { 58 $incposttitle = ""; 59 } 60 61 62 echo "<h3>Scope</h3><p>Select which elements of the page to include in the search terms. If you find the results are too vague you could remove some of these to narrow your search down</p>"; 63 echo '<label>Include Page Title in search: <input type="checkbox" name="inc-page-title" value="1" '.$incpagetitle.'/></label><br />'; 64 echo '<label>Include Post Title in search: <input type="checkbox" name="inc-post-title" value="1" '.$incposttitle.'/></label><br />'; 65 66 67 if(get_option('inc-recent-tweets') == 1){ 68 $increcenttweets = "checked='checked'"; 69 } else { 70 $increcenttweets = ""; 71 } 72 if(get_option('inc-highlight-tweet') == 1){ 73 $inchighlighttweet = "checked='checked'"; 74 } else { 75 $inchighlighttweet = ""; 76 } 77 if(get_option('inc-hot-percent') == 1){ 78 $inchotpercent = "checked='checked'"; 79 } else { 80 $inchotpercent = ""; 81 } 82 //Checkbox for how many tweets, higlighted tweet, hotness percentage. 83 echo "<h3>Display</h3><p>Select which elements of Tweet Deets to show.</p>"; 84 echo '<label>Include Number of Recent Tweets: <input type="checkbox" name="inc-recent-tweets" value="1" '.$increcenttweets.'/></label><br />'; 85 echo '<label>Include Highlighted Tweet: <input type="checkbox" name="inc-highlight-tweet" value="1" '.$inchighlighttweet.'/></label><br />'; 86 echo '<label>Include Hotness Percentage: <input type="checkbox" name="inc-hot-percent" value="1" '.$inchotpercent.'/></label><br />'; 87 88 ?><br /><input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" /><?php 89 echo "</form>"; 90 } 91 92 function register_tweetdeet_settings() { 93 //register our settings 94 register_setting( 'tweetdeet-group', 'num-tweet-pages' ); 95 register_setting( 'tweetdeet-group', 'inc-page-title' ); 96 register_setting( 'tweetdeet-group', 'inc-post-title' ); 97 register_setting( 'tweetdeet-group', 'inc-recent-tweets' ); 98 register_setting( 'tweetdeet-group', 'inc-highlight-tweet' ); 99 register_setting( 'tweetdeet-group', 'inc-hot-percent' ); 100 } 101 102 add_action('admin_menu', 'tweetdeets_menu'); 103 104 function tweetdeets_menu() { 105 add_options_page('Tweet Deets Options', 'Tweet Deets', 'manage_options', 'tweet_deets_options', 'tweetdeet_admin'); 106 107 //call register settings function 108 add_action( 'admin_init', 'register_tweetdeet_settings' ); 109 } 110 30 111 //Add stylesheet for Tweet Deets 31 112 add_action( 'wp_enqueue_scripts', 'prefix_add_tweetdeets_stylesheet' ); … … 39 120 40 121 //Get page title 41 $current_page_title = wp_title("", 0); 122 if(get_option('inc-page-title') == 1){ 123 $current_page_title = "%20OR%20".urlencode(wp_title("", 0)); 124 } else { 125 $current_page_title = ""; 126 } 127 42 128 //Get post title 43 $current_post_title = get_the_title(); 129 if(get_option('inc-post-title') == 1){ 130 $current_post_title = "%20OR%20".urlencode(get_the_title()); 131 } else { 132 $current_post_title = ""; 133 } 134 44 135 //Get current URL 45 136 $current_page_URL = $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]; 137 //echo urlencode($current_page_URL).$current_page_title; 138 //die(); 46 139 47 140 //Twitter search by page title or post title (or containing link to this page) 48 $tweets = file_get_contents("http://search.twitter.com/search.json?q=".urlencode($current_page_title)."%20OR%20".urlencode($current_post_title)."%20OR%20".urlencode($current_page_url)."&rpp=100", "r"); 49 50 51 //Gather JSON information from Twitter search 52 $tweets = json_decode( $tweets, true ); 141 $tweets = array(); 142 $i = 1; 143 while ($i < (get_option('num-tweet-pages') + 1)){ 144 $tweetget = file_get_contents("http://search.twitter.com/search.json?page=".$i."&q=".$current_page_URL.$current_page_title.$current_post_title."&rpp=100", "r"); 145 $tweet_array = json_decode($tweetget, true); 146 array_push($tweets, $tweet_array['results']); 147 $i++; 148 } 149 53 150 54 151 //A count of how many tweets are returned. 55 $tweetcount = count($tweets['results']); 56 152 $tweetcount = 0; 153 $total_tweets = array(); 154 $i_2 = 1; 155 foreach($tweets as $key=>$value){ 156 foreach ($tweets[$key] as $tweetkey=>$tweetvalue){ 157 $tweetnum = count($tweetvalue['text']); 158 $tweetcount = $tweetcount + $tweetnum; 159 array_push($total_tweets, $tweetvalue); 160 } 161 } 57 162 echo '<div class="widget tweet-deets"><h3 class="widget-title tweet-deets-title">Tweet Deets</h3>'; 58 163 echo '<div class="tweet-deets-info"><p>Tweet Deets allows you to see at a glance the buzz this topic has on Twitter.</p></div>'; 59 164 60 165 if($tweetcount > 0){ 166 if(get_option('inc-recent-tweets') == 1){ 61 167 echo '<p class="tweet-deets-count"><span class="tweet-deets-count-text">Recent tweets about this topic:</span> <span class="tweet-deets-count-number">'.$tweetcount.'</span></p>'; 62 168 } 63 169 //Get most recent tweet 64 $tweethighlight = $t weets['results'][0];170 $tweethighlight = $total_tweets[0]; 65 171 //Display it 172 if(get_option('inc-highlight-tweet') == 1){ 66 173 echo '<div class="tweet-deets-highlighted-tweet"><h4 class="tweet-deets-tweet-highlight">Tweet Highlight</h4><p class="tweet-deets-highlighted-tweet-actual"><span class="tweet-deets-higlighted-tweet-author">By @'.$tweethighlight['from_user'].':</span><br />'.$tweethighlight['text'].'</p></div>'; 67 174 } 68 175 //Take date and compare to current time to generate a hotness percentage 69 176 $tweetdate_format = strtotime($tweethighlight['created_at']); 70 177 $current_time = strtotime("now"); 71 178 179 180 $backtweet = end($total_tweets); 181 $backtweetdate = strtotime($backtweet['created_at']); 182 72 183 $distance = $current_time - $tweetdate_format; 184 $backtweet_distance = $current_time - $backtweetdate; 185 $backtweet_days = ((($backtweet_distance / 60) / 60) / 24) * 2; 186 73 187 $distance = $distance / 604800; 74 188 $antipercent = $distance * 100; 75 $percent = 100 - $antipercent;189 $percent = (100 - $antipercent) - $backtweet_days; 76 190 77 191 //Display Hotness percentage 78 echo '<div class="tweet-deets-hotness-percentage"><h4 class="tweet-deets-hotness-percentage-title">Hotness Percentage</h4><p class="tweet-deets-hotness-percentage-actual">'.number_format($percent, 0).'%</p></div>'; 192 if(get_option('inc-hot-percent') == 1){ 193 echo '<div class="tweet-deets-hotness-percentage"><h4 class="tweet-deets-hotness-percentage-title">Hotness Percentage</h4><p class="tweet-deets-hotness-percentage-actual">'.number_format($percent, 0).'%</p></div>'; 194 } 79 195 } else { 80 196 echo '<div class="tweet-deets-no-tweets">No current Twitter buzz about this topic.</div>';
Note: See TracChangeset
for help on using the changeset viewer.