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

Version Description

Download this release

Release Info

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

Code changes from version 3.3.3 to 6.7.2

Include/top-debug.php DELETED
@@ -1,60 +0,0 @@
1
- <?php
2
-
3
- function top_DEBUG( $str ) {
4
- global $top_debug;
5
- $top_enable_log = get_option('top_enable_log');
6
- if($top_enable_log)
7
- {
8
- $top_debug->enable(true);
9
- }
10
-
11
- $top_debug->add_to_log( $str );
12
- }
13
-
14
- function top_is_debug_enabled() {
15
- global $top_debug;
16
-
17
- return $top_debug->is_enabled();
18
- }
19
-
20
- class topDebug {
21
- var $debug_file;
22
- var $log_messages;
23
-
24
- function topDebug() {
25
- $this->debug_file = false;
26
- }
27
-
28
- function is_enabled() {
29
- return ( $this->debug_file );
30
- }
31
-
32
- function enable( $enable_or_disable ) {
33
- if ( $enable_or_disable ) {
34
- $this->debug_file = fopen( WP_CONTENT_DIR . '/plugins/tweet-old-post/log.txt', 'a+t' );
35
- $this->log_messages = 0;
36
- } else if ( $this->debug_file ) {
37
- fclose( $this->debug_file );
38
- $this->debug_file = false;
39
- }
40
- }
41
-
42
- function add_to_log( $str ) {
43
- if ( $this->debug_file ) {
44
-
45
- $log_string = $str;
46
-
47
- // Write the data to the log file
48
- fwrite( $this->debug_file, sprintf( "%12s %s\n", time(), $log_string ) );
49
- fflush( $this->debug_file );
50
-
51
- $this->log_messages++;
52
- }
53
- }
54
- }
55
-
56
- global $top_debug;
57
- $top_debug = &new topDebug;
58
-
59
-
60
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Include/top-oauth.php DELETED
@@ -1,391 +0,0 @@
1
- <?php
2
-
3
- if (!class_exists('WP_Http')) {
4
- include_once( ABSPATH . WPINC . '/class-http.php' );
5
- }
6
-
7
- require_once( 'top-debug.php' );
8
-
9
- define('TOP_OAUTH_CONSUMER_KEY', 'ofaYongByVpa3NDEbXa2g');
10
-
11
-
12
- define('TOP_OAUTH_REQUEST_URL', 'http://api.twitter.com/oauth/request_token');
13
- define('TOP_OAUTH_ACCESS_URL', 'http://api.twitter.com/oauth/access_token');
14
- define('TOP_OAUTH_AUTHORIZE_URL', 'http://api.twitter.com/oauth/authorize');
15
- define('TOP_OAUTH_REALM', 'http://twitter.com/');
16
-
17
- class TOPOAuth {
18
-
19
- var $duplicate_tweet;
20
- var $can_use_curl;
21
- var $response_code;
22
- var $oauth_time_offset;
23
- var $error_message;
24
- var $oauth_consumer_key;
25
- var $oauth_consumer_secret;
26
-
27
- function TOPOAuth() {
28
- $this->duplicate_tweet = false;
29
- $this->can_use_curl = true;
30
- $this->response_code = false;
31
- $this->error_message = false;
32
- $this->oauth_time_offset = 0;
33
- $this->set_defeault_oauth_tokens();
34
- }
35
-
36
- function set_defeault_oauth_tokens() {
37
- $this->oauth_consumer_key = TOP_OAUTH_CONSUMER_KEY;
38
- $this->oauth_consumer_secret = "vTzszlMujMZCY3mVtTE6WovUKQxqv3LVgiVku276M";
39
-
40
- }
41
-
42
- function set_oauth_tokens($key, $secret) {
43
- $this->oauth_consumer_key = $key;
44
- $this->oauth_consumer_secret = $secret;
45
- }
46
-
47
- function get_response_code() {
48
- return $this->response_code;
49
- }
50
-
51
- function get_error_message() {
52
- return $this->error_message;
53
- }
54
-
55
- function enable_curl($value) {
56
- $this->can_use_curl = $value;
57
- }
58
-
59
- function encode($string) {
60
- return str_replace('+', ' ', str_replace('%7E', '~', rawurlencode($string)));
61
- }
62
-
63
- function create_signature_base_string($get_method, $base_url, $params) {
64
- if ($get_method) {
65
- $base_string = "GET&";
66
- } else {
67
- $base_string = "POST&";
68
- }
69
-
70
- $base_string .= $this->encode($base_url) . "&";
71
-
72
- // Sort the parameters
73
- ksort($params);
74
-
75
- $encoded_params = array();
76
- foreach ($params as $key => $value) {
77
- $encoded_params[] = $this->encode($key) . '=' . $this->encode($value);
78
- }
79
-
80
- $base_string = $base_string . $this->encode(implode($encoded_params, "&"));
81
-
82
- TOP_DEBUG('Signature base string is: ' . $base_string);
83
- return $base_string;
84
- }
85
-
86
- function params_to_query_string($params) {
87
- $query_string = array();
88
- foreach ($params as $key => $value) {
89
- $query_string[$key] = $key . '=' . $value;
90
- }
91
-
92
- ksort($query_string);
93
-
94
- return implode('&', $query_string);
95
- }
96
-
97
- function do_get_request($url) {
98
- $request = new WP_Http;
99
- $result = $request->request($url);
100
- $this->response_code = $result['response']['code'];
101
- TOP_DEBUG('do get request returned status code of ' . $this->response_code . ' for url - ' . $url);
102
- if ($result['response']['code'] == '200') {
103
- return $result['body'];
104
- } else {
105
- return false;
106
- }
107
- }
108
-
109
- function check_rate_limit()
110
- {
111
-
112
- }
113
-
114
- function do_request($url, $oauth_header, $body_params = '') {
115
- TOP_DEBUG('Doing POST request, OAUTH header is ' . $oauth_header);
116
-
117
- if (function_exists('curl_init') && $this->can_use_curl) {
118
-
119
-
120
-
121
- $ch = curl_init($url);
122
-
123
- TOP_DEBUG('..using CURL transport');
124
-
125
- // we're doing a POST request
126
- curl_setopt($ch, CURLOPT_POST, 1);
127
-
128
- $body_array = array();
129
- foreach ($body_params as $key => $value) {
130
- $body_array[] = urlencode($key) . '=' . urlencode($value);
131
- }
132
-
133
- if (top_is_debug_enabled()) {
134
- $param_str = print_r($body_array, true);
135
- TOP_DEBUG('..POST parameters are ' . $param_str);
136
- }
137
-
138
- curl_setopt($ch, CURLOPT_POSTFIELDS, implode($body_array, '&'));
139
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: ' . $oauth_header));
140
- curl_setopt($ch, CURLOPT_TIMEOUT, 10);
141
-
142
- // Don't use this option in safe mode
143
- if (!ini_get('safe_mode')) {
144
- @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
145
-
146
- TOP_DEBUG('..CURLOPT_FOLLOWLOCATION is ON');
147
- }
148
-
149
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
150
-
151
- if (( $contents = curl_exec($ch))) {
152
- $response = curl_getinfo($ch);
153
- curl_close($ch);
154
-
155
- TOP_DEBUG('..CURL returned a status code of ' . $response['http_code']);
156
-
157
- $this->response_code = $response['http_code'];
158
- if ($response['http_code'] == 200) {
159
- return $contents;
160
- } else {
161
- TOP_DEBUG('..RESPONSE was ' . print_r($response, true));
162
-
163
- switch ($response['http_code']) {
164
- case 403:
165
- $this->duplicate_tweet = true;
166
- break;
167
- }
168
-
169
- $error_message_found = preg_match('#<error>(.*)</error>#i', $contents, $matches);
170
- if ($error_message_found) {
171
- $this->error_message = $matches[1];
172
- }
173
- }
174
- } else {
175
- TOP_DEBUG("..CURL didn't return any contents");
176
- curl_close($ch);
177
- }
178
- } else {
179
- $request = new WP_Http;
180
- TOP_DEBUG('..using WP transport');
181
- $params = array();
182
- if ($body_params) {
183
- foreach ($body_params as $key => $value) {
184
- $body_params[$key] = ( $value );
185
- }
186
-
187
- $params['body'] = $body_params;
188
- }
189
-
190
- $params['method'] = 'POST';
191
- $params['headers'] = array('Authorization' => $oauth_header);
192
-
193
- $result = $request->request($url, $params);
194
-
195
- if (!is_wp_error($result)) {
196
-
197
- TOP_DEBUG('..WP transport returned a status code of ' . $result['response']['code']);
198
-
199
- $this->response_code = $result['response']['code'];
200
-
201
- if ($result['response']['code'] == '200') {
202
- return $result['body'];
203
- } else {
204
- TOP_DEBUG('..RESPONSE was ' . print_r($result['response'], true));
205
-
206
- switch ($result['response']['code']) {
207
- case 403:
208
- $this->duplicate_tweet = true;
209
- break;
210
- }
211
-
212
- $error_message_found = preg_match('#<error>(.*)</error>#i', $result['body'], $matches);
213
- if ($error_message_found) {
214
- $this->error_message = $matches[1];
215
- }
216
- }
217
- } else {
218
- TOP_DEBUG("..WP transport returned an error, " . $result->get_error_message());
219
- }
220
- }
221
- return false;
222
- }
223
-
224
- function get_nonce() {
225
- return md5(mt_rand() + mt_rand());
226
- }
227
-
228
- function parse_params($string_params) {
229
- $good_params = array();
230
-
231
- $params = explode('&', $string_params);
232
- foreach ($params as $param) {
233
- $keyvalue = explode('=', $param);
234
- $good_params[$keyvalue[0]] = $keyvalue[1];
235
- }
236
-
237
- return $good_params;
238
- }
239
-
240
- function set_oauth_time_offset( $offset ) {
241
- $this->oauth_time_offset = $offset;
242
- }
243
-
244
- function hmac_sha1($key, $data) {
245
- if (function_exists('hash_hmac')) {
246
- $hash = hash_hmac('sha1', $data, $key, true);
247
-
248
- return $hash;
249
- } else {
250
- $blocksize = 64;
251
- $hashfunc = 'sha1';
252
- if (strlen($key) > $blocksize) {
253
- $key = pack('H*', $hashfunc($key));
254
- }
255
-
256
- $key = str_pad($key, $blocksize, chr(0x00));
257
- $ipad = str_repeat(chr(0x36), $blocksize);
258
- $opad = str_repeat(chr(0x5c), $blocksize);
259
- $hash = pack('H*', $hashfunc(( $key ^ $opad ) . pack('H*', $hashfunc(($key ^ $ipad) . $data))));
260
-
261
- return $hash;
262
- }
263
- }
264
-
265
- function do_oauth($url, $params, $token_secret = '') {
266
- $sig_string = $this->create_signature_base_string(false, $url, $params);
267
-
268
- //$hash = hash_hmac( 'sha1', $sig_string, TOP_OAUTH_CONSUMER_SECRET . '&' . $token_secret, true );
269
- $hash = $this->hmac_sha1($this->oauth_consumer_secret . '&' . $token_secret, $sig_string);
270
-
271
- $sig = base64_encode($hash);
272
-
273
- $params['oauth_signature'] = $sig;
274
-
275
- $header = "OAuth ";
276
- $all_params = array();
277
- $other_params = array();
278
- foreach ($params as $key => $value) {
279
- if (strpos($key, 'oauth_') !== false) {
280
- $all_params[] = $key . '="' . $this->encode($value) . '"';
281
- } else {
282
- $other_params[$key] = $value;
283
- }
284
- }
285
-
286
- $header .= implode($all_params, ", ");
287
-
288
- return $this->do_request($url, $header, $other_params);
289
- }
290
-
291
- function get_request_token() {
292
- $params = array();
293
-
294
- $admin_url = get_option('top_opt_admin_url');
295
- if (!isset($admin_url)) {
296
- $admin_url = top_currentPageURL();
297
- }
298
-
299
- TOP_DEBUG( 'In function get_request_token' );
300
- $params['oauth_consumer_key'] = TOP_OAUTH_CONSUMER_KEY;
301
- //$params['oauth_callback'] = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '&TOP_oauth=1';
302
- $params['oauth_callback'] = htmlentities($admin_url . '&TOP_oauth=1');
303
-
304
- $params['oauth_signature_method'] = 'HMAC-SHA1';
305
- $params['oauth_timestamp'] = time();
306
- $params['oauth_nonce'] = $this->get_nonce();
307
- $params['oauth_version'] = '1.0';
308
-
309
- if ( top_is_debug_enabled() ) {
310
- TOP_DEBUG( '..params are ' . print_r( $params, true ) );
311
- }
312
-
313
- $result = $this->do_oauth(TOP_OAUTH_REQUEST_URL, $params);
314
-
315
- if ($result) {
316
- $new_params = $this->parse_params($result);
317
- return $new_params;
318
- }
319
- }
320
-
321
- function get_access_token($token, $token_secret, $verifier) {
322
- $params = array();
323
-
324
- TOP_DEBUG( 'In function get_access_token' );
325
-
326
- $params['oauth_consumer_key'] = $this->oauth_consumer_key;
327
- $params['oauth_signature_method'] = 'HMAC-SHA1';
328
- $params['oauth_timestamp'] = time() + $this->oauth_time_offset;
329
- $params['oauth_nonce'] = $this->get_nonce();
330
- $params['oauth_version'] = '1.0';
331
- $params['oauth_token'] = $token;
332
- $params['oauth_verifier'] = $verifier;
333
-
334
- if ( top_is_debug_enabled() ) {
335
- TOP_DEBUG( '..params are ' . print_r( $params, true ) );
336
- }
337
-
338
- $result = $this->do_oauth(TOP_OAUTH_ACCESS_URL, $params, $token_secret);
339
- if ($result) {
340
- $new_params = $this->parse_params($result);
341
- return $new_params;
342
- }
343
- }
344
-
345
- function update_status($token, $token_secret, $status) {
346
- $params = array();
347
-
348
- $params['oauth_consumer_key'] =$this->oauth_consumer_key;
349
- $params['oauth_signature_method'] = 'HMAC-SHA1';
350
- $params['oauth_timestamp'] = time() + $this->oauth_time_offset;
351
- $params['oauth_nonce'] = $this->get_nonce();
352
- $params['oauth_version'] = '1.0';
353
- $params['oauth_token'] = $token;
354
- $params['status'] = $status;
355
-
356
- if ( top_is_debug_enabled() ) {
357
- TOP_DEBUG( '..params are ' . print_r( $params, true ) );
358
- }
359
-
360
- $url = 'http://api.twitter.com/1/statuses/update.xml';
361
-
362
- $result = $this->do_oauth($url, $params, $token_secret);
363
- if ($result) {
364
- $new_params = TOP_parsexml($result);
365
- return true;
366
- } else {
367
- return false;
368
- }
369
- }
370
-
371
- function was_duplicate_tweet() {
372
- return $this->duplicate_tweet;
373
- }
374
-
375
- function get_auth_url($token) {
376
- return TOP_OAUTH_AUTHORIZE_URL . '?oauth_token=' . $token;
377
- }
378
-
379
- function get_user_info($user_id) {
380
- $url = 'http://api.twitter.com/1/users/show.xml?id=' . $user_id;
381
-
382
- $result = $this->do_get_request($url);
383
- if ($result) {
384
- $new_params = TOP_parsexml($result);
385
- return $new_params;
386
- }
387
- }
388
-
389
- }
390
-
391
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
css/style.css ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Clearfix */
2
+ .clearfix:after { content: "\00A0"; display: block; clear: both; visibility: hidden; line-height: 0; height: 0;}
3
+ .clearfix{ display: inline-block;}
4
+ html[xmlns] .clearfix { display: block;}
5
+ * html .clearfix{ height: 1%;}
6
+ .clearfix { display: block; }
7
+
8
+ /* Padding Fix */
9
+ * { -webkit-box-sizing:border-box; -moz-box-sizing:border-box; box-sizing:border-box; }
10
+
11
+ /* Main Wrapper */
12
+ .cwp_top_wrapper {position: relative; width: 1080px;}
13
+
14
+ /* Tweet Old Post Status */
15
+ .cwp_top_wrapper .cwp_top_status { }
16
+ .cwp_top_wrapper .cwp_top_status p { margin: 0; padding: 10px; text-align: center; font-family: "Roboto", sans-serif; color:#fff; }
17
+ .cwp_top_wrapper .cwp_top_status p.active { background: rgb(185, 243, 203);box-shadow: inset 0px 0px 6px rgba(8, 61, 8, 0.1);border-top: 1px solid rgba(97, 209, 101, 0.4);color: #218618;font-weight: bold;text-shadow: 0px 1px 0px rgba(255,255,255,1.3);border-bottom: 1px solid #fff; }
18
+ .cwp_top_wrapper .cwp_top_status p.inactive { background: rgb(240, 240, 240);box-shadow: inset 0px 0px 6px rgba(0,0,0,0.1);border-top: 1px solid rgba(255,255,255,0.4);color: #494949;font-weight: bold;text-shadow: 0px 1px 0px rgba(255,255,255,1.3);border-bottom: 1px solid #fff; }
19
+
20
+ /* Ajax Animation */
21
+ .cwp_top_wrapper .ajaxAnimation { background: url("../img/loader.gif") no-repeat center center, rgba(255,255,255,0.8); position: absolute;top: 0; left: 0; right: 0; bottom: 0; display: none;}
22
+
23
+ /* Twitter Login Button */
24
+ .cwp_top_container button#twitter-login { background:none; border: none; background:url("../img/twitter_blue_icon.png") no-repeat left 10px center, #fff; padding: 10px 15px 10px 35px; font-weight: bold; font-family: "HelveticaNeue", "Helvetica Neue", Arial, sans-serif; font-size: 1em; line-height: 1; color:#696969; border-radius: 10px; border: 1px solid #f7f7f7; -webkit-transition: all 0.3s ease-in-out;-moz-transition: all 0.3s ease-in-out;-o-transition: all 0.3s ease-in-out;transition: all 0.3s ease-in-out; box-shadow: inset 0px 0px 3px rgba(0,0,0,0.5); }
25
+ .cwp_top_container button#twitter-login:hover { cursor: pointer; background:url("../img/twitter_blue_icon.png") no-repeat left 10px center, #f7f7f7; box-shadow: inset 0px 0px 3px rgba(0,0,0,0.5); border: 1px solid #f7f7f7; text-shadow: 0px 1px 0px rgba(255,255,255,1);}
26
+ .cwp_top_container button#twitter-login.another-account { border:1px solid #ddd; box-shadow: none; border-radius: 3px; background-image: none; display: block; padding: 0; height: 35px; width: 35px; font-weight: 100; }
27
+ .cwp_top_container button#twitter-login.another-account:hover { opacity: 0.8; }
28
+
29
+ /* Logged In User */
30
+ .cwp_top_container .user_details { height: 35px; border: 1px solid #fff; float: left; overflow: hidden; background:#fff; border: 1px solid #ddd; border-radius: 5px; margin-right: 10px;}
31
+ .cwp_top_container .user_details .user_avatar { float: left; width: 35px;}
32
+ .cwp_top_container .user_details .user_avatar img { width: 100%; }
33
+ .cwp_top_container .user_details .user_name { float: left; font-family: Roboto, "Helvetica Neue", HelveticaNeue, sans-serif; font-weight: 400; font-size:14px; line-height: 2.4; padding: 0px 10px; color:#5C5C5C; }
34
+ .cwp_top_container .user_details .remove_user { display:block; width: 35px; height: 35px; float: left; border-left: 1px solid #ddd; }
35
+ .cwp_top_container .user_details .remove_user .logout_user { display: block; width: 100%; height: 100%; background:url("../img/remove_account.png") no-repeat center center, #fff; }
36
+ .cwp_top_container .user_details .remove_user .logout_user:hover { background:url("../img/remove_account_hover.png") no-repeat center center, #fff; }
37
+
38
+ /* Announcement */
39
+ .cwp_top_wrapper .announcement { width: 100%; background: url("../img/reviewgine_announcement.png") no-repeat left -10px top -45px, #f16848; margin-top: 20px;}
40
+ .cwp_top_wrapper .announcement h2 { float: left; font-family: "Helvetica Neue", HelveticaNeue, sans-serif; color:#fff; font-weight: 100; font-size: 17px; line-height: 1; padding-left: 180px; }
41
+ .cwp_top_wrapper .announcement h2 b { font-weight: bold; }
42
+ .cwp_top_wrapper .announcement .show-me { float: right; background:#fff; border-radius: 5px; font-family: "Helvetica Neue", HelveticaNeue, sans-serif; color:#5c5c5c; text-decoration: none; text-transform: uppercase;padding: 7px 15px; margin-top: 9px; margin-right: 20px; -webkit-transition: all 0.3s ease-in-out;-moz-transition: all 0.3s ease-in-out;-o-transition: all 0.3s ease-in-out;transition: all 0.3s ease-in-out; line-height: 1;}
43
+ .cwp_top_wrapper .announcement .show-me:hover { cursor: pointer; opacity: 0.8; }
44
+
45
+ /* Header Styles */
46
+ .cwp_top_wrapper #cwp_top_header { background:#fff; border-top: 5px solid #52aae2; border-bottom: 1px solid #d4d4d4; margin-top: 10px; padding: 20px 10px;}
47
+ .cwp_top_wrapper #cwp_top_header .logo { margin: 0; padding: 0; float: left; font-family: "Open Sans", sans-serif; font-weight: bold; color:#3c3c3c; padding-left: 55px; background:url("../img/logo.png") no-repeat left center; padding: 20px; padding-left: 60px; padding-right: 0; letter-spacing: -1px; margin-left: 14px; }
48
+ .cwp_top_wrapper #cwp_top_header .slogan { float: left; margin: 0; padding: 0; font-size: 17px; color:#858585; font-family: "Open Sans", sans-serif; line-height: 3.5; margin-left: 10px; }
49
+ .cwp_top_wrapper #cwp_top_header .slogan a { color:#858585; font-weight: 600; text-decoration: none; font-style: italic; -webkit-transition: all 0.250s ease-in-out; -moz-transition: all 0.250s ease-in-out; -o-transition: all 0.250s ease-in-out; transition: all 0.250s ease-in-out; }
50
+ .cwp_top_wrapper #cwp_top_header .slogan a:hover { color:#52aae2; }
51
+
52
+ /* Header Actions */
53
+ .cwp_top_wrapper #cwp_top_header .cwp_top_actions { float: right; margin-right: 6px; }
54
+ .cwp_top_wrapper #cwp_top_header .tweet-about-it { background:#52c4ef; text-decoration: none; border-radius: 3px; display: block; height: 30px; border-radius: 3px; font-family: "Open Sans", sans-serif; color:#fff; text-transform: uppercase; font-weight: bold; text-shadow: 0px 1px 0px #33a4ce; line-height: 2.3; padding-right: 10px; display:inline-block; margin-top: 14px; margin-right: 5px; }
55
+ .cwp_top_wrapper #cwp_top_header .tweet-about-it span { background:url("../img/twitter_icon.png") no-repeat center center, #3eaed8; width: 30px; height: 30px; display: block; float: left; border-radius: 3px 0px 0px 3px; margin-right: 10px; }
56
+ .cwp_top_wrapper #cwp_top_header .leave-a-review { background:#f9866b; text-decoration: none; border-radius: 3px; display: block; height: 30px; border-radius: 3px; font-family: "Open Sans", sans-serif; color:#fff; text-transform: uppercase; font-weight: bold; text-shadow: 0px 1px 0px #e46b3d; line-height: 2.3; padding-right: 10px; display:inline-block; margin-top: 14px; margin-right: 5px; }
57
+ .cwp_top_wrapper #cwp_top_header .leave-a-review span { background:url("../img/review_icon.png") no-repeat center center, #f16848; width: 30px; height: 30px; display: block; float: left; border-radius: 3px 0px 0px 3px; margin-right: 10px; }
58
+
59
+ /* Container and form styles */
60
+ .cwp_top_wrapper .cwp_top_container { background:#f9f9f9; border-bottom: 5px solid #52aae2; position: relative;}
61
+ .cwp_top_wrapper .cwp_top_container form { width: 73%; float: left; border-right: 1px solid #d4d4d4;}
62
+ .cwp_top_wrapper .cwp_top_container form .option { width: 100%; margin: 15px 0px; }
63
+ .cwp_top_wrapper .cwp_top_container form .option .left { float: left; width: 45%; }
64
+ .cwp_top_wrapper .cwp_top_container form .option .left .select-all { float: right; background: none; border: none; background:#ddd; border-radius: 3px; padding: 5px 10px; }
65
+ .cwp_top_wrapper .cwp_top_container form .option .left .select-all:hover { cursor: pointer; }
66
+ .cwp_top_wrapper .cwp_top_container form .option label { font-family: "Helvetica Neue", HelveticaNeue, sans-serif; font-size: 15px; color:#525252; }
67
+ .cwp_top_wrapper .cwp_top_container form .option input[type=text], .cwp_top_wrapper .cwp_top_container form .option select { height: 35px; border-radius: 3px; border: 1px solid #d7d7d7; box-shadow: none; font-family: "Roboto", sans-serif; }
68
+ .cwp_top_wrapper .cwp_top_container form .option input[type=text] { width: 90%; }
69
+ .cwp_top_wrapper .cwp_top_container form .option .left * { display: block; text-align: right; }
70
+ .cwp_top_wrapper .cwp_top_container form .option .right { float: left; width: 55%; padding-left: 20px; }
71
+ .cwp_top_wrapper .cwp_top_container form .option .categories-list { padding-top: 4px; }
72
+ .cwp_top_wrapper .cwp_top_container form .option .categories-list .cwp-cat { float: left; width: 50%; margin-bottom: 5px; }
73
+ .cwp_top_wrapper .cwp_top_container form .option .categories-list .cwp-cat label { font-size: 13px; }
74
+
75
+ /* Sidebar Styles */
76
+ .cwp_top_wrapper .cwp_top_container .sidebar { float: left; width: 27%; padding: 10px}
77
+ .cwp_top_wrapper .cwp_top_container .sidebar ul { display: block; margin: 0; padding: 0; }
78
+ .cwp_top_wrapper .cwp_top_container .sidebar ul li { display: block; }
79
+ .cwp_top_wrapper .cwp_top_container .sidebar ul li.upgrade a { display: block; background:url("../img/upgrade-top.png") no-repeat top left; width: 270px; height: 101px; text-indent: -9999px; }
80
+ .cwp_top_wrapper .cwp_top_container .sidebar ul li.readythemes a { display: block; background:url("../img/top_banner_themeisle.png") no-repeat left; width: 270px; height: 101px; text-indent: -9999px; }
81
+ .cwp_top_wrapper .cwp_top_container .sidebar ul li.affiliate-readythemes a { display: block; background:url("../img/affiliate.png") no-repeat left; width: 270px; height: 101px; text-indent: -9999px; }
82
+
83
+ /* Footer Styles */
84
+ .cwp_top_wrapper .cwp_top_container .cwp_top_footer { width: 100%; background:#fff; padding: 20px 10px; border-top: 1px solid #d4d4d4;}
85
+ .cwp_top_wrapper .cwp_top_container .cwp_top_footer .update-options { background:#707070; text-decoration: none; border-radius: 3px; display: block; height: 30px; border-radius: 3px; font-family: "Open Sans", sans-serif; color:#fff; text-transform: uppercase; font-weight: bold; line-height: 2.3; padding-right: 10px; display:inline-block; margin-top: 14px; margin-right: 5px; }
86
+ .cwp_top_wrapper .cwp_top_container .cwp_top_footer .update-options span { background:url("../img/update_icon.png") no-repeat center center, #464646; width: 30px; height: 30px; display: block; float: left; border-radius: 3px 0px 0px 3px; margin-right: 10px; }
87
+
88
+ /* Tweet Now Button Style */
89
+ .cwp_top_wrapper .cwp_top_container .cwp_top_footer .tweet-now { background:#52c4ef; text-decoration: none; border-radius: 3px; display: block; height: 30px; border-radius: 3px; font-family: "Open Sans", sans-serif; color:#fff; text-transform: uppercase; font-weight: bold; line-height: 2.3; padding-right: 10px; display:inline-block; margin-top: 14px; margin-right: 5px; }
90
+ .cwp_top_wrapper .cwp_top_container .cwp_top_footer .tweet-now span { background:url("../img/twitter_icon.png") no-repeat center center, #3eaed8; width: 30px; height: 30px; display: block; float: left; border-radius: 3px 0px 0px 3px; margin-right: 10px; }
91
+
92
+ /* Stop Tweet Button Styles */
93
+ .cwp_top_wrapper .cwp_top_container .cwp_top_footer .stop-tweet-old-post { background:#f9866b; text-decoration: none; border-radius: 3px; display: block; height: 30px; border-radius: 3px; font-family: "Open Sans", sans-serif; color:#fff; text-transform: uppercase; font-weight: bold; line-height: 2.3; padding-right: 10px; display:inline-block; margin-top: 14px; margin-right: 5px; }
94
+ .cwp_top_wrapper .cwp_top_container .cwp_top_footer .stop-tweet-old-post span { background:url("../img/twitter_icon.png") no-repeat center center, #f16848; width: 30px; height: 30px; display: block; float: left; border-radius: 3px 0px 0px 3px; margin-right: 10px; }
95
+
96
+ /* Tweet Now Button Style */
97
+ .cwp_top_wrapper .cwp_top_container .cwp_top_footer .see-sample-tweet { background:#52c4ef; text-decoration: none; border-radius: 3px; display: block; height: 30px; border-radius: 3px; font-family: "Open Sans", sans-serif; color:#fff; text-transform: uppercase; font-weight: bold; line-height: 2.3; padding-right: 10px; display:inline-block; margin-top: 14px; margin-right: 5px; }
98
+ .cwp_top_wrapper .cwp_top_container .cwp_top_footer .see-sample-tweet span { background:url("../img/twitter_icon.png") no-repeat center center, #3eaed8; width: 30px; height: 30px; display: block; float: left; border-radius: 3px 0px 0px 3px; margin-right: 10px; }
99
+
100
+ /* Reset Settings Button Styles */
101
+ .cwp_top_wrapper .cwp_top_container .cwp_top_footer .reset-settings { background:#f9866b; text-decoration: none; border-radius: 3px; display: block; height: 30px; border-radius: 3px; font-family: "Open Sans", sans-serif; color:#fff; text-transform: uppercase; font-weight: bold; line-height: 2.3; padding-right: 10px; display:inline-block; margin-top: 14px; margin-right: 5px; }
102
+ .cwp_top_wrapper .cwp_top_container .cwp_top_footer .reset-settings span { background:url("../img/reset_icon.png") no-repeat center center, #f16848; width: 30px; height: 30px; display: block; float: left; border-radius: 3px 0px 0px 3px; margin-right: 10px; }
103
+ .cwp_top_wrapper .cwp_top_container .cwp_top_footer a { margin: 0 !important; padding: 0; margin-right: 10px !important; }
104
+
105
+ /* Sample Tweet Preview Modal */
106
+ .cwp_top_wrapper .cwp_sample_tweet_preview { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background:rgba(0,0,0,0.2); display: none; }
107
+ .cwp_top_wrapper .cwp_sample_tweet_preview .cwp_sample_tweet_preview_inner h2 { text-align: center; font-weight: bold;color:#7d7d7d; font-family: "HelveticaNeue", "Helvetica Neue", sans-serif; }
108
+ .cwp_top_wrapper .cwp_sample_tweet_preview .cwp_sample_tweet_preview_inner { background:#fff; width: 60%; margin: 0 auto; margin-top: 759px; padding: 20px; border-radius: 5px;box-shadow: 0px 5px 5px rgba(0,0,0,0.1); }
109
+ .cwp_top_wrapper .cwp_sample_tweet_preview .cwp_sample_tweet_preview_inner .sample_tweet { min-height:60px; display: block; width: 100%; border: 1px solid #e8e8e8; padding: 10px; border-radius: 5px; font-family: "Helvetica Neue", HelveticaNeue, sans-serif; font-size: 14px;}
110
+ .cwp_top_wrapper .cwp_sample_tweet_preview .cwp_sample_tweet_preview_inner .sample_tweet a { text-decoration: none; }
111
+ .cwp_top_wrapper .cwp_sample_tweet_preview .cwp_sample_tweet_preview_inner button { display: block; margin: 0 auto; margin-top: 17px; background:#52c4ef; border: none; border-radius: 3px; padding: 5px 10px; color:#fff; font-family: "Open Sans", sans-serif; color:#fff; text-transform: uppercase; font-weight: bold; }
112
+ .cwp_top_wrapper .cwp_sample_tweet_preview .cwp_sample_tweet_preview_inner button:hover { cursor: pointer; }
113
+ .top_preview {
114
+ width: 40px;
115
+ height: 40px;
116
+ padding: 5px;
117
+ float: left;}
118
+ .cwp_top_wrapper_full {
119
+
120
+ width: 90%;
121
+ float: left;
122
+ border-right: none;
123
+ margin: 5px 15px 2px;
124
+ }
125
+
126
+ .cwp_top_wrapper_full .cwp_top_container form {
127
+
128
+ width: 99%;
129
+ float: left;
130
+ border-right: none;
131
+ }
css/tweet-old-post.css DELETED
@@ -1,76 +0,0 @@
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
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
img/affiliate.png ADDED
Binary file
img/loader.gif ADDED
Binary file
img/logo.png ADDED
Binary file
img/note_icon.png ADDED
Binary file
img/remove_account.png ADDED
Binary file
img/remove_account_hover.png ADDED
Binary file
img/reset_icon.png ADDED
Binary file
img/review_icon.png ADDED
Binary file
img/reviewgine_announcement.png ADDED
Binary file
img/top_banner_themeisle.png ADDED
Binary file
{images → img}/twitter.png RENAMED
File without changes
img/twitter_blue_icon.png ADDED
Binary file
img/twitter_icon.png ADDED
Binary file
img/update_icon.png ADDED
Binary file
img/upgrade-top.png ADDED
Binary file
inc/class-remote-notification-client.php ADDED
@@ -0,0 +1,340 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Remote Dashobard Notifications.
4
+ *
5
+ * This class is part of the Remote Dashboard Notifications plugin.
6
+ * This plugin allows you to send notifications to your client's
7
+ * WordPress dashboard easily.
8
+ *
9
+ * Notification you send will be displayed as admin notifications
10
+ * using the standard WordPress hooks. A "dismiss" option is added
11
+ * in order to let the user hide the notification.
12
+ *
13
+ * @package Remote Dashboard Notifications
14
+ * @author ThemeAvenue <web@themeavenue.net>
15
+ * @license GPL-2.0+
16
+ * @link http://themeavenue.net
17
+ * @link http://wordpress.org/plugins/remote-dashboard-notifications/
18
+ * @link https://github.com/ThemeAvenue/Remote-Dashboard-Notifications
19
+ * @copyright 2014 ThemeAvenue
20
+ */
21
+
22
+ // If this file is called directly, abort.
23
+ if ( ! defined( 'WPINC' ) ) {
24
+ die;
25
+ }
26
+
27
+ class TAV_Remote_Notification_Client {
28
+
29
+ /**
30
+ * Class version.
31
+ *
32
+ * @since 0.1.0
33
+ *
34
+ * @var string
35
+ */
36
+ protected static $version = '0.1.1';
37
+
38
+ public function __construct( $channel_id = false, $channel_key = false, $server = false ) {
39
+
40
+ /* Don't continue during Ajax process */
41
+ if( !is_admin() || defined( 'DOING_AJAX' ) && DOING_AJAX )
42
+ return;
43
+
44
+ $this->id = intval( $channel_id );
45
+ $this->key = sanitize_key( $channel_key );
46
+ $this->server = esc_url( $server );
47
+ $this->notice = false;
48
+ $this->cache = apply_filters( 'rn_notice_caching_time', 6 );
49
+
50
+ /* The plugin can't work without those 2 parameters */
51
+ if( false === ( $this->id || $this->key || $this->server ) )
52
+ return;
53
+
54
+ /* Call the dismiss method before testing for Ajax */
55
+ if( isset( $_GET['rn'] ) && isset( $_GET['notification'] ) )
56
+ add_action( 'init', array( $this, 'dismiss' ) );
57
+
58
+ add_action( 'init', array( $this, 'request_server' ) );
59
+
60
+ }
61
+
62
+ /**
63
+ * Send a request to notification server
64
+ *
65
+ * The distant WordPress notification server is
66
+ * queried using the WordPress HTTP API.
67
+ *
68
+ * @since 0.1.0
69
+ */
70
+ public function request_server() {
71
+
72
+ /* Content is false at first */
73
+ $content = get_transient( 'rn_last_notification' );
74
+
75
+ /* Set the request response to null */
76
+ $request = null;
77
+
78
+ /* If no notice is present in DB we query the server */
79
+ if( false === $content || defined( 'RDN_DEV' ) && RDN_DEV ) {
80
+
81
+ /* Prepare the payload to send to server */
82
+ $payload = base64_encode( json_encode( array( 'channel' => $this->id, 'key' => $this->key ) ) );
83
+
84
+ /* Get the endpoint URL ready */
85
+ $url = add_query_arg( array( 'payload' => $payload ), $this->server );
86
+
87
+ /* Query the server */
88
+ $request = wp_remote_get( $url, array( 'timeout' => apply_filters( 'rn_http_request_timeout', 5 ) ) );
89
+
90
+ /* If we have a WP_Error object we abort */
91
+ if( is_wp_error( $request ) )
92
+ return;
93
+
94
+ /* Check if we have a valid response */
95
+ if( is_array( $request ) && isset( $request['response']['code'] ) && 200 === intval( $request['response']['code'] ) ) {
96
+
97
+ /* Get the response body */
98
+ if( isset( $request['body'] ) ) {
99
+
100
+ /**
101
+ * Decode the response JSON string
102
+ */
103
+ $content = json_decode( $request['body'] );
104
+
105
+ /**
106
+ * Check if the payload is in a usable JSON format
107
+ */
108
+ if( version_compare( phpversion(), '5.3.0', '>=' ) ) {
109
+
110
+ if( ! ( json_last_error() == JSON_ERROR_NONE ) )
111
+ return false;
112
+
113
+ } else {
114
+
115
+ if( $content == NULL )
116
+ return false;
117
+
118
+ }
119
+
120
+ set_transient( 'rn_last_notification', $content, $this->cache*60*60 );
121
+
122
+ }
123
+
124
+ }
125
+
126
+ }
127
+
128
+ /**
129
+ * If the JSON string has been decoded we can go ahead
130
+ */
131
+ if( is_object( $content ) ) {
132
+
133
+ if( isset( $content->error ) )
134
+ return;
135
+
136
+ $this->notice = $content;
137
+
138
+ /**
139
+ * Check if notice has already been dismissed
140
+ */
141
+ $dismissed = get_option( '_rn_dismissed' );
142
+
143
+ if( is_array( $dismissed ) && in_array( $content->slug, $dismissed ) )
144
+ return;
145
+
146
+ /**
147
+ * Add the notice style
148
+ */
149
+ add_action( 'admin_print_styles', array( $this, 'style' ), 100 );
150
+
151
+ /**
152
+ * Add the notice to WP dashboard
153
+ */
154
+ add_action( 'admin_notices', array( $this, 'show_notice' ) );
155
+
156
+ } else {
157
+
158
+ return false;
159
+
160
+ }
161
+
162
+ }
163
+
164
+ /**
165
+ * Display the admin notice
166
+ *
167
+ * The function will do some checks to verify if
168
+ * the notice can be displayed on the current page.
169
+ * If all the checks are passed, the notice
170
+ * is added to the page.
171
+ *
172
+ * @since 0.1.0
173
+ */
174
+ public function show_notice() {
175
+
176
+ $content = $this->notice;
177
+
178
+ /* If there is no content we abort */
179
+ if( false === $content )
180
+ return;
181
+
182
+ /* If the type array isn't empty we have a limitation */
183
+ if( isset( $content->type ) && is_array( $content->type ) && !empty( $content->type ) ) {
184
+
185
+ /* Get current post type */
186
+ $pt = get_post_type();
187
+
188
+ /**
189
+ * If the current post type can't be retrieved
190
+ * or if it's not in the allowed post types,
191
+ * then we don't display the admin notice.
192
+ */
193
+ if( false === $pt || !in_array( $pt, $content->type ) )
194
+ return;
195
+
196
+ }
197
+
198
+ /* Prepare alert class */
199
+ $style = isset( $content->style ) ? $content->style : 'updated';
200
+
201
+ if( 'updated' == $style )
202
+ $class = $style;
203
+
204
+ elseif( 'error' == $style )
205
+ $class = 'updated error';
206
+
207
+ else
208
+ $class = "updated rn-alert rn-alert-$style";
209
+
210
+ /**
211
+ * Prepare the dismiss URL
212
+ *
213
+ * @var (string) URL
214
+ * @todo get a more accurate URL of the current page
215
+ */
216
+ $args = array();
217
+ $nonce = wp_create_nonce( 'rn-dismiss' );
218
+ $slug = $content->slug;
219
+
220
+ array_push( $args, "rn=$nonce" );
221
+ array_push( $args, "notification=$slug" );
222
+
223
+ foreach( $_GET as $key => $value ) {
224
+
225
+ array_push( $args, "$key=$value" );
226
+
227
+ }
228
+
229
+ $args = implode( '&', $args );
230
+ $url = "?$args";
231
+ ?>
232
+
233
+ <div class="<?php echo $class; ?>">
234
+ <?php if( !in_array( $style, array( 'updated', 'error' ) ) ): ?><a href="<?php echo $url; ?>" id="rn-dismiss" class="rn-dismiss-btn" title="<?php _e( 'Dismiss notification', 'remote-notifications' ); ?>">&times;</a><?php endif; ?>
235
+ <p><?php echo html_entity_decode( $content->message ); ?></p>
236
+ <?php if( in_array( $style, array( 'updated', 'error' ) ) ): ?><p><a href="<?php echo $url; ?>" id="rn-dismiss" class="rn-dismiss-button button-secondary"><?php _e( 'Dismiss', 'remote-notifications' ); ?></a></p><?php endif; ?>
237
+ </div>
238
+ <?php
239
+
240
+ }
241
+
242
+ /**
243
+ * Dismiss notice
244
+ *
245
+ * When the user dismisses a notice, its slug
246
+ * is added to the _rn_dismissed entry in the DB options table.
247
+ * This entry is then used to check if a notie has been dismissed
248
+ * before displaying it on the dashboard.
249
+ *
250
+ * @since 0.1.0
251
+ */
252
+ public function dismiss() {
253
+
254
+ /* Check if we have all the vars */
255
+ if( !isset( $_GET['rn'] ) || !isset( $_GET['notification'] ) )
256
+ return;
257
+
258
+ /* Validate nonce */
259
+ if( !wp_verify_nonce( sanitize_key( $_GET['rn'] ), 'rn-dismiss' ) )
260
+ return;
261
+
262
+ /* Get dismissed list */
263
+ $dismissed = get_option( '_rn_dismissed', array() );
264
+
265
+ /* Add the current notice to the list if needed */
266
+ if( is_array( $dismissed ) && !in_array( $_GET['notification'], $dismissed ) )
267
+ array_push( $dismissed, $_GET['notification'] );
268
+
269
+ /* Update option */
270
+ update_option( '_rn_dismissed', $dismissed );
271
+
272
+ /* Get redirect URL */
273
+ $args = array();
274
+
275
+ /* Get URL args */
276
+ foreach( $_GET as $key => $value ) {
277
+
278
+ if( in_array( $key, array( 'rn', 'notification' ) ) )
279
+ continue;
280
+
281
+ array_push( $args, "$key=$value" );
282
+
283
+ }
284
+
285
+ $args = implode( '&', $args );
286
+ $url = "?$args";
287
+
288
+ /* Redirect */
289
+ wp_redirect( $url );
290
+
291
+ }
292
+
293
+ /**
294
+ * Adds inline style for non standard notices
295
+ *
296
+ * This function will only be called if the notice style is not standard.
297
+ *
298
+ * @since 0.1.0
299
+ */
300
+ public function style() { ?>
301
+
302
+ <style type="text/css">div.rn-alert{padding:15px;padding-right:35px;margin-bottom:20px;border:1px solid transparent;-webkit-box-shadow:none;box-shadow:none}div.rn-alert p:empty{display:none}div.rn-alert ul,div.rn-alert ul li,div.rn-alert ol,div.rn-alert ol li{list-style:inherit !important}div.rn-alert ul,div.rn-alert ol{padding-left:30px}div.rn-alert hr{-moz-box-sizing:content-box;box-sizing:content-box;height:0;margin-top:20px;margin-bottom:20px;border:0;border-top:1px solid #eee}div.rn-alert h1,h2,h3,h4,h5,h6{margin-top:0;color:inherit}div.rn-alert a{font-weight:700}div.rn-alert a:hover{text-decoration:underline}div.rn-alert>p{margin:0;padding:0;line-height:1}div.rn-alert>p,div.rn-alert>ul{margin-bottom:0}div.rn-alert>p+p{margin-top:5px}div.rn-alert .rn-dismiss-btn{font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;position:relative;top:-2px;right:-21px;padding:0;cursor:pointer;background:0;border:0;-webkit-appearance:none;float:right;font-size:21px;font-weight:700;line-height:1;color:#000;text-shadow:0 1px 0 #fff;opacity:.2;filter:alpha(opacity=20);text-decoration:none}div.rn-alert-success{background-color:#dff0d8;border-color:#d6e9c6;color:#3c763d}div.rn-alert-success hr{border-top-color:#c9e2b3}div.rn-alert-success a{color:#2b542c}div.rn-alert-info{background-color:#d9edf7;border-color:#bce8f1;color:#31708f}div.rn-alert-info hr{border-top-color:#a6e1ec}div.rn-alert-info a{color:#245269}div.rn-alert-warning{background-color:#fcf8e3;border-color:#faebcc;color:#8a6d3b}div.rn-alert-warning hr{border-top-color:#f7e1b5}div.rn-alert-warning a{color:#66512c}div.rn-alert-danger{background-color:#f2dede;border-color:#ebccd1;color:#a94442}div.rn-alert-danger hr{border-top-color:#e4b9c0}div.rn-alert-danger a{color:#843534}</style>
303
+
304
+ <?php }
305
+
306
+ /**
307
+ * Dismiss notice using Ajax
308
+ *
309
+ * This function is NOT used. Testing only.
310
+ */
311
+ public function script() {
312
+
313
+ $url = admin_url();
314
+ ?>
315
+
316
+ <script type="text/javascript">
317
+ jQuery(document).ready(function($) {
318
+
319
+ var prout = 'prout';
320
+
321
+ $('#rn-dismiss').on('click', function(event) {
322
+ event.preventDefault();
323
+ $.ajax({
324
+ type: "GET",
325
+ url: <?php echo $url; ?>,
326
+ data: prout
327
+ });
328
+ console.log('clicked');
329
+ });
330
+
331
+ return false;
332
+
333
+ });
334
+ </script>
335
+
336
+ <?php
337
+
338
+ }
339
+
340
+ }
inc/config.php ADDED
@@ -0,0 +1,360 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ define("CURRENTURL", top_current_page());
3
+ define("CWP_TEXTDOMAIN", "TweetOldPost");
4
+ define("SETTINGSURL", admin_url('admin.php?page=TweetOldPost'));
5
+
6
+ // Settings Array
7
+ $cwp_top_settings = array(
8
+ 'name' => __("Tweet Old Post", CWP_TEXTDOMAIN),
9
+ 'slug' => "TweetOldPost",
10
+ 'oAuth_settings' => array( // Based on TOP Dev Application settings.
11
+ 'oauth_access_token' => "2256465193-KDpAFIYfxpWugX2OU025b1CPs3WB0RJpgA4Gd4h",
12
+ 'oauth_access_token_secret' => "abx4Er8qEJ4jI7XDW8a90obzgy8cEtovPXCUNSjmwlpb9",
13
+ 'consumer_key' => "ofaYongByVpa3NDEbXa2g",
14
+ 'consumer_secret' => "vTzszlMujMZCY3mVtTE6WovUKQxqv3LVgiVku276M"
15
+ )
16
+ );
17
+
18
+
19
+ // Options Array
20
+ $cwp_top_fields = array(
21
+
22
+ 'tweet-content' => array(
23
+ 'id' => '1',
24
+ 'name' => __('Tweet Content', CWP_TEXTDOMAIN),
25
+ 'type' => 'select',
26
+ 'slug' => 'tweet-content',
27
+ 'option' => 'top_opt_tweet_type',
28
+ 'description' => __('What do you want to share?', CWP_TEXTDOMAIN),
29
+ 'options' => array(
30
+ 'title' => __('Title Only', CWP_TEXTDOMAIN),
31
+ 'body' => __('Body Only', CWP_TEXTDOMAIN),
32
+ 'titlenbody' => __('Title & Body', CWP_TEXTDOMAIN),
33
+ 'custom-field' => __('Custom Field', CWP_TEXTDOMAIN)
34
+ )
35
+ ),
36
+
37
+ 'tweet-content-field' => array(
38
+ 'id' => '2',
39
+ 'name' => __('Tweet Content Custom Field', CWP_TEXTDOMAIN),
40
+ 'type' => 'text',
41
+ 'slug' => 'tweet-content-field',
42
+ 'option' => 'top_opt_tweet_type_custom_field',
43
+ 'description' => __('Which custom field do you want to fetch info from?', CWP_TEXTDOMAIN),
44
+ 'options' => array()
45
+ ),
46
+
47
+ 'additional-text' => array(
48
+ 'id' => '3',
49
+ 'name' => __('Additional Text', CWP_TEXTDOMAIN),
50
+ 'type' => 'text',
51
+ 'slug' => 'additional-text',
52
+ 'option' => 'top_opt_add_text',
53
+ 'description' => __('Text added to your auto posts', CWP_TEXTDOMAIN),
54
+ 'options' => array()
55
+ ),
56
+
57
+ 'additional-text-at' => array(
58
+ 'id' => '4',
59
+ 'name' => __('Additional Text At', CWP_TEXTDOMAIN),
60
+ 'type' => 'select',
61
+ 'slug' => 'additional-text-at',
62
+ 'option' => 'top_opt_add_text_at',
63
+ 'description' => __('Where do you want the text to be added?', CWP_TEXTDOMAIN),
64
+ 'options' => array(
65
+ 'beginning' => __('Beginning of Tweet', CWP_TEXTDOMAIN),
66
+ 'end' => __('End of Tweet', CWP_TEXTDOMAIN)
67
+ )
68
+ ),
69
+
70
+ 'include-link' => array(
71
+ 'id' => '5',
72
+ 'name' => __('Include Link', CWP_TEXTDOMAIN),
73
+ 'type' => 'select',
74
+ 'slug' => 'include-link',
75
+ 'option' => 'top_opt_include_link',
76
+ 'description' => __('Include a link to your post?', CWP_TEXTDOMAIN),
77
+ 'options' => array(
78
+ 'true' => __('Yes', CWP_TEXTDOMAIN),
79
+ 'false' => __('No', CWP_TEXTDOMAIN)
80
+ )
81
+ ),
82
+
83
+ 'url-from-custom-field' => array(
84
+ 'id' => '6',
85
+ 'name' => __('Fetch URL From Custom Field', CWP_TEXTDOMAIN),
86
+ 'type' => 'checkbox',
87
+ 'slug' => 'url-from-custom-field',
88
+ 'option' => 'top_opt_custom_url_option',
89
+ 'description' => __('URL will be fetched from a custom field.', CWP_TEXTDOMAIN),
90
+ 'options' => ''
91
+ ),
92
+
93
+ 'custom-field-url' => array(
94
+ 'id' => '7',
95
+ 'name' => __('URL Custom Field', CWP_TEXTDOMAIN),
96
+ 'type' => 'text',
97
+ 'slug' => 'custom-field-url',
98
+ 'option' => 'top_opt_custom_url_field',
99
+ 'description' => __('URL will be fetched from the specified custom field.', CWP_TEXTDOMAIN),
100
+ 'options' => array()
101
+ ),
102
+
103
+ 'use-url-shortner' => array(
104
+ 'id' => '8',
105
+ 'name' => __('Use URL Shortner', CWP_TEXTDOMAIN),
106
+ 'type' => 'checkbox',
107
+ 'slug' => 'use-url-shortner',
108
+ 'option' => 'top_opt_use_url_shortner',
109
+ 'description' => '',
110
+ 'options' => '',
111
+ ),
112
+
113
+
114
+
115
+ 'url-shortner' => array(
116
+ 'id' => '9',
117
+ 'name' => __('URL Shortner Service', CWP_TEXTDOMAIN),
118
+ 'type' => 'select',
119
+ 'slug' => 'url-shortner',
120
+ 'option' => 'top_opt_url_shortner',
121
+ 'description' => __('Shorten the link to your post.', CWP_TEXTDOMAIN),
122
+ 'options' => array(
123
+ 'wp_short_url' => __('wp short url', CWP_TEXTDOMAIN),
124
+ //'t.co' => __('t.co', CWP_TEXTDOMAIN),
125
+ 'is.gd' => __('is.gd', CWP_TEXTDOMAIN),
126
+ 'bit.ly' => __('bit.ly', CWP_TEXTDOMAIN),
127
+ //'tr.im' => __('tr.im', CWP_TEXTDOMAIN),
128
+ //'3.ly' => __('3.ly', CWP_TEXTDOMAIN),
129
+ //'u.nu' => __('u.nu', CWP_TEXTDOMAIN),
130
+ //'1click.at' => __('1click.at', CWP_TEXTDOMAIN),
131
+ //'tinyurl' => __('TinyUrl', CWP_TEXTDOMAIN)
132
+
133
+ )
134
+ ),
135
+
136
+ 'bitly-key' => array(
137
+ 'id' => '22',
138
+ 'name' => __('Bitly Key', CWP_TEXTDOMAIN),
139
+ 'type' => 'text',
140
+ 'slug' => 'bitly-key',
141
+ 'option' => 'top_opt_bitly_key',
142
+ 'description' => '',
143
+ 'options' => '',
144
+ ),
145
+
146
+ 'bitly-user' => array(
147
+ 'id' => '23',
148
+ 'name' => __('Bitly User', CWP_TEXTDOMAIN),
149
+ 'type' => 'text',
150
+ 'slug' => 'bitly-user',
151
+ 'option' => 'top_opt_bitly_user',
152
+ 'description' => '',
153
+ 'options' => '',
154
+ ),
155
+
156
+ 'custom-hashtag-option' => array(
157
+ 'id' => '10',
158
+ 'name' => __('Hashtags', CWP_TEXTDOMAIN),
159
+ 'type' => 'select',
160
+ 'slug' => 'custom-hashtag-option',
161
+ 'option' => 'top_opt_custom_hashtag_option',
162
+ 'description' => __('Include #hashtags in your auto posts?', CWP_TEXTDOMAIN),
163
+ 'options' => array(
164
+ 'nohashtag' => __('Don\'t add any hashtags', CWP_TEXTDOMAIN),
165
+ 'common' => __('Common hashtags for all tweets', CWP_TEXTDOMAIN),
166
+ 'categories'=> __('Create hashtags from Categories', CWP_TEXTDOMAIN),
167
+ 'tags' => __('Create hashtags from Tags', CWP_TEXTDOMAIN),
168
+ 'custom' => __('Create hashtags from Custom Fields', CWP_TEXTDOMAIN)
169
+ )
170
+ ),
171
+
172
+ 'common-hashtags' => array(
173
+ 'id' => '11',
174
+ 'name' => __('Common Hashtags', CWP_TEXTDOMAIN),
175
+ 'type' => 'text',
176
+ 'slug' => 'common-hashtags',
177
+ 'option' => 'top_opt_hashtags',
178
+ 'description' => __('Specify which hashtags you want to be used. eg. #example, #example2', CWP_TEXTDOMAIN),
179
+ 'options' => array()
180
+ ),
181
+
182
+ 'hashtags-length' => array(
183
+ 'id' => '12',
184
+ 'name' => __('Maximum Hashtags Length', CWP_TEXTDOMAIN),
185
+ 'type' => 'text',
186
+ 'slug' => 'hashtags-length',
187
+ 'option' => 'top_opt_hashtag_length',
188
+ 'description' => __('Set to 0 (characters) to include all.', CWP_TEXTDOMAIN),
189
+ 'options' => array()
190
+ ),
191
+
192
+ 'custom-hashtag-field' => array(
193
+ 'id' => '13',
194
+ 'name' => __('Hashtag Custom Field', CWP_TEXTDOMAIN),
195
+ 'type' => 'text',
196
+ 'slug' => 'custom-hashtag-field',
197
+ 'option' => 'top_opt_custom_hashtag_field',
198
+ 'description' => __('Fetch hashtags from specified custom field', CWP_TEXTDOMAIN),
199
+ 'options' => array()
200
+ ),
201
+
202
+ 'interval' => array(
203
+ 'id' => '14',
204
+ 'name' => __('Minimum interval between tweets', CWP_TEXTDOMAIN),
205
+ 'type' => 'text',
206
+ 'slug' => 'interval',
207
+ 'option' => 'top_opt_interval',
208
+ 'description' => __('Minimum time between tweets (Hour/Hours).', CWP_TEXTDOMAIN),
209
+ 'options' => array()
210
+ ),
211
+
212
+ 'age-limit' => array(
213
+ 'id' => '15',
214
+ 'name' => __('Minimum age of post to be eligible for tweet', CWP_TEXTDOMAIN),
215
+ 'type' => 'text',
216
+ 'slug' => 'age-limit',
217
+ 'option' => 'top_opt_age_limit',
218
+ 'description' => __('Day/Days - 0 for Disabled', CWP_TEXTDOMAIN),
219
+ 'options' => array()
220
+ ),
221
+
222
+ 'max-age-limit' => array(
223
+ 'id' => '16',
224
+ 'name' => __('Maximum age of post to be eligible for tweet', CWP_TEXTDOMAIN),
225
+ 'type' => 'text',
226
+ 'slug' => 'max-age-limit',
227
+ 'option' => 'top_opt_max_age_limit',
228
+ 'description' => __('Day/Days - 0 for Disabled', CWP_TEXTDOMAIN),
229
+ 'options' => array()
230
+ ),
231
+
232
+ 'no-of-tweet' => array(
233
+ 'id' => '17',
234
+ 'name' => __('Number of Posts to Tweet', CWP_TEXTDOMAIN),
235
+ 'type' => 'text',
236
+ 'slug' => 'no-of-tweet',
237
+ 'option' => 'top_opt_no_of_tweet',
238
+ 'description' => __('Number of posts to share each time', CWP_TEXTDOMAIN),
239
+ 'options' => array()
240
+ ),
241
+
242
+ 'post-type' => array(
243
+ 'id' => '18',
244
+ 'name' => __('Post Type', CWP_TEXTDOMAIN),
245
+ 'type' => 'select',
246
+ 'slug' => 'post-type',
247
+ 'option' => 'top_opt_post_type',
248
+ 'description' => __('What type of items do you want to share?', CWP_TEXTDOMAIN),
249
+ 'options' => array(
250
+ 'post' => __('Post Only', CWP_TEXTDOMAIN),
251
+ 'page' => __('Page Only', CWP_TEXTDOMAIN),
252
+ 'custom-post-type' => __('Custom Post Type', CWP_TEXTDOMAIN),
253
+ 'both' => __('Post and Page', CWP_TEXTDOMAIN),
254
+ )
255
+ ),
256
+
257
+ 'post-type-value' => array(
258
+ 'id' => '19',
259
+ 'name' => __('Custom Post Type', CWP_TEXTDOMAIN),
260
+ 'type' => 'custom-post-type',
261
+ 'slug' => 'post-type-value',
262
+ 'option' => 'top_opt_post_type_value',
263
+ 'description' => __('Select which custom post type', CWP_TEXTDOMAIN),
264
+ 'options' => array()
265
+ ),
266
+
267
+ 'use-image' => array(
268
+ 'id' => '24',
269
+ 'name' => __('Post with Image', CWP_TEXTDOMAIN),
270
+ 'type' => 'checkbox',
271
+ 'slug' => 'post-with-image',
272
+ 'option' => 'top_opt_post_with_image',
273
+ 'description' => __('Check if you want to add the post featured image to the tweet', CWP_TEXTDOMAIN),
274
+ 'options' => array()
275
+ ),
276
+
277
+ 'tweet-multiple-times' => array(
278
+ 'id' => '24',
279
+ 'name' => __('Tweet old posts more than once', CWP_TEXTDOMAIN),
280
+ 'type' => 'checkbox',
281
+ 'slug' => 'tweet-multiple-times',
282
+ 'option' => 'top_opt_tweet_multiple_times',
283
+ 'description' => __('By default once a post is tweeted it will not be tweeted again until you stop/start the plugin', CWP_TEXTDOMAIN),
284
+ 'options' => array()
285
+ ),
286
+
287
+ /*'tweet-specific-category' => array(
288
+ 'id' => '20',
289
+ 'name' => __('Tweet From Specific Categories', CWP_TEXTDOMAIN),
290
+ 'type' => 'categories-list',
291
+ 'slug' => 'tweet-specific-category',
292
+ 'option' => 'top_opt_tweet_specific_category',
293
+ 'description' => __('Select which categories do you want to tweet from? Blank - All', CWP_TEXTDOMAIN),
294
+ 'options' => array()
295
+ ),*/
296
+
297
+ 'exclude-specific-categories' => array(
298
+ 'id' => '21',
299
+ 'name' => __('Exclude Specific Categories', CWP_TEXTDOMAIN),
300
+ 'type' => 'categories-list',
301
+ 'slug' => 'exclude-specific-category',
302
+ 'option' => 'top_opt_omit_cats',
303
+ 'description' => __('Select which categories do you want to exclude to tweet from? Blank - None', CWP_TEXTDOMAIN),
304
+ 'options' => array()
305
+ ),
306
+
307
+ );
308
+
309
+ // Default option values
310
+ $defaultOptions = array(
311
+ 'top_opt_tweet_type' => 'title',
312
+ 'top_opt_tweet_type_custom_field' => '',
313
+ 'top_opt_add_text' => '',
314
+ 'top_opt_add_text_at' => 'beginning',
315
+ 'top_opt_include_link' => 'false',
316
+ 'top_opt_custom_url_option' => 'off',
317
+ 'top_opt_use_url_shortner' => 'off',
318
+ 'top_opt_url_shortner' => 'is.gd',
319
+ 'top_opt_custom_hashtag_option' => 'nohashtag',
320
+ 'top_opt_hashtags' => '',
321
+ 'top_opt_hashtag_length' => '0',
322
+ 'top_opt_custom_hashtag_field' => '',
323
+ 'top_opt_interval' => '4',
324
+ 'top_opt_age_limit' => '30',
325
+ 'top_opt_max_age_limit' => '0',
326
+ 'top_opt_no_of_tweet' => '1',
327
+ 'top_opt_post_type' => 'post',
328
+ 'top_opt_post_type_value' => 'post',
329
+ 'top_opt_custom_url_field' => '',
330
+ //'top_opt_tweet_specific_category' => '',
331
+ 'top_opt_omit_cats' => '',
332
+
333
+ // Not field related
334
+ 'cwp_topnew_active_status' => 'false'
335
+ );
336
+
337
+ // Define "array_column" function for PHP versions older than 5.5
338
+ if(!function_exists("array_column")) {
339
+ function array_column($array, $column)
340
+ {
341
+ $ret = array();
342
+ foreach ($array as $row) $ret[] = $row[$column];
343
+ return $ret;
344
+ }
345
+ }
346
+
347
+ function top_current_page(){
348
+ $pageURL = 'http';
349
+ if (@$_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
350
+ $pageURL .= "://";
351
+ if (@$_SERVER["SERVER_PORT"] != "80") {
352
+ $pageURL .= @$_SERVER["SERVER_NAME"].":".@$_SERVER["SERVER_PORT"].@$_SERVER["REQUEST_URI"];
353
+ } else {
354
+ $pageURL .= @$_SERVER["SERVER_NAME"].@$_SERVER["REQUEST_URI"];
355
+ }
356
+ return $pageURL;
357
+ }
358
+
359
+ // Store all options in array.
360
+ $cwp_top_options_list = array_column($cwp_top_fields, 'option');
inc/core.php ADDED
@@ -0,0 +1,1233 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // Basic configuration
3
+ require_once(PLUGINPATH."/inc/config.php");
4
+ // twitteroauth class
5
+ require_once(PLUGINPATH."/inc/oAuth/twitteroauth.php");
6
+
7
+ if (!class_exists('CWP_TOP_Core')) {
8
+ class CWP_TOP_Core {
9
+
10
+ // All fields
11
+ public static $fields;
12
+ // Number of fields
13
+ public static $noFields;
14
+
15
+ // Consumer key, Consumer Secret key, oAuth Callback Key
16
+ public $consumer;
17
+ public $consumerSecret;
18
+ public $oAuthCallback;
19
+ public $bitly_key;
20
+ public $bitly_user;
21
+ // Access token, oAuth Token, oAuth Token Secret and User Information
22
+ private $cwp_top_access_token;
23
+ private $cwp_top_oauth_token;
24
+ private $cwp_top_oauth_token_secret;
25
+
26
+
27
+ private $users;
28
+ private $user_info;
29
+
30
+ // Plugin Status
31
+ public $pluginStatus;
32
+ // Interval Set
33
+ public $intervalSet;
34
+ public $cwp_twitter;
35
+
36
+ public function __construct() {
37
+ // Get all fields
38
+ global $cwp_top_fields;
39
+
40
+ // Set all authentication settings
41
+ $this->setAlloAuthSettings();
42
+
43
+ // Load all hooks
44
+ $this->loadAllHooks();
45
+
46
+ // Check if the user added any account
47
+ $this->afterAddAccountCheck();
48
+
49
+ // Save all fields in static var
50
+ self::$fields = $cwp_top_fields;
51
+
52
+ // Save all number of fields in static var
53
+ self::$noFields = count(self::$fields);
54
+ }
55
+
56
+ public function startTweetOldPost()
57
+ {
58
+ // If the plugin is deactivated
59
+ if($this->pluginStatus !== 'true') {
60
+ // Set it to active status
61
+ update_option('cwp_topnew_active_status', 'true');
62
+ update_option('cwp_topnew_notice', '');
63
+ update_option('top_opt_already_tweeted_posts',array());
64
+ // Schedule the next tweet
65
+ //$timeNow = date("Y-m-d H:i:s", time());
66
+ //$timeNow = get_date_from_gmt($timeNow);
67
+ //$timeNow= strtotime($timeNow);
68
+ $timeNow = current_time('timestamp',1);
69
+ $interval = floatval($this->intervalSet) * 60 * 60;
70
+ $timeNow = $timeNow+25;
71
+ wp_schedule_event($timeNow, 'cwp_top_schedule', 'cwp_top_tweet_cron');
72
+ } else {
73
+
74
+ // Report that is already started
75
+ _e("Tweet Old Post is already active!", CWP_TEXTDOMAIN);
76
+ }
77
+
78
+ die(); // Required for AJAX
79
+ }
80
+
81
+ public function stopTweetOldPost()
82
+ {
83
+ //echo $this->pluginStatus;
84
+ // If the plugin is active
85
+ if($this->pluginStatus !== 'false') {
86
+ // Set it to inactive status
87
+ update_option('cwp_topnew_active_status', 'false');
88
+ update_option('cwp_topnew_notice', '');
89
+ update_option('top_opt_already_tweeted_posts',array());
90
+
91
+ // Clear all scheduled tweets
92
+ $this->clearScheduledTweets();
93
+ } else {
94
+ // Report that is already inactive
95
+ _e("Tweet Old Post is already inactive!", CWP_TEXTDOMAIN);
96
+ }
97
+
98
+ die(); // Required for AJAX
99
+ }
100
+
101
+ public function getExcludedPosts() {
102
+
103
+ $postQueryPosts = "";
104
+ $postPosts = get_option('top_opt_excluded_post');
105
+
106
+ if(!empty($postPosts) && is_array($postPosts)) {
107
+ $lastPostPosts = end($postPosts);
108
+ foreach ($postPosts as $key => $cat) {
109
+ if($cat == $lastPostPosts) {
110
+ $postQueryPosts .= $cat;
111
+ } else {
112
+ $postQueryPosts .= $cat . ", ";
113
+ }
114
+ }
115
+ }
116
+ else
117
+ $postQueryPosts = get_option('top_opt_excluded_post');
118
+
119
+ return $postQueryPosts;
120
+
121
+ }
122
+
123
+ public function getTweetsFromDB()
124
+ {
125
+ // Global WordPress $wpdb object.
126
+ global $wpdb;
127
+
128
+ // Generate the Tweet Post Date Range
129
+ $dateQuery = $this->getTweetPostDateRange();
130
+
131
+ // Get the number of tweets to be tweeted each interval.
132
+ $tweetCount = intval(get_option('top_opt_no_of_tweet'));
133
+
134
+ // Get post categories set.
135
+ // $postQueryCategories = $this->getTweetCategories();
136
+ $excludedIds = "";
137
+ $tweetedPosts = get_option("top_opt_already_tweeted_posts");
138
+ if (!$tweetedPosts || get_option('top_opt_tweet_multiple_times')=="on") {
139
+ $tweetedPosts = array();
140
+ }
141
+ $postQueryExcludedPosts = $this->getExcludedPosts();
142
+ if ($postQueryExcludedPosts=="")
143
+ $postQueryExcludedPosts = array();
144
+ //print_r($postQueryExcludedPosts);
145
+ $excludedPosts = array_merge($tweetedPosts,(array)$postQueryExcludedPosts);
146
+ $nrOfExcludedPosts = count($excludedPosts);
147
+ for ($k=0;$k<$nrOfExcludedPosts-1;$k++)
148
+ $excludedIds .=$excludedPosts[$k].", ";
149
+ $excludedIds .=$excludedPosts[$nrOfExcludedPosts-1];
150
+ //print_r($excludedIds);
151
+ // Get excluded categories.
152
+ $postQueryExcludedCategories = $this->getExcludedCategories();
153
+ //echo $postQueryExcludedCategories;
154
+ //print_r($postQueryExcludedCategories);
155
+ // Get post type set.
156
+ $somePostType = $this->getTweetPostType();
157
+
158
+ // Generate dynamic query.
159
+ $query = "
160
+ SELECT *
161
+ FROM {$wpdb->prefix}posts
162
+ INNER JOIN {$wpdb->prefix}term_relationships ON ({$wpdb->prefix}posts.ID = {$wpdb->prefix}term_relationships.object_id)
163
+ WHERE 1=1
164
+ AND ((post_date >= '{$dateQuery['before']}'
165
+ AND post_date <= '{$dateQuery['after']}')) ";
166
+
167
+ // If there are no categories set, select the post from all.
168
+ //if(!empty($postQueryCategories)) {
169
+ // $query .= "AND (wp_term_relationships.term_taxonomy_id IN ({$postQueryCategories})) ";
170
+ // }
171
+
172
+ if(!empty($postQueryExcludedCategories)) {
173
+ $query .= "AND ( {$wpdb->prefix}posts.ID NOT IN (
174
+ SELECT object_id
175
+ FROM {$wpdb->prefix}term_relationships
176
+ INNER JOIN {$wpdb->prefix}term_taxonomy ON ( {$wpdb->prefix}term_relationships.term_taxonomy_id = {$wpdb->prefix}term_taxonomy.term_taxonomy_id )
177
+ WHERE {$wpdb->prefix}term_taxonomy.taxonomy = 'category'
178
+ AND {$wpdb->prefix}term_taxonomy.term_id IN ({$postQueryExcludedCategories}))) ";
179
+ }
180
+
181
+ if(!empty($excludedIds)) {
182
+ $query .= "AND ( {$wpdb->prefix}posts.ID NOT IN ({$excludedIds})) ";
183
+ }
184
+
185
+ $query .= "AND {$wpdb->prefix}posts.post_type IN ({$somePostType})
186
+ AND ({$wpdb->prefix}posts.post_status = 'publish')
187
+ GROUP BY {$wpdb->prefix}posts.ID
188
+ ORDER BY RAND() DESC LIMIT 0,{$tweetCount}
189
+ ";
190
+
191
+ // Save the result in a var for future use.
192
+ $returnedPost = $wpdb->get_results($query);
193
+ //echo $query;
194
+ return $returnedPost;
195
+ }
196
+
197
+ public function isPostWithImageEnabled () {
198
+
199
+ if (get_option("top_opt_post_with_image")!='on')
200
+ return false;
201
+ else
202
+ return true;
203
+ }
204
+
205
+ public function tweetOldPost()
206
+
207
+ {
208
+ $returnedPost = $this->getTweetsFromDB();
209
+
210
+
211
+ $k = 0; // Iterator
212
+
213
+ // Get the number of tweets to be tweeted each interval.
214
+ $tweetCount = intval(get_option('top_opt_no_of_tweet'));
215
+
216
+ if (count($returnedPost) == 0 ) update_option('cwp_topnew_notice', 'There is no suitable post to tweet make sure you excluded correct categories and selected the right dates.');
217
+
218
+ // While haven't reached the limit
219
+ while($k != $tweetCount) {
220
+ // If the post is not already tweeted
221
+ $isNotAlreadyTweeted = $this->isNotAlreadyTweeted($returnedPost[$k]->ID);
222
+
223
+ if (get_option('top_opt_tweet_multiple_times')=="on") $isNotAlreadyTweeted = true;
224
+
225
+ if($isNotAlreadyTweeted) {
226
+
227
+ // Foreach returned post
228
+ foreach ($returnedPost as $post) {
229
+ // Generate a tweet from it based on user settings.
230
+ $finalTweet = $this->generateTweetFromPost($post);
231
+ // Tweet the post
232
+ if ($this->isPostWithImageEnabled()=="on") {
233
+ $resp = $this->tweetPostwithImage($finalTweet, $post->ID);
234
+ update_option('cwp_topnew_notice', $resp);
235
+ }
236
+ else {
237
+ $resp = $this->tweetPost($finalTweet);
238
+ update_option('cwp_topnew_notice', $resp);
239
+ }
240
+ // Get already tweeted posts array.
241
+ $tweetedPosts = get_option("top_opt_already_tweeted_posts");
242
+ if ($tweetedPosts=="") $tweetedPosts = array();
243
+ // Push the tweeted post at the end of the array.
244
+ array_push($tweetedPosts, $post->ID);
245
+ // Update the new already tweeted posts array.
246
+ if ( function_exists('w3tc_pgcache_flush') ) {
247
+
248
+ w3tc_dbcache_flush();
249
+
250
+ w3tc_objectcache_flush();
251
+ $cache = ' and W3TC Caches cleared';
252
+ }
253
+ add_option("top_opt_already_tweeted_posts");
254
+ update_option("top_opt_already_tweeted_posts", $tweetedPosts);
255
+ // Increase
256
+ $k = $k + 1;
257
+ }
258
+ } else {
259
+ update_option('cwp_topnew_notice', 'Tweet was already tweeted, if you want to tweet your old tweets more than once, select "Tweet old posts more than once" option');
260
+ }
261
+ }
262
+
263
+ }
264
+
265
+ public function getNotice() {
266
+ $notice = get_option('cwp_topnew_notice');
267
+
268
+
269
+ if (is_object($notice) && $notice->errors[0]->message)
270
+ echo "Error for your last tweet was :'".$notice->errors[0]->message."'";
271
+ else if (is_object($notice) && $notice->text) {
272
+ echo "Congrats! The following tweet was posted successfully: '".$notice->text."' at ".$notice->created_at;
273
+ } else if ($notice!="") {
274
+ echo "Error for your last tweet was :".$notice;
275
+ }
276
+ die();
277
+ }
278
+
279
+ public function viewSampleTweet()
280
+ {
281
+
282
+ $returnedTweets = $this->getTweetsFromDB();
283
+ $image="";
284
+ //var_dump($returnedTweets);
285
+ $finalTweetsPreview = $this->generateTweetFromPost($returnedTweets[0]);
286
+ $result = $finalTweetsPreview;
287
+
288
+
289
+ if (function_exists('topProImage') && get_option('top_opt_post_with_image')=="on") {
290
+
291
+ if ( has_post_thumbnail( $returnedTweets[0]->ID ) ) :
292
+ $image_array = wp_get_attachment_image_src( get_post_thumbnail_id( $returnedTweets[0]->ID ), 'optional-size' );
293
+ $image = $image_array[0];
294
+ else :
295
+ $image = '';
296
+ endif;
297
+
298
+ $result = '<img class="top_preview" src="'.$image.'"/>'.$finalTweetsPreview;
299
+ }
300
+
301
+ echo $result;
302
+
303
+
304
+ die(); // required
305
+ }
306
+
307
+ /**
308
+ * Returns if the post is already tweeted
309
+ * @param [type] $postId Post ID
310
+ * @return boolean True if not already tweeted / False if already tweeted
311
+ */
312
+
313
+ public function isNotAlreadyTweeted($postId) {
314
+ // Get all already tweeted posts
315
+
316
+ $tweetedPosts = get_option("top_opt_already_tweeted_posts");
317
+
318
+ if (!$tweetedPosts) {
319
+ add_option("top_opt_already_tweeted_posts");
320
+ return true;
321
+ }
322
+
323
+ // If the new post ID is in the array, which means that is already tweeted
324
+ if (!empty($tweetedPosts) && is_array($tweetedPosts) ) {
325
+
326
+ if (in_array($postId, $tweetedPosts))
327
+ return false;
328
+ else
329
+ return true;
330
+ }
331
+ else
332
+ {
333
+ return true;
334
+ }
335
+ }
336
+
337
+
338
+
339
+ /**
340
+ * Generates the tweet based on the user settings
341
+ * @param [type] $postQuery Returned post from database
342
+ * @return [type] Generated Tweet
343
+ */
344
+
345
+ public function generateTweetFromPost($postQuery)
346
+ {
347
+
348
+ // Save all user settings in variables.
349
+ $tweetedPosts = get_option("top_opt_already_tweeted_posts");
350
+ $tweet_content = get_option('top_opt_tweet_type');
351
+ $tweet_content_custom_field = get_option('top_opt_tweet_type_custom_field');
352
+ $additional_text = get_option('top_opt_add_text');
353
+ $additional_text_at = get_option('top_opt_add_text_at');
354
+ $include_link = get_option('top_opt_include_link');
355
+ $fetch_url_from_custom_field = get_option('top_opt_custom_url_option');
356
+ $custom_field_url = get_option('top_opt_custom_url_field');
357
+ $use_url_shortner = get_option('top_opt_use_url_shortner');
358
+ $url_shortner_service = get_option('top_opt_url_shortner');
359
+ $hashtags = get_option('top_opt_custom_hashtag_option');
360
+ $common_hashtags = get_option('top_opt_hashtags');
361
+ $maximum_hashtag_length = get_option('top_opt_hashtag_length');
362
+ $hashtag_custom_field = get_option('top_opt_custom_hashtag_field');
363
+ $bitly_key = get_option('top_opt_bitly_key');
364
+ $bitly_user = get_option('top_opt_bitly_user');
365
+ $additionalTextBeginning = "";
366
+ $additionalTextEnd = "";
367
+
368
+ // If the user set to not use hashtags, set it to empty variable.
369
+ if($hashtags == 'nohashtag') {
370
+ $newHashtags = "";
371
+ }
372
+
373
+ // Generate the tweet content.
374
+ switch ($tweet_content) {
375
+ case 'title':
376
+ $tweetContent = $postQuery->post_title . " ";
377
+ break;
378
+
379
+ case 'body':
380
+ $tweetContent = get_post_field('post_content', $postQuery->ID) . " ";
381
+ break;
382
+
383
+ case 'titlenbody':
384
+ $tweetContent = $postQuery->post_title . " " . get_post_field('post_content', $postQuery->ID) . " ";
385
+ break;
386
+
387
+ case 'custom-field':
388
+ $tweetContent = get_post_meta($postQuery->ID, $tweet_content_custom_field,true);
389
+ break;
390
+ default:
391
+ $tweetContent = $finalTweet;
392
+ break;
393
+ }
394
+
395
+ // Trim new empty lines.
396
+ $tweetContent = trim(preg_replace('/\s+/', ' ', $tweetContent));
397
+
398
+ // Remove html entinies.
399
+ $tweetContent = preg_replace("/&#?[a-z0-9]+;/i","", $tweetContent);
400
+
401
+ // Strip all shortcodes from content.
402
+ $tweetContent = strip_shortcodes($tweetContent);
403
+
404
+ // Generate the post link.
405
+ if($include_link == 'true') {
406
+ if($fetch_url_from_custom_field == 'on') {
407
+ $post_url = " " . get_post_meta($postQuery->ID, $custom_field_url,true) . " ";
408
+ } else {
409
+ $post_url = " " . get_permalink($postQuery->ID);
410
+ }
411
+
412
+ if($use_url_shortner == 'on') {
413
+ $post_url = " " . $this->shortenURL($post_url, $url_shortner_service, $postQuery->ID, $bitly_key, $bitly_user);
414
+ }
415
+ $post_url = $post_url . " ";
416
+ } else { $post_url = ""; }
417
+
418
+ // Generate the hashtags
419
+ $newHashtags = "";
420
+ if($hashtags != 'nohashtag') {
421
+
422
+ switch ($hashtags) {
423
+ case 'common':
424
+ $newHashtags = $common_hashtags;
425
+ break;
426
+
427
+ case 'categories':
428
+ $postCategories = get_the_category($postQuery->ID);
429
+
430
+ foreach ($postCategories as $category) {
431
+ if(strlen($category->cat_name.$newHashtags) <= $maximum_hashtag_length || $maximum_hashtag_length == 0) {
432
+ $newHashtags = $newHashtags . " #" . preg_replace('/-/','',strtolower($category->slug));
433
+ }
434
+ }
435
+
436
+ break;
437
+
438
+ case 'tags':
439
+ $postTags = wp_get_post_tags($postQuery->ID);
440
+
441
+ foreach ($postTags as $postTag) {
442
+ if(strlen($postTag->slug.$newHashtags) <= $maximum_hashtag_length || $maximum_hashtag_length == 0) {
443
+ $newHashtags = $newHashtags . " #" . preg_replace('/-/','',strtolower($postTag->slug));
444
+ }
445
+ }
446
+ break;
447
+
448
+ case 'custom':
449
+ $newHashtags = get_post_meta($postQuery->ID, $hashtag_custom_field, true);
450
+ break;
451
+ default:
452
+ break;
453
+ }
454
+ }
455
+
456
+
457
+ // Generate the additional text
458
+ if($additional_text_at == 'beginning') {
459
+ $additionalTextBeginning = $additional_text . " ";
460
+ }
461
+
462
+ if($additional_text_at == 'end') {
463
+ $additionalTextEnd = " " . $additional_text;
464
+ }
465
+
466
+ // Calculate the final tweet length
467
+ $finalTweetLength = 0;
468
+
469
+ if(!empty($additional_text)) {
470
+ $additionalTextLength = strlen($additional_text); $finalTweetLength += intval($additionalTextLength);
471
+ }
472
+
473
+ if(!empty($post_url)) {
474
+
475
+ $postURLLength = strlen($post_url);
476
+ if ($postURLLength > 50) $postURLLength = 50;
477
+ $finalTweetLength += intval($postURLLength);
478
+ }
479
+
480
+ if(!empty($newHashtags)) {
481
+ $hashtagsLength = strlen($newHashtags);
482
+ $finalTweetLength += intval($hashtagsLength);
483
+ }
484
+
485
+ $finalTweetLength = 139 - $finalTweetLength - 5;
486
+
487
+ $tweetContent = substr($tweetContent,0, $finalTweetLength) . " ";
488
+
489
+ $finalTweet = $additionalTextBeginning . $tweetContent . $post_url . $newHashtags . $additionalTextEnd;
490
+ $finalTweet = substr($finalTweet,0, 139);
491
+
492
+ // Strip any tags and return the final tweet
493
+ return strip_tags($finalTweet);
494
+ }
495
+
496
+ /**
497
+ * Tweets the returned post from generateTweetFromPost()
498
+ * @param [type] $finalTweet Generated tweet
499
+ */
500
+
501
+ public function tweetPost($finalTweet)
502
+ {
503
+ $k=1;
504
+ $nrOfUsers = count($this->users);
505
+
506
+ foreach ($this->users as $user) {
507
+
508
+ // Create a new twitter connection using the stored user credentials.
509
+ $connection = new TwitterOAuth($this->consumer, $this->consumerSecret, $user['oauth_token'], $user['oauth_token_secret']);
510
+ // Post the new tweet
511
+ $status = $connection->post('statuses/update', array('status' => $finalTweet));
512
+ //return $status;
513
+ if ($nrOfUsers == $k)
514
+ return $status;
515
+ else
516
+ $k++;
517
+
518
+ }
519
+ }
520
+
521
+ public function tweetPostwithImage($finalTweet, $id)
522
+ {
523
+
524
+ $k=1;
525
+ $nrOfUsers = count($this->users);
526
+
527
+ foreach ($this->users as $user) {
528
+ // Create a new twitter connection using the stored user credentials.
529
+ $connection = new TwitterOAuth($this->consumer, $this->consumerSecret, $user['oauth_token'], $user['oauth_token_secret']);
530
+ // Post the new tweet
531
+ if (function_exists('topProImage'))
532
+ $status = topProImage($connection, $finalTweet, $id);
533
+
534
+ if ($nrOfUsers == $k)
535
+ return $status;
536
+ else
537
+ $k++;
538
+ }
539
+ }
540
+
541
+ // Generates the tweet date range based on the user input.
542
+ public function getTweetPostDateRange()
543
+ {
544
+ $minAgeLimit = "-" . get_option('top_opt_age_limit') . " days";
545
+ if (get_option('top_opt_max_age_limit')==0) $maxAgeLimit = "- 9999 days";
546
+ else
547
+ $maxAgeLimit = "-" . get_option('top_opt_max_age_limit') . " days";
548
+
549
+ $minAgeLimit = date("Y-m-d H:i:s", strtotime($minAgeLimit));
550
+ $maxAgeLimit = date("Y-m-d H:i:s", strtotime($maxAgeLimit));
551
+
552
+ if(isset($minAgeLimit) || isset($maxAgeLimit)) {
553
+
554
+ $dateQuery = array();
555
+
556
+ if(isset($minAgeLimit)) {
557
+ $dateQuery['before'] = $maxAgeLimit;
558
+ }
559
+
560
+ if(isset($maxAgeLimit)) {
561
+ $dateQuery['after'] = $minAgeLimit;
562
+ }
563
+
564
+ $dateQuery['inclusive'] = true;
565
+
566
+ }
567
+
568
+ if(!empty($dateQuery)) {
569
+ return $dateQuery;
570
+ }
571
+
572
+ }
573
+
574
+ // Gets the tweet categories.
575
+ /* public function getTweetCategories()
576
+ {
577
+ $postQueryCategories = "";
578
+ $postsCategories = get_option('top_opt_tweet_specific_category');
579
+
580
+ if(!empty($postCategories)) {
581
+ $lastPostCategory = end($postsCategories);
582
+ foreach ($postsCategories as $key => $cat) {
583
+ if($cat == $lastPostCategory) {
584
+ $postQueryCategories .= $cat;
585
+ } else {
586
+ $postQueryCategories .= $cat . ", ";
587
+ }
588
+ }
589
+ }
590
+
591
+ return $postQueryCategories;
592
+ }*/
593
+
594
+ // Gets the omited tweet categories
595
+
596
+ public function getExcludedCategories()
597
+ {
598
+ $postQueryCategories = "";
599
+ $postCategories = get_option('top_opt_omit_cats');
600
+
601
+ if(!empty($postCategories) && is_array($postCategories)) {
602
+ $lastPostCategory = end($postCategories);
603
+ foreach ($postCategories as $key => $cat) {
604
+ if($cat == $lastPostCategory) {
605
+ $postQueryCategories .= $cat;
606
+ } else {
607
+ $postQueryCategories .= $cat . ", ";
608
+ }
609
+ }
610
+ }
611
+ else
612
+ $postQueryCategories = get_option('top_opt_omit_cats');
613
+
614
+ return $postQueryCategories;
615
+ }
616
+
617
+ // Gets the tweet post type.
618
+ public function getTweetPostType()
619
+ {
620
+ $top_opt_tweet_type = get_option('top_opt_post_type');
621
+
622
+ /* switch ($top_opt_tweet_type) {
623
+ case 'post':
624
+ return "'post'";
625
+ break;
626
+
627
+ case 'page':
628
+ return "'page'";
629
+ break;
630
+
631
+ case 'custom-post-type':
632
+ return "'" . get_option('top_opt_post_type_value') . "'";
633
+ break;
634
+
635
+ case 'both':
636
+ return "'post', 'page'";
637
+ break;
638
+
639
+ default:
640
+ break;
641
+ }
642
+ */
643
+ return "'post'";
644
+
645
+ }
646
+
647
+
648
+ // Creates a custom Tweet Old Post schedule
649
+ public function createCustomSchedule($schedules)
650
+ {
651
+ $schedules['cwp_top_schedule'] = array(
652
+ 'interval' => floatval($this->intervalSet) * 60 * 60,
653
+ 'display' => __("Custom Tweet User Interval", CWP_TEXTDOMAIN)
654
+ );
655
+
656
+ return $schedules;
657
+ }
658
+
659
+ // Clears the custom Tweet Old Post cron job.
660
+ public function clearScheduledTweets()
661
+ {
662
+ wp_clear_scheduled_hook('cwp_top_tweet_cron');
663
+ }
664
+
665
+ // Deactivation hook
666
+ public function deactivationHook()
667
+ {
668
+ delete_option('activation_hook_test_motherfucker');
669
+ $this->clearScheduledTweets();
670
+ $this->deleteAllOptions();
671
+ }
672
+
673
+ // Sets all authentication settings
674
+ public function setAlloAuthSettings()
675
+ {
676
+ global $cwp_top_settings;
677
+
678
+ $this->consumer = $cwp_top_settings['oAuth_settings']['consumer_key'];
679
+ $this->consumerSecret = $cwp_top_settings['oAuth_settings']['consumer_secret'];
680
+ $this->oAuthCallback = CURRENTURL;
681
+
682
+ $this->cwp_top_access_token = get_option('cwp_top_access_token');
683
+ $this->cwp_top_oauth_token = get_option('cwp_top_oauth_token');
684
+ $this->cwp_top_oauth_token_secret = get_option('cwp_top_oauth_token_secret');
685
+
686
+ $this->user_info = get_option('cwp_top_oauth_user_details');
687
+ $this->users = get_option('cwp_top_logged_in_users');
688
+
689
+ $this->pluginStatus = get_option('cwp_topnew_active_status');
690
+ $this->intervalSet = get_option('top_opt_interval');
691
+
692
+ //update_option('cwp_top_logged_in_users', '');
693
+ }
694
+
695
+ // Checks if twitter returned any temporary credentials to log in the user.
696
+ public function afterAddAccountCheck()
697
+ {
698
+ if(isset($_REQUEST['oauth_token'])) {
699
+ if($_REQUEST['oauth_token'] == $this->cwp_top_oauth_token) {
700
+
701
+ $twitter = new TwitterOAuth($this->consumer, $this->consumerSecret, $this->cwp_top_oauth_token, $this->cwp_top_oauth_token_secret );
702
+ $access_token = $twitter->getAccessToken($_REQUEST['oauth_verifier']);
703
+ $user_details = $twitter->get('account/verify_credentials');
704
+
705
+ $newUser = array(
706
+ 'user_id' => $user_details->id,
707
+ 'oauth_token' => $access_token['oauth_token'],
708
+ 'oauth_token_secret' => $access_token['oauth_token_secret'],
709
+ 'oauth_user_details' => $user_details
710
+ );
711
+
712
+ $loggedInUsers = get_option('cwp_top_logged_in_users');
713
+ if(empty($loggedInUsers)) { $loggedInUsers = array(); }
714
+
715
+
716
+ if(in_array($newUser, $loggedInUsers)) {
717
+ echo "You already added that user! no can do !";
718
+ } else {
719
+ array_push($loggedInUsers, $newUser);
720
+ update_option('cwp_top_logged_in_users', $loggedInUsers);
721
+ }
722
+
723
+ header("Location: " . SETTINGSURL);
724
+ exit;
725
+ }
726
+ }
727
+ }
728
+
729
+ // Used to display the twitter login button
730
+ public function displayTwitterLoginButton()
731
+ {
732
+ // display the twitter login button
733
+ if($this->userIsLoggedIn()) {
734
+ $this->setAlloAuthSettings();
735
+ return true;
736
+ } else {
737
+ return false;
738
+ }
739
+ }
740
+
741
+ // Adds new twitter account
742
+ public function addNewTwitterAccount()
743
+ {
744
+ $this->oAuthCallback = $_POST['currentURL'];
745
+ $twitter = new TwitterOAuth($this->consumer, $this->consumerSecret);
746
+ $requestToken = $twitter->getRequestToken($this->oAuthCallback);
747
+
748
+ update_option('cwp_top_oauth_token', $requestToken['oauth_token']);
749
+ update_option('cwp_top_oauth_token_secret', $requestToken['oauth_token_secret']);
750
+
751
+
752
+
753
+ switch ($twitter->http_code) {
754
+ case 200:
755
+ $url = $twitter->getAuthorizeURL($requestToken['oauth_token']);
756
+ echo $url;
757
+ break;
758
+
759
+ default:
760
+ return __("Could not connect to Twitter!", CWP_TEXTDOMAIN);
761
+ break;
762
+ }
763
+ die(); // Required
764
+ }
765
+
766
+ // Adds new twitter account
767
+ public function addNewTwitterAccountPro()
768
+ {
769
+ if (function_exists('topProAddNewAccount')) {
770
+ topProAddNewAccount();
771
+ }
772
+ else{
773
+ _e("You need to <a target='_blank' href='http://themeisle.com/plugins/tweet-old-post-pro/?utm_source=topplusacc&utm_medium=announce&utm_campaign=top&upgrade=true'>upgrade to the PRO version</a> in order to add more accounts, fellow pirate!", CWP_TEXTDOMAIN);
774
+
775
+ }
776
+ die(); // Required
777
+ }
778
+
779
+ // Gets the next tweet interval.
780
+ public function getNextTweetInterval()
781
+ {
782
+ $timestamp = wp_next_scheduled( 'cwp_top_tweet_cron' );
783
+ //echo $timestamp;
784
+ //$timestamp = date("Y-m-d H:i:s", $timestamp);
785
+ //$timeLeft = get_date_from_gmt($timestamp);
786
+ //$timeLeft = strtotime($timeLeft);
787
+ echo $timestamp;
788
+ }
789
+
790
+ // Checks if the user is logged in/
791
+ public function userIsLoggedIn()
792
+ {
793
+ if(!empty($this->cwp_top_oauth_token) && !empty($this->cwp_top_oauth_token_secret)) {
794
+ return true;
795
+ } else {
796
+ return false;
797
+ }
798
+ }
799
+
800
+ // Clears all Twitter user credentials.
801
+ public function logOutTwitterUser()
802
+ {
803
+ $userID = $_POST['user_id'];
804
+
805
+ $users = get_option('cwp_top_logged_in_users');
806
+
807
+ foreach ($users as $id => $user) {
808
+ foreach ($user as $key => $value) {
809
+ if($userID == $value) {
810
+ $user_id = array_search($user, $users);
811
+ unset($users[$user_id]);
812
+ }
813
+ }
814
+ }
815
+
816
+ update_option('cwp_top_logged_in_users', $users);
817
+
818
+ $this->setAlloAuthSettings();
819
+ die();
820
+ }
821
+
822
+ // Updates all options.
823
+ public function updateAllOptions()
824
+ {
825
+ $dataSent = $_POST['dataSent']['dataSent'];
826
+
827
+ $options = array();
828
+ parse_str($dataSent, $options);
829
+
830
+ //print_r($options);
831
+
832
+ foreach ($options as $option => $newValue) {
833
+ //$newValue = sanitize_text_field($newValue);
834
+ update_option($option, $newValue);
835
+ }
836
+
837
+ update_option('top_opt_post_type', 'post');
838
+
839
+ if(!array_key_exists('top_opt_custom_url_option', $options)) {
840
+ update_option('top_opt_custom_url_option', 'off');
841
+ }
842
+
843
+ if(!array_key_exists('top_opt_use_url_shortner', $options)) {
844
+ update_option('top_opt_use_url_shortner', 'off');
845
+ }
846
+
847
+ if(!array_key_exists('top_opt_post_with_image', $options)) {
848
+ update_option('top_opt_post_with_image', 'off');
849
+ }
850
+
851
+ if(!array_key_exists('top_opt_tweet_multiple_times', $options)) {
852
+ update_option('top_opt_tweet_multiple_times', 'off');
853
+ }
854
+
855
+ //if(!array_key_exists('top_opt_tweet_specific_category', $options)) {
856
+ // update_option('top_opt_tweet_specific_category', '');
857
+ //}
858
+
859
+ if(!array_key_exists('top_opt_omit_cats', $options)) {
860
+ update_option('top_opt_omit_cats', '');
861
+ }
862
+
863
+ //update_option("top_opt_already_tweeted_posts", array());
864
+
865
+ die();
866
+ }
867
+
868
+ public function top_admin_notice() {
869
+ global $current_user ;
870
+ $user_id = $current_user->ID;
871
+ /* Check that the user hasn't already clicked to ignore the message */
872
+ if ( ! get_user_meta($user_id, 'top_ignore_notice3') ) {
873
+ echo '<div class="error"><p>';
874
+ printf(__(' We just fixed the interrupted posting issue and scheduling issue, if you don\'t see any tweets you need to re-authentificate your twitter accounts. | <a href="'.SETTINGSURL.'&top_nag_ignore=0">Hide Notice</a>'));
875
+ echo "</p></div>";
876
+ }
877
+ }
878
+ public function top_nag_ignore() {
879
+ global $current_user;
880
+ $user_id = $current_user->ID;
881
+ /* If user clicks to ignore the notice, add that to their user meta */
882
+ if ( isset($_GET['top_nag_ignore']) && '0' == $_GET['top_nag_ignore'] ) {
883
+ add_user_meta($user_id, 'top_ignore_notice3', 'true', true);
884
+ }
885
+ }
886
+
887
+ public function resetAllOptions()
888
+ {
889
+ update_option('activation_hook_test_motherfucker', "Well, the plugin was activated!");
890
+
891
+ $defaultOptions = array(
892
+ 'top_opt_tweet_type' => 'title',
893
+ 'top_opt_post_with_image' => 'off',
894
+ 'top_opt_bitly_user' =>'',
895
+ 'top_opt_bitly_key' =>'',
896
+ 'top_opt_tweet_type_custom_field' => '',
897
+ 'top_opt_add_text' => '',
898
+ 'top_opt_add_text_at' => 'beginning',
899
+ 'top_opt_include_link' => 'false',
900
+ 'top_opt_custom_url_option' => 'off',
901
+ 'top_opt_use_url_shortner' => 'off',
902
+ 'top_opt_url_shortner' => 'is.gd',
903
+ 'top_opt_custom_hashtag_option' => 'nohashtag',
904
+ 'top_opt_hashtags' => '',
905
+ 'top_opt_hashtag_length' => '0',
906
+ 'top_opt_custom_hashtag_field' => '',
907
+ 'top_opt_interval' => '4',
908
+ 'top_opt_age_limit' => '30',
909
+ 'top_opt_max_age_limit' => '0',
910
+ 'top_opt_no_of_tweet' => '1',
911
+ 'top_opt_post_type' => 'post',
912
+ 'top_opt_post_type_value' => 'post',
913
+ 'top_opt_custom_url_field' => '',
914
+ 'top_opt_omit_cats' => '',
915
+ 'cwp_topnew_active_status' => 'false',
916
+ 'cwp_topnew_notice' => '',
917
+ 'top_opt_excluded_post' => '',
918
+ 'top_opt_tweet-multiple-times' => 'off'
919
+ );
920
+
921
+ foreach ($defaultOptions as $option => $defaultValue) {
922
+ update_option($option, $defaultValue);
923
+ }
924
+ //die();
925
+ }
926
+
927
+ public function deleteAllOptions()
928
+ {
929
+ global $defaultOptions;
930
+ foreach ($defaultOptions as $option => $defaultValue) {
931
+ delete_option($option);
932
+ }
933
+ }
934
+
935
+ // Generate all fields based on settings
936
+ public static function generateFieldType($field)
937
+ {
938
+ $disabled = "";
939
+ $pro = "";
940
+ switch ($field['type']) {
941
+
942
+ case 'text':
943
+ print "<input type='text' placeholder='".$field['description']."' value='".$field['option_value']."' name='".$field['option']."' id='".$field['option']."'>";
944
+ break;
945
+
946
+ case 'select':
947
+ $noFieldOptions = intval(count($field['options']));
948
+ $fieldOptions = array_keys($field['options']);
949
+
950
+ if ($field['option']=='top_opt_post_type') $disabled = "disabled";
951
+ print "<select id='".$field['option']."' name='".$field['option']."'".$disabled.">";
952
+ for ($i=0; $i < $noFieldOptions; $i++) {
953
+ print "<option value=".$fieldOptions[$i];
954
+ if($field['option_value'] == $fieldOptions[$i]) { echo " selected='selected'"; }
955
+ print ">".$field['options'][$fieldOptions[$i]]."</option>";
956
+ }
957
+ print "</select>";
958
+ break;
959
+
960
+ case 'checkbox':
961
+ if ($field['option']=='top_opt_post_with_image'&& !function_exists('topProImage')) {
962
+ $disabled = "disabled='disabled'";
963
+ $pro = "This is only available in the PRO option";
964
+ }
965
+ print "<input id='".$field['option']."' type='checkbox' ".$disabled." name='".$field['option']."'";
966
+ if($field['option_value'] == 'on') { echo "checked=checked"; }
967
+ print " />".$pro;
968
+ break;
969
+
970
+ case 'custom-post-type':
971
+ print "<select id='".$field['option']."' name='".$field['option']."' >";
972
+ $post_types = get_post_types(array('_builtin' => false));
973
+ foreach ($post_types as $post_type) {
974
+ print "<option value='".$post_type."'";
975
+ if($field['option_value'] == $post_type) { print "selected=selected"; }
976
+ print ">" . $post_type . "</option>";
977
+ }
978
+ print "</select>";
979
+ break;
980
+
981
+ case 'categories-list':
982
+ print "<div class='categories-list'>";
983
+ $categories = get_categories();
984
+
985
+ foreach ($categories as $category) {
986
+
987
+ $top_opt_tweet_specific_category = get_option('top_opt_tweet_specific_category');
988
+
989
+ if (!is_array(get_option('top_opt_omit_cats')))
990
+ $top_opt_omit_specific_cats = explode(',',get_option('top_opt_omit_cats'));
991
+ else
992
+ $top_opt_omit_specific_cats = get_option('top_opt_omit_cats');
993
+
994
+ print "<div class='cwp-cat'>";
995
+ print "<input type='checkbox' name='".$field['option']."[]' value='".$category->cat_ID."' id='".$field['option']."_cat_".$category->cat_ID."'";
996
+ /*
997
+ if($field['option'] == 'top_opt_tweet_specific_category' ) {
998
+ if(is_array($top_opt_tweet_specific_category)) {
999
+ if(in_array($category->cat_ID, $top_opt_tweet_specific_category)) {
1000
+ print "checked=checked";
1001
+ }
1002
+ }
1003
+ }
1004
+ */
1005
+ if($field['option'] == 'top_opt_omit_cats') {
1006
+ if(is_array($top_opt_omit_specific_cats)) {
1007
+ if(in_array($category->cat_ID, $top_opt_omit_specific_cats)) {
1008
+ print "checked=checked";
1009
+ }
1010
+ }
1011
+ }
1012
+
1013
+
1014
+ print ">";
1015
+ print "<label for='".$field['option']."_cat_".$category->cat_ID."'>".$category->name."</label>";
1016
+ print "</div>";
1017
+ }
1018
+ print "</div>";
1019
+ break;
1020
+
1021
+ }
1022
+
1023
+ }
1024
+
1025
+ public function top_plugin_action_links($links, $file) {
1026
+
1027
+ $mylinks = array(
1028
+ '<a href="' . admin_url( 'admin.php?page=TweetOldPost' ) . '">Settings</a>',
1029
+ );
1030
+ return array_merge( $links, $mylinks );
1031
+
1032
+
1033
+ }
1034
+
1035
+ public function getTime() {
1036
+
1037
+ echo current_time('timestamp',1);
1038
+
1039
+ die();
1040
+ }
1041
+
1042
+ public function loadAllHooks()
1043
+ {
1044
+ // loading all actions and filters
1045
+ add_action('admin_menu', array($this, 'addAdminMenuPage'));
1046
+ add_action('admin_enqueue_scripts', array($this, 'loadAllScriptsAndStyles'));
1047
+
1048
+ // Update all options ajax action.
1049
+ add_action('wp_ajax_nopriv_update_response', array($this, 'updateAllOptions'));
1050
+ add_action('wp_ajax_update_response', array($this, 'updateAllOptions'));
1051
+
1052
+ // Reset all options ajax action.
1053
+ add_action('wp_ajax_nopriv_reset_options', array($this, 'resetAllOptions'));
1054
+ add_action('wp_ajax_reset_options', array($this, 'resetAllOptions'));
1055
+
1056
+ // Add new twitter account ajax action
1057
+ add_action('wp_ajax_nopriv_add_new_twitter_account', array($this, 'addNewTwitterAccount'));
1058
+ add_action('wp_ajax_add_new_twitter_account', array($this, 'addNewTwitterAccount'));
1059
+
1060
+ // Add more than one twitter account ajax action
1061
+ add_action('wp_ajax_nopriv_add_new_twitter_account_pro', array($this, 'addNewTwitterAccountPro'));
1062
+ add_action('wp_ajax_add_new_twitter_account_pro', array($this, 'addNewTwitterAccountPro'));
1063
+
1064
+ // Log Out Twitter user ajax action
1065
+ add_action('wp_ajax_nopriv_log_out_twitter_user', array($this, 'logOutTwitterUser'));
1066
+ add_action('wp_ajax_log_out_twitter_user', array($this, 'logOutTwitterUser'));
1067
+
1068
+ // Tweet Old Post ajax action.
1069
+ add_action('wp_ajax_nopriv_tweet_old_post_action', array($this, 'startTweetOldPost'));
1070
+ add_action('wp_ajax_tweet_old_post_action', array($this, 'startTweetOldPost'));
1071
+
1072
+ // Tweet Old Post view sample tweet action.
1073
+ add_action('wp_ajax_nopriv_view_sample_tweet_action', array($this, 'viewSampleTweet'));
1074
+ add_action('wp_ajax_view_sample_tweet_action', array($this, 'viewSampleTweet'));
1075
+
1076
+ add_action('wp_ajax_nopriv_gettime_action', array($this, 'getTime'));
1077
+ add_action('wp_ajax_gettime_action', array($this, 'getTime'));
1078
+
1079
+ add_action('wp_ajax_nopriv_getNotice_action', array($this, 'getNotice'));
1080
+ add_action('wp_ajax_getNotice_action', array($this, 'getNotice'));
1081
+
1082
+ // Tweet Old Post ajax action
1083
+ add_action('wp_ajax_nopriv_stop_tweet_old_post', array($this, 'stopTweetOldPost'));
1084
+ add_action('wp_ajax_stop_tweet_old_post', array($this, 'stopTweetOldPost'));
1085
+
1086
+ //Settings link
1087
+
1088
+ //add_filter('plugin_action_links', array($this,'top_plugin_action_links'), 10, 2);
1089
+
1090
+ add_action('admin_notices', array($this,'top_admin_notice'));
1091
+
1092
+ add_action('admin_init', array($this,'top_nag_ignore'));
1093
+
1094
+ // Filter to add new custom schedule based on user input
1095
+ add_filter('cron_schedules', array($this, 'createCustomSchedule'));
1096
+
1097
+ add_action('cwp_top_tweet_cron', array($this, 'tweetOldPost'));
1098
+
1099
+ }
1100
+
1101
+ public function loadAllScriptsAndStyles()
1102
+ {
1103
+ global $cwp_top_settings; // Global Tweet Old Post Settings
1104
+
1105
+ // Enqueue and register all scripts on plugin's page
1106
+ if(isset($_GET['page'])) {
1107
+ if ($_GET['page'] == $cwp_top_settings['slug'] || $_GET['page'] == "ExcludePosts") {
1108
+
1109
+ // Enqueue and Register Main CSS File
1110
+ wp_register_style( 'cwp_top_stylesheet', CSSFILE, false, '1.0.0' );
1111
+ wp_enqueue_style( 'cwp_top_stylesheet' );
1112
+
1113
+ // Register Main JS File
1114
+ wp_enqueue_script( 'cwp_top_js_countdown', JSCOUNTDOWN, array(), '1.0.0', true );
1115
+ wp_enqueue_script( 'cwp_top_javascript', JSFILE, array(), '1.0.0', true );
1116
+ wp_localize_script( 'cwp_top_javascript', 'cwp_top_ajaxload', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
1117
+ }
1118
+ }
1119
+
1120
+ }
1121
+
1122
+ function top_check_user_role( $role, $user_id = null ) {
1123
+
1124
+ if ( is_numeric( $user_id ) )
1125
+ $user = get_userdata( $user_id );
1126
+ else
1127
+ $user = wp_get_current_user();
1128
+
1129
+ if ( empty( $user ) )
1130
+ return false;
1131
+
1132
+ return in_array( $role, (array) $user->roles );
1133
+ }
1134
+
1135
+ public function addAdminMenuPage()
1136
+ {
1137
+ global $cwp_top_settings; // Global Tweet Old Post Settings
1138
+ if (!current_user_can('manage_options') && $this->top_check_user_role( 'Administrator' ))
1139
+ $cap = 1;
1140
+ else
1141
+ $cap='manage_options';
1142
+ add_menu_page($cwp_top_settings['name'], $cwp_top_settings['name'], $cap, $cwp_top_settings['slug'], array($this, 'loadMainView'),'dashicons-twitter','99.87514');
1143
+ add_submenu_page($cwp_top_settings['slug'], __('Exclude Posts',CWP_TEXTDOMAIN), __('Exclude Posts',CWP_TEXTDOMAIN), 'manage_options', __('ExcludePosts',CWP_TEXTDOMAIN), 'top_exclude');
1144
+ }
1145
+
1146
+ public function loadMainView()
1147
+ {
1148
+ global $cwp_top_fields;
1149
+ foreach ($cwp_top_fields as $field => $value) {
1150
+ $cwp_top_fields[$field]['option_value'] = get_option($cwp_top_fields[$field]['option']);
1151
+ }
1152
+ require_once(plugin_dir_path( __FILE__ )."view.php");
1153
+ }
1154
+
1155
+ // Sends a request to the passed URL
1156
+ public function sendRequest($url, $method='GET', $data='', $auth_user='', $auth_pass='') {
1157
+
1158
+ $ch = curl_init($url);
1159
+
1160
+ if (strtoupper($method) == "POST") {
1161
+ curl_setopt($ch, CURLOPT_POST, 1);
1162
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
1163
+ }
1164
+
1165
+ if (ini_get('open_basedir') == '' && ini_get('safe_mode') == 'Off') {
1166
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
1167
+ }
1168
+
1169
+ curl_setopt($ch, CURLOPT_HEADER, 0);
1170
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
1171
+
1172
+ if ($auth_user != '' && $auth_pass != '') {
1173
+ curl_setopt($ch, CURLOPT_USERPWD, "{$auth_user}:{$auth_pass}");
1174
+ }
1175
+
1176
+ $response = curl_exec($ch);
1177
+ $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
1178
+
1179
+ curl_close($ch);
1180
+
1181
+ if ($httpcode != 200) {
1182
+ return $httpcode;
1183
+ }
1184
+
1185
+ return $response;
1186
+ }
1187
+
1188
+ // Shortens the url.
1189
+ public function shortenURL($url, $service, $id, $bitly_key, $bitly_user) {
1190
+
1191
+ if ($service == "bit.ly") {
1192
+ //$shortURL = $url;
1193
+ $url = trim($url);
1194
+ $bitly_key = trim($bitly_key);
1195
+ $bitly_user = trim($bitly_user);
1196
+ $shortURL = "http://api.bit.ly/v3/shorten?format=txt&login=".$bitly_user."&apiKey=".$bitly_key."&longUrl={$url}";
1197
+ $shortURL = $this->sendRequest($shortURL, 'GET');
1198
+ } elseif ($service == "tr.im") {
1199
+ $shortURL = "http://api.tr.im/api/trim_simple?url={$url}";
1200
+ $shortURL = $this->sendRequest($shortURL, 'GET');
1201
+ } elseif ($service == "3.ly") {
1202
+ $shortURL = "http://3.ly/?api=em5893833&u={$url}";
1203
+ $shortURL = $this->sendRequest($shortURL, 'GET');
1204
+ } elseif ($service == "tinyurl") {
1205
+ $shortURL = "http://tinyurl.com/api-create.php?url=" . $url;
1206
+ $shortURL = $this->sendRequest($shortURL, 'GET');
1207
+ } elseif ($service == "u.nu") {
1208
+ $shortURL = "http://u.nu/unu-api-simple?url={$url}";
1209
+ $shortURL = $this->sendRequest($shortURL, 'GET');
1210
+ } elseif ($service == "1click.at") {
1211
+ $shortURL = "http://1click.at/api.php?action=shorturl&url={$url}&format=simple";
1212
+ $shortURL = $this->sendRequest($shortURL, 'GET');
1213
+ } elseif ($service == "is.gd") {
1214
+ $shortURL = "http://is.gd/api.php?longurl={$url}";
1215
+ $shortURL = $this->sendRequest($shortURL, 'GET');
1216
+ } elseif ($service == "t.co") {
1217
+ $shortURL = "http://twitter.com/share?url={$url}";
1218
+ $shortURL = $this->sendRequest($shortURL, 'GET');
1219
+ } else {
1220
+ $shortURL = wp_get_shortlink($id);
1221
+ }
1222
+
1223
+ if($shortURL != ' 400 ') {
1224
+ return $shortURL;
1225
+ }
1226
+ }
1227
+
1228
+ }
1229
+ }
1230
+
1231
+ if(class_exists('CWP_TOP_Core')) {
1232
+ $CWP_TOP_Core = new CWP_TOP_Core;
1233
+ }
top-excludepost.php → inc/exclude-posts.php RENAMED
@@ -1,351 +1,367 @@
1
- <?php
2
-
3
- require_once('tweet-old-post.php');
4
- require_once('top-core.php');
5
- require_once( 'Include/top-oauth.php' );
6
- require_once('xml.php');
7
-
8
- if (!function_exists ("mysql_real_escape_string"))
9
- {
10
- function mysql_real_escape_string ($str)
11
- {
12
- return mysql_escape_string ($str);
13
- }
14
- }
15
-
16
- function top_exclude() {
17
- if (current_user_can('manage_options'))
18
- {
19
- $message = null;
20
- $message_updated = __("Tweet Old Post Options Updated.", 'TweetOldPost');
21
- $response = null;
22
- $records_per_page = 20;
23
- $omit_cat=get_option('top_opt_omit_cats');
24
- $update_text = "Exclude Selected";
25
- $search_term="";
26
- $ex_filter="all";
27
- $cat_filter=0;
28
-
29
- global $wpdb;
30
-
31
- if ((!isset($_GET["paged"])) && (!isset($_POST["delids"]))) {
32
- $exposts = get_option('top_opt_excluded_post');
33
- } else {
34
- $exposts = $_POST["delids"];
35
- }
36
-
37
-
38
-
39
- $exposts = preg_replace('/,,+/', ',', $exposts);
40
- if (substr($exposts, 0, 1) == ",") {
41
- $exposts = substr($exposts, 1, strlen($exposts));
42
- }
43
- if (substr($exposts, -1, 1) == ",") {
44
- $exposts = substr($exposts, 0, strlen($exposts) - 1);
45
- }
46
- $excluded_posts = explode(",", $exposts);
47
-
48
-
49
- if (!isset($_GET['paged']))
50
- $_GET['paged'] = 1;
51
-
52
- if (isset($_POST["excludeall"])) {
53
- if (substr($_POST["delids"], 0, -1) == "") {
54
- print('
55
- <div id="message" style="margin-top:30px" class="updated fade">
56
- <p>' . __('No post selected please select a post to be excluded.', 'TweetOldPost') . '</p>
57
- </div>');
58
- } else {
59
-
60
- update_option('top_opt_excluded_post',$exposts);
61
- print('
62
- <div id="message" style="margin-top:30px" class="updated fade">
63
- <p>' . __('Posts excluded successfully.', 'TweetOldPost') . '</p>
64
- </div>');
65
- }
66
- }
67
-
68
- print('
69
- <div id="help" style="overflow: hidden;padding-left:15px; font-size: 14px; margin-top: 25px; background-color: rgb(239, 239, 239);">
70
- <p>' . __('This page shows all the post from your <a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=TweetOldPost">selected categories</a>.<br /> All the post excluded will not be tweeted even if the category is selected.', 'TweetOldPost') . '</p>
71
- </div>');
72
-
73
- print('
74
- <div id="help" style="overflow: hidden;padding-left:15px; font-size: 14px; margin-top: 25px;margin-bottom:25px; background-color: rgb(239, 239, 239);">
75
- <p>' . __('You have selected following POST IDs to be excluded from tweeting: <span id="excludeList" style="font-weight:bold;font-style:italic;"></span>.<br /> <strong>Note:</strong> If you have made any change and dint hit "Exclude Selected" button changes will not be saved. Please hit "Exclude Selected" button after making any changes.', 'TweetOldPost') . '</p>
76
- </div>');
77
-
78
- $sql = "SELECT p.ID,p.post_title,p.post_date,u.user_nicename,p.guid FROM $wpdb->posts p join $wpdb->users u on p.post_author=u.ID WHERE post_type = 'post'
79
- AND post_status = 'publish'";
80
-
81
-
82
- if(isset($_POST["setFilter"]))
83
- {
84
- if($_POST["cat"] != 0)
85
- {
86
-
87
- $cat_filter = $_POST["cat"];
88
- $cat_filter = mysql_real_escape_string($cat_filter);
89
- $sql = $sql . " and p.ID IN ( SELECT tr.object_id FROM ".$wpdb->prefix."term_relationships AS tr INNER JOIN ".$wpdb->prefix."term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy = 'category' AND tt.term_id=" . $cat_filter . ")";
90
-
91
- }
92
- else
93
- {
94
- $sql = $sql . " and p.ID NOT IN ( SELECT tr.object_id FROM ".$wpdb->prefix."term_relationships AS tr INNER JOIN ".$wpdb->prefix."term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy = 'category' AND tt.term_id IN (" . $omit_cat . "))";
95
- $cat_filter = 0;
96
- }
97
-
98
- if($_POST["selFilter"] == "excluded")
99
- {
100
- $sql = $sql . " and p.ID IN (".$exposts.")";
101
- $update_text = "Update";
102
- $ex_filter = "excluded";
103
- }
104
-
105
- }
106
- else
107
- {
108
- if($omit_cat !='')
109
- {
110
- $sql = $sql . " and p.ID NOT IN ( SELECT tr.object_id FROM ".$wpdb->prefix."term_relationships AS tr INNER JOIN ".$wpdb->prefix."term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy = 'category' AND tt.term_id IN (" . $omit_cat . "))";
111
- }
112
- }
113
-
114
- if(isset($_POST["s"]))
115
- {
116
- if(trim( $_POST["s"]) != "")
117
- {
118
- $_s = $_POST["s"];
119
- $_s = mysql_real_escape_string($_s);
120
- $sql = $sql . " and post_title like '%" . trim( $_s) . "%'";
121
- $search_term = trim( $_s);
122
- }
123
- }
124
-
125
- $sql = $sql . " order by post_date desc";
126
- $posts = $wpdb->get_results($sql);
127
-
128
- $from = $_GET["paged"] * $records_per_page - $records_per_page;
129
- $to = min($_GET['paged'] * $records_per_page, count($posts));
130
- $post_count =count($posts);
131
-
132
- $ex = 0;
133
- for ($j = 0; $j < $post_count; $j++) {
134
- if (in_array($posts[$j]->ID, $excluded_posts)) {
135
- $excludeList[$ex] = $posts[$j]->ID;
136
- $ex = $ex + 1;
137
- }
138
- }
139
- if($excludeList.length >0)
140
- {
141
- $exposts = implode(",",$excludeList);
142
- }
143
- print('<form id="top_TweetOldPost" name="top_TweetOldPost" action="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=ExcludePosts" method="post"><input type="hidden" name="delids" id="delids" value="' . $exposts . '" /><input type="submit" id="pageit" name="pageit" style="display:none" value="" /> ');
144
- print('<div class="tablenav"><div class="alignleft actions">');
145
- print('<input type="submit" class="button-secondary" name="excludeall" value="' . __($update_text, 'TweetOldPost') . '" />');
146
- print('<select name="selFilter" id="selFilter" style="width:100px"><option value="all" '.top_opt_optionselected("all",$ex_filter).'> All </option><option value="excluded" '.top_opt_optionselected("excluded",$ex_filter).'> Excluded </option></select>');
147
- $dropdown_options = array('show_option_all' => __('Selected Categories'),'exclude' =>$omit_cat,'selected' =>$cat_filter);
148
- wp_dropdown_categories($dropdown_options);
149
- print('<input type="submit" class="button-secondary" name="setFilter" value="' . __('Filter', 'TweetOldPost') . '" />');
150
- print('<p class="search-box" style="margin:0px">
151
- <input type="text" id="post-search-input" name="s" value="'.$search_term.'" />
152
- <input type="submit" value="Search Posts" name="search" class="button" />
153
- </p>');
154
- print('</div>');
155
- if (count($posts) > 0) {
156
- $page_links = paginate_links(array(
157
- 'base' => add_query_arg('paged', '%#%'),
158
- 'format' => '',
159
- 'prev_text' => __('&laquo;'),
160
- 'next_text' => __('&raquo;'),
161
- 'total' => ceil(count($posts) / $records_per_page),
162
- 'current' => $_GET['paged']
163
- ));
164
-
165
- if ($page_links) {
166
-
167
- print('<div class="tablenav-pages">');
168
- $page_links_text = sprintf('<span class="displaying-num">' . __('Displaying %s&#8211;%s of %s') . '</span>%s',
169
- number_format_i18n(( $_GET['paged'] - 1 ) * $records_per_page + 1),
170
- number_format_i18n(min($_GET['paged'] * $records_per_page, count($posts))),
171
- number_format_i18n(count($posts)),
172
- $page_links
173
- );
174
- echo $page_links_text;
175
- print('</div>');
176
- }
177
- print('</div>');//tablenav div
178
-
179
- print(' <div class="wrap">
180
- <table class="widefat fixed">
181
- <thead>
182
- <tr>
183
- <th class="manage-column column-cb check-column"><input name="headchkbx" onchange="javascript:checkedAll();" type="checkbox" value="checkall"/></th>
184
- <th>No.</th>
185
- <th>Id</th>
186
- <th>Post Title</th>
187
- <th>Author</th>
188
- <th>Post Date</th>
189
- <th>Categories</th>
190
- </tr>
191
- </thead>
192
- <tbody>
193
- ');
194
-
195
-
196
-
197
-
198
- for ($i = $from; $i < $to; $i++) {
199
- $categories = get_the_category($posts[$i]->ID);
200
- if (!empty($categories)) {
201
- $out = array();
202
- foreach ($categories as $c)
203
- $out[] = "<a href='edit.php?post_type={$post->post_type}&amp;category_name={$c->slug}'> " . esc_html(sanitize_term_field('name', $c->name, $c->term_id, 'category', 'display')) . "</a>";
204
- $cats = join(', ', $out);
205
- } else {
206
- $cats = 'Uncategorized';
207
- }
208
-
209
- if (in_array($posts[$i]->ID, $excluded_posts)) {
210
- $checked = "Checked";
211
- $bgcolor="#FFCC99";
212
- } else {
213
- $checked = "";
214
- $bgcolor="#FFF";
215
- }
216
-
217
- print('
218
-
219
- <tr style="background-color:'.$bgcolor.';">
220
- <th class="check-column">
221
- <input type="checkbox" name="chkbx" id="del' . $posts[$i]->ID . '" onchange="javascript:managedelid(this,\'' . $posts[$i]->ID . '\');" value="' . $posts[$i]->ID . '" ' . $checked . '/>
222
- </th>
223
- <td>
224
- ' . ($i + 1) . '
225
- </td>
226
- <td>
227
- ' . $posts[$i]->ID . '
228
- </td>
229
- <td>
230
- <a href=' . $posts[$i]->guid . ' target="_blank">' . $posts[$i]->post_title . '</a>
231
- </td>
232
- <td>
233
- ' . $posts[$i]->user_nicename . '
234
- </td>
235
- <td>
236
- ' . $posts[$i]->post_date . '
237
- </td>
238
- <td>
239
- ' . $cats . '
240
- </td>
241
- </tr>
242
-
243
- ');
244
- }
245
- print('
246
- </tbody>
247
- </table>
248
- </div>
249
- ');
250
-
251
- print('<div class="tablenav"><div class="alignleft actions"><input type="submit" class="button-secondary" name="excludeall" value="' . __($update_text, 'TweetOldPost') . '" /></div>');
252
-
253
- if ($page_links) {
254
-
255
- print('<div class="tablenav-pages">');
256
- $page_links_text = sprintf('<span class="displaying-num">' . __('Displaying %s&#8211;%s of %s') . '</span>%s',
257
- number_format_i18n(( $_GET['paged'] - 1 ) * $records_per_page + 1),
258
- number_format_i18n(min($_GET['paged'] * $records_per_page, count($posts))),
259
- number_format_i18n(count($posts)),
260
- $page_links
261
- );
262
- echo $page_links_text;
263
- print('</div>');
264
- }
265
- print('</div>');
266
-
267
-
268
-
269
- print('
270
- <script language="javascript">
271
-
272
-
273
- jQuery(function() {
274
- jQuery(".page-numbers").click(function(e){
275
- jQuery("#top_TweetOldPost").attr("action",jQuery(this).attr("href"));
276
- e.preventDefault();
277
- jQuery("#pageit").click();
278
- });// page number click end
279
- });//jquery document.ready end
280
-
281
- function setExcludeList(exlist)
282
- {
283
- jQuery("#excludeList").html("\"" + exlist + "\"");
284
- }
285
-
286
-
287
- function managedelid(ctrl,id)
288
- {
289
-
290
- var delids = document.getElementById("delids").value;
291
- if(ctrl.checked)
292
- {
293
- delids=addId(delids,id);
294
- }
295
- else
296
- {
297
- delids=removeId(delids,id);
298
- }
299
- document.getElementById("delids").value=delids;
300
- setExcludeList(delids);
301
- }
302
-
303
- function removeId(list, value) {
304
- list = list.split(",");
305
- if(list.indexOf(value) != -1)
306
- list.splice(list.indexOf(value), 1);
307
- return list.join(",");
308
- }
309
-
310
-
311
- function addId(list,value)
312
- {
313
- list = list.split(",");
314
- if(list.indexOf(value) == -1)
315
- list.push(value);
316
- return list.join(",");
317
- }
318
-
319
- function checkedAll() {
320
- var ischecked=document.top_TweetOldPost.headchkbx.checked;
321
- var delids="";
322
- for (var i = 0; i < document.top_TweetOldPost.chkbx.length; i++) {
323
- document.top_TweetOldPost.chkbx[i].checked = ischecked;
324
- if(ischecked)
325
- delids=delids+document.top_TweetOldPost.chkbx[i].value+",";
326
- }
327
- document.getElementById("delids").value=delids;
328
- }
329
-
330
- setExcludeList("' . $exposts . '");
331
-
332
- </script>
333
- ');
334
- }
335
- else
336
- {
337
- print('</div>');//tablenav div
338
- print('
339
- <div id="message" style="margin-top:30px" class="updated fade">
340
- <p>' . __('No Posts found. Review your search or filter criteria/term.', 'TweetOldPost') . '</p>
341
- </div>');
342
- }
343
- print('</form>');
344
- } else {
345
- print('
346
- <div id="message" class="updated fade">
347
- <p>' . __('You do not have enough permission to set the option. Please contact your admin.', 'TweetOldPost') . '</p>
348
- </div>');
349
- }
350
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
351
  ?>
1
+ <?php
2
+
3
+ require_once(PLUGINPATH.'/tweet-old-post.php');
4
+ require_once(PLUGINPATH.'/inc/xml.php');
5
+
6
+ if (!function_exists ("mysql_real_escape_string"))
7
+ {
8
+ function mysql_real_escape_string ($str)
9
+ {
10
+ return mysql_escape_string ($str);
11
+ }
12
+ }
13
+ function top_opt_optionselected($opValue, $value) {
14
+ if ($opValue == $value) {
15
+ return 'selected="selected"';
16
+ }
17
+ return '';
18
+ }
19
+
20
+ function top_exclude() {
21
+ if (current_user_can('manage_options'))
22
+ {
23
+ $message = null;
24
+ $message_updated = __("Tweet Old Post Options Updated.", 'TweetOldPost');
25
+ $response = null;
26
+ $records_per_page = 20;
27
+ $twp_obj = new CWP_TOP_Core;
28
+ $omit_cat = "";
29
+
30
+ //$omit_cat=get_option('top_opt_omit_cats');
31
+ $update_text = "Exclude Selected";
32
+ $search_term="";
33
+ $ex_filter="all";
34
+ $cat_filter=0;
35
+
36
+ global $wpdb;
37
+
38
+ if ((!isset($_GET["paged"])) && (!isset($_POST["delids"]))) {
39
+ $exposts = get_option('top_opt_excluded_post');
40
+ } else {
41
+ $exposts = $_POST["delids"];
42
+ }
43
+
44
+
45
+
46
+ $exposts = preg_replace('/,,+/', ',', $exposts);
47
+ if (substr($exposts, 0, 1) == ",") {
48
+ $exposts = substr($exposts, 1, strlen($exposts));
49
+ }
50
+ if (substr($exposts, -1, 1) == ",") {
51
+ $exposts = substr($exposts, 0, strlen($exposts) - 1);
52
+ }
53
+ $excluded_posts = explode(",", $exposts);
54
+
55
+
56
+ if (!isset($_GET['paged']))
57
+ $_GET['paged'] = 1;
58
+
59
+ if (isset($_POST["excludeall"])) {
60
+ if (substr($_POST["delids"], 0, -1) == "") {
61
+ print('
62
+ <div id="message" style="margin-top:30px" class="updated fade">
63
+ <p>' . __('No post selected please select a post to be excluded.', 'TweetOldPost') . '</p>
64
+ </div>');
65
+ } else {
66
+
67
+ update_option('top_opt_excluded_post',$exposts);
68
+ print('
69
+ <div id="message" style="margin-top:30px" class="updated fade">
70
+ <p>' . __('Posts excluded successfully.', 'TweetOldPost') . '</p>
71
+ </div>');
72
+ }
73
+ }
74
+ global $cwp_top_fields;
75
+ foreach ($cwp_top_fields as $field => $value) {
76
+ $cwp_top_fields[$field]['option_value'] = get_option($cwp_top_fields[$field]['option']);
77
+ }
78
+
79
+
80
+ require_once(plugin_dir_path( __FILE__ )."view-exclude.php");
81
+
82
+
83
+ $sql = "SELECT p.ID,p.post_title,p.post_date,u.user_nicename,p.guid,p.post_type FROM $wpdb->posts p join $wpdb->users u on p.post_author=u.ID WHERE (post_type = 'post')
84
+ AND post_status = 'publish'";
85
+
86
+
87
+ if(isset($_POST["setFilter"]))
88
+ {
89
+ if($_POST["cat"] != 0)
90
+ {
91
+
92
+ $cat_filter = $_POST["cat"];
93
+ $cat_filter = mysql_real_escape_string($cat_filter);
94
+ $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 . ")";
95
+
96
+ }
97
+ else
98
+ {
99
+ $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 . "))";
100
+ $cat_filter = 0;
101
+ }
102
+
103
+ if($_POST["selFilter"] == "excluded")
104
+ {
105
+ $sql = $sql . " and p.ID IN (".$exposts.")";
106
+ $update_text = "Update";
107
+ $ex_filter = "excluded";
108
+ }
109
+
110
+ }
111
+ else
112
+ {
113
+ if($omit_cat !='')
114
+ {
115
+ $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 . "))";
116
+ }
117
+ }
118
+
119
+ if(isset($_POST["s"]))
120
+ {
121
+ if(trim( $_POST["s"]) != "")
122
+ {
123
+ $_s = $_POST["s"];
124
+ $_s = mysql_real_escape_string($_s);
125
+ $sql = $sql . " and post_title like '%" . trim( $_s) . "%'";
126
+ $search_term = trim( $_s);
127
+ }
128
+ }
129
+
130
+ $sql = $sql . " order by post_date desc";
131
+ $posts = $wpdb->get_results($sql);
132
+
133
+
134
+
135
+ $from = $_GET["paged"] * $records_per_page - $records_per_page;
136
+ $to = min($_GET['paged'] * $records_per_page, count($posts));
137
+ $post_count =count($posts);
138
+
139
+ $ex = 0;
140
+ $excludeList = array();
141
+ for ($j = 0; $j < $post_count; $j++) {
142
+ if (in_array($posts[$j]->ID, $excluded_posts)) {
143
+ $excludeList[$ex] = $posts[$j]->ID;
144
+ $ex = $ex + 1;
145
+ }
146
+ }
147
+ if(count($excludeList) >0)
148
+ {
149
+ $exposts = implode(",",$excludeList);
150
+ }
151
+ 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="" /> ');
152
+ print('<div class="tablenav"><div class="alignleft actions">');
153
+ print('<input type="submit" class="button-secondary" name="excludeall" value="' . __($update_text, 'TweetOldPost') . '" />');
154
+ 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>');
155
+ $dropdown_options = array('show_option_all' => __('Selected Categories'),'exclude' =>$omit_cat,'selected' =>$cat_filter);
156
+ wp_dropdown_categories($dropdown_options);
157
+ print('<input type="submit" class="button-secondary" name="setFilter" value="' . __('Filter', 'TweetOldPost') . '" />');
158
+ print('<p class="search-box" style="margin:0px">
159
+ <input type="text" id="post-search-input" name="s" value="'.$search_term.'" />
160
+ <input type="submit" value="Search Posts" name="search" class="button" />
161
+ </p>');
162
+ print('</div>');
163
+ if (count($posts) > 0) {
164
+
165
+ $page_links = paginate_links(array(
166
+ 'base' => add_query_arg('paged', '%#%'),
167
+ 'format' => '',
168
+ 'prev_text' => __('&laquo;'),
169
+ 'next_text' => __('&raquo;'),
170
+ 'total' => ceil(count($posts) / $records_per_page),
171
+ 'current' => $_GET['paged']
172
+ ));
173
+
174
+ if ($page_links) {
175
+
176
+ print('<div class="tablenav-pages">');
177
+ $page_links_text = sprintf('<span class="displaying-num">' . __('Displaying %s&#8211;%s of %s') . '</span>%s',
178
+ number_format_i18n(( $_GET['paged'] - 1 ) * $records_per_page + 1),
179
+ number_format_i18n(min($_GET['paged'] * $records_per_page, count($posts))),
180
+ number_format_i18n(count($posts)),
181
+ $page_links
182
+ );
183
+ echo $page_links_text;
184
+ print('</div>');
185
+ }
186
+ print('</div>');//tablenav div
187
+
188
+ print(' <div class="wrap">
189
+ <table class="widefat fixed">
190
+ <thead>
191
+ <tr>
192
+ <th class="manage-column column-cb check-column"><input name="headchkbx" onchange="javascript:checkedAll();" type="checkbox" value="checkall"/></th>
193
+ <th>No.</th>
194
+ <th>Id</th>
195
+ <th>Post Title</th>
196
+ <th>Author</th>
197
+ <th>Post Date</th>
198
+ <th>Categories</th>
199
+ <th>Post Type</th>
200
+ </tr>
201
+ </thead>
202
+ <tbody>
203
+ ');
204
+
205
+
206
+
207
+
208
+ for ($i = $from; $i < $to; $i++) {
209
+
210
+
211
+ $categories = get_the_category($posts[$i]->ID);
212
+ if (!empty($categories)) {
213
+ $out = array();
214
+ foreach ($categories as $c)
215
+ $out[] = "<a href='edit.php?post_type={$posts[$i]->post_type}&amp;category_name={$c->slug}'> " . esc_html(sanitize_term_field('name', $c->name, $c->term_id, 'category', 'display')) . "</a>";
216
+ $cats = join(', ', $out);
217
+ }
218
+ else {
219
+ $cats = 'Uncategorized';
220
+ }
221
+
222
+ if (in_array($posts[$i]->ID, $excluded_posts)) {
223
+ $checked = "Checked";
224
+ $bgcolor="#FFCC99";
225
+ } else {
226
+ $checked = "";
227
+ $bgcolor="#FFF";
228
+ }
229
+
230
+ print('
231
+
232
+ <tr style="background-color:'.$bgcolor.';">
233
+ <th class="check-column">
234
+ <input type="checkbox" name="chkbx" id="del' . $posts[$i]->ID . '" onchange="javascript:managedelid(this,\'' . $posts[$i]->ID . '\');" value="' . $posts[$i]->ID . '" ' . $checked . '/>
235
+ </th>
236
+ <td>
237
+ ' . ($i + 1) . '
238
+ </td>
239
+ <td>
240
+ ' . $posts[$i]->ID . '
241
+ </td>
242
+ <td>
243
+ <a href=' . $posts[$i]->guid . ' target="_blank">' . $posts[$i]->post_title . '</a>
244
+ </td>
245
+ <td>
246
+ ' . $posts[$i]->user_nicename . '
247
+ </td>
248
+ <td>
249
+ ' . $posts[$i]->post_date . '
250
+ </td>
251
+ <td>
252
+ ' . $cats . '
253
+ </td>
254
+ <td>
255
+ ' . $posts[$i]->post_type . '
256
+ </td>
257
+ </tr>
258
+
259
+ ');
260
+ }
261
+ print('
262
+ </tbody>
263
+ </table>
264
+ </div>
265
+ ');
266
+
267
+ print('<div class="tablenav"><div class="alignleft actions"><input type="submit" class="button-secondary" name="excludeall" value="' . __($update_text, 'TweetOldPost') . '" /></div>');
268
+
269
+ if ($page_links) {
270
+
271
+ print('<div class="tablenav-pages">');
272
+ $page_links_text = sprintf('<span class="displaying-num">' . __('Displaying %s&#8211;%s of %s') . '</span>%s',
273
+ number_format_i18n(( $_GET['paged'] - 1 ) * $records_per_page + 1),
274
+ number_format_i18n(min($_GET['paged'] * $records_per_page, count($posts))),
275
+ number_format_i18n(count($posts)),
276
+ $page_links
277
+ );
278
+ echo $page_links_text;
279
+ print('</div>');
280
+ }
281
+ print('</div></div>');
282
+
283
+
284
+
285
+ print('
286
+ <script language="javascript">
287
+
288
+
289
+ jQuery(function() {
290
+ jQuery(".page-numbers").click(function(e){
291
+ jQuery("#top_TweetOldPost").attr("action",jQuery(this).attr("href"));
292
+ e.preventDefault();
293
+ jQuery("#pageit").click();
294
+ });// page number click end
295
+ });//jquery document.ready end
296
+
297
+ function setExcludeList(exlist)
298
+ {
299
+ jQuery("#excludeList").html("\"" + exlist + "\"");
300
+ }
301
+
302
+
303
+ function managedelid(ctrl,id)
304
+ {
305
+
306
+ var delids = document.getElementById("delids").value;
307
+ if(ctrl.checked)
308
+ {
309
+ delids=addId(delids,id);
310
+ }
311
+ else
312
+ {
313
+ delids=removeId(delids,id);
314
+ }
315
+ document.getElementById("delids").value=delids;
316
+ setExcludeList(delids);
317
+ }
318
+
319
+ function removeId(list, value) {
320
+ list = list.split(",");
321
+ if(list.indexOf(value) != -1)
322
+ list.splice(list.indexOf(value), 1);
323
+ return list.join(",");
324
+ }
325
+
326
+
327
+ function addId(list,value)
328
+ {
329
+ list = list.split(",");
330
+ if(list.indexOf(value) == -1)
331
+ list.push(value);
332
+ return list.join(",");
333
+ }
334
+
335
+ function checkedAll() {
336
+ var ischecked=document.top_TweetOldPost.headchkbx.checked;
337
+ var delids="";
338
+ for (var i = 0; i < document.top_TweetOldPost.chkbx.length; i++) {
339
+ document.top_TweetOldPost.chkbx[i].checked = ischecked;
340
+ if(ischecked)
341
+ delids=delids+document.top_TweetOldPost.chkbx[i].value+",";
342
+ }
343
+ document.getElementById("delids").value=delids;
344
+ }
345
+
346
+ setExcludeList("' . $exposts . '");
347
+
348
+ </script>
349
+ ');
350
+ }
351
+ else
352
+ {
353
+ print('</div>');//tablenav div
354
+ print('
355
+ <div id="message" style="margin-top:30px" class="updated fade">
356
+ <p>' . __('No Posts found. Review your search or filter criteria/term.', 'TweetOldPost') . '</p>
357
+ </div>');
358
+ }
359
+ print('</form>');
360
+ } else {
361
+ print('
362
+ <div id="message" class="updated fade">
363
+ <p>' . __('You do not have enough permission to set the option. Please contact your admin.', 'TweetOldPost') . '</p>
364
+ </div>');
365
+ }
366
+ }
367
  ?>
inc/oAuth/OAuth.php ADDED
@@ -0,0 +1,893 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // vim: foldmethod=marker
3
+
4
+ /* Generic exception class
5
+ */
6
+ if (!class_exists('OAuthException')) {
7
+ class OAuthException extends Exception {
8
+ // pass
9
+ }
10
+ }
11
+ if (!class_exists('OAuthConsumer')) {
12
+ class OAuthConsumer {
13
+ public $key;
14
+ public $secret;
15
+
16
+ function __construct($key, $secret, $callback_url=NULL) {
17
+ $this->key = $key;
18
+ $this->secret = $secret;
19
+ $this->callback_url = $callback_url;
20
+ }
21
+
22
+ function __toString() {
23
+ return "OAuthConsumer[key=$this->key,secret=$this->secret]";
24
+ }
25
+ }
26
+ }
27
+ if (!class_exists('OAuthToken')) {
28
+ class OAuthToken {
29
+ // access tokens and request tokens
30
+ public $key;
31
+ public $secret;
32
+
33
+ /**
34
+ * key = the token
35
+ * secret = the token secret
36
+ */
37
+ function __construct($key, $secret) {
38
+ $this->key = $key;
39
+ $this->secret = $secret;
40
+ }
41
+
42
+ /**
43
+ * generates the basic string serialization of a token that a server
44
+ * would respond to request_token and access_token calls with
45
+ */
46
+ function to_string() {
47
+ return "oauth_token=" .
48
+ OAuthUtil::urlencode_rfc3986($this->key) .
49
+ "&oauth_token_secret=" .
50
+ OAuthUtil::urlencode_rfc3986($this->secret);
51
+ }
52
+
53
+ function __toString() {
54
+ return $this->to_string();
55
+ }
56
+ }
57
+ }
58
+ /**
59
+ * A class for implementing a Signature Method
60
+ * See section 9 ("Signing Requests") in the spec
61
+ */
62
+ if (!class_exists('OAuthSignatureMethod')) {
63
+ abstract class OAuthSignatureMethod {
64
+ /**
65
+ * Needs to return the name of the Signature Method (ie HMAC-SHA1)
66
+ * @return string
67
+ */
68
+ abstract public function get_name();
69
+
70
+ /**
71
+ * Build up the signature
72
+ * NOTE: The output of this function MUST NOT be urlencoded.
73
+ * the encoding is handled in OAuthRequest when the final
74
+ * request is serialized
75
+ * @param OAuthRequest $request
76
+ * @param OAuthConsumer $consumer
77
+ * @param OAuthToken $token
78
+ * @return string
79
+ */
80
+ abstract public function build_signature($request, $consumer, $token);
81
+
82
+ /**
83
+ * Verifies that a given signature is correct
84
+ * @param OAuthRequest $request
85
+ * @param OAuthConsumer $consumer
86
+ * @param OAuthToken $token
87
+ * @param string $signature
88
+ * @return bool
89
+ */
90
+ public function check_signature($request, $consumer, $token, $signature) {
91
+ $built = $this->build_signature($request, $consumer, $token);
92
+ return $built == $signature;
93
+ }
94
+ }
95
+ }
96
+ /**
97
+ * The HMAC-SHA1 signature method uses the HMAC-SHA1 signature algorithm as defined in [RFC2104]
98
+ * where the Signature Base String is the text and the key is the concatenated values (each first
99
+ * encoded per Parameter Encoding) of the Consumer Secret and Token Secret, separated by an '&'
100
+ * character (ASCII code 38) even if empty.
101
+ * - Chapter 9.2 ("HMAC-SHA1")
102
+ */
103
+ if (!class_exists('OAuthSignatureMethod_HMAC_SHA1')) {
104
+ class OAuthSignatureMethod_HMAC_SHA1 extends OAuthSignatureMethod {
105
+ function get_name() {
106
+ return "HMAC-SHA1";
107
+ }
108
+
109
+
110
+ public function build_signature($request, $consumer, $token) {
111
+ $base_string = $request->get_signature_base_string();
112
+ $request->base_string = $base_string;
113
+
114
+ $key_parts = array(
115
+ $consumer->secret,
116
+ ($token) ? $token->secret : ""
117
+ );
118
+
119
+ $key_parts = OAuthUtil::urlencode_rfc3986($key_parts);
120
+ $key = implode('&', $key_parts);
121
+
122
+ return base64_encode(hash_hmac('sha1', $base_string, $key, true));
123
+ }
124
+ }
125
+ }
126
+ /**
127
+ * The PLAINTEXT method does not provide any security protection and SHOULD only be used
128
+ * over a secure channel such as HTTPS. It does not use the Signature Base String.
129
+ * - Chapter 9.4 ("PLAINTEXT")
130
+ */
131
+ if (!class_exists('OAuthSignatureMethod_PLAINTEXT')) {
132
+ class OAuthSignatureMethod_PLAINTEXT extends OAuthSignatureMethod {
133
+ public function get_name() {
134
+ return "PLAINTEXT";
135
+ }
136
+
137
+ /**
138
+ * oauth_signature is set to the concatenated encoded values of the Consumer Secret and
139
+ * Token Secret, separated by a '&' character (ASCII code 38), even if either secret is
140
+ * empty. The result MUST be encoded again.
141
+ * - Chapter 9.4.1 ("Generating Signatures")
142
+ *
143
+ * Please note that the second encoding MUST NOT happen in the SignatureMethod, as
144
+ * OAuthRequest handles this!
145
+ */
146
+ public function build_signature($request, $consumer, $token) {
147
+ $key_parts = array(
148
+ $consumer->secret,
149
+ ($token) ? $token->secret : ""
150
+ );
151
+
152
+ $key_parts = OAuthUtil::urlencode_rfc3986($key_parts);
153
+ $key = implode('&', $key_parts);
154
+ $request->base_string = $key;
155
+
156
+ return $key;
157
+ }
158
+ }
159
+ }
160
+
161
+ /**
162
+ * The RSA-SHA1 signature method uses the RSASSA-PKCS1-v1_5 signature algorithm as defined in
163
+ * [RFC3447] section 8.2 (more simply known as PKCS#1), using SHA-1 as the hash function for
164
+ * EMSA-PKCS1-v1_5. It is assumed that the Consumer has provided its RSA public key in a
165
+ * verified way to the Service Provider, in a manner which is beyond the scope of this
166
+ * specification.
167
+ * - Chapter 9.3 ("RSA-SHA1")
168
+ */
169
+ if (!class_exists('OAuthSignatureMethod_RSA_SHA1')) {
170
+ abstract class OAuthSignatureMethod_RSA_SHA1 extends OAuthSignatureMethod {
171
+ public function get_name() {
172
+ return "RSA-SHA1";
173
+ }
174
+
175
+ // Up to the SP to implement this lookup of keys. Possible ideas are:
176
+ // (1) do a lookup in a table of trusted certs keyed off of consumer
177
+ // (2) fetch via http using a url provided by the requester
178
+ // (3) some sort of specific discovery code based on request
179
+ //
180
+ // Either way should return a string representation of the certificate
181
+ protected abstract function fetch_public_cert(&$request);
182
+
183
+ // Up to the SP to implement this lookup of keys. Possible ideas are:
184
+ // (1) do a lookup in a table of trusted certs keyed off of consumer
185
+ //
186
+ // Either way should return a string representation of the certificate
187
+ protected abstract function fetch_private_cert(&$request);
188
+
189
+ public function build_signature($request, $consumer, $token) {
190
+ $base_string = $request->get_signature_base_string();
191
+ $request->base_string = $base_string;
192
+
193
+ // Fetch the private key cert based on the request
194
+ $cert = $this->fetch_private_cert($request);
195
+
196
+ // Pull the private key ID from the certificate
197
+ $privatekeyid = openssl_get_privatekey($cert);
198
+
199
+ // Sign using the key
200
+ $ok = openssl_sign($base_string, $signature, $privatekeyid);
201
+
202
+ // Release the key resource
203
+ openssl_free_key($privatekeyid);
204
+
205
+ return base64_encode($signature);
206
+ }
207
+
208
+ public function check_signature($request, $consumer, $token, $signature) {
209
+ $decoded_sig = base64_decode($signature);
210
+
211
+ $base_string = $request->get_signature_base_string();
212
+
213
+ // Fetch the public key cert based on the request
214
+ $cert = $this->fetch_public_cert($request);
215
+
216
+ // Pull the public key ID from the certificate
217
+ $publickeyid = openssl_get_publickey($cert);
218
+
219
+ // Check the computed signature against the one passed in the query
220
+ $ok = openssl_verify($base_string, $decoded_sig, $publickeyid);
221
+
222
+ // Release the key resource
223
+ openssl_free_key($publickeyid);
224
+
225
+ return $ok == 1;
226
+ }
227
+ }
228
+ }
229
+ if (!class_exists('OAuthRequest')) {
230
+ class OAuthRequest {
231
+ private $parameters;
232
+ private $http_method;
233
+ private $http_url;
234
+ // for debug purposes
235
+ public $base_string;
236
+ public static $version = '1.0';
237
+ public static $POST_INPUT = 'php://input';
238
+
239
+ function __construct($http_method, $http_url, $parameters=NULL) {
240
+ @$parameters or $parameters = array();
241
+ $parameters = array_merge( OAuthUtil::parse_parameters(parse_url($http_url, PHP_URL_QUERY)), $parameters);
242
+ $this->parameters = $parameters;
243
+ $this->http_method = $http_method;
244
+ $this->http_url = $http_url;
245
+ }
246
+
247
+
248
+ /**
249
+ * attempt to build up a request from what was passed to the server
250
+ */
251
+ public static function from_request($http_method=NULL, $http_url=NULL, $parameters=NULL) {
252
+ $scheme = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on")
253
+ ? 'http'
254
+ : 'https';
255
+ @$http_url or $http_url = $scheme .
256
+ '://' . $_SERVER['HTTP_HOST'] .
257
+ ':' .
258
+ $_SERVER['SERVER_PORT'] .
259
+ $_SERVER['REQUEST_URI'];
260
+ @$http_method or $http_method = $_SERVER['REQUEST_METHOD'];
261
+
262
+ // We weren't handed any parameters, so let's find the ones relevant to
263
+ // this request.
264
+ // If you run XML-RPC or similar you should use this to provide your own
265
+ // parsed parameter-list
266
+ if (!$parameters) {
267
+ // Find request headers
268
+ $request_headers = OAuthUtil::get_headers();
269
+
270
+ // Parse the query-string to find GET parameters
271
+ $parameters = OAuthUtil::parse_parameters($_SERVER['QUERY_STRING']);
272
+
273
+ // It's a POST request of the proper content-type, so parse POST
274
+ // parameters and add those overriding any duplicates from GET
275
+ if ($http_method == "POST"
276
+ && @strstr($request_headers["Content-Type"],
277
+ "application/x-www-form-urlencoded")
278
+ ) {
279
+ $post_data = OAuthUtil::parse_parameters(
280
+ file_get_contents(self::$POST_INPUT)
281
+ );
282
+ $parameters = array_merge($parameters, $post_data);
283
+ }
284
+
285
+ // We have a Authorization-header with OAuth data. Parse the header
286
+ // and add those overriding any duplicates from GET or POST
287
+ if (@substr($request_headers['Authorization'], 0, 6) == "OAuth ") {
288
+ $header_parameters = OAuthUtil::split_header(
289
+ $request_headers['Authorization']
290
+ );
291
+ $parameters = array_merge($parameters, $header_parameters);
292
+ }
293
+
294
+ }
295
+
296
+ return new OAuthRequest($http_method, $http_url, $parameters);
297
+ }
298
+
299
+ /**
300
+ * pretty much a helper function to set up the request
301
+ */
302
+ public static function from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters=NULL) {
303
+ @$parameters or $parameters = array();
304
+ $defaults = array("oauth_version" => OAuthRequest::$version,
305
+ "oauth_nonce" => OAuthRequest::generate_nonce(),
306
+ "oauth_timestamp" => OAuthRequest::generate_timestamp(),
307
+ "oauth_consumer_key" => $consumer->key);
308
+ if ($token)
309
+ $defaults['oauth_token'] = $token->key;
310
+
311
+ $parameters = array_merge($defaults, $parameters);
312
+
313
+ return new OAuthRequest($http_method, $http_url, $parameters);
314
+ }
315
+
316
+ public function set_parameter($name, $value, $allow_duplicates = true) {
317
+ if ($allow_duplicates && isset($this->parameters[$name])) {
318
+ // We have already added parameter(s) with this name, so add to the list
319
+ if (is_scalar($this->parameters[$name])) {
320
+ // This is the first duplicate, so transform scalar (string)
321
+ // into an array so we can add the duplicates
322
+ $this->parameters[$name] = array($this->parameters[$name]);
323
+ }
324
+
325
+ $this->parameters[$name][] = $value;
326
+ } else {
327
+ $this->parameters[$name] = $value;
328
+ }
329
+ }
330
+ public function set_parameters($parameters) {
331
+ // keep the oauth parameters
332
+ $oauth_parameters = Array();
333
+ foreach ($this->parameters as $k=>&$v)
334
+ if (substr($k, 0, 6) == "oauth_")
335
+ $oauth_parameters[$k] = $v;
336
+ $this->parameters = array_merge($parameters, $oauth_parameters);
337
+ }
338
+ public function get_parameter($name) {
339
+ return isset($this->parameters[$name]) ? $this->parameters[$name] : null;
340
+ }
341
+
342
+ public function get_parameters() {
343
+ return $this->parameters;
344
+ }
345
+
346
+ public function unset_parameter($name) {
347
+ unset($this->parameters[$name]);
348
+ }
349
+
350
+ /**
351
+ * The request parameters, sorted and concatenated into a normalized string.
352
+ * @return string
353
+ */
354
+ public function get_signable_parameters() {
355
+ // Grab all parameters
356
+ $params = $this->parameters;
357
+
358
+ // Remove oauth_signature if present
359
+ // Ref: Spec: 9.1.1 ("The oauth_signature parameter MUST be excluded.")
360
+ if (isset($params['oauth_signature'])) {
361
+ unset($params['oauth_signature']);
362
+ }
363
+
364
+ return OAuthUtil::build_http_query($params);
365
+ }
366
+
367
+ /**
368
+ * Returns the base string of this request
369
+ *
370
+ * The base string defined as the method, the url
371
+ * and the parameters (normalized), each urlencoded
372
+ * and the concated with &.
373
+ */
374
+ public function get_signature_base_string() {
375
+ $parts = array(
376
+ $this->get_normalized_http_method(),
377
+ $this->get_normalized_http_url(),
378
+ $this->get_signable_parameters()
379
+ );
380
+
381
+ $parts = OAuthUtil::urlencode_rfc3986($parts);
382
+
383
+ return implode('&', $parts);
384
+ }
385
+
386
+ /**
387
+ * just uppercases the http method
388
+ */
389
+ public function get_normalized_http_method() {
390
+ return strtoupper($this->http_method);
391
+ }
392
+
393
+ /**
394
+ * parses the url and rebuilds it to be
395
+ * scheme://host/path
396
+ */
397
+ public function get_normalized_http_url() {
398
+ $parts = parse_url($this->http_url);
399
+
400
+ $port = @$parts['port'];
401
+ $scheme = $parts['scheme'];
402
+ $host = $parts['host'];
403
+ $path = @$parts['path'];
404
+
405
+ $port or $port = ($scheme == 'https') ? '443' : '80';
406
+
407
+ if (($scheme == 'https' && $port != '443')
408
+ || ($scheme == 'http' && $port != '80')) {
409
+ $host = "$host:$port";
410
+ }
411
+ return "$scheme://$host$path";
412
+ }
413
+
414
+ /**
415
+ * builds a url usable for a GET request
416
+ */
417
+ public function to_url() {
418
+ $post_data = $this->to_postdata();
419
+ $out = $this->get_normalized_http_url();
420
+ if ($post_data) {
421
+ $out .= '?'.$post_data;
422
+ }
423
+ return $out;
424
+ }
425
+
426
+ /**
427
+ * builds the data one would send in a POST request
428
+ */
429
+ public function to_postdata() {
430
+ return OAuthUtil::build_http_query($this->parameters);
431
+ }
432
+
433
+ /**
434
+ * builds the Authorization: header
435
+ */
436
+ public function to_header($realm=null) {
437
+ $first = true;
438
+ if($realm) {
439
+ $out = 'Authorization: OAuth realm="' . OAuthUtil::urlencode_rfc3986($realm) . '"';
440
+ $first = false;
441
+ } else
442
+ $out = 'Authorization: OAuth';
443
+
444
+ $total = array();
445
+ foreach ($this->parameters as $k => $v) {
446
+ if (substr($k, 0, 5) != "oauth") continue;
447
+ if (is_array($v)) {
448
+ throw new OAuthException('Arrays not supported in headers');
449
+ }
450
+ $out .= ($first) ? ' ' : ',';
451
+ $out .= OAuthUtil::urlencode_rfc3986($k) .
452
+ '="' .
453
+ OAuthUtil::urlencode_rfc3986($v) .
454
+ '"';
455
+ $first = false;
456
+ }
457
+ return $out;
458
+ }
459
+
460
+ public function __toString() {
461
+ return $this->to_url();
462
+ }
463
+
464
+
465
+ public function sign_request($signature_method, $consumer, $token) {
466
+ $this->set_parameter(
467
+ "oauth_signature_method",
468
+ $signature_method->get_name(),
469
+ false
470
+ );
471
+ $signature = $this->build_signature($signature_method, $consumer, $token);
472
+ $this->set_parameter("oauth_signature", $signature, false);
473
+ }
474
+
475
+ public function build_signature($signature_method, $consumer, $token) {
476
+ $signature = $signature_method->build_signature($this, $consumer, $token);
477
+ return $signature;
478
+ }
479
+
480
+ /**
481
+ * util function: current timestamp
482
+ */
483
+ private static function generate_timestamp() {
484
+ return time();
485
+ }
486
+
487
+ /**
488
+ * util function: current nonce
489
+ */
490
+ private static function generate_nonce() {
491
+ $mt = microtime();
492
+ $rand = mt_rand();
493
+
494
+ return md5($mt . $rand); // md5s look nicer than numbers
495
+ }
496
+ }
497
+ }
498
+ if (!class_exists('OAuthServer')) {
499
+ class OAuthServer {
500
+ protected $timestamp_threshold = 300; // in seconds, five minutes
501
+ protected $version = '1.0'; // hi blaine
502
+ protected $signature_methods = array();
503
+
504
+ protected $data_store;
505
+
506
+ function __construct($data_store) {
507
+ $this->data_store = $data_store;
508
+ }
509
+
510
+ public function add_signature_method($signature_method) {
511
+ $this->signature_methods[$signature_method->get_name()] =
512
+ $signature_method;
513
+ }
514
+
515
+ // high level functions
516
+
517
+ /**
518
+ * process a request_token request
519
+ * returns the request token on success
520
+ */
521
+ public function fetch_request_token(&$request) {
522
+ $this->get_version($request);
523
+
524
+ $consumer = $this->get_consumer($request);
525
+
526
+ // no token required for the initial token request
527
+ $token = NULL;
528
+
529
+ $this->check_signature($request, $consumer, $token);
530
+
531
+ // Rev A change
532
+ $callback = $request->get_parameter('oauth_callback');
533
+ $new_token = $this->data_store->new_request_token($consumer, $callback);
534
+
535
+ return $new_token;
536
+ }
537
+
538
+ /**
539
+ * process an access_token request
540
+ * returns the access token on success
541
+ */
542
+ public function fetch_access_token(&$request) {
543
+ $this->get_version($request);
544
+
545
+ $consumer = $this->get_consumer($request);
546
+
547
+ // requires authorized request token
548
+ $token = $this->get_token($request, $consumer, "request");
549
+
550
+ $this->check_signature($request, $consumer, $token);
551
+
552
+ // Rev A change
553
+ $verifier = $request->get_parameter('oauth_verifier');
554
+ $new_token = $this->data_store->new_access_token($token, $consumer, $verifier);
555
+
556
+ return $new_token;
557
+ }
558
+
559
+ /**
560
+ * verify an api call, checks all the parameters
561
+ */
562
+ public function verify_request(&$request) {
563
+ $this->get_version($request);
564
+ $consumer = $this->get_consumer($request);
565
+ $token = $this->get_token($request, $consumer, "access");
566
+ $this->check_signature($request, $consumer, $token);
567
+ return array($consumer, $token);
568
+ }
569
+
570
+ // Internals from here
571
+ /**
572
+ * version 1
573
+ */
574
+ private function get_version(&$request) {
575
+ $version = $request->get_parameter("oauth_version");
576
+ if (!$version) {
577
+ // Service Providers MUST assume the protocol version to be 1.0 if this parameter is not present.
578
+ // Chapter 7.0 ("Accessing Protected Ressources")
579
+ $version = '1.0';
580
+ }
581
+ if ($version !== $this->version) {
582
+ throw new OAuthException("OAuth version '$version' not supported");
583
+ }
584
+ return $version;
585
+ }
586
+
587
+ /**
588
+ * figure out the signature with some defaults
589
+ */
590
+ private function get_signature_method(&$request) {
591
+ $signature_method =
592
+ @$request->get_parameter("oauth_signature_method");
593
+
594
+ if (!$signature_method) {
595
+ // According to chapter 7 ("Accessing Protected Ressources") the signature-method
596
+ // parameter is required, and we can't just fallback to PLAINTEXT
597
+ throw new OAuthException('No signature method parameter. This parameter is required');
598
+ }
599
+
600
+ if (!in_array($signature_method,
601
+ array_keys($this->signature_methods))) {
602
+ throw new OAuthException(
603
+ "Signature method '$signature_method' not supported " .
604
+ "try one of the following: " .
605
+ implode(", ", array_keys($this->signature_methods))
606
+ );
607
+ }
608
+ return $this->signature_methods[$signature_method];
609
+ }
610
+
611
+ /**
612
+ * try to find the consumer for the provided request's consumer key
613
+ */
614
+ private function get_consumer(&$request) {
615
+ $consumer_key = @$request->get_parameter("oauth_consumer_key");
616
+ if (!$consumer_key) {
617
+ throw new OAuthException("Invalid consumer key");
618
+ }
619
+
620
+ $consumer = $this->data_store->lookup_consumer($consumer_key);
621
+ if (!$consumer) {
622
+ throw new OAuthException("Invalid consumer");
623
+ }
624
+
625
+ return $consumer;
626
+ }
627
+
628
+ /**
629
+ * try to find the token for the provided request's token key
630
+ */
631
+ private function get_token(&$request, $consumer, $token_type="access") {
632
+ $token_field = @$request->get_parameter('oauth_token');
633
+ $token = $this->data_store->lookup_token(
634
+ $consumer, $token_type, $token_field
635
+ );
636
+ if (!$token) {
637
+ throw new OAuthException("Invalid $token_type token: $token_field");
638
+ }
639
+ return $token;
640
+ }
641
+
642
+ /**
643
+ * all-in-one function to check the signature on a request
644
+ * should guess the signature method appropriately
645
+ */
646
+ private function check_signature(&$request, $consumer, $token) {
647
+ // this should probably be in a different method
648
+ $timestamp = @$request->get_parameter('oauth_timestamp');
649
+ $nonce = @$request->get_parameter('oauth_nonce');
650
+
651
+ $this->check_timestamp($timestamp);
652
+ $this->check_nonce($consumer, $token, $nonce, $timestamp);
653
+
654
+ $signature_method = $this->get_signature_method($request);
655
+
656
+ $signature = $request->get_parameter('oauth_signature');
657
+ $valid_sig = $signature_method->check_signature(
658
+ $request,
659
+ $consumer,
660
+ $token,
661
+ $signature
662
+ );
663
+
664
+ if (!$valid_sig) {
665
+ throw new OAuthException("Invalid signature");
666
+ }
667
+ }
668
+
669
+ /**
670
+ * check that the timestamp is new enough
671
+ */
672
+ private function check_timestamp($timestamp) {
673
+ if( ! $timestamp )
674
+ throw new OAuthException(
675
+ 'Missing timestamp parameter. The parameter is required'
676
+ );
677
+
678
+ // verify that timestamp is recentish
679
+ $now = time();
680
+ if (abs($now - $timestamp) > $this->timestamp_threshold) {
681
+ throw new OAuthException(
682
+ "Expired timestamp, yours $timestamp, ours $now"
683
+ );
684
+ }
685
+ }
686
+
687
+ /**
688
+ * check that the nonce is not repeated
689
+ */
690
+ private function check_nonce($consumer, $token, $nonce, $timestamp) {
691
+ if( ! $nonce )
692
+ throw new OAuthException(
693
+ 'Missing nonce parameter. The parameter is required'
694
+ );
695
+
696
+ // verify that the nonce is uniqueish
697
+ $found = $this->data_store->lookup_nonce(
698
+ $consumer,
699
+ $token,
700
+ $nonce,
701
+ $timestamp
702
+ );
703
+ if ($found) {
704
+ throw new OAuthException("Nonce already used: $nonce");
705
+ }
706
+ }
707
+
708
+ }
709
+ }
710
+ if (!class_exists('OAuthDataStore')) {
711
+ class OAuthDataStore {
712
+ function lookup_consumer($consumer_key) {
713
+ // implement me
714
+ }
715
+
716
+ function lookup_token($consumer, $token_type, $token) {
717
+ // implement me
718
+ }
719
+
720
+ function lookup_nonce($consumer, $token, $nonce, $timestamp) {
721
+ // implement me
722
+ }
723
+
724
+ function new_request_token($consumer, $callback = null) {
725
+ // return a new token attached to this consumer
726
+ }
727
+
728
+ function new_access_token($token, $consumer, $verifier = null) {
729
+ // return a new access token attached to this consumer
730
+ // for the user associated with this token if the request token
731
+ // is authorized
732
+ // should also invalidate the request token
733
+ }
734
+
735
+ }
736
+ }
737
+ if (!class_exists('OAuthUtil')) {
738
+ class OAuthUtil {
739
+ public static function urlencode_rfc3986($input) {
740
+ if (is_array($input)) {
741
+ return array_map(array('OAuthUtil', 'urlencode_rfc3986'), $input);
742
+ } else if (is_scalar($input)) {
743
+ return str_replace(
744
+ '+',
745
+ ' ',
746
+ str_replace('%7E', '~', rawurlencode($input))
747
+ );
748
+ } else {
749
+ return '';
750
+ }
751
+ }
752
+
753
+
754
+ // This decode function isn't taking into consideration the above
755
+ // modifications to the encoding process. However, this method doesn't
756
+ // seem to be used anywhere so leaving it as is.
757
+ public static function urldecode_rfc3986($string) {
758
+ return urldecode($string);
759
+ }
760
+
761
+ // Utility function for turning the Authorization: header into
762
+ // parameters, has to do some unescaping
763
+ // Can filter out any non-oauth parameters if needed (default behaviour)
764
+ public static function split_header($header, $only_allow_oauth_parameters = true) {
765
+ $pattern = '/(([-_a-z]*)=("([^"]*)"|([^,]*)),?)/';
766
+ $offset = 0;
767
+ $params = array();
768
+ while (preg_match($pattern, $header, $matches, PREG_OFFSET_CAPTURE, $offset) > 0) {
769
+ $match = $matches[0];
770
+ $header_name = $matches[2][0];
771
+ $header_content = (isset($matches[5])) ? $matches[5][0] : $matches[4][0];
772
+ if (preg_match('/^oauth_/', $header_name) || !$only_allow_oauth_parameters) {
773
+ $params[$header_name] = OAuthUtil::urldecode_rfc3986($header_content);
774
+ }
775
+ $offset = $match[1] + strlen($match[0]);
776
+ }
777
+
778
+ if (isset($params['realm'])) {
779
+ unset($params['realm']);
780
+ }
781
+
782
+ return $params;
783
+ }
784
+
785
+ // helper to try to sort out headers for people who aren't running apache
786
+ public static function get_headers() {
787
+ if (function_exists('apache_request_headers')) {
788
+ // we need this to get the actual Authorization: header
789
+ // because apache tends to tell us it doesn't exist
790
+ $headers = apache_request_headers();
791
+
792
+ // sanitize the output of apache_request_headers because
793
+ // we always want the keys to be Cased-Like-This and arh()
794
+ // returns the headers in the same case as they are in the
795
+ // request
796
+ $out = array();
797
+ foreach( $headers AS $key => $value ) {
798
+ $key = str_replace(
799
+ " ",
800
+ "-",
801
+ ucwords(strtolower(str_replace("-", " ", $key)))
802
+ );
803
+ $out[$key] = $value;
804
+ }
805
+ } else {
806
+ // otherwise we don't have apache and are just going to have to hope
807
+ // that $_SERVER actually contains what we need
808
+ $out = array();
809
+ if( isset($_SERVER['CONTENT_TYPE']) )
810
+ $out['Content-Type'] = $_SERVER['CONTENT_TYPE'];
811
+ if( isset($_ENV['CONTENT_TYPE']) )
812
+ $out['Content-Type'] = $_ENV['CONTENT_TYPE'];
813
+
814
+ foreach ($_SERVER as $key => $value) {
815
+ if (substr($key, 0, 5) == "HTTP_") {
816
+ // this is chaos, basically it is just there to capitalize the first
817
+ // letter of every word that is not an initial HTTP and strip HTTP
818
+ // code from przemek
819
+ $key = str_replace(
820
+ " ",
821
+ "-",
822
+ ucwords(strtolower(str_replace("_", " ", substr($key, 5))))
823
+ );
824
+ $out[$key] = $value;
825
+ }
826
+ }
827
+ }
828
+ return $out;
829
+ }
830
+
831
+ // This function takes a input like a=b&a=c&d=e and returns the parsed
832
+ // parameters like this
833
+ // array('a' => array('b','c'), 'd' => 'e')
834
+ public static function parse_parameters( $input ) {
835
+ if (!isset($input) || !$input) return array();
836
+
837
+ $pairs = explode('&', $input);
838
+
839
+ $parsed_parameters = array();
840
+ foreach ($pairs as $pair) {
841
+ $split = explode('=', $pair, 2);
842
+ $parameter = OAuthUtil::urldecode_rfc3986($split[0]);
843
+ $value = isset($split[1]) ? OAuthUtil::urldecode_rfc3986($split[1]) : '';
844
+
845
+ if (isset($parsed_parameters[$parameter])) {
846
+ // We have already recieved parameter(s) with this name, so add to the list
847
+ // of parameters with this name
848
+
849
+ if (is_scalar($parsed_parameters[$parameter])) {
850
+ // This is the first duplicate, so transform scalar (string) into an array
851
+ // so we can add the duplicates
852
+ $parsed_parameters[$parameter] = array($parsed_parameters[$parameter]);
853
+ }
854
+
855
+ $parsed_parameters[$parameter][] = $value;
856
+ } else {
857
+ $parsed_parameters[$parameter] = $value;
858
+ }
859
+ }
860
+ return $parsed_parameters;
861
+ }
862
+
863
+ public static function build_http_query($params) {
864
+ if (!$params) return '';
865
+
866
+ // Urlencode both keys and values
867
+ $keys = OAuthUtil::urlencode_rfc3986(array_keys($params));
868
+ $values = OAuthUtil::urlencode_rfc3986(array_values($params));
869
+ $params = array_combine($keys, $values);
870
+
871
+ // Parameters are sorted by name, using lexicographical byte value ordering.
872
+ // Ref: Spec: 9.1.1 (1)
873
+ uksort($params, 'strcmp');
874
+
875
+ $pairs = array();
876
+ foreach ($params as $parameter => $value) {
877
+ if (is_array($value)) {
878
+ // If two or more parameters share the same name, they are sorted by their value
879
+ // Ref: Spec: 9.1.1 (1)
880
+ natsort($value);
881
+ foreach ($value as $duplicate_value) {
882
+ $pairs[] = $parameter . '=' . $duplicate_value;
883
+ }
884
+ } else {
885
+ $pairs[] = $parameter . '=' . $value;
886
+ }
887
+ }
888
+ // For each parameter, the name is separated from the corresponding value by an '=' character (ASCII code 61)
889
+ // Each name-value pair is separated by an '&' character (ASCII code 38)
890
+ return implode('&', $pairs);
891
+ }
892
+ }
893
+ }
inc/oAuth/twitteroauth.php ADDED
@@ -0,0 +1,348 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * Abraham Williams (abraham@abrah.am) http://abrah.am
5
+ *
6
+ * The first PHP Library to support OAuth for Twitter's REST API.
7
+ */
8
+
9
+ /* Load OAuth lib. You can find it at http://oauth.net */
10
+ require_once('OAuth.php');
11
+
12
+ /**
13
+ * Twitter OAuth class
14
+ */
15
+ if (!class_exists('TwitterOAuth')) {
16
+ class TwitterOAuth {
17
+ /* Contains the last HTTP status code returned. */
18
+ public $http_code;
19
+ /* Contains the last API call. */
20
+ public $url;
21
+ /* Set up the API root URL. */
22
+ public $host = "https://api.twitter.com/1.1/";
23
+ /* Set timeout default. */
24
+ public $timeout = 30;
25
+ /* Set connect timeout. */
26
+ public $connecttimeout = 30;
27
+ /* Verify SSL Cert. */
28
+ public $ssl_verifypeer = FALSE;
29
+ /* Respons format. */
30
+ public $format = 'json';
31
+ /* Decode returned json data. */
32
+ public $decode_json = TRUE;
33
+ /* Contains the last HTTP headers returned. */
34
+ public $http_info;
35
+ /* Set the useragnet. */
36
+ public $useragent = 'TwitterOAuth v0.2.0-beta2';
37
+ /* Immediately retry the API call if the response was not successful. */
38
+ //public $retry = TRUE;
39
+
40
+ /* caching options */
41
+ /* caching responses for an hour only with GET requests */
42
+ public $cache = 0;
43
+ /* where cache files will be stored if above is set to true */
44
+ public $cacheLocation = '/tmp';
45
+
46
+ /**
47
+ * Set API URLS
48
+ */
49
+ function accessTokenURL() { return 'https://api.twitter.com/oauth/access_token'; }
50
+ function authenticateURL() { return 'https://api.twitter.com/oauth/authenticate'; }
51
+ function authorizeURL() { return 'https://api.twitter.com/oauth/authorize'; }
52
+ function requestTokenURL() { return 'https://api.twitter.com/oauth/request_token'; }
53
+
54
+ /**
55
+ * Debug helpers
56
+ */
57
+ function lastStatusCode() { return $this->http_code; }
58
+ function lastAPICall() { return $this->last_api_call; }
59
+
60
+ /**
61
+ * construct TwitterOAuth object
62
+ */
63
+ function __construct($consumer_key, $consumer_secret, $oauth_token = NULL, $oauth_token_secret = NULL) {
64
+ $this->sha1_method = new OAuthSignatureMethod_HMAC_SHA1();
65
+ $this->consumer = new OAuthConsumer($consumer_key, $consumer_secret);
66
+ if (!empty($oauth_token) && !empty($oauth_token_secret)) {
67
+ $this->token = new OAuthConsumer($oauth_token, $oauth_token_secret);
68
+ } else {
69
+ $this->token = NULL;
70
+ }
71
+ }
72
+
73
+
74
+ /**
75
+ * Get a request_token from Twitter
76
+ *
77
+ * @returns a key/value array containing oauth_token and oauth_token_secret
78
+ */
79
+ function getRequestToken($oauth_callback) {
80
+ $parameters = array();
81
+ $parameters['oauth_callback'] = $oauth_callback;
82
+ $request = $this->oAuthRequest($this->requestTokenURL(), 'GET', $parameters);
83
+ return $this->getToken($request);
84
+ }
85
+
86
+ /**
87
+ * Get the authorize URL
88
+ *
89
+ * @returns a string
90
+ */
91
+ function getAuthorizeURL($token, $sign_in_with_twitter = TRUE) {
92
+ if (is_array($token)) {
93
+ $token = $token['oauth_token'];
94
+ }
95
+ if (empty($sign_in_with_twitter)) {
96
+ return $this->authorizeURL() . "?oauth_token={$token}";
97
+ } else {
98
+ return $this->authenticateURL() . "?oauth_token={$token}";
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Exchange request token and secret for an access token and
104
+ * secret, to sign API calls.
105
+ *
106
+ * @returns array("oauth_token" => "the-access-token",
107
+ * "oauth_token_secret" => "the-access-secret",
108
+ * "user_id" => "9436992",
109
+ * "screen_name" => "abraham")
110
+ */
111
+ function getAccessToken($oauth_verifier) {
112
+ $parameters = array();
113
+ $parameters['oauth_verifier'] = $oauth_verifier;
114
+ $request = $this->oAuthRequest($this->accessTokenURL(), 'GET', $parameters);
115
+ return $this->getToken($request);
116
+ }
117
+
118
+ /**
119
+ * One time exchange of username and password for access token and secret.
120
+ *
121
+ * @returns array("oauth_token" => "the-access-token",
122
+ * "oauth_token_secret" => "the-access-secret",
123
+ * "user_id" => "9436992",
124
+ * "screen_name" => "abraham",
125
+ * "x_auth_expires" => "0")
126
+ */
127
+ function getXAuthToken($username, $password) {
128
+ $parameters = array();
129
+ $parameters['x_auth_username'] = $username;
130
+ $parameters['x_auth_password'] = $password;
131
+ $parameters['x_auth_mode'] = 'client_auth';
132
+ $request = $this->oAuthRequest($this->accessTokenURL(), 'POST', $parameters);
133
+ return $this->getToken($request);
134
+ }
135
+
136
+ /**
137
+ * GET wrapper for oAuthRequest.
138
+ */
139
+ function get($url, $parameters = array()) {
140
+ $response = $this->oAuthRequest($url, 'GET', $parameters);
141
+ if ($this->format === 'json' && $this->decode_json) {
142
+ return json_decode($response);
143
+ }
144
+ return $response;
145
+ }
146
+
147
+ /**
148
+ * POST wrapper for oAuthRequest.
149
+ */
150
+ function post($url, $parameters = array()) {
151
+ $response = $this->oAuthRequest($url, 'POST', $parameters);
152
+ if ($this->format === 'json' && $this->decode_json) {
153
+ return json_decode($response);
154
+ }
155
+ return $response;
156
+ }
157
+
158
+ /**
159
+ * Uploads are handled slightly differently
160
+ */
161
+ function upload($url, $parameters = array()) {
162
+ $response = $this->oAuthRequest($url, 'POST', $parameters, true);
163
+ if ($this->format === 'json' && $this->decode_json) {
164
+ return json_decode($response);
165
+ }
166
+ return $response;
167
+ }
168
+
169
+ /**
170
+ * DELETE wrapper for oAuthReqeust.
171
+ */
172
+ function delete($url, $parameters = array()) {
173
+ $response = $this->oAuthRequest($url, 'DELETE', $parameters);
174
+ if ($this->format === 'json' && $this->decode_json) {
175
+ return json_decode($response);
176
+ }
177
+ return $response;
178
+ }
179
+
180
+ /**
181
+ * Format and sign an OAuth / API request
182
+ */
183
+ function oAuthRequest($url, $method, $parameters, $upload = false) {
184
+
185
+ if (strrpos($url, 'https://') !== 0 && strrpos($url, 'http://') !== 0) {
186
+ $url = "{$this->host}{$url}.{$this->format}";
187
+ }
188
+
189
+ if ($upload) {
190
+ // we only need to sign the oauth_* parameters for this, see
191
+ // https://dev.twitter.com/discussions/1059?page=4
192
+ $signable_parameters = Array();
193
+ foreach ($parameters as $k=>&$v)
194
+ if (substr($k, 0, 6) == "oauth_")
195
+ $signable_parameters[$k] = $v;
196
+ $request = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, $method, $url, $signable_parameters);
197
+ $request->sign_request($this->sha1_method, $this->consumer, $this->token);
198
+ $request->set_parameters($parameters);
199
+ } else {
200
+ $request = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, $method, $url, $parameters);
201
+ $request->sign_request($this->sha1_method, $this->consumer, $this->token);
202
+ }
203
+
204
+ switch ($method) {
205
+ case 'GET':
206
+ return $this->http($request->to_url(), 'GET');
207
+ default:
208
+ return $this->http($request->get_normalized_http_url(), $method, $upload ? $request->get_parameters() : $request->to_postdata(), $upload ? $request->to_header() : false);
209
+ }
210
+ }
211
+
212
+ /**
213
+ * Make an HTTP request
214
+ *
215
+ * @return API results
216
+ */
217
+ function http($url, $method, $postfields = NULL, $authorization_header= false) {
218
+ $this->http_info = array();
219
+
220
+ $ci = curl_init();
221
+
222
+ $headers = Array('Expect:');
223
+ /* Curl settings */
224
+ curl_setopt($ci, CURLOPT_USERAGENT, $this->useragent);
225
+ curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout);
226
+ curl_setopt($ci, CURLOPT_TIMEOUT, $this->timeout);
227
+ curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE);
228
+ curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer);
229
+ curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader'));
230
+ curl_setopt($ci, CURLOPT_HEADER, FALSE);
231
+
232
+ switch ($method) {
233
+ case 'POST':
234
+ curl_setopt($ci, CURLOPT_POST, TRUE);
235
+ if ($authorization_header)
236
+ $headers[] = $authorization_header;
237
+ if (!empty($postfields)) {
238
+ curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);
239
+ }
240
+ break;
241
+ case 'DELETE':
242
+ curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');
243
+ if (!empty($postfields)) {
244
+ $url = "{$url}?{$postfields}";
245
+ }
246
+ }
247
+
248
+ curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);
249
+ curl_setopt($ci, CURLOPT_URL, $url);
250
+ $response = curl_exec($ci);
251
+
252
+ $this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);
253
+ $this->http_info = array_merge($this->http_info, curl_getinfo($ci));
254
+ $this->url = $url;
255
+ curl_close ($ci);
256
+
257
+ if ($this->cache) {
258
+ $this->cacheFile($response, $this->cache_file_name);
259
+ }
260
+
261
+ return $response;
262
+ }
263
+
264
+ /**
265
+ * Get the header info to store.
266
+ */
267
+ function getHeader($ch, $header) {
268
+ $i = strpos($header, ':');
269
+ if (!empty($i)) {
270
+ $key = str_replace('-', '_', strtolower(substr($header, 0, $i)));
271
+ $value = trim(substr($header, $i + 2));
272
+ $this->http_header[$key] = $value;
273
+ }
274
+ return strlen($header);
275
+ }
276
+
277
+ function checkCache($fileName, $time) {
278
+ $fileName = $this->cacheLocation.'/'.$fileName;
279
+
280
+ if (!file_exists($fileName)) {
281
+ $this->cache_debug = $fileName . 'does not exist';
282
+ return 0;
283
+ }
284
+
285
+ if (!$fileTime = filectime($fileName)) {
286
+ $this->cache_error = 'Could not check the cache time';
287
+ return 0;
288
+ }
289
+
290
+ // check if the cache is too old
291
+ if (time() - $fileTime < $time) {
292
+ $this->cache_debug = 'cache file expired';
293
+ return 1;
294
+ }
295
+
296
+ $this->cache_debug = 'cache file still valid';
297
+ return 0;
298
+ }
299
+
300
+ function cacheFile($data, $filename) {
301
+ $new_file = $this->cacheLocation.'/'.$fileName;
302
+ $fh = fopen($new_file, 'w+');
303
+ if (!$fh) {
304
+ $this->cache_error = "Could not open cache file '$filename'";
305
+ return 0;
306
+ }
307
+ if (!fwrite($fh, $data)) {
308
+ $this->cache_error = "Could not write to cache file '$filename'";
309
+ fclose($fh);
310
+ return 0;
311
+ }
312
+ fclose($fh);
313
+ chmod($new_file, 0766);
314
+ return 1;
315
+ }
316
+
317
+ function cacheRetrieve($fileName) {
318
+ error_reporting(E_ALL ^ E_WARNING ^ E_NOTICE);
319
+ if (!$fh = fopen($this->cacheLocation.'/'.$fileName, 'r')) {
320
+ $this->cache_error = 'Could not open cache file';
321
+ return 0;
322
+ }
323
+ error_reporting(E_ALL ^ E_NOTICE);
324
+
325
+ $xml = "";
326
+ while (!feof($fh)) {
327
+ $xml .= fread($fh, 1024);
328
+ }
329
+ fclose($fh);
330
+
331
+ return $xml;
332
+ }
333
+
334
+ /**
335
+ * Get the token from the request
336
+ *
337
+ * @return array
338
+ * @author Justin Palmer
339
+ **/
340
+ private function getToken($request)
341
+ {
342
+ $token = OAuthUtil::parse_parameters($request);
343
+ if(isset($token['oauth_token'], $token['oauth_token_secret']))
344
+ $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
345
+ return $token;
346
+ }
347
+ }
348
+ }
inc/view-exclude.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $twp_obj = new CWP_TOP_Core; ?>
2
+ <div class="cwp_top_wrapper_full cwp_top_wrapper">
3
+ <div class="announcement clearfix">
4
+ <h2><?php _e("After 6 months of hard work, we have just released", CWP_TEXTDOMAIN); ?> <b>ThemeIsle</b>, <?php _e("th’ island ‘o WordPress themes.", CWP_TEXTDOMAIN); ?></h2>
5
+ <a class="show-me" href="http://themeisle.com/?utm_source=topadmin&utm_medium=announce&utm_campaign=top"><?php _e("Show Me", CWP_TEXTDOMAIN); ?></a>
6
+ </div><!-- end .announcement -->
7
+
8
+ <header id="cwp_top_header" class='clearfix'>
9
+ <h1 class="logo">
10
+ <?php if (function_exists('topProAddNewAccount')) {
11
+ _e("Tweet Old Post PRO", CWP_TEXTDOMAIN);
12
+ } else _e("Tweet Old Post", CWP_TEXTDOMAIN); ?>
13
+
14
+ </h1>
15
+ <span class="slogan"><?php _e("by", CWP_TEXTDOMAIN); ?> <a href="http://themeisle.com/?utm_source=topadmin&utm_medium=announce&utm_campaign=top">ThemeIsle</a></span>
16
+
17
+ <div class="cwp_top_actions">
18
+ <a href="https://twitter.com/intent/tweet?text=Check-out%20this%20awesome%20plugin%20-%20&url=http%3A%2F%2Fthemeisle.com%2Fplugins%2Ftweet-old-post-lite%2F&via=themeisle" class="tweet-about-it"><span></span> <?php _e("Show your love", CWP_TEXTDOMAIN); ?></a>
19
+ <a target="_blank" href="http://wordpress.org/support/view/plugin-reviews/tweet-old-post#postform" class="leave-a-review"><span></span> <?php _e("Leave A Review", CWP_TEXTDOMAIN); ?></a>
20
+ </div><!-- end .cwp_top_actions -->
21
+ </header><!-- end .cwp_top_header -->
22
+
23
+ <section class="cwp_top_container clearfix">
24
+
25
+
26
+ <div class="cwp_top_status">
27
+
28
+ <?php if($twp_obj->pluginStatus == 'true') { ?>
29
+ <p class='active'>
30
+ <?php _e("Tweet Old Post is set to tweet on a", CWP_TEXTDOMAIN); ?>
31
+ <span class='tweetInterval'> <?php echo $twp_obj->intervalSet; ?></span>
32
+ <?php _e("hours interval, ", CWP_TEXTDOMAIN); ?>
33
+ <?php _e("and the next tweet will take place in: ", CWP_TEXTDOMAIN); ?>
34
+ <span class='nextTweet'><?php $twp_obj->getNextTweetInterval(); update_option('cwp_topnew_notice', ""); ?></span>
35
+ </p>
36
+ <?php } else { ?>
37
+ <p class='inactive'>
38
+ <?php _e("Tweet Old Post is not set to tweet!", CWP_TEXTDOMAIN); ?>
39
+ </p>
40
+ <?php } ?>
41
+ <p class='inactive'>
42
+ <?php _e("You have selected following POST IDs to be excluded from tweeting: <span id='excludeList' style='font-weight:bold;font-style:italic;'></span>.
43
+ Note: If you have made any change and dint hit 'Exclude Selected' button changes will not be saved. ", CWP_TEXTDOMAIN); ?>
44
+ </p>
45
+
46
+ </div><!-- end .cwp_top_status -->
inc/view.php ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="cwp_top_wrapper">
2
+ <div class="announcement clearfix">
3
+ <h2><?php _e("After 6 months of hard work, we have just released", CWP_TEXTDOMAIN); ?> <b>ThemeIsle</b>, <?php _e("th’ island ‘o WordPress themes.", CWP_TEXTDOMAIN); ?></h2>
4
+ <a class="show-me" href="http://themeisle.com/?utm_source=topadmin&utm_medium=announce&utm_campaign=top"><?php _e("Show Me", CWP_TEXTDOMAIN); ?></a>
5
+ </div><!-- end .announcement -->
6
+
7
+ <header id="cwp_top_header" class='clearfix'>
8
+ <h1 class="logo">
9
+ <?php if (function_exists('topProAddNewAccount')) {
10
+ _e("Tweet Old Post PRO", CWP_TEXTDOMAIN);
11
+ } else _e("Tweet Old Post", CWP_TEXTDOMAIN); ?>
12
+
13
+ </h1>
14
+ <span class="slogan"><?php _e("by", CWP_TEXTDOMAIN); ?> <a href="http://themeisle.com/?utm_source=topadmin&utm_medium=announce&utm_campaign=top">ThemeIsle</a></span>
15
+
16
+ <div class="cwp_top_actions">
17
+ <a href="https://twitter.com/intent/tweet?text=Check-out%20this%20awesome%20plugin%20-%20&url=http%3A%2F%2Fthemeisle.com%2Fplugins%2Ftweet-old-post-lite%2F&via=themeisle" class="tweet-about-it"><span></span> <?php _e("Show your love", CWP_TEXTDOMAIN); ?></a>
18
+ <a target="_blank" href="http://wordpress.org/support/view/plugin-reviews/tweet-old-post#postform" class="leave-a-review"><span></span> <?php _e("Leave A Review", CWP_TEXTDOMAIN); ?></a>
19
+ </div><!-- end .cwp_top_actions -->
20
+ </header><!-- end .cwp_top_header -->
21
+
22
+ <section class="cwp_top_container clearfix">
23
+
24
+
25
+ <div class="cwp_top_status">
26
+
27
+ <?php if($this->pluginStatus == 'true') { ?>
28
+ <p class='active'>
29
+ <?php _e("Tweet Old Post is set to tweet on a", CWP_TEXTDOMAIN); ?>
30
+ <span class='tweetInterval'> <?php echo $this->intervalSet; ?></span>
31
+ <?php _e("hours interval, ", CWP_TEXTDOMAIN); ?>
32
+ <?php _e("and the next tweet will take place in: ", CWP_TEXTDOMAIN); ?>
33
+ <span class='nextTweet'><?php $this->getNextTweetInterval(); update_option('cwp_topnew_notice', ""); ?></span>
34
+ </p>
35
+ <?php } else { ?>
36
+ <p class='inactive'>
37
+ <?php _e("Tweet Old Post is not set to tweet!", CWP_TEXTDOMAIN); ?>
38
+ </p>
39
+ <?php } ?>
40
+ <p class='inactive'>
41
+ <?php _e("Once you click start tweet a tweet will be sent in 15 sec, also here you can see the error message if is any.", CWP_TEXTDOMAIN); ?>
42
+ </p>
43
+
44
+ </div><!-- end .cwp_top_status -->
45
+
46
+ <form action="" method="post" id="cwp_top_form" class="clearfix">
47
+ <input id="cwp_top_currenturl" type="hidden" value="">
48
+
49
+ <fieldset class="option">
50
+ <div class="left">
51
+ <label for="twitter-login"> <?php _e("Twitter Login", CWP_TEXTDOMAIN); ?> </label>
52
+ <span class='description'> <?php _e("Login using your Twitter account.", CWP_TEXTDOMAIN); ?> </span>
53
+ </div><!-- end .left -->
54
+
55
+ <div class='right'>
56
+ <?php if(!empty($this->users)) { ?>
57
+
58
+
59
+ <?php foreach ($this->users as $user) { ?>
60
+ <div class="user_details">
61
+ <div class='user_avatar'><img src="<?php echo $user['oauth_user_details']->profile_image_url; ?>"></div>
62
+ <div class="user_name"><?php echo $user['oauth_user_details']->name; ?></div>
63
+ <div class="remove_user"><a href='#' id='<?php echo $user['user_id']; ?>' class='logout_user'></a></div>
64
+ </div><!-- end .user_details -->
65
+ <?php } ?>
66
+ <button id='twitter-login' class='another-account'>+</button>
67
+ <?php } else { ?>
68
+ <button id='twitter-login'> <?php _e("Add Account", CWP_TEXTDOMAIN) ?> </button>
69
+ <?php } ?>
70
+ </div><!-- end .right -->
71
+ </fieldset><!-- end .option -->
72
+
73
+
74
+ <?php foreach ($cwp_top_fields as $field) { ?>
75
+ <fieldset class="option">
76
+ <div class="left">
77
+ <label for="<?php echo $field['option']; ?>"> <?php echo $field['name'] ?> </label>
78
+ <span class="description"> <?php echo $field['description']; ?> </span>
79
+
80
+ <?php if($field['type'] == 'categories-list') { ?>
81
+ <button class='select-all'>Select All</button>
82
+ <?php } ?>
83
+
84
+ </div><!-- end .left -->
85
+ <div class="right">
86
+ <?php CWP_TOP_Core::generateFieldType( $field ); ?>
87
+ </div><!-- end .right -->
88
+ </fieldset><!-- end .option -->
89
+ <?php } ?>
90
+
91
+ <div class="cwp_top_footer">
92
+ <a class="reset-settings" href="#"><span></span> <?php _e("Reset", CWP_TEXTDOMAIN); ?></a>
93
+ <a class="update-options" href="#"><span></span><?php _e("Save Settings", CWP_TEXTDOMAIN); ?></a>
94
+ <a class="tweet-now" href="#"><span></span> <?php _e("Start Tweeting", CWP_TEXTDOMAIN); ?></a>
95
+ <a class="stop-tweet-old-post" href="#"><span></span> <?php _e("Stop Tweeting", CWP_TEXTDOMAIN); ?></a>
96
+ <a class="see-sample-tweet" href="#"><span></span> <?php _e("See Sample Tweet", CWP_TEXTDOMAIN); ?></a>
97
+ </div><!-- end .cwp_top_footer -->
98
+ <p><?php _e("We are not affiliated or partner with Twitter in any way.", CWP_TEXTDOMAIN); ?>
99
+ </form><!-- end #cwp_top_form -->
100
+
101
+ <aside class="sidebar">
102
+ <ul>
103
+ <li class="upgrade"><a target="_blank" href="http://themeisle.com/plugins/tweet-old-post-pro/?utm_source=bannerright&utm_medium=announce&utm_campaign=top&upgrade=true"> <?php _e("Upgrade Tweet Old Post for only $9.99 - Upgrade To Pro Now!", CWP_TEXTDOMAIN); ?></a></li>
104
+ <li class="readythemes"><a target="_blank" href="http://themeisle.com/allthemes/?utm_source=bannerright&utm_medium=announce&utm_campaign=top"> <?php _e("ThemeIsle - Deadly Simple WordPress Themes", CWP_TEXTDOMAIN); ?></a></li>
105
+ <li class="affiliate-readythemes"><a target="_blank" href="http://themeisle.com/contact/?utm_source=bannerright&utm_medium=announce&utm_campaign=top"> <?php _e("ThemeIsle - Promote Our Themes and Plugins and get 55% Comission", CWP_TEXTDOMAIN); ?></a></li>
106
+ </ul>
107
+ </aside><!-- end .sidebar -->
108
+ </section><!-- end .cwp_top_container -->
109
+
110
+ <div class="cwp_sample_tweet_preview">
111
+ <div class="cwp_sample_tweet_preview_inner">
112
+ <h2>Sample Tweet Preview</h2>
113
+ <span class="sample_tweet">Lorem ipsum dolor sit amet consectetutem! <a href="#">Lorem ipsum</a></span>
114
+ <button>Ok</button>
115
+ </div><!-- end .cwp_sample_tweet_preview_inner -->
116
+ </div><!-- end .cwp_sample_tweet_preview -->
117
+ </div><!-- end .cwp_top_wrapper -->
xml.php → inc/xml.php RENAMED
@@ -1,130 +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
  ?>
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
  ?>
js/countdown.js ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var timenow="";
2
+ (function() {
3
+
4
+ (function($) {
5
+ $.countdown = function(el, options) {
6
+ var getDateData,
7
+ _this = this;
8
+ this.el = el;
9
+ this.$el = $(el);
10
+ this.$el.data("countdown", this);
11
+ this.init = function() {
12
+ _this.options = $.extend({}, $.countdown.defaultOptions, options);
13
+ if (_this.options.refresh) {
14
+ _this.interval = setInterval(function() {
15
+ return _this.render();
16
+ }, _this.options.refresh);
17
+ }
18
+ _this.render();
19
+ return _this;
20
+ };
21
+
22
+ getDateData = function(endDate) {
23
+ var dateData, diff;
24
+ jQuery.ajax({
25
+ type: "POST",
26
+ url: cwp_top_ajaxload.ajaxurl,
27
+ data: {
28
+ action: "gettime_action"
29
+ },
30
+ success: function(response) {
31
+ timenow = response;
32
+ },
33
+ error: function(MLHttpRequest, textStatus, errorThrown) {
34
+ console.log("There was an error: "+errorThrown);
35
+ }
36
+ });
37
+
38
+ //var timenow = new Date(<?php echo time(); ?>*1000)
39
+ //var timenow = new Date( d1.getUTCFullYear(), d1.getUTCMonth(), d1.getUTCDate(), d1.getUTCHours(), d1.getUTCMinutes(), d1.getUTCSeconds() );
40
+ //endDate = Date.parse($.isPlainObject(_this.options.date) ? _this.options.date : new Date(_this.options.date));
41
+ endDate = _this.options.date;
42
+
43
+ if (timenow == '')
44
+ timenow = _this.options.date-20;
45
+
46
+ diff = endDate - timenow;
47
+ //diff = Math.floor(diff);
48
+ if (diff <= 0) {
49
+ diff = 0;
50
+ if (_this.interval) {
51
+ _this.stop();
52
+ }
53
+ _this.options.onEnd.apply(_this);
54
+ }
55
+ dateData = {
56
+ years: 0,
57
+ days: 0,
58
+ hours: 0,
59
+ min: 0,
60
+ sec: 0,
61
+ millisec: 0
62
+ };
63
+ if (diff >= (365.25 * 86400)) {
64
+ dateData.years = Math.floor(diff / (365.25 * 86400));
65
+ diff -= dateData.years * 365.25 * 86400;
66
+ }
67
+ if (diff >= 86400) {
68
+ dateData.days = Math.floor(diff / 86400);
69
+ diff -= dateData.days * 86400;
70
+ }
71
+ if (diff >= 3600) {
72
+ dateData.hours = Math.floor(diff / 3600);
73
+ diff -= dateData.hours * 3600;
74
+ }
75
+ if (diff >= 60) {
76
+ dateData.min = Math.floor(diff / 60);
77
+ diff -= dateData.min * 60;
78
+ }
79
+ dateData.sec = diff;
80
+ return dateData;
81
+ };
82
+ this.leadingZeros = function(num, length) {
83
+ if (length == null) {
84
+ length = 2;
85
+ }
86
+ num = String(num);
87
+ while (num.length < length) {
88
+ num = "0" + num;
89
+ }
90
+ return num;
91
+ };
92
+ this.update = function(newDate) {
93
+ _this.options.date = newDate;
94
+ return _this;
95
+ };
96
+ this.render = function() {
97
+ _this.options.render.apply(_this, [getDateData(_this.options.date)]);
98
+ return _this;
99
+ };
100
+ this.stop = function() {
101
+ if (_this.interval) {
102
+ clearInterval(_this.interval);
103
+ }
104
+ _this.interval = null;
105
+ jQuery(".cwp_top_container .nextTweet").html('Your tweet was just sent to twitter server, wait 5s for a confirmation below. Refresh the page to see when the next one will be posted.');
106
+
107
+ return _this;
108
+ //return _this;
109
+ };
110
+ this.start = function(refresh) {
111
+ if (refresh == null) {
112
+ refresh = _this.options.refresh || $.countdown.defaultOptions.refresh;
113
+ }
114
+ if (_this.interval) {
115
+ clearInterval(_this.interval);
116
+ }
117
+ _this.render();
118
+ _this.options.refresh = refresh;
119
+ _this.interval = setInterval(function() {
120
+ return _this.render();
121
+ }, _this.options.refresh);
122
+ return _this;
123
+ };
124
+ return this.init();
125
+ };
126
+ $.countdown.defaultOptions = {
127
+ date: "June 7, 2087 15:03:25",
128
+ refresh: 2000,
129
+ onEnd: $.noop,
130
+ render: function(date) {
131
+ if (date.days!=0 || date.hours!=0 || date.min!=0 || date.sec!=0)
132
+ return $(this.el).html("" + date.days + " days, " + (this.leadingZeros(date.hours)) + " hours, " + (this.leadingZeros(date.min)) + " min and " + (this.leadingZeros(date.sec)) + " sec");
133
+ }
134
+ };
135
+ $.fn.countdown = function(options) {
136
+ return $.each(this, function(i, el) {
137
+ var $el;
138
+ $el = $(el);
139
+ if (!$el.data('countdown')) {
140
+ return $el.data('countdown', new $.countdown(el, options));
141
+ }
142
+ });
143
+ };
144
+ return void 0;
145
+ })(jQuery);
146
+
147
+ }).call(this);
js/master.js ADDED
@@ -0,0 +1,472 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready(function(){
2
+
3
+ hideSpecifiedFieldsets();
4
+
5
+ jQuery("#cwp_top_currenturl").val(document.location.href);
6
+
7
+ jQuery(".cwp_top_wrapper").append("<div class='ajaxAnimation'></div>")
8
+
9
+ // Update Options Event
10
+ jQuery(".cwp_top_wrapper a.update-options").click(function(e){
11
+ e.preventDefault();
12
+ cwpTopUpdateForm();
13
+ return false;
14
+ });
15
+
16
+ // Reset Options Event
17
+ jQuery(".cwp_top_wrapper a.reset-settings").click(function(e) {
18
+ e.preventDefault();
19
+ startAjaxIntro();
20
+ //cwpTopUpdateForm();
21
+
22
+ jQuery.ajax({
23
+ type: "POST",
24
+ url: cwp_top_ajaxload.ajaxurl,
25
+ data: {
26
+ action: 'reset_options'
27
+ },
28
+ success: function(response) {
29
+ console.log("Success: " + response);
30
+ //jQuery("#cwp_top_form").cwpTopUpdateForm();
31
+ location.reload();
32
+ endAjaxIntro();
33
+ },
34
+ error: function(response) {
35
+ console.log("Error: "+ response);
36
+ }
37
+ });
38
+
39
+ endAjaxIntro();
40
+ return false;
41
+ });
42
+
43
+ function cwpTopUpdateForm() {
44
+ startAjaxIntro();
45
+ var data = jQuery("#cwp_top_form").serialize();
46
+ //console.log(data);
47
+
48
+ var formData = {
49
+ action:'updateAllOptions',
50
+ dataSent:data
51
+ }
52
+
53
+ jQuery.ajax({
54
+ type: "POST",
55
+ url: cwp_top_ajaxload.ajaxurl,
56
+ data: {
57
+ action: "update_response",
58
+ dataSent: formData
59
+ },
60
+ success: function(response) {
61
+ console.log(response);
62
+ },
63
+ error: function(MLHttpRequest, textStatus, errorThrown) {
64
+ console.log("There was an error: "+errorThrown);
65
+ }
66
+ });
67
+
68
+ endAjaxIntro();
69
+ return false;
70
+ }
71
+
72
+ function cwpTopUpdateFormWithoIntro() {
73
+ //startAjaxIntro();
74
+ var data = jQuery("#cwp_top_form").serialize();
75
+ //console.log(data);
76
+
77
+ var formData = {
78
+ action:'updateAllOptions',
79
+ dataSent:data
80
+ }
81
+
82
+ jQuery.ajax({
83
+ type: "POST",
84
+ url: cwp_top_ajaxload.ajaxurl,
85
+ data: {
86
+ action: "update_response",
87
+ dataSent: formData
88
+ },
89
+ success: function(response) {
90
+ console.log(response);
91
+ },
92
+ error: function(MLHttpRequest, textStatus, errorThrown) {
93
+ console.log("There was an error: "+errorThrown);
94
+ }
95
+ });
96
+
97
+ //endAjaxIntro();
98
+ return false;
99
+ }
100
+
101
+
102
+
103
+
104
+ // Add New Twitter Account
105
+ jQuery("#cwp_top_form button#twitter-login").click(function(e){
106
+ e.preventDefault();
107
+
108
+ if (jQuery(this).text()!=="+") {
109
+ startAjaxIntro();
110
+ jQuery.ajax({
111
+ type: "POST",
112
+ url: cwp_top_ajaxload.ajaxurl,
113
+ data: {
114
+ action: "add_new_twitter_account",
115
+ currentURL: jQuery("#cwp_top_currenturl").val()
116
+ },
117
+ success: function(response) {
118
+ window.location.href = response;
119
+ },
120
+ error: function(MLHttpRequest, textStatus, errorThrown) {
121
+ console.log("There was an error: " + errorThrown);
122
+ }
123
+ });
124
+ }
125
+ else
126
+ jQuery.ajax({
127
+ type: "POST",
128
+ url: cwp_top_ajaxload.ajaxurl,
129
+ data: {
130
+ action: "add_new_twitter_account_pro",
131
+ currentURL: jQuery("#cwp_top_currenturl").val()
132
+ },
133
+ success: function(response) {
134
+ if (response.search("api.twitter.com")==-1)
135
+ jQuery(".cwp_top_status .inactive").html(response);
136
+ else
137
+ window.location.href = response;
138
+
139
+ },
140
+ error: function(MLHttpRequest, textStatus, errorThrown) {
141
+ console.log("There was an error: " + errorThrown);
142
+ }
143
+ });
144
+
145
+
146
+ return false;
147
+ });
148
+
149
+ // Log Out Twitter User
150
+ jQuery("#cwp_top_form .logout_user").click(function(e){
151
+ e.preventDefault();
152
+ startAjaxIntro();
153
+
154
+ var userID = jQuery(this).attr('id');
155
+
156
+ jQuery.ajax({
157
+ type: "POST",
158
+ url: cwp_top_ajaxload.ajaxurl,
159
+ data: {
160
+ action: "log_out_twitter_user",
161
+ user_id: userID
162
+ },
163
+ success: function(response) {
164
+ console.log(response);
165
+ window.location.href = jQuery("#cwp_top_currenturl").val();
166
+ },
167
+ error: function(MLHttpRequest, textStatus, errorThrown) {
168
+ console.log("There was an error: "+errorThrown);
169
+ }
170
+ });
171
+
172
+ endAjaxIntro();
173
+ });
174
+
175
+ // Start Tweet
176
+ jQuery("#cwp_top_form a.tweet-now").click(function(e){
177
+ e.preventDefault();
178
+ startAjaxIntro();
179
+ cwpTopUpdateForm();
180
+
181
+ jQuery.ajax({
182
+ type: "POST",
183
+ url: cwp_top_ajaxload.ajaxurl,
184
+ data: {
185
+ action: "tweet_old_post_action"
186
+ },
187
+ success: function(response) {
188
+ if(response !== '') {
189
+
190
+ jQuery('.cwp_top_wrapper').append(response);
191
+
192
+ }
193
+ location.reload();
194
+ },
195
+ error: function(MLHttpRequest, textStatus, errorThrown) {
196
+ console.log("There was an error: "+errorThrown);
197
+ }
198
+ });
199
+
200
+ endAjaxIntro();
201
+ });
202
+
203
+ setInterval(function(){ jQuery.ajax({
204
+ type: "POST",
205
+ url: cwp_top_ajaxload.ajaxurl,
206
+ data: {
207
+ action: "getNotice_action"
208
+ },
209
+ success: function(response) {
210
+ if(response !== '') {
211
+ if (response.substring(0,5)=="Error") {
212
+ jQuery(".cwp_top_status p:nth-child(2)").css( "color", "red" );
213
+ jQuery(".cwp_top_status p:nth-child(2)").text(response);
214
+ } else {
215
+
216
+ //jQuery(".cwp_top_status p:nth-child(2)").addClass("active").removeClass("inactive");
217
+ jQuery(".cwp_top_status p:nth-child(2)").text(response);
218
+ jQuery(".cwp_top_status p:nth-child(2)").css( "color", "#218618" );
219
+
220
+ }
221
+
222
+ //jQuery(".cwp_top_wrapper .cwp_sample_tweet_preview .cwp_sample_tweet_preview_inner .sample_tweet").html(response);
223
+ }
224
+ },
225
+ error: function(MLHttpRequest, textStatus, errorThrown) {
226
+ console.log("There was an error: "+errorThrown);
227
+ }
228
+ })},3000);
229
+
230
+ jQuery("#cwp_top_form a.see-sample-tweet").click(function(e){
231
+ e.preventDefault();
232
+ startAjaxIntro();
233
+ cwpTopUpdateFormWithoIntro();
234
+
235
+ jQuery.ajax({
236
+ type: "POST",
237
+ url: cwp_top_ajaxload.ajaxurl,
238
+ data: {
239
+ action: "view_sample_tweet_action"
240
+ },
241
+ success: function(response) {
242
+ if(response !== '') {
243
+
244
+ jQuery(".cwp_top_wrapper .cwp_sample_tweet_preview").fadeIn().addClass("active");
245
+ jQuery('html, body').animate({
246
+ scrollTop: jQuery(".cwp_top_wrapper .cwp_sample_tweet_preview").offset().top+300
247
+ }, 2000);
248
+ jQuery(".cwp_top_wrapper .cwp_sample_tweet_preview .cwp_sample_tweet_preview_inner .sample_tweet").html(response);
249
+ }
250
+ endAjaxIntro();
251
+ },
252
+ error: function(MLHttpRequest, textStatus, errorThrown) {
253
+ console.log("There was an error: "+errorThrown);
254
+ endAjaxIntro();
255
+ }
256
+ });
257
+
258
+
259
+ });
260
+
261
+ // Stop Tweet Old Post
262
+ jQuery("#cwp_top_form a.stop-tweet-old-post").click(function(e){
263
+ e.preventDefault();
264
+ startAjaxIntro();
265
+ cwpTopUpdateForm();
266
+
267
+ jQuery.ajax({
268
+ type: "POST",
269
+ url: cwp_top_ajaxload.ajaxurl,
270
+ data: {
271
+ action: "stop_tweet_old_post"
272
+ },
273
+ success: function(response) {
274
+ if(response !== '') {
275
+ jQuery('.cwp_top_wrapper').append(response);
276
+ }
277
+ location.reload();
278
+ },
279
+ error: function(MLHttpRequest, textStatus, errorThrown) {
280
+ console.log("There was an error: "+errorThrown);
281
+ }
282
+ });
283
+ endAjaxIntro();
284
+ //location.reload();
285
+ });
286
+
287
+ jQuery(".cwp_top_wrapper .cwp_sample_tweet_preview .cwp_sample_tweet_preview_inner button").click(function(e){
288
+ jQuery(this).parent().parent().fadeOut().removeClass("active");
289
+ });
290
+
291
+ // Transform the date into a countdown.
292
+ var nextTweetDate = jQuery(".cwp_top_container .nextTweet").html();
293
+ jQuery(".cwp_top_container .nextTweet").html('');
294
+ jQuery(".cwp_top_container .nextTweet").countdown({
295
+ date: nextTweetDate
296
+ });
297
+
298
+ // Starting the AJAX intro animation
299
+ function startAjaxIntro() {
300
+ jQuery(".cwp_top_wrapper .ajaxAnimation").fadeIn();
301
+ }
302
+
303
+ // Ending the AJAX intro animation
304
+ function endAjaxIntro() {
305
+ jQuery(".cwp_top_wrapper .ajaxAnimation").fadeOut();
306
+ }
307
+
308
+ // Reset all checkboxes and clear textareas
309
+ jQuery.fn.cwpTopResetForm = function() {
310
+ //jQuery(this).find("input[type=text], textarea").val("");
311
+ //jQuery(this).find("input[type=radio], input[type=checkbox]").checked = false;
312
+ }
313
+
314
+ // Select all function
315
+ jQuery("button.select-all").click(function(e){
316
+ e.preventDefault();
317
+ if(jQuery(this).hasClass('active')) {
318
+ jQuery(this).removeClass('active').text('Select All');
319
+ jQuery(this).parent().parent().find('.right input[type=checkbox]').attr('checked', false);
320
+ } else {
321
+ jQuery(this).addClass('active').text('Deselect All');
322
+ jQuery(this).parent().parent().find('.right input[type=checkbox]').attr('checked', true);
323
+ }
324
+ });
325
+
326
+
327
+ function hideSpecifiedFieldsets()
328
+ {
329
+ jQuery("#top_opt_tweet_type_custom_field").parent().parent().hide();
330
+ jQuery("#top_opt_custom_url_option").parent().parent().hide();
331
+ jQuery("#top_opt_custom_url_field").parent().parent().hide();
332
+ jQuery("#top_opt_url_shortner").parent().parent().hide();
333
+ jQuery("#top_opt_use_url_shortner").parent().parent().hide();
334
+ jQuery("#top_opt_hashtags").parent().parent().hide();
335
+ jQuery("#top_opt_hashtag_length").parent().parent().hide();
336
+ jQuery("#top_opt_custom_hashtag_field").parent().parent().hide();
337
+ jQuery("#top_opt_post_type_value").parent().parent().hide();
338
+ jQuery("#top_opt_bitly_user").parent().parent().hide();
339
+ jQuery("#top_opt_bitly_key").parent().parent().hide();
340
+
341
+ }
342
+
343
+ function cwpManipulateHashtags()
344
+ {
345
+ if(jQuery("#top_opt_custom_hashtag_option").val() == "nohashtag") {
346
+ jQuery("#top_opt_hashtags").parent().parent().slideUp("fast");
347
+ jQuery("#top_opt_hashtag_length").parent().parent().slideUp("fast");
348
+ jQuery("#top_opt_custom_hashtag_field").parent().parent().slideUp("fast");
349
+ } else if(jQuery("#top_opt_custom_hashtag_option").val() == "common") {
350
+ jQuery("#top_opt_hashtags").parent().parent().slideDown("fast");
351
+ jQuery("#top_opt_hashtag_length").parent().parent().slideDown("fast");
352
+ } else if(jQuery("#top_opt_custom_hashtag_option").val() == "categories" || jQuery("#top_opt_custom_hashtag_option").val() == "tags") {
353
+ jQuery("#top_opt_hashtags").parent().parent().slideUp("fast");
354
+ jQuery("#top_opt_hashtag_length").parent().parent().slideDown("fast");
355
+ jQuery("#top_opt_custom_hashtag_field").parent().parent().slideUp("fast");
356
+ } else if(jQuery("#top_opt_custom_hashtag_option").val() == "custom") {
357
+ jQuery("#top_opt_hashtags").parent().parent().slideUp("fast");
358
+ jQuery("#top_opt_hashtag_length").parent().parent().slideDown("fast");
359
+ jQuery("#top_opt_custom_hashtag_field").parent().parent().slideDown("fast");
360
+ }
361
+ }
362
+
363
+
364
+ // Functions to show / hide specific inputs based on user selection.
365
+ cwpManipulateHashtags();
366
+
367
+ if(jQuery("#top_opt_use_url_shortner").is(":checked")) {
368
+ jQuery("#top_opt_url_shortner").parent().parent().show();
369
+ if(jQuery("#top_opt_url_shortner").val() == "bit.ly") {
370
+ jQuery("#top_opt_bitly_user").parent().parent().show();
371
+ jQuery("#top_opt_bitly_key").parent().parent().show();
372
+
373
+ }
374
+ } else {
375
+ jQuery("#top_opt_url_shortner").parent().parent().hide();
376
+ jQuery("#top_opt_bitly_user").parent().parent().hide();
377
+ jQuery("#top_opt_bitly_key").parent().parent().hide();
378
+ }
379
+
380
+ jQuery( "#top_opt_url_shortner" ).change(function(){
381
+ if(jQuery("#top_opt_url_shortner").val() == "bit.ly" && jQuery("#top_opt_use_url_shortner").is(":checked")) {
382
+ jQuery("#top_opt_bitly_user").parent().parent().show();
383
+ jQuery("#top_opt_bitly_key").parent().parent().show();
384
+
385
+ }
386
+ else {
387
+ jQuery("#top_opt_bitly_user").parent().parent().hide();
388
+ jQuery("#top_opt_bitly_key").parent().parent().hide();
389
+ }
390
+ })
391
+
392
+ if(jQuery("select#top_opt_include_link").val() == "true") {
393
+ jQuery("#top_opt_custom_url_option").parent().parent().show();
394
+ jQuery("#top_opt_use_url_shortner").parent().parent().show();
395
+ //jQuery("#top_opt_url_shortner").parent().parent().show();
396
+ if (jQuery("#top_opt_custom_url_option").is(":checked"))
397
+ jQuery("#top_opt_custom_url_field").parent().parent().show();
398
+ } else {
399
+ jQuery("#top_opt_use_url_shortner").parent().parent().hide();
400
+ jQuery("#top_opt_custom_url_option").parent().parent().hide();
401
+ jQuery("#top_opt_url_shortner").parent().parent().hide();
402
+ jQuery("#top_opt_bitly_user").parent().parent().hide();
403
+ jQuery("#top_opt_bitly_key").parent().parent().hide();
404
+ }
405
+
406
+ if(jQuery("#top_opt_post_type").val() == "custom-post-type") {
407
+ jQuery("#top_opt_post_type_value").parent().parent().slideDown("fast");
408
+ } else {
409
+ jQuery("#top_opt_post_type_value").parent().parent().slideUp("fast");
410
+ }
411
+
412
+ jQuery("select#top_opt_tweet_type").change(function(){
413
+ if(jQuery(this).val() == "custom-field") {
414
+ jQuery("#top_opt_tweet_type_custom_field").parent().parent().slideDown("fast");
415
+ } else {
416
+ jQuery("#top_opt_tweet_type_custom_field").parent().parent().slideUp("fast");
417
+ }
418
+ });
419
+
420
+
421
+ jQuery("select#top_opt_include_link").change(function(){
422
+ if(jQuery(this).val() == "true") {
423
+ jQuery("#top_opt_custom_url_option").parent().parent().slideDown("fast");
424
+ jQuery("#top_opt_use_url_shortner").parent().parent().slideDown("fast");
425
+ jQuery("#top_opt_url_shortner").parent().parent().slideDown("fast");
426
+ } else {
427
+ jQuery("#top_opt_use_url_shortner").parent().parent().slideUp("fast");
428
+ jQuery("#top_opt_custom_url_option").parent().parent().slideUp("fast");
429
+ jQuery("#top_opt_url_shortner").parent().parent().slideUp("fast");
430
+ }
431
+ });
432
+
433
+ jQuery("#top_opt_custom_url_option").change(function(){
434
+ if(jQuery(this).is(":checked")) {
435
+ jQuery("#top_opt_custom_url_field").parent().parent().slideDown("fast");
436
+ } else {
437
+ jQuery("#top_opt_custom_url_field").parent().parent().slideUp("fast");
438
+ }
439
+ });
440
+
441
+ jQuery("#top_opt_use_url_shortner").change(function(){
442
+ if(jQuery(this).is(":checked")) {
443
+ jQuery("#top_opt_url_shortner").parent().parent().slideDown("fast");
444
+ if(jQuery("#top_opt_url_shortner").val() == "bit.ly") {
445
+ jQuery("#top_opt_bitly_user").parent().parent().slideDown("fast");
446
+ jQuery("#top_opt_bitly_key").parent().parent().slideDown("fast");
447
+
448
+ }
449
+ } else {
450
+ jQuery("#top_opt_url_shortner").parent().parent().slideUp("fast");
451
+ jQuery("#top_opt_bitly_user").parent().parent().slideUp("fast");
452
+ jQuery("#top_opt_bitly_key").parent().parent().slideUp("fast");
453
+
454
+ }
455
+ });
456
+
457
+ jQuery("#top_opt_custom_hashtag_option").change(function(){
458
+ cwpManipulateHashtags();
459
+ });
460
+
461
+ jQuery("#top_opt_post_type").change(function(){
462
+ if(jQuery(this).val() == "custom-post-type") {
463
+ jQuery("#top_opt_post_type_value").parent().parent().slideDown("fast");
464
+ } else {
465
+ jQuery("#top_opt_post_type_value").parent().parent().slideUp("fast");
466
+ }
467
+ });
468
+
469
+
470
+
471
+
472
+ });
log.txt DELETED
File without changes
readme.txt CHANGED
@@ -1,8 +1,8 @@
1
- === Tweet Old Post ===
2
- Contributors: Ajay Matharu
3
- Tags: Tweet old post, Tweets, Promote old post by tweeting about them, Twitter, Auto Tweet, Hashtags, Twitter Hashtags, Tweet Posts, Tweet, Post Tweets, Wordpress Twitter Plugin, Twitter Plugin, Tweet Selected Posts
4
  Requires at least: 2.7
5
- Tested up to: 3.3.1
6
  Stable tag: trunk
7
 
8
 
@@ -12,301 +12,301 @@ Plugin to tweet about your old posts to get more hits for them and keep them ali
12
 
13
  Tweet Old Posts is a plugin designed to tweet your older posts to get more traffic.
14
 
15
- Tweet Old Posts randomly picks your older post based on the interval specified by you. The primary function of this plugin is to promote older blog posts by tweeting about them and getting more traffic.
 
 
16
 
17
- For updates follow http://twitter.com/matharuajay
18
 
19
  **Fortcoming**
20
 
21
  - Sleep time
22
- - Post priority
23
  - Additional text based on categories
24
- - Post for Facebook and Google+
25
- - Option to set number of tweets to post at a time
26
 
27
 
28
- **Pro Version (will be released soon)**
29
- - Change via Tweet Old Post to your specified name
30
- - Multiple Twitter accounts
31
 
 
 
 
 
 
 
 
32
 
33
- **Let me know if you have any more ideas**
34
 
35
- **New in v3.3.3**
36
 
37
- - Resolved permission issue of exclude post.
38
 
 
39
 
40
- **New in v3.3.2**
41
 
42
- - Resolved too many redirects issue
43
- If its still not working try these steps
44
- - Make sure "Tweet Old Post Admin URL (Current URL)" is showing your current URL.
45
- - Click on "Update Tweet Old Post Options".
46
- - Try to authorize again.
47
- - Removed "_" from hashtags. Previously space in hashtag was replaced with "_". Now there will be no spaces or "_" in hashtags.
48
 
 
49
 
50
- **New in v3.3.1**
51
 
52
- - Changed logic for posting data to twitter.
53
- - Resolved bit.ly issue.
54
 
 
55
 
56
- **New in v3.3.0**
57
 
58
- - Attempt to fix logs out issue (Tweet Old Post pushes out when any action is performed).
59
 
 
60
 
61
- **New in v3.2.9**
62
 
63
- - Option to reset setting. When something goes wrong, please reset the settings and setup again.
64
- - For people still facing issues of conflict with Google Analytics Plugin, this version should work.
65
- - Minor bug fixes.
66
 
 
67
 
68
- **New in v3.2.8**
69
 
70
- - Resolved conflict with Google Analytics Plugin.
71
- - Changed the log file location to root of plugin folder.
72
- - Maintained Tweet Cycle. Repeat only when all post have been tweeted.
73
- - Made other optimizations and resolved some minor bugs.
74
 
 
75
 
76
- **New in v3.2.7**
77
 
78
- - Added logging for people who cant make it work can enable and check the log, or mail me the log file.
79
- - Brought back the exclude post option.
80
- - Made other optimizations and resolved some minor bugs.
81
- - Check http://www.ajaymatharu.com/tweet-old-post-update-3-2-7/ for more detailed explanation.
82
 
 
83
 
84
- **New in v3.2.6**
85
 
86
- - removed exclude post due to security threat. Will work on it and bring it up back.
87
 
 
88
 
89
- **New in v3.2.5**
90
 
91
- - Resolved hashtag not posting issue.
92
- - other bug fixes.
93
 
 
94
 
95
- **New in v3.2.4**
96
 
97
- - Bug fixes
98
 
 
 
99
 
100
- **New in v3.2.3**
101
 
102
- - Bug fixes
103
 
 
 
104
 
105
- **New in v3.2.2**
106
 
107
- - Resolved bit.ly issue
108
- - new option for hashtags
109
- - other bug fixes
110
 
 
111
 
112
- **New in v3.2.1**
113
 
114
- - Bug fixes
115
 
 
 
 
 
116
 
117
- **New in v3.2**
118
 
119
- - Bug fixes
120
- - Option to choose to include link in post
121
- - option to post only title or body or both title and body
122
- - option to set additional text either at beginning or end of tweet
123
- - option to pick hashtags from custom field
124
-
125
-
126
- **New in v3.1.2**
127
-
128
- - Resolved tweets not getting posted when categories are excluded.
129
- - If you are not able to authorise your twitter account set you blog URL in Administration → Settings → General.
130
-
131
-
132
-
133
- **New in v3.1.1**
134
 
135
- - Resolved tweets not getting posted issue. Sorry guys :(
136
 
 
 
 
 
 
 
 
 
137
 
 
138
 
139
- **New in v3.1**
 
 
 
 
 
140
 
141
- - Resolved issue of plugin flooding twitter account with tweets.
142
- - added provision to exclude some post from selected categories
143
 
 
 
144
 
145
 
146
- **New in v3.0**
147
 
148
- - added OAuth authentication
149
- - user defined intervals
150
- - may not work under php 4 requires php 5
151
 
152
 
 
153
 
154
- **New in v2.0**
 
 
155
 
156
- - added provision to select if you want to shorten the URL or not.
157
- - Cleaned other options.
158
 
 
159
 
 
 
160
 
161
- **New in v1.9**
162
 
163
- - Removed PHP 4 support as it was creating problem for lot of people
 
164
 
 
165
 
 
166
 
167
- **New in v1.8**
168
 
169
- - Bug Fixes
170
- - Provision to fetch tweet url from custom field
171
 
 
172
 
173
 
174
- **New in v1.7**
175
 
176
- - Removed api option from 1click.at not needed api key
177
 
178
 
 
179
 
180
- **New in v1.6**
181
 
182
- - Made the plugin PHP 4 compatible. Guys try it out and please let me know if that worked.
183
- - Better error prompting. If your tweets are not appearing on twitter. Try "Tweet Now" button you'll see if there is any problem in tweeting.
184
- - Added 1click.at shortning service you need to get the api key from http://theeasyapi.com/ you need to add your machine IP address in the server of http://theeasyapi.com/ for this api key to work.
185
 
 
186
 
 
187
 
188
- **New in v1.5**
189
 
190
- - Maximum age of post to be eligible for tweet - allows you to set Maximum age of the post to be eligible for tweet
191
- - Added one more shortner service was looking for j.mp but they dont have the api yet.
192
 
 
193
 
 
194
 
195
- **New in v1.4**
196
 
197
- - Hashtags - allows you to set default hashtags for your tweets
198
 
 
199
 
 
200
 
201
- **New in v1.3**
202
 
203
- - URL Shortener Service - allows you to select which URL shortener service you want to use.
204
 
 
205
 
 
206
 
207
- **New in v1.2**
208
 
209
- - Tweet Prefix - Allows you to set prefix to the tweets.
210
- - Add Data - Allows you to add post data to the tweets
211
- - Tweet now - Button that will tweet at that moment without wanting you to wait for scheduled tweet
212
 
 
213
 
 
214
 
215
- **v1.1**
216
 
217
- - Twitter Username & Password - Using this twitter account credentials plugin will tweet.
218
- - Minimum interval between tweets - allows you to determine how often the plugin will automatically choose and tweet a blog post for you.
219
- - Randomness interval - This is a contributing factor in minimum interval so that posts are randomly chosen and tweeted from your blog.
220
- - Minimum age of post to be eligible for tweet - This allows you to set how old your post should be in order to be eligible for the tweet.
221
- - Categories to omit from tweets - This will protect posts from the selected categories from being tweeted.
222
-
223
- == Installation ==
224
 
225
- Following are the steps to install the Tweet Old Post plugin
226
 
227
- 1. Download the latest version of the Tweet Old Posts Plugin to your computer from here.
228
- 2. With an FTP program, access your site�s server.
229
- 3. Upload (copy) the Plugin file(s) or folder to the /wp-content/plugins folder.
230
- 4. In your WordPress Administration Panels, click on Plugins from the menu.
231
- 5. You should see Tweet Old Posts Plugin listed. If not, with your FTP program, check the folder to see if it is installed. If it isn�t, upload the file(s) again. If it is, delete the files and upload them again.
232
- 6. To turn the Tweet Old Posts Plugin on, click Activate.
233
- 7. Check your Administration Panels or WordPress blog to see if the Plugin is working.
234
- 8. You can change the plugin options from Tweet Old Posts under settings menu.
235
 
236
- Alternatively you can also follow the following steps to install the Tweet Old Post plugin
237
 
238
- 1. In your WordPress Administration Panels, click on Add New option under Plugins from the menu.
239
- 2. Click on upload at the top.
240
- 3. Browse the location and select the Tweet Old Post Plugin and click install now.
241
- 4. To turn the Tweet Old Posts Plugin on, click Activate.
242
- 5. Check your Administration Panels or WordPress blog to see if the Plugin is working.
243
- 6. You can change the plugin options from Tweet Old Posts under settings menu.
244
 
245
- == Frequently Asked Questions ==
246
 
247
- If you have any questions please mail me at,
248
- ajay@ajaymatharu.com or matharuajay@yahoo.co.in
249
 
250
- **Too many redirects while trying to authorize**
251
 
252
- - Make sure "Tweet Old Post Admin URL (Current URL)" is showing your current URL.
253
- - Click on "Update Tweet Old Post Options".
254
- - Try to authorize again.
255
 
 
256
 
257
- **If new version doesn't works**
258
 
259
- - Try other versions from http://wordpress.org/extend/plugins/tweet-old-post/download/
260
- - Manually upload it in your plugins folder, activate and use.
261
- - Note: Do not upgrade your plugin if you want to use the older version.
262
 
 
263
 
264
- **Tweet Old post does not posts any tweets?**
 
 
 
265
 
266
- - If its not tweeting any tweets try playing around with the options. Try setting maxtweetage to none and try again.
267
- - Try removing categories from excluded option. Some of them have posted issues of tweet not getting post when categories are selected in exclued category section.
268
 
 
269
 
270
- **Tweet old post giving SimpleXmlElement error?**
 
 
 
 
271
 
272
- - If it is giving SimpleXmlElement error, check with your hosting provider on which version of PHP are they supporting.
273
- Tweet Old Post supports PHP 5 onwards. It will give SimpleXmlElement error if your hosting provider supports PHP 4
274
- or PHP less than 5
275
 
 
276
 
277
- **Tweets not getting posted?**
 
278
 
279
- - If your tweets are not getting posted, try deauthorizing and again authorizing your twitter account with
280
- plugin.
281
 
 
282
 
283
- **Plugin flooded your tweeter account with tweets?**
 
284
 
285
- - please check your setting increase the minimum interval between tweets. If your plugin is not updated please update your plugin to latest version.
286
 
 
287
 
288
- **Not able to authorize your twitter account with Tweet Old Post**
 
 
289
 
290
- - If you are not able to authorise your twitter account set you blog URL in Administration → Settings → General.
291
 
292
- **Any more questions or doubts?**
293
 
294
- - DM me on http://twitter.com/matharuajay or mail me at ajay(at)ajaymatharu(dot)com
 
 
 
295
 
296
 
297
- == Screenshots ==
298
 
299
- for screenshots you can check out
 
 
 
 
 
300
 
301
- http://www.ajaymatharu.com/wordpress-plugin-tweet-old-posts/
302
 
303
- == Changelog ==
304
 
305
  **New in v3.3.3**
306
 
307
  - Resolved permission issue of exclude post.
308
 
309
 
 
310
  **New in v3.3.2**
311
 
312
  - Resolved too many redirects issue
@@ -317,17 +317,20 @@ http://www.ajaymatharu.com/wordpress-plugin-tweet-old-posts/
317
  - Removed "_" from hashtags. Previously space in hashtag was replaced with "_". Now there will be no spaces or "_" in hashtags.
318
 
319
 
 
320
  **New in v3.3.1**
321
 
322
  - Changed logic for posting data to twitter.
323
  - Resolved bit.ly issue.
324
 
325
 
 
326
  **New in v3.3.0**
327
 
328
  - Attempt to fix logs out issue (Tweet Old Post pushes out when any action is performed).
329
 
330
 
 
331
  **New in v3.2.9**
332
 
333
  - Option to reset setting. When something goes wrong, please reset the settings and setup again.
@@ -498,6 +501,78 @@ http://www.ajaymatharu.com/wordpress-plugin-tweet-old-posts/
498
  == Other Notes ==
499
 
500
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
501
  **New in v3.3.3**
502
 
503
  - Resolved permission issue of exclude post.
1
+ === Tweet Old Post ===
2
+ Contributors: codeinwp
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, Twitter, Promote Posts, Tweet Random Post, Share Post, Promote Post, Post Tweets, Wordpress Twitter, Drive Traffic, Tweet Selected Posts
4
  Requires at least: 2.7
5
+ Tested up to: 3.9
6
  Stable tag: trunk
7
 
8
 
12
 
13
  Tweet Old Posts is a plugin designed to tweet your older posts to get more traffic.
14
 
15
+ This plugin helps you to keeps your old posts alive by tweeting about them and driving more traffic to them from twitter. It also helps you to promote your content. You can set time and no of tweets to post to drive more traffic.For questions, comments, or feature requests, <a href="http://themeisle.com/contact/?utm_source=readmetop&utm_medium=announce&utm_campaign=top">contact us</a>!
16
+
17
+ For updates follow https://twitter.com/themeisle If you have anything you can let us know at <a href="http://themeisle.com/contact/?utm_source=readmetop&utm_medium=announce&utm_campaign=top">here</a>
18
 
 
19
 
20
  **Fortcoming**
21
 
22
  - Sleep time
 
23
  - Additional text based on categories
 
 
24
 
25
 
26
+ **Tweet Old Post provides following features**
 
 
27
 
28
+ - Share new and old posts.
29
+ - Choose the time between tweets.
30
+ - Choose the number of tweets to Tweet.
31
+ - Use hashtags to focus on topics.
32
+ - Include links back to your site.
33
+ - Exclude categories
34
+ - Exclude specific posts.
35
 
36
+ **New in v6.7**
37
 
38
+ Fixed interrupted posting issue
39
 
40
+ **New in v6.6**
41
 
42
+ Fixed excluded category issue and some small others.
43
 
44
+ **New in v6.5**
45
 
46
+ Fixed 2 words category space, custom field hashtags, better debug messages, fixed not posting issue
 
 
 
 
 
47
 
48
+ **New in v6.2**
49
 
50
+ After some long working hours excluded posts feature was added back in the free version and integrated in the new version.
51
 
52
+ **New in v6.1**
 
53
 
54
+ Tweets are now posted!
55
 
56
+ **New in v6.0**
57
 
58
+ Tweets now are posted immediately, fixed scheduling and added debug messages
59
 
60
+ **Let me know if you have any more ideas**
61
 
62
+ **New in v5.8**
63
 
64
+ Added post by image options in the pro version and some fixes.
 
 
65
 
66
+ **New in v5.7**
67
 
68
+ Fixed permissions
69
 
70
+ **New in v5.6**
 
 
 
71
 
72
+ Added bit.ly back
73
 
74
+ **New in v5.5**
75
 
76
+ Fixed the table prefix issue
 
 
 
77
 
78
+ **New in v5.4**
79
 
80
+ Fixed the hashtags length issue
81
 
82
+ **New in v5.3**
83
 
84
+ Fixed the custom field issue
85
 
86
+ **New in v5.2**
87
 
88
+ Fixed exclude categories error, added wp short url, fixed oauth error, removed broken shorten services.
 
89
 
90
+ **New in v5.0**
91
 
92
+ - Whole plugin was rewrote from scratch and a pro version was added, so after 50 hours of work, here we are. This change will allow us to easier fix issues/ release new features and maintain the plugin.
93
 
94
+ **New in v4.0.9**
95
 
96
+ - Resolved twitter connectivity issue, for users who were not able to connect in 4.0.8. Twitter has changed their policy
97
+ as per https://dev.twitter.com/discussions/24239
98
 
 
99
 
100
+ **New in v4.0.8**
101
 
102
+ - Resolved twitter connectivity issue. Twitter has changed their policy
103
+ as per https://dev.twitter.com/discussions/24239
104
 
 
105
 
106
+ **New in v4.0.7**
 
 
107
 
108
+ - Resolved tweet not posting issue.
109
 
 
110
 
111
+ **New in v4.0.6**
112
 
113
+ - Changed how pages are navigated. Should not conflict with any of the plugin that interacts with twitter ever.
114
+ - For "Page not found", update the settings and then authorize with twitter.
115
+ - If you are not able to update anything or you are redirecting to your home page, reset the settings and try again.
116
+ - Code Cleanup.
117
 
 
118
 
119
+ == Installation ==
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
 
121
+ Following are the steps to install the Tweet Old Post plugin
122
 
123
+ 1. Download the latest version of the Tweet Old Posts Plugin to your computer from here.
124
+ 2. With an FTP program, access your site�s server.
125
+ 3. Upload (copy) the Plugin file(s) or folder to the /wp-content/plugins folder.
126
+ 4. In your WordPress Administration Panels, click on Plugins from the menu.
127
+ 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.
128
+ 6. To turn the Tweet Old Posts Plugin on, click Activate.
129
+ 7. Check your Administration Panels or WordPress blog to see if the Plugin is working.
130
+ 8. You can change the plugin options from Tweet Old Posts under settings menu.
131
 
132
+ Alternatively you can also follow the following steps to install the Tweet Old Post plugin
133
 
134
+ 1. In your WordPress Administration Panels, click on Add New option under Plugins from the menu.
135
+ 2. Click on upload at the top.
136
+ 3. Browse the location and select the Tweet Old Post Plugin and click install now.
137
+ 4. To turn the Tweet Old Posts Plugin on, click Activate.
138
+ 5. Check your Administration Panels or WordPress blog to see if the Plugin is working.
139
+ 6. You can change the plugin options from Tweet Old Posts under settings menu.
140
 
141
+ == Frequently Asked Questions ==
 
142
 
143
+ If you have any questions please get in touch with us at,
144
+ http://themeisle.com/contact/
145
 
146
 
147
+ **Plugin doesn't tweet at the regular interval**
148
 
149
+ - Unfortunately wp_cron function isn't perfect, it trigger just when somebody visit your site, so you nobody visit your site in 3 hours, TOP won't trigger
 
 
150
 
151
 
152
+ **If new version doesn't works**
153
 
154
+ - Try other versions from http://wordpress.org/extend/plugins/tweet-old-post/download/
155
+ - Manually upload it in your plugins folder, activate and use.
156
+ - Note: Do not upgrade your plugin if you want to use the older version.
157
 
 
 
158
 
159
+ **Tweet Old post does not posts any tweets?**
160
 
161
+ - If its not tweeting any tweets try playing around with the options. Try setting maxtweetage to none and try again.
162
+ - Try removing categories from excluded option. Some of them have posted issues of tweet not getting post when categories are selected in exclued category section.
163
 
164
+ **When I publish a new post to Twitter sometimes it’s ok, but sometimes I am getting this error: "code":226,"message":"This request looks like it might be automated. To protect our users from spam and other malicious activity, we can’t complete this action right now. Please try again later"?**
165
 
166
+ This message is coming from the new Twitter’s spam protection mechanism. It’s analyzed your message and marked it as spam. As you can expect they don’t share any information about how this thing works. Try to change the format of your messages and use/don’t use/change URL shortener. There are also some reports that Twitter rejects posts coming from hosting providers that were used to abuse it.
167
+ Please note: Despite the fact that error is saying "might be automated", it doesn’t mean that Twitter rejects the post because it was made though the API. "Automated" there doesn’t mean "posted/submitted automatically", it means "written/generated automatically".
168
 
169
+ **Any more questions or doubts?**
170
 
171
+ - Contact us at http://themeisle.com/contact/
172
 
 
173
 
174
+ == Screenshots ==
 
175
 
176
+ 1. Screenshot 1 Basic configurable options for Tweet Old Post to function, with ability to tweet at random interval.
177
 
178
 
179
+ for more you can check out
180
 
181
+ http://themeisle.com/plugins/tweet-old-post-lite/
182
 
183
 
184
+ == Changelog ==
185
 
186
+ **New in v6.6**
187
 
188
+ Fixed excluded category issue and some small others.
 
 
189
 
190
+ **New in v6.0**
191
 
192
+ Tweets now are posted immediately, fixed scheduling and added debug messages
193
 
194
+ **New in v5.9**
195
 
196
+ Tags are converted to lowercase automatically now
 
197
 
198
+ **New in v5.8**
199
 
200
+ Added post by image options in the pro version and some fixes.
201
 
202
+ **New in v5.7**
203
 
204
+ Fixed permissions
205
 
206
+ **New in v5.6**
207
 
208
+ Added bit.ly back
209
 
210
+ **New in v5.5**
211
 
212
+ Fixed the table prefix issue
213
 
214
+ **New in v5.4**
215
 
216
+ Fixed the hashtags length issue
217
 
218
+ **New in v5.3**
219
 
220
+ Fixed the custom field issue
 
 
221
 
222
+ **New in v5.2**
223
 
224
+ Fixed exclude categories error, added wp short url, fixed oauth error, removed broken shorten services.
225
 
226
+ **New in v5.0**
227
 
228
+ - Whole plugin was rewrote from scratch and a pro version was added, so after 50 hours of work, here we are. This change will allow us to easier fix issues/ release new features and maintain the plugin.
 
 
 
 
 
 
229
 
230
+ **New in v4.0.9**
231
 
232
+ - Resolved twitter connectivity issue, for users who were not able to connect in 4.0.8. Twitter has changed their policy
233
+ as per https://dev.twitter.com/discussions/24239
 
 
 
 
 
 
234
 
 
235
 
 
 
 
 
 
 
236
 
237
+ **New in v4.0.8**
238
 
239
+ - Resolved twitter connectivity issue. Twitter has changed their policy
240
+ as per https://dev.twitter.com/discussions/24239
241
 
 
242
 
 
 
 
243
 
244
+ **New in v4.0.7**
245
 
246
+ - Resolved tweet not posting issue.
247
 
 
 
 
248
 
249
+ **New in v4.0.6**
250
 
251
+ - Changed how pages are navigated. Should not conflict with any of the plugin that interacts with twitter ever.
252
+ - For "Page not found", update the settings and then authorize with twitter.
253
+ - If you are not able to update anything or you are redirecting to your home page, reset the settings and try again.
254
+ - Code Cleanup.
255
 
 
 
256
 
257
+ **New in v4.0.5**
258
 
259
+ - Implemented Twitter API v1.1 as Twitter is retiring API v1 from 7th May.
260
+ - Handled conflict with BackWPup plugin.
261
+ - Some performance improvements with WPSuperCache plugin.
262
+ - Some design changes.
263
+ - Code Cleanup.
264
 
 
 
 
265
 
266
+ **New in v4.0.4**
267
 
268
+ - Resolved issue of tweet not posting automatically. Thanks to Daniel Lopez Gonzalez for helping me.
269
+ - Minor Fixes
270
 
 
 
271
 
272
+ **New in v4.0.3**
273
 
274
+ - Handled too many tweets when W3 Total Cache plugin is installed. Please check and let me know.
275
+ - Bug fixes
276
 
 
277
 
278
+ **New in v4.0.2**
279
 
280
+ - Removed the option to specify the consumer key and secret as twitter does not show the application from which its tweeted anymore.
281
+ - Most probably, the tweet not posting automatically issue is resolved. Please check and let me know.
282
+ - Bug fixes
283
 
 
284
 
285
+ **New in v4.0.1**
286
 
287
+ - Resolved issue of page getting blank after returning from twitter
288
+ - added pages to exclude post option
289
+ - Bug fixes
290
+ - updated the steps of creating twitter application check here http://www.ajaymatharu.com/major-update-to-tweet-old-post/
291
 
292
 
293
+ **New in v4.0.0**
294
 
295
+ - You can now change the application name. Change via Tweet Old Post to your specified name. Follow the Steps here,
296
+ http://www.ajaymatharu.com/major-update-to-tweet-old-post/
297
+ - Pages can now be included in tweets. Added an option to select what is to be tweeted (pages, posts, or both).
298
+ - Removed "." and used "-" when adding additional text, "." was causing grammatical mistakes if sentence was trimmed.
299
+ - Added option to specify number of posts that can be tweeted simultaneously. You can specify how many tweets you want at a time.
300
+ - Last but not the least, removed random time slot was causing lot of confusion.
301
 
 
302
 
 
303
 
304
  **New in v3.3.3**
305
 
306
  - Resolved permission issue of exclude post.
307
 
308
 
309
+
310
  **New in v3.3.2**
311
 
312
  - Resolved too many redirects issue
317
  - Removed "_" from hashtags. Previously space in hashtag was replaced with "_". Now there will be no spaces or "_" in hashtags.
318
 
319
 
320
+
321
  **New in v3.3.1**
322
 
323
  - Changed logic for posting data to twitter.
324
  - Resolved bit.ly issue.
325
 
326
 
327
+
328
  **New in v3.3.0**
329
 
330
  - Attempt to fix logs out issue (Tweet Old Post pushes out when any action is performed).
331
 
332
 
333
+
334
  **New in v3.2.9**
335
 
336
  - Option to reset setting. When something goes wrong, please reset the settings and setup again.
501
  == Other Notes ==
502
 
503
 
504
+
505
+ **New in v4.0.9**
506
+
507
+ - Resolved twitter connectivity issue, for users who were not able to connect in 4.0.8. Twitter has changed their policy
508
+ as per https://dev.twitter.com/discussions/24239
509
+
510
+
511
+ **New in v4.0.8**
512
+
513
+ - Resolved twitter connectivity issue. Twitter has changed their policy
514
+ as per https://dev.twitter.com/discussions/24239
515
+
516
+
517
+ **New in v4.0.7**
518
+
519
+ - Resolved tweet not posting issue.
520
+
521
+
522
+ **New in v4.0.6**
523
+
524
+ - Changed how pages are navigated. Should not conflict with any of the plugin that interacts with twitter ever.
525
+ - For "Page not found", update the settings and then authorize with twitter.
526
+ - If you are not able to update anything or you are redirecting to your home page, reset the settings and try again.
527
+ - Code Cleanup.
528
+
529
+
530
+ **New in v4.0.5**
531
+
532
+ - Implemented Twitter API v1.1 as Twitter is retiring API v1 from 7th May.
533
+ - Handled conflict with BackWPup plugin.
534
+ - Some performance improvements with WPSuperCache plugin.
535
+ - Some design changes.
536
+ - Code Cleanup.
537
+
538
+
539
+ **New in v4.0.4**
540
+
541
+ - Resolved issue of tweet not posting automatically . Thanks to Daniel Lopez Gonzalez for helping me.
542
+ - Minor Fixes
543
+
544
+
545
+ **New in v4.0.3**
546
+
547
+ - Handled too many tweets when W3 Total Cache plugin is installed. Please check and let me know.
548
+ - Bug fixes
549
+
550
+
551
+ **New in v4.0.2**
552
+
553
+ - Removed the option to specify the consumer key and secret as twitter does not show the application from which its tweeted anymore.
554
+ - Most probably, the tweet not posting automatically issue is resolved. Please check and let me know.
555
+ - Bug fixes
556
+
557
+
558
+ **New in v4.0.1**
559
+
560
+ - Resolved issue of page getting blank after returning from twitter
561
+ - added pages to exclude post option
562
+ - Bug fixes
563
+ - updated the steps of creating twitter application check here http://www.ajaymatharu.com/major-update-to-tweet-old-post/
564
+
565
+
566
+ **New in v4.0.0**
567
+
568
+ - You can now change the application name. Change via Tweet Old Post to your specified name. Follow the Steps here,
569
+ http://www.ajaymatharu.com/major-update-to-tweet-old-post/
570
+ - Pages can now be included in tweets. Added an option to select what is to be tweeted (pages, posts, or both).
571
+ - Removed "." and used "-" when adding additional text, "." was causing grammatical mistakes if sentence was trimmed.
572
+ - Added option to specify number of posts that can be tweeted simultaneously. You can specify how many tweets you want at a time.
573
+ - Last but not the least, removed random time slot was causing lot of confusion.
574
+
575
+
576
  **New in v3.3.3**
577
 
578
  - Resolved permission issue of exclude post.
screenshot-1.png ADDED
Binary file
top-admin.php DELETED
@@ -1,843 +0,0 @@
1
- <?php
2
-
3
- require_once('tweet-old-post.php');
4
- require_once('top-core.php');
5
- require_once( 'Include/top-oauth.php' );
6
- require_once('xml.php');
7
- require_once( 'Include/top-debug.php' );
8
- function top_admin() {
9
- //check permission
10
- if (current_user_can('manage_options'))
11
- {
12
- $message = null;
13
- $message_updated = __("Tweet Old Post Options Updated.", 'TweetOldPost');
14
- $response = null;
15
- $save = true;
16
- $settings = top_get_settings();
17
-
18
- //on authorize
19
- if (isset($_GET['TOP_oauth'])) {
20
- global $top_oauth;
21
-
22
- $result = $top_oauth->get_access_token($settings['oauth_request_token'], $settings['oauth_request_token_secret'], $_GET['oauth_verifier']);
23
-
24
- if ($result) {
25
- $settings['oauth_access_token'] = $result['oauth_token'];
26
- $settings['oauth_access_token_secret'] = $result['oauth_token_secret'];
27
- $settings['user_id'] = $result['user_id'];
28
-
29
- $result = $top_oauth->get_user_info($result['user_id']);
30
- if ($result) {
31
- $settings['profile_image_url'] = $result['user']['profile_image_url'];
32
- $settings['screen_name'] = $result['user']['screen_name'];
33
- if (isset($result['user']['location'])) {
34
- $settings['location'] = $result['user']['location'];
35
- } else {
36
- $settings['location'] = false;
37
- }
38
- }
39
-
40
- top_save_settings($settings);
41
- echo '<script language="javascript">window.open ("' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=TweetOldPost","_self")</script>';
42
- die;
43
- }
44
- }
45
- //on deauthorize
46
- else if (isset($_GET['top']) && $_GET['top'] == 'deauthorize') {
47
- $settings = top_get_settings();
48
- $settings['oauth_access_token'] = '';
49
- $settings['oauth_access_token_secret'] = '';
50
- $settings['user_id'] = '';
51
- $settings['tweet_queue'] = array();
52
-
53
- top_save_settings($settings);
54
- echo '<script language="javascript">window.open ("' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=TweetOldPost","_self")</script>';
55
- die;
56
- }
57
- else if (isset($_GET['top']) && $_GET['top'] == 'reset') {
58
- print('
59
- <div id="message" class="updated fade">
60
- <p>' . __("All settings have been reset. Kindly update the settings for Tweet Old Post to start tweeting again.", 'TweetOldPost') . '</p>
61
- </div>');
62
- }
63
- //check if username and key provided if bitly selected
64
- if (isset($_POST['top_opt_url_shortener'])) {
65
- if ($_POST['top_opt_url_shortener'] == "bit.ly") {
66
-
67
- //check bitly username
68
- if (!isset($_POST['top_opt_bitly_user'])) {
69
- print('
70
- <div id="message" class="updated fade">
71
- <p>' . __('Please enter bit.ly username.', 'TweetOldPost') . '</p>
72
- </div>');
73
- $save = false;
74
- }
75
- //check bitly key
76
- elseif (!isset($_POST['top_opt_bitly_key'])) {
77
- print('
78
- <div id="message" class="updated fade">
79
- <p>' . __('Please enter bit.ly API Key.', 'TweetOldPost') . '</p>
80
- </div>');
81
- $save = false;
82
- }
83
- //if both the good to save
84
- else {
85
- $save = true;
86
- }
87
- }
88
- }
89
-
90
- //if submit and if bitly selected its fields are filled then save
91
- if (isset($_POST['submit']) && $save) {
92
- $message = $message_updated;
93
-
94
- //TOP admin URL (current url)
95
- if (isset($_POST['top_opt_admin_url'])) {
96
- update_option('top_opt_admin_url', $_POST['top_opt_admin_url']);
97
- }
98
-
99
- //what to tweet
100
- if (isset($_POST['top_opt_tweet_type'])) {
101
- update_option('top_opt_tweet_type', $_POST['top_opt_tweet_type']);
102
- }
103
-
104
- //additional data
105
- if (isset($_POST['top_opt_add_text'])) {
106
- update_option('top_opt_add_text', $_POST['top_opt_add_text']);
107
- }
108
-
109
- //place of additional data
110
- if (isset($_POST['top_opt_add_text_at'])) {
111
- update_option('top_opt_add_text_at', $_POST['top_opt_add_text_at']);
112
- }
113
-
114
- //include link
115
- if (isset($_POST['top_opt_include_link'])) {
116
- update_option('top_opt_include_link', $_POST['top_opt_include_link']);
117
- }
118
-
119
- //fetch url from custom field?
120
- if (isset($_POST['top_opt_custom_url_option'])) {
121
- update_option('top_opt_custom_url_option', true);
122
- } else {
123
-
124
- update_option('top_opt_custom_url_option', false);
125
- }
126
-
127
- //custom field to fetch URL from
128
- if (isset($_POST['top_opt_custom_url_field'])) {
129
- update_option('top_opt_custom_url_field', $_POST['top_opt_custom_url_field']);
130
- } else {
131
-
132
- update_option('top_opt_custom_url_field', '');
133
- }
134
-
135
- //use URL shortner?
136
- if (isset($_POST['top_opt_use_url_shortner'])) {
137
- update_option('top_opt_use_url_shortner', true);
138
- } else {
139
-
140
- update_option('top_opt_use_url_shortner', false);
141
- }
142
-
143
- //url shortener to use
144
- if (isset($_POST['top_opt_url_shortener'])) {
145
- update_option('top_opt_url_shortener', $_POST['top_opt_url_shortener']);
146
- if ($_POST['top_opt_url_shortener'] == "bit.ly") {
147
- if (isset($_POST['top_opt_bitly_user'])) {
148
- update_option('top_opt_bitly_user', $_POST['top_opt_bitly_user']);
149
- }
150
- if (isset($_POST['top_opt_bitly_key'])) {
151
- update_option('top_opt_bitly_key', $_POST['top_opt_bitly_key']);
152
- }
153
- }
154
- }
155
-
156
- //hashtags option
157
- if (isset($_POST['top_opt_custom_hashtag_option'])) {
158
- update_option('top_opt_custom_hashtag_option', $_POST['top_opt_custom_hashtag_option']);
159
- } else {
160
- update_option('top_opt_custom_hashtag_option', "nohashtag");
161
- }
162
-
163
- //use inline hashtags
164
- if (isset($_POST['top_opt_use_inline_hashtags'])) {
165
- update_option('top_opt_use_inline_hashtags', true);
166
- } else {
167
- update_option('top_opt_use_inline_hashtags', false);
168
- }
169
-
170
- //hashtag length
171
- if (isset($_POST['top_opt_hashtag_length'])) {
172
- update_option('top_opt_hashtag_length', $_POST['top_opt_hashtag_length']);
173
- } else {
174
- update_option('top_opt_hashtag_length', 0);
175
- }
176
-
177
- //custom field name to fetch hashtag from
178
- if (isset($_POST['top_opt_custom_hashtag_field'])) {
179
- update_option('top_opt_custom_hashtag_field', $_POST['top_opt_custom_hashtag_field']);
180
- } else {
181
- update_option('top_opt_custom_hashtag_field', '');
182
- }
183
-
184
- //default hashtags for tweets
185
- if (isset($_POST['top_opt_hashtags'])) {
186
- update_option('top_opt_hashtags', $_POST['top_opt_hashtags']);
187
- } else {
188
- update_option('top_opt_hashtags', '');
189
- }
190
-
191
- //tweet interval
192
- if (isset($_POST['top_opt_interval'])) {
193
- if (is_numeric($_POST['top_opt_interval']) && $_POST['top_opt_interval'] > 0) {
194
- update_option('top_opt_interval', $_POST['top_opt_interval']);
195
- } else {
196
- update_option('top_opt_interval', "4");
197
- }
198
- }
199
-
200
- //random interval
201
- if (isset($_POST['top_opt_interval_slop'])) {
202
- if (is_numeric($_POST['top_opt_interval_slop']) && $_POST['top_opt_interval_slop'] > 0) {
203
- update_option('top_opt_interval_slop', $_POST['top_opt_interval_slop']);
204
- } else {
205
- update_option('top_opt_interval_slop', "4");
206
- }
207
- }
208
-
209
- //minimum post age to tweet
210
- if (isset($_POST['top_opt_age_limit'])) {
211
- if (is_numeric($_POST['top_opt_age_limit']) && $_POST['top_opt_age_limit'] >= 0) {
212
- update_option('top_opt_age_limit', $_POST['top_opt_age_limit']);
213
- } else {
214
- update_option('top_opt_age_limit', "30");
215
- }
216
- }
217
-
218
- //maximum post age to tweet
219
- if (isset($_POST['top_opt_max_age_limit'])) {
220
- if (is_numeric($_POST['top_opt_max_age_limit']) && $_POST['top_opt_max_age_limit'] > 0) {
221
- update_option('top_opt_max_age_limit', $_POST['top_opt_max_age_limit']);
222
- } else {
223
- update_option('top_opt_max_age_limit', "0");
224
- }
225
- }
226
-
227
- //option to enable log
228
- if ( isset($_POST['top_enable_log'])) {
229
- update_option('top_enable_log', true);
230
- global $top_debug;
231
- $top_debug->enable( true );
232
-
233
- }
234
- else{
235
- update_option('top_enable_log', false);
236
- global $top_debug;
237
- $top_debug->enable( false );
238
- }
239
-
240
- //categories to omit from tweet
241
- if (isset($_POST['post_category'])) {
242
- update_option('top_opt_omit_cats', implode(',', $_POST['post_category']));
243
- } else {
244
- update_option('top_opt_omit_cats', '');
245
- }
246
-
247
- //successful update message
248
- print('
249
- <div id="message" class="updated fade">
250
- <p>' . __('Tweet Old Post Options Updated.', 'TweetOldPost') . '</p>
251
- </div>');
252
- }
253
- //tweet now clicked
254
- elseif (isset($_POST['tweet'])) {
255
- $tweet_msg = top_opt_tweet_old_post();
256
- print('
257
- <div id="message" class="updated fade">
258
- <p>' . __($tweet_msg, 'TweetOldPost') . '</p>
259
- </div>');
260
- }
261
- elseif (isset($_POST['reset'])) {
262
- top_reset_settings();
263
- echo '<script language="javascript">window.open ("' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=TweetOldPost&top=reset","_self")</script>';
264
- die;
265
- }
266
-
267
-
268
- //set up data into fields from db
269
-
270
- //Current URL
271
- $admin_url = get_option('top_opt_admin_url');
272
- if (!isset($admin_url)) {
273
- $admin_url = top_currentPageURL();
274
- update_option('top_opt_admin_url', $admin_url);
275
- }
276
-
277
- //what to tweet?
278
- $tweet_type = get_option('top_opt_tweet_type');
279
- if (!isset($tweet_type)) {
280
- $tweet_type = "title";
281
- }
282
-
283
- //additional text
284
- $additional_text = get_option('top_opt_add_text');
285
- if (!isset($additional_text)) {
286
- $additional_text = "";
287
- }
288
-
289
- //position of additional text
290
- $additional_text_at = get_option('top_opt_add_text_at');
291
- if (!isset($additional_text_at)) {
292
- $additional_text_at = "beginning";
293
- }
294
-
295
- //include link in tweet
296
- $include_link = get_option('top_opt_include_link');
297
- if (!isset($include_link)) {
298
- $include_link = "no";
299
- }
300
-
301
- //use custom field to fetch url
302
- $custom_url_option = get_option('top_opt_custom_url_option');
303
- if (!isset($custom_url_option)) {
304
- $custom_url_option = "";
305
- } elseif ($custom_url_option)
306
- $custom_url_option = "checked";
307
- else
308
- $custom_url_option="";
309
-
310
- //custom field name for url
311
- $custom_url_field = get_option('top_opt_custom_url_field');
312
- if (!isset($custom_url_field)) {
313
- $custom_url_field = "";
314
- }
315
-
316
- //use url shortner?
317
- $use_url_shortner = get_option('top_opt_use_url_shortner');
318
- if (!isset($use_url_shortner)) {
319
- $use_url_shortner = "";
320
- } elseif ($use_url_shortner)
321
- $use_url_shortner = "checked";
322
- else
323
- $use_url_shortner="";
324
-
325
- //url shortner
326
- $url_shortener = get_option('top_opt_url_shortener');
327
- if (!isset($url_shortener)) {
328
- $url_shortener = top_opt_URL_SHORTENER;
329
- }
330
-
331
- //bitly key
332
- $bitly_api = get_option('top_opt_bitly_key');
333
- if (!isset($bitly_api)) {
334
- $bitly_api = "";
335
- }
336
-
337
- //bitly username
338
- $bitly_username = get_option('top_opt_bitly_user');
339
- if (!isset($bitly_username)) {
340
- $bitly_username = "";
341
- }
342
-
343
- //hashtag option
344
- $custom_hashtag_option = get_option('top_opt_custom_hashtag_option');
345
- if (!isset($custom_hashtag_option)) {
346
- $custom_hashtag_option = "nohashtag";
347
- }
348
-
349
- //use inline hashtag
350
- $use_inline_hashtags = get_option('top_opt_use_inline_hashtags');
351
- if (!isset($use_inline_hashtags)) {
352
- $use_inline_hashtags = "";
353
- } elseif ($use_inline_hashtags)
354
- $use_inline_hashtags = "checked";
355
- else
356
- $use_inline_hashtags="";
357
-
358
- //hashtag length
359
- $hashtag_length = get_option('top_opt_hashtag_length');
360
- if (!isset($hashtag_length)) {
361
- $hashtag_length = "20";
362
- }
363
-
364
- //custom field
365
- $custom_hashtag_field = get_option('top_opt_custom_hashtag_field');
366
- if (!isset($custom_hashtag_field)) {
367
- $custom_hashtag_field = "";
368
- }
369
-
370
- //default hashtag
371
- $twitter_hashtags = get_option('top_opt_hashtags');
372
- if (!isset($twitter_hashtags)) {
373
- $twitter_hashtags = top_opt_HASHTAGS;
374
- }
375
-
376
- //interval
377
- $interval = get_option('top_opt_interval');
378
- if (!(isset($interval) && is_numeric($interval))) {
379
- $interval = top_opt_INTERVAL;
380
- }
381
-
382
- //random interval
383
- $slop = get_option('top_opt_interval_slop');
384
- if (!(isset($slop) && is_numeric($slop))) {
385
- $slop = top_opt_INTERVAL_SLOP;
386
- }
387
-
388
- //min age limit
389
- $ageLimit = get_option('top_opt_age_limit');
390
- if (!(isset($ageLimit) && is_numeric($ageLimit))) {
391
- $ageLimit = top_opt_AGE_LIMIT;
392
- }
393
-
394
- //max age limit
395
- $maxAgeLimit = get_option('top_opt_max_age_limit');
396
- if (!(isset($maxAgeLimit) && is_numeric($maxAgeLimit))) {
397
- $maxAgeLimit = top_opt_MAX_AGE_LIMIT;
398
- }
399
-
400
-
401
- //check enable log
402
- $top_enable_log = get_option('top_enable_log');
403
- if (!isset($top_enable_log)) {
404
- $top_enable_log = "";
405
- } elseif ($top_enable_log)
406
- $top_enable_log = "checked";
407
- else
408
- $top_enable_log="";
409
-
410
- //set omitted categories
411
- $omitCats = get_option('top_opt_omit_cats');
412
- if (!isset($omitCats)) {
413
- $omitCats = top_opt_OMIT_CATS;
414
- }
415
-
416
- $x = WP_PLUGIN_URL . '/' . str_replace(basename(__FILE__), "", plugin_basename(__FILE__));
417
-
418
- print('
419
- <div class="wrap">
420
- <h2>' . __('Tweet old post by - ', 'TweetOldPost') . ' <a href="http://www.ajaymatharu.com">Ajay Matharu</a></h2>
421
- <form id="top_opt" name="top_TweetOldPost" action="" method="post">
422
- <input type="hidden" name="top_opt_action" value="top_opt_update_settings" />
423
- <fieldset class="options">
424
- <div class="option">
425
- <label for="top_opt_twitter_username">' . __('Account Login', 'TweetOldPost') . ':</label>
426
-
427
- <div id="profile-box">');
428
- if (!$settings["oauth_access_token"]) {
429
-
430
- echo '<a href="' . top_get_auth_url() . '"><img src="' . $x . 'images/twitter.png" /></a>';
431
- } else {
432
- echo '<img class="avatar" src="' . $settings["profile_image_url"] . '" alt="" />
433
- <h4>' . $settings["screen_name"] . '</h4>';
434
- if ($settings["location"]) {
435
- echo '<h5>' . $settings["location"] . '</h5>';
436
- }
437
- echo '<p>
438
-
439
- Your account has been authorized. <a href="' . $_SERVER["REQUEST_URI"] . '&top=deauthorize" onclick=\'return confirm("Are you sure you want to deauthorize your Twitter account?");\'>Click to deauthorize</a>.<br />
440
-
441
- </p>
442
-
443
- <div class="retweet-clear"></div>
444
- ';
445
- }
446
- print('</div>
447
- </div>
448
- <div class="option">
449
- <b>&nbsp;&nbsp;&nbsp;Note: </b>If you are not able to authorize? or Wordpress logs you out on any button click,<br/>
450
-
451
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- If current URL is not showing your current page URL, copy paste the current page URL in Current URL field and press update settings button to update the settings. Then retry to authorize.<br/>
452
-
453
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- If current URL is showing your current page URL, press update settings button to update the settings. Then retry to authorize.
454
-
455
-
456
- </div>
457
- <div class="option">
458
- <label for="top_opt_admin_url">' . __('Tweet Old Post Admin URL <br/> (Current URL)', 'TweetOldPost') . ':</label>
459
- <input type="text" style="width:500px" id="top_opt_admin_url" value="' . $admin_url . '" name="top_opt_admin_url" /><br/><b>(Note: If this does not show your current URL in this textbox, copy paste the current URL in this textbox)</b>
460
- </div>
461
- <div class="option">
462
- <label for="top_opt_tweet_type">' . __('Tweet Content', 'TweetOldPost') . ':</label>
463
- <select id="top_opt_tweet_type" name="top_opt_tweet_type" style="width:150px">
464
- <option value="title" ' . top_opt_optionselected("title", $tweet_type) . '>' . __(' Title Only ', 'TweetOldPost') . ' </option>
465
- <option value="body" ' . top_opt_optionselected("body", $tweet_type) . '>' . __(' Body Only ', 'TweetOldPost') . ' </option>
466
- <option value="titlenbody" ' . top_opt_optionselected("titlenbody", $tweet_type) . '>' . __(' Title & Body ', 'TweetOldPost') . ' </option>
467
- </select>
468
-
469
- </div>
470
-
471
-
472
- <div class="option">
473
- <label for="top_opt_add_text">' . __('Additional Text', 'TweetOldPost') . ':</label>
474
- <input type="text" size="25" name="top_opt_add_text" id="top_opt_add_text" value="' . $additional_text . '" autocomplete="off" />
475
- </div>
476
- <div class="option">
477
- <label for="top_opt_add_text_at">' . __('Additional Text At', 'TweetOldPost') . ':</label>
478
- <select id="top_opt_add_text_at" name="top_opt_add_text_at" style="width:150px">
479
- <option value="beginning" ' . top_opt_optionselected("beginning", $additional_text_at) . '>' . __(' Beginning of tweet ', 'TweetOldPost') . '</option>
480
- <option value="end" ' . top_opt_optionselected("end", $additional_text_at) . '>' . __(' End of tweet ', 'TweetOldPost') . '</option>
481
- </select>
482
- </div>
483
-
484
- <div class="option">
485
- <label for="top_opt_include_link">' . __('Include Link', 'TweetOldPost') . ':</label>
486
- <select id="top_opt_include_link" name="top_opt_include_link" style="width:150px" onchange="javascript:showURLOptions()">
487
- <option value="false" ' . top_opt_optionselected("false", $include_link) . '>' . __(' No ', 'TweetOldPost') . '</option>
488
- <option value="true" ' . top_opt_optionselected("true", $include_link) . '>' . __(' Yes ', 'TweetOldPost') . '</option>
489
- </select>
490
- </div>
491
-
492
- <div id="urloptions" style="display:none">
493
-
494
- <div class="option">
495
- <label for="top_opt_custom_url_option">' . __('Fetch URL from custom field', 'TweetOldPost') . ':</label>
496
- <input onchange="return showCustomField();" type="checkbox" name="top_opt_custom_url_option" ' . $custom_url_option . ' id="top_opt_custom_url_option" />
497
- <b>If checked URL will be fetched from custom field.</b>
498
- </div>
499
-
500
-
501
-
502
- <div id="customurl" style="display:none;">
503
- <div class="option">
504
- <label for="top_opt_custom_url_field">' . __('Custom field name to fetch URL to be tweeted with post', 'TweetOldPost') . ':</label>
505
- <input type="text" size="25" name="top_opt_custom_url_field" id="top_opt_custom_url_field" value="' . $custom_url_field . '" autocomplete="off" />
506
- <b>If set this will fetch the URL from specified custom field</b>
507
- </div>
508
-
509
- </div>
510
-
511
- <div class="option">
512
- <label for="top_opt_use_url_shortner">' . __('Use URL shortner?', 'TweetOldPost') . ':</label>
513
- <input onchange="return showshortener()" type="checkbox" name="top_opt_use_url_shortner" id="top_opt_use_url_shortner" ' . $use_url_shortner . ' />
514
-
515
- </div>
516
-
517
- <div id="urlshortener">
518
- <div class="option">
519
- <label for="top_opt_url_shortener">' . __('URL Shortener Service', 'TweetOldPost') . ':</label>
520
- <select name="top_opt_url_shortener" id="top_opt_url_shortener" onchange="javascript:showURLAPI()" style="width:100px;">
521
- <option value="is.gd" ' . top_opt_optionselected('is.gd', $url_shortener) . '>' . __('is.gd', 'TweetOldPost') . '</option>
522
- <option value="su.pr" ' . top_opt_optionselected('su.pr', $url_shortener) . '>' . __('su.pr', 'TweetOldPost') . '</option>
523
- <option value="bit.ly" ' . top_opt_optionselected('bit.ly', $url_shortener) . '>' . __('bit.ly', 'TweetOldPost') . '</option>
524
- <option value="tr.im" ' . top_opt_optionselected('tr.im', $url_shortener) . '>' . __('tr.im', 'TweetOldPost') . '</option>
525
- <option value="3.ly" ' . top_opt_optionselected('3.ly', $url_shortener) . '>' . __('3.ly', 'TweetOldPost') . '</option>
526
- <option value="u.nu" ' . top_opt_optionselected('u.nu', $url_shortener) . '>' . __('u.nu', 'TweetOldPost') . '</option>
527
- <option value="1click.at" ' . top_opt_optionselected('1click.at', $url_shortener) . '>' . __('1click.at', 'TweetOldPost') . '</option>
528
- <option value="tinyurl" ' . top_opt_optionselected('tinyurl', $url_shortener) . '>' . __('tinyurl', 'TweetOldPost') . '</option>
529
- </select>
530
- </div>
531
- <div id="showDetail" style="display:none">
532
- <div class="option">
533
- <label for="top_opt_bitly_user">' . __('bit.ly Username', 'TweetOldPost') . ':</label>
534
- <input type="text" size="25" name="top_opt_bitly_user" id="top_opt_bitly_user" value="' . $bitly_username . '" autocomplete="off" />
535
- </div>
536
-
537
- <div class="option">
538
- <label for="top_opt_bitly_key">' . __('bit.ly API Key', 'TweetOldPost') . ':</label>
539
- <input type="text" size="25" name="top_opt_bitly_key" id="top_opt_bitly_key" value="' . $bitly_api . '" autocomplete="off" />
540
- </div>
541
- </div>
542
- </div>
543
- </div>
544
-
545
-
546
- <div class="option">
547
- <label for="top_opt_custom_hashtag_option">' . __('Hashtags', 'TweetOldPost') . ':</label>
548
- <select name="top_opt_custom_hashtag_option" id="top_opt_custom_hashtag_option" onchange="javascript:return showHashtagCustomField()" style="width:250px;">
549
- <option value="nohashtag" ' . top_opt_optionselected('nohashtag', $custom_hashtag_option) . '>' . __('Don`t add any hashtags', 'TweetOldPost') . '</option>
550
- <option value="common" ' . top_opt_optionselected('common', $custom_hashtag_option) . '>' . __('Common hashtag for all tweets', 'TweetOldPost') . '</option>
551
- <option value="categories" ' . top_opt_optionselected('categories', $custom_hashtag_option) . '>' . __('Create hashtags from categories', 'TweetOldPost') . '</option>
552
- <option value="tags" ' . top_opt_optionselected('tags', $custom_hashtag_option) . '>' . __('Create hashtags from tags', 'TweetOldPost') . '</option>
553
- <option value="custom" ' . top_opt_optionselected('custom', $custom_hashtag_option) . '>' . __('Get hashtags from custom fields', 'TweetOldPost') . '</option>
554
-
555
- </select>
556
-
557
-
558
- </div>
559
- <div id="inlinehashtag" style="display:none;">
560
- <div class="option">
561
- <label for="top_opt_use_inline_hashtags">' . __('Use inline hashtags: ', 'TweetOldPost') . '</label>
562
- <input type="checkbox" name="top_opt_use_inline_hashtags" id="top_opt_use_inline_hashtags" ' . $use_inline_hashtags . ' />
563
-
564
- </div>
565
-
566
- <div class="option">
567
- <label for="top_opt_hashtag_length">' . __('Maximum Hashtag length: ', 'TweetOldPost') . '</label>
568
- <input type="text" size="25" name="top_opt_hashtag_length" id="top_opt_hashtag_length" value="' . $hashtag_length . '" />
569
- <b>Set this to 0 to include all hashtags</b>
570
- </div>
571
- </div>
572
- <div id="customhashtag" style="display:none;">
573
- <div class="option">
574
- <label for="top_opt_custom_hashtag_field">' . __('Custom field name', 'TweetOldPost') . ':</label>
575
- <input type="text" size="25" name="top_opt_custom_hashtag_field" id="top_opt_custom_hashtag_field" value="' . $custom_hashtag_field . '" autocomplete="off" />
576
- <b>fetch hashtags from this custom field</b>
577
- </div>
578
-
579
- </div>
580
- <div id="commonhashtag" style="display:none;">
581
- <div class="option">
582
- <label for="top_opt_hashtags">' . __('Common #hashtags for your tweets', 'TweetOldPost') . ':</label>
583
- <input type="text" size="25" name="top_opt_hashtags" id="top_opt_hashtags" value="' . $twitter_hashtags . '" autocomplete="off" />
584
- <b>Include #, like #thoughts</b>
585
- </div>
586
- </div>
587
- <div class="option">
588
- <label for="top_opt_interval">' . __('Minimum interval between tweets: ', 'TweetOldPost') . '</label>
589
- <input type="text" id="top_opt_interval" maxlength="5" value="' . $interval . '" name="top_opt_interval" /> Hour / Hours <b>(Note: If set to 0 it will take default as 4 hours)</b>
590
-
591
- </div>
592
- <div class="option">
593
- <label for="top_opt_interval_slop">' . __('Random Interval (added to minimum interval): ', 'TweetOldPost') . '</label>
594
- <input type="text" id="top_opt_interval_slop" maxlength="5" value="' . $slop . '" name="top_opt_interval_slop" /> Hour / Hours <b>(Note: If set to 0 it will take default as 4 hours)</b>
595
-
596
- </div>
597
- <div class="option">
598
- <label for="top_opt_age_limit">' . __('Minimum age of post to be eligible for tweet: ', 'TweetOldPost') . '</label>
599
- <input type="text" id="top_opt_age_limit" maxlength="5" value="' . $ageLimit . '" name="top_opt_age_limit" /> Day / Days
600
- <b> (enter 0 for today)</b>
601
-
602
- </div>
603
-
604
- <div class="option">
605
- <label for="top_opt_max_age_limit">' . __('Maximum age of post to be eligible for tweet: ', 'TweetOldPost') . '</label>
606
- <input type="text" id="top_opt_max_age_limit" maxlength="5" value="' . $maxAgeLimit . '" name="top_opt_max_age_limit" /> Day / Days
607
- <b>(If you dont want to use this option enter 0 or leave blank)</b><br/>
608
- <b>Post older than specified days will not be tweeted.</b>
609
- </div>
610
-
611
-
612
-
613
-
614
-
615
-
616
- <div class="option">
617
- <label for="top_enable_log">' . __('Enable Log: ', 'TweetOldPost') . '</label>
618
- <input type="checkbox" name="top_enable_log" id="top_enable_log" ' . $top_enable_log . ' />
619
- <b>saves log in log folder</b>
620
-
621
- </div>
622
-
623
-
624
- <div class="option category">
625
- <div style="float:left">
626
- <label class="catlabel">' . __('Categories to Omit from tweets: ', 'TweetOldPost') . '</label> </div>
627
- <div style="float:left">
628
- <ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
629
- ');
630
- wp_category_checklist(0, 0, explode(',', $omitCats));
631
- print(' </ul>
632
- <div style="clear:both;padding-top:20px;">
633
- <a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=ExcludePosts">Exclude specific posts</a> from selected categories.
634
- </div>
635
-
636
-
637
- </div>
638
-
639
- </div>
640
- </fieldset>
641
-
642
-
643
-
644
- <h3>Note: Please click update to then click tweet now to reflect the changes.</h3>
645
- <p class="submit"><input type="submit" name="submit" onclick="javascript:return validate()" value="' . __('Update Tweet Old Post Options', 'TweetOldPost') . '" />
646
- <input type="submit" name="tweet" value="' . __('Tweet Now', 'TweetOldPost') . '" />
647
- <input type="submit" onclick=\'return confirm("This will reset all the setting, including your account, omitted categories and excluded posts. Are you sure you want to reset all the settings?");\' name="reset" value="' . __('Reset Settings', 'TweetOldPost') . '" />
648
- </p>
649
-
650
- </form><script language="javascript" type="text/javascript">
651
- function showURLAPI()
652
- {
653
- var urlShortener=document.getElementById("top_opt_url_shortener").value;
654
- if(urlShortener=="bit.ly")
655
- {
656
- document.getElementById("showDetail").style.display="block";
657
-
658
- }
659
- else
660
- {
661
- document.getElementById("showDetail").style.display="none";
662
-
663
- }
664
-
665
- }
666
-
667
- function validate()
668
- {
669
-
670
- if(document.getElementById("showDetail").style.display=="block" && document.getElementById("top_opt_url_shortener").value=="bit.ly")
671
- {
672
- if(trim(document.getElementById("top_opt_bitly_user").value)=="")
673
- {
674
- alert("Please enter bit.ly username.");
675
- document.getElementById("top_opt_bitly_user").focus();
676
- return false;
677
- }
678
-
679
- if(trim(document.getElementById("top_opt_bitly_key").value)=="")
680
- {
681
- alert("Please enter bit.ly API key.");
682
- document.getElementById("top_opt_bitly_key").focus();
683
- return false;
684
- }
685
- }
686
- if(trim(document.getElementById("top_opt_interval").value) != "" && !isNumber(trim(document.getElementById("top_opt_interval").value)))
687
- {
688
- alert("Enter only numeric in Minimum interval between tweet");
689
- document.getElementById("top_opt_interval").focus();
690
- return false;
691
- }
692
- if(trim(document.getElementById("top_opt_interval_slop").value) != "" && !isNumber(trim(document.getElementById("top_opt_interval_slop").value)))
693
- {
694
- alert("Enter only numeric in Random interval");
695
- document.getElementById("top_opt_interval_slop").focus();
696
- return false;
697
- }
698
- if(trim(document.getElementById("top_opt_age_limit").value) != "" && !isNumber(trim(document.getElementById("top_opt_age_limit").value)))
699
- {
700
- alert("Enter only numeric in Minimum age of post");
701
- document.getElementById("top_opt_age_limit").focus();
702
- return false;
703
- }
704
- if(trim(document.getElementById("top_opt_max_age_limit").value) != "" && !isNumber(trim(document.getElementById("top_opt_max_age_limit").value)))
705
- {
706
- alert("Enter only numeric in Maximum age of post");
707
- document.getElementById("top_opt_max_age_limit").focus();
708
- return false;
709
- }
710
- if(trim(document.getElementById("top_opt_max_age_limit").value) != "" && trim(document.getElementById("top_opt_max_age_limit").value) != 0)
711
- {
712
- if(eval(document.getElementById("top_opt_age_limit").value) > eval(document.getElementById("top_opt_max_age_limit").value))
713
- {
714
- alert("Post max age limit cannot be less than Post min age iimit");
715
- document.getElementById("top_opt_age_limit").focus();
716
- return false;
717
- }
718
- }
719
- }
720
-
721
- function trim(stringToTrim) {
722
- return stringToTrim.replace(/^\s+|\s+$/g,"");
723
- }
724
-
725
- function showCustomField()
726
- {
727
- if(document.getElementById("top_opt_custom_url_option").checked)
728
- {
729
- document.getElementById("customurl").style.display="block";
730
- }
731
- else
732
- {
733
- document.getElementById("customurl").style.display="none";
734
- }
735
- }
736
-
737
- function showHashtagCustomField()
738
- {
739
- if(document.getElementById("top_opt_custom_hashtag_option").value=="custom")
740
- {
741
- document.getElementById("customhashtag").style.display="block";
742
- document.getElementById("commonhashtag").style.display="none";
743
- document.getElementById("inlinehashtag").style.display="block";
744
- }
745
- else if(document.getElementById("top_opt_custom_hashtag_option").value=="common")
746
- {
747
- document.getElementById("customhashtag").style.display="none";
748
- document.getElementById("commonhashtag").style.display="block";
749
- document.getElementById("inlinehashtag").style.display="block";
750
- }
751
- else if(document.getElementById("top_opt_custom_hashtag_option").value=="nohashtag")
752
- {
753
- document.getElementById("customhashtag").style.display="none";
754
- document.getElementById("commonhashtag").style.display="none";
755
- document.getElementById("inlinehashtag").style.display="none";
756
- }
757
- else
758
- {
759
- document.getElementById("inlinehashtag").style.display="block";
760
- document.getElementById("customhashtag").style.display="none";
761
- document.getElementById("commonhashtag").style.display="none";
762
- }
763
- }
764
-
765
- function showURLOptions()
766
- {
767
- if(document.getElementById("top_opt_include_link").value=="true")
768
- {
769
- document.getElementById("urloptions").style.display="block";
770
- }
771
- else
772
- {
773
- document.getElementById("urloptions").style.display="none";
774
- }
775
- }
776
-
777
- function isNumber(val)
778
- {
779
- if(isNaN(val)){
780
- return false;
781
- }
782
- else{
783
- return true;
784
- }
785
- }
786
-
787
- function showshortener()
788
- {
789
-
790
-
791
- if((document.getElementById("top_opt_use_url_shortner").checked))
792
- {
793
- document.getElementById("urlshortener").style.display="block";
794
- }
795
- else
796
- {
797
- document.getElementById("urlshortener").style.display="none";
798
- }
799
- }
800
- function setFormAction()
801
- {
802
- if(document.getElementById("top_opt_admin_url").value == "")
803
- {
804
- document.getElementById("top_opt_admin_url").value=location.href;
805
- document.getElementById("top_opt").action=location.href;
806
- }
807
- else
808
- {
809
- document.getElementById("top_opt").action=document.getElementById("top_opt_admin_url").value;
810
- }
811
- }
812
-
813
- setFormAction();
814
- showURLAPI();
815
- showshortener();
816
- showCustomField();
817
- showHashtagCustomField();
818
- showURLOptions();
819
-
820
- </script>');
821
- } else {
822
- print('
823
- <div id="message" class="updated fade">
824
- <p>' . __('You do not have enough permission to set the option. Please contact your admin.', 'TweetOldPost') . '</p>
825
- </div>');
826
- }
827
- }
828
-
829
- function top_opt_optionselected($opValue, $value) {
830
- if ($opValue == $value) {
831
- return 'selected="selected"';
832
- }
833
- return '';
834
- }
835
-
836
- function top_opt_head_admin() {
837
- $home = get_settings('siteurl');
838
- $base = '/' . end(explode('/', str_replace(array('\\', '/top-admin.php'), array('/', ''), __FILE__)));
839
- $stylesheet = $home . '/wp-content/plugins' . $base . '/css/tweet-old-post.css';
840
- echo('<link rel="stylesheet" href="' . $stylesheet . '" type="text/css" media="screen" />');
841
- }
842
-
843
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
top-core.php DELETED
@@ -1,543 +0,0 @@
1
- <?php
2
-
3
- require_once( 'Include/top-oauth.php' );
4
- global $top_oauth;
5
- $top_oauth = new TOPOAuth;
6
-
7
- function top_tweet_old_post() {
8
- //check last tweet time against set interval and span
9
- if (top_opt_update_time()) {
10
- update_option('top_opt_last_update', time());
11
- top_opt_tweet_old_post();
12
- }
13
- }
14
-
15
- function top_currentPageURL() {
16
-
17
- if(!isset($_SERVER['REQUEST_URI'])){
18
- $serverrequri = $_SERVER['PHP_SELF'];
19
- }else{
20
- $serverrequri = $_SERVER['REQUEST_URI'];
21
- }
22
- $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
23
- $protocol = top_strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
24
- $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
25
- return $protocol."://".$_SERVER['SERVER_NAME'].$port.$serverrequri;
26
-
27
-
28
- }
29
-
30
- function top_strleft($s1, $s2) {
31
- return substr($s1, 0, strpos($s1, $s2));
32
- }
33
-
34
- //get random post and tweet
35
- function top_opt_tweet_old_post() {
36
- return top_generate_query();
37
- }
38
-
39
- function top_generate_query($can_requery = true)
40
- {
41
- global $wpdb;
42
- $rtrn_msg="";
43
- $omitCats = get_option('top_opt_omit_cats');
44
- $maxAgeLimit = get_option('top_opt_max_age_limit');
45
- $ageLimit = get_option('top_opt_age_limit');
46
- $exposts = get_option('top_opt_excluded_post');
47
- $exposts = preg_replace('/,,+/', ',', $exposts);
48
-
49
- $top_opt_tweeted_posts = array();
50
- $top_opt_tweeted_posts = get_option('top_opt_tweeted_posts');
51
-
52
- if(!$top_opt_tweeted_posts)
53
- $top_opt_tweeted_posts = array();
54
-
55
- if($top_opt_tweeted_posts != null)
56
- $already_tweeted = implode(",", $top_opt_tweeted_posts);
57
- else
58
- $already_tweeted="";
59
-
60
- if (substr($exposts, 0, 1) == ",") {
61
- $exposts = substr($exposts, 1, strlen($exposts));
62
- }
63
- if (substr($exposts, -1, 1) == ",") {
64
- $exposts = substr($exposts, 0, strlen($exposts) - 1);
65
- }
66
-
67
- if (!(isset($ageLimit) && is_numeric($ageLimit))) {
68
- $ageLimit = top_opt_AGE_LIMIT;
69
- }
70
-
71
- if (!(isset($maxAgeLimit) && is_numeric($maxAgeLimit))) {
72
- $maxAgeLimit = top_opt_MAX_AGE_LIMIT;
73
- }
74
- if (!isset($omitCats)) {
75
- $omitCats = top_opt_OMIT_CATS;
76
- }
77
-
78
- $sql = "SELECT ID
79
- FROM $wpdb->posts
80
- WHERE post_type = 'post'
81
- AND post_status = 'publish' ";
82
-
83
- if(is_numeric($ageLimit))
84
- {
85
- if($ageLimit > 0)
86
- $sql = $sql . " AND post_date <= curdate( ) - INTERVAL " . $ageLimit . " day";
87
- }
88
-
89
- if ($maxAgeLimit != 0) {
90
- $sql = $sql . " AND post_date >= curdate( ) - INTERVAL " . $maxAgeLimit . " day";
91
- }
92
-
93
- if (isset($exposts)) {
94
- if (trim($exposts) != '') {
95
- $sql = $sql . " AND ID Not IN (" . $exposts . ") ";
96
- }
97
- }
98
-
99
- if (isset($already_tweeted)) {
100
- if(trim($already_tweeted) !="")
101
- {
102
- $sql = $sql . " AND ID Not IN (" . $already_tweeted . ") ";
103
- }
104
- }
105
- if ($omitCats != '') {
106
- $sql = $sql . " AND NOT (ID IN (SELECT tr.object_id FROM " . $wpdb->prefix . "term_relationships AS tr INNER JOIN " . $wpdb->prefix . "term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy = 'category' AND tt.term_id IN (" . $omitCats . ")))";
107
- }
108
- $sql = $sql . "
109
- ORDER BY RAND()
110
- LIMIT 1 ";
111
-
112
- $oldest_post = $wpdb->get_var($sql);
113
-
114
- if($oldest_post == null)
115
- {
116
- if($can_requery)
117
- {
118
- $top_opt_tweeted_posts=array();
119
- update_option('top_opt_tweeted_posts', $top_opt_tweeted_posts);
120
- return top_generate_query(false);
121
- }
122
- else
123
- {
124
- return "No post found to tweet. Please check your settings and try again.";
125
- }
126
- }
127
- if (isset($oldest_post)) {
128
- array_push($top_opt_tweeted_posts, $oldest_post);
129
- update_option('top_opt_tweeted_posts', $top_opt_tweeted_posts);
130
- return top_opt_tweet_post($oldest_post);
131
- }
132
- return $rtrn_msg;
133
- }
134
-
135
-
136
- //tweet for the passed random post
137
- function top_opt_tweet_post($oldest_post) {
138
- global $wpdb;
139
- $post = get_post($oldest_post);
140
- $content = "";
141
- $to_short_url = true;
142
- $shorturl = "";
143
- $tweet_type = get_option('top_opt_tweet_type');
144
- $additional_text = get_option('top_opt_add_text');
145
- $additional_text_at = get_option('top_opt_add_text_at');
146
- $include_link = get_option('top_opt_include_link');
147
- $custom_hashtag_option = get_option('top_opt_custom_hashtag_option');
148
- $custom_hashtag_field = get_option('top_opt_custom_hashtag_field');
149
- $twitter_hashtags = get_option('top_opt_hashtags');
150
- $url_shortener = get_option('top_opt_url_shortener');
151
- $custom_url_option = get_option('top_opt_custom_url_option');
152
- $to_short_url = get_option('top_opt_use_url_shortner');
153
- $use_inline_hashtags = get_option('top_opt_use_inline_hashtags');
154
- $hashtag_length = get_option('top_opt_hashtag_length');
155
-
156
- if ($include_link != "false") {
157
- $permalink = get_permalink($oldest_post);
158
-
159
- if ($custom_url_option) {
160
- $custom_url_field = get_option('top_opt_custom_url_field');
161
- if (trim($custom_url_field) != "") {
162
- $permalink = trim(get_post_meta($post->ID, $custom_url_field, true));
163
- }
164
- }
165
-
166
- if ($to_short_url) {
167
-
168
- if ($url_shortener == "bit.ly") {
169
- $bitly_key = get_option('top_opt_bitly_key');
170
- $bitly_user = get_option('top_opt_bitly_user');
171
- $shorturl = shorten_url($permalink, $url_shortener, $bitly_key, $bitly_user);
172
- } else {
173
- $shorturl = shorten_url($permalink, $url_shortener);
174
- }
175
- } else {
176
- $shorturl = $permalink;
177
- }
178
- }
179
-
180
- if ($tweet_type == "title" || $tweet_type == "titlenbody") {
181
- $title = stripslashes($post->post_title);
182
- $title = strip_tags($title);
183
- $title = preg_replace('/\s\s+/', ' ', $title);
184
- } else {
185
- $title = "";
186
- }
187
-
188
- if ($tweet_type == "body" || $tweet_type == "titlenbody") {
189
- $body = stripslashes($post->post_content);
190
- $body = strip_tags($body);
191
- $body = preg_replace('/\s\s+/', ' ', $body);
192
- } else {
193
- $body = "";
194
- }
195
-
196
- if ($tweet_type == "titlenbody") {
197
- if ($title == null) {
198
- $content = $body;
199
- } elseif ($body == null) {
200
- $content = $title;
201
- } else {
202
- $content = $title . " - " . $body;
203
- }
204
- } elseif ($tweet_type == "title") {
205
- $content = $title;
206
- } elseif ($tweet_type == "body") {
207
- $content = $body;
208
- }
209
-
210
- if ($additional_text != "") {
211
- if ($additional_text_at == "end") {
212
- $content = $content . ". " . $additional_text;
213
- } elseif ($additional_text_at == "beginning") {
214
- $content = $additional_text . ": " . $content;
215
- }
216
- }
217
-
218
- $hashtags = "";
219
- $newcontent = "";
220
- if ($custom_hashtag_option != "nohashtag") {
221
-
222
- if ($custom_hashtag_option == "common") {
223
- //common hashtag
224
- $hashtags = $twitter_hashtags;
225
- }
226
- //post custom field hashtag
227
- elseif ($custom_hashtag_option == "custom") {
228
- if (trim($custom_hashtag_field) != "") {
229
- $hashtags = trim(get_post_meta($post->ID, $custom_hashtag_field, true));
230
- }
231
- } elseif ($custom_hashtag_option == "categories") {
232
- $post_categories = get_the_category($post->ID);
233
- if ($post_categories) {
234
- foreach ($post_categories as $category) {
235
- $tagname = str_replace(".", "", str_replace(" ", "", $category->cat_name));
236
- if ($use_inline_hashtags) {
237
- if (strrpos($content, $tagname) === false) {
238
- $hashtags = $hashtags . "#" . $tagname . " ";
239
- } else {
240
- $newcontent = preg_replace('/\b' . $tagname . '\b/i', "#" . $tagname, $content, 1);
241
- }
242
- } else {
243
- $hashtags = $hashtags . "#" . $tagname . " ";
244
- }
245
- }
246
- }
247
- } elseif ($custom_hashtag_option == "tags") {
248
- $post_tags = get_the_tags($post->ID);
249
- if ($post_tags) {
250
- foreach ($post_tags as $tag) {
251
- $tagname = str_replace(".", "", str_replace(" ", "", $tag->name));
252
- if ($use_inline_hashtags) {
253
- if (strrpos($content, $tagname) === false) {
254
- $hashtags = $hashtags . "#" . $tagname . " ";
255
- } else {
256
- $newcontent = preg_replace('/\b' . $tagname . '\b/i', "#" . $tagname, $content, 1);
257
- }
258
- } else {
259
- $hashtags = $hashtags . "#" . $tagname . " ";
260
- }
261
- }
262
- }
263
- }
264
-
265
- if ($newcontent != "")
266
- $content = $newcontent;
267
- }
268
-
269
-
270
-
271
- if ($include_link != "false") {
272
- if (!is_numeric($shorturl) && (strncmp($shorturl, "http", strlen("http")) == 0)) {
273
-
274
- } else {
275
- return "OOPS!!! problem with your URL shortning service. Some signs of error " . $shorturl . ".";
276
- }
277
- }
278
-
279
- $message = set_tweet_length($content, $shorturl, $hashtags, $hashtag_length);
280
- $status = urlencode(stripslashes(urldecode($message)));
281
- if ($status) {
282
- $poststatus = top_update_status($message);
283
- if ($poststatus == true)
284
- return "Whoopie!!! Tweet Posted Successfully";
285
- else
286
- return "OOPS!!! there seems to be some problem while tweeting. Please try again.";
287
- }
288
- return "OOPS!!! there seems to be some problem while tweeting. Try again. If problem is persistent mail the problem at ajay@ajaymatharu.com";
289
- }
290
-
291
- //send request to passed url and return the response
292
- function send_request($url, $method='GET', $data='', $auth_user='', $auth_pass='') {
293
- $ch = curl_init($url);
294
- if (strtoupper($method) == "POST") {
295
- curl_setopt($ch, CURLOPT_POST, 1);
296
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
297
- }
298
- if (ini_get('open_basedir') == '' && ini_get('safe_mode') == 'Off') {
299
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
300
- }
301
- curl_setopt($ch, CURLOPT_HEADER, 0);
302
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
303
- if ($auth_user != '' && $auth_pass != '') {
304
- curl_setopt($ch, CURLOPT_USERPWD, "{$auth_user}:{$auth_pass}");
305
- }
306
- $response = curl_exec($ch);
307
- $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
308
- curl_close($ch);
309
- if ($httpcode != 200) {
310
- return $httpcode;
311
- }
312
-
313
- return $response;
314
- }
315
-
316
-
317
- /* returns a result form url */
318
- function top_curl_get_result($url) {
319
- $ch = curl_init();
320
- $timeout = 5;
321
- curl_setopt($ch,CURLOPT_URL,$url);
322
- curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
323
- curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
324
- $data = curl_exec($ch);
325
- curl_close($ch);
326
- return $data;
327
- }
328
-
329
- function top_get_bitly_short_url($url,$login,$appkey,$format='txt') {
330
- $connectURL = 'http://api.bit.ly/v3/shorten?login='.$login.'&apiKey='.$appkey.'&uri='.urlencode($url).'&format='.$format;
331
- return top_curl_get_result($connectURL);
332
- }
333
-
334
- //Shorten long URLs with is.gd or bit.ly.
335
- function shorten_url($the_url, $shortener='is.gd', $api_key='', $user='') {
336
-
337
- if (($shortener == "bit.ly") && isset($api_key) && isset($user)) {
338
- $response = top_get_bitly_short_url($the_url, $user, $api_key);
339
- } elseif ($shortener == "su.pr") {
340
- $url = "http://su.pr/api/simpleshorten?url={$the_url}";
341
- $response = send_request($url, 'GET');
342
- } elseif ($shortener == "tr.im") {
343
- $url = "http://api.tr.im/api/trim_simple?url={$the_url}";
344
- $response = send_request($url, 'GET');
345
- } elseif ($shortener == "3.ly") {
346
- $url = "http://3.ly/?api=em5893833&u={$the_url}";
347
- $response = send_request($url, 'GET');
348
- } elseif ($shortener == "tinyurl") {
349
- $url = "http://tinyurl.com/api-create.php?url={$the_url}";
350
- $response = send_request($url, 'GET');
351
- } elseif ($shortener == "u.nu") {
352
- $url = "http://u.nu/unu-api-simple?url={$the_url}";
353
- $response = send_request($url, 'GET');
354
- } elseif ($shortener == "1click.at") {
355
- $url = "http://1click.at/api.php?action=shorturl&url={$the_url}&format=simple";
356
- $response = send_request($url, 'GET');
357
- } else {
358
- $url = "http://is.gd/api.php?longurl={$the_url}";
359
- $response = send_request($url, 'GET');
360
- }
361
-
362
- return $response;
363
- }
364
-
365
- //Shrink a tweet and accompanying URL down to 140 chars.
366
- function set_tweet_length($message, $url, $twitter_hashtags="", $hashtag_length=0) {
367
-
368
- $tags = $twitter_hashtags;
369
- $message_length = strlen($message);
370
- $url_length = strlen($url);
371
- //$cur_length = strlen($tags);
372
- if ($hashtag_length == 0)
373
- $hashtag_length = strlen($tags);
374
-
375
- if ($twitter_hashtags != "") {
376
- if (strlen($tags) > $hashtag_length) {
377
- $tags = substr($tags, 0, $hashtag_length);
378
- $tags = substr($tags, 0, strrpos($tags, ' '));
379
- }
380
- $hashtag_length = strlen($tags);
381
- }
382
-
383
- if ($message_length + $url_length + $hashtag_length > 140) {
384
-
385
-
386
- $shorten_message_to = 140 - $url_length - $hashtag_length;
387
- $shorten_message_to = $shorten_message_to - 4;
388
- //$message = $message." ";
389
- if (strlen($message) > $shorten_message_to) {
390
- $message = substr($message, 0, $shorten_message_to);
391
- $message = substr($message, 0, strrpos($message, ' '));
392
- }
393
- $message = $message . "...";
394
- }
395
- return $message . " " . $url . " " . $tags;
396
- }
397
-
398
- //check time and update the last tweet time
399
- function top_opt_update_time() {
400
-
401
-
402
- return top_to_update();
403
-
404
- }
405
-
406
- function top_to_update() {
407
- $last = get_option('top_opt_last_update');
408
- $interval = get_option('top_opt_interval');
409
- $slop = get_option('top_opt_interval_slop');
410
-
411
- if (!(isset($interval))) {
412
- $interval = top_opt_INTERVAL;
413
- }
414
- else if(!(is_numeric($interval)))
415
- {
416
- $interval = top_opt_INTERVAL;
417
- }
418
-
419
-
420
- if (!(isset($slop))) {
421
- $slop = top_opt_INTERVAL_SLOP;
422
- }
423
- else if(!(is_numeric($slop)))
424
- {
425
- $slop = top_opt_INTERVAL_SLOP;
426
- }
427
-
428
-
429
-
430
- $interval = $interval * 60 * 60;
431
- $slop = $slop * 60 * 60;
432
- if (false === $last) {
433
- $ret = 1;
434
- } else if (is_numeric($last)) {
435
- $ret = ( (time() - $last) > ($interval + rand(0, $slop)));
436
- }
437
-
438
-
439
- return $ret;
440
- }
441
-
442
- function top_get_auth_url() {
443
- global $top_oauth;
444
- $settings = top_get_settings();
445
-
446
- $token = $top_oauth->get_request_token();
447
- if ($token) {
448
- $settings['oauth_request_token'] = $token['oauth_token'];
449
- $settings['oauth_request_token_secret'] = $token['oauth_token_secret'];
450
-
451
- top_save_settings($settings);
452
-
453
- return $top_oauth->get_auth_url($token['oauth_token']);
454
- }
455
- }
456
-
457
- function top_update_status($new_status) {
458
- global $top_oauth;
459
- $settings = top_get_settings();
460
-
461
- if (isset($settings['oauth_access_token']) && isset($settings['oauth_access_token_secret'])) {
462
- return $top_oauth->update_status($settings['oauth_access_token'], $settings['oauth_access_token_secret'], $new_status);
463
- }
464
-
465
- return false;
466
- }
467
-
468
- function top_has_tokens() {
469
- $settings = top_get_settings();
470
-
471
- return ( $settings['oauth_access_token'] && $settings['oauth_access_token_secret'] );
472
- }
473
-
474
- function top_is_valid() {
475
- return twit_has_tokens();
476
- }
477
-
478
- function top_do_tweet($post_id) {
479
- $settings = top_get_settings();
480
-
481
- $message = top_get_message($post_id);
482
-
483
- // If we have a valid message, Tweet it
484
- // this will fail if the Tiny URL service is done
485
- if ($message) {
486
- // If we successfully posted this to Twitter, then we can remove it from the queue eventually
487
- if (twit_update_status($message)) {
488
- return true;
489
- }
490
- }
491
-
492
- return false;
493
- }
494
-
495
- function top_get_settings() {
496
- global $top_defaults;
497
-
498
- $settings = $top_defaults;
499
-
500
- $wordpress_settings = get_option('top_settings');
501
- if ($wordpress_settings) {
502
- foreach ($wordpress_settings as $key => $value) {
503
- $settings[$key] = $value;
504
- }
505
- }
506
-
507
- return $settings;
508
- }
509
-
510
- function top_save_settings($settings) {
511
- update_option('top_settings', $settings);
512
- }
513
-
514
- function top_reset_settings()
515
- {
516
- delete_option('top_settings');
517
- update_option('top_enable_log','');
518
- update_option('top_opt_add_text','');
519
- update_option('top_opt_add_text_at','beginning');
520
- update_option('top_opt_age_limit',30);
521
- update_option('top_opt_bitly_key','');
522
- update_option('top_opt_bitly_user','');
523
- update_option('top_opt_custom_hashtag_field','');
524
- update_option('top_opt_custom_hashtag_option','nohashtag');
525
- update_option('top_opt_custom_url_field','');
526
- update_option('top_opt_custom_url_option','');
527
- update_option('top_opt_excluded_post','');
528
- update_option('top_opt_hashtags','');
529
- update_option('top_opt_hashtag_length','20');
530
- update_option('top_opt_include_link','no');
531
- update_option('top_opt_interval',4);
532
- update_option('top_opt_interval_slop',4);
533
- delete_option('top_opt_last_update');
534
- update_option('top_opt_max_age_limit',60);
535
- update_option('top_opt_omit_cats','');
536
- update_option('top_opt_tweet_type','title');
537
- delete_option('top_opt_tweeted_posts');
538
- update_option('top_opt_url_shortener','is.gd');
539
- update_option('top_opt_use_inline_hashtags','');
540
- update_option('top_opt_use_url_shortner','');
541
- }
542
-
543
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
tweet-old-post.php CHANGED
@@ -1,84 +1,28 @@
1
  <?php
2
  # /*
3
  # Plugin Name: Tweet old post
4
- # Plugin URI: http://www.ajaymatharu.com/wordpress-plugin-tweet-old-posts/
5
- # Description: This plugin helps you to keeps your old posts alive by tweeting about them and driving more traffic to them from twitter.
6
- # Author: Ajay Matharu
7
- # Version: 3.3.3
8
- # Author URI: http://www.ajaymatharu.com/
9
  # */
10
-
11
 
12
- require_once('top-admin.php');
13
- require_once('top-core.php');
14
- require_once('top-excludepost.php');
15
-
16
- define ('top_opt_1_HOUR', 60*60);
17
- define ('top_opt_2_HOURS', 2*top_opt_1_HOUR);
18
- define ('top_opt_4_HOURS', 4*top_opt_1_HOUR);
19
- define ('top_opt_8_HOURS', 8*top_opt_1_HOUR);
20
- define ('top_opt_6_HOURS', 6*top_opt_1_HOUR);
21
- define ('top_opt_12_HOURS', 12*top_opt_1_HOUR);
22
- define ('top_opt_24_HOURS', 24*top_opt_1_HOUR);
23
- define ('top_opt_48_HOURS', 48*top_opt_1_HOUR);
24
- define ('top_opt_72_HOURS', 72*top_opt_1_HOUR);
25
- define ('top_opt_168_HOURS', 168*top_opt_1_HOUR);
26
- define ('top_opt_INTERVAL', 4);
27
- define ('top_opt_INTERVAL_SLOP', 4);
28
- define ('top_opt_AGE_LIMIT', 30); // 120 days
29
- define ('top_opt_MAX_AGE_LIMIT', 60); // 120 days
30
- define ('top_opt_OMIT_CATS', "");
31
- define('top_opt_TWEET_PREFIX',"");
32
- define('top_opt_ADD_DATA',"false");
33
- define('top_opt_URL_SHORTENER',"is.gd");
34
- define('top_opt_HASHTAGS',"");
35
-
36
- global $top_db_version;
37
- $top_db_version = "1.0";
38
-
39
- function top_admin_actions() {
40
- add_menu_page("Tweet Old Post", "Tweet Old Post", 1, "TweetOldPost", "top_admin");
41
- add_submenu_page("TweetOldPost", __('Exclude Posts','TweetOldPost'), __('Exclude Posts','TweetOldPost'), 1, __('ExcludePosts','TweetOldPost'), 'top_exclude');
42
-
43
- }
44
-
45
- add_action('admin_menu', 'top_admin_actions');
46
- add_action('admin_head', 'top_opt_head_admin');
47
- add_action('init','top_tweet_old_post');
48
- add_action('admin_init','top_authorize',1);
49
-
50
- function top_authorize()
51
- {
52
-
53
-
54
- if ( isset( $_REQUEST['oauth_token'] ) ) {
55
- $auth_url= str_replace('oauth_token', 'oauth_token1', top_currentPageURL());
56
- $top_url = get_option('top_opt_admin_url') . substr($auth_url,strrpos($auth_url, "page=TweetOldPost") + strlen("page=TweetOldPost"));
57
- echo '<script language="javascript">window.open ("'.$top_url.'","_self")</script>';
58
-
59
- die;
60
- }
61
-
62
- }
63
-
64
- add_filter('plugin_action_links', 'top_plugin_action_links', 10, 2);
65
-
66
- function top_plugin_action_links($links, $file) {
67
- static $this_plugin;
68
-
69
- if (!$this_plugin) {
70
- $this_plugin = plugin_basename(__FILE__);
71
- }
72
-
73
- if ($file == $this_plugin) {
74
- // The "page" query string value must be equal to the slug
75
- // of the Settings admin page we defined earlier, which in
76
- // this case equals "myplugin-settings".
77
- $settings_link = '<a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=TweetOldPost">Settings</a>';
78
- array_unshift($links, $settings_link);
79
- }
80
-
81
- return $links;
82
  }
83
-
84
- ?>
 
 
 
1
  <?php
2
  # /*
3
  # Plugin Name: Tweet old post
4
+ # Plugin URI: http://themeisle.com/plugins/tweet-old-post-lite/
5
+ # Description: Wordpress plugin that helps you to keeps your old posts alive by tweeting about them and driving more traffic to them from twitter. It also helps you to promote your content. You can set time and no of tweets to post to drive more traffic.For questions, comments, or feature requests, <a href="http://themeisle.com/contact/?utm_source=plugindesc&utm_medium=announce&utm_campaign=top">contact </a> us!
6
+ # Author: ThemeIsle
7
+ # Version: 6.7.2
8
+ # Author URI: http://themeisle.com/
9
  # */
 
10
 
11
+ // Config Constants
12
+ define("PLUGINPATH", realpath(dirname(__FILE__) ));
13
+ define("CSSFILE", plugins_url('css/style.css',__FILE__ ));
14
+ define("JSFILE", plugins_url('js/master.js',__FILE__ ));
15
+ define("JSCOUNTDOWN", plugins_url('js/countdown.js',__FILE__ ));
16
+
17
+ // Require core.
18
+ require_once(PLUGINPATH."/inc/core.php");
19
+ // Require core.
20
+ require_once(PLUGINPATH."/inc/exclude-posts.php");
21
+ if (!class_exists('TAV_Remote_Notification_Client')) {
22
+ require( PLUGINPATH.'/inc/class-remote-notification-client.php' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  }
24
+ $notification = new TAV_Remote_Notification_Client( 37, 'a8be784b898fa2fb', 'http://themeisle.com?post_type=notification' );
25
+ // Clear scheduled tweets on plugin deactivation
26
+ register_deactivation_hook(__FILE__, array($CWP_TOP_Core, 'deactivationHook'));
27
+ // Reset all settings on plugin activation.
28
+ register_activation_hook(__FILE__, array($CWP_TOP_Core, 'resetAllOptions'));