移除多余的无用代码
This commit is contained in:
@@ -52,7 +52,7 @@ static $OJ_REDISPORT=6379;
|
||||
static $OJ_REDISQNAME="hustoj";
|
||||
static $SAE_STORAGE_ROOT="http://hustoj-web.stor.sinaapp.com/"; //新浪云存储引擎
|
||||
static $OJ_CDN_URL=""; // 如果服务器带宽较小,可选用他人同版本的OJ作为静态资源来源 http://cdn.m.hustoj.com:8090/
|
||||
static $OJ_TEMPLATE="syzoj"; //使用的默认模板,template目录下的每个子目录都是一个模板, [bs3 mdui sweet syzoj sidebar bshark] work with discuss3
|
||||
static $OJ_TEMPLATE="syzoj"; //使用的默认模板,当前部署仅保留 syzoj。
|
||||
static $OJ_BG="/image/background.jpg"; //双引号里面填写背景图片的url。
|
||||
// $OJ_BG="/image/bing".date('H').".jpg"; //每个整点更换壁纸,例如准备bing[00~23].jpg在image目录。
|
||||
static $OJ_LOGIN_MOD="hustoj"; //需要在include目录下配置login-xxxx.php来调用其他登录模块。
|
||||
|
||||
127
web/include/editor-upload.php
Normal file
127
web/include/editor-upload.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
@session_start();
|
||||
require_once(__DIR__ . "/db_info.inc.php");
|
||||
|
||||
if (!(isset($_SESSION[$OJ_NAME . '_' . 'administrator'])
|
||||
|| isset($_SESSION[$OJ_NAME . '_' . 'problem_editor'])
|
||||
|| isset($_SESSION[$OJ_NAME . '_' . 'contest_creator']))) {
|
||||
echo "<a href='../loginpage.php'>Please Login First!</a>";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$savePath = realpath(__DIR__ . '/../upload/') . '/';
|
||||
$saveUrl = dirname(dirname($_SERVER['PHP_SELF'])) . '/upload/';
|
||||
$extMap = array(
|
||||
'image' => array('gif', 'jpg', 'jpeg', 'png', 'bmp'),
|
||||
'flash' => array('swf', 'flv'),
|
||||
'media' => array('swf', 'flv', 'mp3', 'wav', 'wma', 'wmv', 'mid', 'avi', 'mpg', 'asf', 'rm', 'rmvb', 'mp4'),
|
||||
'file' => array('pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'htm', 'html', 'txt', 'zip', 'rar', 'gz', 'bz2'),
|
||||
);
|
||||
$maxSize = 400 * 1024 * 1024;
|
||||
|
||||
if (!empty($_FILES['imgFile']['error'])) {
|
||||
switch ($_FILES['imgFile']['error']) {
|
||||
case '1':
|
||||
upload_error('超过php.ini允许的大小。');
|
||||
break;
|
||||
case '2':
|
||||
upload_error('超过表单允许的大小。');
|
||||
break;
|
||||
case '3':
|
||||
upload_error('图片只有部分被上传。');
|
||||
break;
|
||||
case '4':
|
||||
upload_error('请选择图片。');
|
||||
break;
|
||||
case '6':
|
||||
upload_error('找不到临时目录。');
|
||||
break;
|
||||
case '7':
|
||||
upload_error('写文件到硬盘出错。');
|
||||
break;
|
||||
case '8':
|
||||
upload_error('File upload stopped by extension。');
|
||||
break;
|
||||
case '999':
|
||||
default:
|
||||
upload_error('未知错误。');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($_FILES)) {
|
||||
$fileName = $_FILES['imgFile']['name'];
|
||||
$tmpName = $_FILES['imgFile']['tmp_name'];
|
||||
$fileSize = $_FILES['imgFile']['size'];
|
||||
|
||||
if (!$fileName) {
|
||||
upload_error('请选择文件。');
|
||||
}
|
||||
if (@is_dir($savePath) === false) {
|
||||
upload_error('上传目录不存在。');
|
||||
}
|
||||
if (@is_writable($savePath) === false) {
|
||||
upload_error("上传目录没有写权限。在服务器上执行下述命令解决该问题:\n chown www-data -R \"$savePath\" \n");
|
||||
}
|
||||
if (@is_uploaded_file($tmpName) === false) {
|
||||
upload_error('上传失败。');
|
||||
}
|
||||
if ($fileSize > $maxSize) {
|
||||
upload_error('上传文件大小超过限制。');
|
||||
}
|
||||
|
||||
$tempArr = explode('.', $fileName);
|
||||
$fileExt = strtolower(trim(array_pop($tempArr)));
|
||||
$dirName = '';
|
||||
|
||||
foreach ($extMap as $key => $extensions) {
|
||||
if (in_array($fileExt, $extensions)) {
|
||||
$dirName = $key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($dirName === '') {
|
||||
$dirName = 'image';
|
||||
}
|
||||
if (empty($extMap[$dirName])) {
|
||||
upload_error('目录名不正确。');
|
||||
}
|
||||
if (in_array($fileExt, $extMap[$dirName]) === false) {
|
||||
upload_error('上传文件扩展名是不允许的扩展名。\n只允许' . implode(',', $extMap[$dirName]) . '格式。');
|
||||
}
|
||||
|
||||
$savePath .= $dirName . '/';
|
||||
$saveUrl .= $dirName . '/';
|
||||
if (!file_exists($savePath)) {
|
||||
mkdir($savePath, 0744, true);
|
||||
}
|
||||
|
||||
$ymd = date('Ymd');
|
||||
$savePath .= $ymd . '/';
|
||||
$saveUrl .= $ymd . '/';
|
||||
if (!file_exists($savePath)) {
|
||||
mkdir($savePath, 0744, true);
|
||||
}
|
||||
|
||||
$newFileName = date('YmdHis') . '_' . rand(10000, 99999) . '.' . $fileExt;
|
||||
$filePath = $savePath . $newFileName;
|
||||
if (move_uploaded_file($tmpName, $filePath) === false) {
|
||||
upload_error('上传文件失败。');
|
||||
}
|
||||
@chmod($filePath, 0644);
|
||||
|
||||
upload_success($saveUrl . $newFileName);
|
||||
}
|
||||
|
||||
function upload_success($fileUrl) {
|
||||
header('Content-type: text/html; charset=UTF-8');
|
||||
echo json_encode(array('error' => 0, 'url' => $fileUrl), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
exit;
|
||||
}
|
||||
|
||||
function upload_error($message) {
|
||||
header('Content-type: text/html; charset=UTF-8');
|
||||
echo json_encode(array('error' => 1, 'message' => $message), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
exit;
|
||||
}
|
||||
@@ -51,8 +51,8 @@ if($OJ_SaaS_ENABLE){
|
||||
$DOMAIN=$domain;
|
||||
}
|
||||
|
||||
if(isset($_SERVER["HTTP_USER_AGENT"])&&strpos($_SERVER["HTTP_USER_AGENT"],"MSIE")){ // 360 or IE use bs3 instead
|
||||
$OJ_TEMPLATE="bs3";
|
||||
if(isset($_SERVER["HTTP_USER_AGENT"])&&strpos($_SERVER["HTTP_USER_AGENT"],"MSIE")){ // 360 or IE keep using the only remaining syzoj template
|
||||
$OJ_TEMPLATE="syzoj";
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -378,7 +378,7 @@
|
||||
});
|
||||
}
|
||||
|
||||
function kindEditorUploadFormatter(files, responseText) {
|
||||
function editorUploadFormatter(files, responseText) {
|
||||
var payload;
|
||||
var fileName = 'upload';
|
||||
var result;
|
||||
@@ -436,7 +436,7 @@
|
||||
fieldName: options.fieldName || 'imgFile',
|
||||
accept: options.accept || '*/*',
|
||||
format: function (files, responseText) {
|
||||
return kindEditorUploadFormatter(files, responseText);
|
||||
return editorUploadFormatter(files, responseText);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -962,7 +962,7 @@
|
||||
|
||||
function initTextareaVditors(options) {
|
||||
return ensureAssets(options).then(function () {
|
||||
var selector = (options && options.selector) || 'textarea.kindeditor';
|
||||
var selector = (options && options.selector) || 'textarea.vditor-editor';
|
||||
var textareas = documentRef.querySelectorAll(selector);
|
||||
var tasks = [];
|
||||
|
||||
@@ -983,6 +983,6 @@
|
||||
renderMarkdownBlocks: renderMarkdownBlocks,
|
||||
aceThemeToVditorTheme: aceThemeToVditorTheme,
|
||||
decodeHtmlEntities: decodeHtmlEntities,
|
||||
kindEditorUploadFormatter: kindEditorUploadFormatter
|
||||
editorUploadFormatter: editorUploadFormatter
|
||||
};
|
||||
})(window);
|
||||
Reference in New Issue
Block a user