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