PluginProbe
oik / 1.7
oik v1.7
1.10 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.2 1.3 1.3.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.0.1 2.1 2.2 2.3 2.4 2.5 2.5.1 All 71 releases
oik / oik-tides.php

oik-tides.php in oik 1.7, at oik-tides.php

218 lines 9.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php // (C) Copyright Bobbing Wide 2011
2
3
4 /*
5 Plugin Name: oik tides
6 Plugin URI: http://www.oik-plugins.com/oik
7 Description: Easy to use shortcode macro for tide times [bw_tides]
8 Version: 1.7
9 Author: bobbingwide
10 Author URI: http://www.bobbingwide.com
11 License: GPL2
12
13 Copyright 2010, 2011 Bobbing Wide (email : herb@bobbingwide.com )
14
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License version 2,
17 as published by the Free Software Foundation.
18
19 You may NOT assume that you can use any other version of the GPL.
20
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
25
26 The license for this software can likely be found here:
27 http://www.gnu.org/licenses/gpl-2.0.html
28
29 */
30
31
32 require_once( 'bobbfunc.inc' );
33 require_once( 'bobbingwide.inc' );
34
35
36 /**
37 * Code copied and cobbled from http://snippet.me/wordpress/wordpress-plugin-info-api/
38 * having referred to http://ckon.wordpress.com/2010/07/20/undocumented-wordpress-org-plugin-api/
39 * get XML information using simple xml load file
40 */
41 function bw_get_tide_info( $tide_url ) {
42 $request_url = urlencode($tide_url);
43 $response_xml = simplexml_load_file($request_url);
44 bw_trace( $response_xml, __FUNCTION__, __LINE__, __FILE__, "response_xml" );
45 return $response_xml;
46 }
47
48 add_shortcode( 'bw_tides', 'bw_tides' );
49
50
51 /**
52 * Obtain tide information using the shortcode [bw_tides tide_url='tide feed xml url']
53 * The format of the feed is expected to be as in the following output from bw_trace
54
55
56
57 C:\apache\htdocs\wordpress\wp-content\plugins\oik\oik-tides.php(45:0) 2011-04-29T12:11:51+00:00 bw_get_tide_info response_xml SimpleXMLElement Object
58 (
59 [@attributes] => Array
60 (
61 [version] => 2.0
62 )
63
64 [channel] => SimpleXMLElement Object
65 (
66 [title] => Chichester Harbour Tide Times
67 [link] => http://www.tidetimes.org.uk/Chichester_Harbour.html
68 [description] => Chichester Harbour tide times.
69 [lastBuildDate] => Fri, 29 Apr 2011 00:25:00 GMT
70 [language] => en-gb
71 [item] => SimpleXMLElement Object
72 (
73 [title] => Chichester Harbour tide times for 29th April 2011
74 [link] => http://www.tidetimes.org.uk/Chichester_Harbour.html
75 [guid] => http://www.tidetimes.org.uk/Chichester_Harbour.html
76 [pubDate] => Fri, 29 Apr 2011 00:25:00 GMT
77 [description] => Tide times and height information for<br/>Chichester Harbour on 29th April 2011.<br/><br/>01:58 - Low Tide, 1.6m<br/>09:14 - High Tide, 3.9m<br/>14:17 - Low Tide, 1.5m<br/>21:36 - High Tide, 4.2m<br/><br/>
78 )
79
80 )
81
82 )
83
84 as of 4th May the tideinfo->channel->item->description appeared to have additional Google Ad stuff
85
86
87 C:\apache\htdocs\wordpress\wp-content\plugins\oik\oik-tides.php(45:0) 2011-05-04T03:17:51+00:00 bw_get_tide_info response_xml SimpleXMLElement Object
88 (
89 [@attributes] => Array
90 (
91 [version] => 2.0
92 )
93
94 [channel] => SimpleXMLElement Object
95 (
96 [title] => Chichester Harbour Tide Times
97 [link] => http://www.tidetimes.org.uk/Chichester_Harbour.html
98 [description] => Chichester Harbour tide times.
99 [lastBuildDate] => Tue, 3 May 2011 00:08:00 GMT
100 [language] => en-gb
101 [item] => SimpleXMLElement Object
102 (
103 [title] => Chichester Harbour Tide Times for 4th May 2011
104 [link] => http://www.tidetimes.org.uk/Chichester_Harbour.html
105 [guid] => http://www.tidetimes.org.uk/Chichester_Harbour.html
106 [pubDate] => Tue, 3 May 2011 00:08:00 GMT
107 [description] => <b>Chichester Harbour Tide Times:</b><br/>High Tides: 00:50 (4.50m), 13:13 (4.50m)<br/>Low Tides: 06:06 (1.00m), 18:18 (1.20m).<br/><a href="http://www.tidetimes.org.uk/Chichester_Harbour.html" title="Chichester Harbour Tide Times">http://www.tidetimes.org.uk/Chichester_Harbour.html</a><br/><br/><script type="text/javascript"> google_ad_client = "ca-pub-4314088479570355"; google_ad_slot = "4669933729"; google_ad_width = 234; google_ad_height = 60; </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
108 )
109
110 )
111
112 )
113
114 from 28th October (first noticed) it changed again. The description was already formatted.
115 C:\apache\htdocs\wordpress\wp-content\plugins\oik\oik-tides.php(44:0) 2011-10-29T16:49:09+00:00 54 bw_get_tide_info response_xml SimpleXMLElement Object
116 (
117 [@attributes] => Array
118 (
119 [version] => 2.0
120 )
121
122 [channel] => SimpleXMLElement Object
123 (
124 [title] => Chichester Harbour (Entrance) Tide Times
125 [link] => http://www.tidetimes.org.uk/chichester-harbour-entrance-tide-times
126 [description] => Chichester Harbour (Entrance) tide times.
127 [lastBuildDate] => Sat, 29 Oct 2011 00:00:00 BST
128 [language] => en-gb
129 [item] => SimpleXMLElement Object
130 (
131 [title] => Chichester Harbour (Entrance) Tide Times for 29th October 2011
132 [link] => http://www.tidetimes.org.uk/chichester-harbour-entrance-tide-times
133 [guid] => http://www.tidetimes.org.uk/chichester-harbour-entrance-tide-times
134 [pubDate] => Sat, 29 Oct 2011 00:00:00 BST
135 [description] => <a href="http://www.tidetimes.org.uk" title="Tide Times">Tide Times</a> & Heights for<br/><a href="http://www.tidetimes.org.uk/chichester-harbour-entrance-tide-times" title="Chichester Harbour (Entrance) tide times">Chichester Harbour (Entrance)</a> on 29th October 2011<br/><br/>01:18 - High Tide (5.00m)<br/>06:40 - Low Tide (0.70m)<br/>13:38 - High Tide (5.00m)<br/>19:03 - Low Tide (0.70m)<br/>
136 )
137
138 )
139
140 )
141
142
143 */
144
145 function bw_time_of_day_secs() {
146 extract( localtime( time(), true ));
147 $secs = ((($tm_hour * 60) + $tm_min) * 60) + $tm_sec;
148 bw_trace( $secs, __FUNCTION__, __LINE__, __FILE__, 'secs' );
149 return( $secs );
150 }
151
152
153 /**
154 * display information about high and low tides obtained from www.tidetimes.org.uk
155 * the data is stored as transient data until midnight, after which we expect new figures for the next day
156 * If the site is going to display more than one set of tide information then you will need to indicate
157 * a special code for storing the information. I would have liked to have extracted the location from the
158 * tideurl but got distracted with set_transient crashing when passed a SimpleXML object.
159 */
160 function bw_tides( $atts ) {
161
162 bw_trace( $atts, __FUNCTION__, __LINE__, __FILE__, 'atts');
163 extract( shortcode_atts( array(
164 'tideurl' => 'http://www.tidetimes.org.uk/Chichester_Harbour.rss',
165 'store' => '1',
166 ), $atts ) );
167
168 bw_trace( $tideurl, __FUNCTION__, __LINE__, __FILE__, 'tideurl' );
169 bw_trace( $store, __FUNCTION__, __LINE__, __FILE__, 'store' );
170
171 $desc = get_transient( 'bw_tides_desc_'. $store );
172 $title = get_transient( 'bw_tides_title_'. $store );
173 $link = get_transient( 'bw_tides_link_'. $store );
174
175 if ( $desc === FALSE || $title === FALSE || $link === FALSE ) {
176 $tideinfo = bw_get_tide_info( $tideurl );
177 $channel = $tideinfo->channel;
178 bw_trace( $channel, __FUNCTION__, __LINE__, __FILE__, 'channel');
179 $link = (string) $channel->link;
180
181 /* cast to a string since otherwise there can be a problem with attempting to serialise a simpleXML elements */
182 $desc = (string) $channel->item->description;
183
184 bw_trace( $desc, __FUNCTION__, __LINE__, __FILE__, 'desc');
185 /* We may need to strip some unwanted advertising which appears in an anchor tag <a */
186 /*
187 $desc = preg_replace('/<a (.*?)<\/a>/', "\\2", $desc);
188 $allowed = array( 'b' => array(),
189 'br' => array()
190 );
191 $desc = wp_kses( $desc, $allowed );
192 */
193 $title = (string) $channel->item->title;
194 // $title = $channel->item->title; uncomment this to cause set_transient to fail
195
196 $secs = bw_time_of_day_secs();
197 $secs = 86400 - $secs;
198 set_transient( "bw_tides_desc_" . $store, $desc, $secs);
199 set_transient( "bw_tides_title_" . $store, $title, $secs);
200 set_transient( "bw_tides_link_" . $store, $link, $secs);
201 }
202 else {
203 // We got all the data from the transient store
204 }
205
206 bw_trace( $desc, __FUNCTION__, __LINE__, __FILE__, 'desc');
207 bw_trace( $title, __FUNCTION__, __LINE__, __FILE__, 'title');
208 bw_trace( $link, __FUNCTION__, __LINE__, __FILE__, 'link');
209
210 // Now that tidetimes.org.uk creates the links itself we only need to display the informaton in span
211 // with class tides, to allow for custom CSS styling
212 //alink( "tides", $link , $desc , $title );
213 sepan( "tides", $desc );
214
215 return( bw_ret());
216
217 }
218