1 | <?php
|
---|
2 | if(!defined('XPRESS_BLOCK_HEADER_FUNCTION_READ')){
|
---|
3 | define('XPRESS_BLOCK_HEADER_FUNCTION_READ',1);
|
---|
4 | require_once dirname( __FILE__ ) .'/xml.php' ;
|
---|
5 | require_once dirname( __FILE__ ) .'/xpress_cache.php' ;
|
---|
6 | global $xoops_config;
|
---|
7 |
|
---|
8 | if (!is_object($xoops_config)){ // is call other modules
|
---|
9 | require_once dirname(dirname( __FILE__ )) .'/class/config_from_xoops.class.php' ;
|
---|
10 | $xoops_config = new ConfigFromXoops;
|
---|
11 | }
|
---|
12 |
|
---|
13 | function xpress_block_header_cash_write($mydirname,$block_header)
|
---|
14 | {
|
---|
15 | $xml = xpress_XML_serialize($block_header);
|
---|
16 | $xml_name = 'block_header.xml';
|
---|
17 | if (WPLANG == 'ja_EUC'){
|
---|
18 | $xml = str_replace('<?xml version="1.0" ?>', '<?xml version="1.0" encoding="EUC-JP" ?>' , $xml);
|
---|
19 | }
|
---|
20 | xpress_cache_write($mydirname,$xml_name,$xml);
|
---|
21 | }
|
---|
22 | function xpress_block_header_cache_read($mydirname)
|
---|
23 | {
|
---|
24 | $xml_name = 'block_header.xml';
|
---|
25 | $xml_data = xpress_cache_read($mydirname,$xml_name);
|
---|
26 |
|
---|
27 | $GLOBALS['DO_LIBXML_PATCH'] = get_xpress_mod_config($mydirname,'libxml_patch');
|
---|
28 |
|
---|
29 | // The character-code not treatable exists when 'XML_unserialize' of PHP5 processes EUC-JP.
|
---|
30 | // And, the result is returned by character-code UTF-8.
|
---|
31 | // Measures
|
---|
32 | // After the character-code is converted into UTF-8, XML_unserialize will be processed.
|
---|
33 | if ( strstr($xml_data, '<?xml version="1.0" encoding="EUC-JP" ?>') !== false
|
---|
34 | && version_compare(PHP_VERSION, '5.0.0', '>') )
|
---|
35 | {
|
---|
36 | $xml_data = str_replace('<?xml version="1.0" encoding="EUC-JP" ?>', '<?xml version="1.0" encoding="UTF-8" ?>', $xml_data);
|
---|
37 | $ans = mb_convert_variables('UTF-8' , 'EUC-JP', &$xml_data); //EUC-JP to UTF-8
|
---|
38 | $ret = @xpress_XML_unserialize($xml_data);
|
---|
39 | $ans = mb_convert_variables('EUC-JP' , 'UTF-8', &$ret); //UTF-8 to EUC-JP
|
---|
40 | } else {
|
---|
41 | $ret = xpress_XML_unserialize($xml_data);
|
---|
42 | }
|
---|
43 | return $ret;
|
---|
44 | }
|
---|
45 | function get_block_stylesheet_url($mydirname)
|
---|
46 | {
|
---|
47 | global $xoops_config;
|
---|
48 | $mydirpath = $xoops_config->xoops_root_path . '/modules/' . $mydirname;
|
---|
49 | $select_theme = get_xpress_theme_name($mydirname);
|
---|
50 | $style_file = $mydirpath . '/wp-content/themes/' . $select_theme . '/blocks/block_style.css';
|
---|
51 | if (file_exists($style_file))
|
---|
52 | return $xoops_config->xoops_url . '/modules/' .$mydirname . '/wp-content/themes/' . $select_theme . '/blocks/block_style.css';
|
---|
53 | else
|
---|
54 | return $xoops_config->xoops_url . '/modules/' .$mydirname . '/wp-content/themes/xpress_default/blocks/block_style.css';
|
---|
55 | }
|
---|
56 |
|
---|
57 | function set_xpress_block_header($mydirname)
|
---|
58 | {
|
---|
59 | ob_start();
|
---|
60 | bloginfo('stylesheet_url');
|
---|
61 | $stylesheet_link = "\t".'<link rel="stylesheet" href="' . ob_get_contents() . '" type="text/css" media="screen" />';
|
---|
62 | ob_end_clean();
|
---|
63 | $block_stylesheet_link = "\t".'<link rel="stylesheet" href="' . get_block_stylesheet_url($mydirname) . '" type="text/css" media="screen" />';
|
---|
64 |
|
---|
65 | ob_start();
|
---|
66 | $now_ob_level = ob_get_level();
|
---|
67 | wp_head();
|
---|
68 | ob_end_flush_child($now_ob_level);
|
---|
69 | $header_str = ob_get_contents();
|
---|
70 | ob_end_clean();
|
---|
71 |
|
---|
72 | if(function_exists('_admin_bar_bump_cb')){
|
---|
73 | //remove admin_bar_bump_cb
|
---|
74 | ob_start();
|
---|
75 | _admin_bar_bump_cb();
|
---|
76 | $admin_bar_bump_cb_str = ob_get_contents();
|
---|
77 | ob_end_clean();
|
---|
78 | $header_str = str_replace_ex($admin_bar_bump_cb_str,'',$header_str);
|
---|
79 | }
|
---|
80 |
|
---|
81 | if(function_exists('wp_admin_bar_header')){
|
---|
82 | //remove wp_adminbar_header
|
---|
83 | ob_start();
|
---|
84 | wp_admin_bar_header();
|
---|
85 | $wp_admin_bar_header_str = ob_get_contents();
|
---|
86 | ob_end_clean();
|
---|
87 | $header_str = str_replace_ex($wp_admin_bar_header_str,'',$header_str);
|
---|
88 | }
|
---|
89 |
|
---|
90 | $pattern = '<\s*link\s+rel\s*=[^>]*?>';
|
---|
91 | $header_str = preg_replace("/".$pattern."/s" , '' , $header_str);
|
---|
92 | $pattern = '<\s*meta\s+name\s*=[^>]*?>';
|
---|
93 | $header_str = preg_replace("/".$pattern."/i" , '' , $header_str);
|
---|
94 | // $pattern = "<style type.*<\/style>";
|
---|
95 | // $header_str = preg_replace("/".$pattern."/s" , '' , $header_str);
|
---|
96 | $pattern = "^\s*\n";
|
---|
97 | $header_str = preg_replace("/".$pattern."/m" , '' , $header_str);
|
---|
98 | $pattern = "^";
|
---|
99 | $header_str = preg_replace("/".$pattern."/m" , "\t" , $header_str);
|
---|
100 |
|
---|
101 | ob_start();
|
---|
102 | global $show_admin_bar;
|
---|
103 | $show_admin_bar = false; //remove adminbar
|
---|
104 | wp_footer();
|
---|
105 | $footer_str = ob_get_contents();
|
---|
106 | ob_end_clean();
|
---|
107 | $pattern = "^";
|
---|
108 | $footer_str = preg_replace("/".$pattern."/m" , "\t" , $footer_str);
|
---|
109 |
|
---|
110 | $block_header = "<!-- XPressME added block header -->\n";
|
---|
111 | $block_header .= "\t<!-- from bloginfo('stylesheet_url') -->\n";
|
---|
112 | $block_header .= $stylesheet_link ."\n";
|
---|
113 | $block_header .= $block_stylesheet_link ."\n";
|
---|
114 | $block_header .= "\t<!-- from wp_head() -->\n";
|
---|
115 | $block_header .= $header_str ."\n";
|
---|
116 | $block_header .= "\t<!-- from wp_footer() -->\n";
|
---|
117 | $block_header .= $footer_str ."\n";
|
---|
118 | $block_header .= "<!-- end of XPressME added block header -->\n";
|
---|
119 | $data = array();
|
---|
120 | $data['block_header']= $block_header;
|
---|
121 | xpress_block_header_cash_write($mydirname,$data);
|
---|
122 | }
|
---|
123 |
|
---|
124 | function str_replace_ex($regx,$replace,$str){
|
---|
125 |
|
---|
126 | if (empty($regx)) return $str;
|
---|
127 | $pattern = preg_quote($regx,'/');
|
---|
128 | if (preg_match('/\r/',$pattern)){
|
---|
129 | $pattern=preg_replace('/\r/','\\r',$pattern);
|
---|
130 | }
|
---|
131 | if (preg_match('/\n/',$pattern)){
|
---|
132 | $pattern=preg_replace('/\n/','\\n',$pattern);
|
---|
133 | }
|
---|
134 | if (preg_match('/\t/',$pattern)){
|
---|
135 | $pattern=preg_replace('/\t/','\\t',$pattern);
|
---|
136 | }
|
---|
137 | $pattern = '/'. $pattern . '/';
|
---|
138 | if (preg_match($pattern,$str)){
|
---|
139 | $str=preg_replace($pattern,$replace,$str);
|
---|
140 | }
|
---|
141 | return $str;
|
---|
142 | }
|
---|
143 |
|
---|
144 | }
|
---|
145 | ?> |
---|