Esempio n. 1
0
 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;
 }
 /**
  * 解析properties文件并返回一个多维数组
  * 
  * 载入一个由 filename 指定的 properties 文件,
  * 并将其中的设置作为一个联合数组返回。
  * 
  * @param string $filename 文件名
  * @return array
  */
 private function parse_properties_file($filename)
 {
     if (!is_file($filename) || !in_array(substr($filename, strrpos($filename, '.') + 1), array('properties'))) {
         return array();
     }
     $content = explode("\n", WindFile::read($filename));
     $data = array();
     $last_process = $current_process = '';
     foreach ($content as $key => $value) {
         $value = str_replace(array("\n", "\r"), '', trim($value));
         if (0 === strpos(trim($value), self::COMMENT) || in_array(trim($value), array('', "\t", "\n"))) {
             continue;
         }
         $tmp = explode('=', $value, 2);
         if (0 === strpos(trim($value), self::LPROCESS) && strlen($value) - 1 === strrpos($value, self::RPROCESS)) {
             $current_process = $this->trimChar(trim($value), array(self::LPROCESS, self::RPROCESS));
             $data[$current_process] = array();
             $last_process = $current_process;
             continue;
         }
         $tmp[0] = trim($tmp[0]);
         if (count($tmp) == 1) {
             $last_process ? $data[$last_process][$tmp[0]] = '' : ($data[$tmp[0]] = '');
             continue;
         }
         $tmp[1] = trim($tmp[1], '\'"');
         $__tmpValue = strtolower($tmp[1]);
         $tmp[1] = 'false' === $__tmpValue ? false : ('true' === $__tmpValue ? true : $tmp[1]);
         $last_process ? $data[$last_process][$tmp[0]] = $tmp[1] : ($data[$tmp[0]] = $tmp[1]);
     }
     return $data;
 }
Esempio n. 3
0
 /**
  * 获得模板文件内容,目前只支持本地文件获取
  * 
  * @param string $templateFile
  * @return string
  */
 private function getTemplateFileContent($templateFile)
 {
     if (false === ($content = WindFile::read($templateFile))) {
         throw new WindViewException('[viewer.AbstractWindViewTemplate.getTemplateFileContent] Unable to open the template file \'' . $templateFile . '\'.');
     }
     return $content;
 }
Esempio n. 4
0
 private static function _getMP3Audio()
 {
     self::$_audioVerify = '';
     $_len = Pw::strlen(self::$verifyCode);
     for ($i = 0; $i < $_len; $i++) {
         $_code = strtoupper(self::$verifyCode[$i]);
         self::$_audioVerify .= WindFile::read(self::$_audioPath . '/' . $_code . '.mp3', WindFile::READ);
     }
 }
Esempio n. 5
0
 /**
  * 编辑xml
  *
  */
 public function editxmlAction()
 {
     $alias = $this->getInput('alias', 'get');
     /* @var $app PwApplication */
     $app = Wekit::load('APPCENTER:service.PwApplication');
     $app = $app->findByAlias($alias);
     $this->setOutput($app, 'app');
     $manifest = WindFile::read(Wind::getRealPath('EXT:' . $alias . '.Manifest.xml', true));
     $this->setOutput($manifest, 'manifest');
 }
Esempio n. 6
0
 public static function uploadRequest($url, $file, $timeout = 30)
 {
     if (!function_exists('fsockopen')) {
         $urlArr = parse_url($url);
         $port = isset($urlArr['port']) ? $urlArr['port'] : 80;
         $boundary = "---------------------" . substr(md5(rand(0, 32000)), 0, 10);
         $header = "POST " . $urlArr['path'] . '?' . $urlArr['query'] . " HTTP/1.0\r\n";
         $header .= "Host: " . $urlArr['host'] . "\r\n";
         $header .= "Content-type: multipart/form-data, boundary=" . $boundary . "\r\n";
         if (!file_exists($file)) {
             return false;
         }
         $imageInfo = @getimagesize($file);
         $exts = array('1' => 'gif', '2' => 'jpg', '3' => 'png');
         if (!isset($exts[$imageInfo[2]])) {
             continue;
         }
         $ext = $exts[$imageInfo[2]];
         $filename = rand(1000, 9999) . '.' . $ext;
         $data = '';
         $data .= "--{$boundary}\r\n";
         $data .= "Content-Disposition: form-data; name=\"FileData\"; filename=\"" . $filename . "\"\r\n";
         $data .= "Content-Type: " . $imageInfo['mime'] . "\r\n\r\n";
         $data .= WindFile::read($file) . "\r\n";
         $data .= "--{$boundary}--\r\n";
         $header .= "Content-length: " . strlen($data) . "\r\n\r\n";
         $fp = fsockopen($urlArr['host'], $port);
         fputs($fp, $header . $data);
         $response = '';
         while (!feof($fp)) {
             $response .= fgets($fp, 128);
         }
         fclose($fp);
         preg_match("/Content-Length:.?(\\d+)/", $response, $matches);
         if (isset($matches[1])) {
             $response = substr($response, strlen($response) - intval($matches[1]));
         }
         return $response;
     } elseif (function_exists('curl_init')) {
         $curl = curl_init($url);
         curl_setopt($curl, CURLOPT_POST, true);
         curl_setopt($curl, CURLOPT_POSTFIELDS, $file);
         curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
         curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
         $response = curl_exec($curl);
         curl_close($curl);
         return $response;
     } else {
         return false;
     }
 }
