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 | require_once( ABSPATH .'/include/xpress_breadcrumbs.php' );
|
---|
223 | $xoops_breadcrumbs = get_breadcrumbs();
|
---|
224 |
|
---|
225 | xpress_remake_global_for_permlink();
|
---|
226 | $mydirname = basename(dirname(dirname(__FILE__)));
|
---|
227 | include $xoops_config->xoops_root_path ."/header.php";
|
---|
228 | $xoopsTpl->assign('xoops_breadcrumbs', $xoops_breadcrumbs);
|
---|
229 | $xoopsTpl->assign('xoops_module_header', get_xpress_module_header($contents));
|
---|
230 | $page_title = $GLOBALS["xoopsModule"]->getVar("name"). ' »'. get_xpress_title($contents);
|
---|
231 | $xoopsTpl->assign('xoops_pagetitle', $page_title);
|
---|
232 |
|
---|
233 | $xoops_keywords = xpress_get_xoops_meta('keywords');
|
---|
234 |
|
---|
235 | $wp_keyword = get_xpress_meta_name('keywords',$contents);
|
---|
236 | switch ($xpress_config->meta_keyword_type){
|
---|
237 | case 'xoops':
|
---|
238 | break;
|
---|
239 | case 'wordpress':
|
---|
240 | if (!empty($wp_keyword)){
|
---|
241 | xpress_meta_assign('keywords', $wp_keyword);
|
---|
242 | }
|
---|
243 | break;
|
---|
244 | case 'wordpress_xoops':
|
---|
245 | if (!empty($wp_keyword)){
|
---|
246 | if (!empty($xoops_keywords)){
|
---|
247 | $keywords = $wp_keyword . ', ' . $xoops_keywords;
|
---|
248 | } else {
|
---|
249 | $keywords = $wp_keyword;
|
---|
250 | }
|
---|
251 | xpress_meta_assign('keywords', $keywords);
|
---|
252 | }
|
---|
253 | break;
|
---|
254 | default :
|
---|
255 | }
|
---|
256 |
|
---|
257 | $xoops_description = xpress_get_xoops_meta('description');
|
---|
258 | $wp_description = get_xpress_meta_name('description',$contents);
|
---|
259 |
|
---|
260 | switch ($xpress_config->meta_description_type){
|
---|
261 | case 'xoops':
|
---|
262 | break;
|
---|
263 | case 'wordpress':
|
---|
264 | if (!empty($wp_description)){
|
---|
265 | xpress_meta_assign('description', $wp_description);
|
---|
266 | }
|
---|
267 | break;
|
---|
268 | case 'wordpress_xoops':
|
---|
269 | if (!empty($wp_description)){
|
---|
270 | if (!empty($xoops_description)){
|
---|
271 | $description = $wp_description . ' ' . $xoops_description;
|
---|
272 | } else {
|
---|
273 | $description = $wp_description;
|
---|
274 | }
|
---|
275 | xpress_meta_assign('description', $description);
|
---|
276 | }
|
---|
277 | break;
|
---|
278 | default :
|
---|
279 | }
|
---|
280 |
|
---|
281 | $wp_robots = get_xpress_meta_name('robots',$contents);
|
---|
282 | switch ($xpress_config->meta_robot_type){
|
---|
283 | case 'xoops':
|
---|
284 | break;
|
---|
285 | case 'wordpress':
|
---|
286 | if (!empty($wp_robots))
|
---|
287 | xpress_meta_assign('robots', $wp_robots);
|
---|
288 | break;
|
---|
289 | default :
|
---|
290 | }
|
---|
291 | if (empty($contents)){
|
---|
292 | $template_name = get_option('template');
|
---|
293 | $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>";
|
---|
294 | } else {
|
---|
295 | $xpress_data['body_contents'] = get_body($contents);
|
---|
296 | }
|
---|
297 | // used $GLOBALS. becose xpress_left_arrow_post_link() and xpress_right_arrow_post_link() is other loop in this position
|
---|
298 | $xpress_data['left_post_link'] = @$GLOBALS['left_arrow_post_link'];
|
---|
299 | $xpress_data['right_post_link'] = @$GLOBALS['right_arrow_post_link'];
|
---|
300 | $xpress_data['left_posts_link'] = str_replace('«','',xpress_left_arrow_posts_link('echo=0'));
|
---|
301 | $xpress_data['right_posts_link'] = str_replace('»','',xpress_right_arrow_posts_link('echo=0'));
|
---|
302 | $xpress_data['now_user_level'] = xpress_now_user_level('echo=0');
|
---|
303 |
|
---|
304 | //If notification_select.php is not executed in CMS other than XCL, the selector of in-line is not displayed.
|
---|
305 | if (is_object($xoopsModule) && $xoopsModule->getVar('hasnotification') == 1 && is_object($xoopsUser)) {
|
---|
306 | require_once $xoops_config->xoops_root_path . '/include/notification_select.php';
|
---|
307 | }
|
---|
308 |
|
---|
309 | $xoopsTpl->assign('xpress', $xpress_data);
|
---|
310 | $templates_file = 'db:'.$mydirname. '_index.html';
|
---|
311 | echo $xoopsTpl->fetch( $templates_file ) ;
|
---|
312 | include $xoops_config->xoops_root_path . '/footer.php';
|
---|
313 | }
|
---|
314 |
|
---|
315 | ?> |
---|