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 | //rendering for the module header and the body
|
---|
183 | function xpress_render($contents){
|
---|
184 | global $modInfo;
|
---|
185 | global $xoopsUser , $xoopsTpl,$xpress_config , $xoopsModule , $xoopsLogger, $xoopsConfig ; //for XOOPS
|
---|
186 |
|
---|
187 | require_once( ABSPATH .'/include/xpress_breadcrumbs.php' );
|
---|
188 | $xoops_breadcrumbs = get_breadcrumbs();
|
---|
189 |
|
---|
190 | xpress_remake_global_for_permlink();
|
---|
191 | $mydirname = basename(dirname(dirname(__FILE__)));
|
---|
192 | include $modInfo->get_xoops_header_path();
|
---|
193 | $xoopsTpl->assign('xoops_breadcrumbs', $xoops_breadcrumbs);
|
---|
194 | $xoopsTpl->assign('xoops_module_header', get_xpress_module_header($contents));
|
---|
195 | $page_title = $GLOBALS["xoopsModule"]->getVar("name"). ' »'. get_xpress_title($contents);
|
---|
196 | $xoopsTpl->assign('xoops_pagetitle', $page_title);
|
---|
197 |
|
---|
198 | $xoops_keywords = $xoopsTpl->get_template_vars('xoops_meta_keywords');
|
---|
199 | $wp_keyword = get_xpress_meta_name('keywords',$contents);
|
---|
200 | switch ($xpress_config->meta_keyword_type){
|
---|
201 | case 'xoops':
|
---|
202 | break;
|
---|
203 | case 'wordpress':
|
---|
204 | if (!empty($wp_keyword))
|
---|
205 | $xoopsTpl->assign('xoops_meta_keywords', $wp_keyword);
|
---|
206 | break;
|
---|
207 | case 'wordpress_xoops':
|
---|
208 | if (!empty($wp_keyword)){
|
---|
209 | if (!empty($xoops_keywords)){
|
---|
210 | $keywords = $wp_keyword . ', ' . $xoops_keywords;
|
---|
211 | } else {
|
---|
212 | $keywords = $wp_keyword;
|
---|
213 | }
|
---|
214 | $xoopsTpl->assign('xoops_meta_keywords', $keywords);
|
---|
215 | }
|
---|
216 | break;
|
---|
217 | default :
|
---|
218 | }
|
---|
219 |
|
---|
220 | $xoops_description = $xoopsTpl->get_template_vars('xoops_meta_description');
|
---|
221 | $wp_description = get_xpress_meta_name('description',$contents);
|
---|
222 | switch ($xpress_config->meta_description_type){
|
---|
223 | case 'xoops':
|
---|
224 | break;
|
---|
225 | case 'wordpress':
|
---|
226 | if (!empty($wp_description))
|
---|
227 | $xoopsTpl->assign('xoops_meta_description', $wp_description);
|
---|
228 | break;
|
---|
229 | case 'wordpress_xoops':
|
---|
230 | if (!empty($wp_description)){
|
---|
231 | if (!empty($xoops_description)){
|
---|
232 | $description = $wp_description . ' ' . $xoops_description;
|
---|
233 | } else {
|
---|
234 | $description = $wp_description;
|
---|
235 | }
|
---|
236 | $xoopsTpl->assign('xoops_meta_description', $description);
|
---|
237 | }
|
---|
238 | break;
|
---|
239 | default :
|
---|
240 | }
|
---|
241 |
|
---|
242 | $wp_robots = get_xpress_meta_name('robots',$contents);
|
---|
243 | switch ($xpress_config->meta_robot_type){
|
---|
244 | case 'xoops':
|
---|
245 | break;
|
---|
246 | case 'wordpress':
|
---|
247 | if (!empty($wp_robots))
|
---|
248 | $xoopsTpl->assign('xoops_meta_robots', $wp_robots);
|
---|
249 | break;
|
---|
250 | default :
|
---|
251 | }
|
---|
252 | if (empty($contents)){
|
---|
253 | $template_name = get_option('template');
|
---|
254 | $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>";
|
---|
255 | } else {
|
---|
256 | $xpress_data['body_contents'] = get_body($contents);
|
---|
257 | }
|
---|
258 | // used $GLOBALS. becose xpress_left_arrow_post_link() and xpress_right_arrow_post_link() is other loop in this position
|
---|
259 | $xpress_data['left_post_link'] = @$GLOBALS['left_arrow_post_link'];
|
---|
260 | $xpress_data['right_post_link'] = @$GLOBALS['right_arrow_post_link'];
|
---|
261 | $xpress_data['left_posts_link'] = str_replace('«','',xpress_left_arrow_posts_link('echo=0'));
|
---|
262 | $xpress_data['right_posts_link'] = str_replace('»','',xpress_right_arrow_posts_link('echo=0'));
|
---|
263 | $xpress_data['now_user_level'] = xpress_now_user_level('echo=0');
|
---|
264 |
|
---|
265 | //If notification_select.php is not executed in CMS other than XCL, the selector of in-line is not displayed.
|
---|
266 | if (is_object($xoopsModule) && $xoopsModule->getVar('hasnotification') == 1 && is_object($xoopsUser)) {
|
---|
267 | require_once $modInfo->get_xoops_root_path() . '/include/notification_select.php';
|
---|
268 | }
|
---|
269 |
|
---|
270 | $xoopsTpl->assign('xpress', $xpress_data);
|
---|
271 | $templates_file = 'db:'.$mydirname. '_index.html';
|
---|
272 | $xoopsTpl->clear_cache($templates_file);
|
---|
273 | echo $xoopsTpl->fetch( $templates_file ) ;
|
---|
274 | include $modInfo->get_xoops_footer_path();
|
---|
275 | }
|
---|
276 |
|
---|
277 | ?> |
---|