diff --git a/plugins/Common.php b/plugins/Common.php index 8836ef7..2bf1e6a 100644 --- a/plugins/Common.php +++ b/plugins/Common.php @@ -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 { 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 { } //判断用户数据目录是否存在 - 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; } diff --git a/themes/tajian/controller/FrontapiController.php b/themes/tajian/controller/FrontapiController.php index 8069ed4..5e2f852 100644 --- a/themes/tajian/controller/FrontapiController.php +++ b/themes/tajian/controller/FrontapiController.php @@ -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')); + } + } diff --git a/themes/tajian/controller/MyController.php b/themes/tajian/controller/MyController.php index 509061a..5954083 100644 --- a/themes/tajian/controller/MyController.php +++ b/themes/tajian/controller/MyController.php @@ -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 { //切换收藏夹 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 { 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')); } } \ No newline at end of file diff --git a/themes/tajian/views/my/createdir.php b/themes/tajian/views/my/createdir.php index 95467b5..3946c79 100644 --- a/themes/tajian/views/my/createdir.php +++ b/themes/tajian/views/my/createdir.php @@ -11,10 +11,14 @@ $max_num = !empty(FSC::$app['config']['tajian']['max_dir_num']) ? FSC::$app['con <<返回
+ +
此功能限VIP使用,限时免费开通请联系客服哦
+ +
-

说明:
一个手机号码最多添加 个账号,此功能限VIP用户使用。

+

说明:
一个手机号码最多添加 个账号。

+
+
+ \ No newline at end of file diff --git a/themes/tajian/views/my/switchdir.php b/themes/tajian/views/my/switchdir.php index 2f848e5..ee18541 100644 --- a/themes/tajian/views/my/switchdir.php +++ b/themes/tajian/views/my/switchdir.php @@ -15,6 +15,10 @@ if (!empty(FSC::$app['config']['multipleUserUriParse']) && !empty(FSC::$app['use
+ +
此功能限VIP使用,限时免费开通请联系客服哦
+ +
点击昵称切换:
@@ -22,8 +26,12 @@ if (!empty(FSC::$app['config']['multipleUserUriParse']) && !empty(FSC::$app['use $nickname) { + $icon = !empty($viewData['isMine'][$dir]) ? 'person-fill.svg' : 'person-check.svg'; echo <<{$dir} {$nickname} +
  • + icon of {$dir} + {$nickname} +
  • eof; } }else { @@ -33,6 +41,11 @@ eof; } ?> -

    你可以拥有多个“聚宝盆”,每个聚宝盆可以设定不同的主题。

    +

    + icon 为你创建的, + icon 为朋友共享给你的; +
    + 你可以拥有多个“聚宝盆”,为每个聚宝盆设定不同的主题。 +

    diff --git a/www/css/tajian.css b/www/css/tajian.css index ec2a0c7..b8ba2d1 100644 --- a/www/css/tajian.css +++ b/www/css/tajian.css @@ -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} diff --git a/www/img/person-check.svg b/www/img/person-check.svg new file mode 100644 index 0000000..4467182 --- /dev/null +++ b/www/img/person-check.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/www/img/person-fill.svg b/www/img/person-fill.svg new file mode 100644 index 0000000..1839eb8 --- /dev/null +++ b/www/img/person-fill.svg @@ -0,0 +1,4 @@ + + + + diff --git a/www/js/tajian.js b/www/js/tajian.js index 2a504b3..59cbb4d 100644 --- a/www/js/tajian.js +++ b/www/js/tajian.js @@ -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)) { $('#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); +} + })();