Exemple #1
0
function dashboard_archives()
{
    list($req_archive_id, $arch_action, $last_only, $period) = GET('archive_id, arch_action, last_only, period');
    // Do make archive
    if (request_type('POST')) {
        cn_dsi_check();
        // Archives actions
        if ($req_archive_id) {
            // Delete
            if ($arch_action == 'rm') {
                db_archive_meta_update($req_archive_id, 0, 0, 0);
                $req_archive_id = 0;
                cn_throw_message("Archive deleted", 'e');
            } elseif ($arch_action == 'extr') {
                if (!db_extract_archive($req_archive_id)) {
                    cn_throw_message("Archive not extracted correctly", 'e');
                } else {
                    $req_archive_id = 0;
                    cn_throw_message("Archive extracted");
                }
            } else {
                cn_throw_message('@SYSINFO: Unrecognized request', 'e');
            }
        } else {
            if ($last_only) {
                $date_f = ctime() - $period * 3600 * 24;
                $date_t = ctime();
            } else {
                list($_fd, $_fm, $_fy) = GET('from_date_day, from_date_month, from_date_year', 'POST');
                list($_td, $_tm, $_ty) = GET('to_date_day, to_date_month, to_date_year', 'POST');
                $date_f = mktime(0, 0, 0, intval($_fm), intval($_fd), intval($_fy));
                $date_t = mktime(23, 59, 59, intval($_tm), intval($_td), intval($_ty));
            }
            $cc = db_make_archive($date_f, $date_t);
            if ($cc) {
                cn_throw_message(i18n('Archive created (%1 articles)', $cc));
            } else {
                cn_throw_message('There is nothing to archive', 'e');
            }
        }
    }
    // --- archives
    $arch_list = db_get_archives();
    // ---- fetch active ---
    $ids = db_index_load();
    ksort($ids);
    reset($ids);
    $st = key($ids);
    end($ids);
    $ed = key($ids);
    list($f_date_d, $f_date_m, $f_date_y) = make_postponed_date($st);
    list($t_date_d, $t_date_m, $t_date_y) = make_postponed_date($ed);
    cn_assign('arch_list, archive_id', $arch_list, $req_archive_id);
    cn_assign('f_date_d, f_date_m, f_date_y, t_date_d, t_date_m, t_date_y', $f_date_d, $f_date_m, $f_date_y, $t_date_d, $t_date_m, $t_date_y);
    echoheader('-@dashboard/style.css', 'Arhives');
    echo exec_tpl('dashboard/archives');
    echofooter();
}
// 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;
Exemple #3
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();
}