// Add overall news
$news_index = array();
$draft_index = array();
$archive_index = array();
foreach ($files as $news_file) {
    $dt = cn_touch_get(cn_path_construct(SERVDIR, 'cdata', 'news') . $news_file);
    foreach ($dt as $id => $data) {
        // checks news existing in archive
        if ($afn = is_news_inarchive($id, $archive_data)) {
            $archive_index[$afn][$id] = db_index_create($data);
        }
        // checks draft
        if ($data['st'] == 'd') {
            $draft_index[$id] = db_index_create($data);
        } else {
            $news_index[$id] = db_index_create($data);
        }
    }
}
db_index_save($draft_index, 'draft');
db_index_save($news_index);
db_index_update_overall();
foreach ($archive_index as $file => $ind) {
    db_index_save($ind, 'archive-' . $file);
    $min = min(array_keys($ind));
    $max = max(array_keys($ind));
    $cnt = count($ind);
    db_archive_meta_update($file, $min, $max, $cnt);
    db_index_update_overall('archive-' . $file);
}
echo "UPDATE SUCCESS." . PHP_EOL;
示例#2
0
function edit_news_action_massaction()
{
    $FlatDB = new FlatDB();
    list($subaction, $source, $archive_id) = GET('subaction, source, archive_id');
    // Mass Delete
    if ($subaction == 'mass_delete') {
        if (!test('Nud')) {
            cn_throw_message("Operation not permitted for you", 'w');
        }
        list($selected_news) = GET('selected_news');
        if (empty($selected_news)) {
            cn_throw_message("No one news selected", 'e');
        } else {
            $count = count($selected_news);
            if (confirm_first() && $count == 0) {
                cn_throw_message('No none entry selected', 'e');
            }
            if (confirm_post("Delete selected news ({$count})")) {
                if ($source == 'archive') {
                    $source = 'archive-' . intval($archive_id);
                }
                $idx = db_index_load($source);
                // do delete news
                foreach ($selected_news as $id) {
                    $news = db_news_load(db_get_nloc($id));
                    $storent = $news[$id];
                    if (isset($news[$id])) {
                        unset($news[$id]);
                    }
                    if (isset($idx[$id])) {
                        unset($idx[$id]);
                    }
                    // Remove from meta-index (auto_id)
                    $_ts_id = bt_get_id($id, 'nts_id');
                    bt_del_id($id, 'nts_id');
                    bt_del_id($_ts_id, 'nid_ts');
                    // Remove page alias
                    $_ts_pg = bt_get_id($id, 'ts_pg');
                    bt_del_id($id, 'ts_pg');
                    bt_del_id($_ts_pg, 'pg_ts');
                    // ------
                    if (isset($storent['c'])) {
                        $FlatDB->cn_remove_categories($storent['c'], $storent['id']);
                    }
                    if (isset($storent['tg'])) {
                        $FlatDB->cn_remove_tags($storent['tg'], $storent['id']);
                    }
                    $FlatDB->cn_update_date(0, $storent['id']);
                    if (isset($storent['u'])) {
                        $FlatDB->cn_user_sync($storent['u'], 0, $storent['id']);
                    }
                    // ------
                    // Save block
                    db_save_news($news, db_get_nloc($id));
                }
                db_index_save($idx, $source);
                db_index_update_overall($source);
                // Update archive list
                if ($archive_id) {
                    $min = min(array_keys($idx));
                    $max = max(array_keys($idx));
                    $cnt = count($idx);
                    db_archive_meta_update($archive_id, $min, $max, $cnt);
                }
                $FlatDB->cache_clean();
                cn_throw_message('News deleted');
            } else {
                cn_throw_message("No one entry deleted", 'e');
            }
        }
    } elseif ($subaction == 'mass_move_to_cat') {
        cn_assign('catlist', cn_get_categories(false));
        $news_ids = GET('selected_news');
        // Disable commit without news
        if (empty($news_ids) || count($news_ids) == 1 && !$news_ids[0]) {
            cn_throw_message("No one news selected", 'e');
        } else {
            if (confirm_post(exec_tpl('addedit/changecats'))) {
                cn_dsi_check();
                list($news_ids, $cats, $source) = GET('selected_news, cats, source', 'POST');
                $nc = news_make_category(array_keys($cats));
                // Load index for update categories
                $idx = db_index_load($source);
                foreach ($news_ids as $id) {
                    $loc = db_get_nloc($id);
                    $entries = db_news_load($loc);
                    // Catch user trick
                    if (!test_cat($entries[$id]['c'])) {
                        cn_throw_message('Not allowed change category for id = ' . $id, 'w');
                    }
                    $storent = $entries[$id];
                    $idx[$id][0] = $nc;
                    $entries[$id]['c'] = $nc;
                    // ------
                    $FlatDB->cn_remove_categories($storent['c'], $storent['id']);
                    $FlatDB->cn_add_categories($nc, $storent['id']);
                    // ------
                    db_save_news($entries, $loc);
                }
                // Save updated block
                db_index_save($idx, $source);
                cn_throw_message('Successful processed');
                $FlatDB->cache_clean();
            } else {
                cn_throw_message('Operation declined by user', 'e');
            }
        }
    } elseif ($subaction == 'mass_approve') {
        if (!test('Nua')) {
            msg_info("Operation not permitted for you");
        }
        list($selected_news) = GET('selected_news');
        if (empty($selected_news)) {
            cn_throw_message('No one draft selected', 'e');
        } else {
            $ida = db_index_load('');
            $idd = db_index_load('draft');
            // do approve news
            foreach ($selected_news as $id) {
                $news = db_news_load(db_get_nloc($id));
                $news[$id]['st'] = '';
                // 1) remove from draft
                unset($idd[$id]);
                // 2) add to active index
                $ida[$id] = db_index_create($news[$id]);
                // save block
                db_save_news($news, db_get_nloc($id));
            }
            // save indexes
            db_index_save($ida);
            db_index_update_overall();
            db_index_save($idd, 'draft');
            db_index_update_overall('draft');
            $FlatDB->cache_clean();
            cn_throw_message('News was approved');
        }
    } elseif ($subaction == 'switch_to_html') {
        list($selected_news) = GET('selected_news');
        if (empty($selected_news)) {
            cn_throw_message('News not selected', 'e');
        } else {
            // do approve news
            foreach ($selected_news as $id) {
                $news = db_news_load(db_get_nloc($id));
                $news[$id]['ht'] = TRUE;
                db_save_news($news, db_get_nloc($id));
            }
            cn_throw_message('News was switched to HTML');
        }
    } else {
        cn_throw_message('Select action to process', 'w');
    }
    edit_news_action_list();
}