-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.php
87 lines (70 loc) · 2.5 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
<?php
// MemberSkins/plugin.php
// Allows users to change their skins.
if (!defined("IN_ESO")) exit;
class MemberSkins extends Plugin {
var $id = "MemberSkins";
var $name = "MemberSkins";
var $version = "1.2";
var $description = "Allows users to change their skins";
var $author = "grntbg";
function init()
{
parent::init();
// Language definitions.
$this->eso->addLanguage("forumSkin", "Forum skin");
// If we're on the settings view, add the skin settings!
if ($this->eso->action == "settings") {
$this->eso->controller->addHook("init", array($this, "addSkinSettings"));
}
$this->eso->addHook("init", array($this, "setSkin"));
}
// ... NOW we apply the skin!
function setSkin()
{
global $config;
// Apply the stylesheet for the skin that the user has selected.
if (!empty($this->eso->user["skin"])) {
$this->eso->addCSS("skins/" . $this->eso->user["skin"] . "/styles.css");
// Remove the stylesheet of the configured skin from the array.
unset($this->eso->styleSheets["1"]);
}
}
// Loop through the skins directory to create a string of options to go in the skin <select> tag.
function addSkinSettings(&$settings)
{
global $language, $config;
$this->skins = $this->eso->getSkins();
$skinOptions = "";
$memberId = $this->eso->user["memberId"];
foreach ($this->skins as $v) {
$value = ($v == $config["skin"]) ? "" : $v;
$skinOptions .= "<option value='$value'" . ($this->eso->db->result("SELECT skin FROM {$config["tablePrefix"]}members WHERE memberId=$memberId", 0) == $value ? " selected='selected'" : "") . ">$v</option>";
}
$settings->addToForm("settingsOther", array(
"id" => "skin",
"html" => "<label>{$language["forumSkin"]}</label> <select id='skin' name='skin'>$skinOptions</select>",
"databaseField" => "skin",
"required" => true,
"validate" => array($this, "validateSkin")
), 150);
}
// Validate the skin field: make sure the selected skin actually exists.
function validateSkin(&$skin)
{
global $config;
if (!in_array($skin, $this->skins)) $skin = "";
// Change the user's skin.
$this->eso->db->query("UPDATE {$config["tablePrefix"]}members SET skin='$skin' WHERE memberId={$this->eso->user["memberId"]}");
$this->eso->user["skin"] = $_SESSION["user"]["skin"] = $skin;
}
// Add the table to the database.
function upgrade($oldVersion)
{
global $config;
if (!$this->eso->db->numRows("SHOW COLUMNS FROM {$config["tablePrefix"]}members LIKE 'skin'")) {
$this->eso->db->query("ALTER TABLE {$config["tablePrefix"]}members ADD COLUMN skin varchar(255) default NULL");
}
}
}
?>