Пример #1
0
 public function send($code = 200, array $headers = null, $body = null)
 {
     $this->response->setCode($code);
     if (null !== $body) {
         $this->response->setBody($body);
     } else {
         if (null !== $this->view) {
             $this->response->setBody($this->view->render());
         }
     }
     $this->response->send($code, $headers);
 }
Пример #2
0
 /**
  * Send response
  *
  * @param  int    $code
  * @param  array  $headers
  * @param  string $body
  * @return void
  */
 public function send($code = 200, array $headers = null, $body = null)
 {
     $this->response->setCode($code);
     $this->application->trigger('app.send.pre', ['controller' => $this]);
     if (null !== $body) {
         $this->response->setBody($body);
     } else {
         if (null !== $this->view) {
             $this->response->setBody($this->view->render());
         }
     }
     $this->application->trigger('app.send.post', ['controller' => $this]);
     $this->response->send($code, $headers);
 }
Пример #3
0
 public function error()
 {
     $this->response->setBody(json_encode(['error' => 'Resource not found'], JSON_PRETTY_PRINT));
     $this->response->send(404);
 }
 /**
  * Method to get model types
  *
  * @return void
  */
 public function json()
 {
     $body = '';
     if (null !== $this->request->getPath(1)) {
         // Get the selected field history value
         if ($this->request->getPath(1) == 'history' && null !== $this->request->getPath(2) && is_numeric($this->request->getPath(2)) && null !== $this->request->getPath(3) && is_numeric($this->request->getPath(3)) && null !== $this->request->getPath(4) && is_numeric($this->request->getPath(4))) {
             $modelId = $this->request->getPath(2);
             $fieldId = $this->request->getPath(3);
             $time = $this->request->getPath(4);
             $value = '';
             $encOptions = $this->project->module('Phire')->encryptionOptions->asArray();
             $fv = Table\FieldValues::findById(array($fieldId, $modelId));
             if (isset($fv->field_id) && null !== $fv->history) {
                 $history = json_decode($fv->history, true);
                 if (isset($history[$time])) {
                     $value = $history[$time];
                     $f = Table\Fields::findById($fieldId);
                     $value = Model\FieldValue::decrypt($value, $f->encryption, $encOptions);
                 }
             }
             $body = array('fieldId' => $fieldId, 'modelId' => $modelId, 'value' => html_entity_decode($value, ENT_QUOTES, 'UTF-8'));
             // Get the field history timestamps
         } else {
             if ($this->request->getPath(1) == 'history' && null !== $this->request->getPath(2) && is_numeric($this->request->getPath(2)) && null !== $this->request->getPath(3) && is_numeric($this->request->getPath(3))) {
                 $modelId = $this->request->getPath(2);
                 $fieldId = $this->request->getPath(3);
                 $fv = Table\FieldValues::findById(array($fieldId, $modelId));
                 if (isset($fv->field_id) && null !== $fv->history) {
                     $body = array_keys(json_decode($fv->history, true));
                     rsort($body);
                 }
                 // Get the model types
             } else {
                 $clsAry = $this->request->getPath();
                 unset($clsAry[0]);
                 $cls = implode('_', $clsAry);
                 $types = \Phire\Project::getModelTypes($cls);
                 $body = array('types' => $types);
             }
         }
         // Build the response and send it
         $response = new Response();
         $response->setHeader('Content-Type', 'application/json; charset=utf-8')->setBody(json_encode($body));
         $response->send();
     }
 }
 /**
  * Method to get date format
  *
  * @return void
  */
 public function json()
 {
     if (null !== $this->request->getPath(1)) {
         $format = str_replace('_', '/', urldecode($this->request->getPath(1)));
         // Build the response and send it
         $response = new Response();
         $response->setHeader('Content-Type', 'application/json')->setBody(json_encode(array('format' => date($format))));
         $response->send();
     }
 }
 /**
  * Method to get other resource permissions via JS
  *
  * @return void
  */
 public function json()
 {
     if (null !== $this->request->getPath(1)) {
         $resources = \Phire\Model\UserRole::getResources($this->project->module('Phire'));
         $class = str_replace('_', '\\', urldecode($this->request->getPath(1)));
         $types = array();
         $actions = array();
         foreach ($resources as $key => $resource) {
             if ($key == $class) {
                 $types = $resource['types'];
                 $actions = $resource['actions'];
             }
         }
         $body = array('types' => $types, 'actions' => $actions);
         // Build the response and send it
         $response = new Response();
         $response->setHeader('Content-Type', 'application/json')->setBody(json_encode($body));
         $response->send();
     }
 }
Пример #7
0
 /**
  * Error handler
  *
  * @param  \Exception $exception
  * @return void
  */
 public function error(\Exception $exception)
 {
     if ($exception instanceof \Phire\Exception && $exception->isInstallError()) {
         Response::redirect(BASE_PATH . APP_URI . '/install');
         exit;
     }
     // Load assets, if they haven't been loaded already
     $this->loadAssets($_SERVER['DOCUMENT_ROOT'] . APP_PATH . '/data/themes/default', 'default');
     $this->loadAssets(__DIR__ . '/../data/assets', 'phire');
     sort($this->assets['js']);
     sort($this->assets['css']['link']);
     sort($this->assets['css']['import']);
     // Load any custom/override assets
     $this->loadAssets(CONTENT_ABS_PATH . '/phire/assets', 'phire-custom', true);
     $view = new View(__DIR__ . '/../view/phire/exception.phtml');
     $view->title = 'Application Error';
     $view->systemTitle = 'Phire CMS';
     $view->assets = $this->assets;
     $view->phireUri = BASE_PATH . APP_URI;
     $view->basePath = BASE_PATH;
     $view->base_path = BASE_PATH;
     $view->contentPath = BASE_PATH . CONTENT_PATH;
     $view->content_path = BASE_PATH . CONTENT_PATH;
     $view->message = htmlentities(strip_tags($exception->getMessage()), ENT_QUOTES, 'UTF-8');
     $response = new Response();
     $response->setBody((string) $view);
     $response->send();
 }
Пример #8
0
 /**
  * Custom error handler method
  *
  * @param  \Exception $exception
  * @return void
  */
 public function error(\Exception $exception)
 {
     $view = new View(__DIR__ . '/../view/exception.phtml');
     $view->title = 'Application Error';
     $view->message = htmlentities(strip_tags($exception->getMessage()), ENT_QUOTES, 'UTF-8');
     if (file_exists(__DIR__ . '/../config/application.php')) {
         $config = (include __DIR__ . '/../config/application.php');
         $view->application_title = $config['application_title'];
     } else {
         $view->application_title = '';
     }
     $response = new Response();
     $response->setBody((string) $view);
     $response->send(500);
 }
Пример #9
0
 /**
  * Method to send a JSON response
  *
  * @param  mixed $values
  * @param  int   $code
  * @param  array $headers
  * @return void
  */
 public function sendJson($values, $code = 200, array $headers = null)
 {
     // Build the response and send it
     $response = new Response();
     $this->response->setCode($code);
     if (null !== $headers) {
         foreach ($headers as $name => $value) {
             $this->response->setHeader($name, $value);
         }
     }
     // Force JSON content-type header
     $response->setHeader('Content-Type', 'application/json')->setBody(json_encode($values));
     $response->send();
 }