[102] | 1 | <?php
|
---|
| 2 |
|
---|
| 3 | function 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 |
|
---|
| 71 | function 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',
|
---|
[109] | 78 | 'calender_block.html',
|
---|
| 79 | 'popular_posts_block.html',
|
---|
[110] | 80 | 'archives_block.html',
|
---|
| 81 | 'authors_block.html',
|
---|
[118] | 82 | 'page_block.html',
|
---|
[119] | 83 | 'search_block.html',
|
---|
[122] | 84 | 'tag_cloud_block.html',
|
---|
| 85 | 'category_block.html',
|
---|
| 86 | 'meta_block.html' ,
|
---|
[124] | 87 | 'sidebar_block.html' ,
|
---|
[135] | 88 | 'widget_block.html' ,
|
---|
[137] | 89 | 'enhanced_block.html' ,
|
---|
[109] | 90 | 'index.html',
|
---|
[102] | 91 | );
|
---|
| 92 | foreach($temp_list as $ck_file){
|
---|
| 93 | if (strcmp($ck_file,$file_name) == 0) return true;
|
---|
| 94 | }
|
---|
| 95 | return false;
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 |
|
---|
| 99 | ?> |
---|