XPressME Integration Kit

Trac

source: branches/Ver2.0/xpressme_integration_kit/include/xpress_render.php @ 278

Last change on this file since 278 was 278, checked in by toemon, 15 years ago

SQLデバッグONにしたときheaderを読み込まないバグ修正 fixes #149

File size: 7.2 KB
Line 
1<?php
2
3//< style >< script >< link > tag is pulled out from the header of html contents.
4function 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        preg_match("/".$pattern."/s",  $body_cut, $head_matches);
14        $head_str = $head_matches[1];
15       
16        $pattern = '<head[^>]*?>';
17        $head_str = preg_replace("/".$pattern."/s" , '' , $head_str);
18        $pattern = '<\/head>';
19        $head_str = preg_replace("/".$pattern."/s" , '' , $head_str);
20        $pattern = '<\s*html\s+xmlns[^>]*?>';
21        $head_str = preg_replace("/".$pattern."/s" , '' , $head_str);
22        $pattern = '<\s*head\s+profile[^>]*?>';
23        $head_str = preg_replace("/".$pattern."/s" , '' , $head_str);
24        $pattern = '<\s*meta\s+http-equiv[^>]*?>';
25        $head_str = preg_replace("/".$pattern."/s" , '' , $head_str);
26        $pattern = '<title[^>]*?>(.*)<\s*\/\s*title\s*>';
27        $head_str = preg_replace("/".$pattern."/s" , '' , $head_str);
28
29        $head_str = meta_name_cut('robots',$head_str);
30        $head_str = meta_name_cut('keywords',$head_str);
31        $head_str = meta_name_cut('description',$head_str);
32        $head_str = meta_name_cut('rating',$head_str);
33        $head_str = meta_name_cut('author',$head_str);
34        $head_str = meta_name_cut('copyright',$head_str);
35        $head_str = meta_name_cut('generator',$head_str);
36
37        $head_str = preg_replace("/^(\s)*(\r|\n|\r\n)/m", "", $head_str);       
38        return $head_str;
39}
40
41function meta_name_cut($name = '', $head_str)
42{
43        $pattern = '<\s*meta\s+name\s*=\s*["\']' . $name . '["\'][^>]*?>';
44        $head_str = preg_replace("/".$pattern."/i" , '' , $head_str);
45        return $head_str;
46}
47
48// for title reprace plugin (all in one seo pack)
49function get_xpress_title($contents)
50{
51        $pattern = '<title[^>]*?>(.*)<\s*\/\s*title\s*>';
52        preg_match("/".$pattern."/i",  $contents, $head_matches);
53        $title_str = $head_matches[1];
54        return $title_str;
55}
56
57function get_xpress_meta_name($name = '',$contents)
58{
59        $pattern = '<\s*meta\s+name\s*=\s*["\']' . $name . '["\']\s*content\s*=\s*[\'"](.*)[\'"]\s*\/\s*>';
60        preg_match("/".$pattern."/i",  $contents, $head_matches);
61        $meta = $head_matches[1];
62        return $meta;
63}
64
65// get sidebar rendaring
66function get_sidebar_rander($name = null)
67{
68        $templates = array();
69        if ( isset($name) )
70                $templates[] = "sidebar-{$name}.php";
71
72        $templates[] = "sidebar.php";
73
74        $link= locate_template($templates, false);
75        if ('' == $link)
76                $link =  get_theme_root() . '/default/sidebar.php';
77
78        ob_start();
79                require($link);
80                $sidebar = ob_get_contents();
81        ob_end_clean();
82        return $sidebar;
83}
84
85// < body > tag is pulled out from the header of html contents.
86function get_body($contents)
87{
88        $xpess_config = new XPressME_Class();
89        $pattern = "<body[^>]*?>(.*)<\/body>";
90        preg_match("/".$pattern."/s",  $contents, $body_matches);
91        $body = $body_matches[1];
92
93        if (!$xpess_config->is_theme_sidebar_disp){
94                $side_panel = get_sidebar_rander();
95                        $body = str_replace($side_panel,'',$body);
96        }
97        return $body;
98}
99
100//Making of module header
101function get_xpress_module_header($contents)
102{
103        global $xoopsTpl;
104        if( defined( 'XOOPS_CUBE_LEGACY' ) ) {
105                $preload_make_module_header = $xoopsTpl->get_template_vars('xoops_module_header');
106        } else {
107                $preload_make_module_header = '';
108        }
109       
110        if (! empty($preload_make_module_header)){
111        $preload_make_module_header = '<!-- preload added module header -->
112' . $preload_make_module_header . '
113';
114        }
115       
116        $wp_module_header = '<!-- wordpress  added module header -->
117' . get_mod_header($contents) . '
118<!-- end of wordpress  added module header -->';
119       
120        return $preload_make_module_header . $wp_module_header;
121}
122
123//PHP_SELF and GET are remake for the XOOPS event notification.
124function xpress_remake_global_for_permlink(){
125        global $wp_db,$wp_query;
126        $php_self = $_SERVER['PHP_SELF'];
127        $get = $_GET;
128
129        if (preg_match('/\/$/',$php_self) && !preg_match('/index.php/',$php_self)) {
130                $php_self = $php_self . 'index.php';
131                $_SERVER['PHP_SELF'] = $php_self;
132        }
133        if (empty($_GET)){
134                $query_vars = $wp_query->query_vars;
135                $post = $wp_query->post;
136                if ($wp_query->is_single) {
137                        $_GET = array('p'=>$post->ID);
138                } else if($wp_query->is_category){
139                        $_GET = array('cat'=>$query_vars['cat']);
140                } else if($wp_query->is_author){
141                        $_GET = array('author'=>$query_vars['author']);
142                }
143        }
144}
145
146//rendering for the module header and the body
147function xpress_render($contents){
148        global $xoops_config , $xoopsTpl,$xpress_config;
149        xpress_remake_global_for_permlink();
150        $mydirname = basename(dirname(dirname(__FILE__)));
151        include $xoops_config->xoops_root_path ."/header.php";
152        $xoopsTpl->assign('xoops_module_header', get_xpress_module_header($contents));
153        $page_title = $GLOBALS["xoopsModule"]->getVar("name"). ' &raquo;'. get_xpress_title($contents);
154        $xoopsTpl->assign('xoops_pagetitle', $page_title);
155       
156        $xoops_keywords = $xoopsTpl->get_template_vars('xoops_meta_keywords');
157        $wp_keyword = get_xpress_meta_name('keywords',$contents);
158        switch ($xpress_config->meta_keyword_type){
159                case 'xoops':
160                        break;
161                case 'wordpress':
162                        if (!empty($wp_keyword))
163                                $xoopsTpl->assign('xoops_meta_keywords', $wp_keyword);
164                        break;
165                case 'wordpress_xoops':
166                        if (!empty($wp_keyword)){
167                                if (!empty($xoops_keywords)){
168                                        $keywords = $wp_keyword . ', ' . $xoops_keywords;
169                                } else {
170                                        $keywords = $wp_keyword;
171                                }
172                                $xoopsTpl->assign('xoops_meta_keywords', $keywords);
173                        }
174                        break;
175                default :
176        }
177
178        $xoops_description = $xoopsTpl->get_template_vars('xoops_meta_description');
179        $wp_description = get_xpress_meta_name('description',$contents);
180        switch ($xpress_config->meta_description_type){
181                case 'xoops':
182                        break;
183                case 'wordpress':
184                        if (!empty($wp_description))
185                                $xoopsTpl->assign('xoops_meta_description', $wp_description);
186                        break;
187                case 'wordpress_xoops':
188                        if (!empty($wp_description)){
189                                if (!empty($xoops_description)){
190                                        $description = $wp_description . ' ' . $xoops_description;
191                                } else {
192                                        $description = $wp_description;
193                                }
194                                $xoopsTpl->assign('xoops_meta_description', $description);
195                        }
196                        break;
197                default :
198        }
199
200        $wp_robots = get_xpress_meta_name('robots',$contents);
201        switch ($xpress_config->meta_robot_type){
202                case 'xoops':
203                        break;
204                case 'wordpress':
205                        if (!empty($wp_robots))
206                                $xoopsTpl->assign('xoops_meta_robots', $wp_robots);
207                        break;
208                default :
209        }
210       
211        $xpress_data['body_contents'] = get_body($contents);
212        // used $GLOBALS. becose xpress_left_arrow_post_link() and xpress_right_arrow_post_link() is other loop in this position
213        $xpress_data['left_post_link'] = $GLOBALS['left_arrow_post_link'];
214        $xpress_data['right_post_link'] = $GLOBALS['right_arrow_post_link'];
215        $xpress_data['left_posts_link'] =  str_replace('&laquo;','',xpress_left_arrow_posts_link('echo=0'));
216        $xpress_data['right_posts_link'] = str_replace('&raquo;','',xpress_right_arrow_posts_link('echo=0'));
217        $xpress_data['now_user_level'] = xpress_now_user_level('echo=0');
218
219        $xoopsTpl->assign('xpress', $xpress_data);
220        $templates_file = 'db:'.$mydirname. '_index.html';
221        echo $xoopsTpl->fetch( $templates_file ) ;
222        require_once( ABSPATH .'/include/xpress_breadcrumbs.php' );
223        include $xoops_config->xoops_root_path . '/footer.php';
224}
225
226?>
Note: See TracBrowser for help on using the repository browser.