| [1] | 1 | <?php
 | 
|---|
 | 2 | 
 | 
|---|
 | 3 | //< style >< script >< link > tag is pulled out from the header of html contents. 
 | 
|---|
 | 4 | function get_mod_header($contents)
 | 
|---|
 | 5 | {
 | 
|---|
| [201] | 6 |         global $xpress_config;
 | 
|---|
| [278] | 7 |         
 | 
|---|
 | 8 |         $pattern = "<body[^>]*?>(.*)<\/body>";
 | 
|---|
 | 9 |         $body_cut = preg_replace("/".$pattern."/s" , '' , $contents);
 | 
|---|
 | 10 | 
 | 
|---|
 | 11 | 
 | 
|---|
| [1] | 12 |         $pattern = "<head[^>]*?>(.*)<\/head>";
 | 
|---|
| [431] | 13 |         $head_str = '';
 | 
|---|
 | 14 |         if (preg_match("/".$pattern."/s",  $body_cut, $head_matches)){
 | 
|---|
 | 15 |                 $head_str = $head_matches[1];
 | 
|---|
 | 16 |         }
 | 
|---|
| [201] | 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);       
 | 
|---|
| [573] | 39 |         $pattern = "^";
 | 
|---|
 | 40 |         $head_str = preg_replace("/".$pattern."/m" , "\t" , $head_str);
 | 
|---|
 | 41 | 
 | 
|---|
| [201] | 42 |         return $head_str;
 | 
|---|
| [1] | 43 | }
 | 
|---|
 | 44 | 
 | 
|---|
| [201] | 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*>';
 | 
|---|
| [431] | 56 |         $title_str = '';
 | 
|---|
 | 57 |         if (preg_match("/".$pattern."/i",  $contents, $head_matches)){
 | 
|---|
 | 58 |                 $title_str = $head_matches[1];
 | 
|---|
 | 59 |         }
 | 
|---|
| [201] | 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*>';
 | 
|---|
| [431] | 66 |         $meta = '';
 | 
|---|
 | 67 |         if (preg_match("/".$pattern."/i",  $contents, $head_matches)){
 | 
|---|
 | 68 |                 $meta = @$head_matches[1];
 | 
|---|
 | 69 |         }
 | 
|---|
| [201] | 70 |         return $meta;
 | 
|---|
 | 71 | }
 | 
|---|
 | 72 | 
 | 
|---|
| [26] | 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);
 | 
|---|
| [672] | 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 |         }
 | 
|---|
| [26] | 93 | }
 | 
|---|
 | 94 | 
 | 
|---|
| [1] | 95 | // < body > tag is pulled out from the header of html contents. 
 | 
|---|
 | 96 | function get_body($contents)
 | 
|---|
 | 97 | {
 | 
|---|
| [560] | 98 |         global $xpess_config;
 | 
|---|
 | 99 |         if (!is_object($xpess_config)) $xpess_config = new XPressME_Class();
 | 
|---|
| [1] | 100 |         $pattern = "<body[^>]*?>(.*)<\/body>";
 | 
|---|
| [431] | 101 |         $body = '';
 | 
|---|
 | 102 |         if(preg_match("/".$pattern."/s",  $contents, $body_matches)){
 | 
|---|
 | 103 |                 $body = $body_matches[1];
 | 
|---|
 | 104 |         }
 | 
|---|
| [560] | 105 |         
 | 
|---|
| [561] | 106 |         if ($xpess_config->is_theme_sidebar_disp){
 | 
|---|
 | 107 |                 $xpress_class = 'xpress-body';
 | 
|---|
 | 108 |         } else {
 | 
|---|
 | 109 |                 $xpress_class = 'xpress-body onecolumn';
 | 
|---|
 | 110 |         }
 | 
|---|
 | 111 |         
 | 
|---|
| [560] | 112 |         $pattern = '<body\s*([^>]*)>';
 | 
|---|
| [561] | 113 |         $body_class = 'class="' . $xpress_class . '"';
 | 
|---|
| [560] | 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];
 | 
|---|
| [561] | 120 |                         $reprace = $xpress_class . ' '. $class_value;
 | 
|---|
| [560] | 121 |                         $body_class = preg_replace("/".$class_value."/",  $reprace, $body_tag_option);
 | 
|---|
 | 122 |                 } else {
 | 
|---|
| [561] | 123 |                         $body_class = 'class="' . $xpress_class . '" ' . $body_tag_option;
 | 
|---|
| [560] | 124 |                 }
 | 
|---|
 | 125 |         }
 | 
|---|
 | 126 | 
 | 
