コード例 #1
0
 public function checkTxt($filename = '', $content = '')
 {
     if (!$filename && !$content) {
         return new PwError("DESIGN:upload.file.error");
     }
     if ($filename) {
         if (!($content = WindFile::read($filename))) {
             return new PwError("DESIGN:upload.file.error");
         }
     }
     $content = preg_replace("/\\/\\*(.+)\\*\\//", '', $content);
     $content = unserialize(base64_decode($content));
     $_array = array('page', 'segment', 'structure', 'module');
     foreach ($_array as $v) {
         if (!isset($content[$v])) {
             return new PwError("DESIGN:file.check.fail");
         }
     }
     $this->_content = $content;
     if ($filename) {
         WindFile::del($filename);
     }
     return true;
 }
コード例 #2
0
 private function _clear()
 {
     WindFolder::clearRecur(dirname($this->upgrade_temp), true);
     $useFtp = Wekit::cache()->get('system_upgrade_ftp');
     $phps = $this->_getPhps();
     $sql = PUBLIC_PATH . 'update.sql';
     if ($phps || file_exists($sql)) {
         if ($useFtp) {
             try {
                 $ftp = $useFtp['sftp'] ? new PwSftpSave($useFtp) : new PwFtpSave($useFtp);
                 $ftp->delete(str_replace(ROOT_PATH, '', $sql));
             } catch (WindFtpException $e) {
             }
         } else {
             WindFile::del($sql);
         }
         foreach ($phps as $php) {
             $file = PUBLIC_PATH . $php;
             if ($useFtp) {
                 $file = str_replace(ROOT_PATH, '', $file);
                 $ftp->delete($file);
             } else {
                 WindFile::del($file);
             }
         }
         $ftp && $ftp->close();
     }
     WindFile::del(DATA_PATH . 'upgrade/sql.tmp');
     Wekit::cache()->batchDelete(array('system_upgrade', 'system_upgrade_step', 'system_upgrade_db_step', 'system_upgrade_php_step', 'system_upgrade_ftp', 'system_upgrade_download_step', 'system_upgrade_info', 'system_upgrade_replace'));
 }
コード例 #3
0
ファイル: Pw.php プロジェクト: healthguo/PHP
	/**
	 * 删除本地文件
	 *
	 * @param string $filename 文件绝对地址
	 * @return bool
	 */
	public static function deleteFile($filename) {
		return WindFile::del(WindSecurity::escapePath($filename, true));
	}
コード例 #4
0
 /**
  * 导出压缩包
  *
  */
 public function exportAction()
 {
     $alias = $this->getInput('alias', 'get');
     Wind::import('LIB:utility.PwZip');
     $dir = Wind::getRealDir('EXT:' . $alias);
     if (!is_dir($dir)) {
         $this->showError('fail');
     }
     $target = Wind::getRealPath('DATA:tmp.' . $alias . '.zip', true);
     PwApplicationHelper::zip($dir, $target);
     $timestamp = Pw::getTime();
     $this->getResponse()->setHeader('Last-Modified', gmdate('D, d M Y H:i:s', $timestamp + 86400) . ' GMT');
     $this->getResponse()->setHeader('Expires', gmdate('D, d M Y H:i:s', $timestamp + 86400) . ' GMT');
     $this->getResponse()->setHeader('Cache-control', 'max-age=86400');
     $this->getResponse()->setHeader('Content-type', 'application/x-zip-compressed');
     $this->getResponse()->setHeader('Content-Disposition', 'attachment; filename=' . $alias . '.zip');
     $this->getResponse()->sendHeaders();
     @readfile($target);
     WindFile::del($target);
     $this->getResponse()->sendBody();
     exit;
 }
コード例 #5
0
ファイル: WindidStorageFtp.php プロジェクト: fanqimeng/4tweb
 /**
  * 存储附件,如果是远程存储,记得删除本地文件
  *
  * @param string $source 本地源文件地址
  * @param string $filePath 存储相对位置
  * @return bool
  */
 public function save($source, $filePath)
 {
     $this->_getFtp()->upload($source, $filePath, 'I');
     WindFile::del(WindSecurity::escapePath($source, true));
     return true;
 }
コード例 #6
0
 /**
  * 清理安装过程中产生的临时信息
  *
  * step 5
  * 
  * @return void
  */
 public function clear()
 {
     list(, , $install) = $this->resolvedInstallation($this->tmpInstallLog);
     if (is_file($this->tmpInstallLog)) {
         WindFile::del($this->tmpInstallLog);
     }
     if ($install->getTmpPackage()) {
         WindFolder::rm($install->getTmpPackage(), true);
     }
     if ($install->getTmpPath()) {
         WindFolder::rm($install->getTmpPath(), true);
     }
 }
