Skip to content

Commit

Permalink
1.35.0
Browse files Browse the repository at this point in the history
* [+] Path like Pathogen
* [-] removed useless SBEngine::getContentPath(), SBEngine::unEscapeString(()
* [*] code fixes
  • Loading branch information
KarelWintersky committed Jun 10, 2021
1 parent 67be13c commit 65070fa
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 49 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"require-dev": {
"smarty/smarty": "^3.1",
"karelwintersky/arris": "^1.55"
"karelwintersky/arris": "^1.62"
},
"autoload": {
"files": [
Expand Down
59 changes: 59 additions & 0 deletions sources/Path.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace SteamBoat;

class Path
{
public $atoms = [];

public $isImmutable = false;

/**
* Factory ?
*
* @param $path
* @return Path
*/
public static function create($path)
{
return new self($path);
}

public static function createImmutable($path)
{
return new self($path, true);
}

public function __construct($path, $isImmutable = false)
{
$this->isImmutable = $isImmutable;

if (is_string($path)) {
$path = trim($path, DIRECTORY_SEPARATOR);
$this->atoms = explode(DIRECTORY_SEPARATOR, $path);
} elseif (is_array($path)) {
$this->atoms = $path;
}
}

public function toString()
{
return DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $this->atoms) . DIRECTORY_SEPARATOR;
}

public function join($data)
{
if (is_string($data)) {
$data = explode(DIRECTORY_SEPARATOR, trim($data, DIRECTORY_SEPARATOR));
}

if ($this->isImmutable) {
return new self(array_merge($this->atoms, $data), $this->isImmutable);
}

$this->atoms = array_merge($this->atoms, $data);
return $this;
}


}
66 changes: 18 additions & 48 deletions sources/SBEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,43 +119,16 @@ public static function engine_class_loader(string $class)

public static function getContentURL(string $type = "photos", $creation_date = '', bool $final_slash = true): string
{
$directory_separator = DIRECTORY_SEPARATOR;
$cdate = empty($creation_date) ? time() : strtotime($creation_date);

$path = "/{$type}/" . date("Y{$directory_separator}m", $cdate);

$path = DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, [
$type, date('Y', $cdate), date('m', $cdate)
]);
$path .= $final_slash ? '/' : '';

return $path;
}

public static function getContentPath(string $type = "photos", string $creation_date = ''): string
{
$STORAGE_FOLDER = self::$options['PROJECT_STORAGE'];

$directory_separator = DIRECTORY_SEPARATOR;

$creation_date = empty($creation_date) ? time() : strtotime($creation_date);

if (!in_array($type, self::$storages)) {
return "/tmp/";
}

$path
= $STORAGE_FOLDER
. self::$storages[$type]
. DIRECTORY_SEPARATOR
. date("Y{$directory_separator}m", $creation_date)
. DIRECTORY_SEPARATOR;

if (!is_dir($path)) {
if (!mkdir( $path, 0777, true ) && !is_dir( $path )) {
throw new \RuntimeException( sprintf( 'Directory "%s" was not created', $path ) );
}
}

return $path;
}

public static function parseUploadError(array $upload_data, $where = __METHOD__):string
{
switch ($upload_data['error']) {
Expand Down Expand Up @@ -194,10 +167,12 @@ public static function parseUploadError(array $upload_data, $where = __METHOD__)
public static function is_ssl():bool
{
if (isset($_SERVER['HTTPS'])) {
if ('on' == strtolower($_SERVER['HTTPS']))
if ('on' == strtolower($_SERVER['HTTPS'])) {
return true;
if ('1' == $_SERVER['HTTPS'])
}
if ('1' == $_SERVER['HTTPS']) {
return true;
}
} elseif (isset($_SERVER['SERVER_PORT']) && ('443' == $_SERVER['SERVER_PORT'])) {
return true;
}
Expand Down Expand Up @@ -260,13 +235,13 @@ public static function getEngineVersion():array
public static function getSiteUsageMetrics(MySQLWrapper $mysql, array $config): array
{
return [
'site.routed' => $config['ROUTED'] ?? '/',
'site.url' => $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'],
'time.total' => round(microtime(true) - $_SERVER['REQUEST_TIME'], 3),
'memory.usage' => memory_get_usage(true),
'memory.peak' => memory_get_peak_usage(true),
'mysql.query_count' => $mysql->getQueryCount(),
'mysql.query_time' => round($mysql->getQueryTime(), 3),
'time.total' => round(microtime(true) - $_SERVER['REQUEST_TIME'], 3),
'site.routed' => $config['ROUTED'] ?? '/',
'site.url' => $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']
];
}

Expand All @@ -286,8 +261,7 @@ public static function logSiteUsage(LoggerInterface $logger, array $metrics, boo
}

if (self::$options['LOG_SITE_USAGE']) {
unset($metrics['time.start']);
unset($metrics['time.end']);
unset( $metrics[ 'time.start' ], $metrics[ 'time.end' ] );
$logger->notice('Metrics:', $metrics);
}
return true;
Expand Down Expand Up @@ -330,16 +304,7 @@ public static function simpleSendEMAIL($to, $from = "", $subject = "", $message

public static function unEscapeString($input)
{
$escape_chars = "0410 0430 0411 0431 0412 0432 0413 0433 0490 0491 0414 0434 0415 0435 0401 0451 0404 0454 0416 0436 0417 0437 0418 0438 0406 0456 0419 0439 041A 043A 041B 043B 041C 043C 041D 043D 041E 043E 041F 043F 0420 0440 0421 0441 0422 0442 0423 0443 0424 0444 0425 0445 0426 0446 0427 0447 0428 0448 0429 0449 042A 044A 042B 044B 042C 044C 042D 044D 042E 044E 042F 044F";
$russian_chars = "А а Б б В в Г г Ґ ґ Д д Е е Ё ё Є є Ж ж З з И и І і Й й К к Л л М м Н н О о П п Р р С с Т т У у Ф ф Х х Ц ц Ч ч Ш ш Щ щ Ъ ъ Ы ы Ь ь Э э Ю ю Я я";

$e = explode(" ", $escape_chars);
$r = explode(" ", $russian_chars);
$rus_array = explode("%u", $input);

$new_word = str_replace( array( $e, "%20" ), array( $r, " " ), $rus_array );

return (implode("", $new_word));
return $input;
}

public static function setOption(array $options = [], $key = null, $default_value = null)
Expand All @@ -350,6 +315,11 @@ public static function setOption(array $options = [], $key = null, $default_valu

return array_key_exists($key, $options) ? $options[ $key ] : $default_value;
}

public static function getContentPath(string $type = "photos", string $creation_date = ''): string
{
// TODO: Implement getContentPath() method.
}
}

# -eof-

0 comments on commit 65070fa

Please sign in to comment.