From 8d9454e1a71003670bd2af492f9f44be72e7604f Mon Sep 17 00:00:00 2001 From: Nevsen Date: Wed, 23 Sep 2020 02:44:38 +0300 Subject: [PATCH 01/12] first lesson --- date.php | 7 +++++++ index.php | 29 +++++++++++++++++++++++++++++ template.html | 22 ++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 date.php create mode 100644 index.php create mode 100644 template.html diff --git a/date.php b/date.php new file mode 100644 index 0000000..18f3c18 --- /dev/null +++ b/date.php @@ -0,0 +1,7 @@ +Time: $time
Date: $date"; +?> \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..7f7f15b --- /dev/null +++ b/index.php @@ -0,0 +1,29 @@ + \ No newline at end of file diff --git a/template.html b/template.html new file mode 100644 index 0000000..4f58772 --- /dev/null +++ b/template.html @@ -0,0 +1,22 @@ + + + + + + + +

{{ h1 }}

+Краткая биография обо мне +Родился в 1985 году в городе Москва. Закончил в 2008 году МАИ. +На данный момент работаю ведущим инженером в крупной авиакомпании. +Поскольку я люблю авиацию, то хотел бы поделиться несколькими интересными +фотографиями на эту тему +

+Тут можете поместить картинку +

+

+Просто пример жирного текста +

+{{ year }} + + \ No newline at end of file From 7e00b942d6f7b457287a3ae1810480333ef90942 Mon Sep 17 00:00:00 2001 From: Nevsen Date: Mon, 28 Sep 2020 03:02:40 +0300 Subject: [PATCH 02/12] homework for lesson2 --- date.php | 7 ----- index.php | 67 +++++++++++++++++++++++++++++-------------- scripts/task1.php | 12 ++++++++ scripts/task2.php | 41 ++++++++++++++++++++++++++ scripts/task3&4.php | 47 ++++++++++++++++++++++++++++++ scripts/task6.php | 13 +++++++++ scripts/task7.php | 28 ++++++++++++++++++ template.html | 22 -------------- templates/main.php | 65 +++++++++++++++++++++++++++++++++++++++++ templates/task1.php | 21 ++++++++++++++ templates/task2.php | 10 +++++++ templates/task3&4.php | 10 +++++++ templates/task6.php | 9 ++++++ templates/task7.php | 8 ++++++ 14 files changed, 309 insertions(+), 51 deletions(-) delete mode 100644 date.php create mode 100644 scripts/task1.php create mode 100644 scripts/task2.php create mode 100644 scripts/task3&4.php create mode 100644 scripts/task6.php create mode 100644 scripts/task7.php delete mode 100644 template.html create mode 100644 templates/main.php create mode 100644 templates/task1.php create mode 100644 templates/task2.php create mode 100644 templates/task3&4.php create mode 100644 templates/task6.php create mode 100644 templates/task7.php diff --git a/date.php b/date.php deleted file mode 100644 index 18f3c18..0000000 --- a/date.php +++ /dev/null @@ -1,7 +0,0 @@ -Time: $time
Date: $date"; -?> \ No newline at end of file diff --git a/index.php b/index.php index 7f7f15b..401f022 100644 --- a/index.php +++ b/index.php @@ -1,29 +1,52 @@ $value) + { + if (!in_array($value,array(".",".."))) + { + if (is_dir($path . DIRECTORY_SEPARATOR . $value)) + { + $result[$value] = dirToArray($path . DIRECTORY_SEPARATOR . $value); + } + else + { + $result[] = $value; + } + } + } + + return $result; +} + +function renderTemplates($entryPoint){ + $templates = dirToArray($entryPoint); + $content = ''; + + foreach ($templates as $key => $value) { + $content = include("$entryPoint/$value"); + } + return $content; - $content = str_replace("{{ year }}", $template, $content); - echo $content; - - /* task 5 - swap two vars - $a=$a+$b-($b=$a) - */ - - /* task 3 - $a = 5; - $b = '05'; - - var_dump($a == $b); // true потому что производится не строгое сравнение с приведением типа +} - var_dump((int)'00012345'); // Почему 12345? При явном приведении строки в целочисленное число - нули отбрасываются +// function renderTemplatesRecursive($pageName, $content = ''){ +// ob_start(); +// $filename = 'templates/' . $pageName . '.php'; +// if(file_exists($filename)){ +// include($filename); +// } +// return ob_get_clean(); +// } - var_dump((float)123.0 === (int)123.0); // false потому что сравнение строгое со сравнением типов - они разные - var_dump((int)0 === (int)'hello, world'); // true потому что приведение строки к численному типу дает 0 - */ +renderTemplates('templates'); ?> \ No newline at end of file diff --git a/scripts/task1.php b/scripts/task1.php new file mode 100644 index 0000000..d1a11dc --- /dev/null +++ b/scripts/task1.php @@ -0,0 +1,12 @@ + 0) { + $sub = $a - $b; +} elseif ($a && $b < 0) { + $mul = $a * $b; +} else { + $sum = $a + $b; +} +?> \ No newline at end of file diff --git a/scripts/task2.php b/scripts/task2.php new file mode 100644 index 0000000..f5d18fb --- /dev/null +++ b/scripts/task2.php @@ -0,0 +1,41 @@ + \ No newline at end of file diff --git a/scripts/task3&4.php b/scripts/task3&4.php new file mode 100644 index 0000000..f10da0c --- /dev/null +++ b/scripts/task3&4.php @@ -0,0 +1,47 @@ + \ No newline at end of file diff --git a/scripts/task6.php b/scripts/task6.php new file mode 100644 index 0000000..eddaccc --- /dev/null +++ b/scripts/task6.php @@ -0,0 +1,13 @@ + \ No newline at end of file diff --git a/scripts/task7.php b/scripts/task7.php new file mode 100644 index 0000000..c4122ec --- /dev/null +++ b/scripts/task7.php @@ -0,0 +1,28 @@ + 10 && $str < 20){ //11 - 19 + return $for_5; + } + if ($str_x > 1 && $str_x < 5){ //2,3,4 + return $for_2; + } + if ($str_x == 1){ //1 + return $for_1; + } + return $for_5; +} + +$h = handleCases(getHours(), 'час', 'часа', 'часов'); +$m = handleCases(getMinutes(), 'минута', 'минуты', 'минут'); +?> \ No newline at end of file diff --git a/template.html b/template.html deleted file mode 100644 index 4f58772..0000000 --- a/template.html +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - -

