- Timestamp:
- Nov 27, 2009, 3:19:43 PM (15 years ago)
- Location:
- trunk/xpressme_integration_kit/include
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/xpressme_integration_kit/include/onupdate.php
r428 r462 50 50 // make templates 51 51 include_once XOOPS_ROOT_PATH . '/modules/' . $mydirname . '/include/xpress_templates_make.php' ; 52 $mod_version = $module->getVar('version') ; 53 54 $t_mess = xpress_clean_templates_file($mydirname,$mod_version); 55 $msgs = array_merge($msgs,$t_mess); 56 52 57 $t_mess = xpress_templates_make($mid,$mydirname); 53 54 58 $msgs = array_merge($msgs,$t_mess); 55 59 -
trunk/xpressme_integration_kit/include/xpress_templates_make.php
r384 r462 7 7 $tplfile_handler =& xoops_gethandler( 'tplfile' ) ; 8 8 $tpl_path = XOOPS_ROOT_PATH . '/modules/' . $mydirname . '/templates' ; 9 10 //copy template file from source 9 11 if( $handler = @opendir( $tpl_path . '/source/' ) ) { 10 12 while( ( $file = readdir( $handler ) ) !== false ) { … … 26 28 $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><br />'; 27 29 } 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 } 30 } 31 } 32 closedir( $handler ) ; 33 } 34 35 // template added to the database. 36 if( $handler = @opendir( $tpl_path . '/' ) ) { 37 while( ( $file = readdir( $handler ) ) !== false ) { 38 if( substr( $file , 0 , 1 ) == '.' ) continue ; 39 $file_path = $tpl_path . '/' . $file ; 40 $file_name = $file ; 41 $pattern = '^' . $mydirname . '_'; 42 if (preg_match('/' . $pattern . '/' , $file_name, $match)){ 43 if( is_file( $file_path ) ) { 44 $msgs[] = xpress_create_db_template($file_name,$file_path,$mydirname,$mid); 58 45 } 59 46 } … … 61 48 closedir( $handler ) ; 62 49 } 50 63 51 include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php' ; 64 52 include_once XOOPS_ROOT_PATH.'/class/template.php' ; … … 68 56 } 69 57 58 function xpress_create_db_template($file_name,$file_path,$mydirname,$mid){ 59 if( is_file( $file_path ) ) { 60 $tplfile_handler =& xoops_gethandler( 'tplfile' ) ; 61 $tplfile =& $tplfile_handler->create() ; 62 $mtime = intval( @filemtime( $file_path ) ) ; 63 $tplfile->setVar( 'tpl_source' , file_get_contents( $file_path ) , true ) ; 64 $tplfile->setVar( 'tpl_refid' , $mid ) ; 65 $tplfile->setVar( 'tpl_tplset' , 'default' ) ; 66 $tplfile->setVar( 'tpl_file' , $file_name ) ; 67 $tplfile->setVar( 'tpl_desc' , '' , true ) ; 68 $tplfile->setVar( 'tpl_module' , $mydirname ) ; 69 $tplfile->setVar( 'tpl_lastmodified' , $mtime ) ; 70 $tplfile->setVar( 'tpl_lastimported' , 0 ) ; 71 $tplfile->setVar( 'tpl_type' , 'module' ) ; 72 if( ! $tplfile_handler->insert( $tplfile ) ) { 73 $msg = '<span style="color:#ff0000;">ERROR: Template Could not added to the database. <b>'.htmlspecialchars($file_name).'</b> to the database.</span><br />'; 74 } else { 75 $tplid = $tplfile->getVar( 'tpl_id' ) ; 76 $msg = 'Template <b>'.htmlspecialchars($file_name) .'</b> added to the database. (ID: <b>'.$tplid.'</b>)<br />'; 77 // generate compiled file 78 include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php' ; 79 include_once XOOPS_ROOT_PATH.'/class/template.php' ; 80 if( ! xoops_template_touch( $tplid ) ) { 81 $msg = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>'.htmlspecialchars($file_name).'</b>.</span><br />'; 82 } else { 83 $msg = 'Template <b>'.htmlspecialchars($file_name).'</b> compiled.</span><br />'; 84 } 85 } 86 } 87 return $msg; 88 } 70 89 71 90 function is_template($file_name){ … … 96 115 } 97 116 117 function xpress_clean_templates_file($mydirname,$mod_version) 118 { 119 $tpl_path = XOOPS_ROOT_PATH . '/modules/' . $mydirname . '/templates/' ; 120 $msgs = array(); 121 if( $handler = @opendir( $tpl_path) ) { 122 while( ( $file = readdir( $handler ) ) !== false ) { 123 if( substr( $file , 0 , 1 ) == '.' ) continue ; 124 if ( strcmp($file,'source')==0 ) continue ; 125 if ( strcmp($file,'index.html')==0 ) continue ; 126 $target_file_path = $tpl_path . $file; 127 if (is_dir($target_file_path)){ 128 rmDirectory($target_file_path); 129 $msgs[] = 'Template <b>'.htmlspecialchars($file).'</b> directory deleted.</span><br />'; 130 } else { 131 if ($mod_version >= 200){ 132 $pattern = '^' . $mydirname . '_'; 133 if (preg_match('/' . $pattern . '/' , $file, $match)) continue ; 134 } 135 $rcd = @unlink($target_file_path); 136 $msgs[] = 'Template <b>'.htmlspecialchars($file).'</b> file deleted.</span><br />'; 137 } 138 } 139 closedir( $handler ) ; 140 } 141 return $msgs; 142 } 143 144 function rmDirectory($dir){ 145 if ($handle = opendir("$dir")){ 146 while (false !== ($item = readdir($handle))){ 147 if ($item != "." && $item != ".."){ 148 if (is_dir("$dir/$item")){ 149 rmDirectory("$dir/$item"); 150 }else{ 151 unlink("$dir/$item"); 152 } 153 } 154 } 155 closedir($handle); 156 rmdir($dir); 157 } 158 } 98 159 99 160 ?>
Note: See TracChangeset
for help on using the changeset viewer.