composer v1
This commit is contained in:
10
composer.json
Normal file
10
composer.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "franzz/objects",
|
||||
"description": "Objects",
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Franzz\\Objects\\": "inc"
|
||||
}
|
||||
}
|
||||
}
|
||||
55
inc/db.php
55
inc/db.php
@@ -1,5 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Franzz\Objects;
|
||||
use \Settings;
|
||||
|
||||
/**
|
||||
* MySql query manager and generator
|
||||
* @author franzz
|
||||
@@ -23,10 +26,10 @@ class Db extends PhpObject
|
||||
|
||||
/**
|
||||
* SQL connection Handle
|
||||
* @var mysqli
|
||||
* @var \mysqli
|
||||
*/
|
||||
private $oConnection;
|
||||
private $sDatabase;
|
||||
private $asConf;
|
||||
private $asOptions;
|
||||
|
||||
/**
|
||||
@@ -37,20 +40,14 @@ class Db extends PhpObject
|
||||
* 'cascading_delete'=>array('table_name1'=>array('linked_table1', 'linked_table2', ...), 'table_name2'=>...))
|
||||
* @var Array
|
||||
*/
|
||||
public function __construct($sDbServer, $sLogin, $sPass, $sDatabase, $asOptions, $sEncoding='utf8mb4')
|
||||
public function __construct($asConf, $asOptions)
|
||||
{
|
||||
parent::__construct(__FILE__, Settings::DEBUG);
|
||||
$this->sDatabase = $sDatabase;
|
||||
$this->asConf = $asConf;
|
||||
$this->asOptions = $asOptions;
|
||||
//$this->oConnection = mysql_connect(self::DB_SERVER, self::DB_LOGIN, self::DB_PASS);
|
||||
$this->oConnection = new mysqli($sDbServer, $sLogin, $sPass);
|
||||
$this->syncPhpParams($sEncoding);
|
||||
|
||||
/*
|
||||
$dsn = 'mysql:dbname='.$this->sDatabase.';host='.self::DB_SERVER;
|
||||
try {$dbh = new PDO($dsn, self::DB_LOGIN, self::DB_PASS);}
|
||||
catch (PDOException $e) {$this->addError('Connexion échouée : ' . $e->getMessage());}
|
||||
*/
|
||||
parent::__construct(__FILE__, Settings::DEBUG);
|
||||
$this->oConnection = new \mysqli($this->getConf('server'), $this->getConf('user'), $this->getConf('pass'));
|
||||
$this->syncPhpParams($this->getConf('encoding'));
|
||||
|
||||
$this->setTrace(false);
|
||||
if($this->oConnection->connect_error)
|
||||
@@ -60,7 +57,7 @@ class Db extends PhpObject
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!$this->oConnection->select_db($this->sDatabase))
|
||||
if(!$this->oConnection->select_db($this->getConf('database')))
|
||||
{
|
||||
$this->addError('Could not find database "'.$this->sDatabase.'"');
|
||||
$this->sDbState = self::DB_NO_DATA;
|
||||
@@ -73,6 +70,10 @@ class Db extends PhpObject
|
||||
}
|
||||
}
|
||||
|
||||
private function getConf($sConf) {
|
||||
return $this->asConf[$sConf] ?? null;
|
||||
}
|
||||
|
||||
private function syncPhpParams($sEncoding)
|
||||
{
|
||||
//Characters encoding
|
||||
@@ -91,7 +92,6 @@ class Db extends PhpObject
|
||||
public function setTrace($bTrace=true)
|
||||
{
|
||||
$this->bTrace = $bTrace;
|
||||
//if($bTrace) $this->setDebug(true);
|
||||
}
|
||||
|
||||
public function getTrace()
|
||||
@@ -108,7 +108,7 @@ class Db extends PhpObject
|
||||
{
|
||||
//Create Database
|
||||
$this->setQuery("DROP DATABASE IF EXISTS ".$this->sDatabase);
|
||||
$this->setQuery("CREATE DATABASE ".$this->sDatabase." DEFAULT CHARACTER SET ".Settings::DB_ENC." DEFAULT COLLATE ".Settings::DB_ENC."_general_ci");
|
||||
$this->setQuery("CREATE DATABASE ".$this->sDatabase." DEFAULT CHARACTER SET ".$this->getConf('encoding')." DEFAULT COLLATE ".$this->getConf('encoding')."_general_ci");
|
||||
$this->oConnection->select_db($this->sDatabase);
|
||||
|
||||
//Create tables
|
||||
@@ -120,7 +120,7 @@ class Db extends PhpObject
|
||||
|
||||
$sAppPath = '';
|
||||
if(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') $sAppPath = 'C:\ProgramData\xampp\mysql\bin\\';
|
||||
exec($sAppPath.'mysqldump --user='.Settings::DB_LOGIN.' --password='.Settings::DB_PASS.' '.Settings::DB_NAME.' --add-drop-table --result-file='.$sBackupFile);
|
||||
exec($sAppPath.'mysqldump --user='.$this->getConf('user').' --password='.$this->getConf('pass').' '.$this->getConf('database').' --add-drop-table --result-file='.$sBackupFile);
|
||||
if(file_exists($sBackupFile)) {
|
||||
$sBackup = file_get_contents($sBackupFile);
|
||||
unlink($sBackupFile);
|
||||
@@ -133,7 +133,7 @@ class Db extends PhpObject
|
||||
$sAppPath = '';
|
||||
if(file_exists($sBackupFile)) {
|
||||
if(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') $sAppPath = 'C:\ProgramData\xampp\mysql\bin\\';
|
||||
return exec($sAppPath.'mysql --user='.Settings::DB_LOGIN.' --password='.Settings::DB_PASS.' '.Settings::DB_NAME.' < '.$sBackupFile);
|
||||
return exec($sAppPath.'mysql --user='.$this->getConf('user').' --password='.$this->getConf('pass').' '.$this->getConf('database').' < '.$sBackupFile);
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
@@ -750,23 +750,4 @@ class Db extends PhpObject
|
||||
return array_combine($asKeys, $asValues);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public function select($asFields='*')
|
||||
{
|
||||
$oSql = new Sql($this, array('select'=>$asFields));
|
||||
return $oSql;
|
||||
}
|
||||
|
||||
public function from($sTable)
|
||||
{
|
||||
$oSql = new Sql($this, array('from'=>$sTable));
|
||||
return $oSql;
|
||||
}
|
||||
|
||||
public function getConnection()
|
||||
{
|
||||
return $this->oConnection;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
28
inc/main.php
28
inc/main.php
@@ -1,5 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Franzz\Objects;
|
||||
use \Settings;
|
||||
|
||||
/**
|
||||
* Main Class
|
||||
* @author franzz
|
||||
@@ -20,12 +23,6 @@ abstract class Main extends PhpObject
|
||||
//Folders
|
||||
const MASKS_FOLDER = 'masks/';
|
||||
|
||||
/**
|
||||
* Class Management
|
||||
* @var ClassManagement
|
||||
*/
|
||||
protected $oClassManagement;
|
||||
|
||||
/**
|
||||
* DB Handle
|
||||
* @var Db
|
||||
@@ -50,24 +47,23 @@ abstract class Main extends PhpObject
|
||||
|
||||
/**
|
||||
* Main constructor
|
||||
* @param ClassManagement $oClassManagement
|
||||
* @param string $sLang
|
||||
*/
|
||||
public function __construct($oClassManagement, $sProcessPage, $asMandatoryClasses=array(), $bDb=true, $sFile=__FILE__, $sTimeZone='')
|
||||
public function __construct($sProcessPage, $bDb=true, $sFile=__FILE__, $sTimeZone='')
|
||||
{
|
||||
parent::__construct($sFile, Settings::DEBUG);
|
||||
$this->oClassManagement = $oClassManagement;
|
||||
|
||||
//Load classes
|
||||
$asMandatoryClasses[] = array('name'=>'mask', 'project'=>false);
|
||||
if($bDb) $asMandatoryClasses[] = array('name'=>'db', 'project'=>false);
|
||||
foreach($asMandatoryClasses as $asClass) $this->oClassManagement->incClass($asClass['name'], $asClass['project']);
|
||||
|
||||
$this->setContext($sProcessPage, $sTimeZone);
|
||||
|
||||
//Init objects
|
||||
if($bDb) {
|
||||
$this->oDb = new Db(Settings::DB_SERVER, Settings::DB_LOGIN, Settings::DB_PASS, Settings::DB_NAME, $this->getSqlOptions() , Settings::DB_ENC);
|
||||
$asConf = array(
|
||||
'server' => Settings::DB_SERVER,
|
||||
'database' => Settings::DB_NAME,
|
||||
'user' => Settings::DB_LOGIN,
|
||||
'pass' => Settings::DB_PASS,
|
||||
'encoding' => Settings::DB_ENC
|
||||
);
|
||||
$this->oDb = new Db($asConf, $this->getSqlOptions());
|
||||
if(in_array($this->oDb->sDbState, array(Db::DB_NO_DATA, Db::DB_NO_TABLE))) $this->install();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Franzz\Objects;
|
||||
use \Settings;
|
||||
|
||||
/**
|
||||
* Mask Reader
|
||||
* @author franzz
|
||||
@@ -293,7 +296,7 @@ class Mask extends PhpObject
|
||||
if(!is_null($this->oLang) && self::isLangTag($sTagValue)) $sTagValue = $this->oLang->getTranslation($sTagActValue, $this->asTagsParams[$sTagName]);
|
||||
|
||||
//Convert Value to Mask Time Zone
|
||||
if(self::isTimeTag($sTagValue)) $sTagValue = (new DateTime('@'.$sTagActValue))->setTimeZone(new DateTimeZone($this->sTimezone))->format($this->asTagsParams[$sTagName]);;
|
||||
if(self::isTimeTag($sTagValue)) $sTagValue = (new \DateTime('@'.$sTagActValue))->setTimeZone(new \DateTimeZone($this->sTimezone))->format($this->asTagsParams[$sTagName]);;
|
||||
}
|
||||
|
||||
//Replace Tags
|
||||
|
||||
69
class_management.php → inc/phpobject.php
Executable file → Normal file
69
class_management.php → inc/phpobject.php
Executable file → Normal file
@@ -1,72 +1,7 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Manage includes
|
||||
* @author franzz
|
||||
* @version 1.2
|
||||
*/
|
||||
class ClassManagement extends PhpObject
|
||||
{
|
||||
const OBJECT_FOLDER = '../objects/';
|
||||
const INC_FOLDER = 'inc/';
|
||||
const INC_EXT = '.php';
|
||||
const SETTINGS_FILE = 'settings.php';
|
||||
const GLOBAL_SETTINGS_FILE = 'globalsettings.php';
|
||||
const TOOLBOX_CLASS = 'toolbox';
|
||||
const MAIN_CLASS_ABS = 'main';
|
||||
|
||||
private $asIncFiles;
|
||||
|
||||
function __construct($sMainClass)
|
||||
{
|
||||
parent::__construct(__FILE__, true);
|
||||
$this->asIncFiles = array();
|
||||
|
||||
//try to include default files
|
||||
$this->incFile(self::OBJECT_FOLDER.self::GLOBAL_SETTINGS_FILE);
|
||||
$this->incFile(self::SETTINGS_FILE);
|
||||
$this->incClass(self::TOOLBOX_CLASS);
|
||||
|
||||
//Include main class
|
||||
$this->incClass(self::MAIN_CLASS_ABS);
|
||||
$this->incClass($sMainClass, true);
|
||||
}
|
||||
|
||||
function __destruct()
|
||||
{
|
||||
parent::__destruct();
|
||||
}
|
||||
|
||||
public function incClass($sClassName, $bProjectClass=false)
|
||||
{
|
||||
$sProject = $bProjectClass?'':self::OBJECT_FOLDER;
|
||||
$sFile = $sProject.self::INC_FOLDER.$sClassName.self::INC_EXT;
|
||||
return $this->incFile($sFile);
|
||||
}
|
||||
|
||||
public function incFile($sFilePath, $bMandatory=true)
|
||||
{
|
||||
$bIncluded = false;
|
||||
if(!in_array($sFilePath, $this->asIncFiles))
|
||||
{
|
||||
$sMissingFile = 'File "'.$sFilePath.'" missing.';
|
||||
if(file_exists($sFilePath))
|
||||
{
|
||||
$bIncluded = require_once($sFilePath);
|
||||
$this->asIncFiles[] = $sFilePath;
|
||||
}
|
||||
elseif($bMandatory)
|
||||
{
|
||||
die($sMissingFile.' Stopping process.');
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->addError($sMissingFile);
|
||||
}
|
||||
}
|
||||
return $bIncluded;
|
||||
}
|
||||
}
|
||||
namespace Franzz\Objects;
|
||||
use \Settings;
|
||||
|
||||
/**
|
||||
* PHP Object
|
||||
@@ -1,5 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Franzz\Objects;
|
||||
use \Settings;
|
||||
|
||||
/**
|
||||
* RSS Feed Class
|
||||
* @author franzz
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Franzz\Objects;
|
||||
use \Settings;
|
||||
|
||||
/**
|
||||
* ToolBox - Only static functions missing from php library
|
||||
* @author franzz
|
||||
@@ -81,39 +84,6 @@ class ToolBox
|
||||
return $acText;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param String $sFromName
|
||||
* @param String $sSubject
|
||||
* @param String $sMessage
|
||||
* @param String $sTo
|
||||
* @param Array $asCc array(name => email)
|
||||
* @param Boolean $bSelfMail
|
||||
* @return mixed
|
||||
*/
|
||||
public function sendMail($sFromName, $sSubject, $sMessage, $sTo, $asCc=array(), $bSelfMail=true)
|
||||
{
|
||||
$asForm = array('api_key'=>Settings::MAIL_API_KEY,
|
||||
'app'=>'Wedding',
|
||||
'from_name'=>$sFromName,
|
||||
'subject'=>$sSubject,
|
||||
'msg'=>$sMessage,
|
||||
'to_email'=>$sTo,
|
||||
'cc_email'=>self::jsonConvert($asCc),
|
||||
'self'=>$bSelfMail);
|
||||
|
||||
$oCurl = curl_init();
|
||||
curl_setopt($oCurl, CURLOPT_URL, Settings::MAIL_SCRIPT);
|
||||
curl_setopt($oCurl, CURLOPT_POST, true);
|
||||
curl_setopt($oCurl, CURLOPT_HEADER, false);
|
||||
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($oCurl, CURLOPT_POSTFIELDS, $asForm);
|
||||
$iResult = curl_exec($oCurl);
|
||||
curl_close($oCurl);
|
||||
|
||||
return $iResult;
|
||||
}
|
||||
|
||||
public static function jsonExport($asData)
|
||||
{
|
||||
header('Content-type: application/json');
|
||||
@@ -170,7 +140,7 @@ class ToolBox
|
||||
//Retrieving file Content Type
|
||||
if(file_exists($sPath)) //Local
|
||||
{
|
||||
$oFileInfo = new finfo(FILEINFO_MIME);
|
||||
$oFileInfo = new \finfo(FILEINFO_MIME);
|
||||
$sMimetype = $oFileInfo->file($sPath);
|
||||
}
|
||||
else //Remote
|
||||
@@ -346,7 +316,7 @@ class ToolBox
|
||||
return $asResult;
|
||||
}
|
||||
|
||||
public function copyExif($srcfile, $destfile) {
|
||||
public static function copyExif($srcfile, $destfile) {
|
||||
// Function transfers EXIF (APP1) and IPTC (APP13) from $srcfile and adds it to $destfile
|
||||
// JPEG file has format 0xFFD8 + [APP0] + [APP1] + ... [APP15] + <image data> where [APPi] are optional
|
||||
// Segment APPi (where i=0x0 to 0xF) has format 0xFFEi + 0xMM + 0xLL + <data> (where 0xMM is
|
||||
@@ -591,7 +561,6 @@ class ToolBox
|
||||
{
|
||||
if(!preg_match('/[\x80-\xff]/', $string)) return $string;
|
||||
|
||||
if (true || seems_utf8($string)) {
|
||||
$chars = array(
|
||||
// Decompositions for Latin-1 Supplement
|
||||
chr(194).chr(170) => 'a', chr(194).chr(186) => 'o',
|
||||
@@ -790,28 +759,7 @@ class ToolBox
|
||||
}
|
||||
*/
|
||||
$string = strtr($string, $chars);
|
||||
} else {
|
||||
$chars = array();
|
||||
// Assume ISO-8859-1 if not UTF-8
|
||||
$chars['in'] = chr(128).chr(131).chr(138).chr(142).chr(154).chr(158)
|
||||
.chr(159).chr(162).chr(165).chr(181).chr(192).chr(193).chr(194)
|
||||
.chr(195).chr(196).chr(197).chr(199).chr(200).chr(201).chr(202)
|
||||
.chr(203).chr(204).chr(205).chr(206).chr(207).chr(209).chr(210)
|
||||
.chr(211).chr(212).chr(213).chr(214).chr(216).chr(217).chr(218)
|
||||
.chr(219).chr(220).chr(221).chr(224).chr(225).chr(226).chr(227)
|
||||
.chr(228).chr(229).chr(231).chr(232).chr(233).chr(234).chr(235)
|
||||
.chr(236).chr(237).chr(238).chr(239).chr(241).chr(242).chr(243)
|
||||
.chr(244).chr(245).chr(246).chr(248).chr(249).chr(250).chr(251)
|
||||
.chr(252).chr(253).chr(255);
|
||||
|
||||
$chars['out'] = "EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy";
|
||||
|
||||
$string = strtr($string, $chars['in'], $chars['out']);
|
||||
$double_chars = array();
|
||||
$double_chars['in'] = array(chr(140), chr(156), chr(198), chr(208), chr(222), chr(223), chr(230), chr(240), chr(254));
|
||||
$double_chars['out'] = array('OE', 'oe', 'AE', 'DH', 'TH', 'ss', 'ae', 'dh', 'th');
|
||||
$string = str_replace($double_chars['in'], $double_chars['out'], $string);
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Franzz\Objects;
|
||||
use \Settings;
|
||||
|
||||
/**
|
||||
* Translator Class
|
||||
* @author franzz
|
||||
|
||||
1483
inc/uploadhandler.php
Normal file
1483
inc/uploadhandler.php
Normal file
File diff suppressed because it is too large
Load Diff
80
index.php
80
index.php
@@ -1,80 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
Main Project
|
||||
http://git.lutran.fr/main.git
|
||||
Copyright (C) 2015 François Lutran
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see http://www.gnu.org/licenses
|
||||
*/
|
||||
|
||||
/* Requests Handler */
|
||||
|
||||
//Start buffering
|
||||
ob_start();
|
||||
require_once '../objects/class_management.php';
|
||||
$oClassManagement = new ClassManagement('main');
|
||||
ToolBox::cleanPost($_POST);
|
||||
ToolBox::cleanPost($_GET);
|
||||
ToolBox::cleanPost($_REQUEST);
|
||||
ToolBox::fixGlobalVars(isset($argv)?$argv:array());
|
||||
|
||||
//Available variables
|
||||
$sToken = isset($_GET['token'])?$_GET['token']:'';
|
||||
$sAction = isset($_GET['a'])?$_GET['a']:'';
|
||||
$sPage = isset($_GET['p'])?$_GET['p']:'index';
|
||||
$sLang = isset($_GET['l'])?$_GET['l']:(isset($_COOKIE['l'])?$_COOKIE['l']:'');
|
||||
//...
|
||||
|
||||
//Initiate class
|
||||
$oMain = new Main($oClassManagement, __FILE__, $sLang);
|
||||
$bLoggedIn = $oMain->isLoggedIn();
|
||||
|
||||
$sResult = '';
|
||||
if($sAction=='logmein') $sResult = $oMain->logMeIn($sToken);
|
||||
elseif($sAction!='' && $bLoggedIn)
|
||||
{
|
||||
switch ($sAction)
|
||||
{
|
||||
case '':
|
||||
$sResult = $oCvTheque->function();
|
||||
break;
|
||||
default:
|
||||
$sResult = Main::getJsonResult(false, Main::NOT_FOUND);
|
||||
}
|
||||
}
|
||||
elseif($sAction!='' && !$bLoggedIn)
|
||||
{
|
||||
if($oCvTheque->checkApiKey($iApiKey))
|
||||
{
|
||||
switch ($sAction)
|
||||
{
|
||||
case '':
|
||||
$sResult = $oCvTheque->apifunction();
|
||||
break;
|
||||
default:
|
||||
$sResult = Main::getJsonResult(false, Main::NOT_FOUND);
|
||||
}
|
||||
}
|
||||
else $sResult = Main::getJsonResult(false, Main::UNAUTHORIZED);
|
||||
}
|
||||
elseif($bLoggedIn) $sResult = $oMain->getMainPage();
|
||||
else $sResult = $oMain->getLogonPage();
|
||||
|
||||
$sDebug = ob_get_clean();
|
||||
if(Settings::DEBUG && $sDebug!='') $oMain->addUncaughtError($sDebug);
|
||||
|
||||
echo $sResult;
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user