Exemple #1
0
 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);
             }
         }
     }
 }
function block_cache_refresh()
{
    global $xoops_db;
    $mid = get_xpress_modid();
    $sql = "SELECT bid,options,func_file FROM " . get_xoops_prefix() . "newblocks WHERE mid = {$mid}";
    $blocks = $xoops_db->get_results($sql);
    $mydirname = get_xpress_dir_name();
    require_once get_xpress_dir_path() . '/include/xpress_block_render.php';
    foreach ($blocks as $block) {
        $func_file = $block->func_file;
        // Avoid the failure of the operation when switch_to_blog() and other plugin code is called on the admin page.
        $excludes = 'global_recent_posts_list_block\\.php|enhanced_block\\.php|global_recent_comments_block\\.php|global_popular_posts_block\\.php';
        if (preg_match('/' . $excludes . '/', $func_file)) {
            continue;
        }
        $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'];
        $block_render = $call_theme_function_name($options);
        //The block name and the called function name should be assumed to be the same name.
        $xml['block'] = $block_render;
        $xml['block']['options'] = $block->options;
        xpress_block_cache_write($mydirname, $cache_title . $blockID, $xml);
    }
}