/** * 把模块包里的文件写入服务器 * * @access public * @param string $hashcode hash码 * @param string $isreplace 是否替换 * @return string */ function WriteFiles($hashcode, $isreplace = 3) { global $AdminBaseDir; $dap = new DedeAttParse(); $modulefile = $this->modulesPath . '/' . $this->GetHashFile($hashcode); $fp = fopen($modulefile, 'r') or die("文件 {$modulefile} 不存在或不可读!"); $i = 0; while (!feof($fp)) { $line = fgets($fp, 1024); if (preg_match("/^[\\s]{0,}<file/i", $line)) { $i++; $line = trim(preg_replace("/[><]/", "", $line)); $dap->SetSource($line); $filetype = $dap->CAtt->GetAtt('type'); $filename = $dap->CAtt->GetAtt('name'); $filename = str_replace("\\", "/", $filename); if (!empty($AdminBaseDir)) { $filename = $AdminBaseDir . $filename; } if ($filetype == 'dir') { if (!is_dir($filename)) { @mkdir($filename, $GLOBALS['cfg_dir_purview']); } @chmod($filename, $GLOBALS['cfg_dir_purview']); } else { $this->TestDir($filename); if ($isreplace == 0) { continue; } if ($isreplace == 3) { if (is_file($filename)) { $copyname = @preg_replace("/([^\\/]{1,}\$)/", "bak-\$1", $filename); @copy($filename, $copyname); } } if (!empty($filename)) { $fw = fopen($filename, 'w') or die("写入文件 {$filename} 失败,请检查相关目录的权限!"); $ct = ''; while (!feof($fp)) { $l = fgets($fp, 1024); if (preg_match("/^[\\s]{0,}<\\/file/i", trim($l))) { break; } $ct .= $l; } $ct = base64_decode($ct); if ($this->sysLang != $this->moduleLang) { //转换内码 if (preg_match('/\\.(xml|php|inc|txt|htm|html|shtml|tpl|css)$/', $filename)) { $ct = $this->AppCode($ct); } //转换HTML编码标识 if (preg_match('/\\.(php|htm|html|shtml|inc|tpl)$/i', $filename)) { if ($this->sysLang == 'big5') { $charset = 'charset=big5'; } else { if ($this->sysLang == 'utf-8') { $charset = 'charset=gb2312'; } else { $charset = 'charset=gb2312'; } } $ct = preg_match("/charset=([a-z0-9-]*)/i", $charset, $ct); } } fwrite($fw, $ct); fclose($fw); } } } } fclose($fp); return TRUE; }
function WriteFiles($hashcode,$isreplace=3) { global $AdminBaseDir; $dap = new DedeAttParse(); $modulefile = $this->modulesPath.'/'.$this->GetHashFile($hashcode); $fp = fopen($modulefile,'r') or die("文件 {$modulefile} 不存在或不可读!"); $i = 0; while(!feof($fp)) { $line = fgets($fp,1024); if(preg_match("/^[\s]{0,}<file/i",$line)) { $i++; $line = trim(preg_replace("/[><]/","",$line)); $dap->SetSource($line); $filetype = $dap->CAtt->GetAtt('type'); $filename = $dap->CAtt->GetAtt('name'); $filename = str_replace("\\","/",$filename); if(!empty($AdminBaseDir)) $filename = $AdminBaseDir.$filename; if($filetype=='dir') { if(!is_dir($filename)) { @mkdir($filename,$GLOBALS['cfg_dir_purview']); @chmod($filename,$GLOBALS['cfg_dir_purview']); } }else{ $this->TestDir($filename); if($isreplace==0) continue; if($isreplace==3){ if(is_file($filename)){ $copyname = @preg_replace("/([^\/]{1,}$)/","bak-$1",$filename); @copy($filename,$copyname); } } if(!empty($filename)){ $fw = fopen($filename,'w') or die("写入文件 {$filename} 失败,请检查相关目录的权限!"); $ct = ""; while(!feof($fp)){ $l = fgets($fp,1024); if(preg_match("/^[\s]{0,}<\/file/i",trim($l))){ break; } $ct .= $l; } $ct = base64_decode($ct); fwrite($fw,$ct); fclose($fw); } } } } fclose($fp); return true; }