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(); }
function db_index_update_overall($source = '') { $ct = ctime(); $period = 30 * 24 * 3600; $fn = db_index_file_detect($source); $ls = file($fn); $index_data = array('uids' => array(), 'locs' => array(), 'coms' => 0, 'min_id' => $ct); foreach ($ls as $vi) { $vips = explode(':', $vi); $id = isset($vips[0]) ? $vips[0] : false; $ui = isset($vips[2]) ? $vips[2] : false; $co = isset($vips[3]) ? $vips[3] : false; if ($id !== FALSE) { $id = base_convert($id, 36, 10); $loc = db_get_nloc($id); if (isset($index_data['locs'][$loc])) { $index_data['locs'][$loc]++; } else { $index_data['locs'][$loc] = 1; } if ($index_data['min_id'] > $id) { $index_data['min_id'] = $id; } } if ($ui !== FALSE) { if (isset($index_data['uids'][$ui])) { $index_data['uids'][$ui]++; } else { $index_data['uids'][$ui] = 1; } } if ($co !== FALSE) { $index_data['coms'] += $co; } } // Active news is many, auto archive it (and user is hasn't draft rights) if ($source == '' && $index_data['min_id'] < $ct - $period && getoption('auto_archive') && !test('Bd')) { $cc = db_make_archive(0, ctime()); cn_throw_message('Autoarchive performed'); if (getoption('notify_archive')) { cn_send_mail(getoption('notify_email'), i18n("Auto archive news"), i18n("Active news has been archived (%1 articles)", $cc)); } // Refresh overall index return db_index_update_overall(); } // save meta-data $meta = db_index_file_detect("meta-{$source}"); if ($w = fopen($meta, "w+")) { fwrite($w, base64_encode(serialize($index_data))); fclose($w); } return TRUE; }