diff --git a/plugins/Common.php b/plugins/Common.php index 6a2fc46..63323c5 100644 --- a/plugins/Common.php +++ b/plugins/Common.php @@ -213,6 +213,32 @@ Class Common { return true; } + //删除被共享的收藏夹 + public static function deleteSharedFavDir($friends_cellphone, $current_username, $share_dir) { + //不能删除朋友自己的收藏夹 + if (self::isMyFavDir($friends_cellphone, $current_username, $share_dir)) {return false;} + + $friends_dirs = self::getMyDirs($friends_cellphone, $current_username); + $dirs_after_delete = array_diff($friends_dirs, array($share_dir)); + + try { + $my_id = self::getUserId($friends_cellphone); + $rootDir = __DIR__ . '/../www/' . FSC::$app['config']['content_directory']; + $rootDir = str_replace("/{$current_username}", "/{$my_id}", $rootDir); //获取自己的目录 + if (!is_dir($rootDir)) { + $my_first_id = self::getMappedUsername($friends_cellphone); + $rootDir = str_replace("/{$my_id}", "/{$my_first_id}", $rootDir); //获取自己的目录 + } + + $cache_filename = "{$rootDir}/custom_config_usermap.json"; + file_put_contents($cache_filename, json_encode($dirs_after_delete, JSON_PRETTY_PRINT)); + }catch(Exception $e) { + return false; + } + + return true; + } + //新用户注册时初始化用户数据目录 public static function initUserData($cellphone, $friends_code = '') { $userDir = self::getUserDataDir($cellphone); @@ -318,7 +344,7 @@ Class Common { $cache_filename = "{$rootDir}/custom_config_usermap.json"; if (file_exists($cache_filename)) { $mapContent = file_get_contents($cache_filename); - $map = json_decode($mapContent, true); + $map = json_decode($mapContent); } } @@ -329,7 +355,7 @@ Class Common { array_merge($map, $tajian_user_map[$cellphone]) : array_push($map, $tajian_user_map[$cellphone]); } - return array_unique($map, SORT_NUMERIC); + return array_values(array_unique($map)); } public static function getNicknameByDir($dir, $username){ diff --git a/themes/tajian/controller/FrontapiController.php b/themes/tajian/controller/FrontapiController.php index 24d8fec..9e8d510 100644 --- a/themes/tajian/controller/FrontapiController.php +++ b/themes/tajian/controller/FrontapiController.php @@ -1394,6 +1394,9 @@ eof; $saved = Common::deleteFromMyShareDirs($loginedUser['cellphone'], $loginedUser['username'], $friends_cellphone, $share_dir); if ($saved !== false) { + //删除共享给朋友的,修改朋友的账号映射关系 + Common::deleteSharedFavDir($friends_cellphone, $loginedUser['username'], $share_dir); + $msg = "取消账号共享完成"; $code = 1; }else {