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