/** * Заполняет массив $this->post_msg данными из пользовательского запроса. * @see sbr_stages::addMsg() * @see sbr_stages::editMsg() * * @param array $request $_GET | $_POST * @param array $files $_FILES */ private function _msgInitFromRequest($request, $files) { $files = $files['attach']; foreach ($request as $field => $value) { if ($field == 'id') { continue; } if (is_scalar($value)) { $value = stripslashes($value); } switch ($field) { case 'msgtext': if (!trim($value)) { $this->error['msgs'][$field] = 'Сообщение не должно быть пустым'; } break; case 'msg_id': $value = intvalPgSql($value); $this->post_msg['id'] = $value; if ($value && !$this->sbr->isAdmin()) { $msg = $this->getMsgs($this->post_msg['id'], false); if (!$msg) { $this->error['msgs']['msgtext'] = 'Недопустимый параметр.'; } else { if (!$this->checkMsgEditTime($msg['post_date'])) { $this->error['msgs']['msgtext'] = 'Редактирование комментария невозможно: истек допустимый срок с момента публикации — ' . (int) (self::MAX_MSG_EDIT_TIME / 60) . ' мин.'; } } } break; case 'parent_id': $value = intvalPgSql($value); break; case 'delattach': $value = intarrPgSql($value); break; case 'yt_link': if (trim($value)) { if (!($val = video_validate($value))) { $this->error['msgs'][$field] = 'Неверная ссылка'; } else { $value = $val; } } break; case 'date_to_answer_eng_format': $value = __paramValue('string', $value); break; default: break; } $this->post_msg[$field] = $value; } $this->post_msg['stage_id'] = $this->data['id']; $fcnt = sbr::MAX_FILES; if (!$this->error && $files) { $this->sbr->getUploadDir(); // !!! если админ редактирует, то нужно в папку автора коммента загружать. foreach ($files['name'] as $idx => $aname) { foreach ($files as $prop => $a) { $att[$idx][$prop] = $a[$idx]; } if (--$fcnt < 0) { break; } $file = new CFile($att[$idx]); if ($err = $this->sbr->uploadFile($file, sbr::MAX_FILE_SIZE)) { if ($err == -1) { continue; } else { $this->error['msgs']['attach'] = $err; break; } } $this->uploaded_files[] = $file; } } if ($this->uploaded_files) { unset($this->error['msgs']['msgtext']); } }