XPressME Integration Kit

Trac


Ignore:
Timestamp:
Nov 27, 2009, 3:27:01 PM (14 years ago)
Author:
toemon
Message:

ブロックオプションでテンプレートの指定が行えるようにし、ブロック複製時別テンプレートが使えるようにする。 Fixes #247

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/xpressme_integration_kit/include/xpress_block_render.php

    r456 r463  
    5252                        } 
    5353                        return $block_id; 
     54        } 
     55 
     56        function get_block_mid($mydirname) 
     57        { 
     58                        $xoopsDB =& Database::getInstance(); 
     59                        $modules_tbl = $xoopsDB->prefix('modules');      
     60 
     61                        $sql = "SELECT mid FROM $modules_tbl WHERE dirname = '$mydirname'"; 
     62                        $result =  $xoopsDB->query($sql, 0, 0); 
     63                        if ($xoopsDB->getRowsNum($result)  > 0){ 
     64                                $row = $xoopsDB->fetchArray($result); 
     65                                $mid = $row['mid']; 
     66                        } 
     67                        return $mid; 
    5468        } 
    5569 
     
    190204                $option = explode('|' , $block['options']); 
    191205                 
    192                 if (isset($option[1])) 
     206                if (isset($option[1])) { 
    193207                        $templates_file = $option[1]; 
    194                 else 
     208                } else { 
    195209                        $templates_file = 'db:'.$mydirname. '_' . str_replace(".php", ".html", $block_function_name); 
     210                } 
     211                 
    196212                $tpl =& new XoopsTpl() ; 
     213                $tpl->template_dir = $xoops_config->module_path . '/templates'; 
     214                if (!$tpl->template_exists($templates_file)){ 
     215                        $src_file_path = $xoops_config->module_path . '/templates/' .$mydirname. '_' . str_replace(".php", ".html", $block_function_name); 
     216                        add_xpress_tpl($mydirname,$templates_file,$src_file_path); 
     217                } 
    197218                $tpl->assign( 'block' , $block ) ; 
    198219                $ret['content'] = $tpl->fetch( $templates_file ) ; 
    199220                return $ret ; 
     221        } 
     222         
     223        function add_xpress_tpl($mydirname,$templates='',$src_file_path){ 
     224                global $wpdb,$xoops_config , $xoops_db; 
     225                 
     226                $mid = get_block_mid($mydirname); 
     227 
     228                $temp_parm = explode(':' , $templates); 
     229                if (empty($temp_parm[1])) { 
     230                        $filename=$temp_parm[0]; 
     231                        $type = 'db'; 
     232                } else  { 
     233                        $filename=$temp_parm[1]; 
     234                        $type = $temp_parm[0]; 
     235                } 
     236                $temp_file_path = $xoops_config->module_path . '/templates/'. $filename; 
     237                $pattern = '^' . $mydirname . '_'; 
     238                if (preg_match('/' . $pattern . '/' , $filename, $match)){ // file prefix check 
     239                        if (!file_exists($temp_file_path)){             // Repetition check 
     240                                if (file_exists($src_file_path)){       // source file check 
     241                                        $rcd = copy($src_file_path, $temp_file_path); 
     242                                } 
     243                        } 
     244                } 
    200245        } 
    201246         
     
    250295        { 
    251296                global $xoops_db,$xoops_config; 
     297                 
    252298                $mid = get_xpress_modid(); 
    253299                $sql = "SELECT bid,options,func_file FROM " . get_xoops_prefix() . "newblocks WHERE mid = $mid AND visible = 1"; 
     
    294340                        return $xu_row['conf_value']; 
    295341                } 
    296         } 
    297          
     342        }        
    298343}        
    299344?> 
Note: See TracChangeset for help on using the changeset viewer.