|---|
| [26] | 127 |         if (!$xpess_config->is_theme_sidebar_disp){
 | 
|---|
 | 128 |                 $side_panel = get_sidebar_rander();
 | 
|---|
 | 129 |                         $body = str_replace($side_panel,'',$body);
 | 
|---|
 | 130 |         }
 | 
|---|
| [560] | 131 |         $body = "\n<div " . $body_class . "> <!-- Substitution of wordpress <body > -->\n" . $body . "\n</div> <!-- Substitution of wordpress </body > -->\n";
 | 
|---|
| [1] | 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 -->';
 | 
|---|
| [576] | 154 |         $wp_module_header .= "\n<!-- credit " . xpress_credit('echo=0&no_link=1') . " -->\n";
 | 
|---|
 | 155 | 
 | 
|---|
| [1] | 156 |         return $preload_make_module_header . $wp_module_header;
 | 
|---|
 | 157 | }
 | 
|---|
 | 158 | 
 | 
|---|
| [229] | 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 | 
 | 
|---|
| [803] | 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 | 
 | 
|---|
| [1] | 217 | //rendering for the module header and the body
 | 
|---|
 | 218 | function xpress_render($contents){
 | 
|---|
| [346] | 219 |         global $xoops_config;
 | 
|---|
 | 220 |         global $xoopsUser , $xoopsTpl,$xpress_config , $xoopsModule , $xoopsLogger, $xoopsConfig ; //for XOOPS
 | 
|---|
| [422] | 221 |         
 | 
|---|
| [839] | 222 |         //disable cache
 | 
|---|
 | 223 |         $xoopsConfig['module_cache'][$xoopsModule->getVar('mid')] = 0;
 | 
|---|
 | 224 | 
 | 
|---|
| [422] | 225 |         require_once( ABSPATH .'/include/xpress_breadcrumbs.php' );
 | 
|---|
| [432] | 226 |         $xoops_breadcrumbs = get_breadcrumbs();
 | 
|---|
 | 227 | 
 | 
|---|
| [229] | 228 |         xpress_remake_global_for_permlink();
 | 
|---|
| [109] | 229 |         $mydirname = basename(dirname(dirname(__FILE__)));
 | 
|---|
| [96] | 230 |         include $xoops_config->xoops_root_path ."/header.php";
 | 
|---|
| [432] | 231 |         $xoopsTpl->assign('xoops_breadcrumbs', $xoops_breadcrumbs);
 | 
|---|
| [1] | 232 |         $xoopsTpl->assign('xoops_module_header', get_xpress_module_header($contents));
 | 
|---|
| [201] | 233 |         $page_title = $GLOBALS["xoopsModule"]->getVar("name"). ' »'. get_xpress_title($contents);
 | 
|---|
| [1] | 234 |         $xoopsTpl->assign('xoops_pagetitle', $page_title);
 | 
|---|
| [201] | 235 |         
 | 
|---|
| [803] | 236 |         $xoops_keywords =  xpress_get_xoops_meta('keywords');
 | 
|---|
 | 237 |         
 | 
|---|
| [201] | 238 |         $wp_keyword = get_xpress_meta_name('keywords',$contents);
 | 
|---|
 | 239 |         switch ($xpress_config->meta_keyword_type){
 | 
|---|
 | 240 |                 case 'xoops':
 | 
|---|
 | 241 |                         break;
 | 
|---|
 | 242 |                 case 'wordpress':
 | 
|---|
| [803] | 243 |                         if (!empty($wp_keyword)){
 | 
|---|
 | 244 |                                 xpress_meta_assign('keywords', $wp_keyword);
 | 
|---|
 | 245 |                         }
 | 
|---|
| [201] | 246 |                         break;
 | 
|---|
 | 247 |                 case 'wordpress_xoops':
 | 
|---|
 | 248 |                         if (!empty($wp_keyword)){
 | 
|---|
 | 249 |                                 if (!empty($xoops_keywords)){
 | 
|---|
 | 250 |                                         $keywords = $wp_keyword . ', ' . $xoops_keywords;
 | 
|---|
 | 251 |                                 } else {
 | 
|---|
 | 252 |                                         $keywords = $wp_keyword;
 | 
|---|
 | 253 |                                 }
 | 
|---|
| [803] | 254 |                                 xpress_meta_assign('keywords', $keywords);
 | 
|---|
| [201] | 255 |                         } 
 | 
|---|
 | 256 |                         break;
 | 
|---|
 | 257 |                 default :
 | 
|---|
 | 258 |         }
 | 
|---|
 | 259 | 
 | 
|---|
| [803] | 260 |         $xoops_description =  xpress_get_xoops_meta('description');
 | 
|---|
| [201] | 261 |         $wp_description = get_xpress_meta_name('description',$contents);
 | 
|---|
| [803] | 262 | 
 | 
|---|
| [201] | 263 |         switch ($xpress_config->meta_description_type){
 | 
|---|
 | 264 |                 case 'xoops':
 | 
|---|
 | 265 |                         break;
 | 
|---|
 | 266 |                 case 'wordpress':
 | 
|---|
| [803] | 267 |                         if (!empty($wp_description)){
 | 
|---|
 | 268 |                                 xpress_meta_assign('description', $wp_description);
 | 
|---|
 | 269 |                         }
 | 
|---|
| [201] | 270 |                         break;
 | 
|---|
 | 271 |                 case 'wordpress_xoops':
 | 
|---|
 | 272 |                         if (!empty($wp_description)){
 | 
|---|
 | 273 |                                 if (!empty($xoops_description)){
 | 
|---|
 | 274 |                                         $description = $wp_description . ' ' . $xoops_description;
 | 
|---|
 | 275 |                                 } else {
 | 
|---|
 | 276 |                                         $description = $wp_description;
 | 
|---|
 | 277 |                                 }
 | 
|---|
| [803] | 278 |                                 xpress_meta_assign('description', $description);
 | 
|---|
| [201] | 279 |                         } 
 | 
|---|
 | 280 |                         break;
 | 
|---|
 | 281 |                 default :
 | 
|---|
 | 282 |         }
 | 
|---|
| [202] | 283 | 
 | 
|---|
 | 284 |         $wp_robots = get_xpress_meta_name('robots',$contents);
 | 
|---|
 | 285 |         switch ($xpress_config->meta_robot_type){
 | 
|---|
 | 286 |                 case 'xoops':
 | 
|---|
 | 287 |                         break;
 | 
|---|
 | 288 |                 case 'wordpress':
 | 
|---|
 | 289 |                         if (!empty($wp_robots))
 | 
|---|
| [803] | 290 |                                 xpress_meta_assign('robots', $wp_robots);
 | 
|---|
| [202] | 291 |                         break;
 | 
|---|
 | 292 |                 default :
 | 
|---|
 | 293 |         }
 | 
|---|
| [672] | 294 |         if (empty($contents)){
 | 
|---|
 | 295 |                 $template_name = get_option('template');
 | 
|---|
 | 296 |                 $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>";
 | 
|---|
 | 297 |         } else {
 | 
|---|
 | 298 |                 $xpress_data['body_contents'] = get_body($contents);
 | 
|---|
 | 299 |         }
 | 
|---|
| [164] | 300 |         // used $GLOBALS. becose xpress_left_arrow_post_link() and xpress_right_arrow_post_link() is other loop in this position
 | 
|---|
| [431] | 301 |         $xpress_data['left_post_link'] = @$GLOBALS['left_arrow_post_link'];
 | 
|---|
 | 302 |         $xpress_data['right_post_link'] = @$GLOBALS['right_arrow_post_link'];
 | 
|---|
| [272] | 303 |         $xpress_data['left_posts_link'] =  str_replace('«','',xpress_left_arrow_posts_link('echo=0'));
 | 
|---|
 | 304 |         $xpress_data['right_posts_link'] = str_replace('»','',xpress_right_arrow_posts_link('echo=0'));
 | 
|---|
 | 305 |         $xpress_data['now_user_level'] = xpress_now_user_level('echo=0');
 | 
|---|
| [164] | 306 | 
 | 
|---|
| [343] | 307 |         //If notification_select.php is not executed in CMS other than XCL, the selector of in-line is not displayed. 
 | 
|---|
 | 308 |         if (is_object($xoopsModule) && $xoopsModule->getVar('hasnotification') == 1 && is_object($xoopsUser)) {
 | 
|---|
 | 309 |                 require_once $xoops_config->xoops_root_path . '/include/notification_select.php';
 | 
|---|
 | 310 |         }
 | 
|---|
 | 311 |         
 | 
|---|
| [164] | 312 |         $xoopsTpl->assign('xpress', $xpress_data);
 | 
|---|
| [109] | 313 |         $templates_file = 'db:'.$mydirname. '_index.html';
 | 
|---|
 | 314 |         echo $xoopsTpl->fetch( $templates_file ) ;
 | 
|---|
| [96] | 315 |         include $xoops_config->xoops_root_path . '/footer.php';
 | 
|---|
| [1] | 316 | }
 | 
|---|
 | 317 | 
 | 
|---|
 | 318 | ?> | 
|---|