Beispiel #1
0
 public function handler_conversationController_formatPostForTemplate($sender, &$formatted, $post, $conversation)
 {
     if ($post["deleteTime"]) {
         return;
     }
     $isAnswer = $conversation["answered"] == $post["postId"];
     $isFirstPost = $post["memberId"] == $conversation["startMemberId"] && $post["time"] == $conversation["startTime"];
     $isAuthor = $conversation["startMemberId"] == ET::$session->userId;
     if (!$isFirstPost && ($isAuthor || $conversation["canModerate"]) && !$isAnswer) {
         $label = $conversation["startMemberId"] == ET::$session->userId ? "This answers my question" : "This answers the question";
         addToArray($formatted["footer"], "<a href='" . URL("conversation/answer/" . $post["postId"] . "?token=" . ET::$session->token) . "' class='markAsAnswer'><i class='icon-ok'></i> " . T($label) . "</a>", 0);
     }
     // If this post is the answer...
     if ($isAnswer) {
         $formatted["class"][] = "answer";
         addToArray($formatted["info"], "<span class='label label-answered'><i class='icon-ok-sign'></i> " . T("Answer") . "</span>", 100);
     }
     // If this is the first post in the conversation and there is an answer...
     if ($conversation["answered"] and $isFirstPost) {
         // Get the answer post.
         $answer = ET::postModel()->getById($conversation["answered"]);
         $view = $sender->getViewContents("answers/answer", array("answer" => $answer, "conversation" => $conversation));
         $formatted["body"] = $formatted["body"] . $view;
     }
 }
Beispiel #2
0
 public function handler_conversationController_formatPostForTemplate($sender, &$formatted, $post, $conversation)
 {
     if ($post["deleteMemberId"]) {
         return;
     }
     if ($conversation["startMemberId"] == ET::$session->userId or $conversation["canModerate"]) {
         addToArray($formatted["controls"], "<a href='" . URL("conversation/answer/" . $post["postId"] . "?token=" . ET::$session->token) . "' title='" . T("This post answered my question") . "' class='control-answer'><i class='icon-ok-sign'></i></a>");
     }
     // If this post is the answer...
     if ($conversation["answered"] == $post["postId"]) {
         addToArray($formatted["info"], "<span class='label label-answered'><i class='icon-ok-sign'></i> " . T("Answer") . "</span>", 100);
     }
     // If this is the first post in the conversation and there is an answer...
     if ($conversation["answered"] and $post["memberId"] == $conversation["startMemberId"] and $post["time"] == $conversation["startTime"]) {
         // Get the answer post.
         $answer = ET::postModel()->getById($conversation["answered"]);
         $view = $sender->getViewContents("answers/answer", array("answer" => $answer, "conversation" => $conversation));
         // Add this before the "likes" plugin. Bit hacky, but there's no way to prioritize event handlers in esoTalk :(
         $pos = strpos($formatted["body"], "<p class='likes");
         if (!$pos) {
             $pos = strlen($formatted["body"]);
         }
         $formatted["body"] = substr_replace($formatted["body"], $view, $pos, 0);
     }
 }
