Exemplo n.º 1
0
     exit;
 }
 if (is_empty_html($msg)) {
     $msg = '';
 }
 if ($_POST['close_comments']) {
     $close_comments = 't';
 } else {
     $close_comments = 'f';
 }
 if ($_POST['is_private']) {
     $is_private = 't';
 } else {
     $is_private = 'f';
 }
 $msg_name = substr_entity(change_q_x(antispam($_POST['name']), true, false), 0, 96, true);
 $attach = $_FILES['attach'];
 $attach_delete = is_array($_POST['delattach']) ? $_POST['delattach'] : array();
 $attach_have = $_POST['have_attach'];
 $olduser = intval($_POST['olduser']);
 $us = new users();
 $logins = $us->GetName($olduser, $error);
 $olduserlogin = $logins['login'];
 if (!$olduserlogin) {
     break;
 }
 if (!$t) {
     $base = 0;
 } else {
     $base = 1;
 }
/**
 * Сохранение поста в сообществах
 * 
 * @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);
    }
}
Exemplo n.º 3
0
 $answers = array();
 $answers_exists = array();
 $multiple = (bool) $_POST['multiple'];
 if (is_array($_POST['answers']) && !empty($_POST['answers'])) {
     $i = 0;
     foreach ($_POST['answers'] as $pa) {
         if (trim((string) $pa) !== '') {
             $answers[] = substr_entity(change_q_x(antispam(preg_replace('/&/', '&amp;', (string) trim($pa))), false, false, ''), 0, blogs::MAX_POLL_ANSWER_CHARS * 2, true);
             $i++;
         }
     }
 }
 if (is_array($_POST['answers_exists']) && !empty($_POST['answers_exists'])) {
     foreach ($_POST['answers_exists'] as $key => $pa) {
         if (trim((string) $pa) !== '') {
             $answers_exists[$key] = substr_entity(change_q_x(antispam(preg_replace('/&/', '&amp;', (string) trim($pa))), false, false, ''), 0, blogs::MAX_POLL_ANSWER_CHARS * 2, true);
             $i++;
         }
     }
 }
 if ($i > 0 && $question === '') {
     $error_flag = 1;
     $alert[5] = 'Введите текст вопроса';
 } else {
     if ($i > blogs::MAX_POLL_ANSWERS) {
         $error_flag = 1;
         $alert[5] = 'Вы можете указать максимум ' . blogs::MAX_POLL_ANSWERS . ' отетов';
     } else {
         if ($i < 2 && $question !== '') {
             $error_flag = 1;
             $alert[5] = 'Нужно указать минимум 2 варианта ответа в голосовании';