diff --git a/classes/components/accountImage.php b/classes/components/accountImage.php index ae7b008..f53f23d 100644 --- a/classes/components/accountImage.php +++ b/classes/components/accountImage.php @@ -5,21 +5,102 @@ * @author Pierre HUBERT */ class accountImage{ + + /** + * @var String $accountImageURL URL path pointing on image accounts + */ + private $accountImageURL; + + /** + * @var String $accountImagePath URL path pointing on image accounts + */ + private $accountImagePath; + + /** + * @var String $defaultAccountImage name of the default account image + */ + private $defaultAccountImage = "0Reverse.png"; + + /** + * @var String $defaultAccountImage name of the error account image + */ + private $errorAccountImage = "0Red.png"; + /** * Public constructor */ public function __construct(){ - //Nothing now + //Set values + $this->accountImageURL = path_user_data(CS::get()->config->get("imageAccountPath"), false); + $this->accountImagePath = path_user_data(CS::get()->config->get("imageAccountPath"), true); } /** * Returns the path of an account image * * @param Integer $userID The ID of the user on which we perform research - * @return String The URL pointing on the avatar + * @return String The URL pointing on the account image */ public function getPath($userID){ - return path_account_image("0Reverse.png"); + //First, check if the account image exists + $accountImageFileName = $this->accountImagePath."adresse_avatars/".$userID.".txt"; + if(file_exists($accountImageFileName)){ + + //Get account image path + $accountImageFile = $this->accountImageURL.file_get_contents($accountImageFileName); + + //Get account image visibility level + $visibilityLevel = $this->visibilityLevel($userID); + + //If account image is open + if($visibilityLevel == 3) + //Account image is OPEN + return $accountImageFile; + + //If the user just requires user to be in + if($visibilityLevel == 2){ + if(userID != 0) + return $accountImageFile; + else + return $this->accountImageURL.$this->errorAccountImage; + } + + //Else users must be friends + if($visibilityLevel == 1){ + //Level not implemented yet + return $this->accountImageURL.$this->errorAccountImage; + } + } + else + //Return default account image + return $this->accountImageURL.$this->defaultAccountImage; + } + + /** + * Get visibilty level of the account image + * + * 1. The user and his friend ONLY + * 2. User, friends, and logged in users + * 3. Everybody + * + * @param Integer $userID The ID of the user on which we perform researchs + * @return Integer The visibility level of the account image + */ + private function visibilityLevel($userID){ + $filePath = $this->accountImagePath."adresse_avatars/limit_view_".$userID.".txt"; + + //Check restriction file + if(!file_exists($filePath)) + return 3; //Everybody by default + + //Check for personnalized level + $fileContent = file_get_contents($filePath); + if($fileContent == 1 || $fileContent == 2){ + //Return new visibility level + return $fileContent*1; + } + else + return 3; //Everybody by default } } diff --git a/config/main.php b/config/main.php index 0815c1a..8ebb75f 100644 --- a/config/main.php +++ b/config/main.php @@ -23,7 +23,7 @@ $config->set("storage_url", "http://devweb.local/comunic/current/user_data/"); * * The path (on the server) pointing of the user_data folder */ -$config->set("storage_path", "/home/pierre/Documents/projets_web/comunic/current/user_data"); +$config->set("storage_path", "/home/pierre/Documents/projets_web/comunic/current/user_data/"); /** * Database credentials diff --git a/helpers/userData.php b/helpers/userData.php index e23051a..ef1841e 100644 --- a/helpers/userData.php +++ b/helpers/userData.php @@ -17,15 +17,4 @@ function path_user_data($fileURI = "", $systemPath = false){ return CS::get()->config->get("storage_url").$fileURI; else return CS::get()->config->get("storage_path").$fileURI; -} - -/** - * Get and return the URL path to a specified account image - * - * @param String $imageURI Optionnal, defines URI of the image - * @param Boolean $systemPath Optionnal, defines if system path is required instead of URL - * @return String The full URL to the image account file - */ -function path_account_image($imageURI="", $systemPath = false){ - return path_user_data(CS::get()->config->get("imageAccountPath").$imageURI, $systemPath); } \ No newline at end of file diff --git a/init.php b/init.php index 73e05d7..f21ec1a 100644 --- a/init.php +++ b/init.php @@ -13,11 +13,6 @@ foreach(glob(PROJECT_PATH."classes/*.php") as $classFile){ require_once $classFile; } -//Include components -foreach(glob(PROJECT_PATH."classes/components/*.php") as $classFile){ - require_once $classFile; -} - //Include functions foreach(glob(PROJECT_PATH."functions/*.php") as $funcFile){ require_once $funcFile; @@ -60,6 +55,11 @@ $user = new User(); $cs->register("user", $user); unset($user); +//Include components +foreach(glob(PROJECT_PATH."classes/components/*.php") as $classFile){ + require_once $classFile; +} + //Add components object $components = new Components(); $cs->register("components", $components);