{{ h1 }}

-Краткая биография обо мне -Родился в 1985 году в городе Москва. Закончил в 2008 году МАИ. -На данный момент работаю ведущим инженером в крупной авиакомпании. -Поскольку я люблю авиацию, то хотел бы поделиться несколькими интересными -фотографиями на эту тему -

-Тут можете поместить картинку -

-

-Просто пример жирного текста -

-{{ year }} - - \ No newline at end of file diff --git a/templates/main.php b/templates/main.php new file mode 100644 index 0000000..80cacf6 --- /dev/null +++ b/templates/main.php @@ -0,0 +1,65 @@ + + + + + Lesson2 + + + +
+ +
+ + \ No newline at end of file diff --git a/templates/task1.php b/templates/task1.php new file mode 100644 index 0000000..c1d008a --- /dev/null +++ b/templates/task1.php @@ -0,0 +1,21 @@ + +
+

Задание 1

+
+
+ A: +
+
+ B: +
+
+ Сумма: +
+
+ Разность: +
+
+ Произведение: +
+
+
\ No newline at end of file diff --git a/templates/task2.php b/templates/task2.php new file mode 100644 index 0000000..f2589f2 --- /dev/null +++ b/templates/task2.php @@ -0,0 +1,10 @@ + +
+

Задание 2

+

Значения чисел от $a до 15

+
+
+ A: +
+
+
\ No newline at end of file diff --git a/templates/task3&4.php b/templates/task3&4.php new file mode 100644 index 0000000..d642dde --- /dev/null +++ b/templates/task3&4.php @@ -0,0 +1,10 @@ + +
+

Задание 3,4

+
+
Сумма:
+
Разность:
+
Произведение:
+
Частное:
+
+
\ No newline at end of file diff --git a/templates/task6.php b/templates/task6.php new file mode 100644 index 0000000..02cd796 --- /dev/null +++ b/templates/task6.php @@ -0,0 +1,9 @@ + +
+

