| [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' ;
 | 
|---|
| [462] | 9 |         
 | 
|---|
 | 10 |         //copy  template file from source
 | 
|---|
| [102] | 11 |         if( $handler = @opendir( $tpl_path . '/source/' ) ) {
 | 
|---|
 | 12 |                 while( ( $file = readdir( $handler ) ) !== false ) {
 | 
|---|
 | 13 |                         if( substr( $file , 0 , 1 ) == '.' ) continue ;
 | 
|---|
 | 14 |                         if(!is_template($file)) continue ;
 | 
|---|
 | 15 |                         $file_path = $tpl_path . '/source/' . $file ;
 | 
|---|
 | 16 |                         if( is_file( $file_path ) ) {
 | 
|---|
 | 17 |                                 $target_file_name = $mydirname . '_' . $file;
 | 
|---|
 | 18 |                                 $target_file_path = $tpl_path . '/'.$target_file_name;
 | 
|---|
 | 19 |                                 $rcd = @unlink($target_file_path);
 | 
|---|
 | 20 |                                 if ($mydirname != 'xpress') {           //old version file delete
 | 
|---|
 | 21 |                                         $rcd = @unlink($tpl_path . '/xpress'.$file);
 | 
|---|
 | 22 |                                 }
 | 
|---|
 | 23 | //                              $rcd = rename($file_path, $target_file_path);
 | 
|---|
 | 24 |                                 $rcd = copy($file_path, $target_file_path);
 | 
|---|
 | 25 |                                 if ($rcd){
 | 
|---|
| [384] | 26 |                                         $msgs[] = 'Template <b>'.htmlspecialchars($target_file_path).'</b> copy from ' . htmlspecialchars($file) . '<br />';
 | 
|---|
| [102] | 27 |                                 } else {
 | 
|---|
| [384] | 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 />';
 | 
|---|
| [102] | 29 |                                 }                                       
 | 
|---|
| [462] | 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);
 | 
|---|
| [102] | 45 |                                 }
 | 
|---|
 | 46 |                         }
 | 
|---|
 | 47 |                 }
 | 
|---|
 | 48 |                 closedir( $handler ) ;
 | 
|---|
 | 49 |         }
 | 
|---|
| [462] | 50 |         
 | 
|---|
| [102] | 51 |         include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php' ;
 | 
|---|
 | 52 |         include_once XOOPS_ROOT_PATH.'/class/template.php' ;
 | 
|---|
 | 53 |         xoops_template_clear_module_cache( $mid ) ;
 | 
|---|
 | 54 | 
 | 
|---|
 | 55 |         return $msgs;
 | 
|---|
 | 56 | }
 | 
|---|
 | 57 | 
 | 
|---|
| [462] | 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 | }
 | 
|---|
| [102] | 89 | 
 | 
|---|
 | 90 | function is_template($file_name){
 | 
|---|
 | 91 |         if (empty($file_name)) return false;
 | 
|---|
 | 92 |         
 | 
|---|
 | 93 |         $temp_list = array(
 | 
|---|
 | 94 |                 'recent_comments_block.html',
 | 
|---|
 | 95 |                 'recent_posts_content_block.html',
 | 
|---|
 | 96 |                 'recent_posts_list_block.html',
 | 
|---|
| [109] | 97 |                 'calender_block.html',
 | 
|---|
 | 98 |                 'popular_posts_block.html',
 | 
|---|
| [110] | 99 |                 'archives_block.html',
 | 
|---|
 | 100 |                 'authors_block.html',
 | 
|---|
| [118] | 101 |                 'page_block.html',
 | 
|---|
| [119] | 102 |                 'search_block.html',
 | 
|---|
| [122] | 103 |                 'tag_cloud_block.html',
 | 
|---|
 | 104 |                 'category_block.html',
 | 
|---|
 | 105 |                 'meta_block.html' ,
 | 
|---|
| [124] | 106 |                 'sidebar_block.html' ,
 | 
|---|
| [135] | 107 |                 'widget_block.html' ,
 | 
|---|
| [137] | 108 |                 'enhanced_block.html' ,
 | 
|---|
| [533] | 109 |                 'blog_list_block.html' ,
 | 
|---|
| [536] | 110 |                 'global_recent_posts_list_block.html' ,
 | 
|---|
| [543] | 111 |                 'global_recent_comments_block.html',
 | 
|---|
| [552] | 112 |                 'global_popular_posts_block.html',
 | 
|---|
| [109] | 113 |                 'index.html',
 | 
|---|
| [102] | 114 |         );
 | 
|---|
 | 115 |         foreach($temp_list as $ck_file){
 | 
|---|
 | 116 |                 if (strcmp($ck_file,$file_name) ==  0) return true;
 | 
|---|
 | 117 |         }
 | 
|---|
 | 118 |         return false;
 | 
|---|
 | 119 | }
 | 
