Browse Source

create fav dir done

master
filesite 6 months ago
parent
commit
6c1901946a
  1. 11
      conf/app.php
  2. 98
      plugins/Common.php
  3. 69
      themes/tajian/controller/FrontapiController.php
  4. 6
      themes/tajian/views/my/createdir.php
  5. 10
      themes/tajian/views/my/index.php
  6. 40
      www/js/tajian.js

11
conf/app.php

@ -64,6 +64,7 @@ $configs = array( @@ -64,6 +64,7 @@ $configs = array(
'tag_dir' => 'tags/', //tag分类目录
'task_dir' => 'task/', //分享视频下载任务文件保存目录
'task_log' => 'tasks.log', //分享视频下载任务文件日志文件
'max_dir_num' => 20, //一个手机可创建的最大收藏夹数量
'supportedPlatforms' => array(
'B站',
'抖音',
@ -155,6 +156,16 @@ if (file_exists($customConfigFile)) { @@ -155,6 +156,16 @@ if (file_exists($customConfigFile)) {
}
//用户管理多账号自定义配置
$customConfigFile = __DIR__ . "/../runtime/custom_config_usermap.json";
if (file_exists($customConfigFile)) {
try {
$json = file_get_contents($customConfigFile);
$customConfigs = json_decode($json, true);
$configs = array_merge($configs, $customConfigs);
}catch(Exception $e) {}
}
//VIP用户自定义配置
$customConfigFile = __DIR__ . "/../runtime/custom_config_vip.json";
if (file_exists($customConfigFile)) {

98
plugins/Common.php

@ -10,7 +10,8 @@ Class Common { @@ -10,7 +10,8 @@ Class Common {
'&',
'<',
'>',
'\/',
'/',
'\\',
' ',
';',
';',
@ -47,7 +48,97 @@ Class Common { @@ -47,7 +48,97 @@ Class Common {
$logOk = @error_log("{$logTime} invite {$cellphone}\n", 3, "{$logDir}{$friendsLogfile}");
}
//初始化用户数据目录
//保存用户多收藏夹目录映射配置
public static function saveUserDirMap($cellphone, $new_dir) {
$tajian_user_map = FSC::$app['config']['tajian_user_map'];
if (empty($tajian_user_map)) {
$tajian_user_map = array();
$tajian_user_map[$cellphone] = array($new_dir);
}else {
$map = $tajian_user_map[$cellphone];
if (empty($map)) {
$map = array($new_dir);
}else if (is_string($map)) {
$old = $map;
$map = array($old, $new_dir);
}else if (is_array($map) && !in_array($new_dir, $map)) {
array_push($map, $new_dir);
}
$tajian_user_map[$cellphone] = $map;
}
$cache_filename = __DIR__ . '/../runtime/custom_config_usermap.json';
file_put_contents($cache_filename, json_encode(compact('tajian_user_map'), JSON_PRETTY_PRINT));
}
//获取新收藏夹目录名
public static function getNewFavDir($cellphone)
{
$new_dir = 2000; //默认从编号2000开始
$cache_filename = __DIR__ . '/../runtime/userCustomFavDirs.json';
if (file_exists($cache_filename)) {
$json = file_get_contents($cache_filename);
$data = json_decode($json, true);
if (!empty($data['dir'])) {
$new_dir = $data['dir'] + 1;
}
}
return $new_dir;
}
//老用户创建新的收藏夹
public static function createNewFavDir($cellphone, $username, $new_dir, $nickname) {
try {
$rootDir = __DIR__ . '/../www/' . FSC::$app['config']['content_directory'];
$rootDir = str_replace("/{$username}", '', $rootDir); //获取当前收藏夹的上一级目录
$userDir = "{$rootDir}/{$new_dir}"; //新收藏夹目录
if (is_dir($userDir)) { //如果已经存在
return false;
}
mkdir("{$userDir}/data/", 0755, true); //分享视频目录
if (!is_dir("{$userDir}/data/")) {
throw new Exception("创建用户数据目录失败,请检查目录 www/" . FSC::$app['config']['content_directory'] . " 权限配置,允许PHP写入");
}
mkdir("{$userDir}/tags/", 0700, true); //分类目录
copy("{$rootDir}README.md", "{$userDir}/README.md");
copy("{$rootDir}README_title.txt", "{$userDir}/README_title.txt");
if (!empty($nickname)) {
file_put_contents("{$userDir}/README_nickname.txt", $nickname);
}
if (!empty($_COOKIE['friends_code'])) {
$friends_code = $_COOKIE['friends_code'];
file_put_contents("{$userDir}/README_friendscode.txt", $friends_code);
}
file_put_contents("{$userDir}/README_cellphone.txt", $cellphone);
//用户新收藏夹创建成功后,保存最新用户创建的收藏夹记录
$data = array(
'dir' => $new_dir,
'update' => time(),
'lastUser' => $cellphone,
);
$cache_filename = __DIR__ . '/../runtime/userCustomFavDirs.json';
file_put_contents($cache_filename, json_encode($data, JSON_PRETTY_PRINT));
//保存用户手机和收藏夹映射关系
self::saveUserDirMap($cellphone, $new_dir);
}catch(Exception $e) {
return false;
}
return true;
}
//新用户注册时初始化用户数据目录
public static function initUserData($cellphone, $friends_code = '') {
$userDir = self::getUserDataDir($cellphone);
if (!empty($userDir)) {
@ -58,6 +149,7 @@ Class Common { @@ -58,6 +149,7 @@ Class Common {
$rootDir = __DIR__ . '/../www/' . FSC::$app['config']['content_directory'];
$username = self::getMappedUsername($cellphone);
$userDir = "{$rootDir}{$username}";
mkdir("{$userDir}/data/", 0755, true); //分享视频目录
if (!is_dir("{$userDir}/data/")) {
throw new Exception("创建用户数据目录失败,请检查目录 www/" . FSC::$app['config']['content_directory'] . " 权限配置,允许PHP写入");
@ -128,7 +220,7 @@ Class Common { @@ -128,7 +220,7 @@ Class Common {
public static function getNicknameByDir($dir, $username){
$rootDir = __DIR__ . '/../www/' . FSC::$app['config']['content_directory'];
$dirPath = str_replace($username, $dir, $rootDir);
$dirPath = str_replace("/{$username}", "/{$dir}", $rootDir);
$filepath = "{$dirPath}/README_nickname.txt";
$nickname = '';

69
themes/tajian/controller/FrontapiController.php

@ -1183,5 +1183,74 @@ eof; @@ -1183,5 +1183,74 @@ eof;
return $this->renderJson(compact('code', 'msg', 'err'));
}
//创建收藏夹
public function actionCreatedir() {
$ip = $this->getUserIp();
$check_time = 120; //2 分钟内
$max_time_in_minutes = 30; //最多 30 次
$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,请求地址有误');
}
//VIP身份判断
if (empty($loginedUser['cellphone']) || !in_array($loginedUser['cellphone'], FSC::$app['config']['tajian_vip_user'])) {
throw new Exception('Oops,你还不是VIP,请联系首页底部客服邮箱开通。');
}
//返回给视图的变量
$code = 0;
$msg = '';
$err = '';
//用户提交的数据检查
$postParams = $this->post();
if (!empty($postParams)) {
$new_nickname = $this->post('nickname', '');
if (empty($new_nickname)) {
$err = "请填写新账号的昵称";
}else {
$new_nickname = Common::cleanSpecialChars($new_nickname);
}
if (empty($err)) { //如果数据检查通过,尝试保存
//已经创建的收藏夹数量检查
//每个手机号最多创建 20 个收藏夹
$max_num = !empty(FSC::$app['config']['tajian']['max_dir_num']) ? FSC::$app['config']['tajian']['max_dir_num'] : 10;
$myDirs = Common::getMyDirs($loginedUser['cellphone']);
if (count($myDirs) >= $max_num) {
$err = "你已经创建了 {$max_num} 个账号,已达到最大数量";
}else {
$new_dir = Common::getNewFavDir($loginedUser['cellphone']);
$saved = Common::createNewFavDir($loginedUser['cellphone'], $loginedUser['username'], $new_dir, $new_nickname);
if ($saved !== false) {
$msg = "新账号创建完成";
$code = 1;
}else {
$err = "{$new_dir} 创建失败,请稍后重试";
}
}
}
}
return $this->renderJson(compact('code', 'msg', 'err'));
}
}

6
themes/tajian/views/my/createdir.php

@ -4,6 +4,8 @@ $linkPrefix = ''; @@ -4,6 +4,8 @@ $linkPrefix = '';
if (!empty(FSC::$app['config']['multipleUserUriParse']) && !empty(FSC::$app['user_id'])) {
$linkPrefix = '/' . FSC::$app['user_id'];
}
$max_num = !empty(FSC::$app['config']['tajian']['max_dir_num']) ? FSC::$app['config']['tajian']['max_dir_num'] : 10;
?><main class="g_main_lay">
<div class="breadcrumbs">
<a href="<?=$linkPrefix?>/my/">&lt;&lt;返回</a>
@ -11,8 +13,8 @@ if (!empty(FSC::$app['config']['multipleUserUriParse']) && !empty(FSC::$app['use @@ -11,8 +13,8 @@ if (!empty(FSC::$app['config']['multipleUserUriParse']) && !empty(FSC::$app['use
<form class="g_form_style mt65" id="dir_new_form" action="" method="POST">
<div class="mb-3 pt20">
<label for="text_input_dir" class="form-label">账号昵称</label>
<input id="text_input_dir" name="dir" placeholder="请填写 2 - 5 个汉字" value="">
<p class="mt10">说明:<br>最多添加 <strong>10</strong> 个账号</p>
<input id="text_input_dir" name="nickname" placeholder="请填写 2 - 5 个汉字" value="">
<p class="mt10">说明:<br>最多添加 <strong><?=$max_num?></strong> 个账号</p>
</div>
<div class="avform_bt vercenter">
<button class="jsbtn" aria-label="保存" type="button">

10
themes/tajian/views/my/index.php

@ -20,13 +20,13 @@ if (!empty(FSC::$app['config']['multipleUserUriParse']) && !empty(FSC::$app['use @@ -20,13 +20,13 @@ if (!empty(FSC::$app['config']['multipleUserUriParse']) && !empty(FSC::$app['use
</div>
<hr>
<ul class="mg_menus">
<li><a href="<?=$linkPrefix?>/site/new"><img src="/img/addvideos.svg" alt="add favorite" width="20"> 添加收藏</a></li>
<li><a href="<?=$linkPrefix?>/my/addtag"><img src="/img/edit.svg" alt="add tag" width="18"> 添加分类</a></li>
<li><a href="<?=$linkPrefix?>/site/new"><img src="/img/addvideos.svg" alt="add favorite" width="22"> 添加收藏</a></li>
<li><a href="<?=$linkPrefix?>/my/addtag"><img src="/img/edit.svg" alt="add tag" width="20"> 添加分类</a></li>
<li><a href="<?=$linkPrefix?>/my/favs"><img src="/img/favorite.png" alt="favorite" width="20"> 管理收藏</a></li>
<li><a href="<?=$linkPrefix?>/my/tags"><img src="/img/collection.svg" alt="collection" width="18"> 管理分类</a></li>
<li><a href="<?=$linkPrefix?>/my/tags"><img src="/img/collection.svg" alt="collection" width="20"> 管理分类</a></li>
<li><a href="<?=$linkPrefix?>/my/share"><img src="/img/share-fill.svg" alt="share favorite" width="18"> 分享收藏</a></li>
<li><a href="<?=$linkPrefix?>/my/dirs"><img src="/img/people.svg" alt="switch directory" width="18"> 切换账号</a></li>
<li><a href="<?=$linkPrefix?>/my/createdir"><img src="/img/person-add.svg" alt="add directory" width="18"> 添加账号</a></li>
<li><a href="<?=$linkPrefix?>/my/dirs"><img src="/img/people.svg" alt="switch directory" width="20"> 切换账号</a></li>
<li><a href="<?=$linkPrefix?>/my/createdir"><img src="/img/person-add.svg" alt="add directory" width="20"> 添加账号</a></li>
</ul>
</div>
</main>

40
www/js/tajian.js

@ -13,6 +13,7 @@ var taJian = { @@ -13,6 +13,7 @@ var taJian = {
addTag: '/frontapi/addtag', //添加分类
updateFavsTag: '/frontapi/updatefavstag', //修改视频的分类
deleteFav: '/frontapi/deletefav', //删除收藏的视频
createNewFav: '/frontapi/createdir', //创建新的收藏夹
sendSmsCode: '/frontapi/sendsmscode', //发送短信验证码
register: '/frontapi/createuser', //注册
login: '/frontapi/loginuser' //登入
@ -620,4 +621,43 @@ if ($('#share_form').get(0)) { @@ -620,4 +621,43 @@ if ($('#share_form').get(0)) {
});
}
// 创建新收藏夹账号
if ($('#dir_new_form').get(0)) {
$('#dir_new_form .jsbtn').click(function(e) {
e.preventDefault();
var nickname = $('input[name=nickname]').val();
if (!nickname) {
alert('请填写 2 - 5 个汉字的昵称!');
return false;
}
var bt = $(this), btLoading = bt.children('.bt_class_JS'), btText = bt.children('.bt_text_JS');
btLoading.removeClass('elementNone');
bt.prop('disabled', true);
btText.text('提交中...');
var datas = {
'nickname': nickname
};
publicAjax(taJian.apis.createNewFav, 'POST', datas, function (data) {
btLoading.addClass('elementNone');
bt.prop('disabled', false);
btText.text('保存');
if (data.code == 1) {
//alert(data.msg);
location.href = '/' + current_user_id + '/my/dirs';
} else {
alert(data.err);
}
}, function (jqXHR, textStatus, errorThrown) {
bt.prop('disabled', false);
btText.text('保存');
btLoading.addClass('elementNone');
alert('网络请求失败,请重试。');
});
});
}
})();

Loading…
Cancel
Save