* reverted removing base href in html head

* added anonymous usage statistics reporting
* (fix) don't show templates that doesn't exist in Menus option in Admin Panel
* (fix) menu ordering by category
* (fix) showing changelog with urls in Admin Panel
* (internal) moved uninstall logic to Plugins class
This commit is contained in:
slawkens 2017-11-03 09:43:47 +01:00
parent ac9c43e280
commit 9aa4e308c1
16 changed files with 175 additions and 97 deletions

View File

@ -228,6 +228,7 @@ $config = array(
'status_port' => '',
// other
'anonymous_usage_statistics' => false,
'email_lai_sec_interval' => 60, // time in seconds between e-mails to one account from lost account interface, block spam
'google_analytics_id' => '', // e.g.: UA-XXXXXXX-X
'experiencetable_columns' => 5, // how many columns to display in experience table page. * experiencetable_rows, 5 = 500 (will show up to 500 level)

View File

@ -30,20 +30,7 @@
// ini_set('display_startup_errors', 1);
// error_reporting(E_ALL);
if(preg_match("/^(.*)\.(gif|jpg|jpeg|tiff|bmp|css|js|less|map|html|php|zip|rar|gz)$/i", $_SERVER['REQUEST_URI'])) {
header("HTTP/1.0 404 Not Found");
exit;
}
require_once('common.php');
require_once(BASE . 'config.local.php');
if(file_exists(BASE . 'install') && (!isset($config['installed']) || !$config['installed']))
{
header('Location: ' . BASE_URL . 'install/');
die('Setup detected that <b>install/</b> directory exists. Please visit <a href="' . BASE_URL . 'install">this</a> url to start MyAAC Installation.<br/>Delete <b>install/</b> directory if you already installed MyAAC.<br/>Remember to REFRESH this page when you\'re done!');
}
require_once(SYSTEM . 'functions.php');
$uri = $_SERVER['REQUEST_URI'];
@ -57,12 +44,7 @@ else
$uri = str_replace(array('index.php/', '?'), '', $uri);
define('URI', $uri);
$found = false;
if(empty($uri) || isset($_REQUEST['template'])) {
$_REQUEST['p'] = 'news';
$found = true;
}
else if(preg_match("/^[A-Za-z0-9-_%\'+]+\.png$/i", $uri)) {
if(preg_match("/^[A-Za-z0-9-_%\'+]+\.png$/i", $uri)) {
$tmp = explode('.', $uri);
$_REQUEST['name'] = urldecode($tmp[0]);
@ -70,6 +52,23 @@ else if(preg_match("/^[A-Za-z0-9-_%\'+]+\.png$/i", $uri)) {
include(TOOLS . 'signature/index.php');
exit();
}
else if(preg_match("/^(.*)\.(gif|jpg|png|jpeg|tiff|bmp|css|js|less|map|html|php|zip|rar|gz)$/i", $_SERVER['REQUEST_URI'])) {
header("HTTP/1.0 404 Not Found");
exit;
}
require_once(BASE . 'config.local.php');
if(file_exists(BASE . 'install') && (!isset($config['installed']) || !$config['installed']))
{
header('Location: ' . BASE_URL . 'install/');
die('Setup detected that <b>install/</b> directory exists. Please visit <a href="' . BASE_URL . 'install">this</a> url to start MyAAC Installation.<br/>Delete <b>install/</b> directory if you already installed MyAAC.<br/>Remember to REFRESH this page when you\'re done!');
}
$found = false;
if(empty($uri) || isset($_REQUEST['template'])) {
$_REQUEST['p'] = 'news';
$found = true;
}
else if(!preg_match('/[^A-z0-9_\-]/', $uri) && file_exists(SYSTEM . 'pages/' . $uri . '.php')) {
$_REQUEST['p'] = $uri;
$found = true;
@ -193,6 +192,40 @@ $hooks = new Hooks();
$hooks->load();
$hooks->trigger(HOOK_STARTUP);
// anonymous usage statistics
// sent only when user agrees
if(isset($config['anonymous_usage_statistics']) && $config['anonymous_usage_statistics']) {
$report_time = 30 * 24 * 60 * 60; // report one time per 30 days
$should_report = true;
$value = '';
if($cache->enabled() && $cache->fetch('last_usage_report', $value)) {
$should_report = time() > (int)$value + $report_time;
}
else {
$value = '';
if(fetchDatabaseConfig('last_usage_report', $value)) {
$should_report = time() > (int)$value + $report_time;
if($cache->enabled()) {
$cache->set('last_usage_report', $value);
}
}
else {
registerDatabaseConfig('last_usage_report', time());
}
}
if($should_report) {
require_once(LIBS . 'usage_statistics.php');
Usage_Statistics::report();
updateDatabaseConfig('last_usage_report', time());
if($cache->enabled()) {
$cache->set('last_usage_report', time());
}
}
}
if($config['views_counter'])
require_once(SYSTEM . 'counter.php');

View File

@ -23,7 +23,11 @@ if(!$error) {
$value .= "/";
}
if($key != 'var_account' && $key != 'var_account_id' && $key != 'var_password') {
if($key == 'var_usage') {
$content .= '$config[\'anonymous_usage_statistics\'] = ' . ((int)$value == 1 ? 'true' : 'false') . ';';
$content .= PHP_EOL;
}
else if($key != 'var_account' && $key != 'var_account_id' && $key != 'var_password') {
$content .= '$config[\'' . str_replace('var_', '', $key) . '\'] = \'' . $value . '\';';
$content .= PHP_EOL;
}
@ -238,6 +242,7 @@ if(!$error) {
$content .= '// place for your configuration directives, so you can later easily update myaac';
$content .= PHP_EOL;
$content .= "?>";
$file = fopen(BASE . 'config.local.php', 'a+');
if($file) {
if(!$error) {

View File

@ -460,6 +460,7 @@ function template_header($is_admin = false)
<meta http-equiv="content-type" content="text/html; charset=' . $charset . '" />';
if(!$is_admin)
$ret .= '
<base href="' . BASE_URL . '" />
<title>' . $title_full . '</title>';
$ret .= '
@ -983,6 +984,28 @@ function getTopPlayers($limit = 5) {
return $players;
}
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);
}
// validator functions
require_once(LIBS . 'validator.php');
require_once(SYSTEM . 'compat.php');

View File

@ -138,6 +138,52 @@ class Plugins {
return false;
}
public static function uninstall($plugin_name) {
global $cache;
$filename = BASE . 'plugins/' . $plugin_name . '.json';
if(!file_exists($filename)) {
self::$error = 'Plugin ' . $plugin_name . ' does not exist.';
return false;
}
else {
$string = file_get_contents($filename);
$plugin_info = json_decode($string, true);
if($plugin_info == false) {
self::$error = 'Cannot load plugin info ' . $plugin_name . '.json';
return false;
}
else {
if(!isset($plugin_info['uninstall'])) {
self::$error = "Plugin doesn't have uninstall options defined. Skipping...";
return false;
}
else {
$success = true;
foreach($plugin_info['uninstall'] as $file) {
$file = BASE . $file;
if(!deleteDirectory($file)) {
$success = false;
}
}
if($success) {
if($cache->enabled()) {
$cache->delete('templates');
}
return true;
}
else {
self::$error = error_get_last();
}
}
}
}
return false;
}
public static function getWarnings() {
return self::$warnings;
}

View File

@ -11,7 +11,7 @@
defined('MYAAC') or die('Direct access not allowed!');
class Usage_Statistics {
private static $report_url = 'http://my-aac.org/report_usage.php';
private static $report_url = 'https://my-aac.org/report_usage.php';
public static function report() {
$data = json_encode(self::getStats());
@ -20,7 +20,6 @@ class Usage_Statistics {
'http' => array(
'header' => 'Content-type: application/json' . "\r\n"
. 'Content-Length: ' . strlen($data) . "\r\n",
'method' => 'POST',
'content' => $data
)
);
@ -28,7 +27,6 @@ class Usage_Statistics {
$context = stream_context_create($options);
$result = file_get_contents(self::$report_url, false, $context);
//var_dump($result);
return $result !== false;
}

View File

@ -51,6 +51,8 @@ $locale['step_config_mail_address_desc'] = 'Address which will be used for outgo
$locale['step_config_mail_address_error'] = 'Server E-Mail is not correct.';
$locale['step_config_client'] = 'Client version';
$locale['step_config_client_desc'] = 'Used for download page and some templates';
$locale['step_config_usage'] = 'Usage Statistics';
$locale['step_config_usage_desc'] = 'Allow MyAAC to report anonymous usage statistics? The data is sent only once per 30 days and is fully confidential.';
// database
$locale['step_database'] = 'Import schema';

View File

@ -17,10 +17,12 @@ if(!file_exists(BASE . 'CHANGELOG')) {
}
$changelog = file_get_contents(BASE . 'CHANGELOG');
$changelog = nl2br(htmlspecialchars($changelog));
$changelog = htmlspecialchars($changelog);
// replace URLs with <a href...> elements
$changelog = preg_replace('/\s(\w+:\/\/)(\S+)/', ' <a href="\\1\\2" target="_blank">\\1\\2</a>', $changelog);
$changelog = nl2br($changelog);
echo '<div>' . $changelog . '</div>';
?>

View File

@ -29,16 +29,16 @@ if(isset($_REQUEST['template'])) {
}
$db->query('DELETE FROM `' . TABLE_PREFIX . 'menu` WHERE `template` = ' . $db->quote($template));
foreach($post_menu as $id => $menus) {
foreach($post_menu as $category => $menus) {
foreach($menus as $i => $menu) {
if(empty($menu)) // don't save empty menu item
continue;
try {
$db->insert(TABLE_PREFIX . 'menu', array('template' => $template, 'name' => $menu, 'link' => $post_menu_link[$id][$i], 'category' => $id, 'ordering' => $i));
$db->insert(TABLE_PREFIX . 'menu', array('template' => $template, 'name' => $menu, 'link' => $post_menu_link[$category][$i], 'category' => $category, 'ordering' => $i));
}
catch(PDOException $error) {
warning('Error while adding menu item (' . $name . '): ' . $error->getMessage());
warning('Error while adding menu item (' . $menu . '): ' . $error->getMessage());
}
}
}
@ -97,6 +97,12 @@ if(isset($_REQUEST['template'])) {
}
else {
$templates = $db->query('SELECT `template` FROM `' . TABLE_PREFIX . 'menu` GROUP BY `template`;')->fetchAll();
foreach($templates as $key => $value) {
$file = TEMPLATES . $value['template'] . '/config.php';
if(!file_exists($file)) {
unset($templates[$key]);
}
}
echo $twig->render('admin.menus.form.html.twig', array(
'templates' => $templates

View File

@ -14,67 +14,16 @@ $title = 'Plugin manager';
require(SYSTEM . 'hooks.php');
require(LIBS . 'plugins.php');
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);
}
echo $twig->render('admin.plugins.form.html.twig');
if(isset($_REQUEST['uninstall'])){
$uninstall = $_REQUEST['uninstall'];
$filename = BASE . 'plugins/' . $uninstall . '.json';
if(!file_exists($filename)) {
error('Plugin ' . $uninstall . ' does not exist.');
}
else {
$string = file_get_contents($filename);
$plugin_info = json_decode($string, true);
if($plugin_info == false) {
error('Cannot load plugin info ' . $uninstall . '.json');
}
else {
if(!isset($plugin_info['uninstall'])) {
error("Plugin doesn't have uninstall options defined. Skipping...");
}
else {
$success = true;
foreach($plugin_info['uninstall'] as $file) {
$file = BASE . $file;
if(!deleteDirectory($file)) {
$success = false;
}
}
if($success) {
if($cache->enabled()) {
$cache->delete('templates');
}
if(Plugins::uninstall($uninstall)) {
success('Successfully uninstalled plugin ' . $uninstall);
}
else {
error('Error while uninstalling plugin ' . $uninstall . ': ' . error_get_last());
}
}
}
error('Error while uninstalling plugin ' . $plugin_name . ': ' . Plugins::getError());
}
}
else if(isset($_FILES["plugin"]["name"]))

View File

@ -83,7 +83,7 @@ $showed = $post = $reply = false;
echo '</TABLE>';
}
if($bug[2]['status'] != 3)
echo '<br><a href="index.php?subtopic=bugtracker&control=true&id='.$_REQUEST['id'].'&acc='.$_REQUEST['acc'].'&reply=true"><b>[REPLY]</b></a>';
echo '<br><a href="?subtopic=bugtracker&control=true&id='.$_REQUEST['id'].'&acc='.$_REQUEST['acc'].'&reply=true"><b>[REPLY]</b></a>';
}
else
{
@ -112,7 +112,7 @@ $showed = $post = $reply = false;
$type = 2;
$INSERT = $db->query('INSERT INTO `' . TABLE_PREFIX . 'bugtracker` (`account`,`id`,`text`,`reply`,`type`, `who`) VALUES ('.$db->quote($_REQUEST['acc']).','.$db->quote($_REQUEST['id']).','.$db->quote($_POST['text']).','.$db->quote($reply).','.$db->quote($type).','.$db->quote(1).')');
$UPDATE = $db->query('UPDATE `' . TABLE_PREFIX . 'bugtracker` SET `status` = '.$_POST['status'].' where `account` = '.$_REQUEST['acc'].' and `id` = '.$_REQUEST['id'].'');
header('Location: index.php?subtopic=bugtracker&control=true&id='.$_REQUEST['id'].'&acc='.$_REQUEST['acc'].'');
header('Location: ?subtopic=bugtracker&control=true&id='.$_REQUEST['id'].'&acc='.$_REQUEST['acc'].'');
}
}
echo '<br><form method="post" action=""><table><tr><td><i>Description</i></td><td><textarea name="text" rows="15" cols="35"></textarea></td></tr><tr><td>Status[OPEN]</td><td><input type=radio name=status value=2></td></tr><tr><td>Status[CLOSED]</td><td><input type=radio name=status value=3></td></tr></table><br><input type="submit" name="finish" value="Submit" class="input2"/></form>';
@ -138,7 +138,7 @@ $showed = $post = $reply = false;
elseif($report['status'] == 1)
$value = "<font color=blue>[NEW ANSWER]</font>";
echo '<TR BGCOLOR="' . getStyle($i) . '"><td width=75%><a href="index.php?subtopic=bugtracker&control=true&id='.$report['id'].'&acc='.$report['account'].'">'.$tags[$report['tag']].' '.$report['subject'].'</a></td><td>'.$value.'</td></tr>';
echo '<TR BGCOLOR="' . getStyle($i) . '"><td width=75%><a href="?subtopic=bugtracker&control=true&id='.$report['id'].'&acc='.$report['account'].'">'.$tags[$report['tag']].' '.$report['subject'].'</a></td><td>'.$value.'</td></tr>';
$showed=true;
$i++;
@ -202,7 +202,7 @@ $showed = $post = $reply = false;
echo '</TABLE>';
}
if($bug[2]['status'] != 3)
echo '<br><a href="index.php?subtopic=bugtracker&id='.$id.'&reply=true"><b>[REPLY]</b></a>';
echo '<br><a href="?subtopic=bugtracker&id='.$id.'&reply=true"><b>[REPLY]</b></a>';
}
else
{
@ -231,7 +231,7 @@ $showed = $post = $reply = false;
$type = 2;
$INSERT = $db->query('INSERT INTO `myaac_bugtracker` (`account`,`id`,`text`,`reply`,`type`) VALUES ('.$db->quote($acc).','.$db->quote($id).','.$db->quote($_POST['text']).','.$db->quote($reply).','.$db->quote($type).')');
$UPDATE = $db->query('UPDATE `myaac_bugtracker` SET `status` = 1 where `account` = '.$acc.' and `id` = '.$id.'');
header('Location: index.php?subtopic=bugtracker&id='.$id.'');
header('Location: ?subtopic=bugtracker&id='.$id.'');
}
}
echo '<br><form method="post" action=""><table><tr><td><i>Description</i></td><td><textarea name="text" rows="15" cols="35"></textarea></td></tr></table><br><input type="submit" name="finish" value="Submit" class="input2"/></form>';
@ -275,7 +275,7 @@ $showed = $post = $reply = false;
$bgcolor = $light;
}
echo '<TR BGCOLOR="'.$bgcolor.'"><td width=75%><a href="index.php?subtopic=bugtracker&id='.$report['id'].'">'.$tags[$report['tag']].' '.$report['subject'].'</a></td><td>'.$value.'</td></tr>';
echo '<TR BGCOLOR="'.$bgcolor.'"><td width=75%><a href="?subtopic=bugtracker&id='.$report['id'].'">'.$tags[$report['tag']].' '.$report['subject'].'</a></td><td>'.$value.'</td></tr>';
$showed=true;
}
@ -286,7 +286,7 @@ $showed = $post = $reply = false;
}
echo '</TABLE>';
echo '<br><a href="index.php?subtopic=bugtracker&add=true"><b>[ADD REPORT]</b></a>';
echo '<br><a href="?subtopic=bugtracker&add=true"><b>[ADD REPORT]</b></a>';
}
elseif(isset($_REQUEST['add']) && $_REQUEST['add'] == TRUE)
{
@ -320,7 +320,7 @@ $showed = $post = $reply = false;
$type = 1;
$status = 1;
$INSERT = $db->query('INSERT INTO `' . TABLE_PREFIX . 'bugtracker` (`account`,`id`,`text`,`type`,`subject`, `reply`,`status`,`tag`) VALUES ('.$db->quote($acc).','.$db->quote($id_next).','.$db->quote($_POST['text']).','.$db->quote($type).','.$db->quote($_POST['subject']).', 0,'.$db->quote($status).','.$db->quote($_POST['tags']).')');
header('Location: index.php?subtopic=bugtracker&id='.$id_next.'');
header('Location: ?subtopic=bugtracker&id='.$id_next.'');
}
}
@ -338,6 +338,6 @@ $showed = $post = $reply = false;
if(admin() and empty($_REQUEST['control']))
{
echo '<br><br><a href="index.php?subtopic=bugtracker&control=true">[ADMIN PANEL]</a>';
echo '<br><br><a href="?subtopic=bugtracker&control=true">[ADMIN PANEL]</a>';
}
?>

