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

Version Description

Download this release

Release Info

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

Version 3.0

Files changed (7) hide show
  1. Include/oauth.php +242 -0
  2. css/tweet-old-post.css +76 -0
  3. readme.txt +285 -0
  4. top-admin.php +528 -0
  5. top-core.php +343 -0
  6. tweet-old-post.php +43 -0
  7. xml.php +130 -0
Include/oauth.php ADDED
@@ -0,0 +1,242 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if ( !class_exists( 'WP_Http' ) ) {
4
+ include_once( ABSPATH . WPINC. '/class-http.php' );
5
+ }
6
+
7
+ define( 'TOP_OAUTH_CONSUMER_KEY', 'ofaYongByVpa3NDEbXa2g' );
8
+ define( 'TOP_OAUTH_REQUEST_URL', 'http://api.twitter.com/oauth/request_token' );
9
+ define( 'TOP_OAUTH_ACCESS_URL', 'http://api.twitter.com/oauth/access_token' );
10
+ define( 'TOP_OAUTH_AUTHORIZE_URL', 'http://api.twitter.com/oauth/authorize' );
11
+ define( 'TOP_OAUTH_REALM', 'http://twitter.com/' );
12
+
13
+ class TOPOAuth {
14
+ var $duplicate_tweet;
15
+
16
+ function TOPOAuth() {
17
+ $this->duplicate_tweet = false;
18
+
19
+ $this->setup();
20
+ }
21
+
22
+ function encode( $string ) {
23
+ return str_replace( '+', ' ', str_replace( '%7E', '~', rawurlencode( $string ) ) );
24
+ }
25
+
26
+ function create_signature_base_string( $get_method, $base_url, $params ) {
27
+ if ( $get_method ) {
28
+ $base_string = "GET&";
29
+ } else {
30
+ $base_string = "POST&";
31
+ }
32
+
33
+ $base_string .= $this->encode( $base_url ) . "&";
34
+
35
+ // Sort the parameters
36
+ ksort( $params );
37
+
38
+ $encoded_params = array();
39
+ foreach( $params as $key => $value ) {
40
+ $encoded_params[] = $this->encode( $key ) . '=' . $this->encode( $value );
41
+ }
42
+
43
+ $base_string = $base_string . $this->encode( implode( $encoded_params, "&" ) );
44
+
45
+ return $base_string;
46
+ }
47
+
48
+ function params_to_query_string( $params ) {
49
+ $query_string = array();
50
+ foreach( $params as $key => $value ) {
51
+ $query_string[ $key ] = $key . '=' . $value;
52
+ }
53
+
54
+ ksort( $query_string );
55
+
56
+ return implode( '&', $query_string );
57
+ }
58
+
59
+ function do_get_request( $url ) {
60
+ $request = new WP_Http;
61
+ $result = $request->request( $url );
62
+
63
+ if ( $result['response']['code'] == '200' ) {
64
+ return $result['body'];
65
+ } else {
66
+ return false;
67
+ }
68
+ }
69
+
70
+ function do_request( $url, $oauth_header, $body_params = '' ) {
71
+ $request = new WP_Http;
72
+
73
+ $params = array();
74
+ if ( $body_params ) {
75
+ foreach( $body_params as $key => $value ) {
76
+ $body_params[ $key ] = ( $value );
77
+ }
78
+
79
+ $params['body'] = $body_params;
80
+ }
81
+
82
+ $params['method'] = 'POST';
83
+ $params['headers'] = array( 'Authorization' => $oauth_header );
84
+
85
+ $result = $request->request( $url, $params );
86
+
87
+ if ( !is_wp_error( $result ) ) {
88
+ if ( $result['response']['code'] == '200' ) {
89
+ return $result['body'];
90
+ } else if ( $result['response']['code'] == '403' ) {
91
+ // this is a duplicate tweet
92
+ $this->duplicate_tweet = true;
93
+ }
94
+ }
95
+
96
+ return false;
97
+ }
98
+
99
+ function get_nonce() {
100
+ return md5( mt_rand() + mt_rand() );
101
+ }
102
+
103
+ function parse_params( $string_params ) {
104
+ $good_params = array();
105
+
106
+ $params = explode( '&', $string_params );
107
+ foreach( $params as $param ) {
108
+ $keyvalue = explode( '=', $param );
109
+ $good_params[ $keyvalue[0] ] = $keyvalue[1];
110
+ }
111
+
112
+ return $good_params;
113
+ }
114
+
115
+ function hmac_sha1( $key, $data ) {
116
+ if ( function_exists( 'hash_hmac' ) ) {
117
+ $hash = hash_hmac( 'sha1', $data, $key, true );
118
+
119
+ return $hash;
120
+ } else {
121
+ $blocksize = 64;
122
+ $hashfunc = 'sha1';
123
+ if ( strlen( $key ) >$blocksize ) {
124
+ $key = pack( 'H*', $hashfunc( $key ) );
125
+ }
126
+
127
+ $key = str_pad( $key, $blocksize, chr(0x00) );
128
+ $ipad = str_repeat( chr( 0x36 ), $blocksize );
129
+ $opad = str_repeat( chr( 0x5c ), $blocksize );
130
+ $hash = pack( 'H*', $hashfunc( ( $key^$opad ).pack( 'H*',$hashfunc( ($key^$ipad).$data ) ) ) );
131
+
132
+ return $hash;
133
+ }
134
+ }
135
+
136
+ function do_oauth( $url, $params, $token_secret = '' ) {
137
+ $sig_string = $this->create_signature_base_string( false, $url, $params );
138
+
139
+ //$hash = hash_hmac( 'sha1', $sig_string, TOP_OAUTH_CONSUMER_SECRET . '&' . $token_secret, true );
140
+ $hash = $this->hmac_sha1( 'vTzszlMujMZCY3mVtTE6WovUKQxqv3LVgiVku276M' . '&' . $token_secret, $sig_string );
141
+ $sig = base64_encode( $hash );
142
+
143
+ $params['oauth_signature'] = $sig;
144
+
145
+ $header = "OAuth ";
146
+ $all_params = array();
147
+ $other_params = array();
148
+ foreach( $params as $key => $value ) {
149
+ if ( strpos( $key, 'oauth_' ) !== false ) {
150
+ $all_params[] = $key . '="' . $this->encode( $value ) . '"';
151
+ } else {
152
+ $other_params[ $key ] = $value;
153
+ }
154
+ }
155
+
156
+ $header .= implode( $all_params, ", " );
157
+
158
+ return $this->do_request( $url, $header, $other_params );
159
+ }
160
+
161
+ function get_request_token() {
162
+ $params = array();
163
+
164
+ $params['oauth_consumer_key'] = TOP_OAUTH_CONSUMER_KEY;
165
+ $params['oauth_callback'] = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '&TOP_oauth=1';
166
+ $params['oauth_signature_method'] = 'HMAC-SHA1';
167
+ $params['oauth_timestamp'] = time();
168
+ $params['oauth_nonce'] = $this->get_nonce();
169
+ $params['oauth_version'] = '1.0';
170
+
171
+ $result = $this->do_oauth( TOP_OAUTH_REQUEST_URL, $params );
172
+
173
+ if ( $result ) {
174
+ $new_params = $this->parse_params( $result );
175
+ return $new_params;
176
+ }
177
+ }
178
+
179
+ function get_access_token( $token, $token_secret, $verifier ) {
180
+ $params = array();
181
+
182
+ $params['oauth_consumer_key'] = TOP_OAUTH_CONSUMER_KEY;
183
+ $params['oauth_signature_method'] = 'HMAC-SHA1';
184
+ $params['oauth_timestamp'] = time();
185
+ $params['oauth_nonce'] = $this->get_nonce();
186
+ $params['oauth_version'] = '1.0';
187
+ $params['oauth_token'] = $token;
188
+ $params['oauth_verifier'] = $verifier;
189
+
190
+ $result = $this->do_oauth( TOP_OAUTH_ACCESS_URL, $params, $token_secret );
191
+ if ( $result ) {
192
+ $new_params = $this->parse_params( $result );
193
+ return $new_params;
194
+ }
195
+ }
196
+
197
+ function update_status( $token, $token_secret, $status ) {
198
+ $params = array();
199
+
200
+ $params['oauth_consumer_key'] = TOP_OAUTH_CONSUMER_KEY;
201
+ $params['oauth_signature_method'] = 'HMAC-SHA1';
202
+ $params['oauth_timestamp'] = time();
203
+ $params['oauth_nonce'] = $this->get_nonce();
204
+ $params['oauth_version'] = '1.0';
205
+ $params['oauth_token'] = $token;
206
+ $params['status'] = $status;
207
+
208
+ $url = 'http://api.twitter.com/1/statuses/update.xml';
209
+
210
+ $result = $this->do_oauth( $url, $params, $token_secret );
211
+ if ( $result ) {
212
+ $new_params = TOP_parsexml( $result );
213
+ return true;
214
+ } else {
215
+ return false;
216
+ }
217
+ }
218
+
219
+ function was_duplicate_tweet() {
220
+ return $this->duplicate_tweet;
221
+ }
222
+
223
+ function get_auth_url( $token ) {
224
+ return TOP_OAUTH_AUTHORIZE_URL . '?oauth_token=' . $token;
225
+ }
226
+
227
+ function get_user_info( $user_id ) {
228
+ $url = 'http://api.twitter.com/1/users/show.xml?id=' . $user_id;
229
+
230
+ $result = $this->do_get_request( $url );
231
+ if ( $result ) {
232
+ $new_params = TOP_parsexml( $result );
233
+ return $new_params;
234
+ }
235
+ }
236
+
237
+ function setup() {
238
+ eval( base64_decode( 'ZGVmaW5lKCAnV09SRFRXSVRfT0FVVEhfQ09OU1VNRVJfU0VDUkVUJywgJ0cxWkVTQjVXUGpDVDE4dVhDeldxNVZxbHBtdDdKanNVYVN0ZG5Gd3dhdycgKTs=' ) );
239
+ }
240
+ }
241
+
242
+ ?>
css/tweet-old-post.css ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .wrap h2 {
2
+ margin-top: 32px;
3
+ }
4
+ #top_opt .options {
5
+ overflow: hidden;
6
+ border: none;
7
+ }
8
+ #top_opt .option {
9
+ overflow: hidden;
10
+ border-bottom: dashed 1px #ccc;
11
+ padding-bottom: 9px;
12
+ padding-top: 9px;
13
+ }
14
+ #top_opt .option label {
15
+ display: block;
16
+ float: left;
17
+ width: 200px;
18
+ margin-right: 24px;
19
+ text-align: right;
20
+ }
21
+ #top_opt .option span {
22
+ display: block;
23
+ float: left;
24
+ margin-left: 230px;
25
+ margin-top: 6px;
26
+ clear: left;
27
+ }
28
+
29
+ #top_opt p.submit {
30
+ overflow: hidden;
31
+ }
32
+ #top_opt .option span {
33
+ color: #666;
34
+ display: block;
35
+ }
36
+
37
+ #top_opt .category label
38
+ {
39
+ float:left;
40
+ text-align:left;
41
+
42
+ }
43
+
44
+ #top_opt .category .catlabel
45
+ {
46
+ text-align:right;
47
+ }
48
+
49
+ #profile-box
50
+ {
51
+ overflow:hidden;
52
+ padding-left: 15px;
53
+ }
54
+ #profile-box .avatar
55
+ {
56
+ float:left;
57
+ margin-right: 10px;
58
+ border-style: none;
59
+ }
60
+
61
+ #profile-box p {
62
+ margin-left: 58px;
63
+ }
64
+
65
+ #profile-box h4,
66
+ #profile-box h5 {
67
+ font-size: 13px;
68
+ text-shadow: #fff 0 -1px 1px;
69
+ margin: 0px;
70
+ padding-bottom: 2px;
71
+ }
72
+
73
+ #profile-box h5 {
74
+ font-size: 11px;
75
+ font-weight: normal;
76
+ }
readme.txt ADDED
@@ -0,0 +1,285 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
4
+ Requires at least: 2.7
5
+ Tested up to: 3.0.1
6
+ Stable tag: trunk
7
+
8
+ Plugin to tweet about your old posts to get more hits for them and keep them alive.
9
+
10
+ == Description ==
11
+
12
+ Tweet Old Posts is a plugin designed to tweet your older posts to get more traffic.
13
+
14
+ Tweet Old Posts randomly picks your older post based on the interval specified by you. The primary function of this plugin is to promote older blog posts by tweeting about them and getting more traffic.
15
+
16
+
17
+
18
+ Some of the options you can configure for the Tweet Old Posts plugins are,
19
+
20
+ **v1.1**
21
+
22
+ Twitter Username & Password - Using this twitter account credentials plugin will tweet.
23
+
24
+ Minimum interval between tweets - allows you to determine how often the plugin will automatically choose and tweet a blog post for you.
25
+
26
+ Randomness interval - This is a contributing factor in minimum interval so that posts are randomly chosen and tweeted from your blog.
27
+
28
+ 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.
29
+
30
+ Categories to omit from tweets - This will protect posts from the selected categories from being tweeted.
31
+
32
+
33
+
34
+ **New in v1.2**
35
+
36
+ Tweet Prefix - Allows you to set prefix to the tweets.
37
+
38
+ Add Data - Allows you to add post data to the tweets
39
+
40
+ Tweet now - Button that will tweet at that moment without wanting you to wait for scheduled tweet
41
+
42
+
43
+
44
+ **New in v1.3**
45
+
46
+ URL Shortener Service - allows you to select which URL shortener service you want to use.
47
+
48
+
49
+ **New in v1.4**
50
+
51
+ Hashtags - allows you to set default hashtags for your tweets
52
+
53
+
54
+ **New in v1.5**
55
+
56
+ Maximum age of post to be eligible for tweet - allows you to set Maximum age of the post to be eligible for tweet
57
+
58
+ Added one more shortner service was looking for j.mp but they dont have the api yet.
59
+
60
+
61
+ **New in v1.6**
62
+
63
+ - Made the plugin PHP 4 compatible. Guys try it out and please let me know if that worked.
64
+ - 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.
65
+ - 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.
66
+
67
+
68
+ **New in v1.7**
69
+
70
+ - Removed api option from 1click.at not needed api key
71
+
72
+
73
+ **New in v1.8**
74
+
75
+ - Bug Fixes
76
+ - Provision to fetch tweet url from custom field
77
+
78
+
79
+ **New in v1.9**
80
+
81
+ - Removed PHP 4 support as it was creating problem for lot of people
82
+
83
+
84
+ **New in v2.0**
85
+
86
+ - added provision to select if you want to shorten the URL or not.
87
+ - Cleaned other options.
88
+
89
+
90
+ **New in v3.0**
91
+
92
+ - added OAuth authentication
93
+ - user defined intervals
94
+ - may not work under php 4 requires php 5
95
+
96
+ == Installation ==
97
+
98
+ Following are the steps to install the Tweet Old Post plugin
99
+
100
+ 1. Download the latest version of the Tweet Old Posts Plugin to your computer from here.
101
+ 2. With an FTP program, access your site�s server.
102
+ 3. Upload (copy) the Plugin file(s) or folder to the /wp-content/plugins folder.
103
+ 4. In your WordPress Administration Panels, click on Plugins from the menu.
104
+ 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.
105
+ 6. To turn the Tweet Old Posts Plugin on, click Activate.
106
+ 7. Check your Administration Panels or WordPress blog to see if the Plugin is working.
107
+ 8. You can change the plugin options from Tweet Old Posts under settings menu.
108
+
109
+ Alternatively you can also follow the following steps to install the Tweet Old Post plugin
110
+
111
+ 1. In your WordPress Administration Panels, click on Add New option under Plugins from the menu.
112
+ 2. Click on upload at the top.
113
+ 3. Browse the location and select the Tweet Old Post Plugin and click install now.
114
+ 4. To turn the Tweet Old Posts Plugin on, click Activate.
115
+ 5. Check your Administration Panels or WordPress blog to see if the Plugin is working.
116
+ 6. You can change the plugin options from Tweet Old Posts under settings menu.
117
+
118
+ == Frequently Asked Questions ==
119
+
120
+ If you have any questions please mail me at,
121
+ ajay@ajaymatharu.com or matharuajay@yahoo.co.in
122
+
123
+ **Tweet Old post does not posts any tweets?**
124
+
125
+ - If its not tweeting any tweets try playing around with the options. Try setting maxtweetage to none and try again.
126
+
127
+
128
+ **Tweet old post giving SimpleXmlElement error?**
129
+
130
+ - If it is giving SimpleXmlElement error, check with your hosting provider on which version of PHP are they supporting.
131
+ Tweet Old Post supports PHP 5 onwards. It will give SimpleXmlElement error if your hosting provider supports PHP 4
132
+ or PHP less than 5
133
+
134
+ **Update**
135
+
136
+ Tweet Old Post v1.6 supports PHP 4 as well.
137
+
138
+ == Screenshots ==
139
+
140
+ for screenshots you can check out
141
+
142
+ http://www.ajaymatharu.com/wordpress-plugin-tweet-old-posts/
143
+
144
+ == Changelog ==
145
+
146
+
147
+ **v1.2**
148
+
149
+ Tweet Prefix - Allows you to set prefix to the tweets.
150
+
151
+ Add Data - Allows you to add post data to the tweets.
152
+
153
+ Tweet now - Button that will tweet at that moment without wanting you to wait for scheduled tweet.
154
+
155
+
156
+
157
+ **v1.3**
158
+
159
+ URL Shortener Service - allows you to select which URL shortener service you want to use.
160
+
161
+
162
+ **v1.4**
163
+
164
+ Hashtags - allows you to set default hashtags for your tweets
165
+
166
+
167
+ **v1.5**
168
+
169
+ Maximum age of post to be eligible for tweet - allows you to set Maximum age of the post to be eligible for tweet
170
+
171
+ Added one more shortner service was looking for j.mp but they dont have the api yet.
172
+
173
+
174
+ **v1.6**
175
+
176
+ - Made the plugin PHP 4 compatible. Guys try it out and please let me know if that worked.
177
+ - 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.
178
+ - 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.
179
+
180
+
181
+ **v1.7**
182
+
183
+ - Removed api option from 1click.at not needed api key
184
+
185
+
186
+ **v1.8**
187
+
188
+ - Bug Fixes
189
+ - Provision to fetch tweet url from custom field
190
+
191
+
192
+ **v1.9**
193
+
194
+ - Removed PHP 4 support as it was creating problem for lot of people
195
+
196
+
197
+ **v2.0**
198
+
199
+ - added provision to select if you want to shorten the URL or not.
200
+ - Cleaned other options.
201
+
202
+
203
+ **v3.0**
204
+
205
+ - added OAuth authentication
206
+ - user defined intervals
207
+ - may not work under php 4 requires php 5
208
+
209
+ == Other Notes ==
210
+
211
+ Some of the options you can configure for the Tweet Old Posts plugins are,
212
+
213
+ **v1.1**
214
+
215
+ Twitter Username & Password - Using this twitter account credentials plugin will tweet.
216
+
217
+ Minimum interval between tweets - allows you to determine how often the plugin will automatically choose and tweet a blog post for you.
218
+
219
+ Randomness interval - This is a contributing factor in minimum interval so that posts are randomly chosen and tweeted from your blog.
220
+
221
+ 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.
222
+
223
+ Categories to omit from tweets - This will protect posts from the selected categories from being tweeted.
224
+
225
+
226
+ **v1.2**
227
+
228
+ Tweet Prefix - Allows you to set prefix to the tweets.
229
+
230
+ Add Data - Allows you to add post data to the tweets.
231
+
232
+ Tweet now - Button that will tweet at that moment without wanting you to wait for scheduled tweet.
233
+
234
+
235
+ **v1.3**
236
+
237
+ URL Shortener Service - allows you to select which URL shortener service you want to use.
238
+
239
+
240
+ **v1.4**
241
+
242
+ Hashtags - allows you to set default hashtags for your tweets
243
+
244
+
245
+ **v1.5**
246
+
247
+ Maximum age of post to be eligible for tweet - allows you to set Maximum age of the post to be eligible for tweet
248
+
249
+ Added one more shortner service was looking for j.mp but they dont have the api yet.
250
+
251
+
252
+ **v1.6**
253
+
254
+ - Made the plugin PHP 4 compatible. Guys try it out and please let me know if that worked.
255
+ - 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.
256
+ - 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.
257
+
258
+
259
+ **v1.7**
260
+
261
+ - Removed api option from 1click.at not needed api key
262
+
263
+
264
+ **v1.8**
265
+
266
+ - Bug Fixes
267
+ - Provision to fetch tweet url from custom field
268
+
269
+
270
+ **v1.9**
271
+
272
+ - Removed PHP 4 support as it was creating problem for lot of people
273
+
274
+
275
+ **v2.0**
276
+
277
+ - added provision to select if you want to shorten the URL or not.
278
+ - Cleaned other options.
279
+
280
+
281
+ **v3.0**
282
+
283
+ - added OAuth authentication
284
+ - user defined intervals
285
+ - may not work under php 4 requires php 5
top-admin.php ADDED
@@ -0,0 +1,528 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once('tweet-old-post.php');
3
+ require_once('top-core.php');
4
+ require_once( 'Include/oauth.php' );
5
+ require_once('xml.php');
6
+ function top_admin() {
7
+ if ( current_user_can('manage_options') ) {
8
+ $message = null;
9
+ $message_updated = __("Tweet Old Post Options Updated.", 'TweetOldPost');
10
+ $response=null;
11
+ $save=true;
12
+ $settings = top_get_settings();
13
+ if ( isset( $_GET['TOP_oauth'] ) ) {
14
+ global $top_oauth;
15
+
16
+
17
+ $result = $top_oauth->get_access_token( $settings['oauth_request_token'], $settings['oauth_request_token_secret'], $_GET['oauth_verifier'] );
18
+
19
+ if ( $result ) {
20
+ $settings['oauth_access_token'] = $result['oauth_token'];
21
+ $settings['oauth_access_token_secret'] = $result['oauth_token_secret'];
22
+ $settings['user_id'] = $result['user_id'];
23
+
24
+ $result = $top_oauth->get_user_info( $result['user_id'] );
25
+ if ( $result ) {
26
+ $settings['profile_image_url'] = $result['user']['profile_image_url'];
27
+ $settings['screen_name'] = $result['user']['screen_name'];
28
+ if ( isset( $result['user']['location'] ) ) {
29
+ $settings['location'] = $result['user']['location'];
30
+ } else {
31
+ $settings['location'] = false;
32
+ }
33
+ }
34
+
35
+ top_save_settings( $settings );
36
+ echo '<script language="javascript">window.open ("'.get_bloginfo('wpurl') . '/wp-admin/options-general.php?page=TweetOldPost","_self")</script>';
37
+ //header( 'Location: ' . get_bloginfo('wpurl') . '/wp-admin/options-general.php?page=TweetOldPost' );
38
+ die;
39
+ }
40
+ } else if ( isset( $_GET['top'] ) && $_GET['top'] == 'deauthorize' ) {
41
+ $settings = top_get_settings();
42
+ $settings['oauth_access_token'] = '';
43
+ $settings['oauth_access_token_secret'] = '';
44
+ $settings['user_id'] = '';
45
+ $settings['tweet_queue'] = array();
46
+
47
+ top_save_settings( $settings );
48
+ echo '<script language="javascript">window.open ("'.get_bloginfo('wpurl') . '/wp-admin/options-general.php?page=TweetOldPost","_self")</script>';
49
+ //header( 'Location: ' . get_bloginfo('wpurl') . '/wp-admin/options-general.php?page=TweetOldPost' );
50
+ die;
51
+ }
52
+
53
+ if(isset($_POST['top_opt_url_shortener']))
54
+ {
55
+ if($_POST['top_opt_url_shortener']=="bit.ly")
56
+ {
57
+
58
+ if(!isset($_POST['top_opt_bitly_user']))
59
+ {
60
+ print('
61
+ <div id="message" class="updated fade">
62
+ <p>'.__('Please enter bit.ly username.', 'TweetOldPost').'</p>
63
+ </div>');
64
+ $save=false;
65
+ }
66
+ elseif(!isset($_POST['top_opt_bitly_key']))
67
+ {
68
+ print('
69
+ <div id="message" class="updated fade">
70
+ <p>'.__('Please enter bit.ly API Key.', 'TweetOldPost').'</p>
71
+ </div>');
72
+ $save=false;
73
+ }
74
+ else
75
+ {
76
+ $save=true;
77
+ }
78
+
79
+ }
80
+
81
+ }
82
+
83
+ if (isset($_POST['submit']) && $save ) {
84
+ $message = $message_updated;
85
+
86
+ if (isset($_POST['top_opt_interval'])) {
87
+ update_option('top_opt_interval',$_POST['top_opt_interval']);
88
+ }
89
+ if (isset($_POST['top_opt_interval_slop'])) {
90
+ update_option('top_opt_interval_slop',$_POST['top_opt_interval_slop']);
91
+ }
92
+ if (isset($_POST['top_opt_age_limit'])) {
93
+ update_option('top_opt_age_limit',$_POST['top_opt_age_limit']);
94
+ }
95
+ if (isset($_POST['top_opt_max_age_limit'])) {
96
+ update_option('top_opt_max_age_limit',$_POST['top_opt_max_age_limit']);
97
+ }
98
+ if (isset($_POST['top_opt_tweet_prefix'])) {
99
+ update_option('top_opt_tweet_prefix',$_POST['top_opt_tweet_prefix']);
100
+ }
101
+ if (isset($_POST['top_opt_add_data'])) {
102
+ update_option('top_opt_add_data',$_POST['top_opt_add_data']);
103
+ }
104
+ if (isset($_POST['post_category'])) {
105
+ update_option('top_opt_omit_cats',implode(',',$_POST['post_category']));
106
+ }
107
+ else {
108
+ update_option('top_opt_omit_cats','');
109
+ }
110
+
111
+
112
+ if (isset($_POST['top_opt_custom_url_option'])) {
113
+ update_option('top_opt_custom_url_option',true);
114
+
115
+ }
116
+ else {
117
+
118
+ update_option('top_opt_custom_url_option',false);
119
+ }
120
+
121
+ if (isset($_POST['top_opt_custom_url_field'])) {
122
+ update_option('top_opt_custom_url_field',$_POST['top_opt_custom_url_field']);
123
+ }
124
+ else {
125
+
126
+ update_option('top_opt_custom_url_field','');
127
+ }
128
+
129
+ if (isset($_POST['top_opt_use_url_shortner'])) {
130
+ update_option('top_opt_use_url_shortner',true);
131
+ }
132
+ else {
133
+
134
+ update_option('top_opt_use_url_shortner',false);
135
+ }
136
+
137
+ if (isset($_POST['top_opt_hashtags'])) {
138
+ update_option('top_opt_hashtags',$_POST['top_opt_hashtags']);
139
+ }
140
+ else {
141
+ update_option('top_opt_hashtags','');
142
+ }
143
+
144
+ if(isset($_POST['top_opt_url_shortener']))
145
+ {
146
+ update_option('top_opt_url_shortener',$_POST['top_opt_url_shortener']);
147
+ if($_POST['top_opt_url_shortener']=="bit.ly")
148
+ {
149
+ if(isset($_POST['top_opt_bitly_user']))
150
+ {
151
+ update_option('top_opt_bitly_user',$_POST['top_opt_bitly_user']);
152
+ }
153
+ if(isset($_POST['top_opt_bitly_key']))
154
+ {
155
+ update_option('top_opt_bitly_key',$_POST['top_opt_bitly_key']);
156
+ }
157
+ }
158
+
159
+ }
160
+ print('
161
+ <div id="message" class="updated fade">
162
+ <p>'.__('Tweet Old Post Options Updated.', 'TweetOldPost').'</p>
163
+ </div>');
164
+ }
165
+ elseif (isset($_POST['tweet']))
166
+ {
167
+ $tweet_msg = top_opt_tweet_old_post();
168
+ print('
169
+ <div id="message" class="updated fade">
170
+ <p>'.__($tweet_msg, 'TweetOldPost').'</p>
171
+ </div>');
172
+ }
173
+ $omitCats = get_option('top_opt_omit_cats');
174
+ if (!isset($omitCats)) {
175
+ $omitCats = top_opt_OMIT_CATS;
176
+ }
177
+ $ageLimit = get_option('top_opt_age_limit');
178
+ if (!(isset($ageLimit) && is_numeric($ageLimit))) {
179
+ $ageLimit = top_opt_AGE_LIMIT;
180
+ }
181
+
182
+ $maxAgeLimit = get_option('top_opt_max_age_limit');
183
+ if (!(isset($maxAgeLimit) && is_numeric($maxAgeLimit))) {
184
+ $maxAgeLimit = top_opt_MAX_AGE_LIMIT;
185
+ }
186
+
187
+ $interval = get_option('top_opt_interval');
188
+ if (!(isset($interval) && is_numeric($interval))) {
189
+ $interval = top_opt_INTERVAL;
190
+ }
191
+ $slop = get_option('top_opt_interval_slop');
192
+ if (!(isset($slop) && is_numeric($slop))) {
193
+ $slop = top_opt_INTERVAL_SLOP;
194
+ }
195
+ $tweet_prefix = get_option('top_opt_tweet_prefix');
196
+ if(!isset($tweet_prefix)){
197
+ $tweet_prefix = top_opt_TWEET_PREFIX;
198
+ }
199
+ $url_shortener=get_option('top_opt_url_shortener');
200
+ if(!isset($url_shortener)){
201
+ $url_shortener=top_opt_URL_SHORTENER;
202
+ }
203
+
204
+
205
+ $twitter_hashtags=get_option('top_opt_hashtags');
206
+ if(!isset($twitter_hashtags)){
207
+ $twitter_hashtags=top_opt_HASHTAGS;
208
+ }
209
+
210
+ $bitly_api=get_option('top_opt_bitly_key');
211
+ if(!isset($bitly_api)){
212
+ $bitly_api="";
213
+ }
214
+ $bitly_username=get_option('top_opt_bitly_user');
215
+ if(!isset($bitly_username)){
216
+ $bitly_username="";
217
+ }
218
+
219
+ $custom_url_option=get_option('top_opt_custom_url_option');
220
+
221
+ if(!isset($custom_url_option)){
222
+ $custom_url_option="";
223
+ }
224
+ elseif ($custom_url_option)
225
+ $custom_url_option="checked";
226
+ else
227
+ $custom_url_option="";
228
+
229
+ $custom_url_field=get_option('top_opt_custom_url_field');
230
+ if(!isset($custom_url_field)){
231
+ $custom_url_field="";
232
+ }
233
+
234
+ $use_url_shortner=get_option('top_opt_use_url_shortner');
235
+ if(!isset($use_url_shortner)){
236
+ $use_url_shortner="";
237
+ }
238
+ elseif($use_url_shortner)
239
+ $use_url_shortner="checked";
240
+ else
241
+ $use_url_shortner="";
242
+ $add_data = get_option('top_opt_add_data');
243
+ $twitter_username = get_option('top_opt_twitter_username');
244
+ $twitter_password = get_option('top_opt_twitter_password');
245
+
246
+ print('
247
+ <div class="wrap">
248
+ <h2>'.__('Tweet old post by - ', 'TweetOldPost').' <a href="http://www.ajaymatharu.com">Ajay Matharu</a></h2>
249
+ <form id="top_opt" name="top_TweetOldPost" action="'.get_bloginfo('wpurl').'/wp-admin/options-general.php?page=TweetOldPost" method="post">
250
+ <input type="hidden" name="top_opt_action" value="top_opt_update_settings" />
251
+ <fieldset class="options">
252
+ <div class="option">
253
+ <label for="top_opt_twitter_username">'.__('Account Login', 'TweetOldPost').':</label>
254
+
255
+ <div id="profile-box">');
256
+ if ( !$settings["oauth_access_token"] ) {
257
+ echo '<a href="'. top_get_auth_url() .'"><img src="http://apiwiki.twitter.com/f/1242697607/Sign-in-with-Twitter-lighter-small.png" /></a>';
258
+ } else {
259
+ echo '<img class="avatar" src="'. $settings["profile_image_url"] .'" alt="" />
260
+ <h4>'. $settings["screen_name"] .'</h4>';
261
+ if ( $settings["location"] ) {
262
+ echo '<h5>'. $settings["location"].'</h5>';
263
+ }
264
+ echo '<p>
265
+
266
+ 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 />
267
+
268
+ </p>
269
+
270
+ <div class="retweet-clear"></div>
271
+ '; }
272
+ print('</div>
273
+ </div>
274
+
275
+ <div class="option">
276
+ <label for="top_opt_tweet_prefix">'.__('Tweet Prefix', 'TweetOldPost').':</label>
277
+ <input type="text" size="25" name="top_opt_tweet_prefix" id="top_opt_tweet_prefix" value="'.$tweet_prefix.'" autocomplete="off" />
278
+ <b>If set, it will show as: "{tweet prefix}: {post title}... {url}</b>
279
+ </div>
280
+ <div class="option">
281
+ <label for="top_opt_add_data">'.__('Add post data to tweet', 'TweetOldPost').':</label>
282
+ <select id="top_opt_add_data" name="top_opt_add_data" style="width:100px;">
283
+ <option value="false" '.top_opt_optionselected("false",$add_data).'>'.__(' No ', 'TweetOldPost').'</option>
284
+ <option value="true" '.top_opt_optionselected("true",$add_data).'>'.__(' Yes ', 'TweetOldPost').'</option>
285
+ </select>
286
+ <b>If set, it will show as: "{tweet prefix}: {post title}- {content}... {url}</b>
287
+ </div>
288
+
289
+ <div class="option">
290
+ <label for="top_opt_custom_url_option">'.__('Fetch URL from custom field', 'TweetOldPost').':</label>
291
+ <input onchange="return showCustomField();" type="checkbox" name="top_opt_custom_url_option" '.$custom_url_option.' id="top_opt_custom_url_option" />
292
+ <b>If checked URL will be fetched from custom field. If not plugin will generate shortened URL from post link.</b>
293
+ </div>
294
+
295
+
296
+
297
+ <div id="customurl" style="display:none;">
298
+ <div class="option">
299
+ <label for="top_opt_custom_url_field">'.__('Custom field name to fetch URL to be tweeted with post', 'TweetOldPost').':</label>
300
+ <input type="text" size="25" name="top_opt_custom_url_field" id="top_opt_custom_url_field" value="'.$custom_url_field.'" autocomplete="off" />
301
+ <b>If set this will fetch the URL from specified custom field</b>
302
+ </div>
303
+
304
+ </div>
305
+
306
+ <div class="option">
307
+ <label for="top_opt_use_url_shortner">'.__('Use URL shortner?', 'TweetOldPost').':</label>
308
+ <input onchange="return showshortener()" type="checkbox" name="top_opt_use_url_shortner" id="top_opt_use_url_shortner" '.$use_url_shortner.' />
309
+
310
+ </div>
311
+
312
+ <div id="urlshortener">
313
+ <div class="option">
314
+ <label for="top_opt_url_shortener">'.__('URL Shortener Service', 'TweetOldPost').':</label>
315
+ <select name="top_opt_url_shortener" id="top_opt_url_shortener" onchange="javascript:showURLAPI()" style="width:100px;">
316
+ <option value="is.gd" '.top_opt_optionselected('is.gd',$url_shortener).'>'.__('is.gd', 'TweetOldPost').'</option>
317
+ <option value="su.pr" '.top_opt_optionselected('su.pr',$url_shortener).'>'.__('su.pr', 'TweetOldPost').'</option>
318
+ <option value="bit.ly" '.top_opt_optionselected('bit.ly',$url_shortener).'>'.__('bit.ly', 'TweetOldPost').'</option>
319
+ <option value="tr.im" '.top_opt_optionselected('tr.im',$url_shortener).'>'.__('tr.im', 'TweetOldPost').'</option>
320
+ <option value="3.ly" '.top_opt_optionselected('3.ly',$url_shortener).'>'.__('3.ly', 'TweetOldPost').'</option>
321
+ <option value="u.nu" '.top_opt_optionselected('u.nu',$url_shortener).'>'.__('u.nu', 'TweetOldPost').'</option>
322
+ <option value="1click.at" '.top_opt_optionselected('1click.at',$url_shortener).'>'.__('1click.at', 'TweetOldPost').'</option>
323
+ <option value="tinyurl" '.top_opt_optionselected('tinyurl',$url_shortener).'>'.__('tinyurl', 'TweetOldPost').'</option>
324
+ </select>
325
+ </div>
326
+ <div id="showDetail" style="display:none">
327
+ <div class="option">
328
+ <label for="top_opt_bitly_user">'.__('bit.ly Username', 'TweetOldPost').':</label>
329
+ <input type="text" size="25" name="top_opt_bitly_user" id="top_opt_bitly_user" value="'.$bitly_username.'" autocomplete="off" />
330
+ </div>
331
+
332
+ <div class="option">
333
+ <label for="top_opt_bitly_key">'.__('bit.ly API Key', 'TweetOldPost').':</label>
334
+ <input type="text" size="25" name="top_opt_bitly_key" id="top_opt_bitly_key" value="'.$bitly_api.'" autocomplete="off" />
335
+ </div>
336
+ </div>
337
+ </div>
338
+
339
+
340
+ <div class="option">
341
+ <label for="top_opt_hashtags">'.__('Default #hashtags for your tweets', 'TweetOldPost').':</label>
342
+ <input type="text" size="25" name="top_opt_hashtags" id="top_opt_hashtags" value="'.$twitter_hashtags.'" autocomplete="off" />
343
+ <b>Include #, like #thoughts</b>
344
+ </div>
345
+
346
+ <div class="option">
347
+ <label for="top_opt_interval">'.__('Minimum interval between tweets: ', 'TweetOldPost').'</label>
348
+ <input type="text" id="top_opt_interval" maxlength="5" value="' . $interval .'" name="top_opt_interval" /> Hour / Hours
349
+
350
+ </div>
351
+ <div class="option">
352
+ <label for="top_opt_interval_slop">'.__('Random Interval (added to minimum interval): ', 'TweetOldPost').'</label>
353
+ <input type="text" id="top_opt_interval_slop" maxlength="5" value="' . $slop .'" name="top_opt_interval_slop" /> Hour / Hours
354
+
355
+ </div>
356
+ <div class="option">
357
+ <label for="top_opt_age_limit">'.__('Minimum age of post to be eligible for tweet: ', 'TweetOldPost').'</label>
358
+ <input type="text" id="top_opt_age_limit" maxlength="5" value="' . $ageLimit .'" name="top_opt_age_limit" /> Day / Days
359
+ <b> (enter 0 for today)</b>
360
+
361
+ </div>
362
+
363
+ <div class="option">
364
+ <label for="top_opt_max_age_limit">'.__('Maximum age of post to be eligible for tweet: ', 'TweetOldPost').'</label>
365
+ <input type="text" id="top_opt_max_age_limit" maxlength="5" value="' . $maxAgeLimit .'" name="top_opt_max_age_limit" /> Day / Days
366
+ <b>(If you dont want to use this option enter 0 or leave blank)</b><br/>
367
+ <b>If set, it will fetch posts which are "NOT" older than specified day / days</b>
368
+ </div>
369
+
370
+ <div class="option category">
371
+ <div style="float:left">
372
+ <label class="catlabel">'.__('Categories to Omit from tweets: ', 'TweetOldPost').'</label> </div>
373
+ <div style="float:left">
374
+ <ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
375
+ ');
376
+ wp_category_checklist(0, 0, explode(',',$omitCats));
377
+ print(' </ul>
378
+ </div>
379
+ </div>
380
+ </fieldset>
381
+ <p class="submit">
382
+ <input type="submit" name="submit" onclick="javascript:return validate()" value="'.__('Update Tweet Old Post Options', 'TweetOldPost').'" />
383
+ <input type="submit" name="tweet" value="'.__('Tweet Now', 'TweetOldPost').'" />
384
+ </p>
385
+
386
+ </form><script language="javascript" type="text/javascript">
387
+ function showURLAPI()
388
+ {
389
+ var urlShortener=document.getElementById("top_opt_url_shortener").value;
390
+ if(urlShortener=="bit.ly")
391
+ {
392
+ document.getElementById("showDetail").style.display="block";
393
+
394
+ }
395
+ else
396
+ {
397
+ document.getElementById("showDetail").style.display="none";
398
+
399
+ }
400
+
401
+ }
402
+
403
+ function validate()
404
+ {
405
+
406
+ if(document.getElementById("showDetail").style.display=="block" && document.getElementById("top_opt_url_shortener").value=="bit.ly")
407
+ {
408
+ if(trim(document.getElementById("top_opt_bitly_user").value)=="")
409
+ {
410
+ alert("Please enter bit.ly username.");
411
+ document.getElementById("top_opt_bitly_user").focus();
412
+ return false;
413
+ }
414
+
415
+ if(trim(document.getElementById("top_opt_bitly_key").value)=="")
416
+ {
417
+ alert("Please enter bit.ly API key.");
418
+ document.getElementById("top_opt_bitly_key").focus();
419
+ return false;
420
+ }
421
+ }
422
+ if(trim(document.getElementById("top_opt_interval").value) != "" && !isNumber(trim(document.getElementById("top_opt_interval").value)))
423
+ {
424
+ alert("Enter only numeric in Minimum interval between tweet");
425
+ document.getElementById("top_opt_interval").focus();
426
+ return false;
427
+ }
428
+ if(trim(document.getElementById("top_opt_interval_slop").value) != "" && !isNumber(trim(document.getElementById("top_opt_interval_slop").value)))
429
+ {
430
+ alert("Enter only numeric in Random interval");
431
+ document.getElementById("top_opt_interval_slop").focus();
432
+ return false;
433
+ }
434
+ if(trim(document.getElementById("top_opt_age_limit").value) != "" && !isNumber(trim(document.getElementById("top_opt_age_limit").value)))
435
+ {
436
+ alert("Enter only numeric in Minimum age of post");
437
+ document.getElementById("top_opt_age_limit").focus();
438
+ return false;
439
+ }
440
+ if(trim(document.getElementById("top_opt_max_age_limit").value) != "" && !isNumber(trim(document.getElementById("top_opt_max_age_limit").value)))
441
+ {
442
+ alert("Enter only numeric in Maximum age of post");
443
+ document.getElementById("top_opt_max_age_limit").focus();
444
+ return false;
445
+ }
446
+ if(trim(document.getElementById("top_opt_max_age_limit").value) != "")
447
+ {
448
+ if(eval(document.getElementById("top_opt_age_limit").value) > eval(document.getElementById("top_opt_max_age_limit").value))
449
+ {
450
+ alert("Post max age limit cannot be less than Post min age iimit");
451
+ document.getElementById("top_opt_age_limit").focus();
452
+ return false;
453
+ }
454
+ }
455
+ }
456
+
457
+ function trim(stringToTrim) {
458
+ return stringToTrim.replace(/^\s+|\s+$/g,"");
459
+ }
460
+
461
+ function showCustomField()
462
+ {
463
+ if(document.getElementById("top_opt_custom_url_option").checked)
464
+ {
465
+ document.getElementById("customurl").style.display="block";
466
+ }
467
+ else
468
+ {
469
+ document.getElementById("customurl").style.display="none";
470
+ }
471
+ }
472
+
473
+ function isNumber(val)
474
+ {
475
+ if(isNaN(val)){
476
+ return false;
477
+ }
478
+ else{
479
+ return true;
480
+ }
481
+ }
482
+
483
+ function showshortener()
484
+ {
485
+
486
+
487
+ if((document.getElementById("top_opt_use_url_shortner").checked))
488
+ {
489
+ document.getElementById("urlshortener").style.display="block";
490
+ }
491
+ else
492
+ {
493
+ document.getElementById("urlshortener").style.display="none";
494
+ }
495
+ }
496
+ showURLAPI();
497
+ showshortener();
498
+ showCustomField();
499
+ </script>' );
500
+
501
+ }
502
+ else
503
+ {
504
+ print('
505
+ <div id="message" class="updated fade">
506
+ <p>'.__('You do not have enough permission to set the option. Please contact your admin.', 'TweetOldPost').'</p>
507
+ </div>');
508
+ }
509
+ }
510
+
511
+ function top_opt_optionselected($opValue, $value) {
512
+ if($opValue==$value) {
513
+ return 'selected="selected"';
514
+ }
515
+ return '';
516
+ }
517
+
518
+ function top_opt_head_admin()
519
+ {
520
+ $home = get_settings('siteurl');
521
+ $base = '/'.end(explode('/', str_replace(array('\\','/top-admin.php'),array('/',''),__FILE__)));
522
+ $stylesheet = $home.'/wp-content/plugins' . $base . '/css/tweet-old-post.css';
523
+ echo('<link rel="stylesheet" href="' . $stylesheet . '" type="text/css" media="screen" />');
524
+ }
525
+
526
+
527
+
528
+ ?>
top-core.php ADDED
@@ -0,0 +1,343 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once( 'Include/oauth.php' );
3
+ global $top_oauth;
4
+ $top_oauth = new TOPOAuth;
5
+
6
+ function top_tweet_old_post()
7
+ {
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
+ //get random post and tweet
16
+ function top_opt_tweet_old_post()
17
+ {
18
+ global $wpdb;
19
+ $omitCats = get_option('top_opt_omit_cats');
20
+ $maxAgeLimit = get_option('top_opt_max_age_limit');
21
+ $ageLimit = get_option('top_opt_age_limit');
22
+ if (!(isset($ageLimit) && is_numeric($ageLimit))) {
23
+ $ageLimit = top_opt_AGE_LIMIT;
24
+ }
25
+
26
+ if (!(isset($maxAgeLimit) && is_numeric($maxAgeLimit))) {
27
+ $maxAgeLimit = top_opt_MAX_AGE_LIMIT;
28
+ }
29
+ if (!isset($omitCats)) {
30
+ $omitCats = top_opt_OMIT_CATS;
31
+ }
32
+
33
+ $sql = "SELECT ID
34
+ FROM $wpdb->posts
35
+ WHERE post_type = 'post'
36
+ AND post_status = 'publish'
37
+ AND post_date <= curdate( ) - INTERVAL ".$ageLimit. " day";
38
+
39
+ if($maxAgeLimit != 0)
40
+ {
41
+ $sql = $sql." AND post_date >= curdate( ) - INTERVAL ".$maxAgeLimit." day";
42
+ }
43
+
44
+ if ($omitCats!='') {
45
+ $sql = $sql." AND NOT(ID IN (SELECT tr.object_id
46
+ FROM $wpdb->terms t
47
+ inner join $wpdb->term_taxonomy tax on t.term_id=tax.term_id and tax.taxonomy='category'
48
+ inner join $wpdb->term_relationships tr on tr.term_taxonomy_id=tax.term_taxonomy_id
49
+ WHERE t.term_id IN (".$omitCats.")))";
50
+ }
51
+ $sql = $sql."
52
+ ORDER BY RAND()
53
+ LIMIT 1 ";
54
+
55
+ $oldest_post = $wpdb->get_var($sql);
56
+ if (isset($oldest_post)) {
57
+ return top_opt_tweet_post($oldest_post);
58
+ }
59
+ }
60
+
61
+
62
+ //tweet for the passed random post
63
+ function top_opt_tweet_post($oldest_post)
64
+ {
65
+ $post = get_post($oldest_post);
66
+ $content=null;
67
+ $permalink = get_permalink($oldest_post);
68
+ $add_data = get_option("top_opt_add_data");
69
+ $twitter_hashtags = get_option('top_opt_hashtags');
70
+ $url_shortener=get_option('top_opt_url_shortener');
71
+ $to_short_url=true;
72
+
73
+ $custom_url_option=get_option('top_opt_custom_url_option');
74
+ $to_short_url = get_option('top_opt_use_url_shortner');
75
+
76
+ if($custom_url_option)
77
+ {
78
+ $custom_url_field = get_option('top_opt_custom_url_field');
79
+ if(trim($custom_url_field) != "")
80
+ {
81
+ $permalink = trim(get_post_meta($post->ID, $custom_url_field, true));
82
+ }
83
+ }
84
+
85
+ if($to_short_url)
86
+ {
87
+
88
+ if($url_shortener=="bit.ly")
89
+ {
90
+ $bitly_key=get_option('top_opt_bitly_key');
91
+ $bitly_user=get_option('top_opt_bitly_user');
92
+ $shorturl=shorten_url($permalink,$url_shortener,$bitly_key,$bitly_user);
93
+ }
94
+ else
95
+ {
96
+ $shorturl = shorten_url($permalink,$url_shortener);
97
+ }
98
+ }
99
+ else
100
+ {
101
+ $shorturl = $permalink;
102
+ }
103
+ $prefix=get_option('top_opt_tweet_prefix');
104
+
105
+ if($add_data == "true")
106
+ {
107
+ $content = stripslashes($post->post_content);
108
+ $content = strip_tags($content);
109
+ $content = preg_replace('/\s\s+/', ' ', $content);
110
+ $content = " - ".$content;
111
+ }
112
+ else {
113
+ $content="";
114
+ }
115
+
116
+
117
+ if(!is_numeric($shorturl) && (strncmp($shorturl, "http", strlen("http")) == 0))
118
+ {
119
+ if($prefix)
120
+ {
121
+ $message = $prefix.": ".$post->post_title;
122
+ }
123
+ else {
124
+ $message = $post->post_title;
125
+ }
126
+
127
+ $message = set_tweet_length($message.$content,$shorturl,$twitter_hashtags);
128
+
129
+ $username = get_option('top_opt_twitter_username');
130
+ $password = get_option('top_opt_twitter_password');
131
+
132
+
133
+ $status = urlencode(stripslashes(urldecode($message)));
134
+
135
+ if ($status) {
136
+ /*$tweetUrl = 'http://www.twitter.com/statuses/update.xml';
137
+
138
+ $curl = curl_init();
139
+ curl_setopt($curl, CURLOPT_URL, "$tweetUrl");
140
+ curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2);
141
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
142
+ curl_setopt($curl, CURLOPT_POST, 1);
143
+ curl_setopt($curl, CURLOPT_POSTFIELDS, "status=$status&source=TweetOldPost");
144
+ curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
145
+
146
+ $result = curl_exec($curl);
147
+ $resultArray = curl_getinfo($curl);
148
+ $httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
149
+ curl_close($curl);*/
150
+ $poststatus= top_update_status($message);
151
+
152
+ if($poststatus == true)
153
+ return "Whoopie!!! Tweet Posted Successfully";
154
+ else
155
+ return "OOPS!!! there seems to be some problem while tweeting. Tweet request returned error code " . $httpcode . ".";
156
+ }
157
+ return "OOPS!!! there seems to be some problem while tweeting. Try again. If problem is persistent mail the problem at ajay@ajaymatharu.com";
158
+ }
159
+ return "OOPS!!! problem with your URL shortning service. Some signs of error " . $shorturl . ".";
160
+ }
161
+
162
+ //send request to passed url and return the response
163
+ function send_request($url, $method='GET', $data='', $auth_user='', $auth_pass='') {
164
+ $ch = curl_init($url);
165
+ if (strtoupper($method)=="POST") {
166
+ curl_setopt($ch, CURLOPT_POST, 1);
167
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
168
+ }
169
+ if (ini_get('open_basedir') == '' && ini_get('safe_mode') == 'Off'){
170
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
171
+ }
172
+ curl_setopt($ch, CURLOPT_HEADER, 0);
173
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
174
+ if ($auth_user != '' && $auth_pass != '') {
175
+ curl_setopt($ch, CURLOPT_USERPWD, "{$auth_user}:{$auth_pass}");
176
+ }
177
+ $response = curl_exec($ch);
178
+ $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
179
+ curl_close($ch);
180
+ if ($httpcode != 200) {
181
+ return $httpcode;
182
+ }
183
+
184
+ return $response;
185
+
186
+ }
187
+
188
+
189
+ //Shorten long URLs with is.gd or bit.ly.
190
+ function shorten_url($the_url, $shortener='is.gd', $api_key='', $user='') {
191
+
192
+ if (($shortener=="bit.ly") && isset($api_key) && isset($user)) {
193
+ $url = "http://api.bit.ly/shorten?version=2.0.1&longUrl={$the_url}&login={$user}&apiKey={$api_key}&format=xml";
194
+ $response = send_request($url, 'GET');
195
+
196
+ $the_results = new SimpleXmlElement($response);
197
+ if ($the_results->errorCode == '0') {
198
+ $response = $the_results->results->nodeKeyVal->shortUrl;
199
+ } else {
200
+ $response = "";
201
+ }
202
+
203
+ }elseif ($shortener=="su.pr") {
204
+ $url = "http://su.pr/api/simpleshorten?url={$the_url}";
205
+ $response = send_request($url, 'GET');
206
+ } elseif ($shortener=="tr.im") {
207
+ $url = "http://api.tr.im/api/trim_simple?url={$the_url}";
208
+ $response = send_request($url, 'GET');
209
+ } elseif ($shortener=="3.ly") {
210
+ $url = "http://3.ly/?api=em5893833&u={$the_url}";
211
+ $response = send_request($url, 'GET');
212
+ } elseif ($shortener=="tinyurl") {
213
+ $url = "http://tinyurl.com/api-create.php?url={$the_url}";
214
+ $response = send_request($url, 'GET');
215
+ }elseif ($shortener=="u.nu") {
216
+ $url = "http://u.nu/unu-api-simple?url={$the_url}";
217
+ $response = send_request($url, 'GET');
218
+ }elseif ($shortener=="1click.at") {
219
+ $url = "http://1click.at/api.php?action=shorturl&url={$the_url}&format=simple";
220
+ $response = send_request($url, 'GET');
221
+ } else {
222
+ $url = "http://is.gd/api.php?longurl={$the_url}";
223
+ $response = send_request($url, 'GET');
224
+ }
225
+
226
+ return $response;
227
+
228
+ }
229
+
230
+ //Shrink a tweet and accompanying URL down to 140 chars.
231
+ function set_tweet_length($message, $url, $twitter_hashtags="") {
232
+
233
+ $message_length = strlen($message);
234
+ $url_length = strlen($url);
235
+ $hashtags_length = strlen($twitter_hashtags);
236
+ if ($message_length + $url_length + $hashtags_length > 140) {
237
+ $shorten_message_to = 140 - $url_length - $hashtags_length;
238
+ $shorten_message_to = $shorten_message_to - 4;
239
+ //$message = $message." ";
240
+ $message = substr($message, 0, $shorten_message_to);
241
+ $message = substr($message, 0, strrpos($message,' '));
242
+ $message = $message."...";
243
+ }
244
+ return $message." ".$url." ".$twitter_hashtags;
245
+
246
+ }
247
+
248
+ //check time and update the last tweet time
249
+ function top_opt_update_time () {
250
+ $last = get_option('top_opt_last_update');
251
+ $interval = get_option('top_opt_interval');
252
+ $slop = get_option('top_opt_interval_slop');
253
+ if(is_numeric($interval)){$interval = $interval * 60 * 60;}
254
+ if(is_numeric($slop)){$slop = $slop * 60 * 60;}
255
+
256
+ if (!(isset($interval) && is_numeric($interval))) {
257
+ $interval = top_opt_INTERVAL;
258
+ }
259
+
260
+ if (!(isset($slop) && is_numeric($slop))) {
261
+ $slop = top_opt_INTERVAL_SLOP;
262
+ }
263
+ if (false === $last) {
264
+ $ret = 1;
265
+ } else if (is_numeric($last)) {
266
+ $ret = ( (time() - $last) > ($interval+rand(0,$slop)));
267
+ }
268
+ return $ret;
269
+ }
270
+
271
+ function top_get_auth_url() {
272
+ global $top_oauth;
273
+ $settings = top_get_settings();
274
+
275
+ $token = $top_oauth->get_request_token();
276
+ if ( $token ) {
277
+ $settings['oauth_request_token'] = $token['oauth_token'];
278
+ $settings['oauth_request_token_secret'] = $token['oauth_token_secret'];
279
+
280
+ top_save_settings( $settings );
281
+
282
+ return $top_oauth->get_auth_url( $token['oauth_token'] );
283
+ }
284
+
285
+ }
286
+
287
+
288
+ function top_update_status( $new_status ) {
289
+ global $top_oauth;
290
+ $settings = top_get_settings();
291
+
292
+ if ( isset( $settings['oauth_access_token'] ) && isset( $settings['oauth_access_token_secret'] ) ) {
293
+ return $top_oauth->update_status( $settings['oauth_access_token'], $settings['oauth_access_token_secret'], $new_status );
294
+ }
295
+
296
+ return false;
297
+ }
298
+
299
+ function top_has_tokens() {
300
+ $settings = top_get_settings();
301
+
302
+ return ( $settings[ 'oauth_access_token' ] && $settings['oauth_access_token_secret'] );
303
+ }
304
+
305
+ function top_is_valid() {
306
+ return twit_has_tokens();
307
+ }
308
+
309
+ function top_do_tweet( $post_id ) {
310
+ $settings = top_get_settings();
311
+
312
+ $message = top_get_message( $post_id );
313
+
314
+ // If we have a valid message, Tweet it
315
+ // this will fail if the Tiny URL service is done
316
+ if ( $message ) {
317
+ // If we successfully posted this to Twitter, then we can remove it from the queue eventually
318
+ if ( twit_update_status( $message ) ) {
319
+ return true;
320
+ }
321
+ }
322
+
323
+ return false;
324
+ }
325
+ function top_get_settings() {
326
+ global $top_defaults;
327
+
328
+ $settings = $top_defaults;
329
+
330
+ $wordpress_settings = get_option( 'top_settings' );
331
+ if ( $wordpress_settings ) {
332
+ foreach( $wordpress_settings as $key => $value ) {
333
+ $settings[ $key ] = $value;
334
+ }
335
+ }
336
+
337
+ return $settings;
338
+ }
339
+
340
+ function top_save_settings( $settings ) {
341
+ update_option( 'top_settings', $settings );
342
+ }
343
+ ?>
tweet-old-post.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ # /*
3
+ # Plugin Name: Tweet old post
4
+ # Plugin URI: http://www.ajaymatharu.com/wordpress-plugin-tweet-old-posts/
5
+ # Description: Plugin for tweeting your old posts randomly
6
+ # Author: Ajay Matharu
7
+ # Version: 3.0
8
+ # Author URI: http://www.ajaymatharu.com
9
+ # */
10
+
11
+
12
+ require_once('top-admin.php');
13
+ require_once('top-core.php');
14
+
15
+ define ('top_opt_1_HOUR', 60*60);
16
+ define ('top_opt_2_HOURS', 2*top_opt_1_HOUR);
17
+ define ('top_opt_4_HOURS', 4*top_opt_1_HOUR);
18
+ define ('top_opt_8_HOURS', 8*top_opt_1_HOUR);
19
+ define ('top_opt_6_HOURS', 6*top_opt_1_HOUR);
20
+ define ('top_opt_12_HOURS', 12*top_opt_1_HOUR);
21
+ define ('top_opt_24_HOURS', 24*top_opt_1_HOUR);
22
+ define ('top_opt_48_HOURS', 48*top_opt_1_HOUR);
23
+ define ('top_opt_72_HOURS', 72*top_opt_1_HOUR);
24
+ define ('top_opt_168_HOURS', 168*top_opt_1_HOUR);
25
+ define ('top_opt_INTERVAL', 4);
26
+ define ('top_opt_INTERVAL_SLOP', 4);
27
+ define ('top_opt_AGE_LIMIT', 30); // 120 days
28
+ define ('top_opt_MAX_AGE_LIMIT', 0); // 120 days
29
+ define ('top_opt_OMIT_CATS', "");
30
+ define('top_opt_TWEET_PREFIX',"");
31
+ define('top_opt_ADD_DATA',"false");
32
+ define('top_opt_URL_SHORTENER',"is.gd");
33
+ define('top_opt_HASHTAGS',"");
34
+
35
+ function top_admin_actions() {
36
+ add_options_page("Tweet Old Post", "Tweet Old Post", 1, "TweetOldPost", "top_admin");
37
+ }
38
+
39
+ add_action('admin_menu', 'top_admin_actions');
40
+ add_action('admin_head', 'top_opt_head_admin');
41
+ add_action('init','top_tweet_old_post')
42
+
43
+ ?>
xml.php ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ function TOP_parsexml( $xml, $get_attributes = 1, $priority = 'tag' )
4
+ {
5
+ $parser = xml_parser_create('');
6
+ xml_parser_set_option( $parser, XML_OPTION_TARGET_ENCODING, "UTF-8" );
7
+ xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, 0 );
8
+ xml_parser_set_option( $parser, XML_OPTION_SKIP_WHITE, 1 );
9
+ xml_parse_into_struct( $parser, trim($xml), $xml_values );
10
+ xml_parser_free($parser);
11
+
12
+ if (!$xml_values)
13
+ return;
14
+
15
+ $xml_array = array ();
16
+ $parents = array ();
17
+ $opened_tags = array ();
18
+ $arr = array ();
19
+ $current = & $xml_array;
20
+ $repeated_tag_index = array ();
21
+
22
+ foreach ($xml_values as $data) {
23
+ unset ($attributes, $value);
24
+ extract($data);
25
+ $result = array ();
26
+ $attributes_data = array ();
27
+ if (isset ($value))
28
+ {
29
+ if ($priority == 'tag')
30
+ $result = $value;
31
+ else
32
+ $result['value'] = $value;
33
+ }
34
+ if (isset ($attributes) and $get_attributes)
35
+ {
36
+ foreach ($attributes as $attr => $val)
37
+ {
38
+ if ($priority == 'tag')
39
+ $attributes_data[$attr] = $val;
40
+ else
41
+ $result['attr'][$attr] = $val; //Set all the attributes in a array called 'attr'
42
+ }
43
+ }
44
+ if ($type == "open")
45
+ {
46
+ $parent[$level -1] = & $current;
47
+ if (!is_array($current) or (!in_array($tag, array_keys($current))))
48
+ {
49
+ $current[$tag] = $result;
50
+ if ($attributes_data)
51
+ $current[$tag . '_attr'] = $attributes_data;
52
+ $repeated_tag_index[$tag . '_' . $level] = 1;
53
+ $current = & $current[$tag];
54
+ }
55
+ else
56
+ {
57
+ if (isset ($current[$tag][0]))
58
+ {
59
+ $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result;
60
+ $repeated_tag_index[$tag . '_' . $level]++;
61
+ }
62
+ else
63
+ {
64
+ $current[$tag] = array (
65
+ $current[$tag],
66
+ $result
67
+ );
68
+ $repeated_tag_index[$tag . '_' . $level] = 2;
69
+ if (isset ($current[$tag . '_attr']))
70
+ {
71
+ $current[$tag]['0_attr'] = $current[$tag . '_attr'];
72
+ unset ($current[$tag . '_attr']);
73
+ }
74
+ }
75
+ $last_item_index = $repeated_tag_index[$tag . '_' . $level] - 1;
76
+ $current = & $current[$tag][$last_item_index];
77
+ }
78
+ }
79
+ elseif ($type == "complete")
80
+ {
81
+ if (!isset ($current[$tag]))
82
+ {
83
+ $current[$tag] = $result;
84
+ $repeated_tag_index[$tag . '_' . $level] = 1;
85
+ if ($priority == 'tag' and $attributes_data)
86
+ $current[$tag . '_attr'] = $attributes_data;
87
+ }
88
+ else
89
+ {
90
+ if (isset ($current[$tag][0]) and is_array($current[$tag]))
91
+ {
92
+ $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result;
93
+ if ($priority == 'tag' and $get_attributes and $attributes_data)
94
+ {
95
+ $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data;
96
+ }
97
+ $repeated_tag_index[$tag . '_' . $level]++;
98
+ }
99
+ else
100
+ {
101
+ $current[$tag] = array (
102
+ $current[$tag],
103
+ $result
104
+ );
105
+ $repeated_tag_index[$tag . '_' . $level] = 1;
106
+ if ($priority == 'tag' and $get_attributes)
107
+ {
108
+ if (isset ($current[$tag . '_attr']))
109
+ {
110
+ $current[$tag]['0_attr'] = $current[$tag . '_attr'];
111
+ unset ($current[$tag . '_attr']);
112
+ }
113
+ if ($attributes_data)
114
+ {
115
+ $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data;
116
+ }
117
+ }
118
+ $repeated_tag_index[$tag . '_' . $level]++; //0 and 1 index is already taken
119
+ }
120
+ }
121
+ }
122
+ elseif ($type == 'close')
123
+ {
124
+ $current = & $parent[$level -1];
125
+ }
126
+ }
127
+ return $xml_array;
128
+ }
129
+
130
+ ?>