|
|
|
@ -50,36 +50,23 @@ Class Common {
@@ -50,36 +50,23 @@ Class Common {
|
|
|
|
|
|
|
|
|
|
//保存用户多收藏夹目录映射配置 |
|
|
|
|
public static function saveUserDirMap($cellphone, $username, $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(); |
|
|
|
|
|
|
|
|
|
$defaultDir = self::getUserId($cellphone); //先获取用户自己的目录 |
|
|
|
|
if (self::existUserDataDir($defaultDir, $username)) { |
|
|
|
|
array_push($map, $defaultDir); |
|
|
|
|
} |
|
|
|
|
$my_user_map = self::getMyDirs($cellphone, $username); |
|
|
|
|
array_push($my_user_map, $new_dir); |
|
|
|
|
|
|
|
|
|
if ($new_dir != $defaultDir) { |
|
|
|
|
array_push($map, $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); |
|
|
|
|
$my_id = self::getUserId($cellphone); |
|
|
|
|
$rootDir = __DIR__ . '/../www/' . FSC::$app['config']['content_directory']; |
|
|
|
|
$rootDir = str_replace("/{$username}", "/{$my_id}", $rootDir); //获取自己的目录 |
|
|
|
|
if (!is_dir($rootDir)) { |
|
|
|
|
$my_first_id = self::getMappedUsername($cellphone); |
|
|
|
|
$rootDir = str_replace("/{$my_id}", "/{$my_first_id}", $rootDir); //获取自己的目录 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$tajian_user_map[$cellphone] = $map; |
|
|
|
|
$saved = false; |
|
|
|
|
if (is_dir($rootDir)) { |
|
|
|
|
$cache_filename = "{$rootDir}/custom_config_usermap.json"; |
|
|
|
|
$saved = file_put_contents($cache_filename, json_encode($my_user_map, JSON_PRETTY_PRINT)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$cache_filename = __DIR__ . '/../runtime/custom_config_usermap.json'; |
|
|
|
|
$saved = file_put_contents($cache_filename, json_encode(compact('tajian_user_map'), JSON_PRETTY_PRINT)); |
|
|
|
|
|
|
|
|
|
return $saved === false ? false : true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -236,19 +223,35 @@ Class Common {
@@ -236,19 +223,35 @@ Class Common {
|
|
|
|
|
return $username; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static function getMyDirs($cellphone){ |
|
|
|
|
$userDirs = array(); |
|
|
|
|
//从自己的目录里获取收藏夹映射关系 |
|
|
|
|
//返回:数组 |
|
|
|
|
public static function getMyDirs($cellphone, $username){ |
|
|
|
|
$map = 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]; |
|
|
|
|
$my_id = self::getUserId($cellphone); |
|
|
|
|
$rootDir = __DIR__ . '/../www/' . FSC::$app['config']['content_directory']; |
|
|
|
|
$rootDir = str_replace("/{$username}", "/{$my_id}", $rootDir); //获取自己的目录 |
|
|
|
|
if (!is_dir($rootDir)) { |
|
|
|
|
$my_first_id = self::getMappedUsername($cellphone); |
|
|
|
|
$rootDir = str_replace("/{$my_id}", "/{$my_first_id}", $rootDir); //获取自己的目录 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (is_dir($rootDir)) { |
|
|
|
|
$cache_filename = "{$rootDir}/custom_config_usermap.json"; |
|
|
|
|
if (file_exists($cache_filename)) { |
|
|
|
|
$mapContent = file_get_contents($cache_filename); |
|
|
|
|
$map = json_decode($mapContent, true); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//跟公用配置合并 |
|
|
|
|
$tajian_user_map = FSC::$app['config']['tajian_user_map']; |
|
|
|
|
if (!empty($tajian_user_map[$cellphone])) { |
|
|
|
|
$map = is_array($tajian_user_map[$cellphone]) ? |
|
|
|
|
array_merge($map, $tajian_user_map[$cellphone]) : array_push($map, $tajian_user_map[$cellphone]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $userDirs; |
|
|
|
|
return array_unique($map); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static function getNicknameByDir($dir, $username){ |
|
|
|
|