View File

@ -38,7 +38,7 @@ if(isset($_POST['reload_monsters']) && $canEdit)
if($canEdit)
{
?>
<form method="post" action="index.php?subtopic=creatures">
<form method="post" action="<?php echo getLink('creatures'); ?>">
<input type="hidden" name="reload_monsters" value="yes"/>
<input type="submit" value="(admin) Reload monsters"/>
</form>

View File

@ -43,7 +43,7 @@ if(!file_exists($template_path . '/index.php') &&
!file_exists($template_path . '/layout.php'))
{
$template_name = 'kathrine';
$template_path = 'templates/' . $template_name;
$template_path = TEMPLATES . $template_name;
}
$file = $template_path . '/config.ini';
@ -106,7 +106,7 @@ function get_template_menus() {
global $db, $template_name;
$menus = array();
$query = $db->query('SELECT `name`, `link`, `category` FROM `' . TABLE_PREFIX . 'menu` WHERE `template` = ' . $db->quote($template_name) . ' ORDER BY `ordering` ASC');
$query = $db->query('SELECT `name`, `link`, `category` FROM `' . TABLE_PREFIX . 'menu` WHERE `template` = ' . $db->quote($template_name) . ' ORDER BY `category`, `ordering` ASC');
foreach($query->fetchAll() as $menu) {
$menus[$menu['category']][] = array('name' => $menu['name'], 'link' => $menu['link']);
}

View File

@ -31,6 +31,18 @@
<em>{{ locale.step_config_client_desc }}</em>
</td>
</tr>
<tr>
<td>
<label for="vars_usage">
<span>{{ locale.step_config_usage }}</span>
</label>
<br>
<input type="checkbox" name="vars[usage]" id="vars_usage" value="1" checked/>
</td>
<td>
<em>{{ locale.step_config_usage_desc }}</em>
</td>
</tr>
</table>
{{ buttons|raw }}

View File

@ -75,11 +75,12 @@ defined('MYAAC') or die('Direct access not allowed!');
<div id="mainsubmenu">
<?php
foreach($menus as $category => $menu) {
echo '<div id="' . $config['menu_categories'][$category]['id'] . '-submenu">';
if(!isset($menus[$category])) {
return;
continue;
}
echo '<div id="' . $config['menu_categories'][$category]['id'] . '-submenu">';
$size = count($menus[$category]);
$i = 0;

View File

@ -26,7 +26,7 @@
$file = trim(strtolower($config['signature_type'])) . '.php';
if(!file_exists($file))
die('ERROR: Wrong signature type in config.');
die('ERROR: Wrong signature_type in config.');
putenv('GDFONTPATH=' . SIGNATURES_FONTS);
@ -52,7 +52,7 @@
}
$cached = SIGNATURES_CACHE.$player->getId() . '.png';
if(file_exists($cached) and (time() < (filemtime($cached) + (60 * $config['signature_cache_time']))))
if(file_exists($cached) && (time() < (filemtime($cached) + (60 * $config['signature_cache_time']))))
{
header( 'Content-type: image/png' );
readfile( SIGNATURES_CACHE.$player->getId().'.png' );