|---|
 | 120 | 
 | 
|---|
| [462] | 121 | function xpress_clean_templates_file($mydirname,$mod_version)
 | 
|---|
 | 122 | {
 | 
|---|
 | 123 |         $tpl_path = XOOPS_ROOT_PATH . '/modules/' . $mydirname . '/templates/' ;
 | 
|---|
 | 124 |         $msgs = array();
 | 
|---|
 | 125 |         if( $handler = @opendir( $tpl_path) ) {
 | 
|---|
 | 126 |                 while( ( $file = readdir( $handler ) ) !== false ) {
 | 
|---|
 | 127 |                         if( substr( $file , 0 , 1 ) == '.' ) continue ;
 | 
|---|
 | 128 |                         if ( strcmp($file,'source')==0 ) continue ;
 | 
|---|
 | 129 |                         if ( strcmp($file,'index.html')==0 ) continue ;
 | 
|---|
 | 130 |                         $target_file_path = $tpl_path . $file;
 | 
|---|
 | 131 |                         if (is_dir($target_file_path)){
 | 
|---|
 | 132 |                                 rmDirectory($target_file_path);
 | 
|---|
 | 133 |                                 $msgs[] = 'Template <b>'.htmlspecialchars($file).'</b> directory deleted.</span><br />';
 | 
|---|
 | 134 |                         } else {
 | 
|---|
 | 135 |                                 if ($mod_version >= 200){
 | 
|---|
 | 136 |                                         $pattern = '^' . $mydirname . '_';
 | 
|---|
 | 137 |                                         if (preg_match('/' . $pattern . '/' , $file, $match))  continue ;
 | 
|---|
 | 138 |                                 }
 | 
|---|
 | 139 |                                 $rcd = @unlink($target_file_path);
 | 
|---|
 | 140 |                                 $msgs[] = 'Template <b>'.htmlspecialchars($file).'</b> file deleted.</span><br />';
 | 
|---|
 | 141 |                         }
 | 
|---|
 | 142 |                 }
 | 
|---|
 | 143 |                 closedir( $handler ) ;
 | 
|---|
 | 144 |         }
 | 
|---|
 | 145 |         return $msgs;
 | 
|---|
 | 146 | }
 | 
|---|
| [102] | 147 | 
 | 
|---|
| [462] | 148 | function rmDirectory($dir){
 | 
|---|
 | 149 |         if ($handle = opendir("$dir")){
 | 
|---|
 | 150 |                 while (false !== ($item = readdir($handle))){
 | 
|---|
 | 151 |                         if ($item != "." && $item != ".."){
 | 
|---|
 | 152 |                                 if (is_dir("$dir/$item")){
 | 
|---|
 | 153 |                                         rmDirectory("$dir/$item");
 | 
|---|
 | 154 |                                 }else{
 | 
|---|
 | 155 |                                         unlink("$dir/$item");
 | 
|---|
 | 156 |                                 }
 | 
|---|
 | 157 |                         }
 | 
|---|
 | 158 |                 }
 | 
|---|
 | 159 |                 closedir($handle);
 | 
|---|
 | 160 |                 rmdir($dir);
 | 
|---|
 | 161 |         }
 | 
|---|
 | 162 | }
 | 
|---|
 | 163 | 
 | 
|---|
| [102] | 164 | ?> | 
|---|