Exemplo n.º 1
0
 /**
  * @param string $uri
  * @return string|boolean
  */
 public static function findSimilar($uri)
 {
     if (empty($uri)) {
         return false;
     }
     $uriSlugs = array_merge([''], preg_split('/\\//', $uri, -1, PREG_SPLIT_NO_EMPTY));
     $slugs = DB::table('pages')->select('id', 'slug')->wherein('status_id', config('pages.similar.find_in_statuses', []));
     if (config('pages.check_date')) {
         $slugs->where('published_at', '<=', DB::raw('NOW()'));
     }
     $slugs = $slugs->get()->lists('slug', 'id');
     $newSlugs = [];
     foreach ($uriSlugs as $slug) {
         if (in_array($slug, $slugs)) {
             $newSlugs[] = $slug;
             continue;
         }
         $similarPages = Text::similarWord($slug, $slugs);
         if (!empty($similarPages)) {
             $pageId = key($similarPages);
             $page = static::findById($pageId);
             $newSlugs[] = $page->getSlug();
         }
     }
     if (!config('pages.similar.return_parent_page') and count($uriSlugs) != count($newSlugs)) {
         return false;
     }
     $uri = implode('/', $newSlugs);
     $page = static::find($uri);
     return $page ? $uri : false;
 }
Exemplo n.º 2
0
 /**
  * @return int
  */
 public function getSize()
 {
     if ($this->isNew()) {
         $size = 0;
     } else {
         $size = $this->file->getSize();
     }
     return Text::bytes($size);
 }