Exemplo n.º 1
0
 public function getDocumentContent($id)
 {
     $page = Input::get('page', 1);
     if (!$page) {
         $page = 1;
     }
     $format = Input::get('format');
     if (!$format) {
         $format = 'html';
     }
     $cacheKey = 'doc-' . $id . '-' . $page . '-' . $format;
     if ($format === 'html' && Cache::has($cacheKey)) {
         return Response::json(Cache::get($cacheKey));
     }
     $docContent = DocContent::where('doc_id', $id)->limit(1)->offset($page - 1)->first();
     $returned = array();
     if ($docContent) {
         if ($format === 'raw' || $format === 'all') {
             $returned['raw'] = $docContent->content;
         }
         if ($format === 'html' || $format === 'all') {
             $returned['html'] = $docContent->html();
         }
     }
     if ($format === 'html') {
         Cache::forever($cacheKey, $returned);
         $returned['cached'] = false;
     }
     return Response::json($returned);
 }
Exemplo n.º 2
0
 public function getDocumentContent($id)
 {
     $page = Input::get('page', 1);
     $format = Input::get('format');
     if (!$format) {
         $format = 'html';
     }
     $docContent = DocContent::where('doc_id', $id)->limit(1)->offset($page - 1)->first();
     $returned = array();
     if ($docContent) {
         if ($format === 'raw' || $format === 'all') {
             $returned['raw'] = $docContent->content;
         }
         if ($format === 'html' || $format === 'all') {
             $returned['html'] = $docContent->html();
         }
     }
     return Response::json($returned);
 }
Exemplo n.º 3
0
 public function deleteContent($docId, $page)
 {
     $doc_content = DocContent::where('doc_id', $docId)->where('page', $page)->first();
     if ($doc_content) {
         $doc_content->delete();
         DocContent::where('doc_id', $docId)->where('page', '>', $page)->decrement('page');
         $doc = Doc::find($docId);
         $doc->enableCounts();
         Event::fire(MadisonEvent::DOC_EDITED, $doc);
         return Response::json($doc->toArray());
     }
 }
Exemplo n.º 4
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;
     }
 }