Skip to content

Commit

Permalink
Merged release/Version_1.0.0 into master
Browse files Browse the repository at this point in the history
  • Loading branch information
loulou123546 committed Jan 18, 2017
2 parents c342155 + b742a32 commit bc9a13d
Show file tree
Hide file tree
Showing 4 changed files with 300 additions and 0 deletions.
21 changes: 21 additions & 0 deletions DOWNLOAD/source/Datas.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
class Datas {
private static $config = array("password" => "PASSWORD","path" => "data/");
public static function get_ALL ($password,$db){if(self::connect($password)){return json_decode(self::get_content($db),true);}else{return false;}}
public static function set_ALL ($password,$db,$value,$isJSON = false){if(self::connect($password)){if($isJSON == true){self::set_content($db,$value);}else{self::set_content($db,json_encode($value));}return true;}else{return false;}}
public static function new_DB ($password,$db){if(self::connect($password)){return self::set_content($db,'{"INFO":{"VERSION":"1.0.0","LASTCHANGE":"01/01/2000"},"DATA":[]}');}else{return false;}}
public static function delete_DB ($password,$db){return unlink(self::$config['path'].$db.".json");}
public static function get_INFO ($password,$db){if(self::connect($password)){$result = json_decode(self::get_content($db),true);return $result['INFO'];}else{return false;}}
public static function set_INFO ($password,$db,$version,$lastchange){if(self::connect($password)){$result = json_decode(self::get_content($db),true);$result['INFO']['VERSION'] = $version;$result['INFO']['LASTCHANGE'] = $lastchange;self::set_content($db,json_encode($result));return true;}else{return false;}}
public static function get_DATA ($password,$db){if(self::connect($password)){$result = json_decode(self::get_content($db),true);return $result['DATA'];}else{return false;}}
public static function set_DATA ($password,$db,$value,$isJSON = false){if(self::connect($password)){$result = json_decode(self::get_content($db),true);if($isJSON){$value = json_decode($value,true);}$result['DATA'] = $value;self::set_content($db,json_encode($result));return true;}else{return false;}}
public static function add_ITEM ($password,$db,$value,$isJSON = false){if(self::connect($password)){$content = json_decode(self::get_content($db),true);if($isJSON){$content['DATA'][] = json_decode($value,true);}else{$content['DATA'][] = $value;}self::set_content($db,json_encode($content));return count($content['DATA'])-1;}else{return false;}}
public static function delete_ITEM ($password,$db,$ID){if(self::connect($password)){$content = json_decode(self::get_content($db),true);array_splice($content['DATA'],$ID,1);self::set_content($db,json_encode($content));return true;}else{return false;}}
public static function get_ITEM ($password,$db,$ID){if(self::connect($password)){$content = json_decode(self::get_content($db),true);return $content['DATA'][$ID];}else{return false;}}
public static function set_ITEM ($password,$db,$ID,$value,$isJSON = false){if(self::connect($password)){$content = json_decode(self::get_content($db),true);if($isJSON){$content['DATA'][$ID] = json_decode($value,true);}else{$content['DATA'][$ID] = $value;}self::set_content($db,json_encode($content));return true;}else{return false;}}
public static function find_ID ($password,$db,$value){if(self::connect($password)){$content = json_decode(self::get_content($db),true);$result = array();foreach($content['DATA'] as $ID => $item){$valid = true;foreach($value as $rule){if(eval("if(\$item".$rule."){return true;}else{return false;}") == false){$valid = false;}}if($valid){$result[] = $ID;}}return $result;}else{return false;}}
public static function find_ITEM ($password,$db,$value){if(self::connect($password)){$content = json_decode(self::get_content($db),true);$result = array();foreach($content['DATA'] as $ID => $item){$valid = true;foreach($value as $rule){if(eval("if(\$item".$rule."){return true;}else{return false;}") == false){$valid = false;}}if($valid){$result[] = $item;}}return $result;}else{return false;}}
private static function connect ($password){if(self::$config['password'] === $password){return true;}else{return false;}}
private static function get_content ($db){if(file_exists(self::$config['path'].$db.".json")){$file = fopen(self::$config['path'].$db.".json","r");$content = fread($file,filesize(self::$config['path'].$db.".json"));fclose($file);return $content;}else{return false;}}
private static function set_content ($db,$value = ""){$file = fopen(self::$config['path'].$db.".json","w");fwrite($file,$value);fclose($file);return true;}}
?>
21 changes: 21 additions & 0 deletions Demo/exemple/Datas.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
class Datas {
private static $config = array("password" => "PASSWORD","path" => "data/");
public static function get_ALL ($password,$db){if(self::connect($password)){return json_decode(self::get_content($db),true);}else{return false;}}
public static function set_ALL ($password,$db,$value,$isJSON = false){if(self::connect($password)){if($isJSON == true){self::set_content($db,$value);}else{self::set_content($db,json_encode($value));}return true;}else{return false;}}
public static function new_DB ($password,$db){if(self::connect($password)){return self::set_content($db,'{"INFO":{"VERSION":"1.0.0","LASTCHANGE":"01/01/2000"},"DATA":[]}');}else{return false;}}
public static function delete_DB ($password,$db){return unlink(self::$config['path'].$db.".json");}
public static function get_INFO ($password,$db){if(self::connect($password)){$result = json_decode(self::get_content($db),true);return $result['INFO'];}else{return false;}}
public static function set_INFO ($password,$db,$version,$lastchange){if(self::connect($password)){$result = json_decode(self::get_content($db),true);$result['INFO']['VERSION'] = $version;$result['INFO']['LASTCHANGE'] = $lastchange;self::set_content($db,json_encode($result));return true;}else{return false;}}
public static function get_DATA ($password,$db){if(self::connect($password)){$result = json_decode(self::get_content($db),true);return $result['DATA'];}else{return false;}}
public static function set_DATA ($password,$db,$value,$isJSON = false){if(self::connect($password)){$result = json_decode(self::get_content($db),true);if($isJSON){$value = json_decode($value,true);}$result['DATA'] = $value;self::set_content($db,json_encode($result));return true;}else{return false;}}
public static function add_ITEM ($password,$db,$value,$isJSON = false){if(self::connect($password)){$content = json_decode(self::get_content($db),true);if($isJSON){$content['DATA'][] = json_decode($value,true);}else{$content['DATA'][] = $value;}self::set_content($db,json_encode($content));return count($content['DATA'])-1;}else{return false;}}
public static function delete_ITEM ($password,$db,$ID){if(self::connect($password)){$content = json_decode(self::get_content($db),true);array_splice($content['DATA'],$ID,1);self::set_content($db,json_encode($content));return true;}else{return false;}}
public static function get_ITEM ($password,$db,$ID){if(self::connect($password)){$content = json_decode(self::get_content($db),true);return $content['DATA'][$ID];}else{return false;}}
public static function set_ITEM ($password,$db,$ID,$value,$isJSON = false){if(self::connect($password)){$content = json_decode(self::get_content($db),true);if($isJSON){$content['DATA'][$ID] = json_decode($value,true);}else{$content['DATA'][$ID] = $value;}self::set_content($db,json_encode($content));return true;}else{return false;}}
public static function find_ID ($password,$db,$value){if(self::connect($password)){$content = json_decode(self::get_content($db),true);$result = array();foreach($content['DATA'] as $ID => $item){$valid = true;foreach($value as $rule){if(eval("if(\$item".$rule."){return true;}else{return false;}") == false){$valid = false;}}if($valid){$result[] = $ID;}}return $result;}else{return false;}}
public static function find_ITEM ($password,$db,$value){if(self::connect($password)){$content = json_decode(self::get_content($db),true);$result = array();foreach($content['DATA'] as $ID => $item){$valid = true;foreach($value as $rule){if(eval("if(\$item".$rule."){return true;}else{return false;}") == false){$valid = false;}}if($valid){$result[] = $item;}}return $result;}else{return false;}}
private static function connect ($password){if(self::$config['password'] === $password){return true;}else{return false;}}
private static function get_content ($db){if(file_exists(self::$config['path'].$db.".json")){$file = fopen(self::$config['path'].$db.".json","r");$content = fread($file,filesize(self::$config['path'].$db.".json"));fclose($file);return $content;}else{return false;}}
private static function set_content ($db,$value = ""){$file = fopen(self::$config['path'].$db.".json","w");fwrite($file,$value);fclose($file);return true;}}
?>
12 changes: 12 additions & 0 deletions Demo/exemple/exemple.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
//add Datas.php in your project
// REMEMBER TO CHANGE THE DEFAULT PASSWORD
require("Datas.php");

