Last active
December 12, 2015 02:18
-
-
Save tokkonopapa/4697073 to your computer and use it in GitHub Desktop.
WPtouch switch for Quick Cache.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* WPtouch switch for Quick Cache | |
* - WPtouch 1.9.6.1 | |
* - Ktai Style 2.0.5 | |
* - Quick Cache 111203 | |
* | |
* Quick Cache MD5 Version Salt (smartphone, featurephone) | |
* ((preg_match("{AdsBot-Google|Android|BB10|BlackBerry 9350|BlackBerry 9360|BlackBerry 9370|BlackBerry 9380|BlackBerry 9780|BlackBerry 9790|BlackBerry 9800|BlackBerry 9810|BlackBerry 9850|BlackBerry 9860|BlackBerry 9900|BlackBerry 9930|BlackBerry9500|BlackBerry9520|BlackBerry9530|BlackBerry9550|CUPCAKE|Googlebot-Mobile|bada|dream|froyo|iPhone|iPod|incognito|s8000|webOS|webmate}", $_SERVER["HTTP_USER_AGENT"])) && $_COOKIE["wptouch_switch_toggle"] != "normal" ? "smartphone" : ((preg_match("{DoCoMo/|J-PHONE/|J-EMULATOR/|Vodafone/|MOT(EMULATOR)?-|SoftBank/|[VS]emulator/|KDDI-|UP\.Browser/|emobile/|Huawei/|IAC/|Nokia|mixi-mobile-converter/|DDIPOCKET;|WILLCOM;|Opera Mini|Opera Mobi|PalmOS|Windows CE;|PDA; SL-|PlayStation Portable;|SONY/COM|Nitro|Nintendo}", $_SERVER["HTTP_USER_AGENT"])) ? "featurephone" : "")) | |
* | |
* @todo add this program to theme function.php | |
*/ | |
if (isset($GLOBALS['wptouch_plugin'])) { | |
function wptouch_switch_script() { | |
echo "<script type='text/javascript'>"; | |
echo "if (window.navigator.userAgent.match(/(AdsBot-Google|Android|BB10|BlackBerry 9350|BlackBerry 9360|BlackBerry 9370|BlackBerry 9380|BlackBerry 9780|BlackBerry 9790|BlackBerry 9800|BlackBerry 9810|BlackBerry 9850|BlackBerry 9860|BlackBerry 9900|BlackBerry 9930|BlackBerry9500|BlackBerry9520|BlackBerry9530|BlackBerry9550|CUPCAKE|Googlebot-Mobile|bada|dream|froyo|iPhone|iPod|incognito|s8000|webOS|webmate)/)) {"; | |
// Load stylesheet | |
echo "var link = document.createElement('link');"; | |
echo "link.rel = 'stylesheet';"; | |
echo "link.href = '" . WP_PLUGIN_URL . "/wptouch/themes/core/core-css/wptouch-switch-link.css';"; | |
echo "link.type = 'text/css';"; | |
echo "link.media = 'screen';"; | |
echo "document.getElementsByTagName('head')[0].appendChild(link);"; | |
// Render switch (same as wptouch_switch() in wptouch.php) | |
echo "document.write(\""; | |
echo "<div id='switch'>"; | |
_e( "Mobile Theme", "wptouch" ); | |
echo "<div>"; | |
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'] ) . "'>"; | |
echo "<span id='switch-on'>ON</span>"; | |
echo "<span id='switch-off' class='active'>OFF</span>"; | |
echo "</a>"; | |
echo "</div></div>"; | |
echo "\");}</script>\n"; | |
} | |
// Substitute the original stylesheet in header and mobile switch in footer | |
remove_filter( 'wp_head', array($GLOBALS['wptouch_plugin'], 'bnc_head') ); | |
remove_action( 'wp_footer', 'wptouch_switch' ); | |
add_action( 'wp_footer', 'wptouch_switch_script' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment