Skip to content

Commit

Permalink
1.4.9
Browse files Browse the repository at this point in the history
Remastered version
  • Loading branch information
KarelWintersky committed Mar 14, 2018
1 parent 120c7d8 commit dd2d156
Show file tree
Hide file tree
Showing 10 changed files with 503 additions and 475 deletions.
23 changes: 12 additions & 11 deletions build.minified.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,28 @@
# Generating minimized file (all-in-one)
DIR_SOURCES='./sources_v1'
DIR_DEST='./production'
FILE_SOURCE='generator.php'
FILE_DEST='sitemap_generator.php'

echo 'Generating all-in-one php-file'

echo '#!/usr/bin/php' > $DIR_DEST/$FILE_DEST
cat $DIR_SOURCES/generate.php >> $DIR_DEST/$FILE_DEST
cat $DIR_SOURCES/$FILE_SOURCE >> $DIR_DEST/$FILE_DEST

echo 'Incapsulating core.sitemapgen.php'
cp $DIR_SOURCES/core.sitemapgen.php __tmp__.php
echo 'Incapsulating class.CLIConsole.php'
cp $DIR_SOURCES/class.CLIConsole.php __tmp__.php
sed -i "1s/.*/\/\*\*\//" __tmp__.php
sed -i -e "/core\.sitemapgen\.php/{r __tmp__.php" -e ' d}' $DIR_DEST/$FILE_DEST
sed -i -e "/class\.CLIConsole\.php/{r __tmp__.php" -e ' d}' $DIR_DEST/$FILE_DEST

echo 'Incapsulating class.INI_config.php'
cp $DIR_SOURCES/class.INI_config.php __tmp__.php
echo 'Incapsulating class.INI_Config.php'
cp $DIR_SOURCES/class.INI_Config.php __tmp__.php
sed -i "1s/.*/\/\*\*\//" __tmp__.php
sed -i -e "/class\.INI_config\.php/{r __tmp__.php" -e 'd}' $DIR_DEST/$FILE_DEST
sed -i -e "/class\.INI_Config\.php/{r __tmp__.php" -e 'd}' $DIR_DEST/$FILE_DEST

echo 'Incapsulating class.DBConnectionLite.php'
cp $DIR_SOURCES/class.DBConnectionLite.php __tmp__.php
echo 'Incapsulating class.DBConnection.php'
cp $DIR_SOURCES/class.DBConnection.php __tmp__.php
sed -i "1s/.*/\/\*\*\//" __tmp__.php
sed -i -e "/class\.DBConnectionLite\.php/{r __tmp__.php" -e 'd}' $DIR_DEST/$FILE_DEST
sed -i -e "/class\.DBConnection\.php/{r __tmp__.php" -e 'd}' $DIR_DEST/$FILE_DEST

echo 'Incapsulating class.SitemapFileSaver.php'
cp $DIR_SOURCES/class.SitemapFileSaver.php __tmp__.php
Expand All @@ -32,5 +33,5 @@ sed -i -e "/class\.SitemapFileSaver\.php/{r __tmp__.php" -e 'd}' $DIR_DEST/$FIL
rm -f __tmp__.php

echo 'Ok.'
echo "$DIR_DEST/sitemap_generator.php GENERATED"
echo "$DIR_DEST/$FILE_DEST GENERATED"

File renamed without changes.
File renamed without changes.
File renamed without changes.
169 changes: 169 additions & 0 deletions sources_v1/class.CLIConsole.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
<?php

/**
* User: Arris
*
* Class CLIConsole
*
* Date: 14.03.2018, time: 22:11
*/
class CLIConsole
{
const VERSION = 1.4;

const FOREGROUND_COLORS = [
'black' => '0;30',
'dark gray' => '1;30',
'dgray' => '1;30',
'blue' => '0;34',
'light blue' => '1;34',
'lblue' => '1;34',
'green' => '0;32',
'light green' => '1;32',
'lgreen' => '1;32',
'cyan' => '0;36',
'light cyan' => '1;36',
'lcyan' => '1;36',
'red' => '0;31',
'light red' => '1;31',
'lred' => '1;31',
'purple' => '0;35',
'light purple' => '1;35',
'lpurple' => '1;35',
'brown' => '0;33',
'yellow' => '1;33',
'light gray' => '0;37',
'lgray' => '0;37',
'white' => '1;37'
];

const BACKGROUND_COLORS = [
'black' => '40',
'red' => '41',
'green' => '42',
'yellow' => '43',
'blue' => '44',
'magenta' => '45',
'cyan' => '46',
'light gray'=> '47'
];

private static $echo_status_cli_flags = [
'strip_tags' => false,
'decode_entities' => false
];

/**
* ConsoleReadline::readline('Введите число от 1 до 999: ', '/^\d{1,3}$/');
* ConsoleReadline::readline('Введите число от 100 до 999: ', '/^\d{3}$/');
*
* @param $prompt -
* @param $allowed_pattern
* @param bool|FALSE $strict_mode
* @return bool|string
*/
public static function readline($prompt, $allowed_pattern = '/.*/', $strict_mode = FALSE)
{
if ($strict_mode) {
if ((substr($allowed_pattern, 0, 1) !== '/') || (substr($allowed_pattern, -1, 1) !== '/')) {
return FALSE;
}
} else {
if (substr($allowed_pattern, 0, 1) !== '/')
$allowed_pattern = '/' . $allowed_pattern;
if (substr($allowed_pattern, -1, 1) !== '/')
$allowed_pattern .= '/';
}

do {
$result = readline($prompt);

} while (preg_match($allowed_pattern, $result) !== 1);
return $result;
}

/**
* Печатает в консоли цветное сообщение.
* Допустимые форматтеры:
* <font color=""> задает цвет из списка: black, dark gray, blue, light blue, green, lightgreen, cyan, light cyan, red, light red, purple, light purple, brown, yellow, light gray, gray
* <hr> - горизонтальная черта, 80 минусов (работает только в отдельной строчке)
* <strong> - заменяет белым цветом
* @param string $message
* @param bool|TRUE $breakline
*/
public static function echo_status_cli($message = "", $breakline = TRUE)
{
$fgcolors = self::FOREGROUND_COLORS;

// replace <br>
$pattern_br = '#(?<br>\<br\s?\/?\>)#U';
$message = preg_replace_callback($pattern_br, function ($matches) {
return PHP_EOL;
}, $message);

// replace <hr>
$pattern_hr = '#(?<hr>\<hr\s?\/?\>)#U';
$message = preg_replace_callback($pattern_hr, function ($matches) {
return PHP_EOL . str_repeat('-', 80) . PHP_EOL;
}, $message);

// replace <font>
$pattern_font = '#(?<Full>\<font[\s]+color=[\\\'\"](?<Color>[\D]+)[\\\'\"]\>(?<Content>.*)\<\/font\>)#U';
$message = preg_replace_callback($pattern_font, function ($matches) use ($fgcolors) {
$color = (PHP_VERSION_ID < 70000)
? isset($fgcolors[$matches['Color']]) ? $fgcolors[$matches['Color']] : $fgcolors['white'] // php below 7.0
: $fgcolors[$matches['Color']] ?? $fgcolors['white ']; // php 7.0+
return "\033[{$color}m{$matches['Content']}\033[0m";
}, $message);

// replace <strong>
$pattern_strong = '#(?<Full>\<strong\>(?<Content>.*)\<\/strong\>)#U';
$message = preg_replace_callback($pattern_strong, function ($matches) use ($fgcolors) {
$color = $fgcolors['white'];
return "\033[{$color}m{$matches['Content']}\033[0m";
}, $message);

// вырезает все лишние таги (если установлен флаг)
if (self::$echo_status_cli_flags['strip_tags'])
$message = strip_tags($message);

// преобразует html entity-сущности (если установлен флаг)
if (self::$echo_status_cli_flags['decode_entities'])
$message = htmlspecialchars_decode($message, ENT_QUOTES | ENT_HTML5);

if ($breakline === TRUE) $message .= PHP_EOL;
echo $message;
}

/**
* Wrapper around echo/echo_status_cli
* Выводит сообщение на экран. Если мы вызваны из командной строки - заменяет теги на управляющие последовательности.
* @param $message
* @param bool|TRUE $breakline
*/
public static function echo_status($message = "", $breakline = TRUE)
{
if (php_sapi_name() === "cli") {
self::echo_status_cli($message, $breakline);
} else {
if ($breakline === TRUE) $message .= PHP_EOL . "<br/>\r\n";
echo $message;
}
}

/**
* Устанавливает флаги обработки разных тегов в функции echo_status()
* @param bool|FALSE $will_strip - вырезать ли все лишние теги после обработки заменяемых?
* @param bool|FALSE $will_decode - преобразовывать ли html entities в их html-представление?
*/
public static function echo_status_setmode($will_strip = FALSE, $will_decode = FALSE)
{
self::$echo_status_cli_flags = array(
'strip_tags' => $will_strip,
'decode_entities' => $will_decode
);
}

}

/* end class.CLIConsole.php */
62 changes: 62 additions & 0 deletions sources_v1/class.DBConnection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

/**
* User: Arris
*
* Class DBConnection
*
* Date: 15.03.2018, time: 0:31
*/
class DBConnection extends \PDO
{
private $database_settings = array();
private $pdo_connection;
private $table_prefix = '';
public $is_connected = FALSE;
public $error_message = '';

public function __construct($db_settings)
{
$database_settings = $db_settings;

$this->table_prefix = $db_settings['table_prefix'] ?? '';
$this->database_settings = $database_settings;

$dbhost = $database_settings['hostname'];
$dbname = $database_settings['database'];
$dbuser = $database_settings['username'];
$dbpass = $database_settings['password'];
$dbport = $database_settings['port'];

$dsl = "mysql:host=$dbhost;port=$dbport;dbname=$dbname";

try {
$dbh = new \PDO($dsl, $dbuser, $dbpass);

$dbh->exec("SET NAMES utf8 COLLATE utf8_unicode_ci");
$dbh->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$dbh->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_ASSOC);

$this->pdo_connection = $dbh;
} catch (\PDOException $e) {
$this->error_message = "Database connection error!: " . $e->getMessage() . "<br/>";
$this->pdo_connection = null;
return false;
}

$this->is_connected = true;
return true;
}

/**
* @return null|PDO
*/
public function getconnection()
{
return $this->pdo_connection;
}


}

/* end class.DBConnection.php */
112 changes: 0 additions & 112 deletions sources_v1/class.DBConnectionLite.php

This file was deleted.

Loading

0 comments on commit dd2d156

Please sign in to comment.