public function action_index($orderBy = false, $start = 0) { if (!$this->allowed("esoTalk.members.visibleToGuests")) { return; } //If admin has disabled reputatoin points, break if (!C("plugin.Reputation.showReputationPublic")) { return; } $model = ET::getInstance("reputationModel"); $members = $model->getReputationMembers(); //Get rank of current member and get nearby members if rank is greater than 10 $rank = $model->getRankOfCurrentMember(ET::$session->userId, $members); //Three parameters for getNearbyReputationMembers is number of members to be shown, offset, members array if ($rank > 10) { $nearbyMembers = $model->getNearbyReputationMembers(10, $rank - 5, $members); } //Get top 10 reputation members $topMembers = $model->getTopReputationMembers(10, $members); //Pass data to view $this->data("topMembers", $topMembers); $this->data("nearbyMembers", $nearbyMembers); $this->data("rank", $rank); $this->render("reputation"); }
public function handler_init($sender) { ET::$controller->addCSSFile($this->resource("pages.css"), true); $model = ET::getInstance("pagesModel"); $pages = $model->get(); if ($pages) { foreach ($pages as $page) { if (ET::$session->userId) { $sender->addToMenu($page['menu'], $page['slug'] . '-page', '<a href="' . URL("pages") . '/' . $page['pageId'] . '-' . $page['slug'] . '">' . $page['title'] . '</a>'); } elseif ($page['hideFromGuests'] == 0) { $sender->addToMenu($page['menu'], $page['slug'] . '-page', '<a href="' . URL("pages") . '/' . $page['pageId'] . '-' . $page['slug'] . '">' . $page['title'] . '</a>'); } } } }
public function handler_conversationModel_deleteBefore($sender, $sql, $ids) { $model = ET::getInstance("attachmentModel"); // Create a subquery to get all post IDs for these conversations. $postIds = ET::SQL()->select("postId")->from("post")->where("conversationId IN (:conversationIds)")->bind(":conversationIds", $ids)->get(); // Get all attachments for all posts in these conversations, as well as all draft attachments for these conversations. $attachments = ET::SQL()->select("*")->from("attachment")->where("draftConversationId IN (:conversationIds) OR postId IN ({$postIds})")->bind(":conversationIds", $ids)->exec()->allRows("attachmentId"); // Delete them from the database. if (!empty($attachments)) { ET::SQL()->delete()->from("attachment")->where("attachmentId IN (:attachmentIds)")->bind(":attachmentIds", array_keys($attachments))->exec(); // Delete all of these attachments from the filesystem. foreach ($attachments as $attachment) { $model->removeFile($attachment); } } }
public function handler_conversationModel_setDraftAfter($sender, $conversation, $memberId, $draft) { // If we're discarding the draft, delete all relevant attachments from the database. if ($draft === null) { ET::SQL()->delete()->from("attachment")->where("draftMemberId", ET::$session->userId)->where("draftConversationId", $conversation["conversationId"])->exec(); // TODO: delete them from the filesystem as well. } else { $model = ET::getInstance("attachmentModel"); $attachments = $model->extractFromSession(ET::$controller->controllerMethod == "start" ? "c0" : "c" . $conversation["conversationId"]); if (!empty($attachments)) { $model->insertAttachments($attachments, array("draftMemberId" => $memberId, "draftConversationId" => $conversation["conversationId"])); } } }
public function remove($attachmentId) { if (!$this->validateToken()) { return; } $session = (array) ET::$session->get("attachments"); if (isset($session[$attachmentId])) { unset($session[$attachmentId]); ET::$session->store("attachments", $session); } else { $model = ET::getInstance("attachmentModel"); $attachment = $model->getById($attachmentId); // Make sure the user has permission to edit this post. $permission = false; if (!empty($attachment["postId"])) { $post = ET::postModel()->getById($attachment["postId"]); $conversation = ET::conversationModel()->getById($post["conversationId"]); $permission = ET::postModel()->canEditPost($post, $conversation); } else { $permission = ET::$session->userId == $attachment["draftMemberId"]; } if (!$permission) { $this->renderMessage(T("Error"), T("message.noPermission")); return false; } // Remove the attachment from the database and filesystem. $model->deleteById($attachmentId); @unlink($model->path() . $attachmentId . $attachment["secret"]); } }
public function action_removeSession($postId) { if (!$this->validateToken()) { return; } $model = ET::getInstance("attachmentModel"); $attachments = $model->extractFromSession("p" . $postId); foreach ($attachments as $attachment) { $model->removeFile($attachment); } }
private function getAttachmentModel() { return ET::getInstance("attachmentModel"); }
public function handler_membersController_parseTerms($sender, &$terms, $sql, &$conditions) { $model = ET::getInstance("profileFieldModel"); $fields = $model->get(array("searchable" => 1)); foreach ($terms as $k => $term) { $term = strtolower(trim($term)); foreach ($fields as $field) { $prefix = strtolower($field["name"]) . ":"; if (strpos($term, $prefix) === 0) { // Find all member IDs that have field data matching this term. $rows = ET::SQL()->select("DISTINCT memberId")->from("profile_data")->where("fieldId", $field["fieldId"])->where("data LIKE :value")->bind(":value", "%" . trim(substr($term, strlen($prefix))) . "%")->exec()->allRows("memberId"); $ids = array_keys($rows); // Add these members to the results. $conditions[] = "m.memberId IN (:field{$k})"; $sql->bind(":field{$k}", count($ids) ? $ids : 0); unset($terms[$k]); break; } } } }
protected function model() { return ET::getInstance("pagesModel"); }
protected function model() { return ET::getInstance("profileFieldModel"); }
/** * 一覧データにメイン画像サムネイル表示情報を追加する * @param type $results */ private function addMainThumb($results) { if (!SWC_MAIN_THUMB_DISPLAY) { $results; } $atModel = ET::getInstance("attachmentModel"); foreach ($results as &$r) { // XXX: 一覧メイン画像サムネイル表示処理 // ※下書きには別アイコンが出るので表示しない if (!$r["draft"] && intval($r["countPosts"]) > 0) { // 下書きでない、投稿カウントありの場合 // メイン画像ID取得 $attachmentId = $atModel->getMainAttachmentId($r["conversationId"]); $menuImgUrl = ""; if ($attachmentId) { // 添付画像あり $menuImgUrl = URL("attachment/menu/" . $attachmentId); } else { // デフォルトイメージ画像url $menuImgUrl = SwcUtils::getNoImageFileUrl(); } $r["menuImgUrl"] = $menuImgUrl; } } unset($r); return $results; }