Ejemplo n.º 1
0
 public static function add_term($term)
 {
     $existing = self::where('term', '=', $term)->first();
     if (!empty($existing)) {
         $existing->count++;
         $existing->save();
     } else {
         $new_term = new PageSearchLog();
         $new_term->term = $term;
         $new_term->count = 1;
         $new_term->save();
     }
 }
Ejemplo n.º 2
0
 public function getIndex()
 {
     $requests = PagePublishRequests::can_moderate(['status' => 'awaiting'], 10);
     if ($requests->isEmpty()) {
         $requests = 'No awaiting requests';
     }
     $requests_table = View::make('coaster::partials.tabs.publish_requests.table', array('show' => ['page' => true, 'status' => false, 'requested_by' => true], 'requests' => $requests))->render();
     $any_requests = config('coaster::admin.publishing') && !PagePublishRequests::can_moderate([], 1)->isEmpty();
     $user_requests = PagePublishRequests::all_requests(0, ['user_id' => Auth::user()->id, 'status' => 'awaiting'], 10);
     if ($user_requests->isEmpty()) {
         $user_requests = 'No awaiting requests';
     }
     $user_requests_table = View::make('coaster::partials.tabs.publish_requests.table', array('show' => ['page' => true, 'status' => true, 'requested_by' => false], 'requests' => $user_requests))->render();
     $any_user_requests = config('coaster::admin.publishing') && !PagePublishRequests::all_requests(0, ['user_id' => Auth::user()->id], 1)->isEmpty();
     $logs_data = AdminLog::with(['user', 'backup'])->orderBy('id', 'desc')->paginate(10);
     $logs = View::make('coaster::partials.logs.table', array('logs' => $logs_data));
     $firstTimer = false;
     if (Install::getInstallState() == 'complete-welcome') {
         Install::setInstallState('complete');
         $firstTimer = true;
     }
     $coasterBlog = 'https://www.coastercms.org/blog/';
     $coasterBlogHttpClient = new Client(['base_uri' => $coasterBlog . 'wp-json/wp/v2/']);
     try {
         $latestPosts = $coasterBlogHttpClient->request('GET', 'posts', ['query' => ['per_page' => 3]]);
         $latestPosts = json_decode($latestPosts->getBody());
     } catch (\Exception $e) {
         $latestPosts = [];
     }
     $posts = collect($latestPosts);
     // Search data
     $numbSearches = PageSearchLog::count();
     if (Auth::action('search.index') && $numbSearches) {
         $search_data = PageSearchLog::orderBy('count', 'DESC')->orderBy('updated_at', 'DESC')->limit(6)->get();
         $numbSearches = $search_data->count();
         $search_view = View::make('coaster::pages.search', array('search_data' => $search_data));
     } else {
         $search_view = '';
     }
     $data = array('firstTimer' => $firstTimer, 'coasterPosts' => $posts, 'coasterBlog' => $coasterBlog, 'logs' => $logs, 'requests' => $requests_table, 'user_requests' => $user_requests_table, 'any_requests' => $any_requests, 'any_user_requests' => $any_user_requests);
     $data['searchLogNumber'] = $numbSearches;
     $data['searchLogs'] = $search_view;
     $data['canViewSettings'] = Auth::action('system');
     $upgrade = new \stdClass();
     $upgrade->from = config('coaster::site.version');
     $upgrade->to = Setting::latestTag();
     $upgrade->required = version_compare(config('coaster::site.version'), $upgrade->to, '<');
     $upgrade->allowed = Auth::action('system.upgrade');
     $data['upgrade'] = $upgrade;
     $this->layoutData['title'] = 'Admin home';
     $this->layoutData['content'] = View::make('coaster::pages.dashboard', $data);
 }
Ejemplo n.º 3
0
 public static function lookup($keywords, $onlyLive = 1, $limit = 100)
 {
     $foundPages = [];
     if (!empty($keywords)) {
         PageSearchLog::add_term($keywords);
         // create array containing, whole term then each individual word (or just whole term if one word)
         $keywordsArray = array_merge([$keywords], explode(' ', $keywords));
         $keywordsArray = count($keywordsArray) == 2 ? [$keywordsArray[0]] : $keywordsArray;
         $numberOfKeywords = count($keywordsArray);
         // load search objects
         $searchObjects = [new Cms($onlyLive), new WordPress($onlyLive, config('coaster::blog.url') ? Setting::blogConnection() : false)];
         event(new Search($searchObjects, $onlyLive));
         // run search functions
         foreach ($keywordsArray as $i => $keyword) {
             $keywordAdditionalWeight = ($numberOfKeywords - $i) * 0.1 + ($i == 0 && $numberOfKeywords > 1 ? 5 : 0);
             foreach ($searchObjects as $searchObject) {
                 $searchObject->run($keyword, $keywordAdditionalWeight);
             }
         }
         // get search results
         $weights = [];
         $pages = [];
         foreach ($searchObjects as $i => $searchObject) {
             $weights = $weights + $searchObject->getWeights();
             $pages = $pages + $searchObject->getPages();
         }
         // order, limit and create page data array
         if ($weights) {
             arsort($weights);
             if (count($weights) > $limit) {
                 $weights = array_slice($weights, 0, 100, true);
             }
             $pageIds = array_keys($weights);
             foreach ($pageIds as $pageId) {
                 if (array_key_exists($pageId, $pages)) {
                     $foundPages[] = $pages[$pageId];
                 }
             }
         }
     }
     return $foundPages;
 }
Ejemplo n.º 4
0
 public function getIndex()
 {
     $search_data = PageSearchLog::orderBy('count', 'DESC')->orderBy('updated_at', 'DESC')->get();
     $this->layoutData['content'] = View::make('coaster::pages.search', array('search_data' => $search_data));
 }