Esempio n. 7
0
 /**
  * 存储附件,如果是远程存储,记得删除本地文件
  *
  * @param string $source 本地源文件地址
  * @param string $filePath 存储相对位置
  * @return bool
  */
 public function save($source, &$filePath)
 {
     $data = WindFile::read($source);
     $stuff = WindFile::getSuffix($source);
     $result = $this->_getCdn()->write($data, $stuff);
     if ($result) {
         Pw::deleteFile($source);
         $filePath = $result;
         return true;
     } else {
         return false;
     }
 }
 /**
  * 编译模板并返回编译后模板地址及内容
  * 
  * <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);
 }
Esempio n. 9
0
 /**
  * 编译模板并返回编译后模板地址及内容
  * <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);
 }
Esempio n. 10
0
 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');
         }
     }
 }
Esempio n. 11
0
 /**
  * @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;
 }
Esempio n. 12
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;
 }
Esempio n. 13
0
 public function doimportAction()
 {
     Wind::import('SRV:upload.action.PwWordUpload');
     Wind::import('LIB:upload.PwUpload');
     $bhv = new PwWordUpload();
     $upload = new PwUpload($bhv);
     if (($result = $upload->check()) === true) {
         $result = $upload->execute();
     }
     if ($result !== true) {
         $error = $result->getError();
         if (is_array($error)) {
             list($error, ) = $error;
             if ($error == 'upload.ext.error') {
                 $this->showError('WORD:ext.error');
             }
         }
         $this->showError($result->getError());
     }
     $source = $bhv->getAbsoluteFile();
     if (!WindFile::isFile($source)) {
         $this->showError('operate.fail');
     }
     $content = WindFile::read($source);
     pw::deleteAttach($bhv->dir . $bhv->filename, 0, $bhv->isLocal);
     $content = explode("\n", $content);
     if (!$content) {
         $this->showError('WORD:import.data.empty');
     }
     $wordService = $this->_getWordService();
     $typeMap = $this->_getWordDS()->getTypeMap();
     Wind::import('SRV:word.dm.PwWordDm');
     foreach ($content as $value) {
         list($word, $type, $replace) = $this->_parseTextUseInImport($value, $typeMap);
         if (!$word || !$type || $wordService->isExistWord($word)) {
             continue;
         }
         $dm = new PwWordDm();
         /* @var $dm PwWordDm */
         $dm->setWord($word)->setWordType($type);
         $replace = $this->_getWordDS()->isReplaceWord($type) ? $replace ? $replace : '****' : '';
         $dm->setWordReplace($replace);
         $this->_getWordDS()->add($dm);
     }
     $this->_getWordFilter()->updateCache();
     $this->showMessage('success');
 }
 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);
 }
Esempio n. 15
0
 protected function getValue($key)
 {
     if (!is_file($key)) {
         return null;
     }
     return WindFile::read($key);
 }
Esempio n. 16
0
 /**
  * 组装系统表白名单wind_structure.sql获取
  * 
  * @return void
  */
 protected function _buildTables($tables)
 {
     if (!$tables) {
         return array();
     }
     $structure = WindFile::read(Wind::getRealPath('APPS:install.lang.wind_structure.sql', true));
     if (!$structure) {
         return array();
     }
     $tablePrefix = $this->_getBackupDs()->getTablePrefix();
     preg_match_all('/DROP TABLE IF EXISTS `pw_(\\w+)`/', $structure, $matches);
     $tableNames = array_keys($tables);
     $whitleTables = array();
     foreach ($matches[1] as $v) {
         if (in_array($tablePrefix . $v, $tableNames)) {
             $whitleTables[$tablePrefix . $v] = $tables[$tablePrefix . $v];
         }
     }
     return $whitleTables;
 }
