Changeset 201 for trunk/include/xpress_render.php
- Timestamp:
- May 4, 2009, 7:31:25 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/xpress_render.php
r164 r201 4 4 function get_mod_header($contents) 5 5 { 6 global $xpress_config; 6 7 $pattern = "<head[^>]*?>(.*)<\/head>"; 7 8 preg_match("/".$pattern."/s", $contents, $head_matches); 8 9 $head_str = $head_matches[1]; 9 10 10 $pattern = "<style[^>]*?>(.*)<\/style>"; 11 preg_match("/".$pattern."/s", $head_str, $style_matches); 12 if (empty($style_matches[0])) 13 $style = ''; 14 else 15 $style = $style_matches[0]; 16 17 $pattern = "<link(.*)>"; 18 preg_match_all("/".$pattern."/", $head_str, $link_match,PREG_PATTERN_ORDER); 19 $links = $link_match[0]; 20 $link_str =''; 21 foreach ( $links as $link){ 22 ob_start(); 23 echo $link . "\n"; 24 25 $link_str .= ob_get_contents(); 26 ob_end_clean(); 27 } 28 29 $pattern = "<script[^>]*?>(.*)<\/script>"; 30 preg_match_all("/".$pattern."/s", $head_str, $script_match,PREG_PATTERN_ORDER); 31 $scripts = $script_match[0]; 32 $script_str =''; 33 foreach ( $scripts as $script){ 34 if (($GLOBALS["xoopsModuleConfig"]['use_d3forum'] != 1) || (strpos($script,'function wpopen') ===false)) 35 $script_str .= $script; 36 } 37 return $link_str."\n".$style . "\n" . $script_str ."\n"; 11 $pattern = '<head[^>]*?>'; 12 $head_str = preg_replace("/".$pattern."/s" , '' , $head_str); 13 $pattern = '<\/head>'; 14 $head_str = preg_replace("/".$pattern."/s" , '' , $head_str); 15 $pattern = '<\s*html\s+xmlns[^>]*?>'; 16 $head_str = preg_replace("/".$pattern."/s" , '' , $head_str); 17 $pattern = '<\s*head\s+profile[^>]*?>'; 18 $head_str = preg_replace("/".$pattern."/s" , '' , $head_str); 19 $pattern = '<\s*meta\s+http-equiv[^>]*?>'; 20 $head_str = preg_replace("/".$pattern."/s" , '' , $head_str); 21 $pattern = '<title[^>]*?>(.*)<\s*\/\s*title\s*>'; 22 $head_str = preg_replace("/".$pattern."/s" , '' , $head_str); 23 24 $head_str = meta_name_cut('robots',$head_str); 25 $head_str = meta_name_cut('keywords',$head_str); 26 $head_str = meta_name_cut('description',$head_str); 27 $head_str = meta_name_cut('rating',$head_str); 28 $head_str = meta_name_cut('author',$head_str); 29 $head_str = meta_name_cut('copyright',$head_str); 30 $head_str = meta_name_cut('generator',$head_str); 31 32 $head_str = preg_replace("/^(\s)*(\r|\n|\r\n)/m", "", $head_str); 33 return $head_str; 34 } 35 36 function meta_name_cut($name = '', $head_str) 37 { 38 $pattern = '<\s*meta\s+name\s*=\s*["\']' . $name . '["\'][^>]*?>'; 39 $head_str = preg_replace("/".$pattern."/i" , '' , $head_str); 40 return $head_str; 41 } 42 43 // for title reprace plugin (all in one seo pack) 44 function get_xpress_title($contents) 45 { 46 $pattern = '<title[^>]*?>(.*)<\s*\/\s*title\s*>'; 47 preg_match("/".$pattern."/i", $contents, $head_matches); 48 $title_str = $head_matches[1]; 49 return $title_str; 50 } 51 52 function get_xpress_meta_name($name = '',$contents) 53 { 54 $pattern = '<\s*meta\s+name\s*=\s*["\']' . $name . '["\']\s*content\s*=\s*[\'"](.*)[\'"]\s*\/\s*>'; 55 preg_match("/".$pattern."/i", $contents, $head_matches); 56 $meta = $head_matches[1]; 57 return $meta; 38 58 } 39 59 … … 98 118 //rendering for the module header and the body 99 119 function xpress_render($contents){ 100 global $xoops_config , $xoopsTpl ;120 global $xoops_config , $xoopsTpl,$xpress_config; 101 121 $mydirname = basename(dirname(dirname(__FILE__))); 102 122 include $xoops_config->xoops_root_path ."/header.php"; 103 $page_title = $GLOBALS["xoopsModule"]->getVar("name")." ".wp_title('»', false);104 123 $xoopsTpl->assign('xoops_module_header', get_xpress_module_header($contents)); 124 $page_title = $GLOBALS["xoopsModule"]->getVar("name"). ' »'. get_xpress_title($contents); 105 125 $xoopsTpl->assign('xoops_pagetitle', $page_title); 126 127 $xoops_keywords = $xoopsTpl->get_template_vars('xoops_meta_keywords'); 128 $wp_keyword = get_xpress_meta_name('keywords',$contents); 129 switch ($xpress_config->meta_keyword_type){ 130 case 'xoops': 131 break; 132 case 'wordpress': 133 if (!empty($wp_keyword)) 134 $xoopsTpl->assign('xoops_meta_keywords', $wp_keyword); 135 break; 136 case 'wordpress_xoops': 137 if (!empty($wp_keyword)){ 138 if (!empty($xoops_keywords)){ 139 $keywords = $wp_keyword . ', ' . $xoops_keywords; 140 } else { 141 $keywords = $wp_keyword; 142 } 143 $xoopsTpl->assign('xoops_meta_keywords', $keywords); 144 } 145 break; 146 default : 147 } 148 149 $xoops_description = $xoopsTpl->get_template_vars('xoops_meta_description'); 150 $wp_description = get_xpress_meta_name('description',$contents); 151 switch ($xpress_config->meta_description_type){ 152 case 'xoops': 153 break; 154 case 'wordpress': 155 if (!empty($wp_description)) 156 $xoopsTpl->assign('xoops_meta_description', $wp_description); 157 break; 158 case 'wordpress_xoops': 159 if (!empty($wp_description)){ 160 if (!empty($xoops_description)){ 161 $description = $wp_description . ' ' . $xoops_description; 162 } else { 163 $description = $wp_description; 164 } 165 $xoopsTpl->assign('xoops_meta_description', $description); 166 } 167 break; 168 default : 169 } 170 171 106 172 $xpress_data['body_contents'] = get_body($contents); 107 173 // used $GLOBALS. becose xpress_left_arrow_post_link() and xpress_right_arrow_post_link() is other loop in this position
Note: See TracChangeset
for help on using the changeset viewer.