public function handler_conversationsController_init($sender) { ET::searchModel(); // Load the search model so we can add this gambit. ETSearchModel::addGambit('return $term == strtolower(T("gambit.order by views"));', array($this, "gambitOrderByViews")); }
/** * Set the channel of a conversation. * * @param array $conversation The conversation to set the channel for. The conversation array's channelId * attribute will be updated. * @param int $channelId Whether or not the conversation is locked. * @return bool Returns true on success, or false if there is an error. */ public function setChannel(&$conversation, $channelId) { if (!ET::channelModel()->hasPermission($channelId, "start")) { $this->error("channelId", T("message.noPermission")); } if ($this->errorCount()) { return false; } // Decrease the conversation/post count of the old channel. ET::SQL()->update("channel")->set("countConversations", "countConversations - 1", false)->set("countPosts", "countPosts - :posts", false)->bind(":posts", $conversation["countPosts"])->where("channelId=:channelId")->bind(":channelId", $conversation["channelId"])->exec(); $this->updateById($conversation["conversationId"], array("channelId" => $channelId)); // Increase the conversation/post count of the new channel. ET::SQL()->update("channel")->set("countConversations", "countConversations + 1", false)->set("countPosts", "countPosts + :posts", false)->bind(":posts", $conversation["countPosts"])->where("channelId=:channelId")->bind(":channelId", $channelId)->exec(); $conversation["channelId"] = $channelId; //Flush conversition cache $sm = ET::searchModel(); ET::$cache->store($sm::CACHE_NS_KEY, time()); return true; }
/** * Return updated HTML for each row in the conversations table, and indicate if there are new results for the * specified channel and search query. * * @param string $channelSlug The channel slug. * @param string $query The search query. * @return void */ public function action_update($channelSlug = "", $query = "") { // This must be done as an AJAX request. $this->responseType = RESPONSE_TYPE_AJAX; list($channelInfo, $currentChannels, $channelIds, $includeDescendants) = $this->getSelectedChannels($channelSlug); $search = ET::searchModel(); // Work out which conversations we need to get updated details for (according to the input value.) $conversationIds = explode(",", R("conversationIds")); // Make sure they are all integers. foreach ($conversationIds as $k => $v) { if (!($conversationIds[$k] = (int) $v)) { unset($conversationIds[$k]); } } if (!count($conversationIds)) { return; } $conversationIds = array_slice((array) $conversationIds, 0, 20); // Work out if there are any new results for this channel/search query. // If the "random" gambit is in the search string, then don't go any further (because the results will // obviously differ!) $random = false; $terms = $query ? explode("+", strtolower(str_replace("-", "+!", trim($query, " +-")))) : array(); foreach ($terms as $v) { if (trim($v) == T("gambit.random")) { $random = true; } } if (!$random) { // TODO: set a #limit gambit for 20 results, because we only check for differences in the first 20 // Get a list of conversation IDs for the channel/query. $newConversationIds = $search->getConversationIDs($channelIds, $query, count($currentChannels) or !ET::$session->userId); $newConversationIds = array_slice((array) $newConversationIds, 0, 20); // Get the difference of the two sets of conversationId's. $diff = array_diff((array) $newConversationIds, (array) $conversationIds); if (count($diff)) { $this->message(sprintf(T("message.newSearchResults"), "javascript:ETSearch.showNewActivity();void(0)"), array("id" => "newSearchResults")); } } // Add fulltext keywords to be highlighted. Make sure we keep ones "in quotes" together. $this->highlight($search->fulltext); $fulltextString = implode(" ", $search->fulltext); // Get the full result data for these conversations, and construct an array of rendered conversation rows. $results = $search->getResults($conversationIds, true); $rows = array(); foreach ($results as $conversation) { $rows[$conversation["conversationId"]] = $this->getViewContents("conversations/conversation", array("conversation" => $conversation, "channelInfo" => $channelInfo, "fulltextString" => $fulltextString)); } // Add that to the response. $this->json("conversations", $rows); $this->render(); }
/** * Return updated HTML for each row in the conversations table, and indicate if there are new results for the * specified channel and search query. * * @param string $channelSlug The channel slug. * @param string $query The search query. * @return void */ public function update($channelSlug = "", $query = "") { // This must be done as an AJAX request. $this->responseType = RESPONSE_TYPE_AJAX; list($channelInfo, $currentChannels, $channelIds, $includeDescendants) = $this->getSelectedChannels($channelSlug); // Work out which conversations we need to get details for (according to the input value.) $conversationIds = explode(",", R("conversationIds")); // Make sure they are all integers. foreach ($conversationIds as $k => $v) { if (!($conversationIds[$k] = (int) $v)) { unset($conversationIds[$k]); } } if (!count($conversationIds)) { return; } // Get the full result data for these conversations, and construct an array of rendered conversation rows. $results = ET::searchModel()->getResults($conversationIds, true); $rows = array(); foreach ($results as $conversation) { $rows[$conversation["conversationId"]] = $this->getViewContents("conversations/conversation", array("conversation" => $conversation, "channelInfo" => $channelInfo)); } // Add that to the response. $this->json("conversations", $rows); // Now we need to work out if there are any new results for this channel/search query. // If the "random" gambit is in the search string, then don't go any further (because the results will // obviously differ!) $terms = $query ? explode("+", strtolower(str_replace("-", "+!", trim($query, " +-")))) : array(); foreach ($terms as $v) { if (trim($v) == T("gambit.random")) { return; } } // Get a list of conversation IDs for the channel/query. $newConversationIds = ET::searchModel()->getConversationIDs($channelIds, $query, count($currentChannels)); $newConversationIds = array_slice((array) $newConversationIds, 0, 20); // Get the difference of the two sets of conversationId's. $diff = array_diff((array) $newConversationIds, (array) $conversationIds); if (count($diff)) { $this->message(T("message.newSearchResults")); } $this->render(); }
public function handler_conversationsController_init($sender) { if (!ET::$session->user) { return; } ET::searchModel(); // Load the search model so we can add this gambit. ETSearchModel::addGambit('return $term == strtolower(T("gambit.bookmarked"));', array($this, "gambitBookmarked")); }
* * @package esoTalk */ ?> <ul class='list conversationList'> <?php // Loop through the conversations and output a table row for each one. foreach ($data["results"] as $conversation) { $this->renderView("conversations/conversation", $data + array("conversation" => $conversation)); } ?> <?php if ($data["showViewMoreLink"]) { ?> <li class='viewMore'> <a href='<?php $searchWithoutLimit = ET::searchModel()->removeGambit($data["searchString"], 'return strpos($term, strtolower(T("gambit.limit:"))) === 0;'); echo URL("conversations/" . $data["channelSlug"] . "?search=" . urlencode($searchWithoutLimit . ($searchWithoutLimit ? " + " : "") . "#" . T("gambit.limit:") . ($data["limit"] + C("esoTalk.search.limitIncrement")))); ?> '><?php echo T("View more"); ?> </a> </li> <?php } ?> </ul>
/** * Unmark a post as deleted. * * @param array $post The post to unmark as deleted. * @return bool true on success, false on error. */ public function restorePost(&$post) { // Update the post. $time = time(); $this->updateById($post["postId"], array("deleteMemberId" => null, "deleteTime" => null)); $post["deleteMemberId"] = null; $post["deleteMemberName"] = null; $post["deleteTime"] = null; //更新缓存 $am = ET::activityModel(); ET::$cache->store($am::CACHE_KEY . '_' . $post['memberId'] . '_' . $am::CACHE_NS_KEY, time()); $sm = ET::searchModel(); ET::$cache->store($sm::CACHE_NS_KEY, time()); return true; }
/** * Toggle a flag on a conversation. * * @param int $conversationId The ID of the conversation. * @param string $type The name of the flag to toggle. * @return void */ public function toggle($conversationId, $type) { if (!$this->validateToken()) { return; } if (!($conversation = $this->getConversation($conversationId))) { return; } // Do we have permission to do this? if (!$conversation["canModerate"]) { $this->renderMessage(T("Error"), T("message.noPermission")); return; } $function = "set" . ucfirst($type); ET::conversationModel()->{$function}($conversation, !$conversation[$type]); //Flush conversition cache $sm = ET::searchModel(); ET::$cache->store($sm::CACHE_NS_KEY, time()); // For the default response type, redirect back to the conversation. if ($this->responseType === RESPONSE_TYPE_DEFAULT) { $this->redirect(URL(R("return", conversationURL($conversation["id"], $conversation["title"])))); } else { $this->json($type, !$conversation[$type]); if ($this->responseType === RESPONSE_TYPE_AJAX) { $this->json("labels", $this->getViewContents("conversation/labels", array("labels" => $conversation["labels"]))); } $this->render(); } }