Esempio n. 17
0
 /**
  * step 6 : 数据库更新操作
  *
  * 先执行update.sql,再跳转到update.php
  */
 public function dbAction()
 {
     $step = (int) Wekit::cache()->get('system_upgrade_db_step');
     $step || $this->installService->after($this->localFileList, Wekit::cache()->get('system_upgrade_ftp'), $this->fileList);
     $sqlFile = Wind::getRealPath('PUBLIC:update.sql', true);
     $success = 1;
     if (!file_exists($sqlFile)) {
         Wekit::cache()->set('system_upgrade_step', 6);
         PwSystemHelper::log('no db update', $this->version);
         $this->forwardRedirect(WindUrlHelper::createUrl('appcenter/upgrade/php'));
     }
     $lang = Wind::getComponent('i18n');
     try {
         /* @var $db WindConnection */
         $db = Wind::getComponent('db');
         if (!$step) {
             $sqlArray = PwSystemHelper::sqlParser(WindFile::read($sqlFile), $db->getConfig('charset', '', 'utf8'), $db->getTablePrefix(), $db->getConfig('engine', '', 'MYISAM'));
             WindFile::savePhpData(DATA_PATH . 'upgrade/sql.tmp', $sqlArray);
         } else {
             $sqlArray = (include DATA_PATH . 'upgrade/sql.tmp');
         }
         end($sqlArray);
         if ($step > key($sqlArray)) {
             Wekit::cache()->set('system_upgrade_step', 6);
             PwSystemHelper::log('db update success', $this->version);
             $this->forwardRedirect(WindUrlHelper::createUrl('appcenter/upgrade/php'));
         }
         $sql = $sqlArray[$step];
         if ($sql) {
             foreach ($sql as $v) {
                 if (empty($v)) {
                     continue;
                 }
                 if (preg_match('/^ALTER\\s+TABLE\\s+`?(\\w+)`?\\s+(DROP|ADD)\\s+(KEY|INDEX|UNIQUE)\\s+([\\w\\(\\),`]+)?/i', $v, $matches)) {
                     list($key, $fields) = explode('(', $matches[4]);
                     $fields = trim($fields, '),');
                     list($matches[3]) = explode(' ', $matches[3]);
                     $matches[3] = trim(strtoupper($matches[3]));
                     PwSystemHelper::log($matches[1] . ' ' . str_replace('`', '', $key) . ' ' . ($fields ? str_replace('`', '', $fields) : '') . ' ' . $matches[3], $this->version);
                     PwSystemHelper::alterIndex(array($matches[1], str_replace('`', '', $key), $fields ? str_replace('`', '', $fields) : '', $matches[3], $matches[2]), $db);
                 } elseif (preg_match('/^ALTER\\s+TABLE\\s+`?(\\w+)`?\\s+(CHANGE|DROP|ADD)\\s+`?(\\w+)`?/i', $v, $matches)) {
                     PwSystemHelper::log($matches[1] . ' ' . $matches[3], $this->version);
                     PwSystemHelper::alterField(array($matches[1], $matches[3], $v), $db);
                 } else {
                     PwSystemHelper::log('execute sql ' . $v, $this->version);
                     $db->execute($v);
                 }
             }
         }
     } catch (Exception $e) {
         if ($e instanceof WindForwardException) {
             throw $e;
         }
         $success = 0;
         $this->setOutput(1, 'error');
         PwSystemHelper::log('execute sql failed' . $e->getMessage(), $this->version);
         $this->setOutput($lang->getMessage('APPCENTER:upgrade.db.error', array(implode(';', $sql))), 'msg');
     }
     if ($success) {
         $this->setOutput($lang->getMessage('APPCENTER:upgrade.db.update', array($step, key($sqlArray))), 'msg');
     }
     Wekit::cache()->set('system_upgrade_db_step', ++$step);
 }
