Revive Old Posts – Auto Post to Social Media - Version v3.1.2

Version Description

Download this release

Release Info

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

Version v3.1.2

Files changed (8) hide show
  1. Include/oauth.php +242 -0
  2. css/tweet-old-post.css +76 -0
  3. readme.txt +368 -0
  4. top-admin.php +519 -0
  5. top-core.php +316 -0
  6. top-excludepost.php +326 -0
  7. tweet-old-post.php +52 -0
  8. xml.php +130 -0
Include/oauth.php ADDED
@@ -0,0 +1,242 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if ( !class_exists( 'WP_Http' ) ) {
4
+ include_once( ABSPATH . WPINC. '/class-http.php' );
5
+ }
6
+
7
+ define( 'TOP_OAUTH_CONSUMER_KEY', 'ofaYongByVpa3NDEbXa2g' );
8
+ define( 'TOP_OAUTH_REQUEST_URL', 'http://api.twitter.com/oauth/request_token' );
9
+ define( 'TOP_OAUTH_ACCESS_URL', 'http://api.twitter.com/oauth/access_token' );
10
+ define( 'TOP_OAUTH_AUTHORIZE_URL', 'http://api.twitter.com/oauth/authorize' );
11
+ define( 'TOP_OAUTH_REALM', 'http://twitter.com/' );
12
+
13
+ class TOPOAuth {
14
+ var $duplicate_tweet;
15
+
16
+ function TOPOAuth() {
17
+ $this->duplicate_tweet = false;
18
+
19
+ $this->setup();
20
+ }
21
+
22
+ function encode( $string ) {
23
+ return str_replace( '+', ' ', str_replace( '%7E', '~', rawurlencode( $string ) ) );
24
+ }
25
+
26
+ function create_signature_base_string( $get_method, $base_url, $params ) {
27
+ if ( $get_method ) {
28
+ $base_string = "GET&";
29
+ } else {
30
+ $base_string = "POST&";
31
+ }
32
+
33
+ $base_string .= $this->encode( $base_url ) . "&";
34
+
35
+ // Sort the parameters
36
+ ksort( $params );
37
+
38
+ $encoded_params = array();
39
+ foreach( $params as $key => $value ) {
40
+ $encoded_params[] = $this->encode( $key ) . '=' . $this->encode( $value );
41
+ }
42
+
43
+ $base_string = $base_string . $this->encode( implode( $encoded_params, "&" ) );
44
+
45
+ return $base_string;
46
+ }
47
+
48
+ function params_to_query_string( $params ) {
49
+ $query_string = array();
50
+ foreach( $params as $key => $value ) {
51
+ $query_string[ $key ] = $key . '=' . $value;
52
+ }
53
+
54
+ ksort( $query_string );
55
+
56
+ return implode( '&', $query_string );
57
+ }
58
+
59
+ function do_get_request( $url ) {
60
+ $request = new WP_Http;
61
+ $result = $request->request( $url );
62
+
63
+ if ( $result['response']['code'] == '200' ) {
64
+ return $result['body'];
65
+ } else {
66
+ return false;
67
+ }
68
+ }
69
+
70
+ function do_request( $url, $oauth_header, $body_params = '' ) {
71
+ $request = new WP_Http;
72
+
73
+ $params = array();
74
+ if ( $body_params ) {
75
+ foreach( $body_params as $key => $value ) {
76
+ $body_params[ $key ] = ( $value );
77
+ }
78
+
79
+ $params['body'] = $body_params;
80
+ }
81
+
82
+ $params['method'] = 'POST';
83
+ $params['headers'] = array( 'Authorization' => $oauth_header );
84
+
85
+ $result = $request->request( $url, $params );
86
+
87
+ if ( !is_wp_error( $result ) ) {
88
+ if ( $result['response']['code'] == '200' ) {
89
+ return $result['body'];
90
+ } else if ( $result['response']['code'] == '403' ) {
91
+ // this is a duplicate tweet
92
+ $this->duplicate_tweet = true;
93
+ }
94
+ }
95
+
96
+ return false;
97
+ }
98
+
99
+ function get_nonce() {
100
+ return md5( mt_rand() + mt_rand() );
101
+ }
102
+
103
+ function parse_params( $string_params ) {
104
+ $good_params = array();
105
+
106
+ $params = explode( '&', $string_params );
107
+ foreach( $params as $param ) {
108
+ $keyvalue = explode( '=', $param );
109
+ $good_params[ $keyvalue[0] ] = $keyvalue[1];
110
+ }
111
+
112
+ return $good_params;
113
+ }
114
+
115
+ function hmac_sha1( $key, $data ) {
116
+ if ( function_exists( 'hash_hmac' ) ) {
117
+ $hash = hash_hmac( 'sha1', $data, $key, true );
118
+
119
+ return $hash;
120
+ } else {
121
+ $blocksize = 64;
122
+ $hashfunc = 'sha1';
123
+ if ( strlen( $key ) >$blocksize ) {
124
+ $key = pack( 'H*', $hashfunc( $key ) );
125
+ }
126
+
127
+ $key = str_pad( $key, $blocksize, chr(0x00) );
128
+ $ipad = str_repeat( chr( 0x36 ), $blocksize );
129
+ $opad = str_repeat( chr( 0x5c ), $blocksize );
130
+ $hash = pack( 'H*', $hashfunc( ( $key^$opad ).pack( 'H*',$hashfunc( ($key^$ipad).$data ) ) ) );
131
+
132
+ return $hash;
133
+ }
134
+ }
135
+
136
+ function do_oauth( $url, $params, $token_secret = '' ) {
137
+ $sig_string = $this->create_signature_base_string( false, $url, $params );
138
+
139
+ //$hash = hash_hmac( 'sha1', $sig_string, TOP_OAUTH_CONSUMER_SECRET . '&' . $token_secret, true );
140
+ $hash = $this->hmac_sha1( 'vTzszlMujMZCY3mVtTE6WovUKQxqv3LVgiVku276M' . '&' . $token_secret, $sig_string );
141
+ $sig = base64_encode( $hash );
142
+
143
+ $params['oauth_signature'] = $sig;
144
+
145
+ $header = "OAuth ";
146
+ $all_params = array();
147
+ $other_params = array();
148
+ foreach( $params as $key => $value ) {
149
+ if ( strpos( $key, 'oauth_' ) !== false ) {
150
+ $all_params[] = $key . '="' . $this->encode( $value ) . '"';
151
+ } else {
152
+ $other_params[ $key ] = $value;
153
+ }
154
+ }
155
+
156
+ $header .= implode( $all_params, ", " );
157
+
158
+ return $this->do_request( $url, $header, $other_params );
159
+ }
160
+
161
+ function get_request_token() {
162
+ $params = array();
163
+
164
+ $params['oauth_consumer_key'] = TOP_OAUTH_CONSUMER_KEY;
165
+ $params['oauth_callback'] = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '&TOP_oauth=1';
166
+ $params['oauth_signature_method'] = 'HMAC-SHA1';
167
+ $params['oauth_timestamp'] = time();
168
+ $params['oauth_nonce'] = $this->get_nonce();
169
+ $params['oauth_version'] = '1.0';
170
+
171
+ $result = $this->do_oauth( TOP_OAUTH_REQUEST_URL, $params );
172
+
173
+ if ( $result ) {
174
+ $new_params = $this->parse_params( $result );
175
+ return $new_params;
176
+ }
177
+ }
178
+
179
+ function get_access_token( $token, $token_secret, $verifier ) {
180
+ $params = array();
181
+
182
+ $params['oauth_consumer_key'] = TOP_OAUTH_CONSUMER_KEY;
183
+ $params['oauth_signature_method'] = 'HMAC-SHA1';
184
+ $params['oauth_timestamp'] = time();
185
+ $params['oauth_nonce'] = $this->get_nonce();
186
+ $params['oauth_version'] = '1.0';
187
+ $params['oauth_token'] = $token;
188
+ $params['oauth_verifier'] = $verifier;
189
+
190
+ $result = $this->do_oauth( TOP_OAUTH_ACCESS_URL, $params, $token_secret );
191
+ if ( $result ) {
192
+ $new_params = $this->parse_params( $result );
193
+ return $new_params;
194
+ }
195
+ }
196
+
197
+ function update_status( $token, $token_secret, $status ) {
198
+ $params = array();
199
+
200
+ $params['oauth_consumer_key'] = TOP_OAUTH_CONSUMER_KEY;
201
+ $params['oauth_signature_method'] = 'HMAC-SHA1';
202
+ $params['oauth_timestamp'] = time();
203
+ $params['oauth_nonce'] = $this->get_nonce();
204
+ $params['oauth_version'] = '1.0';
205
+ $params['oauth_token'] = $token;
206
+ $params['status'] = $status;
207
+
208
+ $url = 'http://api.twitter.com/1/statuses/update.xml';
209
+
210
+ $result = $this->do_oauth( $url, $params, $token_secret );
211
+ if ( $result ) {
212
+ $new_params = TOP_parsexml( $result );
213
+ return true;
214
+ } else {
215
+ return false;
216
+ }
217
+ }
218
+
219
+ function was_duplicate_tweet() {
220
+ return $this->duplicate_tweet;
221
+ }
222
+
223
+ function get_auth_url( $token ) {
224
+ return TOP_OAUTH_AUTHORIZE_URL . '?oauth_token=' . $token;
225
+ }
226
+
227
+ function get_user_info( $user_id ) {
228
+ $url = 'http://api.twitter.com/1/users/show.xml?id=' . $user_id;
229
+
230
+ $result = $this->do_get_request( $url );
231
+ if ( $result ) {
232
+ $new_params = TOP_parsexml( $result );
233
+ return $new_params;
234
+ }
235
+ }
236
+
237
+ function setup() {
238
+ eval( base64_decode( 'ZGVmaW5lKCAnV09SRFRXSVRfT0FVVEhfQ09OU1VNRVJfU0VDUkVUJywgJ0cxWkVTQjVXUGpDVDE4dVhDeldxNVZxbHBtdDdKanNVYVN0ZG5Gd3dhdycgKTs=' ) );
239
+ }
240
+ }
241
+
242
+ ?>
css/tweet-old-post.css ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ }
48
+
49
+ #profile-box
50
+ {
51
+ overflow:hidden;
52
+ padding-left: 15px;
53
+ }
54
+ #profile-box .avatar
55
+ {
56
+ float:left;
57
+ margin-right: 10px;
58
+ border-style: none;
59
+ }
60
+
61
+ #profile-box p {
62
+ margin-left: 58px;
63
+ }
64
+
65
+ #profile-box h4,
66
+ #profile-box h5 {
67
+ font-size: 13px;
68
+ text-shadow: #fff 0 -1px 1px;
69
+ margin: 0px;
70
+ padding-bottom: 2px;
71
+ }
72
+
73
+ #profile-box h5 {
74
+ font-size: 11px;
75
+ font-weight: normal;
76
+ }
readme.txt ADDED
@@ -0,0 +1,368 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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, Tweet, Post Tweets, Wordpress Twitter Plugin, Twitter Plugin, Tweet Selected Posts
4
+ Requires at least: 2.7
5
+ Tested up to: 3.0.1
6
+ Stable tag: trunk
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
+ New
19
+
20
+ **New in v3.1.2**
21
+
22
+ - Resolved tweets not getting posted when categories are excluded.
23
+ - If you are not able to authorise your twitter account set you blog URL in Administration → Settings → General.
24
+
25
+
26
+
27
+ **New in v3.1.1**
28
+
29
+ - Resolved tweets not getting posted issue. Sorry guys :(
30
+
31
+
32
+
33
+ **New in v3.1**
34
+
35
+ - Resolved issue of plugin flooding twitter account with tweets.
36
+ - added provision to exclude some post from selected categories
37
+
38
+
39
+
40
+ **New in v3.0**
41
+
42
+ - added OAuth authentication
43
+ - user defined intervals
44
+ - may not work under php 4 requires php 5
45
+
46
+
47
+
48
+ **New in v2.0**
49
+
50
+ - added provision to select if you want to shorten the URL or not.
51
+ - Cleaned other options.
52
+
53
+
54
+
55
+ **New in v1.9**
56
+
57
+ - Removed PHP 4 support as it was creating problem for lot of people
58
+
59
+
60
+
61
+ **New in v1.8**
62
+
63
+ - Bug Fixes
64
+ - Provision to fetch tweet url from custom field
65
+
66
+
67
+
68
+ **New in v1.7**
69
+
70
+ - Removed api option from 1click.at not needed api key
71
+
72
+
73
+
74
+ **New in v1.6**
75
+
76
+ - Made the plugin PHP 4 compatible. Guys try it out and please let me know if that worked.
77
+ - Better error prompting. If your tweets are not appearing on twitter. Try "Tweet Now" button you'll see if there is any problem in tweeting.
78
+ - Added 1click.at shortning service you need to get the api key from http://theeasyapi.com/ you need to add your machine IP address in the server of http://theeasyapi.com/ for this api key to work.
79
+
80
+
81
+
82
+ **New in v1.5**
83
+
84
+ - Maximum age of post to be eligible for tweet - allows you to set Maximum age of the post to be eligible for tweet
85
+ - Added one more shortner service was looking for j.mp but they dont have the api yet.
86
+
87
+
88
+
89
+ **New in v1.4**
90
+
91
+ - Hashtags - allows you to set default hashtags for your tweets
92
+
93
+
94
+
95
+ **New in v1.3**
96
+
97
+ - URL Shortener Service - allows you to select which URL shortener service you want to use.
98
+
99
+
100
+
101
+ **New in v1.2**
102
+
103
+ - Tweet Prefix - Allows you to set prefix to the tweets.
104
+ - Add Data - Allows you to add post data to the tweets
105
+ - Tweet now - Button that will tweet at that moment without wanting you to wait for scheduled tweet
106
+
107
+
108
+
109
+ **v1.1**
110
+
111
+ - Twitter Username & Password - Using this twitter account credentials plugin will tweet.
112
+ - Minimum interval between tweets - allows you to determine how often the plugin will automatically choose and tweet a blog post for you.
113
+ - Randomness interval - This is a contributing factor in minimum interval so that posts are randomly chosen and tweeted from your blog.
114
+ - 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.
115
+ - Categories to omit from tweets - This will protect posts from the selected categories from being tweeted.
116
+
117
+ == Installation ==
118
+
119
+ Following are the steps to install the Tweet Old Post plugin
120
+
121
+ 1. Download the latest version of the Tweet Old Posts Plugin to your computer from here.
122
+ 2. With an FTP program, access your site�s server.
123
+ 3. Upload (copy) the Plugin file(s) or folder to the /wp-content/plugins folder.
124
+ 4. In your WordPress Administration Panels, click on Plugins from the menu.
125
+ 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.
126
+ 6. To turn the Tweet Old Posts Plugin on, click Activate.
127
+ 7. Check your Administration Panels or WordPress blog to see if the Plugin is working.
128
+ 8. You can change the plugin options from Tweet Old Posts under settings menu.
129
+
130
+ Alternatively you can also follow the following steps to install the Tweet Old Post plugin
131
+
132
+ 1. In your WordPress Administration Panels, click on Add New option under Plugins from the menu.
133
+ 2. Click on upload at the top.
134
+ 3. Browse the location and select the Tweet Old Post Plugin and click install now.
135
+ 4. To turn the Tweet Old Posts Plugin on, click Activate.
136
+ 5. Check your Administration Panels or WordPress blog to see if the Plugin is working.
137
+ 6. You can change the plugin options from Tweet Old Posts under settings menu.
138
+
139
+ == Frequently Asked Questions ==
140
+
141
+ If you have any questions please mail me at,
142
+ ajay@ajaymatharu.com or matharuajay@yahoo.co.in
143
+
144
+ **Tweet Old post does not posts any tweets?**
145
+
146
+ - If its not tweeting any tweets try playing around with the options. Try setting maxtweetage to none and try again.
147
+ - Try removing categories from excluded option. Some of them have posted issues of tweet not getting post when categories are selected in exclued category section.
148
+
149
+
150
+ **Tweet old post giving SimpleXmlElement error?**
151
+
152
+ - If it is giving SimpleXmlElement error, check with your hosting provider on which version of PHP are they supporting.
153
+ Tweet Old Post supports PHP 5 onwards. It will give SimpleXmlElement error if your hosting provider supports PHP 4
154
+ or PHP less than 5
155
+
156
+
157
+ **Tweets not getting posted?**
158
+
159
+ - If your tweets are not getting posted, try deauthorizing and again authorizing your twitter account with
160
+ plugin.
161
+
162
+
163
+ **Plugin flooded your tweeter account with tweets?**
164
+
165
+ - please check your setting increase the minimum interval between tweets. If your plugin is not updated please update your plugin to latest version.
166
+
167
+
168
+ **Not able to authorize your twitter account with Tweet Old Post**
169
+
170
+ - If you are not able to authorise your twitter account set you blog URL in Administration → Settings → General.
171
+
172
+
173
+ == Screenshots ==
174
+
175
+ for screenshots you can check out
176
+
177
+ http://www.ajaymatharu.com/wordpress-plugin-tweet-old-posts/
178
+
179
+ == Changelog ==
180
+
181
+ **New in v3.1.2**
182
+
183
+ - Resolved tweets not getting posted when categories are excluded.
184
+ - If you are not able to authorise your twitter account set you blog URL in Administration → Settings → General.
185
+
186
+
187
+
188
+ **New in v3.1**
189
+
190
+ - Resolved issue of plugin flooding twitter account with tweets.
191
+ - added provision to exclude some post from selected categories
192
+
193
+
194
+
195
+ **New in v3.0**
196
+
197
+ - added OAuth authentication
198
+ - user defined intervals
199
+ - may not work under php 4 requires php 5
200
+
201
+
202
+
203
+ **New in v2.0**
204
+
205
+ - added provision to select if you want to shorten the URL or not.
206
+ - Cleaned other options.
207
+
208
+
209
+
210
+ **New in v1.9**
211
+
212
+ - Removed PHP 4 support as it was creating problem for lot of people
213
+
214
+
215
+
216
+ **New in v1.8**
217
+
218
+ - Bug Fixes
219
+ - Provision to fetch tweet url from custom field
220
+
221
+
222
+
223
+ **New in v1.7**
224
+
225
+ - Removed api option from 1click.at not needed api key
226
+
227
+
228
+
229
+ **New in v1.6**
230
+
231
+ - Made the plugin PHP 4 compatible. Guys try it out and please let me know if that worked.
232
+ - Better error prompting. If your tweets are not appearing on twitter. Try "Tweet Now" button you'll see if there is any problem in tweeting.
233
+ - Added 1click.at shortning service you need to get the api key from http://theeasyapi.com/ you need to add your machine IP address in the server of http://theeasyapi.com/ for this api key to work.
234
+
235
+
236
+
237
+ **New in v1.5**
238
+
239
+ - Maximum age of post to be eligible for tweet - allows you to set Maximum age of the post to be eligible for tweet
240
+ - Added one more shortner service was looking for j.mp but they dont have the api yet.
241
+
242
+
243
+
244
+ **New in v1.4**
245
+
246
+ - Hashtags - allows you to set default hashtags for your tweets
247
+
248
+
249
+
250
+ **New in v1.3**
251
+
252
+ - URL Shortener Service - allows you to select which URL shortener service you want to use.
253
+
254
+
255
+
256
+ **New in v1.2**
257
+
258
+ - Tweet Prefix - Allows you to set prefix to the tweets.
259
+ - Add Data - Allows you to add post data to the tweets
260
+ - Tweet now - Button that will tweet at that moment without wanting you to wait for scheduled tweet
261
+
262
+
263
+
264
+ **v1.1**
265
+
266
+ - Twitter Username & Password - Using this twitter account credentials plugin will tweet.
267
+ - Minimum interval between tweets - allows you to determine how often the plugin will automatically choose and tweet a blog post for you.
268
+ - Randomness interval - This is a contributing factor in minimum interval so that posts are randomly chosen and tweeted from your blog.
269
+ - 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.
270
+ - Categories to omit from tweets - This will protect posts from the selected categories from being tweeted.
271
+
272
+
273
+ == Other Notes ==
274
+
275
+ Some of the options you can configure for the Tweet Old Posts plugins are,
276
+
277
+
278
+ **New in v3.1.2**
279
+
280
+ - Resolved tweets not getting posted when categories are excluded.
281
+ - If you are not able to authorise your twitter account set you blog URL in Administration → Settings → General.
282
+
283
+
284
+
285
+ **New in v3.1**
286
+
287
+ - Resolved issue of plugin flooding twitter account with tweets.
288
+ - added provision to exclude some post from selected categories
289
+
290
+
291
+
292
+ **New in v3.0**
293
+
294
+ - added OAuth authentication
295
+ - user defined intervals
296
+ - may not work under php 4 requires php 5
297
+
298
+
299
+
300
+ **New in v2.0**
301
+
302
+ - added provision to select if you want to shorten the URL or not.
303
+ - Cleaned other options.
304
+
305
+
306
+
307
+ **New in v1.9**
308
+
309
+ - Removed PHP 4 support as it was creating problem for lot of people
310
+
311
+
312
+
313
+ **New in v1.8**
314
+
315
+ - Bug Fixes
316
+ - Provision to fetch tweet url from custom field
317
+
318
+
319
+
320
+ **New in v1.7**
321
+
322
+ - Removed api option from 1click.at not needed api key
323
+
324
+
325
+
326
+ **New in v1.6**
327
+
328
+ - Made the plugin PHP 4 compatible. Guys try it out and please let me know if that worked.
329
+ - Better error prompting. If your tweets are not appearing on twitter. Try "Tweet Now" button you'll see if there is any problem in tweeting.
330
+ - Added 1click.at shortning service you need to get the api key from http://theeasyapi.com/ you need to add your machine IP address in the server of http://theeasyapi.com/ for this api key to work.
331
+
332
+
333
+
334
+ **New in v1.5**
335
+
336
+ - Maximum age of post to be eligible for tweet - allows you to set Maximum age of the post to be eligible for tweet
337
+ - Added one more shortner service was looking for j.mp but they dont have the api yet.
338
+
339
+
340
+
341
+ **New in v1.4**
342
+
343
+ - Hashtags - allows you to set default hashtags for your tweets
344
+
345
+
346
+
347
+ **New in v1.3**
348
+
349
+ - URL Shortener Service - allows you to select which URL shortener service you want to use.
350
+
351
+
352
+
353
+ **New in v1.2**
354
+
355
+ - Tweet Prefix - Allows you to set prefix to the tweets.
356
+ - Add Data - Allows you to add post data to the tweets
357
+ - Tweet now - Button that will tweet at that moment without wanting you to wait for scheduled tweet
358
+
359
+
360
+
361
+ **v1.1**
362
+
363
+ - Twitter Username & Password - Using this twitter account credentials plugin will tweet.
364
+ - Minimum interval between tweets - allows you to determine how often the plugin will automatically choose and tweet a blog post for you.
365
+ - Randomness interval - This is a contributing factor in minimum interval so that posts are randomly chosen and tweeted from your blog.
366
+ - 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.
367
+ - Categories to omit from tweets - This will protect posts from the selected categories from being tweeted.
368
+
top-admin.php ADDED
@@ -0,0 +1,519 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once('tweet-old-post.php');
4
+ require_once('top-core.php');
5
+ require_once( 'Include/oauth.php' );
6
+ require_once('xml.php');
7
+
8
+ function top_admin() {
9
+ if (current_user_can('manage_options')) {
10
+ $message = null;
11
+ $message_updated = __("Tweet Old Post Options Updated.", 'TweetOldPost');
12
+ $response = null;
13
+ $save = true;
14
+ $settings = top_get_settings();
15
+ if (isset($_GET['TOP_oauth'])) {
16
+ global $top_oauth;
17
+
18
+
19
+ $result = $top_oauth->get_access_token($settings['oauth_request_token'], $settings['oauth_request_token_secret'], $_GET['oauth_verifier']);
20
+
21
+ if ($result) {
22
+ $settings['oauth_access_token'] = $result['oauth_token'];
23
+ $settings['oauth_access_token_secret'] = $result['oauth_token_secret'];
24
+ $settings['user_id'] = $result['user_id'];
25
+
26
+ $result = $top_oauth->get_user_info($result['user_id']);
27
+ if ($result) {
28
+ $settings['profile_image_url'] = $result['user']['profile_image_url'];
29
+ $settings['screen_name'] = $result['user']['screen_name'];
30
+ if (isset($result['user']['location'])) {
31
+ $settings['location'] = $result['user']['location'];
32
+ } else {
33
+ $settings['location'] = false;
34
+ }
35
+ }
36
+
37
+ top_save_settings($settings);
38
+ echo '<script language="javascript">window.open ("' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=TweetOldPost","_self")</script>';
39
+ die;
40
+ }
41
+ } else if (isset($_GET['top']) && $_GET['top'] == 'deauthorize') {
42
+ $settings = top_get_settings();
43
+ $settings['oauth_access_token'] = '';
44
+ $settings['oauth_access_token_secret'] = '';
45
+ $settings['user_id'] = '';
46
+ $settings['tweet_queue'] = array();
47
+
48
+ top_save_settings($settings);
49
+ echo '<script language="javascript">window.open ("' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=TweetOldPost","_self")</script>';
50
+ die;
51
+ }
52
+
53
+ if (isset($_POST['top_opt_url_shortener'])) {
54
+ if ($_POST['top_opt_url_shortener'] == "bit.ly") {
55
+
56
+ if (!isset($_POST['top_opt_bitly_user'])) {
57
+ print('
58
+ <div id="message" class="updated fade">
59
+ <p>' . __('Please enter bit.ly username.', 'TweetOldPost') . '</p>
60
+ </div>');
61
+ $save = false;
62
+ } elseif (!isset($_POST['top_opt_bitly_key'])) {
63
+ print('
64
+ <div id="message" class="updated fade">
65
+ <p>' . __('Please enter bit.ly API Key.', 'TweetOldPost') . '</p>
66
+ </div>');
67
+ $save = false;
68
+ } else {
69
+ $save = true;
70
+ }
71
+ }
72
+ }
73
+
74
+ if (isset($_POST['submit']) && $save) {
75
+ $message = $message_updated;
76
+
77
+ if (isset($_POST['top_opt_interval'])) {
78
+ if (is_numeric($_POST['top_opt_interval']) && $_POST['top_opt_interval']>0) {
79
+ update_option('top_opt_interval', $_POST['top_opt_interval']);
80
+ }
81
+ else
82
+ {
83
+ update_option('top_opt_interval',"4");
84
+ }
85
+
86
+
87
+ }
88
+ if (isset($_POST['top_opt_interval_slop'])) {
89
+
90
+ if (is_numeric($_POST['top_opt_interval_slop']) && $_POST['top_opt_interval_slop']>0) {
91
+ update_option('top_opt_interval_slop', $_POST['top_opt_interval_slop']);
92
+ }
93
+ else
94
+ {
95
+ update_option('top_opt_interval_slop',"4");
96
+ }
97
+ }
98
+ if (isset($_POST['top_opt_age_limit'])) {
99
+ update_option('top_opt_age_limit', $_POST['top_opt_age_limit']);
100
+ }
101
+ if (isset($_POST['top_opt_max_age_limit'])) {
102
+ update_option('top_opt_max_age_limit', $_POST['top_opt_max_age_limit']);
103
+ }
104
+ if (isset($_POST['top_opt_tweet_prefix'])) {
105
+ update_option('top_opt_tweet_prefix', $_POST['top_opt_tweet_prefix']);
106
+ }
107
+ if (isset($_POST['top_opt_add_data'])) {
108
+ update_option('top_opt_add_data', $_POST['top_opt_add_data']);
109
+ }
110
+ if (isset($_POST['post_category'])) {
111
+ update_option('top_opt_omit_cats', implode(',', $_POST['post_category']));
112
+ } else {
113
+ update_option('top_opt_omit_cats', '');
114
+ }
115
+
116
+
117
+ if (isset($_POST['top_opt_custom_url_option'])) {
118
+ update_option('top_opt_custom_url_option', true);
119
+ } else {
120
+
121
+ update_option('top_opt_custom_url_option', false);
122
+ }
123
+
124
+ if (isset($_POST['top_opt_custom_url_field'])) {
125
+ update_option('top_opt_custom_url_field', $_POST['top_opt_custom_url_field']);
126
+ } else {
127
+
128
+ update_option('top_opt_custom_url_field', '');
129
+ }
130
+
131
+ if (isset($_POST['top_opt_use_url_shortner'])) {
132
+ update_option('top_opt_use_url_shortner', true);
133
+ } else {
134
+
135
+ update_option('top_opt_use_url_shortner', false);
136
+ }
137
+
138
+ if (isset($_POST['top_opt_hashtags'])) {
139
+ update_option('top_opt_hashtags', $_POST['top_opt_hashtags']);
140
+ } else {
141
+ update_option('top_opt_hashtags', '');
142
+ }
143
+
144
+ if (isset($_POST['top_opt_url_shortener'])) {
145
+ update_option('top_opt_url_shortener', $_POST['top_opt_url_shortener']);
146
+ if ($_POST['top_opt_url_shortener'] == "bit.ly") {
147
+ if (isset($_POST['top_opt_bitly_user'])) {
148
+ update_option('top_opt_bitly_user', $_POST['top_opt_bitly_user']);
149
+ }
150
+ if (isset($_POST['top_opt_bitly_key'])) {
151
+ update_option('top_opt_bitly_key', $_POST['top_opt_bitly_key']);
152
+ }
153
+ }
154
+ }
155
+ print('
156
+ <div id="message" class="updated fade">
157
+ <p>' . __('Tweet Old Post Options Updated.', 'TweetOldPost') . '</p>
158
+ </div>');
159
+ } elseif (isset($_POST['tweet'])) {
160
+ $tweet_msg = top_opt_tweet_old_post();
161
+ print('
162
+ <div id="message" class="updated fade">
163
+ <p>' . __($tweet_msg, 'TweetOldPost') . '</p>
164
+ </div>');
165
+ }
166
+ $omitCats = get_option('top_opt_omit_cats');
167
+ if (!isset($omitCats)) {
168
+ $omitCats = top_opt_OMIT_CATS;
169
+ }
170
+ $ageLimit = get_option('top_opt_age_limit');
171
+ if (!(isset($ageLimit) && is_numeric($ageLimit))) {
172
+ $ageLimit = top_opt_AGE_LIMIT;
173
+ }
174
+
175
+ $maxAgeLimit = get_option('top_opt_max_age_limit');
176
+ if (!(isset($maxAgeLimit) && is_numeric($maxAgeLimit))) {
177
+ $maxAgeLimit = top_opt_MAX_AGE_LIMIT;
178
+ }
179
+
180
+ $interval = get_option('top_opt_interval');
181
+ if (!(isset($interval) && is_numeric($interval))) {
182
+ $interval = top_opt_INTERVAL;
183
+ }
184
+ $slop = get_option('top_opt_interval_slop');
185
+ if (!(isset($slop) && is_numeric($slop))) {
186
+ $slop = top_opt_INTERVAL_SLOP;
187
+ }
188
+ $tweet_prefix = get_option('top_opt_tweet_prefix');
189
+ if (!isset($tweet_prefix)) {
190
+ $tweet_prefix = top_opt_TWEET_PREFIX;
191
+ }
192
+ $url_shortener = get_option('top_opt_url_shortener');
193
+ if (!isset($url_shortener)) {
194
+ $url_shortener = top_opt_URL_SHORTENER;
195
+ }
196
+
197
+
198
+ $twitter_hashtags = get_option('top_opt_hashtags');
199
+ if (!isset($twitter_hashtags)) {
200
+ $twitter_hashtags = top_opt_HASHTAGS;
201
+ }
202
+
203
+ $bitly_api = get_option('top_opt_bitly_key');
204
+ if (!isset($bitly_api)) {
205
+ $bitly_api = "";
206
+ }
207
+ $bitly_username = get_option('top_opt_bitly_user');
208
+ if (!isset($bitly_username)) {
209
+ $bitly_username = "";
210
+ }
211
+
212
+ $custom_url_option = get_option('top_opt_custom_url_option');
213
+
214
+ if (!isset($custom_url_option)) {
215
+ $custom_url_option = "";
216
+ } elseif ($custom_url_option)
217
+ $custom_url_option = "checked";
218
+ else
219
+ $custom_url_option="";
220
+
221
+ $custom_url_field = get_option('top_opt_custom_url_field');
222
+ if (!isset($custom_url_field)) {
223
+ $custom_url_field = "";
224
+ }
225
+
226
+ $use_url_shortner = get_option('top_opt_use_url_shortner');
227
+ if (!isset($use_url_shortner)) {
228
+ $use_url_shortner = "";
229
+ } elseif ($use_url_shortner)
230
+ $use_url_shortner = "checked";
231
+ else
232
+ $use_url_shortner="";
233
+ $add_data = get_option('top_opt_add_data');
234
+ $twitter_username = get_option('top_opt_twitter_username');
235
+ $twitter_password = get_option('top_opt_twitter_password');
236
+
237
+ print('
238
+ <div class="wrap">
239
+ <h2>' . __('Tweet old post by - ', 'TweetOldPost') . ' <a href="http://www.ajaymatharu.com">Ajay Matharu</a></h2>
240
+ <form id="top_opt" name="top_TweetOldPost" action="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=TweetOldPost" method="post">
241
+ <input type="hidden" name="top_opt_action" value="top_opt_update_settings" />
242
+ <fieldset class="options">
243
+ <div class="option">
244
+ <label for="top_opt_twitter_username">' . __('Account Login', 'TweetOldPost') . ':</label>
245
+
246
+ <div id="profile-box">');
247
+ if (!$settings["oauth_access_token"]) {
248
+ echo '<a href="' . top_get_auth_url() . '"><img src="http://apiwiki.twitter.com/f/1242697607/Sign-in-with-Twitter-lighter-small.png" /></a>';
249
+ } else {
250
+ echo '<img class="avatar" src="' . $settings["profile_image_url"] . '" alt="" />
251
+ <h4>' . $settings["screen_name"] . '</h4>';
252
+ if ($settings["location"]) {
253
+ echo '<h5>' . $settings["location"] . '</h5>';
254
+ }
255
+ echo '<p>
256
+
257
+ Your account has been authorized. <a href="' . $_SERVER["REQUEST_URI"] . '&top=deauthorize" onclick=\'return confirm("Are you sure you want to deauthorize your Twitter account?");\'>Click to deauthorize</a>.<br />
258
+
259
+ </p>
260
+
261
+ <div class="retweet-clear"></div>
262
+ ';
263
+ }
264
+ print('</div>
265
+ </div>
266
+
267
+ <div class="option">
268
+ <label for="top_opt_tweet_prefix">' . __('Tweet Prefix', 'TweetOldPost') . ':</label>
269
+ <input type="text" size="25" name="top_opt_tweet_prefix" id="top_opt_tweet_prefix" value="' . $tweet_prefix . '" autocomplete="off" />
270
+ <b>If set, it will show as: "{tweet prefix}: {post title}... {url}</b>
271
+ </div>
272
+ <div class="option">
273
+ <label for="top_opt_add_data">' . __('Add post data to tweet', 'TweetOldPost') . ':</label>
274
+ <select id="top_opt_add_data" name="top_opt_add_data" style="width:100px;">
275
+ <option value="false" ' . top_opt_optionselected("false", $add_data) . '>' . __(' No ', 'TweetOldPost') . '</option>
276
+ <option value="true" ' . top_opt_optionselected("true", $add_data) . '>' . __(' Yes ', 'TweetOldPost') . '</option>
277
+ </select>
278
+ <b>If set, it will show as: "{tweet prefix}: {post title}- {content}... {url}</b>
279
+ </div>
280
+
281
+ <div class="option">
282
+ <label for="top_opt_custom_url_option">' . __('Fetch URL from custom field', 'TweetOldPost') . ':</label>
283
+ <input onchange="return showCustomField();" type="checkbox" name="top_opt_custom_url_option" ' . $custom_url_option . ' id="top_opt_custom_url_option" />
284
+ <b>If checked URL will be fetched from custom field. If not plugin will generate shortened URL from post link.</b>
285
+ </div>
286
+
287
+
288
+
289
+ <div id="customurl" style="display:none;">
290
+ <div class="option">
291
+ <label for="top_opt_custom_url_field">' . __('Custom field name to fetch URL to be tweeted with post', 'TweetOldPost') . ':</label>
292
+ <input type="text" size="25" name="top_opt_custom_url_field" id="top_opt_custom_url_field" value="' . $custom_url_field . '" autocomplete="off" />
293
+ <b>If set this will fetch the URL from specified custom field</b>
294
+ </div>
295
+
296
+ </div>
297
+
298
+ <div class="option">
299
+ <label for="top_opt_use_url_shortner">' . __('Use URL shortner?', 'TweetOldPost') . ':</label>
300
+ <input onchange="return showshortener()" type="checkbox" name="top_opt_use_url_shortner" id="top_opt_use_url_shortner" ' . $use_url_shortner . ' />
301
+
302
+ </div>
303
+
304
+ <div id="urlshortener">
305
+ <div class="option">
306
+ <label for="top_opt_url_shortener">' . __('URL Shortener Service', 'TweetOldPost') . ':</label>
307
+ <select name="top_opt_url_shortener" id="top_opt_url_shortener" onchange="javascript:showURLAPI()" style="width:100px;">
308
+ <option value="is.gd" ' . top_opt_optionselected('is.gd', $url_shortener) . '>' . __('is.gd', 'TweetOldPost') . '</option>
309
+ <option value="su.pr" ' . top_opt_optionselected('su.pr', $url_shortener) . '>' . __('su.pr', 'TweetOldPost') . '</option>
310
+ <option value="bit.ly" ' . top_opt_optionselected('bit.ly', $url_shortener) . '>' . __('bit.ly', 'TweetOldPost') . '</option>
311
+ <option value="tr.im" ' . top_opt_optionselected('tr.im', $url_shortener) . '>' . __('tr.im', 'TweetOldPost') . '</option>
312
+ <option value="3.ly" ' . top_opt_optionselected('3.ly', $url_shortener) . '>' . __('3.ly', 'TweetOldPost') . '</option>
313
+ <option value="u.nu" ' . top_opt_optionselected('u.nu', $url_shortener) . '>' . __('u.nu', 'TweetOldPost') . '</option>
314
+ <option value="1click.at" ' . top_opt_optionselected('1click.at', $url_shortener) . '>' . __('1click.at', 'TweetOldPost') . '</option>
315
+ <option value="tinyurl" ' . top_opt_optionselected('tinyurl', $url_shortener) . '>' . __('tinyurl', 'TweetOldPost') . '</option>
316
+ </select>
317
+ </div>
318
+ <div id="showDetail" style="display:none">
319
+ <div class="option">
320
+ <label for="top_opt_bitly_user">' . __('bit.ly Username', 'TweetOldPost') . ':</label>
321
+ <input type="text" size="25" name="top_opt_bitly_user" id="top_opt_bitly_user" value="' . $bitly_username . '" autocomplete="off" />
322
+ </div>
323
+
324
+ <div class="option">
325
+ <label for="top_opt_bitly_key">' . __('bit.ly API Key', 'TweetOldPost') . ':</label>
326
+ <input type="text" size="25" name="top_opt_bitly_key" id="top_opt_bitly_key" value="' . $bitly_api . '" autocomplete="off" />
327
+ </div>
328
+ </div>
329
+ </div>
330
+
331
+
332
+ <div class="option">
333
+ <label for="top_opt_hashtags">' . __('Default #hashtags for your tweets', 'TweetOldPost') . ':</label>
334
+ <input type="text" size="25" name="top_opt_hashtags" id="top_opt_hashtags" value="' . $twitter_hashtags . '" autocomplete="off" />
335
+ <b>Include #, like #thoughts</b>
336
+ </div>
337
+
338
+ <div class="option">
339
+ <label for="top_opt_interval">' . __('Minimum interval between tweets: ', 'TweetOldPost') . '</label>
340
+ <input type="text" id="top_opt_interval" maxlength="5" value="' . $interval . '" name="top_opt_interval" /> Hour / Hours <b>(Note: If set to 0 it will take default as 4 hours)</b>
341
+
342
+ </div>
343
+ <div class="option">
344
+ <label for="top_opt_interval_slop">' . __('Random Interval (added to minimum interval): ', 'TweetOldPost') . '</label>
345
+ <input type="text" id="top_opt_interval_slop" maxlength="5" value="' . $slop . '" name="top_opt_interval_slop" /> Hour / Hours <b>(Note: If set to 0 it will take default as 4 hours)</b>
346
+
347
+ </div>
348
+ <div class="option">
349
+ <label for="top_opt_age_limit">' . __('Minimum age of post to be eligible for tweet: ', 'TweetOldPost') . '</label>
350
+ <input type="text" id="top_opt_age_limit" maxlength="5" value="' . $ageLimit . '" name="top_opt_age_limit" /> Day / Days
351
+ <b> (enter 0 for today)</b>
352
+
353
+ </div>
354
+
355
+ <div class="option">
356
+ <label for="top_opt_max_age_limit">' . __('Maximum age of post to be eligible for tweet: ', 'TweetOldPost') . '</label>
357
+ <input type="text" id="top_opt_max_age_limit" maxlength="5" value="' . $maxAgeLimit . '" name="top_opt_max_age_limit" /> Day / Days
358
+ <b>(If you dont want to use this option enter 0 or leave blank)</b><br/>
359
+ <b>If set, it will fetch posts which are "NOT" older than specified day / days</b>
360
+ </div>
361
+
362
+ <div class="option category">
363
+ <div style="float:left">
364
+ <label class="catlabel">' . __('Categories to Omit from tweets: ', 'TweetOldPost') . '</label> </div>
365
+ <div style="float:left">
366
+ <ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
367
+ ');
368
+ wp_category_checklist(0, 0, explode(',', $omitCats));
369
+ print(' </ul>
370
+ <div style="clear:both;padding-top:20px;">
371
+ <a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=ExcludePosts">Exclude specific posts</a> from selected categories.
372
+ </div>
373
+ </div>
374
+
375
+ </div>
376
+ </fieldset>
377
+
378
+ <h3>Note: Please click update to then click tweet now to reflect the changes.</h3>
379
+ <p class="submit"><input type="submit" name="submit" onclick="javascript:return validate()" value="' . __('Update Tweet Old Post Options', 'TweetOldPost') . '" />
380
+ <input type="submit" name="tweet" value="' . __('Tweet Now', 'TweetOldPost') . '" />
381
+ </p>
382
+
383
+ </form><script language="javascript" type="text/javascript">
384
+ function showURLAPI()
385
+ {
386
+ var urlShortener=document.getElementById("top_opt_url_shortener").value;
387
+ if(urlShortener=="bit.ly")
388
+ {
389
+ document.getElementById("showDetail").style.display="block";
390
+
391
+ }
392
+ else
393
+ {
394
+ document.getElementById("showDetail").style.display="none";
395
+
396
+ }
397
+
398
+ }
399
+
400
+ function validate()
401
+ {
402
+
403
+ if(document.getElementById("showDetail").style.display=="block" && document.getElementById("top_opt_url_shortener").value=="bit.ly")
404
+ {
405
+ if(trim(document.getElementById("top_opt_bitly_user").value)=="")
406
+ {
407
+ alert("Please enter bit.ly username.");
408
+ document.getElementById("top_opt_bitly_user").focus();
409
+ return false;
410
+ }
411
+
412
+ if(trim(document.getElementById("top_opt_bitly_key").value)=="")
413
+ {
414
+ alert("Please enter bit.ly API key.");
415
+ document.getElementById("top_opt_bitly_key").focus();
416
+ return false;
417
+ }
418
+ }
419
+ if(trim(document.getElementById("top_opt_interval").value) != "" && !isNumber(trim(document.getElementById("top_opt_interval").value)))
420
+ {
421
+ alert("Enter only numeric in Minimum interval between tweet");
422
+ document.getElementById("top_opt_interval").focus();
423
+ return false;
424
+ }
425
+ if(trim(document.getElementById("top_opt_interval_slop").value) != "" && !isNumber(trim(document.getElementById("top_opt_interval_slop").value)))
426
+ {
427
+ alert("Enter only numeric in Random interval");
428
+ document.getElementById("top_opt_interval_slop").focus();
429
+ return false;
430
+ }
431
+ if(trim(document.getElementById("top_opt_age_limit").value) != "" && !isNumber(trim(document.getElementById("top_opt_age_limit").value)))
432
+ {
433
+ alert("Enter only numeric in Minimum age of post");
434
+ document.getElementById("top_opt_age_limit").focus();
435
+ return false;
436
+ }
437
+ if(trim(document.getElementById("top_opt_max_age_limit").value) != "" && !isNumber(trim(document.getElementById("top_opt_max_age_limit").value)))
438
+ {
439
+ alert("Enter only numeric in Maximum age of post");
440
+ document.getElementById("top_opt_max_age_limit").focus();
441
+ return false;
442
+ }
443
+ if(trim(document.getElementById("top_opt_max_age_limit").value) != "" && trim(document.getElementById("top_opt_max_age_limit").value) != 0)
444
+ {
445
+ if(eval(document.getElementById("top_opt_age_limit").value) > eval(document.getElementById("top_opt_max_age_limit").value))
446
+ {
447
+ alert("Post max age limit cannot be less than Post min age iimit");
448
+ document.getElementById("top_opt_age_limit").focus();
449
+ return false;
450
+ }
451
+ }
452
+ }
453
+
454
+ function trim(stringToTrim) {
455
+ return stringToTrim.replace(/^\s+|\s+$/g,"");
456
+ }
457
+
458
+ function showCustomField()
459
+ {
460
+ if(document.getElementById("top_opt_custom_url_option").checked)
461
+ {
462
+ document.getElementById("customurl").style.display="block";
463
+ }
464
+ else
465
+ {
466
+ document.getElementById("customurl").style.display="none";
467
+ }
468
+ }
469
+
470
+ function isNumber(val)
471
+ {
472
+ if(isNaN(val)){
473
+ return false;
474
+ }
475
+ else{
476
+ return true;
477
+ }
478
+ }
479
+
480
+ function showshortener()
481
+ {
482
+
483
+
484
+ if((document.getElementById("top_opt_use_url_shortner").checked))
485
+ {
486
+ document.getElementById("urlshortener").style.display="block";
487
+ }
488
+ else
489
+ {
490
+ document.getElementById("urlshortener").style.display="none";
491
+ }
492
+ }
493
+ showURLAPI();
494
+ showshortener();
495
+ showCustomField();
496
+ </script>');
497
+ } else {
498
+ print('
499
+ <div id="message" class="updated fade">
500
+ <p>' . __('You do not have enough permission to set the option. Please contact your admin.', 'TweetOldPost') . '</p>
501
+ </div>');
502
+ }
503
+ }
504
+
505
+ function top_opt_optionselected($opValue, $value) {
506
+ if ($opValue == $value) {
507
+ return 'selected="selected"';
508
+ }
509
+ return '';
510
+ }
511
+
512
+ function top_opt_head_admin() {
513
+ $home = get_settings('siteurl');
514
+ $base = '/' . end(explode('/', str_replace(array('\\', '/top-admin.php'), array('/', ''), __FILE__)));
515
+ $stylesheet = $home . '/wp-content/plugins' . $base . '/css/tweet-old-post.css';
516
+ echo('<link rel="stylesheet" href="' . $stylesheet . '" type="text/css" media="screen" />');
517
+ }
518
+
519
+ ?>
top-core.php ADDED
@@ -0,0 +1,316 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once( 'Include/oauth.php' );
4
+ global $top_oauth;
5
+ $top_oauth = new TOPOAuth;
6
+
7
+ function top_tweet_old_post() {
8
+ //check last tweet time against set interval and span
9
+ if (top_opt_update_time ()) {
10
+ update_option('top_opt_last_update', time());
11
+ top_opt_tweet_old_post();
12
+ }
13
+ }
14
+
15
+ //get random post and tweet
16
+ function top_opt_tweet_old_post() {
17
+ global $wpdb;
18
+ $omitCats = get_option('top_opt_omit_cats');
19
+ $maxAgeLimit = get_option('top_opt_max_age_limit');
20
+ $ageLimit = get_option('top_opt_age_limit');
21
+ $exposts = get_option('top_opt_excluded_post');
22
+ $exposts = preg_replace('/,,+/', ',', $exposts);
23
+ if (substr($exposts, 0, 1) == ",") {
24
+ $exposts = substr($exposts, 1, strlen($exposts));
25
+ }
26
+ if (substr($exposts, -1, 1) == ",") {
27
+ $exposts = substr($exposts, 0, strlen($exposts) - 1);
28
+ }
29
+
30
+ if (!(isset($ageLimit) && is_numeric($ageLimit))) {
31
+ $ageLimit = top_opt_AGE_LIMIT;
32
+ }
33
+
34
+ if (!(isset($maxAgeLimit) && is_numeric($maxAgeLimit))) {
35
+ $maxAgeLimit = top_opt_MAX_AGE_LIMIT;
36
+ }
37
+ if (!isset($omitCats)) {
38
+ $omitCats = top_opt_OMIT_CATS;
39
+ }
40
+
41
+ $sql = "SELECT ID
42
+ FROM $wpdb->posts
43
+ WHERE post_type = 'post'
44
+ AND post_status = 'publish'
45
+ AND post_date <= curdate( ) - INTERVAL " . $ageLimit . " day";
46
+
47
+ if ($maxAgeLimit != 0) {
48
+ $sql = $sql . " AND post_date >= curdate( ) - INTERVAL " . $maxAgeLimit . " day";
49
+ }
50
+ if (isset($exposts)) {
51
+ if(trim($exposts) != '')
52
+ {
53
+ $sql = $sql . " AND ID Not IN (" . $exposts . ") ";
54
+ }
55
+ }
56
+ /*if ($omitCats != '') {
57
+ $sql = $sql . " AND NOT (ID IN (SELECT tr.object_id FROM wp_term_relationships AS tr INNER JOIN wp_term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy = 'category' AND tt.term_id IN (" . $omitCats . ")))";
58
+ }*/
59
+ if ($omitCats != '') {
60
+ $sql = $sql . " AND NOT (ID IN (SELECT tr.object_id FROM ".$wpdb->prefix."term_relationships AS tr INNER JOIN ".$wpdb->prefix."term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy = 'category' AND tt.term_id IN (" . $omitCats . ")))";
61
+ }
62
+ $sql = $sql . "
63
+ ORDER BY RAND()
64
+ LIMIT 1 ";
65
+
66
+ $oldest_post = $wpdb->get_var($sql);
67
+ if ($oldest_post == null) {
68
+ return "No post found to tweet. Please check your settings and try again.";
69
+ }
70
+ if (isset($oldest_post)) {
71
+ return top_opt_tweet_post($oldest_post);
72
+ }
73
+ }
74
+
75
+ //tweet for the passed random post
76
+ function top_opt_tweet_post($oldest_post) {
77
+ $post = get_post($oldest_post);
78
+ $content = null;
79
+ $permalink = get_permalink($oldest_post);
80
+ $add_data = get_option("top_opt_add_data");
81
+ $twitter_hashtags = get_option('top_opt_hashtags');
82
+ $url_shortener = get_option('top_opt_url_shortener');
83
+ $to_short_url = true;
84
+
85
+ $custom_url_option = get_option('top_opt_custom_url_option');
86
+ $to_short_url = get_option('top_opt_use_url_shortner');
87
+
88
+ if ($custom_url_option) {
89
+ $custom_url_field = get_option('top_opt_custom_url_field');
90
+ if (trim($custom_url_field) != "") {
91
+ $permalink = trim(get_post_meta($post->ID, $custom_url_field, true));
92
+ }
93
+ }
94
+
95
+ if ($to_short_url) {
96
+
97
+ if ($url_shortener == "bit.ly") {
98
+ $bitly_key = get_option('top_opt_bitly_key');
99
+ $bitly_user = get_option('top_opt_bitly_user');
100
+ $shorturl = shorten_url($permalink, $url_shortener, $bitly_key, $bitly_user);
101
+ } else {
102
+ $shorturl = shorten_url($permalink, $url_shortener);
103
+ }
104
+ } else {
105
+ $shorturl = $permalink;
106
+ }
107
+ $prefix = get_option('top_opt_tweet_prefix');
108
+
109
+ if ($add_data == "true") {
110
+ $content = stripslashes($post->post_content);
111
+ $content = strip_tags($content);
112
+ $content = preg_replace('/\s\s+/', ' ', $content);
113
+ $content = " - " . $content;
114
+ } else {
115
+ $content = "";
116
+ }
117
+
118
+
119
+ if (!is_numeric($shorturl) && (strncmp($shorturl, "http", strlen("http")) == 0)) {
120
+ if ($prefix) {
121
+ $message = $prefix . ": " . $post->post_title;
122
+ } else {
123
+ $message = $post->post_title;
124
+ }
125
+
126
+ $message = set_tweet_length($message . $content, $shorturl, $twitter_hashtags);
127
+ $status = urlencode(stripslashes(urldecode($message)));
128
+ if ($status) {
129
+ $poststatus = top_update_status($message);
130
+ if ($poststatus == true)
131
+ return "Whoopie!!! Tweet Posted Successfully";
132
+ else
133
+ return "OOPS!!! there seems to be some problem while tweeting. If problem continues please try re-authorizing your acount again.<br/> First Deauthorize and then authorize again and check.";
134
+ }
135
+ return "OOPS!!! there seems to be some problem while tweeting. Try again. If problem is persistent mail the problem at ajay@ajaymatharu.com";
136
+ }
137
+ return "OOPS!!! problem with your URL shortning service. Some signs of error " . $shorturl . ".";
138
+ }
139
+
140
+ //send request to passed url and return the response
141
+ function send_request($url, $method='GET', $data='', $auth_user='', $auth_pass='') {
142
+ $ch = curl_init($url);
143
+ if (strtoupper($method) == "POST") {
144
+ curl_setopt($ch, CURLOPT_POST, 1);
145
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
146
+ }
147
+ if (ini_get('open_basedir') == '' && ini_get('safe_mode') == 'Off') {
148
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
149
+ }
150
+ curl_setopt($ch, CURLOPT_HEADER, 0);
151
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
152
+ if ($auth_user != '' && $auth_pass != '') {
153
+ curl_setopt($ch, CURLOPT_USERPWD, "{$auth_user}:{$auth_pass}");
154
+ }
155
+ $response = curl_exec($ch);
156
+ $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
157
+ curl_close($ch);
158
+ if ($httpcode != 200) {
159
+ return $httpcode;
160
+ }
161
+
162
+ return $response;
163
+ }
164
+
165
+ //Shorten long URLs with is.gd or bit.ly.
166
+ function shorten_url($the_url, $shortener='is.gd', $api_key='', $user='') {
167
+
168
+ if (($shortener == "bit.ly") && isset($api_key) && isset($user)) {
169
+ $url = "http://api.bit.ly/shorten?version=2.0.1&longUrl={$the_url}&login={$user}&apiKey={$api_key}&format=xml";
170
+ $response = send_request($url, 'GET');
171
+
172
+ $the_results = new SimpleXmlElement($response);
173
+ if ($the_results->errorCode == '0') {
174
+ $response = $the_results->results->nodeKeyVal->shortUrl;
175
+ } else {
176
+ $response = "";
177
+ }
178
+ } elseif ($shortener == "su.pr") {
179
+ $url = "http://su.pr/api/simpleshorten?url={$the_url}";
180
+ $response = send_request($url, 'GET');
181
+ } elseif ($shortener == "tr.im") {
182
+ $url = "http://api.tr.im/api/trim_simple?url={$the_url}";
183
+ $response = send_request($url, 'GET');
184
+ } elseif ($shortener == "3.ly") {
185
+ $url = "http://3.ly/?api=em5893833&u={$the_url}";
186
+ $response = send_request($url, 'GET');
187
+ } elseif ($shortener == "tinyurl") {
188
+ $url = "http://tinyurl.com/api-create.php?url={$the_url}";
189
+ $response = send_request($url, 'GET');
190
+ } elseif ($shortener == "u.nu") {
191
+ $url = "http://u.nu/unu-api-simple?url={$the_url}";
192
+ $response = send_request($url, 'GET');
193
+ } elseif ($shortener == "1click.at") {
194
+ $url = "http://1click.at/api.php?action=shorturl&url={$the_url}&format=simple";
195
+ $response = send_request($url, 'GET');
196
+ } else {
197
+ $url = "http://is.gd/api.php?longurl={$the_url}";
198
+ $response = send_request($url, 'GET');
199
+ }
200
+
201
+ return $response;
202
+ }
203
+
204
+ //Shrink a tweet and accompanying URL down to 140 chars.
205
+ function set_tweet_length($message, $url, $twitter_hashtags="") {
206
+
207
+ $message_length = strlen($message);
208
+ $url_length = strlen($url);
209
+ $hashtags_length = strlen($twitter_hashtags);
210
+ if ($message_length + $url_length + $hashtags_length > 140) {
211
+ $shorten_message_to = 140 - $url_length - $hashtags_length;
212
+ $shorten_message_to = $shorten_message_to - 4;
213
+ //$message = $message." ";
214
+ $message = substr($message, 0, $shorten_message_to);
215
+ $message = substr($message, 0, strrpos($message, ' '));
216
+ $message = $message . "...";
217
+ }
218
+ return $message . " " . $url . " " . $twitter_hashtags;
219
+ }
220
+
221
+ //check time and update the last tweet time
222
+ function top_opt_update_time() {
223
+ $last = get_option('top_opt_last_update');
224
+ $interval = get_option('top_opt_interval');
225
+ $slop = get_option('top_opt_interval_slop');
226
+
227
+ if (!(isset($interval) && is_numeric($interval))) {
228
+ $interval = top_opt_INTERVAL;
229
+ }
230
+
231
+ if (!(isset($slop) && is_numeric($slop))) {
232
+ $slop = top_opt_INTERVAL_SLOP;
233
+ }
234
+ $interval = $interval * 60 * 60;
235
+ $slop = $slop * 60 * 60;
236
+ if (false === $last) {
237
+ $ret = 1;
238
+ } else if (is_numeric($last)) {
239
+ $ret = ( (time() - $last) > ($interval + rand(0, $slop)));
240
+ }
241
+ return $ret;
242
+ }
243
+
244
+ function top_get_auth_url() {
245
+ global $top_oauth;
246
+ $settings = top_get_settings();
247
+
248
+ $token = $top_oauth->get_request_token();
249
+ if ($token) {
250
+ $settings['oauth_request_token'] = $token['oauth_token'];
251
+ $settings['oauth_request_token_secret'] = $token['oauth_token_secret'];
252
+
253
+ top_save_settings($settings);
254
+
255
+ return $top_oauth->get_auth_url($token['oauth_token']);
256
+ }
257
+ }
258
+
259
+ function top_update_status($new_status) {
260
+ global $top_oauth;
261
+ $settings = top_get_settings();
262
+
263
+ if (isset($settings['oauth_access_token']) && isset($settings['oauth_access_token_secret'])) {
264
+ return $top_oauth->update_status($settings['oauth_access_token'], $settings['oauth_access_token_secret'], $new_status);
265
+ }
266
+
267
+ return false;
268
+ }
269
+
270
+ function top_has_tokens() {
271
+ $settings = top_get_settings();
272
+
273
+ return ( $settings['oauth_access_token'] && $settings['oauth_access_token_secret'] );
274
+ }
275
+
276
+ function top_is_valid() {
277
+ return twit_has_tokens();
278
+ }
279
+
280
+ function top_do_tweet($post_id) {
281
+ $settings = top_get_settings();
282
+
283
+ $message = top_get_message($post_id);
284
+
285
+ // If we have a valid message, Tweet it
286
+ // this will fail if the Tiny URL service is done
287
+ if ($message) {
288
+ // If we successfully posted this to Twitter, then we can remove it from the queue eventually
289
+ if (twit_update_status($message)) {
290
+ return true;
291
+ }
292
+ }
293
+
294
+ return false;
295
+ }
296
+
297
+ function top_get_settings() {
298
+ global $top_defaults;
299
+
300
+ $settings = $top_defaults;
301
+
302
+ $wordpress_settings = get_option('top_settings');
303
+ if ($wordpress_settings) {
304
+ foreach ($wordpress_settings as $key => $value) {
305
+ $settings[$key] = $value;
306
+ }
307
+ }
308
+
309
+ return $settings;
310
+ }
311
+
312
+ function top_save_settings($settings) {
313
+ update_option('top_settings', $settings);
314
+ }
315
+
316
+ ?>
top-excludepost.php ADDED
@@ -0,0 +1,326 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once('tweet-old-post.php');
4
+ require_once('top-core.php');
5
+ require_once( 'Include/oauth.php' );
6
+ require_once('xml.php');
7
+
8
+ function top_exclude() {
9
+
10
+ $message = null;
11
+ $message_updated = __("Tweet Old Post Options Updated.", 'TweetOldPost');
12
+ $response = null;
13
+ $records_per_page = 20;
14
+ $omit_cat=get_option('top_opt_omit_cats');
15
+ $update_text = "Exclude Selected";
16
+ $search_term="";
17
+ $ex_filter="all";
18
+ $cat_filter=0;
19
+
20
+ global $wpdb;
21
+
22
+ if ((!isset($_GET["paged"])) && (!isset($_POST["delids"]))) {
23
+ $exposts = get_option('top_opt_excluded_post');
24
+ } else {
25
+ $exposts = $_POST["delids"];
26
+ }
27
+
28
+ $exposts = preg_replace('/,,+/', ',', $exposts);
29
+ if (substr($exposts, 0, 1) == ",") {
30
+ $exposts = substr($exposts, 1, strlen($exposts));
31
+ }
32
+ if (substr($exposts, -1, 1) == ",") {
33
+ $exposts = substr($exposts, 0, strlen($exposts) - 1);
34
+ }
35
+ $excluded_posts = explode(",", $exposts);
36
+
37
+
38
+ if (!isset($_GET['paged']))
39
+ $_GET['paged'] = 1;
40
+
41
+ if (isset($_POST["excludeall"])) {
42
+ if (substr($_POST["delids"], 0, -1) == "") {
43
+ print('
44
+ <div id="message" style="margin-top:30px" class="updated fade">
45
+ <p>' . __('No post selected please select a post to be excluded.', 'TweetOldPost') . '</p>
46
+ </div>');
47
+ } else {
48
+
49
+ update_option('top_opt_excluded_post',$exposts);
50
+ print('
51
+ <div id="message" style="margin-top:30px" class="updated fade">
52
+ <p>' . __('Posts excluded successfully.', 'TweetOldPost') . '</p>
53
+ </div>');
54
+ }
55
+ }
56
+
57
+ print('
58
+ <div id="help" style="overflow: hidden;padding-left:15px; font-size: 14px; margin-top: 25px; background-color: rgb(239, 239, 239);">
59
+ <p>' . __('This page shows all the post from your <a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=TweetOldPost">selected categories</a>.<br /> All the post excluded will not be tweeted even if the category is selected.', 'TweetOldPost') . '</p>
60
+ </div>');
61
+
62
+ print('
63
+ <div id="help" style="overflow: hidden;padding-left:15px; font-size: 14px; margin-top: 25px;margin-bottom:25px; background-color: rgb(239, 239, 239);">
64
+ <p>' . __('You have selected following POST IDs to be excluded from tweeting: <span id="excludeList" style="font-weight:bold;font-style:italic;"></span>.<br /> <strong>Note:</strong> If you have made any change and dint hit "Exclude Selected" button changes will not be saved. Please hit "Exclude Selected" button after making any changes.', 'TweetOldPost') . '</p>
65
+ </div>');
66
+
67
+ $sql = "SELECT p.ID,p.post_title,p.post_date,u.user_nicename,p.guid FROM $wpdb->posts p join $wpdb->users u on p.post_author=u.ID WHERE post_type = 'post'
68
+ AND post_status = 'publish'";
69
+
70
+ //$sql = $sql . " and p.ID NOT IN ( SELECT tr.object_id FROM wp_term_relationships AS tr INNER JOIN wp_term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy = 'category' AND tt.term_id IN (" . $omit_cat . "))";
71
+ if(isset($_POST["setFilter"]))
72
+ {
73
+ if($_POST["cat"] != 0)
74
+ {
75
+ $sql = $sql . " and p.ID IN ( SELECT tr.object_id FROM wp_term_relationships AS tr INNER JOIN wp_term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy = 'category' AND tt.term_id=" . $_POST["cat"] . ")";
76
+ $cat_filter = $_POST["cat"];
77
+ }
78
+ else
79
+ {
80
+ $sql = $sql . " and p.ID NOT IN ( SELECT tr.object_id FROM wp_term_relationships AS tr INNER JOIN wp_term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy = 'category' AND tt.term_id IN (" . $omit_cat . "))";
81
+ $cat_filter = 0;
82
+ }
83
+
84
+ if($_POST["selFilter"] == "excluded")
85
+ {
86
+ $sql = $sql . " and p.ID IN (".$exposts.")";
87
+ $update_text = "Update";
88
+ $ex_filter = "excluded";
89
+ }
90
+
91
+ }
92
+ else
93
+ {
94
+ $sql = $sql . " and p.ID NOT IN ( SELECT tr.object_id FROM wp_term_relationships AS tr INNER JOIN wp_term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy = 'category' AND tt.term_id IN (" . $omit_cat . "))";
95
+ }
96
+
97
+ if(isset($_POST["s"]))
98
+ {
99
+ if(trim( $_POST["s"]) != "")
100
+ {
101
+ $sql = $sql . " and post_title like '%" . trim( $_POST["s"]) . "%'";
102
+ $search_term = trim( $_POST["s"]);
103
+ }
104
+ }
105
+
106
+ $sql = $sql . " order by post_date desc";
107
+ $posts = $wpdb->get_results($sql);
108
+
109
+ $from = $_GET["paged"] * $records_per_page - $records_per_page;
110
+ $to = min($_GET['paged'] * $records_per_page, count($posts));
111
+ $post_count =count($posts);
112
+
113
+ $ex = 0;
114
+ for ($j = 0; $j < $post_count; $j++) {
115
+ if (in_array($posts[$j]->ID, $excluded_posts)) {
116
+ $excludeList[$ex] = $posts[$j]->ID;
117
+ $ex = $ex + 1;
118
+ }
119
+ }
120
+ if($excludeList.length >0)
121
+ {
122
+ $exposts = implode(",",$excludeList);
123
+ }
124
+ print('<form id="top_TweetOldPost" name="top_TweetOldPost" action="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=ExcludePosts" method="post"><input type="hidden" name="delids" id="delids" value="' . $exposts . '" /><input type="submit" id="pageit" name="pageit" style="display:none" value="" /> ');
125
+ print('<div class="tablenav"><div class="alignleft actions">');
126
+ print('<input type="submit" class="button-secondary" name="excludeall" value="' . __($update_text, 'TweetOldPost') . '" />');
127
+ print('<select name="selFilter" id="selFilter" style="width:100px"><option value="all" '.top_opt_optionselected("all",$ex_filter).'> All </option><option value="excluded" '.top_opt_optionselected("excluded",$ex_filter).'> Excluded </option></select>');
128
+ $dropdown_options = array('show_option_all' => __('Selected Categories'),'exclude' =>$omit_cat,'selected' =>$cat_filter);
129
+ wp_dropdown_categories($dropdown_options);
130
+ print('<input type="submit" class="button-secondary" name="setFilter" value="' . __('Filter', 'TweetOldPost') . '" />');
131
+ print('<p class="search-box" style="margin:0px">
132
+ <input type="text" id="post-search-input" name="s" value="'.$search_term.'" />
133
+ <input type="submit" value="Search Posts" name="search" class="button" />
134
+ </p>');
135
+ print('</div>');
136
+ if (count($posts) > 0) {
137
+ $page_links = paginate_links(array(
138
+ 'base' => add_query_arg('paged', '%#%'),
139
+ 'format' => '',
140
+ 'prev_text' => __('&laquo;'),
141
+ 'next_text' => __('&raquo;'),
142
+ 'total' => ceil(count($posts) / $records_per_page),
143
+ 'current' => $_GET['paged']
144
+ ));
145
+
146
+ if ($page_links) {
147
+
148
+ print('<div class="tablenav-pages">');
149
+ $page_links_text = sprintf('<span class="displaying-num">' . __('Displaying %s&#8211;%s of %s') . '</span>%s',
150
+ number_format_i18n(( $_GET['paged'] - 1 ) * $records_per_page + 1),
151
+ number_format_i18n(min($_GET['paged'] * $records_per_page, count($posts))),
152
+ number_format_i18n(count($posts)),
153
+ $page_links
154
+ );
155
+ echo $page_links_text;
156
+ print('</div>');
157
+ }
158
+ print('</div>');//tablenav div
159
+
160
+ print(' <div class="wrap">
161
+ <table class="widefat fixed">
162
+ <thead>
163
+ <tr>
164
+ <th class="manage-column column-cb check-column"><input name="headchkbx" onchange="javascript:checkedAll();" type="checkbox" value="checkall"/></th>
165
+ <th>No.</th>
166
+ <th>Id</th>
167
+ <th>Post Title</th>
168
+ <th>Author</th>
169
+ <th>Post Date</th>
170
+ <th>Categories</th>
171
+ </tr>
172
+ </thead>
173
+ <tbody>
174
+ ');
175
+
176
+
177
+
178
+
179
+ for ($i = $from; $i < $to; $i++) {
180
+ $categories = get_the_category($posts[$i]->ID);
181
+ if (!empty($categories)) {
182
+ $out = array();
183
+ foreach ($categories as $c)
184
+ $out[] = "<a href='edit.php?post_type={$post->post_type}&amp;category_name={$c->slug}'> " . esc_html(sanitize_term_field('name', $c->name, $c->term_id, 'category', 'display')) . "</a>";
185
+ $cats = join(', ', $out);
186
+ } else {
187
+ $cats = 'Uncategorized';
188
+ }
189
+
190
+ if (in_array($posts[$i]->ID, $excluded_posts)) {
191
+ $checked = "Checked";
192
+ $bgcolor="#FFCC99";
193
+ } else {
194
+ $checked = "";
195
+ $bgcolor="#FFF";
196
+ }
197
+
198
+ print('
199
+
200
+ <tr style="background-color:'.$bgcolor.';">
201
+ <th class="check-column">
202
+ <input type="checkbox" name="chkbx" id="del' . $posts[$i]->ID . '" onchange="javascript:managedelid(this,\'' . $posts[$i]->ID . '\');" value="' . $posts[$i]->ID . '" ' . $checked . '/>
203
+ </th>
204
+ <td>
205
+ ' . ($i + 1) . '
206
+ </td>
207
+ <td>
208
+ ' . $posts[$i]->ID . '
209
+ </td>
210
+ <td>
211
+ <a href=' . $posts[$i]->guid . ' target="_blank">' . $posts[$i]->post_title . '</a>
212
+ </td>
213
+ <td>
214
+ ' . $posts[$i]->user_nicename . '
215
+ </td>
216
+ <td>
217
+ ' . $posts[$i]->post_date . '
218
+ </td>
219
+ <td>
220
+ ' . $cats . '
221
+ </td>
222
+ </tr>
223
+
224
+ ');
225
+ }
226
+ print('
227
+ </tbody>
228
+ </table>
229
+ </div>
230
+ ');
231
+
232
+ print('<div class="tablenav"><div class="alignleft actions"><input type="submit" class="button-secondary" name="excludeall" value="' . __($update_text, 'TweetOldPost') . '" /></div>');
233
+
234
+ if ($page_links) {
235
+
236
+ print('<div class="tablenav-pages">');
237
+ $page_links_text = sprintf('<span class="displaying-num">' . __('Displaying %s&#8211;%s of %s') . '</span>%s',
238
+ number_format_i18n(( $_GET['paged'] - 1 ) * $records_per_page + 1),
239
+ number_format_i18n(min($_GET['paged'] * $records_per_page, count($posts))),
240
+ number_format_i18n(count($posts)),
241
+ $page_links
242
+ );
243
+ echo $page_links_text;
244
+ print('</div>');
245
+ }
246
+ print('</div>');
247
+
248
+
249
+
250
+ print('
251
+ <script language="javascript">
252
+
253
+
254
+ jQuery(function() {
255
+ jQuery(".page-numbers").click(function(e){
256
+ jQuery("#top_TweetOldPost").attr("action",jQuery(this).attr("href"));
257
+ e.preventDefault();
258
+ jQuery("#pageit").click();
259
+ });// page number click end
260
+ });//jquery document.ready end
261
+
262
+ function setExcludeList(exlist)
263
+ {
264
+ jQuery("#excludeList").html("\"" + exlist + "\"");
265
+ }
266
+
267
+
268
+ function managedelid(ctrl,id)
269
+ {
270
+
271
+ var delids = document.getElementById("delids").value;
272
+ if(ctrl.checked)
273
+ {
274
+ delids=addId(delids,id);
275
+ }
276
+ else
277
+ {
278
+ delids=removeId(delids,id);
279
+ }
280
+ document.getElementById("delids").value=delids;
281
+ setExcludeList(delids);
282
+ }
283
+
284
+ function removeId(list, value) {
285
+ list = list.split(",");
286
+ if(list.indexOf(value) != -1)
287
+ list.splice(list.indexOf(value), 1);
288
+ return list.join(",");
289
+ }
290
+
291
+
292
+ function addId(list,value)
293
+ {
294
+ list = list.split(",");
295
+ if(list.indexOf(value) == -1)
296
+ list.push(value);
297
+ return list.join(",");
298
+ }
299
+
300
+ function checkedAll() {
301
+ var ischecked=document.top_TweetOldPost.headchkbx.checked;
302
+ var delids="";
303
+ for (var i = 0; i < document.top_TweetOldPost.chkbx.length; i++) {
304
+ document.top_TweetOldPost.chkbx[i].checked = ischecked;
305
+ if(ischecked)
306
+ delids=delids+document.top_TweetOldPost.chkbx[i].value+",";
307
+ }
308
+ document.getElementById("delids").value=delids;
309
+ }
310
+
311
+ setExcludeList("' . $exposts . '");
312
+
313
+ </script>
314
+ ');
315
+ }
316
+ else
317
+ {
318
+ print('</div>');//tablenav div
319
+ print('
320
+ <div id="message" style="margin-top:30px" class="updated fade">
321
+ <p>' . __('No Posts found. Review your search or filter criteria/term.', 'TweetOldPost') . '</p>
322
+ </div>');
323
+ }
324
+ print('</form>');
325
+ }
326
+ ?>
tweet-old-post.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: 3.1.2
8
+ # Author URI: http://www.ajaymatharu.com
9
+ # */
10
+
11
+
12
+ require_once('top-admin.php');
13
+ require_once('top-core.php');
14
+ require_once ('top-excludepost.php');
15
+ define ('top_opt_1_HOUR', 60*60);
16
+ define ('top_opt_2_HOURS', 2*top_opt_1_HOUR);
17
+ define ('top_opt_4_HOURS', 4*top_opt_1_HOUR);
18
+ define ('top_opt_8_HOURS', 8*top_opt_1_HOUR);
19
+ define ('top_opt_6_HOURS', 6*top_opt_1_HOUR);
20
+ define ('top_opt_12_HOURS', 12*top_opt_1_HOUR);
21
+ define ('top_opt_24_HOURS', 24*top_opt_1_HOUR);
22
+ define ('top_opt_48_HOURS', 48*top_opt_1_HOUR);
23
+ define ('top_opt_72_HOURS', 72*top_opt_1_HOUR);
24
+ define ('top_opt_168_HOURS', 168*top_opt_1_HOUR);
25
+ define ('top_opt_INTERVAL', 4);
26
+ define ('top_opt_INTERVAL_SLOP', 4);
27
+ define ('top_opt_AGE_LIMIT', 30); // 120 days
28
+ define ('top_opt_MAX_AGE_LIMIT', 0); // 120 days
29
+ define ('top_opt_OMIT_CATS', "");
30
+ define('top_opt_TWEET_PREFIX',"");
31
+ define('top_opt_ADD_DATA',"false");
32
+ define('top_opt_URL_SHORTENER',"is.gd");
33
+ define('top_opt_HASHTAGS',"");
34
+
35
+ function top_admin_actions() {
36
+ add_menu_page("Tweet Old Post", "Tweet Old Post", 1, "TweetOldPost", "top_admin");
37
+ add_submenu_page("TweetOldPost", __('Exclude Posts','TweetOldPost'), __('Exclude Posts','TweetOldPost'), 1, __('ExcludePosts','TweetOldPost'), 'top_exclude');
38
+ }
39
+
40
+ add_action('admin_menu', 'top_admin_actions');
41
+ add_action('admin_head', 'top_opt_head_admin');
42
+ add_action('init','top_tweet_old_post');
43
+ register_activation_hook(__FILE__, "top_on_activation");
44
+
45
+ function top_on_activation()
46
+ {
47
+ update_option('top_opt_interval', "4");
48
+ update_option('top_opt_interval_slop', "4");
49
+ update_option('top_opt_age_limit', "30");
50
+ update_option('top_opt_max_age_limit', "0");
51
+ }
52
+ ?>
xml.php ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ function TOP_parsexml( $xml, $get_attributes = 1, $priority = 'tag' )
4
+ {
5
+ $parser = xml_parser_create('');
6
+ xml_parser_set_option( $parser, XML_OPTION_TARGET_ENCODING, "UTF-8" );
7
+ xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, 0 );
8
+ xml_parser_set_option( $parser, XML_OPTION_SKIP_WHITE, 1 );
9
+ xml_parse_into_struct( $parser, trim($xml), $xml_values );
10
+ xml_parser_free($parser);
11
+
12
+ if (!$xml_values)
13
+ return;
14
+
15
+ $xml_array = array ();
16
+ $parents = array ();
17
+ $opened_tags = array ();
18
+ $arr = array ();
19
+ $current = & $xml_array;
20
+ $repeated_tag_index = array ();
21
+
22
+ foreach ($xml_values as $data) {
23
+ unset ($attributes, $value);
24
+ extract($data);
25
+ $result = array ();
26
+ $attributes_data = array ();
27
+ if (isset ($value))
28
+ {
29
+ if ($priority == 'tag')
30
+ $result = $value;
31
+ else
32
+ $result['value'] = $value;
33
+ }
34
+ if (isset ($attributes) and $get_attributes)
35
+ {
36
+ foreach ($attributes as $attr => $val)
37
+ {
38
+ if ($priority == 'tag')
39
+ $attributes_data[$attr] = $val;
40
+ else
41
+ $result['attr'][$attr] = $val; //Set all the attributes in a array called 'attr'
42
+ }
43
+ }
44
+ if ($type == "open")
45
+ {
46
+ $parent[$level -1] = & $current;
47
+ if (!is_array($current) or (!in_array($tag, array_keys($current))))
48
+ {
49
+ $current[$tag] = $result;
50
+ if ($attributes_data)
51
+ $current[$tag . '_attr'] = $attributes_data;
52
+ $repeated_tag_index[$tag . '_' . $level] = 1;
53
+ $current = & $current[$tag];
54
+ }
55
+ else
56
+ {
57
+ if (isset ($current[$tag][0]))
58
+ {
59
+ $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result;
60
+ $repeated_tag_index[$tag . '_' . $level]++;
61
+ }
62
+ else
63
+ {
64
+ $current[$tag] = array (
65
+ $current[$tag],
66
+ $result
67
+ );
68
+ $repeated_tag_index[$tag . '_' . $level] = 2;
69
+ if (isset ($current[$tag . '_attr']))
70
+ {
71
+ $current[$tag]['0_attr'] = $current[$tag . '_attr'];
72
+ unset ($current[$tag . '_attr']);
73
+ }
74
+ }
75
+ $last_item_index = $repeated_tag_index[$tag . '_' . $level] - 1;
76
+ $current = & $current[$tag][$last_item_index];
77
+ }
78
+ }
79
+ elseif ($type == "complete")
80
+ {
81
+ if (!isset ($current[$tag]))
82
+ {
83
+ $current[$tag] = $result;
84
+ $repeated_tag_index[$tag . '_' . $level] = 1;
85
+ if ($priority == 'tag' and $attributes_data)
86
+ $current[$tag . '_attr'] = $attributes_data;
87
+ }
88
+ else
89
+ {
90
+ if (isset ($current[$tag][0]) and is_array($current[$tag]))
91
+ {
92
+ $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result;
93
+ if ($priority == 'tag' and $get_attributes and $attributes_data)
94
+ {
95
+ $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data;
96
+ }
97
+ $repeated_tag_index[$tag . '_' . $level]++;
98
+ }
99
+ else
100
+ {
101
+ $current[$tag] = array (
102
+ $current[$tag],
103
+ $result
104
+ );
105
+ $repeated_tag_index[$tag . '_' . $level] = 1;
106
+ if ($priority == 'tag' and $get_attributes)
107
+ {
108
+ if (isset ($current[$tag . '_attr']))
109
+ {
110
+ $current[$tag]['0_attr'] = $current[$tag . '_attr'];
111
+ unset ($current[$tag . '_attr']);
112
+ }
113
+ if ($attributes_data)
114
+ {
115
+ $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data;
116
+ }
117
+ }
118
+ $repeated_tag_index[$tag . '_' . $level]++; //0 and 1 index is already taken
119
+ }
120
+ }
121
+ }
122
+ elseif ($type == 'close')
123
+ {
124
+ $current = & $parent[$level -1];
125
+ }
126
+ }
127
+ return $xml_array;
128
+ }
129
+
130
+ ?>