From b59a43bdc8e09a65322042eb455b66b0a11a0190 Mon Sep 17 00:00:00 2001 From: filesite Date: Mon, 20 May 2024 08:37:48 +0800 Subject: [PATCH] multiple fav management added --- plugins/Common.php | 55 ++++++++++++++++++++++- themes/tajian/controller/MyController.php | 34 +++++++++++++- themes/tajian/views/my/index.php | 1 + themes/tajian/views/my/switchdir.php | 34 ++++++++++++++ themes/tajian/views/site/tajian.php | 5 ++- www/img/people.svg | 4 ++ 6 files changed, 129 insertions(+), 4 deletions(-) create mode 100644 themes/tajian/views/my/switchdir.php create mode 100644 www/img/people.svg diff --git a/plugins/Common.php b/plugins/Common.php index de13db1..9fd3261 100644 --- a/plugins/Common.php +++ b/plugins/Common.php @@ -92,11 +92,18 @@ Class Common { } //根据手机号码获取映射的用户名 + //支持数组格式,一个手机号码管理多个收藏夹 public static function getMappedUsername($cellphone){ $username = $cellphone; - if (!empty(FSC::$app['config']['tajian_user_map']) && !empty(FSC::$app['config']['tajian_user_map'][$username])) { - $username = FSC::$app['config']['tajian_user_map'][$username]; + $user_map = FSC::$app['config']['tajian_user_map']; + if (!empty($user_map[$cellphone])) { + $userDirs = $user_map[$cellphone]; + if (is_string($userDirs)) { + $username = $userDirs; + }else if (is_array($userDirs) && !empty($userDirs)) { + $username = $userDirs[0]; + } }else { $username = self::getUserId($cellphone); } @@ -104,6 +111,37 @@ Class Common { return $username; } + public static function getMyDirs($cellphone){ + $userDirs = array(); + + $user_map = FSC::$app['config']['tajian_user_map']; + if (!empty($user_map[$cellphone])) { + if (is_string($user_map[$cellphone])) { + array_push($userDirs, $user_map[$cellphone]); + }else if (is_array($user_map[$cellphone])) { + $userDirs = $user_map[$cellphone]; + } + } + + return $userDirs; + } + + public static function getNicknameByDir($dir, $username){ + $rootDir = __DIR__ . '/../www/' . FSC::$app['config']['content_directory']; + $dirPath = str_replace($username, $dir, $rootDir); + $filepath = "{$dirPath}/README_nickname.txt"; + + $nickname = $username; + if (file_exists($filepath)) { + $nickname = file_get_contents($filepath); + if (!empty($nickname)) { + $nickname = trim($nickname); + } + } + + return $nickname; + } + //判断用户数据目录是否存在 public static function getUserDataDir($cellphone) { $rootDir = __DIR__ . '/../www/' . FSC::$app['config']['content_directory']; @@ -161,6 +199,19 @@ Class Common { return compact('login_time', 'username', 'friends_code', 'cellphone'); } + public static function switchUserDir($dir) { + if(session_status() !== PHP_SESSION_ACTIVE) { + session_start(); + } + + $currentDir = $_SESSION['username']; + FSC::$app['config']['content_directory'] = str_replace($currentDir, $dir, FSC::$app['config']['content_directory']); + + $_SESSION['username'] = $dir; + + return $_SESSION['username']; + } + //从session里获取用户数据 public static function getUserFromSession() { if(session_status() !== PHP_SESSION_ACTIVE) { diff --git a/themes/tajian/controller/MyController.php b/themes/tajian/controller/MyController.php index c7e82c1..d3764a6 100644 --- a/themes/tajian/controller/MyController.php +++ b/themes/tajian/controller/MyController.php @@ -8,7 +8,7 @@ require_once __DIR__ . '/SiteController.php'; Class MyController extends SiteController { - public function actionIndex($viewName = 'index', $defaultTitle = '个人中心') { + public function actionIndex($viewName = 'index', $defaultTitle = '个人中心', $viewData = array()) { //判断是否已经登录,自动跳转到自己的添加视频网址 $loginedUser = Common::getUserFromSession(); if (empty($loginedUser['username'])) { @@ -18,6 +18,14 @@ Class MyController extends SiteController { return $this->redirect($shareUrl); } + //账号切换支持 + $goDir = $this->get('dir', ''); + if (!empty($goDir) && !empty($loginedUser['cellphone'])) { + $myDirs = Common::getMyDirs($loginedUser['cellphone']); + if (in_array($goDir, $myDirs)) { + Common::switchUserDir($goDir); + } + } //获取数据 $htmlReadme = ''; //Readme.md 内容,底部网站详细介绍 @@ -62,6 +70,11 @@ Class MyController extends SiteController { 'cateId', 'dirTree', 'scanResults', 'htmlReadme', 'tags', 'nickname' ); + + if (!empty($viewData)) { + $params = array_merge($params, $viewData); + } + return $this->render($viewName, $params, $pageTitle); } @@ -100,4 +113,23 @@ Class MyController extends SiteController { return $this->actionIndex($viewName, $defaultTitle); } + //切换收藏夹 + public function actionDirs() { + $myDirs = $myNicks = 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']); + } + } + } + + $defaultTitle = "切换账号"; + $viewName = 'switchdir'; + return $this->actionIndex($viewName, $defaultTitle, compact('myDirs', 'myNicks')); + } + } \ No newline at end of file diff --git a/themes/tajian/views/my/index.php b/themes/tajian/views/my/index.php index c0db117..a797dbc 100644 --- a/themes/tajian/views/my/index.php +++ b/themes/tajian/views/my/index.php @@ -25,6 +25,7 @@ if (!empty(FSC::$app['config']['multipleUserUriParse']) && !empty(FSC::$app['use
  • favorite 管理收藏
  • collection 管理分类
  • share favorite 分享收藏
  • +
  • share favorite 切换账号
  • diff --git a/themes/tajian/views/my/switchdir.php b/themes/tajian/views/my/switchdir.php new file mode 100644 index 0000000..711a32a --- /dev/null +++ b/themes/tajian/views/my/switchdir.php @@ -0,0 +1,34 @@ +
    +
    +
    + 点击切换 +
    +
    +
      + $nickname) { + echo <<{$dir} {$nickname} +eof; + } + }else { + echo <<你还没有创建聚宝盆哦! +eof; + } + ?> +
    +
    +
    diff --git a/themes/tajian/views/site/tajian.php b/themes/tajian/views/site/tajian.php index aace6d3..66d19cc 100644 --- a/themes/tajian/views/site/tajian.php +++ b/themes/tajian/views/site/tajian.php @@ -88,7 +88,10 @@ eof;
  • 快手
  • 西瓜视频
  • -

    更多App和网站将陆续增加。。。

    +

    + 更多视频App和网站将陆续增加; +
    任意网站收藏限VIP用户使用,如需开通请联系客服邮箱(machete#filesite.io,替换#为@)。 +

    Ta荐核心数据

    diff --git a/www/img/people.svg b/www/img/people.svg new file mode 100644 index 0000000..33132d9 --- /dev/null +++ b/www/img/people.svg @@ -0,0 +1,4 @@ + + + +