|
|
@ -712,9 +712,150 @@ eof; |
|
|
|
return $this->renderJson(compact('code', 'msg', 'err')); |
|
|
|
return $this->renderJson(compact('code', 'msg', 'err')); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//分类管理 |
|
|
|
|
|
|
|
public function actionSavetags() { |
|
|
|
|
|
|
|
$ip = $this->getUserIp(); |
|
|
|
|
|
|
|
$check_time = 120; //2 分钟内 |
|
|
|
|
|
|
|
$max_time_in_minutes = 10; //最多 10 次 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$isUserGotRequestLimit = $this->requestLimit($ip, $max_time_in_minutes, $check_time); |
|
|
|
|
|
|
|
if ($isUserGotRequestLimit) { |
|
|
|
|
|
|
|
$this->logError("Request limit got, ip: {$ip}"); |
|
|
|
|
|
|
|
throw new Exception('Oops,操作太快了,请喝杯咖啡休息会吧...'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//只允许修改自己的数据 |
|
|
|
|
|
|
|
$loginedUser = Common::getUserFromSession(); |
|
|
|
|
|
|
|
if (empty($loginedUser['username'])) { |
|
|
|
|
|
|
|
throw new Exception('Oops,你还没登录哦'); |
|
|
|
|
|
|
|
}else if ( |
|
|
|
|
|
|
|
!empty(FSC::$app['config']['multipleUserUriParse']) |
|
|
|
|
|
|
|
&& (empty(FSC::$app['user_id']) || FSC::$app['user_id'] != $loginedUser['username']) |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
throw new Exception('Oops,请求地址有误'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//TODO: 分类管理 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//返回给视图的变量 |
|
|
|
|
|
|
|
$code = 0; |
|
|
|
|
|
|
|
$msg = ''; |
|
|
|
|
|
|
|
$err = ''; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//用户提交的数据检查 |
|
|
|
|
|
|
|
$postParams = $this->post(); |
|
|
|
|
|
|
|
if (!empty($postParams)) { |
|
|
|
|
|
|
|
$tags = $this->post('tags', ''); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (empty($tags)) { |
|
|
|
|
|
|
|
$err = "请至少保留一个分类"; |
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
|
|
$tags_ok = array(); |
|
|
|
|
|
|
|
foreach($tags as $index => $tag) { |
|
|
|
|
|
|
|
$tag = Common::cleanSpecialChars($tag); |
|
|
|
|
|
|
|
if (!empty($tag) && !is_numeric($tag)) { |
|
|
|
|
|
|
|
array_push($tags_ok, mb_substr($tag, 0, 5, 'utf-8')); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (empty($tags_ok)) { |
|
|
|
|
|
|
|
$err = "请按规则填写分类:2 - 5 个汉字、数字、英文字符"; |
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
|
|
$tags = $tags_ok; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (empty($err)) { //如果数据检查通过,尝试保存 |
|
|
|
|
|
|
|
//获取已有的分类 |
|
|
|
|
|
|
|
$scanner = new DirScanner(); |
|
|
|
|
|
|
|
$scanner->setWebRoot(FSC::$app['config']['content_directory']); |
|
|
|
|
|
|
|
$dirTree = $scanner->scan(__DIR__ . '/../../../www/' . FSC::$app['config']['content_directory'], 3); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$menus_sorted = array(); //Readme_sort.txt 说明文件内容,一级目录菜单从上到下的排序 |
|
|
|
|
|
|
|
$readmeFile = $scanner->getDefaultReadme(); |
|
|
|
|
|
|
|
if (!empty($readmeFile)) { |
|
|
|
|
|
|
|
if (!empty($readmeFile['sort'])) { |
|
|
|
|
|
|
|
$menus_sorted = explode("\n", $readmeFile['sort']); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取tags分类 |
|
|
|
|
|
|
|
$tags_current = $this->getTags($dirTree); |
|
|
|
|
|
|
|
//排序 |
|
|
|
|
|
|
|
if (!empty($menus_sorted) && !empty($tags_current)) { |
|
|
|
|
|
|
|
$tags_current = $this->sortTags($menus_sorted, $tags_current); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//获取只包含分类名的数组 |
|
|
|
|
|
|
|
$tmp_arr = array(); |
|
|
|
|
|
|
|
foreach ($tags_current as $id => $tag) { |
|
|
|
|
|
|
|
array_push($tmp_arr, $tag['name']); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//保存 |
|
|
|
|
|
|
|
$saved = $this->saveTags($tags, $tmp_arr); |
|
|
|
|
|
|
|
if (!empty($saved)) { |
|
|
|
|
|
|
|
$msg = "分类已保存"; |
|
|
|
|
|
|
|
$code = 1; |
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
|
|
$err = '分类保存失败,请稍后重试'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $this->renderJson(compact('code', 'msg', 'err')); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//删除管理 |
|
|
|
|
|
|
|
public function actionDeletetag() { |
|
|
|
|
|
|
|
$ip = $this->getUserIp(); |
|
|
|
|
|
|
|
$check_time = 120; //2 分钟内 |
|
|
|
|
|
|
|
$max_time_in_minutes = 10; //最多 10 次 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$isUserGotRequestLimit = $this->requestLimit($ip, $max_time_in_minutes, $check_time); |
|
|
|
|
|
|
|
if ($isUserGotRequestLimit) { |
|
|
|
|
|
|
|
$this->logError("Request limit got, ip: {$ip}"); |
|
|
|
|
|
|
|
throw new Exception('Oops,操作太快了,请喝杯咖啡休息会吧...'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//只允许修改自己的数据 |
|
|
|
|
|
|
|
$loginedUser = Common::getUserFromSession(); |
|
|
|
|
|
|
|
if (empty($loginedUser['username'])) { |
|
|
|
|
|
|
|
throw new Exception('Oops,你还没登录哦'); |
|
|
|
|
|
|
|
}else if ( |
|
|
|
|
|
|
|
!empty(FSC::$app['config']['multipleUserUriParse']) |
|
|
|
|
|
|
|
&& (empty(FSC::$app['user_id']) || FSC::$app['user_id'] != $loginedUser['username']) |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
throw new Exception('Oops,请求地址有误'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//返回给视图的变量 |
|
|
|
|
|
|
|
$code = 0; |
|
|
|
|
|
|
|
$msg = ''; |
|
|
|
|
|
|
|
$err = ''; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//用户提交的数据检查 |
|
|
|
|
|
|
|
$postParams = $this->post(); |
|
|
|
|
|
|
|
if (!empty($postParams)) { |
|
|
|
|
|
|
|
$tag_to_delete = $this->post('tag', ''); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (empty($tag_to_delete)) { |
|
|
|
|
|
|
|
$err = "参数错误,缺少tag传参"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (empty($err)) { //如果数据检查通过,尝试保存 |
|
|
|
|
|
|
|
//保存 |
|
|
|
|
|
|
|
$saved = $this->deleteTag($tag_to_delete); |
|
|
|
|
|
|
|
if (!empty($saved)) { |
|
|
|
|
|
|
|
$msg = "分类已删除"; |
|
|
|
|
|
|
|
$code = 1; |
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
|
|
$err = '分类删除失败,请稍后重试'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $this->renderJson(compact('code', 'msg', 'err')); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//TODO: 视频管理 |
|
|
|
//TODO: 视频管理 |
|
|
|
|
|
|
|
|
|
|
|