static function replaceVars($template, $er = array()) { $r = rex_extension::registerPoint(new rex_extension_point('YFORM_EMAIL_BEFORE_REPLACEVARS', ['template' => $template, 'search_replace' => $er, 'status' => false])); $template = $r['template']; $er = $r['search_replace']; $status = $r['status']; if ($status) { return true; } $er['REX_SERVER'] = rex::getServer(); $er['REX_ERROR_EMAIL'] = rex::getErrorEmail(); $er['REX_SERVERNAME'] = rex::getServerName(); $er['REX_NOTFOUND_ARTICLE_ID'] = rex_article::getNotfoundArticleId(); $er['REX_ARTICLE_ID'] = rex_article::getCurrentId(); $template['body'] = rex_var::parse($template['body'], '', 'yform_email_template', $er); $template['body_html'] = rex_var::parse($template['body_html'], '', 'yform_email_template', $er); // rex_vars bug: sonst wird der Zeilenumbruch entfernt - wenn DATA_VAR am Ende einer Zeile if (rex_string::versionCompare(rex::getVersion(), '5.0.1', '<')) { $template['body'] = str_replace("?>\r", "?>\r\n\r", $template['body']); $template['body'] = str_replace("?>\n", "?>\n\r\n", $template['body']); $template['body_html'] = str_replace("?>\r", "?>\r\n\r", $template['body_html']); $template['body_html'] = str_replace("?>\n", "?>\n\r\n", $template['body_html']); } $template['body'] = rex_file::getOutput(rex_stream::factory('yform/email/template/' . $template['name'] . '/body', $template['body'])); $template['body_html'] = rex_file::getOutput(rex_stream::factory('yform/email/template/' . $template['name'] . '/body_html', $template['body_html'])); return $template; }
public function testStreamInclude() { $content = 'MY_TEST'; $streamUrl = rex_stream::factory('test-stream', $content); ob_start(); require $streamUrl; $result = ob_get_clean(); $this->assertEquals($result, $content); }
public static function getTemplateStream($id, rex_article_content_base $article = null) { ob_start(); $tmpl = new rex_template($id); $tmpl = $tmpl->getTemplate(); if ($article) { $tmpl = $article->replaceCommonVars($tmpl, $id); } return rex_stream::factory('template/' . $id, $tmpl); }
public function testStreamIncludeWithRealFile() { $property = new ReflectionProperty('rex_stream', 'useRealFiles'); $property->setAccessible(true); $property->setValue(true); $content = 'foo <?php echo "bar";'; $streamUrl = rex_stream::factory('test-stream/2', $content); ob_start(); require $streamUrl; $result = ob_get_clean(); $this->assertEquals('foo bar', $result); $property->setValue(null); }
public function exec($type) { if (!in_array($type, [self::PREVIEW, self::PRESAVE, self::POSTSAVE])) { throw new InvalidArgumentException('$type musst be rex_article_action::PREVIEW, ::PRESAVE or ::POSTSAVE'); } $this->messages = []; $this->save = true; $ga = rex_sql::factory(); $ga->setQuery('SELECT a.id, `' . $type . '` as code FROM ' . rex::getTable('module_action') . ' ma,' . rex::getTable('action') . ' a WHERE `' . $type . '` != "" AND ma.action_id=a.id AND module_id=? AND (a.' . $type . 'mode & ?)', [$this->moduleId, $this->mode]); foreach ($ga as $row) { $action = $row->getValue('code'); $action = str_replace($this->vars['search'], $this->vars['replace'], $action); $action = rex_var::parse($action, rex_var::ENV_BACKEND | rex_var::ENV_INPUT, 'action', $this->sql); require rex_stream::factory('action/' . $row->getValue('id') . '/' . $type, $action); } }
protected function fireCallbacks(rex_sql $sqlFields) { foreach ($sqlFields as $row) { if ($row->getValue('callback') != '') { // use a small sandbox, so the callback cannot affect our local variables $sandboxFunc = function ($field) { // TODO add var to ref the actual table (rex_article,...) $fieldName = $field->getValue('name'); $fieldType = $field->getValue('type_id'); $fieldAttributes = $field->getValue('attributes'); $fieldValue = self::getSaveValue($fieldName, $fieldType, $fieldAttributes); require rex_stream::factory('metainfo/' . $field->getValue('id') . '/callback', $field->getValue('callback')); }; // pass a clone to the custom handler, so the callback will not change our var $sandboxFunc(clone $row); } } }
protected function getStreamOutput($path, $content) { if (!$this->eval) { $key = 'EOD_' . strtoupper(sha1(time())); return "require rex_stream::factory('{$path}', \n<<<'{$key}'\n{$content}\n{$key}\n);\n"; } ob_start(); ob_implicit_flush(0); require rex_stream::factory($path, $content); $CONTENT = ob_get_contents(); ob_end_clean(); return $CONTENT; }
protected function getParseOutput($content) { return rex_file::getOutput(rex_stream::factory('rex-var-test', rex_var::parse($content))); }