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