Задание 6

+
+
Число:
+
Степень:
+
Значение:
+
+
\ No newline at end of file diff --git a/templates/task7.php b/templates/task7.php new file mode 100644 index 0000000..08cae9c --- /dev/null +++ b/templates/task7.php @@ -0,0 +1,8 @@ + + +
+

Задание 7

+
+
Текущее время:
+
+
\ No newline at end of file From cc4924150db3be174ba94a55677dcb1e7e7452ee Mon Sep 17 00:00:00 2001 From: Nevsen Date: Tue, 29 Sep 2020 20:21:27 +0300 Subject: [PATCH 03/12] some updates and refactor --- scripts/task1.php | 4 ++-- scripts/task3&4.php | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/task1.php b/scripts/task1.php index d1a11dc..fae2e6c 100644 --- a/scripts/task1.php +++ b/scripts/task1.php @@ -2,9 +2,9 @@ $a = rand(-50, 50); $b = rand(-50, 50); -if ($a && $b > 0) { +if ($a >= 0 && $b >= 0) { $sub = $a - $b; -} elseif ($a && $b < 0) { +} elseif ($a < 0 || $b < 0) { $mul = $a * $b; } else { $sum = $a + $b; diff --git a/scripts/task3&4.php b/scripts/task3&4.php index f10da0c..00518da 100644 --- a/scripts/task3&4.php +++ b/scripts/task3&4.php @@ -12,18 +12,14 @@ function mul($arg1, $arg2){ } function div($arg1, $arg2){ - if($arg1 == 0 || $arg2 == 0) { + if($arg2 == 0) { return 'Ошибка! На ноль делить нельзя.'; } return round($arg1 / $arg2, 3); } -function handleData($str){ - return explode(" ", $str); -} - function mathOperation($str){ - $arr = handleData($str); + $arr = explode(" ", $str); switch ($arr[1]) { case '+': return sum($arr[0], $arr[2]); @@ -33,13 +29,17 @@ function mathOperation($str){ return mul($arr[0], $arr[2]); case '/': return div($arr[0], $arr[2]); + default: + return "Нет такой операции"; } } /* Вариант реализации по заданию, выше - собственный function mathOperation($arg1, $arg2, $operation){ - return $operation($arg1, $arg2); + if(function_exists($operation)){ + return $operation($arg1, $arg2); + } } echo mathOperation(4, 7, 'mul'); From c11c3e57af6e7330c7c23cd1ab869c76a959ef34 Mon Sep 17 00:00:00 2001 From: Nevsen Date: Sat, 3 Oct 2020 08:20:06 +0300 Subject: [PATCH 04/12] homework for lesson3 --- index.php | 73 ++++++++++------------- scripts/task1.php | 12 ---- scripts/task2.php | 41 ------------- scripts/task3&4.php | 47 --------------- scripts/task6.php | 13 ---- scripts/task7.php | 28 --------- templates/index.php | 1 + templates/layouts/main.php | 118 +++++++++++++++++++++++++++++++++++++ templates/main.php | 65 -------------------- templates/menu.php | 7 +++ templates/task1.php | 21 ------- templates/task2.php | 10 ---- templates/task3&4.php | 10 ---- templates/task6.php | 9 --- templates/task7.php | 8 --- templates/task_1.php | 12 ++++ templates/task_2.php | 20 +++++++ templates/task_3_8.php | 53 +++++++++++++++++ templates/task_4_5_9.php | 62 +++++++++++++++++++ 19 files changed, 304 insertions(+), 306 deletions(-) delete mode 100644 scripts/task1.php delete mode 100644 scripts/task2.php delete mode 100644 scripts/task3&4.php delete mode 100644 scripts/task6.php delete mode 100644 scripts/task7.php create mode 100644 templates/index.php create mode 100644 templates/layouts/main.php delete mode 100644 templates/main.php create mode 100644 templates/menu.php delete mode 100644 templates/task1.php delete mode 100644 templates/task2.php delete mode 100644 templates/task3&4.php delete mode 100644 templates/task6.php delete mode 100644 templates/task7.php create mode 100644 templates/task_1.php create mode 100644 templates/task_2.php create mode 100644 templates/task_3_8.php create mode 100644 templates/task_4_5_9.php diff --git a/index.php b/index.php index 401f022..db4ea18 100644 --- a/index.php +++ b/index.php @@ -1,52 +1,41 @@ $value) - { - if (!in_array($value,array(".",".."))) - { - if (is_dir($path . DIRECTORY_SEPARATOR . $value)) - { - $result[$value] = dirToArray($path . DIRECTORY_SEPARATOR . $value); - } - else - { - $result[] = $value; - } - } - } - - return $result; +if (isset($_GET['page'])) { + $page = $_GET['page']; +} else { + $page = 'index'; } -function renderTemplates($entryPoint){ - $templates = dirToArray($entryPoint); - $content = ''; +echo render($page, $params); - foreach ($templates as $key => $value) { - $content = include("$entryPoint/$value"); - } - return $content; - +function render($page, $params = []) +{ + return renderTemplate(LAYOUTS_DIR . 'main', [ + 'content' => renderTemplate($page, $params), + 'menu' => renderTemplate('menu') + ] + ); } -// function renderTemplatesRecursive($pageName, $content = ''){ -// ob_start(); -// $filename = 'templates/' . $pageName . '.php'; -// if(file_exists($filename)){ -// include($filename); -// } -// return ob_get_clean(); -// } +function renderTemplate($page, $params = []) +{ + ob_start(); + + if (!is_null($params)) + extract($params); + + $fileName = TEMPLATES_DIR . $page . ".php"; + + if (file_exists($fileName)) { + include $fileName; + } else { + Die("Такой страницы не существует. 404"); + } + + return ob_get_clean(); +} -renderTemplates('templates'); ?> \ No newline at end of file diff --git a/scripts/task1.php b/scripts/task1.php deleted file mode 100644 index fae2e6c..0000000 --- a/scripts/task1.php +++ /dev/null @@ -1,12 +0,0 @@ -= 0 && $b >= 0) { - $sub = $a - $b; -} elseif ($a < 0 || $b < 0) { - $mul = $a * $b; -} else { - $sum = $a + $b; -} -?> \ No newline at end of file diff --git a/scripts/task2.php b/scripts/task2.php deleted file mode 100644 index f5d18fb..0000000 --- a/scripts/task2.php +++ /dev/null @@ -1,41 +0,0 @@ - \ No newline at end of file diff --git a/scripts/task3&4.php b/scripts/task3&4.php deleted file mode 100644 index 00518da..0000000 --- a/scripts/task3&4.php +++ /dev/null @@ -1,47 +0,0 @@ - \ No newline at end of file diff --git a/scripts/task6.php b/scripts/task6.php deleted file mode 100644 index eddaccc..0000000 --- a/scripts/task6.php +++ /dev/null @@ -1,13 +0,0 @@ - \ No newline at end of file diff --git a/scripts/task7.php b/scripts/task7.php deleted file mode 100644 index c4122ec..0000000 --- a/scripts/task7.php +++ /dev/null @@ -1,28 +0,0 @@ - 10 && $str < 20){ //11 - 19 - return $for_5; - } - if ($str_x > 1 && $str_x < 5){ //2,3,4 - return $for_2; - } - if ($str_x == 1){ //1 - return $for_1; - } - return $for_5; -} - -$h = handleCases(getHours(), 'час', 'часа', 'часов'); -$m = handleCases(getMinutes(), 'минута', 'минуты', 'минут'); -?> \ No newline at end of file diff --git a/templates/index.php b/templates/index.php new file mode 100644 index 0000000..5dc78f3 --- /dev/null +++ b/templates/index.php @@ -0,0 +1 @@ +

Домашняя работа №3

\ No newline at end of file diff --git a/templates/layouts/main.php b/templates/layouts/main.php new file mode 100644 index 0000000..549e199 --- /dev/null +++ b/templates/layouts/main.php @@ -0,0 +1,118 @@ + + + + + index + + + +
+ +
+
+ +
+ + \ No newline at end of file diff --git a/templates/main.php b/templates/main.php deleted file mode 100644 index 80cacf6..0000000 --- a/templates/main.php +++ /dev/null @@ -1,65 +0,0 @@ - - - - - Lesson2 - - - -
- -
- - \ No newline at end of file diff --git a/templates/menu.php b/templates/menu.php new file mode 100644 index 0000000..e38fcf9 --- /dev/null +++ b/templates/menu.php @@ -0,0 +1,7 @@ + \ No newline at end of file diff --git a/templates/task1.php b/templates/task1.php deleted file mode 100644 index c1d008a..0000000 --- a/templates/task1.php +++ /dev/null @@ -1,21 +0,0 @@ - -
-

Задание 1

-
-
- A: -
-
- B: -
-
- Сумма: -
-
- Разность: -
-
- Произведение: -
-
-
\ No newline at end of file diff --git a/templates/task2.php b/templates/task2.php deleted file mode 100644 index f2589f2..0000000 --- a/templates/task2.php +++ /dev/null @@ -1,10 +0,0 @@ - -
-

Задание 2

-

Значения чисел от $a до 15

-
-
- A: -
-
-
\ No newline at end of file diff --git a/templates/task3&4.php b/templates/task3&4.php deleted file mode 100644 index d642dde..0000000 --- a/templates/task3&4.php +++ /dev/null @@ -1,10 +0,0 @@ - -
-

Задание 3,4

-
-
Сумма:
-
Разность:
-
Произведение:
-
Частное:
-
-
\ No newline at end of file diff --git a/templates/task6.php b/templates/task6.php deleted file mode 100644 index 02cd796..0000000 --- a/templates/task6.php +++ /dev/null @@ -1,9 +0,0 @@ - -
-

Задание 6

-
-
Число:
-
Степень:
-
Значение:
-
-
\ No newline at end of file diff --git a/templates/task7.php b/templates/task7.php deleted file mode 100644 index 08cae9c..0000000 --- a/templates/task7.php +++ /dev/null @@ -1,8 +0,0 @@ - - -
-

Задание 7

-
-
Текущее время:
-
-
\ No newline at end of file diff --git a/templates/task_1.php b/templates/task_1.php new file mode 100644 index 0000000..6971b6e --- /dev/null +++ b/templates/task_1.php @@ -0,0 +1,12 @@ +
+

Задание 1

+
+

С помощью цикла while вывести все числа в промежутке от 0 до 100, которые делятся на 3 без остатка.


+ + + +
+
\ No newline at end of file diff --git a/templates/task_2.php b/templates/task_2.php new file mode 100644 index 0000000..b2a8b85 --- /dev/null +++ b/templates/task_2.php @@ -0,0 +1,20 @@ +
+

Задание 2

+
+

С помощью цикла do…while написать функцию для вывода чисел от 0 до 10.


+ '; + } + if($i & 1){ + echo "{$i} - не чётное
"; + }elseif($i != 0) { + echo "{$i} - чётное
"; + } + $i++; + } while ( $i <= 10); + ?> +
+
\ No newline at end of file diff --git a/templates/task_3_8.php b/templates/task_3_8.php new file mode 100644 index 0000000..f630f43 --- /dev/null +++ b/templates/task_3_8.php @@ -0,0 +1,53 @@ + [ + 'Москва', + 'Зеленоград', + 'Клин' + ], + 'Ленинградская область' => [ + 'Санкт-Петербург', + 'Всеволожск', + 'Павловск', + 'Кронштадт' + ], + 'Рязанская область' => [ + 'Рязань', + 'Касимов', + 'Скопин', + 'Сасово', + 'Ряжск', + 'Рыбное' + ] + ]; + // знаю, что выводить таким образом - плохой тон, но что-то я так и не понял как мне из цикла извлечь эти переменные и отобразить как мне надо в шаблоне + function printAreas($areas){ + foreach ($areas as $area => $city) { + $city = implode(', ', $city) . "."; + echo "
$area:
"; + echo "
$city

"; + } + } + + + // Города начинающиеся с буквы "К". + + // function printCitiesStartsWithChar($areas){ + // foreach ($areas as $area => $city) { + // echo "
$area:
"; + // foreach ($city as $value) { + // if(preg_match('/^(к|К)/', $value)){ + // echo "
$value

"; + // } + // } + // } + // } +?> +
+

Задания 3 и 8

+
+

Объявить массив, в котором в качестве ключей будут использоваться названия областей, а в качестве значений – массивы с названиями городов из соответствующей области. Вывести в цикле значения массива. + Вывести на экран только города, начинающиеся с буквы «К»


+ +
+
\ No newline at end of file diff --git a/templates/task_4_5_9.php b/templates/task_4_5_9.php new file mode 100644 index 0000000..3a818b5 --- /dev/null +++ b/templates/task_4_5_9.php @@ -0,0 +1,62 @@ + 'а', + 'б' => 'b', + 'в' => 'v', + 'г' => 'g', + 'д' => 'd', + 'е' => 'e', + 'ё' => 'e', + 'ж' => 'j', + 'з' => 'z', + 'и' => 'i', + 'к' => 'k', + 'л' => 'l', + 'м' => 'm', + 'н' => 'n', + 'о' => 'o', + 'п' => 'p', + 'р' => 'r', + 'с' => 's', + 'т' => 't', + 'у' => 'u', + 'ф' => 'f', + 'х' => 'h', + 'ц' => 'c', + 'ч' => '4', + 'ш' => 'sh', + 'щ' => 'shc', + 'ъ' => '', + 'ы' => 'y', + 'ь' => '', + 'э' => 'e', + 'ю' => 'yu', + 'я' => '9', + ' ' => '_' + ]; + } + + function translit($str){ + $dictionary = getDictionary(); + $res = ''; + + for ($i = 0; $i < mb_strLen($str); $i++) { + $char = mb_substr($str, $i, 1); + if (empty($dictionary[$char])) { + $char = mb_strtolower($char); + $res .= mb_strtoupper($dictionary[$char]); + } else { + $res .= $dictionary[$char]; + } + } + return $res; + } +?> +
+

Задание 4, 5 и 9

+
+

Объявить массив, индексами которого являются буквы русского языка, а значениями – соответствующие латинские буквосочетания.


+ +
+
\ No newline at end of file From 6aaae0acd7b05a2909ae9c65bdb9c9326278e757 Mon Sep 17 00:00:00 2001 From: Nevsen Date: Tue, 6 Oct 2020 01:25:11 +0300 Subject: [PATCH 05/12] upd and refactor --- index.php | 2 +- templates/layouts/main.php | 3 +- templates/menu.php | 63 +++++++++++++++++++++++++++++++++----- templates/task_2.php | 5 ++- 4 files changed, 61 insertions(+), 12 deletions(-) diff --git a/index.php b/index.php index db4ea18..1baf5c4 100644 --- a/index.php +++ b/index.php @@ -8,7 +8,7 @@ $page = 'index'; } -echo render($page, $params); +echo render($page); function render($page, $params = []) { diff --git a/templates/layouts/main.php b/templates/layouts/main.php index 549e199..4b927c2 100644 --- a/templates/layouts/main.php +++ b/templates/layouts/main.php @@ -42,10 +42,11 @@ cursor: pointer; } .nav-link { + font-size: 15px; text-transform: uppercase; text-decoration: none; padding: 8px 10px; - width: 120px; + width: 150px; margin: 2%; text-align: center; background-color: #4c4848b8; diff --git a/templates/menu.php b/templates/menu.php index e38fcf9..5c8cddc 100644 --- a/templates/menu.php +++ b/templates/menu.php @@ -1,7 +1,56 @@ - \ No newline at end of file + 'Главная', + 'href' => '/', + 'style' => 'nav-li', + 'styleLink' => 'nav-link' + ], + [ + 'title' => 'Задание 1', + 'href' => '?page=task_1', + 'style' => 'nav-li', + 'styleLink' => 'nav-link' + ], + [ + 'title' => 'Задание 2', + 'href' => '?page=task_2', + 'style' => 'nav-li', + 'styleLink' => 'nav-link' + ], + [ + 'title' => 'Задание 3 и 8', + 'href' => '?page=task_3_8', + 'style' => 'nav-li', + 'styleLink' => 'nav-link' + ], + [ + 'title' => 'Задание 4, 5 и 9', + 'href' => '?page=task_4_5_9', + 'style' => 'nav-li', + 'styleLink' => 'nav-link' + ], +]; + +function renderMenu($menuList) { + $res = "