if ($PHORUM["DATA"]["OPTION_ALLOWED"]["subscribe_mail"]) { $subscribe_type = PHORUM_SUBSCRIPTION_MESSAGE; } break; default: trigger_error("Illegal message subscription type: " . htmlspecialchars($message["subscription"])); break; } if ($subscribe_type !== NULL) { phorum_api_user_subscribe($message["user_id"], $message["thread"], $PHORUM["forum_id"], $subscribe_type); } elseif ($mode == 'reply') { phorum_api_user_unsubscribe($message["user_id"], $message["thread"]); } if ($PHORUM["DATA"]["LOGGEDIN"]) { // Mark own message read. phorum_db_newflag_add_read(array(0 => array("id" => $message["message_id"], "forum" => $message["forum_id"]))); // Increase the user's post count. phorum_api_user_increment_posts(); } // Actions for messages which are approved. if ($message["status"] > 0) { // Update forum statistics. phorum_db_update_forum_stats(false, 1, $message["datestamp"]); // Mail subscribed users. phorum_email_notice($message); } // Mail moderators. if ($PHORUM["email_moderators"] == PHORUM_EMAIL_MODERATOR_ON) { phorum_email_moderators($message); } /*
// and again for the header-links $PHORUM['DATA']['FEEDS'] = array(array('TITLE' => $PHORUM['DATA']['FEED'], 'URL' => $GLOBALS["PHORUM"]["DATA"]["URL"]["FEED"])); } // include the correct template $templates = array(); if ($PHORUM["threaded_read"] == 1) { $templates[] = "read_threads"; } elseif ($PHORUM["threaded_read"] == 2) { $templates[] = "read_hybrid"; } else { $templates[] = "read"; } if ($PHORUM["DATA"]["LOGGEDIN"]) { // setting read messages really read if (count($read_messages)) { phorum_db_newflag_add_read($read_messages); if ($PHORUM['cache_newflags']) { phorum_cache_remove('newflags', $newflagkey); phorum_cache_remove('newflags_index', $newflagkey); } } } // {REPLY_ON_READ} is set when message replies are done on // the read page. The template can use this to add the // #REPLY anchor to the page. This way, the browser can jump // to the editor when clicking a reply link. $PHORUM["DATA"]["REPLY_ON_READ"] = !empty($PHORUM["reply_on_read_page"]); if (isset($PHORUM["reply_on_read_page"]) && $PHORUM["reply_on_read_page"]) { // Never show the reply box if the message is closed. if ($thread_is_closed) { $PHORUM["DATA"]["OKMSG"] = $PHORUM["DATA"]["LANG"]["ThreadClosed"];
/** * Mark all messages for a forum read for the active Phorum user. * * @param integer $forum_id * The forum to mark read or 0 (zero) to mark the current forum read. */ function phorum_db_newflag_allread($forum_id = 0) { $PHORUM = $GLOBALS['PHORUM']; if (empty($forum_id)) { $forum_id = $PHORUM['forum_id']; } settype($forum_id, 'int'); // Delete all the existing newflags for this user for this forum. phorum_db_newflag_delete(0, $forum_id); // Retrieve the maximum message_id in this forum. $max_id = phorum_db_interact(DB_RETURN_VALUE, "SELECT max(message_id)\n FROM {$PHORUM['message_table']}\n WHERE forum_id = {$forum_id}"); // Set this message_id as the min-id for the forum. if ($max_id) { phorum_db_newflag_add_read(array(0 => array('id' => $max_id, 'forum' => $forum_id))); } }
if (!defined("PHORUM_ADMIN")) { return; } // wow doing it all by hand this time :( // adding the new field phorum_db_interact(DB_RETURN_RES, "ALTER TABLE {$PHORUM['user_newflags_table']}\n ADD message_id INT UNSIGNED NOT NULL DEFAULT '0'", NULL, DB_MASTERQUERY); // removing old primary-key phorum_db_interact(DB_RETURN_RES, "ALTER TABLE {$PHORUM['user_newflags_table']}\n DROP PRIMARY KEY", NULL, DB_MASTERQUERY); // adding new primary-key phorum_db_interact(DB_RETURN_RES, "ALTER TABLE {$PHORUM['user_newflags_table']}\n ADD PRIMARY KEY (user_id , forum_id , message_id)", NULL, DB_MASTERQUERY); // converting the newflags $rows = phorum_db_interact(DB_RETURN_ASSOCS, "SELECT *\n FROM {$PHORUM['user_newflags_table']}\n WHERE message_id=0", NULL, DB_MASTERQUERY); $olduser = $GLOBALS['PHORUM']['user']['user_id']; foreach ($rows as $row) { $forum = $row['forum_id']; $data = unserialize($row['newflags']); $GLOBALS['PHORUM']['user']['user_id'] = $row['user_id']; $newdata = array(); foreach ($data as $mid1 => $mid2) { if (is_int($mid1)) { $newdata[] = array("id" => $mid1, "forum" => $forum); } } phorum_db_newflag_add_read($newdata); unset($data); unset($newdata); } $GLOBALS['PHORUM']['user']['user_id'] = $olduser; phorum_db_interact(DB_RETURN_RES, "DELETE FROM {$PHORUM['user_newflags_table']}\n WHERE message_id=0", NULL, DB_MASTERQUERY); // remove old column phorum_db_interact(DB_RETURN_RES, "ALTER TABLE {$PHORUM['user_newflags_table']}\n DROP newflags", NULL, DB_MASTERQUERY);
/** * Mark forums, threads or messages as read for the active Phorum user. * * @param mixed $markread_ids * This parameter provides the ids of the items that have to be marked * read. It can be either a single item id (depending on the $mode * parameter either message_id, thread_id or forum_id) or an array * of item ids. * * @param integer $mode * This determines whether messages, threads or forums are marked * read. Possible values for this parameter are: * {@link PHORUM_MARKREAD_MESSAGES}, * {@link PHORUM_MARKREAD_THREADS}, * {@link PHORUM_MARKREAD_FORUMS} */ function phorum_api_newflags_markread($markread_ids, $mode = PHORUM_MARKREAD_MESSAGES) { global $PHORUM; // No newflags for anonymous users. if (!$PHORUM['user']['user_id']) { return $messages; } // Make sure that the $markread_ids parameter is an array of integers. if (!is_array($markread_ids)) { $markread_ids = array((int) $markread_ids); } else { foreach ($markread_ids as $key => $val) { $markread_ids[$key] = (int) $val; } } // An array to keep track of the forums for which we need to invalidate // the cache later on. $processed_forum_ids = array(); // Handle marking forums read. if ($mode == PHORUM_MARKREAD_FORUMS) { foreach ($markread_ids as $forum_id) { phorum_db_newflag_allread($forum_id); $processed_forum_ids[$forum_id] = $forum_id; } } elseif ($mode == PHORUM_MARKREAD_THREADS) { // Retrieve the data for the threads to mark read. $threads = phorum_db_get_message($markread_ids, 'message_id', TRUE); // Process the threads. $markread = array(); foreach ($threads as $thread) { // In case this was no thread or broken thread data. if ($thread['parent_id'] != 0 || empty($thread['meta']['message_ids'])) { continue; } // Fetch the user's newflags for the thread's forum, so we // can limit the messages to mark read to the actual unread // messages in the thread. $forum_id = $thread['forum_id']; if (!isset($PHORUM['user']['newflags'][$forum_id])) { $newflags = phorum_api_newflags_by_forum($forum_id); } else { $newflags = $PHORUM['user']['newflags'][$forum_id]; } // Find out what message_ids are unread in the thread. // If we have no newflags for the forum (yet), then consider // all the messages in the thread as new. $markread = array(); foreach ($thread['meta']['message_ids'] as $mid) { if (empty($newflags) || !isset($newflags[$mid]) && $mid > $newflags['min_id']) { $markread[] = array('id' => $mid, 'forum' => $forum_id); } } $processed_forum_ids[$forum_id] = $forum_id; } // Mark the messages in the thread(s) as read. phorum_db_newflag_add_read($markread); } elseif ($mode == PHORUM_MARKREAD_MESSAGES) { // Retrieve the data for the messages to mark read. $messages = phorum_db_get_message($markread_ids); // Process the messages. $markread = array(); foreach ($messages as $message) { $markread[] = array('id' => $message['message_id'], 'forum' => $message['forum_id']); $processed_forum_ids[$message['forum_id']] = $message['forum_id']; } // Mark the messages read in the database. phorum_db_newflag_add_read($markread); } // Invalidate cached forum newflags data. foreach ($processed_forum_ids as $forum_id) { unset($PHORUM['user']['newflags'][$forum_id]); if ($PHORUM['cache_newflags']) { $cachekey = $forum_id . '-' . $PHORUM['user']['user_id']; phorum_cache_remove('newflags', $cachekey); phorum_cache_remove('newflags_index', $cachekey); } } }
/** * Create a message. * * @param int $p_forumId * The forum ID that this message belongs to. * * @param string $p_subject * The subject of the message. * * @param string $p_body * The body of the message * * @param int $p_threadId * Set this to zero if it is the first message in the thread * * @param int $p_parentId * The message you are replying to. * * @param string $p_author * Human readable string for the name of the author. * * @param string $p_email * Author's email. * * @param int $p_userId * User ID that is stored in the phorum_users table. * * @return boolean */ public function create($p_forumId, $p_subject ='', $p_body = '', $p_threadId = 0, $p_parentId = 0, $p_author = '', $p_email = '', $p_userId = 0) { global $PHORUM; global $g_ado_db; if (!is_numeric($p_forumId)) { return null; } // Fetch the settings and pretend they were returned to // us instead of setting a global variable. phorum_db_load_settings(); $settings = $PHORUM['SETTINGS']; // Required Input $message['forum_id'] = $p_forumId; // Optional input $message['body'] = $p_body; $message['subject'] = $p_subject; $message['thread'] = $p_threadId; $message['parent_id'] = $p_parentId; $message['author'] = $p_author; $message['email'] = $p_email; $message['user_id'] = $p_userId; // Defaults $message['sort'] = PHORUM_SORT_DEFAULT; $message['closed'] = 0; // ??? Whats that suffix for? // $suffix = preg_replace("/[^a-z0-9]/i", "", $PHORUM["name"]); // $message['msgid'] = md5(uniqid(rand())) . ".$suffix"; $message['msgid'] = md5(uniqid(rand())); $message['moderator_post'] = '0'; $message['datestamp'] = time(); // Fetch the forum object - // we need it for the config values. $forumObj = new Phorum_forum($p_forumId); if (!$forumObj->exists()) { return false; } // Set message workflow based on forum config. if ($forumObj->isModerated()) { $message['status'] = PHORUM_STATUS_HOLD; } else { $message['status'] = PHORUM_STATUS_APPROVED; } // Set user IP. $user_ip = $_SERVER["REMOTE_ADDR"]; if ($settings["dns_lookup"]) { $resolved = @gethostbyaddr($_SERVER["REMOTE_ADDR"]); if (!empty($resolved)) { $user_ip = $resolved; } } $message["ip"] = $user_ip; $lockTables = array($PHORUM['message_table'], $PHORUM['search_table'], $PHORUM['subscribers_table']); $this->lockTables($lockTables); phorum_db_post_message($message); $this->mod_emailcomments($message); // Update the thread count. $sql = "SELECT COUNT(*) as thread_count FROM ".$PHORUM['message_table'] ." WHERE forum_id=".$p_forumId ." AND thread=".$message['thread'] ." AND status > 0"; $threadCount = $g_ado_db->GetOne($sql); $sql = "UPDATE ".$PHORUM['message_table'] ." SET thread_count=".$threadCount; $g_ado_db->Execute($sql); // Retrieve the message again because the database sets // some values. $message = phorum_db_get_message($message["message_id"], "message_id", true); $this->m_data = $message; // Set the thread depth $this->__initThreadDepth(); // Set the thread order. $this->__initThreadOrder(); $this->__updateThreadInfo(); if (isset($PHORUM['user']['user_id'])) { // Mark own message read. phorum_db_newflag_add_read(array(0=>array( "id" => $message["message_id"], "forum" => $message["forum_id"], ))); // Update the number of messages the user has posted. phorum_db_user_addpost(); } // Actions for messages which are approved. if ($message["status"] > 0) { // Update forum statistics, // ??? Note: phorum_db_update_forum_stats requires global parameter-passing. $PHORUM['forum_id'] = $p_forumId; phorum_db_update_forum_stats(false, 1, $message["datestamp"]); // Mail subscribed users. //phorum_email_notice($message); } // Mail moderators. if ($forumObj->emailModeratorsEnabled()) { //phorum_email_moderators($message); } $this->unlockTables(); return true; } // fn create
/** * This function returns the newinfo-array for markallread */ function phorum_db_newflag_allread($forum_id=0) { $PHORUM = $GLOBALS['PHORUM']; $conn = phorum_db_postgresql_connect(); settype($forum_id, "int"); if(empty($forum_id)) $forum_id=$PHORUM["forum_id"]; // delete all newflags for this user and forum phorum_db_newflag_delete(0,$forum_id); // get the maximum message-id in this forum $sql = "select max(message_id) from {$PHORUM['message_table']} where forum_id=$forum_id"; $res = pg_query($conn, $sql); if ($err = pg_last_error()){ phorum_db_pg_last_error("$err: $sql"); }elseif (pg_num_rows($res) > 0){ $row = pg_fetch_row($res); if($row[0] > 0) { // set this message as min-id phorum_db_newflag_add_read(array(0=>array('id'=>$row[0],'forum'=>$forum_id))); } } }
if ($PHORUM["DATA"]["LOGGEDIN"]) { $PHORUM["DATA"]["URL"]["MARK_READ"] = phorum_get_url(PHORUM_LIST_URL, $PHORUM["forum_id"], "markread"); } if ($PHORUM["DATA"]["MODERATOR"]) { $PHORUM["DATA"]["URL"]["UNAPPROVED"] = phorum_get_url(PHORUM_CONTROLCENTER_URL, "panel=messages"); } // add feed url if (isset($PHORUM['use_rss']) && $PHORUM['use_rss']) { $PHORUM['DATA']['FEEDS'] = array(array('URL' => phorum_get_url(PHORUM_FEED_URL, $PHORUM['forum_id'], 'type=' . $PHORUM['default_feed']), 'TITLE' => $PHORUM['DATA']['FEED'] . ' (' . strtolower($PHORUM['DATA']['LANG']['Threads']) . ')'), array("URL" => phorum_get_url(PHORUM_FEED_URL, $PHORUM['forum_id'], 'replies=1', 'type=' . $PHORUM['default_feed']), "TITLE" => $PHORUM['DATA']['FEED'] . ' (' . strtolower($PHORUM['DATA']['LANG']['Threads'] . ' + ' . $PHORUM['DATA']['LANG']['replies']) . ')')); $PHORUM["DATA"]["URL"]["FEED"] = phorum_get_url(PHORUM_FEED_URL, $PHORUM['forum_id'], 'replies=1', 'type=' . $PHORUM['default_feed']); } // updating new-info for first visit (last message on first page is first new) if ($PHORUM["DATA"]["LOGGEDIN"] && $PHORUM['user']['newinfo']['min_id'] == 0 && !isset($PHORUM['user']['newinfo'][$min_id]) && $min_id != 0) { // setting it as min-id // set it -1 as the comparison is "post newer than min_id" $min_id--; phorum_db_newflag_add_read($min_id); if ($PHORUM['cache_newflags']) { phorum_cache_remove('newflags', $newflagkey); phorum_cache_remove('newflags_index', $newflagkey); } } // include the correct template if ($PHORUM["threaded_list"]) { $template = "list_threads"; } else { $template = "list"; } phorum_output($template); //timing_mark('end'); //timing_print();
$msg = array("parent_id" => $parent, "thread" => $thread, "forum_id" => $f, "subject" => "Message {$i} of stress batch thread {$batch} / {$count}", "body" => "I am just a test message, created by the Phorum\n" . "stress testing software. I have no value at all.\n", "user_id" => $u, "author" => $users[$u]["username"], "ip" => "127.0.0.1", "status" => PHORUM_STATUS_APPROVED, "msgid" => "<stressbatch_{$batch}_{$count}_{$i}@localhost>", "moderator_post" => 0, "sort" => PHORUM_SORT_DEFAULT, "closed" => 0); phorum_db_post_message($msg); $thread = $msg["thread"]; $treemsgs[] = $msg["message_id"]; $parent = $treemsgs[array_rand($treemsgs)]; } phorum_update_thread_info($thread); $tcount--; } print "\n"; foreach ($forum_ids as $id) { $PHORUM["forum_id"] = $id; phorum_db_update_forum_stats(true); } } if ($ncount) { print "\nSetting {$ncount} newflags for " . count($users) . " users:\n\n"; $recent = phorum_db_get_recent_messages($ncount); $markread = array(); foreach ($recent as $id => $msg) { $markread[] = array("id" => $id, "forum" => $msg["forum_id"]); } foreach ($users as $user_id => $stuff) { print "."; $PHORUM["user"]["user_id"] = $user_id; phorum_db_newflag_add_read($markread); } print "\n"; } print "\nDone!\n\n"; exit(0);