/** * This function sets the stats for a thread like count, timestamp, etc. */ function phorum_update_thread_info($thread) { $PHORUM = $GLOBALS["PHORUM"]; $messages=phorum_db_get_messages($thread); //these are not needed here unset($messages['users']); // remove hidden/unapproved messages from the array $filtered_messages=array_filter($messages, "phorum_remove_hidden"); $thread_count=count($filtered_messages); if($thread_count>0){ $message_ids=array_keys($filtered_messages); $parent_message=$filtered_messages[$thread]; if (isset($PHORUM["reverse_threading"]) && $PHORUM["reverse_threading"]) { reset($filtered_messages); $recent_message=current($filtered_messages); } else { $recent_message=end($filtered_messages); } // prep the message to save $message["thread_count"]=$thread_count; $message["modifystamp"]=$recent_message["datestamp"]; $message["meta"]=$parent_message["meta"]; $message["meta"]["recent_post"]["user_id"]=$recent_message["user_id"]; $message["meta"]["recent_post"]["author"]=$recent_message["author"]; $message["meta"]["recent_post"]["message_id"]=$recent_message["message_id"]; $message["meta"]["message_ids"]=$message_ids; // used only for mods $message["meta"]["message_ids_moderator"]=array_keys($messages); phorum_db_update_message($thread, $message); } }
// then set the vroot to the vroot of the parent-folder (be it 0 or a real vroot) phorum_admin_set_vroot($cur_folder_id,$parent_folder[$cur_folder['parent_id']]['vroot'],$cur_folder_id); } else { // just default root ... phorum_admin_set_vroot($cur_folder_id,0,$cur_folder_id); } // need to clear announcements in this vroot $PHORUM['forum_id']=$oldfolder['vroot']; $GLOBALS['PHORUM']['forum_id']=$oldfolder['vroot']; $msg_array=phorum_db_get_message(PHORUM_SORT_ANNOUNCEMENT,'sort'); while(count($msg_array)) { // set announcements to forum-id=0 and hidden ... $new_msg=array('forum_id'=>0,'status'=>PHORUM_STATUS_HIDDEN); phorum_db_update_message($msg_array['message_id'],$new_msg); $msg_array=phorum_db_get_message(PHORUM_SORT_ANNOUNCEMENT,'sort'); } // we have now set this folder as vroot } elseif($setvroot && ($oldfolder['vroot']==0 || $oldfolder['vroot'] != $cur_folder_id)) { if(!phorum_admin_set_vroot($cur_folder_id)) { $error="Database error while setting virtual-root info."; } } // is there an else? } else { $error="Database error while adding/updating folder."; }
/** * This function sets the stats for a thread like count, timestamp, etc. */ function phorum_update_thread_info($thread) { $PHORUM = $GLOBALS["PHORUM"]; $messages = phorum_db_get_messages($thread, 0, 1, 1); //these are not needed here unset($messages['users']); // Compute the threadviewcount, based on the individual message views. // This can be useful for updating the view counters after enabling // the view_count_per_thread option. $threadviewcount = 0; foreach ($messages as $id => $message) { $threadviewcount += $message['viewcount']; } // remove hidden/unapproved messages from the array $filtered_messages = array_filter($messages, "phorum_remove_hidden"); $thread_count = count($filtered_messages); if ($thread_count > 0) { $message_ids = array_keys($filtered_messages); sort($message_ids); $parent_message = $filtered_messages[$thread]; // find the latest post in the thread (aka recent_message) $last_message_id_by_time = 0; $last_post_time = 0; foreach ($filtered_messages as $message_id => $message_data) { if ($message_data['datestamp'] > $last_post_time) { $last_post_time = $message_data['datestamp']; $last_message_id_by_time = $message_id; } elseif ($message_data['datestamp'] == $last_post_time && $message_id > $last_message_id_by_time) { $last_post_time = $message_data['datestamp']; $last_message_id_by_time = $message_id; } } $recent_message = $filtered_messages[$last_message_id_by_time]; // prep the message to save $message = array(); $message["thread_count"] = $thread_count; $message["threadviewcount"] = $threadviewcount; $message["modifystamp"] = $recent_message["datestamp"]; $message["recent_message_id"] = $recent_message["message_id"]; $message["recent_user_id"] = $recent_message["user_id"]; $message["recent_author"] = $recent_message["author"]; $message["meta"] = $parent_message["meta"]; // For cleaning up pre-5.2 recent post data. unset($message["meta"]["recent_post"]); $message["meta"]["message_ids"] = $message_ids; // used only for mods $message_ids_moderator = array_keys($messages); sort($message_ids_moderator); $message["meta"]["message_ids_moderator"] = $message_ids_moderator; if ($PHORUM['cache_messages']) { // we can simply store them here again, no need to invalidate the cache // this function is called in any place where we change something to the thread phorum_cache_put('message_index', $PHORUM['forum_id'] . "-{$thread}-1", $message["meta"]["message_ids"]); phorum_cache_put('message_index', $PHORUM['forum_id'] . "-{$thread}-0", $message["meta"]["message_ids_moderator"]); // but we need to invalidate the main-message as its changed for the recent author/message phorum_cache_remove('message', $thread); } phorum_db_update_message($thread, $message); } }
/** * Purifies a data array */ function phorum_htmlpurifier_format($data) { $PHORUM = $GLOBALS["PHORUM"]; $purifier =& HTMLPurifier::getInstance(); $cache_serial = $PHORUM['mod_htmlpurifier']['body_cache_serial']; foreach ($data as $message_id => $message) { if (isset($message['body'])) { if ($message_id) { // we're dealing with a real message, not a fake, so // there a number of shortcuts that can be taken if (isset($message['meta']['htmlpurifier_light'])) { // format hook was called outside of Phorum's normal // functions, do the abridged purification $data[$message_id]['body'] = $purifier->purify($message['body']); continue; } if (!empty($PHORUM['args']['purge'])) { // purge the cache, must be below the following if unset($message['meta']['body_cache']); } if (isset($message['meta']['body_cache']) && isset($message['meta']['body_cache_serial']) && $message['meta']['body_cache_serial'] == $cache_serial) { // cached version is present, bail out early $data[$message_id]['body'] = base64_decode($message['meta']['body_cache']); continue; } } // migration might edit this array, that's why it's defined // so early $updated_message = array(); // create the $body variable if ($message_id && !isset($message['meta']['body_cache_serial'])) { // perform migration $fake_data = array(); list($signature, $edit_message) = phorum_htmlpurifier_remove_sig_and_editmessage($message); $fake_data[$message_id] = $message; $fake_data = phorum_htmlpurifier_migrate($fake_data); $body = $fake_data[$message_id]['body']; $body = str_replace("<phorum break>\n", "\n", $body); $updated_message['body'] = $body; // save it in $body .= $signature . $edit_message; // add it back in } else { // reverse Phorum's pre-processing $body = $message['body']; // order is important $body = str_replace("<phorum break>\n", "\n", $body); $body = str_replace(array('<', '>', '&', '"'), array('<', '>', '&', '"'), $body); if (!$message_id && defined('PHORUM_CONTROL_CENTER')) { // we're in control.php, so it was double-escaped $body = str_replace(array('<', '>', '&', '"'), array('<', '>', '&', '"'), $body); } } $body = $purifier->purify($body); // dynamically update the cache (MUST BE DONE HERE!) // this is inefficient because it's one db call per // cache miss, but once the cache is in place things are // a lot zippier. if ($message_id) { // make sure it's not a fake id $updated_message['meta'] = $message['meta']; $updated_message['meta']['body_cache'] = base64_encode($body); $updated_message['meta']['body_cache_serial'] = $cache_serial; phorum_db_update_message($message_id, $updated_message); } // must not get overloaded until after we cache it, otherwise // we'll inadvertently change the original text $data[$message_id]['body'] = $body; } } return $data; }
phorum_hook("after_edit", $dbmessage); } // remove the message from the cache if caching is enabled // no need to clear the thread-index as the message has only been changed if ($PHORUM['cache_messages']) { phorum_cache_remove('message', $message["message_id"]); phorum_db_update_forum(array('forum_id' => $PHORUM['forum_id'], 'cache_version' => $PHORUM['cache_version'] + 1)); } // Update children to the same sort setting. if (!$message["parent_id"] && $origmessage["sort"] != $dbmessage["sort"]) { $messages = phorum_db_get_messages($message["thread"], 0); unset($messages["users"]); foreach ($messages as $message_id => $msg) { if ($msg["sort"] != $dbmessage["sort"] || $msg["forum_id"] != $dbmessage["forum_id"]) { $msg["sort"] = $dbmessage["sort"]; phorum_db_update_message($message_id, $msg); if ($PHORUM['cache_messages']) { phorum_cache_remove('message', $message_id); } } } } // Update all thread messages to the same closed setting. if (!$message["parent_id"] && $origmessage["closed"] != $dbmessage["closed"]) { if ($dbmessage["closed"]) { phorum_db_close_thread($message["thread"]); } else { phorum_db_reopen_thread($message["thread"]); } } // Update thread info.
} else { $PHORUM['DATA']["URL"]["REDIRECT"] = $PHORUM["DATA"]["URL"]["LIST"]; } break; case PHORUM_HIDE_POST: // hiding a message (and its replies) $old_message = phorum_db_get_message($msgthd_id); $newpost = array("status" => PHORUM_STATUS_HIDDEN); $mids = phorum_db_get_messagetree($msgthd_id, $old_message["forum_id"]); // make an array from the string $mids_arr = explode(",", $mids); // count the entries for later use $num_hidden = count($mids_arr); foreach ($mids_arr as $key => $mid) { // setting the new status phorum_db_update_message($mid, $newpost); } /* * [hook] * hide_thread * * [description] * This hook can be used for performing actions like sending * notifications or making log entries after hiding a message. * * [category] * Moderation * * [when] * In <filename>moderation.php</filename>, right after a message has * been hidden by a moderator.
/** * Update the thread info. * Thread info is stored in the first message in the thread. * The first message in the thread is the one where * the message_id is equal to the thread_id. * * This code is mainly copied from phorum_update_thread_info(), * but that function uses phorum_db_get_messages(), * which uses external function calls to APIs outside of * mysql.php, which we want to avoid. * * @return void */ private function __updateThreadInfo() { $thread_id = $this->m_data['thread']; $searchConditions = array("thread" => $thread_id, "forum_id" => $this->m_data['forum_id'], "status" => PHORUM_STATUS_APPROVED); $messages = Phorum_message::GetMessages($searchConditions); $thread_count = count($messages); // If there are any messages left in the thread, // then update the thread data. if ($thread_count > 0) { $threadBeginMessage = array(); $message_ids = array_keys($messages); if (isset($messages[$thread_id])) { $parent_message = $messages[$thread_id]; // Paul Baranowski: my hack so that multiple top-level messages // are allowed within a thread. Disabled but here for // reference, because this worked. // $parent_message = isset($messages[$thread_id]) ? $messages[$thread_id] : current($messages); // $thread_id = $parent_message->getMessageId(); // The most recent message in the thread. $recent_message = end($messages); // Updates to the first thread message. $threadBeginMessage["thread_count"] = $thread_count; $threadBeginMessage["modifystamp"] = $recent_message->m_data["datestamp"]; $threadBeginMessage["meta"] = $parent_message->m_data["meta"]; $threadBeginMessage["meta"]["recent_post"]["user_id"] = $recent_message->m_data["user_id"]; $threadBeginMessage["meta"]["recent_post"]["author"] = $recent_message->m_data["author"]; $threadBeginMessage["meta"]["recent_post"]["message_id"] = $recent_message->m_data["message_id"]; $threadBeginMessage["meta"]["message_ids"] = $message_ids; // Used only for mods // Get the message IDs of all messages in the thread, // regardless of status. // // ??? Note: why are these stored in this way? // Why not just grab these from the database when you // want them - it would probably be just as fast. $searchConditions = array("thread" => $thread_id, "forum_id" => $this->m_data['forum_id']); $allMessages = Phorum_message::GetMessages($searchConditions); $threadBeginMessage["meta"]["message_ids_moderator"] = array_keys($allMessages); phorum_db_update_message($thread_id, $threadBeginMessage); } } } // fn __updateThreadInfo