コード例 #7
0
ファイル: PwDesignImage.php プロジェクト: fanqimeng/4tweb
 public function clearFiles($moduleid, $images)
 {
     if (!$images || !is_array($images)) {
         return false;
     }
     $dir = $this->getSaveDir($moduleid);
     $store = Wind::getComponent('storage');
     //单独使用
     if (!$store instanceof PwStorageLocal) {
         foreach ($images as $image) {
             $store->delete($dir . $image, 0);
         }
     } else {
         $dir = Wind::getRealDir('PUBLIC:') . PUBLIC_ATTACH . '/' . $dir;
         foreach ($images as $image) {
             is_file($dir . $image) && WindFile::del($dir . $image);
         }
     }
 }
コード例 #8
0
 /**
  * 递归的删除目录
  * 
  * @param string $dir 目录
  * @param Boolean $delFolder 是否删除目录
  */
 public static function clearRecur($dir, $delFolder = false)
 {
     if (!self::isDir($dir)) {
         return false;
     }
     if (!($handle = @opendir($dir))) {
         return false;
     }
     while (false !== ($file = readdir($handle))) {
         if ('.' === $file || '..' === $file) {
             continue;
         }
         $_path = $dir . '/' . $file;
         if (self::isDir($_path)) {
             self::clearRecur($_path, $delFolder);
         } elseif (WindFile::isFile($_path)) {
             WindFile::del($_path);
         }
     }
     $delFolder && @rmdir($dir);
     @closedir($handle);
     return true;
 }
コード例 #9
0
 /**
  * 根据现有目录结构调整升级包目录
  *
  * @param array $fileList        	
  */
 public function sortDirectory($fileList)
 {
     $this->_log('start to sort the directory');
     $sourceDir = $this->tmpPath . DIRECTORY_SEPARATOR . $this->target;
     $directoryFile = $sourceDir . DIRECTORY_SEPARATOR . 'conf/directory.php';
     $directory = @(include $directoryFile);
     if (!is_array($directory)) {
         return new PwError('APPCENTER:upgrade.directory.fail');
     }
     $this->_log('the remote directory is:' . var_export($directory, true));
     $root = Wind::getRealDir('ROOT:');
     $sort = array('TPL', 'THEMES', 'ACLOUD', 'WINDID', 'REP', 'SRV', 'LIB', 'HOOK', 'EXT', 'APPS', 'CONF', 'DATA', 'SRC', 'PUBLIC');
     $strtr = array();
     $localDirectory = @(include Wind::getRealPath('CONF:directory.php', true));
     foreach ($sort as $v) {
         if ($directory[$v] == $localDirectory[$v]) {
             continue;
         }
         $search = PwSystemHelper::relative(WEKIT_PATH . str_replace('/', DIRECTORY_SEPARATOR, $directory[$v]));
         $strtr[rtrim($search, '/\\')] = rtrim(Wind::getRootPath($v), '/\\');
     }
     $this->_log('way of moving directory' . var_export($strtr, true));
     if (!($sourceMd5 = WindFile::read($sourceDir . DIRECTORY_SEPARATOR . 'conf/md5sum'))) {
         return new PwError('APPCENTER:upgrade.target.hash.fail');
     }
     $sourceMd5 = PwSystemHelper::resolveMd5($sourceMd5);
     // md5sum
     $data = '';
     foreach ($sourceMd5 as $v => $md5) {
         $v = trim($v, '/');
         $v = str_replace('/', DIRECTORY_SEPARATOR, $v);
         $_v = ROOT_PATH . $v;
         $file = $v;
         foreach ($strtr as $search => $replace) {
             if (0 === strpos($_v, $search)) {
                 $file = str_replace(ROOT_PATH, '', $replace . substr($_v, strlen($search)));
                 $file = str_replace('//', '/', $file);
                 break;
             }
         }
         $data .= PwSystemHelper::md5content($md5, $file);
     }
     WindFile::write($sourceDir . DIRECTORY_SEPARATOR . 'conf/md5sum', $data);
     $moveList = $newFileList = array();
     $url = PwApplicationHelper::acloudUrl(array('a' => 'forward', 'do' => 'getVersionHash', 'pwversion' => $this->local));
     /* 从线上获取当前版本的所有文件md5 */
     /* $result = PwApplicationHelper::requestAcloudData($url);
     		if ($result['code'] !== '0' || !$result['info']) return new PwError(array('APPCENTER:upgrade.version.hash.fail', array($result['msg']))); */
     if (!($tmp = WindFile::read(CONF_PATH . 'md5sum'))) {
         return new PwError('APPCENTER:upgrade.hash.fail');
     }
     $md5List = PwSystemHelper::resolveMd5($tmp);
     $this->_log('obtain the md5 list of current version');
     foreach ($fileList as $v) {
         $v = trim($v, '/');
         $v = str_replace('/', DIRECTORY_SEPARATOR, $v);
         $_v = $root . $v;
         $file = $v;
         foreach ($strtr as $search => $replace) {
             if (0 === strpos($_v, $search)) {
                 $file = str_replace($root, '', $replace . substr($_v, strlen($search)));
                 $file = str_replace('//', '/', $file);
                 $moveList[$v] = $file;
                 break;
             }
         }
         $newFileList[$file] = $md5List[str_replace(DIRECTORY_SEPARATOR, '/', $file)];
     }
     $this->_log('files need to move ' . var_export($moveList, true));
     $relativePath_1 = PwSystemHelper::resolveRelativePath(PUBLIC_PATH, Wind::getRealPath('SRC:wekit'));
     $relativePath_2 = PwSystemHelper::resolveRelativePath(PUBLIC_PATH . 'aCloud', Wind::getRealPath('SRC:wekit'));
     foreach ($moveList as $old => $new) {
         WindFolder::mkRecur(dirname($sourceDir . DIRECTORY_SEPARATOR . $new));
         copy($sourceDir . DIRECTORY_SEPARATOR . $old, $sourceDir . DIRECTORY_SEPARATOR . $new);
         WindFile::del($sourceDir . DIRECTORY_SEPARATOR . $old);
         if ('.php' === substr($old, -4) && !strncasecmp($old, 'www' . DIRECTORY_SEPARATOR, 4)) {
             $content = WindFile::read($sourceDir . DIRECTORY_SEPARATOR . $new);
             if (strpos($content, '../../src/wekit.php')) {
                 $content = str_replace('../../src/wekit.php', $relativePath_2, $content);
             } else {
                 $content = str_replace('../src/wekit.php', $relativePath_1, $content);
             }
             // $content = str_replace('../src/wekit.php',
             // Wind::getRealPath('SRC:wekit'), $content);
             WindFile::write($sourceDir . DIRECTORY_SEPARATOR . $new, $content);
         }
     }
     // 目录文件
     if ($directory != $localDirectory) {
         $directory = array_merge($directory, $localDirectory);
         $temp = "<?php\r\n defined('WEKIT_VERSION') or exit(403);\r\n return ";
         $temp .= WindString::varToString($directory) . ";\r\n?>";
         WindFile::write($directoryFile, $temp);
     }
     Wekit::cache()->set('system_upgrade_replace', 1);
     return $newFileList;
 }
