Beispiel #1
0
 /**
  * @param mixed Values, will be encoded using json_encode
  */
 function __construct($data, $mimetype = null)
 {
     if (null == $mimetype) {
         $mimetype = Pluf::f('mimetype_json', 'application/json') . '; charset=utf-8';
     }
     parent::__construct(json_encode($data), $mimetype);
 }
Beispiel #2
0
 function __construct($exception, $mimetype = null)
 {
     $content = '';
     $admins = Pluf::f('admins', array());
     if (count($admins) > 0) {
         // Get a nice stack trace and send it by emails.
         $stack = Pluf_HTTP_Response_ServerError_Pretty($exception);
         $subject = $exception->getMessage();
         $subject = substr(strip_tags(nl2br($subject)), 0, 50) . '...';
         foreach ($admins as $admin) {
             $email = new Pluf_Mail($admin[1], $admin[1], $subject);
             $email->addTextMessage($stack);
             $email->sendMail();
         }
     }
     try {
         $context = new Pluf_Template_Context(array('message' => $exception->getMessage()));
         $tmpl = new Pluf_Template('500.html');
         $content = $tmpl->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;
 }
Beispiel #3
0
 /**
  * Redirect response to a given URL.
  *
  * @param string URL
  * @paran int Redirect code (302) or 301 for permanent
  */
 function __construct($url, $code = 302)
 {
     $content = sprintf(__('<a href="%s">Please, click here to be redirected</a>.'), $url);
     parent::__construct($content);
     $this->headers['Location'] = $url;
     $this->status_code = $code;
 }
Beispiel #4
0
 function __construct($request)
 {
     $content = '';
     try {
         $context = new Pluf_Template_Context(array('query' => $request->query));
         $tmpl = new Pluf_Template('403.html');
         $content = $tmpl->render($context);
         $mimetype = null;
     } catch (Exception $e) {
         $mimetype = 'text/plain';
         $content = 'You are not authorized to view this page. You do not have permission' . "\n" . 'to view the requested directory or page using the credentials supplied.' . "\n\n" . '403 - Forbidden';
     }
     parent::__construct($content, $mimetype);
     $this->status_code = 403;
 }
Beispiel #5
0
 function __construct($request)
 {
     $content = '';
     try {
         $context = new Pluf_Template_Context(array('query' => $request->query));
         $tmpl = new Pluf_Template('404.html');
         $content = $tmpl->render($context);
         $mimetype = null;
     } catch (Exception $e) {
         $mimetype = 'text/plain';
         $content = sprintf('The requested URL %s was not found on this server.' . "\n" . 'Please check the URL and try again.' . "\n\n" . '404 - Not Found', Pluf_esc($request->query));
     }
     parent::__construct($content, $mimetype);
     $this->status_code = 404;
 }
Beispiel #6
0
 /**
  * The $request object is used to know what the post login
  * redirect url should be.
  *
  * If the action url of the login page is not set, it will try to
  * get the url from the login view from the 'login_view'
  * configuration key.
  *
  * @param Pluf_HTTP_Request The request object of the current page.
  * @param string The full url of the login page (null)
  */
 function __construct($request, $loginurl = null)
 {
     if ($loginurl !== null) {
         $murl = new Pluf_HTTP_URL();
         $url = $murl->generate($loginurl, array('_redirect_after' => $request->uri), false);
         $encoded = $murl->generate($loginurl, array('_redirect_after' => $request->uri));
     } else {
         Pluf::loadFunction('Pluf_HTTP_URL_urlForView');
         $url = Pluf_HTTP_URL_urlForView(Pluf::f('login_view', 'login_view'), array(), array('_redirect_after' => $request->uri), false);
         $encoded = Pluf_HTTP_URL_urlForView(Pluf::f('login_view', 'login_view'), array(), array('_redirect_after' => $request->uri));
     }
     $content = sprintf(__('<a href="%s">Please, click here to be redirected</a>.'), $encoded);
     parent::__construct($content);
     $this->headers['Location'] = $url;
     $this->status_code = 302;
 }
Beispiel #7
0
 function __construct($request)
 {
     $content = '';
     try {
         $context = new Pluf_Template_Context(array('query' => $request->query));
         $tmpl = new Pluf_Template('503.html');
         $content = $tmpl->render($context);
         $mimetype = null;
     } catch (Exception $e) {
         $mimetype = 'text/plain';
         $content = sprintf('The requested URL %s is not available at the moment.' . "\n" . 'Please try again later.' . "\n\n" . '503 - Service Unavailable', Pluf_esc($request->query));
     }
     parent::__construct($content, $mimetype);
     $this->status_code = 503;
     $this->headers['Retry-After'] = 300;
     // retry after 5 minutes
 }
Beispiel #8
0
 function __construct($stdio, $revision)
 {
     parent::__construct($revision, 'application/x-zip');
     $this->stdio = $stdio;
     $this->revision = $revision;
 }
Beispiel #9
0
 function __construct($filepath, $mimetype = null, $delete_file = false)
 {
     parent::__construct($filepath, $mimetype);
     $this->delete_file = $delete_file;
 }
Beispiel #10
0
 /**
  * The command argument must be a safe string!
  *
  * @param string Command to run.
  * @param string Mimetype (null)
  */
 function __construct($command, $mimetype = null)
 {
     parent::__construct($command, $mimetype);
 }