-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
skywalker512
committed
Jul 6, 2018
1 parent
a71fa46
commit fc2530b
Showing
11 changed files
with
371 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
$definitions["Add a Converstation Warning"] = "设置回帖提醒"; | ||
$definitions["Define the rules of a Conversation"] = "以上内容将在用户回复该贴时在编辑器下方显示 "; | ||
$definitions["Edit Warning"] = "编辑"; | ||
$definitions["Remove Warning"] = "删除"; | ||
$definitions["Warning!"] = "回帖提醒"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
## esoTalk – Conversation Warning plugin | ||
|
||
- Define the rules of conversation before replying. | ||
|
||
### Installation | ||
|
||
Browse to your esoTalk plugin directory: | ||
``` | ||
cd WEB_ROOT_DIR/addons/plugins/ | ||
``` | ||
|
||
Clone the ConversationWarning plugin repo into the plugin directory: | ||
``` | ||
git clone [email protected]:tvb/ConversationWarning.git ConversationWarning | ||
``` | ||
|
||
Chown the ConversationWarning plugin folder to the right web user: | ||
``` | ||
chown -R apache:apache ConversationWarning/ | ||
``` | ||
|
||
### Translation | ||
|
||
Create `definitions.ConversationWarning.php` in your language pack with the following definitions: | ||
|
||
``` | ||
$definitions["Add a Converstation Warning"] = "Add a Converstation Warning"; | ||
$definitions["Define the rules of a Conversation"] = "Define the rules of a Conversation"; | ||
$definitions["Edit Warning"] = "Edit Warning"; | ||
$definitions["Remove Warning"] = "Remove Warning"; | ||
$definitions["Warning!"] = "Warning"; | ||
``` |
73 changes: 73 additions & 0 deletions
73
addons/plugins/ConversationWarning/WarningController.class.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
// Copyright 2014 Tristan van Bokkem | ||
|
||
if (!defined("IN_ESOTALK")) exit; | ||
|
||
class WarningController extends ETController { | ||
|
||
protected function plugin() | ||
{ | ||
return ET::$plugins["ConversationWarning"]; | ||
} | ||
|
||
protected function model() | ||
{ | ||
return ET::getInstance("warningModel"); | ||
} | ||
|
||
public function action_index($conversationId = 0) | ||
{ | ||
// Get the existing warning. | ||
$model = ET::getInstance("warningModel"); | ||
$result = $model->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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
// Copyright 2014 Tristan van Bokkem | ||
|
||
if (!defined("IN_ESOTALK")) exit; | ||
|
||
class WarningModel extends ETModel { | ||
|
||
public function __construct() | ||
{ | ||
parent::__construct("conversation"); | ||
} | ||
|
||
// Function to update the warning column. | ||
public function update($conversationId, $warning = NULL) | ||
{ | ||
return ET::SQL() | ||
->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(); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?php | ||
// Copyright 2014 Tristan van Bokkem | ||
|
||
if (!defined("IN_ESOTALK")) exit; | ||
|
||
ET::$pluginInfo["ConversationWarning"] = array( | ||
"name" => "回帖提醒", | ||
"description" => "允许用户设置回帖提醒,以提醒其他用户回帖的注意事项", | ||
"version" => "1.1.2", | ||
"author" => "Tristan van Bokkem", | ||
"authorEmail" => "[email protected]", | ||
"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 <HEAD>. | ||
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", "<a href='#' id='addWarning'><i class='icon-warning-sign'></i> ".T("Warning!")."</a>", 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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
// Copyright 2014 Tristan van Bokkem | ||
|
||
if (!defined("IN_ESOTALK")) exit; | ||
$form = $data["form"]; | ||
?> | ||
|
||
<div class='sheet' id='warningSheet'> | ||
<div class='sheetContent'> | ||
<?php echo $form->open(); ?> | ||
<h3><?php echo T("Add a Converstation Warning"); ?></h3> | ||
<div class='section'> | ||
<?php echo $form->input("warning", "textarea", array("cols" => "67", "rows" => "10")); ?><br /> | ||
<small><?php echo T("Define the rules of a Conversation").". ".T("HTML is allowed."); ?></small> | ||
</div> | ||
<div class='buttons'> | ||
<?php echo $form->saveButton("warningSave"); ?> | ||
<?php echo $form->cancelButton(); ?> | ||
</div> | ||
<?php echo $form->close(); ?> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
// Copyright 2014 Tristan van Bokkem | ||
|
||
if (!defined("IN_ESOTALK")) exit; | ||
|
||
?> | ||
<div class='modbreak'> | ||
<?php if(is_object(ET::$session) and ET::$session->isAdmin()): ?> | ||
<div class='controls'> | ||
<a class='control-edit-warning' title='<?php echo T("Edit Warning"); ?>'><i class='icon-edit'></i></a> | ||
<a class='control-remove-warning' title='<?php echo T("Remove Warning"); ?>'><i class='icon-remove'></i></a> | ||
</div> | ||
<?php endif; ?> | ||
<div class='legend'><strong><?php echo T("Warning!").":"; ?></strong></div> | ||
<span class='warning'><?php echo nl2br($data["warning"]); ?></span> | ||
</div> |