Beispiel #3
0
 public function action_conversationController_liked($sender, $postId = false)
 {
     if (!($postId = (int) $postId)) {
         return;
     }
     $post = ET::postModel()->getById($postId);
     if (!$post) {
         return;
     }
     $sender->data("members", $post["likes"]);
     $sender->render($this->view("liked"));
 }
 /**
  * Return post data to work with for an editing action (editPost, deletePost, etc.), but only if the post
  * exists and the user has permission to edit it.
  *
  * @param int $postId The post ID.
  * @return bool|array An array of post data, or false if it cannot be edited.
  */
 protected function getPostForEditing($postId)
 {
     // Get the conversation.
     if (!($conversation = $this->getConversation($postId, true))) {
         return false;
     }
     // Get the post.
     $post = ET::postModel()->getById($postId);
     // Stop here with an error if the user isn't allowed to edit this post.
     if (!ET::postModel()->canEditPost($post, $conversation)) {
         // If users only have permission to edit their posts until someone replies, and someone has replied since...
         if (C("esoTalk.conversation.editPostTimeLimit") === "reply" and ($conversation["lastPostTime"] > $post["time"] or $conversation["lastPostMemberId"] != $post["memberId"])) {
             $msg = T("message.cannotEditSinceReply");
         } else {
             $msg = T("message.noPermission");
         }
         $this->renderMessage(T("Error"), $msg);
         return false;
     }
     $post["conversation"] = $conversation;
     return $post;
 }
 /**
  * Set the title of a conversation.
  *
  * @param array $conversation The conversation to set the title of. The conversation array's title
  * 		attribute will be updated.
  * @param string $title The new title of the conversation.
  * @return bool Returns true on success, or false if there is an error.
  */
 public function setTitle(&$conversation, $title)
 {
     $this->validate("title", $title, array($this, "validateTitle"));
     if ($this->errorCount()) {
         return false;
     }
     $this->updateById($conversation["conversationId"], array("title" => $title));
     // Update the title column in the posts table as well (which is used for fulltext searching).
     ET::postModel()->update(array("title" => $title), array("conversationId" => $conversation["conversationId"]));
     $conversation["title"] = $title;
     return true;
 }
 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"]);
     }
 }
 /**
  * Set the title of a conversation.
  *
  * @param array $conversation The conversation to set the title of. The conversation array's title
  * 		attribute will be updated.
  * @param string $title The new title of the conversation.
  * @return bool Returns true on success, or false if there is an error.
  */
 public function setTitle(&$conversation, $title)
 {
     $this->validate("title", $title, array($this, "validateTitle"));
     if ($this->errorCount()) {
         return false;
     }
     $this->updateById($conversation["conversationId"], array("title" => $title));
     // Update the title column in the posts table as well (which is used for fulltext searching).
     ET::postModel()->update(array("title" => $title), array("conversationId" => $conversation["conversationId"]));
     $conversation["title"] = $title;
     //Flush conversition cache
     $sm = ET::searchModel();
     ET::$cache->store($sm::CACHE_NS_KEY, time());
     return true;
 }
 public function action_remove($attachmentId)
 {
     if (!$this->validateToken()) {
         return;
     }
     //		$session = (array)ET::$session->get("attachments");
     $model = ET::getInstance("attachmentModel");
     $attachment = $model->getById($attachmentId);
     $sessId = ET::$session->getSessId();
     if (is_array($attachment) && count($attachment) > 0) {
         // 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 {
             if ($attachment["sessId"] == $sessId) {
                 $permission = true;
             } else {
                 $permission = ET::$session->userId == $attachment["draftMemberId"];
             }
         }
         if (!$permission) {
             $this->renderMessage(T("Error"), T("message.noPermission"));
             return false;
         }
         // Remove the attachment from the database.
         $model->deleteById($attachmentId);
         // Remove the attachment from the filesystem.
         $model->removeFile($attachment);
     }
 }
 /**
  * Return post data to work with for an editing action (editPost, deletePost, etc.), but only if the post
  * exists and the user has permission to edit it.
  *
  * @param int $postId The post ID.
  * @return bool|array An array of post data, or false if it cannot be edited.
  */
 protected function getPostForEditing($postId)
 {
     // Get the conversation.
     if (!($conversation = $this->getConversation($postId, true))) {
         return false;
     }
     // Get the post.
     $post = ET::postModel()->getById($postId);
     // Stop here with an error if the user isn't allowed to edit this post.
     if (!$this->canEditPost($post, $conversation)) {
         $this->renderMessage(T("Error"), T("message.noPermission"));
         return false;
     }
     $post["conversation"] = $conversation;
     return $post;
 }
Beispiel #10
0
 public function handler_conversationController_like_after($sender, $postId = false)
 {
     $post = ET::postModel()->getById($postId);
     $points = "reputationPoints + " . C("plugin.Reputation.likesRP");
     $this->updateReputationPoints($points, $post["memberId"]);
     return;
 }