mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-11-27 15:59:29 +00:00
Can update visibility level of an account image
This commit is contained in:
parent
caad9550b2
commit
0309d4f880
@ -257,6 +257,32 @@ class SettingsController {
|
|||||||
return array("success" => "The account image has been deleted!");
|
return array("success" => "The account image has been deleted!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the visibility of user account image
|
||||||
|
*
|
||||||
|
* @url POST /settings/set_account_image_visibility
|
||||||
|
*/
|
||||||
|
public function set_account_image_visibility(){
|
||||||
|
|
||||||
|
//Login required
|
||||||
|
user_login_required();
|
||||||
|
|
||||||
|
//Get the list of API visibility levels
|
||||||
|
$levels = array_flip(self::AccountImageVisibilityLevels);
|
||||||
|
$post_visibility = postString("visibility");
|
||||||
|
|
||||||
|
//Get visibility level
|
||||||
|
if(!isset($levels[$post_visibility])){
|
||||||
|
Rest_fatal_error(401, "Unrecognized visibility level !");
|
||||||
|
}
|
||||||
|
|
||||||
|
//Save visibility level
|
||||||
|
components()->accountImage->setVisibilityLevel(userID, $levels[$post_visibility]);
|
||||||
|
|
||||||
|
//Success
|
||||||
|
return array("success" => "The visibility level of the account image has been updated!");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Turn a GeneralSettings object into a valid API object
|
* Turn a GeneralSettings object into a valid API object
|
||||||
*
|
*
|
||||||
|
@ -105,7 +105,7 @@ class AccountImage {
|
|||||||
* @return int The visibility level of the account image
|
* @return int The visibility level of the account image
|
||||||
*/
|
*/
|
||||||
public function getVisibilityLevel(int $userID) : int {
|
public function getVisibilityLevel(int $userID) : int {
|
||||||
$filePath = path_user_data(cs()->config->get(self::accountImageDirConfItem)."adresse_avatars/limit_view_".$userID.".txt", TRUE);
|
$filePath = $this->getPathVisibilityFile($userID);
|
||||||
|
|
||||||
//Check restriction file
|
//Check restriction file
|
||||||
if(!file_exists($filePath))
|
if(!file_exists($filePath))
|
||||||
@ -118,6 +118,31 @@ class AccountImage {
|
|||||||
return $fileContent;
|
return $fileContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set (update) the visibility level of a an account image
|
||||||
|
*
|
||||||
|
* @param int $userID Target user ID
|
||||||
|
* @param int $level New visibility level
|
||||||
|
*/
|
||||||
|
public function setVisibilityLevel(int $userID, int $level){
|
||||||
|
|
||||||
|
//Get the name of the file that contains visibility levels
|
||||||
|
$file = $this->getPathVisibilityFile($userID);
|
||||||
|
|
||||||
|
//Check if the account image is publicy visible
|
||||||
|
if($level == AccountImageSettings::VISIBILITY_OPEN){
|
||||||
|
|
||||||
|
//We do not need visibility file
|
||||||
|
if(file_exists($file))
|
||||||
|
unlink($file);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Else append the new value to the file
|
||||||
|
file_put_contents($file, $level);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get AccountImageSettings for an account
|
* Get AccountImageSettings for an account
|
||||||
*
|
*
|
||||||
@ -207,6 +232,17 @@ class AccountImage {
|
|||||||
private function getPathMetadataFile(int $userID) : string {
|
private function getPathMetadataFile(int $userID) : string {
|
||||||
return path_user_data(cs()->config->get(self::accountImageDirConfItem)."adresse_avatars/".$userID.".txt", TRUE);
|
return path_user_data(cs()->config->get(self::accountImageDirConfItem)."adresse_avatars/".$userID.".txt", TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the system path of the file that contains visibility level restrictions
|
||||||
|
*
|
||||||
|
* @param int $userID The ID of the target user
|
||||||
|
* @return string The sys path pointing on the file
|
||||||
|
*/
|
||||||
|
private function getPathVisibilityFile(int $userID) : string {
|
||||||
|
return path_user_data(cs()->config->get(
|
||||||
|
self::accountImageDirConfItem)."adresse_avatars/limit_view_".$userID.".txt", TRUE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Register class
|
//Register class
|
||||||
|
Loading…
Reference in New Issue
Block a user