Ejemplo n.º 1
0
 /**
  * calls Stud.IP's kill_format and additionally removes any found smiley-tag
  *
  * @param string $text the text to parse
  * @return string the text without format-tags and without smileys
  */
 static function killFormat($text)
 {
     $text = kill_format($text);
     // find stuff which is enclosed between to colons
     preg_match('/:.*:/U', $text, $matches);
     // remove the match if it is a smiley
     foreach ($matches as $match) {
         if (Smiley::getByName($match) || Smiley::getByShort($match)) {
             $text = str_replace($match, '', $text);
         }
     }
     return $text;
 }
Ejemplo n.º 2
0
 /**
  * Displays upload form and processes the upload command
  *
  * @param String $view View to return to if canceled
  */
 public function upload_action($view)
 {
     PageLayout::setTitle(_('Neues Smiley hochladen'));
     if (!Request::submitted('upload')) {
         $this->view = $view;
         return;
     }
     // File submitted?
     $upload = $_FILES['smiley_file'];
     if (empty($upload) or empty($upload['name'])) {
         $error = _('Sie haben keine Datei zum Hochladen ausgewählt!');
         PageLayout::postMessage(MessageBox::error($error));
         return;
     }
     // Error upon upload?
     if ($upload['error']) {
         $error = _('Es gab einen Fehler beim Upload. Bitte versuchen Sie es erneut.');
         PageLayout::postMessage(MessageBox::error($error));
         return;
     }
     // Correct mime-type?
     $no_image = !empty($upload['type']) && substr($upload['type'], 0, 5) != 'image';
     if (!$no_image) {
         $image_info = getimagesize($upload['tmp_name']);
         // Used later on!
         $no_gif = $image_info[2] != IMAGETYPE_GIF;
     }
     if ($no_image) {
         $error = _('Die Datei ist keine Bilddatei');
         PageLayout::postMessage(MessageBox::error($error));
         return;
     }
     // Extract smiley information
     $smiley_file = $upload['name'];
     $smiley_name = substr($smiley_file, 0, strrpos($smiley_file, '.'));
     // Replace smiley?
     $smiley = Smiley::getByName($smiley_name);
     $replace = Request::int('replace');
     if ($smiley->id && !$replace) {
         $error = sprintf(_('Es ist bereits eine Bildatei mit dem Namen "%s" vorhanden.'), $smiley_file);
         PageLayout::postMessage(MessageBox::error($error));
         return;
     }
     // Copy file into file system
     $destination = Smiley::getFilename($smiley_file);
     if (!move_uploaded_file($upload['tmp_name'], $destination)) {
         $error = _('Es ist ein Fehler beim Kopieren der Datei aufgetreten. Das Bild wurde nicht hochgeladen!');
         PageLayout::postMessage(MessageBox::error($error));
         return;
     }
     // set permissions for uploaded file
     chmod($destination, 0666 & ~umask());
     // Import smiley into database
     Smiley::refresh($destination);
     // Output appropriate wurde message
     $message = $replace ? sprintf(_('Die Bilddatei "%s" wurde erfolgreich ersetzt.'), $smiley_file) : sprintf(_('Die Bilddatei "%s" wurde erfolgreich hochgeladen.'), $smiley_file);
     PageLayout::postMessage(MessageBox::success($message));
     // Return to index and display the view the uploaded smiley is in
     $this->redirect('admin/smileys?view=' . $smiley_file[0]);
 }
Ejemplo n.º 3
0
 /**
  * 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;
 }