Browse Source

add dir share functions

master
filesite 6 months ago
parent
commit
cfc4168cea
  1. 36
      plugins/Common.php
  2. 77
      themes/tajian/controller/FrontapiController.php
  3. 49
      themes/tajian/controller/MyController.php
  4. 6
      themes/tajian/views/my/createdir.php
  5. 4
      themes/tajian/views/my/index.php
  6. 52
      themes/tajian/views/my/sharedir.php
  7. 17
      themes/tajian/views/my/switchdir.php
  8. 10
      www/css/tajian.css
  9. 5
      www/img/person-check.svg
  10. 4
      www/img/person-fill.svg
  11. 48
      www/js/tajian.js

36
plugins/Common.php

@ -69,7 +69,9 @@ Class Common { @@ -69,7 +69,9 @@ Class Common {
}
$cache_filename = __DIR__ . '/../runtime/custom_config_usermap.json';
file_put_contents($cache_filename, json_encode(compact('tajian_user_map'), JSON_PRETTY_PRINT));
$saved = file_put_contents($cache_filename, json_encode(compact('tajian_user_map'), JSON_PRETTY_PRINT));
return $saved === false ? false : true;
}
//获取新收藏夹目录名
@ -171,6 +173,29 @@ Class Common { @@ -171,6 +173,29 @@ Class Common {
return true;
}
//判断某个收藏夹是否属于当前用户
public static function isMyFavDir($cellphone, $username, $fav_dir) {
try {
$rootDir = __DIR__ . '/../www/' . FSC::$app['config']['content_directory'];
$rootDir = str_replace("/{$username}", '', $rootDir); //获取当前收藏夹的上一级目录
$userDir = "{$rootDir}/{$fav_dir}"; //目标收藏夹目录
if (!is_dir($userDir)) { //如果不存在
return false;
}
$filepath = "{$userDir}/README_cellphone.txt";
$content = file_get_contents($filepath);
if (!empty($content) && strpos($content, $cellphone) !== false) {
return true;
}
}catch(Exception $e) {
return false;
}
return false;
}
//根据手机号码获取用户名ID
//规则:前6位对 97 求余数,再拼接后5位
public static function getUserId($cellphone){
@ -235,11 +260,16 @@ Class Common { @@ -235,11 +260,16 @@ Class Common {
}
//判断用户数据目录是否存在
public static function getUserDataDir($cellphone) {
public static function getUserDataDir($cellphone, $currentUsername = '') {
$rootDir = __DIR__ . '/../www/' . FSC::$app['config']['content_directory'];
$username = self::getMappedUsername($cellphone);
$userDir = "{$rootDir}{$username}";
if (!empty($currentUsername)) {
$userDir = str_replace("/{$currentUsername}", "/{$username}", $rootDir);
}else {
$userDir = "{$rootDir}{$username}";
}
return is_dir($userDir) ? $userDir : false;
}

77
themes/tajian/controller/FrontapiController.php

@ -1253,5 +1253,82 @@ eof; @@ -1253,5 +1253,82 @@ eof;
return $this->renderJson(compact('code', 'msg', 'err'));
}
//账号共享接口
public function actionSharedir() {
$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,请求地址有误');
}
//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)) {
$friends_cellphone = $this->post('cellphone', '');
$share_dir = $this->post('dir', '');
if (empty($friends_cellphone) || Common::isCellphoneNumber($friends_cellphone) == false) {
$err = "请填写正确的手机号码";
}else if (empty($share_dir)) {
$err = "请选择要共享的账号";
}else if ($friends_cellphone == $loginedUser['cellphone']) {
$err = "只能共享给朋友,不能共享给自己哦";
}
//只能共享属于自己的账号
if (empty($err)) {
$isMine = Common::isMyFavDir($loginedUser['cellphone'], $loginedUser['username'], $share_dir);
if (empty($isMine)) {
$err = '只能共享自己的账号,朋友共享给你的账号不能再共享给他人';
}else {
//检查朋友的账号是否存在
$friend_exist = Common::getUserDataDir($friends_cellphone, $loginedUser['username']);
if (empty($friend_exist)) {
$err = "{$friends_cellphone} 还没注册哦,请朋友先注册吧";
}
}
}
if (empty($err)) { //如果数据检查通过,尝试保存
$saved = Common::saveUserDirMap($friends_cellphone, $share_dir);
if ($saved !== false) {
$msg = "账号共享完成";
$code = 1;
}else {
$err = "账号共享失败,请稍后重试";
}
}
}
return $this->renderJson(compact('code', 'msg', 'err'));
}
}

49
themes/tajian/controller/MyController.php

