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(); }
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(); }
/** * 检查并导入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; }
public function doEditXmlAction() { list($xml, $alias) = $this->getInput(array('xml', 'alias'), 'post'); $file = Wind::getRealDir('EXT:' . $alias) . '/Manifest.xml'; Wind::import('WIND:parser.WindXmlParser'); $parser = new WindXmlParser(); if (!$parser->parseXmlStream($xml)) { $this->showError('APPCENTER:xml.fail'); } $r = WindFile::write($file, $xml); if (!$r) { $this->showError('APPCENTER:generate.copy.fail'); } Wekit::load('APPCENTER:service.srv.PwDebugApplication')->compile(true); $this->showMessage('success'); }