Ejemplo n.º 1
0
    public function testRendererSreturn()
    {
        $in = '<p>string
</p>';
        $out = '&lt;p&gt;string
&lt;/p&gt;';
        $mod = template\Renderer::sreturn($in);
        $this->assertEquals($out, (string) $mod);
        $mod = Modifier::safe($mod);
        $this->assertEquals($out, (string) template\Renderer::sreturn($mod));
    }
Ejemplo n.º 2
0
 /**
  * Renders the HTML of the input.
  *
  * @param string Name of the field.
  * @param mixed Value for the field, can be a non valid value.
  * @param array Extra attributes to add to the input form (array())
  * @return string The HTML string of the input.
  */
 public function render($name, $value, $extra_attrs = array())
 {
     if ($value === null) {
         $value = '';
     }
     $final_attrs = $this->buildAttrs(array('name' => $name), $extra_attrs);
     return new SafeString(sprintf('<textarea%s>%s</textarea>', widget_attrs($final_attrs), \photon\template\Renderer::sreturn($value)), true);
 }
Ejemplo n.º 3
0
 function end($param1 = 'end foo')
 {
     $to_show = sprintf('Param1: %s', $param1);
     \photon\template\Renderer::secho($to_show);
 }
Ejemplo n.º 4
0
 /**
  * Render a template file and an array as a reponse.
  *
  * @param $tmpl Template file name
  * @param $context Associative array for the context
  * @return Rendered template as a string
  */
 public static function RenderToString($tmpl, $context)
 {
     $renderer = new ptemplate\Renderer($tmpl, Conf::f('template_folders'));
     $context = new ptemplate\Context($context);
     return $renderer->render($context);
 }
Ejemplo n.º 5
0
 /**
  * New line to <br /> returning a safe string.
  *
  * @param $mixed Input
  * @return string Safe to display in HTML.
  */
 public static function nl2br($mixed)
 {
     if (!is_object($mixed) || 'photon\\template\\SafeString' !== get_class($mixed)) {
         return Renderer::markSafe(\nl2br(htmlspecialchars($mixed)));
     } else {
         return Renderer::markSafe(\nl2br((string) $mixed));
     }
 }
Ejemplo n.º 6
0
 public function testEventTagNotConnected()
 {
     $request = (object) array();
     $renderer = new template\Renderer('data-template-event-tag.html', array(__DIR__));
     $ctx = new template\ContextRequest($request, array());
     $out = $renderer->render($ctx);
     $this->assertequals("\n", $out);
 }
Ejemplo n.º 7
0
 function __construct($exception, $mimetype = null)
 {
     $this->exception = $exception;
     $content = '';
     $admins = Conf::f('admins', array());
     if (count($admins) > 0) {
         // Get a nice stack trace and send it by emails.
         $stack = pretty_server_error($exception);
         $subject = $exception->getMessage();
         $subject = substr(strip_tags(nl2br($subject)), 0, 50) . '...';
         foreach ($admins as $admin) {
             $email = new Mail($admin[1], $admin[1], $subject);
             $email->addTextMessage($stack);
             $email->sendMail();
         }
     }
     try {
         $context = new template\Context(array('message' => $exception->getMessage()));
         $renderer = new template\Renderer('500.html');
         $content = $renderer->render($context);
         $mimetype = null;
     } catch (\Exception $e) {
         $mimetype = 'text/plain';
         $content = 'The server encountered an unexpected condition which prevented it from fulfilling your request.' . "\n\n" . 'An email has been sent to the administrators, we will correct this error as soon as possible. Thank you for your comprehension.' . "\n\n" . '500 - Internal Server Error';
     }
     parent::__construct($content, $mimetype);
     $this->status_code = 500;
 }