<commit_before><?php
/*
 * You may not change or alter any portion of this comment or credits
 * of supporting developers from this source code or any supporting source code
 * which is considered copyrighted (c) material of the original comment or credit authors.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */

/**
 * @copyright    XOOPS Project http://sourceforge.net/projects/xoops/
 * @license      GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
 * @package      xNews
 * @since        1.6.0
 * @author       XOOPS Development Team, DNPROSSI
 * @version      $Id $
 */

require_once __DIR__ . '/admin_header.php';
require_once __DIR__ . '/../../../include/cp_header.php';
require_once XNI_MODULE_PATH . '/include/functions.php';
require_once XNI_MODULE_PATH . '/admin/functions.php';

//require_once XNI_MODULE_PATH . '/class/NewsTopic.php';
//require_once XNI_MODULE_PATH . '/class/NewsStory.php';

$myts = \MyTextSanitizer::getInstance();

$importFromModuleName = isset($_POST['importfrom']);
$importToCloneID      = @$_POST['importto'];
trigger_error($importToModuleDirName, E_USER_WARNING);
trigger_error($importToCloneID, E_USER_WARNING);
$scriptname = 'import_news.php';

if ('go' === $op) {
    xoops_cp_header();

    adminMenu(-1, _AM_XNI_IMPORT);

    $moduleHandler  = xoops_getHandler('module');
    $moduleObj      = $moduleHandler->getByDirname('news');
    $news_module_id = $moduleObj->getVar('mid');

    $gpermHandler = xoops_getHandler('groupperm');

    $cnt_imported_cat      = 0;
    $cnt_imported_articles = 0;

    $parentId = $_POST['parent_category'];

    $resultCat = $xoopsDB->query('SELECT * FROM ' . $xoopsDB->prefix('topics'));

    $newCatArray     = [];
    $newArticleArray = [];
    $oldToNew        = [];
    while (false !== ($arrCat = $xoopsDB->fetchArray($resultCat))) {

        /*$newCat = array();
        $newCat['oldid'] = $arrCat['topic_id'];
        $newCat['oldpid'] = $arrCat['topic_pid'];

        $topic = new Xnews\NewsTopic;

        $result = $xoopsDB->query("SELECT * FROM " . $xoopsDB->prefix(XNI_SUBPREFIX . '_topics') . " WHERE topic_title = '" . $arrCat['topic_title'] . "'");
        $title_arr = $xoopsDB->fetchArray($result);
        if ($title_arr['topic_title'] == $arrCat['topic_title']) {
            $topic->topic_title = $arrCat['topic_title'] . '-new';
        } else {
            $topic->topic_title = $arrCat['topic_title'];
        }

        $topic->topic_pid = $arrCat['topic_pid'];
        //$topic->topic_title = $arrCat['topic_title'];
        $topic->topic_description = $arrCat['topic_description'];
        $topic->menu = $arrCat['menu'];
        $topic->topic_frontpage = $arrCat['topic_frontpage'];
        $topic->topic_rssurl = $arrCat['topic_rssurl'];
        $topic->topic_color = $arrCat['topic_color'];

        // Category image
        if ( ($arrCat['topic_imgurl'] != 'blank.gif') && ($arrCat['topic_imgurl'] != '') ) {
            if ( copy(XOOPS_ROOT_PATH . "/modules/news/images/topics/" . $arrCat['topic_imgurl'], XNI_TOPICS_FILES_PATH . "/" . $arrCat['topic_imgurl']) ) {
                $topic->topic_imgurl = ($arrCat['topic_imgurl']);
            }
        }

        $idresult = $xoopsDB->query("SHOW TABLE STATUS LIKE '" . $xoopsDB->prefix(XNI_SUBPREFIX . '_topics') . "'");
        $row =  $xoopsDB->fetchArray($idresult);
        $auto_increment = $row['Auto_increment'];

        //trigger_error((int)($auto_increment -1) , E_USER_WARNING);
        if (!$topic->store($topic)) {
            echo sprintf(_AM_XNI_IMPORT_CATEGORY_ERROR, $arrCat['topic_title']) . "<br>";
            continue;
        }

        $newCat['newid'] = $auto_increment;
        ++$cnt_imported_cat;

        echo sprintf("<br\>" . _AM_XNI_IMPORT_CATEGORY_SUCCESS, $topic->topic_title());

        $sql = "SELECT * FROM " . $xoopsDB->prefix('stories') .  " WHERE topicid=" . $arrCat['topic_id'];
        $resultArticles = $xoopsDB->query($sql);
        while ($arrArticle = $xoopsDB->fetchArray($resultArticles)) {
            // insert article
            $story =new NewsStory;

            $story->uid = $arrArticle['uid'];
            $story->title = $arrArticle['title'];
            $story->created = $arrArticle['created'];
            $story->published = $arrArticle['published'];
            $story->expired = $arrArticle['expired'];
            $story->hostname = $arrArticle['hostname'];
            $story->nohtml = $arrArticle['nohtml'];
            $story->nosmiley = $arrArticle['nosmiley'];
            $story->hometext = $arrArticle['hometext'];
            $story->bodytext = $arrArticle['bodytext'];
            $story->keywords = $arrArticle['keywords']; //META
            $story->description = $arrArticle['description']; //META<commit_msg>Assignment in Condition<commit_after><?php
/*
 * You may not change or alter any portion of this comment or credits
 * of supporting developers from this source code or any supporting source code
 * which is considered copyrighted (c) material of the original comment or credit authors.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */

/**
 * @copyright    XOOPS Project http://sourceforge.net/projects/xoops/
 * @license      GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
 * @package      xNews
 * @since        1.6.0
 * @author       XOOPS Development Team, DNPROSSI
 * @version      $Id $
 */

require_once __DIR__ . '/admin_header.php';
require_once __DIR__ . '/../../../include/cp_header.php';
require_once XNI_MODULE_PATH . '/include/functions.php';
require_once XNI_MODULE_PATH . '/admin/functions.php';

//require_once XNI_MODULE_PATH . '/class/NewsTopic.php';
//require_once XNI_MODULE_PATH . '/class/NewsStory.php';

$myts = \MyTextSanitizer::getInstance();

$importFromModuleName = isset($_POST['importfrom']);
$importToCloneID      = @$_POST['importto'];
trigger_error($importToModuleDirName, E_USER_WARNING);
trigger_error($importToCloneID, E_USER_WARNING);
$scriptname = 'import_news.php';

if ('go' === $op) {
    xoops_cp_header();

    adminMenu(-1, _AM_XNI_IMPORT);

    $moduleHandler  = xoops_getHandler('module');
    $moduleObj      = $moduleHandler->getByDirname('news');
    $news_module_id = $moduleObj->getVar('mid');

    $gpermHandler = xoops_getHandler('groupperm');

    $cnt_imported_cat      = 0;
    $cnt_imported_articles = 0;

    $parentId = $_POST['parent_category'];

    $resultCat = $xoopsDB->query('SELECT * FROM ' . $xoopsDB->prefix('topics'));

    $newCatArray     = [];
    $newArticleArray = [];
    $oldToNew        = [];
    while (false !== ($arrCat = $xoopsDB->fetchArray($resultCat))) {

        /*$newCat = array();
        $newCat['oldid'] = $arrCat['topic_id'];
        $newCat['oldpid'] = $arrCat['topic_pid'];

        $topic = new Xnews\NewsTopic;

        $result = $xoopsDB->query("SELECT * FROM " . $xoopsDB->prefix(XNI_SUBPREFIX . '_topics') . " WHERE topic_title = '" . $arrCat['topic_title'] . "'");
        $title_arr = $xoopsDB->fetchArray($result);
        if ($title_arr['topic_title'] == $arrCat['topic_title']) {
            $topic->topic_title = $arrCat['topic_title'] . '-new';
        } else {
            $topic->topic_title = $arrCat['topic_title'];
        }

        $topic->topic_pid = $arrCat['topic_pid'];
        //$topic->topic_title = $arrCat['topic_title'];
        $topic->topic_description = $arrCat['topic_description'];
        $topic->menu = $arrCat['menu'];
        $topic->topic_frontpage = $arrCat['topic_frontpage'];
        $topic->topic_rssurl = $arrCat['topic_rssurl'];
        $topic->topic_color = $arrCat['topic_color'];

        // Category image
        if ( ($arrCat['topic_imgurl'] != 'blank.gif') && ($arrCat['topic_imgurl'] != '') ) {
            if ( copy(XOOPS_ROOT_PATH . "/modules/news/images/topics/" . $arrCat['topic_imgurl'], XNI_TOPICS_FILES_PATH . "/" . $arrCat['topic_imgurl']) ) {
                $topic->topic_imgurl = ($arrCat['topic_imgurl']);
            }
        }

        $idresult = $xoopsDB->query("SHOW TABLE STATUS LIKE '" . $xoopsDB->prefix(XNI_SUBPREFIX . '_topics') . "'");
        $row =  $xoopsDB->fetchArray($idresult);
        $auto_increment = $row['Auto_increment'];

        //trigger_error((int)($auto_increment -1) , E_USER_WARNING);
        if (!$topic->store($topic)) {
            echo sprintf(_AM_XNI_IMPORT_CATEGORY_ERROR, $arrCat['topic_title']) . "<br>";
            continue;
        }

        $newCat['newid'] = $auto_increment;
        ++$cnt_imported_cat;

        echo sprintf("<br\>" . _AM_XNI_IMPORT_CATEGORY_SUCCESS, $topic->topic_title());

        $sql = "SELECT * FROM " . $xoopsDB->prefix('stories') .  " WHERE topicid=" . $arrCat['topic_id'];
        $resultArticles = $xoopsDB->query($sql);
        while (false !== ($arrArticle = $xoopsDB->fetchArray($resultArticles))) {
            // insert article
            $story =new NewsStory;

            $story->uid = $arrArticle['uid'];
            $story->title = $arrArticle['title'];
            $story->created = $arrArticle['created'];
            $story->published = $arrArticle['published'];
            $story->expired = $arrArticle['expired'];
            $story->hostname = $arrArticle['hostname'];
            $story->nohtml = $arrArticle['nohtml'];
            $story->nosmiley = $arrArticle['nosmiley'];
            $story->hometext = $arrArticle['hometext'];
            $story->bodytext = $arrArticle['bodytext'];
            $story->keywords = $arrArticle['keywords']; //META
            $story->description = $arrArticle['description']; //META
{'fraction_non_alphanumeric': 0.1673100365704998, 'fraction_numerical': 0.0020316944331572532, 'mean_word_length': 3.036490364903649, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 83, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2132850', 'n_tokens_mistral': 3176, 'n_tokens_neox': 3112, 'n_words': 558}