Version Description
Download this release
Release Info
Developer | codeinwp |
Plugin | Revive Old Posts – Auto Post to Social Media |
Version | 3.1.1 |
Comparing to | |
See all releases |
Version 3.1.1
- readme.txt +341 -0
- top-admin.php +519 -0
- top-core.php +313 -0
- top-excludepost.php +326 -0
- tweet-old-post.php +52 -0
- xml.php +130 -0
readme.txt
ADDED
@@ -0,0 +1,341 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.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 |
+
New
|
19 |
+
|
20 |
+
**New in v3.1.1**
|
21 |
+
|
22 |
+
- Resolved tweets not getting posted issue. Sorry guys :(
|
23 |
+
|
24 |
+
|
25 |
+
|
26 |
+
**New in v3.1**
|
27 |
+
|
28 |
+
- Resolved issue of plugin flooding twitter account with tweets.
|
29 |
+
- added provision to exclude some post from selected categories
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
**New in v3.0**
|
34 |
+
|
35 |
+
- added OAuth authentication
|
36 |
+
- user defined intervals
|
37 |
+
- may not work under php 4 requires php 5
|
38 |
+
|
39 |
+
|
40 |
+
|
41 |
+
**New in v2.0**
|
42 |
+
|
43 |
+
- added provision to select if you want to shorten the URL or not.
|
44 |
+
- Cleaned other options.
|
45 |
+
|
46 |
+
|
47 |
+
|
48 |
+
**New in v1.9**
|
49 |
+
|
50 |
+
- Removed PHP 4 support as it was creating problem for lot of people
|
51 |
+
|
52 |
+
|
53 |
+
|
54 |
+
**New in v1.8**
|
55 |
+
|
56 |
+
- Bug Fixes
|
57 |
+
- Provision to fetch tweet url from custom field
|
58 |
+
|
59 |
+
|
60 |
+
|
61 |
+
**New in v1.7**
|
62 |
+
|
63 |
+
- Removed api option from 1click.at not needed api key
|
64 |
+
|
65 |
+
|
66 |
+
|
67 |
+
**New in v1.6**
|
68 |
+
|
69 |
+
- Made the plugin PHP 4 compatible. Guys try it out and please let me know if that worked.
|
70 |
+
- 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.
|
71 |
+
- 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.
|
72 |
+
|
73 |
+
|
74 |
+
|
75 |
+
**New in v1.5**
|
76 |
+
|
77 |
+
- Maximum age of post to be eligible for tweet - allows you to set Maximum age of the post to be eligible for tweet
|
78 |
+
- Added one more shortner service was looking for j.mp but they dont have the api yet.
|
79 |
+
|
80 |
+
|
81 |
+
|
82 |
+
**New in v1.4**
|
83 |
+
|
84 |
+
- Hashtags - allows you to set default hashtags for your tweets
|
85 |
+
|
86 |
+
|
87 |
+
|
88 |
+
**New in v1.3**
|
89 |
+
|
90 |
+
- URL Shortener Service - allows you to select which URL shortener service you want to use.
|
91 |
+
|
92 |
+
|
93 |
+
|
94 |
+
**New in v1.2**
|
95 |
+
|
96 |
+
- Tweet Prefix - Allows you to set prefix to the tweets.
|
97 |
+
- Add Data - Allows you to add post data to the tweets
|
98 |
+
- Tweet now - Button that will tweet at that moment without wanting you to wait for scheduled tweet
|
99 |
+
|
100 |
+
|
101 |
+
|
102 |
+
**v1.1**
|
103 |
+
|
104 |
+
- Twitter Username & Password - Using this twitter account credentials plugin will tweet.
|
105 |
+
- Minimum interval between tweets - allows you to determine how often the plugin will automatically choose and tweet a blog post for you.
|
106 |
+
- Randomness interval - This is a contributing factor in minimum interval so that posts are randomly chosen and tweeted from your blog.
|
107 |
+
- 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.
|
108 |
+
- Categories to omit from tweets - This will protect posts from the selected categories from being tweeted.
|
109 |
+
|
110 |
+
== Installation ==
|
111 |
+
|
112 |
+
Following are the steps to install the Tweet Old Post plugin
|
113 |
+
|
114 |
+
1. Download the latest version of the Tweet Old Posts Plugin to your computer from here.
|
115 |
+
2. With an FTP program, access your site�s server.
|
116 |
+
3. Upload (copy) the Plugin file(s) or folder to the /wp-content/plugins folder.
|
117 |
+
4. In your WordPress Administration Panels, click on Plugins from the menu.
|
118 |
+
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.
|
119 |
+
6. To turn the Tweet Old Posts Plugin on, click Activate.
|
120 |
+
7. Check your Administration Panels or WordPress blog to see if the Plugin is working.
|
121 |
+
8. You can change the plugin options from Tweet Old Posts under settings menu.
|
122 |
+
|
123 |
+
Alternatively you can also follow the following steps to install the Tweet Old Post plugin
|
124 |
+
|
125 |
+
1. In your WordPress Administration Panels, click on Add New option under Plugins from the menu.
|
126 |
+
2. Click on upload at the top.
|
127 |
+
3. Browse the location and select the Tweet Old Post Plugin and click install now.
|
128 |
+
4. To turn the Tweet Old Posts Plugin on, click Activate.
|
129 |
+
5. Check your Administration Panels or WordPress blog to see if the Plugin is working.
|
130 |
+
6. You can change the plugin options from Tweet Old Posts under settings menu.
|
131 |
+
|
132 |
+
== Frequently Asked Questions ==
|
133 |
+
|
134 |
+
If you have any questions please mail me at,
|
135 |
+
ajay@ajaymatharu.com or matharuajay@yahoo.co.in
|
136 |
+
|
137 |
+
**Tweet Old post does not posts any tweets?**
|
138 |
+
|
139 |
+
- If its not tweeting any tweets try playing around with the options. Try setting maxtweetage to none and try again.
|
140 |
+
|
141 |
+
|
142 |
+
**Tweet old post giving SimpleXmlElement error?**
|
143 |
+
|
144 |
+
- If it is giving SimpleXmlElement error, check with your hosting provider on which version of PHP are they supporting.
|
145 |
+
Tweet Old Post supports PHP 5 onwards. It will give SimpleXmlElement error if your hosting provider supports PHP 4
|
146 |
+
or PHP less than 5
|
147 |
+
|
148 |
+
|
149 |
+
**Tweets not getting posted?**
|
150 |
+
|
151 |
+
- If your tweets are not getting posted, try deauthorizing and again authorizing your twitter account with
|
152 |
+
plugin.
|
153 |
+
|
154 |
+
|
155 |
+
**Plugin flooded your tweeter account with tweets?**
|
156 |
+
|
157 |
+
- please check your setting increase the minimum interval between tweets. If your plugin is not updated please update your plugin to latest version.
|
158 |
+
|
159 |
+
|
160 |
+
== Screenshots ==
|
161 |
+
|
162 |
+
for screenshots you can check out
|
163 |
+
|
164 |
+
http://www.ajaymatharu.com/wordpress-plugin-tweet-old-posts/
|
165 |
+
|
166 |
+
== Changelog ==
|
167 |
+
|
168 |
+
**New in v3.1**
|
169 |
+
|
170 |
+
- Resolved issue of plugin flooding twitter account with tweets.
|
171 |
+
- added provision to exclude some post from selected categories
|
172 |
+
|
173 |
+
|
174 |
+
|
175 |
+
**New in v3.0**
|
176 |
+
|
177 |
+
- added OAuth authentication
|
178 |
+
- user defined intervals
|
179 |
+
- may not work under php 4 requires php 5
|
180 |
+
|
181 |
+
|
182 |
+
|
183 |
+
**New in v2.0**
|
184 |
+
|
185 |
+
- added provision to select if you want to shorten the URL or not.
|
186 |
+
- Cleaned other options.
|
187 |
+
|
188 |
+
|
189 |
+
|
190 |
+
**New in v1.9**
|
191 |
+
|
192 |
+
- Removed PHP 4 support as it was creating problem for lot of people
|
193 |
+
|
194 |
+
|
195 |
+
|
196 |
+
**New in v1.8**
|
197 |
+
|
198 |
+
- Bug Fixes
|
199 |
+
- Provision to fetch tweet url from custom field
|
200 |
+
|
201 |
+
|
202 |
+
|
203 |
+
**New in v1.7**
|
204 |
+
|
205 |
+
- Removed api option from 1click.at not needed api key
|
206 |
+
|
207 |
+
|
208 |
+
|
209 |
+
**New in v1.6**
|
210 |
+
|
211 |
+
- Made the plugin PHP 4 compatible. Guys try it out and please let me know if that worked.
|
212 |
+
- 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.
|
213 |
+
- 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.
|
214 |
+
|
215 |
+
|
216 |
+
|
217 |
+
**New in v1.5**
|
218 |
+
|
219 |
+
- Maximum age of post to be eligible for tweet - allows you to set Maximum age of the post to be eligible for tweet
|
220 |
+
- Added one more shortner service was looking for j.mp but they dont have the api yet.
|
221 |
+
|
222 |
+
|
223 |
+
|
224 |
+
**New in v1.4**
|
225 |
+
|
226 |
+
- Hashtags - allows you to set default hashtags for your tweets
|
227 |
+
|
228 |
+
|
229 |
+
|
230 |
+
**New in v1.3**
|
231 |
+
|
232 |
+
- URL Shortener Service - allows you to select which URL shortener service you want to use.
|
233 |
+
|
234 |
+
|
235 |
+
|
236 |
+
**New in v1.2**
|
237 |
+
|
238 |
+
- Tweet Prefix - Allows you to set prefix to the tweets.
|
239 |
+
- Add Data - Allows you to add post data to the tweets
|
240 |
+
- Tweet now - Button that will tweet at that moment without wanting you to wait for scheduled tweet
|
241 |
+
|
242 |
+
|
243 |
+
|
244 |
+
**v1.1**
|
245 |
+
|
246 |
+
- Twitter Username & Password - Using this twitter account credentials plugin will tweet.
|
247 |
+
- Minimum interval between tweets - allows you to determine how often the plugin will automatically choose and tweet a blog post for you.
|
248 |
+
- Randomness interval - This is a contributing factor in minimum interval so that posts are randomly chosen and tweeted from your blog.
|
249 |
+
- 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.
|
250 |
+
- Categories to omit from tweets - This will protect posts from the selected categories from being tweeted.
|
251 |
+
|
252 |
+
|
253 |
+
== Other Notes ==
|
254 |
+
|
255 |
+
Some of the options you can configure for the Tweet Old Posts plugins are,
|
256 |
+
|
257 |
+
|
258 |
+
**New in v3.1**
|
259 |
+
|
260 |
+
- Resolved issue of plugin flooding twitter account with tweets.
|
261 |
+
- added provision to exclude some post from selected categories
|
262 |
+
|
263 |
+
|
264 |
+
|
265 |
+
**New in v3.0**
|
266 |
+
|
267 |
+
- added OAuth authentication
|
268 |
+
- user defined intervals
|
269 |
+
- may not work under php 4 requires php 5
|
270 |
+
|
271 |
+
|
272 |
+
|
273 |
+
**New in v2.0**
|
274 |
+
|
275 |
+
- added provision to select if you want to shorten the URL or not.
|
276 |
+
- Cleaned other options.
|
277 |
+
|
278 |
+
|
279 |
+
|
280 |
+
**New in v1.9**
|
281 |
+
|
282 |
+
- Removed PHP 4 support as it was creating problem for lot of people
|
283 |
+
|
284 |
+
|
285 |
+
|
286 |
+
**New in v1.8**
|
287 |
+
|
288 |
+
- Bug Fixes
|
289 |
+
- Provision to fetch tweet url from custom field
|
290 |
+
|
291 |
+
|
292 |
+
|
293 |
+
**New in v1.7**
|
294 |
+
|
295 |
+
- Removed api option from 1click.at not needed api key
|
296 |
+
|
297 |
+
|
298 |
+
|
299 |
+
**New in v1.6**
|
300 |
+
|
301 |
+
- Made the plugin PHP 4 compatible. Guys try it out and please let me know if that worked.
|
302 |
+
- 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.
|
303 |
+
- 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.
|
304 |
+
|
305 |
+
|
306 |
+
|
307 |
+
**New in v1.5**
|
308 |
+
|
309 |
+
- Maximum age of post to be eligible for tweet - allows you to set Maximum age of the post to be eligible for tweet
|
310 |
+
- Added one more shortner service was looking for j.mp but they dont have the api yet.
|
311 |
+
|
312 |
+
|
313 |
+
|
314 |
+
**New in v1.4**
|
315 |
+
|
316 |
+
- Hashtags - allows you to set default hashtags for your tweets
|
317 |
+
|
318 |
+
|
319 |
+
|
320 |
+
**New in v1.3**
|
321 |
+
|
322 |
+
- URL Shortener Service - allows you to select which URL shortener service you want to use.
|
323 |
+
|
324 |
+
|
325 |
+
|
326 |
+
**New in v1.2**
|
327 |
+
|
328 |
+
- Tweet Prefix - Allows you to set prefix to the tweets.
|
329 |
+
- Add Data - Allows you to add post data to the tweets
|
330 |
+
- Tweet now - Button that will tweet at that moment without wanting you to wait for scheduled tweet
|
331 |
+
|
332 |
+
|
333 |
+
|
334 |
+
**v1.1**
|
335 |
+
|
336 |
+
- Twitter Username & Password - Using this twitter account credentials plugin will tweet.
|
337 |
+
- Minimum interval between tweets - allows you to determine how often the plugin will automatically choose and tweet a blog post for you.
|
338 |
+
- Randomness interval - This is a contributing factor in minimum interval so that posts are randomly chosen and tweeted from your blog.
|
339 |
+
- 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.
|
340 |
+
- Categories to omit from tweets - This will protect posts from the selected categories from being tweeted.
|
341 |
+
|
top-admin.php
ADDED
@@ -0,0 +1,519 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once('tweet-old-post.php');
|
4 |
+
require_once('top-core.php');
|
5 |
+
require_once( 'Include/oauth.php' );
|
6 |
+
require_once('xml.php');
|
7 |
+
|
8 |
+
function top_admin() {
|
9 |
+
if (current_user_can('manage_options')) {
|
10 |
+
$message = null;
|
11 |
+
$message_updated = __("Tweet Old Post Options Updated.", 'TweetOldPost');
|
12 |
+
$response = null;
|
13 |
+
$save = true;
|
14 |
+
$settings = top_get_settings();
|
15 |
+
if (isset($_GET['TOP_oauth'])) {
|
16 |
+
global $top_oauth;
|
17 |
+
|
18 |
+
|
19 |
+
$result = $top_oauth->get_access_token($settings['oauth_request_token'], $settings['oauth_request_token_secret'], $_GET['oauth_verifier']);
|
20 |
+
|
21 |
+
if ($result) {
|
22 |
+
$settings['oauth_access_token'] = $result['oauth_token'];
|
23 |
+
$settings['oauth_access_token_secret'] = $result['oauth_token_secret'];
|
24 |
+
$settings['user_id'] = $result['user_id'];
|
25 |
+
|
26 |
+
$result = $top_oauth->get_user_info($result['user_id']);
|
27 |
+
if ($result) {
|
28 |
+
$settings['profile_image_url'] = $result['user']['profile_image_url'];
|
29 |
+
$settings['screen_name'] = $result['user']['screen_name'];
|
30 |
+
if (isset($result['user']['location'])) {
|
31 |
+
$settings['location'] = $result['user']['location'];
|
32 |
+
} else {
|
33 |
+
$settings['location'] = false;
|
34 |
+
}
|
35 |
+
}
|
36 |
+
|
37 |
+
top_save_settings($settings);
|
38 |
+
echo '<script language="javascript">window.open ("' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=TweetOldPost","_self")</script>';
|
39 |
+
die;
|
40 |
+
}
|
41 |
+
} else if (isset($_GET['top']) && $_GET['top'] == 'deauthorize') {
|
42 |
+
$settings = top_get_settings();
|
43 |
+
$settings['oauth_access_token'] = '';
|
44 |
+
$settings['oauth_access_token_secret'] = '';
|
45 |
+
$settings['user_id'] = '';
|
46 |
+
$settings['tweet_queue'] = array();
|
47 |
+
|
48 |
+
top_save_settings($settings);
|
49 |
+
echo '<script language="javascript">window.open ("' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=TweetOldPost","_self")</script>';
|
50 |
+
die;
|
51 |
+
}
|
52 |
+
|
53 |
+
if (isset($_POST['top_opt_url_shortener'])) {
|
54 |
+
if ($_POST['top_opt_url_shortener'] == "bit.ly") {
|
55 |
+
|
56 |
+
if (!isset($_POST['top_opt_bitly_user'])) {
|
57 |
+
print('
|
58 |
+
<div id="message" class="updated fade">
|
59 |
+
<p>' . __('Please enter bit.ly username.', 'TweetOldPost') . '</p>
|
60 |
+
</div>');
|
61 |
+
$save = false;
|
62 |
+
} elseif (!isset($_POST['top_opt_bitly_key'])) {
|
63 |
+
print('
|
64 |
+
<div id="message" class="updated fade">
|
65 |
+
<p>' . __('Please enter bit.ly API Key.', 'TweetOldPost') . '</p>
|
66 |
+
</div>');
|
67 |
+
$save = false;
|
68 |
+
} else {
|
69 |
+
$save = true;
|
70 |
+
}
|
71 |
+
}
|
72 |
+
}
|
73 |
+
|
74 |
+
if (isset($_POST['submit']) && $save) {
|
75 |
+
$message = $message_updated;
|
76 |
+
|
77 |
+
if (isset($_POST['top_opt_interval'])) {
|
78 |
+
if (is_numeric($_POST['top_opt_interval']) && $_POST['top_opt_interval']>0) {
|
79 |
+
update_option('top_opt_interval', $_POST['top_opt_interval']);
|
80 |
+
}
|
81 |
+
else
|
82 |
+
{
|
83 |
+
update_option('top_opt_interval',"4");
|
84 |
+
}
|
85 |
+
|
86 |
+
|
87 |
+
}
|
88 |
+
if (isset($_POST['top_opt_interval_slop'])) {
|
89 |
+
|
90 |
+
if (is_numeric($_POST['top_opt_interval_slop']) && $_POST['top_opt_interval_slop']>0) {
|
91 |
+
update_option('top_opt_interval_slop', $_POST['top_opt_interval_slop']);
|
92 |
+
}
|
93 |
+
else
|
94 |
+
{
|
95 |
+
update_option('top_opt_interval_slop',"4");
|
96 |
+
}
|
97 |
+
}
|
98 |
+
if (isset($_POST['top_opt_age_limit'])) {
|
99 |
+
update_option('top_opt_age_limit', $_POST['top_opt_age_limit']);
|
100 |
+
}
|
101 |
+
if (isset($_POST['top_opt_max_age_limit'])) {
|
102 |
+
update_option('top_opt_max_age_limit', $_POST['top_opt_max_age_limit']);
|
103 |
+
}
|
104 |
+
if (isset($_POST['top_opt_tweet_prefix'])) {
|
105 |
+
update_option('top_opt_tweet_prefix', $_POST['top_opt_tweet_prefix']);
|
106 |
+
}
|
107 |
+
if (isset($_POST['top_opt_add_data'])) {
|
108 |
+
update_option('top_opt_add_data', $_POST['top_opt_add_data']);
|
109 |
+
}
|
110 |
+
if (isset($_POST['post_category'])) {
|
111 |
+
update_option('top_opt_omit_cats', implode(',', $_POST['post_category']));
|
112 |
+
} else {
|
113 |
+
update_option('top_opt_omit_cats', '');
|
114 |
+
}
|
115 |
+
|
116 |
+
|
117 |
+
if (isset($_POST['top_opt_custom_url_option'])) {
|
118 |
+
update_option('top_opt_custom_url_option', true);
|
119 |
+
} else {
|
120 |
+
|
121 |
+
update_option('top_opt_custom_url_option', false);
|
122 |
+
}
|
123 |
+
|
124 |
+
if (isset($_POST['top_opt_custom_url_field'])) {
|
125 |
+
update_option('top_opt_custom_url_field', $_POST['top_opt_custom_url_field']);
|
126 |
+
} else {
|
127 |
+
|
128 |
+
update_option('top_opt_custom_url_field', '');
|
129 |
+
}
|
130 |
+
|
131 |
+
if (isset($_POST['top_opt_use_url_shortner'])) {
|
132 |
+
update_option('top_opt_use_url_shortner', true);
|
133 |
+
} else {
|
134 |
+
|
135 |
+
update_option('top_opt_use_url_shortner', false);
|
136 |
+
}
|
137 |
+
|
138 |
+
if (isset($_POST['top_opt_hashtags'])) {
|
139 |
+
update_option('top_opt_hashtags', $_POST['top_opt_hashtags']);
|
140 |
+
} else {
|
141 |
+
update_option('top_opt_hashtags', '');
|
142 |
+
}
|
143 |
+
|
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 |
+
print('
|
156 |
+
<div id="message" class="updated fade">
|
157 |
+
<p>' . __('Tweet Old Post Options Updated.', 'TweetOldPost') . '</p>
|
158 |
+
</div>');
|
159 |
+
} elseif (isset($_POST['tweet'])) {
|
160 |
+
$tweet_msg = top_opt_tweet_old_post();
|
161 |
+
print('
|
162 |
+
<div id="message" class="updated fade">
|
163 |
+
<p>' . __($tweet_msg, 'TweetOldPost') . '</p>
|
164 |
+
</div>');
|
165 |
+
}
|
166 |
+
$omitCats = get_option('top_opt_omit_cats');
|
167 |
+
if (!isset($omitCats)) {
|
168 |
+
$omitCats = top_opt_OMIT_CATS;
|
169 |
+
}
|
170 |
+
$ageLimit = get_option('top_opt_age_limit');
|
171 |
+
if (!(isset($ageLimit) && is_numeric($ageLimit))) {
|
172 |
+
$ageLimit = top_opt_AGE_LIMIT;
|
173 |
+
}
|
174 |
+
|
175 |
+
$maxAgeLimit = get_option('top_opt_max_age_limit');
|
176 |
+
if (!(isset($maxAgeLimit) && is_numeric($maxAgeLimit))) {
|
177 |
+
$maxAgeLimit = top_opt_MAX_AGE_LIMIT;
|
178 |
+
}
|
179 |
+
|
180 |
+
$interval = get_option('top_opt_interval');
|
181 |
+
if (!(isset($interval) && is_numeric($interval))) {
|
182 |
+
$interval = top_opt_INTERVAL;
|
183 |
+
}
|
184 |
+
$slop = get_option('top_opt_interval_slop');
|
185 |
+
if (!(isset($slop) && is_numeric($slop))) {
|
186 |
+
$slop = top_opt_INTERVAL_SLOP;
|
187 |
+
}
|
188 |
+
$tweet_prefix = get_option('top_opt_tweet_prefix');
|
189 |
+
if (!isset($tweet_prefix)) {
|
190 |
+
$tweet_prefix = top_opt_TWEET_PREFIX;
|
191 |
+
}
|
192 |
+
$url_shortener = get_option('top_opt_url_shortener');
|
193 |
+
if (!isset($url_shortener)) {
|
194 |
+
$url_shortener = top_opt_URL_SHORTENER;
|
195 |
+
}
|
196 |
+
|
197 |
+
|
198 |
+
$twitter_hashtags = get_option('top_opt_hashtags');
|
199 |
+
if (!isset($twitter_hashtags)) {
|
200 |
+
$twitter_hashtags = top_opt_HASHTAGS;
|
201 |
+
}
|
202 |
+
|
203 |
+
$bitly_api = get_option('top_opt_bitly_key');
|
204 |
+
if (!isset($bitly_api)) {
|
205 |
+
$bitly_api = "";
|
206 |
+
}
|
207 |
+
$bitly_username = get_option('top_opt_bitly_user');
|
208 |
+
if (!isset($bitly_username)) {
|
209 |
+
$bitly_username = "";
|
210 |
+
}
|
211 |
+
|
212 |
+
$custom_url_option = get_option('top_opt_custom_url_option');
|
213 |
+
|
214 |
+
if (!isset($custom_url_option)) {
|
215 |
+
$custom_url_option = "";
|
216 |
+
} elseif ($custom_url_option)
|
217 |
+
$custom_url_option = "checked";
|
218 |
+
else
|
219 |
+
$custom_url_option="";
|
220 |
+
|
221 |
+
$custom_url_field = get_option('top_opt_custom_url_field');
|
222 |
+
if (!isset($custom_url_field)) {
|
223 |
+
$custom_url_field = "";
|
224 |
+
}
|
225 |
+
|
226 |
+
$use_url_shortner = get_option('top_opt_use_url_shortner');
|
227 |
+
if (!isset($use_url_shortner)) {
|
228 |
+
$use_url_shortner = "";
|
229 |
+
} elseif ($use_url_shortner)
|
230 |
+
$use_url_shortner = "checked";
|
231 |
+
else
|
232 |
+
$use_url_shortner="";
|
233 |
+
$add_data = get_option('top_opt_add_data');
|
234 |
+
$twitter_username = get_option('top_opt_twitter_username');
|
235 |
+
$twitter_password = get_option('top_opt_twitter_password');
|
236 |
+
|
237 |
+
print('
|
238 |
+
<div class="wrap">
|
239 |
+
<h2>' . __('Tweet old post by - ', 'TweetOldPost') . ' <a href="http://www.ajaymatharu.com">Ajay Matharu</a></h2>
|
240 |
+
<form id="top_opt" name="top_TweetOldPost" action="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=TweetOldPost" method="post">
|
241 |
+
<input type="hidden" name="top_opt_action" value="top_opt_update_settings" />
|
242 |
+
<fieldset class="options">
|
243 |
+
<div class="option">
|
244 |
+
<label for="top_opt_twitter_username">' . __('Account Login', 'TweetOldPost') . ':</label>
|
245 |
+
|
246 |
+
<div id="profile-box">');
|
247 |
+
if (!$settings["oauth_access_token"]) {
|
248 |
+
echo '<a href="' . top_get_auth_url() . '"><img src="http://apiwiki.twitter.com/f/1242697607/Sign-in-with-Twitter-lighter-small.png" /></a>';
|
249 |
+
} else {
|
250 |
+
echo '<img class="avatar" src="' . $settings["profile_image_url"] . '" alt="" />
|
251 |
+
<h4>' . $settings["screen_name"] . '</h4>';
|
252 |
+
if ($settings["location"]) {
|
253 |
+
echo '<h5>' . $settings["location"] . '</h5>';
|
254 |
+
}
|
255 |
+
echo '<p>
|
256 |
+
|
257 |
+
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 />
|
258 |
+
|
259 |
+
</p>
|
260 |
+
|
261 |
+
<div class="retweet-clear"></div>
|
262 |
+
';
|
263 |
+
}
|
264 |
+
print('</div>
|
265 |
+
</div>
|
266 |
+
|
267 |
+
<div class="option">
|
268 |
+
<label for="top_opt_tweet_prefix">' . __('Tweet Prefix', 'TweetOldPost') . ':</label>
|
269 |
+
<input type="text" size="25" name="top_opt_tweet_prefix" id="top_opt_tweet_prefix" value="' . $tweet_prefix . '" autocomplete="off" />
|
270 |
+
<b>If set, it will show as: "{tweet prefix}: {post title}... {url}</b>
|
271 |
+
</div>
|
272 |
+
<div class="option">
|
273 |
+
<label for="top_opt_add_data">' . __('Add post data to tweet', 'TweetOldPost') . ':</label>
|
274 |
+
<select id="top_opt_add_data" name="top_opt_add_data" style="width:100px;">
|
275 |
+
<option value="false" ' . top_opt_optionselected("false", $add_data) . '>' . __(' No ', 'TweetOldPost') . '</option>
|
276 |
+
<option value="true" ' . top_opt_optionselected("true", $add_data) . '>' . __(' Yes ', 'TweetOldPost') . '</option>
|
277 |
+
</select>
|
278 |
+
<b>If set, it will show as: "{tweet prefix}: {post title}- {content}... {url}</b>
|
279 |
+
</div>
|
280 |
+
|
281 |
+
<div class="option">
|
282 |
+
<label for="top_opt_custom_url_option">' . __('Fetch URL from custom field', 'TweetOldPost') . ':</label>
|
283 |
+
<input onchange="return showCustomField();" type="checkbox" name="top_opt_custom_url_option" ' . $custom_url_option . ' id="top_opt_custom_url_option" />
|
284 |
+
<b>If checked URL will be fetched from custom field. If not plugin will generate shortened URL from post link.</b>
|
285 |
+
</div>
|
286 |
+
|
287 |
+
|
288 |
+
|
289 |
+
<div id="customurl" style="display:none;">
|
290 |
+
<div class="option">
|
291 |
+
<label for="top_opt_custom_url_field">' . __('Custom field name to fetch URL to be tweeted with post', 'TweetOldPost') . ':</label>
|
292 |
+
<input type="text" size="25" name="top_opt_custom_url_field" id="top_opt_custom_url_field" value="' . $custom_url_field . '" autocomplete="off" />
|
293 |
+
<b>If set this will fetch the URL from specified custom field</b>
|
294 |
+
</div>
|
295 |
+
|
296 |
+
</div>
|
297 |
+
|
298 |
+
<div class="option">
|
299 |
+
<label for="top_opt_use_url_shortner">' . __('Use URL shortner?', 'TweetOldPost') . ':</label>
|
300 |
+
<input onchange="return showshortener()" type="checkbox" name="top_opt_use_url_shortner" id="top_opt_use_url_shortner" ' . $use_url_shortner . ' />
|
301 |
+
|
302 |
+
</div>
|
303 |
+
|
304 |
+
<div id="urlshortener">
|
305 |
+
<div class="option">
|
306 |
+
<label for="top_opt_url_shortener">' . __('URL Shortener Service', 'TweetOldPost') . ':</label>
|
307 |
+
<select name="top_opt_url_shortener" id="top_opt_url_shortener" onchange="javascript:showURLAPI()" style="width:100px;">
|
308 |
+
<option value="is.gd" ' . top_opt_optionselected('is.gd', $url_shortener) . '>' . __('is.gd', 'TweetOldPost') . '</option>
|
309 |
+
<option value="su.pr" ' . top_opt_optionselected('su.pr', $url_shortener) . '>' . __('su.pr', 'TweetOldPost') . '</option>
|
310 |
+
<option value="bit.ly" ' . top_opt_optionselected('bit.ly', $url_shortener) . '>' . __('bit.ly', 'TweetOldPost') . '</option>
|
311 |
+
<option value="tr.im" ' . top_opt_optionselected('tr.im', $url_shortener) . '>' . __('tr.im', 'TweetOldPost') . '</option>
|
312 |
+
<option value="3.ly" ' . top_opt_optionselected('3.ly', $url_shortener) . '>' . __('3.ly', 'TweetOldPost') . '</option>
|
313 |
+
<option value="u.nu" ' . top_opt_optionselected('u.nu', $url_shortener) . '>' . __('u.nu', 'TweetOldPost') . '</option>
|
314 |
+
<option value="1click.at" ' . top_opt_optionselected('1click.at', $url_shortener) . '>' . __('1click.at', 'TweetOldPost') . '</option>
|
315 |
+
<option value="tinyurl" ' . top_opt_optionselected('tinyurl', $url_shortener) . '>' . __('tinyurl', 'TweetOldPost') . '</option>
|
316 |
+
</select>
|
317 |
+
</div>
|
318 |
+
<div id="showDetail" style="display:none">
|
319 |
+
<div class="option">
|
320 |
+
<label for="top_opt_bitly_user">' . __('bit.ly Username', 'TweetOldPost') . ':</label>
|
321 |
+
<input type="text" size="25" name="top_opt_bitly_user" id="top_opt_bitly_user" value="' . $bitly_username . '" autocomplete="off" />
|
322 |
+
</div>
|
323 |
+
|
324 |
+
<div class="option">
|
325 |
+
<label for="top_opt_bitly_key">' . __('bit.ly API Key', 'TweetOldPost') . ':</label>
|
326 |
+
<input type="text" size="25" name="top_opt_bitly_key" id="top_opt_bitly_key" value="' . $bitly_api . '" autocomplete="off" />
|
327 |
+
</div>
|
328 |
+
</div>
|
329 |
+
</div>
|
330 |
+
|
331 |
+
|
332 |
+
<div class="option">
|
333 |
+
<label for="top_opt_hashtags">' . __('Default #hashtags for your tweets', 'TweetOldPost') . ':</label>
|
334 |
+
<input type="text" size="25" name="top_opt_hashtags" id="top_opt_hashtags" value="' . $twitter_hashtags . '" autocomplete="off" />
|
335 |
+
<b>Include #, like #thoughts</b>
|
336 |
+
</div>
|
337 |
+
|
338 |
+
<div class="option">
|
339 |
+
<label for="top_opt_interval">' . __('Minimum interval between tweets: ', 'TweetOldPost') . '</label>
|
340 |
+
<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>
|
341 |
+
|
342 |
+
</div>
|
343 |
+
<div class="option">
|
344 |
+
<label for="top_opt_interval_slop">' . __('Random Interval (added to minimum interval): ', 'TweetOldPost') . '</label>
|
345 |
+
<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>
|
346 |
+
|
347 |
+
</div>
|
348 |
+
<div class="option">
|
349 |
+
<label for="top_opt_age_limit">' . __('Minimum age of post to be eligible for tweet: ', 'TweetOldPost') . '</label>
|
350 |
+
<input type="text" id="top_opt_age_limit" maxlength="5" value="' . $ageLimit . '" name="top_opt_age_limit" /> Day / Days
|
351 |
+
<b> (enter 0 for today)</b>
|
352 |
+
|
353 |
+
</div>
|
354 |
+
|
355 |
+
<div class="option">
|
356 |
+
<label for="top_opt_max_age_limit">' . __('Maximum age of post to be eligible for tweet: ', 'TweetOldPost') . '</label>
|
357 |
+
<input type="text" id="top_opt_max_age_limit" maxlength="5" value="' . $maxAgeLimit . '" name="top_opt_max_age_limit" /> Day / Days
|
358 |
+
<b>(If you dont want to use this option enter 0 or leave blank)</b><br/>
|
359 |
+
<b>If set, it will fetch posts which are "NOT" older than specified day / days</b>
|
360 |
+
</div>
|
361 |
+
|
362 |
+
<div class="option category">
|
363 |
+
<div style="float:left">
|
364 |
+
<label class="catlabel">' . __('Categories to Omit from tweets: ', 'TweetOldPost') . '</label> </div>
|
365 |
+
<div style="float:left">
|
366 |
+
<ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
|
367 |
+
');
|
368 |
+
wp_category_checklist(0, 0, explode(',', $omitCats));
|
369 |
+
print(' </ul>
|
370 |
+
<div style="clear:both;padding-top:20px;">
|
371 |
+
<a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=ExcludePosts">Exclude specific posts</a> from selected categories.
|
372 |
+
</div>
|
373 |
+
</div>
|
374 |
+
|
375 |
+
</div>
|
376 |
+
</fieldset>
|
377 |
+
|
378 |
+
<h3>Note: Please click update to then click tweet now to reflect the changes.</h3>
|
379 |
+
<p class="submit"><input type="submit" name="submit" onclick="javascript:return validate()" value="' . __('Update Tweet Old Post Options', 'TweetOldPost') . '" />
|
380 |
+
<input type="submit" name="tweet" value="' . __('Tweet Now', 'TweetOldPost') . '" />
|
381 |
+
</p>
|
382 |
+
|
383 |
+
</form><script language="javascript" type="text/javascript">
|
384 |
+
function showURLAPI()
|
385 |
+
{
|
386 |
+
var urlShortener=document.getElementById("top_opt_url_shortener").value;
|
387 |
+
if(urlShortener=="bit.ly")
|
388 |
+
{
|
389 |
+
document.getElementById("showDetail").style.display="block";
|
390 |
+
|
391 |
+
}
|
392 |
+
else
|
393 |
+
{
|
394 |
+
document.getElementById("showDetail").style.display="none";
|
395 |
+
|
396 |
+
}
|
397 |
+
|
398 |
+
}
|
399 |
+
|
400 |
+
function validate()
|
401 |
+
{
|
402 |
+
|
403 |
+
if(document.getElementById("showDetail").style.display=="block" && document.getElementById("top_opt_url_shortener").value=="bit.ly")
|
404 |
+
{
|
405 |
+
if(trim(document.getElementById("top_opt_bitly_user").value)=="")
|
406 |
+
{
|
407 |
+
alert("Please enter bit.ly username.");
|
408 |
+
document.getElementById("top_opt_bitly_user").focus();
|
409 |
+
return false;
|
410 |
+
}
|
411 |
+
|
412 |
+
if(trim(document.getElementById("top_opt_bitly_key").value)=="")
|
413 |
+
{
|
414 |
+
alert("Please enter bit.ly API key.");
|
415 |
+
document.getElementById("top_opt_bitly_key").focus();
|
416 |
+
return false;
|
417 |
+
}
|
418 |
+
}
|
419 |
+
if(trim(document.getElementById("top_opt_interval").value) != "" && !isNumber(trim(document.getElementById("top_opt_interval").value)))
|
420 |
+
{
|
421 |
+
alert("Enter only numeric in Minimum interval between tweet");
|
422 |
+
document.getElementById("top_opt_interval").focus();
|
423 |
+
return false;
|
424 |
+
}
|
425 |
+
if(trim(document.getElementById("top_opt_interval_slop").value) != "" && !isNumber(trim(document.getElementById("top_opt_interval_slop").value)))
|
426 |
+
{
|
427 |
+
alert("Enter only numeric in Random interval");
|
428 |
+
document.getElementById("top_opt_interval_slop").focus();
|
429 |
+
return false;
|
430 |
+
}
|
431 |
+
if(trim(document.getElementById("top_opt_age_limit").value) != "" && !isNumber(trim(document.getElementById("top_opt_age_limit").value)))
|
432 |
+
{
|
433 |
+
alert("Enter only numeric in Minimum age of post");
|
434 |
+
document.getElementById("top_opt_age_limit").focus();
|
435 |
+
return false;
|
436 |
+
}
|
437 |
+
if(trim(document.getElementById("top_opt_max_age_limit").value) != "" && !isNumber(trim(document.getElementById("top_opt_max_age_limit").value)))
|
438 |
+
{
|
439 |
+
alert("Enter only numeric in Maximum age of post");
|
440 |
+
document.getElementById("top_opt_max_age_limit").focus();
|
441 |
+
return false;
|
442 |
+
}
|
443 |
+
if(trim(document.getElementById("top_opt_max_age_limit").value) != "" && trim(document.getElementById("top_opt_max_age_limit").value) != 0)
|
444 |
+
{
|
445 |
+
if(eval(document.getElementById("top_opt_age_limit").value) > eval(document.getElementById("top_opt_max_age_limit").value))
|
446 |
+
{
|
447 |
+
alert("Post max age limit cannot be less than Post min age iimit");
|
448 |
+
document.getElementById("top_opt_age_limit").focus();
|
449 |
+
return false;
|
450 |
+
}
|
451 |
+
}
|
452 |
+
}
|
453 |
+
|
454 |
+
function trim(stringToTrim) {
|
455 |
+
return stringToTrim.replace(/^\s+|\s+$/g,"");
|
456 |
+
}
|
457 |
+
|
458 |
+
function showCustomField()
|
459 |
+
{
|
460 |
+
if(document.getElementById("top_opt_custom_url_option").checked)
|
461 |
+
{
|
462 |
+
document.getElementById("customurl").style.display="block";
|
463 |
+
}
|
464 |
+
else
|
465 |
+
{
|
466 |
+
document.getElementById("customurl").style.display="none";
|
467 |
+
}
|
468 |
+
}
|
469 |
+
|
470 |
+
function isNumber(val)
|
471 |
+
{
|
472 |
+
if(isNaN(val)){
|
473 |
+
return false;
|
474 |
+
}
|
475 |
+
else{
|
476 |
+
return true;
|
477 |
+
}
|
478 |
+
}
|
479 |
+
|
480 |
+
function showshortener()
|
481 |
+
{
|
482 |
+
|
483 |
+
|
484 |
+
if((document.getElementById("top_opt_use_url_shortner").checked))
|
485 |
+
{
|
486 |
+
document.getElementById("urlshortener").style.display="block";
|
487 |
+
}
|
488 |
+
else
|
489 |
+
{
|
490 |
+
document.getElementById("urlshortener").style.display="none";
|
491 |
+
}
|
492 |
+
}
|
493 |
+
showURLAPI();
|
494 |
+
showshortener();
|
495 |
+
showCustomField();
|
496 |
+
</script>');
|
497 |
+
} else {
|
498 |
+
print('
|
499 |
+
<div id="message" class="updated fade">
|
500 |
+
<p>' . __('You do not have enough permission to set the option. Please contact your admin.', 'TweetOldPost') . '</p>
|
501 |
+
</div>');
|
502 |
+
}
|
503 |
+
}
|
504 |
+
|
505 |
+
function top_opt_optionselected($opValue, $value) {
|
506 |
+
if ($opValue == $value) {
|
507 |
+
return 'selected="selected"';
|
508 |
+
}
|
509 |
+
return '';
|
510 |
+
}
|
511 |
+
|
512 |
+
function top_opt_head_admin() {
|
513 |
+
$home = get_settings('siteurl');
|
514 |
+
$base = '/' . end(explode('/', str_replace(array('\\', '/top-admin.php'), array('/', ''), __FILE__)));
|
515 |
+
$stylesheet = $home . '/wp-content/plugins' . $base . '/css/tweet-old-post.css';
|
516 |
+
echo('<link rel="stylesheet" href="' . $stylesheet . '" type="text/css" media="screen" />');
|
517 |
+
}
|
518 |
+
|
519 |
+
?>
|
top-core.php
ADDED
@@ -0,0 +1,313 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once( 'Include/oauth.php' );
|
4 |
+
global $top_oauth;
|
5 |
+
$top_oauth = new TOPOAuth;
|
6 |
+
|
7 |
+
function top_tweet_old_post() {
|
8 |
+
//check last tweet time against set interval and span
|
9 |
+
if (top_opt_update_time ()) {
|
10 |
+
update_option('top_opt_last_update', time());
|
11 |
+
top_opt_tweet_old_post();
|
12 |
+
}
|
13 |
+
}
|
14 |
+
|
15 |
+
//get random post and tweet
|
16 |
+
function top_opt_tweet_old_post() {
|
17 |
+
global $wpdb;
|
18 |
+
$omitCats = get_option('top_opt_omit_cats');
|
19 |
+
$maxAgeLimit = get_option('top_opt_max_age_limit');
|
20 |
+
$ageLimit = get_option('top_opt_age_limit');
|
21 |
+
$exposts = get_option('top_opt_excluded_post');
|
22 |
+
$exposts = preg_replace('/,,+/', ',', $exposts);
|
23 |
+
if (substr($exposts, 0, 1) == ",") {
|
24 |
+
$exposts = substr($exposts, 1, strlen($exposts));
|
25 |
+
}
|
26 |
+
if (substr($exposts, -1, 1) == ",") {
|
27 |
+
$exposts = substr($exposts, 0, strlen($exposts) - 1);
|
28 |
+
}
|
29 |
+
|
30 |
+
if (!(isset($ageLimit) && is_numeric($ageLimit))) {
|
31 |
+
$ageLimit = top_opt_AGE_LIMIT;
|
32 |
+
}
|
33 |
+
|
34 |
+
if (!(isset($maxAgeLimit) && is_numeric($maxAgeLimit))) {
|
35 |
+
$maxAgeLimit = top_opt_MAX_AGE_LIMIT;
|
36 |
+
}
|
37 |
+
if (!isset($omitCats)) {
|
38 |
+
$omitCats = top_opt_OMIT_CATS;
|
39 |
+
}
|
40 |
+
|
41 |
+
$sql = "SELECT ID
|
42 |
+
FROM $wpdb->posts
|
43 |
+
WHERE post_type = 'post'
|
44 |
+
AND post_status = 'publish'
|
45 |
+
AND post_date <= curdate( ) - INTERVAL " . $ageLimit . " day";
|
46 |
+
|
47 |
+
if ($maxAgeLimit != 0) {
|
48 |
+
$sql = $sql . " AND post_date >= curdate( ) - INTERVAL " . $maxAgeLimit . " day";
|
49 |
+
}
|
50 |
+
if (isset($exposts)) {
|
51 |
+
if(trim($exposts) != '')
|
52 |
+
{
|
53 |
+
$sql = $sql . " AND ID Not IN (" . $exposts . ") ";
|
54 |
+
}
|
55 |
+
}
|
56 |
+
if ($omitCats != '') {
|
57 |
+
$sql = $sql . " AND NOT (ID IN (SELECT tr.object_id FROM wp_term_relationships AS tr INNER JOIN wp_term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy = 'category' AND tt.term_id IN (" . $omitCats . ")))";
|
58 |
+
}
|
59 |
+
$sql = $sql . "
|
60 |
+
ORDER BY RAND()
|
61 |
+
LIMIT 1 ";
|
62 |
+
|
63 |
+
$oldest_post = $wpdb->get_var($sql);
|
64 |
+
if ($oldest_post == null) {
|
65 |
+
return "No post found to tweet. Please check your settings and try again.";
|
66 |
+
}
|
67 |
+
if (isset($oldest_post)) {
|
68 |
+
return top_opt_tweet_post($oldest_post);
|
69 |
+
}
|
70 |
+
}
|
71 |
+
|
72 |
+
//tweet for the passed random post
|
73 |
+
function top_opt_tweet_post($oldest_post) {
|
74 |
+
$post = get_post($oldest_post);
|
75 |
+
$content = null;
|
76 |
+
$permalink = get_permalink($oldest_post);
|
77 |
+
$add_data = get_option("top_opt_add_data");
|
78 |
+
$twitter_hashtags = get_option('top_opt_hashtags');
|
79 |
+
$url_shortener = get_option('top_opt_url_shortener');
|
80 |
+
$to_short_url = true;
|
81 |
+
|
82 |
+
$custom_url_option = get_option('top_opt_custom_url_option');
|
83 |
+
$to_short_url = get_option('top_opt_use_url_shortner');
|
84 |
+
|
85 |
+
if ($custom_url_option) {
|
86 |
+
$custom_url_field = get_option('top_opt_custom_url_field');
|
87 |
+
if (trim($custom_url_field) != "") {
|
88 |
+
$permalink = trim(get_post_meta($post->ID, $custom_url_field, true));
|
89 |
+
}
|
90 |
+
}
|
91 |
+
|
92 |
+
if ($to_short_url) {
|
93 |
+
|
94 |
+
if ($url_shortener == "bit.ly") {
|
95 |
+
$bitly_key = get_option('top_opt_bitly_key');
|
96 |
+
$bitly_user = get_option('top_opt_bitly_user');
|
97 |
+
$shorturl = shorten_url($permalink, $url_shortener, $bitly_key, $bitly_user);
|
98 |
+
} else {
|
99 |
+
$shorturl = shorten_url($permalink, $url_shortener);
|
100 |
+
}
|
101 |
+
} else {
|
102 |
+
$shorturl = $permalink;
|
103 |
+
}
|
104 |
+
$prefix = get_option('top_opt_tweet_prefix');
|
105 |
+
|
106 |
+
if ($add_data == "true") {
|
107 |
+
$content = stripslashes($post->post_content);
|
108 |
+
$content = strip_tags($content);
|
109 |
+
$content = preg_replace('/\s\s+/', ' ', $content);
|
110 |
+
$content = " - " . $content;
|
111 |
+
} else {
|
112 |
+
$content = "";
|
113 |
+
}
|
114 |
+
|
115 |
+
|
116 |
+
if (!is_numeric($shorturl) && (strncmp($shorturl, "http", strlen("http")) == 0)) {
|
117 |
+
if ($prefix) {
|
118 |
+
$message = $prefix . ": " . $post->post_title;
|
119 |
+
} else {
|
120 |
+
$message = $post->post_title;
|
121 |
+
}
|
122 |
+
|
123 |
+
$message = set_tweet_length($message . $content, $shorturl, $twitter_hashtags);
|
124 |
+
$status = urlencode(stripslashes(urldecode($message)));
|
125 |
+
if ($status) {
|
126 |
+
$poststatus = top_update_status($message);
|
127 |
+
if ($poststatus == true)
|
128 |
+
return "Whoopie!!! Tweet Posted Successfully";
|
129 |
+
else
|
130 |
+
return "OOPS!!! there seems to be some problem while tweeting. If problem continues please try re-authorizing your acount again.<br/> First Deauthorize and then authorize again and check.";
|
131 |
+
}
|
132 |
+
return "OOPS!!! there seems to be some problem while tweeting. Try again. If problem is persistent mail the problem at ajay@ajaymatharu.com";
|
133 |
+
}
|
134 |
+
return "OOPS!!! problem with your URL shortning service. Some signs of error " . $shorturl . ".";
|
135 |
+
}
|
136 |
+
|
137 |
+
//send request to passed url and return the response
|
138 |
+
function send_request($url, $method='GET', $data='', $auth_user='', $auth_pass='') {
|
139 |
+
$ch = curl_init($url);
|
140 |
+
if (strtoupper($method) == "POST") {
|
141 |
+
curl_setopt($ch, CURLOPT_POST, 1);
|
142 |
+
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
143 |
+
}
|
144 |
+
if (ini_get('open_basedir') == '' && ini_get('safe_mode') == 'Off') {
|
145 |
+
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
|
146 |
+
}
|
147 |
+
curl_setopt($ch, CURLOPT_HEADER, 0);
|
148 |
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
149 |
+
if ($auth_user != '' && $auth_pass != '') {
|
150 |
+
curl_setopt($ch, CURLOPT_USERPWD, "{$auth_user}:{$auth_pass}");
|
151 |
+
}
|
152 |
+
$response = curl_exec($ch);
|
153 |
+
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
154 |
+
curl_close($ch);
|
155 |
+
if ($httpcode != 200) {
|
156 |
+
return $httpcode;
|
157 |
+
}
|
158 |
+
|
159 |
+
return $response;
|
160 |
+
}
|
161 |
+
|
162 |
+
//Shorten long URLs with is.gd or bit.ly.
|
163 |
+
function shorten_url($the_url, $shortener='is.gd', $api_key='', $user='') {
|
164 |
+
|
165 |
+
if (($shortener == "bit.ly") && isset($api_key) && isset($user)) {
|
166 |
+
$url = "http://api.bit.ly/shorten?version=2.0.1&longUrl={$the_url}&login={$user}&apiKey={$api_key}&format=xml";
|
167 |
+
$response = send_request($url, 'GET');
|
168 |
+
|
169 |
+
$the_results = new SimpleXmlElement($response);
|
170 |
+
if ($the_results->errorCode == '0') {
|
171 |
+
$response = $the_results->results->nodeKeyVal->shortUrl;
|
172 |
+
} else {
|
173 |
+
$response = "";
|
174 |
+
}
|
175 |
+
} elseif ($shortener == "su.pr") {
|
176 |
+
$url = "http://su.pr/api/simpleshorten?url={$the_url}";
|
177 |
+
$response = send_request($url, 'GET');
|
178 |
+
} elseif ($shortener == "tr.im") {
|
179 |
+
$url = "http://api.tr.im/api/trim_simple?url={$the_url}";
|
180 |
+
$response = send_request($url, 'GET');
|
181 |
+
} elseif ($shortener == "3.ly") {
|
182 |
+
$url = "http://3.ly/?api=em5893833&u={$the_url}";
|
183 |
+
$response = send_request($url, 'GET');
|
184 |
+
} elseif ($shortener == "tinyurl") {
|
185 |
+
$url = "http://tinyurl.com/api-create.php?url={$the_url}";
|
186 |
+
$response = send_request($url, 'GET');
|
187 |
+
} elseif ($shortener == "u.nu") {
|
188 |
+
$url = "http://u.nu/unu-api-simple?url={$the_url}";
|
189 |
+
$response = send_request($url, 'GET');
|
190 |
+
} elseif ($shortener == "1click.at") {
|
191 |
+
$url = "http://1click.at/api.php?action=shorturl&url={$the_url}&format=simple";
|
192 |
+
$response = send_request($url, 'GET');
|
193 |
+
} else {
|
194 |
+
$url = "http://is.gd/api.php?longurl={$the_url}";
|
195 |
+
$response = send_request($url, 'GET');
|
196 |
+
}
|
197 |
+
|
198 |
+
return $response;
|
199 |
+
}
|
200 |
+
|
201 |
+
//Shrink a tweet and accompanying URL down to 140 chars.
|
202 |
+
function set_tweet_length($message, $url, $twitter_hashtags="") {
|
203 |
+
|
204 |
+
$message_length = strlen($message);
|
205 |
+
$url_length = strlen($url);
|
206 |
+
$hashtags_length = strlen($twitter_hashtags);
|
207 |
+
if ($message_length + $url_length + $hashtags_length > 140) {
|
208 |
+
$shorten_message_to = 140 - $url_length - $hashtags_length;
|
209 |
+
$shorten_message_to = $shorten_message_to - 4;
|
210 |
+
//$message = $message." ";
|
211 |
+
$message = substr($message, 0, $shorten_message_to);
|
212 |
+
$message = substr($message, 0, strrpos($message, ' '));
|
213 |
+
$message = $message . "...";
|
214 |
+
}
|
215 |
+
return $message . " " . $url . " " . $twitter_hashtags;
|
216 |
+
}
|
217 |
+
|
218 |
+
//check time and update the last tweet time
|
219 |
+
function top_opt_update_time() {
|
220 |
+
$last = get_option('top_opt_last_update');
|
221 |
+
$interval = get_option('top_opt_interval');
|
222 |
+
$slop = get_option('top_opt_interval_slop');
|
223 |
+
|
224 |
+
if (!(isset($interval) && is_numeric($interval))) {
|
225 |
+
$interval = top_opt_INTERVAL;
|
226 |
+
}
|
227 |
+
|
228 |
+
if (!(isset($slop) && is_numeric($slop))) {
|
229 |
+
$slop = top_opt_INTERVAL_SLOP;
|
230 |
+
}
|
231 |
+
$interval = $interval * 60 * 60;
|
232 |
+
$slop = $slop * 60 * 60;
|
233 |
+
if (false === $last) {
|
234 |
+
$ret = 1;
|
235 |
+
} else if (is_numeric($last)) {
|
236 |
+
$ret = ( (time() - $last) > ($interval + rand(0, $slop)));
|
237 |
+
}
|
238 |
+
return $ret;
|
239 |
+
}
|
240 |
+
|
241 |
+
function top_get_auth_url() {
|
242 |
+
global $top_oauth;
|
243 |
+
$settings = top_get_settings();
|
244 |
+
|
245 |
+
$token = $top_oauth->get_request_token();
|
246 |
+
if ($token) {
|
247 |
+
$settings['oauth_request_token'] = $token['oauth_token'];
|
248 |
+
$settings['oauth_request_token_secret'] = $token['oauth_token_secret'];
|
249 |
+
|
250 |
+
top_save_settings($settings);
|
251 |
+
|
252 |
+
return $top_oauth->get_auth_url($token['oauth_token']);
|
253 |
+
}
|
254 |
+
}
|
255 |
+
|
256 |
+
function top_update_status($new_status) {
|
257 |
+
global $top_oauth;
|
258 |
+
$settings = top_get_settings();
|
259 |
+
|
260 |
+
if (isset($settings['oauth_access_token']) && isset($settings['oauth_access_token_secret'])) {
|
261 |
+
return $top_oauth->update_status($settings['oauth_access_token'], $settings['oauth_access_token_secret'], $new_status);
|
262 |
+
}
|
263 |
+
|
264 |
+
return false;
|
265 |
+
}
|
266 |
+
|
267 |
+
function top_has_tokens() {
|
268 |
+
$settings = top_get_settings();
|
269 |
+
|
270 |
+
return ( $settings['oauth_access_token'] && $settings['oauth_access_token_secret'] );
|
271 |
+
}
|
272 |
+
|
273 |
+
function top_is_valid() {
|
274 |
+
return twit_has_tokens();
|
275 |
+
}
|
276 |
+
|
277 |
+
function top_do_tweet($post_id) {
|
278 |
+
$settings = top_get_settings();
|
279 |
+
|
280 |
+
$message = top_get_message($post_id);
|
281 |
+
|
282 |
+
// If we have a valid message, Tweet it
|
283 |
+
// this will fail if the Tiny URL service is done
|
284 |
+
if ($message) {
|
285 |
+
// If we successfully posted this to Twitter, then we can remove it from the queue eventually
|
286 |
+
if (twit_update_status($message)) {
|
287 |
+
return true;
|
288 |
+
}
|
289 |
+
}
|
290 |
+
|
291 |
+
return false;
|
292 |
+
}
|
293 |
+
|
294 |
+
function top_get_settings() {
|
295 |
+
global $top_defaults;
|
296 |
+
|
297 |
+
$settings = $top_defaults;
|
298 |
+
|
299 |
+
$wordpress_settings = get_option('top_settings');
|
300 |
+
if ($wordpress_settings) {
|
301 |
+
foreach ($wordpress_settings as $key => $value) {
|
302 |
+
$settings[$key] = $value;
|
303 |
+
}
|
304 |
+
}
|
305 |
+
|
306 |
+
return $settings;
|
307 |
+
}
|
308 |
+
|
309 |
+
function top_save_settings($settings) {
|
310 |
+
update_option('top_settings', $settings);
|
311 |
+
}
|
312 |
+
|
313 |
+
?>
|
top-excludepost.php
ADDED
@@ -0,0 +1,326 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once('tweet-old-post.php');
|
4 |
+
require_once('top-core.php');
|
5 |
+
require_once( 'Include/oauth.php' );
|
6 |
+
require_once('xml.php');
|
7 |
+
|
8 |
+
function top_exclude() {
|
9 |
+
|
10 |
+
$message = null;
|
11 |
+
$message_updated = __("Tweet Old Post Options Updated.", 'TweetOldPost');
|
12 |
+
$response = null;
|
13 |
+
$records_per_page = 20;
|
14 |
+
$omit_cat=get_option('top_opt_omit_cats');
|
15 |
+
$update_text = "Exclude Selected";
|
16 |
+
$search_term="";
|
17 |
+
$ex_filter="all";
|
18 |
+
$cat_filter=0;
|
19 |
+
|
20 |
+
global $wpdb;
|
21 |
+
|
22 |
+
if ((!isset($_GET["paged"])) && (!isset($_POST["delids"]))) {
|
23 |
+
$exposts = get_option('top_opt_excluded_post');
|
24 |
+
} else {
|
25 |
+
$exposts = $_POST["delids"];
|
26 |
+
}
|
27 |
+
|
28 |
+
$exposts = preg_replace('/,,+/', ',', $exposts);
|
29 |
+
if (substr($exposts, 0, 1) == ",") {
|
30 |
+
$exposts = substr($exposts, 1, strlen($exposts));
|
31 |
+
}
|
32 |
+
if (substr($exposts, -1, 1) == ",") {
|
33 |
+
$exposts = substr($exposts, 0, strlen($exposts) - 1);
|
34 |
+
}
|
35 |
+
$excluded_posts = explode(",", $exposts);
|
36 |
+
|
37 |
+
|
38 |
+
if (!isset($_GET['paged']))
|
39 |
+
$_GET['paged'] = 1;
|
40 |
+
|
41 |
+
if (isset($_POST["excludeall"])) {
|
42 |
+
if (substr($_POST["delids"], 0, -1) == "") {
|
43 |
+
print('
|
44 |
+
<div id="message" style="margin-top:30px" class="updated fade">
|
45 |
+
<p>' . __('No post selected please select a post to be excluded.', 'TweetOldPost') . '</p>
|
46 |
+
</div>');
|
47 |
+
} else {
|
48 |
+
|
49 |
+
update_option('top_opt_excluded_post',$exposts);
|
50 |
+
print('
|
51 |
+
<div id="message" style="margin-top:30px" class="updated fade">
|
52 |
+
<p>' . __('Posts excluded successfully.', 'TweetOldPost') . '</p>
|
53 |
+
</div>');
|
54 |
+
}
|
55 |
+
}
|
56 |
+
|
57 |
+
print('
|
58 |
+
<div id="help" style="overflow: hidden;padding-left:15px; font-size: 14px; margin-top: 25px; background-color: rgb(239, 239, 239);">
|
59 |
+
<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>
|
60 |
+
</div>');
|
61 |
+
|
62 |
+
print('
|
63 |
+
<div id="help" style="overflow: hidden;padding-left:15px; font-size: 14px; margin-top: 25px;margin-bottom:25px; background-color: rgb(239, 239, 239);">
|
64 |
+
<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>
|
65 |
+
</div>');
|
66 |
+
|
67 |
+
$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'
|
68 |
+
AND post_status = 'publish'";
|
69 |
+
|
70 |
+
//$sql = $sql . " and p.ID NOT IN ( SELECT tr.object_id FROM wp_term_relationships AS tr INNER JOIN wp_term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy = 'category' AND tt.term_id IN (" . $omit_cat . "))";
|
71 |
+
if(isset($_POST["setFilter"]))
|
72 |
+
{
|
73 |
+
if($_POST["cat"] != 0)
|
74 |
+
{
|
75 |
+
$sql = $sql . " and p.ID IN ( SELECT tr.object_id FROM wp_term_relationships AS tr INNER JOIN wp_term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy = 'category' AND tt.term_id=" . $_POST["cat"] . ")";
|
76 |
+
$cat_filter = $_POST["cat"];
|
77 |
+
}
|
78 |
+
else
|
79 |
+
{
|
80 |
+
$sql = $sql . " and p.ID NOT IN ( SELECT tr.object_id FROM wp_term_relationships AS tr INNER JOIN wp_term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy = 'category' AND tt.term_id IN (" . $omit_cat . "))";
|
81 |
+
$cat_filter = 0;
|
82 |
+
}
|
83 |
+
|
84 |
+
if($_POST["selFilter"] == "excluded")
|
85 |
+
{
|
86 |
+
$sql = $sql . " and p.ID IN (".$exposts.")";
|
87 |
+
$update_text = "Update";
|
88 |
+
$ex_filter = "excluded";
|
89 |
+
}
|
90 |
+
|
91 |
+
}
|
92 |
+
else
|
93 |
+
{
|
94 |
+
$sql = $sql . " and p.ID NOT IN ( SELECT tr.object_id FROM wp_term_relationships AS tr INNER JOIN wp_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 |
+
}
|
96 |
+
|
97 |
+
if(isset($_POST["s"]))
|
98 |
+
{
|
99 |
+
if(trim( $_POST["s"]) != "")
|
100 |
+
{
|
101 |
+
$sql = $sql . " and post_title like '%" . trim( $_POST["s"]) . "%'";
|
102 |
+
$search_term = trim( $_POST["s"]);
|
103 |
+
}
|
104 |
+
}
|
105 |
+
|
106 |
+
$sql = $sql . " order by post_date desc";
|
107 |
+
$posts = $wpdb->get_results($sql);
|
108 |
+
|
109 |
+
$from = $_GET["paged"] * $records_per_page - $records_per_page;
|
110 |
+
$to = min($_GET['paged'] * $records_per_page, count($posts));
|
111 |
+
$post_count =count($posts);
|
112 |
+
|
113 |
+
$ex = 0;
|
114 |
+
for ($j = 0; $j < $post_count; $j++) {
|
115 |
+
if (in_array($posts[$j]->ID, $excluded_posts)) {
|
116 |
+
$excludeList[$ex] = $posts[$j]->ID;
|
117 |
+
$ex = $ex + 1;
|
118 |
+
}
|
119 |
+
}
|
120 |
+
if($excludeList.length >0)
|
121 |
+
{
|
122 |
+
$exposts = implode(",",$excludeList);
|
123 |
+
}
|
124 |
+
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="" /> ');
|
125 |
+
print('<div class="tablenav"><div class="alignleft actions">');
|
126 |
+
print('<input type="submit" class="button-secondary" name="excludeall" value="' . __($update_text, 'TweetOldPost') . '" />');
|
127 |
+
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>');
|
128 |
+
$dropdown_options = array('show_option_all' => __('Selected Categories'),'exclude' =>$omit_cat,'selected' =>$cat_filter);
|
129 |
+
wp_dropdown_categories($dropdown_options);
|
130 |
+
print('<input type="submit" class="button-secondary" name="setFilter" value="' . __('Filter', 'TweetOldPost') . '" />');
|
131 |
+
print('<p class="search-box" style="margin:0px">
|
132 |
+
<input type="text" id="post-search-input" name="s" value="'.$search_term.'" />
|
133 |
+
<input type="submit" value="Search Posts" name="search" class="button" />
|
134 |
+
</p>');
|
135 |
+
print('</div>');
|
136 |
+
if (count($posts) > 0) {
|
137 |
+
$page_links = paginate_links(array(
|
138 |
+
'base' => add_query_arg('paged', '%#%'),
|
139 |
+
'format' => '',
|
140 |
+
'prev_text' => __('«'),
|
141 |
+
'next_text' => __('»'),
|
142 |
+
'total' => ceil(count($posts) / $records_per_page),
|
143 |
+
'current' => $_GET['paged']
|
144 |
+
));
|
145 |
+
|
146 |
+
if ($page_links) {
|
147 |
+
|
148 |
+
print('<div class="tablenav-pages">');
|
149 |
+
$page_links_text = sprintf('<span class="displaying-num">' . __('Displaying %s–%s of %s') . '</span>%s',
|
150 |
+
number_format_i18n(( $_GET['paged'] - 1 ) * $records_per_page + 1),
|
151 |
+
number_format_i18n(min($_GET['paged'] * $records_per_page, count($posts))),
|
152 |
+
number_format_i18n(count($posts)),
|
153 |
+
$page_links
|
154 |
+
);
|
155 |
+
echo $page_links_text;
|
156 |
+
print('</div>');
|
157 |
+
}
|
158 |
+
print('</div>');//tablenav div
|
159 |
+
|
160 |
+
print(' <div class="wrap">
|
161 |
+
<table class="widefat fixed">
|
162 |
+
<thead>
|
163 |
+
<tr>
|
164 |
+
<th class="manage-column column-cb check-column"><input name="headchkbx" onchange="javascript:checkedAll();" type="checkbox" value="checkall"/></th>
|
165 |
+
<th>No.</th>
|
166 |
+
<th>Id</th>
|
167 |
+
<th>Post Title</th>
|
168 |
+
<th>Author</th>
|
169 |
+
<th>Post Date</th>
|
170 |
+
<th>Categories</th>
|
171 |
+
</tr>
|
172 |
+
</thead>
|
173 |
+
<tbody>
|
174 |
+
');
|
175 |
+
|
176 |
+
|
177 |
+
|
178 |
+
|
179 |
+
for ($i = $from; $i < $to; $i++) {
|
180 |
+
$categories = get_the_category($posts[$i]->ID);
|
181 |
+
if (!empty($categories)) {
|
182 |
+
$out = array();
|
183 |
+
foreach ($categories as $c)
|
184 |
+
$out[] = "<a href='edit.php?post_type={$post->post_type}&category_name={$c->slug}'> " . esc_html(sanitize_term_field('name', $c->name, $c->term_id, 'category', 'display')) . "</a>";
|
185 |
+
$cats = join(', ', $out);
|
186 |
+
} else {
|
187 |
+
$cats = 'Uncategorized';
|
188 |
+
}
|
189 |
+
|
190 |
+
if (in_array($posts[$i]->ID, $excluded_posts)) {
|
191 |
+
$checked = "Checked";
|
192 |
+
$bgcolor="#FFCC99";
|
193 |
+
} else {
|
194 |
+
$checked = "";
|
195 |
+
$bgcolor="#FFF";
|
196 |
+
}
|
197 |
+
|
198 |
+
print('
|
199 |
+
|
200 |
+
<tr style="background-color:'.$bgcolor.';">
|
201 |
+
<th class="check-column">
|
202 |
+
<input type="checkbox" name="chkbx" id="del' . $posts[$i]->ID . '" onchange="javascript:managedelid(this,\'' . $posts[$i]->ID . '\');" value="' . $posts[$i]->ID . '" ' . $checked . '/>
|
203 |
+
</th>
|
204 |
+
<td>
|
205 |
+
' . ($i + 1) . '
|
206 |
+
</td>
|
207 |
+
<td>
|
208 |
+
' . $posts[$i]->ID . '
|
209 |
+
</td>
|
210 |
+
<td>
|
211 |
+
<a href=' . $posts[$i]->guid . ' target="_blank">' . $posts[$i]->post_title . '</a>
|
212 |
+
</td>
|
213 |
+
<td>
|
214 |
+
' . $posts[$i]->user_nicename . '
|
215 |
+
</td>
|
216 |
+
<td>
|
217 |
+
' . $posts[$i]->post_date . '
|
218 |
+
</td>
|
219 |
+
<td>
|
220 |
+
' . $cats . '
|
221 |
+
</td>
|
222 |
+
</tr>
|
223 |
+
|
224 |
+
');
|
225 |
+
}
|
226 |
+
print('
|
227 |
+
</tbody>
|
228 |
+
</table>
|
229 |
+
</div>
|
230 |
+
');
|
231 |
+
|
232 |
+
print('<div class="tablenav"><div class="alignleft actions"><input type="submit" class="button-secondary" name="excludeall" value="' . __($update_text, 'TweetOldPost') . '" /></div>');
|
233 |
+
|
234 |
+
if ($page_links) {
|
235 |
+
|
236 |
+
print('<div class="tablenav-pages">');
|
237 |
+
$page_links_text = sprintf('<span class="displaying-num">' . __('Displaying %s–%s of %s') . '</span>%s',
|
238 |
+
number_format_i18n(( $_GET['paged'] - 1 ) * $records_per_page + 1),
|
239 |
+
number_format_i18n(min($_GET['paged'] * $records_per_page, count($posts))),
|
240 |
+
number_format_i18n(count($posts)),
|
241 |
+
$page_links
|
242 |
+
);
|
243 |
+
echo $page_links_text;
|
244 |
+
print('</div>');
|
245 |
+
}
|
246 |
+
print('</div>');
|
247 |
+
|
248 |
+
|
249 |
+
|
250 |
+
print('
|
251 |
+
<script language="javascript">
|
252 |
+
|
253 |
+
|
254 |
+
jQuery(function() {
|
255 |
+
jQuery(".page-numbers").click(function(e){
|
256 |
+
jQuery("#top_TweetOldPost").attr("action",jQuery(this).attr("href"));
|
257 |
+
e.preventDefault();
|
258 |
+
jQuery("#pageit").click();
|
259 |
+
});// page number click end
|
260 |
+
});//jquery document.ready end
|
261 |
+
|
262 |
+
function setExcludeList(exlist)
|
263 |
+
{
|
264 |
+
jQuery("#excludeList").html("\"" + exlist + "\"");
|
265 |
+
}
|
266 |
+
|
267 |
+
|
268 |
+
function managedelid(ctrl,id)
|
269 |
+
{
|
270 |
+
|
271 |
+
var delids = document.getElementById("delids").value;
|
272 |
+
if(ctrl.checked)
|
273 |
+
{
|
274 |
+
delids=addId(delids,id);
|
275 |
+
}
|
276 |
+
else
|
277 |
+
{
|
278 |
+
delids=removeId(delids,id);
|
279 |
+
}
|
280 |
+
document.getElementById("delids").value=delids;
|
281 |
+
setExcludeList(delids);
|
282 |
+
}
|
283 |
+
|
284 |
+
function removeId(list, value) {
|
285 |
+
list = list.split(",");
|
286 |
+
if(list.indexOf(value) != -1)
|
287 |
+
list.splice(list.indexOf(value), 1);
|
288 |
+
return list.join(",");
|
289 |
+
}
|
290 |
+
|
291 |
+
|
292 |
+
function addId(list,value)
|
293 |
+
{
|
294 |
+
list = list.split(",");
|
295 |
+
if(list.indexOf(value) == -1)
|
296 |
+
list.push(value);
|
297 |
+
return list.join(",");
|
298 |
+
}
|
299 |
+
|
300 |
+
function checkedAll() {
|
301 |
+
var ischecked=document.top_TweetOldPost.headchkbx.checked;
|
302 |
+
var delids="";
|
303 |
+
for (var i = 0; i < document.top_TweetOldPost.chkbx.length; i++) {
|
304 |
+
document.top_TweetOldPost.chkbx[i].checked = ischecked;
|
305 |
+
if(ischecked)
|
306 |
+
delids=delids+document.top_TweetOldPost.chkbx[i].value+",";
|
307 |
+
}
|
308 |
+
document.getElementById("delids").value=delids;
|
309 |
+
}
|
310 |
+
|
311 |
+
setExcludeList("' . $exposts . '");
|
312 |
+
|
313 |
+
</script>
|
314 |
+
');
|
315 |
+
}
|
316 |
+
else
|
317 |
+
{
|
318 |
+
print('</div>');//tablenav div
|
319 |
+
print('
|
320 |
+
<div id="message" style="margin-top:30px" class="updated fade">
|
321 |
+
<p>' . __('No Posts found. Review your search or filter criteria/term.', 'TweetOldPost') . '</p>
|
322 |
+
</div>');
|
323 |
+
}
|
324 |
+
print('</form>');
|
325 |
+
}
|
326 |
+
?>
|
tweet-old-post.php
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.1.1
|
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 |
+
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_menu_page("Tweet Old Post", "Tweet Old Post", 1, "TweetOldPost", "top_admin");
|
37 |
+
add_submenu_page("TweetOldPost", __('Exclude Posts','TweetOldPost'), __('Exclude Posts','TweetOldPost'), 1, __('ExcludePosts','TweetOldPost'), 'top_exclude');
|
38 |
+
}
|
39 |
+
|
40 |
+
add_action('admin_menu', 'top_admin_actions');
|
41 |
+
add_action('admin_head', 'top_opt_head_admin');
|
42 |
+
add_action('init','top_tweet_old_post');
|
43 |
+
register_activation_hook(__FILE__, "top_on_activation");
|
44 |
+
|
45 |
+
function top_on_activation()
|
46 |
+
{
|
47 |
+
update_option('top_opt_interval', "4");
|
48 |
+
update_option('top_opt_interval_slop', "4");
|
49 |
+
update_option('top_opt_age_limit', "30");
|
50 |
+
update_option('top_opt_max_age_limit', "0");
|
51 |
+
}
|
52 |
+
?>
|
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 |
+
?>
|