function cn_helper_category($e) { $nice = ''; $cat = cn_get_categories(TRUE); $sp = spsep($e['c']); foreach ($sp as $cid) { if (isset($cat[$cid])) { $nice[] = $cat[intval($cid)]; } } return $nice; }
function cn_api_get_entry($id = NULL) { if (is_null($id)) { $id = REQ('id'); } $id = cn_id_alias($id); $db = db_news_load(db_get_nloc($id)); // Other meta-information if (isset($db[$id])) { $_cot = array(); $_cat = cn_get_categories(true); $_cts = spsep($db[$id]['c']); foreach ($_cts as $cid) { $_cot[$cid] = $_cat[$cid]['name']; } $db[$id][':cot'] = $_cot; return $db[$id]; } else { return array(); } }
<?php // init list($source, $page, $per_page, $entries, $showed, $entries_total, $userlist) = _GL('source, page, per_page, entries, entries_showed:intval, entries_total:intval, userlist'); list($sort, $dir, $ptree, $YS, $MS, $DS, $TY, $TM, $TD) = _GL('sort, dir, ptree, year_selected, mon_selected, day_selected, TY, TM, TD'); list($nactive, $ndraft, $nprospect, $has_next, $archives) = _GL('nactive, ndraft, nprospect, has_next, archives'); list($category_filters, $user_filters, $cat_filter) = _GL('category_filters, user_filters, cat_filter'); $i = 0; $page = intval($page); $archive_id = intval(REQ('archive_id', 'GPG')); $category = cn_get_categories(false); // MESSAGES BLOCK cn_snippet_messages(); ?> <div class="panel"> <div style="float: right;"> Entries on page: <?php foreach (array(25, 50, 100, 250) as $_per_page) { echo ' <a href="' . cn_url_modify('mod=editnews', "per_page={$_per_page}") . '" ' . ($per_page == $_per_page ? 'class="b"' : '') . '>' . $_per_page . '</a> '; } ?> <a style="color: #008080;" href="#" onclick="DoDiv('filters'); return false;">[Change filters]</a> </div> <?php echo i18n('Showed <b>%1</b> ', $showed); if ($nprospect) { echo i18n('(postponed <b>%1</b>)', $nprospect); } echo i18n(' from total <b>%1</b> ', $entries_total);
function dashboard_intwiz() { $sub = REQ('sub'); $categories = cn_get_categories(false); $rss = getoption('#rss'); $rss_encoding = isset($rss['encoding']) ? $rss['encoding'] : 'UTF-8'; $rss_news_include_url = isset($rss['news_include_url']) ? $rss['news_include_url'] : ''; $rss_title = isset($rss['title']) ? $rss['title'] : ''; $rss_language = isset($rss['language']) ? $rss['language'] : 'en-us'; // Default: view if ($rss_encoding == '') { $rss_encoding = 'UTF-8'; } if ($rss_language == '') { $rss_language = 'en-us'; } // Check submit if (request_type('POST')) { cn_dsi_check(); // Save new configuration if ($sub == 'rss') { $rss['encoding'] = $rss_encoding = REQ('rss_encoding'); $rss['news_include_url'] = $rss_news_include_url = REQ('rss_news_include_url'); $rss['title'] = $rss_title = REQ('rss_title'); $rss['language'] = $rss_language = REQ('rss_language'); // Default: save if ($rss_encoding == '') { $rss_encoding = 'UTF-8'; } if ($rss_language == '') { $rss_language = 'en-us'; } setoption('#rss', $rss); } } $all_tpls = array(); $listsys = cn_template_list(); $templates = getoption('#templates'); // Get all templates foreach ($listsys as $id => $_t) { $all_tpls[$id] = $id; } foreach ($templates as $id => $_t) { $all_tpls[$id] = $id; } cn_assign('sub, categories, all_tpls', $sub, $categories, $all_tpls); cn_assign('rss_news_include_url, rss_encoding, rss_language, rss_title', $rss_news_include_url, $rss_encoding, $rss_language, $rss_title); echoheader('-@dashboard/style.css', 'Integration Wizard'); echo exec_tpl('dashboard/intwiz'); echofooter(); }
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(); }
function add_news_invoke() { $FlatDB = new FlatDB(); // loadall list($article_type, $preview) = GET('postpone_draft, preview', 'GETPOST'); list($from_date_hour, $from_date_minutes, $from_date_seconds, $from_date_month, $from_date_day, $from_date_year) = GET('from_date_hour, from_date_minutes, from_date_seconds, from_date_month, from_date_day, from_date_year', 'GETPOST'); list($title, $page, $category, $short_story, $full_story, $if_use_html, $vConcat, $vTags, $faddm) = GET('title, page, category, short_story, full_story, if_use_html, concat, tags, faddm', 'GETPOST'); $categories = cn_get_categories(false); list($morefields) = cn_get_more_fields($faddm); $is_active_html = test('Csr'); // Prepare data to add new item if (request_type('POST')) { cn_dsi_check(); if (!preg_match("~^[0-9]{1,}\$~", $from_date_hour) or !preg_match("~^[0-9]{1,}\$~", $from_date_minutes) or !preg_match("~^[0-9]{1,}\$~", $from_date_seconds)) { cn_throw_message("You want to add article, but the hour format is invalid.", 'e'); } // create publish time $c_time = mktime($from_date_hour, $from_date_minutes, $from_date_seconds, $from_date_month, $from_date_day, $from_date_year); // flat category to array if ($category == '') { $category = array(); } elseif (!is_array($category)) { $category = array($category); } // article is draft? if ($article_type == 'draft') { $draft = 1; } else { $draft = 0; } $if_use_html = $if_use_html ? TRUE : (getoption('use_wysiwyg') ? TRUE : FALSE); // draft, if Behavior Draft is set if (test('Bd')) { $draft = 1; } // sanitize page name $page = preg_replace('/[^a-z0-9_\\.]/i', '-', $page); if (empty($page) && getoption('auto_news_alias')) { $page = strtolower(preg_replace('/[^a-z0-9_\\.]/i', '-', cn_transliterate($title))); } // basic news $member = member_get(); $entry = array(); $entry['id'] = $c_time; $entry['t'] = cn_htmlclear($title); $entry['u'] = $member['name']; $entry['c'] = news_make_category($category); $entry['s'] = cn_htmlclear($short_story); $entry['f'] = cn_htmlclear($full_story); $entry['ht'] = $if_use_html; $entry['st'] = $draft ? 'd' : ''; $entry['co'] = array(); // 0 comments $entry['cc'] = $vConcat ? TRUE : FALSE; $entry['tg'] = strip_tags($vTags); $entry['pg'] = $page; // Check page alias for exists if ($page && bt_get_id($page, 'pg_ts') && !$preview) { cn_throw_message('Page alias already exists', 'e'); } else { // Get latest id for news $latest_id = intval(bt_get_id('latest_id', 'conf')); $latest_id++; bt_set_id($latest_id, $c_time, 'nid_ts'); bt_set_id($c_time, $latest_id, 'nts_id'); bt_set_id('latest_id', $latest_id, 'conf'); // apply more field list($entry, $disallow_message) = cn_more_fields_apply($entry, $faddm); // has message from function if ($disallow_message) { cn_throw_message($disallow_message, 'e'); } } // ---- if (!$preview) { if (!getoption('disable_title') && empty($title)) { cn_throw_message('The title cannot be blank', 'e'); } if (getoption('news_title_max_long') && strlen($title) > getoption('news_title_max_long')) { cn_throw_message('The title cannon be greater then ' . getoption('news_title_max_long') . ' charecters', 'e'); } if (!getoption('disable_short') && empty($short_story)) { cn_throw_message('The story cannot be blank', 'e'); } // no errors in a[rticle] area if (cn_get_message('e', 'c') == 0) { // Add page alias bt_set_id($page, $c_time, 'pg_ts'); bt_set_id($c_time, $page, 'ts_pg'); $sc = $draft ? 'draft' : ''; $es = db_news_load(db_get_nloc($entry['id'])); // make unique id while (isset($es[$c_time])) { $c_time++; } // override ts $entry['id'] = $c_time; // add default group permission $member = member_get(); // add to database $es[$c_time] = $entry; // do save item db_save_news($es, db_get_nloc($c_time)); // add news to index db_index_add($c_time, $entry['c'], $member['id'], $sc); // ------------------------ $FlatDB->cn_update_date($c_time, 0); $FlatDB->cn_source_update($c_time, $draft ? 'D' : ''); $FlatDB->cn_add_categories($entry['c'], $c_time); $FlatDB->cn_add_tags($entry['tg'], $c_time); $FlatDB->cn_user_sync($entry['u'], $c_time); // ------------------------ // increase user count written news $cnt = intval($member['cnt']) + 1; db_user_update($member['name'], "cnt={$cnt}"); // do update meta-index db_index_update_overall($sc); // Notify for unapproved if (getoption('notify_unapproved') && test('Bd')) { cn_send_mail(getoption('notify_email'), i18n('CuteNews unapproved article was added'), "CuteNews - Unapproved article was added CuUnArWaAd", cn_replace_text(cn_get_template('notify_unapproved', 'mail'), '%username%, %article_title%', $member['name'], $title)); } $FlatDB->cache_clean(); // view in editor cn_relocation(PHP_SELF . '?mod=editnews&action=editnews&id=' . $c_time . '&m=added'); } } else { //correct preview links $preview_html = preg_replace('/href="(.*?)"/', 'href="#"', entry_make($entry, 'active')); $preview_html_full = preg_replace('/href="(.*?)"/', 'href="#"', entry_make($entry, 'full')); cn_assign('preview_html, preview_html_full, gstamp', $preview_html, $preview_html_full, $c_time); } } if (empty($category)) { $category = array(); } // ----------------------------------------------------------------------------------------------------------------- cn_assign('categories, vCategory, vTitle, vShort, vFull, is_active_html, vUseHtml, vConcat, vTags, morefields,vPage', $categories, $category, $title, $short_story, $full_story, $is_active_html, $if_use_html, $vConcat, $vTags, $morefields, $page); // --- echoheader("addedit@addedit/main.css", i18n("Add News")); echo exec_tpl('addedit/main'); echofooter(); }