Commit a1556c2c authored by Carsten  Rose's avatar Carsten Rose
Browse files

Store.php: Impelemented Store 'Parent Record'. Extended Store 'Client' with...

Store.php: Impelemented Store 'Parent Record'. Extended Store 'Client' with Server SVars. Reorded fucntions. Added createSipAfterFormLoad()
parent 86a348c3
......@@ -42,9 +42,12 @@ class Store {
private function __construct($bodytext = '') {
self::$defaultSanatizeClass = [
T3_BODYTEXT_DEBUG_LOAD => SANATIZE_ALLOW_DIGIT,
T3_BODYTEXT_DEBUG_SAVE => SANATIZE_ALLOW_DIGIT,
T3_BODYTEXT_FORM => SANATIZE_ALLOW_ALNUMX,
TYPO3_DEBUG_LOAD => SANATIZE_ALLOW_DIGIT,
TYPO3_DEBUG_SAVE => SANATIZE_ALLOW_DIGIT,
TYPO3_FORM => SANATIZE_ALLOW_ALNUMX,
TYPO3_FE_USER => SANATIZE_ALLOW_ALNUMX,
TYPO3_FE_USER_UID => SANATIZE_ALLOW_DIGIT,
TYPO3_FE_USER_GROUP => SANATIZE_ALLOW_ALNUMX,
CLIENT_SIP => SANATIZE_ALLOW_ALNUMX,
CLIENT_GET_SIP => SANATIZE_ALLOW_DIGIT,
......@@ -57,6 +60,22 @@ class Store {
CLIENT_PAGE_LANGUAGE => SANATIZE_ALLOW_DIGIT,
CLIENT_FORM => SANATIZE_ALLOW_ALNUMX,
// Part of $_SERVER. Missing vars must be requested individual with the needed sanatize class.
CLIENT_SCRIPT_URL => SANATIZE_ALLOW_ALNUMX,
CLIENT_SCRIPT_URI => SANATIZE_ALLOW_ALNUMX,
CLIENT_HTTP_HOST => SANATIZE_ALLOW_ALNUMX,
CLIENT_HTTP_USER_AGENT => SANATIZE_ALLOW_ALNUMX,
CLIENT_SERVER_NAME => SANATIZE_ALLOW_ALNUMX,
CLIENT_SERVER_ADDRESS => SANATIZE_ALLOW_ALNUMX,
CLIENT_SERVER_PORT => SANATIZE_ALLOW_DIGIT,
CLIENT_REMOTE_ADDRESS => SANATIZE_ALLOW_ALNUMX,
CLIENT_REQUEST_SCHEME => SANATIZE_ALLOW_ALNUMX,
CLIENT_SCRIPT_FILENAME => SANATIZE_ALLOW_ALNUMX,
CLIENT_QUERY_STRING => SANATIZE_ALLOW_ALL,
CLIENT_REQUEST_URI => SANATIZE_ALLOW_ALL,
CLIENT_SCRIPT_NAME => SANATIZE_ALLOW_ALNUMX,
CLIENT_PHP_SELF => SANATIZE_ALLOW_ALNUMX,
SYSTEM_DBUSER => SANATIZE_ALLOW_ALNUMX,
SYSTEM_DBSERVER => SANATIZE_ALLOW_ALNUMX,
SYSTEM_DBPW => SANATIZE_ALLOW_ALL,
......@@ -81,7 +100,7 @@ class Store {
];
self::fillSystemStore();
self::fillStoreT3Bodytext($bodytext);
self::fillStoreTypo3($bodytext);
self::fillStoreClient();
self::fillStoreSip();
......@@ -118,50 +137,43 @@ class Store {
* @param $bodytext
* @throws CodeException
*/
private function fillStoreT3Bodytext($bodytext) {
private function fillStoreTypo3($bodytext) {
$parser = new \qfq\helper\KeyValueStringParser("=", "\n");
$arr = $parser->parse($bodytext);
if (isset($GLOBALS["TSFE"]->fe_user->user["username"]))
$arr[TYPO3_FE_USER] = $GLOBALS["TSFE"]->fe_user->user["username"];
if (isset($GLOBALS["TSFE"]->fe_user->user["uid"]))
$arr[TYPO3_FE_USER_UID] = $GLOBALS["TSFE"]->fe_user->user["uid"];
if (isset($GLOBALS["TSFE"]->fe_user->user["usergroup"]))
$arr[TYPO3_FE_USER_GROUP] = $GLOBALS["TSFE"]->fe_user->user["usergroup"];
self::setVarArray($parser->parse($bodytext), STORE_T3_BODYTEXT);
self::setVarArray($arr, STORE_TYPO3);
}
/**
* @throws CodeException
*/
private function fillStoreClient() {
// copy GET and POST Parameter. POST Parameter have a higher priority.
$arr = $_GET;
foreach ($_POST as $key => $value) {
$arr[$key] = $value;
}
self::setVarArray($arr, STORE_CLIENT);
// copy GET and POST and SERVER Parameter. Priority: SERVER, POST, GET
$arr = array_merge($_GET, $_POST, $_SERVER);
# SIP: if POST exist, this means 'form save'. To distinguish load and save, store both.
if (isset($_GET[CLIENT_SIP]))
self::setVar(CLIENT_GET_SIP, $_GET[CLIENT_SIP], STORE_CLIENT);
$arr[CLIENT_GET_SIP] = $_GET[CLIENT_SIP];
if (isset($_POST[CLIENT_SIP]))
self::setVar(CLIENT_POST_SIP, $_GET[CLIENT_SIP], STORE_CLIENT);
}
$arr[CLIENT_POST_SIP] = $_POST[CLIENT_SIP];
self::setVarArray($arr, STORE_CLIENT);
}
/*
*
*/
/**
* @param $key
* @param $value
* @param $store
* @throws CodeException
*/
public static function setVar($key, $value, $store) {
self::$raw[$store][$key] = $value;
// Invalidate cache to force new sanatize
self::$cache[$store][$key] = null;
}
private function fillStoreSip() {
$sessionName = self::getVar(SYSTEM_SESSIONNAME, STORE_SYSTEM);
......@@ -178,9 +190,9 @@ class Store {
}
/**
* Cycles throught all stores in $useStore.
* Cycles through all stores in $useStore.
* First match will return the found value.
* During cycling:, fill cache and sanatize a raw value.
* During cycling: fill cache with requestet value and sanatize raw value.
*
* @param string $key
* @param string $useStores f.e.: 'FSRD'
......@@ -190,8 +202,8 @@ class Store {
public static function getVar($key, $useStores = USE_STORE_DEFAULT, $sanatizeClass = '') {
// no store specifed?
if ($useStores === "") {
return false;
if ($useStores === "" || $useStores === null) {
$useStores = USE_STORE_DEFAULT;
}
while ($useStores !== false) {
......@@ -218,7 +230,7 @@ class Store {
}
// get final sanatizeClass
if ($sanatizeClass === '') {
if ($sanatizeClass === '' || $sanatizeClass === null) {
$sanatizeClass = isset(self::$defaultSanatizeClass[$key]) ? self::$defaultSanatizeClass[$key] : SANATIZE_DEFAULT;
}
......@@ -256,8 +268,8 @@ class Store {
* @param $formName
* @throws CodeException
*/
public static function createFakeSipAfterFormLoad($formName) {
$recordId = self::getVar(CLIENT_RECORD_ID, STORE_T3_BODYTEXT . STORE_CLIENT);
public static function createSipAfterFormLoad($formName) {
$recordId = self::getVar(CLIENT_RECORD_ID, STORE_TYPO3 . STORE_CLIENT);
if ($recordId === false) {
$recordId = 0;
}
......@@ -281,6 +293,20 @@ class Store {
public static function getSip() {
return self::$sip;
}
/**
* @param $key
* @param $value
* @param $store
* @throws CodeException
*/
public static function setVar($key, $value, $store) {
self::$raw[$store][$key] = $value;
// Invalidate cache to force new sanatize
self::$cache[$store][$key] = null;
}
}
......
......@@ -36,7 +36,7 @@ class StoreTest extends \PHPUnit_Framework_TestCase {
$_GET['key04'] = '4567';
$_POST['key04'] = '5678';
$this->store = Store::getInstance("\n; some comment\n" . T3_BODYTEXT_FORM . "=testformnameDoNotChange\n" . T3_BODYTEXT_DEBUG_SAVE . "=6\n" . T3_BODYTEXT_DEBUG_LOAD . "=7\n", true);
$this->store = Store::getInstance("\n; some comment\n" . TYPO3_FORM . "=testformnameDoNotChange\n" . TYPO3_DEBUG_SAVE . "=6\n" . TYPO3_DEBUG_LOAD . "=7\n", true);
}
......@@ -51,16 +51,16 @@ class StoreTest extends \PHPUnit_Framework_TestCase {
public function testGetVarT3Bodytext() {
// T3 Bodytext
$this->store->setVar(T3_BODYTEXT_FORM, "testformnameDoNotChange", STORE_T3_BODYTEXT);
$this->assertEquals('testformnameDoNotChange', $this->store->getVar(T3_BODYTEXT_FORM, STORE_T3_BODYTEXT), "System: " . T3_BODYTEXT_FORM);
$this->store->setVar(TYPO3_FORM, "testformnameDoNotChange", STORE_TYPO3);
$this->assertEquals('testformnameDoNotChange', $this->store->getVar(TYPO3_FORM, STORE_TYPO3), "System: " . TYPO3_FORM);
// T3 Bodytext
$this->store->setVar(T3_BODYTEXT_DEBUG_SAVE, "6", STORE_T3_BODYTEXT);
$this->assertEquals('6', $this->store->getVar(T3_BODYTEXT_DEBUG_SAVE, STORE_T3_BODYTEXT), "System: " . T3_BODYTEXT_DEBUG_SAVE);
$this->store->setVar(TYPO3_DEBUG_SAVE, "6", STORE_TYPO3);
$this->assertEquals('6', $this->store->getVar(TYPO3_DEBUG_SAVE, STORE_TYPO3), "System: " . TYPO3_DEBUG_SAVE);
// T3 Bodytext
$this->store->setVar(T3_BODYTEXT_DEBUG_LOAD, "7", STORE_T3_BODYTEXT);
$this->assertEquals('7', $this->store->getVar(T3_BODYTEXT_DEBUG_LOAD, STORE_T3_BODYTEXT), "System: " . T3_BODYTEXT_DEBUG_LOAD);
$this->store->setVar(TYPO3_DEBUG_LOAD, "7", STORE_TYPO3);
$this->assertEquals('7', $this->store->getVar(TYPO3_DEBUG_LOAD, STORE_TYPO3), "System: " . TYPO3_DEBUG_LOAD);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment