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

Version Description

Download this release

Release Info

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

Version 3.2.1

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