コード例 #10
0
 /**
  *
  * @param PwInstallApplication $install        	
  */
 public function afterInstall($install)
 {
     $tmp = $install->getTmpPackage();
     WindFile::del($tmp . '/Manifest.xml');
     PwApplicationHelper::copyRecursive($tmp, ROOT_PATH);
 }
コード例 #11
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;
 }
コード例 #12
0
 /**
  * 清理安装过程中产生的临时信息
  *
  * step 5
  *
  * @return void
  */
 public function clear()
 {
     if (is_file($this->tmpInstallLog)) {
         WindFile::del($this->tmpInstallLog);
     }
     if ($this->tmpPackage) {
         WindFolder::rm($this->tmpPackage, true);
     }
     if ($this->tmpPath) {
         WindFolder::rm($this->tmpPath, true);
     }
 }
コード例 #13
0
 /**
  * 导出压缩包
  *
  */
 public function exportAction()
 {
     list($type, $alias) = $this->getInput(array('type', 'alias'), 'get');
     $conf = Wekit::load('APPCENTER:service.srv.PwInstallApplication')->getConfig('style-type', $type);
     if (!$conf) {
         $this->showMessage('fail');
     }
     Wind::import('LIB:utility.PwZip');
     $dir = Wind::getRealDir('THEMES:') . DIRECTORY_SEPARATOR . $conf[1] . DIRECTORY_SEPARATOR . $alias;
     if (!is_dir($dir)) {
         $this->showError('fail');
     }
     $target = Wind::getRealPath('DATA:tmp.' . $alias . '.zip', true);
     PwApplicationHelper::zip($dir, $target);
     $this->getResponse()->setHeader('Content-type', 'application/x-zip-compressed');
     $this->getResponse()->setHeader('Content-Disposition', 'attachment; filename=' . $alias . '.zip');
     $this->getResponse()->setHeader('Expires', '0');
     $this->getResponse()->sendHeaders();
     readfile($target);
     WindFile::del($target);
     $this->getResponse()->sendBody();
     exit;
 }
