* updated tinymce to the latest (4.7.0) version

* added option to uninstall plugin
* added option to require specified myaac or php version for plugins
* added links loaded from database to admin panel - for future plugins
* added few characters hooks
* fixed some kathrine template js bug when shop is disabled
This commit is contained in:
slawkens
2017-10-09 16:47:34 +02:00
parent e984a467ef
commit 04d9ec9c94
343 changed files with 824 additions and 37919 deletions

View File

@@ -16,8 +16,14 @@ define('HOOK_AFTER_PAGE', 3);
define('HOOK_FINISH', 4);
define('HOOK_TIBIACOM_ARTICLE', 5);
define('HOOK_TIBIACOM_BORDER_3', 6);
define('HOOK_CHARACTERS_BEFORE_INFORMATIONS', 7);
define('HOOK_CHARACTERS_AFTER_INFORMATIONS', 8);
define('HOOK_CHARACTERS_BEFORE_SIGNATURE', 9);
define('HOOK_CHARACTERS_AFTER_SIGNATURE', 10);
define('HOOK_CHARACTERS_AFTER_ACCOUNT', 11);
define('HOOK_CHARACTERS_AFTER_CHARACTERS', 12);
define('HOOK_FIRST', HOOK_STARTUP);
define('HOOK_LAST', HOOK_TIBIACOM_BORDER_3);
define('HOOK_LAST', HOOK_CHARACTERS_AFTER_CHARACTERS);
$hook_types = array(
'STARTUP' => HOOK_STARTUP,
@@ -25,7 +31,13 @@ $hook_types = array(
'AFTER_PAGE' => HOOK_AFTER_PAGE,
'FINISH' => HOOK_FINISH,
'TIBIACOM_ARTICLE' => HOOK_TIBIACOM_ARTICLE,
'TIBIACOM_BORDER_3' => HOOK_TIBIACOM_BORDER_3
'TIBIACOM_BORDER_3' => HOOK_TIBIACOM_BORDER_3,
'CHARACTERS_BEFORE_INFORMATIONS' => HOOK_CHARACTERS_BEFORE_INFORMATIONS,
'CHARACTERS_AFTER_INFORMATIONS' => HOOK_CHARACTERS_AFTER_INFORMATIONS,
'CHARACTERS_BEFORE_SIGNATURE' => HOOK_CHARACTERS_BEFORE_SIGNATURE,
'CHARACTERS_AFTER_SIGNATURE' => HOOK_CHARACTERS_AFTER_SIGNATURE,
'CHARACTERS_AFTER_ACCOUNT' => HOOK_CHARACTERS_AFTER_ACCOUNT,
'CHARACTERS_AFTER_CHARACTERS' => HOOK_CHARACTERS_AFTER_CHARACTERS
);
class Hook
@@ -84,7 +96,7 @@ class Hooks
public function load()
{
global $db;
$hooks = $db->query('SELECT `name`, `type`, `file` FROM `' . TABLE_PREFIX . 'hooks` WHERE `enabled` = 1;');
$hooks = $db->query('SELECT `name`, `type`, `file` FROM `' . TABLE_PREFIX . 'hooks` WHERE `enabled` = 1 ORDER BY `ordering`;');
foreach($hooks as $hook)
$this->register($hook['name'], $hook['type'], $hook['file']);
}

View File

@@ -51,6 +51,12 @@ $function = new Twig_SimpleFunction('getLink', function ($s) {
});
$twig->addFunction($function);
$function = new Twig_SimpleFunction('hook', function ($hook) {
global $hooks;
$hooks->trigger($hook);
});
$twig->addFunction($function);
// trim values we receive
if(isset($_POST))
{

17
system/migrations/10.php Normal file
View File

@@ -0,0 +1,17 @@
<?php
if(!fieldExist('ordering', TABLE_PREFIX . 'hooks'))
$db->query("ALTER TABLE `" . TABLE_PREFIX . "hooks` ADD `ordering` INT(11) NOT NULL DEFAULT 0 AFTER `file`;");
if(!tableExist(TABLE_PREFIX . 'admin_menu'))
$db->query("
CREATE TABLE `myaac_admin_menu`
(
`id` INT(11) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL DEFAULT '',
`page` VARCHAR(255) NOT NULL DEFAULT '',
`ordering` INT(11) NOT NULL DEFAULT 0,
`flags` INT(11) NOT NULL DEFAULT 0,
`enabled` INT(1) NOT NULL DEFAULT 1,
PRIMARY KEY (`id`)
) ENGINE = MyISAM;");
?>

View File

@@ -15,8 +15,55 @@ require(SYSTEM . 'hooks.php');
echo $twig->render('admin.plugins.form.html.twig');
$message = '';
if(isset($_FILES["plugin"]["name"]))
function deleteDirectory($dir) {
if(!file_exists($dir)) {
return true;
}
if(!is_dir($dir)) {
return unlink($dir);
}
foreach(scandir($dir) as $item) {
if($item == '.' || $item == '..') {
continue;
}
if(!deleteDirectory($dir . DIRECTORY_SEPARATOR . $item)) {
return false;
}
}
return rmdir($dir);
}
if(isset($_REQUEST['uninstall'])){
$uninstall = $_REQUEST['uninstall'];
$string = file_get_contents(BASE . 'plugins/' . $uninstall . '.json');
$plugin_info = json_decode($string, true);
if($plugin_info == false) {
warning('Cannot load plugin info ' . $uninstall . '.json');
}
else {
$success = true;
foreach($plugin_info['uninstall'] as $file) {
$file = BASE . $file;
if(!deleteDirectory($file)) {
$success = false;
}
}
if($success) {
success('Successfully uninstalled plugin ' . $uninstall);
}
else {
error('Error while uninstalling plugin ' . $uninstall . ': ' . error_get_last());
}
}
}
else if(isset($_FILES["plugin"]["name"]))
{
$file = $_FILES["plugin"];
$filename = $file["name"];
@@ -28,7 +75,7 @@ if(isset($_FILES["plugin"]["name"]))
if(isset($file['error'])) {
$error = 'Error uploading file';
switch( $file['error'] ) {
switch($file['error']) {
case UPLOAD_ERR_OK:
$error = false;
break;
@@ -79,33 +126,55 @@ if(isset($_FILES["plugin"]["name"]))
$string = file_get_contents($file_name);
$plugin = json_decode($string, true);
if ($plugin == null) {
warning('Cannot load ' . $file_name . '. File might be not valid json code.');
warning('Cannot load ' . $file_name . '. File might be not a valid json code.');
}
if(isset($plugin['install'])) {
if(file_exists(BASE . $plugin['install']))
require(BASE . $plugin['install']);
else
warning('Cannot load install script. Your plugin might be not working correctly.');
}
if(isset($plugin['hooks'])) {
foreach($plugin['hooks'] as $_name => $info) {
if(isset($hook_types[$info['type']])) {
$query = $db->query('SELECT `id` FROM `' . TABLE_PREFIX . 'hooks` WHERE `name` = ' . $db->quote($_name) . ';');
if($query->rowCount() == 1) { // found something
$query = $query->fetch();
$db->query('UPDATE `' . TABLE_PREFIX . 'hooks` SET `type` = ' . $hook_types[$info['type']] . ', `file` = ' . $db->quote($info['file']) . ' WHERE `id` = ' . (int)$query['id'] . ';');
}
else {
$db->query('INSERT INTO `' . TABLE_PREFIX . 'hooks` (`id`, `name`, `type`, `file`) VALUES (NULL, ' . $db->quote($_name) . ', ' . $hook_types[$info['type']] . ', ' . $db->quote($info['file']) . ');');
else {
$continue = true;
$require = $plugin['require'];
if(isset($require)) {
$require_myaac = $require['myaac'];
if(isset($require_myaac)) {
if(version_compare(MYAAC_VERSION, $require_myaac, '<')) {
warning("This plugin requires MyAAC version " . $require_myaac . ", you're using version " . MYAAC_VERSION . " - please update.");
$continue = false;
}
}
else
warning('Unknown event type: ' . $info['type']);
$require_php = $require['php'];
if(isset($require_php)) {
if(version_compare(phpversion(), $require_php, '<')) {
warning("This plugin requires PHP version " . $require_php . ", you're using version " . phpversion() . " - please update.");
$continue = false;
}
}
}
if($continue) {
if (isset($plugin['install'])) {
if (file_exists(BASE . $plugin['install']))
require(BASE . $plugin['install']);
else
warning('Cannot load install script. Your plugin might be not working correctly.');
}
if (isset($plugin['hooks'])) {
foreach ($plugin['hooks'] as $_name => $info) {
if (isset($hook_types[$info['type']])) {
$query = $db->query('SELECT `id` FROM `' . TABLE_PREFIX . 'hooks` WHERE `name` = ' . $db->quote($_name) . ';');
if ($query->rowCount() == 1) { // found something
$query = $query->fetch();
$db->query('UPDATE `' . TABLE_PREFIX . 'hooks` SET `type` = ' . $hook_types[$info['type']] . ', `file` = ' . $db->quote($info['file']) . ' WHERE `id` = ' . (int)$query['id'] . ';');
} else {
$db->query('INSERT INTO `' . TABLE_PREFIX . 'hooks` (`id`, `name`, `type`, `file`) VALUES (NULL, ' . $db->quote($_name) . ', ' . $hook_types[$info['type']] . ', ' . $db->quote($info['file']) . ');');
}
} else
warning('Unknown event type: ' . $info['type']);
}
}
success('<strong>' . $plugin['name'] . '</strong> plugin has been successfully installed.');
}
}
success('<strong>' . $plugin['name'] . '</strong> plugin has been successfully installed.');
}
}
else {
@@ -132,8 +201,6 @@ if(isset($_FILES["plugin"]["name"]))
}
}
echo $message;
$plugins = array();
$rows = array();
@@ -146,14 +213,20 @@ foreach(scandir($path) as $file)
$string = file_get_contents(BASE . 'plugins/' . $file_info[0] . '.json');
$plugin_info = json_decode($string, true);
$rows[] = array(
'name' => $plugin_info['name'],
'description' => $plugin_info['description'],
'version' => $plugin_info['version'],
'author' => $plugin_info['author'],
'contact' => $plugin_info['contact'],
'file' => $file,
);
if($plugin_info == false) {
warning('Cannot load plugin info ' . $file);
}
else {
$rows[] = array(
'name' => $plugin_info['name'],
'description' => $plugin_info['description'],
'version' => $plugin_info['version'],
'author' => $plugin_info['author'],
'contact' => $plugin_info['contact'],
'file' => $file_info[0],
'uninstall' => isset($plugin_info['uninstall'])
);
}
}
echo $twig->render('admin.plugins.html.twig', array(

View File

@@ -1,21 +1,15 @@
<script type="text/javascript" src="{{ constant('BASE_URL') }}tools/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript" src="{{ constant('BASE_URL') }}tools/tinymce/tinymce.min.js"></script>
<script type="text/javascript">
tinyMCE.init({
mode : "textareas",
theme : "advanced",
plugins: "safari,advimage,emotions,insertdatetime,preview,wordcount",
relative_urls : false,
remove_script_host : false,
document_base_url : "{{ constant('BASE_URL') }}",
theme_advanced_buttons3_add : "emotions,insertdate,inserttime,preview,|,forecolor,backcolor",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true,
});
tinymce.init({
selector : "textarea",
theme : "modern",
plugins: 'print preview fullpage searchreplace autolink directionality visualblocks visualchars fullscreen image link media template codesample table charmap hr pagebreak nonbreaking anchor toc insertdatetime advlist lists textcolor wordcount spellchecker imagetools contextmenu colorpicker textpattern help',
toolbar1: 'formatselect | bold italic strikethrough forecolor backcolor | link | alignleft aligncenter alignright alignjustify | numlist bullist outdent indent | removeformat',
image_advtab: true,
relative_urls : false,
remove_script_host : false,
document_base_url : "{{ constant('BASE_URL') }}"
});
</script>
<table width="800" cellspacing="1" cellpadding="2" border="0" align="center">
<form method="post">

View File

@@ -6,14 +6,16 @@
<th>Version</th>
<th>Author</th>
<th>Contact</th>
<th>Options</th>
</tr>
{% for plugin in plugins %}
<tr>
<td><div title="{{ plugin.description }}">{{ plugin.name }}</div></td>
<td>{{ plugin.file }}</td>
<td>{{ plugin.file }}.json</td>
<td>{{ plugin.version }}</td>
<td>{{ plugin.author }}</td>
<td>{{ plugin.contact }}</td>
<td><a href="?p=plugins&uninstall={{ plugin.file }}">Uninstall</a></td>
</tr>
{% endfor %}
</table>

View File

@@ -2,6 +2,7 @@
<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr>
<td><img src="<{{ template_path }}/images/general/blank.gif" width="10" height="1" border="0"></td>
<td>
{{ hook(constant('HOOK_CHARACTERS_BEFORE_INFORMATIONS')) }}
<table border="0" cellspacing="1" cellpadding="4" width="100%">
{% if config.characters.outfit %}
<div style="width:64px;height:64px;border:2px solid #F1E0C6; border-radius:50px; padding:13px; margin-top:38px;margin-left:376px;position:absolute;"><img style="margin-left:{% if player.getLookType() in [75, 266, 302] %}-0px;margin-top:-0px;width:64px;height:64px;{% else %}-60px;margin-top:-60px;width:128px;height:128px;{% endif %}" src="{{ outfit }}" alt="player outfit"/></div>
@@ -139,6 +140,7 @@
<td>{% if account.isPremium() %}Premium Account{% else %}Free Account{% endif %}</td>
</tr>
</table>
{{ hook(constant('HOOK_CHARACTERS_AFTER_INFORMATIONS')) }}
<br/>
<table border="0" width="100%">
<tr>
@@ -217,21 +219,23 @@
{{ deaths|raw }}
{{ frags|raw }}
{{ hook(constant('HOOK_CHARACTERS_BEFORE_SIGNATURE')) }}
{% if config.signature_enabled %}
<script type="text/javascript">
function showSignLinks()
{
if(document.getElementById('signLinks').style.display == "none")
{
document.getElementById('signLinks').style.display = "inline";
document.getElementById('signText').innerHTML = "Hide links";
}
function showSignLinks()
{
if(document.getElementById('signLinks').style.display == "none")
{
document.getElementById('signLinks').style.display = "inline";
document.getElementById('signText').innerHTML = "Hide links";
}
else
{
document.getElementById('signLinks').style.display = "none";
document.getElementById('signText').innerHTML = "Show links";
}
}
{
document.getElementById('signLinks').style.display = "none";
document.getElementById('signText').innerHTML = "Show links";
}
}
</script>
<br/>
<table border="0" cellspacing="1" cellpadding="4" width="100%"><tr bgcolor="{{ config.vdarkborder }}"><td colspan=2 class="white"><b>Signature</b></td></tr>
@@ -257,7 +261,7 @@
</td></tr>
</table>
{% endif %}
{{ hook(constant('HOOK_CHARACTERS_AFTER_SIGNATURE')) }}
{% if hidden != 1 %}
{% set rows = 0 %}
<br/><br/>
@@ -299,6 +303,7 @@
<td>{{ account.getCustomField("created")|date("j F Y, g:i a") ~bannedUntil }}</td>
</tr>
</table>
{{ hook(constant('HOOK_CHARACTERS_AFTER_ACCOUNT')) }}
<br/><br/>
<table border="0" cellspacing="1" cellpadding="4" width="100%">
<tr bgcolor="{{ config.vdarkborder }}">
@@ -342,6 +347,7 @@
{% endfor %}
</table>
{% endif %}
{{ hook(constant('HOOK_CHARACTERS_AFTER_CHARACTERS')) }}
</td>
<td>
<img src="{{ template_path }}/images/general/blank.gif" width="10" height="1" border="0">

View File

@@ -1,18 +1,11 @@
<script type="text/javascript" src="{{ constant('BASE_URL') }}tools/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript" src="{{ constant('BASE_URL') }}tools/tinymce/tinymce.min.js"></script>
<script type="text/javascript">
tinyMCE.init({
forced_root_block : false,
mode : "textareas",
theme : "advanced",
plugins: "safari,advimage,emotions,insertdatetime,preview,wordcount",
theme_advanced_buttons3_add : "emotions,insertdate,inserttime,preview,|,forecolor,backcolor",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true,
tinymce.init({
selector : "textarea",
theme : "modern",
plugins: 'print preview fullpage searchreplace autolink directionality visualblocks visualchars fullscreen image link media template codesample table charmap hr pagebreak nonbreaking anchor toc insertdatetime advlist lists textcolor wordcount spellchecker imagetools contextmenu colorpicker textpattern help',
toolbar1: 'formatselect | bold italic strikethrough forecolor backcolor | link | alignleft aligncenter alignright alignjustify | numlist bullist outdent indent | removeformat',
image_advtab: true
});
</script>
{% if action != 'edit' %}