Пример #1
0
 public function save($file)
 {
     if (!isset($_POST['csrf'])) {
         http_response_code(400);
         return ['csrf' => $this->generateCsrf(), 'success' => false, 'message' => 'CSRF token missing.'];
     }
     if (!$this->validateCsrf($_POST['csrf'])) {
         http_response_code(400);
         return ['csrf' => $this->generateCsrf(), 'success' => false, 'message' => 'CSRF invalid.'];
     }
     if (!parent::saveJson($file)) {
         http_response_code(500);
         return ['csrf' => $this->generateCsrf(), 'success' => false, 'message' => 'Failed to save content.'];
     }
     return ['csrf' => $this->generateCsrf(), 'success' => true];
 }
Пример #2
0
 public function save()
 {
     if (!isset($_POST['raptor-content'])) {
         throw new ClientException('Content parameter missing.');
     }
     $newContent = json_decode($_POST['raptor-content']);
     if ($newContent === false) {
         throw new ClientException('Failed to decode content.');
     }
     $content = $this->getContent();
     foreach ($newContent as $id => $html) {
         if (!isset($content[$id]) || $content[$id] != $html) {
             $this->addRevision($id, $html);
         }
     }
     $this->saveRevisions();
     return parent::save();
 }