@ -66,10 +66,13 @@ Class MyController extends SiteController { @@ -66,10 +66,13 @@ Class MyController extends SiteController {
//昵称支持
$nickname = $this->getNickname($readmeFile);
//显示手机号码
$cellphone_hide = preg_replace("/^(.{3,})\d{4}(.{4})$/i", '$1****$2', $loginedUser['cellphone']);
$pageTitle = "{$defaultTitle} | " . FSC::$app['config']['site_name'];
$params = compact(
'cateId', 'dirTree', 'scanResults',
'htmlReadme', 'tags', 'nickname'
'htmlReadme', 'tags', 'nickname', 'cellphone_hide'
);
if (!empty($viewData)) {
@ -123,7 +126,7 @@ Class MyController extends SiteController { @@ -123,7 +126,7 @@ Class MyController extends SiteController {
//切换收藏夹
public function actionDirs() {
$myDirs = $myNicks = array();
$myDirs = $myNicks = $isMine = array();
$loginedUser = Common::getUserFromSession();
if (!empty($loginedUser['cellphone'])) {
@ -131,28 +134,60 @@ Class MyController extends SiteController { @@ -131,28 +134,60 @@ Class MyController extends SiteController {
if (!empty($myDirs)) {
foreach($myDirs as $dir) {
$myNicks[$dir] = Common::getNicknameByDir($dir, $loginedUser['username']);
$isMine[$dir] = Common::isMyFavDir($loginedUser['cellphone'], $loginedUser['username'], $dir);
}
}
}
//VIP身份判断
$isVipUser = true;
if (empty($loginedUser['cellphone']) || !in_array($loginedUser['cellphone'], FSC::$app['config']['tajian_vip_user'])) {
$isVipUser = false;
}
$defaultTitle = "切换账号";
$viewName = 'switchdir';
return $this->actionIndex($viewName, $defaultTitle, compact('myDirs', 'myNicks'));
return $this->actionIndex($viewName, $defaultTitle, compact('myDirs', 'myNicks', 'isMine', 'isVipUser'));
}
//添加收藏夹
public function actionCreatedir() {
$myDirs = $myNicks = array();
//VIP身份判断
$loginedUser = Common::getUserFromSession();
$isVipUser = true;
if (empty($loginedUser['cellphone']) || !in_array($loginedUser['cellphone'], FSC::$app['config']['tajian_vip_user'])) {
throw new Exception('Oops,你还不是VIP,请联系首页底部客服邮箱开通。');
$isVipUser = false;
}
$defaultTitle = "添加账号";
$viewName = 'createdir';
return $this->actionIndex($viewName, $defaultTitle);
return $this->actionIndex($viewName, $defaultTitle, compact('isVipUser'));
}
//共享收藏夹
public function actionSharedir() {
$myDirs = $myNicks = $isMine = array();
$loginedUser = Common::getUserFromSession();
if (!empty($loginedUser['cellphone'])) {
$myDirs = Common::getMyDirs($loginedUser['cellphone']);
if (!empty($myDirs)) {
foreach($myDirs as $dir) {
$myNicks[$dir] = Common::getNicknameByDir($dir, $loginedUser['username']);
$isMine[$dir] = Common::isMyFavDir($loginedUser['cellphone'], $loginedUser['username'], $dir);
}
}
}
//VIP身份判断
$isVipUser = true;
if (empty($loginedUser['cellphone']) || !in_array($loginedUser['cellphone'], FSC::$app['config']['tajian_vip_user'])) {
$isVipUser = false;
}
$defaultTitle = "共享账号";
$viewName = 'sharedir';
return $this->actionIndex($viewName, $defaultTitle, compact('myDirs', 'myNicks', 'isMine', 'isVipUser'));
}
}

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

@ -11,10 +11,14 @@ $max_num = !empty(FSC::$app['config']['tajian']['max_dir_num']) ? FSC::$app['con @@ -11,10 +11,14 @@ $max_num = !empty(FSC::$app['config']['tajian']['max_dir_num']) ? FSC::$app['con
<a href="<?=$linkPrefix?>/my/">&lt;&lt;返回</a>
</div>
<form class="g_form_style mt65" id="dir_new_form" action="" method="POST">
<?php if (empty($viewData['isVipUser'])) { ?>
<div class="alert warning">此功能限VIP使用,限时免费开通请联系客服哦</div>
<?php } ?>
<div class="mb-3 pt20">
<label for="text_input_dir" class="form-label">账号昵称</label>
<input id="text_input_dir" name="nickname" placeholder="请填写 2 - 5 个汉字" value="">
<p class="mt10">说明:<br>一个手机号码最多添加 <strong><?=$max_num?></strong> 个账号,此功能限VIP用户使用。</p>
<p class="mt10">说明:<br>一个手机号码最多添加 <strong><?=$max_num?></strong> 个账号。</p>
</div>
<div class="avform_bt">
<button class="jsbtn" aria-label="保存" type="submit">

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

@ -12,6 +12,7 @@ if (!empty(FSC::$app['config']['multipleUserUriParse']) && !empty(FSC::$app['use @@ -12,6 +12,7 @@ if (!empty(FSC::$app['config']['multipleUserUriParse']) && !empty(FSC::$app['use
?><main class="g_main_lay">
<div class="g_form_style">
<div class="vercenter">
<span><?=htmlspecialchars($viewData['cellphone_hide'], ENT_QUOTES)?></span>
<strong class="nickname"><?=htmlspecialchars($viewData['nickname'], ENT_QUOTES)?></strong>
(<a href="<?=$linkPrefix?>/my/setnickname">修改</a>)
<p class="mt10 verright">
@ -25,8 +26,9 @@ if (!empty(FSC::$app['config']['multipleUserUriParse']) && !empty(FSC::$app['use @@ -25,8 +26,9 @@ if (!empty(FSC::$app['config']['multipleUserUriParse']) && !empty(FSC::$app['use
<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="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="20"> 切换账号</a></li>
<li><a href="<?=$linkPrefix?>/my/createdir"><img src="/img/person-add.svg" alt="add directory" width="20"> 添加账号</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/sharedir"><img src="/img/person-check.svg" alt="share directory to someone" width="20"> 共享账号</a></li>
</ul>
</div>
</main>

52
themes/tajian/views/my/sharedir.php

@ -0,0 +1,52 @@ @@ -0,0 +1,52 @@
<?php
$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>
</div>
<form class="g_form_style mt65" id="share_dir_form" action="" method="POST">
<?php if (empty($viewData['isVipUser'])) { ?>
<div class="alert warning">此功能限VIP使用,限时免费开通请联系客服哦</div>
<?php } ?>
<div class="mb-3 pt20">
<label for="text_input_phone" class="form-label">朋友手机号码</label>
<input id="text_input_phone" name="cellphone" placeholder="请填写朋友的手机号码" value="">
</div>
<div class="mb-3 pt20">
<select name="dir">
<option value="">选择账号</option>
<?php if (!empty($viewData['myNicks'])) {
foreach($viewData['myNicks'] as $dir => $nickname) {
//忽略不属于自己的账号
if (!empty($viewData['isMine']) && empty($viewData['isMine'][$dir])) {continue;}
echo <<<eof
<option value="{$dir}">{$nickname}</option>
eof;
}
} ?>
</select>
</div>
<p class="mt10">说明:<br>把聚宝盆共享给朋友之后,你们可以共同维护里面的内容。</p>
<div class="avform_bt">
<button class="jsbtn" aria-label="保存" type="submit">
<div class="loading_bt bt_class_JS elementNone verMiddle">
<svg viewBox="25 25 50 50">
<circle cx="50" cy="50" r="20"></circle>
</svg>
</div>
<span class="bt_text_JS">保存</span>
<div class="bt_loading_cover bt_class_JS elementNone"></div>
</button>
</div>
</form>
</main>

17
themes/tajian/views/my/switchdir.php

@ -15,6 +15,10 @@ if (!empty(FSC::$app['config']['multipleUserUriParse']) && !empty(FSC::$app['use @@ -15,6 +15,10 @@ if (!empty(FSC::$app['config']['multipleUserUriParse']) && !empty(FSC::$app['use
</div>
<div class="g_form_style">
<?php if (empty($viewData['isVipUser'])) { ?>
<div class="alert warning">此功能限VIP使用,限时免费开通请联系客服哦</div>
<?php } ?>
<div>
点击昵称切换:
</div>
@ -22,8 +26,12 @@ if (!empty(FSC::$app['config']['multipleUserUriParse']) && !empty(FSC::$app['use @@ -22,8 +26,12 @@ if (!empty(FSC::$app['config']['multipleUserUriParse']) && !empty(FSC::$app['use
<?php
if (!empty($viewData['myNicks'])) {
foreach($viewData['myNicks'] as $dir => $nickname) {
$icon = !empty($viewData['isMine'][$dir]) ? 'person-fill.svg' : 'person-check.svg';
echo <<<eof
<li><a href="{$linkPrefix}/my/index?dir={$dir}">{$dir} {$nickname}</a></li>
<li><a href="{$linkPrefix}/my/index?dir={$dir}">
<img src="/img/{$icon}" alt="icon of {$dir}" width="16">
{$nickname}
</a></li>
eof;
}
}else {
@ -33,6 +41,11 @@ eof; @@ -33,6 +41,11 @@ eof;
}
?>
</ul>
<p class="mt20">你可以拥有多个“聚宝盆”,每个聚宝盆可以设定不同的主题。</p>
<p class="mt20">
<img src="/img/person-fill.svg" alt="icon" width="20" class="verBottom"> 为你创建的,
<img src="/img/person-check.svg" alt="icon" width="20" class="verBottom"> 为朋友共享给你的;
<br>
你可以拥有多个“聚宝盆”,为每个聚宝盆设定不同的主题。
</p>
</div>
</main>

10
www/css/tajian.css

@ -263,10 +263,12 @@ select.tagselect{max-width:100%} @@ -263,10 +263,12 @@ select.tagselect{max-width:100%}
.stats .col{display:inline-block;padding:13px 4px;width:30%;max-width:128px;background:#444;color:#FFF;margin-right:4px;margin-bottom:6px;text-align:center}
.stats .col strong{font-size:28px}
.stats .col label{display:block;font-size:15px}
.stats .info{background-color:darkblue}
.stats .success{background-color:green}
.stats .warning{background-color:orange;color:#444}
.stats .danger{background-color:red}
.info{background-color:darkblue}
.success{background-color:green}
.warning{background-color:#332701;border-color:#997404}
.danger{background-color:red}
.alert{padding: 1em;border:1px solid;border-radius:5px}
.alert.warning{color:#ffda6a}
/* 注册/登录 */
.twocol label{display:block}

5
www/img/person-check.svg

@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-person-check" viewBox="0 0 16 16">
<path d="M12.5 16a3.5 3.5 0 1 0 0-7 3.5 3.5 0 0 0 0 7m1.679-4.493-1.335 2.226a.75.75 0 0 1-1.174.144l-.774-.773a.5.5 0 0 1 .708-.708l.547.548 1.17-1.951a.5.5 0 1 1 .858.514M11 5a3 3 0 1 1-6 0 3 3 0 0 1 6 0M8 7a2 2 0 1 0 0-4 2 2 0 0 0 0 4"/>
<path d="M8.256 14a4.5 4.5 0 0 1-.229-1.004H3c.001-.246.154-.986.832-1.664C4.484 10.68 5.711 10 8 10q.39 0 .74.025c.226-.341.496-.65.804-.918Q8.844 9.002 8 9c-5 0-6 3-6 4s1 1 1 1z"/>
</svg>

After

Width:  |  Height:  |  Size: 605 B

4
www/img/person-fill.svg

@ -0,0 +1,4 @@ @@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-person-fill" viewBox="0 0 16 16">
<path d="M3 14s-1 0-1-1 1-4 6-4 6 3 6 4-1 1-1 1zm5-6a3 3 0 1 0 0-6 3 3 0 0 0 0 6"/>
</svg>

After

Width:  |  Height:  |  Size: 262 B

48
www/js/tajian.js

@ -14,6 +14,8 @@ var taJian = { @@ -14,6 +14,8 @@ var taJian = {
updateFavsTag: '/frontapi/updatefavstag', //修改视频的分类
deleteFav: '/frontapi/deletefav', //删除收藏的视频
createNewFav: '/frontapi/createdir', //创建新的收藏夹
shareFav2Friend: '/frontapi/sharedir', //共享收藏夹给朋友
sendSmsCode: '/frontapi/sendsmscode', //发送短信验证码
register: '/frontapi/createuser', //注册
login: '/frontapi/loginuser' //登入
@ -658,4 +660,50 @@ if ($('#dir_new_form').get(0)) { @@ -658,4 +660,50 @@ if ($('#dir_new_form').get(0)) {
$('#dir_new_form').submit(handle_new_dir);
}
// 共享收藏夹账号
if ($('#share_dir_form').get(0)) {
var handle_share_dir = function(e) {
e.preventDefault();
var cellphone = $('input[name=cellphone]').val(),
favName = $('select[name=dir]').val();
if (!cellphone) {
alert('请填写需要共享的朋友手机号码!');
return false;
}else if (!favName) {
alert('请选择需要共享的账号!');
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 = {
'cellphone': cellphone,
'dir': favName
};
publicAjax(taJian.apis.shareFav2Friend, 'POST', datas, function (data) {
btLoading.addClass('elementNone');
bt.prop('disabled', false);
btText.text('保存');
if (data.code == 1) {
location.href = '/' + current_user_id + '/my/';
} else {
alert(data.err);
}
}, function (jqXHR, textStatus, errorThrown) {
bt.prop('disabled', false);
btText.text('保存');
btLoading.addClass('elementNone');
alert('网络请求失败,请重试。');
});
};
$('#share_dir_form .jsbtn').click(handle_share_dir);
$('#share_dir_form').submit(handle_share_dir);
}
})();

Loading…
Cancel
Save