예제 #1
0
 /**
  * Check for uniqueness of the username
  *
  * @param string $username URL encoded username
  */
 public function actionCheckUsername($username)
 {
     // is this Ajax?
     if ($this->request->isAjax()) {
         // URL decode & filter out username
         $username = Fari_Escape::text(Fari_Decode::url($username));
         if (empty($username)) {
             $this->renderJson("The username can't be empty.");
         } else {
             // alphanumeric only?
             if (!Fari_Filter::isAlpha($username)) {
                 $this->renderJson("Only alphanumeric characters are allowed.");
             } else {
                 // do we have a match?
                 if (!$this->accounts->isUsernameUnique($username)) {
                     $this->renderJson("The username \"{$username}\" is unavailable, sorry.");
                 } else {
                     $this->renderJson('');
                 }
             }
         }
     } else {
         $this->renderTemplate('error404/javascript');
     }
 }
예제 #2
0
 public function results($query)
 {
     if (!empty($query)) {
         // cleanup, convert, replace, strip...
         $query = Fari_Decode::url($query);
         $query = preg_replace('~\\s{2,}~', ' ', implode(' ', explode('-', strtolower($query))));
         $query = substr($query, -1) == ' ' ? substr($query, 0, -1) : $query;
         // trailing space
         $query = substr($query, 0, 1) == ' ' ? substr($query, 1) : $query;
         // leading space
         $this->view->query = $query = Fari_Escape::alpha($query);
         $this->view->keywords = implode('-', explode(' ', $query));
         // implode back to have clean keywords
     } else {
         $this->redirect('/');
         die;
     }
     // fetch the result and add relevance to it
     $this->view->result = Search::query($query);
     $this->view->display('results');
 }