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

Version Description

Download this release

Release Info

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

Version 3.2.7

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