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