1 | <?php
|
---|
2 | if(!defined('XPRESS_BLOCK_RENDER_FUNCTION_READ')){
|
---|
3 | define('XPRESS_BLOCK_RENDER_FUNCTION_READ',1);
|
---|
4 | require_once dirname( __FILE__ ) .'/xml.php' ;
|
---|
5 | require_once dirname( __FILE__ ) .'/xpress_cache.php' ;
|
---|
6 | global $xoops_config;
|
---|
7 |
|
---|
8 | if (!is_object($xoops_config)){ // is call other modules
|
---|
9 | require_once dirname(dirname( __FILE__ )) .'/class/config_from_xoops.class.php' ;
|
---|
10 | $xoops_config = new ConfigFromXoops;
|
---|
11 | }
|
---|
12 |
|
---|
13 | function xpress_block_cache_write($mydirname,$block_name,$block)
|
---|
14 | {
|
---|
15 | $xml = xpress_XML_serialize($block);
|
---|
16 | $xml_name = $block_name . '.xml';
|
---|
17 | if (WPLANG == 'ja_EUC'){
|
---|
18 | $xml = str_replace('<?xml version="1.0" ?>', '<?xml version="1.0" encoding="EUC-JP" ?>' , $xml);
|
---|
19 | }
|
---|
20 | xpress_cache_write($mydirname,$xml_name,$xml);
|
---|
21 | }
|
---|
22 | function xpress_block_cache_read($mydirname,$block_name)
|
---|
23 | {
|
---|
24 | $xml_name = $block_name . '.xml';
|
---|
25 | $xml_data = xpress_cache_read($mydirname,$xml_name);
|
---|
26 |
|
---|
27 | $GLOBALS['DO_LIBXML_PATCH'] = get_xpress_mod_config($mydirname,'libxml_patch');
|
---|
28 |
|
---|
29 | $ret = @xpress_XML_unserialize($xml_data);
|
---|
30 | if (strstr($xml_data, '<?xml version="1.0" encoding="EUC-JP" ?>') !== false){
|
---|
31 | $ans = mb_convert_variables('EUC-JP' , 'UTF-8', &$ret);
|
---|
32 | }
|
---|
33 | return $ret;
|
---|
34 | }
|
---|
35 |
|
---|
36 | function get_block_id($mydirname,$func_file,$options)
|
---|
37 | {
|
---|
38 | $options_string = '';
|
---|
39 | foreach ($options as $val){
|
---|
40 | if (!empty($options_string)) $options_string .='|';
|
---|
41 | $options_string .= $val;
|
---|
42 | }
|
---|
43 | $xoopsDB =& Database::getInstance();
|
---|
44 | $block_tbl = $xoopsDB->prefix('newblocks');
|
---|
45 | $module_dir = XOOPS_ROOT_PATH . '/modules/' . $mydirname;
|
---|
46 |
|
---|
47 | $sql = "SELECT bid FROM $block_tbl WHERE (func_file LIKE '$func_file') AND (options LIKE '$options_string')";
|
---|
48 | $result = $xoopsDB->query($sql, 0, 0);
|
---|
49 | if ($xoopsDB->getRowsNum($result) > 0){
|
---|
50 | $row = $xoopsDB->fetchArray($result);
|
---|
51 | $block_id = $row['bid'];
|
---|
52 | }
|
---|
53 | return $block_id;
|
---|
54 | }
|
---|
55 |
|
---|
56 | function get_xpress_theme_name($mydirname)
|
---|
57 | {
|
---|
58 | global $wpdb;
|
---|
59 |
|
---|
60 | if (is_null($wpdb)){
|
---|
61 | $xoopsDB =& Database::getInstance();
|
---|
62 | $wp_prefix = $mydirname;
|
---|
63 | if ($wp_prefix == 'wordpress') $wp_prefix = 'wp';
|
---|
64 |
|
---|
65 | $module_tbl = $xoopsDB->prefix($wp_prefix).'_options';
|
---|
66 | $theme_name = '';
|
---|
67 |
|
---|
68 | $sql = "SELECT option_value FROM $module_tbl WHERE option_name LIKE 'template'";
|
---|
69 | $result = $xoopsDB->query($sql, 0, 0);
|
---|
70 | if ($xoopsDB->getRowsNum($result) > 0){
|
---|
71 | $row = $xoopsDB->fetchArray($result);
|
---|
72 | $theme_name = $row['option_value'];
|
---|
73 | }
|
---|
74 | } else {
|
---|
75 | $theme_name = get_option('template');
|
---|
76 | }
|
---|
77 | return $theme_name;
|
---|
78 | }
|
---|
79 |
|
---|
80 | function get_block_stylesheet_url($mydirname)
|
---|
81 | {
|
---|
82 | global $xoops_config;
|
---|
83 | $mydirpath = $xoops_config->xoops_root_path . '/modules/' . $mydirname;
|
---|
84 | $select_theme = get_xpress_theme_name($mydirname);
|
---|
85 | $style_file = $mydirpath . '/wp-content/themes/' . $select_theme . '/blocks/block_style.css';
|
---|
86 | if (file_exists($style_file))
|
---|
87 | return $xoops_config->xoops_url . '/modules/' .$mydirname . '/wp-content/themes/' . $select_theme . '/blocks/block_style.css';
|
---|
88 | else
|
---|
89 | return $xoops_config->xoops_url . '/modules/' .$mydirname . '/wp-content/themes/xpress_default/blocks/block_style.css';
|
---|
90 | }
|
---|
91 |
|
---|
92 | function get_stylesheet_url($mydirname)
|
---|
93 | {
|
---|
94 | global $xoops_config;
|
---|
95 | $mydirpath = $xoops_config->xoops_root_path . '/modules/' . $mydirname;
|
---|
96 | $select_theme = get_xpress_theme_name($mydirname);
|
---|
97 | $style_file = $mydirpath . '/wp-content/themes/' . $select_theme . '/style.css';
|
---|
98 | if (file_exists($style_file))
|
---|
99 | return $xoops_config->xoops_url . '/modules/' .$mydirname . '/wp-content/themes/' . $select_theme . '/style.css';
|
---|
100 | else
|
---|
101 | return $xoops_config->xoops_url . '/modules/' .$mydirname . '/wp-content/themes/xpress_default/style.css';
|
---|
102 | }
|
---|
103 |
|
---|
104 | function xpress_get_plugin_css($mydirname = '')
|
---|
105 | {
|
---|
106 | $this_url = '/modules/'. $mydirname;
|
---|
107 | $call_url = $_SERVER['REQUEST_URI'];
|
---|
108 | if (!strstr($call_url,$this_url)){
|
---|
109 | global $xoops_config;
|
---|
110 |
|
---|
111 | // Module Main CSS
|
---|
112 | $output = "\n".'<style type="text/css">@import url('.get_stylesheet_url($mydirname).');</style>';
|
---|
113 |
|
---|
114 | // hotDate
|
---|
115 | $output .= "\n".'<style type="text/css">@import url('.$xoops_config->module_url.'/wp-content/plugins/hotDates/hotDates.css);</style>';
|
---|
116 | return $output;
|
---|
117 | }
|
---|
118 | return '';
|
---|
119 | }
|
---|
120 |
|
---|
121 | function xpress_block_css_set($mydirname = '')
|
---|
122 | {
|
---|
123 | $style_url = get_block_stylesheet_url($mydirname);
|
---|
124 |
|
---|
125 | $tplVars =& $GLOBALS['xoopsTpl']->get_template_vars();
|
---|
126 | $csslink = "\n".'<link rel="stylesheet" type="text/css" media="screen" href="'. $style_url .'" />';
|
---|
127 | // Module Main CSS Plugin Css
|
---|
128 | $csslink .= xpress_get_plugin_css($mydirname);
|
---|
129 |
|
---|
130 | if(array_key_exists('xoops_block_header', $tplVars)) {
|
---|
131 | if (!strstr($tplVars['xoops_block_header'],$csslink)) {
|
---|
132 | $GLOBALS['xoopsTpl']->assign('xoops_block_header',$tplVars['xoops_block_header'].$csslink);
|
---|
133 | }
|
---|
134 | } else {
|
---|
135 | $GLOBALS['xoopsTpl']->assign('xoops_block_header',$csslink);
|
---|
136 | }
|
---|
137 | }
|
---|
138 |
|
---|
139 | function get_block_file_path($mydirname,$file_name)
|
---|
140 | {
|
---|
141 | global $xoops_config;
|
---|
142 | $mydirpath = $xoops_config->xoops_root_path . '/modules/' . $mydirname;
|
---|
143 | $select_theme = get_xpress_theme_name($mydirname);
|
---|
144 | $block_file = $mydirpath . '/wp-content/themes/' . $select_theme . '/blocks/' . $file_name;
|
---|
145 |
|
---|
146 | if (!file_exists($block_file))
|
---|
147 | $block_file = $xoops_config->xoops_root_path . '/modules/' .$mydirname . '/wp-content/themes/xpress_default/blocks/' . $file_name;
|
---|
148 | return $block_file;
|
---|
149 | }
|
---|
150 |
|
---|
151 | function xpress_block_cache_found($mydirname,$block_name)
|
---|
152 | {
|
---|
153 | global $xoops_config;
|
---|
154 | if(defined('XOOPS_ROOT_PATH')){
|
---|
155 | $cache_dir = XOOPS_ROOT_PATH . '/cache/';
|
---|
156 | } else {
|
---|
157 | $cache_dir = $xoops_config->xoops_root_path . '/cache/';
|
---|
158 | }
|
---|
159 | $xml_name = $block_name . '.xml';
|
---|
160 |
|
---|
161 | $filename = $cache_dir .$mydirname . '_' . $xml_name;
|
---|
162 | $cache_time = 0;
|
---|
163 | // if (file_exists($filename) && ((time() - filemtime($filename)) < $cache_time)) {
|
---|
164 | if (file_exists($filename)) {
|
---|
165 | return true;
|
---|
166 | } else {
|
---|
167 | return false;
|
---|
168 | }
|
---|
169 | }
|
---|
170 |
|
---|
171 | function xpress_block_render($mydirname,$block_function_name,$options)
|
---|
172 | {
|
---|
173 | global $wpdb;
|
---|
174 | $func_file = $block_function_name;
|
---|
175 | $call_theme_function_name = str_replace(".php", "", $block_function_name);
|
---|
176 | $inc_theme_file_name = $call_theme_function_name . '_theme.php';
|
---|
177 | $cache_title = str_replace(".php", "", $block_function_name);
|
---|
178 | $blockID =get_block_id($mydirname,$func_file,$options);
|
---|
179 |
|
---|
180 | $this_url = '/modules/'. $mydirname;
|
---|
181 | $call_url = $_SERVER['REQUEST_URI'];
|
---|
182 |
|
---|
183 | xpress_block_css_set($mydirname);
|
---|
184 | if (strstr($call_url,$this_url)){
|
---|
185 | $block_theme_file = get_block_file_path($mydirname,$inc_theme_file_name);
|
---|
186 | require_once $block_theme_file;
|
---|
187 | $block = $call_theme_function_name($options); //The block name and the called function name should be assumed to be the same name.
|
---|
188 | } else {
|
---|
189 | if (xpress_block_cache_found($mydirname,$cache_title. $blockID)){
|
---|
190 | $xml = xpress_block_cache_read($mydirname,$cache_title. $blockID);
|
---|
191 | $block = $xml['block'];
|
---|
192 | } else {
|
---|
193 | $block['err_message'] = sprintf(_MB_XP2_BLOCK_CACHE_ERR, '<a href="' . XOOPS_URL . '/modules/' . $mydirname . '">' . $mydirname .'</a>');
|
---|
194 | }
|
---|
195 | }
|
---|
196 |
|
---|
197 | $templates_file = 'db:'.$mydirname. '_' . str_replace(".php", ".html", $block_function_name);
|
---|
198 | $tpl =& new XoopsTpl() ;
|
---|
199 | $tpl->assign( 'block' , $block ) ;
|
---|
200 | $ret['content'] = $tpl->fetch( $templates_file ) ;
|
---|
201 | return $ret ;
|
---|
202 | }
|
---|
203 |
|
---|
204 | function xpress_block_cache_refresh($mydirname)
|
---|
205 | {
|
---|
206 | global $xoops_db;
|
---|
207 | $mid = get_xpress_modid();
|
---|
208 |
|
---|
209 | // It is a block that needs cache arranged outside the module.
|
---|
210 | // Only the block arranged outside the module is detected here.
|
---|
211 | $newblocks = get_xoops_prefix() . "newblocks";
|
---|
212 | $block_module_link = get_xoops_prefix(). "block_module_link";
|
---|
213 | $sql = "SELECT * FROM $newblocks LEFT JOIN $block_module_link ON {$newblocks}.bid = {$block_module_link}.block_id ";
|
---|
214 | $sql .= "WHERE {$newblocks}.mid = $mid AND {$newblocks}.visible = 1 AND {$block_module_link}.module_id != $mid ";
|
---|
215 | $sql .= "GROUP BY {$newblocks}.bid";
|
---|
216 |
|
---|
217 | $blocks = $xoops_db->get_results($sql);
|
---|
218 | require_once get_xpress_dir_path() . '/include/xpress_block_render.php';
|
---|
219 |
|
---|
220 | foreach($blocks as $block){
|
---|
221 | $func_file = $block->func_file;
|
---|
222 | $call_theme_function_name = str_replace(".php", "", $func_file);
|
---|
223 | $inc_theme_file_name = str_replace(".php", "", $func_file) . '_theme.php';
|
---|
224 | $cache_title = str_replace(".php", "", $func_file);
|
---|
225 | $blockID = $block->bid;
|
---|
226 | $options = explode("|", $block->options);
|
---|
227 |
|
---|
228 | $block_theme_file = get_block_file_path($mydirname,$inc_theme_file_name);
|
---|
229 | require_once $block_theme_file;
|
---|
230 | $render = $call_theme_function_name($options); //The block name and the called function name should be assumed to be the same name.
|
---|
231 | $render_array['block'] = $render;
|
---|
232 | $render_array['block']['options'] = $block->options;
|
---|
233 | if (xpress_block_cache_found($mydirname,$cache_title. $blockID)){
|
---|
234 | $render_serialize = xpress_XML_serialize($render_array);
|
---|
235 | $render_md5 = md5($render_serialize);
|
---|
236 |
|
---|
237 | $cache_serialize = xpress_cache_read($mydirname,$cache_title. $blockID.'.xml');
|
---|
238 | $cache_md5 = md5($cache_serialize);
|
---|
239 |
|
---|
240 | if ($render_md5 != $cache_md5){
|
---|
241 | xpress_block_cache_write($mydirname,$cache_title. $blockID, $render_array);
|
---|
242 | }
|
---|
243 | } else {
|
---|
244 | xpress_block_cache_write($mydirname,$cache_title. $blockID, $render_array);
|
---|
245 | }
|
---|
246 | }
|
---|
247 | }
|
---|
248 |
|
---|
249 | function xpress_unnecessary_block_cache_delete($mydirname)
|
---|
250 | {
|
---|
251 | global $xoops_db,$xoops_config;
|
---|
252 | $mid = get_xpress_modid();
|
---|
253 | $sql = "SELECT bid,options,func_file FROM " . get_xoops_prefix() . "newblocks WHERE mid = $mid AND visible = 1";
|
---|
254 | $blocks = $xoops_db->get_results($sql);
|
---|
255 | require_once get_xpress_dir_path() . '/include/xpress_block_render.php';
|
---|
256 |
|
---|
257 | $pattern ='';
|
---|
258 | foreach($blocks as $block){
|
---|
259 | $cache_file_name = $mydirname . '_'. str_replace(".php", "", $block->func_file) . $block->bid;
|
---|
260 | if (!empty($pattern)) $pattern .= '|';
|
---|
261 | $pattern .= $cache_file_name;
|
---|
262 | }
|
---|
263 | $pattern = '(' . $pattern . ')';
|
---|
264 |
|
---|
265 | $cache_dir = $xoops_config->xoops_root_path . '/cache/';
|
---|
266 | $cache_time = 0;
|
---|
267 | if ($dh = opendir($cache_dir)) {
|
---|
268 | while (($file = readdir($dh)) !== false) {
|
---|
269 | if (preg_match('/^' . preg_quote($mydirname) . '/', $file)) {
|
---|
270 | if(! preg_match('/' . $pattern . '/', $file)) {
|
---|
271 | unlink($cache_dir.$file);
|
---|
272 | }
|
---|
273 | }
|
---|
274 | }
|
---|
275 | closedir($dh);
|
---|
276 | }
|
---|
277 | }
|
---|
278 |
|
---|
279 | function get_xpress_mod_config($mydirname,$conf_name=''){
|
---|
280 | $module_handler =& xoops_gethandler('module');
|
---|
281 | $xoopsModule =& $module_handler->getByDirname($mydirname);
|
---|
282 | $mid = $xoopsModule->getVar('mid');
|
---|
283 | $xoopsDB =& Database::getInstance();
|
---|
284 | $db_config = $xoopsDB->prefix('config');
|
---|
285 |
|
---|
286 | $wu_sql = "SELECT conf_value FROM $db_config ";
|
---|
287 | $wu_sql .= "WHERE (conf_modid = $mid ) AND (conf_name LIKE '$conf_name')";
|
---|
288 | $wu_res = $xoopsDB->queryF($wu_sql, 0, 0);
|
---|
289 |
|
---|
290 | if ($wu_res === false){
|
---|
291 | return 0;
|
---|
292 | } else {
|
---|
293 | $xu_row = $xoopsDB->fetchArray($wu_res);
|
---|
294 | return $xu_row['conf_value'];
|
---|
295 | }
|
---|
296 | }
|
---|
297 |
|
---|
298 | }
|
---|
299 | ?> |
---|