if (!$comment) { $comment = $bkp; } } // ID => [u]ser, [c]comment text, [e]mail, [ip] */ $db[$id]['co'][$cid] = array('id' => $cid, 'u' => $name, 'e' => $mail, 'ip' => CLIENT_IP, 'c' => $comment, 'ed' => $edit_id); db_save_news($db, $nloc); // save db piece db_comm_sync($id, $cid); // update latest comments // Hook comment checker if (hook('add_comment_checker', FALSE)) { return FALSE; } // Notify for New Comment if (getoption('notify_comment')) { $url = $_SERVER['HTTP_REFERER']; $date = date(getoption('timestamp_active'), ctime()); $subject = i18n("CuteNews - New Comment Added"); $message = i18n("New Comment was added by %1 on %3 at %4\n\n%2 ", $name, $comment, $date, $url); cn_send_mail(getoption('notify_email'), $subject, $message); } // Also, remember non authorized user if (!$logged_as_member && isset($_POST['cn_remember_me'])) { cn_guest_auth($name, $mail); } // Redirect... $ref = preg_replace('/&edit_id=\\d+/', '', REQ('referer')); echo '<script type="text/javascript">window.location="' . addslashes($ref) . '";</script>'; echo '<div><a href="' . $refer . '">click there</a> if automatic redirect not work</div>'; return FALSE;
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; }
function dashboard_personal() { $member = member_get(); // Additional fields for user $personal_more = array('site' => array('name' => 'Personal site', 'type' => 'text'), 'about' => array('name' => 'About me', 'type' => 'textarea')); if (request_type('POST')) { cn_dsi_check(); $clause = ''; $any_changes = FALSE; list($editpassword, $confirmpassword, $editnickname, $edithidemail, $more) = GET('editpassword, confirmpassword, editnickname, edithidemail, more', 'POST'); $avatar_file = isset($_FILES['avatar_file']) ? $_FILES['avatar_file'] : null; if (!isset($member['nick']) && !empty($editnickname) || isset($member['nick']) && $member['nick'] !== $editnickname) { $any_changes = TRUE; } if (!isset($member['e-hide']) && !empty($edithidemail) || isset($member['e-hide']) && $member['e-hide'] !== $edithidemail) { $any_changes = TRUE; } if ($editpassword) { if ($editpassword === $confirmpassword) { $any_changes = TRUE; db_user_update($member['name'], "pass="******"Check your email."; cn_send_mail($member['email'], i18n("Password was changed"), $notification); } else { cn_throw_message('Password and confirm do not match', 'e'); } } // Update additional fields for personal data $o_more = base64_encode(serialize($member['more'])); $n_more = base64_encode(serialize($more)); if ($o_more !== $n_more) { $any_changes = TRUE; db_user_update($member['name'], "more=" . $n_more); } // Set an avatar if (!empty($avatar_file) && $avatar_file['error'] == 0) { $uploads_dir = getoption('uploads_dir'); if ($uploads_dir) { $file_name = 'avatar_' . $member['name'] . '_' . $avatar_file['name']; if (isset($member['avatar']) && $member['avatar'] != $file_name) { // remove old avatar unlink($uploads_dir . $member['avatar']); } move_uploaded_file($avatar_file['tmp_name'], $uploads_dir . $file_name); db_user_update($member['name'], "avatar=" . $file_name); $any_changes = TRUE; } } // Has changes? if ($any_changes) { db_user_update($member['name'], "nick={$editnickname}", "e-hide={$edithidemail}"); // Update & Get member from DB mcache_set('#member', NULL); $member = member_get(); cn_throw_message("User info updated! {$clause}"); } else { cn_throw_message("No changes", 'w'); } } $grp = getoption('#grp'); $acl_desc = $grp[$member['acl']]['N']; // Get info from personal data foreach ($personal_more as $name => $pdata) { if (isset($member['more'][$name])) { $personal_more[$name]['value'] = $member['more'][$name]; } } cn_assign('member, acl_write_news, acl_desc, personal_more', $member, test('Can'), $acl_desc, $personal_more); echoheader('-@dashboard/style.css', "Personal options"); echo exec_tpl('dashboard/personal'); 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(); }