mirror of
				https://github.com/pierre42100/ComunicAPI
				synced 2025-11-04 12:14:12 +00:00 
			
		
		
		
	Created components class & default userID
This commit is contained in:
		
							
								
								
									
										34
									
								
								classes/components.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								classes/components.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,34 @@
 | 
			
		||||
<?php
 | 
			
		||||
/**
 | 
			
		||||
 * Components unificator
 | 
			
		||||
 *
 | 
			
		||||
 * @author Pierre HUBERT
 | 
			
		||||
 */
 | 
			
		||||
class Components {
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * A static table that contains all the object
 | 
			
		||||
	 *
 | 
			
		||||
	 * @var array
 | 
			
		||||
	 */
 | 
			
		||||
	private static $objects = array();
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Public constructor
 | 
			
		||||
	 */
 | 
			
		||||
	public function __construct(){
 | 
			
		||||
		//Transform static object into dynamic object
 | 
			
		||||
		foreach(self::$objects as $name=>$object)
 | 
			
		||||
			$this->{$name} = $object;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Class registration
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param String $className The name of the class to register
 | 
			
		||||
	 * @param Object $object The object to register
 | 
			
		||||
	 */
 | 
			
		||||
	public static function register($className, $object){
 | 
			
		||||
		self::$objects[$className] = $object;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										21
									
								
								classes/components/accountImage.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								classes/components/accountImage.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
			
		||||
<?php
 | 
			
		||||
/**
 | 
			
		||||
 * Account image class
 | 
			
		||||
 *
 | 
			
		||||
 * @author Pierre HUBERT
 | 
			
		||||
 */
 | 
			
		||||
class accountImage{
 | 
			
		||||
	/**
 | 
			
		||||
	 * Public constructor
 | 
			
		||||
	 */
 | 
			
		||||
	public function __construct(){
 | 
			
		||||
		//Nothing now
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function test(){
 | 
			
		||||
		return "test";
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//Register class
 | 
			
		||||
Components::register("accountImage", new accountImage());
 | 
			
		||||
@@ -16,6 +16,10 @@ function user_login_required(){
 | 
			
		||||
        Rest_fatal_error(401, "This function requires user to be logged in!");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Check if userID is the number 0
 | 
			
		||||
    if(userID == 0)
 | 
			
		||||
        Rest_fatal_error(401, "This function requires user to be logged in!");
 | 
			
		||||
 | 
			
		||||
    //User logged in
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
@@ -23,12 +23,12 @@ require PROJECT_PATH."3rdparty/RestServer/RestServer.php";
 | 
			
		||||
//Allow remote requests
 | 
			
		||||
header("Access-Control-Allow-Origin: *");
 | 
			
		||||
 | 
			
		||||
//By default format is json
 | 
			
		||||
//By default return format is json
 | 
			
		||||
if(!isset($_GET["format"]))
 | 
			
		||||
	$_GET['format'] = "json";
 | 
			
		||||
 | 
			
		||||
//Check client tokens
 | 
			
		||||
if($cs->config->get("site_mode") == "debug"){
 | 
			
		||||
if($cs->config->get("site_mode") == "debug"){ //DEBUG ONLY
 | 
			
		||||
	$_POST['serviceName'] = "testService";
 | 
			
		||||
	$_POST['serviceToken'] = "testPasswd";
 | 
			
		||||
}
 | 
			
		||||
@@ -50,6 +50,10 @@ if(isset($_POST['userToken1']) AND isset($_POST['userToken2'])){
 | 
			
		||||
	//Else save userID
 | 
			
		||||
	define("userID", $userID);
 | 
			
		||||
}
 | 
			
		||||
else {
 | 
			
		||||
	//Defined userID is number 0
 | 
			
		||||
	define("userID", 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Handle Rest requests
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										12
									
								
								init.php
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								init.php
									
									
									
									
									
								
							@@ -13,6 +13,11 @@ 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;
 | 
			
		||||
@@ -53,4 +58,9 @@ unset($tokens);
 | 
			
		||||
//Add user object
 | 
			
		||||
$user = new User();
 | 
			
		||||
$cs->register("user", $user);
 | 
			
		||||
unset($user);
 | 
			
		||||
unset($user);
 | 
			
		||||
 | 
			
		||||
//Add components object
 | 
			
		||||
$components = new Components();
 | 
			
		||||
$cs->register("components", $components);
 | 
			
		||||
unset($components);
 | 
			
		||||
		Reference in New Issue
	
	Block a user