Esempio n. 18
0
 /**
  * 解析模板内容并返回
  * 
  * 将输入的模板内容解析为方法数组{@example <pre>
  * 以下模板内容将解析为:
  * <hook-action name="testHook" args='a,c'>
  * <div>
  * hi, i am testHook
  * </div>
  * </hook-action>
  * <hook-action name="testHook1">
  * <div>
  * hi, i am testHook
  * </div>
  * </hook-action>
  * 
  * $content = array(
  * 'testHook' => array('content', array('a','c')),
  * 'testHook1' => array('content', array('data'))
  * );
  * </pre>}
  * @param string $template
  * @return array
  */
 private static function _resolveTemplate($template, $_prefix)
 {
     if (false === ($content = WindFile::read($template))) {
         throw new PwException('template.path.fail', array('{parm1}' => 'wekit.engine.hook.PwHook._resolveTemplate', '{parm2}' => $template));
     }
     self::$methods = array();
     $content = preg_replace_callback('/<(\\/)?hook-action[=,\\w\\s\'\\"]*>(\\n)*/i', 'PwHook::_pregContent', $content);
     $content = explode("</hook-action>", $content);
     $_content = array();
     $_i = 0;
     //如果该模板中只有一段片段没有使用hook-action,则该方法名将会设为该模板名称,接受的参数为$data
     if (count(self::$methods) == 0) {
         $_content[$_prefix] = array($content[0], array('data'));
     } else {
         $_i = 0;
         foreach (self::$methods as $method) {
             $key = $method['name'] ? $_prefix . '_' . strtoupper($method['name']) : $_prefix . '_' . ($_i + 1);
             $args = $method['args'] ? explode(',', $method['args']) : array('data');
             $_content[$key] = array($content[$_i], $args);
             $_i++;
         }
     }
     return $_content;
 }
Esempio n. 19
0
 protected function read($file)
 {
     return WindFile::read($file);
 }
Esempio n. 20
0
 /**
  * 注册数据文件
  *
  * @param PwInstallApplication $install        	
  * @return PwError true
  */
 public function registeData($install)
 {
     try {
         $sqlFile = $install->getTmpPackage() . '/' . self::DB_TABLE;
         if (!is_file($sqlFile)) {
             return true;
         }
         $strSql = WindFile::read($sqlFile);
         /* @var $db WindConnection */
         $db = Wind::getComponent('db');
         $sql = PwApplicationHelper::sqlParser($strSql, $db->getConfig('charset', '', 'utf8'), $db->getTablePrefix(), $db->getConfig('engine', '', 'MYISAM'));
         if ($sql['CREATE']) {
             foreach ($sql['CREATE'] as $table => $statement) {
                 $db->execute($statement);
             }
         }
         $install->setInstallLog('table', $sql['CREATE']);
         foreach ($sql as $option => $statements) {
             if (!in_array($option, array('INSERT', 'UPDATE', 'REPLACE', 'ALTER'))) {
                 continue;
             }
             foreach ($statements as $table => $statement) {
                 if ($option == 'ALTER') {
                     if (preg_match('/^ALTER\\s+TABLE\\s+`?(\\w+)`?\\s+(DROP|ADD)\\s+(KEY|INDEX|UNIQUE)\\s+([\\w\\(\\),`]+)?/i', $statement, $matches)) {
                         list($key, $fields) = explode('(', $matches[4]);
                         $fields = trim($fields, '),');
                         list($matches[3]) = explode(' ', $matches[3]);
                         $matches[3] = trim(strtoupper($matches[3]));
                         PwSystemHelper::alterIndex(array($matches[1], $key, $fields ? $fields : '', $matches[3], $matches[2]), $db);
                     } elseif (preg_match('/^ALTER\\s+TABLE\\s+`?(\\w+)`?\\s+(CHANGE|DROP|ADD)\\s+`?(\\w+)`?/i', $statement, $matches)) {
                         PwSystemHelper::alterField(array($matches[1], $matches[3], $statement), $db);
                     } else {
                         $db->execute($statement);
                     }
                 } else {
                     if ($option == 'INSERT') {
                         $statement = 'REPLACE' . substr($statement, 6);
                     }
                     $db->execute($statement);
                 }
             }
         }
         return true;
     } catch (Exception $e) {
         return new PwError('APPCENTER:install.fail', array('{{error}}' => $e->getMessage()));
     }
     file_put_contents(DATA_PATH . 'tmp/log', 'registedata!', FILE_APPEND);
 }
Esempio n. 21
0
 private function _getTemplate($path)
 {
     $fileName = Wind::getRealPath($path, 'htm');
     return WindFile::read($fileName);
 }
Esempio n. 22
0
 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;
 }
Esempio n. 23
0
 /**
  * 创建数据表
  */
 public function tableAction()
 {
     @set_time_limit(300);
     $db = $this->_checkDatabase();
     try {
         $pdo = new WindConnection($db['dsn'], $db['user'], $db['pwd']);
         $pdo->setConfig($db);
     } catch (PDOException $e) {
         $this->showError($e->getMessage(), false);
     }
     $tableSql = (include $this->_getTableSqlFile());
     try {
         foreach ($tableSql['DROP'] as $sql) {
             $pdo->query($sql);
         }
         foreach ($tableSql['CREATE'] as $sql) {
             $pdo->query($sql);
         }
     } catch (PDOException $e) {
         $this->showError($e->getMessage(), false);
     }
     $pdo->close();
     $log = WindFile::read($this->_getTableLogFile());
     $this->setOutput($log, 'log');
 }
