예제 #1
0
 public static function make($type = null)
 {
     if (empty($type)) {
         $type = 'post';
     }
     $auto_draft = self::where('type', '=', $type)->where('status', '=', 'auto-draft')->with(array('post_contents.meta', 'galleries', 'post_meta'))->first();
     if (empty($auto_draft)) {
         $auto_draft = new PostModel();
         if ($type == 'post') {
             $parent = self::where('type', '=', 'page')->where('status', '=', 'publish')->where('archive_type', '=', 'post')->first();
             if (!$parent) {
                 self::$errors[] = 'No archive page';
                 return false;
             }
             $parent_id = $parent->id;
         } else {
             $parent_id = 0;
         }
         $view = '';
         switch ($type) {
             case 'post':
                 $view = 'article';
                 break;
             case 'gallery-page':
                 $view = 'gallery';
                 break;
             case 'page':
             default:
                 $view = 'page';
                 break;
         }
         $auto_draft->insert(array('parent_id' => $parent_id, 'type' => $type, 'status' => 'auto-draft', 'view' => $view));
     }
     return $auto_draft;
 }
예제 #2
0
 /**
  * @name getArticles
  *
  * 
  * @param mixed $status [optional] - article status
  * @return Response - returns Respons in json format including array of posts or error
  * 
  * @todo move this code to article repository
  */
 public function getArticles($status = array())
 {
     $query = Post::query();
     // @CHANGE
     $query->where('type', '=', $this->postType);
     // status
     // -------------------------------------
     $status = array('publish', 'draft');
     $query->whereIn('status', $status);
     // relations
     // -------------------------------------
     $query->with(array("post_contents", "featured_image.file"));
     // order
     // -------------------------------------
     $order_by = 'created_at';
     $order = 'desc';
     $query->orderBy($order_by, $order);
     // get
     // -------------------------------------
     $result = $query->get();
     return Response::json($result);
 }
예제 #3
0
 /**
  * Edit existing Page
  *
  * @param string|int page (post) id
  */
 public function edit($id = false)
 {
     //set the layout content
     $content_data = array();
     if (!empty($id)) {
         $model = Post::where('type', 'post')->find($id);
         if ($model) {
             $content_data['post_id'] = $model->id;
             $content_data['mod'] = 'edit';
         } else {
             //throw new Exception("Cant find post with that ID", 1);
             //die();
             // 404
         }
     } else {
         //throw new Exception("You have to specify post ID", 1);
         //die();
         // 404
     }
     // Page scripts
     $footer_data['scripts'] = array(array('src' => asset('packages/vizioart/cookbook/js/lib/require.min.js'), 'attrs' => array('data-main' => asset('packages/vizioart/cookbook/js/app/article/ps-article-main.js'))));
     $this->renderPage(array("content_view" => 'cookbook::pages.article.edit', "content_data" => $content_data, "footer_data" => $footer_data));
 }
예제 #4
0
 /**
  * @name attachToPost
  *
  * Attach gallery to post by post ID
  * NOTE: gallery should be instantiated in $this
  * 
  * @param int $post_id - Array of IDs or single ID of item/items for delete
  * @return bool - returns TRUE on success or FALSE if there was an error
  */
 public function attachToPost($post_id)
 {
     $post = Post::find($post_id);
     if (!$post) {
         $this->errors[] = 'No such post';
         return false;
     }
     if (!$this->post_owners()->attach($post_id, array('type' => self::POST_ITEM_TYPE))) {
         $this->errors[] = 'Failed to attach gallery to post';
         return false;
     }
     return true;
 }
예제 #5
0
 /**
  * @name getIsUrlUnique
  *
  * Checks if given url is unique in posts table
  * 
  * @param string $url - URL that should be checked
  * @return Response - returns Respons in json format including bool if url is unique
  */
 public function getIsUrlUnique($url)
 {
     $model = new Post();
     $isUnique = $model->is_url_unique($url);
     return Response::json(array('isUnique' => $isUnique), 200);
 }
예제 #6
0
 /**
  * @name attachToPost
  *
  * Attach attachment to post by post ID
  * NOTE: attachment should be instantiated in $this
  * 
  * @param int $post_id - ID of post to which it will be attached
  * @return bool - returns TRUE on success or FALSE if there was an error
  */
 public function attachToPost($post_id)
 {
     $post = Post::find($post_id);
     if (!$post) {
         $this->errors[] = 'No such post';
         return false;
     }
     $this->fill(array('parent_id' => $post_id, 'parent_type' => self::POST_ITEM_PARENT));
     try {
         DB::beginTransaction();
         if (!$this->save()) {
             DB::rollBack();
             $this->errors[] = 'Failed to save attachment';
             return false;
         }
         DB::commit();
         return true;
     } catch (PDOException $e) {
         DB::rollBack();
         $this->errors[] = 'Fatal error' . $e->message;
         return false;
     }
 }
예제 #7
0
 /**
  *
  */
 public function resolveRoute($route = null)
 {
     // make sure default route is set
     App::setLocale('cs');
     /**
      * when using route like this : Route::get('{var?}', ...)->where('var', '(.*)');
      * var is passed with first forward slash
      */
     $route = ltrim($route, '/');
     // home page (default locale)
     if (empty($route)) {
         return $this->renderHomePage();
     }
     if (!empty($this->route_segments)) {
         // check for locale segment
         if (in_array($this->route_segments[0], $this->get_site_locales())) {
             App::setLocale($this->route_segments[0]);
             $this->locale = $this->route_segments[0];
         } else {
             /** 
              * First segment is reserved for locale
              * If its not locale string return 404
              *
              * @TO_DO try to return more helpful response.
              */
             App::abort(404);
         }
     }
     if (count($this->route_segments) == 1) {
         // home page in requested locale
         return $this->renderHomePage();
     }
     // try to get page by url
     $model = new Post();
     $post = $model->get_by_url($route);
     if ($post) {
         return $this->renderPage($post);
     }
     // -----------------------------------------------
     //  Parameterized Pages
     // -----------------------------------------------
     $route_segments = $this->route_segments;
     $popped_route_segments = array();
     $searched_urls = array();
     $found_url = '';
     $tries = 0;
     while (!$post && count($route_segments) > 2 && $tries < 3) {
         $tries++;
         array_push($popped_route_segments, array_pop($route_segments));
         $url = implode('/', $route_segments);
         $searched_urls[] = $url;
         $post = $model->get_by_url($url);
         if ($post) {
             $found_url = $url;
         }
     }
     if ($post) {
         // get params in original order after page url is found
         $page_params = array_reverse($popped_route_segments);
         return $this->renderPage($post, $page_params);
     }
     // no result, do 404
     // -----------------------------------------------
     App::abort(404);
 }