|
|
@ -10,7 +10,8 @@ Class Common { |
|
|
|
'&', |
|
|
|
'&', |
|
|
|
'<', |
|
|
|
'<', |
|
|
|
'>', |
|
|
|
'>', |
|
|
|
'\/', |
|
|
|
'/', |
|
|
|
|
|
|
|
'\\', |
|
|
|
' ', |
|
|
|
' ', |
|
|
|
';', |
|
|
|
';', |
|
|
|
';', |
|
|
|
';', |
|
|
@ -47,7 +48,97 @@ Class Common { |
|
|
|
$logOk = @error_log("{$logTime} invite {$cellphone}\n", 3, "{$logDir}{$friendsLogfile}"); |
|
|
|
$logOk = @error_log("{$logTime} invite {$cellphone}\n", 3, "{$logDir}{$friendsLogfile}"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//初始化用户数据目录 |
|
|
|
//保存用户多收藏夹目录映射配置 |
|
|
|
|
|
|
|
public static function saveUserDirMap($cellphone, $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($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; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$cache_filename = __DIR__ . '/../runtime/custom_config_usermap.json'; |
|
|
|
|
|
|
|
file_put_contents($cache_filename, json_encode(compact('tajian_user_map'), JSON_PRETTY_PRINT)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取新收藏夹目录名 |
|
|
|
|
|
|
|
public static function getNewFavDir($cellphone) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$new_dir = 2000; //默认从编号2000开始 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$cache_filename = __DIR__ . '/../runtime/userCustomFavDirs.json'; |
|
|
|
|
|
|
|
if (file_exists($cache_filename)) { |
|
|
|
|
|
|
|
$json = file_get_contents($cache_filename); |
|
|
|
|
|
|
|
$data = json_decode($json, true); |
|
|
|
|
|
|
|
if (!empty($data['dir'])) { |
|
|
|
|
|
|
|
$new_dir = $data['dir'] + 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $new_dir; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//老用户创建新的收藏夹 |
|
|
|
|
|
|
|
public static function createNewFavDir($cellphone, $username, $new_dir, $nickname) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
$rootDir = __DIR__ . '/../www/' . FSC::$app['config']['content_directory']; |
|
|
|
|
|
|
|
$rootDir = str_replace("/{$username}", '', $rootDir); //获取当前收藏夹的上一级目录 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$userDir = "{$rootDir}/{$new_dir}"; //新收藏夹目录 |
|
|
|
|
|
|
|
if (is_dir($userDir)) { //如果已经存在 |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mkdir("{$userDir}/data/", 0755, true); //分享视频目录 |
|
|
|
|
|
|
|
if (!is_dir("{$userDir}/data/")) { |
|
|
|
|
|
|
|
throw new Exception("创建用户数据目录失败,请检查目录 www/" . FSC::$app['config']['content_directory'] . " 权限配置,允许PHP写入"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mkdir("{$userDir}/tags/", 0700, true); //分类目录 |
|
|
|
|
|
|
|
copy("{$rootDir}README.md", "{$userDir}/README.md"); |
|
|
|
|
|
|
|
copy("{$rootDir}README_title.txt", "{$userDir}/README_title.txt"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($nickname)) { |
|
|
|
|
|
|
|
file_put_contents("{$userDir}/README_nickname.txt", $nickname); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($_COOKIE['friends_code'])) { |
|
|
|
|
|
|
|
$friends_code = $_COOKIE['friends_code']; |
|
|
|
|
|
|
|
file_put_contents("{$userDir}/README_friendscode.txt", $friends_code); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
file_put_contents("{$userDir}/README_cellphone.txt", $cellphone); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//用户新收藏夹创建成功后,保存最新用户创建的收藏夹记录 |
|
|
|
|
|
|
|
$data = array( |
|
|
|
|
|
|
|
'dir' => $new_dir, |
|
|
|
|
|
|
|
'update' => time(), |
|
|
|
|
|
|
|
'lastUser' => $cellphone, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
$cache_filename = __DIR__ . '/../runtime/userCustomFavDirs.json'; |
|
|
|
|
|
|
|
file_put_contents($cache_filename, json_encode($data, JSON_PRETTY_PRINT)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//保存用户手机和收藏夹映射关系 |
|
|
|
|
|
|
|
self::saveUserDirMap($cellphone, $new_dir); |
|
|
|
|
|
|
|
}catch(Exception $e) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//新用户注册时初始化用户数据目录 |
|
|
|
public static function initUserData($cellphone, $friends_code = '') { |
|
|
|
public static function initUserData($cellphone, $friends_code = '') { |
|
|
|
$userDir = self::getUserDataDir($cellphone); |
|
|
|
$userDir = self::getUserDataDir($cellphone); |
|
|
|
if (!empty($userDir)) { |
|
|
|
if (!empty($userDir)) { |
|
|
@ -58,6 +149,7 @@ Class Common { |
|
|
|
$rootDir = __DIR__ . '/../www/' . FSC::$app['config']['content_directory']; |
|
|
|
$rootDir = __DIR__ . '/../www/' . FSC::$app['config']['content_directory']; |
|
|
|
$username = self::getMappedUsername($cellphone); |
|
|
|
$username = self::getMappedUsername($cellphone); |
|
|
|
$userDir = "{$rootDir}{$username}"; |
|
|
|
$userDir = "{$rootDir}{$username}"; |
|
|
|
|
|
|
|
|
|
|
|
mkdir("{$userDir}/data/", 0755, true); //分享视频目录 |
|
|
|
mkdir("{$userDir}/data/", 0755, true); //分享视频目录 |
|
|
|
if (!is_dir("{$userDir}/data/")) { |
|
|
|
if (!is_dir("{$userDir}/data/")) { |
|
|
|
throw new Exception("创建用户数据目录失败,请检查目录 www/" . FSC::$app['config']['content_directory'] . " 权限配置,允许PHP写入"); |
|
|
|
throw new Exception("创建用户数据目录失败,请检查目录 www/" . FSC::$app['config']['content_directory'] . " 权限配置,允许PHP写入"); |
|
|
@ -128,7 +220,7 @@ Class Common { |
|
|
|
|
|
|
|
|
|
|
|
public static function getNicknameByDir($dir, $username){ |
|
|
|
public static function getNicknameByDir($dir, $username){ |
|
|
|
$rootDir = __DIR__ . '/../www/' . FSC::$app['config']['content_directory']; |
|
|
|
$rootDir = __DIR__ . '/../www/' . FSC::$app['config']['content_directory']; |
|
|
|
$dirPath = str_replace($username, $dir, $rootDir); |
|
|
|
$dirPath = str_replace("/{$username}", "/{$dir}", $rootDir); |
|
|
|
$filepath = "{$dirPath}/README_nickname.txt"; |
|
|
|
$filepath = "{$dirPath}/README_nickname.txt"; |
|
|
|
|
|
|
|
|
|
|
|
$nickname = ''; |
|
|
|
$nickname = ''; |
|
|
|