[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 | {
|
---|
[502] | 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 | // The character-code not treatable exists when 'XML_unserialize' of PHP5 processes EUC-JP.
|
---|
| 30 | // And, the result is returned by character-code UTF-8.
|
---|
| 31 | // Measures
|
---|
| 32 | // After the character-code is converted into UTF-8, XML_unserialize will be processed.
|
---|
| 33 | if ( strstr($xml_data, '<?xml version="1.0" encoding="EUC-JP" ?>') !== false
|
---|
| 34 | && version_compare(PHP_VERSION, '5.0.0', '>') )
|
---|
| 35 | {
|
---|
| 36 | $xml_data = str_replace('<?xml version="1.0" encoding="EUC-JP" ?>', '<?xml version="1.0" encoding="UTF-8" ?>', $xml_data);
|
---|
[836] | 37 | $ans = mb_convert_variables('UTF-8' , 'EUC-JP', $xml_data); //EUC-JP to UTF-8
|
---|
[364] | 38 | $ret = @xpress_XML_unserialize($xml_data);
|
---|
[836] | 39 | $ans = mb_convert_variables('EUC-JP' , 'UTF-8', $ret); //UTF-8 to EUC-JP
|
---|
[502] | 40 | } else {
|
---|
| 41 | $ret = xpress_XML_unserialize($xml_data);
|
---|
| 42 | }
|
---|
| 43 | return $ret;
|
---|
[44] | 44 | }
|
---|
| 45 |
|
---|
| 46 | function get_block_id($mydirname,$func_file,$options)
|
---|
| 47 | {
|
---|
| 48 | $options_string = '';
|
---|
[708] | 49 | $mid = get_block_mid($mydirname);
|
---|
[44] | 50 | foreach ($options as $val){
|
---|
| 51 | if (!empty($options_string)) $options_string .='|';
|
---|
| 52 | $options_string .= $val;
|
---|
| 53 | }
|
---|
[835] | 54 | $xoopsDB =& XoopsDatabaseFactory::getDatabaseConnection();
|
---|
[44] | 55 | $block_tbl = $xoopsDB->prefix('newblocks');
|
---|
| 56 | $module_dir = XOOPS_ROOT_PATH . '/modules/' . $mydirname;
|
---|
| 57 |
|
---|
[708] | 58 | $sql = "SELECT bid FROM $block_tbl WHERE (mid = $mid) AND (func_file LIKE '$func_file') AND (options LIKE '$options_string')";
|
---|
[44] | 59 | $result = $xoopsDB->query($sql, 0, 0);
|
---|
| 60 | if ($xoopsDB->getRowsNum($result) > 0){
|
---|
| 61 | $row = $xoopsDB->fetchArray($result);
|
---|
| 62 | $block_id = $row['bid'];
|
---|
| 63 | }
|
---|
| 64 | return $block_id;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
[463] | 67 | function get_block_mid($mydirname)
|
---|
| 68 | {
|
---|
[835] | 69 | $xoopsDB =& XoopsDatabaseFactory::getDatabaseConnection();
|
---|
[719] | 70 | $modules_tbl = $xoopsDB->prefix('modules');
|
---|
[463] | 71 |
|
---|
| 72 | $sql = "SELECT mid FROM $modules_tbl WHERE dirname = '$mydirname'";
|
---|
| 73 | $result = $xoopsDB->query($sql, 0, 0);
|
---|
| 74 | if ($xoopsDB->getRowsNum($result) > 0){
|
---|
| 75 | $row = $xoopsDB->fetchArray($result);
|
---|
| 76 | $mid = $row['mid'];
|
---|
| 77 | }
|
---|
| 78 | return $mid;
|
---|
| 79 | }
|
---|
| 80 |
|
---|
[44] | 81 | function get_xpress_theme_name($mydirname)
|
---|
| 82 | {
|
---|
[46] | 83 | global $wpdb;
|
---|
| 84 |
|
---|
| 85 | if (is_null($wpdb)){
|
---|
[835] | 86 | $xoopsDB =& XoopsDatabaseFactory::getDatabaseConnection();
|
---|
[583] | 87 | $wp_prefix = preg_replace('/wordpress/','wp',$mydirname);
|
---|
[44] | 88 |
|
---|
[719] | 89 | $module_tbl = $xoopsDB->prefix($wp_prefix).'_options';
|
---|
| 90 | $theme_name = '';
|
---|
[44] | 91 |
|
---|
[46] | 92 | $sql = "SELECT option_value FROM $module_tbl WHERE option_name LIKE 'template'";
|
---|
| 93 | $result = $xoopsDB->query($sql, 0, 0);
|
---|
| 94 | if ($xoopsDB->getRowsNum($result) > 0){
|
---|
| 95 | $row = $xoopsDB->fetchArray($result);
|
---|
| 96 | $theme_name = $row['option_value'];
|
---|
| 97 | }
|
---|
| 98 | } else {
|
---|
| 99 | $theme_name = get_option('template');
|
---|
[44] | 100 | }
|
---|
| 101 | return $theme_name;
|
---|
| 102 | }
|
---|
| 103 |
|
---|
[573] | 104 | function xpress_block_header_set($mydirname = '')
|
---|
[44] | 105 | {
|
---|
[573] | 106 | require_once( dirname( __FILE__ ).'/xpress_block_header.php' );
|
---|
| 107 | $xml = xpress_block_header_cache_read($mydirname);
|
---|
| 108 | $block_header = $xml['block_header'];
|
---|
| 109 | if (!empty($block_header)){
|
---|
| 110 | $tplVars =& $GLOBALS['xoopsTpl']->get_template_vars();
|
---|
[44] | 111 | if(array_key_exists('xoops_block_header', $tplVars)) {
|
---|
[573] | 112 | if (!strstr($tplVars['xoops_block_header'],$block_header)) {
|
---|
| 113 | $GLOBALS['xoopsTpl']->assign('xoops_block_header',$tplVars['xoops_block_header'].$block_header);
|
---|
[44] | 114 | }
|
---|
| 115 | } else {
|
---|
[573] | 116 | $GLOBALS['xoopsTpl']->assign('xoops_block_header',$block_header);
|
---|
[44] | 117 | }
|
---|
[573] | 118 | }
|
---|
[44] | 119 | }
|
---|
| 120 |
|
---|
| 121 |
|
---|
[96] | 122 | function xpress_block_cache_found($mydirname,$block_name)
|
---|
| 123 | {
|
---|
| 124 | global $xoops_config;
|
---|
[657] | 125 |
|
---|
| 126 | $cache_dir = $xoops_config->xoops_cache_path . '/';
|
---|
[96] | 127 | $xml_name = $block_name . '.xml';
|
---|
| 128 |
|
---|
| 129 | $filename = $cache_dir .$mydirname . '_' . $xml_name;
|
---|
| 130 | $cache_time = 0;
|
---|
| 131 | // if (file_exists($filename) && ((time() - filemtime($filename)) < $cache_time)) {
|
---|
| 132 | if (file_exists($filename)) {
|
---|
| 133 | return true;
|
---|
| 134 | } else {
|
---|
| 135 | return false;
|
---|
| 136 | }
|
---|
| 137 | }
|
---|
| 138 |
|
---|
[44] | 139 | function xpress_block_render($mydirname,$block_function_name,$options)
|
---|
| 140 | {
|
---|
[719] | 141 | global $wpdb,$xoops_config,$xoopsUserIsAdmin;
|
---|
[44] | 142 | $func_file = $block_function_name;
|
---|
| 143 | $call_theme_function_name = str_replace(".php", "", $block_function_name);
|
---|
| 144 | $inc_theme_file_name = $call_theme_function_name . '_theme.php';
|
---|
| 145 | $cache_title = str_replace(".php", "", $block_function_name);
|
---|
[89] | 146 | $blockID =get_block_id($mydirname,$func_file,$options);
|
---|
| 147 |
|
---|
[483] | 148 | $this_block_url = '/' . $mydirname . '/';
|
---|
[96] | 149 | $call_url = $_SERVER['REQUEST_URI'];
|
---|
[719] | 150 | $block['err_message'] = '';
|
---|
| 151 |
|
---|
[506] | 152 | if (strstr($call_url , $this_block_url) !== false && strstr($call_url , $this_block_url . 'admin/') === false){
|
---|
[44] | 153 | $block_theme_file = get_block_file_path($mydirname,$inc_theme_file_name);
|
---|
[448] | 154 | require_once $block_theme_file['file_path'];
|
---|
[44] | 155 | $block = $call_theme_function_name($options); //The block name and the called function name should be assumed to be the same name.
|
---|
[448] | 156 | if (!empty($block_theme_file['error']))
|
---|
[719] | 157 | $block['err_message'] .= $block_theme_file['error'];
|
---|
[44] | 158 | } else {
|
---|
[719] | 159 | if (xpress_block_cache_found($mydirname,$cache_title. $blockID)){
|
---|
| 160 | $xml = xpress_block_cache_read($mydirname,$cache_title. $blockID);
|
---|
| 161 | $block = $xml['block'];
|
---|
[96] | 162 | } else {
|
---|
[719] | 163 | $block['err_message'] .= sprintf(_MB_XP2_BLOCK_CACHE_ERR, '<a href="' . XOOPS_URL . '/modules/' . $mydirname . '">' . $mydirname .'</a>');
|
---|
[96] | 164 | }
|
---|
[44] | 165 | }
|
---|
[719] | 166 |
|
---|
| 167 | if(!cache_is_writable()){
|
---|
| 168 | $block['err_message'] ='<span style="color:#ff0000">';
|
---|
| 169 | $block['err_message'] .= _MB_XP2_CACHE_NOT_WRITABLE ;
|
---|
| 170 | if($xoopsUserIsAdmin){
|
---|
| 171 | $block['err_message'] .= " ($cache_dir)";
|
---|
| 172 | $block['err_message'] .= '</span>';
|
---|
| 173 | }
|
---|
| 174 | }
|
---|
[691] | 175 | xpress_block_header_set($mydirname);
|
---|
[656] | 176 | $block['request_uri'] = $_SERVER['REQUEST_URI'];
|
---|
[690] | 177 | $temp_option = @explode(':' , $options[1]);
|
---|
[455] | 178 |
|
---|
[480] | 179 | if (isset($temp_option[1])) {
|
---|
[497] | 180 | $templates_file = $options[1];
|
---|
[463] | 181 | } else {
|
---|
[455] | 182 | $templates_file = 'db:'.$mydirname. '_' . str_replace(".php", ".html", $block_function_name);
|
---|
[463] | 183 | }
|
---|
| 184 |
|
---|
[802] | 185 | if (defined('ICMS_ROOT_PATH')) {
|
---|
| 186 | include_once ICMS_ROOT_PATH.'/class/template.php';
|
---|
| 187 | }
|
---|
| 188 |
|
---|
[836] | 189 | if ( version_compare(PHP_VERSION, '5.0.0', '>')) {
|
---|
| 190 | eval('$tpl = new XoopsTpl();');
|
---|
| 191 | }else {
|
---|
| 192 | eval('$tpl = & new XoopsTpl();');
|
---|
| 193 | }
|
---|
| 194 | $tpl->template_dir = $xoops_config->module_path . '/templates';
|
---|
[463] | 195 | if (!$tpl->template_exists($templates_file)){
|
---|
| 196 | $src_file_path = $xoops_config->module_path . '/templates/' .$mydirname. '_' . str_replace(".php", ".html", $block_function_name);
|
---|
[472] | 197 | $templates_file = add_xpress_tpl($mydirname,$templates_file,$src_file_path);
|
---|
[463] | 198 | }
|
---|
[89] | 199 | $tpl->assign( 'block' , $block ) ;
|
---|
| 200 | $ret['content'] = $tpl->fetch( $templates_file ) ;
|
---|
[656] | 201 | if(preg_match('/\S/',$ret['content'])){
|
---|
| 202 | return $ret ;
|
---|
| 203 | }else {
|
---|
| 204 | return null;
|
---|
| 205 | }
|
---|
[44] | 206 | }
|
---|
| 207 |
|
---|
[463] | 208 | function add_xpress_tpl($mydirname,$templates='',$src_file_path){
|
---|
| 209 | global $wpdb,$xoops_config , $xoops_db;
|
---|
| 210 |
|
---|
| 211 | $mid = get_block_mid($mydirname);
|
---|
| 212 |
|
---|
| 213 | $temp_parm = explode(':' , $templates);
|
---|
| 214 | if (empty($temp_parm[1])) {
|
---|
| 215 | $filename=$temp_parm[0];
|
---|
| 216 | $type = 'db';
|
---|
| 217 | } else {
|
---|
| 218 | $filename=$temp_parm[1];
|
---|
| 219 | $type = $temp_parm[0];
|
---|
| 220 | }
|
---|
| 221 | $temp_file_path = $xoops_config->module_path . '/templates/'. $filename;
|
---|
| 222 | $pattern = '^' . $mydirname . '_';
|
---|
| 223 | if (preg_match('/' . $pattern . '/' , $filename, $match)){ // file prefix check
|
---|
| 224 | if (!file_exists($temp_file_path)){ // Repetition check
|
---|
| 225 | if (file_exists($src_file_path)){ // source file check
|
---|
| 226 | $rcd = copy($src_file_path, $temp_file_path);
|
---|
| 227 | }
|
---|
| 228 | }
|
---|
[472] | 229 | return 'file:' . $filename;
|
---|
[463] | 230 | }
|
---|
[472] | 231 | return $templates;
|
---|
[463] | 232 | }
|
---|
| 233 |
|
---|
[172] | 234 | function xpress_block_cache_refresh($mydirname)
|
---|
[135] | 235 | {
|
---|
| 236 | global $xoops_db;
|
---|
| 237 | $mid = get_xpress_modid();
|
---|
[394] | 238 |
|
---|
| 239 | // It is a block that needs cache arranged outside the module.
|
---|
| 240 | // Only the block arranged outside the module is detected here.
|
---|
| 241 | $newblocks = get_xoops_prefix() . "newblocks";
|
---|
| 242 | $block_module_link = get_xoops_prefix(). "block_module_link";
|
---|
| 243 | $sql = "SELECT * FROM $newblocks LEFT JOIN $block_module_link ON {$newblocks}.bid = {$block_module_link}.block_id ";
|
---|
| 244 | $sql .= "WHERE {$newblocks}.mid = $mid AND {$newblocks}.visible = 1 AND {$block_module_link}.module_id != $mid ";
|
---|
| 245 | $sql .= "GROUP BY {$newblocks}.bid";
|
---|
| 246 |
|
---|
[135] | 247 | $blocks = $xoops_db->get_results($sql);
|
---|
| 248 | require_once get_xpress_dir_path() . '/include/xpress_block_render.php';
|
---|
| 249 |
|
---|
| 250 | foreach($blocks as $block){
|
---|
| 251 | $func_file = $block->func_file;
|
---|
| 252 | $call_theme_function_name = str_replace(".php", "", $func_file);
|
---|
| 253 | $inc_theme_file_name = str_replace(".php", "", $func_file) . '_theme.php';
|
---|
| 254 | $cache_title = str_replace(".php", "", $func_file);
|
---|
| 255 | $blockID = $block->bid;
|
---|
| 256 | $options = explode("|", $block->options);
|
---|
| 257 |
|
---|
| 258 | $block_theme_file = get_block_file_path($mydirname,$inc_theme_file_name);
|
---|
[448] | 259 | require_once $block_theme_file['file_path'];
|
---|
[135] | 260 | $render = $call_theme_function_name($options); //The block name and the called function name should be assumed to be the same name.
|
---|
| 261 | $render_array['block'] = $render;
|
---|
| 262 | $render_array['block']['options'] = $block->options;
|
---|
[448] | 263 | if (!empty($block_theme_file['error']))
|
---|
| 264 | $render_array['block']['err_message'] = $block_theme_file['error'];
|
---|
[719] | 265 | if(cache_is_writable()){
|
---|
| 266 | if (xpress_block_cache_found($mydirname,$cache_title. $blockID)){
|
---|
| 267 | $render_serialize = xpress_XML_serialize($render_array);
|
---|
| 268 | $render_md5 = md5($render_serialize);
|
---|
[135] | 269 |
|
---|
[719] | 270 | $cache_serialize = xpress_cache_read($mydirname,$cache_title. $blockID.'.xml');
|
---|
| 271 | $cache_md5 = md5($cache_serialize);
|
---|
| 272 |
|
---|
| 273 | if ($render_md5 != $cache_md5){
|
---|
| 274 | xpress_block_cache_write($mydirname,$cache_title. $blockID, $render_array);
|
---|
| 275 | }
|
---|
| 276 | } else {
|
---|
[135] | 277 | xpress_block_cache_write($mydirname,$cache_title. $blockID, $render_array);
|
---|
| 278 | }
|
---|
| 279 | }
|
---|
| 280 | }
|
---|
| 281 | }
|
---|
| 282 |
|
---|
[172] | 283 | function xpress_unnecessary_block_cache_delete($mydirname)
|
---|
[135] | 284 | {
|
---|
| 285 | global $xoops_db,$xoops_config;
|
---|
[463] | 286 |
|
---|
[135] | 287 | $mid = get_xpress_modid();
|
---|
| 288 | $sql = "SELECT bid,options,func_file FROM " . get_xoops_prefix() . "newblocks WHERE mid = $mid AND visible = 1";
|
---|
| 289 | $blocks = $xoops_db->get_results($sql);
|
---|
| 290 | require_once get_xpress_dir_path() . '/include/xpress_block_render.php';
|
---|
| 291 |
|
---|
[588] | 292 | $pattern =$mydirname . '_block_header';
|
---|
[135] | 293 | foreach($blocks as $block){
|
---|
| 294 | $cache_file_name = $mydirname . '_'. str_replace(".php", "", $block->func_file) . $block->bid;
|
---|
| 295 | if (!empty($pattern)) $pattern .= '|';
|
---|
| 296 | $pattern .= $cache_file_name;
|
---|
| 297 | }
|
---|
| 298 | $pattern = '(' . $pattern . ')';
|
---|
| 299 |
|
---|
[657] | 300 | $cache_dir = $xoops_config->xoops_cache_path . '/';
|
---|
[135] | 301 | $cache_time = 0;
|
---|
| 302 | if ($dh = opendir($cache_dir)) {
|
---|
| 303 | while (($file = readdir($dh)) !== false) {
|
---|
[482] | 304 | if (preg_match('/^' . preg_quote($mydirname) . '_/', $file)) {
|
---|
[135] | 305 | if(! preg_match('/' . $pattern . '/', $file)) {
|
---|
| 306 | unlink($cache_dir.$file);
|
---|
| 307 | }
|
---|
| 308 | }
|
---|
| 309 | }
|
---|
| 310 | closedir($dh);
|
---|
| 311 | }
|
---|
| 312 | }
|
---|
[387] | 313 |
|
---|
| 314 | function get_xpress_mod_config($mydirname,$conf_name=''){
|
---|
| 315 | $module_handler =& xoops_gethandler('module');
|
---|
| 316 | $xoopsModule =& $module_handler->getByDirname($mydirname);
|
---|
| 317 | $mid = $xoopsModule->getVar('mid');
|
---|
[835] | 318 | $xoopsDB =& XoopsDatabaseFactory::getDatabaseConnection();
|
---|
[387] | 319 | $db_config = $xoopsDB->prefix('config');
|
---|
| 320 |
|
---|
| 321 | $wu_sql = "SELECT conf_value FROM $db_config ";
|
---|
| 322 | $wu_sql .= "WHERE (conf_modid = $mid ) AND (conf_name LIKE '$conf_name')";
|
---|
| 323 | $wu_res = $xoopsDB->queryF($wu_sql, 0, 0);
|
---|
| 324 |
|
---|
| 325 | if ($wu_res === false){
|
---|
| 326 | return 0;
|
---|
| 327 | } else {
|
---|
| 328 | $xu_row = $xoopsDB->fetchArray($wu_res);
|
---|
| 329 | return $xu_row['conf_value'];
|
---|
| 330 | }
|
---|
[463] | 331 | }
|
---|
[172] | 332 | }
|
---|
[44] | 333 | ?> |
---|