<?php if (!defined('EXEC_TIME')) { die('Access restricted'); } global $PHP_SELF; // Scan external query // $qhl - query search highlight list($id, $template, $qhl) = GET('id, template, qhl', 'GPG'); // Get alias of ID $id = cn_id_alias($id); if (!$template) { $template = 'Default'; } if ($id == 0) { die("@SYSLOG: INTERNAL ERROR[2]"); } $ent = db_news_load(db_get_nloc($id)); if (!isset($ent[$id])) { echo '<div style="text-align: center;">' . i18n('Cannot find an article with id') . ': <strong>' . intval($id) . '</strong></div>'; return FALSE; } else { $entry = $ent[$id]; $text = entry_make($entry, 'full', $template); $text = cn_snippet_search_hl($text, $qhl); echo $text; } return TRUE;
if ($member && test('Mac') || !$member) { $comment_url = getoption('rw_engine') ? $_SERVER['REQUEST_URI'] : PHP_SELF; echo '<form name="comment_frm" action="' . $comment_url . '" method="POST"/>'; echo '<input type="hidden" name="id" value="' . $id . '" />'; echo '<input type="hidden" name="subaction" value="addcomment" />'; echo '<input type="hidden" name="popup" value="' . cn_htmlspecialchars(REQ('popup')) . '" />'; echo '<input type="hidden" name="referer" value="' . cn_htmlspecialchars($_SERVER['REQUEST_URI']) . '" />'; $edit_id = intval(REQ('edit_id')); if ($edit_id) { echo '<input id="edt_comm_mode" type="hidden" name="edit_id" value="' . intval($edit_id) . '" />'; } if ($is_encode) { $comments = $entry['co']; foreach ($comments as $item) { $ni = iconv('UTF-8', $user_encoding . '//TRANSLIT', $item['c']); if ($ni) { $entry['co'][$item['id']]['c'] = $ni; } } } $echo = entry_make($entry, 'form', $template, 'comm'); // Keep [bb]codes[/bb] if ($edit_id) { $echo = str_replace('&#91;', '[', $echo); } echo $echo; echo '</form>'; } else { echo '<div class="cn_error_comment">' . i18n("Comments disabled for you.") . '</div>'; } return TRUE;
// Make settings $opts = array('source' => $_source, 'sort' => $sortby, 'dir' => $dir, 'start' => $start_from, 'per_page' => $number, 'archive_id' => $archive, 'nocat' => $nocat, 'tag' => $tag, 'cfilter' => array_keys($requested_cats), 'ufilter' => $user_by, 'page_alias' => $page_alias, 'only_active' => $only_active); list($entries, $rs) = cn_get_news($opts); // Count showed rows $_cn = $rs['overall']; if (empty($entries)) { $_cn = 0; } // Check end of list $echo = array(); // Delete unused params from GET-request for active news cn_rm_GET('no_prev,no_next,source,number,start_from,reverse,static,sortby,dir,per_page,category,nocategory,page_alias,only_active,user_by'); // show news (include arhives, too) foreach ($entries as $entry) { cn_translate_active_news($entry, $translate); $echo[] = entry_make($entry, 'active', $template); } // No Entries if (($_show_rows = count($echo)) == 0) { echo i18n('No entries to show'); } // Re-Request this parameters for news listing cn_set_GET('source,number,start_from,reverse,static,sortby,dir,per_page,archive,category,nocategory,ucat,template=Default,page_alias,only_active,user_by'); // Show news list echo join('', $echo); // Get config $_enable_pagination = getoption('disable_pagination') ? FALSE : TRUE; // Enable ignore rewrite for pagination $_ignore_rewrite = isset($ignore_rewrite) && $ignore_rewrite ? true : false; $ignore_rewrite = false; // No pagination, if showed rows less than number
<?php require_once dirname(__FILE__) . '/core/init.php'; list($id, $template, $popup) = GET('id, template, popup'); $id = cn_id_alias($id); if (!$template) { $template = 'default'; } $ent = db_news_load(db_get_nloc($id)); if (isset($ent[$id])) { if ($popup) { echo "<html><head><style> \n body { margin: 0; padding: 0; }\n body, td\n {\n font-family: verdana, arial, sans-serif;\n color: black;\n font-size: 12px;\n font-weight: normal;\n line-height: 1.3em;\n }\n input { border-radius: 3px; }\n input.text { background: #ffffff; border: 1px solid gray; }\n input.submit { background: #f0f0f0; border: 1px groove #808080; }\n input.submit:hover { background: #ffffff; cursor: pointer; }\n .cn_comm_textarea { width: 450px; height: 150px; }\n </style></head><body>"; if ($popup == 'comment') { $subaction = 'only_comments'; } include SERVDIR . '/show_news.php'; echo "</body></html>"; } else { echo entry_make($ent[$id], 'print', $template); } } else { echo i18n("ID not found for active news"); }
function edit_news_action_edit() { $flatdb = new FlatDB(); $preview_html = $preview_html_full = ''; $ID = $gstamp = intval(REQ('id', 'GETPOST')); list($status, $preview) = GET('m, preview'); list($vConcat, $vTags, $faddm, $archive_id, $source) = GET('concat, tags, faddm, archive_id, source', 'GETPOST'); // get news part by day $news = db_news_load(db_get_nloc($ID)); if ($ID == 0) { msg_info("Can't edit news without ID"); } if (!isset($news[$ID])) { msg_info("News entry not found!"); } // load entry $entry = $news[$ID]; $oldentry = $entry; // disallowed by category if (!test_cat($entry['c'])) { msg_info("You can't view entry. Category disallow"); } // set status message if ($status == 'added') { cn_throw_message('News was added'); } if ($status == 'moved') { cn_throw_message('Moved to another time'); } // load more fields list($morefields) = cn_get_more_fields($entry['mf']); // do save news? if (request_type('POST')) { $flatdb->cache_clean(); // check exists news if (isset($news[$ID])) { // extract data $entry = $storent = $news[$ID]; // Prepare text list($title, $page, $category, $short_story, $full_story, $if_use_html, $postpone_draft) = GET('title, page, category, short_story, full_story, if_use_html, postpone_draft', 'GETPOST'); // Change date? 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'); $c_time = intval(mktime($from_date_hour, $from_date_minutes, $from_date_seconds, $from_date_month, $from_date_day, $from_date_year)); // sanitize page name $page = preg_replace('/[^a-z0-9_\\.]/i', '-', $page); if (empty($page) && !empty($title) && getoption('auto_news_alias')) { $page = strtolower(preg_replace('/[^a-z0-9_\\.]/i', '-', cn_transliterate($title))); } // current source is archive, active (postponed) or draft news $draft_target = $postpone_draft === 'draft'; // User can't post active news if (test('Bd') && $draft_target !== 'draft') { $draft_target = 'draft'; } // if archive_id is present, unable send to draft $current_source = $archive_id ? "archive-{$archive_id}" : ($source == 'draft' ? 'draft' : ''); $target_source = $archive_id ? "archive-{$archive_id}" : ($draft_target ? 'draft' : ''); $if_use_html = $if_use_html ? TRUE : (getoption('use_wysiwyg') ? TRUE : FALSE); $entry['t'] = cn_htmlclear($title); $entry['c'] = is_array($category) ? join(',', $category) : $category; $entry['s'] = cn_htmlclear($short_story); $entry['f'] = cn_htmlclear($full_story); $entry['ht'] = $if_use_html; $entry['st'] = $draft_target ? 'd' : ''; $entry['pg'] = $page; $entry['cc'] = $vConcat ? TRUE : FALSE; $entry['tg'] = strip_tags($vTags); // apply more field (for news & frontend) list($entry, $disallow_message) = cn_more_fields_apply($entry, $faddm); list($morefields) = cn_get_more_fields($faddm); // has message from function if ($disallow_message) { cn_throw_message($disallow_message, 'e'); } // Make preview if ($preview) { //correct preview links $gstamp = $entry['id'] = $c_time; $preview_html = preg_replace('/href="(.*?)"/', 'href="#"', entry_make($entry, 'active')); $preview_html_full = preg_replace('/href="(.*?)"/', 'href="#"', entry_make($entry, 'full')); } elseif (REQ('do_editsave', 'POST')) { if (!getoption('disable_title') && empty($title)) { cn_throw_message('The title cannot be blank', 'e'); } if (!getoption('disable_short') && empty($short_story)) { cn_throw_message('The story cannot be blank', 'e'); } // Check for change alias $pgts = bt_get_id($ID, 'ts_pg'); if ($pgts && $pgts !== $page) { if ($page) { if (bt_get_id($page, 'pg_ts')) { cn_throw_message('For other news page alias already exists!', 'e'); } } else { bt_del_id($pgts, 'pg_ts'); bt_del_id($ID, 'ts_pg'); } } // no errors in a[rticle] area if (cn_get_message('e', 'c') == 0) { $FlatDB = new FlatDB(); $ida = db_index_load($current_source); $idd = db_index_load($target_source); // Time is changed if ($c_time != intval($ID)) { // Load next block (or current) $next = db_news_load(db_get_nloc($c_time)); if (isset($next[$c_time])) { cn_throw_message('The article time already busy, select another', 'e'); } else { // set new time $entry['id'] = $c_time; $next[$c_time] = $entry; // remove old news [from source / dest] if (isset($news[$ID])) { unset($news[$ID]); } if (isset($next[$ID])) { unset($next[$ID]); } // remove old index if (isset($idd[$ID])) { unset($idd[$ID]); } // Delete old indexes $_ts_id = bt_get_id($ID, 'nts_id'); bt_del_id($ID, 'nts_id'); // Update bt_set_id($_ts_id, $c_time, 'nid_ts'); bt_set_id($c_time, $_ts_id, 'nts_id'); // save 2 blocks db_save_news($news, db_get_nloc($ID)); db_save_news($next, db_get_nloc($c_time)); cn_throw_message('News moved from <b>' . date('Y-m-d H:i:s', $ID) . '</b> to <b>' . date('Y-m-d H:i:s', $c_time) . '</b>'); } } else { $news[$ID] = $entry; db_save_news($news, db_get_nloc($ID)); cn_throw_message('News was edited'); } // Update page aliases $_ts_pg = bt_get_id($ID, 'ts_pg'); bt_del_id($ID, 'ts_pg'); bt_del_id($_ts_pg, 'pg_ts'); if ($page) { bt_set_id($c_time, $page, 'ts_pg'); bt_set_id($page, $c_time, 'pg_ts'); } // 1) remove from old index if (isset($ida[$ID])) { unset($ida[$ID]); } // Fill probably unused $storent['tg'] = isset($storent['tg']) ? $storent['tg'] : ''; // 2) add new index $idd[$c_time] = db_index_create($entry); // 3) sync indexes db_index_save($ida, $current_source); db_index_update_overall($current_source); db_index_save($idd, $target_source); db_index_update_overall($target_source); // ------ // UPDATE categories $FlatDB->cn_remove_categories($storent['c'], $storent['id']); $FlatDB->cn_add_categories($entry['c'], $c_time); // UPDATE tags $FlatDB->cn_remove_tags($storent['tg'], $storent['id']); $FlatDB->cn_add_tags($entry['tg'], $c_time); // UPDATE date / id storage [with comments count] $FlatDB->cn_update_date($entry['id'], $storent['id'], count($storent['co'])); // ------ } } } else { msg_info("News entry not found or has been deleted"); } } if (empty($entry['pg']) && isset($entry['t']) && getoption('auto_news_alias')) { $entry['pg'] = strtolower(preg_replace('/[^a-z0-9_\\.]/i', '-', cn_transliterate($entry['t']))); } // Assign template vars $category = spsep($entry['c']); $categories = cn_get_categories(false); $title = isset($entry['t']) ? $entry['t'] : ''; $short_story = isset($entry['s']) ? $entry['s'] : ''; $page = isset($entry['pg']) ? $entry['pg'] : ''; $full_story = isset($entry['f']) ? $entry['f'] : ''; $is_draft = isset($entry['st']) ? $entry['st'] == 'd' : false; $vConcat = isset($entry['cc']) ? $entry['cc'] : ''; $vTags = isset($entry['tg']) ? $entry['tg'] : ''; $if_use_html = isset($entry['ht']) ? $entry['ht'] : false; $is_active_html = test('Csr'); cn_assign('categories, vCategory, vTitle, vPage, vShort, vFull, vUseHtml, preview_html, preview_html_full, gstamp, is_draft, vConcat, vTags, morefields, archive_id, is_active_html', $categories, $category, $title, $page, $short_story, $full_story, $if_use_html, $preview_html, $preview_html_full, $gstamp, $is_draft, $vConcat, $vTags, $morefields, $archive_id, $is_active_html); cn_assign("EDITMODE", 1); // show edit page echoheader("addedit@addedit/main.css", i18n("Edit news")); echo exec_tpl('addedit/main'); echofooter(); }
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(); }