-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathktai_style.php
executable file
·966 lines (902 loc) · 29.4 KB
/
ktai_style.php
1
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
<?php
/*
Plugin Name: Ktai Style
Plugin URI: http://wordpress.org/extend/plugins/ktai-style/
Version: 2.0.5
Description: Provides lightweight pages and simple admin interfaces for mobile phones.
Author: IKEDA Yuriko
Author URI: http://en.yuriko.net/
Text Domain: ktai_style
Domain Path: /lang
*/
define ('KTAI_STYLE_VERSION', '2.0.5');
/* Copyright (c) 2007-2011 IKEDA Yuriko
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
if ( (defined('WP_INSTALLING') && WP_INSTALLING) || (defined('DOING_CRON') && DOING_CRON) ) {
return;
}
define('KTAI_DO_ECHO', true);
define('KTAI_NOT_ECHO', false);
define('KTAI_NOT_ESCAPE', false);
if (! defined('KTAI_COOKIE_PCVIEW')) :
define ('KTAI_COOKIE_PCVIEW', 'ktai_pc_view');
endif;
if (! defined('WP_LOAD_CONF')) {
define('WP_LOAD_CONF', 'wp-load-conf.php');
define('WP_LOAD_PATH_STRING', 'WP-LOAD-PATH:');
}
/* ==================================================
* KtaiStyle class
================================================== */
class KtaiStyle {
private static $wp_vers = NULL;
private $plugin_dir;
private $plugin_url;
private $plugin_basename;
private $admin_dir;
public $textdomain_loaded = false;
private $encoding = false;
private $encoding_converted = false;
public $ktai;
public $theme;
public $admin;
public $config;
public $shrinkage;
public $redir;
const TEXT_DOMAIN = 'ktai_style';
const DOMAIN_PATH = '/lang';
const ADMIN_AVAILABLE_WP_OLDEST = '2.8';
const ADMIN_AVAILABLE_WP_NEWEST = '3.0.99';
const ADMIN_DIR = 'admin';
const LOGIN_PAGE = 'login.php';
const CONFIG_DIR = 'config';
const INCLUDES_DIR = 'inc';
const PATCHES_DIR = 'patches';
const QUOTED_STRING_REGEX = '[^\\\\>]*?(?:\\\\.[^\\\\>]*?)*';
const DOUBLE_QUOTED_STRING_REGEX = '[^"\\\\>]*?(?:\\\\.[^"\\\\>]*?)*';
/* ==================================================
* @param none
* @return object $this
* @since 0.70
*/
public function __construct() {
$this->plugin_dir = basename(dirname(__FILE__));
$this->plugin_url = plugins_url($this->plugin_dir . '/');
$this->plugin_basename = plugin_basename(__FILE__);
$this->admin_dir = dirname(__FILE__) . '/' . self::ADMIN_DIR;
if ( function_exists('mb_internal_encoding') ) {
$this->encoding = mb_internal_encoding();
} else {
$this->encoding = get_bloginfo('charset');
}
add_action('plugins_loaded', array($this, 'load_textdomain'));
add_action('plugins_loaded', array($this, 'determine_pcview'));
$this->set_allowedtags();
}
/* ==================================================
* @param string $key
* @return mixed $value
*/
public function get($key) {
switch ($key) {
case 'wp_vers':
return NULL;
case 'plugin_dir':
case 'plugin_url':
case 'plugin_basename':
case 'textdomain_loaded':
case 'encoding_converted':
case 'theme':
case 'theme_root':
case 'theme_root_uri':
case 'template_dir':
case 'template_uri':
return $this->$key;
default:
if (! $this->ktai) {
return KtaiServices::get($key);
}
return $this->ktai->get($key);
}
}
/* ==================================================
* @param string $name
* @return mix $value
*/
public function get_option($name, $return_default = false) {
if (! $return_default) {
$value = get_option($name);
if (preg_match('/^ks_theme/', $name)) {
$value = preg_replace('|^wp-content/|', '', $value);
}
if (false !== $value) {
return $value;
}
}
// default values
switch ($name) {
case 'ks_theme':
return 'default';
case 'ks_date_color':
return '#00aa33';
case 'ks_author_color':
return '#808080';
case 'ks_comment_type_color':
return '#808080';
case 'ks_external_link_color':
return '#660099';
case 'ks_edit_color':
return 'maroon';
case 'ks_year_format':
return 'Y-m-d';
case 'ks_month_date_format':
return 'n/j H:i';
case 'ks_time_format':
return 'H:i';
case 'ks_theme_touch':
case 'ks_theme_mova':
case 'ks_theme_foma':
case 'ks_theme_ezweb':
case 'ks_theme_sb_pdc':
case 'ks_theme_sb_3g':
case 'ks_theme_willcom':
case 'ks_theme_emobile':
default:
return NULL;
}
}
/* ==================================================
* @param none
* @return none
*/
public function load_textdomain() {
if (! $this->textdomain_loaded) {
load_plugin_textdomain(self::TEXT_DOMAIN, false, $this->get('plugin_dir') . self::DOMAIN_PATH);
$this->textdomain_loaded = true;
}
}
/* ==================================================
* @param none
* @return boolean $is_ktai
*/
public function is_ktai() {
if ($this->ktai && ! isset($_COOKIE[KTAI_COOKIE_PCVIEW])) {
return $this->ktai->get('operator');
}
return false;
}
/* ==================================================
* @param none
* @return none
* @since 2.0.0
*/
private function set_allowedtags() {
global $allowedposttags, $allowedtags;
if ($allowedposttags) {
$allowedposttags['img']['localsrc'] = array();
$allowedposttags['img']['alt'] = array();
}
if ($allowedtags) {
$allowedtags['img']['localsrc'] = array();
$allowedtags['img']['alt'] = array();
}
}
/* ==================================================
* @param none
* @return none
* @since 2.0.0
*/
public function determine_pcview() {
if ($this->get('pcview_enabled') && isset($_GET['pcview'])) {
setcookie(KTAI_COOKIE_PCVIEW, ($_GET['pcview'] == 'true'), 0, COOKIEPATH, COOKIE_DOMAIN);
if ( COOKIEPATH != SITECOOKIEPATH ) {
setcookie(KTAI_COOKIE_PCVIEW, ($_GET['pcview'] == 'true'), 0, SITECOOKIEPATH, COOKIE_DOMAIN);
}
$location = remove_query_arg('pcview', $_SERVER['REQUEST_URI']);
wp_redirect($location);
exit;
}
}
/* ==================================================
* @param string $version
* @param string $operator
* @return boolean $result
*/
public function check_wp_version($version, $operator = '>=') {
if (! isset(self::$wp_vers)) {
self::$wp_vers = get_bloginfo('version');
}
return version_compare(self::$wp_vers, $version, $operator);
}
/* ==================================================
* @return boolean $result
* @since 2.0.4
*/
public function admin_available_wp() {
return $this->check_wp_version(self::ADMIN_AVAILABLE_WP_OLDEST);
}
/* ==================================================
* @return boolean $result
* @since 2.0.5
*/
public function admin_available_wp_upper() {
return ( self::ADMIN_AVAILABLE_WP_NEWEST < 1
|| $this->check_wp_version(self::ADMIN_AVAILABLE_WP_NEWEST, '<=') );
}
/* ==================================================
* @param none
* @return none
*/
public function init_mobile() {
require dirname(__FILE__) . '/' . self::INCLUDES_DIR . '/theme.php';
$this->theme = new KtaiThemes();
add_action('sanitize_comment_cookies', array($this, 'convert_encodings'));
add_filter('query_vars', array($this, 'query_vars'));
add_action('setup_theme', array($this->theme, 'load_theme_function'));
add_action('comments_template', array($this->theme, 'comments_template'));
add_action('template_redirect', array($this, 'output'), 11);
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'locale_stylesheet');
remove_action('wp_head', 'wp_print_scripts');
remove_action('wp_head', 'wp_generator');
if (file_exists($this->admin_dir)) {
if ( $this->admin_available_wp() && $this->ktai->get('flat_rate') ) {
require $this->admin_dir . '/pluggable-override.php'; // must be loaded before pluggable.php
require $this->admin_dir . '/class.php';
if ( !defined('KTAI_ADMIN_MODE') ) {
add_action('plugins_loaded', array($this, 'check_ktai_login'));
}
} else {
/* don't load admin feature */
}
} elseif ( !defined('KTAI_KEEP_ADMIN_ACESS') || !KTAI_KEEP_ADMIN_ACESS ) {
// kill access to WP's admin feature
function auth_redirect() {
exit();
}
add_action('plugins_loaded', array($this, 'shutout_login'));
}
}
/* ==================================================
* @param boolean $exit
* @return none
*/
public function check_ktai_login($exit = false) {
if ( class_exists('KtaiStyle_Admin') && $this->ktai->get('flat_rate') ) {
$this->admin = new KtaiStyle_Admin;
$user_login = $this->admin->check_session();
$this->admin->renew_session();
}
$login_url = parse_url(site_url('/wp-login', 'login'));
if (preg_match('!^' . preg_quote($login_url['path'], '!') . '($|\?|\.php)!', $_SERVER['REQUEST_URI'])) {
if ( $exit ) {
wp_die(__('Mobile admin feature is not available.', 'ktai_style'));
exit;
}
wp_redirect($this->get('plugin_url') . self::LOGIN_PAGE);
exit();
}
}
/* ==================================================
* @param none
* @return none
*/
public function shutout_login() {
$this->check_ktai_login(true);
}
/* ==================================================
* @param none
* @return none
* @since 1.80
*/
public function convert_encodings() {
if (isset($_GET['ks']) && ! empty($_GET['ks'])) {
$encoding = $this->input_encoding();
if ( !$encoding ) {
$encoding = isset($_GET['Submit']) ? $this->detect_encoding($_GET['Submit']) : $this->ktai->get('charset');
}
$_GET['s'] = $this->decode_from_ktai($_GET['ks'], $encoding, false);
} else {
$_GET['s'] = NULL;
}
if (isset($_POST['urlquery']) && isset($_POST['post_password'])) {
parse_str(stripslashes_deep($_POST['urlquery']), $query);
foreach($query as $k => $v) {
$_GET[$k] = $v;
}
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['charset_detect']) && function_exists('mb_convert_encoding')) {
$_POST = $this->convert_post_encodings($_POST, $this->detect_encoding(stripslashes($_POST['charset_detect'])));
$this->encoding_converted = true;
}
}
/* ==================================================
* @param array $post
* @param string $encoding
* @return array $post
* @since 1.80
*/
private function convert_post_encodings($post, $encoding) {
if ( empty($post) ) {
return $post;
}
foreach ($post as $k => $v) {
if ( empty($v) ) {
$post[$k] = $v;
} elseif ( is_array($v) ) {
$post[$k] = $this->convert_post_encodings($v, $encoding);
} else {
$post[$k] = $this->decode_from_ktai($v, $encoding);
}
}
return $post;
}
/* ==================================================
* @param string $input
* @return string $encoding
*/
public function input_encoding() {
if ( !ini_get('mbstring.encoding_translation') && function_exists('mb_http_input') ) {
$encoding = mb_http_input('G');
} else {
$encoding = NULL;
}
return $encoding;
}
/* ==================================================
* @param string $input
* @return string $encoding
*/
public function detect_encoding($input) {
if ( empty($input) || !function_exists('mb_detect_encoding') ) {
$encoding = 'auto';
} else {
$encoding = mb_detect_encoding($input, array('ASCII', 'JIS', 'UTF-8', 'SJIS', 'EUC-JP'));
if ( !$encoding || $encoding == 'ASCII' ) {
$encoding = 'auto';
}
}
return $encoding;
}
/* ==================================================
* @param string $encoding1
* @param string $encoding2
* @return boolean $is_same
*/
public function similar_encoding($encoding1, $encoding2) {
$normalize = array(
'shift_jis' => 'sjis',
'sjis-win' => 'sjis',
'cp932' => 'sjis',
'eucjp-win' => 'euc-jp',
'iso-2022-jp' => 'jis',
'iso-2022-jp-1' => 'jis',
'iso-2022-jp-2' => 'jis',
);
$encoding1 = strtr(strtolower($encoding1), $normalize);
$encoding2 = strtr(strtolower($encoding2), $normalize);
return (strcmp($encoding1, $encoding2) === 0);
}
/* ==================================================
* @param array $ctype
* @return string $encoding
*/
public function check_encoding($buffer, $encoding) {
if ( !function_exists('mb_check_encoding') ) {
return true;
}
if ($encoding == 'auto') {
$encoding = mb_detect_encoding($buffer, 'JIS, SJIS, UTF-8, EUC-JP');
}
if ($this->similar_encoding($encoding, 'sjis')) {
$result = mb_check_encoding($buffer, 'Shift_JIS') || mb_check_encoding($buffer, 'SJIS-win');
} else {
$result = mb_check_encoding($buffer, $encoding);
}
return $result;
}
/* ==================================================
* @param string $buffer
* @param string $encoding
* @return string $buffer
*/
public function decode_from_ktai($buffer, $encoding = 'auto', $allow_pics = NULL) {
if ( !$this->check_encoding($buffer, $encoding) ) {
$this->ks_die(sprintf(__('Invalid character found for %s encoding', 'ktai_style'), $encoding));
// exit;
}
if ( is_null($allow_pics) ) {
$allow_pics = $this->get_option('ks_allow_pictograms');
}
$buffer = stripslashes($buffer);
if ($this->similar_encoding($encoding, $this->ktai->get('charset'))) {
$buffer = $this->ktai->pickup_pics($buffer);
if ( !$allow_pics ) {
$buffer = preg_replace('!<img localsrc="[^"]*" />!', '', $buffer);
}
}
if ( function_exists('mb_convert_encoding') ) {
$buffer = mb_convert_encoding($buffer, get_bloginfo('charset'), $encoding);
}
if ( $buffer ) {
$buffer = add_magic_quotes($buffer); // avoid returning empty array
}
return $buffer;
}
/* ==================================================
* @param string $buffer
* @param string $encoding
* @return string $buffer
*/
public function encode_for_ktai($buffer, $encoding = '') {
if (function_exists('mb_convert_encoding')) {
if (! $encoding) {
if (isset($this->ktai)) {
$encoding = $this->ktai->get('charset');
} else {
global $Ktai_Style;
$encoding = $Ktai_Style->ktai->get('charset');
}
}
if ( function_exists('mb_convert_encoding') ) {
$buffer = mb_convert_encoding($buffer, $encoding, get_bloginfo('charset'));
}
}
return $buffer;
}
/* ==================================================
* @param array $vars
* @return array $vars
* @since 2.0.0
*/
public function query_vars($vars) {
$vars[] = 'menu';
$vars[] = 'view';
$vars[] = 'img';
$vars[] = 'kp';
return $vars;
}
/* ==================================================
* @param none
* @return none
*/
public function output() {
if (is_robots() || is_feed() || is_trackback()) {
return;
}
require dirname(__FILE__) . '/' . self::INCLUDES_DIR . '/template-tags.php';
if (is_404()) {
$this->theme->bypass_admin_404();
}
if (! $template = $this->theme->load_template()) {
$this->ks_die(__("Can't display pages. Bacause mobile phone templates are collapsed.", 'ktai_style'));
// exit;
}
add_filter('wp_list_categories', array($this, 'filter_tags'), 90);
add_filter('wp_list_pages', array($this, 'filter_tags'), 90);
add_filter('ktai_raw_content', array($this->ktai, 'shrink_pre_encode'), 9);
add_filter('ktai_encoding_converted', array($this->ktai, 'shrink_pre_split'), 5);
add_filter('ktai_encoding_converted', array($this->ktai, 'replace_smiley'), 7);
add_filter('ktai_encoding_converted', array($this->ktai, 'convert_pict'), 9);
add_filter('ktai_split_page', array($this->ktai, 'shrink_post_split'), 15);
add_action('ktai_wp_head', array($this, 'disallow_index'));
$buffer = $this->ktai->get('preamble');
$buffer .= ($buffer ? "\n" : '');
ob_start();
include $template;
$buffer .= ob_get_contents();
ob_end_clean();
if ( isset($this->admin) ) {
$this->admin->store_referer()->save_data();
$this->admin->unset_prev_session($Ktai_Style->admin->get_sid());
}
$buffer = apply_filters('ktai_raw_content', $buffer);
$buffer = apply_filters('raw_content/ktai_style.php', $buffer); // backward compatiblity
$buffer = $this->encode_for_ktai($buffer);
$buffer = apply_filters('ktai_encoding_converted', $buffer);
$buffer = apply_filters('encoding_converted/ktai_style.php', $buffer); // backward compatiblity
$buffer = apply_filters('ktai_split_page', $buffer, $this->shrinkage->get_page_num());
$buffer = apply_filters('split_page/ktai_style.php', $buffer, $this->shrinkage->get_page_num()); // backward compatiblity
$mime_type = apply_filters('ktai_mime_type', $this->ktai->get('mime_type'));
$iana_charset = apply_filters('ktai_iana_charset', $this->ktai->get('iana_charset'));
if (ks_is_front() || ks_is_menu('comments')) {
nocache_headers();
}
if (function_exists('mb_http_output')) {
mb_http_output('pass');
}
header ("Content-Type: $mime_type; charset=$iana_charset");
echo $buffer;
exit;
}
/* ==================================================
* @param string $html
* @return string $html
*/
public function filter_tags($html) {
if (! class_exists('Ktai_HTML_Filter')) {
require_once dirname(__FILE__) . '/' . self::INCLUDES_DIR . '/kses.php';
}
$html = Ktai_HTML_Filter::kses($html, $this->get('allowedtags'));
return $html;
}
/* ==================================================
* @param none
* @return none
*/
public function init_pc() {
if ( defined('WP_USE_THEMES') && WP_USE_THEMES ) {
add_action('wp_head', array($this, 'show_mobile_url'));
// add_action('atom_head', array($this, 'show_mobile_url_atom_head'));
// add_action('atom_entry', array($this, 'show_mobile_url_atom_entry'));
add_action('rss2_ns', array($this, 'show_mobile_url_rss2_ns'));
add_action('rss2_head', array($this, 'show_mobile_url_rss2_head'));
add_action('rss2_item', array($this, 'show_mobile_url_rss2_item'));
if (isset($_COOKIE[KTAI_COOKIE_PCVIEW])) {
add_action('wp_head', array($this, 'switch_ktai_view_css'));
add_action('wp_footer', array($this, 'switch_ktai_view'));
}
} elseif (is_admin()) {
add_filter('tiny_mce_before_init', array($this, 'make_valid_pictogram_tag'));
require dirname(__FILE__) . '/' . self::INCLUDES_DIR . '/theme.php';
require dirname(__FILE__) . '/' . self::CONFIG_DIR . '/panel.php';
$this->config = new KtaiStyle_Config();
add_action('in_plugin_update_message-' . $this->plugin_basename, array($this, 'add_update_notice'));
if ( file_exists($this->admin_dir) && $this->admin_available_wp() ) {
require $this->admin_dir . '/install.php';
register_activation_hook(__FILE__, array($this, 'check_wp_load'));
register_activation_hook(__FILE__, array('KtaiStyle_Install', 'install'));
register_deactivation_hook(__FILE__, array('KtaiStyle_Install', 'uninstall'));
if (function_exists('get_blog_list')) {
add_action('activate_sitewide_plugin', array('KtaiStyle_Install', 'install_sitewidely'));
add_action('deactivate_sitewide_plugin', array('KtaiStyle_Install', 'uninstall_sitewidely'));
}
}
}
add_filter('the_content', array('KtaiServices', 'convert_pict'));
add_filter('get_comment_text', array('KtaiServices', 'convert_pict'));
}
/* ==================================================
* @param array $init
* @return array $init
* @since 1.80
*/
public function make_valid_pictogram_tag($init) {
if (isset($init['extended_valid_elements']) && preg_match('/\bimg\[/', $init['extended_valid_elements'])) {
$init['extended_valid_elements'] = preg_replace('/\bimg\[/', 'img[localsrc|', $init['extended_valid_elements']);
} else {
$init['extended_valid_elements'] = 'img[localsrc|longdesc|usemap|src|border|alt|title|hspace|vspace|width|height|align|class|style]';
}
return $init;
}
/* ==================================================
* @param none
* @return none
*/
public function check_wp_load() {
$wp_root = dirname(dirname(dirname(dirname(__FILE__)))) . '/';
if ( !file_exists($wp_root . 'wp-load.php') && !file_exists($wp_root . 'wp-config.php') && function_exists('plugins_url')) {
$conf = dirname(__FILE__) . '/' . WP_LOAD_CONF;
if (file_put_contents($conf, "<?php /*\n" . WP_LOAD_PATH_STRING . ABSPATH . "\n*/ ?>", LOCK_EX)) { // <?php /* syntax highiting fix */
$stat = stat(dirname(__FILE__));
chmod($conf, 0000666 & $stat['mode']);
}
}
}
/* ==================================================
* @param int $post_id
* @return string $url
* @since 1.10
*/
static function get_self_url() {
if (! preg_match('|^(https?://[^/]*)|', get_bloginfo('url'), $host)) {
$scheme = (empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') ? 'http://' : 'https://';
$host[1] = $scheme . $_SERVER['SERVER_NAME'];
}
return $host[1] . $_SERVER['REQUEST_URI'];
}
/* ==================================================
* @param none
* @return none
* @since 1.10
*/
public function show_mobile_url() {
$url = self::get_self_url();
?>
<link rel="alternate" media="handheld" type="text/html" href="<?php echo htmlspecialchars($url, ENT_QUOTES); ?>" />
<?php
}
/* ==================================================
* @param none
* @return none
* @since 1.40
*/
public function show_mobile_url_atom_head() {
$url = preg_replace('!(\?feed=atom|feed/atom/?)$!', '', self::get_self_url());
?>
<link rel="alternate" x:media="handheld" type="text/html" href="<?php echo htmlspecialchars($url, ENT_QUOTES); ?>" />
<?php
}
/* ==================================================
* @param none
* @return none
* @since 1.40
*/
public function show_mobile_url_atom_entry() {
$url = get_permalink();
?>
<link rel="alternate" x:media="handheld" type="text/html" href="<?php echo htmlspecialchars($url, ENT_QUOTES); ?>" />
<?php
}
/* ==================================================
* @param none
* @return none
* @since 1.40
*/
public function show_mobile_url_rss2_ns() {
?>
xmlns:xhtml="http://www.w3.org/1999/xhtml"
<?php
}
/* ==================================================
* @param none
* @return none
* @since 1.40
*/
public function show_mobile_url_rss2_head() {
$url = preg_replace('!(\?feed=rss2|feed/rss2/?)$!', '', self::get_self_url());
?>
<xhtml:link rel="alternate" media="handheld" type="text/html" href="<?php echo htmlspecialchars($url, ENT_QUOTES); ?>" />
<?php
}
/* ==================================================
* @param none
* @return none
* @since 1.40
*/
public function show_mobile_url_rss2_item() {
$url = get_permalink();
?>
<xhtml:link rel="alternate" media="handheld" type="text/html" href="<?php echo htmlspecialchars($url, ENT_QUOTES); ?>" />
<?php
}
/* ==================================================
* @param none
* @return none
* @since 0.95
*/
public function switch_ktai_view_css() {
$style = <<< E__O__T
#switch-mobile {color:white; background:gray; text-align:center; clear:both;}
#switch-mobile a, #switch-mobile a:link, #switch-mobile a:visited {color:white;}
E__O__T;
$style = apply_filters('ktai_switch_mobile_view_css', $style);
$style = apply_filters('switch_ktai_view_css/ktai_style.php', $style);
if ($style) {
echo '<style type="text/css">' . $style . '</style>';
}
}
/* ==================================================
* @param none
* @return none
* @since 0.95
*/
public function switch_ktai_view() {
$here = $_SERVER['REQUEST_URI'];
$menu = '<div id="switch-mobile"><a href="' .
esc_attr($here . (strpos($here, '?') === false ? '?' : '&') . 'pcview=false') .
'">' . __('To Mobile view', 'ktai_style') . '</a></div>';
$menu = apply_filters('ktai_switch_mobile_view', $menu, $here);
$menu = apply_filters('switch_ktai_view/ktai_style.php', $menu, $here);
echo $menu;
}
/* ==================================================
* @param string $action
* @return string $nonce
*/
function create_anon_nonce($action = -1) {
$i = wp_nonce_tick();
return substr(wp_hash($i . $action), -12, 10);
}
/* ==================================================
* @param string $nonce
* @param string $action
* @return boolean $verified
*/
function verify_anon_nonce($nonce, $action = -1) {
$i = wp_nonce_tick();
// Nonce generated 0-12 hours ago
if ( substr(wp_hash($i . $action), -12, 10) == $nonce )
return 1;
// Nonce generated 12-24 hours ago
if ( substr(wp_hash(($i - 1) . $action), -12, 10) == $nonce )
return 2;
// Invalid nonce
return false;
}
/* ==================================================
* @param string $url
* @return string $url
*/
public function strip_host($url = '/') {
$url_parts = parse_url($url);
$http_host = explode(':', $_SERVER['HTTP_HOST']);
if ( isset($url_parts['host']) && $url_parts['host'] == $http_host[0]
&& ( !isset($url_parts['port']) || $url_parts['port'] == $http_host[1] ) ) {
$url = preg_replace('!^https?://[^/]*/?!', '/', $url);
}
return $url;
}
/* ==================================================
* @param none
* @return none
* @since 2.0.0
*/
public function disallow_index() {
if ( ks_is_comment_post() || ks_is_redir() ) {
echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
}
}
/* ==================================================
* @param none
* @return none
* @since 2.0.5
*/
public function add_update_notice() {
echo '<br />';
_e('Mobile themes in <code>ktai-style/themes/*</code> are initialized to the distribution state. If you customize these themes directory, create a <code>wp-content/ktai-themes/</code> directory and move your themes to there.', 'ktai_style');
}
/* ==================================================
* @param string $message
* @param string $title
* @param boolean $show_back_link
* @param boolean $encoded
* @return none
* based on wp_die() at wp-includes/functions() of WP 2.2.3
*/
public function ks_die($message, $title = '', $show_back_link = true, $encoded = false) {
if ( is_wp_error( $message ) ) {
if ( empty($title) ) {
$error_data = $message->get_error_data();
if ( is_array($error_data) && isset($error_data['title']) )
$title = $error_data['title'];
}
$errors = $message->get_error_messages();
switch ( count($errors) ) :
case 0 :
$message = '';
break;
case 1 :
$message = '<p>' . $errors[0] . '</p>';
break;
default :
$message = '<ul><li>' . join( '</li><li>', $errors ) . '</li></ul>';
break;
endswitch;
} elseif (is_string($message) && strpos($message, '<p>') === false) {
$message = '<p>' . $message . '</p>';
}
if ($show_back_link && isset($this->admin) && $referer = $this->admin->get_referer()) {
$message .= sprintf(__('Back to <a href="%s">the previous page</a>.', 'ktai_style'), esc_attr($referer));
}
$logo_ext = 'png';
$header = '';
switch ($this->is_ktai()) {
case 'DoCoMo':
$logo_ext = 'gif';
break;
case 'KDDI':
case 'SoftBank':
$header = '<style><![CDATA[ p {margin-bottom:1em;} ]]></style>';
break;
case 'Touch':
$header = '<meta name="viewport" content="width=device-width,initial-scale=1.0" />';
default:
break;
}
if ( !defined('KTAI_ADMIN_HEAD') ) :
$encoding = $this->ktai->get('charset');
$iana_charset = $this->ktai->get('iana_charset');
$mime_type = 'text/html';
$this->ktai->set('mime_type', $mime_type);
if (function_exists('mb_http_output')) {
mb_http_output('pass');
}
header ("Content-Type: $mime_type; charset=$iana_charset");
if ( !$encoded ) {
$title = $this->encode_for_ktai($title, $encoding);
$message = $this->encode_for_ktai($message, $encoding);
}
if (empty($title)) {
$title = $this->encode_for_ktai(__('WordPress | Error', 'ktai_style'), $encoding);
}
echo '<?xml version="1.0" encoding="' . $iana_charset .'" ?>' . "\n"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="<?php echo $mime_type; ?>; charset=<?php echo $iana_charset; ?>" />
<meta name="robots" content="noindex,nofollow" />
<title><?php echo esc_html($title); ?></title>
<?php echo $header; ?>
</head>
<body>
<?php endif; // KTAI_ADMIN_HEAD
$logo_url = $this->strip_host($this->get('plugin_url')) . self::INCLUDES_DIR . '/wplogo.' . $logo_ext ;
$title = '<div><h1 id="logo"><img alt="WordPress" src="' . $logo_url . '" /></h1></div>';
$title = apply_filters('ktai_die_logo', $title, $logo_url, $logo_ext);
$title = apply_filters('ks_die_logo/ktai_style.php', $title, $logo_url, $logo_ext);
echo $title, $message; ?>
</body>
</html>
<?php
if (defined('KTAI_ADMIN_HEAD')) {
ob_flush();
}
exit();
}
// ===== End of class ====================
}
/* ==================================================
* KS_Error class
================================================== */
function is_ks_error($thing) {
return (is_object($thing) && is_a($thing, 'KS_Error'));
}
class KS_Error extends Exception {
public function setCode($code) {
$this->code = $code;
}
// ===== End of class ====================
}
/* ==================================================
* @param string $attribute
* @return string $is_ktai
*/
function is_ktai($attribute = NULL) {
global $Ktai_Style;
switch ($attribute) {
case 'type':
return isset($Ktai_Style->ktai) ? $Ktai_Style->ktai->get('type') : false;
case 'flat_rate':
return isset($Ktai_Style->ktai) ? $Ktai_Style->ktai->get('flat_rate') : false;
case 'search_engine':
return isset($Ktai_Style->ktai) ? $Ktai_Style->ktai->is_search_engine() : KtaiStyle::is_search_engine();
default:
return isset($Ktai_Style->ktai) ? $Ktai_Style->is_ktai() : false;
}
}
/* ==================================================
* @param string $name
* @return mix $value
*/
function ks_option($name) {
return KtaiStyle::get_option($name);
}
// ==================================================
global $Ktai_Style;
$Ktai_Style = new KtaiStyle;
require dirname(__FILE__) . '/operators/base.php';
$Ktai_Style->ktai = KtaiServices::factory();
if (is_ktai()) {
require dirname(__FILE__) . '/' . KtaiStyle::PATCHES_DIR . '/mobile.php';
$Ktai_Style->init_mobile();
do_action('ktai_init_mobile');
do_action('init_mobile/ktai_style.php');
} else {
require dirname(__FILE__) . '/' . KtaiStyle::PATCHES_DIR . '/pc.php';
$Ktai_Style->init_pc();
do_action('ktai_init_pc');
do_action('init_pc/ktai_style.php');
}
?>