Revive Old Posts – Auto Post to Social Media - Version 1.4

Version Description

Download this release

Release Info

Developer codeinwp
Plugin Icon 128x128 Revive Old Posts – Auto Post to Social Media
Version 1.4
Comparing to
See all releases

Version 1.4

Files changed (5) hide show
  1. css/tweet-old-post.css +47 -0
  2. readme.txt +142 -0
  3. top-admin.php +349 -0
  4. top-core.php +215 -0
  5. tweet-old-post.php +40 -0
css/tweet-old-post.css ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .wrap h2 {
2
+ margin-top: 32px;
3
+ }
4
+ #top_opt .options {
5
+ overflow: hidden;
6
+ border: none;
7
+ }
8
+ #top_opt .option {
9
+ overflow: hidden;
10
+ border-bottom: dashed 1px #ccc;
11
+ padding-bottom: 9px;
12
+ padding-top: 9px;
13
+ }
14
+ #top_opt .option label {
15
+ display: block;
16
+ float: left;
17
+ width: 200px;
18
+ margin-right: 24px;
19
+ text-align: right;
20
+ }
21
+ #top_opt .option span {
22
+ display: block;
23
+ float: left;
24
+ margin-left: 230px;
25
+ margin-top: 6px;
26
+ clear: left;
27
+ }
28
+
29
+ #top_opt p.submit {
30
+ overflow: hidden;
31
+ }
32
+ #top_opt .option span {
33
+ color: #666;
34
+ display: block;
35
+ }
36
+
37
+ #top_opt .category label
38
+ {
39
+ float:left;
40
+ text-align:left;
41
+
42
+ }
43
+
44
+ #top_opt .category .catlabel
45
+ {
46
+ text-align:right;
47
+ }
readme.txt ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Tweet Old Post ===
2
+ Contributors: Ajay Matharu
3
+ Tags: Tweet old post, Tweets, Promote old post by tweeting about them, Twitter, Auto Tweet, Hashtags, Twitter Hashtags, Tweet Posts
4
+ Requires at least: 2.0.2
5
+ Tested up to: 2.9
6
+ Stable tag: 1.4
7
+
8
+ Plugin to tweet about your old posts to get more hits for them and keep them alive.
9
+
10
+ == Description ==
11
+
12
+ Tweet Old Posts is a plugin designed to tweet your older posts to get more traffic.
13
+
14
+ Tweet Old Posts randomly picks your older post based on the interval specified by you. The primary function of this plugin is to promote older blog posts by tweeting about them and getting more traffic.
15
+
16
+
17
+
18
+ Some of the options you can configure for the Tweet Old Posts plugins are,
19
+
20
+ **v1.1**
21
+
22
+ Twitter Username & Password - Using this twitter account credentials plugin will tweet.
23
+
24
+ Minimum interval between tweets - allows you to determine how often the plugin will automatically choose and tweet a blog post for you.
25
+
26
+ Randomness interval - This is a contributing factor in minimum interval so that posts are randomly chosen and tweeted from your blog.
27
+
28
+ Minimum age of post to be eligible for tweet - This allows you to set how old your post should be in order to be eligible for the tweet.
29
+
30
+ Categories to omit from tweets - This will protect posts from the selected categories from being tweeted.
31
+
32
+
33
+
34
+ **New in v1.2**
35
+
36
+ Tweet Prefix - Allows you to set prefix to the tweets.
37
+
38
+ Add Data - Allows you to add post data to the tweets
39
+
40
+ Tweet now - Button that will tweet at that moment without wanting you to wait for scheduled tweet
41
+
42
+
43
+
44
+ **New in v1.3**
45
+
46
+ URL Shortener Service - allows you to select which URL shortener service you want to use.
47
+
48
+
49
+ **New in v1.4**
50
+
51
+ Hashtags - allows you to set default hashtags for your tweets
52
+
53
+ == Installation ==
54
+
55
+ Following are the steps to install the Tweet Old Post plugin
56
+
57
+ 1. Download the latest version of the Tweet Old Posts Plugin to your computer from here.
58
+ 2. With an FTP program, access your site�s server.
59
+ 3. Upload (copy) the Plugin file(s) or folder to the /wp-content/plugins folder.
60
+ 4. In your WordPress Administration Panels, click on Plugins from the menu.
61
+ 5. You should see Tweet Old Posts Plugin listed. If not, with your FTP program, check the folder to see if it is installed. If it isn�t, upload the file(s) again. If it is, delete the files and upload them again.
62
+ 6. To turn the Tweet Old Posts Plugin on, click Activate.
63
+ 7. Check your Administration Panels or WordPress blog to see if the Plugin is working.
64
+ 8. You can change the plugin options from Tweet Old Posts under settings menu.
65
+
66
+ Alternatively you can also follow the following steps to install the Tweet Old Post plugin
67
+
68
+ 1. In your WordPress Administration Panels, click on Add New option under Plugins from the menu.
69
+ 2. Click on upload at the top.
70
+ 3. Browse the location and select the Tweet Old Post Plugin and click install now.
71
+ 4. To turn the Tweet Old Posts Plugin on, click Activate.
72
+ 5. Check your Administration Panels or WordPress blog to see if the Plugin is working.
73
+ 6. You can change the plugin options from Tweet Old Posts under settings menu.
74
+
75
+ == Frequently Asked Questions ==
76
+
77
+ If you have any questions please mail me at,
78
+ ajay@ajaymatharu.com or matharuajay@yahoo.co.in
79
+
80
+ == Screenshots ==
81
+
82
+ for screenshots you can check out
83
+
84
+ http://www.ajaymatharu.com/wordpress-plugin-tweet-old-posts/
85
+
86
+ == Changelog ==
87
+
88
+
89
+ **v1.2**
90
+
91
+ Tweet Prefix - Allows you to set prefix to the tweets.
92
+
93
+ Add Data - Allows you to add post data to the tweets.
94
+
95
+ Tweet now - Button that will tweet at that moment without wanting you to wait for scheduled tweet.
96
+
97
+
98
+
99
+ **v1.3**
100
+
101
+ URL Shortener Service - allows you to select which URL shortener service you want to use.
102
+
103
+
104
+ **v1.4**
105
+
106
+ Hashtags - allows you to set default hashtags for your tweets
107
+
108
+
109
+ == Other Notes ==
110
+
111
+ Some of the options you can configure for the Tweet Old Posts plugins are,
112
+
113
+ **v1.1**
114
+
115
+ Twitter Username & Password - Using this twitter account credentials plugin will tweet.
116
+
117
+ Minimum interval between tweets - allows you to determine how often the plugin will automatically choose and tweet a blog post for you.
118
+
119
+ Randomness interval - This is a contributing factor in minimum interval so that posts are randomly chosen and tweeted from your blog.
120
+
121
+ Minimum age of post to be eligible for tweet - This allows you to set how old your post should be in order to be eligible for the tweet.
122
+
123
+ Categories to omit from tweets - This will protect posts from the selected categories from being tweeted.
124
+
125
+
126
+ **v1.2**
127
+
128
+ Tweet Prefix - Allows you to set prefix to the tweets.
129
+
130
+ Add Data - Allows you to add post data to the tweets.
131
+
132
+ Tweet now - Button that will tweet at that moment without wanting you to wait for scheduled tweet.
133
+
134
+
135
+ **v1.3**
136
+
137
+ URL Shortener Service - allows you to select which URL shortener service you want to use.
138
+
139
+
140
+ **v1.4**
141
+
142
+ Hashtags - allows you to set default hashtags for your tweets
top-admin.php ADDED
@@ -0,0 +1,349 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once('tweet-old-post.php');
4
+ require_once('top-core.php');
5
+
6
+
7
+ function top_admin() {
8
+ $message = null;
9
+ $message_updated = __("Tweet Old Post Options Updated.", 'TweetOldPost');
10
+ $response=null;
11
+ $save=null;
12
+
13
+ if(isset($_POST['top_opt_twitter_password']) && isset($_POST['top_opt_twitter_username']))
14
+ {
15
+ $response=verify_credentials($_POST['top_opt_twitter_username'],$_POST['top_opt_twitter_password']);
16
+ if($response != 200 && $response == 401)
17
+ {
18
+ $message = __("Incorrect Twitter Username & Password. Please verify your credentials.", 'TweetOldPost');
19
+ print('
20
+ <div id="message" class="updated fade">
21
+ <p>'.__('Incorrect Twitter Username & Password. Please verify your credentials.', 'TweetOldPost').'</p>
22
+ </div>');
23
+ $save=false;
24
+ }
25
+ else
26
+ $save=true;
27
+ }
28
+
29
+ if(isset($_POST['top_opt_url_shortener']))
30
+ {
31
+ if($_POST['top_opt_url_shortener']=="bit.ly")
32
+ {
33
+ if($save)
34
+ {
35
+ if(!isset($_POST['top_opt_bitly_user']))
36
+ {
37
+ print('
38
+ <div id="message" class="updated fade">
39
+ <p>'.__('Please enter bit.ly username.', 'TweetOldPost').'</p>
40
+ </div>');
41
+ $save=false;
42
+ }
43
+ elseif(!isset($_POST['top_opt_bitly_key']))
44
+ {
45
+ print('
46
+ <div id="message" class="updated fade">
47
+ <p>'.__('Please enter bit.ly API Key.', 'TweetOldPost').'</p>
48
+ </div>');
49
+ $save=false;
50
+ }
51
+ else
52
+ {
53
+ $save=true;
54
+ }
55
+ }
56
+ }
57
+ }
58
+
59
+ if (isset($_POST['submit']) && $save ) {
60
+ $message = $message_updated;
61
+ if (isset($_POST['top_opt_twitter_username'])) {
62
+ update_option('top_opt_twitter_username',$_POST['top_opt_twitter_username']);
63
+ }
64
+ if (isset($_POST['top_opt_twitter_password'])) {
65
+ update_option('top_opt_twitter_password',$_POST['top_opt_twitter_password']);
66
+ }
67
+ if (isset($_POST['top_opt_interval'])) {
68
+ update_option('top_opt_interval',$_POST['top_opt_interval']);
69
+ }
70
+ if (isset($_POST['top_opt_interval_slop'])) {
71
+ update_option('top_opt_interval_slop',$_POST['top_opt_interval_slop']);
72
+ }
73
+ if (isset($_POST['top_opt_age_limit'])) {
74
+ update_option('top_opt_age_limit',$_POST['top_opt_age_limit']);
75
+ }
76
+ if (isset($_POST['top_opt_tweet_prefix'])) {
77
+ update_option('top_opt_tweet_prefix',$_POST['top_opt_tweet_prefix']);
78
+ }
79
+ if (isset($_POST['top_opt_add_data'])) {
80
+ update_option('top_opt_add_data',$_POST['top_opt_add_data']);
81
+ }
82
+ if (isset($_POST['post_category'])) {
83
+ update_option('top_opt_omit_cats',implode(',',$_POST['post_category']));
84
+ }
85
+ else {
86
+ update_option('top_opt_omit_cats','');
87
+ }
88
+
89
+ if (isset($_POST['top_opt_hashtags'])) {
90
+ update_option('top_opt_hashtags',$_POST['top_opt_hashtags']);
91
+ }
92
+ else {
93
+ update_option('top_opt_hashtags','');
94
+ }
95
+
96
+ if(isset($_POST['top_opt_url_shortener']))
97
+ {
98
+ update_option('top_opt_url_shortener',$_POST['top_opt_url_shortener']);
99
+ if($_POST['top_opt_url_shortener']=="bit.ly")
100
+ {
101
+ if(isset($_POST['top_opt_bitly_user']))
102
+ {
103
+ update_option('top_opt_bitly_user',$_POST['top_opt_bitly_user']);
104
+ }
105
+ if(isset($_POST['top_opt_bitly_key']))
106
+ {
107
+ update_option('top_opt_bitly_key',$_POST['top_opt_bitly_key']);
108
+ }
109
+ }
110
+ }
111
+ print('
112
+ <div id="message" class="updated fade">
113
+ <p>'.__('Tweet Old Post Options Updated.', 'TweetOldPost').'</p>
114
+ </div>');
115
+ }
116
+ elseif (isset($_POST['tweet']))
117
+ {
118
+ top_opt_tweet_old_post();
119
+ print('
120
+ <div id="message" class="updated fade">
121
+ <p>'.__('Tweet posted successfully.', 'TweetOldPost').'</p>
122
+ </div>');
123
+ }
124
+ $omitCats = get_option('top_opt_omit_cats');
125
+ if (!isset($omitCats)) {
126
+ $omitCats = top_opt_OMIT_CATS;
127
+ }
128
+ $ageLimit = get_option('top_opt_age_limit');
129
+ if (!isset($ageLimit)) {
130
+ $ageLimit = top_opt_AGE_LIMIT;
131
+ }
132
+
133
+ $interval = get_option('top_opt_interval');
134
+ if (!(isset($interval) && is_numeric($interval))) {
135
+ $interval = top_opt_INTERVAL;
136
+ }
137
+ $slop = get_option('top_opt_interval_slop');
138
+ if (!(isset($slop) && is_numeric($slop))) {
139
+ $slop = top_opt_INTERVAL_SLOP;
140
+ }
141
+ $tweet_prefix = get_option('top_opt_tweet_prefix');
142
+ if(!isset($tweet_prefix)){
143
+ $tweet_prefix = top_opt_TWEET_PREFIX;
144
+ }
145
+ $url_shortener=get_option('top_opt_url_shortener');
146
+ if(!isset($url_shortener)){
147
+ $url_shortener=top_opt_URL_SHORTENER;
148
+ }
149
+
150
+ $twitter_hashtags=get_option('top_opt_hashtags');
151
+ if(!isset($twitter_hashtags)){
152
+ $twitter_hashtags=top_opt_HASHTAGS;
153
+ }
154
+
155
+ $bitly_api=get_option('top_opt_bitly_key');
156
+ if(!isset($bitly_api)){
157
+ $bitly_api="";
158
+ }
159
+ $bitly_username=get_option('top_opt_bitly_user');
160
+ if(!isset($bitly_username)){
161
+ $bitly_username="";
162
+ }
163
+ $add_data = get_option('top_opt_add_data');
164
+ $twitter_username = get_option('top_opt_twitter_username');
165
+ $twitter_password = get_option('top_opt_twitter_password');
166
+
167
+ print('
168
+ <div class="wrap">
169
+ <h2>'.__('Tweet old post by - ', 'TweetOldPost').' <a href="http://www.ajaymatharu.com">Ajay Matharu</a></h2>
170
+ <form id="top_opt" name="top_TweetOldPost" action="'.get_bloginfo('wpurl').'/wp-admin/options-general.php?page=TweetOldPost" method="post">
171
+ <input type="hidden" name="top_opt_action" value="top_opt_update_settings" />
172
+ <fieldset class="options">
173
+ <div class="option">
174
+ <label for="top_opt_twitter_username">'.__('Twitter Username', 'TweetOldPost').':</label>
175
+ <input type="text" size="25" name="top_opt_twitter_username" id="top_opt_twitter_username" value="'.$twitter_username.'" autocomplete="off" />
176
+ </div>
177
+ <div class="option">
178
+ <label for="top_opt_twitter_password">'.__('Twitter Password', 'TweetOldPost').':</label>
179
+ <input type="password" size="25" name="top_opt_twitter_password" id="top_opt_twitter_password" value="'.$twitter_password.'" autocomplete="off" />
180
+ </div>
181
+ <div class="option">
182
+ <label for="top_opt_tweet_prefix">'.__('Tweet Prefix', 'TweetOldPost').':</label>
183
+ <input type="text" size="25" name="top_opt_tweet_prefix" id="top_opt_tweet_prefix" value="'.$tweet_prefix.'" autocomplete="off" />
184
+ <b>If set, it will show as: "{tweet prefix}: {post title}... {url}</b>
185
+ </div>
186
+ <div class="option">
187
+ <label for="top_opt_add_data">'.__('Add post data to tweet', 'TweetOldPost').':</label>
188
+ <select id="top_opt_add_data" name="top_opt_add_data" style="width:100px;">
189
+ <option value="false" '.top_opt_optionselected("false",$add_data).'>'.__(' No ', 'TweetOldPost').'</option>
190
+ <option value="true" '.top_opt_optionselected("true",$add_data).'>'.__(' Yes ', 'TweetOldPost').'</option>
191
+ </select>
192
+ <b>If set, it will show as: "{tweet prefix}: {post title}- {content}... {url}</b>
193
+ </div>
194
+ <div class="option">
195
+ <label for="top_opt_url_shortener">'.__('URL Shortener Service', 'TweetOldPost').':</label>
196
+ <select name="top_opt_url_shortener" id="top_opt_url_shortener" onchange="javascript:showURLAPI()" style="width:100px;">
197
+ <option value="is.gd" '.top_opt_optionselected('is.gd',$url_shortener).'>'.__('is.gd', 'TweetOldPost').'</option>
198
+ <option value="su.pr" '.top_opt_optionselected('su.pr',$url_shortener).'>'.__('su.pr', 'TweetOldPost').'</option>
199
+ <option value="bit.ly" '.top_opt_optionselected('bit.ly',$url_shortener).'>'.__('bit.ly', 'TweetOldPost').'</option>
200
+ <option value="tr.im" '.top_opt_optionselected('tr.im',$url_shortener).'>'.__('tr.im', 'TweetOldPost').'</option>
201
+ <option value="3.ly" '.top_opt_optionselected('3.ly',$url_shortener).'>'.__('3.ly', 'TweetOldPost').'</option>
202
+ <option value="tinyurl" '.top_opt_optionselected('tinyurl',$url_shortener).'>'.__('tinyurl', 'TweetOldPost').'</option>
203
+ </select>
204
+ </div>
205
+ <div id="showDetail" style="display:none">
206
+ <div class="option">
207
+ <label for="top_opt_bitly_user">'.__('bit.ly Username', 'TweetOldPost').':</label>
208
+ <input type="text" size="25" name="top_opt_bitly_user" id="top_opt_bitly_user" value="'.$bitly_username.'" autocomplete="off" />
209
+ </div>
210
+
211
+ <div class="option">
212
+ <label for="top_opt_bitly_key">'.__('bit.ly API Key', 'TweetOldPost').':</label>
213
+ <input type="text" size="25" name="top_opt_bitly_key" id="top_opt_bitly_key" value="'.$bitly_api.'" autocomplete="off" />
214
+ </div>
215
+ </div>
216
+
217
+ <div class="option">
218
+ <label for="top_opt_hashtags">'.__('Default #hashtags for your tweets', 'TweetOldPost').':</label>
219
+ <input type="text" size="25" name="top_opt_hashtags" id="top_opt_hashtags" value="'.$twitter_hashtags.'" autocomplete="off" />
220
+ <b>Include #, like #thoughts</b>
221
+ </div>
222
+
223
+ <div class="option">
224
+ <label for="top_opt_interval">'.__('Minimum interval between tweets: ', 'TweetOldPost').'</label>
225
+ <select name="top_opt_interval" id="top_opt_interval">
226
+ <option value="'.top_opt_1_HOUR.'" '.top_opt_optionselected(top_opt_1_HOUR,$interval).'>'.__('1 Hour', 'TweetOldPost').'</option>
227
+ <option value="'.top_opt_4_HOURS.'" '.top_opt_optionselected(top_opt_4_HOURS,$interval).'>'.__('4 Hours', 'TweetOldPost').'</option>
228
+ <option value="'.top_opt_6_HOURS.'" '.top_opt_optionselected(top_opt_6_HOURS,$interval).'>'.__('6 Hours', 'TweetOldPost').'</option>
229
+ <option value="'.top_opt_12_HOURS.'" '.top_opt_optionselected(top_opt_12_HOURS,$interval).'>'.__('12 Hours', 'TweetOldPost').'</option>
230
+ <option value="'.top_opt_24_HOURS.'" '.top_opt_optionselected(top_opt_24_HOURS,$interval).'>'.__('24 Hours (1 day)', 'TweetOldPost').'</option>
231
+ <option value="'.top_opt_48_HOURS.'" '.top_opt_optionselected(top_opt_48_HOURS,$interval).'>'.__('48 Hours (2 days)', 'TweetOldPost').'</option>
232
+ <option value="'.top_opt_72_HOURS.'" '.top_opt_optionselected(top_opt_72_HOURS,$interval).'>'.__('72 Hours (3 days)', 'TweetOldPost').'</option>
233
+ <option value="'.top_opt_168_HOURS.'" '.top_opt_optionselected(top_opt_168_HOURS,$interval).'>'.__('168 Hours (7 days)', 'TweetOldPost').'</option>
234
+ </select>
235
+ </div>
236
+ <div class="option">
237
+ <label for="top_opt_interval_slop">'.__('Random Interval (added to minimum interval): ', 'TweetOldPost').'</label>
238
+ <select name="top_opt_interval_slop" id="top_opt_interval_slop">
239
+ <option value="'.top_opt_1_HOUR.'" '.top_opt_optionselected(top_opt_1_HOUR,$slop).'>'.__('Upto 1 Hour', 'TweetOldPost').'</option>
240
+ <option value="'.top_opt_4_HOURS.'" '.top_opt_optionselected(top_opt_4_HOURS,$slop).'>'.__('Upto 4 Hours', 'TweetOldPost').'</option>
241
+ <option value="'.top_opt_6_HOURS.'" '.top_opt_optionselected(top_opt_6_HOURS,$slop).'>'.__('Upto 6 Hours', 'TweetOldPost').'</option>
242
+ <option value="'.top_opt_12_HOURS.'" '.top_opt_optionselected(top_opt_12_HOURS,$slop).'>'.__('Upto 12 Hours', 'TweetOldPost').'</option>
243
+ <option value="'.top_opt_24_HOURS.'" '.top_opt_optionselected(top_opt_24_HOURS,$slop).'>'.__('Upto 24 Hours (1 day)', 'TweetOldPost').'</option>
244
+ </select>
245
+ </div>
246
+ <div class="option">
247
+ <label for="top_opt_age_limit">'.__('Minimum age of post to be eligible for tweet: ', 'TweetOldPost').'</label>
248
+ <select name="top_opt_age_limit" id="top_opt_age_limit">
249
+ <option value="7" '.top_opt_optionselected(7,$ageLimit).'>'.__('7 Days', 'TweetOldPost').'</option>
250
+ <option value="15" '.top_opt_optionselected(15,$ageLimit).'>'.__('15 Days', 'TweetOldPost').'</option>
251
+ <option value="30" '.top_opt_optionselected(30,$ageLimit).'>'.__('30 Days', 'TweetOldPost').'</option>
252
+ <option value="60" '.top_opt_optionselected(60,$ageLimit).'>'.__('60 Days', 'TweetOldPost').'</option>
253
+ <option value="90" '.top_opt_optionselected(90,$ageLimit).'>'.__('90 Days', 'TweetOldPost').'</option>
254
+ <option value="120" '.top_opt_optionselected(120,$ageLimit).'>'.__('120 Days', 'TweetOldPost').'</option>
255
+ <option value="240" '.top_opt_optionselected(240,$ageLimit).'>'.__('240 Days', 'TweetOldPost').'</option>
256
+ <option value="365" '.top_opt_optionselected(365,$ageLimit).'>'.__('365 Days', 'TweetOldPost').'</option>
257
+ </select>
258
+ </div>
259
+ <div class="option category">
260
+ <div style="float:left">
261
+ <label class="catlabel">'.__('Categories to Omit from tweets: ', 'TweetOldPost').'</label> </div>
262
+ <div style="float:left">
263
+ <ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
264
+ ');
265
+ wp_category_checklist(0, 0, explode(',',$omitCats));
266
+ print(' </ul>
267
+ </div>
268
+ </div>
269
+ </fieldset>
270
+ <p class="submit">
271
+ <input type="submit" name="submit" onclick="javascript:return validate()" value="'.__('Update Tweet Old Post Options', 'TweetOldPost').'" />
272
+ <input type="submit" name="tweet" value="'.__('Tweet Now', 'TweetOldPost').'" />
273
+ </p>
274
+
275
+ </form><script language="javascript" type="text/javascript">
276
+ function showURLAPI()
277
+ {
278
+ var urlShortener=document.getElementById("top_opt_url_shortener").value;
279
+ if(urlShortener=="bit.ly")
280
+ {
281
+ document.getElementById("showDetail").style.display="block";
282
+ }
283
+ else
284
+ {
285
+ document.getElementById("showDetail").style.display="none";
286
+ }
287
+ }
288
+
289
+ function validate()
290
+ {
291
+
292
+ if(document.getElementById("showDetail").style.display=="block" && document.getElementById("top_opt_url_shortener").value=="bit.ly")
293
+ {
294
+ if(trim(document.getElementById("top_opt_bitly_user").value)=="")
295
+ {
296
+ alert("Please enter bit.ly username.");
297
+ document.getElementById("top_opt_bitly_user").focus();
298
+ return false;
299
+ }
300
+
301
+ if(trim(document.getElementById("top_opt_bitly_key").value)=="")
302
+ {
303
+ alert("Please enter bit.ly API key.");
304
+ document.getElementById("top_opt_bitly_key").focus();
305
+ return false;
306
+ }
307
+ }
308
+ }
309
+
310
+ function trim(stringToTrim) {
311
+ return stringToTrim.replace(/^\s+|\s+$/g,"");
312
+ }
313
+
314
+ showURLAPI();
315
+ </script>' );
316
+
317
+ }
318
+
319
+ function top_opt_optionselected($opValue, $value) {
320
+ if($opValue==$value) {
321
+ return 'selected="selected"';
322
+ }
323
+ return '';
324
+ }
325
+
326
+ function top_opt_head_admin()
327
+ {
328
+ $home = get_settings('siteurl');
329
+ $base = '/'.end(explode('/', str_replace(array('\\','/top-admin.php'),array('/',''),__FILE__)));
330
+ $stylesheet = $home.'/wp-content/plugins' . $base . '/css/tweet-old-post.css';
331
+ echo('<link rel="stylesheet" href="' . $stylesheet . '" type="text/css" media="screen" />');
332
+ }
333
+
334
+
335
+ //Verify a user's credentials
336
+ function verify_credentials($auth_user, $auth_pass) {
337
+
338
+ $url = "http://twitter.com/account/verify_credentials.xml";
339
+ $response = send_request($url, 'GET', '', $auth_user, $auth_pass);
340
+ if(is_numeric($response))
341
+ {
342
+ return $response;
343
+ }
344
+ else {
345
+ $xml = new SimpleXmlElement($response);
346
+ return $xml;}
347
+
348
+ }
349
+ ?>
top-core.php ADDED
@@ -0,0 +1,215 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ function top_tweet_old_post()
4
+ {
5
+ //check last tweet time against set interval and span
6
+ if (top_opt_update_time()) {
7
+ update_option('top_opt_last_update', time());
8
+ top_opt_tweet_old_post();
9
+ }
10
+ }
11
+
12
+ //get random post and tweet
13
+ function top_opt_tweet_old_post()
14
+ {
15
+ global $wpdb;
16
+ $omitCats = get_option('top_opt_omit_cats');
17
+ $ageLimit = get_option('top_opt_age_limit');
18
+ if (!isset($omitCats)) {
19
+ $omitCats = top_opt_OMIT_CATS;
20
+ }
21
+ if (!isset($ageLimit)) {
22
+ $ageLimit = top_opt_AGE_LIMIT;
23
+ }
24
+ $sql = "SELECT ID
25
+ FROM $wpdb->posts
26
+ WHERE post_type = 'post'
27
+ AND post_status = 'publish'
28
+ AND post_date < curdate( ) - INTERVAL ".$ageLimit." DAY
29
+ ";
30
+ if ($omitCats!='') {
31
+ $sql = $sql."AND NOT(ID IN (SELECT tr.object_id
32
+ FROM $wpdb->terms t
33
+ inner join $wpdb->term_taxonomy tax on t.term_id=tax.term_id and tax.taxonomy='category'
34
+ inner join $wpdb->term_relationships tr on tr.term_taxonomy_id=tax.term_taxonomy_id
35
+ WHERE t.term_id IN (".$omitCats.")))";
36
+ }
37
+ $sql = $sql."
38
+ ORDER BY RAND()
39
+ LIMIT 1 ";
40
+ $oldest_post = $wpdb->get_var($sql);
41
+ if (isset($oldest_post)) {
42
+ top_opt_tweet_post($oldest_post);
43
+ }
44
+ }
45
+
46
+
47
+ //tweet for the passed random post
48
+ function top_opt_tweet_post($oldest_post)
49
+ {
50
+ $post = get_post($oldest_post);
51
+ $content=null;
52
+ $permalink = get_permalink($oldest_post);
53
+ $add_data = get_option("top_opt_add_data");
54
+ $twitter_hashtags = get_option('top_opt_hashtags');
55
+ $url_shortener=get_option('top_opt_url_shortener');
56
+ if($url_shortener=="bit.ly")
57
+ {
58
+ $bitly_key=get_option('top_opt_bitly_key');
59
+ $bitly_user=get_option('top_opt_bitly_user');
60
+ $shorturl=shorten_url($permalink,$url_shortener,$bitly_key,$bitly_user);
61
+ }
62
+ else
63
+ {
64
+ $shorturl = shorten_url($permalink,$url_shortener);
65
+ }
66
+
67
+ $prefix=get_option('top_opt_tweet_prefix');
68
+
69
+ if($add_data == "true")
70
+ {
71
+ $content = stripslashes($post->post_content);
72
+ $content = strip_tags($content);
73
+ $content = preg_replace('/\s\s+/', ' ', $content);
74
+ $content = " - ".$content;
75
+ }
76
+ else {
77
+ $content="";
78
+ }
79
+
80
+ if(!is_numeric($shorturl))
81
+ {
82
+ if($prefix)
83
+ {
84
+ $message = $prefix.": ".$post->post_title;
85
+ }
86
+ else {
87
+ $message = $post->post_title;
88
+ }
89
+
90
+ $message = set_tweet_length($message.$content,$shorturl,$twitter_hashtags);
91
+
92
+ $username = get_option('top_opt_twitter_username');
93
+ $password = get_option('top_opt_twitter_password');
94
+
95
+
96
+ $status = urlencode(stripslashes(urldecode($message)));
97
+
98
+ if ($status) {
99
+ $tweetUrl = 'http://www.twitter.com/statuses/update.xml';
100
+
101
+ $curl = curl_init();
102
+ curl_setopt($curl, CURLOPT_URL, "$tweetUrl");
103
+ curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2);
104
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
105
+ curl_setopt($curl, CURLOPT_POST, 1);
106
+ curl_setopt($curl, CURLOPT_POSTFIELDS, "status=$status&source=TweetOldPost");
107
+ curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
108
+
109
+ $result = curl_exec($curl);
110
+ $resultArray = curl_getinfo($curl);
111
+
112
+ curl_close($curl);
113
+ }
114
+ }
115
+ }
116
+
117
+ //send request to passed url and return the response
118
+ function send_request($url, $method='GET', $data='', $auth_user='', $auth_pass='') {
119
+ $ch = curl_init($url);
120
+ if (strtoupper($method)=="POST") {
121
+ curl_setopt($ch, CURLOPT_POST, 1);
122
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
123
+ }
124
+ if (ini_get('open_basedir') == '' && ini_get('safe_mode') == 'Off'){
125
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
126
+ }
127
+ curl_setopt($ch, CURLOPT_HEADER, 0);
128
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
129
+ if ($auth_user != '' && $auth_pass != '') {
130
+ curl_setopt($ch, CURLOPT_USERPWD, "{$auth_user}:{$auth_pass}");
131
+ }
132
+ $response = curl_exec($ch);
133
+ $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
134
+ curl_close($ch);
135
+ if ($httpcode != 200) {
136
+ return $httpcode;
137
+ }
138
+
139
+ return $response;
140
+
141
+ }
142
+
143
+
144
+ //Shorten long URLs with is.gd or bit.ly.
145
+ function shorten_url($the_url, $shortener='is.gd', $api_key='', $user='') {
146
+
147
+ if ($shortener=="bit.ly" && isset($api_key) && isset($user)) {
148
+ $url = "http://api.bit.ly/shorten?version=2.0.1&longUrl={$the_url}&login={$user}&apiKey={$api_key}&format=xml";
149
+ $response = send_request($url, 'GET');
150
+ $the_results = new SimpleXmlElement($response);
151
+ if ($the_results->errorCode == '0') {
152
+ $response = $the_results->results->nodeKeyVal->shortUrl;
153
+ } else {
154
+ $response = "";
155
+ }
156
+ } elseif ($shortener=="su.pr") {
157
+ $url = "http://su.pr/api/simpleshorten?url={$the_url}";
158
+ $response = send_request($url, 'GET');
159
+ } elseif ($shortener=="tr.im") {
160
+ $url = "http://api.tr.im/api/trim_simple?url={$the_url}";
161
+ $response = send_request($url, 'GET');
162
+ } elseif ($shortener=="3.ly") {
163
+ $url = "http://3.ly/?api=em5893833&u={$the_url}";
164
+ $response = send_request($url, 'GET');
165
+ } elseif ($shortener=="tinyurl") {
166
+ $url = "http://tinyurl.com/api-create.php?url={$the_url}";
167
+ $response = send_request($url, 'GET');
168
+ } else {
169
+ $url = "http://is.gd/api.php?longurl={$the_url}";
170
+ $response = send_request($url, 'GET');
171
+ }
172
+ return $response;
173
+
174
+ }
175
+
176
+
177
+
178
+ //Shrink a tweet and accompanying URL down to 140 chars.
179
+ function set_tweet_length($message, $url, $twitter_hashtags="") {
180
+
181
+ $message_length = strlen($message);
182
+ $url_length = strlen($url);
183
+ $hashtags_length = strlen($twitter_hashtags);
184
+ if ($message_length + $url_length + $hashtags_length > 140) {
185
+ $shorten_message_to = 140 - $url_length - $hashtags_length;
186
+ $shorten_message_to = $shorten_message_to - 4;
187
+ //$message = $message." ";
188
+ $message = substr($message, 0, $shorten_message_to);
189
+ $message = substr($message, 0, strrpos($message,' '));
190
+ $message = $message."...";
191
+ }
192
+ return $message." ".$url." ".$twitter_hashtags;
193
+
194
+ }
195
+
196
+ //check time and update the last tweet time
197
+ function top_opt_update_time () {
198
+ $last = get_option('top_opt_last_update');
199
+ $interval = get_option('top_opt_interval');
200
+ if (!(isset($interval) && is_numeric($interval))) {
201
+ $interval = top_opt_INTERVAL;
202
+ }
203
+ $slop = get_option('top_opt_interval_slop');
204
+ if (!(isset($slop) && is_numeric($slop))) {
205
+ $slop = top_opt_INTERVAL_SLOP;
206
+ }
207
+ if (false === $last) {
208
+ $ret = 1;
209
+ } else if (is_numeric($last)) {
210
+ $ret = ( (time() - $last) > ($interval+rand(0,$slop)));
211
+ }
212
+ return $ret;
213
+ }
214
+
215
+ ?>
tweet-old-post.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ # /*
3
+ # Plugin Name: Tweet old post
4
+ # Plugin URI: http://www.ajaymatharu.com/wordpress-plugin-tweet-old-posts/
5
+ # Description: Plugin for tweeting your old posts randomly
6
+ # Author: Ajay Matharu
7
+ # Version: 1.4
8
+ # Author URI: http://www.ajaymatharu.com
9
+ # */
10
+
11
+
12
+ require_once('top-admin.php');
13
+ require_once('top-core.php');
14
+
15
+ define ('top_opt_1_HOUR', 60*60);
16
+ define ('top_opt_4_HOURS', 4*top_opt_1_HOUR);
17
+ define ('top_opt_6_HOURS', 6*top_opt_1_HOUR);
18
+ define ('top_opt_12_HOURS', 12*top_opt_1_HOUR);
19
+ define ('top_opt_24_HOURS', 24*top_opt_1_HOUR);
20
+ define ('top_opt_48_HOURS', 48*top_opt_1_HOUR);
21
+ define ('top_opt_72_HOURS', 72*top_opt_1_HOUR);
22
+ define ('top_opt_168_HOURS', 168*top_opt_1_HOUR);
23
+ define ('top_opt_INTERVAL', top_opt_12_HOURS);
24
+ define ('top_opt_INTERVAL_SLOP', top_opt_4_HOURS);
25
+ define ('top_opt_AGE_LIMIT', 120); // 120 days
26
+ define ('top_opt_OMIT_CATS', "");
27
+ define('top_opt_TWEET_PREFIX',"");
28
+ define('top_opt_ADD_DATA',"false");
29
+ define('top_opt_URL_SHORTENER',"is.gd");
30
+ define('top_opt_HASHTAGS',"");
31
+
32
+ function top_admin_actions() {
33
+ add_options_page("Tweet Old Post", "Tweet Old Post", 1, "TweetOldPost", "top_admin");
34
+ }
35
+
36
+ add_action('admin_menu', 'top_admin_actions');
37
+ add_action('admin_head', 'top_opt_head_admin');
38
+ add_action('init','top_tweet_old_post')
39
+
40
+ ?>