// create a new Database
Datas::new_DB("PASSWORD", "my_db");

// set all content of file (not recommended)
//Datas::set_ALL("PASSWORD", "my_db", "{}")

?>
246 changes: 246 additions & 0 deletions sources/datas.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
<?php

class Datas {

/*************************************
* *
* stockage des données de Datas *
* *
*************************************/
private static $config = array(
"password" => "PASSWORD",
"path" => "data/"
);


/*************************************
* *
* Fonction public *
* *
*************************************/
public static function get_ALL ($password, $db) {
if(self::connect($password)){
return json_decode(self::get_content($db), true);
}
else {
return false;
}
}
public static function set_ALL ($password, $db, $value, $isJSON = false) {
if(self::connect($password)){
if($isJSON == true){
self::set_content($db, $value);
}
else {
self::set_content($db, json_encode($value));
}
return true;
}
else {
return false;
}
}

/**
* @param string $password mot de passe
* @param string $db nom de base de données
* @return boolean true si réussi, false en cas de pb
*/
public static function new_DB ($password, $db) {
if(self::connect($password)){
return self::set_content($db, '{"INFO":{"VERSION":"1.0.0","LASTCHANGE":"01/01/2000"},"DATA":[]}');
}
else {
return false;
}
}
public static function delete_DB ($password, $db) {
return unlink(self::$config['path'] . $db . ".json");
}

public static function get_INFO ($password, $db) {
if(self::connect($password)){
$result = json_decode(self::get_content($db), true);
return $result['INFO'];
}
else {
return false;
}
}
public static function set_INFO ($password, $db, $version, $lastchange) {
if(self::connect($password)){
$result = json_decode(self::get_content($db), true);
$result['INFO']['VERSION'] = $version;
$result['INFO']['LASTCHANGE'] = $lastchange;
self::set_content($db, json_encode($result));
return true;
}
else {
return false;
}
}

public static function get_DATA ($password, $db) {
if(self::connect($password)){
$result = json_decode(self::get_content($db), true);
return $result['DATA'];
}
else {
return false;
}
}
public static function set_DATA ($password, $db, $value, $isJSON = false) {
if(self::connect($password)){
$result = json_decode(self::get_content($db), true);
if($isJSON){
$value = json_decode($value, true);
}
$result['DATA'] = $value;
self::set_content($db, json_encode($result));
return true;
}
else {
return false;
}
}

public static function add_ITEM ($password, $db, $value, $isJSON = false) {
if(self::connect($password)){
$content = json_decode(self::get_content($db), true);
if($isJSON){
$content['DATA'][] = json_decode($value, true);
} else {
$content['DATA'][] = $value;
}
self::set_content($db, json_encode($content));
return count($content['DATA']) - 1;
}
else {
return false;
}
}
public static function delete_ITEM ($password, $db, $ID) {
if(self::connect($password)){
$content = json_decode(self::get_content($db), true);
array_splice($content['DATA'], $ID, 1);
self::set_content($db, json_encode($content));
return true;
}
else {
return false;
}
}
public static function get_ITEM ($password, $db, $ID) {
if(self::connect($password)){
$content = json_decode(self::get_content($db), true);
return $content['DATA'][$ID];
}
else {
return false;
}
}
public static function set_ITEM ($password, $db, $ID, $value, $isJSON = false) {
if(self::connect($password)){
$content = json_decode(self::get_content($db), true);
if($isJSON){
$content['DATA'][$ID] = json_decode($value, true);
} else {
$content['DATA'][$ID] = $value;
}
self::set_content($db, json_encode($content));
return true;
}
else {
return false;
}
}

// $value = array('["USER"]["PSEUDO"] == "loulou"','["USER"]["MDP" == "password"')
public static function find_ID ($password, $db, $value) {
if(self::connect($password)){
$content = json_decode(self::get_content($db), true);
$result = array();
foreach($content['DATA'] as $ID => $item){
$valid = true;
foreach($value as $rule){
if(eval("if(\$item".$rule."){return true;}else{return false;}") == false){
$valid = false;
}
}
if($valid){
$result[] = $ID;
}
}
return $result;
}
else {
return false;
}
}
// $value = array('["USER"]["PSEUDO"] == "loulou"','["USER"]["MDP" == "password"')
public static function find_ITEM ($password, $db, $value) {
if(self::connect($password)){
$content = json_decode(self::get_content($db), true);
$result = array();
foreach($content['DATA'] as $ID => $item){
$valid = true;
foreach($value as $rule){
if(eval("if(\$item".$rule."){return true;}else{return false;}") == false){
$valid = false;
}
}
if($valid){
$result[] = $item;
}
}
return $result;
}
else {
return false;
}
}


/*************************************
* *
* Allow you to connect on DB *
* *
*************************************/
private static function connect ($password) {
if(self::$config['password'] === $password){
return true;
}
else {
return false;
}
}


/*************************************
* *
* Fonction d'accés au fichiers *
* *
*************************************/
private static function get_content ($db) {
if(file_exists(self::$config['path'] . $db . ".json")){
$file = fopen(self::$config['path'] . $db . ".json", "r");
$content = fread($file, filesize(self::$config['path'] . $db . ".json"));
fclose($file);
return $content;
}
else {
return false;
}
}
private static function set_content ($db, $value = "") {
$file = fopen(self::$config['path'] . $db . ".json", "w");
fwrite($file, $value);
fclose($file);
return true;
}




}
?>

0 comments on commit bc9a13d

Please sign in to comment.