Skip to content

Commit

Permalink
LOOOOTS of updates and optims and code style and unreadable diff
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierstoval committed Jun 1, 2018
1 parent 83a00ff commit 51030d8
Show file tree
Hide file tree
Showing 89 changed files with 2,755 additions and 2,992 deletions.
52 changes: 9 additions & 43 deletions app.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
* Effectue le chargement des modules du site en fonction de l'url
*/

use App\bdd;
use App\FileAndDir;
use App\Session;
use App\Translate;
use App\Users;

require __DIR__.'/vendor/autoload.php';

define('ROOT', __DIR__); //Chemin vers le dossier racine
Expand All @@ -16,47 +22,6 @@
define('P_JS', WEBROOT.DS.'js');
define('CHAR_EXPORT', WEBROOT.DS.'files'.DS.'characters_export');

## Chargement des classes
$class_inc = array(
'bddPDO',
'encoding',
'esterenchar',
'minifier',
'translate',
'users',
'fpdf',
//'fpdfMakefont',
//'fpdfTTFparser',
'tfpdf',
'tfpdfTTFonts',
'mailerEasyPeasyICS',
'mailerHtml2text',
'mailerNtlm_sasl_client',
'mailerPhpmailer',
'mailerPop3',
'mailerSmtp',
'cakePhpFileAndDir',
'cakePhpInflector',
'cakePhpHash',
'cakePhpSession',
'cakePhpSet',
'cakePhpString',
);
foreach ($class_inc as $val) {
$filename = ROOT.DS.'class'.DS.'class_'.$val.'.php';
if (file_exists($filename)) {
try {
require_once $filename;
} catch (\Exception $e) {
echo $e->getMessage();
}
} else {
echo 'Erreur dans le chargement de la classe '.$val;
exit;
}
}
unset($class_inc);

