From 958033a0576ff3548ccb02fef021234eec2a4962 Mon Sep 17 00:00:00 2001 From: Podlesnov Phedor Date: Fri, 21 May 2021 11:36:47 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B7=D1=80=D0=B5=D1=88=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BD=D0=B0=20-=20=D0=B2=20=D0=BD=D0=B0?= =?UTF-8?q?=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8=D0=B8=20=D1=84=D0=B0=D0=B9=D0=BB?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Tools/Image.php | 10 ++-- src/Tools/String.php | 94 ++++++++++++++++++------------------- src/Tools/TemplateImage.php | 47 +++++++++---------- 3 files changed, 75 insertions(+), 76 deletions(-) diff --git a/src/Tools/Image.php b/src/Tools/Image.php index c9c10ef..e750540 100644 --- a/src/Tools/Image.php +++ b/src/Tools/Image.php @@ -1,7 +1,7 @@ 1 && !$force) $percent = 1; $new_width = $width * $percent; $new_height = $height * $percent; - + $image_p = imagecreatetruecolor($new_width, $new_height); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); @@ -36,4 +36,4 @@ class Tools_Image case 'gif': imagegif($image, $uri); break; } } -} +} \ No newline at end of file diff --git a/src/Tools/String.php b/src/Tools/String.php index 678fd26..8380c77 100644 --- a/src/Tools/String.php +++ b/src/Tools/String.php @@ -4,55 +4,55 @@ class Tools_String { // from creole static function strToArray($str) { - $str = substr($str, 1, -1); // remove { } - $res = array(); - - $subarr = array(); - $in_subarr = 0; - - $toks = explode(',', $str); - foreach($toks as $tok) { - if ($in_subarr > 0) { // already in sub-array? - $subarr[$in_subarr][] = $tok; - if ('}' === substr($tok, -1, 1)) { // check to see if we just added last component - $res[] = static::strToArray(implode(',', $subarr[$in_subarr])); - $in_subarr--; - } - } elseif ($tok[0] === '{') { // we're inside a new sub-array - if ('}' !== substr($tok, -1, 1)) { - $in_subarr++; - // if sub-array has more than one element - $subarr[$in_subarr] = array(); - $subarr[$in_subarr][] = $tok; - } else { - $res[] = static::strToArray($tok); - } - } else { // not sub-array - $val = trim($tok, '"'); // remove " (surrounding strings) - // perform type castng here? - $res[] = $val; - } - } - - return $res; + $str = substr($str, 1, -1); // remove { } + $res = array(); + + $subarr = array(); + $in_subarr = 0; + + $toks = explode(',', $str); + foreach($toks as $tok) { + if ($in_subarr > 0) { // already in sub-array? + $subarr[$in_subarr][] = $tok; + if ('}' === substr($tok, -1, 1)) { // check to see if we just added last component + $res[] = static::strToArray(implode(',', $subarr[$in_subarr])); + $in_subarr--; + } + } elseif ($tok[0] === '{') { // we're inside a new sub-array + if ('}' !== substr($tok, -1, 1)) { + $in_subarr++; + // if sub-array has more than one element + $subarr[$in_subarr] = array(); + $subarr[$in_subarr][] = $tok; + } else { + $res[] = static::strToArray($tok); + } + } else { // not sub-array + $val = trim($tok, '"'); // remove " (surrounding strings) + // perform type castng here? + $res[] = $val; + } + } + + return $res; } //Нормализация строк на русском static function normalizeRussian($str) { $result = preg_replace('/\s+/',' ', $str); if (is_string($result)) { - $result = trim($result); //Замена длинных пробелов на одинарные, пробелы по краям - $result = mb_strtolower($result); - $result = preg_replace('/ё/','е', $str); //е на ё + $result = trim($result); //Замена длинных пробелов на одинарные, пробелы по краям + $result = mb_strtolower($result); + $result = preg_replace('/ё/','е', $str); //е на ё } - return $result; + return $result; } - + //Проверка равенства двух строк на русском языке. static function equalRussianCheck($str1,$str2) { - return self::normalizeRussian($str1) == self::normalizeRussian($str2); + return self::normalizeRussian($str1) == self::normalizeRussian($str2); } - + /** * Попадает ли строка в список вариантов @@ -60,7 +60,7 @@ class Tools_String { * output: true * input: $str="foo" $variants="foo1|foo2|foo3" * output: false -*/ +*/ static function compare_string_to_variants($str, $variants){ $variants_array = explode('|', $variants); $founded = false; @@ -69,17 +69,17 @@ class Tools_String { } return $founded; } - + static function mb_str_split($str) { return preg_split('~~u', $str, null, PREG_SPLIT_NO_EMPTY); } - + static function mb_strtr($str, $from, $to) { return str_replace(self::mb_str_split($from), self::mb_str_split($to), $str); - } - + } + 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 = strtr($st, array( " " => '_', @@ -94,8 +94,8 @@ class Tools_String { "#" => '_', "*" => '_', "ж"=>"zh", "ц"=>"ts", "ч"=>"ch", "ш"=>"sh", - "щ"=>"shch","ь"=>"", "ю"=>"yu", "я"=>"ya", - "Ж"=>"ZH", "Ц"=>"TS", "Ч"=>"CH", "Ш"=>"SH", + "щ"=>"shch","ь"=>"", "ю"=>"yu", "я"=>"ya", + "Ж"=>"ZH", "Ц"=>"TS", "Ч"=>"CH", "Ш"=>"SH", "Щ"=>"SHCH","Ь"=>"", "Ю"=>"YU", "Я"=>"YA", "Й"=>"i", "й"=>"ie", "ё"=>"Ye", "№"=>"N" @@ -107,4 +107,4 @@ class Tools_String { $enc_st = self::encodestring($st); return preg_match('/^[\w_-]+(\.[\w_-]+)?$/', $enc_st); } -} +} \ No newline at end of file diff --git a/src/Tools/TemplateImage.php b/src/Tools/TemplateImage.php index 0c0f489..cdf97ca 100644 --- a/src/Tools/TemplateImage.php +++ b/src/Tools/TemplateImage.php @@ -7,14 +7,14 @@ class Tools_TemplateImage { static $listfiles = array('jpg' => 'jpeg', 'gif' => 'gif', 'png' => 'png', 'bmp' => 'wbmp'); static $listfonts = array( - 'georgia' => 'georgia.ttf', - 'georgiabd' => 'georgiab.ttf', - 'georgiaz' => 'georgiaz.ttf', - 'times' => 'times.ttf', - 'timesbd' => 'timesbd.ttf', - 'arial' => 'arial.ttf', - 'arialbd' => 'arialbd.ttf', - 'tahoma' => 'tahoma.ttf', + 'georgia' => 'georgia.ttf', + 'georgiabd' => 'georgiab.ttf', + 'georgiaz' => 'georgiaz.ttf', + 'times' => 'times.ttf', + 'timesbd' => 'timesbd.ttf', + 'arial' => 'arial.ttf', + 'arialbd' => 'arialbd.ttf', + 'tahoma' => 'tahoma.ttf', 'calibri' => 'calibri.ttf', 'calibribd' => 'calibrib.ttf', 'calibrii' => 'calibrii.ttf', @@ -59,14 +59,14 @@ class Tools_TemplateImage /** * Путь у шрифтам */ - function fontPath($path) + function fontPath($path) { assert(is_string($path)); $this->base = $path; } - - function set($name, $value) + + function set($name, $value) { assert(is_string($name)); @@ -87,11 +87,11 @@ class Tools_TemplateImage /** * Создает изображение из файла */ - function imagefromfile($file) + function imagefromfile($file) { assert(is_string($file)); - $suffix = pathinfo($file, PATHINFO_EXTENSION); + $suffix = pathinfo($file, PATHINFO_EXTENSION); if (array_key_exists($suffix, self::$listfiles)) { return call_user_func('imagecreatefrom' . self::$listfiles[$suffix], $file); } @@ -99,12 +99,12 @@ class Tools_TemplateImage } function getFontFile($name) - { + { assert(is_string($name)); if(array_key_exists(strtolower($name), self::$listfonts)) { return $this->base . self::$listfonts[$name]; - } + } return $this->base . 'arial.ttf'; } @@ -127,23 +127,23 @@ class Tools_TemplateImage $fontfile = $this->getFontFile($value->fontFamily . $this->fontSuffix($value->fontStyle)); $color = intval(substr($value->color, 1), 16); - if ($value->align[0]) { + if ($value->align[0]) { $align = Tools_Drawing::ALIGN_LEFT; - } elseif ($value->align[2]) { + } elseif ($value->align[2]) { $align = Tools_Drawing::ALIGN_RIGHT; } else { $align = Tools_Drawing::ALIGN_CENTER; } - if ($value->valign[0]) { + if ($value->valign[0]) { $valign = Tools_Drawing::ALIGN_TOP; - } elseif ($value->valign[1]) { + } elseif ($value->valign[1]) { $valign = Tools_Drawing::ALIGN_CENTER; } else { $valign = Tools_Drawing::ALIGN_BOTTOM; } - Tools_Drawing::imagettftextbox($this->image, $size, 0, $value->left, $value->top, $color, $fontfile, $text, + Tools_Drawing::imagettftextbox($this->image, $size, 0, $value->left, $value->top, $color, $fontfile, $text, $value->width, $value->height, $align, $valign); } @@ -158,8 +158,8 @@ class Tools_TemplateImage } function setSize($new_width, $new_height) - { - $width = imagesx($this->image); + { + $width = imagesx($this->image); $height = imagesy($this->image); if($new_height == false) { $new_height = ceil($height * $new_width / $width); @@ -170,7 +170,7 @@ class Tools_TemplateImage imagecopyresampled($image_p, $this->image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); // imagecopyresized($image_p, $this->image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); $this->image = $image_p; - } + } function prepare() { if($this->prepare) { @@ -201,4 +201,3 @@ class Tools_TemplateImage } } } -