Compare commits
1 commit
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
085820d78c |
5 changed files with 71 additions and 62 deletions
|
|
@ -57,6 +57,7 @@ class Controller_Component
|
||||||
public /*.Settings.*/$registry;
|
public /*.Settings.*/$registry;
|
||||||
public /*.Database.*/$db;
|
public /*.Database.*/$db;
|
||||||
public /*.Collection.*/$parameter;
|
public /*.Collection.*/$parameter;
|
||||||
|
static public $ID;
|
||||||
|
|
||||||
public $module;
|
public $module;
|
||||||
public $item_module;
|
public $item_module;
|
||||||
|
|
@ -223,7 +224,7 @@ class Controller_Component
|
||||||
if (file_exists($path)) {
|
if (file_exists($path)) {
|
||||||
require_once ($path);
|
require_once ($path);
|
||||||
|
|
||||||
$component = new $className();
|
$component = new $className();
|
||||||
$component->db = $db;
|
$component->db = $db;
|
||||||
$component->registry = $registry;
|
$component->registry = $registry;
|
||||||
|
|
||||||
|
|
@ -244,13 +245,18 @@ class Controller_Component
|
||||||
$component->webPath = array(COMPONENTS_WEB . '/' . $name, SITE_WWW_PATH . '/components/' . $name);
|
$component->webPath = array(COMPONENTS_WEB . '/' . $name, SITE_WWW_PATH . '/components/' . $name);
|
||||||
$component->COMPONENTS_WEB = COMPONENTS_WEB;
|
$component->COMPONENTS_WEB = COMPONENTS_WEB;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$stmt = $db->prepareStatement("SELECT * FROM component WHERE code = ?");
|
// Нужно для отличия компонентов на странице нужно извлекать id для всей страницы сразу?
|
||||||
$stmt->setString(1, $expression);
|
// Просто вести глобальный счетчик для компонентов
|
||||||
$cid = $stmt->executeQuery();
|
|
||||||
if ($cid->next()) {
|
$component->component_id = self::$ID++;
|
||||||
$component->component_id = $cid->getInt('id_component');
|
/*
|
||||||
|
$stmt = $db->prepare("SELECT * FROM component WHERE code = :code");
|
||||||
|
$stmt->execute(['code' => $expression]);
|
||||||
|
$cid = $stmt->fetch();
|
||||||
|
if ($cid) {
|
||||||
|
$component->component_id = $cid['id_component'];
|
||||||
} else {
|
} else {
|
||||||
$last = $db->getIdGenerator();
|
$last = $db->getIdGenerator();
|
||||||
if ($last->isBeforeInsert()) {
|
if ($last->isBeforeInsert()) {
|
||||||
|
|
@ -269,6 +275,7 @@ class Controller_Component
|
||||||
}
|
}
|
||||||
$component->component_id = $result;
|
$component->component_id = $result;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
$params = new Collection();
|
$params = new Collection();
|
||||||
$params->import(array_merge($_GET, $arguments));
|
$params->import(array_merge($_GET, $arguments));
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,8 @@ class Database extends PDO
|
||||||
static function getConnection(array $dsn)
|
static function getConnection(array $dsn)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($dsn['phptype'] == 'pgsql' || $dsn['phptype'] == 'mysql') {
|
if ($dsn['phptype'] == 'pgsql' || $dsn['phptype'] == 'mysql') {
|
||||||
$port = (isset($dsn['port'])) ? "port={$dsn['port']};" : "";
|
$port = (isset($dsn['port'])) ? "port={$dsn['port']};" : "";
|
||||||
/*.Database.*/$connection = new static("{$dsn['phptype']}:host={$dsn['hostspec']}; $port dbname={$dsn['database']}", $dsn['username'], $dsn['password']);
|
/*.Database.*/$connection = new static("{$dsn['phptype']}:host={$dsn['hostspec']}; $port dbname={$dsn['database']}", $dsn['username'], $dsn['password']);
|
||||||
if ($dsn['phptype'] == 'pgsql') {
|
if ($dsn['phptype'] == 'pgsql') {
|
||||||
$connection->query('SET client_encoding="UTF-8"');
|
$connection->query('SET client_encoding="UTF-8"');
|
||||||
|
|
@ -100,8 +100,7 @@ class Database extends PDO
|
||||||
return $sth->fetch(PDO::FETCH_ASSOC);
|
return $sth->fetch(PDO::FETCH_ASSOC);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function assignQuote($x, $y)
|
function assignQuote($x, $y) {
|
||||||
{
|
|
||||||
return $x . "=" . $this->quote($y);
|
return $x . "=" . $this->quote($y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,9 @@ class Database_PDOStatement extends PDOStatement implements IteratorAggregate
|
||||||
|
|
||||||
function execute($args = null) {
|
function execute($args = null) {
|
||||||
$result = parent::execute($args);
|
$result = parent::execute($args);
|
||||||
|
if (class_exists('Log')) {
|
||||||
|
Log::add('execute', [$this->queryString, $args]);
|
||||||
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -143,7 +143,7 @@ class Tools_SQLStatementExtractor {
|
||||||
trigger_error("substring(), Endindex out of bounds must be $startpos<n<".($len-1), E_USER_ERROR);
|
trigger_error("substring(), Endindex out of bounds must be $startpos<n<".($len-1), E_USER_ERROR);
|
||||||
}
|
}
|
||||||
if ($startpos === $endpos) {
|
if ($startpos === $endpos) {
|
||||||
return (string) $string{$startpos};
|
return (string) $string[$startpos];
|
||||||
} else {
|
} else {
|
||||||
$len = $endpos-$startpos;
|
$len = $endpos-$startpos;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,66 +1,66 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Tools_String {
|
class Tools_String {
|
||||||
|
|
||||||
// from creole
|
// from creole
|
||||||
static function strToArray($str) {
|
static function strToArray($str) {
|
||||||
$str = substr($str, 1, -1); // remove { }
|
$str = substr($str, 1, -1); // remove { }
|
||||||
$res = array();
|
$res = array();
|
||||||
|
|
||||||
$subarr = array();
|
$subarr = array();
|
||||||
$in_subarr = 0;
|
$in_subarr = 0;
|
||||||
|
|
||||||
$toks = explode(',', $str);
|
$toks = explode(',', $str);
|
||||||
foreach($toks as $tok) {
|
foreach($toks as $tok) {
|
||||||
if ($in_subarr > 0) { // already in sub-array?
|
if ($in_subarr > 0) { // already in sub-array?
|
||||||
$subarr[$in_subarr][] = $tok;
|
$subarr[$in_subarr][] = $tok;
|
||||||
if ('}' === substr($tok, -1, 1)) { // check to see if we just added last component
|
if ('}' === substr($tok, -1, 1)) { // check to see if we just added last component
|
||||||
$res[] = static::strToArray(implode(',', $subarr[$in_subarr]));
|
$res[] = static::strToArray(implode(',', $subarr[$in_subarr]));
|
||||||
$in_subarr--;
|
$in_subarr--;
|
||||||
}
|
}
|
||||||
} elseif ($tok{0} === '{') { // we're inside a new sub-array
|
} elseif ($tok[0] === '{') { // we're inside a new sub-array
|
||||||
if ('}' !== substr($tok, -1, 1)) {
|
if ('}' !== substr($tok, -1, 1)) {
|
||||||
$in_subarr++;
|
$in_subarr++;
|
||||||
// if sub-array has more than one element
|
// if sub-array has more than one element
|
||||||
$subarr[$in_subarr] = array();
|
$subarr[$in_subarr] = array();
|
||||||
$subarr[$in_subarr][] = $tok;
|
$subarr[$in_subarr][] = $tok;
|
||||||
} else {
|
} else {
|
||||||
$res[] = static::strToArray($tok);
|
$res[] = static::strToArray($tok);
|
||||||
}
|
}
|
||||||
} else { // not sub-array
|
} else { // not sub-array
|
||||||
$val = trim($tok, '"'); // remove " (surrounding strings)
|
$val = trim($tok, '"'); // remove " (surrounding strings)
|
||||||
// perform type castng here?
|
// perform type castng here?
|
||||||
$res[] = $val;
|
$res[] = $val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Нормализация строк на русском
|
//Нормализация строк на русском
|
||||||
static function normalizeRussian($str) {
|
static function normalizeRussian($str) {
|
||||||
$result = preg_replace('/\s+/',' ', $str);
|
$result = preg_replace('/\s+/',' ', $str);
|
||||||
if (is_string($result)) {
|
if (is_string($result)) {
|
||||||
$result = trim($result); //Замена длинных пробелов на одинарные, пробелы по краям
|
$result = trim($result); //Замена длинных пробелов на одинарные, пробелы по краям
|
||||||
$result = mb_strtolower($result);
|
$result = mb_strtolower($result);
|
||||||
$result = preg_replace('/ё/','е', $str); //е на ё
|
$result = preg_replace('/ё/','е', $str); //е на ё
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Проверка равенства двух строк на русском языке.
|
//Проверка равенства двух строк на русском языке.
|
||||||
static function equalRussianCheck($str1,$str2) {
|
static function equalRussianCheck($str1,$str2) {
|
||||||
return self::normalizeRussian($str1) == self::normalizeRussian($str2);
|
return self::normalizeRussian($str1) == self::normalizeRussian($str2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Попадает ли строка в список вариантов
|
* Попадает ли строка в список вариантов
|
||||||
* input: $str="foo1" $variants="foo1|foo2|foo3"
|
* input: $str="foo1" $variants="foo1|foo2|foo3"
|
||||||
* output: true
|
* output: true
|
||||||
* input: $str="foo" $variants="foo1|foo2|foo3"
|
* input: $str="foo" $variants="foo1|foo2|foo3"
|
||||||
* output: false
|
* output: false
|
||||||
*/
|
*/
|
||||||
static function compare_string_to_variants($str, $variants){
|
static function compare_string_to_variants($str, $variants){
|
||||||
$variants_array = explode('|', $variants);
|
$variants_array = explode('|', $variants);
|
||||||
$founded = false;
|
$founded = false;
|
||||||
|
|
@ -69,15 +69,15 @@ class Tools_String {
|
||||||
}
|
}
|
||||||
return $founded;
|
return $founded;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function mb_str_split($str) {
|
static function mb_str_split($str) {
|
||||||
return preg_split('~~u', $str, null, PREG_SPLIT_NO_EMPTY);
|
return preg_split('~~u', $str, null, PREG_SPLIT_NO_EMPTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function mb_strtr($str, $from, $to) {
|
static function mb_strtr($str, $from, $to) {
|
||||||
return str_replace(self::mb_str_split($from), self::mb_str_split($to), $str);
|
return str_replace(self::mb_str_split($from), self::mb_str_split($to), $str);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function encodestring($st) {
|
static function encodestring($st) {
|
||||||
$st = self::mb_strtr($st,"абвгдеёзийклмнопрстуфхъыэ !+-()", "abvgdeeziyklmnoprstufh_ie______");
|
$st = self::mb_strtr($st,"абвгдеёзийклмнопрстуфхъыэ !+-()", "abvgdeeziyklmnoprstufh_ie______");
|
||||||
$st = self::mb_strtr($st,"АБВГДЕЁЗИЙКЛМНОПРСТУФХЪЫЭ", "ABVGDEEZIYKLMNOPRSTUFH_IE");
|
$st = self::mb_strtr($st,"АБВГДЕЁЗИЙКЛМНОПРСТУФХЪЫЭ", "ABVGDEEZIYKLMNOPRSTUFH_IE");
|
||||||
|
|
@ -95,16 +95,16 @@ class Tools_String {
|
||||||
"*" => '_',
|
"*" => '_',
|
||||||
"ж"=>"zh", "ц"=>"ts", "ч"=>"ch", "ш"=>"sh",
|
"ж"=>"zh", "ц"=>"ts", "ч"=>"ch", "ш"=>"sh",
|
||||||
"щ"=>"shch","ь"=>"", "ю"=>"yu", "я"=>"ya",
|
"щ"=>"shch","ь"=>"", "ю"=>"yu", "я"=>"ya",
|
||||||
"Ж"=>"ZH", "Ц"=>"TS", "Ч"=>"CH", "Ш"=>"SH",
|
"Ж"=>"ZH", "Ц"=>"TS", "Ч"=>"CH", "Ш"=>"SH",
|
||||||
"Щ"=>"SHCH","Ь"=>"", "Ю"=>"YU", "Я"=>"YA",
|
"Щ"=>"SHCH","Ь"=>"", "Ю"=>"YU", "Я"=>"YA",
|
||||||
"Й"=>"i", "й"=>"ie", "ё"=>"Ye",
|
"Й"=>"i", "й"=>"ie", "ё"=>"Ye",
|
||||||
"№"=>"N"
|
"№"=>"N"
|
||||||
));
|
));
|
||||||
return strtolower($st);
|
return strtolower($st);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function validate_encoded_string($st) {
|
static function validate_encoded_string($st) {
|
||||||
$enc_st = self::encodestring($st);
|
$enc_st = self::encodestring($st);
|
||||||
return preg_match('/^[\w_-]+(\.[\w_-]+)?$/', $enc_st);
|
return preg_match('/^[\w_-]+(\.[\w_-]+)?$/', $enc_st);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue