@@ -12,84 +12,84 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class Tools extends Model { |
14 | 14 | |
15 | - /** |
|
16 | - * Return random string |
|
17 | - * |
|
18 | - * @param int $length |
|
19 | - * @param string $characters |
|
20 | - * @return string |
|
21 | - */ |
|
22 | - public static function randomString($length = 20, $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') { |
|
15 | + /** |
|
16 | + * Return random string |
|
17 | + * |
|
18 | + * @param int $length |
|
19 | + * @param string $characters |
|
20 | + * @return string |
|
21 | + */ |
|
22 | + public static function randomString($length = 20, $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') { |
|
23 | 23 | $charactersLength = strlen($characters); |
24 | 24 | $randomString = ''; |
25 | 25 | for ($i = 0; $i < $length; $i++) { |
26 | - $randomString .= $characters[rand(0, $charactersLength - 1)]; |
|
26 | + $randomString .= $characters[rand(0, $charactersLength - 1)]; |
|
27 | 27 | } |
28 | 28 | return $randomString; |
29 | - } |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * Clean and return user query params |
|
33 | - * |
|
34 | - * @param string $uri |
|
35 | - * @return array |
|
36 | - */ |
|
37 | - public static function uriParse($uri) { |
|
31 | + /** |
|
32 | + * Clean and return user query params |
|
33 | + * |
|
34 | + * @param string $uri |
|
35 | + * @return array |
|
36 | + */ |
|
37 | + public static function uriParse($uri) { |
|
38 | 38 | $answerPos = strpos($uri, '?'); |
39 | 39 | $params = array_slice(explode('/', substr($uri, 0, $answerPos ? $answerPos : strlen($uri) )), 1); |
40 | 40 | |
41 | 41 | foreach ($params as $key => $param) { |
42 | - if ($param != '') { |
|
42 | + if ($param != '') { |
|
43 | 43 | $params[$key] = urldecode($param); |
44 | - } else { |
|
44 | + } else { |
|
45 | 45 | unset($params[$key]); |
46 | - } |
|
46 | + } |
|
47 | 47 | } |
48 | 48 | return $params; |
49 | - } |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Recursive create dir |
|
53 | - * |
|
54 | - * @param string $path |
|
55 | - * @return boolean |
|
56 | - */ |
|
57 | - public static function createDir($path) { |
|
51 | + /** |
|
52 | + * Recursive create dir |
|
53 | + * |
|
54 | + * @param string $path |
|
55 | + * @return boolean |
|
56 | + */ |
|
57 | + public static function createDir($path) { |
|
58 | 58 | if (file_exists($path)) |
59 | - return true; |
|
59 | + return true; |
|
60 | 60 | |
61 | 61 | $path = explode('/', $path); |
62 | 62 | $cur = ''; |
63 | 63 | foreach ($path as $item) { |
64 | - $cur .= $item . '/'; |
|
65 | - if (!file_exists($cur)) { |
|
64 | + $cur .= $item . '/'; |
|
65 | + if (!file_exists($cur)) { |
|
66 | 66 | mkdir($cur); |
67 | - } |
|
67 | + } |
|
68 | 68 | } |
69 | 69 | return true; |
70 | - } |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * Resize image in path |
|
74 | - * |
|
75 | - * @param string $img_path |
|
76 | - * @param int $max_width |
|
77 | - * @param int $max_height |
|
78 | - * @param string|false $crop |
|
79 | - * @param string $pos |
|
80 | - * @return string |
|
81 | - */ |
|
82 | - public static function resizeImage($img_path, $max_width = 1000, $max_height = 1000, $crop = false, $pos = 'center') { |
|
72 | + /** |
|
73 | + * Resize image in path |
|
74 | + * |
|
75 | + * @param string $img_path |
|
76 | + * @param int $max_width |
|
77 | + * @param int $max_height |
|
78 | + * @param string|false $crop |
|
79 | + * @param string $pos |
|
80 | + * @return string |
|
81 | + */ |
|
82 | + public static function resizeImage($img_path, $max_width = 1000, $max_height = 1000, $crop = false, $pos = 'center') { |
|
83 | 83 | ini_set("gd.jpeg_ignore_warning", 1); |
84 | 84 | list( $img_width, $img_height, $img_type, $img_tag ) = getimagesize($img_path); |
85 | 85 | switch ($img_type) { |
86 | - case 1: |
|
86 | + case 1: |
|
87 | 87 | $img_type = 'gif'; |
88 | 88 | break; |
89 | - case 3: |
|
89 | + case 3: |
|
90 | 90 | $img_type = 'png'; |
91 | 91 | break; |
92 | - case 2: |
|
92 | + case 2: |
|
93 | 93 | default: |
94 | 94 | $img_type = 'jpeg'; |
95 | 95 | break; |
@@ -97,55 +97,55 @@ discard block |
||
97 | 97 | $imagecreatefromX = "imagecreatefrom{$img_type}"; |
98 | 98 | $src_res = $imagecreatefromX($img_path); |
99 | 99 | if (!$src_res) { |
100 | - return false; |
|
100 | + return false; |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | if ($img_width / $max_width > $img_height / $max_height) |
104 | - $separator = $img_width / $max_width; |
|
104 | + $separator = $img_width / $max_width; |
|
105 | 105 | else |
106 | - $separator = $img_height / $max_height; |
|
106 | + $separator = $img_height / $max_height; |
|
107 | 107 | |
108 | 108 | if ($crop === true || $crop == 'q') { |
109 | - if ($img_width > $img_height) { |
|
109 | + if ($img_width > $img_height) { |
|
110 | 110 | $imgX = floor(( $img_width - $img_height ) / 2); |
111 | 111 | $imgY = 0; |
112 | 112 | $img_width = $img_height; |
113 | 113 | $new_width = $max_width; |
114 | 114 | $new_height = $max_height; |
115 | - } else { |
|
115 | + } else { |
|
116 | 116 | $imgX = 0; |
117 | 117 | $imgY = floor(( $img_height - $img_width ) / 2); |
118 | 118 | $img_height = $img_width; |
119 | 119 | $new_width = $max_width; |
120 | 120 | $new_height = $max_height; |
121 | - } |
|
122 | - if ($pos == 'top') { |
|
121 | + } |
|
122 | + if ($pos == 'top') { |
|
123 | 123 | $imgY = 0; |
124 | - } |
|
124 | + } |
|
125 | 125 | } elseif ($crop == 'c') { |
126 | 126 | //Вычисляем некий коэффициент масштабирования |
127 | - $k1 = $img_width / $max_width; |
|
128 | - $k2 = $img_height / $max_height; |
|
129 | - $k = $k1 > $k2 ? $k2 : $k1; |
|
130 | - $ow = $img_width; |
|
131 | - $oh = $img_height; |
|
127 | + $k1 = $img_width / $max_width; |
|
128 | + $k2 = $img_height / $max_height; |
|
129 | + $k = $k1 > $k2 ? $k2 : $k1; |
|
130 | + $ow = $img_width; |
|
131 | + $oh = $img_height; |
|
132 | 132 | //Вычисляем размеры области для нового изображения |
133 | - $img_width = intval($max_width * $k); |
|
134 | - $img_height = intval($max_height * $k); |
|
135 | - $new_width = $max_width; |
|
136 | - $new_height = $max_height; |
|
133 | + $img_width = intval($max_width * $k); |
|
134 | + $img_height = intval($max_height * $k); |
|
135 | + $new_width = $max_width; |
|
136 | + $new_height = $max_height; |
|
137 | 137 | //Находим начальные координаты (центрируем новое изображение) |
138 | - $imgX = (int) (($ow / 2) - ($img_width / 2) ); |
|
139 | - if ($pos == 'center') { |
|
138 | + $imgX = (int) (($ow / 2) - ($img_width / 2) ); |
|
139 | + if ($pos == 'center') { |
|
140 | 140 | $imgY = (int) (($oh / 2) - ($img_height / 2)); |
141 | - } else { |
|
141 | + } else { |
|
142 | 142 | $imgY = 0; |
143 | - } |
|
143 | + } |
|
144 | 144 | } else { |
145 | - $imgX = 0; |
|
146 | - $imgY = 0; |
|
147 | - $new_width = floor($img_width / $separator); |
|
148 | - $new_height = floor($img_height / $separator); |
|
145 | + $imgX = 0; |
|
146 | + $imgY = 0; |
|
147 | + $new_width = floor($img_width / $separator); |
|
148 | + $new_height = floor($img_height / $separator); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | $new_res = imagecreatetruecolor($new_width, $new_height); |
@@ -154,128 +154,128 @@ discard block |
||
154 | 154 | imagecopyresampled($new_res, $src_res, 0, 0, $imgX, $imgY, $new_width, $new_height, $img_width, $img_height); |
155 | 155 | |
156 | 156 | if ($img_type == 'jpeg') { |
157 | - imageinterlace($new_res, 1); // чересстрочное формирование изображение |
|
158 | - imagejpeg($new_res, $img_path, 85); |
|
157 | + imageinterlace($new_res, 1); // чересстрочное формирование изображение |
|
158 | + imagejpeg($new_res, $img_path, 85); |
|
159 | 159 | } else { |
160 | - $imageX = "image{$img_type}"; |
|
161 | - $imageX($new_res, $img_path); |
|
160 | + $imageX = "image{$img_type}"; |
|
161 | + $imageX($new_res, $img_path); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | imagedestroy($new_res); |
165 | 165 | imagedestroy($src_res); |
166 | 166 | return $img_type; |
167 | - } |
|
167 | + } |
|
168 | 168 | |
169 | - /** |
|
170 | - * Send mail |
|
171 | - * |
|
172 | - * @param string $from |
|
173 | - * @param string $to |
|
174 | - * @param string $subject |
|
175 | - * @param string $text |
|
176 | - * @param string $charset |
|
177 | - * @param string $ctype |
|
178 | - * @return boolean |
|
179 | - */ |
|
180 | - public static function sendMail($from, $to, $subject, $text, $charset = 'utf-8', $ctype = 'text/html') { |
|
169 | + /** |
|
170 | + * Send mail |
|
171 | + * |
|
172 | + * @param string $from |
|
173 | + * @param string $to |
|
174 | + * @param string $subject |
|
175 | + * @param string $text |
|
176 | + * @param string $charset |
|
177 | + * @param string $ctype |
|
178 | + * @return boolean |
|
179 | + */ |
|
180 | + public static function sendMail($from, $to, $subject, $text, $charset = 'utf-8', $ctype = 'text/html') { |
|
181 | 181 | $msg = compact('from', 'to', 'subject', 'text', 'charset', 'ctype'); |
182 | 182 | $msg = Inji::$inst->event('sendMail', $msg); |
183 | 183 | if (is_array($msg)) { |
184 | - $headers = "From: {$msg['from']}\r\n"; |
|
185 | - $headers .= "Content-type: {$msg['ctype']}; charset={$msg['charset']}\r\n"; |
|
186 | - $headers .= "Mime-Version: 1.0\r\n"; |
|
187 | - return mail($msg['to'], $msg['subject'], $msg['text'], $headers); |
|
184 | + $headers = "From: {$msg['from']}\r\n"; |
|
185 | + $headers .= "Content-type: {$msg['ctype']}; charset={$msg['charset']}\r\n"; |
|
186 | + $headers .= "Mime-Version: 1.0\r\n"; |
|
187 | + return mail($msg['to'], $msg['subject'], $msg['text'], $headers); |
|
188 | 188 | } |
189 | 189 | return $msg; |
190 | - } |
|
190 | + } |
|
191 | 191 | |
192 | - /** |
|
193 | - * Redirect user from any place of code |
|
194 | - * |
|
195 | - * Also add message to message query for view |
|
196 | - * |
|
197 | - * @param string $href |
|
198 | - * @param string $text |
|
199 | - * @param string $status |
|
200 | - */ |
|
201 | - public static function redirect($href = null, $text = false, $status = 'info') { |
|
192 | + /** |
|
193 | + * Redirect user from any place of code |
|
194 | + * |
|
195 | + * Also add message to message query for view |
|
196 | + * |
|
197 | + * @param string $href |
|
198 | + * @param string $text |
|
199 | + * @param string $status |
|
200 | + */ |
|
201 | + public static function redirect($href = null, $text = false, $status = 'info') { |
|
202 | 202 | if ($href === null) { |
203 | - $href = $_SERVER['REQUEST_URI']; |
|
203 | + $href = $_SERVER['REQUEST_URI']; |
|
204 | 204 | } |
205 | 205 | if ($text !== false) { |
206 | - Msg::add($text, $status); |
|
206 | + Msg::add($text, $status); |
|
207 | 207 | } |
208 | 208 | if (!headers_sent()) { |
209 | - header("Location: {$href}"); |
|
209 | + header("Location: {$href}"); |
|
210 | 210 | } else { |
211 | - echo '\'"><script>window.location="' . $href . '";</script>'; |
|
211 | + echo '\'"><script>window.location="' . $href . '";</script>'; |
|
212 | 212 | } |
213 | 213 | exit("Перенаправление на: <a href = '{$href}'>{$href}</a>"); |
214 | - } |
|
214 | + } |
|
215 | 215 | |
216 | - /** |
|
217 | - * Функция возвращает окончание для множественного числа слова на основании числа и массива окончаний |
|
218 | - * @param $number Integer Число на основе которого нужно сформировать окончание |
|
219 | - * @param $endingsArray Array Массив слов или окончаний для чисел (1, 4, 5), |
|
220 | - * например array('яблоко', 'яблока', 'яблок') |
|
221 | - * @return String |
|
222 | - */ |
|
223 | - public static function getNumEnding($number, $endingArray) { |
|
216 | + /** |
|
217 | + * Функция возвращает окончание для множественного числа слова на основании числа и массива окончаний |
|
218 | + * @param $number Integer Число на основе которого нужно сформировать окончание |
|
219 | + * @param $endingsArray Array Массив слов или окончаний для чисел (1, 4, 5), |
|
220 | + * например array('яблоко', 'яблока', 'яблок') |
|
221 | + * @return String |
|
222 | + */ |
|
223 | + public static function getNumEnding($number, $endingArray) { |
|
224 | 224 | $number = $number % 100; |
225 | 225 | if ($number >= 11 && $number <= 19) { |
226 | - $ending = $endingArray[2]; |
|
226 | + $ending = $endingArray[2]; |
|
227 | 227 | } else { |
228 | - $i = $number % 10; |
|
229 | - switch ($i) { |
|
228 | + $i = $number % 10; |
|
229 | + switch ($i) { |
|
230 | 230 | case (1): $ending = $endingArray[0]; |
231 | - break; |
|
231 | + break; |
|
232 | 232 | case (2): |
233 | 233 | case (3): |
234 | 234 | case (4): $ending = $endingArray[1]; |
235 | - break; |
|
235 | + break; |
|
236 | 236 | default: $ending = $endingArray[2]; |
237 | - } |
|
237 | + } |
|
238 | 238 | } |
239 | 239 | return $ending; |
240 | - } |
|
240 | + } |
|
241 | 241 | |
242 | - /** |
|
243 | - * Clean request path |
|
244 | - * |
|
245 | - * @param string $path |
|
246 | - * @return string |
|
247 | - */ |
|
248 | - public static function parsePath($path) { |
|
242 | + /** |
|
243 | + * Clean request path |
|
244 | + * |
|
245 | + * @param string $path |
|
246 | + * @return string |
|
247 | + */ |
|
248 | + public static function parsePath($path) { |
|
249 | 249 | $path = str_replace('\\', '/', $path); |
250 | 250 | $pathArray = explode('/', $path); |
251 | 251 | $cleanPathArray = []; |
252 | 252 | do { |
253 | - $changes = 0; |
|
254 | - foreach ($pathArray as $pathItem) { |
|
253 | + $changes = 0; |
|
254 | + foreach ($pathArray as $pathItem) { |
|
255 | 255 | if (trim($pathItem) === '' || $pathItem == '.') { |
256 | - $changes++; |
|
257 | - continue; |
|
256 | + $changes++; |
|
257 | + continue; |
|
258 | 258 | } |
259 | 259 | if ($pathItem == '..') { |
260 | - array_pop($cleanPathArray); |
|
261 | - $changes++; |
|
262 | - continue; |
|
260 | + array_pop($cleanPathArray); |
|
261 | + $changes++; |
|
262 | + continue; |
|
263 | 263 | } |
264 | 264 | $cleanPathArray[] = $pathItem; |
265 | - } |
|
266 | - $pathArray = $cleanPathArray; |
|
267 | - $cleanPathArray = []; |
|
265 | + } |
|
266 | + $pathArray = $cleanPathArray; |
|
267 | + $cleanPathArray = []; |
|
268 | 268 | } while ($changes); |
269 | 269 | return (strpos($path, '/') === 0 ? '/' : '') . implode('/', $pathArray); |
270 | - } |
|
270 | + } |
|
271 | 271 | |
272 | - /** |
|
273 | - * Show date in rus |
|
274 | - * |
|
275 | - * @param string $date |
|
276 | - * @return string |
|
277 | - */ |
|
278 | - public static function toRusDate($date) { |
|
272 | + /** |
|
273 | + * Show date in rus |
|
274 | + * |
|
275 | + * @param string $date |
|
276 | + * @return string |
|
277 | + */ |
|
278 | + public static function toRusDate($date) { |
|
279 | 279 | $yy = (int) substr($date, 0, 4); |
280 | 280 | $mm = (int) substr($date, 5, 2); |
281 | 281 | $dd = (int) substr($date, 8, 2); |
@@ -284,114 +284,114 @@ discard block |
||
284 | 284 | |
285 | 285 | $month = array('января', 'февраля', 'марта', 'апреля', 'мая', 'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря'); |
286 | 286 | if (empty($month[$mm - 1])) { |
287 | - return 'Не указано'; |
|
287 | + return 'Не указано'; |
|
288 | 288 | } |
289 | 289 | return ($dd > 0 ? $dd . " " : '') . $month[$mm - 1] . " " . $yy . " " . $hours; |
290 | - } |
|
290 | + } |
|
291 | 291 | |
292 | - /** |
|
293 | - * Set header |
|
294 | - * |
|
295 | - * @param string $code |
|
296 | - * @param boolean $exit |
|
297 | - */ |
|
298 | - public static function header($code, $exit = false) { |
|
292 | + /** |
|
293 | + * Set header |
|
294 | + * |
|
295 | + * @param string $code |
|
296 | + * @param boolean $exit |
|
297 | + */ |
|
298 | + public static function header($code, $exit = false) { |
|
299 | 299 | if (!headers_sent()) { |
300 | - switch ($code) { |
|
300 | + switch ($code) { |
|
301 | 301 | case '404': |
302 | 302 | header('HTTP/1.1 404 Not Found'); |
303 | - break; |
|
303 | + break; |
|
304 | 304 | default : |
305 | 305 | header($code); |
306 | - } |
|
306 | + } |
|
307 | 307 | } |
308 | 308 | if ($exit) { |
309 | - exit; |
|
309 | + exit; |
|
310 | + } |
|
310 | 311 | } |
311 | - } |
|
312 | 312 | |
313 | - /** |
|
314 | - * Return exist path from array |
|
315 | - * |
|
316 | - * If no exist path in array - return default |
|
317 | - * |
|
318 | - * @param array $paths |
|
319 | - * @param string|false $default |
|
320 | - * @return string|false |
|
321 | - */ |
|
322 | - public static function pathsResolve($paths = [], $default = false) { |
|
313 | + /** |
|
314 | + * Return exist path from array |
|
315 | + * |
|
316 | + * If no exist path in array - return default |
|
317 | + * |
|
318 | + * @param array $paths |
|
319 | + * @param string|false $default |
|
320 | + * @return string|false |
|
321 | + */ |
|
322 | + public static function pathsResolve($paths = [], $default = false) { |
|
323 | 323 | foreach ($paths as $path) { |
324 | - if (file_exists($path)) { |
|
324 | + if (file_exists($path)) { |
|
325 | 325 | return $path; |
326 | - } |
|
326 | + } |
|
327 | 327 | } |
328 | 328 | return $default; |
329 | - } |
|
329 | + } |
|
330 | 330 | |
331 | - /** |
|
332 | - * Convert acronyms to bites |
|
333 | - * |
|
334 | - * @param string $val |
|
335 | - * @return int |
|
336 | - */ |
|
337 | - public static function toBytes($val) { |
|
331 | + /** |
|
332 | + * Convert acronyms to bites |
|
333 | + * |
|
334 | + * @param string $val |
|
335 | + * @return int |
|
336 | + */ |
|
337 | + public static function toBytes($val) { |
|
338 | 338 | $val = trim($val); |
339 | 339 | $last = strtolower($val[strlen($val) - 1]); |
340 | 340 | switch ($last) { |
341 | - case 'g': |
|
341 | + case 'g': |
|
342 | 342 | $val *= 1024; |
343 | - case 'm': |
|
343 | + case 'm': |
|
344 | 344 | $val *= 1024; |
345 | - case 'k': |
|
345 | + case 'k': |
|
346 | 346 | $val *= 1024; |
347 | 347 | } |
348 | 348 | |
349 | 349 | return $val; |
350 | - } |
|
350 | + } |
|
351 | 351 | |
352 | - /** |
|
353 | - * Recursive copy directories and files |
|
354 | - * |
|
355 | - * @param string $from |
|
356 | - * @param string $to |
|
357 | - */ |
|
358 | - public static function copyFiles($from, $to) { |
|
352 | + /** |
|
353 | + * Recursive copy directories and files |
|
354 | + * |
|
355 | + * @param string $from |
|
356 | + * @param string $to |
|
357 | + */ |
|
358 | + public static function copyFiles($from, $to) { |
|
359 | 359 | $from = rtrim($from, '/'); |
360 | 360 | $to = rtrim($to, '/'); |
361 | 361 | self::createDir($to); |
362 | 362 | $files = scandir($from); |
363 | 363 | foreach ($files as $file) { |
364 | - if (in_array($file, ['.', '..'])) { |
|
364 | + if (in_array($file, ['.', '..'])) { |
|
365 | 365 | continue; |
366 | - } |
|
367 | - if (is_dir($from . '/' . $file)) { |
|
366 | + } |
|
367 | + if (is_dir($from . '/' . $file)) { |
|
368 | 368 | self::copyFiles($from . '/' . $file, $to . '/' . $file); |
369 | - } else { |
|
369 | + } else { |
|
370 | 370 | copy($from . '/' . $file, $to . '/' . $file); |
371 | - } |
|
371 | + } |
|
372 | + } |
|
372 | 373 | } |
373 | - } |
|
374 | 374 | |
375 | - /** |
|
376 | - * Translit function |
|
377 | - * |
|
378 | - * @param string $str |
|
379 | - * @return string |
|
380 | - */ |
|
381 | - public static function translit($str) { |
|
375 | + /** |
|
376 | + * Translit function |
|
377 | + * |
|
378 | + * @param string $str |
|
379 | + * @return string |
|
380 | + */ |
|
381 | + public static function translit($str) { |
|
382 | 382 | $rus = array('А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ё', 'Ж', 'З', 'И', 'Й', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ъ', 'Ы', 'Ь', 'Э', 'Ю', 'Я', 'а', 'б', 'в', 'г', 'д', 'е', 'ё', 'ж', 'з', 'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ъ', 'ы', 'ь', 'э', 'ю', 'я'); |
383 | 383 | $lat = array('A', 'B', 'V', 'G', 'D', 'E', 'E', 'Gh', 'Z', 'I', 'Y', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'F', 'H', 'C', 'Ch', 'Sh', 'Sch', 'Y', 'Y', 'Y', 'E', 'Yu', 'Ya', 'a', 'b', 'v', 'g', 'd', 'e', 'e', 'gh', 'z', 'i', 'y', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'f', 'h', 'c', 'ch', 'sh', 'sch', 'y', 'y', 'y', 'e', 'yu', 'ya'); |
384 | 384 | return str_replace($rus, $lat, $str); |
385 | - } |
|
385 | + } |
|
386 | 386 | |
387 | - /** |
|
388 | - * get youtube video ID from URL |
|
389 | - * |
|
390 | - * @author http://stackoverflow.com/a/6556662 |
|
391 | - * @param string $url |
|
392 | - * @return string Youtube video id or FALSE if none found. |
|
393 | - */ |
|
394 | - public static function youtubeIdFromUrl($url) { |
|
387 | + /** |
|
388 | + * get youtube video ID from URL |
|
389 | + * |
|
390 | + * @author http://stackoverflow.com/a/6556662 |
|
391 | + * @param string $url |
|
392 | + * @return string Youtube video id or FALSE if none found. |
|
393 | + */ |
|
394 | + public static function youtubeIdFromUrl($url) { |
|
395 | 395 | $pattern = '%^# Match any youtube URL |
396 | 396 | (?:https?://)? # Optional scheme. Either http or https |
397 | 397 | (?:www\.)? # Optional www subdomain |
@@ -409,20 +409,20 @@ discard block |
||
409 | 409 | ; |
410 | 410 | $result = preg_match($pattern, $url, $matches); |
411 | 411 | if (false !== $result) { |
412 | - return $matches[1]; |
|
412 | + return $matches[1]; |
|
413 | 413 | } |
414 | 414 | return false; |
415 | - } |
|
415 | + } |
|
416 | 416 | |
417 | - /** |
|
418 | - * check array is associative |
|
419 | - * |
|
420 | - * @author http://stackoverflow.com/a/173479 |
|
421 | - * @param array $arr |
|
422 | - * @return boolean |
|
423 | - */ |
|
424 | - public static function isAssoc(&$arr) { |
|
417 | + /** |
|
418 | + * check array is associative |
|
419 | + * |
|
420 | + * @author http://stackoverflow.com/a/173479 |
|
421 | + * @param array $arr |
|
422 | + * @return boolean |
|
423 | + */ |
|
424 | + public static function isAssoc(&$arr) { |
|
425 | 425 | return array_keys($arr) !== range(0, count($arr) - 1); |
426 | - } |
|
426 | + } |
|
427 | 427 | |
428 | 428 | } |
@@ -13,52 +13,52 @@ discard block |
||
13 | 13 | |
14 | 14 | class Slide extends \Model { |
15 | 15 | |
16 | - public static $objectName = "Слайд"; |
|
17 | - public static $cols = [ |
|
18 | - 'name' => ['type' => 'text'], |
|
19 | - 'link' => ['type' => 'text'], |
|
20 | - 'description' => ['type' => 'html'], |
|
21 | - 'image_file_id' => ['type' => 'image'], |
|
22 | - 'preview_image_file_id' => ['type' => 'image'], |
|
23 | - 'slider_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'slider'], |
|
24 | - 'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'], |
|
25 | - 'weight' => ['type' => 'number'], |
|
26 | - 'date_create' => ['type' => 'dateTime'], |
|
27 | - ]; |
|
28 | - public static $labels = [ |
|
29 | - 'name' => 'Имя', |
|
30 | - 'link' => 'Ссылка', |
|
31 | - 'description' => 'Описание', |
|
32 | - 'date_create' => 'Дата создания', |
|
33 | - 'slider_id' => 'Слайдер', |
|
34 | - 'user_id' => 'Создатель', |
|
35 | - 'weight' => 'Вес', |
|
36 | - 'image_file_id' => 'Изображение', |
|
37 | - 'preview_image_file_id' => 'Превью Изображения', |
|
38 | - ]; |
|
39 | - public static $dataManagers = [ |
|
40 | - 'manager' => [ |
|
41 | - 'name' => 'Слайды', |
|
42 | - 'cols' => [ |
|
43 | - 'image_file_id', 'name', 'link', 'date_create' |
|
44 | - ], |
|
45 | - 'filters' => [ |
|
46 | - 'slider_id', 'name', 'link', 'description', 'date_create' |
|
47 | - ], |
|
48 | - 'sortMode' => true |
|
49 | - ], |
|
50 | - ]; |
|
51 | - public static $forms = [ |
|
52 | - 'manager' => [ |
|
53 | - 'map' => [ |
|
54 | - ['name', 'link'], |
|
55 | - ['preview_image_file_id', 'image_file_id'], |
|
56 | - ['description'], |
|
57 | - ], |
|
58 | - ], |
|
59 | - ]; |
|
16 | + public static $objectName = "Слайд"; |
|
17 | + public static $cols = [ |
|
18 | + 'name' => ['type' => 'text'], |
|
19 | + 'link' => ['type' => 'text'], |
|
20 | + 'description' => ['type' => 'html'], |
|
21 | + 'image_file_id' => ['type' => 'image'], |
|
22 | + 'preview_image_file_id' => ['type' => 'image'], |
|
23 | + 'slider_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'slider'], |
|
24 | + 'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'], |
|
25 | + 'weight' => ['type' => 'number'], |
|
26 | + 'date_create' => ['type' => 'dateTime'], |
|
27 | + ]; |
|
28 | + public static $labels = [ |
|
29 | + 'name' => 'Имя', |
|
30 | + 'link' => 'Ссылка', |
|
31 | + 'description' => 'Описание', |
|
32 | + 'date_create' => 'Дата создания', |
|
33 | + 'slider_id' => 'Слайдер', |
|
34 | + 'user_id' => 'Создатель', |
|
35 | + 'weight' => 'Вес', |
|
36 | + 'image_file_id' => 'Изображение', |
|
37 | + 'preview_image_file_id' => 'Превью Изображения', |
|
38 | + ]; |
|
39 | + public static $dataManagers = [ |
|
40 | + 'manager' => [ |
|
41 | + 'name' => 'Слайды', |
|
42 | + 'cols' => [ |
|
43 | + 'image_file_id', 'name', 'link', 'date_create' |
|
44 | + ], |
|
45 | + 'filters' => [ |
|
46 | + 'slider_id', 'name', 'link', 'description', 'date_create' |
|
47 | + ], |
|
48 | + 'sortMode' => true |
|
49 | + ], |
|
50 | + ]; |
|
51 | + public static $forms = [ |
|
52 | + 'manager' => [ |
|
53 | + 'map' => [ |
|
54 | + ['name', 'link'], |
|
55 | + ['preview_image_file_id', 'image_file_id'], |
|
56 | + ['description'], |
|
57 | + ], |
|
58 | + ], |
|
59 | + ]; |
|
60 | 60 | |
61 | - public static function relations() { |
|
61 | + public static function relations() { |
|
62 | 62 | return [ |
63 | 63 | 'slider' => [ |
64 | 64 | 'model' => 'Sliders\Slider', |
@@ -77,6 +77,6 @@ discard block |
||
77 | 77 | 'col' => 'user_id' |
78 | 78 | ] |
79 | 79 | ]; |
80 | - } |
|
80 | + } |
|
81 | 81 | |
82 | 82 | } |
@@ -13,13 +13,13 @@ |
||
13 | 13 | |
14 | 14 | class Type extends \Model { |
15 | 15 | |
16 | - public static $cols = [ |
|
17 | - 'dir' => ['type' => 'text'], |
|
18 | - 'ext' => ['type' => 'text'], |
|
19 | - 'group' => ['type' => 'text'], |
|
20 | - 'allow_resize' => ['type' => 'bool'], |
|
21 | - 'options' => ['type' => 'textarea'], |
|
22 | - 'date_create' => ['type' => 'dateTime'], |
|
23 | - ]; |
|
16 | + public static $cols = [ |
|
17 | + 'dir' => ['type' => 'text'], |
|
18 | + 'ext' => ['type' => 'text'], |
|
19 | + 'group' => ['type' => 'text'], |
|
20 | + 'allow_resize' => ['type' => 'bool'], |
|
21 | + 'options' => ['type' => 'textarea'], |
|
22 | + 'date_create' => ['type' => 'dateTime'], |
|
23 | + ]; |
|
24 | 24 | |
25 | 25 | } |
@@ -1,39 +1,39 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | return function($step = NULL, $params = []) { |
4 | - $options = ['max_height' => 1200, 'max_width' => 1200]; |
|
5 | - $types = [ |
|
6 | - [ |
|
7 | - 'dir' => '/static/mediafiles/images/', |
|
8 | - 'ext' => 'png', |
|
9 | - 'group' => 'image', |
|
10 | - 'allow_resize' => 1, |
|
11 | - 'options' => json_encode($options) |
|
12 | - ], |
|
13 | - [ |
|
14 | - 'dir' => '/static/mediafiles/images/', |
|
15 | - 'ext' => 'jpeg', |
|
16 | - 'group' => 'image', |
|
17 | - 'allow_resize' => 1, |
|
18 | - 'options' => json_encode($options) |
|
19 | - ], |
|
20 | - [ |
|
21 | - 'dir' => '/static/mediafiles/images/', |
|
22 | - 'ext' => 'jpg', |
|
23 | - 'group' => 'image', |
|
24 | - 'allow_resize' => 1, |
|
25 | - 'options' => json_encode($options) |
|
26 | - ], |
|
27 | - [ |
|
28 | - 'dir' => '/static/mediafiles/images/', |
|
29 | - 'ext' => 'gif', |
|
30 | - 'group' => 'image', |
|
31 | - 'allow_resize' => 1, |
|
32 | - 'options' => json_encode($options) |
|
33 | - ], |
|
34 | - ]; |
|
35 | - foreach ($types as $type) { |
|
4 | + $options = ['max_height' => 1200, 'max_width' => 1200]; |
|
5 | + $types = [ |
|
6 | + [ |
|
7 | + 'dir' => '/static/mediafiles/images/', |
|
8 | + 'ext' => 'png', |
|
9 | + 'group' => 'image', |
|
10 | + 'allow_resize' => 1, |
|
11 | + 'options' => json_encode($options) |
|
12 | + ], |
|
13 | + [ |
|
14 | + 'dir' => '/static/mediafiles/images/', |
|
15 | + 'ext' => 'jpeg', |
|
16 | + 'group' => 'image', |
|
17 | + 'allow_resize' => 1, |
|
18 | + 'options' => json_encode($options) |
|
19 | + ], |
|
20 | + [ |
|
21 | + 'dir' => '/static/mediafiles/images/', |
|
22 | + 'ext' => 'jpg', |
|
23 | + 'group' => 'image', |
|
24 | + 'allow_resize' => 1, |
|
25 | + 'options' => json_encode($options) |
|
26 | + ], |
|
27 | + [ |
|
28 | + 'dir' => '/static/mediafiles/images/', |
|
29 | + 'ext' => 'gif', |
|
30 | + 'group' => 'image', |
|
31 | + 'allow_resize' => 1, |
|
32 | + 'options' => json_encode($options) |
|
33 | + ], |
|
34 | + ]; |
|
35 | + foreach ($types as $type) { |
|
36 | 36 | $typeObject = new \Files\Type($type); |
37 | 37 | $typeObject->save(); |
38 | - } |
|
38 | + } |
|
39 | 39 | }; |
@@ -10,58 +10,58 @@ discard block |
||
10 | 10 | */ |
11 | 11 | class Files extends Module { |
12 | 12 | |
13 | - /** |
|
14 | - * Загрузка файлов |
|
15 | - * |
|
16 | - * $file - масив из переменной $_FILES[{input name}] |
|
17 | - * $options - массив из опций заливки |
|
18 | - * -- [file_code]: уникальный код для системы медиаданых |
|
19 | - * -- [allow_types]: досупные для заливки типы файлов. Например image (тип форматов из таблицы типов файлов file_type_ext) |
|
20 | - */ |
|
21 | - public function upload($file, $options = []) { |
|
13 | + /** |
|
14 | + * Загрузка файлов |
|
15 | + * |
|
16 | + * $file - масив из переменной $_FILES[{input name}] |
|
17 | + * $options - массив из опций заливки |
|
18 | + * -- [file_code]: уникальный код для системы медиаданых |
|
19 | + * -- [allow_types]: досупные для заливки типы файлов. Например image (тип форматов из таблицы типов файлов file_type_ext) |
|
20 | + */ |
|
21 | + public function upload($file, $options = []) { |
|
22 | 22 | |
23 | 23 | $sitePath = App::$primary->path; |
24 | 24 | |
25 | 25 | if (!is_uploaded_file($file['tmp_name'])) |
26 | - return 0; |
|
26 | + return 0; |
|
27 | 27 | |
28 | 28 | $fileinfo = pathinfo($file['name']); |
29 | 29 | if (empty($fileinfo['extension'])) |
30 | - return 0; |
|
30 | + return 0; |
|
31 | 31 | |
32 | 32 | $type = Files\Type::get($fileinfo['extension'], 'ext'); |
33 | 33 | if (!$type) |
34 | - return 0; |
|
34 | + return 0; |
|
35 | 35 | |
36 | 36 | if (!empty($options['accept_group']) && $options['accept_group'] != $type->group) { |
37 | - return 0; |
|
37 | + return 0; |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | $fileObject = new Files\File(); |
41 | 41 | if (!empty($options['file_code'])) { |
42 | - $fileObject = Files\File::get($options['file_code'], 'code'); |
|
43 | - if (!$fileObject) { |
|
42 | + $fileObject = Files\File::get($options['file_code'], 'code'); |
|
43 | + if (!$fileObject) { |
|
44 | 44 | $fileObject = new Files\File(); |
45 | 45 | $fileObject->code = $options['file_code']; |
46 | - } |
|
46 | + } |
|
47 | 47 | } |
48 | 48 | $fileObject->name = $fileinfo['filename']; |
49 | 49 | $fileObject->path = $type->type_dir . date('Y-m-d') . '/' . microtime(true) . '.' . $fileinfo['extension']; |
50 | 50 | if ($fileObject->id && file_exists($sitePath . $fileObject->path)) |
51 | - unlink($sitePath . $fileObject->path); |
|
51 | + unlink($sitePath . $fileObject->path); |
|
52 | 52 | |
53 | 53 | Tools::createDir($sitePath . $type->type_dir . date('Y-m-d') . '/'); |
54 | 54 | |
55 | 55 | if (!move_uploaded_file($file['tmp_name'], $sitePath . $fileObject->path)) { |
56 | - return false; |
|
56 | + return false; |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | if ($type->allow_resize && $type->options && json_decode($type->options, true)) { |
60 | - $typeOptions = json_decode($type->options, true); |
|
61 | - list( $img_width, $img_height, $img_type, $img_tag ) = getimagesize($sitePath . $fileObject->path); |
|
62 | - if ($img_height > $typeOptions['max_height'] || $img_width > $typeOptions['max_width']) { |
|
60 | + $typeOptions = json_decode($type->options, true); |
|
61 | + list( $img_width, $img_height, $img_type, $img_tag ) = getimagesize($sitePath . $fileObject->path); |
|
62 | + if ($img_height > $typeOptions['max_height'] || $img_width > $typeOptions['max_width']) { |
|
63 | 63 | Tools::resizeImage($sitePath . $fileObject->path, $typeOptions['max_width'], $typeOptions['max_height']); |
64 | - } |
|
64 | + } |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | $fileObject->type_id = $type->pk(); |
@@ -70,60 +70,60 @@ discard block |
||
70 | 70 | $fileObject->save(); |
71 | 71 | |
72 | 72 | return $fileObject->id; |
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Загрузка файлов по урл |
|
77 | - * |
|
78 | - * $url - адрес файла |
|
79 | - * $options - массив из опций заливки |
|
80 | - * -- [file_code]: уникальный код для системы медиаданых |
|
81 | - * -- [allow_types]: досупные для заливки типы файлов. Например image (тип форматов из таблицы типов файлов file_type_ext) |
|
82 | - */ |
|
83 | - public function uploadFromUrl($url, $options = []) { |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Загрузка файлов по урл |
|
77 | + * |
|
78 | + * $url - адрес файла |
|
79 | + * $options - массив из опций заливки |
|
80 | + * -- [file_code]: уникальный код для системы медиаданых |
|
81 | + * -- [allow_types]: досупные для заливки типы файлов. Например image (тип форматов из таблицы типов файлов file_type_ext) |
|
82 | + */ |
|
83 | + public function uploadFromUrl($url, $options = []) { |
|
84 | 84 | $sitePath = App::$primary->path; |
85 | 85 | |
86 | 86 | $fileinfo = pathinfo($url); |
87 | 87 | if (empty($fileinfo['extension'])) |
88 | - return 0; |
|
88 | + return 0; |
|
89 | 89 | |
90 | 90 | $type = Files\Type::get($fileinfo['extension'], 'ext'); |
91 | 91 | if (!$type) |
92 | - return 0; |
|
92 | + return 0; |
|
93 | 93 | |
94 | 94 | if (!empty($options['accept_group']) && $options['accept_group'] != $type->group) { |
95 | - return 0; |
|
95 | + return 0; |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | $fileObject = new Files\File(); |
99 | 99 | if (!empty($options['file_code'])) { |
100 | - $fileObject = Files\File::get($options['file_code'], 'code'); |
|
101 | - if (!$fileObject) { |
|
100 | + $fileObject = Files\File::get($options['file_code'], 'code'); |
|
101 | + if (!$fileObject) { |
|
102 | 102 | $fileObject = new Files\File(); |
103 | 103 | $fileObject->code = $options['file_code']; |
104 | - } |
|
104 | + } |
|
105 | 105 | } |
106 | 106 | $fileObject->name = $fileinfo['filename']; |
107 | 107 | $fileObject->path = $type->type_dir . date('Y-m-d') . '/' . microtime(true) . '.' . $fileinfo['extension']; |
108 | 108 | if ($fileObject->id && file_exists($sitePath . $fileObject->path)) |
109 | - unlink($sitePath . $fileObject->path); |
|
109 | + unlink($sitePath . $fileObject->path); |
|
110 | 110 | |
111 | 111 | Tools::createDir($sitePath . $type->type_dir . date('Y-m-d') . '/'); |
112 | 112 | |
113 | 113 | $file = @file_get_contents($url); |
114 | 114 | if ($file === false) { |
115 | - return 0; |
|
115 | + return 0; |
|
116 | 116 | } |
117 | 117 | if (!file_put_contents($sitePath . $fileObject->path, $file)) { |
118 | - return 0; |
|
118 | + return 0; |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | if ($type->allow_resize && $type->options && json_decode($type->options, true)) { |
122 | - $typeOptions = json_decode($type->options, true); |
|
123 | - list( $img_width, $img_height, $img_type, $img_tag ) = getimagesize($sitePath . $fileObject->path); |
|
124 | - if ($img_height > $typeOptions['max_height'] || $img_width > $typeOptions['max_width']) { |
|
122 | + $typeOptions = json_decode($type->options, true); |
|
123 | + list( $img_width, $img_height, $img_type, $img_tag ) = getimagesize($sitePath . $fileObject->path); |
|
124 | + if ($img_height > $typeOptions['max_height'] || $img_width > $typeOptions['max_width']) { |
|
125 | 125 | Tools::resizeImage($sitePath . $fileObject->path, $typeOptions['max_width'], $typeOptions['max_height']); |
126 | - } |
|
126 | + } |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | $fileObject->type_id = $type->pk(); |
@@ -132,6 +132,6 @@ discard block |
||
132 | 132 | $fileObject->save(); |
133 | 133 | |
134 | 134 | return $fileObject->id; |
135 | - } |
|
135 | + } |
|
136 | 136 | |
137 | 137 | } |
@@ -13,30 +13,30 @@ discard block |
||
13 | 13 | |
14 | 14 | class Mysql extends \Object { |
15 | 15 | |
16 | - public $config = []; // настройки подключения выбраной базы |
|
17 | - public $connect = FALSE; // ярлык соединения с MySQL |
|
18 | - public $encoding = 'utf-8'; // установленная кодировка |
|
19 | - public $db_name = 'test'; // выбраная в данный момент база |
|
20 | - public $table_prefix = 'inji_'; // префикс названий таблиц |
|
21 | - public $pdo = NULL; |
|
22 | - public $lastQuery = ''; |
|
23 | - public $last_error = ''; |
|
24 | - public $noConnectAbort = false; |
|
25 | - public $dbInstance = null; |
|
16 | + public $config = []; // настройки подключения выбраной базы |
|
17 | + public $connect = FALSE; // ярлык соединения с MySQL |
|
18 | + public $encoding = 'utf-8'; // установленная кодировка |
|
19 | + public $db_name = 'test'; // выбраная в данный момент база |
|
20 | + public $table_prefix = 'inji_'; // префикс названий таблиц |
|
21 | + public $pdo = NULL; |
|
22 | + public $lastQuery = ''; |
|
23 | + public $last_error = ''; |
|
24 | + public $noConnectAbort = false; |
|
25 | + public $dbInstance = null; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Подключение к MySQL |
|
29 | - */ |
|
30 | - public function init($connect_options) { |
|
27 | + /** |
|
28 | + * Подключение к MySQL |
|
29 | + */ |
|
30 | + public function init($connect_options) { |
|
31 | 31 | extract($connect_options); |
32 | 32 | if (isset($db_name)) |
33 | - $this->db_name = $db_name; |
|
33 | + $this->db_name = $db_name; |
|
34 | 34 | if (isset($encoding)) |
35 | - $this->encoding = $encoding; |
|
35 | + $this->encoding = $encoding; |
|
36 | 36 | if (isset($table_prefix)) |
37 | - $this->table_prefix = $table_prefix; |
|
37 | + $this->table_prefix = $table_prefix; |
|
38 | 38 | if (isset($noConnectAbort)) |
39 | - $this->noConnectAbort = $noConnectAbort; |
|
39 | + $this->noConnectAbort = $noConnectAbort; |
|
40 | 40 | |
41 | 41 | $dsn = "mysql:host=$host;port=$port;dbname=$db_name;charset=$encoding"; |
42 | 42 | $dt = new \DateTime(); |
@@ -50,21 +50,21 @@ discard block |
||
50 | 50 | $this->pdo = new \PDO($dsn, $user, $pass, $opt); |
51 | 51 | $error = $this->pdo->errorInfo(); |
52 | 52 | if ((int) $error[0]) { |
53 | - if ($this->noConnectAbort) { |
|
53 | + if ($this->noConnectAbort) { |
|
54 | 54 | return false; |
55 | - } else { |
|
55 | + } else { |
|
56 | 56 | INJI_SYSTEM_ERROR($error[2], true); |
57 | - } |
|
57 | + } |
|
58 | 58 | } else { |
59 | - $this->connect = true; |
|
60 | - $query = new Mysql\Query($this); |
|
61 | - $query->query("SET SQL_BIG_SELECTS=1"); |
|
62 | - $query->query("SET SESSION sql_mode = 'NO_ENGINE_SUBSTITUTION'"); |
|
63 | - return true; |
|
59 | + $this->connect = true; |
|
60 | + $query = new Mysql\Query($this); |
|
61 | + $query->query("SET SQL_BIG_SELECTS=1"); |
|
62 | + $query->query("SET SESSION sql_mode = 'NO_ENGINE_SUBSTITUTION'"); |
|
63 | + return true; |
|
64 | + } |
|
64 | 65 | } |
65 | - } |
|
66 | 66 | |
67 | - public function getTableCols($table_name) { |
|
67 | + public function getTableCols($table_name) { |
|
68 | 68 | $query = new Mysql\Query($this); |
69 | 69 | $old_db = $this->db_name; |
70 | 70 | $old_prefix = $this->table_prefix; |
@@ -77,35 +77,35 @@ discard block |
||
77 | 77 | $this->db_name = $old_db; |
78 | 78 | $this->table_prefix = $old_prefix; |
79 | 79 | return $result->getArray('COLUMN_NAME'); |
80 | - } |
|
80 | + } |
|
81 | 81 | |
82 | - public function tableExist($tableName) { |
|
82 | + public function tableExist($tableName) { |
|
83 | 83 | $query = new Mysql\Query($this); |
84 | 84 | return (bool) $query->query("SHOW TABLES FROM `{$this->db_name}` LIKE '{$this->table_prefix}{$tableName}'")->getArray(); |
85 | - } |
|
85 | + } |
|
86 | 86 | |
87 | - public function addCol($table = false, $name = false, $param = 'TEXT NOT NULL') { |
|
87 | + public function addCol($table = false, $name = false, $param = 'TEXT NOT NULL') { |
|
88 | 88 | if (!$table || !$name) { |
89 | - return false; |
|
89 | + return false; |
|
90 | 90 | } |
91 | 91 | if ($param == 'pk') { |
92 | - $param = "int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`{$name}`)"; |
|
92 | + $param = "int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`{$name}`)"; |
|
93 | 93 | } |
94 | 94 | $query = new Mysql\Query($this); |
95 | 95 | return $query->query("ALTER TABLE `{$this->db_name}`.`{$this->table_prefix}{$table}` ADD `{$name}` {$param}"); |
96 | - } |
|
96 | + } |
|
97 | 97 | |
98 | - public function delCol($table = false, $name = false) { |
|
98 | + public function delCol($table = false, $name = false) { |
|
99 | 99 | if (!$table || !$name) { |
100 | - return false; |
|
100 | + return false; |
|
101 | 101 | } |
102 | 102 | $query = new Mysql\Query($this); |
103 | 103 | return $query->query("ALTER TABLE `{$this->db_name}`.`{$this->table_prefix}{$table}` DROP `{$name}`"); |
104 | - } |
|
104 | + } |
|
105 | 105 | |
106 | - public function getTables() { |
|
106 | + public function getTables() { |
|
107 | 107 | $query = new Mysql\Query($this); |
108 | 108 | return $query->query("SHOW TABLES")->getArray(); |
109 | - } |
|
109 | + } |
|
110 | 110 | |
111 | 111 | } |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | ], '', true); |
11 | 11 | $buttons = $dataManager->getButtons($params, $model); |
12 | 12 | if ($buttons) { |
13 | - ?> |
|
13 | + ?> |
|
14 | 14 | <h3 class="dataManager-title"><?= $dataManager->name; ?> |
15 | 15 | <div class ='pull-right dataManager-managerButtons'> |
16 | 16 | <div class="btn-group"> |
@@ -26,13 +26,13 @@ discard block |
||
26 | 26 | 'style' => '' |
27 | 27 | ]; |
28 | 28 | if (!empty($dataManager->managerOptions['categorys'])) { |
29 | - $mainCol['style'].='margin-left:260px;'; |
|
30 | - echo '<div class ="pull-left dataManager-categorys" style = "width:250px;">'; |
|
31 | - $this->widget('Ui\DataManager/categorys', compact('dataManager')); |
|
32 | - echo '</div>'; |
|
29 | + $mainCol['style'].='margin-left:260px;'; |
|
30 | + echo '<div class ="pull-left dataManager-categorys" style = "width:250px;">'; |
|
31 | + $this->widget('Ui\DataManager/categorys', compact('dataManager')); |
|
32 | + echo '</div>'; |
|
33 | 33 | } |
34 | 34 | if (!empty($dataManager->managerOptions['filters'])) { |
35 | - ?> |
|
35 | + ?> |
|
36 | 36 | <div class="modal fade" id = "<?= $dataManager->managerId; ?>_filters" > |
37 | 37 | <div class="modal-dialog modal-lg"> |
38 | 38 | <div class="modal-content"> |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | continue; |
47 | 47 | } |
48 | 48 | if(++$i && !($i%2)){ |
49 | - echo '</div><div class="row">'; |
|
49 | + echo '</div><div class="row">'; |
|
50 | 50 | } |
51 | 51 | echo '<div class="col-md-6">'; |
52 | 52 | if (!empty($colInfo['colParams']['type'])) { |
@@ -139,40 +139,40 @@ discard block |
||
139 | 139 | ?> |
140 | 140 | <div class="filter_form_field filter_select"> |
141 | 141 | <?php |
142 | - if (!empty($_GET['datamanagerFilters'][$col]['value'])) { |
|
143 | - $value = 1; |
|
144 | - } elseif (isset($_GET['datamanagerFilters'][$col]['value'])) { |
|
145 | - $value = 0; |
|
146 | - } else { |
|
147 | - $value = ''; |
|
148 | - } |
|
149 | - $inputOptions = ['value' => $value, 'values' => [ |
|
150 | - '' => 'Не важно', |
|
151 | - '1' => $colInfo['label'], |
|
152 | - '0' => 'Нет' |
|
153 | - ] |
|
154 | - ]; |
|
155 | - if (!empty($dataManager->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'][$col])) { |
|
142 | + if (!empty($_GET['datamanagerFilters'][$col]['value'])) { |
|
143 | + $value = 1; |
|
144 | + } elseif (isset($_GET['datamanagerFilters'][$col]['value'])) { |
|
145 | + $value = 0; |
|
146 | + } else { |
|
147 | + $value = ''; |
|
148 | + } |
|
149 | + $inputOptions = ['value' => $value, 'values' => [ |
|
150 | + '' => 'Не важно', |
|
151 | + '1' => $colInfo['label'], |
|
152 | + '0' => 'Нет' |
|
153 | + ] |
|
154 | + ]; |
|
155 | + if (!empty($dataManager->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'][$col])) { |
|
156 | 156 | |
157 | - $inputOptions['disabled'] = true; |
|
158 | - $colOptions = $dataManager->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'][$col]; |
|
159 | - if (!empty($colOptions['userCol'])) { |
|
160 | - if (strpos($colOptions['userCol'], ':')) { |
|
161 | - $rel = substr($colOptions['userCol'], 0, strpos($colOptions['userCol'], ':')); |
|
162 | - $param = substr($colOptions['userCol'], strpos($colOptions['userCol'], ':') + 1); |
|
157 | + $inputOptions['disabled'] = true; |
|
158 | + $colOptions = $dataManager->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'][$col]; |
|
159 | + if (!empty($colOptions['userCol'])) { |
|
160 | + if (strpos($colOptions['userCol'], ':')) { |
|
161 | + $rel = substr($colOptions['userCol'], 0, strpos($colOptions['userCol'], ':')); |
|
162 | + $param = substr($colOptions['userCol'], strpos($colOptions['userCol'], ':') + 1); |
|
163 | 163 | |
164 | - $inputOptions['value'] = \Users\User::$cur->$rel->$param; |
|
165 | - } else { |
|
166 | - $this->model->$col = \Users\User::$cur->{$preset['userCol']}; |
|
167 | - } |
|
168 | - } elseif (!empty($colOptions['value'])) { |
|
164 | + $inputOptions['value'] = \Users\User::$cur->$rel->$param; |
|
165 | + } else { |
|
166 | + $this->model->$col = \Users\User::$cur->{$preset['userCol']}; |
|
167 | + } |
|
168 | + } elseif (!empty($colOptions['value'])) { |
|
169 | 169 | |
170 | - $inputOptions['value'] = $colOptions['value']; |
|
171 | - } |
|
172 | - } |
|
173 | - $inputOptions['class'] = 'input-sm'; |
|
174 | - $form->input('select', "datamanagerFilters[{$col}][value]", $colInfo['label'], $inputOptions); |
|
175 | - ?> |
|
170 | + $inputOptions['value'] = $colOptions['value']; |
|
171 | + } |
|
172 | + } |
|
173 | + $inputOptions['class'] = 'input-sm'; |
|
174 | + $form->input('select', "datamanagerFilters[{$col}][value]", $colInfo['label'], $inputOptions); |
|
175 | + ?> |
|
176 | 176 | </div> |
177 | 177 | |
178 | 178 | <?php |
@@ -13,99 +13,99 @@ discard block |
||
13 | 13 | |
14 | 14 | class Material extends \Model { |
15 | 15 | |
16 | - public static $objectName = 'Материал'; |
|
17 | - public static $categoryModel = 'Materials\Category'; |
|
18 | - public static $labels = [ |
|
19 | - 'name' => 'Заголовок', |
|
20 | - 'category_id' => 'Раздел', |
|
21 | - 'preview' => 'Краткое превью', |
|
22 | - 'text' => 'Текст страницы', |
|
23 | - 'alias' => 'Алиас страницы', |
|
24 | - 'template' => 'Шаблон сайта', |
|
25 | - 'viewer' => 'Тип страницы', |
|
26 | - 'image_file_id' => 'Фото материала', |
|
27 | - 'description' => 'Описание для поисковиков', |
|
28 | - 'keywords' => 'Ключевые слова', |
|
29 | - 'user_id' => 'Создатель', |
|
30 | - 'date_create' => 'Дата создания', |
|
31 | - 'tag_list' => 'Теги' |
|
32 | - ]; |
|
33 | - public static $dataManagers = [ |
|
34 | - 'manager' => [ |
|
35 | - 'cols' => [ |
|
36 | - 'name', |
|
37 | - 'alias', |
|
38 | - 'category_id', |
|
39 | - 'date_create', |
|
40 | - 'tag_list' |
|
41 | - ], |
|
42 | - 'sortable' => [ |
|
43 | - 'name', |
|
44 | - 'alias', |
|
45 | - 'category_id', |
|
46 | - 'date_create' |
|
47 | - ], |
|
48 | - 'filters' => [ |
|
49 | - 'name', |
|
50 | - 'preview', |
|
51 | - 'text', |
|
52 | - 'alias', |
|
53 | - 'template', |
|
54 | - 'viewer', |
|
55 | - 'description', |
|
56 | - 'keywords', |
|
57 | - 'user_id', |
|
58 | - 'date_create' |
|
59 | - ], |
|
60 | - 'categorys' => [ |
|
61 | - 'model' => 'Materials\Category', |
|
62 | - ], |
|
63 | - 'sortMode' => true |
|
64 | - ] |
|
65 | - ]; |
|
66 | - public static $cols = [ |
|
67 | - 'name' => ['type' => 'text'], |
|
68 | - 'alias' => ['type' => 'text'], |
|
69 | - 'preview' => ['type' => 'html'], |
|
70 | - 'text' => ['type' => 'html'], |
|
71 | - 'keywords' => ['type' => 'text'], |
|
72 | - 'description' => ['type' => 'text'], |
|
73 | - 'category_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'category'], |
|
74 | - 'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'], |
|
75 | - 'template' => ['type' => 'select', 'source' => 'method', 'method' => 'templatesList', 'module' => 'Materials'], |
|
76 | - 'viewer' => ['type' => 'select', 'source' => 'method', 'method' => 'viewsList', 'module' => 'Materials'], |
|
77 | - 'default' => ['type' => 'bool'], |
|
78 | - 'hidden' => ['type' => 'bool'], |
|
79 | - 'image_file_id' => ['type' => 'image'], |
|
80 | - 'link' => ['type' => 'dataManager', 'relation' => 'links'], |
|
81 | - 'tree_path' => ['type' => 'text'], |
|
82 | - 'weight' => ['type' => 'number'], |
|
83 | - 'date_create' => ['type' => 'dateTime'], |
|
84 | - 'tag_list' => ['type' => 'text'], |
|
85 | - ]; |
|
86 | - public static $forms = [ |
|
87 | - 'manager' => [ |
|
88 | - 'options' => [ |
|
89 | - 'access' => [ |
|
90 | - 'groups' => [ |
|
91 | - 3 |
|
92 | - ] |
|
93 | - ] |
|
94 | - ], |
|
95 | - 'map' => [ |
|
96 | - ['name', 'category_id'], |
|
97 | - ['alias', 'image_file_id'], |
|
98 | - ['template', 'viewer'], |
|
99 | - ['keywords', 'description'], |
|
100 | - ['tag_list'], |
|
101 | - ['preview'], |
|
102 | - ['text'], |
|
103 | - ['link'], |
|
104 | - ] |
|
105 | - ] |
|
106 | - ]; |
|
16 | + public static $objectName = 'Материал'; |
|
17 | + public static $categoryModel = 'Materials\Category'; |
|
18 | + public static $labels = [ |
|
19 | + 'name' => 'Заголовок', |
|
20 | + 'category_id' => 'Раздел', |
|
21 | + 'preview' => 'Краткое превью', |
|
22 | + 'text' => 'Текст страницы', |
|
23 | + 'alias' => 'Алиас страницы', |
|
24 | + 'template' => 'Шаблон сайта', |
|
25 | + 'viewer' => 'Тип страницы', |
|
26 | + 'image_file_id' => 'Фото материала', |
|
27 | + 'description' => 'Описание для поисковиков', |
|
28 | + 'keywords' => 'Ключевые слова', |
|
29 | + 'user_id' => 'Создатель', |
|
30 | + 'date_create' => 'Дата создания', |
|
31 | + 'tag_list' => 'Теги' |
|
32 | + ]; |
|
33 | + public static $dataManagers = [ |
|
34 | + 'manager' => [ |
|
35 | + 'cols' => [ |
|
36 | + 'name', |
|
37 | + 'alias', |
|
38 | + 'category_id', |
|
39 | + 'date_create', |
|
40 | + 'tag_list' |
|
41 | + ], |
|
42 | + 'sortable' => [ |
|
43 | + 'name', |
|
44 | + 'alias', |
|
45 | + 'category_id', |
|
46 | + 'date_create' |
|
47 | + ], |
|
48 | + 'filters' => [ |
|
49 | + 'name', |
|
50 | + 'preview', |
|
51 | + 'text', |
|
52 | + 'alias', |
|
53 | + 'template', |
|
54 | + 'viewer', |
|
55 | + 'description', |
|
56 | + 'keywords', |
|
57 | + 'user_id', |
|
58 | + 'date_create' |
|
59 | + ], |
|
60 | + 'categorys' => [ |
|
61 | + 'model' => 'Materials\Category', |
|
62 | + ], |
|
63 | + 'sortMode' => true |
|
64 | + ] |
|
65 | + ]; |
|
66 | + public static $cols = [ |
|
67 | + 'name' => ['type' => 'text'], |
|
68 | + 'alias' => ['type' => 'text'], |
|
69 | + 'preview' => ['type' => 'html'], |
|
70 | + 'text' => ['type' => 'html'], |
|
71 | + 'keywords' => ['type' => 'text'], |
|
72 | + 'description' => ['type' => 'text'], |
|
73 | + 'category_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'category'], |
|
74 | + 'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'], |
|
75 | + 'template' => ['type' => 'select', 'source' => 'method', 'method' => 'templatesList', 'module' => 'Materials'], |
|
76 | + 'viewer' => ['type' => 'select', 'source' => 'method', 'method' => 'viewsList', 'module' => 'Materials'], |
|
77 | + 'default' => ['type' => 'bool'], |
|
78 | + 'hidden' => ['type' => 'bool'], |
|
79 | + 'image_file_id' => ['type' => 'image'], |
|
80 | + 'link' => ['type' => 'dataManager', 'relation' => 'links'], |
|
81 | + 'tree_path' => ['type' => 'text'], |
|
82 | + 'weight' => ['type' => 'number'], |
|
83 | + 'date_create' => ['type' => 'dateTime'], |
|
84 | + 'tag_list' => ['type' => 'text'], |
|
85 | + ]; |
|
86 | + public static $forms = [ |
|
87 | + 'manager' => [ |
|
88 | + 'options' => [ |
|
89 | + 'access' => [ |
|
90 | + 'groups' => [ |
|
91 | + 3 |
|
92 | + ] |
|
93 | + ] |
|
94 | + ], |
|
95 | + 'map' => [ |
|
96 | + ['name', 'category_id'], |
|
97 | + ['alias', 'image_file_id'], |
|
98 | + ['template', 'viewer'], |
|
99 | + ['keywords', 'description'], |
|
100 | + ['tag_list'], |
|
101 | + ['preview'], |
|
102 | + ['text'], |
|
103 | + ['link'], |
|
104 | + ] |
|
105 | + ] |
|
106 | + ]; |
|
107 | 107 | |
108 | - public static function relations() { |
|
108 | + public static function relations() { |
|
109 | 109 | return [ |
110 | 110 | 'category' => [ |
111 | 111 | 'model' => '\Materials\Category', |
@@ -125,43 +125,43 @@ discard block |
||
125 | 125 | 'col' => 'material_id' |
126 | 126 | ] |
127 | 127 | ]; |
128 | - } |
|
128 | + } |
|
129 | 129 | |
130 | - public function getHref() { |
|
130 | + public function getHref() { |
|
131 | 131 | $href = !empty(\App::$primary->config['defaultModule']) && \App::$primary->config['defaultModule'] == 'Materials' ? '' : '/materials'; |
132 | 132 | $treePath = array_filter(explode('/', $this->tree_path)); |
133 | 133 | if ($treePath) { |
134 | - $categorys = Category::getList(['where' => ['id', implode(',', $treePath), 'IN']]); |
|
135 | - foreach ($categorys as $category) { |
|
134 | + $categorys = Category::getList(['where' => ['id', implode(',', $treePath), 'IN']]); |
|
135 | + foreach ($categorys as $category) { |
|
136 | 136 | if ($category->alias) { |
137 | - $href .="/{$category->alias}"; |
|
137 | + $href .="/{$category->alias}"; |
|
138 | + } |
|
138 | 139 | } |
139 | - } |
|
140 | 140 | } |
141 | 141 | if ((!$href || $href == '/materials') && !$this->alias) { |
142 | - return ($href ? $href : '/materials') . '/view/' . $this->pk(); |
|
142 | + return ($href ? $href : '/materials') . '/view/' . $this->pk(); |
|
143 | 143 | } |
144 | 144 | return $href . "/" . ($this->alias ? $this->alias : $this->pk()); |
145 | - } |
|
145 | + } |
|
146 | 146 | |
147 | - public function resolveTemplate() { |
|
147 | + public function resolveTemplate() { |
|
148 | 148 | if ($this->template !== 'inherit') { |
149 | - return $this->template; |
|
149 | + return $this->template; |
|
150 | 150 | } elseif ($this->template == 'inherit' && $this->category) { |
151 | - return $this->category->resolveTemplate(true); |
|
151 | + return $this->category->resolveTemplate(true); |
|
152 | 152 | } else { |
153 | - return 'current'; |
|
153 | + return 'current'; |
|
154 | + } |
|
154 | 155 | } |
155 | - } |
|
156 | 156 | |
157 | - public function resolveViewer() { |
|
157 | + public function resolveViewer() { |
|
158 | 158 | if ($this->viewer !== 'inherit') { |
159 | - return $this->viewer; |
|
159 | + return $this->viewer; |
|
160 | 160 | } elseif ($this->viewer == 'inherit' && $this->category) { |
161 | - return $this->category->resolveViewer(true); |
|
161 | + return $this->category->resolveViewer(true); |
|
162 | 162 | } else { |
163 | - return 'default'; |
|
163 | + return 'default'; |
|
164 | + } |
|
164 | 165 | } |
165 | - } |
|
166 | 166 | |
167 | 167 | } |