forked from Felli/Signature
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.php
executable file
·117 lines (98 loc) · 3.48 KB
/
plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
// Copyright 2014 Tristan van Bokkem
if (!defined("IN_ESOTALK")) exit;
ET::$pluginInfo["Signature"] = array(
"name" => "Signature",
"description" => "Let users add their signature to posts.",
"version" => "1.1.6",
"author" => "Tristan van Bokkem",
"authorEmail" => "tristanvanbokkem@gmail.com",
"authorURL" => "http://www.bitcoinclub.nl",
"license" => "GPLv2",
"priority" => "0"
);
class ETPlugin_Signature extends ETPlugin {
function setup()
{
ET::writeConfig(array("plugin.Signature.characters" => "150"));
return true;
}
function handler_settingsController_initGeneral($sender, $form)
{
$sender->addCSSFile($this->resource("signature.css"));
$form->addSection("signature", T("Signature"), array("after" => "privacy"));
$form->setValue("signature", ET::$session->preference("signature"));
$form->addField("signature", "signature", array($this, "fieldSignature"), array($this, "saveSignature"));
}
function fieldSignature($form)
{
$signature = substr(ET::formatter()->init(ET::$session->preference("signature"))->format()->get(),0,C("plugin.Signature.characters"));
if ($signature)
{
return $form->input("signature", "text")." <small>(".T("Max characters:")." ".C("plugin.Signature.characters").", ".T("BBCode Allowed").")</small><br /><br /><div class='signature-settings'><small>".$signature."</small></div>";
}
else
{
return $form->input("signature", "text")." <small>(".T("Max characters:")." ".C("plugin.Signature.characters").", ".T("BBCode Allowed").")</small><br /><br /><small>-</small>";
}
}
public function saveSignature($form, $key, &$preferences)
{
$signature = $form->getValue($key);
$preferences["signature"] = $signature;
}
public function handler_conversationController_renderBefore($sender)
{
$sender->addCSSFile($this->resource("signature.css"));
$sender->addJSFile($this->resource("signature.js"));
}
public function handler_conversationController_formatPostForTemplate($sender, &$formatted, $post, $conversation)
{
if ($post["deleteMemberId"]) return;
// Lets check if the Likes plugin is active,
// if so we need to output the signature HTML a bit different.
if (in_array("Likes", C("esoTalk.enabledPlugins")))
{
if(isset($post["preferences"]["signature"]))
{
$signature = ET::formatter()->init($post["preferences"]["signature"])->format()->get();
}
else
{
$signature = NULL;
}
if ($signature)
{
addToArray($formatted["footer"], "<div class='signature'>".substr($signature,0,C("plugin.Signature.characters"))."</div>", 0);
}
else
{
return;
}
}
else
{
$signature = ET::formatter()->init($post["preferences"]["signature"])->format()->get();
addToArray($formatted["footer"], "<div class='signature-no-likes'>".substr($signature,0,C("plugin.Signature.characters"))."</div>", 0);
}
}
public function settings($sender)
{
// Set up the settings form.
$form = ETFactory::make("form");
$form->action = URL("admin/plugins/settings/Signature");
// Set the values for the sitemap options.
$form->setValue("characters", C("plugin.Signature.characters", "150"));
// If the form was submitted...
if ($form->validPostBack()) {
// Construct an array of config options to write.
$config = array();
$config["plugin.Signature.characters"] = $form->getValue("characters");
// Write the config file.
ET::writeConfig($config);
$sender->redirect(URL("admin/plugins"));
}
$sender->data("SignatureSettingsForm", $form);
return $this->view("settings");
}
}