<commit_before><?php
/**
 * $Id: save.php,v 1.43 2007-05-24 19:59:29 thorstenr Exp $
 *
 * Saves a user FAQ record and sends an email to the user
 *
 * @author       <NAME> <<EMAIL>>
 * @author       <NAME> <<EMAIL>>
 * @author       <NAME> <<EMAIL>>
 * @since        2002-09-16
 * @copyright    (c) 2002-2007 phpMyFAQ Team
 *
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 */

if (!defined('IS_VALID_PHPMYFAQ')) {
    header('Location: http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME']));
    exit();
}

$captcha = new PMF_Captcha($db, $sids, $pmf->language);

if (    isset($_POST['username']) && $_POST['username'] != ''
    && isset($_POST['usermail']) && checkEmail($_POST['usermail'])
    && ((!isset($_POST['faqid']) && isset($_POST['rubrik']) && is_array($_POST['rubrik']))
        || (isset($_POST['faqid']) && is_numeric($_POST['faqid']) && (intval($_POST['faqid']) > 0) && isset($_POST['faqlanguage']) && PMF_Init::isASupportedLanguage($_POST['faqlanguage'])))
    && isset($_POST['thema']) && $_POST['thema'] != ''
    && isset($_POST['content']) && $_POST['content'] != ''
    && IPCheck($_SERVER['REMOTE_ADDR'])
    && checkBannedWord(htmlspecialchars(strip_tags($_POST['thema'])))
    && checkBannedWord(htmlspecialchars(strip_tags($_POST['content'])))
    && checkCaptchaCode()) {

    $isNew = true;
    if (isset($_POST['faqid'])) {
        $isNew = false;
        Tracking('save_new_translation_entry', 0);
    } else {
        Tracking('save_new_entry', 0);
    }
    $content = $db->escape_string(safeHTML(nl2br($_POST['content'])));
    $contentlink = $db->escape_string(safeHTML($_POST['contentlink']));
    
    $isTranslation = false;
    if (isset($_POST['faqlanguage'])) {
        $isTranslation = true;
        $newLanguage = $db->escape_string($_POST['faqlanguage']);
    }

    if (substr($contentlink,7) != "") {
        $content = $content."<br />".$PMF_LANG["msgInfo"]."<a href=\"http://".substr($contentlink,7)."\" target=\"_blank\">".$contentlink."</a>";
    }

    $userMail = $IDN->encode($db->escape_string($_POST['usermail']));
    $newData = array(
        'lang'          => ($isTranslation == true ? $newLanguage : $LANGCODE),
        'thema'         => $db->escape_string(safeHTML($_POST['thema'])),
        'active'        => FAQ_SQL_ACTIVE_NO,
        'content'       => $content,
        'keywords'      => $db->escape_string($_POST['keywords']),
        'author'        => $db->escape_string($_POST['username']),
        'email'         => $userMail,
        'comment'       => FAQ_SQL_YES,
        'date'          => date('YmdHis'),
        'dateStart'     => '00000000000000',
        'dateEnd'       => '99991231235959',
        'linkState'     => '',
        'linkDateCheck' => 0);

    if ($isNew) {
        $categories = $_POST['rubrik'];
    } else {
        // Fix data with correct values
        $newData['id'] = intval($_POST['faqid']);
        // Set categories equal to the faq source of the translation
        $category = new PMF_Category($_POST['faqlanguage']);
        $categories = $category->getCategoryIdsFromArticle($newData['id']);
    }

    $recordId = $faq->addRecord($newData, $isNew);
    $faq->addCategoryRelations($categories, $recordId, $newData['lang']);

    $sent = array();

    // Let the PMF Administrator and the Category Owner to be informed by email of this new entry
    foreach($categories as $_category) {

        $userId = $category->getCategoryUser($_category);<commit_msg>MFB: Fixed possible security issue<commit_after><?php
/**
 * $Id: save.php,v 1.44 2007-05-30 20:35:59 thorstenr Exp $
 *
 * Saves a user FAQ record and sends an email to the user
 *
 * @author       <NAME> <<EMAIL>>
 * @author       <NAME> <<EMAIL>>
 * @author       <NAME> <<EMAIL>>
 * @since        2002-09-16
 * @copyright    (c) 2002-2007 phpMyFAQ Team
 *
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 */

if (!defined('IS_VALID_PHPMYFAQ')) {
    header('Location: http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME']));
    exit();
}

