\'right thumbnail\', \'w\'=> \'400\', \'alt/title\'=>\'\']) ?> _(t-italic) %text% '; // проверка каталогов if (!file_exists($saveTo)) mkdir($saveTo, 0777, true); if (!file_exists($saveTo . 'static')) mkdir($saveTo . 'static', 0777, true); if (!file_exists($saveToImages)) mkdir($saveToImages, 0777, true); // получение всех записей $p = mso_get_pages([ 'type' => false, 'no_limit' => true, 'pagination' => false, 'content' => true, 'work_cut' => false, 'page_status' => false, 'get_page_categories' => true, 'get_page_meta_tags' => true, 'get_page_count_comments' => true, 'custom_type' => 'home', 'order' => 'page_id', 'order_asc' => 'desc', ], $temp); // контрольный вывод pr(count($p)); $counts = []; // отдельный массив для кол-ва прочтений записи foreach ($p as $page) { $result = $templ; $result = str_replace('%title%', $page['page_title'], $result); $result = str_replace('%slug%', $page['page_slug'], $result); $result = str_replace('%date%', $page['page_date_publish'], $result); $result = str_replace('%page_id%', $page['page_id'], $result); $result = str_replace('%page_status%', $page['page_status'], $result); $result = str_replace('%page_view_count%', $page['page_view_count'], $result); if ($page['page_tags']) $result = str_replace('%tags%', 'tags: ' . implode(', ', $page['page_tags']) . "\n", $result); else $result = str_replace('%tags%', '', $result); $page_type_name = $page['page_type_name']; $result = str_replace('%page_type_name0%', $page_type_name, $result); // если тип записи не равен static то ставим ему blog (так принято в Albireo CMS) if ($page_type_name != 'static') $page_type_name = 'blog'; $result = str_replace('%page_type_name%', $page_type_name, $result); if ($page['page_status'] === 'draft') $result = str_replace('%draft%', "draft: +\n", $result); else $result = str_replace('%draft%', '', $result); if ($page['page_comment_allow']) // комментарии по умолчанию $result = str_replace('%page_comment_allow%', '', $result); else // отключенные комментарии $result = str_replace('%page_comment_allow%', 'comments: -', $result); $timePub = strtotime($page['page_date_publish']); $dateYm = date('Y-m', $timePub); // первое изображение используем как изображение записи if (isset($page['page_meta']['image_for_page'][0])) { $image = $page['page_meta']['image_for_page'][0]; $image = str_replace('https://' . $SITE . '/uploads/_pages/', '', $image); $image = str_replace('https://' . $SITE . '/uploads/', '', $image); $image = str_replace('https://' . $SITE . '/uploads/', '', $image); $image = str_replace('http://' . $SITE . '/uploads/_pages/', '', $image); $image = str_replace('http://' . $SITE . '/uploads/', '', $image); $image = str_replace('/uploads/_pages/', '', $image); $image = str_replace('uploads/_pages/', '', $image); $result = str_replace('%image_for_page_file_only%', basename($image), $result); $result = str_replace('%image_for_page%', $image, $result); } else { // если не было файла $result = str_replace('%image_for_page%', '', $result); $result = str_replace($NEW_UPLOADS_SUBDIR . '/' . $page['page_id'] . '-%image_for_page_file_only%', 'default.webp', $result); // } // рубрики $cats = ''; foreach ($page['page_categories_detail'] as $cat) { $cats .= $cat['category_slug'] . ', '; } $cats = rtrim($cats, ', '); $result = str_replace('%category%', $cats, $result); // контент $text = $page['page_content']; $text = str_replace("\r", '', $text); // специфичные замены зависит от конкретного сайта $text = str_replace('

', '', $text); $text = str_replace('

', "\n", $text); $text = str_replace('

', '## ', $text); $text = str_replace('

