ACC SHELL
<?php
// Author: Jakub Macek, CZ; Copyright: Poski.com s.r.o.; Code is 100% my work. Do not copy.
class History
{
public static $active = true;
public static $save_current = true;
public static $return_point = true;
const KEY = 'history';
public static function initialize()
{
if (!self::$active)
return;
if (!isset($_SESSION[self::KEY]) || !is_array($_SESSION[self::KEY]))
$_SESSION[self::KEY] = array();
}
public static function save()
{
if (!self::$active || !self::$save_current)
return;
if (page()->location == '404')
return;
$info = array(
'timestamp' => time(),
'request_uri' => substr(site()->url, 0, -strlen(PATH)) . $_SERVER['REQUEST_URI'],
'page' => $GLOBALS["page"],
'return_point' => self::$return_point,
);
array_unshift($_SESSION[self::KEY], $info);
$_SESSION[self::KEY] = array_slice($_SESSION[self::KEY], 0, 50);
}
public static function last($pattern = null, $field = 'page.location')
{
if (!@$_SESSION[self::KEY])
return null;
$result = null;
if ($pattern === null)
list($result) = array_split($_SESSION[self::KEY], 0, 1);
else
{
if ($negative = (substr($pattern, 0, 1) == '!'))
$pattern = substr($pattern, 1);
foreach ($_SESSION[self::KEY] as $info)
{
if (substr($field, 0, 4) == 'page')
$value = $info['page'][substr($field, 5)];
else
$value = $info[$field];
$matches = preg_match($pattern, $value);
if ((!$negative && $matches) || ($negative && !$matches))
return $info;
}
}
return $result;
}
}
?>
ACC SHELL 2018