Example: '); ?>
See also: http://www.php.net/manual/en/class.streamwrapper.php
Author: gharlan
 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;
 }
Beispiel #2
0
 /**
  * Prepares a new stream.
  *
  * @param string $path    Virtual path which should describe the content (e.g. "template/1"), only relevant for error messages
  * @param string $content Content which will be included
  *
  * @throws InvalidArgumentException
  *
  * @return string Full path with protocol (e.g. "rex://template/1")
  */
 public static function factory($path, $content)
 {
     if (!is_string($path) || empty($path)) {
         throw new InvalidArgumentException('Expecting $path to be a string and not empty!');
     }
     if (!is_string($content)) {
         throw new InvalidArgumentException('Expecting $content to be a string!');
     }
     if (null === self::$useRealFiles) {
         self::$useRealFiles = extension_loaded('suhosin') && !preg_match('/(?:^|,)rex(?::|,|$)/', ini_get('suhosin.executor.include.whitelist'));
     }
     if (self::$useRealFiles) {
         $hash = substr(sha1($content), 0, 7);
         $path = rex_path::coreCache('stream/' . $path . '/' . $hash);
         if (!file_exists($path)) {
             rex_file::put($path, $content);
         }
         return $path;
     }
     if (!self::$registered) {
         stream_wrapper_register('rex', __CLASS__);
         self::$registered = true;
     }
     $path = 'rex://' . $path;
     self::$nextContent[$path] = $content;
     return $path;
 }
Beispiel #3
0
 /**
  * Prepares a new stream.
  *
  * @param string $path    Virtual path which should describe the content (e.g. "template/1"), only relevant for error messages
  * @param string $content Content which will be included
  *
  * @throws InvalidArgumentException
  *
  * @return string Full path with protocol (e.g. "rex:///template/1")
  */
 public static function factory($path, $content)
 {
     if (!is_string($path) || empty($path)) {
         throw new InvalidArgumentException('Expecting $path to be a string and not empty!');
     }
     if (!is_string($content)) {
         throw new InvalidArgumentException('Expecting $content to be a string!');
     }
     if (null === self::$useRealFiles) {
         self::$useRealFiles = extension_loaded('suhosin') && !preg_match('/(?:^|,)rex(?::|,|$)/', ini_get('suhosin.executor.include.whitelist'));
     }
     if (self::$useRealFiles) {
         $hash = substr(sha1($content), 0, 7);
         $path = rex_path::coreCache('stream/' . $path . '/' . $hash);
         if (!file_exists($path)) {
             rex_file::put($path, $content);
         }
         return $path;
     }
     if (!self::$registered) {
         stream_wrapper_register('rex', __CLASS__);
         self::$registered = true;
     }
     // 3 slashes needed to sidestep some server url include protections
     // example: https://www.strato.de/faq/article/622/Warum-erhalte-ich-über-PHP-die-Fehlermeldung-%22Warning:-main()-…:-include(….).html
     $path = 'rex:///' . $path;
     self::$nextContent[$path] = $content;
     return $path;
 }
Beispiel #4
0
 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);
 }
Beispiel #5
0
 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);
 }
Beispiel #6
0
 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);
 }
Beispiel #7
0
 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);
     }
 }
Beispiel #8
0
 /**
  * Prepares a new stream.
  *
  * @param string $path    Virtual path which should describe the content (e.g. "template/1"), only relevant for error messages
  * @param string $content Content which will be included
  *
  * @throws InvalidArgumentException
  *
  * @return string Full path with protocol (e.g. "rex://template/1")
  */
 public static function factory($path, $content)
 {
     if (!is_string($path) || empty($path)) {
         throw new InvalidArgumentException('Expecting $path to be a string and not empty!');
     }
     if (!is_string($content)) {
         throw new InvalidArgumentException('Expecting $content to be a string!');
     }
     if (!self::$registered) {
         stream_wrapper_register('rex', __CLASS__);
         self::$registered = true;
     }
     $path = 'rex://' . $path;
     self::$nextContent[$path] = $content;
     return $path;
 }
Beispiel #9
0
 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);
         }
     }
 }
Beispiel #10
0
 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;
 }
Beispiel #11
0
 protected function getParseOutput($content)
 {
     return rex_file::getOutput(rex_stream::factory('rex-var-test', rex_var::parse($content)));
 }