XPressME Integration Kit

Trac

source: trunk/include/xpress_templates_make.php @ 124

Last change on this file since 124 was 124, checked in by toemon, 15 years ago

サイドバーブロック実装 #36 bump Ver0.10

File size: 3.6 KB
Line 
1<?php
2
3function xpress_templates_make($mid,$mydirname)
4{
5        $msgs = array();
6        // TEMPLATES
7        $tplfile_handler =& xoops_gethandler( 'tplfile' ) ;
8        $tpl_path = XOOPS_ROOT_PATH . '/modules/' . $mydirname . '/templates' ;
9        if( $handler = @opendir( $tpl_path . '/source/' ) ) {
10                while( ( $file = readdir( $handler ) ) !== false ) {
11                        if( substr( $file , 0 , 1 ) == '.' ) continue ;
12                        if(!is_template($file)) continue ;
13                        $file_path = $tpl_path . '/source/' . $file ;
14                        if( is_file( $file_path ) ) {
15                                $target_file_name = $mydirname . '_' . $file;
16                                $target_file_path = $tpl_path . '/'.$target_file_name;
17                                $rcd = @unlink($target_file_path);
18                                if ($mydirname != 'xpress') {           //old version file delete
19                                        $rcd = @unlink($tpl_path . '/xpress'.$file);
20                                }
21//                              $rcd = rename($file_path, $target_file_path);
22                                $rcd = copy($file_path, $target_file_path);
23                                if ($rcd){
24                                        $msgs[] = 'Template <b>'.htmlspecialchars($target_file_path).'</b> copy from ' . htmlspecialchars($file);
25                                } else {
26                                        $msgs[] = '<span style="color:#ff0000;">ERROR: Could not copy template <b>'.htmlspecialchars($target_file_name).'</b> from ' . htmlspecialchars($file). '(check templates directory permision (777))</span>';
27                                }                                       
28                                $tplfile =& $tplfile_handler->create() ;
29                                if ($rcd) {
30                                        $mtime = intval( @filemtime( $target_file_path ) ) ;
31                                        $tplfile->setVar( 'tpl_source' , file_get_contents( $target_file_path ) , true ) ;
32                                } else {
33                                        $mtime = intval( @filemtime( $file_path ) ) ;
34                                        $tplfile->setVar( 'tpl_source' , file_get_contents( $file_path ) , true ) ;
35                                }
36
37                                $tplfile->setVar( 'tpl_refid' , $mid ) ;
38                                $tplfile->setVar( 'tpl_tplset' , 'default' ) ;
39                                $tplfile->setVar( 'tpl_file' , $target_file_name ) ;
40                                $tplfile->setVar( 'tpl_desc' , '' , true ) ;
41                                $tplfile->setVar( 'tpl_module' , $mydirname ) ;
42                                $tplfile->setVar( 'tpl_lastmodified' , $mtime ) ;
43                                $tplfile->setVar( 'tpl_lastimported' , 0 ) ;
44                                $tplfile->setVar( 'tpl_type' , 'module' ) ;
45                                if( ! $tplfile_handler->insert( $tplfile ) ) {
46                                        $msgs[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>'.htmlspecialchars($target_file_name).'</b> to the database.</span><br />';
47                                } else {
48                                        $tplid = $tplfile->getVar( 'tpl_id' ) ;
49                                        $msgs[] = 'Template <b>'.htmlspecialchars($target_file_name) .'</b> added to the database. (ID: <b>'.$tplid.'</b>)<br />';
50                                        // generate compiled file
51                                        include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php' ;
52                                        include_once XOOPS_ROOT_PATH.'/class/template.php' ;
53                                        if( ! xoops_template_touch( $tplid ) ) {
54                                                $msgs[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>'.htmlspecialchars($target_file_name).'</b>.</span><br />';
55                                        } else {
56                                                $msgs[] = 'Template <b>'.htmlspecialchars($target_file_name).'</b> compiled.</span><br />';
57                                        }
58                                }
59                        }
60                }
61                closedir( $handler ) ;
62        }
63        include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php' ;
64        include_once XOOPS_ROOT_PATH.'/class/template.php' ;
65        xoops_template_clear_module_cache( $mid ) ;
66
67        return $msgs;
68}
69
70
71function is_template($file_name){
72        if (empty($file_name)) return false;
73       
74        $temp_list = array(
75                'recent_comments_block.html',
76                'recent_posts_content_block.html',
77                'recent_posts_list_block.html',
78                'calender_block.html',
79                'popular_posts_block.html',
80                'archives_block.html',
81                'authors_block.html',
82                'page_block.html',
83                'search_block.html',
84                'tag_cloud_block.html',
85                'category_block.html',
86                'meta_block.html' ,
87                'sidebar_block.html' ,
88                'index.html',
89        );
90        foreach($temp_list as $ck_file){
91                if (strcmp($ck_file,$file_name) ==  0) return true;
92        }
93        return false;
94}
95
96
97?>
Note: See TracBrowser for help on using the repository browser.