Esempio n. 24
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());
 }
Esempio n. 25
0
 private function _getTemplate($path)
 {
     list($tpl, $compile) = $this->windViewerResolver->getWindView()->getViewTemplate($path);
     if (!$tpl) {
         return '';
     }
     return WindFile::read($tpl);
 }
 /**
  * 获得page页模板内容
  *
  * @return string|mixed
  */
 private function getTplContent()
 {
     if (!$this->tpl) {
         return '';
     }
     list($pageFile) = $this->windViewerResolver->getWindView()->getViewTemplate($this->tpl);
     if (!is_file($pageFile)) {
         throw new WindViewException($pageFile, WindViewException::VIEW_NOT_EXIST);
     }
     $content = WindFile::read($pageFile);
     strpos($this->url, '?') !== false || ($this->url .= '?');
     $url = '{@url:' . $this->url . '&page=$_page_i}{@' . $this->args . ' ? \'&\' . http_build_query(' . $this->args . ') : \'\'';
     $content = str_ireplace(array('{@$url', '{$url'), $url, $content);
     $_windTemplate = Wind::getComponent('template');
     $content = $_windTemplate->compileStream($content, $this->windViewerResolver);
     $arrPageTags = array('$total', '$page', '$count');
     $arrPageVars = array('$__tplPageTotal', '$__tplPageCurrent', '$__tplPageCount');
     return str_ireplace($arrPageTags, $arrPageVars, $content);
 }
Esempio n. 27
0
 /**
  * 对模块进行删除
  * 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");
 }
Esempio n. 28
0
 public function flushLog()
 {
     if ($this->target) {
         $logFile = Wind::getRealDir('DATA:upgrade.log', true) . '/' . $this->target . '.log';
         if (file_exists($logFile) && ($log = WindFile::read($logFile))) {
             Wekit::load('patch.PwUpgradeLog')->addLog($this->target, substr($log, 0, 60000));
         }
     }
 }
Esempio n. 29
0
 private function _backinFileData($filename, $extend)
 {
     if ($extend == 'zip') {
         $zipService = Wekit::load('LIB:utility.PwZip');
         list($data) = $zipService->extract($filename);
         $sql = explode("\n", $data['data']);
     } else {
         $data = WindFile::read($filename);
         $sql = explode("\n", $data);
     }
     $this->_doBackIn($sql);
     return true;
 }
Esempio n. 30
0
 /**
  * 备份
  * 
  * @return void
  */
 public function dobackAction()
 {
     @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) {
         $config = new PwConfigSet('site');
         $siteState = Wekit::load('config.PwConfig')->getValues('site');
         WindFile::savePhpData(WindSecurity::escapePath($tabledbTmpSaveDir . tempSite . '.php'), $siteState['visit.state']);
         $config->set('visit.state', 2)->flush();
         $specialTables = array_intersect($backupService->getSpecialTables(), $tabledb);
         $tabledb = array_values(array_diff($tabledb, $backupService->getSpecialTables()));
         // 备份数据表结构
         // 备份特殊表结构和数据
         if ($specialTables) {
             $backupService->backupSpecialTable($specialTables, $dirname, $compress, $insertmethod);
         }
         if ($tabledb) {
             $backupService->backupTable($tabledb, $dirname, $compress);
             $tabledbname = 'cached_table_buckup';
             WindFile::write(WindSecurity::escapePath($tabledbTmpSaveDir . $tabledbname . '.tmp'), implode("|", $tabledb), 'wb');
         }
     }
     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, $totalRows) = $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, '{totalRows}' => $totalRows, '{currentPos}' => $currentPos, '{createdFileNum}' => $createdFileNum)), $referer, true);
     } else {
         //还原站点
         $siteState = (require_once WindSecurity::escapePath($tabledbTmpSaveDir . tempSite . '.php'));
         $config = new PwConfigSet('site');
         $config->set('visit.state', $siteState)->flush();
         unlink(WindSecurity::escapePath($tabledbTmpSaveDir . $tabledbname . '.tmp'));
         $this->showMessage(array('BACKUP:bakup_success', array('{path}' => $backupService->getSavePath() . $dirname)), 'admin/backup/backup/run');
     }
 }