PageRenderTime 51ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://gitlab.com/Gashler/sg
PHP | 290 lines | 218 code | 42 blank | 30 comment | 52 complexity | 9d9f00b4c0c63520f5371c5e5a3a510b 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 == get_option('wp_mobile_disable') )
  33. return false;
  34. if ( isset($_COOKIE['akm_mobile']) && $_COOKIE['akm_mobile'] == 'true' )
  35. return true;
  36. $is_mobile = jetpack_is_mobile();
  37. return apply_filters( 'jetpack_check_mobile', $is_mobile );
  38. }
  39. function jetpack_mobile_exclude() {
  40. $exclude = false;
  41. $pages_to_exclude = array(
  42. 'wp-admin',
  43. 'wp-comments-post.php',
  44. 'wp-mail.php',
  45. 'wp-login.php',
  46. 'wp-activate.php',
  47. );
  48. foreach ( $pages_to_exclude as $exclude_page ) {
  49. if ( strstr( strtolower( $_SERVER['REQUEST_URI'] ), $exclude_page ) )
  50. $exclude = true;
  51. }
  52. if ( defined( 'DOING_AJAX' ) && true === DOING_AJAX )
  53. $exclude = false;
  54. if ( isset( $GLOBALS['wp_customize'] ) )
  55. return true;
  56. return $exclude;
  57. }
  58. function wp_mobile_get_main_template() {
  59. remove_action( 'option_template', 'jetpack_mobile_template' );
  60. $template = get_option( 'template' );
  61. add_action( 'option_template', 'jetpack_mobile_template' );
  62. return $template;
  63. }
  64. function wp_mobile_get_main_stylesheet() {
  65. remove_action( 'option_stylesheet', 'jetpack_mobile_stylesheet' );
  66. $stylesheet = get_option( 'stylesheet' );
  67. add_action( 'option_stylesheet', 'jetpack_mobile_stylesheet' );
  68. return $stylesheet;
  69. }
  70. function jetpack_mobile_stylesheet( $theme ) {
  71. return apply_filters( 'jetpack_mobile_stylesheet', 'pub/minileven', $theme );
  72. }
  73. function jetpack_mobile_template( $theme ) {
  74. return apply_filters( 'jetpack_mobile_template', 'pub/minileven', $theme );
  75. }
  76. function jetpack_mobile_available() {
  77. echo '<div style="text-align:center;margin:10px 0;"><a href="'. home_url( '?ak_action=accept_mobile' ) . '">' . __( 'View Mobile Site', 'jetpack' ) . '</a></div>';
  78. }
  79. function jetpack_mobile_request_handler() {
  80. global $wpdb;
  81. if (isset($_GET['ak_action'])) {
  82. $url = parse_url( get_bloginfo( 'url' ) );
  83. $domain = $url['host'];
  84. if (!empty($url['path'])) {
  85. $path = $url['path'];
  86. }
  87. else {
  88. $path = '/';
  89. }
  90. $redirect = false;
  91. switch ($_GET['ak_action']) {
  92. case 'reject_mobile':
  93. setcookie(
  94. 'akm_mobile'
  95. , 'false'
  96. , time() + 300000
  97. , $path
  98. , $domain
  99. );
  100. $redirect = true;
  101. do_action( 'mobile_reject_mobile' );
  102. break;
  103. case 'force_mobile':
  104. case 'accept_mobile':
  105. setcookie(
  106. 'akm_mobile'
  107. , 'true'
  108. , time() + 300000
  109. , $path
  110. , $domain
  111. );
  112. $redirect = true;
  113. do_action( 'mobile_force_mobile' );
  114. break;
  115. }
  116. if ($redirect) {
  117. if ( isset( $_GET['redirect_to'] ) && $_GET['redirect_to'] ) {
  118. $go = urldecode( $_GET['redirect_to'] );
  119. } else if (!empty($_SERVER['HTTP_REFERER'])) {
  120. $go = $_SERVER['HTTP_REFERER'];
  121. }
  122. else {
  123. $go = remove_query_arg( array( 'ak_action' ) );
  124. }
  125. wp_safe_redirect( $go );
  126. exit;
  127. }
  128. }
  129. }
  130. add_action('init', 'jetpack_mobile_request_handler');
  131. function jetpack_mobile_theme_setup() {
  132. if ( jetpack_check_mobile() ) {
  133. // Redirect to download page if user clicked mobile app promo link in mobile footer
  134. if ( isset( $_GET['app-download'] ) ) {
  135. do_action( 'mobile_app_promo_download', $_GET['app-download'] );
  136. switch ( $_GET['app-download'] ) {
  137. case 'android':
  138. header( 'Location: market://search?q=pname:org.wordpress.android' );
  139. exit;
  140. break;
  141. case 'ios':
  142. header( 'Location: http://itunes.apple.com/us/app/wordpress/id335703880?mt=8' );
  143. exit;
  144. break;
  145. case 'blackberry':
  146. header( 'Location: http://blackberry.wordpress.org/download/' );
  147. exit;
  148. break;
  149. }
  150. }
  151. add_action('stylesheet', 'jetpack_mobile_stylesheet');
  152. add_action('template', 'jetpack_mobile_template');
  153. add_action('option_template', 'jetpack_mobile_template');
  154. add_action('option_stylesheet', 'jetpack_mobile_stylesheet');
  155. if ( class_exists( 'Jetpack_Custom_CSS' ) && method_exists( 'Jetpack_Custom_CSS', 'disable' ) && ! get_option( 'wp_mobile_custom_css' ) )
  156. add_action( 'init', array( 'Jetpack_Custom_CSS', 'disable' ), 11 );
  157. do_action( 'mobile_setup' );
  158. }
  159. }
  160. // Need a hook after plugins_loaded (since this code won't be loaded in Jetpack
  161. // until then) but after init (because it has its own init hooks to add).
  162. add_action( 'setup_theme', 'jetpack_mobile_theme_setup' );
  163. if (isset($_COOKIE['akm_mobile']) && $_COOKIE['akm_mobile'] == 'false') {
  164. add_action('wp_footer', 'jetpack_mobile_available');
  165. }
  166. function jetpack_mobile_app_promo() {
  167. ?>
  168. <script type="text/javascript">
  169. if ( ! navigator.userAgent.match( /wp-(iphone|android|blackberry|nokia|windowsphone)/i ) ) {
  170. if ( ( navigator.userAgent.match( /iphone/i ) ) || ( navigator.userAgent.match( /ipod/i ) ) )
  171. 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 />' );
  172. else if ( ( navigator.userAgent.match( /android/i ) ) && ( null == navigator.userAgent.match( /playbook/i ) && null == navigator.userAgent.match( /bb10/i ) ) )
  173. 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 />' );
  174. else if ( ( navigator.userAgent.match( /blackberry/i ) ) || ( navigator.userAgent.match( /playbook/i ) ) || ( navigator.userAgent.match( /bb10/i ) ) )
  175. 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 />' );
  176. }
  177. </script>
  178. <?php
  179. }
  180. add_action( 'wp_mobile_theme_footer', 'jetpack_mobile_app_promo' );
  181. /**
  182. * Adds an option to allow your Custom CSS to also be applied to the Mobile Theme.
  183. * It's disabled by default, but this should allow people who know what they're
  184. * doing to customize the mobile theme.
  185. */
  186. function jetpack_mobile_css_settings() {
  187. $mobile_css = get_option( 'wp_mobile_custom_css' );
  188. ?>
  189. <div class="misc-pub-section">
  190. <label><?php esc_html_e( 'Mobile-compatible:', 'jetpack' ); ?></label>
  191. <span id="mobile-css-display"><?php echo $mobile_css ? __( 'Yes', 'jetpack' ) : __( 'No', 'jetpack' ); ?></span>
  192. <a class="edit-mobile-css hide-if-no-js" href="#mobile-css"><?php echo esc_html_e( 'Edit', 'jetpack' ); ?></a>
  193. <div id="mobile-css-select" class="hide-if-js">
  194. <input type="hidden" name="mobile_css" id="mobile-css" value="<?php echo intval( $mobile_css ); ?>" />
  195. <label>
  196. <input type="checkbox" id="mobile-css-visible" <?php checked( get_option( 'wp_mobile_custom_css' ) ); ?> />
  197. <?php esc_html_e( 'Include this CSS in the Mobile Theme', 'jetpack' ); ?>
  198. </label>
  199. <p>
  200. <a class="save-mobile-css hide-if-no-js button" href="#mobile-css"><?php esc_html_e( 'OK', 'jetpack' ); ?></a>
  201. <a class="cancel-mobile-css hide-if-no-js" href="#mobile-css"><?php esc_html_e( 'Cancel', 'jetpack' ); ?></a>
  202. </p>
  203. </div>
  204. </div>
  205. <script type="text/javascript">
  206. jQuery( function ( $ ) {
  207. $( '.edit-mobile-css' ).bind( 'click', function ( e ) {
  208. e.preventDefault();
  209. $( '#mobile-css-select' ).slideDown();
  210. $( this ).hide();
  211. } );
  212. $( '.cancel-mobile-css' ).bind( 'click', function ( e ) {
  213. e.preventDefault();
  214. $( '#mobile-css-select' ).slideUp( function () {
  215. $( '.edit-mobile-css' ).show();
  216. $( '#mobile-css-visible' ).prop( 'checked', $( '#mobile-css' ).val() == '1' );
  217. } );
  218. } );
  219. $( '.save-mobile-css' ).bind( 'click', function ( e ) {
  220. e.preventDefault();
  221. $( '#mobile-css-select' ).slideUp();
  222. $( '#mobile-css-display' ).text( $( '#mobile-css-visible' ).prop( 'checked' ) ? 'Yes' : 'No' );
  223. $( '#mobile-css' ).val( $( '#mobile-css-visible' ).prop( 'checked' ) ? '1' : '0' );
  224. $( '.edit-mobile-css' ).show();
  225. } );
  226. } );
  227. </script>
  228. <?php
  229. }
  230. add_action( 'custom_css_submitbox_misc_actions', 'jetpack_mobile_css_settings' );
  231. function jetpack_mobile_customizer_controls( $wp_customize ) {
  232. $wp_customize->add_setting( 'wp_mobile_custom_css' , array(
  233. 'default' => true,
  234. 'transport' => 'postMessage',
  235. 'type' => 'option'
  236. ) );
  237. $wp_customize->add_control( 'jetpack_mobile_css_control', array(
  238. 'type' => 'checkbox',
  239. 'label' => __( 'Include this CSS in the Mobile Theme', 'jetpack' ),
  240. 'section' => 'jetpack_custom_css',
  241. 'settings' => 'wp_mobile_custom_css',
  242. ) );
  243. }
  244. add_action( 'jetpack_custom_css_customizer_controls', 'jetpack_mobile_customizer_controls' );
  245. function jetpack_mobile_save_css_settings() {
  246. update_option( 'wp_mobile_custom_css', isset( $_POST['mobile_css'] ) && ! empty( $_POST['mobile_css'] ) );
  247. }
  248. add_action( 'safecss_save_pre', 'jetpack_mobile_save_css_settings' );