Ejemplo n.º 1
0
 /**
  * Administrtion view for smileys
  */
 public function index_action()
 {
     $this->view = Request::option('view', Smiley::getFirstUsedCharacter() ?: 'a');
     $this->smileys = Smiley::getGrouped($this->view);
     $this->favorites_enabled = SmileyFavorites::isEnabled();
     $this->setSidebar($this->view);
 }
Ejemplo n.º 2
0
 /**
  * Back end for the smiley picker javascript module.
  * Renders a list of smileys very similar to the index action but
  * unfortunately still to different to be combined.
  *
  * @param mixed $view Subset to display, defaults to favorites if enabled
  * @param int   $page Section of subset to display
  */
 function picker_action($view = null, $page = 0)
 {
     $per_page = self::GRID_WIDTH * self::GRID_HEIGHT;
     $this->view = $view ?: ($this->default === 'favorites' ? 'favorites' : 'all');
     $smileys = $this->view == 'favorites' ? Smiley::getByIds($this->favorites->get()) : Smiley::getGrouped($this->view);
     $this->page = $page;
     $this->pages = floor(count($smileys) / $per_page);
     array_walk($smileys, function ($smiley) {
         $smiley->link = Smiley::getURL($smiley->name);
         $smiley->html = Smiley::img($smiley->name);
     });
     $this->smileys = array_slice($smileys, $page * $per_page, $per_page);
     $this->characters = Smiley::getUsedCharacters();
 }
Ejemplo n.º 3
0
 /**
  * Garbage collector. Removes all smiley ids from the users' favorites
  * that are no longer in the database.
  *
  * @return int Number of changed records
  */
 static function gc()
 {
     $smileys = Smiley::getGrouped('all', Smiley::FETCH_ID);
     $query = "SELECT user_id, smiley_favorite FROM user_info WHERE smiley_favorite != ''";
     $statement = DBManager::get()->prepare($query);
     $statement->execute(array());
     $temp = $statement->fetchGrouped(PDO::FETCH_COLUMN);
     $changed = 0;
     foreach ($temp as $user_id => $favorite_string) {
         $old_favorites = explode(',', $favorite_string);
         $new_favorites = array_intersect($smileys, $old_favorites);
         if (count($old_favorites) > count($new_favorites)) {
             $favorites = new self($user_id);
             $favorites->set($new_favorites);
             $changed += 1;
         }
     }
     return $changed;
 }