$captcha = new PMF_Captcha($db, $sids, $pmf->language);

if (    isset($_POST['username']) && $_POST['username'] != ''
    && isset($_POST['usermail']) && checkEmail($_POST['usermail'])
    && ((!isset($_POST['faqid']) && isset($_POST['rubrik']) && is_array($_POST['rubrik']))
        || (isset($_POST['faqid']) && is_numeric($_POST['faqid']) && (intval($_POST['faqid']) > 0) && isset($_POST['faqlanguage']) && PMF_Init::isASupportedLanguage($_POST['faqlanguage'])))
    && isset($_POST['thema']) && $_POST['thema'] != ''
    && isset($_POST['content']) && $_POST['content'] != ''
    && IPCheck($_SERVER['REMOTE_ADDR'])
    && checkBannedWord(htmlspecialchars(strip_tags($_POST['thema'])))
    && checkBannedWord(htmlspecialchars(strip_tags($_POST['content'])))
    && checkCaptchaCode()) {

    $isNew = true;
    if (isset($_POST['faqid'])) {
        $isNew = false;
        Tracking('save_new_translation_entry', 0);
    } else {
        Tracking('save_new_entry', 0);
    }
    $content = $db->escape_string(safeHTML(nl2br($_POST['content'])));
    $contentlink = $db->escape_string(safeHTML($_POST['contentlink']));

    $isTranslation = false;
    if (isset($_POST['faqlanguage'])) {
        $isTranslation = true;
        $newLanguage = $db->escape_string($_POST['faqlanguage']);
    }

    if (substr($contentlink,7) != "") {
        $content = $content."<br />".$PMF_LANG["msgInfo"]."<a href=\"http://".substr($contentlink,7)."\" target=\"_blank\">".$contentlink."</a>";
    }

    $userMail = $IDN->encode($db->escape_string($_POST['usermail']));
    $newData = array(
        'lang'          => ($isTranslation == true ? $newLanguage : $LANGCODE),
        'thema'         => $db->escape_string(safeHTML($_POST['thema'])),
        'active'        => FAQ_SQL_ACTIVE_NO,
        'content'       => $content,
        'keywords'      => $db->escape_string($_POST['keywords']),
        'author'        => $db->escape_string($_POST['username']),
        'email'         => $userMail,
        'comment'       => FAQ_SQL_YES,
        'date'          => date('YmdHis'),
        'dateStart'     => '00000000000000',
        'dateEnd'       => '99991231235959',
        'linkState'     => '',
        'linkDateCheck' => 0);

    if ($isNew) {
        $categories = $_POST['rubrik'];
    } else {
        // Fix data with correct values
        $newData['id'] = intval($_POST['faqid']);
        // Set categories equal to the faq source of the translation
        $category = new PMF_Category($newLanguage);
        $categories = $category->getCategoryIdsFromArticle($newData['id']);
    }

    $recordId = $faq->addRecord($newData, $isNew);
    $faq->addCategoryRelations($categories, $recordId, $newData['lang']);

    $sent = array();

    // Let the PMF Administrator and the Category Owner to be informed by email of this new entry
    foreach($categories as $_category) {

        $userId = $category->getCategoryUser($_category);
{'fraction_non_alphanumeric': 0.186909926001531, 'fraction_numerical': 0.017861699413115592, 'mean_word_length': 3.31900826446281, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4579876', 'n_tokens_mistral': 2558, 'n_tokens_neox': 2421, 'n_words': 523}