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

Version Description

Download this release

Release Info

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

Version 3.2.2

Files changed (9) hide show
  1. Include/oauth.php +242 -0
  2. css/tweet-old-post.css +76 -0
  3. images/twitter.png +0 -0
  4. readme.txt +440 -0
  5. top-admin.php +750 -0
  6. top-core.php +426 -0
  7. top-excludepost.php +328 -0
  8. tweet-old-post.php +81 -0
  9. 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
+ }
images/twitter.png ADDED
Binary file
readme.txt ADDED
@@ -0,0 +1,440 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.2.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
+ For updates follow http://twitter.com/matharuajay
17
+
18
+ New
19
+
20
+ **New in v3.2.2**
21
+
22
+ - Resolved bit.ly issue
23
+ - new option for hashtags
24
+ - other bug fixes
25
+
26
+
27
+ **New in v3.2.1**
28
+
29
+ - Bug fixes
30
+
31
+
32
+ **New in v3.2**
33
+
34
+ - Bug fixes
35
+ - Option to choose to include link in post
36
+ - option to post only title or body or both title and body
37
+ - option to set additional text either at beginning or end of tweet
38
+ - option to pick hashtags from custom field
39
+
40
+
41
+ **New in v3.1.2**
42
+
43
+ - Resolved tweets not getting posted when categories are excluded.
44
+ - If you are not able to authorise your twitter account set you blog URL in Administration → Settings → General.
45
+
46
+
47
+
48
+ **New in v3.1.1**
49
+
50
+ - Resolved tweets not getting posted issue. Sorry guys :(
51
+
52
+
53
+
54
+ **New in v3.1**
55
+
56
+ - Resolved issue of plugin flooding twitter account with tweets.
57
+ - added provision to exclude some post from selected categories
58
+
59
+
60
+
61
+ **New in v3.0**
62
+
63
+ - added OAuth authentication
64
+ - user defined intervals
65
+ - may not work under php 4 requires php 5
66
+
67
+
68
+
69
+ **New in v2.0**
70
+
71
+ - added provision to select if you want to shorten the URL or not.
72
+ - Cleaned other options.
73
+
74
+
75
+
76
+ **New in v1.9**
77
+
78
+ - Removed PHP 4 support as it was creating problem for lot of people
79
+
80
+
81
+
82
+ **New in v1.8**
83
+
84
+ - Bug Fixes
85
+ - Provision to fetch tweet url from custom field
86
+
87
+
88
+
89
+ **New in v1.7**
90
+
91
+ - Removed api option from 1click.at not needed api key
92
+
93
+
94
+
95
+ **New in v1.6**
96
+
97
+ - Made the plugin PHP 4 compatible. Guys try it out and please let me know if that worked.
98
+ - 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.
99
+ - 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.
100
+
101
+
102
+
103
+ **New in v1.5**
104
+
105
+ - Maximum age of post to be eligible for tweet - allows you to set Maximum age of the post to be eligible for tweet
106
+ - Added one more shortner service was looking for j.mp but they dont have the api yet.
107
+
108
+
109
+
110
+ **New in v1.4**
111
+
112
+ - Hashtags - allows you to set default hashtags for your tweets
113
+
114
+
115
+
116
+ **New in v1.3**
117
+
118
+ - URL Shortener Service - allows you to select which URL shortener service you want to use.
119
+
120
+
121
+
122
+ **New in v1.2**
123
+
124
+ - Tweet Prefix - Allows you to set prefix to the tweets.
125
+ - Add Data - Allows you to add post data to the tweets
126
+ - Tweet now - Button that will tweet at that moment without wanting you to wait for scheduled tweet
127
+
128
+
129
+
130
+ **v1.1**
131
+
132
+ - Twitter Username & Password - Using this twitter account credentials plugin will tweet.
133
+ - Minimum interval between tweets - allows you to determine how often the plugin will automatically choose and tweet a blog post for you.
134
+ - Randomness interval - This is a contributing factor in minimum interval so that posts are randomly chosen and tweeted from your blog.
135
+ - 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.
136
+ - Categories to omit from tweets - This will protect posts from the selected categories from being tweeted.
137
+
138
+ == Installation ==
139
+
140
+ Following are the steps to install the Tweet Old Post plugin
141
+
142
+ 1. Download the latest version of the Tweet Old Posts Plugin to your computer from here.
143
+ 2. With an FTP program, access your site�s server.
144
+ 3. Upload (copy) the Plugin file(s) or folder to the /wp-content/plugins folder.
145
+ 4. In your WordPress Administration Panels, click on Plugins from the menu.
146
+ 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.
147
+ 6. To turn the Tweet Old Posts Plugin on, click Activate.
148
+ 7. Check your Administration Panels or WordPress blog to see if the Plugin is working.
149
+ 8. You can change the plugin options from Tweet Old Posts under settings menu.
150
+
151
+ Alternatively you can also follow the following steps to install the Tweet Old Post plugin
152
+
153
+ 1. In your WordPress Administration Panels, click on Add New option under Plugins from the menu.
154
+ 2. Click on upload at the top.
155
+ 3. Browse the location and select the Tweet Old Post Plugin and click install now.
156
+ 4. To turn the Tweet Old Posts Plugin on, click Activate.
157
+ 5. Check your Administration Panels or WordPress blog to see if the Plugin is working.
158
+ 6. You can change the plugin options from Tweet Old Posts under settings menu.
159
+
160
+ == Frequently Asked Questions ==
161
+
162
+ If you have any questions please mail me at,
163
+ ajay@ajaymatharu.com or matharuajay@yahoo.co.in
164
+
165
+ **Tweet Old post does not posts any tweets?**
166
+
167
+ - If its not tweeting any tweets try playing around with the options. Try setting maxtweetage to none and try again.
168
+ - 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.
169
+
170
+
171
+ **Tweet old post giving SimpleXmlElement error?**
172
+
173
+ - If it is giving SimpleXmlElement error, check with your hosting provider on which version of PHP are they supporting.
174
+ Tweet Old Post supports PHP 5 onwards. It will give SimpleXmlElement error if your hosting provider supports PHP 4
175
+ or PHP less than 5
176
+
177
+
178
+ **Tweets not getting posted?**
179
+
180
+ - If your tweets are not getting posted, try deauthorizing and again authorizing your twitter account with
181
+ plugin.
182
+
183
+
184
+ **Plugin flooded your tweeter account with tweets?**
185
+
186
+ - please check your setting increase the minimum interval between tweets. If your plugin is not updated please update your plugin to latest version.
187
+
188
+
189
+ **Not able to authorize your twitter account with Tweet Old Post**
190
+
191
+ - If you are not able to authorise your twitter account set you blog URL in Administration → Settings → General.
192
+
193
+ **Any more questions or doubts?**
194
+
195
+ - DM me on http://twitter.com/matharuajay or mail me at ajay(at)ajaymatharu(dot)com
196
+
197
+
198
+ == Screenshots ==
199
+
200
+ for screenshots you can check out
201
+
202
+ http://www.ajaymatharu.com/wordpress-plugin-tweet-old-posts/
203
+
204
+ == Changelog ==
205
+
206
+ **New in v3.2.2**
207
+
208
+ - Resolved bit.ly issue
209
+ - new option for hashtags
210
+ - other bug fixes
211
+
212
+
213
+
214
+ **New in v3.2.1**
215
+
216
+ - Bug fixes
217
+
218
+
219
+
220
+ **New in v3.2**
221
+
222
+ - Bug fixes
223
+ - Option to choose to include link in post
224
+ - option to post only title or body or both title and body
225
+ - option to set additional text either at beginning or end of tweet
226
+ - option to pick hashtags from custom field
227
+
228
+
229
+
230
+ **New in v3.1.2**
231
+
232
+ - Resolved tweets not getting posted when categories are excluded.
233
+ - If you are not able to authorise your twitter account set you blog URL in Administration → Settings → General.
234
+
235
+
236
+
237
+ **New in v3.1**
238
+
239
+ - Resolved issue of plugin flooding twitter account with tweets.
240
+ - added provision to exclude some post from selected categories
241
+
242
+
243
+
244
+ **New in v3.0**
245
+
246
+ - added OAuth authentication
247
+ - user defined intervals
248
+ - may not work under php 4 requires php 5
249
+
250
+
251
+
252
+ **New in v2.0**
253
+
254
+ - added provision to select if you want to shorten the URL or not.
255
+ - Cleaned other options.
256
+
257
+
258
+
259
+ **New in v1.9**
260
+
261
+ - Removed PHP 4 support as it was creating problem for lot of people
262
+
263
+
264
+
265
+ **New in v1.8**
266
+
267
+ - Bug Fixes
268
+ - Provision to fetch tweet url from custom field
269
+
270
+
271
+
272
+ **New in v1.7**
273
+
274
+ - Removed api option from 1click.at not needed api key
275
+
276
+
277
+
278
+ **New in v1.6**
279
+
280
+ - Made the plugin PHP 4 compatible. Guys try it out and please let me know if that worked.
281
+ - 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.
282
+ - 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.
283
+
284
+
285
+
286
+ **New in v1.5**
287
+
288
+ - Maximum age of post to be eligible for tweet - allows you to set Maximum age of the post to be eligible for tweet
289
+ - Added one more shortner service was looking for j.mp but they dont have the api yet.
290
+
291
+
292
+
293
+ **New in v1.4**
294
+
295
+ - Hashtags - allows you to set default hashtags for your tweets
296
+
297
+
298
+
299
+ **New in v1.3**
300
+
301
+ - URL Shortener Service - allows you to select which URL shortener service you want to use.
302
+
303
+
304
+
305
+ **New in v1.2**
306
+
307
+ - Tweet Prefix - Allows you to set prefix to the tweets.
308
+ - Add Data - Allows you to add post data to the tweets
309
+ - Tweet now - Button that will tweet at that moment without wanting you to wait for scheduled tweet
310
+
311
+
312
+
313
+ **v1.1**
314
+
315
+ - Twitter Username & Password - Using this twitter account credentials plugin will tweet.
316
+ - Minimum interval between tweets - allows you to determine how often the plugin will automatically choose and tweet a blog post for you.
317
+ - Randomness interval - This is a contributing factor in minimum interval so that posts are randomly chosen and tweeted from your blog.
318
+ - 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.
319
+ - Categories to omit from tweets - This will protect posts from the selected categories from being tweeted.
320
+
321
+
322
+ == Other Notes ==
323
+
324
+ Some of the options you can configure for the Tweet Old Posts plugins are,
325
+
326
+ **New in v3.2.2**
327
+
328
+ - Resolved bit.ly issue
329
+ - new option for hashtags
330
+ - other bug fixes
331
+
332
+
333
+
334
+ **New in v3.2.1**
335
+
336
+ - Bug fixes
337
+
338
+
339
+
340
+ **New in v3.2**
341
+
342
+ - Bug fixes
343
+ - Option to choose to include link in post
344
+ - option to post only title or body or both title and body
345
+ - option to set additional text either at beginning or end of tweet
346
+ - option to pick hashtags from custom field
347
+
348
+
349
+
350
+ **New in v3.1.2**
351
+
352
+ - Resolved tweets not getting posted when categories are excluded.
353
+ - If you are not able to authorise your twitter account set you blog URL in Administration → Settings → General.
354
+
355
+
356
+
357
+ **New in v3.1**
358
+
359
+ - Resolved issue of plugin flooding twitter account with tweets.
360
+ - added provision to exclude some post from selected categories
361
+
362
+
363
+
364
+ **New in v3.0**
365
+
366
+ - added OAuth authentication
367
+ - user defined intervals
368
+ - may not work under php 4 requires php 5
369
+
370
+
371
+
372
+ **New in v2.0**
373
+
374
+ - added provision to select if you want to shorten the URL or not.
375
+ - Cleaned other options.
376
+
377
+
378
+
379
+ **New in v1.9**
380
+
381
+ - Removed PHP 4 support as it was creating problem for lot of people
382
+
383
+
384
+
385
+ **New in v1.8**
386
+
387
+ - Bug Fixes
388
+ - Provision to fetch tweet url from custom field
389
+
390
+
391
+
392
+ **New in v1.7**
393
+
394
+ - Removed api option from 1click.at not needed api key
395
+
396
+
397
+
398
+ **New in v1.6**
399
+
400
+ - Made the plugin PHP 4 compatible. Guys try it out and please let me know if that worked.
401
+ - 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.
402
+ - 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.
403
+
404
+
405
+
406
+ **New in v1.5**
407
+
408
+ - Maximum age of post to be eligible for tweet - allows you to set Maximum age of the post to be eligible for tweet
409
+ - Added one more shortner service was looking for j.mp but they dont have the api yet.
410
+
411
+
412
+
413
+ **New in v1.4**
414
+
415
+ - Hashtags - allows you to set default hashtags for your tweets
416
+
417
+
418
+
419
+ **New in v1.3**
420
+
421
+ - URL Shortener Service - allows you to select which URL shortener service you want to use.
422
+
423
+
424
+
425
+ **New in v1.2**
426
+
427
+ - Tweet Prefix - Allows you to set prefix to the tweets.
428
+ - Add Data - Allows you to add post data to the tweets
429
+ - Tweet now - Button that will tweet at that moment without wanting you to wait for scheduled tweet
430
+
431
+
432
+
433
+ **v1.1**
434
+
435
+ - Twitter Username & Password - Using this twitter account credentials plugin will tweet.
436
+ - Minimum interval between tweets - allows you to determine how often the plugin will automatically choose and tweet a blog post for you.
437
+ - Randomness interval - This is a contributing factor in minimum interval so that posts are randomly chosen and tweeted from your blog.
438
+ - 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.
439
+ - Categories to omit from tweets - This will protect posts from the selected categories from being tweeted.
440
+
top-admin.php ADDED
@@ -0,0 +1,750 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ //check permission
10
+ if (current_user_can('manage_options')) {
11
+ $message = null;
12
+ $message_updated = __("Tweet Old Post Options Updated.", 'TweetOldPost');
13
+ $response = null;
14
+ $save = true;
15
+ $settings = top_get_settings();
16
+
17
+ //on authorize
18
+ if (isset($_GET['TOP_oauth'])) {
19
+ global $top_oauth;
20
+
21
+ $result = $top_oauth->get_access_token($settings['oauth_request_token'], $settings['oauth_request_token_secret'], $_GET['oauth_verifier']);
22
+
23
+ if ($result) {
24
+ $settings['oauth_access_token'] = $result['oauth_token'];
25
+ $settings['oauth_access_token_secret'] = $result['oauth_token_secret'];
26
+ $settings['user_id'] = $result['user_id'];
27
+
28
+ $result = $top_oauth->get_user_info($result['user_id']);
29
+ if ($result) {
30
+ $settings['profile_image_url'] = $result['user']['profile_image_url'];
31
+ $settings['screen_name'] = $result['user']['screen_name'];
32
+ if (isset($result['user']['location'])) {
33
+ $settings['location'] = $result['user']['location'];
34
+ } else {
35
+ $settings['location'] = false;
36
+ }
37
+ }
38
+
39
+ top_save_settings($settings);
40
+ echo '<script language="javascript">window.open ("' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=TweetOldPost","_self")</script>';
41
+ die;
42
+ }
43
+ }
44
+ //on deauthorize
45
+ else if (isset($_GET['top']) && $_GET['top'] == 'deauthorize') {
46
+ $settings = top_get_settings();
47
+ $settings['oauth_access_token'] = '';
48
+ $settings['oauth_access_token_secret'] = '';
49
+ $settings['user_id'] = '';
50
+ $settings['tweet_queue'] = array();
51
+
52
+ top_save_settings($settings);
53
+ echo '<script language="javascript">window.open ("' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=TweetOldPost","_self")</script>';
54
+ die;
55
+ }
56
+
57
+ //check if username and key provided if bitly selected
58
+ if (isset($_POST['top_opt_url_shortener'])) {
59
+ if ($_POST['top_opt_url_shortener'] == "bit.ly") {
60
+
61
+ //check bitly username
62
+ if (!isset($_POST['top_opt_bitly_user'])) {
63
+ print('
64
+ <div id="message" class="updated fade">
65
+ <p>' . __('Please enter bit.ly username.', 'TweetOldPost') . '</p>
66
+ </div>');
67
+ $save = false;
68
+ }
69
+ //check bitly key
70
+ elseif (!isset($_POST['top_opt_bitly_key'])) {
71
+ print('
72
+ <div id="message" class="updated fade">
73
+ <p>' . __('Please enter bit.ly API Key.', 'TweetOldPost') . '</p>
74
+ </div>');
75
+ $save = false;
76
+ }
77
+ //if both the good to save
78
+ else {
79
+ $save = true;
80
+ }
81
+ }
82
+ }
83
+
84
+ //if submit and if bitly selected its fields are filled then save
85
+ if (isset($_POST['submit']) && $save) {
86
+ $message = $message_updated;
87
+
88
+ //what to tweet
89
+ if (isset($_POST['top_opt_tweet_type'])) {
90
+ update_option('top_opt_tweet_type', $_POST['top_opt_tweet_type']);
91
+ }
92
+
93
+ //additional data
94
+ if (isset($_POST['top_opt_add_text'])) {
95
+ update_option('top_opt_add_text', $_POST['top_opt_add_text']);
96
+ }
97
+
98
+ //place of additional data
99
+ if (isset($_POST['top_opt_add_text_at'])) {
100
+ update_option('top_opt_add_text_at', $_POST['top_opt_add_text_at']);
101
+ }
102
+
103
+ //include link
104
+ if (isset($_POST['top_opt_include_link'])) {
105
+ update_option('top_opt_include_link', $_POST['top_opt_include_link']);
106
+ }
107
+
108
+ //fetch url from custom field?
109
+ if (isset($_POST['top_opt_custom_url_option'])) {
110
+ update_option('top_opt_custom_url_option', true);
111
+ } else {
112
+
113
+ update_option('top_opt_custom_url_option', false);
114
+ }
115
+
116
+ //custom field to fetch URL from
117
+ if (isset($_POST['top_opt_custom_url_field'])) {
118
+ update_option('top_opt_custom_url_field', $_POST['top_opt_custom_url_field']);
119
+ } else {
120
+
121
+ update_option('top_opt_custom_url_field', '');
122
+ }
123
+
124
+ //use URL shortner?
125
+ if (isset($_POST['top_opt_use_url_shortner'])) {
126
+ update_option('top_opt_use_url_shortner', true);
127
+ } else {
128
+
129
+ update_option('top_opt_use_url_shortner', false);
130
+ }
131
+
132
+ //url shortener to use
133
+ if (isset($_POST['top_opt_url_shortener'])) {
134
+ update_option('top_opt_url_shortener', $_POST['top_opt_url_shortener']);
135
+ if ($_POST['top_opt_url_shortener'] == "bit.ly") {
136
+ if (isset($_POST['top_opt_bitly_user'])) {
137
+ update_option('top_opt_bitly_user', $_POST['top_opt_bitly_user']);
138
+ }
139
+ if (isset($_POST['top_opt_bitly_key'])) {
140
+ update_option('top_opt_bitly_key', $_POST['top_opt_bitly_key']);
141
+ }
142
+ }
143
+ }
144
+
145
+ //hashtags option
146
+ if (isset($_POST['top_opt_custom_hashtag_option'])) {
147
+ update_option('top_opt_custom_hashtag_option', $_POST['top_opt_custom_hashtag_option']);
148
+ } else {
149
+ update_option('top_opt_custom_hashtag_option', "nohashtag");
150
+ }
151
+
152
+ //use inline hashtags
153
+ if (isset($_POST['top_opt_use_inline_hashtags'])) {
154
+ update_option('top_opt_use_inline_hashtags', true);
155
+ } else {
156
+ update_option('top_opt_use_inline_hashtags', false);
157
+ }
158
+
159
+ //hashtag length
160
+ if (isset($_POST['top_opt_hashtag_length'])) {
161
+ update_option('top_opt_hashtag_length', $_POST['top_opt_hashtag_length']);
162
+ } else {
163
+ update_option('top_opt_hashtag_length', 0);
164
+ }
165
+
166
+ //custom field name to fetch hashtag from
167
+ if (isset($_POST['top_opt_custom_hashtag_field'])) {
168
+ update_option('top_opt_custom_hashtag_field', $_POST['top_opt_custom_hashtag_field']);
169
+ } else {
170
+ update_option('top_opt_custom_hashtag_field', '');
171
+ }
172
+
173
+ //default hashtags for tweets
174
+ if (isset($_POST['top_opt_hashtags'])) {
175
+ update_option('top_opt_hashtags', $_POST['top_opt_hashtags']);
176
+ } else {
177
+ update_option('top_opt_hashtags', '');
178
+ }
179
+
180
+ //tweet interval
181
+ if (isset($_POST['top_opt_interval'])) {
182
+ if (is_numeric($_POST['top_opt_interval']) && $_POST['top_opt_interval'] > 0) {
183
+ update_option('top_opt_interval', $_POST['top_opt_interval']);
184
+ } else {
185
+ update_option('top_opt_interval', "4");
186
+ }
187
+ }
188
+
189
+ //random interval
190
+ if (isset($_POST['top_opt_interval_slop'])) {
191
+
192
+ if (is_numeric($_POST['top_opt_interval_slop']) && $_POST['top_opt_interval_slop'] > 0) {
193
+ update_option('top_opt_interval_slop', $_POST['top_opt_interval_slop']);
194
+ } else {
195
+ update_option('top_opt_interval_slop', "4");
196
+ }
197
+ }
198
+
199
+ //minimum post age to tweet
200
+ if (isset($_POST['top_opt_age_limit'])) {
201
+ if (is_numeric($_POST['top_opt_age_limit']) && $_POST['top_opt_age_limit'] > 0) {
202
+ update_option('top_opt_age_limit', $_POST['top_opt_age_limit']);
203
+ } else {
204
+ update_option('top_opt_age_limit', "30");
205
+ }
206
+ }
207
+
208
+ //maximum post age to tweet
209
+ if (isset($_POST['top_opt_max_age_limit'])) {
210
+ if (is_numeric($_POST['top_opt_max_age_limit']) && $_POST['top_opt_max_age_limit'] > 0) {
211
+ update_option('top_opt_max_age_limit', $_POST['top_opt_max_age_limit']);
212
+ } else {
213
+ update_option('top_opt_max_age_limit', "0");
214
+ }
215
+ }
216
+
217
+ //categories to omit from tweet
218
+ if (isset($_POST['post_category'])) {
219
+ update_option('top_opt_omit_cats', implode(',', $_POST['post_category']));
220
+ } else {
221
+ update_option('top_opt_omit_cats', '');
222
+ }
223
+
224
+ //successful update message
225
+ print('
226
+ <div id="message" class="updated fade">
227
+ <p>' . __('Tweet Old Post Options Updated.', 'TweetOldPost') . '</p>
228
+ </div>');
229
+ }
230
+ //tweet now clicked
231
+ elseif (isset($_POST['tweet'])) {
232
+ $tweet_msg = top_opt_tweet_old_post();
233
+ print('
234
+ <div id="message" class="updated fade">
235
+ <p>' . __($tweet_msg, 'TweetOldPost') . '</p>
236
+ </div>');
237
+ }
238
+
239
+
240
+ //set up data into fields from db
241
+ //what to tweet?
242
+ $tweet_type = get_option('top_opt_tweet_type');
243
+ if (!isset($tweet_type)) {
244
+ $tweet_type = "title";
245
+ }
246
+
247
+ //additional text
248
+ $additional_text = get_option('top_opt_add_text');
249
+ if (!isset($additional_text)) {
250
+ $additional_text = "";
251
+ }
252
+
253
+ //position of additional text
254
+ $additional_text_at = get_option('top_opt_add_text_at');
255
+ if (!isset($additional_text_at)) {
256
+ $additional_text_at = "beginning";
257
+ }
258
+
259
+ //include link in tweet
260
+ $include_link = get_option('top_opt_include_link');
261
+ if (!isset($include_link)) {
262
+ $include_link = "no";
263
+ }
264
+
265
+ //use custom field to fetch url
266
+ $custom_url_option = get_option('top_opt_custom_url_option');
267
+ if (!isset($custom_url_option)) {
268
+ $custom_url_option = "";
269
+ } elseif ($custom_url_option)
270
+ $custom_url_option = "checked";
271
+ else
272
+ $custom_url_option="";
273
+
274
+ //custom field name for url
275
+ $custom_url_field = get_option('top_opt_custom_url_field');
276
+ if (!isset($custom_url_field)) {
277
+ $custom_url_field = "";
278
+ }
279
+
280
+ //use url shortner?
281
+ $use_url_shortner = get_option('top_opt_use_url_shortner');
282
+ if (!isset($use_url_shortner)) {
283
+ $use_url_shortner = "";
284
+ } elseif ($use_url_shortner)
285
+ $use_url_shortner = "checked";
286
+ else
287
+ $use_url_shortner="";
288
+
289
+ //url shortner
290
+ $url_shortener = get_option('top_opt_url_shortener');
291
+ if (!isset($url_shortener)) {
292
+ $url_shortener = top_opt_URL_SHORTENER;
293
+ }
294
+
295
+ //bitly key
296
+ $bitly_api = get_option('top_opt_bitly_key');
297
+ if (!isset($bitly_api)) {
298
+ $bitly_api = "";
299
+ }
300
+
301
+ //bitly username
302
+ $bitly_username = get_option('top_opt_bitly_user');
303
+ if (!isset($bitly_username)) {
304
+ $bitly_username = "";
305
+ }
306
+
307
+ //hashtag option
308
+ $custom_hashtag_option = get_option('top_opt_custom_hashtag_option');
309
+ if (!isset($custom_hashtag_option)) {
310
+ $custom_hashtag_option = "nohashtag";
311
+ }
312
+
313
+ //use inline hashtag
314
+ $use_inline_hashtags = get_option('top_opt_use_inline_hashtags');
315
+ if (!isset($use_inline_hashtags)) {
316
+ $use_inline_hashtags = "";
317
+ } elseif ($use_inline_hashtags)
318
+ $use_inline_hashtags = "checked";
319
+ else
320
+ $use_inline_hashtags="";
321
+
322
+ //hashtag length
323
+ $hashtag_length = get_option('top_opt_hashtag_length');
324
+ if (!isset($hashtag_length)) {
325
+ $hashtag_length = "20";
326
+ }
327
+
328
+ //custom field
329
+ $custom_hashtag_field = get_option('top_opt_custom_hashtag_field');
330
+ if (!isset($custom_hashtag_field)) {
331
+ $custom_hashtag_field = "";
332
+ }
333
+
334
+ //default hashtag
335
+ $twitter_hashtags = get_option('top_opt_hashtags');
336
+ if (!isset($twitter_hashtags)) {
337
+ $twitter_hashtags = top_opt_HASHTAGS;
338
+ }
339
+
340
+ //interval
341
+ $interval = get_option('top_opt_interval');
342
+ if (!(isset($interval) && is_numeric($interval))) {
343
+ $interval = top_opt_INTERVAL;
344
+ }
345
+
346
+ //random interval
347
+ $slop = get_option('top_opt_interval_slop');
348
+ if (!(isset($slop) && is_numeric($slop))) {
349
+ $slop = top_opt_INTERVAL_SLOP;
350
+ }
351
+
352
+ //min age limit
353
+ $ageLimit = get_option('top_opt_age_limit');
354
+ if (!(isset($ageLimit) && is_numeric($ageLimit))) {
355
+ $ageLimit = top_opt_AGE_LIMIT;
356
+ }
357
+
358
+ //max age limit
359
+ $maxAgeLimit = get_option('top_opt_max_age_limit');
360
+ if (!(isset($maxAgeLimit) && is_numeric($maxAgeLimit))) {
361
+ $maxAgeLimit = top_opt_MAX_AGE_LIMIT;
362
+ }
363
+
364
+ //set omitted categories
365
+ $omitCats = get_option('top_opt_omit_cats');
366
+ if (!isset($omitCats)) {
367
+ $omitCats = top_opt_OMIT_CATS;
368
+ }
369
+
370
+ $x = WP_PLUGIN_URL . '/' . str_replace(basename(__FILE__), "", plugin_basename(__FILE__));
371
+
372
+ print('
373
+ <div class="wrap">
374
+ <h2>' . __('Tweet old post by - ', 'TweetOldPost') . ' <a href="http://www.ajaymatharu.com">Ajay Matharu</a></h2>
375
+ <form id="top_opt" name="top_TweetOldPost" action="' . top_currentPageURL() . '" method="post">
376
+ <input type="hidden" name="top_opt_action" value="top_opt_update_settings" />
377
+ <fieldset class="options">
378
+ <div class="option">
379
+ <label for="top_opt_twitter_username">' . __('Account Login', 'TweetOldPost') . ':</label>
380
+
381
+ <div id="profile-box">');
382
+ if (!$settings["oauth_access_token"]) {
383
+
384
+ echo '<a href="' . top_get_auth_url() . '"><img src="' . $x . 'images/twitter.png" /></a>';
385
+ } else {
386
+ echo '<img class="avatar" src="' . $settings["profile_image_url"] . '" alt="" />
387
+ <h4>' . $settings["screen_name"] . '</h4>';
388
+ if ($settings["location"]) {
389
+ echo '<h5>' . $settings["location"] . '</h5>';
390
+ }
391
+ echo '<p>
392
+
393
+ 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 />
394
+
395
+ </p>
396
+
397
+ <div class="retweet-clear"></div>
398
+ ';
399
+ }
400
+ print('</div>
401
+ </div>
402
+ <div class="option">
403
+ <label for="top_opt_tweet_type">' . __('Tweet Content', 'TweetOldPost') . ':</label>
404
+ <select id="top_opt_tweet_type" name="top_opt_tweet_type" style="width:150px">
405
+ <option value="title" ' . top_opt_optionselected("title", $tweet_type) . '>' . __(' Title Only ', 'TweetOldPost') . ' </option>
406
+ <option value="body" ' . top_opt_optionselected("body", $tweet_type) . '>' . __(' Body Only ', 'TweetOldPost') . ' </option>
407
+ <option value="titlenbody" ' . top_opt_optionselected("titlenbody", $tweet_type) . '>' . __(' Title & Body ', 'TweetOldPost') . ' </option>
408
+ </select>
409
+ </div>
410
+
411
+
412
+ <div class="option">
413
+ <label for="top_opt_add_text">' . __('Additional Text', 'TweetOldPost') . ':</label>
414
+ <input type="text" size="25" name="top_opt_add_text" id="top_opt_add_text" value="' . $additional_text . '" autocomplete="off" />
415
+ </div>
416
+ <div class="option">
417
+ <label for="top_opt_add_text_at">' . __('Additional Text At', 'TweetOldPost') . ':</label>
418
+ <select id="top_opt_add_text_at" name="top_opt_add_text_at" style="width:150px">
419
+ <option value="beginning" ' . top_opt_optionselected("beginning", $additional_text_at) . '>' . __(' Beginning of tweet ', 'TweetOldPost') . '</option>
420
+ <option value="end" ' . top_opt_optionselected("end", $additional_text_at) . '>' . __(' End of tweet ', 'TweetOldPost') . '</option>
421
+ </select>
422
+ </div>
423
+
424
+ <div class="option">
425
+ <label for="top_opt_include_link">' . __('Include Link', 'TweetOldPost') . ':</label>
426
+ <select id="top_opt_include_link" name="top_opt_include_link" style="width:150px" onchange="javascript:showURLOptions()">
427
+ <option value="false" ' . top_opt_optionselected("false", $include_link) . '>' . __(' No ', 'TweetOldPost') . '</option>
428
+ <option value="true" ' . top_opt_optionselected("true", $include_link) . '>' . __(' Yes ', 'TweetOldPost') . '</option>
429
+ </select>
430
+ </div>
431
+
432
+ <div id="urloptions" style="display:none">
433
+
434
+ <div class="option">
435
+ <label for="top_opt_custom_url_option">' . __('Fetch URL from custom field', 'TweetOldPost') . ':</label>
436
+ <input onchange="return showCustomField();" type="checkbox" name="top_opt_custom_url_option" ' . $custom_url_option . ' id="top_opt_custom_url_option" />
437
+ <b>If checked URL will be fetched from custom field.</b>
438
+ </div>
439
+
440
+
441
+
442
+ <div id="customurl" style="display:none;">
443
+ <div class="option">
444
+ <label for="top_opt_custom_url_field">' . __('Custom field name to fetch URL to be tweeted with post', 'TweetOldPost') . ':</label>
445
+ <input type="text" size="25" name="top_opt_custom_url_field" id="top_opt_custom_url_field" value="' . $custom_url_field . '" autocomplete="off" />
446
+ <b>If set this will fetch the URL from specified custom field</b>
447
+ </div>
448
+
449
+ </div>
450
+
451
+ <div class="option">
452
+ <label for="top_opt_use_url_shortner">' . __('Use URL shortner?', 'TweetOldPost') . ':</label>
453
+ <input onchange="return showshortener()" type="checkbox" name="top_opt_use_url_shortner" id="top_opt_use_url_shortner" ' . $use_url_shortner . ' />
454
+
455
+ </div>
456
+
457
+ <div id="urlshortener">
458
+ <div class="option">
459
+ <label for="top_opt_url_shortener">' . __('URL Shortener Service', 'TweetOldPost') . ':</label>
460
+ <select name="top_opt_url_shortener" id="top_opt_url_shortener" onchange="javascript:showURLAPI()" style="width:100px;">
461
+ <option value="is.gd" ' . top_opt_optionselected('is.gd', $url_shortener) . '>' . __('is.gd', 'TweetOldPost') . '</option>
462
+ <option value="su.pr" ' . top_opt_optionselected('su.pr', $url_shortener) . '>' . __('su.pr', 'TweetOldPost') . '</option>
463
+ <option value="bit.ly" ' . top_opt_optionselected('bit.ly', $url_shortener) . '>' . __('bit.ly', 'TweetOldPost') . '</option>
464
+ <option value="tr.im" ' . top_opt_optionselected('tr.im', $url_shortener) . '>' . __('tr.im', 'TweetOldPost') . '</option>
465
+ <option value="3.ly" ' . top_opt_optionselected('3.ly', $url_shortener) . '>' . __('3.ly', 'TweetOldPost') . '</option>
466
+ <option value="u.nu" ' . top_opt_optionselected('u.nu', $url_shortener) . '>' . __('u.nu', 'TweetOldPost') . '</option>
467
+ <option value="1click.at" ' . top_opt_optionselected('1click.at', $url_shortener) . '>' . __('1click.at', 'TweetOldPost') . '</option>
468
+ <option value="tinyurl" ' . top_opt_optionselected('tinyurl', $url_shortener) . '>' . __('tinyurl', 'TweetOldPost') . '</option>
469
+ </select>
470
+ </div>
471
+ <div id="showDetail" style="display:none">
472
+ <div class="option">
473
+ <label for="top_opt_bitly_user">' . __('bit.ly Username', 'TweetOldPost') . ':</label>
474
+ <input type="text" size="25" name="top_opt_bitly_user" id="top_opt_bitly_user" value="' . $bitly_username . '" autocomplete="off" />
475
+ </div>
476
+
477
+ <div class="option">
478
+ <label for="top_opt_bitly_key">' . __('bit.ly API Key', 'TweetOldPost') . ':</label>
479
+ <input type="text" size="25" name="top_opt_bitly_key" id="top_opt_bitly_key" value="' . $bitly_api . '" autocomplete="off" />
480
+ </div>
481
+ </div>
482
+ </div>
483
+ </div>
484
+
485
+
486
+ <div class="option">
487
+ <label for="top_opt_custom_hashtag_option">' . __('Hashtags', 'TweetOldPost') . ':</label>
488
+ <select name="top_opt_custom_hashtag_option" id="top_opt_custom_hashtag_option" onchange="javascript:return showHashtagCustomField()" style="width:250px;">
489
+ <option value="nohashtag" ' . top_opt_optionselected('nohashtag', $custom_hashtag_option) . '>' . __('Don`t add any hashtags', 'TweetOldPost') . '</option>
490
+ <option value="common" ' . top_opt_optionselected('common', $custom_hashtag_option) . '>' . __('Common hashtag for all tweets', 'TweetOldPost') . '</option>
491
+ <option value="categories" ' . top_opt_optionselected('categories', $custom_hashtag_option) . '>' . __('Create hashtags from categories', 'TweetOldPost') . '</option>
492
+ <option value="tags" ' . top_opt_optionselected('tags', $custom_hashtag_option) . '>' . __('Create hashtags from tags', 'TweetOldPost') . '</option>
493
+ <option value="custom" ' . top_opt_optionselected('custom', $custom_hashtag_option) . '>' . __('Get hashtags from custom fields', 'TweetOldPost') . '</option>
494
+
495
+ </select>
496
+
497
+
498
+ </div>
499
+ <div id="inlinehashtag" style="display:none;">
500
+ <div class="option">
501
+ <label for="top_opt_use_inline_hashtags">' . __('Use inline hashtags: ', 'TweetOldPost') . '</label>
502
+ <input type="checkbox" name="top_opt_use_inline_hashtags" id="top_opt_use_inline_hashtags" ' . $use_inline_hashtags . ' />
503
+
504
+ </div>
505
+
506
+ <div class="option">
507
+ <label for="top_opt_hashtag_length">' . __('Total Hashtag length: ', 'TweetOldPost') . '</label>
508
+ <input type="text" size="25" name="top_opt_hashtag_length" id="top_opt_hashtag_length" value="' . $hashtag_length . '" />
509
+ <b>Set this to 0 to include all hashtags</b>
510
+ </div>
511
+ </div>
512
+ <div id="customhashtag" style="display:none;">
513
+ <div class="option">
514
+ <label for="top_opt_custom_hashtag_field">' . __('Custom field name', 'TweetOldPost') . ':</label>
515
+ <input type="text" size="25" name="top_opt_custom_hashtag_field" id="top_opt_custom_hashtag_field" value="' . $custom_hashtag_field . '" autocomplete="off" />
516
+ <b>fetch hashtags from this custom field</b>
517
+ </div>
518
+
519
+ </div>
520
+ <div id="commonhashtag" style="display:none;">
521
+ <div class="option">
522
+ <label for="top_opt_hashtags">' . __('Common #hashtags for your tweets', 'TweetOldPost') . ':</label>
523
+ <input type="text" size="25" name="top_opt_hashtags" id="top_opt_hashtags" value="' . $twitter_hashtags . '" autocomplete="off" />
524
+ <b>Include #, like #thoughts</b>
525
+ </div>
526
+ </div>
527
+ <div class="option">
528
+ <label for="top_opt_interval">' . __('Minimum interval between tweets: ', 'TweetOldPost') . '</label>
529
+ <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>
530
+
531
+ </div>
532
+ <div class="option">
533
+ <label for="top_opt_interval_slop">' . __('Random Interval (added to minimum interval): ', 'TweetOldPost') . '</label>
534
+ <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>
535
+
536
+ </div>
537
+ <div class="option">
538
+ <label for="top_opt_age_limit">' . __('Minimum age of post to be eligible for tweet: ', 'TweetOldPost') . '</label>
539
+ <input type="text" id="top_opt_age_limit" maxlength="5" value="' . $ageLimit . '" name="top_opt_age_limit" /> Day / Days
540
+ <b> (enter 0 for today)</b>
541
+
542
+ </div>
543
+
544
+ <div class="option">
545
+ <label for="top_opt_max_age_limit">' . __('Maximum age of post to be eligible for tweet: ', 'TweetOldPost') . '</label>
546
+ <input type="text" id="top_opt_max_age_limit" maxlength="5" value="' . $maxAgeLimit . '" name="top_opt_max_age_limit" /> Day / Days
547
+ <b>(If you dont want to use this option enter 0 or leave blank)</b><br/>
548
+ <b>Post older than specified days will not be tweeted.</b>
549
+ </div>
550
+
551
+ <div class="option category">
552
+ <div style="float:left">
553
+ <label class="catlabel">' . __('Categories to Omit from tweets: ', 'TweetOldPost') . '</label> </div>
554
+ <div style="float:left">
555
+ <ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
556
+ ');
557
+ wp_category_checklist(0, 0, explode(',', $omitCats));
558
+ print(' </ul>
559
+ <div style="clear:both;padding-top:20px;">
560
+ <a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=ExcludePosts">Exclude specific posts</a> from selected categories.
561
+ </div>
562
+ </div>
563
+
564
+ </div>
565
+ </fieldset>
566
+
567
+ <h3>Note: Please click update to then click tweet now to reflect the changes.</h3>
568
+ <p class="submit"><input type="submit" name="submit" onclick="javascript:return validate()" value="' . __('Update Tweet Old Post Options', 'TweetOldPost') . '" />
569
+ <input type="submit" name="tweet" value="' . __('Tweet Now', 'TweetOldPost') . '" />
570
+ </p>
571
+
572
+ </form><script language="javascript" type="text/javascript">
573
+ function showURLAPI()
574
+ {
575
+ var urlShortener=document.getElementById("top_opt_url_shortener").value;
576
+ if(urlShortener=="bit.ly")
577
+ {
578
+ document.getElementById("showDetail").style.display="block";
579
+
580
+ }
581
+ else
582
+ {
583
+ document.getElementById("showDetail").style.display="none";
584
+
585
+ }
586
+
587
+ }
588
+
589
+ function validate()
590
+ {
591
+
592
+ if(document.getElementById("showDetail").style.display=="block" && document.getElementById("top_opt_url_shortener").value=="bit.ly")
593
+ {
594
+ if(trim(document.getElementById("top_opt_bitly_user").value)=="")
595
+ {
596
+ alert("Please enter bit.ly username.");
597
+ document.getElementById("top_opt_bitly_user").focus();
598
+ return false;
599
+ }
600
+
601
+ if(trim(document.getElementById("top_opt_bitly_key").value)=="")
602
+ {
603
+ alert("Please enter bit.ly API key.");
604
+ document.getElementById("top_opt_bitly_key").focus();
605
+ return false;
606
+ }
607
+ }
608
+ if(trim(document.getElementById("top_opt_interval").value) != "" && !isNumber(trim(document.getElementById("top_opt_interval").value)))
609
+ {
610
+ alert("Enter only numeric in Minimum interval between tweet");
611
+ document.getElementById("top_opt_interval").focus();
612
+ return false;
613
+ }
614
+ if(trim(document.getElementById("top_opt_interval_slop").value) != "" && !isNumber(trim(document.getElementById("top_opt_interval_slop").value)))
615
+ {
616
+ alert("Enter only numeric in Random interval");
617
+ document.getElementById("top_opt_interval_slop").focus();
618
+ return false;
619
+ }
620
+ if(trim(document.getElementById("top_opt_age_limit").value) != "" && !isNumber(trim(document.getElementById("top_opt_age_limit").value)))
621
+ {
622
+ alert("Enter only numeric in Minimum age of post");
623
+ document.getElementById("top_opt_age_limit").focus();
624
+ return false;
625
+ }
626
+ if(trim(document.getElementById("top_opt_max_age_limit").value) != "" && !isNumber(trim(document.getElementById("top_opt_max_age_limit").value)))
627
+ {
628
+ alert("Enter only numeric in Maximum age of post");
629
+ document.getElementById("top_opt_max_age_limit").focus();
630
+ return false;
631
+ }
632
+ if(trim(document.getElementById("top_opt_max_age_limit").value) != "" && trim(document.getElementById("top_opt_max_age_limit").value) != 0)
633
+ {
634
+ if(eval(document.getElementById("top_opt_age_limit").value) > eval(document.getElementById("top_opt_max_age_limit").value))
635
+ {
636
+ alert("Post max age limit cannot be less than Post min age iimit");
637
+ document.getElementById("top_opt_age_limit").focus();
638
+ return false;
639
+ }
640
+ }
641
+ }
642
+
643
+ function trim(stringToTrim) {
644
+ return stringToTrim.replace(/^\s+|\s+$/g,"");
645
+ }
646
+
647
+ function showCustomField()
648
+ {
649
+ if(document.getElementById("top_opt_custom_url_option").checked)
650
+ {
651
+ document.getElementById("customurl").style.display="block";
652
+ }
653
+ else
654
+ {
655
+ document.getElementById("customurl").style.display="none";
656
+ }
657
+ }
658
+
659
+ function showHashtagCustomField()
660
+ {
661
+ if(document.getElementById("top_opt_custom_hashtag_option").value=="custom")
662
+ {
663
+ document.getElementById("customhashtag").style.display="block";
664
+ document.getElementById("commonhashtag").style.display="none";
665
+ document.getElementById("inlinehashtag").style.display="block";
666
+ }
667
+ else if(document.getElementById("top_opt_custom_hashtag_option").value=="common")
668
+ {
669
+ document.getElementById("customhashtag").style.display="none";
670
+ document.getElementById("commonhashtag").style.display="block";
671
+ document.getElementById("inlinehashtag").style.display="block";
672
+ }
673
+ else if(document.getElementById("top_opt_custom_hashtag_option").value=="nohashtag")
674
+ {
675
+ document.getElementById("customhashtag").style.display="none";
676
+ document.getElementById("commonhashtag").style.display="none";
677
+ document.getElementById("inlinehashtag").style.display="none";
678
+ }
679
+ else
680
+ {
681
+ document.getElementById("inlinehashtag").style.display="block";
682
+ document.getElementById("customhashtag").style.display="none";
683
+ document.getElementById("commonhashtag").style.display="none";
684
+ }
685
+ }
686
+
687
+ function showURLOptions()
688
+ {
689
+ if(document.getElementById("top_opt_include_link").value=="true")
690
+ {
691
+ document.getElementById("urloptions").style.display="block";
692
+ }
693
+ else
694
+ {
695
+ document.getElementById("urloptions").style.display="none";
696
+ }
697
+ }
698
+
699
+ function isNumber(val)
700
+ {
701
+ if(isNaN(val)){
702
+ return false;
703
+ }
704
+ else{
705
+ return true;
706
+ }
707
+ }
708
+
709
+ function showshortener()
710
+ {
711
+
712
+
713
+ if((document.getElementById("top_opt_use_url_shortner").checked))
714
+ {
715
+ document.getElementById("urlshortener").style.display="block";
716
+ }
717
+ else
718
+ {
719
+ document.getElementById("urlshortener").style.display="none";
720
+ }
721
+ }
722
+ showURLAPI();
723
+ showshortener();
724
+ showCustomField();
725
+ showHashtagCustomField();
726
+ showURLOptions();
727
+ </script>');
728
+ } else {
729
+ print('
730
+ <div id="message" class="updated fade">
731
+ <p>' . __('You do not have enough permission to set the option. Please contact your admin.', 'TweetOldPost') . '</p>
732
+ </div>');
733
+ }
734
+ }
735
+
736
+ function top_opt_optionselected($opValue, $value) {
737
+ if ($opValue == $value) {
738
+ return 'selected="selected"';
739
+ }
740
+ return '';
741
+ }
742
+
743
+ function top_opt_head_admin() {
744
+ $home = get_settings('siteurl');
745
+ $base = '/' . end(explode('/', str_replace(array('\\', '/top-admin.php'), array('/', ''), __FILE__)));
746
+ $stylesheet = $home . '/wp-content/plugins' . $base . '/css/tweet-old-post.css';
747
+ echo('<link rel="stylesheet" href="' . $stylesheet . '" type="text/css" media="screen" />');
748
+ }
749
+
750
+ ?>
top-core.php ADDED
@@ -0,0 +1,426 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ function top_currentPageURL() {
16
+ $pageURL = 'http';
17
+ if ($_SERVER["HTTPS"] == "on") {
18
+ $pageURL .= "s";
19
+ }
20
+ $pageURL .= "://";
21
+ if ($_SERVER["SERVER_PORT"] != "80") {
22
+ $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
23
+ } else {
24
+ $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
25
+ }
26
+ return $pageURL;
27
+ }
28
+
29
+ //get random post and tweet
30
+ function top_opt_tweet_old_post() {
31
+ global $wpdb;
32
+ $omitCats = get_option('top_opt_omit_cats');
33
+ $maxAgeLimit = get_option('top_opt_max_age_limit');
34
+ $ageLimit = get_option('top_opt_age_limit');
35
+ $exposts = get_option('top_opt_excluded_post');
36
+ $exposts = preg_replace('/,,+/', ',', $exposts);
37
+
38
+ if (substr($exposts, 0, 1) == ",") {
39
+ $exposts = substr($exposts, 1, strlen($exposts));
40
+ }
41
+ if (substr($exposts, -1, 1) == ",") {
42
+ $exposts = substr($exposts, 0, strlen($exposts) - 1);
43
+ }
44
+
45
+ if (!(isset($ageLimit) && is_numeric($ageLimit))) {
46
+ $ageLimit = top_opt_AGE_LIMIT;
47
+ }
48
+
49
+ if (!(isset($maxAgeLimit) && is_numeric($maxAgeLimit))) {
50
+ $maxAgeLimit = top_opt_MAX_AGE_LIMIT;
51
+ }
52
+ if (!isset($omitCats)) {
53
+ $omitCats = top_opt_OMIT_CATS;
54
+ }
55
+
56
+ $sql = "SELECT ID
57
+ FROM $wpdb->posts
58
+ WHERE post_type = 'post'
59
+ AND post_status = 'publish'
60
+ AND post_date <= curdate( ) - INTERVAL " . $ageLimit . " day";
61
+
62
+ if ($maxAgeLimit != 0) {
63
+ $sql = $sql . " AND post_date >= curdate( ) - INTERVAL " . $maxAgeLimit . " day";
64
+ }
65
+ if (isset($exposts)) {
66
+ if (trim($exposts) != '') {
67
+ $sql = $sql . " AND ID Not IN (" . $exposts . ") ";
68
+ }
69
+ }
70
+ /* if ($omitCats != '') {
71
+ $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 . ")))";
72
+ } */
73
+ if ($omitCats != '') {
74
+ $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 . ")))";
75
+ }
76
+ $sql = $sql . "
77
+ ORDER BY RAND()
78
+ LIMIT 1 ";
79
+
80
+ $oldest_post = $wpdb->get_var($sql);
81
+ if ($oldest_post == null) {
82
+ return "No post found to tweet. Please check your settings and try again.";
83
+ }
84
+ if (isset($oldest_post)) {
85
+ return top_opt_tweet_post($oldest_post);
86
+ }
87
+ }
88
+
89
+ //tweet for the passed random post
90
+ function top_opt_tweet_post($oldest_post) {
91
+ global $wpdb;
92
+ $post = get_post($oldest_post);
93
+ $content = "";
94
+ $to_short_url = true;
95
+ $shorturl = "";
96
+ $tweet_type = get_option('top_opt_tweet_type');
97
+ $additional_text = get_option('top_opt_add_text');
98
+ $additional_text_at = get_option('top_opt_add_text_at');
99
+ $include_link = get_option('top_opt_include_link');
100
+ $custom_hashtag_option = get_option('top_opt_custom_hashtag_option');
101
+ $custom_hashtag_field = get_option('top_opt_custom_hashtag_field');
102
+ $twitter_hashtags = get_option('top_opt_hashtags');
103
+ $url_shortener = get_option('top_opt_url_shortener');
104
+ $custom_url_option = get_option('top_opt_custom_url_option');
105
+ $to_short_url = get_option('top_opt_use_url_shortner');
106
+ $use_inline_hashtags = get_option('top_opt_use_inline_hashtags');
107
+ $hashtag_length = get_option('top_opt_hashtag_length');
108
+
109
+ if ($include_link != "false") {
110
+ $permalink = get_permalink($oldest_post);
111
+
112
+ if ($custom_url_option) {
113
+ $custom_url_field = get_option('top_opt_custom_url_field');
114
+ if (trim($custom_url_field) != "") {
115
+ $permalink = trim(get_post_meta($post->ID, $custom_url_field, true));
116
+ }
117
+ }
118
+
119
+ if ($to_short_url) {
120
+
121
+ if ($url_shortener == "bit.ly") {
122
+ $bitly_key = get_option('top_opt_bitly_key');
123
+ $bitly_user = get_option('top_opt_bitly_user');
124
+ $shorturl = shorten_url($permalink, $url_shortener, $bitly_key, $bitly_user);
125
+ } else {
126
+ $shorturl = shorten_url($permalink, $url_shortener);
127
+ }
128
+ } else {
129
+ $shorturl = $permalink;
130
+ }
131
+ }
132
+
133
+ if ($tweet_type == "title" || $tweet_type == "titlenbody") {
134
+ $title = stripslashes($post->post_title);
135
+ $title = strip_tags($title);
136
+ $title = preg_replace('/\s\s+/', ' ', $title);
137
+ } else {
138
+ $title = "";
139
+ }
140
+
141
+ if ($tweet_type == "body" || $tweet_type == "titlenbody") {
142
+ $body = stripslashes($post->post_content);
143
+ $body = strip_tags($body);
144
+ $body = preg_replace('/\s\s+/', ' ', $body);
145
+ } else {
146
+ $body = "";
147
+ }
148
+
149
+ if ($tweet_type == "titlenbody") {
150
+ if ($title == null) {
151
+ $content = $body;
152
+ } elseif ($body == null) {
153
+ $content = $title;
154
+ } else {
155
+ $content = $title . " - " . $body;
156
+ }
157
+ } elseif ($tweet_type == "title") {
158
+ $content = $title;
159
+ } elseif ($tweet_type == "body") {
160
+ $content = $body;
161
+ }
162
+
163
+ if ($additional_text != "") {
164
+ if ($additional_text_at == "end") {
165
+ $content = $content . ". " . $additional_text;
166
+ } elseif ($additional_text_at == "beginning") {
167
+ $content = $additional_text . ": " . $content;
168
+ }
169
+ }
170
+
171
+ $hashtags = "";
172
+ $newcontent = "";
173
+ if ($custom_hashtag_option != "nohashtag") {
174
+
175
+ if ($custom_hashtag_option == "common") {
176
+ //common hashtag
177
+ $hashtags = $twitter_hashtags;
178
+ }
179
+ //post custom field hashtag
180
+ elseif ($custom_hashtag_option == "custom") {
181
+ if (trim($custom_hashtag_field) != "") {
182
+ $hashtags = trim(get_post_meta($post->ID, $custom_hashtag_field, true));
183
+ }
184
+ } elseif ($custom_hashtag_option == "categories") {
185
+ $post_categories = get_the_category($post->ID);
186
+ if ($post_categories) {
187
+ foreach ($post_categories as $category) {
188
+ $tagname = str_replace(".", "", str_replace(" ", "_", $category->cat_name));
189
+ if ($use_inline_hashtags) {
190
+ if (strrpos($content, $tagname) === false) {
191
+ $hashtags = $hashtags . "#" . $tagname . " ";
192
+ } else {
193
+ $newcontent = preg_replace('/\b' . $tagname . '\b/i', "#" . $tagname, $content, 1);
194
+ }
195
+ } else {
196
+ $hashtags = $hashtags . "#" . $tagname . " ";
197
+ }
198
+ }
199
+ }
200
+ } elseif ($custom_hashtag_option == "tags") {
201
+ $post_tags = get_the_tags($post->ID);
202
+ if ($post_tags) {
203
+ foreach ($post_tags as $tag) {
204
+ $tagname = str_replace(".", "", str_replace(" ", "_", $tag->name));
205
+ if ($use_inline_hashtags) {
206
+ if (strrpos($content, $tagname) === false) {
207
+ $hashtags = $hashtags . "#" . $tagname . " ";
208
+ } else {
209
+ $newcontent = preg_replace('/\b' . $tagname . '\b/i', "#" . $tagname, $content, 1);
210
+ }
211
+ } else {
212
+ $hashtags = $hashtags . "#" . $tagname . " ";
213
+ }
214
+ }
215
+ }
216
+ }
217
+
218
+ if ($newcontent != "")
219
+ $content = $newcontent;
220
+ }
221
+
222
+
223
+
224
+ if ($include_link != "false") {
225
+ if (!is_numeric($shorturl) && (strncmp($shorturl, "http", strlen("http")) == 0)) {
226
+
227
+ } else {
228
+ return "OOPS!!! problem with your URL shortning service. Some signs of error " . $shorturl . ".";
229
+ }
230
+ }
231
+
232
+ $message = set_tweet_length($content, $shorturl, $hashtags, $hashtag_length);
233
+ $status = urlencode(stripslashes(urldecode($message)));
234
+ if ($status) {
235
+ $poststatus = top_update_status($message);
236
+ if ($poststatus == true)
237
+ return "Whoopie!!! Tweet Posted Successfully";
238
+ else
239
+ return "OOPS!!! there seems to be some problem while tweeting. Please try again.";
240
+ }
241
+ return "OOPS!!! there seems to be some problem while tweeting. Try again. If problem is persistent mail the problem at ajay@ajaymatharu.com";
242
+ }
243
+
244
+ //send request to passed url and return the response
245
+ function send_request($url, $method='GET', $data='', $auth_user='', $auth_pass='') {
246
+ $ch = curl_init($url);
247
+ if (strtoupper($method) == "POST") {
248
+ curl_setopt($ch, CURLOPT_POST, 1);
249
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
250
+ }
251
+ if (ini_get('open_basedir') == '' && ini_get('safe_mode') == 'Off') {
252
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
253
+ }
254
+ curl_setopt($ch, CURLOPT_HEADER, 0);
255
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
256
+ if ($auth_user != '' && $auth_pass != '') {
257
+ curl_setopt($ch, CURLOPT_USERPWD, "{$auth_user}:{$auth_pass}");
258
+ }
259
+ $response = curl_exec($ch);
260
+ $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
261
+ curl_close($ch);
262
+ if ($httpcode != 200) {
263
+ return $httpcode;
264
+ }
265
+
266
+ return $response;
267
+ }
268
+
269
+ //Shorten long URLs with is.gd or bit.ly.
270
+ function shorten_url($the_url, $shortener='is.gd', $api_key='', $user='') {
271
+
272
+ if (($shortener == "bit.ly") && isset($api_key) && isset($user)) {
273
+
274
+ $url = "http://api.bit.ly/v3/shorten?longUrl={$the_url}&login={$user}&apiKey={$api_key}&format=json";
275
+ $result = json_decode(file_get_contents($url));
276
+ if ($result->status_code == 200)
277
+ $response = $result->data->url;
278
+ else
279
+ $response="" . $result->status_txt ."";
280
+ } elseif ($shortener == "su.pr") {
281
+ $url = "http://su.pr/api/simpleshorten?url={$the_url}";
282
+ $response = send_request($url, 'GET');
283
+ } elseif ($shortener == "tr.im") {
284
+ $url = "http://api.tr.im/api/trim_simple?url={$the_url}";
285
+ $response = send_request($url, 'GET');
286
+ } elseif ($shortener == "3.ly") {
287
+ $url = "http://3.ly/?api=em5893833&u={$the_url}";
288
+ $response = send_request($url, 'GET');
289
+ } elseif ($shortener == "tinyurl") {
290
+ $url = "http://tinyurl.com/api-create.php?url={$the_url}";
291
+ $response = send_request($url, 'GET');
292
+ } elseif ($shortener == "u.nu") {
293
+ $url = "http://u.nu/unu-api-simple?url={$the_url}";
294
+ $response = send_request($url, 'GET');
295
+ } elseif ($shortener == "1click.at") {
296
+ $url = "http://1click.at/api.php?action=shorturl&url={$the_url}&format=simple";
297
+ $response = send_request($url, 'GET');
298
+ } else {
299
+ $url = "http://is.gd/api.php?longurl={$the_url}";
300
+ $response = send_request($url, 'GET');
301
+ }
302
+
303
+ return $response;
304
+ }
305
+
306
+ //Shrink a tweet and accompanying URL down to 140 chars.
307
+ function set_tweet_length($message, $url, $twitter_hashtags="", $hashtag_length=0) {
308
+
309
+ $tags = $twitter_hashtags;
310
+ $message_length = strlen($message);
311
+ $url_length = strlen($url);
312
+ if ($hashtag_length == 0)
313
+ $hashtag_length = strlen($tags);
314
+
315
+ if ($message_length + $url_length + $hashtag_length > 140) {
316
+ $tags = substr($tags, 0, $hashtag_length);
317
+ $tags = substr($tags, 0, strrpos($tags, ' '));
318
+
319
+ $hashtag_length = strlen($tags);
320
+
321
+ $shorten_message_to = 140 - $url_length - $hashtag_length;
322
+ $shorten_message_to = $shorten_message_to - 4;
323
+ //$message = $message." ";
324
+ $message = substr($message, 0, $shorten_message_to);
325
+ $message = substr($message, 0, strrpos($message, ' '));
326
+ $message = $message . "...";
327
+ }
328
+ return $message . " " . $url . " " . $tags;
329
+ }
330
+
331
+ //check time and update the last tweet time
332
+ function top_opt_update_time() {
333
+ $last = get_option('top_opt_last_update');
334
+ $interval = get_option('top_opt_interval');
335
+ $slop = get_option('top_opt_interval_slop');
336
+
337
+ if (!(isset($interval) && is_numeric($interval))) {
338
+ $interval = top_opt_INTERVAL;
339
+ }
340
+
341
+ if (!(isset($slop) && is_numeric($slop))) {
342
+ $slop = top_opt_INTERVAL_SLOP;
343
+ }
344
+ $interval = $interval * 60 * 60;
345
+ $slop = $slop * 60 * 60;
346
+ if (false === $last) {
347
+ $ret = 1;
348
+ } else if (is_numeric($last)) {
349
+ $ret = ( (time() - $last) > ($interval + rand(0, $slop)));
350
+ }
351
+ return $ret;
352
+ }
353
+
354
+ function top_get_auth_url() {
355
+ global $top_oauth;
356
+ $settings = top_get_settings();
357
+
358
+ $token = $top_oauth->get_request_token();
359
+ if ($token) {
360
+ $settings['oauth_request_token'] = $token['oauth_token'];
361
+ $settings['oauth_request_token_secret'] = $token['oauth_token_secret'];
362
+
363
+ top_save_settings($settings);
364
+
365
+ return $top_oauth->get_auth_url($token['oauth_token']);
366
+ }
367
+ }
368
+
369
+ function top_update_status($new_status) {
370
+ global $top_oauth;
371
+ $settings = top_get_settings();
372
+
373
+ if (isset($settings['oauth_access_token']) && isset($settings['oauth_access_token_secret'])) {
374
+ return $top_oauth->update_status($settings['oauth_access_token'], $settings['oauth_access_token_secret'], $new_status);
375
+ }
376
+
377
+ return false;
378
+ }
379
+
380
+ function top_has_tokens() {
381
+ $settings = top_get_settings();
382
+
383
+ return ( $settings['oauth_access_token'] && $settings['oauth_access_token_secret'] );
384
+ }
385
+
386
+ function top_is_valid() {
387
+ return twit_has_tokens();
388
+ }
389
+
390
+ function top_do_tweet($post_id) {
391
+ $settings = top_get_settings();
392
+
393
+ $message = top_get_message($post_id);
394
+
395
+ // If we have a valid message, Tweet it
396
+ // this will fail if the Tiny URL service is done
397
+ if ($message) {
398
+ // If we successfully posted this to Twitter, then we can remove it from the queue eventually
399
+ if (twit_update_status($message)) {
400
+ return true;
401
+ }
402
+ }
403
+
404
+ return false;
405
+ }
406
+
407
+ function top_get_settings() {
408
+ global $top_defaults;
409
+
410
+ $settings = $top_defaults;
411
+
412
+ $wordpress_settings = get_option('top_settings');
413
+ if ($wordpress_settings) {
414
+ foreach ($wordpress_settings as $key => $value) {
415
+ $settings[$key] = $value;
416
+ }
417
+ }
418
+
419
+ return $settings;
420
+ }
421
+
422
+ function top_save_settings($settings) {
423
+ update_option('top_settings', $settings);
424
+ }
425
+
426
+ ?>
top-excludepost.php ADDED
@@ -0,0 +1,328 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $message = null;
10
+ $message_updated = __("Tweet Old Post Options Updated.", 'TweetOldPost');
11
+ $response = null;
12
+ $records_per_page = 20;
13
+ $omit_cat=get_option('top_opt_omit_cats');
14
+ $update_text = "Exclude Selected";
15
+ $search_term="";
16
+ $ex_filter="all";
17
+ $cat_filter=0;
18
+
19
+ global $wpdb;
20
+
21
+ if ((!isset($_GET["paged"])) && (!isset($_POST["delids"]))) {
22
+ $exposts = get_option('top_opt_excluded_post');
23
+ } else {
24
+ $exposts = $_POST["delids"];
25
+ }
26
+
27
+ $exposts = preg_replace('/,,+/', ',', $exposts);
28
+ if (substr($exposts, 0, 1) == ",") {
29
+ $exposts = substr($exposts, 1, strlen($exposts));
30
+ }
31
+ if (substr($exposts, -1, 1) == ",") {
32
+ $exposts = substr($exposts, 0, strlen($exposts) - 1);
33
+ }
34
+ $excluded_posts = explode(",", $exposts);
35
+
36
+
37
+ if (!isset($_GET['paged']))
38
+ $_GET['paged'] = 1;
39
+
40
+ if (isset($_POST["excludeall"])) {
41
+ if (substr($_POST["delids"], 0, -1) == "") {
42
+ print('
43
+ <div id="message" style="margin-top:30px" class="updated fade">
44
+ <p>' . __('No post selected please select a post to be excluded.', 'TweetOldPost') . '</p>
45
+ </div>');
46
+ } else {
47
+
48
+ update_option('top_opt_excluded_post',$exposts);
49
+ print('
50
+ <div id="message" style="margin-top:30px" class="updated fade">
51
+ <p>' . __('Posts excluded successfully.', 'TweetOldPost') . '</p>
52
+ </div>');
53
+ }
54
+ }
55
+
56
+ print('
57
+ <div id="help" style="overflow: hidden;padding-left:15px; font-size: 14px; margin-top: 25px; background-color: rgb(239, 239, 239);">
58
+ <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>
59
+ </div>');
60
+
61
+ print('
62
+ <div id="help" style="overflow: hidden;padding-left:15px; font-size: 14px; margin-top: 25px;margin-bottom:25px; background-color: rgb(239, 239, 239);">
63
+ <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>
64
+ </div>');
65
+
66
+ $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'
67
+ AND post_status = 'publish'";
68
+
69
+
70
+ if(isset($_POST["setFilter"]))
71
+ {
72
+ if($_POST["cat"] != 0)
73
+ {
74
+ $sql = $sql . " and p.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=" . $_POST["cat"] . ")";
75
+ $cat_filter = $_POST["cat"];
76
+ }
77
+ else
78
+ {
79
+ $sql = $sql . " and p.ID NOT 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 (" . $omit_cat . "))";
80
+ $cat_filter = 0;
81
+ }
82
+
83
+ if($_POST["selFilter"] == "excluded")
84
+ {
85
+ $sql = $sql . " and p.ID IN (".$exposts.")";
86
+ $update_text = "Update";
87
+ $ex_filter = "excluded";
88
+ }
89
+
90
+ }
91
+ else
92
+ {
93
+ if($omit_cat !='')
94
+ {
95
+ $sql = $sql . " and p.ID NOT 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 (" . $omit_cat . "))";
96
+ }
97
+ }
98
+
99
+ if(isset($_POST["s"]))
100
+ {
101
+ if(trim( $_POST["s"]) != "")
102
+ {
103
+ $sql = $sql . " and post_title like '%" . trim( $_POST["s"]) . "%'";
104
+ $search_term = trim( $_POST["s"]);
105
+ }
106
+ }
107
+
108
+ $sql = $sql . " order by post_date desc";
109
+ $posts = $wpdb->get_results($sql);
110
+
111
+ $from = $_GET["paged"] * $records_per_page - $records_per_page;
112
+ $to = min($_GET['paged'] * $records_per_page, count($posts));
113
+ $post_count =count($posts);
114
+
115
+ $ex = 0;
116
+ for ($j = 0; $j < $post_count; $j++) {
117
+ if (in_array($posts[$j]->ID, $excluded_posts)) {
118
+ $excludeList[$ex] = $posts[$j]->ID;
119
+ $ex = $ex + 1;
120
+ }
121
+ }
122
+ if($excludeList.length >0)
123
+ {
124
+ $exposts = implode(",",$excludeList);
125
+ }
126
+ 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="" /> ');
127
+ print('<div class="tablenav"><div class="alignleft actions">');
128
+ print('<input type="submit" class="button-secondary" name="excludeall" value="' . __($update_text, 'TweetOldPost') . '" />');
129
+ 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>');
130
+ $dropdown_options = array('show_option_all' => __('Selected Categories'),'exclude' =>$omit_cat,'selected' =>$cat_filter);
131
+ wp_dropdown_categories($dropdown_options);
132
+ print('<input type="submit" class="button-secondary" name="setFilter" value="' . __('Filter', 'TweetOldPost') . '" />');
133
+ print('<p class="search-box" style="margin:0px">
134
+ <input type="text" id="post-search-input" name="s" value="'.$search_term.'" />
135
+ <input type="submit" value="Search Posts" name="search" class="button" />
136
+ </p>');
137
+ print('</div>');
138
+ if (count($posts) > 0) {
139
+ $page_links = paginate_links(array(
140
+ 'base' => add_query_arg('paged', '%#%'),
141
+ 'format' => '',
142
+ 'prev_text' => __('&laquo;'),
143
+ 'next_text' => __('&raquo;'),
144
+ 'total' => ceil(count($posts) / $records_per_page),
145
+ 'current' => $_GET['paged']
146
+ ));
147
+
148
+ if ($page_links) {
149
+
150
+ print('<div class="tablenav-pages">');
151
+ $page_links_text = sprintf('<span class="displaying-num">' . __('Displaying %s&#8211;%s of %s') . '</span>%s',
152
+ number_format_i18n(( $_GET['paged'] - 1 ) * $records_per_page + 1),
153
+ number_format_i18n(min($_GET['paged'] * $records_per_page, count($posts))),
154
+ number_format_i18n(count($posts)),
155
+ $page_links
156
+ );
157
+ echo $page_links_text;
158
+ print('</div>');
159
+ }
160
+ print('</div>');//tablenav div
161
+
162
+ print(' <div class="wrap">
163
+ <table class="widefat fixed">
164
+ <thead>
165
+ <tr>
166
+ <th class="manage-column column-cb check-column"><input name="headchkbx" onchange="javascript:checkedAll();" type="checkbox" value="checkall"/></th>
167
+ <th>No.</th>
168
+ <th>Id</th>
169
+ <th>Post Title</th>
170
+ <th>Author</th>
171
+ <th>Post Date</th>
172
+ <th>Categories</th>
173
+ </tr>
174
+ </thead>
175
+ <tbody>
176
+ ');
177
+
178
+
179
+
180
+
181
+ for ($i = $from; $i < $to; $i++) {
182
+ $categories = get_the_category($posts[$i]->ID);
183
+ if (!empty($categories)) {
184
+ $out = array();
185
+ foreach ($categories as $c)
186
+ $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>";
187
+ $cats = join(', ', $out);
188
+ } else {
189
+ $cats = 'Uncategorized';
190
+ }
191
+
192
+ if (in_array($posts[$i]->ID, $excluded_posts)) {
193
+ $checked = "Checked";
194
+ $bgcolor="#FFCC99";
195
+ } else {
196
+ $checked = "";
197
+ $bgcolor="#FFF";
198
+ }
199
+
200
+ print('
201
+
202
+ <tr style="background-color:'.$bgcolor.';">
203
+ <th class="check-column">
204
+ <input type="checkbox" name="chkbx" id="del' . $posts[$i]->ID . '" onchange="javascript:managedelid(this,\'' . $posts[$i]->ID . '\');" value="' . $posts[$i]->ID . '" ' . $checked . '/>
205
+ </th>
206
+ <td>
207
+ ' . ($i + 1) . '
208
+ </td>
209
+ <td>
210
+ ' . $posts[$i]->ID . '
211
+ </td>
212
+ <td>
213
+ <a href=' . $posts[$i]->guid . ' target="_blank">' . $posts[$i]->post_title . '</a>
214
+ </td>
215
+ <td>
216
+ ' . $posts[$i]->user_nicename . '
217
+ </td>
218
+ <td>
219
+ ' . $posts[$i]->post_date . '
220
+ </td>
221
+ <td>
222
+ ' . $cats . '
223
+ </td>
224
+ </tr>
225
+
226
+ ');
227
+ }
228
+ print('
229
+ </tbody>
230
+ </table>
231
+ </div>
232
+ ');
233
+
234
+ print('<div class="tablenav"><div class="alignleft actions"><input type="submit" class="button-secondary" name="excludeall" value="' . __($update_text, 'TweetOldPost') . '" /></div>');
235
+
236
+ if ($page_links) {
237
+
238
+ print('<div class="tablenav-pages">');
239
+ $page_links_text = sprintf('<span class="displaying-num">' . __('Displaying %s&#8211;%s of %s') . '</span>%s',
240
+ number_format_i18n(( $_GET['paged'] - 1 ) * $records_per_page + 1),
241
+ number_format_i18n(min($_GET['paged'] * $records_per_page, count($posts))),
242
+ number_format_i18n(count($posts)),
243
+ $page_links
244
+ );
245
+ echo $page_links_text;
246
+ print('</div>');
247
+ }
248
+ print('</div>');
249
+
250
+
251
+
252
+ print('
253
+ <script language="javascript">
254
+
255
+
256
+ jQuery(function() {
257
+ jQuery(".page-numbers").click(function(e){
258
+ jQuery("#top_TweetOldPost").attr("action",jQuery(this).attr("href"));
259
+ e.preventDefault();
260
+ jQuery("#pageit").click();
261
+ });// page number click end
262
+ });//jquery document.ready end
263
+
264
+ function setExcludeList(exlist)
265
+ {
266
+ jQuery("#excludeList").html("\"" + exlist + "\"");
267
+ }
268
+
269
+
270
+ function managedelid(ctrl,id)
271
+ {
272
+
273
+ var delids = document.getElementById("delids").value;
274
+ if(ctrl.checked)
275
+ {
276
+ delids=addId(delids,id);
277
+ }
278
+ else
279
+ {
280
+ delids=removeId(delids,id);
281
+ }
282
+ document.getElementById("delids").value=delids;
283
+ setExcludeList(delids);
284
+ }
285
+
286
+ function removeId(list, value) {
287
+ list = list.split(",");
288
+ if(list.indexOf(value) != -1)
289
+ list.splice(list.indexOf(value), 1);
290
+ return list.join(",");
291
+ }
292
+
293
+
294
+ function addId(list,value)
295
+ {
296
+ list = list.split(",");
297
+ if(list.indexOf(value) == -1)
298
+ list.push(value);
299
+ return list.join(",");
300
+ }
301
+
302
+ function checkedAll() {
303
+ var ischecked=document.top_TweetOldPost.headchkbx.checked;
304
+ var delids="";
305
+ for (var i = 0; i < document.top_TweetOldPost.chkbx.length; i++) {
306
+ document.top_TweetOldPost.chkbx[i].checked = ischecked;
307
+ if(ischecked)
308
+ delids=delids+document.top_TweetOldPost.chkbx[i].value+",";
309
+ }
310
+ document.getElementById("delids").value=delids;
311
+ }
312
+
313
+ setExcludeList("' . $exposts . '");
314
+
315
+ </script>
316
+ ');
317
+ }
318
+ else
319
+ {
320
+ print('</div>');//tablenav div
321
+ print('
322
+ <div id="message" style="margin-top:30px" class="updated fade">
323
+ <p>' . __('No Posts found. Review your search or filter criteria/term.', 'TweetOldPost') . '</p>
324
+ </div>');
325
+ }
326
+ print('</form>');
327
+ }
328
+ ?>
tweet-old-post.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.2.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
+
16
+ define ('top_opt_1_HOUR', 60*60);
17
+ define ('top_opt_2_HOURS', 2*top_opt_1_HOUR);
18
+ define ('top_opt_4_HOURS', 4*top_opt_1_HOUR);
19
+ define ('top_opt_8_HOURS', 8*top_opt_1_HOUR);
20
+ define ('top_opt_6_HOURS', 6*top_opt_1_HOUR);
21
+ define ('top_opt_12_HOURS', 12*top_opt_1_HOUR);
22
+ define ('top_opt_24_HOURS', 24*top_opt_1_HOUR);
23
+ define ('top_opt_48_HOURS', 48*top_opt_1_HOUR);
24
+ define ('top_opt_72_HOURS', 72*top_opt_1_HOUR);
25
+ define ('top_opt_168_HOURS', 168*top_opt_1_HOUR);
26
+ define ('top_opt_INTERVAL', 4);
27
+ define ('top_opt_INTERVAL_SLOP', 4);
28
+ define ('top_opt_AGE_LIMIT', 30); // 120 days
29
+ define ('top_opt_MAX_AGE_LIMIT', 60); // 120 days
30
+ define ('top_opt_OMIT_CATS', "");
31
+ define('top_opt_TWEET_PREFIX',"");
32
+ define('top_opt_ADD_DATA',"false");
33
+ define('top_opt_URL_SHORTENER',"is.gd");
34
+ define('top_opt_HASHTAGS',"");
35
+
36
+ global $top_db_version;
37
+ $top_db_version = "1.0";
38
+
39
+ function top_admin_actions() {
40
+ add_menu_page("Tweet Old Post", "Tweet Old Post", 1, "TweetOldPost", "top_admin");
41
+ add_submenu_page("TweetOldPost", __('Exclude Posts','TweetOldPost'), __('Exclude Posts','TweetOldPost'), 1, __('ExcludePosts','TweetOldPost'), 'top_exclude');
42
+
43
+ }
44
+
45
+ add_action('admin_menu', 'top_admin_actions');
46
+ add_action('admin_head', 'top_opt_head_admin');
47
+ add_action('init','top_tweet_old_post');
48
+
49
+ register_activation_hook(__FILE__, "top_on_activation");
50
+
51
+
52
+ function top_on_activation()
53
+ {
54
+ update_option('top_opt_interval', "4");
55
+ update_option('top_opt_interval_slop', "4");
56
+ update_option('top_opt_age_limit', "30");
57
+ update_option('top_opt_max_age_limit', "60");
58
+ }
59
+
60
+
61
+ add_filter('plugin_action_links', 'top_plugin_action_links', 10, 2);
62
+
63
+ function top_plugin_action_links($links, $file) {
64
+ static $this_plugin;
65
+
66
+ if (!$this_plugin) {
67
+ $this_plugin = plugin_basename(__FILE__);
68
+ }
69
+
70
+ if ($file == $this_plugin) {
71
+ // The "page" query string value must be equal to the slug
72
+ // of the Settings admin page we defined earlier, which in
73
+ // this case equals "myplugin-settings".
74
+ $settings_link = '<a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=TweetOldPost">Settings</a>';
75
+ array_unshift($links, $settings_link);
76
+ }
77
+
78
+ return $links;
79
+ }
80
+
81
+ ?>
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
+ ?>