function & xpress_XML_serialize(&$data, $level = 0, $prior_key = NULL){ if($level == 0){ ob_start(); echo '<?xml version="1.0" ?>',"\n"; } while(list($key, $value) = each($data)) if(!strpos($key, ' attr')) #if it's not an attribute #we don't treat attributes by themselves, so for an empty element # that has attributes you still need to set the element to NULL if(is_array($value) and array_key_exists(0, $value)){ xpress_XML_serialize($value, $level, $key); }else{ $tag = $prior_key ? $prior_key : $key; echo str_repeat("\t", $level),'<',$tag; if(array_key_exists("$key attr", $data)){ #if there's an attribute for this element while(list($attr_name, $attr_value) = each($data["$key attr"])) echo ' ',$attr_name,'="',htmlspecialchars($attr_value),'"'; reset($data["$key attr"]); } if(is_null($value)) echo " />\n"; elseif(!is_array($value)) echo '>',htmlspecialchars($value),"</$tag>\n"; else echo ">\n",xpress_XML_serialize($value, $level+1),str_repeat("\t", $level),"</$tag>\n"; } reset($data); if($level == 0){ $str = &ob_get_contents(); ob_end_clean(); return $str; } }
function xpress_block_header_cash_write($mydirname,$block_header) { $xml = xpress_XML_serialize($block_header); $xml_name = 'block_header.xml'; if (WPLANG == 'ja_EUC'){ $xml = str_replace('<?xml version="1.0" ?>', '<?xml version="1.0" encoding="EUC-JP" ?>' , $xml); } if(cache_is_writable()) xpress_cache_write($mydirname,$xml_name,$xml); }
function xpress_block_cache_refresh($mydirname) { global $xoops_db; $mid = get_xpress_modid(); // It is a block that needs cache arranged outside the module. // Only the block arranged outside the module is detected here. $newblocks = get_xoops_prefix() . "newblocks"; $block_module_link = get_xoops_prefix() . "block_module_link"; $sql = "SELECT * FROM {$newblocks} LEFT JOIN {$block_module_link} ON {$newblocks}.bid = {$block_module_link}.block_id "; $sql .= "WHERE {$newblocks}.mid = {$mid} AND {$newblocks}.visible = 1 AND {$block_module_link}.module_id != {$mid} "; $sql .= "GROUP BY {$newblocks}.bid"; $blocks = $xoops_db->get_results($sql); require_once get_xpress_dir_path() . '/include/xpress_block_render.php'; foreach ($blocks as $block) { $func_file = $block->func_file; $call_theme_function_name = str_replace(".php", "", $func_file); $inc_theme_file_name = str_replace(".php", "", $func_file) . '_theme.php'; $cache_title = str_replace(".php", "", $func_file); $blockID = $block->bid; $options = explode("|", $block->options); $block_theme_file = get_block_file_path($mydirname, $inc_theme_file_name); require_once $block_theme_file['file_path']; $render = $call_theme_function_name($options); //The block name and the called function name should be assumed to be the same name. $render_array['block'] = $render; $render_array['block']['options'] = $block->options; if (!empty($block_theme_file['error'])) { $render_array['block']['err_message'] = $block_theme_file['error']; } if (cache_is_writable()) { if (xpress_block_cache_found($mydirname, $cache_title . $blockID)) { $render_serialize = xpress_XML_serialize($render_array); $render_md5 = md5($render_serialize); $cache_serialize = xpress_cache_read($mydirname, $cache_title . $blockID . '.xml'); $cache_md5 = md5($cache_serialize); if ($render_md5 != $cache_md5) { xpress_block_cache_write($mydirname, $cache_title . $blockID, $render_array); } } else { xpress_block_cache_write($mydirname, $cache_title . $blockID, $render_array); } } } }