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

Version Description

Download this release

Release Info

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

Version 3.3.3

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