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