eval = $eval; // specified once during initialisation. $this->tt_content_uid = $tt_content_uid; } /** * Matches on the variables {{10.20.name}} and substitutes them with the values * * @param string $text * * @return mixed * @throws \CodeException * @throws \DbException * @throws \UserFormException * @throws \UserReportException */ public function doVariables($text) { if ($text == '') { return ''; } // $str = preg_replace_callback("/{{(([a-zA-Z0-9.:_])*)}}/", array($this, 'replaceVariables'), $text); // Process all {{x[.x].name}} $str = preg_replace_callback('/{{\s*(([0-9]+.)+[a-zA-Z0-9_.]+)\s*}}/', array($this, 'replaceVariables'), $text); // Try the Stores $str = $this->eval->parse($str); return $str; } /** * Callbackfunction called by variableSQL() * Replaces the variablenames with the value from the resultArray * * @param $matches * * @return string The content that is displayed on the website * @internal param string $content : The PlugIn content * @internal param array $conf : The PlugIn configuration */ public function replaceVariables($matches) { // $matches[0]: {{variablename: 10.20.}} // $matches[1]: variablename: 10.20. $data = $matches[0]; // index of last '.' $pos = strrpos($matches[1], "."); if ($pos !== false) { $fullLevel = substr($matches[1], 0, $pos + 1); $varName = substr($matches[1], $pos + 1, strlen($matches[1])); if (isset($this->resultArray[$fullLevel][$varName])) { $data = $this->resultArray[$fullLevel][$varName]; } } // If not replaced, try the Stores // if ($data === $matches[0]) { // $dataTmp = $this->eval->parse($data); // if ($dataTmp !== false) // $data = $dataTmp; // } return $data; } /** * Collect Global Variables * * @param void * * @return array with global variables which might be replaced */ public function collectGlobalVariables() { $arr = array(); if (isset($_SERVER["REMOTE_ADDR"])) { //TODO: Variablen sollten vom STORE_TYPO3 genommen werden $arr["REMOTE_ADDR"] = $_SERVER["REMOTE_ADDR"] ?? ''; $arr["HTTP_HOST"] = $_SERVER["HTTP_HOST"] ?? ''; $arr["REQUEST_URI"] = $_SERVER["REQUEST_URI"] ?? ''; $protocol = 'http'; if (isset($_SERVER['HTTPS'])) { if ($_SERVER["HTTPS"] != "off") $protocol = 'https'; } $arr["url"] = $protocol . "://" . $_SERVER["HTTP_HOST"]; if ($_SERVER["SERVER_PORT"] != 80) $arr["url"] .= ":" . $_SERVER["SERVER_PORT"]; $arr["url"] .= $arr["REQUEST_URI"]; } if (isset($GLOBALS["TSFE"]->fe_user)) { $arr["fe_user_uid"] = $GLOBALS["TSFE"]->fe_user->user["uid"] ?? '-'; $arr["fe_user"] = $GLOBALS["TSFE"]->fe_user->user["username"] ?? '-'; } else { $arr["fe_user_uid"] = '-'; $arr["fe_user"] = '-'; } $arr["be_user_uid"] = (isset($GLOBALS['BE_USER'])) ? $GLOBALS['BE_USER']->user["uid"] : '-'; $arr["ttcontent_uid"] = $this->tt_content_uid; if (isset($GLOBALS["TSFE"])) { $arr["page_id"] = $GLOBALS["TSFE"]->id; $arr["page_type"] = $GLOBALS["TSFE"]->type; $arr["page_language_uid"] = $GLOBALS["TSFE"]->sys_language_uid; } return ($arr); } /** * @param $arr * @param $return * @param string $keyPath */ public function linearizeArray($arr, &$return, $keyPath = "") { if (is_array($arr)) { foreach ($arr as $key => $value) { $this->linearizeArray($value, $return, $keyPath . "_" . $key); } } else { $return[ltrim($keyPath, "_")] = $arr; } } }