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

Version Description

Download this release

Release Info

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

Version 3.3.0

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