예제 #1
0
 /**
  * Send HTTP response
  *
  * @param KDispatcherResponseInterface $response
  * @return boolean
  */
 public function send(KDispatcherResponseInterface $response)
 {
     $request = $response->getRequest();
     if (!$response->isDownloadable() && $request->getFormat() == 'html') {
         //Render the page
         $this->getObject('com:koowa.controller.page', array('response' => $response))->layout($request->query->get('tmpl', 'cmd') == 'koowa' ? 'koowa' : 'joomla')->render();
         //Pass back to Joomla
         if ($request->isGet() && $request->query->get('tmpl', 'cmd') != 'koowa') {
             //Mimetype
             JFactory::getDocument()->setMimeEncoding($response->getContentType());
             //Remove Content-Type header to prevent duplicate header conflict (see #172)
             $response->headers->remove('Content-Type');
             //Headers
             $headers = explode("\r\n", trim((string) $response->headers));
             foreach ($headers as $header) {
                 $parts = explode(':', $header, 2);
                 if (count($parts) !== 2) {
                     // Empty values are not allowed per RFC2616 Sec 4.2
                     continue;
                 }
                 // JResponse doesn't play well with cookie headers for some reason
                 if ($parts[0] === 'Set-Cookie') {
                     continue;
                 }
                 JResponse::setHeader($parts[0], $parts[1]);
             }
             //Cookies
             foreach ($response->headers->getCookies() as $cookie) {
                 setcookie($cookie->name, $cookie->value, $cookie->expire, $cookie->path, $cookie->domain, $cookie->isSecure(), $cookie->isHttpOnly());
             }
             //Set messages for any request method
             $messages = $response->getMessages();
             foreach ($messages as $type => $group) {
                 if ($type === 'success') {
                     $type = 'message';
                 }
                 foreach ($group as $message) {
                     JFactory::getApplication()->enqueueMessage($message, $type);
                 }
             }
             //Content
             echo $response->getContent();
             return true;
         }
     }
     return parent::send($response);
 }
예제 #2
0
 /**
  * Send HTTP response
  *
  * If the format is json, add the padding by inspect the request query for a 'callback' parameter or by using
  * the default padding if set.
  *
  * Don't stop the transport handler chain to allow other transports handlers to continue processing the
  * response.
  *
  * @link http://tools.ietf.org/html/rfc2616
  *
  * @param KDispatcherResponseInterface $response
  * @return boolean
  */
 public function send(KDispatcherResponseInterface $response)
 {
     $request = $response->getRequest();
     //Force to use the json transport if format is json
     if ($request->getFormat() == 'json') {
         //If not padding is set inspect the request query.
         if (empty($this->_padding)) {
             if ($request->query->has('callback')) {
                 $this->setCallback($request->query->get('callback', 'cmd'));
             }
         }
         if (!empty($this->_padding)) {
             $response->setContent(sprintf('%s(%s);', $this->_padding, $response->getContent()));
         }
     }
 }