public function zip($charset = 'utf-8')
 {
     Wind::import('LIB:utility.PwZip');
     $zip = new PwZip();
     $files = $this->read($this->dir);
     $fromCharset = Wekit::app()->charset;
     foreach ($files as &$v) {
         $v['filename'] = str_replace($this->dir, '', $v['filename']);
         $ext = strrchr($v['filename'], ".");
         if ($ext != $this->_tplExt) {
             continue;
         }
         //$v['data'] = $this->decompilePw($v['data']);
         $v['data'] = $this->decompileTitle($v['data']);
         //$v['data'] = $this->decompileList($v['data']);
         $v['data'] = $this->decompileTpl($v['data']);
         $v['data'] = $this->decompileStyle($v['data']);
     }
     foreach ($files as $file) {
         if ($file['filename'] == 'module/data.txt') {
             continue;
         }
         if (strtolower($file['filename']) == 'manifest.xml') {
             Wind::import("WIND:parser.WindXmlParser");
             $xml = new WindXmlParser('1.0', $fromCharset);
             $config = $xml->parseXmlStream($file['data'], 0);
             unset($config['module']);
             $file['data'] = $this->xmlFormat($config, $charset);
         } else {
             $ext = strtolower(substr(strrchr($file['filename'], '.'), 1));
             if (in_array($ext, array('css', 'js', 'htm'))) {
                 $file['data'] = WindConvert::convert($file['data'], $charset, $fromCharset);
             }
         }
         $file['filename'] = $this->folder . '/' . $file['filename'];
         if (!$zip->addFile($file['data'], $file['filename'])) {
             return new PwError("DESIGN:zlib.error");
         }
     }
     $txt = $this->doTxt($charset);
     $txtfile = $this->folder . '/module/data.txt';
     $zip->addFile($txt['content'], $txtfile);
     return $zip->getCompressedFile();
 }
Example #2
0
 public function zip()
 {
     Wind::import('LIB:utility.PwZip');
     $zip = new PwZip();
     $files = $this->read($this->dir);
     foreach ($files as &$v) {
         $v['filename'] = str_replace($this->dir, '', $v['filename']);
         $ext = strrchr($v['filename'], ".");
         if ($ext != $this->_tplExt) {
             continue;
         }
         //$v['data'] = $this->decompilePw($v['data']);
         $v['data'] = $this->decompileTitle($v['data']);
         //$v['data'] = $this->decompileList($v['data']);
         $v['data'] = $this->decompileTpl($v['data']);
         $v['data'] = $this->decompileStyle($v['data']);
     }
     foreach ($files as $file) {
         if ($file['filename'] == 'module/data.txt') {
             continue;
         }
         if (strtolower($file['filename']) == 'manifest.xml') {
             Wind::import("WIND:parser.WindXmlParser");
             $xml = new WindXmlParser();
             $config = $xml->parseXmlStream($file['data'], 0);
             unset($config['module']);
             $file['data'] = $this->xmlFormat($config);
         }
         $file['filename'] = $this->folder . '/' . $file['filename'];
         if (!$zip->addFile($file['data'], $file['filename'])) {
             return new PwError("DESIGN:zlib.error");
         }
     }
     $txt = $this->doTxt();
     $txtfile = $this->folder . '/module/data.txt';
     $zip->addFile($txt['content'], $txtfile);
     return $zip->getCompressedFile();
 }
Example #3
0
 /**
  * 检查并导入zip文件
  * Enter description here ...
  * @param string $filename
  */
 public function checkZip($filename)
 {
     Wind::import("WIND:parser.WindXmlParser");
     Wind::import('LIB:utility.PwZip');
     $config = array();
     $_isTpl = false;
     $extension = array('htm', 'js', 'gif', 'jpg', 'jpeg', 'txt', 'png', 'css', 'xml');
     $zip = new PwZip();
     $xml = new WindXmlParser('1.0', Wekit::app()->charset);
     if (!($fileData = $zip->extract($filename))) {
         return new PwError("DESIGN:upload.file.error");
     }
     foreach ($fileData as &$file) {
         $file['filename'] = str_replace('\\', '/', $file['filename']);
         $pos = strpos($file['filename'], '/');
         $lenth = strlen($file['filename']);
         $file['filename'] = substr($file['filename'], (int) $pos + 1, $lenth - $pos);
         if (strtolower($file['filename']) == 'manifest.xml') {
             $config = $xml->parseXmlStream($file['data'], 0);
         }
         //过滤文件类型
         $ext = strtolower(substr(strrchr($file['filename'], '.'), 1));
         if (!in_array($ext, $extension)) {
             unset($file);
             continue;
         }
         //过滤中文文件名
         if (preg_match('/^[\\x7f-\\xff]+$/', $file['filename'])) {
             unset($file);
             continue;
         }
         //导入模块数据并记录新ID
         if ($file['filename'] == 'module/data.txt') {
             $this->importTxt($file['data']);
             unset($file);
         }
     }
     //if (!$config) return new PwError("DESIGN:file.check.fail");
     foreach ($fileData as &$_file) {
         $ext = strrchr($_file['filename'], ".");
         if ($ext != $this->_tplExt) {
             continue;
         }
         $_file['data'] = $this->replaceTpl($_file['data']);
         $_file['data'] = $this->compileStyle($_file['data']);
         if ($_file['data']) {
             $_isTpl = true;
         }
     }
     WindFile::del($filename);
     //TODO 版本号验证
     if (!$fileData) {
         return new PwError("DESIGN:file.check.fail");
     }
     if (!$_isTpl) {
         return new PwError("DESIGN:file.check.fail");
     }
     if (!$this->writeFile($fileData)) {
         return true;
     }
     return false;
 }
Example #4
0
 public static function zip($dir, $target)
 {
     $files = self::readRecursive($dir);
     Wind::import('LIB:utility.PwZip');
     $zip = new PwZip();
     $dir_len = strlen(dirname($dir)) + 1;
     foreach ($files as $v) {
         $zip->addFile(WindFile::read($v), substr($v, $dir_len));
     }
     return WindFile::write($target, $zip->getCompressedFile());
 }