Exemple #1
0
 public static function update($model, $id, $update_lit = '')
 {
     Session::permit_admin();
     $success = parent::update(Record::allow($model, ['title', 'name', 'type']), $id, $update_lit);
     if (isset($model['content'])) {
         $success = DocContent::create(['doc_id' => $id, 'content' => $model['content']]);
     }
     if (isset($model['routes'])) {
         DocRoute::destroy_all($id);
         if ($model['routes']) {
             $routes = [];
             foreach (explode(',', $model['routes']) as $route_def) {
                 $parts = explode('=>', $route_def);
                 $route = trim($parts[0]);
                 if (strlen($route) == 0 || $route[0] != '/') {
                     $route = '/' . $route;
                 }
                 $handler = count($parts) > 1 ? trim($parts[1]) : null;
                 $routes[] = ['doc_id' => $id, 'route' => $route, 'handler' => $handler ? $handler : null];
             }
             DocRoute::create_all($routes);
         }
     }
     return $success;
 }
 public function saveDocumentEdits($documentId)
 {
     if (!Auth::check()) {
         return Redirect::to('documents')->with('error', 'You must be logged in');
     }
     $content = Input::get('content');
     $contentId = Input::get('content_id');
     if (empty($content)) {
         return Redirect::to('documents')->with('error', "You must provide content to save");
     }
     if (!empty($contentId)) {
         $docContent = DocContent::find($contentId);
     } else {
         $docContent = new DocContent();
     }
     if (!$docContent instanceof DocContent) {
         return Redirect::to('documents')->with('error', 'Could not locate document to save');
     }
     $document = Doc::find($documentId);
     if (!$document instanceof Doc) {
         return Redirect::to('documents')->with('error', "Could not locate the document");
     }
     if (!$document->canUserEdit(Auth::user())) {
         return Redirect::to('documents')->with('error', 'You are not authorized to save that document.');
     }
     $docContent->doc_id = $documentId;
     $docContent->content = $content;
     try {
         DB::transaction(function () use($docContent, $content, $documentId, $document) {
             $docContent->save();
         });
     } catch (\Exception $e) {
         return Redirect::to('documents')->with('error', "There was an error saving the document: {$e->getMessage()}");
     }
     //Fire document edited event for admin notifications
     $doc = Doc::find($docContent->doc_id);
     Event::fire(MadisonEvent::DOC_EDITED, $doc);
     try {
         $document->indexContent($docContent);
     } catch (\Exception $e) {
         return Redirect::to('documents')->with('error', "Document saved, but there was an error with Elasticsearch: {$e->getMessage()}");
     }
     return Redirect::to('documents')->with('success_message', 'Document Saved Successfully');
 }
 public function postContent($id)
 {
     $doc = Doc::find($id);
     $doc_content = DocContent::firstOrCreate(array('doc_id' => $doc->id));
     $doc_content->content = Input::get('content');
     $doc_content->save();
     $doc->content(array($doc_content));
     $doc->save();
     Event::fire(MadisonEvent::DOC_EDITED, $doc);
     $response['messages'][0] = array('text' => 'Document content saved', 'severity' => 'info');
     return Response::json($response);
 }
Exemple #4
0
 /**
  * 	Recursive function to save children of a given node as DocContent items.
  */
 public function saveChildren($node, $parent_id, $child_priority)
 {
     if (!isset($parent_id) || $parent_id == 0) {
         throw new Exception("Error saving content.");
     }
     //Check the node is in the document structure elements
     @($valid = in_array($node->tagName, $this->structure));
     if (!$valid) {
         //If the node has no children, return
         if (!$node->hasChildNodes()) {
             return;
         } else {
             //Otherwise save the children, passing on the parent id ( this isn't a valid parent )
             $c = 0;
             foreach ($node->childNodes as $child) {
                 $this->saveChildren($child, $parent_id, $c++);
             }
             return;
         }
     }
     //Save this item
     $contentItem = new DocContent();
     $contentItem->doc_id = $this->bill->id;
     $contentItem->content = $this->getNodeContent($node);
     $contentItem->child_priority = $child_priority;
     $contentItem->parent_id = $parent_id;
     $contentItem->save();
     if ($node->childNodes->length == 0) {
         return;
     }
     $c = 0;
     foreach ($node->childNodes as $child) {
         $this->saveChildren($child, $contentItem->id, $c++);
     }
 }
 /**
  * 	PUT route for saving documents.
  */
 public function putDocs($id = '')
 {
     $user = Auth::user();
     if (!$user->can('admin_manage_documents')) {
         return Redirect::to('/dashboard')->with('message', "You do not have permission");
     }
     $content = Input::get('content');
     $content_id = Input::get('content_id');
     if ($content_id) {
         try {
             $doc_content = DocContent::find($content_id);
         } catch (Exception $e) {
             return Redirect::to('dashboard/docs/' . $id)->with('error', 'Error saving the document: ' . $e->getMessage());
         }
     } else {
         $doc_content = new DocContent();
     }
     $doc_content->doc_id = $id;
     $doc_content->content = $content;
     $doc_content->save();
     Event::fire(MadisonEvent::DOC_EDITED, $doc);
     $doc = Doc::find($id);
     $doc->indexContent($doc_content);
     return Redirect::to('dashboard/docs/' . $id)->with('success_message', 'Document Saved Successfully');
 }
Exemple #6
0
 public function get_content($format = null)
 {
     $path = $this->get_file_path($format);
     try {
         return File::get($path);
     } catch (Illuminate\Filesystem\FileNotFoundException $e) {
         $content = DocContent::where('doc_id', '=', $this->attributes['id'])->where('parent_id')->first()->content;
         if ($format == 'html') {
             $content = Markdown::render($content);
         }
         return $content;
     }
 }
Exemple #7
0
 public function version($params = [])
 {
     $contents = DocContent::read(['*'], FALSE, ['doc_id = ?', $params['doc_id']], 'updated DESC');
     Render::json(array_slice($contents, 0, 10));
 }
 public function create_one($params = [])
 {
     Session::permit_admin();
     return DocContent::create($params);
 }