diff --git a/includes/ajaxHandler.class.php b/includes/ajaxHandler.class.php index 292e00fa..1b2aac30 100644 --- a/includes/ajaxHandler.class.php +++ b/includes/ajaxHandler.class.php @@ -30,12 +30,7 @@ class AjaxHandler if (!$what || !method_exists($this, $f)) return null; - // see GenericPage::display() - header('Expires: Sat, 01 Jan 2000 01:00:00 GMT'); - header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); - header('Cache-Control: no-store, no-cache, must-revalidate'); - header('Cache-Control: post-check=0, pre-check=0', false); - header('Pragma: no-cache'); + Util::sendNoCacheHeader(); return $this->$f(); } diff --git a/includes/utilities.php b/includes/utilities.php index 1671bc75..d9625aa2 100644 --- a/includes/utilities.php +++ b/includes/utilities.php @@ -1715,6 +1715,15 @@ class Util return [$result, $jsGlobals]; } + + public static function sendNoCacheHeader() + { + header('Expires: Sat, 01 Jan 2000 01:00:00 GMT'); + header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); + header('Cache-Control: no-store, no-cache, must-revalidate'); + header('Cache-Control: post-check=0, pre-check=0', false); + header('Pragma: no-cache'); + } } ?> diff --git a/pages/genericPage.class.php b/pages/genericPage.class.php index 4a5f7838..f227be74 100644 --- a/pages/genericPage.class.php +++ b/pages/genericPage.class.php @@ -56,31 +56,32 @@ trait ListPage class GenericPage { - protected $tpl = ''; - protected $restrictedGroups = U_GROUP_NONE; - protected $mode = CACHE_TYPE_NONE; + protected $tpl = ''; + protected $reqUGroup = U_GROUP_NONE; + protected $reqAuth = false; + protected $mode = CACHE_TYPE_NONE; - protected $jsGlobals = []; - protected $lvData = []; - protected $title = [CFG_NAME]; // for title-Element - protected $name = ''; // for h1-Element - protected $tabId = null; - protected $gDataKey = false; // adds the dataKey to the user vars - protected $js = []; - protected $css = []; + protected $jsGlobals = []; + protected $lvData = []; + protected $title = [CFG_NAME]; // for title-Element + protected $name = ''; // for h1-Element + protected $tabId = null; + protected $gDataKey = false; // adds the dataKey to the user vars + protected $js = []; + protected $css = []; // private vars don't get cached - private $time = 0; - private $cacheDir = 'cache/template/'; - private $jsgBuffer = []; - private $gPageInfo = []; - private $gUser = []; - private $pageTemplate = []; - private $community = ['co' => [], 'sc' => [], 'vi' => []]; + private $time = 0; + private $cacheDir = 'cache/template/'; + private $jsgBuffer = []; + private $gPageInfo = []; + private $gUser = []; + private $pageTemplate = []; + private $community = ['co' => [], 'sc' => [], 'vi' => []]; - private $cacheLoaded = []; - private $skipCache = 0x0; - private $memcached = null; + private $cacheLoaded = []; + private $skipCache = 0x0; + private $memcached = null; public function __construct($pageCall/*, $pageParam */) { @@ -97,10 +98,6 @@ class GenericPage $this->skipCache = CACHE_MODE_FILECACHE | CACHE_MODE_MEMCACHED; } - // restricted access - if ($this->restrictedGroups && !User::isInGroup($this->restrictedGroups)) - $this->error(); - // display modes if (isset($_GET['power']) && method_exists($this, 'generateTooltip')) $this->mode = CACHE_TYPE_TOOLTIP; @@ -111,13 +108,23 @@ class GenericPage $this->gUser = User::getUserGlobals(); $this->pageTemplate['pageName'] = strtolower($pageCall); - if (isset($this->tabId)) - $this->pageTemplate['activeTab'] = $this->tabId; - if (!$this->isValidPage() || !$this->tpl) $this->error(); } + // requires authed user + if ($this->reqAuth && !User::$id) + $this->forwardToSignIn($_SERVER['QUERY_STRING']); + + // restricted access + if ($this->reqUGroup && !User::isInGroup($this->reqUGroup)) + { + if (User::$id) + $this->error(); + else + $this->forwardToSignIn($_SERVER['QUERY_STRING']); + } + if (CFG_MAINTENANCE && !User::isInGroup(U_GROUP_EMPLOYEE)) $this->maintenance(); else if (CFG_MAINTENANCE && User::isInGroup(U_GROUP_EMPLOYEE)) @@ -289,7 +296,8 @@ class GenericPage // display occured notices if ($_ = Util::getNotes()) { - $this->announcements[] = array( + $this->announcements[0] = array( + 'parent' => 'announcement-0', 'id' => 0, 'mode' => 1, 'status' => 1, @@ -302,7 +310,7 @@ class GenericPage // fetch announcements if (preg_match('/^([a-z\-]+)=?.*$/i', $_SERVER['QUERY_STRING'], $match)) { - $ann = DB::Aowow()->Select('SELECT * FROM ?_announcements WHERE status = 1 AND (page = ? OR page = "*") AND (groupMask = 0 OR groupMask & ?d)', $match[1], User::$groups); + $ann = DB::Aowow()->Select('SELECT ABS(id) AS ARRAY_KEY, a.* FROM ?_announcements a WHERE status = 1 AND (page = ? OR page = "*") AND (groupMask = 0 OR groupMask & ?d)', $match[1], User::$groups); foreach ($ann as $k => $v) { if ($t = Util::localizedString($v, 'text')) @@ -312,9 +320,19 @@ class GenericPage 'STATIC_URL' => STATIC_URL ); - $ann[$k]['text'] = strtr($t, $replace); - $ann[$k]['style'] = strtr($ann[$k]['style'], $replace); - $this->announcements[] = $ann[$k]; + $_ = array( + 'parent' => 'announcement-'.$k, + 'id' => $v['id'], + 'mode' => $v['mode'], + 'status' => $v['status'], + 'name' => $v['name'], + 'text' => strtr($t, $replace) + ); + + if ($v['style']) // may be empty + $_['style'] = strtr($v['style'], $replace); + + $this->announcements[$k] = $_; } } } @@ -348,12 +366,17 @@ class GenericPage $this->mysql = DB::Aowow()->getStatistics(); $this->hasComContent = false; + if (isset($this->tabId)) + $this->pageTemplate['activeTab'] = $this->tabId; + $this->display('text-page-generic'); exit(); } public function error() // unknown page { + $this->path = null; + $this->tabId = null; $this->type = -99; // get error-article $this->typeId = 0; $this->title[] = Lang::$main['errPageTitle']; @@ -381,11 +404,10 @@ class GenericPage { // Heisenbug: IE11 and FF32 will sometimes (under unknown circumstances) cache 302 redirects and stop // re-requesting them from the server but load them from local cache, thus breaking menu features. - header('Expires: Sat, 01 Jan 2000 01:00:00 GMT'); - header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); - header('Cache-Control: no-store, no-cache, must-revalidate'); - header('Cache-Control: post-check=0, pre-check=0', false); - header('Pragma: no-cache'); + Util::sendNoCacheHeader(); + + if (isset($this->tabId)) + $this->pageTemplate['activeTab'] = $this->tabId; if ($override) { diff --git a/pages/search.php b/pages/search.php index 2f95eaaa..24b061ac 100644 --- a/pages/search.php +++ b/pages/search.php @@ -60,7 +60,7 @@ class SearchPage extends GenericPage $this->query = strtr($this->search, '?*', '_%'); // restricted access - if ($this->restrictedGroups && !User::isInGroup($this->restrictedGroups)) + if ($this->reqUGroup && !User::isInGroup($this->reqUGroup)) $this->error(); // statWeight for JSON-search diff --git a/pages/zone.php b/pages/zone.php index 7094b11c..196014ce 100644 --- a/pages/zone.php +++ b/pages/zone.php @@ -40,7 +40,7 @@ class ZonePage extends GenericPage /* Infobox */ /***********/ - $infobox = []; + $infobox = Lang::getInfoBoxForFlags($this->subject->getField('cuFlags')); // City if ($this->subject->getField('flags') & 0x200000 && !$this->subject->getField('parentArea')) diff --git a/template/bricks/announcement.tpl.php b/template/bricks/announcement.tpl.php index 4bc35f00..a508bc35 100644 --- a/template/bricks/announcement.tpl.php +++ b/template/bricks/announcement.tpl.php @@ -1,18 +1,12 @@ announcements as $_): +foreach ($this->announcements as $id => $data): + $data = json_encode($data, JSON_NUMERIC_CHECK); + // json_encode does not recognize variables + $data = preg_replace('/"\$((.+?)([^\\\\]))"/i', '$1', $data); ?> -
+