/** * Searches for a paste by its content * * @access public * @param string $term * @return \Illuminate\Support\Facades\View */ public function getSearch() { $term = Input::get('q'); $config = Site::config('general'); // Initialize the antispam filters $antispam = Antispam::make('search', 'q'); if ($config->pasteSearch and strlen($term) >= 5) { if ($antispam->passes() or Session::has('search.exempt')) { // Show all pastes to admins if (Auth::roles()->admin) { $query = Paste::query(); } else { $query = Paste::where('private', '<>', 1); } // Append the search term $query = $query->where('data', 'like', "%{$term}%"); // Filter by project if (!empty($this->project)) { $query = $query->where('project', $this->project); } // Get number of results to show per page $perPage = $config->perPage; // Query the search results $pastes = $query->orderBy('id', 'desc')->paginate($perPage); // Append the search term to pagination URLs $pastes->appends('q', $term); // We will not run antispam if it passed once and there are // multiple pages. But we exempt it only for the next request. Session::flash('search.exempt', $perPage > $pastes->count()); return $this->getList($pastes, TRUE); } else { Session::flash('messages.error', $antispam->message()); } } return Redirect::to('all')->withInput(); }