protected function postUpload($tmp_name, $filename) { if (strpos($filename, '..') !== false || strpos($filename, '.php.') !== false || preg_match('/\\.php$/', $filename)) { exit('illegal file type!'); } WindFolder::mkRecur(dirname($filename)); if (function_exists("move_uploaded_file") && @move_uploaded_file($tmp_name, $filename)) { @unlink($tmp_name); @chmod($filename, 0777); return filesize($filename); } elseif (@copy($tmp_name, $filename)) { @unlink($tmp_name); @chmod($filename, 0777); return filesize($filename); } elseif (is_readable($tmp_name)) { Wind::import('WIND:utility.WindFile'); WindFile::write($filename, WindFile::read($tmp_name)); @unlink($tmp_name); if (file_exists($filename)) { @chmod($filename, 0777); return filesize($filename); } } return false; }
/** * 将给出的文件列表进行打包 * * @param mixed $fileList 文件列表 * @param string $dst 打包文件的存放位置 * @param method $packMethod 打包的方式,默认为stripWhiteSpaceByPhp * @param boolean $compress 打包是否采用压缩的方式,默认为true * @return boolean */ public function packFromFileList($fileList, $dst, $packMethod = WindPack::STRIP_PHP, $compress = true) { if (empty($dst) || empty($fileList)) { return false; } $content = array(); $this->readContentFromFileList($fileList, $packMethod, $content); $replace = $compress ? ' ' : "\n"; $content = implode($replace, $content); $content = $this->callBack($content, $replace); $content = $this->stripNR($content, $replace); $content = $this->stripPhpIdentify($content, ''); return WindFile::write($dst, '<?php' . $replace . $content . '?>'); }
/** * 编译模板并返回编译后模板地址及内容 * * <pre> * <i>$output==true</i>返回编译文件绝对路径地址和内容,不生成编译文件; * <i>$output==false</i>返回编译文件绝对路径地址和内容,生成编译文件 * </pre> * * @param string $template 模板名称 必填 * @param string $suffix 模板后缀 默认为空 * @param boolean $readOnly 是否直接输出模板内容,接受两个值true,false 默认值为false * @param boolean $forceOutput 是否强制返回模板内容,默认为不强制 * @return array(compileFile,content) <pre> * <i>compileFile</i>模板编译文件绝对地址, * <i>content</i>编译后模板输出内容,当<i>$output</i> * 为false时将content写入compileFile</pre> */ public function compile($template, $suffix = '', $readOnly = false, $forceOutput = false) { $templateFile = $this->windView->getViewTemplate($template, $suffix); if (!is_file($templateFile)) { throw new WindViewException('[component.viewer.WindViewerResolver.compile] ' . $templateFile, WindViewException::VIEW_NOT_EXIST); } $compileFile = $this->windView->getCompileFile($template); if (!$this->checkReCompile($templateFile, $compileFile)) { return array($compileFile, $forceOutput ? WindFile::read($compileFile) : ''); } /* @var $_windTemplate WindViewTemplate */ $_windTemplate = Wind::getApp()->getComponent('template'); $_output = $_windTemplate->compile($templateFile, $this); $readOnly === false && WindFile::write($compileFile, $_output); return array($compileFile, $_output); }
/** * 编译模板并返回编译后模板地址及内容 * <pre> * <i>$output==true</i>返回编译文件绝对路径地址和内容,不生成编译文件; * <i>$output==false</i>返回编译文件绝对路径地址和内容,生成编译文件 * </pre> * * @param string $template 模板名称 必填 * @param string $suffix 模板后缀 默认为空 * @param boolean $readOnly 是否直接输出模板内容,接受两个值true,false 默认值为false * @param boolean $forceOutput 是否强制返回模板内容,默认为不强制 * @return array(compileFile,content) <pre> * <i>compileFile</i>模板编译文件绝对地址, * <i>content</i>编译后模板输出内容,当<i>$output</i> * 为false时将content写入compileFile</pre> */ public function compile($template, $suffix = '', $readOnly = false, $forceOutput = false) { list($templateFile, $compileFile, $this->currentThemeKey) = $this->windView->getViewTemplate($template, $suffix); if (!is_file($templateFile)) { throw new WindViewException('[viewer.resolver.WindViewerResolver.compile] ' . $templateFile, WindViewException::VIEW_NOT_EXIST); } if (!$this->checkReCompile($templateFile, $compileFile)) { return array($compileFile, $forceOutput || $readOnly ? WindFile::read($compileFile) : ''); } /* @var $_windTemplate WindViewTemplate */ $_windTemplate = Wind::getComponent('template'); $_output = $_windTemplate->compile($templateFile, $this); if (false === $readOnly) { WindFolder::mkRecur(dirname($compileFile)); WindFile::write($compileFile, $_output); } return array($compileFile, $_output); }
/** * @param string $stylePackage * @param booelan $isManifestChanged * @return boolean */ private function _doCss($stylePackage) { $file = $stylePackage . '/' . $this->manifest; $dir = $stylePackage . '/' . $this->cssDevDir; $_dir = $stylePackage . '/' . $this->cssDir; WindFolder::mkRecur($_dir); $files = WindFolder::read($dir, WindFolder::READ_FILE); foreach ($files as $v) { if (WindFile::getSuffix($v) === 'css') { $dev_css = $dir . '/' . $v; //待编译文件 $css = $_dir . '/' . $v; //编译后文件 $data = WindFile::read($dir . '/' . $v); $_data = $this->_compress($data); if (WindFile::write($css, $_data) === false) { return new PwError('STYLE:style.css.write.fail'); } } } return true; }
public function doCompile() { $JS_DEV_PATH = Wind::getRealDir('PUBLIC:res.js.dev'); $JS_BUILD_PATH = Wind::getRealDir('PUBLIC:res.js.build'); Wind::import('Wind:utility.WindFolder'); $files = $this->_getFiles($JS_DEV_PATH); foreach ($files as $file) { $newfile = $JS_BUILD_PATH . substr($file, strlen($JS_DEV_PATH)); WindFolder::mkRecur(dirname($newfile)); if (substr($file, -3) != '.js') { if (!copy($file, $newfile)) { return new PwError('copy failed'); } continue; } $content = WindFile::read($file); $compress = jscompress::pack($content); if (!WindFile::write($newfile, $compress)) { return new PwError('write failed'); } } }
/** * 备份 * * @return void */ public function dobackAction() { $siteState = Wekit::C('site', 'visit.state'); if ($siteState != 2) { $this->showError('BACKUP:site.isopen'); } @set_time_limit(500); list($sizelimit, $compress, $start, $tableid, $step, $dirname) = $this->getInput(array('sizelimit', 'compress', 'start', 'tableid', 'step', 'dirname')); list($tabledb, $insertmethod, $tabledbname) = $this->getInput(array('tabledb', 'insertmethod', 'tabledbname')); $backupService = $this->_getBackupService(); $tabledbTmpSaveDir = $backupService->getDataDir() . 'tmp/'; $backupService->createFolder($tabledbTmpSaveDir); $tableid = intval($tableid); $tableid = $tableid ? $tableid : 0; $insertmethod = $insertmethod == 'extend' ? 'extend' : 'common'; $sizelimit = $sizelimit ? $sizelimit : 2048; (!is_array($tabledb) || !$tabledb) && !$step && $this->showError('BACKUP:name.empty'); // 读取保存的需要操作的表 if (!$tabledb && $step) { $cachedTable = WindFile::read(WindSecurity::escapePath($tabledbTmpSaveDir . $tabledbname . '.tmp')); $tabledb = explode("|", $cachedTable); } !$dirname && ($dirname = $backupService->getDirectoryName()); // 第一次临时保存需要操作的表 if (!$step) { $specialTables = array_intersect($backupService->getSpecialTables(), $tabledb); $tabledb = array_values(array_diff($tabledb, $backupService->getSpecialTables())); if ($tabledb) { $backupService->backupTable($tabledb, $dirname, $compress); $tabledbname = 'cached_table_buckup'; WindFile::write(WindSecurity::escapePath($tabledbTmpSaveDir . $tabledbname . '.tmp'), implode("|", $tabledb), 'wb'); } // 备份数据表结构 // 备份特殊表结构和数据 if ($specialTables) { $backupService->backupSpecialTable($specialTables, $dirname, $compress, $insertmethod); $referer = 'admin/backup/backup/doback?' . "start=0&tableid={$tableid}&sizelimit={$sizelimit}&step=1&insertmethod={$insertmethod}&compress={$compress}&tabledbname={$tabledbname}&dirname={$dirname}"; $this->showMessage('正在备份', $referer, true); } } if (!$tabledb) { $this->showMessage(array('BACKUP:bakup_success', array('{path}' => $backupService->getSavePath() . $dirname)), 'admin/backup/backup/run'); } // 保存数据 $step = (!$step ? 1 : $step) + 1; $filename = $dirname . '/' . $dirname . '_' . ($step - 1) . '.sql'; list($backupData, $tableid, $start) = $backupService->backupData($tabledb, $tableid, $start, $sizelimit, $insertmethod, $filename); $continue = $tableid < count($tabledb) ? true : false; $backupService->saveData($filename, $backupData, $compress); // 循环执行 if ($continue) { $currentTableName = $tabledb[$tableid]; $currentPos = $start + 1; $createdFileNum = $step - 1; $referer = 'admin/backup/backup/doback?' . "start={$start}&tableid={$tableid}&sizelimit={$sizelimit}&step={$step}&insertmethod={$insertmethod}&compress={$compress}&tabledbname={$tabledbname}&dirname={$dirname}"; $this->showMessage(array('BACKUP:bakup_step', array('{currentTableName}' => $currentTableName, '{currentPos}' => $currentPos, '{createdFileNum}' => $createdFileNum)), $referer, true); } else { unlink(WindSecurity::escapePath($tabledbTmpSaveDir . $tabledbname . '.tmp')); $this->showMessage(array('BACKUP:bakup_success', array('{path}' => $backupService->getSavePath() . $dirname)), 'admin/backup/backup/run'); } }
public function install($patch) { $tmpfiles = $this->bakFiles = array(); WindFolder::mkRecur($this->tmpPath); if ($this->ftp && !is_object($this->ftp)) { try { $this->ftp = $this->ftp['sftp'] ? new PwSftpSave($this->ftp) : new PwFtpSave($this->ftp); } catch (WindFtpException $e) { return false; } } foreach ($patch['rule'] as $rule) { $rule['filename'] = $this->sortFile($rule['filename']); $filename = ROOT_PATH . $rule['filename']; $search = base64_decode($rule['search']); $replace = base64_decode($rule['replace']); $count = $rule['count']; $nums = $rule['nums']; $str = WindFile::read($filename); $realCount = substr_count($str, $search); if ($realCount != $count) { return new PwError('APPCENTER:upgrade.patch.update.fail', array($patch['id'])); } $bakfile = basename($rule['filename']) . '.' . Pw::time2str(WEKIT_TIMESTAMP, 'Ymd') . '.bak'; $bakfile = $this->ftp ? dirname($rule['filename']) . '/' . $bakfile : dirname($filename) . '/' . $bakfile; $tmpfile = tempnam($this->tmpPath, 'patch'); $replacestr = PwSystemHelper::replaceStr($str, $search, $replace, $count, $nums); WindFile::write($tmpfile, $replacestr); if ($this->ftp) { try { $this->ftp->upload($filename, $bakfile); $this->ftp->upload($tmpfile, $rule['filename']); } catch (WindFtpException $e) { return false; } } else { if (!@copy($filename, $bakfile)) { return new PwError('APPCENTER:upgrade.copy.fail', array($rule['filename'])); } if (!@copy($tmpfile, $filename)) { return new PwError('APPCENTER:upgrade.copy.fail', array($rule['filename'])); } } $tmpfiles[] = $tmpfile; $this->bakFiles[] = $bakfile; } $this->_ds()->addLog($patch['id'], $patch, 2); return true; }
public static function log($msg, $version, $start = false) { static $log; if (!$log) { $log = Wind::getRealDir('DATA:upgrade.log', true) . '/' . $version . '.log'; WindFolder::mkRecur(dirname($log)); } $status = $start ? WindFile::READWRITE : WindFile::APPEND_WRITEREAD; WindFile::write($log, "\r\n" . date('Y-m-d H:i') . ' ' . $msg, $status); }
/** * 记录表数据的保存文件跟位置 * * @param $tableSaveInfo * @param $filename * @return bool */ public function _recordTableSaveInfo($tableSaveInfo, $filename) { if (!$filename || !is_array($tableSaveInfo) || !count($tableSaveInfo)) { return false; } $filePath = $this->getSavePath() . dirname($filename); $filename = basename($filename); $this->createFolder($filePath); $linesOfBackupTip = $this->getLinesOfBackupTip(); foreach ($tableSaveInfo as $key => $value) { $value['start'] += $linesOfBackupTip; $value['end'] != -1 && ($value['end'] += $linesOfBackupTip); $record .= $key . ':' . $filename . ',' . $value['start'] . ',' . $value['end'] . "\n"; } Wind::import('WIND:utility.WindFile'); WindFile::write($filePath . '/table.index', $record, 'ab+'); return true; }
protected function write($content, $file) { return WindFile::write($file, $content); }
public function extract2($zipPack, $target) { if (!$zipPack || !is_file($zipPack)) { return false; } $extractedData = array(); $target = rtrim($target, '/'); WindFolder::mkRecur($target, 0777); $this->fileHandle = fopen($zipPack, 'rb'); $filesize = sprintf('%u', filesize($zipPack)); $EofCentralDirData = $this->_findEOFCentralDirectoryRecord($filesize); if (!is_array($EofCentralDirData)) { return false; } $centralDirectoryHeaderOffset = $EofCentralDirData['centraldiroffset']; for ($i = 0; $i < $EofCentralDirData['totalentries']; $i++) { rewind($this->fileHandle); fseek($this->fileHandle, $centralDirectoryHeaderOffset); $centralDirectoryData = $this->_readCentralDirectoryData(); if (!is_array($centralDirectoryData)) { $centralDirectoryHeaderOffset += 46; continue; } $centralDirectoryHeaderOffset += 46 + $centralDirectoryData['filenamelength'] + $centralDirectoryData['extrafieldlength'] + $centralDirectoryData['commentlength']; if (substr($centralDirectoryData['filename'], -1) === '/') { WindFolder::mkRecur($target . '/' . $centralDirectoryData['filename'], 0777); $extractedData['folder'][$i] = $centralDirectoryData['filename']; continue; } else { $data = $this->_readLocalFileHeaderAndData($centralDirectoryData); if ($data === false) { continue; } WindFile::write($target . '/' . $centralDirectoryData['filename'], $data); $extractedData['file'][$i] = $centralDirectoryData['filename']; } } fclose($this->fileHandle); return $extractedData; }
/** * 生成www目录及index.php * */ protected function generateWww() { $content = <<<EOS <?php error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING); define('WIND_DEBUG', 1); require_once '%s'; Wind::register(realpath('%s'), '%s'); Wind::application('%s', '%s')->run(); EOS; $dir = $this->dir . '/' . $this->wwwDir; WindFolder::mkRecur($dir); $content = sprintf($content, $this->_resolveRelativePath($dir, Wind::getRealPath('WIND:Wind.php', true)), $this->_resolveRelativePath($dir, $this->dir), strtoupper($this->name), $this->name, $this->_resolveRelativePath($dir, $this->confFile)); if (!WindFile::write($dir . '/index.php', $content)) { return false; } return true; }
protected function _generateService() { if (!$this->need_service) { return true; } $prefix = 'app_' . $this->alias . '_table'; $classFrefix = str_replace(' ', '', ucwords('app_ ' . $this->alias . '_ ' . $this->alias)); WindFolder::mkRecur($this->baseDir . '/service/dao/'); WindFolder::mkRecur($this->baseDir . '/service/dm/'); $dao_file = $this->defaultDir . '/service/dao/defaultdao'; $class_dao = $classFrefix . 'Dao'; $dao = strtr(WindFile::read($dao_file), array('{{classname}}' => $class_dao, '{{prefix}}' => $prefix, '{{author}}' => $this->author, '{{email}}' => $this->email, '{{website}}' => $this->website)); WindFile::write($this->baseDir . '/service/dao/' . $class_dao . '.php', $dao); $dm_file = $this->defaultDir . '/service/dm/defaultdm'; $class_dm = $classFrefix . 'Dm'; $dm = strtr(WindFile::read($dm_file), array('{{classname}}' => $class_dm, '{{author}}' => $this->author, '{{email}}' => $this->email, '{{website}}' => $this->website)); WindFile::write($this->baseDir . '/service/dm/' . $class_dm . '.php', $dm); $ds_file = $this->defaultDir . '/service/defaultds'; $class_ds = $classFrefix; $ds = strtr(WindFile::read($ds_file), array('{{classname}}' => $class_ds, '{{alias}}' => $this->alias, '{{class_dm}}' => $class_dm, '{{class_dao}}' => $class_dao, '{{author}}' => $this->author, '{{email}}' => $this->email, '{{website}}' => $this->website)); WindFile::write($this->baseDir . '/service/' . $class_ds . '.php', $ds); }
/** * 安装完成 */ 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()); }
/** * 编译模板片段,并将模板片段放在name缓存文件中 * 模板文件中允许存在如下三种形式: * <pre> * 1、第一种: * <hook-action name="hook1" args='a,b,c'> * <div>i am from hook1 {$a} |{$b}|{$c}</div> * </hook-action> * 如上将会被编译成: * function templateName_hook1($a, $b, $c){ * } * 2、第二种: * <hook-action name="hook2"> * <div> i am from hook2 {$data} </div> * </hook-action> * 如上将会编译成: * function templateName_hook2($data){ * } * 3、第三种: * <div> i am from segment {$data}</div> * 如上将会被编译成: * function templateName($data) { * } * * 模板标签: * <segment alias='' name='' args='' tpl='' /> * tpl文件中的模板内容按照如上三种规则被编译之后,将会保存到__segment_alias文件中 * 调用方法根据: * tpl_name来调用,如果func没有写,则调用方法为tpl,否则为tpl_func,传入参数为args * </pre> * * @param string $template * @param array $args * @param string $func * @param string $alias * @param WindViewResolve $viewer * @return */ public static function segment($template, $args, $func = '', $alias = '', $viewer = null) { if ($viewer instanceof WindViewerResolver) { self::$viewer = $viewer; } $_prefix = str_replace(array(':', "."), '_', $template); $alias = '__segment_' . strtolower($alias ? $alias : $_prefix); list($templateFile, $cacheCompileFile) = self::$viewer->getWindView()->getViewTemplate($template); $pathinfo = pathinfo($cacheCompileFile); $cacheCompileFile = $pathinfo['dirname'] . '/' . $alias . '.' . $pathinfo['extension']; $_method = strtoupper($func ? $_prefix . '_' . $func : $_prefix); if (WIND_DEBUG) { WindFolder::mkRecur(dirname($cacheCompileFile)); WindFile::write($cacheCompileFile, '', WindFile::READWRITE); } else { if (!function_exists($_method) && is_file($cacheCompileFile)) { include $cacheCompileFile; } if (function_exists($_method)) { call_user_func_array($_method, $args); return; } } if (!($content = self::_resolveTemplate($templateFile, strtoupper($_prefix)))) { return; } $_content = array(); foreach ($content as $method => $_item) { $_tmpArgs = ''; foreach ($_item[1] as $_k) { $_tmpArgs .= '$' . trim($_k) . ','; } $windTemplate = Wind::getComponent('template'); $_content[] = '<?php if (!function_exists("' . $method . '")) {function ' . $method . '(' . trim($_tmpArgs, ',') . '){?>'; $_content[] = $windTemplate->compileStream($_item[0], self::$viewer); $_content[] = '<?php }}?>'; } WindFolder::mkRecur(dirname($cacheCompileFile)); WindFile::write($cacheCompileFile, implode("\r\n", $_content), WindFile::APPEND_WRITE); include $cacheCompileFile; call_user_func_array($_method, $args); }
protected function writeFile($fileData) { $failArray = array(); $dir = $this->tplPath; WindFolder::rm($dir, true); WindFolder::mk($dir); foreach ($fileData as $file) { WindFolder::mkRecur($dir . '/' . dirname($file['filename'])); if (!WindFile::write($dir . '/' . $file['filename'], $file['data'])) { $failArray[] = $file['filename']; } } return $failArray; }
/** * 保存敏感词字典 * * @param array $nodes */ public function saveData($nodes) { WindFolder::mkRecur($this->file); WindFile::write($this->file . '/word.txt', serialize($nodes)); }
public function after($fileList, $useFtp, $oldList) { if (Wekit::cache()->get('system_upgrade_replace')) { return true; } $relativePath_1 = PwSystemHelper::resolveRelativePath(PUBLIC_PATH, Wind::getRealPath('SRC:wekit')); $relativePath_2 = PwSystemHelper::resolveRelativePath(PUBLIC_PATH . 'aCloud', Wind::getRealPath('SRC:wekit')); $strtr = $this->getMoveWay(); $move = array(); $entrance = array('index.php', 'read.php', 'install.php', 'windid.php', 'admin.php', 'alipay.php', 'pay99bill.php', 'paypal.php', 'tenpay.php'); if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { foreach ($oldList as $v) { $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; } } $move[$file] = $_v; if (in_array(basename($_v), $entrance)) { $content = WindFile::read($_v); 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); } $tmp = tempnam($this->tmpPath, basename($_v) . WindUtility::generateRandStr(3)); WindFile::write($tmp, $content); $move[$file] = $tmp; } } } else { foreach ($fileList as $f => $hash) { $_v = ROOT_PATH . $f; if (in_array(basename($_v), $entrance)) { $content = WindFile::read($_v); 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); } $tmp = tempnam($this->tmpPath, basename($_v) . WindUtility::generateRandStr(3)); WindFile::write($tmp, $content); $move[$f] = $tmp; } } } // MD5SUM $md5File = WindFile::read(CONF_PATH . 'md5sum'); $sourceMd5 = PwSystemHelper::resolveMd5($md5File); $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); } $tmp = tempnam($this->tmpPath, 'md5temp'); WindFile::write($tmp, $data); $move[str_replace(ROOT_PATH, '', CONF_PATH . 'md5sum')] = $tmp; // 入口文件 if ($useFtp) { try { $ftp = $useFtp['sftp'] ? new PwSftpSave($useFtp) : new PwFtpSave($useFtp); } catch (WindFtpException $e) { return new PwError(array('APPCENTER:upgrade.ftp.fail', array($e->getMessage()))); } } foreach ($move as $k => $v) { if ($useFtp) { try { $r = $ftp->upload($v, $k); if ($useFtp['sftp'] && !$r && ($e = $ftp->getError())) { return new PwError('APPCENTER:upgrade.upload.fail', array($v . var_export($e, true))); } } catch (WindFtpException $e) { return new PwError(array('APPCENTER:upgrade.ftp.fail', array($e->getMessage()))); } } else { copy($v, ROOT_PATH . $k); } } $useFtp && $ftp->close(); return true; }
/** * 将记录的日志列表信息写入文件 * * @return boolean */ public function flush() { if (empty($this->_logs)) { return false; } Wind::import('WIND:utility.WindFile'); $_l = $_logTypes = $_logLevels = array(); $_map = array(self::LEVEL_INFO => 'info', self::LEVEL_ERROR => 'error', self::LEVEL_DEBUG => 'debug', self::LEVEL_TRACE => 'trace', self::LEVEL_PROFILE => 'profile'); foreach ($this->_logs as $key => $value) { $_l[] = $value[2]; $_logTypes[$value[1]][] = $value[2]; $_logLevels[$value[0]][] = $value[2]; } if ($this->_writeType & 1) { foreach ($_logLevels as $key => $value) { if (!($fileName = $this->_getFileName($_map[$key]))) { continue; } WindFile::write($fileName, join("", $value), 'a'); } } if ($this->_writeType & 2) { foreach ($_logTypes as $key => $value) { if (!($fileName = $this->_getFileName($key))) { continue; } WindFile::write($fileName, join("", $value), 'a'); } } if ($fileName = $this->_getFileName()) { WindFile::write($fileName, join("", $_l), 'a'); } $this->_logs = array(); $this->_logCount = 0; return true; }
protected function deleteValue($key) { return WindFile::write($key, ''); }
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'); }
protected function getImage($url, $path, $filename = "") { if ($url == "" || $path == "") { return false; } if (!$this->createFolder($path)) { return false; } $ext = strrchr($url, "."); if ($ext != ".gif" && $ext != ".jpg" && $ext != ".png") { return false; } $filename = $filename ? $filename : mt_rand(1, 999999) . '.' . $ext; $filename = $path . $filename; if ($this->store instanceof PwStorageFtp) { $ftp = Wekit::load('design.srv.ftp.PwDesignFtp'); $ftp->download($this->image, $filename); } else { ob_start(); echo $this->getContents($url); $img = ob_get_contents(); ob_end_clean(); WindFile::write($filename, $img); } return $filename; }
private function addLog($request, $adminUser, $router_info) { $admin_name = str_replace('|', '|', $adminUser); $router_info = str_replace('|', '|', $router_info); $post_data = $request->isPost() ? $this->arr2str($request->getPost()) : ''; $request_uri = str_replace('|', '|', $request->getRequestUri()); $online_ip = $request->getClientIp(); $timestamp = time(); $record = "|{$admin_name}|{$router_info}|{$online_ip}|{$timestamp}|{$request_uri}|{$post_data}|\n"; WindFile::write($this->logfile, $record, "ab"); }
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; }
$content[$value] = parseFilePath($key); } //$pack->setContentInjectionCallBack('addImports'); $pack->packFromFileList($fileList, WIND_PATH . 'wind_basic.php', WindPack::STRIP_PHP, true); $message[] = "COMPILE: pack core file successful~"; WindFile::write(_COMPILE_PATH . 'wind_imports.php', '<?php return ' . WindString::varToString($content) . ';'); $message[] = "COMPILE: wind_imports.php successful~"; /* 编译配置文件信息 */ $windConfigParser = new WindConfigParser(); $dh = opendir(_COMPILE_PATH . 'config'); while (($file = readdir($dh)) !== false) { if (is_file(_COMPILE_PATH . 'config/' . $file) && $file !== '.' && $file !== '..') { $result = $windConfigParser->parse(_COMPILE_PATH . 'config/' . $file); $file = preg_replace('/\\.(\\w)*$/i', '', $file); //WindFile::write(_COMPILE_PATH . $file . '.php', '<?php return ' . WindString::varToString($result) . ';'); WindFile::write(WIND_PATH . $file . '.php', '<?php return ' . WindString::varToString($result) . ';'); } } $message[] = 'COMPILE: configs successful~'; $message[] = 'compile successful!'; echo implode("<br>", $message); /*********************************************************************/ /* 向wind包中注入imports文件目录信息 */ function addImports() { $_content = WindString::varToString($GLOBALS['imports']); $_content = str_replace(array("\r\n", "\t", " "), '', $_content); return 'Wind::setImports(' . $_content . ');'; } /* 清理所有缓存 */ function parseFilePath($filePath)
/** * 自定义页面升级 start * * @return boolean */ protected function _designUpgrade() { Wind::import('SRV:design.srv.vo.PwDesignPortalSo'); $vo = new PwDesignPortalSo(); $vo->setIsopen(1); $list = $this->_getPortalDs()->searchPortal($vo, 0, 100); $dirList = array(); foreach ($list as $k => $v) { if (empty($v['template'])) { $dirList[$k] = $v['id']; } } $dir = Wind::getRealDir('THEMES:portal.local.'); $_dir = array(); if (!is_dir($dir)) { return array(); } if (!($handle = @opendir($dir))) { return array(); } while (false !== ($file = @readdir($handle))) { if ('.' === $file || '..' === $file) { continue; } $fileName = $dir . $file; if (is_file($fileName)) { continue; } elseif (is_dir($fileName) && is_numeric($file)) { $key = array_search($file, $dirList); unset($dirList[$k]); if ((int) $file != $file) { continue; } $tplPath = 'special_' . $file; Wind::import('SRV:design.dm.PwDesignPortalDm'); $dm = new PwDesignPortalDm($file); $dm->setTemplate($tplPath); Wekit::load('design.PwDesignPortal')->updatePortal($dm); $this->copyRecur($fileName, $dir . $tplPath . '/'); } } $srv = Wekit::load('design.srv.PwDesignService'); foreach ($dirList as $k => $v) { $tplPath = 'special_' . $v; $result = $srv->defaultTemplate($k, $tplPath); if ($result) { WindFile::write($dir . $tplPath . '/template/index.htm', $this->_tpl()); Wind::import('SRV:design.dm.PwDesignPortalDm'); $dm = new PwDesignPortalDm($v); $dm->setTemplate($tplPath); Wekit::load('design.PwDesignPortal')->updatePortal($dm); } } @closedir($handle); return true; }
$r = getLine("'{$folder}' is to be register as '{$alias}' ? (Y|N) "); if (strtolower($r[0]) != 'y') { $alias = getLine('Please input the relative path using namespace: '); } $fileList += readRecur(realpath($folder), $alias); } /* 载入需要的文件信息 */ Wind::import('WIND:utility.WindPack'); /* 打包 */ $pack = new WindPack(); $pack->packFromFileList($fileList, _COMPILE_PATH . 'wind_basic.php', WindPack::STRIP_PHP, true); $message = array(); $message[] = "COMPILE: pack core file successful~"; /*装载imports和classes*/ $data = '<?php Wind::$_imports += ' . var_export($imports, true) . ';' . 'Wind::$_classes += ' . var_export($classes, true) . ';'; WindFile::write(_COMPILE_PATH . 'wind_imports.php', $data); $message[] = "COMPILE: wind_imports.php successful~"; $message[] = ''; exit(implode("\n", $message)); /** * 递归目录 * * @param string $dir * @return array */ function readRecur($dir, $alias) { static $fileList = array(); if (false === ($files = scandir($dir, 0))) { e("{$dir} opened failed\n"); }
/** * 对模块进行删除 * PS:不是真正的删除,记录为isused = 0状态 */ public function deleteAction() { $moduleid = (int) $this->getInput('moduleid', 'post'); $module = $this->_getModuleDs()->getModule($moduleid); if (!$module || $module['page_id'] < 1) { $this->showError('operate.fail'); } Wekit::load('design.PwDesignPermissions'); $permissions = $this->_getPermissionsService()->getPermissionsForModule($this->loginUser->uid, $moduleid); if ($permissions < PwDesignPermissions::IS_DESIGN) { $this->showError("DESIGN:permissions.fail"); } Wind::import('SRV:design.bo.PwDesignPageBo'); $pageBo = new PwDesignPageBo($module['page_id']); if ($pageBo->getLock()) { $this->showError('DESIGN:page.edit.other.user'); } Wind::import('SRV:design.dm.PwDesignModuleDm'); $dm = new PwDesignModuleDm($moduleid); $dm->setIsused(0); $resource = $this->_getModuleDs()->updateModule($dm); if ($resource instanceof PwError) { $this->showError($resource->getError()); } //if (!$this->_getModuleDs()->deleteModule($moduleid)) $this->showMessage("operate.fail"); $this->_getDataDs()->deleteByModuleId($moduleid); Wekit::load('design.PwDesignPush')->deleteByModuleId($moduleid); //删除导入数据的模版内容 $dir = Wind::getRealDir('THEMES:portal.local.'); $path = $dir . $pageBo->getTplPath() . '/template/'; $files = WindFolder::read($path, WindFolder::READ_FILE); foreach ($files as $file) { $filePath = $path . $file; $content = WindFile::read($filePath); if (!$content) { continue; } $tmp = preg_replace('/\\<pw-list\\s*id=\\"' . $moduleid . '\\"\\s*>(.+)<\\/pw-list>/isU', '', $content); if ($tmp != $content) { WindFile::write($filePath, $tmp); } } $this->showMessage("operate.success"); }
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()); }