|
1 <?php |
|
2 /* |
|
3 Plugin Name: WPtouch iPhone Theme |
|
4 Plugin URI: http://bravenewcode.com/wptouch |
|
5 Description: A plugin which formats your site with a mobile theme for the Apple <a href="http://www.apple.com/iphone/">iPhone</a> / <a href="http://www.apple.com/ipodtouch/">iPod touch</a>, <a href="http://www.android.com/">Google Android</a> and other touch-based smartphones. |
|
6 Author: Dale Mugford & Duane Storey (BraveNewCode) |
|
7 Version: 1.9.7.6 |
|
8 Author URI: http://www.bravenewcode.com |
|
9 |
|
10 # Thanks to ContentRobot and the iWPhone theme/plugin |
|
11 # which the detection feature of the plugin was based on. |
|
12 # (http://iwphone.contentrobot.com/) |
|
13 |
|
14 # Also thanks to Henrik Urlund, who's "Prowl Me" plugin inspired |
|
15 # the Push notification additions. |
|
16 # (http://codework.dk/referencer/wp-plugins/prowl-me/) |
|
17 |
|
18 # All Admin and theme design / CSS is Copyright (c) 2007-2010 |
|
19 # Duane Storey & Dale Mugford of BraveNewCode Inc. |
|
20 # |
|
21 # 'WPtouch' is an unregistered trademark of BraveNewCode Inc., |
|
22 # and may not be used in conjuction with this software without permission. |
|
23 |
|
24 # The code in this plugin is free software; you can redistribute the code aspects of |
|
25 # the plugin and/or modify the code under the terms of the GNU Lesser General |
|
26 # Public License as published by the Free Software Foundation; either |
|
27 # version 2.1 of the License, or (at your option) any later version. |
|
28 |
|
29 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
30 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|
31 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
32 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
|
33 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
|
34 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
|
35 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
36 # |
|
37 # See the GNU lesser General Public License for more details. |
|
38 */ |
|
39 |
|
40 |
|
41 global $bnc_wptouch_version; |
|
42 $bnc_wptouch_version = '1.9.7.6'; |
|
43 |
|
44 require_once( 'include/plugin.php' ); |
|
45 require_once( 'include/compat.php' ); |
|
46 |
|
47 define( 'WPTOUCH_PROWL_APPNAME', 'WPtouch'); |
|
48 |
|
49 function wp_touch_get_comment_count() { |
|
50 global $wpdb; |
|
51 global $post; |
|
52 |
|
53 $result = $wpdb->get_row( $wpdb->prepare( "SELECT count(*) as c FROM {$wpdb->comments} WHERE comment_type = '' AND comment_approved = 1 AND comment_post_ID = %d", $post->ID ) ); |
|
54 if ( $result ) { |
|
55 return $result->c; |
|
56 } else { |
|
57 return 0; |
|
58 } |
|
59 } |
|
60 |
|
61 |
|
62 //The WPtouch Settings Defaults |
|
63 global $wptouch_defaults; |
|
64 $wptouch_defaults = array( |
|
65 'header-title' => get_bloginfo('name'), |
|
66 'main_title' => 'Default.png', |
|
67 'enable-post-excerpts' => true, |
|
68 'enable-page-coms' => false, |
|
69 'enable-cats-button' => true, |
|
70 'enable-tags-button' => true, |
|
71 'enable-search-button' => true, |
|
72 'enable-login-button' => false, |
|
73 'enable-ajax-comments' => true, |
|
74 'enable-gravatars' => true, |
|
75 'enable-main-home' => true, |
|
76 'enable-main-rss' => true, |
|
77 'enable-main-name' => true, |
|
78 'enable-main-tags' => true, |
|
79 'enable-main-categories' => true, |
|
80 'enable-main-email' => true, |
|
81 // Prowl |
|
82 'prowl-api' => '', |
|
83 'enable-prowl-comments-button' => false, |
|
84 'enable-prowl-users-button' => false, |
|
85 'enable-prowl-message-button' => false, |
|
86 // |
|
87 'header-background-color' => '000000', |
|
88 'header-border-color' => '333333', |
|
89 'header-text-color' => 'eeeeee', |
|
90 'link-color' => '006bb3', |
|
91 // New |
|
92 'post-cal-thumb' =>'calendar-icons', |
|
93 'h2-font' =>'Helvetica Neue', |
|
94 // |
|
95 'style-text-justify' => 'full-justified', |
|
96 'style-background' => 'classic-wptouch-bg', |
|
97 'enable-regular-default' => false, |
|
98 'excluded-cat-ids' => '', |
|
99 'home-page' => 0, |
|
100 'enable-exclusive' => false, |
|
101 'sort-order' => 'name', |
|
102 'adsense-id' => '', |
|
103 'statistics' => '', |
|
104 'adsense-channel' => '', |
|
105 'custom-user-agents' => array(), |
|
106 'enable-show-tweets' => false, |
|
107 'enable-gigpress-button' => false |
|
108 ); |
|
109 |
|
110 function wptouch_get_plugin_dir_name() { |
|
111 global $wptouch_plugin_dir_name; |
|
112 return $wptouch_plugin_dir_name; |
|
113 } |
|
114 |
|
115 function wptouch_delete_icon( $icon ) { |
|
116 if ( !current_user_can( 'upload_files' ) ) { |
|
117 // don't allow users to delete who don't have access to upload (security feature) |
|
118 return; |
|
119 } |
|
120 |
|
121 $dir = explode( 'wptouch', $icon ); |
|
122 $loc = compat_get_upload_dir() . "/wptouch/" . ltrim( $dir[1], '/' ); |
|
123 |
|
124 unlink( $loc ); |
|
125 } |
|
126 |
|
127 function wptouch_init() { |
|
128 if ( isset( $_GET['delete_icon'] ) ) { |
|
129 wptouch_delete_icon( $_GET['delete_icon'] ); |
|
130 header( 'Location: ' . get_bloginfo('wpurl') . '/wp-admin/options-general.php?page=wptouch/wptouch.php#available_icons' ); |
|
131 die; |
|
132 } |
|
133 |
|
134 } |
|
135 |
|
136 function wptouch_include_adsense() { |
|
137 global $wptouch_plugin; |
|
138 $settings = bnc_wptouch_get_settings(); |
|
139 if ( bnc_is_iphone() && $wptouch_plugin->desired_view == 'mobile' && isset( $settings['adsense-id'] ) && strlen( $settings['adsense-id'] ) && is_single() ) { |
|
140 global $wptouch_settings; |
|
141 $wptouch_settings = $settings; |
|
142 |
|
143 include( 'include/adsense-new.php' ); |
|
144 } |
|
145 } |
|
146 |
|
147 function wptouch_content_filter( $content ) { |
|
148 global $wptouch_plugin; |
|
149 $settings = bnc_wptouch_get_settings(); |
|
150 if ( bnc_is_iphone() && $wptouch_plugin->desired_view == 'mobile' && isset($settings['adsense-id']) && strlen($settings['adsense-id']) && is_single() ) { |
|
151 global $wptouch_settings; |
|
152 $wptouch_settings = $settings; |
|
153 |
|
154 ob_start(); |
|
155 include( 'include/adsense-new.php' ); |
|
156 $ad_contents = ob_get_contents(); |
|
157 ob_end_clean(); |
|
158 |
|
159 return '<div class="wptouch-adsense-ad">' . $ad_contents . '</div>' . $content; |
|
160 } else { |
|
161 return $content; |
|
162 } |
|
163 } |
|
164 |
|
165 add_filter('init', 'wptouch_init'); |
|
166 |
|
167 function WPtouch($before = '', $after = '') { |
|
168 global $bnc_wptouch_version; |
|
169 echo $before . 'WPtouch ' . $bnc_wptouch_version . $after; |
|
170 } |
|
171 |
|
172 //Add a link to settings on the plugin listings page |
|
173 function wptouch_settings_link( $links, $file ) { |
|
174 if( $file == 'wptouch/wptouch.php' && function_exists( "admin_url" ) ) { |
|
175 $settings_link = '<a href="' . admin_url( 'options-general.php?page=wptouch/wptouch.php' ) . '">' . __('Settings') . '</a>'; |
|
176 array_unshift( $links, $settings_link ); // before other links |
|
177 } |
|
178 return $links; |
|
179 } |
|
180 |
|
181 // WP Admin stylesheets & javascript |
|
182 function wptouch_admin_files() { |
|
183 if ( isset( $_GET['page'] ) && $_GET['page'] == 'wptouch/wptouch.php' ) { |
|
184 echo "<link rel='stylesheet' type='text/css' href='" . compat_get_plugin_url( 'wptouch' ) . "/admin-css/wptouch-admin.css' />\n"; |
|
185 echo "<link rel='stylesheet' type='text/css' href='" . compat_get_plugin_url( 'wptouch' ) . "/admin-css/bnc-global.css' />\n"; |
|
186 echo "<link rel='stylesheet' type='text/css' href='" . compat_get_plugin_url( 'wptouch' ) . "/admin-css/bnc-compressed-global.css' />\n"; |
|
187 echo "<script type='text/javascript' src='" . compat_get_plugin_url( 'wptouch' ) . "/js/ajax_upload_3.6.js'></script>\n"; |
|
188 echo "<script type='text/javascript' src='" . compat_get_plugin_url( 'wptouch' ) . "/js/colorpicker_1.4.js'></script>\n"; |
|
189 echo "<script type='text/javascript' src='" . compat_get_plugin_url( 'wptouch' ) . "/js/fancybox_1.2.5.js'></script>\n"; |
|
190 echo "<script type='text/javascript' src='" . compat_get_plugin_url( 'wptouch' ) . "/js/admin_1.9.js'></script>\n"; |
|
191 } |
|
192 } |
|
193 |
|
194 function bnc_wptouch_get_user_agents() { |
|
195 $useragents = array( |
|
196 "iphone", // Apple iPhone |
|
197 "ipod", // Apple iPod touch |
|
198 "aspen", // iPhone simulator |
|
199 "dream", // Pre 1.5 Android |
|
200 "android", // 1.5+ Android |
|
201 "cupcake", // 1.5+ Android |
|
202 "blackberry9500", // Storm |
|
203 "blackberry9530", // Storm |
|
204 "opera mini", // Experimental |
|
205 "webos", // Experimental |
|
206 "incognito", // Other iPhone browser |
|
207 "webmate" // Other iPhone browser |
|
208 ); |
|
209 |
|
210 $settings = bnc_wptouch_get_settings(); |
|
211 if ( isset( $settings['custom-user-agents'] ) ) { |
|
212 foreach( $settings['custom-user-agents'] as $agent ) { |
|
213 if ( !strlen( $agent ) ) continue; |
|
214 |
|
215 $useragents[] = $agent; |
|
216 } |
|
217 } |
|
218 |
|
219 asort( $useragents ); |
|
220 |
|
221 // WPtouch User Agent Filter |
|
222 $useragents = apply_filters( 'wptouch_user_agents', $useragents ); |
|
223 |
|
224 return $useragents; |
|
225 } |
|
226 |
|
227 function bnc_wptouch_is_prowl_key_valid() { |
|
228 require_once( 'include/class.prowl.php' ); |
|
229 |
|
230 $settings = bnc_wptouch_get_settings(); |
|
231 |
|
232 if ( isset( $settings['prowl-api'] ) ) { |
|
233 $api_key = $settings['prowl-api']; |
|
234 |
|
235 $prowl = new Prowl( $api_key, $settings['header-title'] ); |
|
236 $verify = $prowl->verify(); |
|
237 return ( $verify === true ); |
|
238 } |
|
239 |
|
240 return false; |
|
241 } |
|
242 |
|
243 class WPtouchPlugin { |
|
244 var $applemobile; |
|
245 var $desired_view; |
|
246 var $output_started; |
|
247 var $prowl_output; |
|
248 var $prowl_success; |
|
249 |
|
250 function WPtouchPlugin() { |
|
251 $this->output_started = false; |
|
252 $this->applemobile = false; |
|
253 $this->prowl_output = false; |
|
254 $this->prowl_success = false; |
|
255 |
|
256 add_action( 'plugins_loaded', array(&$this, 'detectAppleMobile') ); |
|
257 add_filter( 'stylesheet', array(&$this, 'get_stylesheet') ); |
|
258 add_filter( 'theme_root', array(&$this, 'theme_root') ); |
|
259 add_filter( 'theme_root_uri', array(&$this, 'theme_root_uri') ); |
|
260 add_filter( 'template', array(&$this, 'get_template') ); |
|
261 add_filter( 'init', array(&$this, 'bnc_filter_iphone') ); |
|
262 add_filter( 'wp', array(&$this, 'bnc_do_redirect') ); |
|
263 add_filter( 'wp_head', array(&$this, 'bnc_head') ); |
|
264 add_filter( 'query_vars', array( &$this, 'wptouch_query_vars' ) ); |
|
265 add_filter( 'parse_request', array( &$this, 'wptouch_parse_request' ) ); |
|
266 add_action( 'comment_post', array( &$this, 'wptouch_handle_new_comment' ) ); |
|
267 add_action( 'user_register', array( &$this, 'wptouch_handle_new_user' ) ); |
|
268 |
|
269 $this->detectAppleMobile(); |
|
270 } |
|
271 |
|
272 function wptouch_cleanup_growl( $msg ) { |
|
273 $msg = str_replace("\r\n","\n", $msg); |
|
274 $msg = str_replace("\r","\n", $msg); |
|
275 return $msg; |
|
276 } |
|
277 |
|
278 function wptouch_send_prowl_message( $title, $message ) { |
|
279 require_once( 'include/class.prowl.php' ); |
|
280 |
|
281 $settings = bnc_wptouch_get_settings(); |
|
282 |
|
283 if ( isset( $settings['prowl-api'] ) ) { |
|
284 $api_key = $settings['prowl-api']; |
|
285 |
|
286 $prowl = new Prowl( $api_key, $settings['header-title'] ); |
|
287 |
|
288 $this->prowl_output = true; |
|
289 $result = $prowl->add( 1, $title, $this->wptouch_cleanup_growl( stripslashes( $message ) ) ); |
|
290 |
|
291 if ( $result ) { |
|
292 $this->prowl_success = true; |
|
293 } else { |
|
294 $this->prowl_success = false; |
|
295 } |
|
296 } else { |
|
297 return false; |
|
298 } |
|
299 } |
|
300 |
|
301 function wptouch_handle_new_comment( $comment_id, $approval_status = '1' ) { |
|
302 $settings = bnc_wptouch_get_settings(); |
|
303 |
|
304 if ( $approval_status != 'spam' |
|
305 && isset( $settings['prowl-api'] ) |
|
306 && isset( $settings['enable-prowl-comments-button']) |
|
307 && $settings['enable-prowl-comments-button'] == 1 ) { |
|
308 |
|
309 $api_key = $settings['prowl-api']; |
|
310 |
|
311 require_once( 'include/class.prowl.php' ); |
|
312 $comment = get_comment( $comment_id ); |
|
313 $prowl = new Prowl( $api_key, $settings['header-title'] ); |
|
314 |
|
315 if ( $comment->comment_type != 'spam' && $comment->comment_approved != 'spam' ) { |
|
316 if ( $comment->comment_type == 'trackback' || $comment->comment_type == 'pingback' ) { |
|
317 $result = $prowl->add( 1, |
|
318 __( "New Ping/Trackback", "wptouch" ), |
|
319 'From: '. $this->wptouch_cleanup_growl( stripslashes( $comment->comment_author ) ) . |
|
320 "\nPost: ". $this->wptouch_cleanup_growl( stripslashes( $comment->comment_content ) ) |
|
321 ); |
|
322 } else { |
|
323 $result = $prowl->add( 1, |
|
324 __( "New Comment", "wptouch" ), |
|
325 'Name: '. $this->wptouch_cleanup_growl( stripslashes( $comment->comment_author ) ) . |
|
326 "\nE-Mail: ". $this->wptouch_cleanup_growl( stripslashes( $comment->comment_author_email ) ) . |
|
327 "\nComment: ". $this->wptouch_cleanup_growl( stripslashes( $comment->comment_content ) ) |
|
328 ); |
|
329 } |
|
330 } |
|
331 } |
|
332 |
|
333 } |
|
334 |
|
335 |
|
336 function wptouch_handle_new_user( $user_id ) { |
|
337 $settings = bnc_wptouch_get_settings(); |
|
338 |
|
339 if ( isset( $settings['prowl-api'] ) |
|
340 && isset( $settings['enable-prowl-users-button'] ) |
|
341 && $settings['enable-prowl-users-button'] == 1 ) { |
|
342 |
|
343 global $wpdb; |
|
344 $api_key = $settings['prowl-api']; |
|
345 require_once( 'include/class.prowl.php' ); |
|
346 global $table_prefix; |
|
347 $sql = $wpdb->prepare( "SELECT * from " . $table_prefix . "users WHERE ID = %d", $user_id ); |
|
348 $user = $wpdb->get_row( $sql ); |
|
349 |
|
350 if ( $user ) { |
|
351 $prowl = new Prowl( $api_key, $settings['header-title'] ); |
|
352 $result = $prowl->add( 1, |
|
353 __( "User Registration", "wptouch" ), |
|
354 'Name: '. $this->wptouch_cleanup_growl( stripslashes( $user->user_login ) ) . |
|
355 "\nE-Mail: ". $this->wptouch_cleanup_growl( stripslashes( $user->user_email ) ) |
|
356 ); |
|
357 } |
|
358 } |
|
359 } |
|
360 |
|
361 function wptouch_query_vars( $vars ) { |
|
362 $vars[] = "wptouch"; |
|
363 return $vars; |
|
364 } |
|
365 |
|
366 function wptouch_parse_request( $wp ) { |
|
367 if (array_key_exists( "wptouch", $wp->query_vars ) ) { |
|
368 switch ( $wp->query_vars["wptouch"] ) { |
|
369 case "upload": |
|
370 include( 'ajax/file_upload.php' ); |
|
371 break; |
|
372 case "plugins": |
|
373 include( 'ajax/load-plugins.php' ); |
|
374 break; |
|
375 } |
|
376 exit; |
|
377 } |
|
378 } |
|
379 |
|
380 function bnc_head() { |
|
381 if ( $this->applemobile && $this->desired_view == 'normal' ) { |
|
382 echo "<link rel='stylesheet' type='text/css' href='" . compat_get_plugin_url( 'wptouch' ) . "/themes/core/core-css/wptouch-switch-link.css'></link>\n"; |
|
383 echo "<meta name=\"viewport\" content=\"width=device-width,initial-scale=0,user-scalable=yes\" /> \n"; |
|
384 } |
|
385 } |
|
386 |
|
387 function bnc_do_redirect() { |
|
388 global $post; |
|
389 |
|
390 // check for wptouch prowl direct messages |
|
391 $nonce = ''; |
|
392 if ( isset( $_POST['_nonce'] ) ) { |
|
393 $nonce = $_POST['_nonce']; |
|
394 } |
|
395 |
|
396 if ( isset( $_POST['wptouch-prowl-message'] ) && wp_verify_nonce( $nonce, 'wptouch-prowl' ) ) { |
|
397 $name = $_POST['prowl-msg-name']; |
|
398 $email = $_POST['prowl-msg-email']; |
|
399 $msg = $_POST['prowl-msg-message']; |
|
400 |
|
401 $title = __( "Direct Message", "wptouch" ); |
|
402 $prowl_message = 'From: '. $this->wptouch_cleanup_growl( $name ) . |
|
403 "\nE-Mail: ". $this->wptouch_cleanup_growl( $email ) . |
|
404 "\nMessage: ". $this->wptouch_cleanup_growl( $msg ); |
|
405 "\nIP: " . $_SERVER["REMOTE_ADDR"] . |
|
406 |
|
407 $this->wptouch_send_prowl_message( $title, $prowl_message ); |
|
408 } |
|
409 |
|
410 if ( $this->applemobile && $this->desired_view == 'mobile' ) { |
|
411 $version = (float)get_bloginfo('version'); |
|
412 $is_front = 0; |
|
413 $is_front = (is_front_page() && (bnc_get_selected_home_page() > 0)); |
|
414 |
|
415 if ( $is_front ) { |
|
416 $url = get_permalink( bnc_get_selected_home_page() ); |
|
417 header('Location: ' . $url); |
|
418 die; |
|
419 } |
|
420 } |
|
421 } |
|
422 |
|
423 function bnc_filter_iphone() { |
|
424 $key = 'wptouch_switch_cookie'; |
|
425 |
|
426 if (isset($_GET['theme_view'])) { |
|
427 if ($_GET['theme_view'] == 'mobile') { |
|
428 setcookie($key, 'mobile', 0); |
|
429 } elseif ($_GET['theme_view'] == 'normal') { |
|
430 setcookie($key, 'normal', 0); |
|
431 } |
|
432 |
|
433 $redirect_location = get_bloginfo( 'siteurl' ); |
|
434 // fix by cybrstudd |
|
435 if ( isset( $_GET['wptouch_redirect'] ) ) { |
|
436 $protocol = ($_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://'; |
|
437 $redirect_location = $protocol . $_GET['wptouch_redirect']; |
|
438 } |
|
439 |
|
440 header( 'Location: ' . $redirect_location ); |
|
441 die; |
|
442 } |
|
443 |
|
444 $settings = bnc_wptouch_get_settings(); |
|
445 if (isset($_COOKIE[$key])) { |
|
446 $this->desired_view = $_COOKIE[$key]; |
|
447 } else { |
|
448 if ( $settings['enable-regular-default'] ) { |
|
449 $this->desired_view = 'normal'; |
|
450 } else { |
|
451 $this->desired_view = 'mobile'; |
|
452 } |
|
453 } |
|
454 } |
|
455 |
|
456 function detectAppleMobile($query = '') { |
|
457 $container = $_SERVER['HTTP_USER_AGENT']; |
|
458 // The below prints out the user agent array. Uncomment to see it shown on the page. |
|
459 // print_r($container); |
|
460 // Add whatever user agents you want here to the array if you want to make this show on another device. |
|
461 // No guarantees it'll look pretty, though! |
|
462 $useragents = bnc_wptouch_get_user_agents(); |
|
463 |
|
464 $devfile = compat_get_plugin_dir( 'wptouch' ) . '/include/developer.mode'; |
|
465 $this->applemobile = false; |
|
466 foreach ( $useragents as $useragent ) { |
|
467 if ( eregi( $useragent, $container ) || file_exists($devfile) ) { |
|
468 $this->applemobile = true; |
|
469 } |
|
470 } |
|
471 } |
|
472 |
|
473 function get_stylesheet( $stylesheet ) { |
|
474 if ($this->applemobile && $this->desired_view == 'mobile') { |
|
475 return 'default'; |
|
476 } else { |
|
477 return $stylesheet; |
|
478 } |
|
479 } |
|
480 |
|
481 function get_template( $template ) { |
|
482 $this->bnc_filter_iphone(); |
|
483 if ($this->applemobile && $this->desired_view === 'mobile') { |
|
484 return 'default'; |
|
485 } else { |
|
486 return $template; |
|
487 } |
|
488 } |
|
489 |
|
490 function get_template_directory( $value ) { |
|
491 $theme_root = compat_get_plugin_dir( 'wptouch' ); |
|
492 if ($this->applemobile && $this->desired_view === 'mobile') { |
|
493 return $theme_root . '/themes'; |
|
494 } else { |
|
495 return $value; |
|
496 } |
|
497 } |
|
498 |
|
499 function theme_root( $path ) { |
|
500 $theme_root = compat_get_plugin_dir( 'wptouch' ); |
|
501 if ($this->applemobile && $this->desired_view === 'mobile') { |
|
502 return $theme_root . '/themes'; |
|
503 } else { |
|
504 return $path; |
|
505 } |
|
506 } |
|
507 |
|
508 function theme_root_uri( $url ) { |
|
509 if ($this->applemobile && $this->desired_view === 'mobile') { |
|
510 $dir = compat_get_plugin_url( 'wptouch' ) . "/themes"; |
|
511 return $dir; |
|
512 } else { |
|
513 return $url; |
|
514 } |
|
515 } |
|
516 } |
|
517 |
|
518 global $wptouch_plugin; |
|
519 $wptouch_plugin = new WPtouchPlugin(); |
|
520 |
|
521 //Thanks to edyoshi: |
|
522 function bnc_is_iphone() { |
|
523 global $wptouch_plugin; |
|
524 $wptouch_plugin->bnc_filter_iphone(); |
|
525 return $wptouch_plugin->applemobile; |
|
526 } |
|
527 |
|
528 // The Automatic Footer Template Switch Code (into "wp_footer()" in regular theme's footer.php) |
|
529 function wptouch_switch() { |
|
530 global $wptouch_plugin; |
|
531 if ( bnc_is_iphone() && $wptouch_plugin->desired_view == 'normal' ) { |
|
532 echo '<div id="wptouch-switch-link">'; |
|
533 _e( "Mobile Theme", "wptouch" ); |
|
534 echo "<a onclick=\"document.getElementById('switch-on').style.display='block';document.getElementById('switch-off').style.display='none';\" href=\"" . get_bloginfo('siteurl') . "/?theme_view=mobile&wptouch_redirect=" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . "\"><img id=\"switch-on\" src=\"" . compat_get_plugin_url( 'wptouch' ) . "/themes/core/core-images/on.jpg\" alt=\"on switch image\" class=\"wptouch-switch-image\" style=\"display:none\" /><img id=\"switch-off\" src=\"" . compat_get_plugin_url( 'wptouch' ) . "/themes/core/core-images/off.jpg\" alt=\"off switch image\" class=\"wptouch-switch-image\" /></a>"; |
|
535 echo '</div>'; |
|
536 } |
|
537 } |
|
538 |
|
539 function bnc_options_menu() { |
|
540 add_options_page( __( 'WPtouch iPhone Theme', 'wptouch' ), 'WPtouch', 9, __FILE__, bnc_wp_touch_page ); |
|
541 } |
|
542 |
|
543 function bnc_wptouch_get_settings() { |
|
544 return bnc_wp_touch_get_menu_pages(); |
|
545 } |
|
546 |
|
547 function bnc_validate_wptouch_settings( &$settings ) { |
|
548 global $wptouch_defaults; |
|
549 foreach ( $wptouch_defaults as $key => $value ) { |
|
550 if ( !isset( $settings[$key] ) ) { |
|
551 $settings[$key] = $value; |
|
552 } |
|
553 } |
|
554 } |
|
555 |
|
556 function bnc_wptouch_is_exclusive() { |
|
557 $settings = bnc_wptouch_get_settings(); |
|
558 return $settings['enable-exclusive']; |
|
559 } |
|
560 |
|
561 function bnc_can_show_tweets() { |
|
562 $settings = bnc_wptouch_get_settings(); |
|
563 return $settings['enable-show-tweets']; |
|
564 } |
|
565 |
|
566 function bnc_wp_touch_get_menu_pages() { |
|
567 $v = get_option('bnc_iphone_pages'); |
|
568 if (!$v) { |
|
569 $v = array(); |
|
570 } |
|
571 |
|
572 if (!is_array($v)) { |
|
573 $v = unserialize($v); |
|
574 } |
|
575 |
|
576 bnc_validate_wptouch_settings( $v ); |
|
577 |
|
578 return $v; |
|
579 } |
|
580 |
|
581 function bnc_get_selected_home_page() { |
|
582 $v = bnc_wp_touch_get_menu_pages(); |
|
583 return $v['home-page']; |
|
584 } |
|
585 |
|
586 function wptouch_get_stats() { |
|
587 $options = bnc_wp_touch_get_menu_pages(); |
|
588 if (isset($options['statistics'])) { |
|
589 echo stripslashes($options['statistics']); |
|
590 } |
|
591 } |
|
592 |
|
593 function bnc_get_title_image() { |
|
594 $ids = bnc_wp_touch_get_menu_pages(); |
|
595 $title_image = $ids['main_title']; |
|
596 |
|
597 if ( file_exists( compat_get_plugin_dir( 'wptouch' ) . '/images/icon-pool/' . $title_image ) ) { |
|
598 $image = compat_get_plugin_url( 'wptouch' ) . '/images/icon-pool/' . $title_image; |
|
599 } else if ( file_exists( compat_get_upload_dir() . '/wptouch/custom-icons/' . $title_image ) ) { |
|
600 $image = compat_get_upload_url() . '/wptouch/custom-icons/' . $title_image; |
|
601 } |
|
602 |
|
603 return $image; |
|
604 } |
|
605 |
|
606 function wptouch_excluded_cats() { |
|
607 $settings = bnc_wptouch_get_settings(); |
|
608 return stripslashes($settings['excluded-cat-ids']); |
|
609 } |
|
610 |
|
611 function bnc_excerpt_enabled() { |
|
612 $ids = bnc_wp_touch_get_menu_pages(); |
|
613 return $ids['enable-post-excerpts']; |
|
614 } |
|
615 |
|
616 function bnc_is_page_coms_enabled() { |
|
617 $ids = bnc_wp_touch_get_menu_pages(); |
|
618 return $ids['enable-page-coms']; |
|
619 } |
|
620 |
|
621 function bnc_is_cats_button_enabled() { |
|
622 $ids = bnc_wp_touch_get_menu_pages(); |
|
623 return $ids['enable-cats-button']; |
|
624 } |
|
625 |
|
626 function bnc_is_tags_button_enabled() { |
|
627 $ids = bnc_wp_touch_get_menu_pages(); |
|
628 return $ids['enable-tags-button']; |
|
629 } |
|
630 |
|
631 function bnc_is_search_enabled() { |
|
632 $ids = bnc_wp_touch_get_menu_pages(); |
|
633 return $ids['enable-search-button']; |
|
634 } |
|
635 |
|
636 function bnc_is_gigpress_enabled() { |
|
637 $ids = bnc_wp_touch_get_menu_pages(); |
|
638 return $ids['enable-gigpress-button']; |
|
639 } |
|
640 |
|
641 function bnc_is_login_button_enabled() { |
|
642 $ids = bnc_wp_touch_get_menu_pages(); |
|
643 return $ids['enable-login-button']; |
|
644 } |
|
645 |
|
646 function bnc_is_gravatars_enabled() { |
|
647 $ids = bnc_wp_touch_get_menu_pages(); |
|
648 return $ids['enable-gravatars']; |
|
649 } |
|
650 |
|
651 function bnc_is_ajax_coms_enabled() { |
|
652 $ids = bnc_wp_touch_get_menu_pages(); |
|
653 return $ids['enable-ajax-comments']; |
|
654 } |
|
655 |
|
656 function bnc_show_author() { |
|
657 $ids = bnc_wp_touch_get_menu_pages(); |
|
658 return $ids['enable-main-name']; |
|
659 } |
|
660 |
|
661 function bnc_show_tags() { |
|
662 $ids = bnc_wp_touch_get_menu_pages(); |
|
663 return $ids['enable-main-tags']; |
|
664 } |
|
665 |
|
666 function bnc_show_categories() { |
|
667 $ids = bnc_wp_touch_get_menu_pages(); |
|
668 return $ids['enable-main-categories']; |
|
669 } |
|
670 |
|
671 function bnc_is_home_enabled() { |
|
672 $ids = bnc_wp_touch_get_menu_pages(); |
|
673 return $ids['enable-main-home']; |
|
674 } |
|
675 |
|
676 function bnc_is_rss_enabled() { |
|
677 $ids = bnc_wp_touch_get_menu_pages(); |
|
678 return $ids['enable-main-rss']; |
|
679 } |
|
680 |
|
681 function bnc_is_email_enabled() { |
|
682 $ids = bnc_wp_touch_get_menu_pages(); |
|
683 return $ids['enable-main-email']; |
|
684 } |
|
685 |
|
686 // Prowl Functions |
|
687 function bnc_is_prowl_direct_message_enabled() { |
|
688 $settings = bnc_wptouch_get_settings(); |
|
689 return ( isset( $settings['enable-prowl-message-button'] ) && $settings['enable-prowl-message-button'] && $settings['prowl-api'] ); |
|
690 } |
|
691 |
|
692 function bnc_prowl_did_try_message() { |
|
693 global $wptouch_plugin; |
|
694 return $wptouch_plugin->prowl_output; |
|
695 } |
|
696 |
|
697 function bnc_prowl_message_success() { |
|
698 global $wptouch_plugin; |
|
699 return $wptouch_plugin->prowl_success; |
|
700 } |
|
701 // End prowl functions |
|
702 |
|
703 function bnc_wp_touch_get_pages() { |
|
704 global $table_prefix; |
|
705 global $wpdb; |
|
706 |
|
707 $ids = bnc_wp_touch_get_menu_pages(); |
|
708 $a = array(); |
|
709 $keys = array(); |
|
710 foreach ($ids as $k => $v) { |
|
711 if ($k == 'main_title' || $k == 'enable-post-excerpts' || $k == 'enable-page-coms' || |
|
712 $k == 'enable-cats-button' || $k == 'enable-tags-button' || $k == 'enable-search-button' || |
|
713 $k == 'enable-login-button' || $k == 'enable-gravatars' || $k == 'enable-ajax-comments' || |
|
714 $k == 'enable-main-home' || $k == 'enable-main-rss' || $k == 'enable-main-email' || |
|
715 $k == 'enable-main-name' || $k == 'enable-main-tags' || $k == 'enable-main-categories' || |
|
716 $k == 'enable-prowl-comments-button' || $k == 'enable-prowl-users-button' || |
|
717 $k == 'enable-prowl-message-button' || $k == 'enable-gigpress-button') { |
|
718 } else { |
|
719 if (is_numeric($k)) { |
|
720 $keys[] = $k; |
|
721 } |
|
722 } |
|
723 } |
|
724 |
|
725 $menu_order = array(); |
|
726 $results = false; |
|
727 |
|
728 if ( count( $keys ) > 0 ) { |
|
729 $query = "select * from {$table_prefix}posts where ID in (" . implode(',', $keys) . ") and post_status = 'publish' order by post_title asc"; |
|
730 $results = $wpdb->get_results( $query, ARRAY_A ); |
|
731 } |
|
732 |
|
733 if ( $results ) { |
|
734 foreach ( $results as $row ) { |
|
735 $row['icon'] = $ids[$row['ID']]; |
|
736 $a[$row['ID']] = $row; |
|
737 if (isset($menu_order[$row['menu_order']])) { |
|
738 $menu_order[$row['menu_order']*100 + $inc] = $row; |
|
739 } else { |
|
740 $menu_order[$row['menu_order']*100] = $row; |
|
741 } |
|
742 $inc = $inc + 1; |
|
743 } |
|
744 } |
|
745 |
|
746 if (isset($ids['sort-order']) && $ids['sort-order'] == 'page') { |
|
747 asort($menu_order); |
|
748 return $menu_order; |
|
749 } else { |
|
750 return $a; |
|
751 } |
|
752 } |
|
753 |
|
754 function bnc_get_header_title() { |
|
755 $v = bnc_wp_touch_get_menu_pages(); |
|
756 return $v['header-title']; |
|
757 } |
|
758 |
|
759 function bnc_get_header_background() { |
|
760 $v = bnc_wp_touch_get_menu_pages(); |
|
761 return $v['header-background-color']; |
|
762 } |
|
763 |
|
764 function bnc_get_header_border_color() { |
|
765 $v = bnc_wp_touch_get_menu_pages(); |
|
766 return $v['header-border-color']; |
|
767 } |
|
768 |
|
769 function bnc_get_header_color() { |
|
770 $v = bnc_wp_touch_get_menu_pages(); |
|
771 return $v['header-text-color']; |
|
772 } |
|
773 |
|
774 function bnc_get_link_color() { |
|
775 $v = bnc_wp_touch_get_menu_pages(); |
|
776 return $v['link-color']; |
|
777 } |
|
778 |
|
779 function bnc_get_h2_font() { |
|
780 $v = bnc_wp_touch_get_menu_pages(); |
|
781 return $v['h2-font']; |
|
782 } |
|
783 |
|
784 require_once( 'include/icons.php' ); |
|
785 |
|
786 function bnc_wp_touch_page() { |
|
787 if (isset($_POST['submit'])) { |
|
788 echo('<div class="wrap"><div id="bnc-global"><div id="wptouchupdated" style="display:none"><p class="saved"><span>'); |
|
789 echo __( "Settings saved", "wptouch"); |
|
790 echo('</span></p></div>'); |
|
791 } |
|
792 elseif (isset($_POST['reset'])) { |
|
793 echo('<div class="wrap"><div id="bnc-global"><div id="wptouchupdated" style="display:none"><p class="reset"><span>'); |
|
794 echo __( "Defaults restored", "wptouch"); |
|
795 echo('</span></p></div>'); |
|
796 } else { |
|
797 echo('<div class="wrap"><div id="bnc-global">'); |
|
798 } |
|
799 ?> |
|
800 |
|
801 <?php $icons = bnc_get_icon_list(); ?> |
|
802 |
|
803 <?php require_once( 'include/submit.php' ); ?> |
|
804 <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> |
|
805 <?php require_once( 'html/head-area.php' ); ?> |
|
806 <?php require_once( 'html/general-settings-area.php' ); ?> |
|
807 <?php require_once( 'html/advanced-area.php' ); ?> |
|
808 <?php require_once( 'html/push-area.php' ); ?> |
|
809 <?php require_once( 'html/style-area.php' ); ?> |
|
810 <?php require_once( 'html/icon-area.php' ); ?> |
|
811 <?php require_once( 'html/page-area.php' ); ?> |
|
812 <?php require_once( 'html/ads-stats-area.php' ); ?> |
|
813 <?php require_once( 'html/plugin-compat-area.php' ); ?> |
|
814 <input type="submit" name="submit" value="<?php _e('Save Options', 'wptouch' ); ?>" id="bnc-button" class="button-primary" /> |
|
815 </form> |
|
816 |
|
817 <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> |
|
818 <input type="submit" onclick="return confirm('<?php _e('Restore default WPtouch settings?', 'wptouch' ); ?>');" name="reset" value="<?php _e('Restore Defaults', 'wptouch' ); ?>" id="bnc-button-reset" class="button-highlighted" /> |
|
819 </form> |
|
820 |
|
821 <?php echo('' . WPtouch('<div class="bnc-plugin-version"> This is ','</div>') . ''); ?> |
|
822 |
|
823 <div class="bnc-clearer"></div> |
|
824 </div> |
|
825 <?php |
|
826 echo('</div>'); } |
|
827 add_action('wp_footer', 'wptouch_switch'); |
|
828 add_action('admin_head', 'wptouch_admin_files'); |
|
829 add_action('admin_menu', 'bnc_options_menu'); |
|
830 add_filter( 'plugin_action_links', 'wptouch_settings_link', 9, 2 ); |
|
831 ?> |