XPressME Integration Kit

Trac

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

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

ページソース内へのクレジット(コメント扱い)位置変更 Fixes #330

File size: 8.9 KB
RevLine 
[1]1<?php
2
3//< style >< script >< link > tag is pulled out from the header of html contents.
4function 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]45function 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)
53function 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
63function 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
74function 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
86        ob_start();
87                require($link);
88                $sidebar = ob_get_contents();
89        ob_end_clean();
90        return $sidebar;
91}
92
[1]93// < body > tag is pulled out from the header of html contents.
94function get_body($contents)
95{
[560]96        global $xpess_config;
97        if (!is_object($xpess_config)) $xpess_config = new XPressME_Class();
[1]98        $pattern = "<body[^>]*?>(.*)<\/body>";
[431]99        $body = '';
100        if(preg_match("/".$pattern."/s",  $contents, $body_matches)){
101                $body = $body_matches[1];
102        }
[560]103       
[561]104        if ($xpess_config->is_theme_sidebar_disp){
105                $xpress_class = 'xpress-body';
106        } else {
107                $xpress_class = 'xpress-body onecolumn';
108        }
109       
[560]110        $pattern = '<body\s*([^>]*)>';
[561]111        $body_class = 'class="' . $xpress_class . '"';
[560]112        if(preg_match("/".$pattern."/s",  $contents, $body_matches)){
113                $body_tag_option = $body_matches[1];
114
115                $pattern = 'class\s*=\s*[\'|"]([^\'|^"]*)[\'|"]';               
116                if(preg_match("/".$pattern."/",  $body_tag_option, $class_matches)){
117                        $class_value = $class_matches[1];
[561]118                        $reprace = $xpress_class . ' '. $class_value;
[560]119                        $body_class = preg_replace("/".$class_value."/",  $reprace, $body_tag_option);
120                } else {
[561]121                        $body_class = 'class="' . $xpress_class . '" ' . $body_tag_option;
[560]122                }
123        }
124
[26]125        if (!$xpess_config->is_theme_sidebar_disp){
126                $side_panel = get_sidebar_rander();
127                        $body = str_replace($side_panel,'',$body);
128        }
[560]129        $body = "\n<div " . $body_class . "> <!-- Substitution of wordpress <body > -->\n" . $body . "\n</div> <!-- Substitution of wordpress </body > -->\n";
[1]130        return $body;
131}
132
133//Making of module header
134function get_xpress_module_header($contents)
135{
136        global $xoopsTpl;
137        if( defined( 'XOOPS_CUBE_LEGACY' ) ) {
138                $preload_make_module_header = $xoopsTpl->get_template_vars('xoops_module_header');
139        } else {
140                $preload_make_module_header = '';
141        }
142       
143        if (! empty($preload_make_module_header)){
144        $preload_make_module_header = '<!-- preload added module header -->
145' . $preload_make_module_header . '
146';
147        }
148       
149        $wp_module_header = '<!-- wordpress  added module header -->
150' . get_mod_header($contents) . '
151<!-- end of wordpress  added module header -->';
[576]152        $wp_module_header .= "\n<!-- credit " . xpress_credit('echo=0&no_link=1') . " -->\n";
153
[1]154        return $preload_make_module_header . $wp_module_header;
155}
156
[229]157//PHP_SELF and GET are remake for the XOOPS event notification.
158function xpress_remake_global_for_permlink(){
159        global $wp_db,$wp_query;
160        $php_self = $_SERVER['PHP_SELF'];
161        $get = $_GET;
162
163        if (preg_match('/\/$/',$php_self) && !preg_match('/index.php/',$php_self)) {
164                $php_self = $php_self . 'index.php';
165                $_SERVER['PHP_SELF'] = $php_self;
166        }
167        if (empty($_GET)){
168                $query_vars = $wp_query->query_vars;
169                $post = $wp_query->post;
170                if ($wp_query->is_single) {
171                        $_GET = array('p'=>$post->ID);
172                } else if($wp_query->is_category){
173                        $_GET = array('cat'=>$query_vars['cat']);
174                } else if($wp_query->is_author){
175                        $_GET = array('author'=>$query_vars['author']);
176                }
177        }
178}
179
[1]180//rendering for the module header and the body
181function xpress_render($contents){
[346]182        global $xoops_config;
183        global $xoopsUser , $xoopsTpl,$xpress_config , $xoopsModule , $xoopsLogger, $xoopsConfig ; //for XOOPS
[422]184       
185        require_once( ABSPATH .'/include/xpress_breadcrumbs.php' );
[432]186        $xoops_breadcrumbs = get_breadcrumbs();
187
[229]188        xpress_remake_global_for_permlink();
[109]189        $mydirname = basename(dirname(dirname(__FILE__)));
[96]190        include $xoops_config->xoops_root_path ."/header.php";
[432]191        $xoopsTpl->assign('xoops_breadcrumbs', $xoops_breadcrumbs);
[1]192        $xoopsTpl->assign('xoops_module_header', get_xpress_module_header($contents));
[201]193        $page_title = $GLOBALS["xoopsModule"]->getVar("name"). ' &raquo;'. get_xpress_title($contents);
[1]194        $xoopsTpl->assign('xoops_pagetitle', $page_title);
[201]195       
196        $xoops_keywords = $xoopsTpl->get_template_vars('xoops_meta_keywords');
197        $wp_keyword = get_xpress_meta_name('keywords',$contents);
198        switch ($xpress_config->meta_keyword_type){
199                case 'xoops':
200                        break;
201                case 'wordpress':
202                        if (!empty($wp_keyword))
203                                $xoopsTpl->assign('xoops_meta_keywords', $wp_keyword);
204                        break;
205                case 'wordpress_xoops':
206                        if (!empty($wp_keyword)){
207                                if (!empty($xoops_keywords)){
208                                        $keywords = $wp_keyword . ', ' . $xoops_keywords;
209                                } else {
210                                        $keywords = $wp_keyword;
211                                }
212                                $xoopsTpl->assign('xoops_meta_keywords', $keywords);
213                        }
214                        break;
215                default :
216        }
217
218        $xoops_description = $xoopsTpl->get_template_vars('xoops_meta_description');
219        $wp_description = get_xpress_meta_name('description',$contents);
220        switch ($xpress_config->meta_description_type){
221                case 'xoops':
222                        break;
223                case 'wordpress':
224                        if (!empty($wp_description))
225                                $xoopsTpl->assign('xoops_meta_description', $wp_description);
226                        break;
227                case 'wordpress_xoops':
228                        if (!empty($wp_description)){
229                                if (!empty($xoops_description)){
230                                        $description = $wp_description . ' ' . $xoops_description;
231                                } else {
232                                        $description = $wp_description;
233                                }
234                                $xoopsTpl->assign('xoops_meta_description', $description);
235                        }
236                        break;
237                default :
238        }
[202]239
240        $wp_robots = get_xpress_meta_name('robots',$contents);
241        switch ($xpress_config->meta_robot_type){
242                case 'xoops':
243                        break;
244                case 'wordpress':
245                        if (!empty($wp_robots))
246                                $xoopsTpl->assign('xoops_meta_robots', $wp_robots);
247                        break;
248                default :
249        }
[201]250       
[164]251        $xpress_data['body_contents'] = get_body($contents);
252        // used $GLOBALS. becose xpress_left_arrow_post_link() and xpress_right_arrow_post_link() is other loop in this position
[431]253        $xpress_data['left_post_link'] = @$GLOBALS['left_arrow_post_link'];
254        $xpress_data['right_post_link'] = @$GLOBALS['right_arrow_post_link'];
[272]255        $xpress_data['left_posts_link'] =  str_replace('&laquo;','',xpress_left_arrow_posts_link('echo=0'));
256        $xpress_data['right_posts_link'] = str_replace('&raquo;','',xpress_right_arrow_posts_link('echo=0'));
257        $xpress_data['now_user_level'] = xpress_now_user_level('echo=0');
[164]258
[343]259        //If notification_select.php is not executed in CMS other than XCL, the selector of in-line is not displayed.
260        if (is_object($xoopsModule) && $xoopsModule->getVar('hasnotification') == 1 && is_object($xoopsUser)) {
261                require_once $xoops_config->xoops_root_path . '/include/notification_select.php';
262        }
263       
[164]264        $xoopsTpl->assign('xpress', $xpress_data);
[109]265        $templates_file = 'db:'.$mydirname. '_index.html';
266        echo $xoopsTpl->fetch( $templates_file ) ;
[96]267        include $xoops_config->xoops_root_path . '/footer.php';
[1]268}
269
270?>
Note: See TracBrowser for help on using the repository browser.