PageRenderTime 38ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/jetpack/modules/minileven/minileven.php

https://gitlab.com/hunt9310/ras
PHP | 347 lines | 218 code | 42 blank | 87 comment | 52 complexity | a7c4b3755767d858bf6ffafcaa925070 MD5 | raw file
  1. <?php
  2. // ********** modify blog option 'wp_mobile_template' manually to specify a theme (ex. 'vip/cnnmobile')
  3. // WordPress Mobile Edition
  4. //
  5. // Copyright (c) 2002-2008 Alex King
  6. // http://alexking.org/projects/wordpress
  7. //
  8. // Released under the GPL license
  9. // http://www.opensource.org/licenses/gpl-license.php
  10. //
  11. // **********************************************************************
  12. // This program is distributed in the hope that it will be useful, but
  13. // WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. // *****************************************************************
  16. /*
  17. Plugin Name: WordPress Mobile Edition
  18. Plugin URI: http://alexking.org/projects/wordpress
  19. Description: Show a mobile view of the post/page if the visitor is on a known mobile device. Questions on configuration, etc.? Make sure to read the README.
  20. Author: Alex King
  21. Author URI: http://alexking.org
  22. Version: 2.1a-WPCOM
  23. */
  24. $_SERVER['REQUEST_URI'] = ( isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['SCRIPT_NAME'] . (( isset($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '')));
  25. function jetpack_check_mobile() {
  26. if ( ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST ) || ( defined('APP_REQUEST') && APP_REQUEST ) )
  27. return false;
  28. if ( !isset($_SERVER["HTTP_USER_AGENT"]) || (isset($_COOKIE['akm_mobile']) && $_COOKIE['akm_mobile'] == 'false') )
  29. return false;
  30. if ( jetpack_mobile_exclude() )
  31. return false;
  32. if ( 1 == Jetpack_Options::get_option_and_ensure_autoload( 'wp_mobile_disable', '0' ) )
  33. return false;
  34. if ( isset($_COOKIE['akm_mobile']) && $_COOKIE['akm_mobile'] == 'true' )
  35. return true;
  36. $is_mobile = jetpack_is_mobile();
  37. /**
  38. * Filter the Mobile check results.
  39. *
  40. * @module minileven
  41. *
  42. * @since 1.8.0
  43. *
  44. * @param bool $is_mobile Is the reader on a mobile device.
  45. */
  46. return apply_filters( 'jetpack_check_mobile', $is_mobile );
  47. }
  48. function jetpack_mobile_exclude() {
  49. $exclude = false;
  50. $pages_to_exclude = array(
  51. 'wp-admin',
  52. 'wp-comments-post.php',
  53. 'wp-mail.php',
  54. 'wp-login.php',
  55. 'wp-activate.php',
  56. );
  57. foreach ( $pages_to_exclude as $exclude_page ) {
  58. if ( strstr( strtolower( $_SERVER['REQUEST_URI'] ), $exclude_page ) )
  59. $exclude = true;
  60. }
  61. if ( defined( 'DOING_AJAX' ) && true === DOING_AJAX )
  62. $exclude = false;
  63. if ( isset( $GLOBALS['wp_customize'] ) )
  64. return true;
  65. return $exclude;
  66. }
  67. function wp_mobile_get_main_template() {
  68. remove_action( 'option_template', 'jetpack_mobile_template' );
  69. $template = get_option( 'template' );
  70. add_action( 'option_template', 'jetpack_mobile_template' );
  71. return $template;
  72. }
  73. function wp_mobile_get_main_stylesheet() {
  74. remove_action( 'option_stylesheet', 'jetpack_mobile_stylesheet' );
  75. $stylesheet = get_option( 'stylesheet' );
  76. add_action( 'option_stylesheet', 'jetpack_mobile_stylesheet' );
  77. return $stylesheet;
  78. }
  79. function jetpack_mobile_stylesheet( $theme ) {
  80. /**
  81. * Filter Jetpack's Mobile stylesheet.
  82. *
  83. * @module minileven
  84. *
  85. * @since 1.8.0
  86. *
  87. * @param string $theme Theme.
  88. */
  89. return apply_filters( 'jetpack_mobile_stylesheet', 'pub/minileven', $theme );
  90. }
  91. function jetpack_mobile_template( $theme ) {
  92. /**
  93. * Filter Jetpack's Mobile template.
  94. *
  95. * @module minileven
  96. *
  97. * @since 1.8.0
  98. *
  99. * @param string $theme Theme.
  100. */
  101. return apply_filters( 'jetpack_mobile_template', 'pub/minileven', $theme );
  102. }
  103. function jetpack_mobile_available() {
  104. echo '<div class="jetpack-mobile-link" style="text-align:center;margin:10px 0;"><a href="'. home_url( '?ak_action=accept_mobile' ) . '">' . __( 'View Mobile Site', 'jetpack' ) . '</a></div>';
  105. }
  106. function jetpack_mobile_request_handler() {
  107. global $wpdb;
  108. if (isset($_GET['ak_action'])) {
  109. $url = parse_url( get_bloginfo( 'url' ) );
  110. $domain = $url['host'];
  111. if (!empty($url['path'])) {
  112. $path = $url['path'];
  113. }
  114. else {
  115. $path = '/';
  116. }
  117. $redirect = false;
  118. switch ($_GET['ak_action']) {
  119. case 'reject_mobile':
  120. setcookie(
  121. 'akm_mobile'
  122. , 'false'
  123. , time() + 300000
  124. , $path
  125. , $domain
  126. );
  127. $redirect = true;
  128. /**
  129. * In Jetpack's Mobile theme, fires after the user taps on the link to display a full version of the site.
  130. *
  131. * @module minileven
  132. *
  133. * @since 1.8.0
  134. */
  135. do_action( 'mobile_reject_mobile' );
  136. break;
  137. case 'force_mobile':
  138. case 'accept_mobile':
  139. setcookie(
  140. 'akm_mobile'
  141. , 'true'
  142. , time() + 300000
  143. , $path
  144. , $domain
  145. );
  146. $redirect = true;
  147. /**
  148. * In Jetpack's Mobile theme, fires after the user taps on the link to go back from full site to mobile site.
  149. *
  150. * @module minileven
  151. *
  152. * @since 1.8.0
  153. */
  154. do_action( 'mobile_force_mobile' );
  155. break;
  156. }
  157. if ($redirect) {
  158. if ( isset( $_GET['redirect_to'] ) && $_GET['redirect_to'] ) {
  159. $go = urldecode( $_GET['redirect_to'] );
  160. } else if (!empty($_SERVER['HTTP_REFERER'])) {
  161. $go = $_SERVER['HTTP_REFERER'];
  162. }
  163. else {
  164. $go = remove_query_arg( array( 'ak_action' ) );
  165. }
  166. wp_safe_redirect( $go );
  167. exit;
  168. }
  169. }
  170. }
  171. add_action('init', 'jetpack_mobile_request_handler');
  172. function jetpack_mobile_theme_setup() {
  173. if ( jetpack_check_mobile() ) {
  174. // Redirect to download page if user clicked mobile app promo link in mobile footer
  175. if ( isset( $_GET['app-download'] ) ) {
  176. /**
  177. * Fires before you're redirected to download page if you clicked the mobile app promo link in mobile footer
  178. *
  179. * @module minileven
  180. *
  181. * @since 1.8.0
  182. *
  183. * @param string $_GET['app-download'] app-download URL parameter.
  184. */
  185. do_action( 'mobile_app_promo_download', $_GET['app-download'] );
  186. switch ( $_GET['app-download'] ) {
  187. case 'android':
  188. header( 'Location: market://search?q=pname:org.wordpress.android' );
  189. exit;
  190. break;
  191. case 'ios':
  192. header( 'Location: http://itunes.apple.com/us/app/wordpress/id335703880?mt=8' );
  193. exit;
  194. break;
  195. case 'blackberry':
  196. header( 'Location: http://blackberry.wordpress.org/download/' );
  197. exit;
  198. break;
  199. }
  200. }
  201. add_action('stylesheet', 'jetpack_mobile_stylesheet');
  202. add_action('template', 'jetpack_mobile_template');
  203. add_action('option_template', 'jetpack_mobile_template');
  204. add_action('option_stylesheet', 'jetpack_mobile_stylesheet');
  205. if ( class_exists( 'Jetpack_Custom_CSS' ) && method_exists( 'Jetpack_Custom_CSS', 'disable' ) && ! get_option( 'wp_mobile_custom_css' ) )
  206. add_action( 'init', array( 'Jetpack_Custom_CSS', 'disable' ), 11 );
  207. /**
  208. * Fires after Jetpack's mobile theme has been setup.
  209. *
  210. * @module minileven
  211. *
  212. * @since 1.8.0
  213. */
  214. do_action( 'mobile_setup' );
  215. }
  216. }
  217. // Need a hook after plugins_loaded (since this code won't be loaded in Jetpack
  218. // until then) but after init (because it has its own init hooks to add).
  219. add_action( 'setup_theme', 'jetpack_mobile_theme_setup' );
  220. if (isset($_COOKIE['akm_mobile']) && $_COOKIE['akm_mobile'] == 'false') {
  221. add_action('wp_footer', 'jetpack_mobile_available');
  222. }
  223. function jetpack_mobile_app_promo() {
  224. ?>
  225. <script type="text/javascript">
  226. if ( ! navigator.userAgent.match( /wp-(iphone|android|blackberry|nokia|windowsphone)/i ) ) {
  227. if ( ( navigator.userAgent.match( /iphone/i ) ) || ( navigator.userAgent.match( /ipod/i ) ) )
  228. document.write( '<span id="wpcom-mobile-app-promo" style="margin-top: 10px; font-size: 13px;"><strong>Now Available!</strong> <a href="/index.php?app-download=ios">Download WordPress for iOS</a></span><br /><br />' );
  229. else if ( ( navigator.userAgent.match( /android/i ) ) && ( null == navigator.userAgent.match( /playbook/i ) && null == navigator.userAgent.match( /bb10/i ) ) )
  230. document.write( '<span id="wpcom-mobile-app-promo" style="margin-top: 10px; font-size: 13px;"><strong>Now Available!</strong> <a href="/index.php?app-download=android">Download WordPress for Android</a></span><br /><br />' );
  231. else if ( ( navigator.userAgent.match( /blackberry/i ) ) || ( navigator.userAgent.match( /playbook/i ) ) || ( navigator.userAgent.match( /bb10/i ) ) )
  232. document.write( '<span id="wpcom-mobile-app-promo" style="margin-top: 10px; font-size: 13px;"><strong>Now Available!</strong> <a href="/index.php?app-download=blackberry">Download WordPress for BlackBerry</a></span><br /><br />' );
  233. }
  234. </script>
  235. <?php
  236. }
  237. add_action( 'wp_mobile_theme_footer', 'jetpack_mobile_app_promo' );
  238. /**
  239. * Adds an option to allow your Custom CSS to also be applied to the Mobile Theme.
  240. * It's disabled by default, but this should allow people who know what they're
  241. * doing to customize the mobile theme.
  242. */
  243. function jetpack_mobile_css_settings() {
  244. $mobile_css = get_option( 'wp_mobile_custom_css' );
  245. ?>
  246. <div class="misc-pub-section">
  247. <label><?php esc_html_e( 'Mobile-compatible:', 'jetpack' ); ?></label>
  248. <span id="mobile-css-display"><?php echo $mobile_css ? __( 'Yes', 'jetpack' ) : __( 'No', 'jetpack' ); ?></span>
  249. <a class="edit-mobile-css hide-if-no-js" href="#mobile-css"><?php echo esc_html_e( 'Edit', 'jetpack' ); ?></a>
  250. <div id="mobile-css-select" class="hide-if-js">
  251. <input type="hidden" name="mobile_css" id="mobile-css" value="<?php echo intval( $mobile_css ); ?>" />
  252. <label>
  253. <input type="checkbox" id="mobile-css-visible" <?php checked( get_option( 'wp_mobile_custom_css' ) ); ?> />
  254. <?php esc_html_e( 'Include this CSS in the Mobile Theme', 'jetpack' ); ?>
  255. </label>
  256. <p>
  257. <a class="save-mobile-css hide-if-no-js button" href="#mobile-css"><?php esc_html_e( 'OK', 'jetpack' ); ?></a>
  258. <a class="cancel-mobile-css hide-if-no-js" href="#mobile-css"><?php esc_html_e( 'Cancel', 'jetpack' ); ?></a>
  259. </p>
  260. </div>
  261. </div>
  262. <script type="text/javascript">
  263. jQuery( function ( $ ) {
  264. $( '.edit-mobile-css' ).bind( 'click', function ( e ) {
  265. e.preventDefault();
  266. $( '#mobile-css-select' ).slideDown();
  267. $( this ).hide();
  268. } );
  269. $( '.cancel-mobile-css' ).bind( 'click', function ( e ) {
  270. e.preventDefault();
  271. $( '#mobile-css-select' ).slideUp( function () {
  272. $( '.edit-mobile-css' ).show();
  273. $( '#mobile-css-visible' ).prop( 'checked', $( '#mobile-css' ).val() == '1' );
  274. } );
  275. } );
  276. $( '.save-mobile-css' ).bind( 'click', function ( e ) {
  277. e.preventDefault();
  278. $( '#mobile-css-select' ).slideUp();
  279. $( '#mobile-css-display' ).text( $( '#mobile-css-visible' ).prop( 'checked' ) ? 'Yes' : 'No' );
  280. $( '#mobile-css' ).val( $( '#mobile-css-visible' ).prop( 'checked' ) ? '1' : '0' );
  281. $( '.edit-mobile-css' ).show();
  282. } );
  283. } );
  284. </script>
  285. <?php
  286. }
  287. add_action( 'custom_css_submitbox_misc_actions', 'jetpack_mobile_css_settings' );
  288. function jetpack_mobile_customizer_controls( $wp_customize ) {
  289. $wp_customize->add_setting( 'wp_mobile_custom_css' , array(
  290. 'default' => true,
  291. 'transport' => 'postMessage',
  292. 'type' => 'option'
  293. ) );
  294. $wp_customize->add_control( 'jetpack_mobile_css_control', array(
  295. 'type' => 'checkbox',
  296. 'label' => __( 'Include this CSS in the Mobile Theme', 'jetpack' ),
  297. 'section' => 'jetpack_custom_css',
  298. 'settings' => 'wp_mobile_custom_css',
  299. ) );
  300. }
  301. add_action( 'jetpack_custom_css_customizer_controls', 'jetpack_mobile_customizer_controls' );
  302. function jetpack_mobile_save_css_settings() {
  303. update_option( 'wp_mobile_custom_css', isset( $_POST['mobile_css'] ) && ! empty( $_POST['mobile_css'] ) );
  304. }
  305. add_action( 'safecss_save_pre', 'jetpack_mobile_save_css_settings' );