Exemplo n.º 1
0
 protected function _actionRender(Library\CommandContext $context)
 {
     if ($context->request->getFormat() == 'html') {
         return Library\ControllerView::_actionRender($context);
     }
     return parent::_actionRender($context);
 }
Exemplo n.º 2
0
 public function _actionRender(Library\CommandContext $context)
 {
     $data = array('url' => $context->request->query->get('url', 'url'), 'content-length' => false);
     if (!function_exists('curl_init')) {
         throw new \RuntimeException('Curl library does not exist');
     }
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $data['url']);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
     curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
     curl_setopt($ch, CURLOPT_TIMEOUT, 20);
     //CURLOPT_NOBODY changes the request from GET to HEAD
     curl_setopt($ch, CURLOPT_NOBODY, true);
     $response = curl_exec($ch);
     if (curl_errno($ch)) {
         throw new \RuntimeException('Curl Error: ' . curl_error($ch));
     }
     $info = curl_getinfo($ch);
     if (isset($info['http_code']) && $info['http_code'] != 200) {
         throw new \RuntimeException($data['url'] . ' Not Found', $info['http_code']);
     }
     if (isset($info['download_content_length'])) {
         $data['content-length'] = $info['download_content_length'];
     }
     if (isset($info['content_type'])) {
         $data['content-type'] = $info['content_type'];
     }
     curl_close($ch);
     $this->getView()->setContent($data);
     return parent::_actionRender($context);
 }
Exemplo n.º 3
0
 protected function _initialize(Library\ObjectConfig $config)
 {
     parent::_initialize($config);
     //Don't dispatch event or allow callbacks
     $config->dispatch_events = false;
     $config->enable_callbacks = false;
 }
Exemplo n.º 4
0
 protected function _actionRender(Library\CommandContext $context)
 {
     $content = parent::_actionRender($context);
     //Make images paths absolute
     $base = $this->getObject('request')->getBaseUrl();
     $site = $this->getObject('application')->getSite();
     $path = $base->getPath() . '/files/' . $site . '/images/';
     $content = str_replace($base . '/images/', $path, $content);
     $content = str_replace(array('../images', './images'), '"' . $path, $content);
     $context->response->setContent($content);
     return $content;
 }
Exemplo n.º 5
0
 /**
  * Render an exception
  *
  * @throws \InvalidArgumentException If the action parameter is not an instance of Library\Exception
  * @param Library\CommandContext $context	A command context object
  */
 protected function _actionRender(Library\CommandContext $context)
 {
     //Check an exception was passed
     if (!isset($context->param) && !$context->param instanceof Library\Exception) {
         throw new \InvalidArgumentException("Action parameter 'exception' [Library\\Exception] is required");
     }
     //Set the exception data in the view
     $exception = $context->param;
     //If the error code does not correspond to a status message, use 500
     $code = $exception->getCode();
     if (!isset(Library\HttpResponse::$status_messages[$code])) {
         $code = '500';
     }
     $message = Library\HttpResponse::$status_messages[$code];
     $traces = $exception->getTrace();
     //Find the real file path
     $aliases = $this->getObject('manager')->getClassLoader()->getAliases();
     //Cleanup the traces information
     foreach ($traces as $key => $trace) {
         if (isset($trace['file'])) {
             if ($alias = array_search($trace['file'], $aliases)) {
                 $trace['file'] = $alias;
             }
             $traces[$key]['file'] = str_replace(JPATH_ROOT, '', $trace['file']);
         }
     }
     //Traverse up the trace stack to find the actual function that was not found
     if ($traces[0]['function'] == '__call') {
         foreach ($traces as $trace) {
             if ($trace['function'] != '__call') {
                 $message = "Call to undefined method : " . $trace['class'] . $trace['type'] . $trace['function'];
                 $file = isset($trace['file']) ? $trace['file'] : '';
                 $line = isset($trace['line']) ? $trace['line'] : '';
                 $function = $trace['function'];
                 $class = $trace['class'];
                 $args = isset($trace['args']) ? $trace['args'] : '';
                 $info = isset($trace['info']) ? $trace['info'] : '';
                 break;
             }
         }
     } else {
         $message = $exception->getMessage();
         $file = isset($traces[0]['file']) ? $traces[0]['file'] : $exception->getFile();
         $line = $exception->getLine();
         $function = $traces[0]['function'];
         $class = isset($traces[0]['class']) ? $traces[0]['class'] : '';
         $args = isset($traces[0]['args']) ? $traces[0]['args'] : '';
         $info = isset($traces[0]['info']) ? $traces[0]['info'] : '';
     }
     //Find and use file alias if it exists
     if ($alias = array_search($file, $aliases)) {
         $file = str_replace(JPATH_ROOT, '', $alias);
     }
     //Create the exception message
     if (ini_get('display_errors')) {
         $message = "Exception '" . get_class($exception) . "' with message '" . $message . "' in " . $file . ":" . $line;
     } else {
         $traces = array();
     }
     $this->getView()->code = $code;
     $this->getView()->message = $message;
     $this->getView()->file = $file;
     $this->getView()->line = $line;
     $this->getView()->function = $function;
     $this->getView()->class = $class;
     $this->getView()->args = $args;
     $this->getView()->info = $info;
     $this->getView()->trace = $traces;
     //Make sure the buffers are cleared
     while (@ob_get_clean()) {
     }
     //Render the exception
     $result = parent::_actionRender($context);
     //Set the response status
     $context->response->setStatus($code, $message);
     return $result;
 }
Exemplo n.º 6
0
 protected function _actionRender(Library\CommandContext $context)
 {
     return Library\ControllerView::_actionRender($context);
 }
Exemplo n.º 7
0
 protected function _initialize(Library\ObjectConfig $config)
 {
     $config->append(array('behaviors' => 'captchable'));
     parent::_initialize($config);
 }