コード例 #14
0
 protected function deleteFile($filename)
 {
     return WindFile::del(WindSecurity::escapePath($filename, true));
 }
コード例 #15
0
ファイル: IndexController.php プロジェクト: sanzhumu/nextwind
 /**
  * 安装完成
  */
 public function finishAction()
 {
     //Wekit::createapp('phpwind');
     Wekit::C()->reload('windid');
     WindidApi::api('user');
     $db = $this->_checkDatabase();
     //更新HOOK配置数据
     Wekit::load('hook.srv.PwHookRefresh')->refresh();
     //初始化站点config
     $site_hash = WindUtility::generateRandStr(8);
     $cookie_pre = WindUtility::generateRandStr(3);
     Wekit::load('config.PwConfig')->setConfig('site', 'hash', $site_hash);
     Wekit::load('config.PwConfig')->setConfig('site', 'cookie.pre', $cookie_pre);
     Wekit::load('config.PwConfig')->setConfig('site', 'info.mail', $db['founder']['manager_email']);
     Wekit::load('config.PwConfig')->setConfig('site', 'info.url', PUBLIC_URL);
     Wekit::load('nav.srv.PwNavService')->updateConfig();
     Wind::import('WINDID:service.config.srv.WindidConfigSet');
     $windidConfig = new WindidConfigSet('site');
     $windidConfig->set('hash', $site_hash)->set('cookie.pre', $cookie_pre)->flush();
     //风格默认数据
     Wekit::load('APPCENTER:service.srv.PwStyleInit')->init();
     //计划任务默认数据
     Wekit::load('cron.srv.PwCronService')->updateSysCron();
     //更新数据缓存
     /* @var $usergroup PwUserGroupsService */
     $usergroup = Wekit::load('SRV:usergroup.srv.PwUserGroupsService');
     $usergroup->updateLevelCache();
     $usergroup->updateGroupCache(range(1, 16));
     $usergroup->updateGroupRightCache();
     /* @var $emotion PwEmotionService */
     $emotion = Wekit::load('SRV:emotion.srv.PwEmotionService');
     $emotion->updateCache();
     //创始人配置
     $uid = $this->_writeFounder($db['founder']['manager'], $db['founder']['manager_pwd'], $db['founder']['manager_email']);
     //门户演示数据
     Wekit::load('SRV:design.srv.PwDesignDefaultService')->likeModule();
     Wekit::load('SRV:design.srv.PwDesignDefaultService')->tagModule();
     Wekit::load('SRV:design.srv.PwDesignDefaultService')->reviseDefaultData();
     //演示数据导入
     Wind::import('SRV:forum.srv.PwPost');
     Wind::import('SRV:forum.srv.post.PwTopicPost');
     $pwPost = new PwPost(new PwTopicPost(2, new PwUserBo($uid)));
     $threads = $this->_getDemoThreads();
     foreach ($threads as $thread) {
         $postDm = $pwPost->getDm();
         $postDm->setTitle($thread['title'])->setContent($thread['content']);
         $result = $pwPost->execute($postDm);
     }
     //全局缓存更新
     Wekit::load('SRV:cache.srv.PwCacheUpdateService')->updateConfig();
     Wekit::load('SRV:cache.srv.PwCacheUpdateService')->updateMedal();
     //清理安装过程的文件
     WindFile::write($this->_getInstallLockFile(), 'LOCKED');
     WindFile::del($this->_getTempFile());
     WindFile::del($this->_getTableLogFile());
     WindFile::del($this->_getTableSqlFile());
 }
コード例 #16
0
 /**
  * 批量删除备份
  * 
  * @return void
  */
 public function batchdeleteAction()
 {
     $files = $this->getInput('files');
     !$files && $this->showError('BACKUP:name.empty');
     foreach ($files as $value) {
         $value = WindSecurity::escapePath($value);
         if (!$value) {
             continue;
         }
         if (preg_match('/^(\\w{8}_pw_[^_]+_\\d{14})(.*)(sql|zip)$/i', $value)) {
             $deletePath = $this->_bakupDir . $value;
             WindFile::del($deletePath);
         } elseif (preg_match('/^\\w{8}_pw_([^_]+)_(\\d{14})/i', $value)) {
             WindFolder::rm($this->_bakupDir . $value, true);
         }
     }
     $this->showMessage('success');
 }