/** * 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); }
/** * Common tasks for all actions. */ function before_filter(&$action, &$args) { parent::before_filter($action, $args); PageLayout::setTitle(_('Smiley-Übersicht')); $this->favorites_activated = SmileyFavorites::isEnabled() && $GLOBALS['user']->id != nobody; if ($this->favorites_activated) { $this->favorites = new SmileyFavorites($GLOBALS['user']->id); $this->default = count($this->favorites->get()) > 0 ? 'favorites' : Smiley::getFirstUsedCharacter(); } else { $this->default = Smiley::getFirstUsedCharacter(); } }
/** * Synchronizes the smileys' file system or an atomic file with the * database. * The smiley directory is scanned for new, changed or missing files. * Any difference will change the database's record. * * This method is also used for uploading new smileys. Provide an * absolute filename of a smiley and it will either be imported into * the database or the database will be adjusted to the current file's * dimensions. * * @param mixed $smiley_file If no filename is provided, the whole file * system is refreshed * @return Array Numbers: inserted, updated, removed (, favorites adjusted) */ static function refresh($smiley_file = null) { $counts = array('insert' => 0, 'update' => 0); if ($filename === null) { $files = glob(self::getFilename('*')); } else { $files = array($smiley_file); } foreach ($files as $file) { $image_info = getimagesize($file); if ($image_info[2] !== IMAGETYPE_GIF) { continue; } $name = substr(basename($file), 0, strrpos(basename($file), ".")); //$name = basename($file, '.gif'); $smiley = Smiley::getByName($name); $update = false; if (!$smiley->id) { $smiley->name = $name; $smiley->short = array_search($name, $GLOBALS['SMILE_SHORT']) ?: ''; $smiley->width = $image_info[0]; $smiley->height = $image_info[1]; $update = true; $counts['insert'] += 1; } else { if ($smiley->width + $smiley->height != $image_info[0] + $image_info[1]) { $smiley->width = $image_info[0]; $smiley->height = $image_info[1]; $update = true; $counts['update'] += 1; } } //$smiley->width || $smiley->width = 20; //$smiley->height || $smiley->height = 20; if ($update) { $smiley->store(); } $ids[] = $smiley->id; } $db_ids = self::getGrouped('all', self::FETCH_ID); $missing = array_diff($db_ids, $ids); self::Remove($missing); $counts['delete'] = count($missing); if (SmileyFavorites::isEnabled()) { $counts['favorites'] = SmileyFavorites::gc(); } return $counts; }