/** * Сохранение поста в сообществах * * @param object $objResponse xajaxResponse * @param string $rec_id идентификатор записи * @param string $rec_type тип записи * @param array $aForm массив данных * @param string $sDrawFunc имя функции для выполнения после сохранения */ function _admEditCommunityPostSaveForm(&$objResponse, $rec_id = '', $rec_type = '', $aForm = array(), $sDrawFunc = '') { // инициализация require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/commune.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/attachedfiles.php'; $aForm['title'] = antispam(change_q_x($aForm['title'], true, false)); $aForm['title'] = substr($aForm['title'], 0, 256); $aForm['title'] = $aForm['title'] === false ? '' : $aForm['title']; $aForm['youtube_link'] = change_q_x($aForm['youtube_link'], false, true, null, false, false); $aForm['question'] = trim(change_q_x($aForm['question'], true)); $aForm['close_comments'] = isset($aForm['close_comments']) ? $aForm['close_comments'] : 0; $aForm['is_private'] = isset($aForm['is_private']) ? $aForm['is_private'] : 0; $aForm['answers'] = is_array($aForm['answers']) ? $aForm['answers'] : array(); $aForm['answers_exists'] = is_array($aForm['answers_exists']) ? $aForm['answers_exists'] : array(); $question = change_q_x_a(antispam(preg_replace('/&/', '&', $aForm['question'])), false, false, ''); $multiple = (bool) $aForm['multiple']; $answers = array(); $answers_exists = array(); $acount = 0; $alert = array(); $attachedfiles = new attachedfiles($aForm['attachedfiles_session']); if (commune::IS_NEW_WYSIWYG) { $aForm['msgtext'] = __paramValue('ckedit', antispam($aForm['msgtext'])); $aForm['msgtext'] = stripslashes($aForm['msgtext']); } else { $aForm['msgtext'] = __paramValue('wysiwyg_tidy', antispam($aForm['msgtext'])); } if ($aForm['answers'] && is_array($aForm['answers'])) { foreach ($aForm['answers'] as $key => $answer) { if (($t = substr_entity(change_q_x_a(antispam(preg_replace('/&/', '&', trim((string) $answer))), false, false, ''), 0, commune::POLL_ANSWER_CHARS_MAX * 2, true)) != '') { $answers[] = $t; ++$acount; } else { unset($aForm['answers'][$key]); } } } if ($aForm['answers_exists'] && is_array($aForm['answers_exists'])) { foreach ($aForm['answers_exists'] as $key => $answer) { if (intval($key) && ($t = substr_entity(change_q_x_a(antispam(preg_replace('/&/', '&', trim((string) $answer))), false, false, ''), 0, commune::POLL_ANSWER_CHARS_MAX * 2, true)) != '') { $answers_exists[intval($key)] = $t; ++$acount; } } } if (strlen_real($question) > commune::POLL_QUESTION_CHARS_MAX) { $len = strlen($question); $rlen = strlen_real($question); $question = substr($question, 0, $len - ($rlen - commune::POLL_QUESTION_CHARS_MAX)); } // валидация if (strlen($_POST['title']) > commune::MSG_TITLE_MAX_LENGTH) { $alert[1] = 'Количество символов превышает допустимое (' . commune::MSG_TITLE_MAX_LENGTH . ')'; } if ($aForm['youtube_link'] != '') { if ($video = video_validate($aForm['youtube_link'])) { $aForm['youtube_link'] = $video; } else { $alert[2] = 'Неверная ссылка'; } } if ($acount > 0 && $question == '') { $alert[3] = 'Введите текст вопроса'; } elseif ($acount > commune::POLL_ANSWERS_MAX && $question != '') { $alert[3] = 'Вы можете указать максимум ' . commune::POLL_ANSWERS_MAX . ' ответов'; } elseif ($acount < 2 && $question != '') { $alert[3] = 'Нужно указать минимум 2 варианта ответа'; } $files_info = $attachedfiles->calcFiles(); if (is_empty_html($aForm['msgtext']) && $question == '' && empty($alert) && !$files_info['count'] && $aForm['youtube_link'] == '') { $alert[4] = 'Поле заполнено некорректно'; $aForm['msgtext'] = ''; } elseif (strlen($aForm['msgtext']) > commune::MSG_TEXT_MAX_LENGTH) { $alert[4] = 'Количество символов превышает допустимое'; } if (!$alert) { require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/messages.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/user_content.php'; commune::CreateMessage($aForm, $aForm['commune_id'], $_SESSION['uid'], $rec_id, null, $question, $answers, $answers_exists, $multiple); commune::DeleteMarkedAttach($rec_id); // прикрепленные файлы $attachedfiles_files = $attachedfiles->getFiles(array(1, 3, 4)); commune::addAttachedFiles($attachedfiles_files, $rec_id, $aForm['user_login'], false); $attachedfiles->clear(); // !!!TODO: https://beta.free-lance.ru/mantis/view.php?id=19174 $sReason = _parseReason($aForm['user_id'], $aForm['adm_edit_text']); messages::communityModifiedNotification($rec_id, $rec_type, $aForm['user_login'], $aForm['user_uname'], $aForm['user_usurname'], $sReason); $content_id = user_content::MODER_COMMUNITY; _admEditAfterAll($objResponse, $content_id, $rec_id, $rec_type, $sDrawFunc, $aForm); } else { _setErrors($objResponse, $alert, array(1 => 'title', 2 => 'youtube_link', 3 => 'question', 4 => 'msg'), $sDrawFunc); } }
if ($countfiles > blogs::MAX_FILES) { $error_flag = 1; $alert[3] = 'Максимальное кол-во файлов для загрузки: ' . blogs::MAX_FILES; } require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/attachedfiles.php'; $attachedfiles_session = $_POST['attachedfiles_session']; if (!$attachedfiles_session) { $attachedfiles = new attachedfiles('', true); $asid = $attachedfiles->createSessionID(); $attachedfiles->addNewSession($asid); $attachedfiles_session = $asid; } else { $attachedfiles = new attachedfiles($attachedfiles_session); $asid = $attachedfiles_session; } $attachedfiles_info = $attachedfiles->calcFiles(); if ($attachedfiles_session) { $countfiles = 0; } if ($msg === '' && $question === '' && empty($alert[5]) && !($countfiles || $attachedfiles_info['count']) && $yt_link === '') { $error_flag = 1; $alert[2] = 'Ошибка. Сообщение не должно быть пустым!'; } elseif (!$error && !$error_flag && ($msg !== '' || $attach['name'] || $attach_have || $attach_delete || $question || $yt_link || $attachedfiles_info['count'])) { $blog_obj->Edit($_SESSION['uid'], $thread, $msg, $msg_name, $files, getRemoteIP(), $err, $mod, NULL, $gr, $t, $attach_delete, $olduserlogin, $yt_link, $close_comments, $is_private, $ontop, null, $question, $answers, $answers_exists, $multiple); //$nStopWordsCnt = $stop_words->calculate( $msg, $msg_name, $question, $answers, $answers_exists ); $attachedfiles_files = $attachedfiles->getFiles(array(1, 3, 4)); $blog_obj->addAttachedFiles($attachedfiles_files, $thread, $olduserlogin, $draft_id ? true : false); $attachedfiles->clear(); //$blog_obj->insertIntoModeration( $thread, $nStopWordsCnt ); // больше не модерируем if ($err) { $alert = $alert + $err;