/** * 设置缓存文件 * * @param string $file 相对于临时文件夹 * * @return $this */ public function setFile($file) { $this->cacheFile = $this->app->DIR . '/temp/html' . $file . '.php'; $this->expireFile = $this->cacheFile . '_expire.php'; dir_check(dirname($this->cacheFile)); return $this; }
/** * 写入日志文件 * 不需要手动调用 * * @return bool */ public function write() { $temp = self::$dir; if (!dir_check($temp)) { return false; } $file = $temp . '/' . date("Y-m-d-H-i", $this->app->TIME) . ".log.txt"; $temp = date('Y-m-d H:i:s', $this->app->TIME); //写入文件,记录错误信息 $content = PHP_EOL . PHP_EOL . PHP_EOL . '===============[date: ' . $temp . ' ]===============' . PHP_EOL; foreach (self::$sqlErrors as $i => $sqlError) { $content .= PHP_EOL . '[ 第' . $i . '条 ]'; if (is_array($sqlError)) { foreach ($sqlError as $key => $value) { $content .= PHP_EOL . $key . "\t\t : " . $value; } } else { if (is_string($sqlError)) { $content .= PHP_EOL . $sqlError; } } } error_reporting(0); $temp = error_log($content, 3, $file); error_reporting($this->app->DEBUG); return $temp; }
/** * 构造方法 * * @param $configFile * @param $tempDir */ public function __construct($configFile, $tempDir) { //设置应用配置文件 $this->configFile = $configFile; //设置配置文件编译后的保存位置 $this->compileFile = $tempDir . '/config/' . basename($configFile); dir_check(dirname($this->compileFile)); //加载配置 $this->loadConfig(); }
/** * 用CURL模拟http、https、ftp、gopher、telnet、dict、file * 和ldap协议同其他网站通信 * @param null|string $cookiePath cookie保存路径 * @param null|string $proxy 代理设置 * @param int $expire 时间限制 */ public function __construct($cookiePath = NULL, $proxy = null, $expire = 30) { if (is_null($cookiePath)) { $this->cookieFile = APP_PATH . '/temp/curl/curl.txt'; } else { $cookiePath = dir_format($cookiePath); dir_check($cookiePath); $this->cookieFile = $cookiePath . '/curl.txt'; } $this->proxy = $proxy; $this->expire = $expire; }
/** * @param Monkey\App $app */ public function __construct($app) { $config = $app->config()->getComponentConfig('cache', 'file'); $this->TIME = $app->TIME; $this->expire = $config['expire']; $this->cachePath = dir_format($app->TEMP . ($config['dir'] ? $config['dir'] : '/fileCache')); $this->cacheFile = $config['filename'] ? '/' . $config['filename'] : '/data'; $this->cacheSize = $config['filesize'] ? $config['filesize'] : '15M'; $this->dataOnCheck = $config['check'] ? $config['check'] : false; //是否验证数据 if (!dir_check($this->cachePath)) { $this->error('缓存目录校验失败。'); } $this->workat($this->cachePath . $this->cacheFile); }
/** * 写入日志文件 * 不需要手动调用 * * @return bool */ public function write() { $temp = self::$logDir; if (!dir_check($temp)) { return false; } $file = self::$logDir . '/' . date("Y-m-d-H-i", $this->app->TIME) . ".log.txt"; foreach (self::$logs as $log) { if (!is_array($log)) { $this->write2($log, $file); continue; } if (isset($log['code'])) { $this->write2($log, $temp . '/' . $log['code'] . ".log.txt"); } else { $this->write2($log, $file); } } return true; }
<p style='margin-top:10px;text-indent: 2em'>1. 您可以在遵守本协议的基础上,免费获得WSTMall的授权并将本系统应用于商业用途或者非商业用途(包括个人用户:不具备法人资格的自然人,以个人名义从事电子商务开设网店的;非盈利性用途:从事非盈利活动的商业机构及非盈利性组织,将 WSTMall产品用且仅用于产品演示、展示及发布,或者用来买卖及盈利的运营活动)。</p> <p style='text-indent: 2em'>2. 您可以在协议规定的约束和限制范围内二次开发 WSTMall功能、插件或者风格,以适应您的网站运营要求。</p> <p style='text-indent: 2em'>3. 您可免费将本软件用于多用户O2O电子商务网站搭建(包括但不限于个人、企业搭建电子商务网站)。</p> <p style='text-indent: 2em'>4. WSTMall开源商城,保留WSTMall版权可二次开发并进行使用。无论用途如何、是否经过修改或美化、修改程度如何,只要使用 WSTMall的整体或任何部分,未经书面许可,网站顶部的 WSTMall名称和WSTMall的版权需保留,而不能清除或修改,或者拨打客服电话<strong>020-29806661</strong>进行咨询。</p> <p style='text-indent: 2em'>5. 禁止在 WSTMall的整体或任何部分基础上以发展任何派生版本、修改版本或第三方版本用于重新分发。 </p> <p style='text-indent: 2em'>本协议一旦发生变更,广州晴暖信息科技有限公司将在WSTMall官方网站(<a target='_blank' href='http://www.wstmall.com'>http://www.wstmall.com</a>)上公布修改内容。修改后的服务条款将有效代替原来的服务条款。</p> </div> <div class='bottom'> <input type='button' class='btn' value='我同意' onclick='showStep(1)'/> </div> </div> <?php } else { if ($step == 1) { $env_items = env_check($env_items); $dir_items = dir_check($dir_items); $func_items = check_func($func_items); ?> <div id="system_env" class="main"> <div class="content"> <span class='bold' style='font-size:15px;'>系统环境检查</span> <table class="check-env" style='margin-bottom:20px;'> <?php echo '<tr><td class="left">操作系统</td><td><span class="check' . $env_items['os']['status'] . '"></span>' . $env_items['os']['current'] . '</td></tr>'; echo '<tr><td class="left">PHP 版本</td><td><span class="check' . $env_items['php']['status'] . '"></span>' . $env_items['php']['current'] . '</td></tr>'; echo '<tr><td class="left">附件上传</td><td><span class="check' . $env_items['attachmentupload']['status'] . '"></span>' . $env_items['attachmentupload']['current'] . '</td></tr>'; echo '<tr><td class="left">GD 库</td><td><span class="check' . $env_items['gdversion']['status'] . '"></span>' . $env_items['gdversion']['current'] . '</td></tr>'; echo '<tr><td class="left">磁盘空间 </td><td><span class="check' . $env_items['diskspace']['status'] . '"></span>' . $env_items['diskspace']['current'] . '</td></tr>'; ?> </table> <span class='bold' style='font-size:15px;'>目录权限检查</span>
private function uploadAction($index, $upName, $upSize, $upTmp, $upError, $saveDir, $saveName, $filterType = null, $maxSize = 0, $overwrite = false) { $saveDir = dir_format($saveDir); dir_check($saveDir); if (!is_uploaded_file($upTmp)) { return $this->notice(0, '这不是一个上传的文件!'); } !is_int($maxSize) and $maxSize = size_to_bit($maxSize); if ($maxSize > 0 && $upSize > $maxSize) { return $this->notice(0, '文件超过指定的文件大小!'); } switch ($upError) { case 0: break; case 1: $error = '文件超过服务器的约定大小'; break; case 2: $error = '文件超过指定的文件大小!'; break; case 3: $error = '文件只上传了部分!'; break; case 4: $error = '文件上传失败!'; break; default: $error = '未知错误!'; } if (!empty($error)) { return $this->notice(0, $error); } $pathInfo = pathinfo($upName); $extension = $pathInfo['extension']; empty($saveName) and $saveName = substr($upName, 0, 0 - 1 - strlen($extension)); $saveName = strtr($saveName, '.', '_'); //消除因为apache配置失误造成的上传漏洞。 $index and $saveName .= '_' . $index; $saveName .= '.' . strtolower($extension); $this->fileSystemCharset == 'GB2312' and $saveName = iconv("UTF-8", "GB2312//IGNORE", $saveName); $saveName = $saveDir . '/' . $saveName; if (!is_null($filterType)) { $types = explode('|', strtolower($filterType)); if (!in_array($extension, $types)) { return $this->notice(0, '上传文件类型不在限定的文件类型之内!'); } $upRealTypes = $this->getTypeOfReal($upTmp); $upRealTypes = explode('|', $upRealTypes); if (!in_array($extension, $upRealTypes)) { return $this->notice(0, '上传文件文件类型与其真实类型不一致,可能是修改了扩展名!'); } } if (file_exists($saveName)) { if (!$overwrite) { return $this->notice(0, '要保存的文件名已存在,且不可覆盖!'); } else { unlink($saveName); } } $result = move_uploaded_file($upTmp, $saveName); return $this->notice($result, $result ? $saveName : '未知错误,上传失败!'); }
/** * 生成浮雕或浊刻文字水印 * @param string $imagePath 原图路径 * @param string $waterText 水印文本 * @param string $fontFile 字体文件 * @param int $fontSize 字号 * @param int $fontAngle 逆时针旋转角度 * @param bool $emboss 浮雕效果,TRUE为浮雕,FALSE为浊刻 * @param int $waterPositionOption =9 水印位置(0-9) 0为随机,其他代表九宫格的9个位置 * @param int $alpha =85 水印的透明度,0(完全透明)-100(完全不透明)之间 * @param string $resultPath 带水印的结果图片路径,默认输出到浏览器 * @return boolean */ public function waterByTextOfEmboss($imagePath, $waterText, $fontFile, $fontSize = 50, $fontAngle = 0, $emboss = true, $waterPositionOption = 9, $alpha = 60, $resultPath = NULL) { //检查图片是否存在 if (!file_exists($imagePath)) { return false; } if (!is_null($resultPath)) { dir_check(dirname($resultPath)); } //读取原图像文件 $imageInfo = $this->getInfo($imagePath); $imageFun = "imagecreatefrom" . $imageInfo['type']; $imageHandler = $imageFun($imagePath); //设置水印文本 $waterTextBox = imagettfbbox($fontSize, $fontAngle, $fontFile, $waterText); //取得文本框大小 $waterTextw = abs($waterTextBox[2] - $waterTextBox[6]) + 10; //为margin_right加5px, $waterTexth = abs($waterTextBox[3] - $waterTextBox[7]) + 10; $waterHandler = imagecreatetruecolor($waterTextw, $waterTexth); //创建文本框 $backgroundColor = imagecolorallocate($waterHandler, 10, 10, 10); //设置背景颜色 imagefill($waterHandler, 0, 0, $backgroundColor); //填充背景颜色 $color = 0; $pos = array(abs($waterTextBox[0]), abs($waterTextBox[7])); if ($emboss) { for ($i = 0; $i < 5; $i++) { $color = 65 + $i * 40; imagettftext($waterHandler, $fontSize, $fontAngle, $pos[0] + 6 - $i, $pos[1] + 6 - $i, imagecolorallocate($waterHandler, $color, $color, $color), $fontFile, $waterText); //写入文本 } $pos[0] += 1; $pos[1] += 1; } else { for ($i = 0; $i < 5; $i++) { $color = 65 + $i * 40; //$color=225-$i*40; imagettftext($waterHandler, $fontSize, $fontAngle, $pos[0] + $i, $pos[1] + $i, imagecolorallocate($waterHandler, $color, $color, $color), $fontFile, $waterText); //写入文本 } $pos[0] += 6; $pos[1] += 6; } imagettftext($waterHandler, $fontSize, $fontAngle, $pos[0], $pos[1], imagecolorallocate($waterHandler, $color, $color, $color), $fontFile, $waterText); //写入文本 imagecolortransparent($waterHandler, $backgroundColor); $this->water($imageHandler, $waterHandler, $resultPath, $imageInfo['type'], $imageInfo['width'], $imageInfo['height'], $waterTextw, $waterTexth, $waterPositionOption, $alpha); return true; }
/** * 载入模板 * * @param string $tplFilename 模板文件名,相对于模板根目录。 * @param bool $display 是否直接显示,默认为否 * * @return void|string 当直接显示时无返回,关闭显示后返回字符串 */ public function loading($tplFilename, $display = false) { $tplFilename[0] !== '/' and $tplFilename = '/' . $tplFilename; $tplFile = self::$tplRoot . $tplFilename; if (!file_exists($tplFile)) { new \Exception(':模板文件【' . $tplFilename . '】不存在'); } $compFile = self::$compiledRoot . $tplFilename; if ($this->app->DEBUG || !file_exists($compFile) || filemtime($compFile) < filemtime($tplFile)) { $compiled = $this->compile($tplFile); //获取经编译后的内容 dir_check(dirname($compFile)); //保证编译后目录存在 file_put_contents($compFile, $compiled, LOCK_EX); } extract($this->variable, EXTR_OVERWRITE); //执行模板 if ($display) { include $compFile; return ''; } else { ob_start(); include $compFile; return ob_get_clean(); } }
/** * 将一个文件夹内容,复制或移动到另一个文件夹 * * @param string $source 源文件夹名 * @param string $target 目标文件夹 * @param boolean $deleteSource 是否删除源文件夹(是则相当于移动,否则相当于复制) * * @return boolean */ function dir_copy($source, $target, $deleteSource = false) { $source = dir_format($source); $target = dir_format($target); if ($source == $target) { return true; } if (!is_dir($source)) { return false; } dir_check($target); $handle = opendir($source); if (!$handle) { return false; } $sourcePath = $targetPath = ''; while (($item = readdir($handle)) !== false) { if ($item == '.' || $item == '..') { continue; } $sourcePath = $source . '/' . $item; $targetPath = $target . '/' . $item; if (is_dir($sourcePath)) { dir_copy($sourcePath, $targetPath, $deleteSource); if ($deleteSource) { rmdir($sourcePath); } } else { copy($sourcePath, $targetPath); if ($deleteSource) { unlink($sourcePath); } } } closedir($handle); return true; }
/** * 备份数据库 * @param string|array $table 表名或表名数组,为空时备份所有表 * @return bool */ public function backup($table = null) { $tables = empty($table) ? $this->getTables() : (is_array($table) ? $table : array($table)); $filePre = $this->dataDir . '/' . date('Ymd', time()); $tablesStructure = ''; $i = 0; $dataTemp = array(); $dataHead = ''; $backupData = ''; $file = ''; foreach ($tables as $table) { $tablesStructure .= '------------------------------------------' . PHP_EOL . '-- 表名:' . $table . PHP_EOL . '--------' . PHP_EOL . 'DROP TABLE IF EXISTS ' . $table . ';' . PHP_EOL; $createtable = $this->query('SHOW CREATE TABLE ' . $table)->fetchAll(); $createtable = end($createtable[0]); $createtable = preg_replace('/AUTO_INCREMENT=\\d*/i', 'AUTO_INCREMENT=0', $createtable); $tablesStructure .= $createtable . ';' . PHP_EOL; $data = $this->query('SELECT * FROM ' . $table)->fetchAll(); $dataHead = 'INSERT INTO ' . $table . ' VALUES' . PHP_EOL; foreach ($data as $rowIndex => $row) { foreach ($row as $colKey => $colValue) { $row[$colKey] = $this->db->quote($colValue); } $dataTemp[] = '(' . implode(', ', $row) . ')'; $data[$rowIndex] = ''; if ($i < 200) { $i++; } else { $backupData .= $dataHead . implode(',' . PHP_EOL, $dataTemp) . ';' . PHP_EOL; $dataTemp = array(); $i = 0; } } if (!empty($dataTemp)) { $backupData .= $dataHead . implode(',' . PHP_EOL, $dataTemp) . ';' . PHP_EOL; } $file = $filePre . '/' . $table . $this->dataFix; dir_check(dirname($file)); file_put_contents($file, $backupData, LOCK_EX); $i = 0; $dataTemp = array(); $dataHead = null; $backupData = ''; } $file = $filePre . '/' . $this->structureFile; dir_check(dirname($file)); file_put_contents($file, $tablesStructure, LOCK_EX); return true; }
private function loadPattern() { if (file_exists($this->patternFile) and filemtime($this->patternFile) >= filemtime($this->mapFile)) { $this->patterns = unserialize(file_get_contents($this->patternFile)); } else { //file_exists($this->patternFile) and unlink($this->patternFile); $patterns = (include $this->mapFile); foreach ($patterns as $pattern => $router) { $this->addPattern($pattern, $router); } dir_check(dirname($this->patternFile)); file_put_contents($this->patternFile, serialize($this->patterns), LOCK_EX); //echo '<br/>保存扫描结果到缓存文件中...<br/>'; } }