PluginProbe
oik / 1.4
oik v1.4
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.4, at oik-tides.php

183 lines 7.4 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.4
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 */
115
116 function bw_time_of_day_secs() {
117 extract( localtime( time(), true ));
118 $secs = ((($tm_hour * 60) + $tm_min) * 60) + $tm_sec;
119 bw_trace( $secs, __FUNCTION__, __LINE__, __FILE__, 'secs' );
120 return( $secs );
121 }
122
123
124 /**
125 * display information about high and low tides obtained from www.tidetimes.org.uk
126 * the data is stored as transient data until midnight, after which we expect new figures for the next day
127 * If the site is going to display more than one set of tide information then you will need to indicate
128 * a special code for storing the information. I would have liked to have extracted the location from the
129 * tideurl but got distracted with set_transient crashing when passed a SimpleXML object.
130 */
131 function bw_tides( $atts ) {
132
133 bw_trace( $atts, __FUNCTION__, __LINE__, __FILE__, 'atts');
134 extract( shortcode_atts( array(
135 'tideurl' => 'http://www.tidetimes.org.uk/Chichester_Harbour.rss',
136 'store' => '1',
137 ), $atts ) );
138
139 bw_trace( $tideurl, __FUNCTION__, __LINE__, __FILE__, 'tideurl' );
140 bw_trace( $store, __FUNCTION__, __LINE__, __FILE__, 'store' );
141
142 $desc = get_transient( 'bw_tides_desc_'. $store );
143 $title = get_transient( 'bw_tides_title_'. $store );
144 $link = get_transient( 'bw_tides_link_'. $store );
145
146 if ( $desc === FALSE || $title === FALSE || $link === FALSE ) {
147 $tideinfo = bw_get_tide_info( $tideurl );
148 $channel = $tideinfo->channel;
149 bw_trace( $channel, __FUNCTION__, __LINE__, __FILE__, 'channel');
150 $link = (string) $channel->link;
151 bw_trace( $desc, __FUNCTION__, __LINE__, __FILE__, 'desc');
152
153 /* We may need to strip some unwanted advertising which appears in an anchor tag <a */
154 $desc = $channel->item->description;
155 $desc = preg_replace('/<a (.*?)<\/a>/', "\\2", $desc);
156 $allowed = array( 'b' => array(),
157 'br' => array()
158 );
159 $desc = wp_kses( $desc, $allowed );
160 $title = (string) $channel->item->title;
161 // $title = $channel->item->title; uncomment this to cause set_transient to fail
162
163 $secs = bw_time_of_day_secs();
164 $secs = 86400 - $secs;
165 set_transient( "bw_tides_desc_" . $store, $desc, $secs);
166 set_transient( "bw_tides_title_" . $store, $title, $secs);
167 set_transient( "bw_tides_link_" . $store, $link, $secs);
168 }
169 else {
170 // We got all the data from the transient store
171 }
172
173 bw_trace( $desc, __FUNCTION__, __LINE__, __FILE__, 'desc');
174 bw_trace( $title, __FUNCTION__, __LINE__, __FILE__, 'title');
175 bw_trace( $link, __FUNCTION__, __LINE__, __FILE__, 'link');
176
177 alink( "tides", $link , $desc , $title );
178
179
180 return( bw_ret());
181
182 }
183