XPressME Integration Kit

Trac

source: trunk/include/xpress_block_render.php @ 95

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

XOOPS mainfile.phpのdefine文を事前に読み取りwp-config.phpのDB接続関係を生成することにより、XOOPSシステムを必要なときだけ呼び出す仕組みを作る。
およびイベント通知関係の修正(まだゲストのアクセス権限がないと駄目)

File size: 4.7 KB
Line 
1<?php
2        require_once dirname( __FILE__ ) .'/xml.php' ;
3        require_once dirname( __FILE__ ) .'/xpress_cache.php' ;
4       
5        function xpress_block_cache_write($mydirname,$block_name,$block)
6        {
7                        $xml = xpress_XML_serialize($block);
8                        $xml_name = $block_name . '.xml';
9                        xpress_cache_write($mydirname,$xml_name,$xml);
10        }
11        function xpress_block_cache_read($mydirname,$block_name)
12        {
13                        $xml_name = $block_name . '.xml';
14                        $xml_data = xpress_cache_read($mydirname,$xml_name);
15                        return @xpress_XML_unserialize($xml_data);
16        }
17       
18        function get_block_id($mydirname,$func_file,$options)
19        {
20                $options_string = '';
21                foreach ($options as $val){
22                        if (!empty($options_string)) $options_string .='|';
23                        $options_string .= $val;
24                }
25                        $xoopsDB =& Database::getInstance();
26                        $block_tbl = $xoopsDB->prefix('newblocks');     
27                        $module_dir = XOOPS_ROOT_PATH . '/modules/' . $mydirname;
28
29                        $sql = "SELECT bid FROM $block_tbl WHERE (func_file LIKE '$func_file') AND (options LIKE '$options_string')";
30                        $result =  $xoopsDB->query($sql, 0, 0);
31                        if ($xoopsDB->getRowsNum($result)  > 0){
32                                $row = $xoopsDB->fetchArray($result);
33                                $block_id = $row['bid'];
34                        }
35                        return $block_id;
36        }
37
38        function get_xpress_theme_name($mydirname)
39        {
40                global $wpdb;
41               
42                if (is_null($wpdb)){
43                        $xoopsDB =& Database::getInstance();
44                        $wp_prefix = $mydirname;
45                        if ($wp_prefix == 'wordpress') $wp_prefix = 'wp';
46
47                        $module_tbl = $xoopsDB->prefix($wp_prefix).'_options'; 
48                        $theme_name = '';       
49
50                        $sql = "SELECT option_value FROM $module_tbl WHERE option_name LIKE 'template'";
51                        $result =  $xoopsDB->query($sql, 0, 0);
52                        if ($xoopsDB->getRowsNum($result)  > 0){
53                                $row = $xoopsDB->fetchArray($result);
54                                $theme_name = $row['option_value'];
55                        }
56                } else {
57                        $theme_name = get_option('template');
58                }
59                return $theme_name;
60        }
61
62        function get_block_stylesheet_url($mydirname)
63        {
64                global $xoops_config;
65                $mydirpath = $xoops_config->xoops_root_path . '/modules/' . $mydirname;
66                $select_theme = get_xpress_theme_name($mydirname);
67                $style_file = $mydirpath . '/wp-content/themes/' . $select_theme . '/blocks/style.css';
68                if (file_exists($style_file))
69                        return $xoops_config->xoops_url . '/modules/' .$mydirname . '/wp-content/themes/' . $select_theme . '/blocks/style.css';
70                else   
71                        return $xoops_config->xoops_url . '/modules/' .$mydirname . '/wp-content/themes/xpress_default/blocks/style.css';
72        }
73
74        function xpress_block_css_set($mydirname = '')
75        {
76                $style_url =  get_block_stylesheet_url($mydirname);
77                 
78                $tplVars =& $GLOBALS['xoopsTpl']->get_template_vars();
79                $csslink = "\n".'<link rel="stylesheet" type="text/css" media="screen" href="'. $style_url .'" />';
80                        if(array_key_exists('xoops_block_header', $tplVars)) {
81                                if (!strstr($tplVars['xoops_block_header'],$csslink)) {
82                                        $GLOBALS['xoopsTpl']->assign('xoops_block_header',$tplVars['xoops_block_header'].$csslink);
83                                }
84                        } else {
85                                $GLOBALS['xoopsTpl']->assign('xoops_block_header',$csslink);
86                        }
87        }
88       
89        function get_block_file_path($mydirname,$file_name)
90        {
91                global $xoops_config;
92                $mydirpath = $xoops_config->xoops_root_path . '/modules/' . $mydirname;
93                $select_theme = get_xpress_theme_name($mydirname);
94                $block_file = $mydirpath . '/wp-content/themes/' . $select_theme . '/blocks/' . $file_name;
95
96                if (!file_exists($block_file))
97                        $block_file =  $xoops_config->xoops_root_path . '/modules/' .$mydirname . '/wp-content/themes/xpress_default/blocks/' . $file_name;
98                return $block_file;
99        }
100       
101        function xpress_block_render($mydirname,$block_function_name,$options)
102        {
103                global $wpdb;
104                $func_file = $block_function_name;
105                $call_theme_function_name = str_replace(".php", "", $block_function_name);
106                $inc_theme_file_name = $call_theme_function_name . '_theme.php';
107                $cache_title = str_replace(".php", "", $block_function_name);
108                $blockID =get_block_id($mydirname,$func_file,$options);         
109
110                if (!is_null($wpdb)){
111                        xpress_block_css_set($mydirname);
112                       
113                        $block_theme_file = get_block_file_path($mydirname,$inc_theme_file_name);
114                        require_once $block_theme_file;
115                        $block = $call_theme_function_name($options);           //The block name and the called function name should be assumed to be the same name.
116
117// Not Cache Write Now.  Becose Cache Write On WordPress Event                 
118//                      xpress_block_cache_write($mydirname,$cache_title. $blockID, $block); 
119                } else {
120                        $xml = xpress_block_cache_read($mydirname,$cache_title. $blockID);
121                        $block = $xml['block'];
122                }
123
124                $templates_file = 'db:'.$mydirname. '_' . str_replace(".php", ".html", $block_function_name);
125                $tpl =& new XoopsTpl() ;
126                $tpl->assign( 'block' , $block ) ;
127                $ret['content'] = $tpl->fetch( $templates_file ) ;
128                return $ret ;
129        }
130       
131?>
Note: See TracBrowser for help on using the repository browser.