1 | <?php
|
---|
2 |
|
---|
3 | //< style >< script >< link > tag is pulled out from the header of html contents.
|
---|
4 | function get_mod_header($contents)
|
---|
5 | {
|
---|
6 | global $xpress_config;
|
---|
7 |
|
---|
8 | $pattern = "<body[^>]*?>(.*)<\/body>";
|
---|
9 | $body_cut = preg_replace("/".$pattern."/s" , '' , $contents);
|
---|
10 |
|
---|
11 |
|
---|
12 | $pattern = "<head[^>]*?>(.*)<\/head>";
|
---|
13 | $head_str = '';
|
---|
14 | if (preg_match("/".$pattern."/s", $body_cut, $head_matches)){
|
---|
15 | $head_str = $head_matches[1];
|
---|
16 | }
|
---|
17 | $pattern = '<head[^>]*?>';
|
---|
18 | $head_str = preg_replace("/".$pattern."/s" , '' , $head_str);
|
---|
19 | $pattern = '<\/head>';
|
---|
20 | $head_str = preg_replace("/".$pattern."/s" , '' , $head_str);
|
---|
21 | $pattern = '<\s*html\s+xmlns[^>]*?>';
|
---|
22 | $head_str = preg_replace("/".$pattern."/s" , '' , $head_str);
|
---|
23 | $pattern = '<\s*head\s+profile[^>]*?>';
|
---|
24 | $head_str = preg_replace("/".$pattern."/s" , '' , $head_str);
|
---|
25 | $pattern = '<\s*meta\s+http-equiv[^>]*?>';
|
---|
26 | $head_str = preg_replace("/".$pattern."/s" , '' , $head_str);
|
---|
27 | $pattern = '<title[^>]*?>(.*)<\s*\/\s*title\s*>';
|
---|
28 | $head_str = preg_replace("/".$pattern."/s" , '' , $head_str);
|
---|
29 |
|
---|
30 | $head_str = meta_name_cut('robots',$head_str);
|
---|
31 | $head_str = meta_name_cut('keywords',$head_str);
|
---|
32 | $head_str = meta_name_cut('description',$head_str);
|
---|
33 | $head_str = meta_name_cut('rating',$head_str);
|
---|
34 | $head_str = meta_name_cut('author',$head_str);
|
---|
35 | $head_str = meta_name_cut('copyright',$head_str);
|
---|
36 | $head_str = meta_name_cut('generator',$head_str);
|
---|
37 |
|
---|
38 | $head_str = preg_replace("/^(\s)*(\r|\n|\r\n)/m", "", $head_str);
|
---|
39 | $head_str = $head_str . "\n<!-- credit " . xpress_credit('echo=0&no_link=1') . " -->\n";
|
---|
40 | $pattern = "^";
|
---|
41 | $head_str = preg_replace("/".$pattern."/m" , "\t" , $head_str);
|
---|
42 |
|
---|
43 | return $head_str;
|
---|
44 | }
|
---|
45 |
|
---|
46 | function meta_name_cut($name = '', $head_str)
|
---|
47 | {
|
---|
48 | $pattern = '<\s*meta\s+name\s*=\s*["\']' . $name . '["\'][^>]*?>';
|
---|
49 | $head_str = preg_replace("/".$pattern."/i" , '' , $head_str);
|
---|
50 | return $head_str;
|
---|
51 | }
|
---|
52 |
|
---|
53 | // for title reprace plugin (all in one seo pack)
|
---|
54 | function get_xpress_title($contents)
|
---|
55 | {
|
---|
56 | $pattern = '<title[^>]*?>(.*)<\s*\/\s*title\s*>';
|
---|
57 | $title_str = '';
|
---|
58 | if (preg_match("/".$pattern."/i", $contents, $head_matches)){
|
---|
59 | $title_str = $head_matches[1];
|
---|
60 | }
|
---|
61 | return $title_str;
|
---|
62 | }
|
---|
63 |
|
---|
64 | function get_xpress_meta_name($name = '',$contents)
|
---|
65 | {
|
---|
66 | $pattern = '<\s*meta\s+name\s*=\s*["\']' . $name . '["\']\s*content\s*=\s*[\'"](.*)[\'"]\s*\/\s*>';
|
---|
67 | $meta = '';
|
---|
68 | if (preg_match("/".$pattern."/i", $contents, $head_matches)){
|
---|
69 | $meta = @$head_matches[1];
|
---|
70 | }
|
---|
71 | return $meta;
|
---|
72 | }
|
---|
73 |
|
---|
74 | // get sidebar rendaring
|
---|
75 | function get_sidebar_rander($name = null)
|
---|
76 | {
|
---|
77 | $templates = array();
|
---|
78 | if ( isset($name) )
|
---|
79 | $templates[] = "sidebar-{$name}.php";
|
---|
80 |
|
---|
81 | $templates[] = "sidebar.php";
|
---|
82 |
|
---|
83 | $link= locate_template($templates, false);
|
---|
84 | if ('' == $link)
|
---|
85 | $link = get_theme_root() . '/default/sidebar.php';
|
---|
86 |
|
---|
87 | ob_start();
|
---|
88 | require($link);
|
---|
89 | $sidebar = ob_get_contents();
|
---|
90 | ob_end_clean();
|
---|
91 | return $sidebar;
|
---|
92 | }
|
---|
93 |
|
---|
94 | // < body > tag is pulled out from the header of html contents.
|
---|
95 | function get_body($contents)
|
---|
96 | {
|
---|
97 | global $xpess_config;
|
---|
98 | if (!is_object($xpess_config)) $xpess_config = new XPressME_Class();
|
---|
99 | $pattern = "<body[^>]*?>(.*)<\/body>";
|
---|
100 | $body = '';
|
---|
101 | if(preg_match("/".$pattern."/s", $contents, $body_matches)){
|
---|
102 | $body = $body_matches[1];
|
---|
103 | }
|
---|
104 |
|
---|
105 | if ($xpess_config->is_theme_sidebar_disp){
|
---|
106 | $xpress_class = 'xpress-body';
|
---|
107 | } else {
|
---|
108 | $xpress_class = 'xpress-body onecolumn';
|
---|
109 | }
|
---|
110 |
|
---|
111 | $pattern = '<body\s*([^>]*)>';
|
---|
112 | $body_class = 'class="' . $xpress_class . '"';
|
---|
113 | if(preg_match("/".$pattern."/s", $contents, $body_matches)){
|
---|
114 | $body_tag_option = $body_matches[1];
|
---|
115 |
|
---|
116 | $pattern = 'class\s*=\s*[\'|"]([^\'|^"]*)[\'|"]';
|
---|
117 | if(preg_match("/".$pattern."/", $body_tag_option, $class_matches)){
|
---|
118 | $class_value = $class_matches[1];
|
---|
119 | $reprace = $xpress_class . ' '. $class_value;
|
---|
120 | $body_class = preg_replace("/".$class_value."/", $reprace, $body_tag_option);
|
---|
121 | } else {
|
---|
122 | $body_class = 'class="' . $xpress_class . '" ' . $body_tag_option;
|
---|
123 | }
|
---|
124 | }
|
---|
125 |
|
---|
126 | if (!$xpess_config->is_theme_sidebar_disp){
|
---|
127 | $side_panel = get_sidebar_rander();
|
---|
128 | $body = str_replace($side_panel,'',$body);
|
---|
129 | }
|
---|
130 | $body = "\n<div " . $body_class . "> <!-- Substitution of wordpress <body > -->\n" . $body . "\n</div> <!-- Substitution of wordpress </body > -->\n";
|
---|
131 | return $body;
|
---|
132 | }
|
---|
133 |
|
---|
134 | //Making of module header
|
---|
135 | function get_xpress_module_header($contents)
|
---|
136 | {
|
---|
137 | global $xoopsTpl;
|
---|
138 | if( defined( 'XOOPS_CUBE_LEGACY' ) ) {
|
---|
139 | $preload_make_module_header = $xoopsTpl->get_template_vars('xoops_module_header');
|
---|
140 | } else {
|
---|
141 | $preload_make_module_header = '';
|
---|
142 | }
|
---|
143 |
|
---|
144 | if (! empty($preload_make_module_header)){
|
---|
145 | $preload_make_module_header = '<!-- preload added module header -->
|
---|
146 | ' . $preload_make_module_header . '
|
---|
147 | ';
|
---|
148 | }
|
---|
149 |
|
---|
150 | $wp_module_header = '<!-- wordpress added module header -->
|
---|
151 | ' . get_mod_header($contents) . '
|
---|
152 | <!-- end of wordpress added module header -->';
|
---|
153 |
|
---|
154 | return $preload_make_module_header . $wp_module_header;
|
---|
155 | }
|
---|
156 |
|
---|
157 | //PHP_SELF and GET are remake for the XOOPS event notification.
|
---|
158 | function xpress_remake_global_for_permlink(){
|
---|
159 | global $wp_db,$wp_query;
|
---|
160 | $php_self = $_SERVER['PHP_SELF'];
|
---|
161 | $get = $_GET;
|
---|
162 |
|
---|
163 | if (preg_match('/\/$/',$php_self) && !preg_match('/index.php/',$php_self)) {
|
---|
164 | $php_self = $php_self . 'index.php';
|
---|
165 | $_SERVER['PHP_SELF'] = $php_self;
|
---|
166 | }
|
---|
167 | if (empty($_GET)){
|
---|
168 | $query_vars = $wp_query->query_vars;
|
---|
169 | $post = $wp_query->post;
|
---|
170 | if ($wp_query->is_single) {
|
---|
171 | $_GET = array('p'=>$post->ID);
|
---|
172 | } else if($wp_query->is_category){
|
---|
173 | $_GET = array('cat'=>$query_vars['cat']);
|
---|
174 | } else if($wp_query->is_author){
|
---|
175 | $_GET = array('author'=>$query_vars['author']);
|
---|
176 | }
|
---|
177 | }
|
---|
178 | }
|
---|
179 |
|
---|
180 | //rendering for the module header and the body
|
---|
181 | function xpress_render($contents){
|
---|
182 | global $xoops_config;
|
---|
183 | global $xoopsUser , $xoopsTpl,$xpress_config , $xoopsModule , $xoopsLogger, $xoopsConfig ; //for XOOPS
|
---|
184 |
|
---|
185 | require_once( ABSPATH .'/include/xpress_breadcrumbs.php' );
|
---|
186 | $xoops_breadcrumbs = get_breadcrumbs();
|
---|
187 |
|
---|
188 | xpress_remake_global_for_permlink();
|
---|
189 | $mydirname = basename(dirname(dirname(__FILE__)));
|
---|
190 | include $xoops_config->xoops_root_path ."/header.php";
|
---|
191 | $xoopsTpl->assign('xoops_breadcrumbs', $xoops_breadcrumbs);
|
---|
192 | $xoopsTpl->assign('xoops_module_header', get_xpress_module_header($contents));
|
---|
193 | $page_title = $GLOBALS["xoopsModule"]->getVar("name"). ' »'. get_xpress_title($contents);
|
---|
194 | $xoopsTpl->assign('xoops_pagetitle', $page_title);
|
---|
195 |
|
---|
196 | $xoops_keywords = $xoopsTpl->get_template_vars('xoops_meta_keywords');
|
---|
197 | $wp_keyword = get_xpress_meta_name('keywords',$contents);
|
---|
198 | switch ($xpress_config->meta_keyword_type){
|
---|
199 | case 'xoops':
|
---|
200 | break;
|
---|
201 | case 'wordpress':
|
---|
202 | if (!empty($wp_keyword))
|
---|
203 | $xoopsTpl->assign('xoops_meta_keywords', $wp_keyword);
|
---|
204 | break;
|
---|
205 | case 'wordpress_xoops':
|
---|
206 | if (!empty($wp_keyword)){
|
---|
207 | if (!empty($xoops_keywords)){
|
---|
208 | $keywords = $wp_keyword . ', ' . $xoops_keywords;
|
---|
209 | } else {
|
---|
210 | $keywords = $wp_keyword;
|
---|
211 | }
|
---|
212 | $xoopsTpl->assign('xoops_meta_keywords', $keywords);
|
---|
213 | }
|
---|
214 | break;
|
---|
215 | default :
|
---|
216 | }
|
---|
217 |
|
---|
218 | $xoops_description = $xoopsTpl->get_template_vars('xoops_meta_description');
|
---|
219 | $wp_description = get_xpress_meta_name('description',$contents);
|
---|
220 | switch ($xpress_config->meta_description_type){
|
---|
221 | case 'xoops':
|
---|
222 | break;
|
---|
223 | case 'wordpress':
|
---|
224 | if (!empty($wp_description))
|
---|
225 | $xoopsTpl->assign('xoops_meta_description', $wp_description);
|
---|
226 | break;
|
---|
227 | case 'wordpress_xoops':
|
---|
228 | if (!empty($wp_description)){
|
---|
229 | if (!empty($xoops_description)){
|
---|
230 | $description = $wp_description . ' ' . $xoops_description;
|
---|
231 | } else {
|
---|
232 | $description = $wp_description;
|
---|
233 | }
|
---|
234 | $xoopsTpl->assign('xoops_meta_description', $description);
|
---|
235 | }
|
---|
236 | break;
|
---|
237 | default :
|
---|
238 | }
|
---|
239 |
|
---|
240 | $wp_robots = get_xpress_meta_name('robots',$contents);
|
---|
241 | switch ($xpress_config->meta_robot_type){
|
---|
242 | case 'xoops':
|
---|
243 | break;
|
---|
244 | case 'wordpress':
|
---|
245 | if (!empty($wp_robots))
|
---|
246 | $xoopsTpl->assign('xoops_meta_robots', $wp_robots);
|
---|
247 | break;
|
---|
248 | default :
|
---|
249 | }
|
---|
250 |
|
---|
251 | $xpress_data['body_contents'] = get_body($contents);
|
---|
252 | // used $GLOBALS. becose xpress_left_arrow_post_link() and xpress_right_arrow_post_link() is other loop in this position
|
---|
253 | $xpress_data['left_post_link'] = @$GLOBALS['left_arrow_post_link'];
|
---|
254 | $xpress_data['right_post_link'] = @$GLOBALS['right_arrow_post_link'];
|
---|
255 | $xpress_data['left_posts_link'] = str_replace('«','',xpress_left_arrow_posts_link('echo=0'));
|
---|
256 | $xpress_data['right_posts_link'] = str_replace('»','',xpress_right_arrow_posts_link('echo=0'));
|
---|
257 | $xpress_data['now_user_level'] = xpress_now_user_level('echo=0');
|
---|
258 |
|
---|
259 | //If notification_select.php is not executed in CMS other than XCL, the selector of in-line is not displayed.
|
---|
260 | if (is_object($xoopsModule) && $xoopsModule->getVar('hasnotification') == 1 && is_object($xoopsUser)) {
|
---|
261 | require_once $xoops_config->xoops_root_path . '/include/notification_select.php';
|
---|
262 | }
|
---|
263 |
|
---|
264 | $xoopsTpl->assign('xpress', $xpress_data);
|
---|
265 | $templates_file = 'db:'.$mydirname. '_index.html';
|
---|
266 | echo $xoopsTpl->fetch( $templates_file ) ;
|
---|
267 | include $xoops_config->xoops_root_path . '/footer.php';
|
---|
268 | }
|
---|
269 |
|
---|
270 | ?> |
---|