mirror of
https://github.com/slawkens/myaac.git
synced 2025-10-14 09:44:55 +02:00
Feature/new router (#165)
* Remove unneeded escape * Fix guild back buttons (change logo & motd) * small adjustment in news.php * Fix create character when admin (any case is allowed now) * Fix forum table style (boards & thread view) * Small improvement to plugins.enabled check * [WIP] nikic/fast-route implementation I will describe it more in Pull Request * Optimisations & fixes. * Fix path - should not be absolute * Add PLUGINS to Twig path * Don't hide "Install Plugin" Box by default * Update package-lock.json * nothing important, just early exit & fixes Fix creature display * fix premium_ends_at for tfs 1.3+ * Move pages * Move pages tbc * $db->select: make $where parameter optional, allows to get all records * Add some error box to error * fix parse error * Rewriting the router v2 To be more flexible * small fixes * fix & add admin icons * Move mass_* pages to correct folder * fix logout hook 2 * Delete accountmanagement.php * This code wasn't used * Add missing var * Add redirect_from && redirect_to to router options + Also add * for all methods shortcut * Remove comments Not allowed in normal json * Allow admin pages included into plugins dir * block access to some files * Fix admin logout * Fix #178 * feature: mail confirmed reward Suggested by @EPuncker # Conflicts: # system/hooks.php * remove misleading comment * adjust required version according to composer.json * fix duplicated word * Adjustments & fixed to mass actions * Add password confirm, and change text type to password * Add list of Open Source Software MyAAC is using * Fix signature * Show First, Second instead of numbers * fix base dir detection * fix double ACTION define + undefined URI in template * new function> escapeHtml + fix css in admin menus * fix changelog add * fix news adding, rename const to NEWS_* * Add verify to pages, add messages, limits, fix add * fix "Please fill all input" * add required input to admin pages * shorten some expressions with ?? * shorten code + fix conversion (int) * Move account_types to config, account.web_flags to common.php * Update example.json * feature: router aliases * shorten some code + const convert * remove wrong char * fix signature on custom basedir * fix: mass teleport position validation (#214) * fix: mass teleport position validation * fix: max position * Fix execute in CLI * fix warning in reload cache in dev mode * Configurable admin panel folder * feature: plugin require more options with comma * $config_account_salt -> USE_ACCOUNT_SALT * fix forum show_thread * Update show_thread.php --------- Co-authored-by: Gabriel Pedro <gpedro@users.noreply.github.com>
This commit is contained in:
@@ -8,12 +8,12 @@ class News
|
||||
$errors[] = 'Please fill all inputs.';
|
||||
return false;
|
||||
}
|
||||
if(strlen($title) > TITLE_LIMIT) {
|
||||
$errors[] = 'News title cannot be longer than ' . TITLE_LIMIT . ' characters.';
|
||||
if(strlen($title) > NEWS_TITLE_LIMIT) {
|
||||
$errors[] = 'News title cannot be longer than ' . NEWS_TITLE_LIMIT . ' characters.';
|
||||
return false;
|
||||
}
|
||||
if(strlen($body) > BODY_LIMIT) {
|
||||
$errors[] = 'News content cannot be longer than ' . BODY_LIMIT . ' characters.';
|
||||
if(strlen($body) > NEWS_BODY_LIMIT) {
|
||||
$errors[] = 'News content cannot be longer than ' . NEWS_BODY_LIMIT . ' characters.';
|
||||
return false;
|
||||
}
|
||||
if(strlen($article_text) > ARTICLE_TEXT_LIMIT) {
|
||||
@@ -138,4 +138,4 @@ class News
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -45,12 +45,117 @@ class Plugins {
|
||||
private static $error = null;
|
||||
private static $plugin_json = array();
|
||||
|
||||
public static function getRoutes()
|
||||
{
|
||||
$cache = Cache::getInstance();
|
||||
if ($cache->enabled()) {
|
||||
$tmp = '';
|
||||
if ($cache->fetch('plugins_routes', $tmp)) {
|
||||
return unserialize($tmp);
|
||||
}
|
||||
}
|
||||
|
||||
$routes = [];
|
||||
foreach(get_plugins() as $filename) {
|
||||
$string = file_get_contents(PLUGINS . $filename . '.json');
|
||||
$string = self::removeComments($string);
|
||||
$plugin = json_decode($string, true);
|
||||
self::$plugin_json = $plugin;
|
||||
if ($plugin == null) {
|
||||
self::$warnings[] = 'Cannot load ' . $filename . '.json. File might be not a valid json code.';
|
||||
continue;
|
||||
}
|
||||
|
||||
if(isset($plugin['enabled']) && !getBoolean($plugin['enabled'])) {
|
||||
self::$warnings[] = 'Skipping ' . $filename . '... The plugin is disabled.';
|
||||
continue;
|
||||
}
|
||||
|
||||
$warningPreTitle = 'Plugin: ' . $filename . ' - ';
|
||||
|
||||
if (isset($plugin['routes'])) {
|
||||
foreach ($plugin['routes'] as $_name => $info) {
|
||||
// default method: get
|
||||
$method = $info['method'] ?? ['GET'];
|
||||
if ($method !== '*') {
|
||||
$methods = is_string($method) ? explode(',', $info['method']) : $method;
|
||||
foreach ($methods as $method) {
|
||||
if (!in_array($method, ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD'])) {
|
||||
self::$warnings[] = $warningPreTitle . 'Not allowed method ' . $method . '... Disabling this route...';
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$methods = '*'; // all available methods
|
||||
}
|
||||
|
||||
if (!isset($info['priority'])) {
|
||||
$info['priority'] = 100; // default priority
|
||||
}
|
||||
|
||||
if (isset($info['redirect_from'])) {
|
||||
removeIfFirstSlash($info['redirect_from']);
|
||||
|
||||
$info['pattern'] = $info['redirect_from'];
|
||||
if (!isset($info['redirect_to'])) {
|
||||
self::$warnings[] = $warningPreTitle . 'redirect set without "redirect_to".';
|
||||
}
|
||||
else {
|
||||
removeIfFirstSlash($info['redirect_to']);
|
||||
$info['file'] = '__redirect__/' . $info['redirect_to'];
|
||||
}
|
||||
}
|
||||
|
||||
// replace first occurence of / in pattern if found (will be auto-added later)
|
||||
removeIfFirstSlash($info['pattern']);
|
||||
|
||||
foreach ($routes as $id => &$route) {
|
||||
if($route[1] == $info['pattern']) {
|
||||
if($info['priority'] < $route[3]) {
|
||||
self::$warnings[] = $warningPreTitle . "Duplicated route with lower priority: {$info['pattern']}. Disabling this route...";
|
||||
continue 2;
|
||||
}
|
||||
else {
|
||||
self::$warnings[] = $warningPreTitle . "Duplicated route with lower priority: {$route[1]} ({$route[3]}). Disabling this route...";
|
||||
unset($routes[$id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$routes[] = [$methods, $info['pattern'], $info['file'], $info['priority']];
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
usort($routes, function ($a, $b)
|
||||
{
|
||||
// key 3 is priority
|
||||
if ($a[3] == $b[3]) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ($a[3] > $b[3]) ? -1 : 1;
|
||||
});
|
||||
*/
|
||||
// cleanup before passing back
|
||||
// priority is not needed anymore
|
||||
foreach ($routes as &$route) {
|
||||
unset($route[3]);
|
||||
}
|
||||
|
||||
if ($cache->enabled()) {
|
||||
$cache->set('plugins_routes', serialize($routes), 600);
|
||||
}
|
||||
|
||||
return $routes;
|
||||
}
|
||||
|
||||
public static function getHooks()
|
||||
{
|
||||
$cache = Cache::getInstance();
|
||||
if ($cache->enabled()) {
|
||||
$tmp = '';
|
||||
if ($cache->fetch('hooks', $tmp)) {
|
||||
if ($cache->fetch('plugins_hooks', $tmp)) {
|
||||
return unserialize($tmp);
|
||||
}
|
||||
}
|
||||
@@ -84,7 +189,7 @@ class Plugins {
|
||||
}
|
||||
|
||||
if ($cache->enabled()) {
|
||||
$cache->set('hooks', serialize($hooks), 600);
|
||||
$cache->set('plugins_hooks', serialize($hooks), 600);
|
||||
}
|
||||
|
||||
return $hooks;
|
||||
@@ -225,27 +330,59 @@ class Plugins {
|
||||
}
|
||||
|
||||
if(in_array($req, array('php-ext', 'php-extension'))) { // require php extension
|
||||
if(!extension_loaded($version)) {
|
||||
self::$error = "This plugin requires php extension: " . $version . " to be installed.";
|
||||
$tmpDisplayError = false;
|
||||
$explode = explode(',', $version);
|
||||
|
||||
foreach ($explode as $item) {
|
||||
if(!extension_loaded($item)) {
|
||||
$errors[] = "This plugin requires php extension: " . $item . " to be installed.";
|
||||
$tmpDisplayError = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($tmpDisplayError) {
|
||||
self::$error = implode('<br/>', $errors);
|
||||
$continue = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if($req == 'table') {
|
||||
if(!$db->hasTable($version)) {
|
||||
self::$error = "This plugin requires table: " . $version . " to exist in the database.";
|
||||
$tmpDisplayError = false;
|
||||
$explode = explode(',', $version);
|
||||
foreach ($explode as $item) {
|
||||
if(!$db->hasTable($item)) {
|
||||
$errors[] = "This plugin requires table: " . $item . " to exist in the database.";
|
||||
$tmpDisplayError = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($tmpDisplayError) {
|
||||
self::$error = implode('<br/>', $errors);
|
||||
$continue = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if($req == 'column') {
|
||||
$tmp = explode('.', $version);
|
||||
if(count($tmp) == 2) {
|
||||
if(!$db->hasColumn($tmp[0], $tmp[1])) {
|
||||
self::$error = "This plugin requires database column: " . $tmp[0] . "." . $tmp[1] . " to exist in database.";
|
||||
$continue = false;
|
||||
break;
|
||||
$tmpDisplayError = false;
|
||||
$explode = explode(',', $version);
|
||||
foreach ($explode as $item) {
|
||||
$tmp = explode('.', $item);
|
||||
|
||||
if(count($tmp) == 2) {
|
||||
if(!$db->hasColumn($tmp[0], $tmp[1])) {
|
||||
$errors[] = "This plugin requires database column: " . $tmp[0] . "." . $tmp[1] . " to exist in database.";
|
||||
$tmpDisplayError = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
self::$warnings[] = "Invalid plugin require column: " . $item;
|
||||
}
|
||||
}
|
||||
|
||||
if ($tmpDisplayError) {
|
||||
self::$error = implode('<br/>', $errors);
|
||||
$continue = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if(strpos($req, 'ext-') !== false) {
|
||||
@@ -378,6 +515,10 @@ class Plugins {
|
||||
return self::$warnings;
|
||||
}
|
||||
|
||||
public static function clearWarnings() {
|
||||
self::$warnings = [];
|
||||
}
|
||||
|
||||
public static function getError() {
|
||||
return self::$error;
|
||||
}
|
||||
|
@@ -92,25 +92,38 @@ abstract class OTS_Base_DB extends PDO implements IOTS_DB
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function select($table, $where, $limit = null)
|
||||
public function select($table, $where = [], $limit = null)
|
||||
{
|
||||
$fields = array_keys($where);
|
||||
$values = array_values($where);
|
||||
$query = 'SELECT * FROM ' . $this->tableName($table) . ' WHERE (';
|
||||
$query = 'SELECT * FROM ' . $this->tableName($table);
|
||||
|
||||
$count = count($fields);
|
||||
for ($i = 0; $i < $count; $i++)
|
||||
$query.= $this->fieldName($fields[$i]).' = '.$this->quote($values[$i]).' AND ';
|
||||
if (!empty($where)) {
|
||||
$query .= ' WHERE (';
|
||||
|
||||
$count = count($fields);
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$query .= $this->fieldName($fields[$i]) . ' = ' . $this->quote($values[$i]) . ' AND ';
|
||||
}
|
||||
|
||||
$query = substr($query, 0, -4);
|
||||
$query .= ')';
|
||||
}
|
||||
|
||||
$query = substr($query, 0, -4);
|
||||
if (isset($limit))
|
||||
$query .=') LIMIT '.$limit.';';
|
||||
$query .=' LIMIT '.$limit.';';
|
||||
else
|
||||
$query .=');';
|
||||
$query .=';';
|
||||
|
||||
$query = $this->query($query);
|
||||
if($query->rowCount() != 1) return false;
|
||||
return $query->fetch();
|
||||
$rowCount = $query->rowCount();
|
||||
if ($rowCount <= 0) return false;
|
||||
else if ($rowCount == 1) {
|
||||
return $query->fetch();
|
||||
}
|
||||
|
||||
return $query->fetchAll();
|
||||
|
||||
}
|
||||
|
||||
public function insert($table, $data)
|
||||
|
Reference in New Issue
Block a user