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 | $pattern = "^";
|
---|
40 | $head_str = preg_replace("/".$pattern."/m" , "\t" , $head_str);
|
---|
41 |
|
---|
42 | return $head_str;
|
---|
43 | }
|
---|
44 |
|
---|
45 | function meta_name_cut($name = '', $head_str)
|
---|
46 | {
|
---|
47 | $pattern = '<\s*meta\s+name\s*=\s*["\']' . $name . '["\'][^>]*?>';
|
---|
48 | $head_str = preg_replace("/".$pattern."/i" , '' , $head_str);
|
---|
49 | return $head_str;
|
---|
50 | }
|
---|
51 |
|
---|
52 | // for title reprace plugin (all in one seo pack)
|
---|
53 | function get_xpress_title($contents)
|
---|
54 | {
|
---|
55 | $pattern = '<title[^>]*?>(.*)<\s*\/\s*title\s*>';
|
---|
56 | $title_str = '';
|
---|
57 | if (preg_match("/".$pattern."/i", $contents, $head_matches)){
|
---|
58 | $title_str = $head_matches[1];
|
---|
59 | }
|
---|
60 | return $title_str;
|
---|
61 | }
|
---|
62 |
|
---|
63 | function get_xpress_meta_name($name = '',$contents)
|
---|
64 | {
|
---|
65 | $pattern = '<\s*meta\s+name\s*=\s*["\']' . $name . '["\']\s*content\s*=\s*[\'"](.*)[\'"]\s*\/\s*>';
|
---|
66 | $meta = '';
|
---|
67 | if (preg_match("/".$pattern."/i", $contents, $head_matches)){
|
---|
68 | $meta = @$head_matches[1];
|
---|
69 | }
|
---|
70 | return $meta;
|
---|
71 | }
|
---|
72 |
|
---|
73 | // get sidebar rendaring
|
---|
74 | function get_sidebar_rander($name = null)
|
---|
75 | {
|
---|
76 | $templates = array();
|
---|
77 | if ( isset($name) )
|
---|
78 | $templates[] = "sidebar-{$name}.php";
|
---|
79 |
|
---|
80 | $templates[] = "sidebar.php";
|
---|
81 |
|
---|
82 | $link= locate_template($templates, false);
|
---|
83 | if ('' == $link){
|
---|
84 | // $link = get_theme_root() . '/default/sidebar.php';
|
---|
85 | return '';
|
---|
86 | } else {
|
---|
87 | ob_start();
|
---|
88 | require($link);
|
---|
89 | $sidebar = ob_get_contents();
|
---|
90 | ob_end_clean();
|
---|
91 | return $sidebar;
|
---|
92 | }
|
---|
93 | }
|
---|
94 |
|
---|
95 | // < body > tag is pulled out from the header of html contents.
|
---|
96 | function get_body($contents)
|
---|
97 | {
|
---|
98 | global $xpess_config;
|
---|
99 | if (!is_object($xpess_config)) $xpess_config = new XPressME_Class();
|
---|
100 | $pattern = "<body[^>]*?>(.*)<\/body>";
|
---|
101 | $body = '';
|
---|
102 | if(preg_match("/".$pattern."/s", $contents, $body_matches)){
|
---|
103 | $body = $body_matches[1];
|
---|
104 | }
|
---|
105 |
|
---|
106 | if ($xpess_config->is_theme_sidebar_disp){
|
---|
107 | $xpress_class = 'xpress-body';
|
---|
108 | } else {
|
---|
109 | $xpress_class = 'xpress-body onecolumn';
|
---|
110 | }
|
---|
111 |
|
---|
112 | $pattern = '<body\s*([^>]*)>';
|
---|
113 | $body_class = 'class="' . $xpress_class . '"';
|
---|
114 | if(preg_match("/".$pattern."/s", $contents, $body_matches)){
|
---|
115 | $body_tag_option = $body_matches[1];
|
---|
116 |
|
---|
117 | $pattern = 'class\s*=\s*[\'|"]([^\'|^"]*)[\'|"]';
|
---|
118 | if(preg_match("/".$pattern."/", $body_tag_option, $class_matches)){
|
---|
119 | $class_value = $class_matches[1];
|
---|
120 | $reprace = $xpress_class . ' '. $class_value;
|
---|
121 | $body_class = preg_replace("/".$class_value."/", $reprace, $body_tag_option);
|
---|
122 | } else {
|
---|
123 | $body_class = 'class="' . $xpress_class . '" ' . $body_tag_option;
|
---|
124 | }
|
---|
125 | }
|
---|
126 |
|
---|
127 | if (!$xpess_config->is_theme_sidebar_disp){
|
---|
128 | $side_panel = get_sidebar_rander();
|
---|
129 | $body = str_replace($side_panel,'',$body);
|
---|
130 | }
|
---|
131 | $body = "\n<div " . $body_class . "> <!-- Substitution of wordpress <body > -->\n" . $body . "\n</div> <!-- Substitution of wordpress </body > -->\n";
|
---|
132 | return $body;
|
---|
133 | }
|
---|
134 |
|
---|
135 | //Making of module header
|
---|
136 | function get_xpress_module_header($contents)
|
---|
137 | {
|
---|
138 | global $xoopsTpl;
|
---|
139 | if( defined( 'XOOPS_CUBE_LEGACY' ) ) {
|
---|
140 | $preload_make_module_header = $xoopsTpl->get_template_vars('xoops_module_header');
|
---|
141 | } else {
|
---|
142 | $preload_make_module_header = '';
|
---|
143 | }
|
---|
144 |
|
---|
145 | if (! empty($preload_make_module_header)){
|
---|
146 | $preload_make_module_header = '<!-- preload added module header -->
|
---|
147 | ' . $preload_make_module_header . '
|
---|
148 | ';
|
---|
149 | }
|
---|
150 |
|
---|
151 | $wp_module_header = '<!-- wordpress added module header -->
|
---|
152 | ' . get_mod_header($contents) . '
|
---|
153 | <!-- end of wordpress added module header -->';
|
---|
154 | $wp_module_header .= "\n<!-- credit " . xpress_credit('echo=0&no_link=1') . " -->\n";
|
---|
155 |
|
---|
156 | return $preload_make_module_header . $wp_module_header;
|
---|
157 | }
|
---|
158 |
|
---|
159 | //PHP_SELF and GET are remake for the XOOPS event notification.
|
---|
160 | function xpress_remake_global_for_permlink(){
|
---|
161 | global $wp_db,$wp_query;
|
---|
162 | $php_self = $_SERVER['PHP_SELF'];
|
---|
163 | $get = $_GET;
|
---|
164 |
|
---|
165 | if (preg_match('/\/$/',$php_self) && !preg_match('/index.php/',$php_self)) {
|
---|
166 | $php_self = $php_self . 'index.php';
|
---|
167 | $_SERVER['PHP_SELF'] = $php_self;
|
---|
168 | }
|
---|
169 | if (empty($_GET)){
|
---|
170 | $query_vars = $wp_query->query_vars;
|
---|
171 | $post = $wp_query->post;
|
---|
172 | if ($wp_query->is_single) {
|
---|
173 | $_GET = array('p'=>$post->ID);
|
---|
174 | } else if($wp_query->is_category){
|
---|
175 | $_GET = array('cat'=>$query_vars['cat']);
|
---|
176 | } else if($wp_query->is_author){
|
---|
177 | $_GET = array('author'=>$query_vars['author']);
|
---|
178 | }
|
---|
179 | }
|
---|
180 | }
|
---|
181 |
|
---|
182 | function xpress_meta_assign($meta_key,$meta_word){
|
---|
183 | global $xoopsTpl,$xoTheme; //for XOOPS
|
---|
184 |
|
---|
185 | if (!empty($meta_key) && !empty($meta_word)){
|
---|
186 | if (defined('LEGACY_MODULE_VERSION') && version_compare(LEGACY_MODULE_VERSION, '2.2', '>=')) {
|
---|
187 | // For XCL 2.2
|
---|
188 | $xclRoot =& XCube_Root::getSingleton();
|
---|
189 | $headerScript = $xclRoot->mContext->getAttribute('headerScript');
|
---|
190 | $headerScript->addMeta($meta_key, $meta_word);
|
---|
191 | } elseif (isset($xoTheme) && is_object($xoTheme)) {
|
---|
192 | // For XOOPS 2.3 or higher & Impress CMS.
|
---|
193 | $xoTheme->addMeta('meta', $meta_key, $meta_word);
|
---|
194 | }
|
---|
195 | $xoopsTpl->assign('xoops_meta_'. $meta_key, $meta_word);
|
---|
196 | }
|
---|
197 | }
|
---|
198 | function xpress_get_xoops_meta($meta_key){
|
---|
199 | global $xoopsTpl,$xoTheme; //for XOOPS
|
---|
200 |
|
---|
201 | if (defined('LEGACY_MODULE_VERSION') && version_compare(LEGACY_MODULE_VERSION, '2.2', '>=')) {
|
---|
202 | // For XCL 2.2
|
---|
203 | $moduleHandler =& xoops_gethandler('module');
|
---|
204 | $legacyRender =& $moduleHandler->getByDirname('legacyRender');
|
---|
205 | $configHandler =& xoops_gethandler('config');
|
---|
206 | $configs =& $configHandler->getConfigsByCat(0, $legacyRender->get('mid'));
|
---|
207 | $ret = htmlspecialchars($configs['meta_'.$meta_key]);
|
---|
208 | } elseif (isset($xoTheme) && is_object($xoTheme)) {
|
---|
209 | $ret = $xoTheme->metas['meta'][$meta_key];
|
---|
210 | } else {
|
---|
211 | $ret = $xoopsTpl->get_template_vars('xoops_meta_'.$meta_key);
|
---|
212 | }
|
---|
213 | return $ret;
|
---|
214 | }
|
---|
215 |
|
---|
216 |
|
---|
217 | //rendering for the module header and the body
|
---|
218 | function xpress_render($contents){
|
---|
219 | global $xoops_config;
|
---|
220 | global $xoopsUser , $xoopsTpl,$xpress_config , $xoopsModule , $xoopsLogger, $xoopsConfig ; //for XOOPS
|
---|
221 |
|
---|
222 | //disable cache
|
---|
223 | $xoopsConfig['module_cache'][$xoopsModule->getVar('mid')] = 0;
|
---|
224 |
|
---|
225 | require_once( ABSPATH .'/include/xpress_breadcrumbs.php' );
|
---|
226 | $xoops_breadcrumbs = get_breadcrumbs();
|
---|
227 |
|
---|
228 | xpress_remake_global_for_permlink();
|
---|
229 | $mydirname = basename(dirname(dirname(__FILE__)));
|
---|
230 | if (defined('LEGACY_BASE_VERSION') && version_compare(LEGACY_BASE_VERSION, '2.2.1.1', '>=')) {
|
---|
231 | $module_handler =& xoops_gethandler('module');
|
---|
232 | $thisModule =& $module_handler->getByDirname($mydirname);
|
---|
233 | $thisModule->modinfo = null;
|
---|
234 | }
|
---|
235 | include $xoops_config->xoops_root_path ."/header.php";
|
---|
236 | $xoopsTpl->assign('xoops_breadcrumbs', $xoops_breadcrumbs);
|
---|
237 | $xoopsTpl->assign('xoops_module_header', get_xpress_module_header($contents));
|
---|
238 | $page_title = $GLOBALS["xoopsModule"]->getVar("name"). ' »'. get_xpress_title($contents);
|
---|
239 | $xoopsTpl->assign('xoops_pagetitle', $page_title);
|
---|
240 |
|
---|
241 | $xoops_keywords = xpress_get_xoops_meta('keywords');
|
---|
242 |
|
---|
243 | $wp_keyword = get_xpress_meta_name('keywords',$contents);
|
---|
244 | switch ($xpress_config->meta_keyword_type){
|
---|
245 | case 'xoops':
|
---|
246 | break;
|
---|
247 | case 'wordpress':
|
---|
248 | if (!empty($wp_keyword)){
|
---|
249 | xpress_meta_assign('keywords', $wp_keyword);
|
---|
250 | }
|
---|
251 | break;
|
---|
252 | case 'wordpress_xoops':
|
---|
253 | if (!empty($wp_keyword)){
|
---|
254 | if (!empty($xoops_keywords)){
|
---|
255 | $keywords = $wp_keyword . ', ' . $xoops_keywords;
|
---|
256 | } else {
|
---|
257 | $keywords = $wp_keyword;
|
---|
258 | }
|
---|
259 | xpress_meta_assign('keywords', $keywords);
|
---|
260 | }
|
---|
261 | break;
|
---|
262 | default :
|
---|
263 | }
|
---|
264 |
|
---|
265 | $xoops_description = xpress_get_xoops_meta('description');
|
---|
266 | $wp_description = get_xpress_meta_name('description',$contents);
|
---|
267 |
|
---|
268 | switch ($xpress_config->meta_description_type){
|
---|
269 | case 'xoops':
|
---|
270 | break;
|
---|
271 | case 'wordpress':
|
---|
272 | if (!empty($wp_description)){
|
---|
273 | xpress_meta_assign('description', $wp_description);
|
---|
274 | }
|
---|
275 | break;
|
---|
276 | case 'wordpress_xoops':
|
---|
277 | if (!empty($wp_description)){
|
---|
278 | if (!empty($xoops_description)){
|
---|
279 | $description = $wp_description . ' ' . $xoops_description;
|
---|
280 | } else {
|
---|
281 | $description = $wp_description;
|
---|
282 | }
|
---|
283 | xpress_meta_assign('description', $description);
|
---|
284 | }
|
---|
285 | break;
|
---|
286 | default :
|
---|
287 | }
|
---|
288 |
|
---|
289 | $wp_robots = get_xpress_meta_name('robots',$contents);
|
---|
290 | switch ($xpress_config->meta_robot_type){
|
---|
291 | case 'xoops':
|
---|
292 | break;
|
---|
293 | case 'wordpress':
|
---|
294 | if (!empty($wp_robots))
|
---|
295 | xpress_meta_assign('robots', $wp_robots);
|
---|
296 | break;
|
---|
297 | default :
|
---|
298 | }
|
---|
299 | if (empty($contents)){
|
---|
300 | $template_name = get_option('template');
|
---|
301 | $xpress_data['body_contents'] = "<p>Themes \"$template_name\" is broken or doesn't exist. </p><p>Please choose the right theme from the admin page of wordpress.</p>";
|
---|
302 | } else {
|
---|
303 | $xpress_data['body_contents'] = get_body($contents);
|
---|
304 | }
|
---|
305 | // used $GLOBALS. becose xpress_left_arrow_post_link() and xpress_right_arrow_post_link() is other loop in this position
|
---|
306 | $xpress_data['left_post_link'] = @$GLOBALS['left_arrow_post_link'];
|
---|
307 | $xpress_data['right_post_link'] = @$GLOBALS['right_arrow_post_link'];
|
---|
308 | $xpress_data['left_posts_link'] = str_replace('«','',xpress_left_arrow_posts_link('echo=0'));
|
---|
309 | $xpress_data['right_posts_link'] = str_replace('»','',xpress_right_arrow_posts_link('echo=0'));
|
---|
310 | $xpress_data['now_user_level'] = xpress_now_user_level('echo=0');
|
---|
311 |
|
---|
312 | //If notification_select.php is not executed in CMS other than XCL, the selector of in-line is not displayed.
|
---|
313 | if (is_object($xoopsModule) && $xoopsModule->getVar('hasnotification') == 1 && is_object($xoopsUser)) {
|
---|
314 | require_once $xoops_config->xoops_root_path . '/include/notification_select.php';
|
---|
315 | }
|
---|
316 |
|
---|
317 | $xoopsTpl->assign('xpress', $xpress_data);
|
---|
318 | $templates_file = 'db:'.$mydirname. '_index.html';
|
---|
319 | echo $xoopsTpl->fetch( $templates_file ) ;
|
---|
320 | include $xoops_config->xoops_root_path . '/footer.php';
|
---|
321 | }
|
---|
322 |
|
---|
323 | ?> |
---|