PageRenderTime 50ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/wptouch/wptouch.php

https://bitbucket.org/crypticrod/sr_wp_code
PHP | 1109 lines | 893 code | 171 blank | 45 comment | 213 complexity | 3b457682b8d82a4ea911f8ff53e1e15a MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, GPL-3.0, LGPL-2.0, AGPL-3.0
  1. <?php
  2. /*
  3. Plugin Name: WPtouch
  4. Plugin URI: http://wordpress.org/extend/plugins/wptouch/
  5. Version: 1.9.5.3
  6. Description: A plugin which formats your site with a mobile theme for visitors on 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>, <a href="http://www.blackberry.com/">Blackberry Storm and Torch</a>, <a href="http://www.palm.com/us/products/phones/pre/">Palm Pre</a> and other touch-based smartphones.
  7. Author: BraveNewCode Inc.
  8. Author URI: http://www.bravenewcode.com
  9. Text Domain: wptouch
  10. Domain Path: /lang
  11. License: GNU General Public License 2.0 (GPL) http://www.gnu.org/licenses/gpl.html
  12. # Thanks to ContentRobot and the iWPhone theme/plugin
  13. # which the detection feature of the plugin was based on.
  14. # (http://iwphone.contentrobot.com/)
  15. # Also thanks to Henrik Urlund, who's "Prowl Me" plugin inspired
  16. # the Push notification additions.
  17. # (http://codework.dk/referencer/wp-plugins/prowl-me/)
  18. # Copyright (c) 2008 - 2011 BraveNewCode Inc.
  19. # 'WPtouch' is an unregistered trademark of BraveNewCode Inc.,
  20. # and may not be used in conjuction with any redistribution
  21. # of this software without express prior permission from BraveNewCode Inc.
  22. */
  23. load_plugin_textdomain( 'wptouch', false, dirname( plugin_basename( __FILE__ ) ) );
  24. global $bnc_wptouch_version;
  25. $bnc_wptouch_version = '1.9.5.3';
  26. require_once( 'include/plugin.php' );
  27. require_once( 'include/compat.php' );
  28. define( 'WPTOUCH_PROWL_APPNAME', 'WPtouch');
  29. define( 'WPTOUCH_ATOM', 1 );
  30. //The WPtouch Settings Defaults
  31. global $wptouch_defaults;
  32. $wptouch_defaults = array(
  33. 'header-title' => get_bloginfo('name'),
  34. 'main_title' => 'Default.png',
  35. 'enable-post-excerpts' => true,
  36. 'enable-page-coms' => false,
  37. 'enable-zoom' => false,
  38. 'enable-cats-button' => true,
  39. 'enable-tags-button' => true,
  40. 'enable-search-button' => true,
  41. 'enable-login-button' => false,
  42. 'enable-gravatars' => true,
  43. 'enable-main-home' => true,
  44. 'enable-main-rss' => true,
  45. 'enable-main-name' => true,
  46. 'enable-main-tags' => true,
  47. 'enable-main-categories' => true,
  48. 'enable-main-email' => true,
  49. 'enable-truncated-titles' => true,
  50. 'prowl-api' => '',
  51. 'enable-prowl-comments-button' => false,
  52. 'enable-prowl-users-button' => false,
  53. 'enable-prowl-message-button' => false,
  54. 'header-background-color' => '000000',
  55. 'header-border-color' => '333333',
  56. 'header-text-color' => 'eeeeee',
  57. 'link-color' => '006bb3',
  58. 'post-cal-thumb' =>'calendar-icons',
  59. 'h2-font' =>'Helvetica Neue',
  60. 'style-text-justify' => 'left-justified',
  61. 'style-background' => 'low-contrast-linen-wptouch-bg',
  62. 'style-icon' => 'glossy-icon',
  63. 'enable-regular-default' => false,
  64. 'excluded-cat-ids' => '',
  65. 'excluded-tag-ids' => '',
  66. 'custom-footer-msg' => 'All content Copyright '. get_bloginfo('name') . '',
  67. 'home-page' => 0,
  68. 'enable-exclusive' => false,
  69. 'sort-order' => 'name',
  70. 'adsense-id' => '',
  71. 'statistics' => '',
  72. 'adsense-channel' => '',
  73. 'custom-user-agents' => array(),
  74. 'enable-show-comments' => true,
  75. 'enable-show-tweets' => false,
  76. 'enable-gigpress-button' => false,
  77. 'enable-flat-icon' => false,
  78. 'wptouch-language' => 'auto',
  79. 'enable-twenty-eleven-footer' => 0,
  80. 'enable-fixed-header' => false,
  81. 'ad_service' => 'adsense',
  82. 'show_powered_by' => false
  83. );
  84. function wptouch_get_plugin_dir_name() {
  85. global $wptouch_plugin_dir_name;
  86. return $wptouch_plugin_dir_name;
  87. }
  88. function wptouch_delete_icon( $icon ) {
  89. if ( !current_user_can( 'manage_options' ) ) {
  90. // don't allow users non administrators to delete files (security check)
  91. return;
  92. }
  93. $dir = explode( 'wptouch', $icon );
  94. $loc = compat_get_upload_dir() . "/wptouch/" . ltrim( $dir[1], '/' );
  95. $real_location = realpath( $loc );
  96. if ( strpos( $real_location, WP_CONTENT_DIR ) !== false ) {
  97. unlink( $loc );
  98. }
  99. }
  100. add_action( 'wptouch_load_locale', 'load_wptouch_languages' );
  101. function load_wptouch_languages() {
  102. $settings = bnc_wptouch_get_settings();
  103. $wptouch_dir = compat_get_plugin_dir( 'wptouch' );
  104. if ( $wptouch_dir ) {
  105. if ( isset( $settings['wptouch-language'] ) ) {
  106. if ( $settings['wptouch-language'] == 'auto' ) {
  107. // check the locale
  108. $locale = get_locale();
  109. if ( file_exists( $wptouch_dir . '/lang/' . $locale . '.mo' ) ) {
  110. load_textdomain( 'wptouch', $wptouch_dir . '/lang/' . $locale . '.mo' );
  111. }
  112. } else {
  113. if ( file_exists( $wptouch_dir . '/lang/' . $settings['wptouch-language'] . '.mo' ) ) {
  114. load_textdomain( 'wptouch', $wptouch_dir . '/lang/' . $settings['wptouch-language'] . '.mo' );
  115. } else if ( file_exists( WP_CONTENT_DIR . '/wptouch/lang/' . $settings['wptouch-language'] . '.mo' ) ) {
  116. load_textdomain( 'wptouch', WP_CONTENT_DIR . '/wptouch/lang/' . $settings['wptouch-language'] . '.mo' );
  117. }
  118. }
  119. }
  120. }
  121. }
  122. function wptouch_init() {
  123. if ( isset( $_GET['delete_icon'] ) ) {
  124. $nonce = $_GET['nonce'];
  125. if ( !wp_verify_nonce( $nonce, 'wptouch_delete_nonce' ) ) {
  126. die( 'Security Failure' );
  127. } else {
  128. wptouch_delete_icon( $_GET['delete_icon'] );
  129. header( 'Location: ' . site_url() . '/wp-admin/options-general.php?page=wptouch/wptouch.php#available_icons' );
  130. die;
  131. }
  132. }
  133. if ( !is_admin() ) {
  134. do_action( 'wptouch_load_locale' );
  135. }
  136. }
  137. function wptouch_include_ads() {
  138. global $wptouch_plugin;
  139. $settings = bnc_wptouch_get_settings();
  140. // Check to make sure it's on a mobile site
  141. if ( bnc_is_iphone() && $wptouch_plugin->desired_view == 'mobile' ) {
  142. // Check which type of advertising the user has selected
  143. switch ( $settings['ad_service'] ) {
  144. case 'adsense':
  145. if ( isset( $settings['adsense-id'] ) && strlen( $settings['adsense-id'] ) && is_single() ) {
  146. global $wptouch_settings;
  147. $wptouch_settings = $settings;
  148. include( 'include/adsense-new.php' );
  149. }
  150. break;
  151. case 'appstores':
  152. break;
  153. default:
  154. break;
  155. }
  156. }
  157. }
  158. function wptouch_header_advertising() {
  159. global $wptouch_plugin;
  160. $settings = bnc_wptouch_get_settings();
  161. }
  162. function wptouch_content_filter( $content ) {
  163. global $wptouch_plugin;
  164. $settings = bnc_wptouch_get_settings();
  165. if ( bnc_is_iphone() && $wptouch_plugin->desired_view == 'mobile' && isset($settings['adsense-id']) && strlen($settings['adsense-id']) && is_single() ) {
  166. global $wptouch_settings;
  167. $wptouch_settings = $settings;
  168. ob_start();
  169. include( 'include/adsense-new.php' );
  170. $ad_contents = ob_get_contents();
  171. ob_end_clean();
  172. return '<div class="wptouch-adsense-ad">' . $ad_contents . '</div>' . $content;
  173. } else {
  174. return $content;
  175. }
  176. }
  177. // Version number for the admin header, footer
  178. function WPtouch($before = '', $after = '') {
  179. global $bnc_wptouch_version;
  180. echo $before . 'WPtouch ' . $bnc_wptouch_version . $after;
  181. }
  182. // Stop '0' Comment Counts
  183. function wp_touch_get_comment_count() {
  184. global $wpdb;
  185. global $post;
  186. $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 ) );
  187. if ( $result ) {
  188. return $result->c;
  189. } else {
  190. return 0;
  191. }
  192. }
  193. // WPtouch WP Thumbnail Support
  194. if ( function_exists( 'add_theme_support' ) ) { // Added in 2.9
  195. add_theme_support( 'post-thumbnails' ); // Add it for posts
  196. }
  197. //Add a link to 'Settings' on the plugin listings page
  198. function wptouch_settings_link( $links, $file ) {
  199. if( $file == 'wptouch/wptouch.php' && function_exists( "admin_url" ) ) {
  200. $settings_link = '<a href="' . admin_url( 'options-general.php?page=wptouch/wptouch.php' ) . '">' . __('Settings') . '</a>';
  201. array_push( $links, $settings_link ); // after other links
  202. }
  203. return $links;
  204. }
  205. // WPtouch Admin JavaScript
  206. function wptouch_admin_enqueue_files() {
  207. if ( isset( $_GET['page'] ) && $_GET['page'] == 'wptouch/wptouch.php' ) {
  208. wp_enqueue_script( 'ajax-upload', compat_get_plugin_url( 'wptouch' ) . '/js/ajax_upload.js', array( 'jquery' ) );
  209. wp_enqueue_script( 'jquery-colorpicker', compat_get_plugin_url( 'wptouch' ) . '/js/colorpicker_1.4.js', array( 'ajax-upload' ) );
  210. wp_enqueue_script( 'jquery-fancybox', compat_get_plugin_url( 'wptouch' ) . '/js/fancybox_1.2.5.js', array( 'jquery-colorpicker' ) );
  211. wp_enqueue_script( 'wptouch-js', compat_get_plugin_url( 'wptouch' ) . '/js/admin_1.9.js', array( 'jquery-fancybox' ) );
  212. }
  213. }
  214. // WPtouch Admin StyleSheets
  215. function wptouch_admin_files() {
  216. if ( isset( $_GET['page'] ) && $_GET['page'] == 'wptouch/wptouch.php' ) {
  217. echo "<script type='text/javascript' src='" . home_url() . "/?wptouch-ajax=js'></script>\n";
  218. echo "<link rel='stylesheet' type='text/css' href='" . compat_get_plugin_url( 'wptouch' ) . "/admin-css/wptouch-admin.css' />\n";
  219. echo "<link rel='stylesheet' type='text/css' href='" . compat_get_plugin_url( 'wptouch' ) . "/admin-css/bnc-global.css' />\n";
  220. echo "<link rel='stylesheet' type='text/css' href='" . compat_get_plugin_url( 'wptouch' ) . "/admin-css/bnc-compressed-global.css' />\n";
  221. }
  222. }
  223. function wptouch_ajax_handler() {
  224. if ( isset( $_GET['wptouch-ajax'] ) ) {
  225. switch( $_GET['wptouch-ajax'] ) {
  226. case 'js':
  227. header( 'Content-type: text/javascript' );
  228. $url = rtrim( site_url(), '/' ) . '/';
  229. echo "var wptouchBlogUrl = '" . $url . "';";
  230. break;
  231. case 'news':
  232. include( WP_PLUGIN_DIR . '/wptouch/ajax/news.php' );
  233. break;
  234. default:
  235. break;
  236. }
  237. die;
  238. }
  239. }
  240. add_action( 'init', 'wptouch_ajax_handler' );
  241. function bnc_wptouch_get_exclude_user_agents() {
  242. $user_agents = array(
  243. 'SCH-I800', // Samsung Galaxy Tab
  244. 'Xoom', // Motorola Xoom tablet
  245. 'P160U' , // HP TouchPad
  246. 'Nexus 7' // Nexus 7
  247. );
  248. return apply_filters( 'wptouch_exclude_user_agents', $user_agents );
  249. }
  250. function bnc_wptouch_get_user_agents() {
  251. $useragents = array(
  252. 'iPhone', // iPhone
  253. 'iPod', // iPod touch
  254. 'incognito', // iPhone alt browser
  255. 'webmate', // iPhone alt browser
  256. 'Android', // Android
  257. 'dream', // Android
  258. 'CUPCAKE', // Android
  259. 'froyo', // Android
  260. 'BlackBerry9500', // Storm 1
  261. 'BlackBerry9520', // Storm 1
  262. 'BlackBerry9530', // Storm 2
  263. 'BlackBerry9550', // Storm 2
  264. 'BlackBerry 9800', // Torch
  265. 'BlackBerry 9850', // Torch 2
  266. 'BlackBerry 9860', // Torch 2
  267. 'BlackBerry 9780', // Bold 3
  268. 'BlackBerry 9790', // Bold Touch
  269. 'BlackBerry 9900', // Bold
  270. 'BlackBerry 9930', // Bold
  271. 'BlackBerry 9350', // Curve
  272. 'BlackBerry 9360', // Curve
  273. 'BlackBerry 9370', // Curve
  274. 'BlackBerry 9380', // Curve
  275. 'BlackBerry 9810', // Torch
  276. 'webOS', // Palm Pre/Pixi
  277. 's8000', // Samsung s8000
  278. 'bada', // Samsung Bada Phone
  279. 'Googlebot-Mobile', // Google's mobile Crawler
  280. 'AdsBot-Google' // Google's Ad Bot Crawler
  281. );
  282. $settings = bnc_wptouch_get_settings();
  283. if ( isset( $settings['custom-user-agents'] ) ) {
  284. foreach( $settings['custom-user-agents'] as $agent ) {
  285. if ( !strlen( $agent ) ) continue;
  286. $useragents[] = $agent;
  287. }
  288. }
  289. asort( $useragents );
  290. // WPtouch User Agent Filter
  291. $useragents = apply_filters( 'wptouch_user_agents', $useragents );
  292. return $useragents;
  293. }
  294. function bnc_wptouch_is_prowl_key_valid() {
  295. require_once( 'include/class.prowl.php' );
  296. $settings = bnc_wptouch_get_settings();
  297. if ( isset( $settings['prowl-api'] ) ) {
  298. $api_key = $settings['prowl-api'];
  299. $prowl = new Prowl( $api_key, WPTOUCH_PROWL_APPNAME );
  300. $verify = $prowl->verify();
  301. return ( $verify === true );
  302. }
  303. return false;
  304. }
  305. class WPtouchPlugin {
  306. var $applemobile;
  307. var $desired_view;
  308. var $output_started;
  309. var $prowl_output;
  310. var $prowl_success;
  311. function WPtouchPlugin() {
  312. $this->output_started = false;
  313. $this->applemobile = false;
  314. $this->prowl_output = false;
  315. $this->prowl_success = false;
  316. // Don't change the template directory when in the admin panel
  317. add_action( 'plugins_loaded', array(&$this, 'detectAppleMobile') );
  318. if ( !is_admin() ) {
  319. add_filter( 'stylesheet', array(&$this, 'get_stylesheet') );
  320. add_filter( 'theme_root', array(&$this, 'theme_root') );
  321. add_filter( 'theme_root_uri', array(&$this, 'theme_root_uri') );
  322. add_filter( 'template', array(&$this, 'get_template') );
  323. }
  324. add_filter( 'init', array(&$this, 'bnc_filter_iphone') );
  325. add_filter( 'wp', array(&$this, 'bnc_do_redirect') );
  326. add_filter( 'wp', array( &$this, 'bnc_check_switch_redirect') );
  327. add_filter( 'wp_head', array(&$this, 'bnc_head') );
  328. add_filter( 'query_vars', array( &$this, 'wptouch_query_vars' ) );
  329. add_filter( 'parse_request', array( &$this, 'wptouch_parse_request' ) );
  330. add_action( 'comment_post', array( &$this, 'wptouch_handle_new_comment' ) );
  331. add_action( 'user_register', array( &$this, 'wptouch_handle_new_user' ) );
  332. add_action( 'wptouch_core_header_enqueue', 'wptouch_header_advertising' );
  333. $this->detectAppleMobile();
  334. }
  335. function wptouch_cleanup_growl( $msg ) {
  336. $msg = str_replace("\r\n","\n", $msg);
  337. $msg = str_replace("\r","\n", $msg);
  338. return $msg;
  339. }
  340. function wptouch_output_supports_in_footer( $content ) {
  341. $mobile_string = sprintf( __( 'Mobile site by %s', 'wptouch' ), '<a href="http://www.bravenewcode.com/wptouch" title="Mobile iPhone and iPad Plugin for WordPress">WPtouch</a>' );
  342. $content = str_replace( 'WordPress</a>', 'WordPress</a><br />' . $mobile_string, $content );
  343. return $content;
  344. }
  345. function wptouch_show_supports_in_footer() {
  346. ob_start( array( &$this, 'wptouch_output_supports_in_footer' ) );
  347. }
  348. function wptouch_send_prowl_message( $title, $message ) {
  349. require_once( 'include/class.prowl.php' );
  350. $settings = bnc_wptouch_get_settings();
  351. if ( isset( $settings['prowl-api'] ) ) {
  352. $api_key = $settings['prowl-api'];
  353. $prowl = new Prowl( $api_key, $settings['header-title'] );
  354. $this->prowl_output = true;
  355. $result = $prowl->add( 1, $title, $this->wptouch_cleanup_growl( stripslashes( $message ) ) );
  356. if ( $result ) {
  357. $this->prowl_success = true;
  358. } else {
  359. $this->prowl_success = false;
  360. }
  361. } else {
  362. return false;
  363. }
  364. }
  365. function wptouch_handle_new_comment( $comment_id, $approval_status = '1' ) {
  366. $settings = bnc_wptouch_get_settings();
  367. if ( $approval_status != 'spam'
  368. && isset( $settings['prowl-api'] )
  369. && isset( $settings['enable-prowl-comments-button'])
  370. && $settings['enable-prowl-comments-button'] == 1 ) {
  371. $api_key = $settings['prowl-api'];
  372. require_once( 'include/class.prowl.php' );
  373. $comment = get_comment( $comment_id );
  374. $prowl = new Prowl( $api_key, $settings['header-title'] );
  375. if ( $comment->comment_type != 'spam' && $comment->comment_approved != 'spam' ) {
  376. if ( $comment->comment_type == 'trackback' || $comment->comment_type == 'pingback' ) {
  377. $result = $prowl->add( 1,
  378. __( "New Ping/Trackback", "wptouch" ),
  379. 'From: '. $this->wptouch_cleanup_growl( stripslashes( $comment->comment_author ) ) .
  380. "\nPost: ". $this->wptouch_cleanup_growl( stripslashes( $comment->comment_content ) )
  381. );
  382. } else {
  383. $result = $prowl->add( 1,
  384. __( "New Comment", "wptouch" ),
  385. 'Name: '. $this->wptouch_cleanup_growl( stripslashes( $comment->comment_author ) ) .
  386. "\nE-Mail: ". $this->wptouch_cleanup_growl( stripslashes( $comment->comment_author_email ) ) .
  387. "\nComment: ". $this->wptouch_cleanup_growl( stripslashes( $comment->comment_content ) )
  388. );
  389. }
  390. }
  391. }
  392. }
  393. function wptouch_handle_new_user( $user_id ) {
  394. $settings = bnc_wptouch_get_settings();
  395. if ( isset( $settings['prowl-api'] )
  396. && isset( $settings['enable-prowl-users-button'] )
  397. && $settings['enable-prowl-users-button'] == 1 ) {
  398. global $wpdb;
  399. $api_key = $settings['prowl-api'];
  400. require_once( 'include/class.prowl.php' );
  401. global $table_prefix;
  402. $sql = $wpdb->prepare( "SELECT * from " . $table_prefix . "users WHERE ID = %d", $user_id );
  403. $user = $wpdb->get_row( $sql );
  404. if ( $user ) {
  405. $prowl = new Prowl( $api_key, $settings['header-title'] );
  406. $result = $prowl->add( 1,
  407. __( "User Registration", "wptouch" ),
  408. 'Name: '. $this->wptouch_cleanup_growl( stripslashes( $user->user_login ) ) .
  409. "\nE-Mail: ". $this->wptouch_cleanup_growl( stripslashes( $user->user_email ) )
  410. );
  411. }
  412. }
  413. }
  414. function wptouch_query_vars( $vars ) {
  415. $vars[] = "wptouch";
  416. return $vars;
  417. }
  418. function wptouch_parse_request( $wp ) {
  419. if (array_key_exists( "wptouch", $wp->query_vars ) ) {
  420. switch ( $wp->query_vars["wptouch"] ) {
  421. case "upload":
  422. include( 'ajax/file_upload.php' );
  423. break;
  424. }
  425. exit;
  426. }
  427. }
  428. function bnc_head() {
  429. if ( $this->applemobile && $this->desired_view == 'normal' ) {
  430. echo "<link rel='stylesheet' type='text/css' href='" . compat_get_plugin_url( 'wptouch' ) . "/themes/core/core-css/wptouch-switch-link.css'></link>\n";
  431. }
  432. }
  433. function bnc_do_redirect() {
  434. global $post;
  435. // check for wptouch prowl direct messages
  436. $nonce = '';
  437. if ( isset( $_POST['_nonce'] ) ) {
  438. $nonce = $_POST['_nonce'];
  439. }
  440. if ( isset( $_POST['wptouch-prowl-message'] ) && wp_verify_nonce( $nonce, 'wptouch-prowl' ) ) {
  441. $name = $_POST['prowl-msg-name'];
  442. $email = $_POST['prowl-msg-email'];
  443. $msg = $_POST['prowl-msg-message'];
  444. $title = __( "Direct Message", "wptouch" );
  445. $prowl_message = 'From: '. $this->wptouch_cleanup_growl( $name ) .
  446. "\nE-Mail: ". $this->wptouch_cleanup_growl( $email ) .
  447. "\nMessage: ". $this->wptouch_cleanup_growl( $msg );
  448. "\nIP: " . $_SERVER["REMOTE_ADDR"] .
  449. $this->wptouch_send_prowl_message( $title, $prowl_message );
  450. }
  451. if ( ( $this->applemobile && $this->desired_view == 'mobile' ) && !isset( $_GET['wptouch_redirect'] ) ) {
  452. $version = (float)get_bloginfo('version');
  453. $is_front = 0;
  454. $is_front = (is_front_page() && (bnc_get_selected_home_page() > 0));
  455. if ( $is_front ) {
  456. $url = get_permalink( bnc_get_selected_home_page() );
  457. header('Location: ' . $url);
  458. die;
  459. }
  460. }
  461. }
  462. function bnc_check_switch_redirect() {
  463. if ( isset( $_GET['wptouch_redirect'] ) ) {
  464. if ( isset( $_GET['wptouch_redirect_nonce'] ) ) {
  465. $nonce = $_GET['wptouch_redirect_nonce'];
  466. if ( !wp_verify_nonce( $nonce, 'wptouch_redirect' ) ) {
  467. _e( 'Nonce failure', 'wptouch' );
  468. die;
  469. }
  470. $protocol = ( !empty($_SERVER['HTTPS']) ) ? 'https://' : 'http://';
  471. $redirect_location = $protocol . $_SERVER['SERVER_NAME'] . $_GET['wptouch_redirect'];
  472. header( 'Location: ' . $redirect_location );
  473. die;
  474. }
  475. }
  476. }
  477. function bnc_filter_iphone() {
  478. $key = 'wptouch_switch_toggle';
  479. $time = time()+60*60*24*365; // one year
  480. $url_path = '/';
  481. if ( isset( $_GET[ 'wptouch_view'] ) ) {
  482. if ( $_GET[ 'wptouch_view' ] == 'mobile' ) {
  483. setcookie( $key, 'mobile', $time, $url_path );
  484. } elseif ( $_GET[ 'wptouch_view' ] == 'normal') {
  485. setcookie( $key, 'normal', $time, $url_path );
  486. }
  487. }
  488. $settings = bnc_wptouch_get_settings();
  489. if (isset($_COOKIE[$key])) {
  490. $this->desired_view = $_COOKIE[$key];
  491. } else {
  492. if ( $settings['enable-regular-default'] || defined( 'XMLRPC_REQUEST' ) || defined( 'APP_REQUEST' ) ) {
  493. $this->desired_view = 'normal';
  494. } else {
  495. $this->desired_view = 'mobile';
  496. }
  497. }
  498. if ( isset( $settings['enable-twenty-eleven-footer'] ) && $settings['enable-twenty-eleven-footer'] ) {
  499. if ( function_exists( 'twentyeleven_setup' ) ) {
  500. add_action( 'twentyeleven_credits', array( &$this, 'handle_footer' ) );
  501. } else if ( function_exists( 'twentyten_setup' ) ) {
  502. add_action( 'twentyten_credits', array( &$this, 'handle_footer' ) );
  503. }
  504. }
  505. }
  506. function handle_footer() {
  507. ob_start( array( &$this, 'handle_footer_done') );
  508. }
  509. function handle_footer_done( $content ) {
  510. if ( function_exists( 'twentyeleven_setup' ) ) {
  511. return str_replace( "WordPress</a>", "WordPress</a> <a href='http://www.wordpress.org/extend/plugins/wptouch'>" . sprintf( __( 'and %s', 'wptouch' ), "WPtouch" ) . "</a>", $content );
  512. } else if ( function_exists( 'twentyten_setup' ) ) {
  513. return str_replace( "WordPress. </a>", "WordPress</a> <a style='background-image: none;' href='http://www.wordpress.org/extend/plugins/wptouch'>" . sprintf( __( 'and %s', 'wptouch' ), "WPtouch" ) . "</a>", $content );
  514. }
  515. }
  516. function detectAppleMobile($query = '') {
  517. $container = $_SERVER['HTTP_USER_AGENT'];
  518. // The below prints out the user agent array. Uncomment to see it shown on the page.
  519. // print_r($container);
  520. $this->applemobile = false;
  521. $useragents = bnc_wptouch_get_user_agents();
  522. $exclude_agents = bnc_wptouch_get_exclude_user_agents();
  523. $devfile = compat_get_plugin_dir( 'wptouch' ) . '/include/developer.mode';
  524. foreach ( $useragents as $useragent ) {
  525. if ( preg_match( "#$useragent#i", $container ) || file_exists( $devfile ) ) {
  526. $this->applemobile = true;
  527. break;
  528. }
  529. }
  530. if ( $this->applemobile && !file_exists( $devfile ) ) {
  531. foreach( $exclude_agents as $agent ) {
  532. if ( preg_match( "#$agent#i", $container ) ) {
  533. $this->applemobile = false;
  534. break;
  535. }
  536. }
  537. }
  538. }
  539. function get_stylesheet( $stylesheet ) {
  540. if ($this->applemobile && $this->desired_view == 'mobile') {
  541. return 'default';
  542. } else {
  543. return $stylesheet;
  544. }
  545. }
  546. function get_template( $template ) {
  547. $this->bnc_filter_iphone();
  548. if ($this->applemobile && $this->desired_view === 'mobile') {
  549. return 'default';
  550. } else {
  551. return $template;
  552. }
  553. }
  554. function get_template_directory( $value ) {
  555. $theme_root = compat_get_plugin_dir( 'wptouch' );
  556. if ($this->applemobile && $this->desired_view === 'mobile') {
  557. return $theme_root . '/themes';
  558. } else {
  559. return $value;
  560. }
  561. }
  562. function theme_root( $path ) {
  563. $theme_root = compat_get_plugin_dir( 'wptouch' );
  564. if ($this->applemobile && $this->desired_view === 'mobile') {
  565. return $theme_root . '/themes';
  566. } else {
  567. return $path;
  568. }
  569. }
  570. function theme_root_uri( $url ) {
  571. if ($this->applemobile && $this->desired_view === 'mobile') {
  572. $dir = compat_get_plugin_url( 'wptouch' ) . "/themes";
  573. return $dir;
  574. } else {
  575. return $url;
  576. }
  577. }
  578. }
  579. global $wptouch_plugin;
  580. $wptouch_plugin = new WPtouchPlugin();
  581. function bnc_wptouch_is_mobile() {
  582. global $wptouch_plugin;
  583. return ( $wptouch_plugin->applemobile && $wptouch_plugin->desired_view == 'mobile' );
  584. }
  585. //Thanks to edyoshi:
  586. function bnc_is_iphone() {
  587. global $wptouch_plugin;
  588. $wptouch_plugin->bnc_filter_iphone();
  589. return $wptouch_plugin->applemobile;
  590. }
  591. // The Automatic Footer Template Switch Code (into "wp_footer()" in regular theme's footer.php)
  592. function wptouch_switch() {
  593. global $wptouch_plugin;
  594. if ( bnc_is_iphone() && $wptouch_plugin->desired_view == 'normal' ) {
  595. echo '<div id="switch">';
  596. _e( "Mobile Theme", "wptouch" );
  597. echo '<div>';
  598. echo "<a id='switch-link' onclick=\"var addActive = document.getElementById('switch-on'); addActive.className = addActive.className + ' active';var removeActive = document.getElementById('switch-off'); removeActive.className = ' ';\" href=\"" . home_url() . "/?wptouch_view=mobile&wptouch_redirect_nonce=" . wp_create_nonce( 'wptouch_redirect' ) . "&wptouch_redirect=" . urlencode( $_SERVER['REQUEST_URI'] ) . "\">";
  599. echo '<span id="switch-on">ON</span>';
  600. echo '<span id="switch-off" class="active">OFF</span>';
  601. echo '</a>';
  602. echo '</div></div>';
  603. }
  604. }
  605. function bnc_options_menu() {
  606. add_options_page( __( 'WPtouch Options', 'wptouch' ), 'WPtouch', 'manage_options', __FILE__, 'bnc_wp_touch_page' );
  607. }
  608. function bnc_wptouch_get_settings() {
  609. return bnc_wp_touch_get_menu_pages();
  610. }
  611. function bnc_validate_wptouch_settings( &$settings ) {
  612. global $wptouch_defaults;
  613. foreach ( $wptouch_defaults as $key => $value ) {
  614. if ( !isset( $settings[$key] ) ) {
  615. $settings[$key] = $value;
  616. }
  617. }
  618. }
  619. function bnc_wptouch_is_exclusive() {
  620. $settings = bnc_wptouch_get_settings();
  621. return $settings['enable-exclusive'];
  622. }
  623. function bnc_can_show_tweets() {
  624. $settings = bnc_wptouch_get_settings();
  625. return $settings['enable-show-tweets'];
  626. }
  627. function bnc_can_show_comments() {
  628. $settings = bnc_wptouch_get_settings();
  629. return $settings['enable-show-comments'];
  630. }
  631. function bnc_wp_touch_get_menu_pages() {
  632. $v = get_option('bnc_iphone_pages');
  633. if (!$v) {
  634. $v = array();
  635. }
  636. if (!is_array($v)) {
  637. $v = unserialize($v);
  638. }
  639. bnc_validate_wptouch_settings( $v );
  640. return $v;
  641. }
  642. function bnc_get_selected_home_page() {
  643. $v = bnc_wp_touch_get_menu_pages();
  644. return $v['home-page'];
  645. }
  646. function wptouch_use_fixed_header() {
  647. $settings = bnc_wptouch_get_settings();
  648. return $settings['enable-fixed-header'];
  649. }
  650. function wptouch_get_stats() {
  651. $options = bnc_wp_touch_get_menu_pages();
  652. if (isset($options['statistics'])) {
  653. echo stripslashes($options['statistics']);
  654. }
  655. }
  656. function bnc_get_title_image() {
  657. $ids = bnc_wp_touch_get_menu_pages();
  658. $title_image = $ids['main_title'];
  659. if ( file_exists( compat_get_plugin_dir( 'wptouch' ) . '/images/icon-pool/' . $title_image ) ) {
  660. $image = compat_get_plugin_url( 'wptouch' ) . '/images/icon-pool/' . $title_image;
  661. } else if ( file_exists( compat_get_upload_dir() . '/wptouch/custom-icons/' . $title_image ) ) {
  662. $image = compat_get_upload_url() . '/wptouch/custom-icons/' . $title_image;
  663. }
  664. return $image;
  665. }
  666. function wptouch_excluded_cats() {
  667. $settings = bnc_wptouch_get_settings();
  668. return stripslashes($settings['excluded-cat-ids']);
  669. }
  670. function wptouch_excluded_tags() {
  671. $settings = bnc_wptouch_get_settings();
  672. return stripslashes($settings['excluded-tag-ids']);
  673. }
  674. function wptouch_custom_footer_msg() {
  675. $settings = bnc_wptouch_get_settings();
  676. return stripslashes($settings['custom-footer-msg']);
  677. }
  678. function bnc_excerpt_enabled() {
  679. $ids = bnc_wp_touch_get_menu_pages();
  680. return $ids['enable-post-excerpts'];
  681. }
  682. function bnc_is_page_coms_enabled() {
  683. $ids = bnc_wp_touch_get_menu_pages();
  684. return $ids['enable-page-coms'];
  685. }
  686. function bnc_is_zoom_enabled() {
  687. $ids = bnc_wp_touch_get_menu_pages();
  688. return $ids['enable-zoom'];
  689. }
  690. function bnc_is_cats_button_enabled() {
  691. $ids = bnc_wp_touch_get_menu_pages();
  692. return $ids['enable-cats-button'];
  693. }
  694. function bnc_is_tags_button_enabled() {
  695. $ids = bnc_wp_touch_get_menu_pages();
  696. return $ids['enable-tags-button'];
  697. }
  698. function bnc_is_search_enabled() {
  699. $ids = bnc_wp_touch_get_menu_pages();
  700. return $ids['enable-search-button'];
  701. }
  702. function bnc_is_gigpress_enabled() {
  703. $ids = bnc_wp_touch_get_menu_pages();
  704. return $ids['enable-gigpress-button'];
  705. }
  706. function bnc_is_flat_icon_enabled() {
  707. $ids = bnc_wp_touch_get_menu_pages();
  708. return $ids['enable-flat-icon'];
  709. }
  710. function bnc_is_login_button_enabled() {
  711. $ids = bnc_wp_touch_get_menu_pages();
  712. if ( ( get_option( 'comment_registration' ) || get_option( 'users_can_register' ) ) && $ids['enable-login-button'] ) {
  713. return true;
  714. } else {
  715. return false;
  716. }
  717. }
  718. function bnc_is_gravatars_enabled() {
  719. $ids = bnc_wp_touch_get_menu_pages();
  720. return $ids['enable-gravatars'];
  721. }
  722. function bnc_show_author() {
  723. $ids = bnc_wp_touch_get_menu_pages();
  724. return $ids['enable-main-name'];
  725. }
  726. function bnc_show_tags() {
  727. $ids = bnc_wp_touch_get_menu_pages();
  728. return $ids['enable-main-tags'];
  729. }
  730. function bnc_show_categories() {
  731. $ids = bnc_wp_touch_get_menu_pages();
  732. return $ids['enable-main-categories'];
  733. }
  734. function bnc_is_home_enabled() {
  735. $ids = bnc_wp_touch_get_menu_pages();
  736. return $ids['enable-main-home'];
  737. }
  738. function bnc_is_rss_enabled() {
  739. $ids = bnc_wp_touch_get_menu_pages();
  740. return $ids['enable-main-rss'];
  741. }
  742. function bnc_is_email_enabled() {
  743. $ids = bnc_wp_touch_get_menu_pages();
  744. return $ids['enable-main-email'];
  745. }
  746. function bnc_is_truncated_enabled() {
  747. $ids = bnc_wp_touch_get_menu_pages();
  748. return $ids['enable-truncated-titles'];
  749. }
  750. // Prowl Functions
  751. function bnc_is_prowl_direct_message_enabled() {
  752. $settings = bnc_wptouch_get_settings();
  753. return ( isset( $settings['enable-prowl-message-button'] ) && $settings['enable-prowl-message-button'] && $settings['prowl-api'] );
  754. }
  755. function bnc_prowl_did_try_message() {
  756. global $wptouch_plugin;
  757. return $wptouch_plugin->prowl_output;
  758. }
  759. function bnc_prowl_message_success() {
  760. global $wptouch_plugin;
  761. return $wptouch_plugin->prowl_success;
  762. }
  763. // End prowl functions
  764. function bnc_wp_touch_get_pages() {
  765. global $table_prefix;
  766. global $wpdb;
  767. $ids = bnc_wp_touch_get_menu_pages();
  768. $a = array();
  769. $keys = array();
  770. foreach ($ids as $k => $v) {
  771. if ($k == 'main_title' || $k == 'enable-post-excerpts' || $k == 'enable-page-coms' ||
  772. $k == 'enable-cats-button' || $k == 'enable-tags-button' || $k == 'enable-search-button' ||
  773. $k == 'enable-login-button' || $k == 'enable-gravatars' ||
  774. $k == 'enable-main-home' || $k == 'enable-main-rss' || $k == 'enable-main-email' ||
  775. $k == 'enable-truncated-titles' || $k == 'enable-main-name' || $k == 'enable-main-tags' ||
  776. $k == 'enable-main-categories' || $k == 'enable-prowl-comments-button' || $k == 'enable-prowl-users-button' ||
  777. $k == 'enable-prowl-message-button' || $k == 'enable-gigpress-button' || $k == 'enable-flat-icon') {
  778. } else {
  779. if (is_numeric($k)) {
  780. $keys[] = $k;
  781. }
  782. }
  783. }
  784. $menu_order = array();
  785. $results = false;
  786. if ( count( $keys ) > 0 ) {
  787. if ( isset( $ids['sort-order'] ) && $ids['sort-order'] == 'page' ) {
  788. $query = "SELECT * from {$table_prefix}posts WHERE ID IN (" . implode(',', $keys) . ") AND post_status = 'publish' ORDER BY ID ASC";
  789. } else {
  790. $query = "SELECT * from {$table_prefix}posts WHERE ID IN (" . implode(',', $keys) . ") AND post_status = 'publish' ORDER BY post_title ASC";
  791. }
  792. $results = $wpdb->get_results( $query, ARRAY_A );
  793. }
  794. if ( $results ) {
  795. $inc = 0;
  796. foreach ( $results as $row ) {
  797. $row['icon'] = $ids[$row['ID']];
  798. $a[$row['ID']] = $row;
  799. if (isset($menu_order[$row['menu_order']])) {
  800. $menu_order[$row['menu_order']*100 + $inc] = $row;
  801. } else {
  802. $menu_order[$row['menu_order']*100] = $row;
  803. }
  804. $inc = $inc + 1;
  805. }
  806. }
  807. if ( isset($ids['sort-order']) && $ids['sort-order'] == 'page' ) {
  808. return $menu_order;
  809. } else {
  810. return $a;
  811. }
  812. }
  813. function bnc_the_page_icon() {
  814. $settings = bnc_wp_touch_get_menu_pages();
  815. $mypages = bnc_wp_touch_get_pages();
  816. $icon_name = false;
  817. if ( isset( $settings['sort-order'] ) && $settings['sort-order'] == 'page' ) {
  818. global $post;
  819. foreach( $mypages as $key => $page ) {
  820. if ( $page['ID'] == $post->ID ) {
  821. $icon_name = $page['icon'];
  822. break;
  823. }
  824. }
  825. } else {
  826. if ( isset( $mypages[ get_the_ID() ]) ) {
  827. $icon_name = $mypages[ get_the_ID() ]['icon'];
  828. }
  829. }
  830. if ( $icon_name ) {
  831. if ( file_exists( compat_get_plugin_dir( 'wptouch' ) . '/images/icon-pool/' . $icon_name ) ) {
  832. $image = compat_get_plugin_url( 'wptouch' ) . '/images/icon-pool/' . $icon_name;
  833. } else {
  834. $image = compat_get_upload_url() . '/wptouch/custom-icons/' . $icon_name;
  835. }
  836. echo( '<img class="pageicon" src="' . $image . '" alt="icon" />' );
  837. } else {
  838. echo( '<img class="pageicon" src="' . compat_get_plugin_url( 'wptouch' ) . '/images/icon-pool/Default.png" alt="pageicon" />');
  839. }
  840. }
  841. function bnc_get_header_title() {
  842. $v = bnc_wp_touch_get_menu_pages();
  843. return $v['header-title'];
  844. }
  845. function bnc_get_header_background() {
  846. $v = bnc_wp_touch_get_menu_pages();
  847. return $v['header-background-color'];
  848. }
  849. function bnc_get_header_border_color() {
  850. $v = bnc_wp_touch_get_menu_pages();
  851. return $v['header-border-color'];
  852. }
  853. function bnc_get_header_color() {
  854. $v = bnc_wp_touch_get_menu_pages();
  855. return $v['header-text-color'];
  856. }
  857. function bnc_get_link_color() {
  858. $v = bnc_wp_touch_get_menu_pages();
  859. return $v['link-color'];
  860. }
  861. function bnc_get_h2_font() {
  862. $v = bnc_wp_touch_get_menu_pages();
  863. return $v['h2-font'];
  864. }
  865. function bnc_get_icon_style() {
  866. $v = bnc_wp_touch_get_menu_pages();
  867. return $v['icon-style'];
  868. }
  869. function bnc_wptouch_can_show_powered_by() {
  870. $settings = bnc_wp_touch_get_menu_pages();
  871. return $settings['show_powered_by'];
  872. }
  873. function bnc_get_wptouch_custom_lang_files() {
  874. $lang_files = array();
  875. $lang_dir = WP_CONTENT_DIR . '/wptouch/lang';
  876. if ( file_exists( $lang_dir ) ) {
  877. $d = opendir( $lang_dir );
  878. if ( $d ) {
  879. while ( $f = readdir( $d ) ) {
  880. if ( strpos( $f, ".mo" ) !== false ) {
  881. $file_info = new stdClass;
  882. $file_info->name = $f;
  883. $file_info->path = $lang_dir . '/' . $f;
  884. $file_info->prefix = str_replace( ".mo", "", $f );
  885. $lang_files[] = $file_info;
  886. }
  887. }
  888. }
  889. }
  890. return $lang_files;
  891. }
  892. require_once( 'include/icons.php' );
  893. function bnc_wp_touch_page() {
  894. if (isset($_POST['submit'])) {
  895. echo('<div class="wrap"><div id="bnc-global"><div id="wptouchupdated"><p class="saved"><span>');
  896. echo __( "Settings saved!", "wptouch");
  897. echo('</span></p></div>');
  898. }
  899. elseif (isset($_POST['reset'])) {
  900. echo('<div class="wrap"><div id="bnc-global"><div id="wptouchupdated"><p class="reset"><span>');
  901. echo __( "Defaults restored.", "wptouch");
  902. echo('</span></p></div>');
  903. } else {
  904. echo('<div class="wrap"><div id="bnc-global">');
  905. }
  906. ?>
  907. <?php $icons = bnc_get_icon_list(); ?>
  908. <?php require_once( 'include/submit.php' ); ?>
  909. <form method="post" action="<?php echo admin_url( 'options-general.php?page=wptouch/wptouch.php' ); ?>">
  910. <?php require_once( 'html/head-area.php' ); ?>
  911. <?php require_once( 'html/general-settings-area.php' ); ?>
  912. <?php require_once( 'html/advanced-area.php' ); ?>
  913. <?php require_once( 'html/push-area.php' ); ?>
  914. <?php require_once( 'html/style-area.php' ); ?>
  915. <?php require_once( 'html/ads-stats-area.php' ); ?>
  916. <?php require_once( 'html/icon-area.php' ); ?>
  917. <?php require_once( 'html/page-area.php' ); ?>
  918. <input type="hidden" name="wptouch-nonce" value="<?php echo wp_create_nonce( 'wptouch-nonce' ); ?>" />
  919. <input type="submit" name="submit" value="<?php _e('Save Options', 'wptouch' ); ?>" id="bnc-button" class="button-primary" />
  920. </form>
  921. <form method="post" action="">
  922. <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" />
  923. </form>
  924. <?php // echo( '' . WPtouch( '<div class="bnc-plugin-version"> This is ','</div>' ) . '' ); ?>
  925. <div class="bnc-clearer"></div>
  926. </div>
  927. <?php
  928. echo('</div>'); }
  929. add_filter( 'init', 'wptouch_init' );
  930. add_action( 'wp_footer', 'wptouch_switch' );
  931. add_action( 'admin_init', 'wptouch_admin_enqueue_files' );
  932. add_action( 'admin_head', 'wptouch_admin_files' );
  933. add_action( 'admin_menu', 'bnc_options_menu' );
  934. add_filter( 'plugin_action_links', 'wptouch_settings_link', 9, 2 );