| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
if (!function_exists('is_admin_page')) { |
|---|
| 27 |
function is_admin_page() { |
|---|
| 28 |
if (function_exists('is_admin')) { |
|---|
| 29 |
return is_admin(); |
|---|
| 30 |
} |
|---|
| 31 |
if (function_exists('check_admin_referer')) { |
|---|
| 32 |
return true; |
|---|
| 33 |
} |
|---|
| 34 |
else { |
|---|
| 35 |
return false; |
|---|
| 36 |
} |
|---|
| 37 |
} |
|---|
| 38 |
} |
|---|
| 39 |
|
|---|
| 40 |
$_SERVER['REQUEST_URI'] = ( isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['SCRIPT_NAME'] . (( isset($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : ''))); |
|---|
| 41 |
|
|---|
| 42 |
function akm_check_mobile() { |
|---|
| 43 |
if (!isset($_SERVER["HTTP_USER_AGENT"]) || (isset($_COOKIE['akm_mobile']) && $_COOKIE['akm_mobile'] == 'false')) { |
|---|
| 44 |
return false; |
|---|
| 45 |
} |
|---|
| 46 |
if (akm_mobile_exclude()) { |
|---|
| 47 |
return false; |
|---|
| 48 |
} |
|---|
| 49 |
if (isset($_COOKIE['akm_mobile']) && $_COOKIE['akm_mobile'] == 'true') { |
|---|
| 50 |
return true; |
|---|
| 51 |
} |
|---|
| 52 |
$whitelist = array( |
|---|
| 53 |
'Stand Alone/QNws' |
|---|
| 54 |
); |
|---|
| 55 |
foreach ($whitelist as $browser) { |
|---|
| 56 |
if (strstr($_SERVER["HTTP_USER_AGENT"], $browser)) { |
|---|
| 57 |
return false; |
|---|
| 58 |
} |
|---|
| 59 |
} |
|---|
| 60 |
$small_browsers = array( |
|---|
| 61 |
'2.0 MMP' |
|---|
| 62 |
,'240x320' |
|---|
| 63 |
,'AvantGo' |
|---|
| 64 |
,'BlackBerry' |
|---|
| 65 |
,'Blazer' |
|---|
| 66 |
,'Cellphone' |
|---|
| 67 |
,'Danger' |
|---|
| 68 |
,'DoCoMo' |
|---|
| 69 |
,'Elaine/3.0' |
|---|
| 70 |
,'EudoraWeb' |
|---|
| 71 |
,'hiptop' |
|---|
| 72 |
,'IEMobile' |
|---|
| 73 |
,'KYOCERA/WX310K' |
|---|
| 74 |
,'LG/U990' |
|---|
| 75 |
,'MIDP-2.' |
|---|
| 76 |
,'MMEF20' |
|---|
| 77 |
,'MOT-V' |
|---|
| 78 |
,'NetFront' |
|---|
| 79 |
,'Newt' |
|---|
| 80 |
,'Nintendo Wii' |
|---|
| 81 |
,'Nitro' |
|---|
| 82 |
,'Nokia' |
|---|
| 83 |
,'Opera Mini' |
|---|
| 84 |
,'Palm' |
|---|
| 85 |
,'PlayStation Portable' |
|---|
| 86 |
,'portalmmm' |
|---|
| 87 |
,'Proxinet' |
|---|
| 88 |
,'ProxiNet' |
|---|
| 89 |
,'SHARP-TQ-GX10' |
|---|
| 90 |
,'Small' |
|---|
| 91 |
,'SonyEricsson' |
|---|
| 92 |
,'Symbian OS' |
|---|
| 93 |
,'SymbianOS' |
|---|
| 94 |
,'TS21i-10' |
|---|
| 95 |
,'UP.Browser' |
|---|
| 96 |
,'UP.Link' |
|---|
| 97 |
,'Windows CE' |
|---|
| 98 |
,'WinWAP' |
|---|
| 99 |
); |
|---|
| 100 |
|
|---|
| 101 |
foreach ($small_browsers as $browser) { |
|---|
| 102 |
if (strstr($_SERVER["HTTP_USER_AGENT"], $browser)) { |
|---|
| 103 |
return true; |
|---|
| 104 |
} |
|---|
| 105 |
} |
|---|
| 106 |
return false; |
|---|
| 107 |
} |
|---|
| 108 |
|
|---|
| 109 |
function akm_mobile_exclude() { |
|---|
| 110 |
$exclude = false; |
|---|
| 111 |
$pages_to_exclude = array( |
|---|
| 112 |
'wp-admin' |
|---|
| 113 |
,'wp-comments-post.php' |
|---|
| 114 |
,'wp-mail.php' |
|---|
| 115 |
,'wp-login.php' |
|---|
| 116 |
); |
|---|
| 117 |
foreach ($pages_to_exclude as $exclude_page) { |
|---|
| 118 |
if (strstr(strtolower($_SERVER['REQUEST_URI']), $exclude_page)) { |
|---|
| 119 |
$exclude = true; |
|---|
| 120 |
} |
|---|
| 121 |
} |
|---|
| 122 |
return $exclude; |
|---|
| 123 |
} |
|---|
| 124 |
|
|---|
| 125 |
function akm_template($theme) { |
|---|
| 126 |
if (akm_installed()) { |
|---|
| 127 |
return apply_filters('akm_template', 'wp-mobile'); |
|---|
| 128 |
} |
|---|
| 129 |
else { |
|---|
| 130 |
return $theme; |
|---|
| 131 |
} |
|---|
| 132 |
} |
|---|
| 133 |
|
|---|
| 134 |
function akm_installed() { |
|---|
| 135 |
return is_dir(ABSPATH.'/wp-content/themes/wp-mobile'); |
|---|
| 136 |
} |
|---|
| 137 |
|
|---|
| 138 |
if (is_admin_page() && !akm_installed()) { |
|---|
| 139 |
global $wp_version; |
|---|
| 140 |
if (isset($wp_version) && version_compare($wp_version, '2.5', '>=')) { |
|---|
| 141 |
add_action('admin_notices', create_function( '', "echo '<div class=\"error\">WP Mobile is incorrectly installed. Please check the <a href=\"http://alexking.org/projects/wordpress/readme?project=wordpress-mobile-edition\">README</a>.</div>';" ) ); |
|---|
| 142 |
} |
|---|
| 143 |
} |
|---|
| 144 |
|
|---|
| 145 |
function akm_mobile_available($content) { |
|---|
| 146 |
return $content.'<p><a href="'.get_bloginfo('wpurl').'/index.php?ak_action=accept_mobile">Return to the Mobile Edition</a>.</p>'; |
|---|
| 147 |
} |
|---|
| 148 |
|
|---|
| 149 |
function akm_mobile_link() { |
|---|
| 150 |
echo '<a href="'.get_bloginfo('wpurl').'/index.php?ak_action=force_mobile">Mobile Edition</a>'; |
|---|
| 151 |
} |
|---|
| 152 |
|
|---|
| 153 |
if (!function_exists('ak_recent_posts')) { |
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 |
function ak_recent_posts($count = 5, $before = '<li>', $after = '</li>', $hide_pass_post = true, $skip_posts = 0, $show_excerpts = false, $where = '', $join = '', $groupby = '') { |
|---|
| 164 |
$wpdb; |
|---|
| 165 |
$time_difference = get_settings('gmt_offset'); |
|---|
| 166 |
$now = gmdate("Y-m-d H:i:s",time()); |
|---|
| 167 |
|
|---|
| 168 |
$join = apply_filters('posts_join', $join); |
|---|
| 169 |
$where = apply_filters('posts_where', $where); |
|---|
| 170 |
$groupby = apply_filters('posts_groupby', $groupby); |
|---|
| 171 |
$groupby)) { $groupby = ' GROUP BY '.$groupby; } |
|---|
| 172 |
|
|---|
| 173 |
$request = "SELECT ID, post_title, post_excerpt FROM $wpdb->posts $join WHERE post_status = 'publish' AND post_type != 'page' "; |
|---|
| 174 |
$hide_pass_post) $request .= "AND post_password ='' "; |
|---|
| 175 |
$request .= "AND post_date_gmt < '$now' $where $groupby ORDER BY post_date DESC LIMIT $skip_posts, $count"; |
|---|
| 176 |
$posts = $wpdb->get_results($request); |
|---|
| 177 |
$output = ''; |
|---|
| 178 |
$posts) { |
|---|
| 179 |
$posts as $post) { |
|---|
| 180 |
$post_title = stripslashes($post->post_title); |
|---|
| 181 |
$permalink = get_permalink($post->ID); |
|---|
| 182 |
$output .= $before . '<a href="' . $permalink . '" rel="bookmark" title="Permanent Link: ' . htmlspecialchars($post_title, ENT_COMPAT) . '">' . htmlspecialchars($post_title) . '</a>'; |
|---|
| 183 |
$show_excerpts) { |
|---|
| 184 |
$post_excerpt = stripslashes($post->post_excerpt); |
|---|
| 185 |
$output.= '<br />' . $post_excerpt; |
|---|
| 186 |
|
|---|
| 187 |
$output .= $after; |
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 |
$output .= $before . "None found" . $after; |
|---|
| 191 |
|
|---|
| 192 |
$output; |
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 |
akm_request_handler() { |
|---|
| 197 |
$_GET['ak_action'])) { |
|---|
| 198 |
$url = parse_url(get_bloginfo('home')); |
|---|
| 199 |
$domain = $url['host']; |
|---|
| 200 |
$url['path'])) { |
|---|
| 201 |
$path = $url['path']; |
|---|
| 202 |
|
|---|
| 203 |
|
|---|
| 204 |
$path = '/'; |
|---|
| 205 |
|
|---|
| 206 |
$redirect = false; |
|---|
| 207 |
$_GET['ak_action']) { |
|---|
| 208 |
'reject_mobile': |
|---|
| 209 |
setcookie( |
|---|
| 210 |
'akm_mobile' |
|---|
| 211 |
, 'false' |
|---|
| 212 |
, time() + 300000 |
|---|
| 213 |
, $path |
|---|
| 214 |
, $domain |
|---|
| 215 |
); |
|---|
| 216 |
$redirect = true; |
|---|
| 217 |
|
|---|
| 218 |
'force_mobile': |
|---|
| 219 |
'accept_mobile': |
|---|
| 220 |
setcookie( |
|---|
| 221 |
'akm_mobile' |
|---|
| 222 |
, 'true' |
|---|
| 223 |
, time() + 300000 |
|---|
| 224 |
, $path |
|---|
| 225 |
, $domain |
|---|
| 226 |
); |
|---|
| 227 |
$redirect = true; |
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 |
$redirect) { |
|---|
| 231 |
$_SERVER['HTTP_REFERER'])) { |
|---|
| 232 |
$go = $_SERVER['HTTP_REFERER']; |
|---|
| 233 |
|
|---|
| 234 |
|
|---|
| 235 |
$go = get_bloginfo('home'); |
|---|
| 236 |
|
|---|
| 237 |
header('Location: '.$go); |
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 |
add_action('init', 'akm_request_handler'); |
|---|
| 243 |
|
|---|
| 244 |
if (akm_check_mobile()) { |
|---|
| 245 |
add_action('template', 'akm_template'); |
|---|
| 246 |
add_action('option_template', 'akm_template'); |
|---|
| 247 |
add_action('option_stylesheet', 'akm_template'); |
|---|
| 248 |
} |
|---|
| 249 |
|
|---|
| 250 |
if (isset($_COOKIE['akm_mobile']) && $_COOKIE['akm_mobile'] == 'false') { |
|---|
| 251 |
add_action('the_content', 'akm_mobile_available'); |
|---|
| 252 |
} |
|---|
| 253 |
|
|---|
| 254 |
?> |
|---|