Esempio n. 1
0
 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();
 }
Esempio n. 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();
 }
Esempio n. 3
0
 public function generate()
 {
     $addons = Wekit::load('APPS:appcenter.service.srv.PwInstallApplication')->getConfig('style-type');
     $base = str_replace('/', '.', $addons[$this->style_type][1]);
     $this->defaultDir = Wind::getRealDir('THEMES:' . $base . '.default');
     if (!is_dir($this->defaultDir)) {
         return new PwError('APPCENTER:generate.style.unsupport');
     }
     $this->baseDir = Wind::getRealDir('THEMES:' . $base . '.' . $this->alias);
     if (is_dir($this->baseDir)) {
         return new PwError('APPCENTER:alias.exist');
     }
     WindFolder::mkRecur($this->baseDir);
     Wind::import('APPS:appcenter.service.srv.helper.PwSystemHelper');
     $writable = PwSystemHelper::checkWriteAble($this->baseDir . '/');
     if (!$writable) {
         return new PwError('APPCENTER:generate.copy.fail');
     }
     PwApplicationHelper::copyRecursive($this->defaultDir, $this->baseDir);
     $file = $this->baseDir . '/Manifest.xml';
     Wind::import('WIND:parser.WindXmlParser');
     $parser = new WindXmlParser();
     $manifest = $parser->parse($file);
     $manifest['application']['name'] = $this->name;
     $manifest['application']['alias'] = $this->alias;
     $manifest['application']['description'] = $this->description;
     $manifest['application']['version'] = $this->version;
     $manifest['application']['pw-version'] = $this->pwversion;
     $manifest['application']['website'] = $this->website;
     $manifest['application']['author-name'] = $this->author;
     $manifest['application']['author-email'] = $this->email;
     $parser = new WindXmlParser();
     $manifest = str_replace('><', ">\n\t<", $parser->parseToXml(array('manifest' => $manifest), Wind::getApp()->getResponse()->getCharset()));
     WindFile::write($this->baseDir . '/Manifest.xml', $manifest);
     return 'THEMES:' . $base . '.' . $this->alias;
 }
Esempio n. 4
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;
 }
Esempio n. 5
0
 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');
 }
 private function _generateAdmin()
 {
     if ($this->need_admin) {
         $classname = $this->_ucwords($this->alias) . '_ConfigDo';
         $hook = array('s_admin_menu' => array('app_' . $this->alias => array('class' => 'EXT:' . $this->alias . '.service.srv.' . $classname, 'loadway' => 'load', 'method' => 'getAdminMenu', 'description' => $this->name . 'admin menu')));
         Wind::import('WIND:parser.WindXmlParser');
         $parser = new WindXmlParser();
         $hook = preg_replace('/<\\?xml[^\\?]+\\?>/i', '', $parser->parseToXml($hook, Wind::getApp()->getResponse()->getCharset()));
         $hook = str_replace('><', ">\n\t<", $hook);
         $this->manifest = strtr($this->manifest, array('{{inject_services}}' => $hook));
         $class = WindFile::read(dirname($this->defaultDir) . '/hook.admin');
         $class = strtr($class, array('{{alias}}' => $this->alias, '{{name}}' => $this->name, '{{classname}}' => $classname, '{{author}}' => $this->author, '{{email}}' => $this->email, '{{website}}' => $this->website));
         WindFolder::mkRecur($this->baseDir . '/service/srv/');
         WindFile::write($this->baseDir . '/service/srv/' . $classname . '.php', $class);
     } else {
         $this->manifest = strtr($this->manifest, array('{{inject_services}}' => ''));
         WindFolder::clearRecur($this->baseDir . '/admin', true);
         WindFolder::clearRecur($this->baseDir . '/template/admin', true);
     }
 }