', "\n", $text); $text = str_replace('
', '> ', $text); $text = str_replace('
', '> ', $text); $text = str_replace('
', '', $text); $text = str_replace('
', '
', $text);
    
    $text = str_replace('https://' . $SITE . '/uploads/_pages/', '' . $NEW_UPLOADS_SUBDIR . '/', $text);
    $text = str_replace('http://' . $SITE . '/uploads/_pages/', '' . $NEW_UPLOADS_SUBDIR . '/', $text);
    
    $text = str_replace('[cut]', '', $text);
    
    // замены для TextSimple
    $text = str_replace("
    ", "ul\n", $text); $text = str_replace("
", "\n/ul\n", $text); $text = str_replace("
    ", "ol\n", $text); $text = str_replace("
", "\n/ol\n", $text); $text = str_replace("
  • ", "* ", $text); $text = str_replace("
  • \n", "\n", $text); // $text = str_replace("\n<>", "\n", $text); $text = str_replace("\n\n\n", "\n\n", $text); // замены ссылок старого сайта на новый так, чтобы адрес автоматом подставлялся через константу SITE_URL $text = str_replace('https://'. $SITE . '/', '', $text); // шотркод галереи (очень специфичен!) $text = str_replace("[/gl]\n", "[/gl]\n\n", $text); $text = str_replace("\n[gl=", "\n" . '_ <'.'?= hIMG(\'[image-large]\', [\'alt/title\'=>\'' . $page['page_title'] . '\']) ?>' . "\n\n[gl=", $text); // подчистка $text = str_replace("\n", "\n_ ", $text); $text = str_replace("\n", "\n_ ", $text); $text = str_replace("\n", "
    \n", $text); $text = str_replace('
    ';
        pr($file);
        // pr($result);
        
        $counts[$file] = $page['page_view_count'];
    }
    
    
    if (!$convertComments) return;
    
    // комментарии
    // берем только опубликованные комментарии!
    
    // старый префикс для всех записей (он повторяется в slug)
    $ADD_URL = 'page/';
    
    require_once getinfo('common_dir') . 'comments.php'; // функции комментариев
    $comments = mso_get_comments(false, []);
    
    try {
        // Подключаемся к базе данных
        $pdo = new PDO("sqlite:$sqliteFile");
        $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
        // Настраиваем журналирование
        $pdo->exec("PRAGMA journal_mode=MEMORY");
    
        // Создаём таблицу (или очищаем, если уже существует)
        $pdo->exec("
            CREATE TABLE IF NOT EXISTS comments (
                id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
                page TEXT NOT NULL DEFAULT '',
                author TEXT NOT NULL DEFAULT '',
                ip TEXT NOT NULL DEFAULT '',
                date TEXT NOT NULL DEFAULT '',
                dateT INTEGER NOT NULL DEFAULT 0,
                allow INTEGER NOT NULL DEFAULT 0,
                mark TEXT NOT NULL DEFAULT '',
                user TEXT NOT NULL DEFAULT '',
                content TEXT NOT NULL DEFAULT ''
            );
            
            CREATE INDEX IF NOT EXISTS idx_comments_page ON comments(page);
            CREATE INDEX IF NOT EXISTS idx_comments_allow ON comments(allow);
                    
            DELETE FROM comments;
        ");
    
        // Начинаем транзакцию
        $pdo->beginTransaction();
    
        // Подготавливаем SQL-запрос
        $stmt = $pdo->prepare("
            INSERT INTO comments (page, author, ip, date, dateT, allow, mark, content)
            VALUES (:page, :author, :ip, :date, :dateT, :allow, :mark, :content)
        ");
    
        // Заполняем таблицу данными
        foreach ($comments as $com) {
            $date = $com['comments_date'];
            $dateT = strtotime($date);
            $ip = $com['comments_author_ip'];
            $allow = $com['comments_approved'] ? 1 : 0;
            $page = $ADD_URL . $com['page_slug'];
            $content = trim($com['comments_content']);
            
            $content = str_replace('

    ', '', $content); $content = str_replace('

    ', "\n", $content); // Определяем автора и метку $mark = ''; if ($com['users_id']) { $author = trim($com['users_nik']); $mark = 'admin'; } elseif ($com['comusers_id']) { $author = trim($com['comusers_nik']); } else { $author = trim($com['comments_author_name']); } if (!$author) $author = 'Anonymous'; // Выполняем вставку данных $stmt->execute([ ':page' => $page, ':author' => $author, ':ip' => $ip, ':date' => $date, ':dateT' => $dateT, ':allow' => $allow, ':mark' => $mark, ':content' => $content ]); } // Завершаем транзакцию $pdo->commit(); echo "Данные успешно загружены в SQLite!"; } catch (PDOException $e) { echo "Ошибка: " . $e->getMessage(); } # end of file