## Chargement des fonctions
$function_inc = array(
'arrayDiffRecursive',
Expand All @@ -69,6 +34,7 @@
'errorLogging',
'goto404',
'gv',
'tr',
'httpCode',
'isBlacklisted',
'minify',
Expand Down Expand Up @@ -106,7 +72,7 @@
}
## Configuration de la base de données
if (!FileAndDir::fexists(ROOT.DS.'config.php')) {
echo "Database not configured.";
echo 'Database not configured.';
exit;
}
require ROOT.DS.'config.php';
Expand Down Expand Up @@ -178,7 +144,7 @@
}
if (!isset($_PAGE['dont_log'])) {
$f = fopen($logfile, 'ab');##On stocke le temps d'exécution dans le fichier log
$final = "*|*|*Date=>".json_encode(date(DATE_RFC822))
$final = '*|*|*Date=>'.json_encode(date(DATE_RFC822))
.'||Ip=>'.json_encode($_SERVER['REMOTE_ADDR'])
.'||Referer=>'.json_encode(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '')
.'||Page.get=>'.json_encode($_PAGE['get'])
Expand Down
18 changes: 5 additions & 13 deletions bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
* Créées par Alexandre Ancelet - Pierstoval
* 2012-2013
*/

use App\FileAndDir;
use App\Session;
use App\Translate;

setlocale(LC_TIME, array('fr_FR', 'fr_FR.UTF-8'));

## Réécriture d'url active ou non, permet de créer des liens cohérents);
Expand All @@ -24,19 +29,6 @@
define('P_FPDF_FONTPATH', ROOT.DS.'files'.DS.'fpdf'.DS.'fonts');
define('P_FPDF_SYSTEM_TTF_FONTS', ROOT.DS.'files'.DS.'fpdf'.DS.'fonts');

## Couleur des différents types de variables pour les fonctions p_dump et p_dumpTxt
define('P_DUMP_INTCOLOR', 'blue');
define('P_DUMP_FLOATCOLOR', 'darkblue');
define('P_DUMP_NUMSTRINGCOLOR', '#c0c');
define('P_DUMP_STRINGCOLOR', 'darkgreen');
define('P_DUMP_RESSCOLOR', '#aa0');
define('P_DUMP_NULLCOLOR', '#aaa');
define('P_DUMP_BOOLTRUECOLOR', '#0c0');
define('P_DUMP_BOOLFALSECOLOR', 'red');
define('P_DUMP_OBJECTCOLOR', 'pink');
define('P_DUMP_PADDINGLEFT', '25px');
define('P_DUMP_WIDTH', '');

## Générer les fichiers css et js des pages à chaque chargement via la fonction buffWrite(). Permet de réinitialiser une partie cache en local ou lorsque le superadmin est connecté
define('P_GEN_FILES_ONLOAD', ($_SERVER['HTTP_HOST'] === '127.0.0.1' ? true : false));

Expand Down
159 changes: 42 additions & 117 deletions class/class_cakePhpString.php → class/CakePHPString.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

namespace App;

/**
* String handling methods.
*
Expand Down Expand Up @@ -27,86 +30,11 @@
*/
class CakePHPString {

/**
* Generate a random UUID
*
* @see http://www.ietf.org/rfc/rfc4122.txt
* @return RFC 4122 UUID
* @static
*/
public static function uuid() {
$node = env('SERVER_ADDR');
$pid = null;

if (strpos($node, ':') !== false) {
if (substr_count($node, '::')) {
$node = str_replace(
'::', str_repeat(':0000', 8 - substr_count($node, ':')) . ':', $node
);
}
$node = explode(':', $node) ;
$ipv6 = '' ;

foreach ($node as $id) {
$ipv6 .= str_pad(base_convert($id, 16, 2), 16, 0, STR_PAD_LEFT);
}
$node = base_convert($ipv6, 2, 10);

if (strlen($node) < 38) {
$node = null;
} else {
$node = crc32($node);
}
} elseif (empty($node)) {
$host = env('HOSTNAME');

if (empty($host)) {
$host = env('HOST');
}

if (!empty($host)) {
$ip = gethostbyname($host);

if ($ip === $host) {
$node = crc32($host);
} else {
$node = ip2long($ip);
}
}
} elseif ($node !== '127.0.0.1') {
$node = ip2long($node);
} else {
$node = null;
}

if (empty($node)) {
$node = crc32(Configure::read('Security.salt'));
}

if (function_exists('zend_thread_id')) {
$pid = zend_thread_id();
} else {
$pid = getmypid();
}

if (!$pid || $pid > 65535) {
$pid = mt_rand(0, 0xfff) | 0x4000;
}

list($timeMid, $timeLow) = explode(' ', microtime());
$uuid = sprintf(
"%08x-%04x-%04x-%02x%02x-%04x%08x", (int)$timeLow, (int)substr($timeMid, 2) & 0xffff,
mt_rand(0, 0xfff) | 0x4000, mt_rand(0, 0x3f) | 0x80, mt_rand(0, 0xff), $pid, $node
);

return $uuid;
}

/**
* Tokenizes a string using $separator, ignoring any instance of $separator that appears between
* $leftBound and $rightBound
*
* @param string $data The data to tokenize
* @param string|array $data The data to tokenize
* @param string $separator The token to split the data on.
* @param string $leftBound The left boundary to ignore separators in.
* @param string $rightBound The right boundary to ignore separators in.
Expand Down Expand Up @@ -134,36 +62,34 @@ public static function tokenize($data, $separator = ',', $leftBound = '(', $righ
strpos($data, $rightBound, $offset)
);
for ($i = 0; $i < 3; $i++) {
if ($offsets[$i] !== false && ($offsets[$i] < $tmpOffset || $tmpOffset == -1)) {
if ($offsets[$i] !== false && ($offsets[$i] < $tmpOffset || $tmpOffset === -1)) {
$tmpOffset = $offsets[$i];
}
}
if ($tmpOffset !== -1) {
$buffer .= substr($data, $offset, ($tmpOffset - $offset));
if ($data{$tmpOffset} == $separator && $depth == 0) {
$buffer .= substr($data, $offset, $tmpOffset - $offset);
if (!$depth && $data{$tmpOffset} === $separator) {
$results[] = $buffer;
$buffer = '';
} else {
$buffer .= $data{$tmpOffset};
}
if ($leftBound != $rightBound) {
if ($data{$tmpOffset} == $leftBound) {
if ($leftBound !== $rightBound) {
if ($data{$tmpOffset} === $leftBound) {
$depth++;
}
if ($data{$tmpOffset} == $rightBound) {
if ($data{$tmpOffset} === $rightBound) {
$depth--;
}
} else {
if ($data{$tmpOffset} == $leftBound) {
if (!$open) {
$depth++;
$open = true;
} else {
$depth--;
$open = false;
}
}
}
} elseif ($data{$tmpOffset} === $leftBound) {
if (!$open) {
$depth++;
$open = true;
} else {
$depth--;
$open = false;
}
}
$offset = ++$tmpOffset;
} else {
$results[] = $buffer . substr($data, $offset);
Expand Down Expand Up @@ -198,7 +124,7 @@ public static function tokenize($data, $separator = ',', $leftBound = '(', $righ
* - clean: A boolean or array with instructions for String::cleanInsert
*
* @param string $str A string containing variable placeholders
* @param string $data A key => val array where each key stands for a placeholder variable name
* @param string|array $data A key => val array where each key stands for a placeholder variable name
* to be replaced with val
* @param string $options An array of options, see description above
* @return string
Expand All @@ -213,7 +139,7 @@ public static function insert($str, $data, $options = array()) {
$format = $options['format'];
$data = (array)$data;
if (empty($data)) {
return ($options['clean']) ? static::cleanInsert($str, $options) : $str;
return $options['clean'] ? static::cleanInsert($str, $options) : $str;
}

if (!isset($format)) {
Expand All @@ -232,32 +158,31 @@ public static function insert($str, $data, $options = array()) {
$offset = $pos + strlen($val);
$str = substr_replace($str, $val, $pos, 1);
}
return ($options['clean']) ? static::cleanInsert($str, $options) : $str;
} else {
asort($data);
return $options['clean'] ? static::cleanInsert($str, $options) : $str;
}

$hashKeys = array();
foreach ($data as $key => $value) {
$hashKeys[] = crc32($key);
}
asort($data);

$tempData = array_combine(array_keys($data), array_values($hashKeys));
krsort($tempData);
foreach ($tempData as $key => $hashVal) {
$key = sprintf($format, preg_quote($key, '/'));
$str = preg_replace($key, $hashVal, $str);
}
$dataReplacements = array_combine($hashKeys, array_values($data));
foreach ($dataReplacements as $tmpHash => $tmpValue) {
$tmpValue = (is_array($tmpValue)) ? '' : $tmpValue;
$str = str_replace($tmpHash, $tmpValue, $str);
}
}
$hashKeys = array();
foreach ($data as $key => $value) {
$hashKeys[] = crc32($key);
}

$tempData = array_combine(array_keys($data), array_values($hashKeys));
krsort($tempData);
foreach ($tempData as $key => $hashVal) {
$key = sprintf($format, preg_quote($key, '/'));
$str = preg_replace($key, $hashVal, $str);
}
foreach (array_combine($hashKeys, array_values($data)) as $tmpHash => $tmpValue) {
$tmpValue = is_array($tmpValue) ? '' : $tmpValue;
$str = str_replace($tmpHash, $tmpValue, $str);
}

if (!isset($options['format']) && isset($options['before'])) {
if (!isset($options['format']) && isset($options['before'])) {
$str = str_replace($options['escape'].$options['before'], $options['before'], $str);
}
return ($options['clean']) ? static::cleanInsert($str, $options) : $str;
return $options['clean'] ? static::cleanInsert($str, $options) : $str;
}

/**
Expand All @@ -267,7 +192,7 @@ public static function insert($str, $data, $options = array()) {
* by static::insert().
*
* @param string $str
* @param string $options
* @param array $options
* @return string
* @access public
* @static
Expand Down
Loading

0 comments on commit 51030d8

Please sign in to comment.