XPressME Integration Kit

Trac


Ignore:
Timestamp:
Dec 15, 2009, 4:52:57 PM (14 years ago)
Author:
toemon
Message:

開発ベースにVer2.2をマージ

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/XPressMU/xpressme_integration_kit/include/xpress_block_render.php

    r451 r488  
    2929                        $ret = @xpress_XML_unserialize($xml_data); 
    3030                        if (strstr($xml_data, '<?xml version="1.0" encoding="EUC-JP" ?>') !== false){ 
    31                                 $ans = mb_convert_variables('EUC-JP' , 'UTF-8', &$ret); 
     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                                } 
    3234                        } 
    3335                        return $ret; 
     
    5254                        } 
    5355                        return $block_id; 
     56        } 
     57 
     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; 
    5470        } 
    5571 
     
    160176        function xpress_block_render($mydirname,$block_function_name,$options) 
    161177        { 
    162                 global $wpdb; 
     178                global $wpdb,$xoops_config; 
    163179                $func_file = $block_function_name; 
    164180                $call_theme_function_name = str_replace(".php", "", $block_function_name); 
     
    167183                $blockID =get_block_id($mydirname,$func_file,$options);          
    168184 
    169                 $this_url = '/modules/'. $mydirname; 
     185                $this_block_url = '/' . $mydirname . '/'; 
    170186                $call_url = $_SERVER['REQUEST_URI']; 
    171187                 
    172188                xpress_block_css_set($mydirname); 
    173                 if (strstr($call_url,$this_url)){                        
     189                if (strstr($call_url , $this_block_url) !== false){ 
    174190                        $block_theme_file = get_block_file_path($mydirname,$inc_theme_file_name); 
    175191                        require_once $block_theme_file['file_path']; 
     
    185201                        } 
    186202                } 
    187  
    188                 $templates_file = 'db:'.$mydirname. '_' . str_replace(".php", ".html", $block_function_name); 
     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                 
    189211                $tpl =& new XoopsTpl() ; 
     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                } 
    190217                $tpl->assign( 'block' , $block ) ; 
    191218                $ret['content'] = $tpl->fetch( $templates_file ) ; 
    192219                return $ret ; 
     220        } 
     221         
     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; 
    193246        } 
    194247         
     
    243296        { 
    244297                global $xoops_db,$xoops_config; 
     298                 
    245299                $mid = get_xpress_modid(); 
    246300                $sql = "SELECT bid,options,func_file FROM " . get_xoops_prefix() . "newblocks WHERE mid = $mid AND visible = 1"; 
     
    260314        if ($dh = opendir($cache_dir)) { 
    261315            while (($file = readdir($dh)) !== false) { 
    262                 if (preg_match('/^' . preg_quote($mydirname) . '/', $file)) { 
     316                if (preg_match('/^' . preg_quote($mydirname) . '_/', $file)) { 
    263317                        if(! preg_match('/' . $pattern . '/', $file)) { 
    264318                        unlink($cache_dir.$file); 
     
    287341                        return $xu_row['conf_value']; 
    288342                } 
    289         } 
    290          
     343        }        
    291344}        
    292345?> 
Note: See TracChangeset for help on using the changeset viewer.