diff --git a/addons/languages/Chinese/definitions.ConversationWarning.php b/addons/languages/Chinese/definitions.ConversationWarning.php new file mode 100644 index 0000000..796fa4d --- /dev/null +++ b/addons/languages/Chinese/definitions.ConversationWarning.php @@ -0,0 +1,6 @@ +getWarning($conversationId); + $warning = $result->result(); + + // Set up the form. + $form = ETFactory::make("form"); + $form->addHidden("conversationId", $conversationId); + $form->setValue("warning", $warning); + $form->action = URL("warning"); + + // Was the save button pressed? + if ($form->validPostBack("warningSave")) { + + // Get the conversationId and warning values + $conversationId = $form->getValue("conversationId"); + $warning = $form->getValue("warning"); + + // Update the conversation warning column with the warning. + $model = $this->model(); + $model->update($conversationId, $warning); + + if ($model->errorCount()) { + + // If there were errors, pass them on to the form. + $form->errors($model->errors()); + } else { + + // Otherwise, send the admin a success message. + ET::$controller->message(T("Warning successfully added."), "success autoDismiss"); + + // And redirect back to the conversation page. + $this->redirect(URL("conversation/".$conversationId)); + } + } + + $this->data("form", $form); + $this->responseType = RESPONSE_TYPE_VIEW; + $this->render($this->plugin()->view("add")); + } + + public function action_remove($conversationId) + { + // We can't do this if we're not admin. + if (!ET::$session->isAdmin() or !$this->validateToken()) return false; + + // Remove the warning. + $model = ET::getInstance("warningModel"); + $result = $model->update($conversationId); + $warning = $result->result(); + + return $warning; + } +} diff --git a/addons/plugins/ConversationWarning/WarningModel.class.php b/addons/plugins/ConversationWarning/WarningModel.class.php new file mode 100644 index 0000000..2751ba3 --- /dev/null +++ b/addons/plugins/ConversationWarning/WarningModel.class.php @@ -0,0 +1,34 @@ +update("conversation") + ->set("warning", $warning) + ->where("conversationId = :conversationId") + ->bind(":conversationId", $conversationId, PDO::PARAM_INT) + ->exec(); + } + + // Function to retrieve an existing warning. + public function getWarning($conversationId) + { + return ET::SQL() + ->select("warning") + ->from("conversation") + ->where("conversationId = :conversationId") + ->bind(":conversationId", $conversationId, PDO::PARAM_INT) + ->exec(); + } +} diff --git a/addons/plugins/ConversationWarning/icon.png b/addons/plugins/ConversationWarning/icon.png new file mode 100644 index 0000000..27bd858 Binary files /dev/null and b/addons/plugins/ConversationWarning/icon.png differ diff --git a/addons/plugins/ConversationWarning/index.html b/addons/plugins/ConversationWarning/index.html new file mode 100644 index 0000000..e69de29 diff --git a/addons/plugins/ConversationWarning/plugin.php b/addons/plugins/ConversationWarning/plugin.php new file mode 100644 index 0000000..7f31f5a --- /dev/null +++ b/addons/plugins/ConversationWarning/plugin.php @@ -0,0 +1,115 @@ + "回帖提醒", + "description" => "允许用户设置回帖提醒,以提醒其他用户回帖的注意事项", + "version" => "1.1.2", + "author" => "Tristan van Bokkem", + "authorEmail" => "tristanvanbokkem@gmail.com", + "authorURL" => "http://www.bitcoinclub.nl", + "license" => "GPLv2" +); + +class ETPlugin_ConversationWarning extends ETPlugin { + + // Setup: add a 'warning' column to the conversation table. + public function setup($oldVersion = "") + { + $structure = ET::$database->structure(); + $structure->table("conversation") + ->column("warning", "varchar(1000)") + ->exec(false); + + return true; + } + + public function __construct($rootDirectory) + { + parent::__construct($rootDirectory); + + // Register the warning model which provides convenient methods to + // manage warning data. + ETFactory::register("warningModel", "WarningModel", dirname(__FILE__)."/WarningModel.class.php"); + + // Register the warning controller which provides an interface for + // moderators to manage conversation warnings. + ETFactory::registerController("warning", "WarningController", dirname(__FILE__)."/WarningController.class.php"); + } + + // Add the JavaScript and style sheet to . + public function handler_conversationController_renderBefore($sender) + { + $sender->addCSSFile($this->resource("warning.css")); + $sender->addJSFile($this->resource("warning.js")); + $sender->addJSLanguage("Warning successfully removed."); + } + + // Add the warning control button before the sitcky control button to the conversation controls. + public function handler_conversationController_conversationIndexDefault($sender, $conversation, $controls, $replyForm, $replyControls) + { + if (is_object(ET::$session) and !ET::$session->isAdmin()) return; + + $controls->add("warning", " ".T("Warning!")."", array("before" => "sticky")); + + return $controls; + } + + // When we render the reply box, add the warning area to the bottom of it. + public function handler_conversationController_renderReplyBox($sender, &$formatted, $conversation) + { + // Get the conversation warning by conversationId. + $conversationId = $conversation["conversationId"]; + $model = ET::getInstance("warningModel"); + $result = $model->getWarning($conversationId); + $warning = $result->result(); + + // If there is a warning, append the warning div. + if($warning) { + $this->appendWarning($sender, $formatted, $warning); + } + } + + // When we render an edit post box, add the warning area to the bottom of it. + public function handler_conversationController_renderEditBox($sender, &$formatted, $post) + { + // Get the conversation warning by conversationId based on the postId + $conversation = ET::conversationModel()->getByPostId($post["postId"]); + $conversationId = $conversation["conversationId"]; + + $model = ET::getInstance("warningModel"); + $result = $model->getWarning($conversationId); + $warning = $result->result(); + + // If there is a warning, append the warning div. + if($warning) { + $this->appendWarning($sender, $formatted, $warning); + } + } + + // Get the contents of the "warning" view and append it before the editButtons div + // and after the attachments div. + protected function appendWarning($sender, &$formatted, $warning) + { + $view = $sender->getViewContents("list", array("warning" => $warning)); + if (in_array("Attachments", C("esoTalk.enabledPlugins"))) { + + // After attachments div. + addToArray($formatted["footer"], $view, 1); + + } else { + + // Before editButtons div. + addToArray($formatted["footer"], $view, 0); + } + } + + public function uninstall() + { + $structure = ET::$database->structure(); + $structure->table("conversation")->dropColumn("warning"); + return true; + } +} diff --git a/addons/plugins/ConversationWarning/resources/warning.css b/addons/plugins/ConversationWarning/resources/warning.css new file mode 100644 index 0000000..cbf7b63 --- /dev/null +++ b/addons/plugins/ConversationWarning/resources/warning.css @@ -0,0 +1,17 @@ +.modbreak { + clear:both; + padding:5px 10px 10px 10px; + background-color:#f0d8dd; + border-top:1px solid #d7bec4; + border-bottom:1px solid #d7bec4; + font-size:14px; + margin:0 -2px 0 -2px; +} +.modbreak .legend { + color:#b9133c; + font-weight:700; + margin-bottom:10px; +} +.modbreak .warning {color:#000} +.modbreak .control-modbreak {position:relative;float:right;display:inline} +.control-edit-warning, .control-remove-warning {cursor:pointer} diff --git a/addons/plugins/ConversationWarning/resources/warning.js b/addons/plugins/ConversationWarning/resources/warning.js new file mode 100644 index 0000000..efa3330 --- /dev/null +++ b/addons/plugins/ConversationWarning/resources/warning.js @@ -0,0 +1,56 @@ +// Copyright 2014 Tristan van Bokkem + +// function to load a sheet and formatting the add warning form. +function loadWarningSheet(formData) { + if (!formData) { + ETSheet.loadSheet("warningSheet", "warning/" + ETConversation.id, function() { + }); + } else { + ETSheet.hideSheet("warningSheet"); + } +}; + +// function for removing a conversation warning. +function removeWarning() { + $.ETAjax({ + url: "warning/remove/" + ETConversation.id, + type: "post", + success: function(data) { + $(".modbreak").remove(); + ETMessages.showMessage(T("Warning successfully removed."), {className: "success autoDismiss"}); + } + }); +}; + +// click trigger to remove a warning while editting a post. +$(".control-remove-warning").live("click", function(e) { + e.preventDefault(); + removeWarning(); +}); + +// click trigger to edit a warning while editting a post. +$(".control-edit-warning").live("click", function(e) { + e.preventDefault(); + loadWarningSheet(); +}); + +$(function() { + // click trigger to remove a warning while initiating a new reply. + $(".control-remove-warning").on("click", function(e) { + e.preventDefault(); + removeWarning(); + }); + + // click trigger to edit a warning while editting a post. + $(".control-edit-warning").on("click", function(e) { + e.preventDefault(); + loadWarningSheet(); + }); + + // click trigger to add a warning. + $("#addWarning").live("click", function(e) { + e.preventDefault(); + loadWarningSheet(); + }); + +}); diff --git a/addons/plugins/ConversationWarning/views/add.php b/addons/plugins/ConversationWarning/views/add.php new file mode 100644 index 0000000..62ee8bf --- /dev/null +++ b/addons/plugins/ConversationWarning/views/add.php @@ -0,0 +1,22 @@ + + +
+
+ open(); ?> +

+
+ input("warning", "textarea", array("cols" => "67", "rows" => "10")); ?>
+ +
+
+ saveButton("warningSave"); ?> + cancelButton(); ?> +
+ close(); ?> +
+
diff --git a/addons/plugins/ConversationWarning/views/list.php b/addons/plugins/ConversationWarning/views/list.php new file mode 100644 index 0000000..c734b53 --- /dev/null +++ b/addons/plugins/ConversationWarning/views/list.php @@ -0,0 +1,16 @@ + +
+ isAdmin()): ?> +
+ + +
+ +
+ +