XPressME Integration Kit

Trac

source: trunk/xpressme_integration_kit/include/xpress_render.php @ 431

Last change on this file since 431 was 431, checked in by toemon, 14 years ago

パターンマッチしない場合のトラップを設けていなかった所を修正

File size: 7.8 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        $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
43function 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)
51function 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
61function 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
72function 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.
92function get_body($contents)
93{
94        $xpess_config = new XPressME_Class();
95        $pattern = "<body[^>]*?>(.*)<\/body>";
96        $body = '';
97        if(preg_match("/".$pattern."/s",  $contents, $body_matches)){
98                $body = $body_matches[1];
99        }
100        if (!$xpess_config->is_theme_sidebar_disp){
101                $side_panel = get_sidebar_rander();
102                        $body = str_replace($side_panel,'',$body);
103        }
104        return $body;
105}
106
107//Making of module header
108function get_xpress_module_header($contents)
109{
110        global $xoopsTpl;
111        if( defined( 'XOOPS_CUBE_LEGACY' ) ) {
112                $preload_make_module_header = $xoopsTpl->get_template_vars('xoops_module_header');
113        } else {
114                $preload_make_module_header = '';
115        }
116       
117        if (! empty($preload_make_module_header)){
118        $preload_make_module_header = '<!-- preload added module header -->
119' . $preload_make_module_header . '
120';
121        }
122       
123        $wp_module_header = '<!-- wordpress  added module header -->
124' . get_mod_header($contents) . '
125<!-- end of wordpress  added module header -->';
126       
127        return $preload_make_module_header . $wp_module_header;
128}
129
130//PHP_SELF and GET are remake for the XOOPS event notification.
131function xpress_remake_global_for_permlink(){
132        global $wp_db,$wp_query;
133        $php_self = $_SERVER['PHP_SELF'];
134        $get = $_GET;
135
136        if (preg_match('/\/$/',$php_self) && !preg_match('/index.php/',$php_self)) {
137                $php_self = $php_self . 'index.php';
138                $_SERVER['PHP_SELF'] = $php_self;
139        }
140        if (empty($_GET)){
141                $query_vars = $wp_query->query_vars;
142                $post = $wp_query->post;
143                if ($wp_query->is_single) {
144                        $_GET = array('p'=>$post->ID);
145                } else if($wp_query->is_category){
146                        $_GET = array('cat'=>$query_vars['cat']);
147                } else if($wp_query->is_author){
148                        $_GET = array('author'=>$query_vars['author']);
149                }
150        }
151}
152
153//rendering for the module header and the body
154function xpress_render($contents){
155        global $xoops_config;
156        global $xoopsUser , $xoopsTpl,$xpress_config , $xoopsModule , $xoopsLogger, $xoopsConfig ; //for XOOPS
157       
158        require_once( ABSPATH .'/include/xpress_breadcrumbs.php' );
159       
160        xpress_remake_global_for_permlink();
161        $mydirname = basename(dirname(dirname(__FILE__)));
162        include $xoops_config->xoops_root_path ."/header.php";
163        $xoopsTpl->assign('xoops_module_header', get_xpress_module_header($contents));
164        $page_title = $GLOBALS["xoopsModule"]->getVar("name"). ' &raquo;'. get_xpress_title($contents);
165        $xoopsTpl->assign('xoops_pagetitle', $page_title);
166       
167        $xoops_keywords = $xoopsTpl->get_template_vars('xoops_meta_keywords');
168        $wp_keyword = get_xpress_meta_name('keywords',$contents);
169        switch ($xpress_config->meta_keyword_type){
170                case 'xoops':
171                        break;
172                case 'wordpress':
173                        if (!empty($wp_keyword))
174                                $xoopsTpl->assign('xoops_meta_keywords', $wp_keyword);
175                        break;
176                case 'wordpress_xoops':
177                        if (!empty($wp_keyword)){
178                                if (!empty($xoops_keywords)){
179                                        $keywords = $wp_keyword . ', ' . $xoops_keywords;
180                                } else {
181                                        $keywords = $wp_keyword;
182                                }
183                                $xoopsTpl->assign('xoops_meta_keywords', $keywords);
184                        }
185                        break;
186                default :
187        }
188
189        $xoops_description = $xoopsTpl->get_template_vars('xoops_meta_description');
190        $wp_description = get_xpress_meta_name('description',$contents);
191        switch ($xpress_config->meta_description_type){
192                case 'xoops':
193                        break;
194                case 'wordpress':
195                        if (!empty($wp_description))
196                                $xoopsTpl->assign('xoops_meta_description', $wp_description);
197                        break;
198                case 'wordpress_xoops':
199                        if (!empty($wp_description)){
200                                if (!empty($xoops_description)){
201                                        $description = $wp_description . ' ' . $xoops_description;
202                                } else {
203                                        $description = $wp_description;
204                                }
205                                $xoopsTpl->assign('xoops_meta_description', $description);
206                        }
207                        break;
208                default :
209        }
210
211        $wp_robots = get_xpress_meta_name('robots',$contents);
212        switch ($xpress_config->meta_robot_type){
213                case 'xoops':
214                        break;
215                case 'wordpress':
216                        if (!empty($wp_robots))
217                                $xoopsTpl->assign('xoops_meta_robots', $wp_robots);
218                        break;
219                default :
220        }
221       
222        $xpress_data['body_contents'] = get_body($contents);
223        // used $GLOBALS. becose xpress_left_arrow_post_link() and xpress_right_arrow_post_link() is other loop in this position
224        $xpress_data['left_post_link'] = @$GLOBALS['left_arrow_post_link'];
225        $xpress_data['right_post_link'] = @$GLOBALS['right_arrow_post_link'];
226        $xpress_data['left_posts_link'] =  str_replace('&laquo;','',xpress_left_arrow_posts_link('echo=0'));
227        $xpress_data['right_posts_link'] = str_replace('&raquo;','',xpress_right_arrow_posts_link('echo=0'));
228        $xpress_data['now_user_level'] = xpress_now_user_level('echo=0');
229
230        //If notification_select.php is not executed in CMS other than XCL, the selector of in-line is not displayed.
231        if (is_object($xoopsModule) && $xoopsModule->getVar('hasnotification') == 1 && is_object($xoopsUser)) {
232                require_once $xoops_config->xoops_root_path . '/include/notification_select.php';
233        }
234       
235        $xoopsTpl->assign('xpress', $xpress_data);
236        $templates_file = 'db:'.$mydirname. '_index.html';
237        echo $xoopsTpl->fetch( $templates_file ) ;
238        include $xoops_config->xoops_root_path . '/footer.php';
239}
240
241?>
Note: See TracBrowser for help on using the repository browser.