deleteThumbnails() public static method

Delete thumbnails based on the folders in the path
public static deleteThumbnails ( string $path, string $thumbnail )
$path string The path wherein the thumbnail-folders exist.
$thumbnail string The filename to be deleted.
Ejemplo n.º 1
0
 public function execute()
 {
     // get parameters
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id !== null && BackendHotelsModel::exists('hotels_rooms', $this->id)) {
         // call parent, this will probably add some general CSS/JS or other required files
         parent::execute();
         // get data
         $this->record = (array) BackendHotelsModel::getRecord('hotels_rooms', $this->id);
         if ($this->record['image']) {
             // the image path
             $imagePath = FRONTEND_FILES_PATH . '/rooms/images';
             BackendModel::deleteThumbnails($imagePath, $this->record['image']);
         }
         // delete item
         BackendHotelsModel::deleteRecord('hotels_rooms', $this->id);
         // build redirect URL
         $redirectUrl = BackendModel::createURLForAction('Rooms') . '&report=deleted&var=' . urlencode($this->record['title'] . '&id=' . $this->record['id']);
         // item was deleted, so redirect
         $this->redirect($redirectUrl);
     } else {
         // something went wrong
         $this->redirect(BackendModel::createURLForAction('Rooms') . '&error=non-existing&id=' . $this->record['id']);
     }
 }
Ejemplo n.º 2
0
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $fields = $this->frm->getFields();
         $fields['title']->isFilled(BL::err('TitleIsRequired'));
         if ($this->frm->isCorrect()) {
             $item = [];
             $item['id'] = $this->id;
             $item['title'] = $fields['title']->getValue();
             $item['image'] = $this->record['image'];
             $item['capacity'] = $fields['capacity']->getValue();
             $item['count'] = $fields['count']->getValue();
             $item['price'] = $fields['price']->getValue();
             // the image path
             $imagePath = FRONTEND_FILES_PATH . '/rooms/images';
             // create folders if needed
             $fs = new Filesystem();
             if ($fields['delete_image']->isFilled() || $fields['image']->isFilled() && $this->record['image']) {
                 $item['image'] = null;
                 BackendModel::deleteThumbnails($imagePath, $this->record['image']);
             }
             if ($fields['image']->isFilled()) {
                 if (!$fs->exists($imagePath . '/128x128')) {
                     $fs->mkdir(array($imagePath . '/source', $imagePath . '/128x128'));
                 }
                 if (!$fs->exists($imagePath . '/64x64')) {
                     $fs->mkdir(array($imagePath . '/source', $imagePath . '/64x64'));
                 }
                 $item['image'] = $fields['image']->getFileName(false) . '.' . $fields['image']->getExtension();
                 $i = 2;
                 while ($fs->exists($imagePath . '/source/' . $item['image'])) {
                     $item['image'] = $fields['image']->getFileName(false) . '(' . $i . ')' . '.' . $fields['image']->getExtension();
                     $i++;
                 }
                 // upload the image & generate thumbnails
                 $fields['image']->generateThumbnails($imagePath, $item['image']);
             }
             BackendHotelsModel::updateRecord('hotels_rooms', $item, $this->id);
             $this->redirect(BackendModel::createURLForAction('Rooms') . '&report=edited&var=' . urlencode($item['title']) . '&id=' . $this->hotel['id'] . '&highlight=row-' . $item['id']);
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired'));
         if ($this->frm->getField('image')->isFilled()) {
             $this->frm->getField('image')->isAllowedExtension(array('jpg', 'png', 'gif', 'jpeg'), BL::err('JPGGIFAndPNGOnly'));
             $this->frm->getField('image')->isAllowedMimeType(array('image/jpg', 'image/png', 'image/gif', 'image/jpeg'), BL::err('JPGGIFAndPNGOnly'));
         }
         $this->meta->validate();
         if ($this->frm->isCorrect()) {
             // build item
             $item['id'] = $this->id;
             $item['title'] = $this->frm->getField('title')->getValue();
             $item['meta_id'] = $this->meta->save(true);
             // the image path
             $imagePath = FRONTEND_FILES_PATH . '/catalog/brands';
             // create folders if needed
             $fs = new Filesystem();
             if (!$fs->exists($imagePath . '/source/')) {
                 $fs->mkdir($imagePath . '/source/');
                 $fs->mkdir($imagePath . '/150x150/');
             }
             if ($this->frm->getField('delete_image')->isChecked()) {
                 BackendModel::deleteThumbnails($imagePath, $this->record['image']);
                 $item['image'] = null;
             }
             // image provided?
             if ($this->frm->getField('image')->isFilled()) {
                 BackendModel::deleteThumbnails($imagePath, $this->record['image']);
                 // build the image name
                 $item['image'] = $this->meta->getUrl() . '.' . $this->frm->getField('image')->getExtension();
                 // upload the image & generate thumbnails
                 $this->frm->getField('image')->generateThumbnails($imagePath, $item['image']);
             }
             // update the item
             BackendCatalogModel::updateBrand($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_edit_brand', array('item' => $item));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('brands') . '&report=edited-brand&var=' . urlencode($item['title']) . '&highlight=row-' . $item['id']);
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Update an existing item
  *
  * @param array $item The new data.
  *
  * @return int
  */
 public static function update(array $item)
 {
     $db = BackendModel::getContainer()->get('database');
     // check if new version is active
     if ($item['status'] == 'active') {
         // archive all older active versions
         $db->update('blog_posts', array('status' => 'archived'), 'id = ? AND status = ?', array($item['id'], $item['status']));
         // get the record of the exact item we're editing
         $revision = self::getRevision($item['id'], $item['revision_id']);
         // assign values
         $item['created_on'] = BackendModel::getUTCDate('Y-m-d H:i:s', $revision['created_on']);
         $item['num_comments'] = $revision['num_comments'];
         // if it used to be a draft that we're now publishing, remove drafts
         if ($revision['status'] == 'draft') {
             $db->delete('blog_posts', 'id = ? AND status = ?', array($item['id'], $revision['status']));
         }
     }
     // don't want revision id
     unset($item['revision_id']);
     // how many revisions should we keep
     $rowsToKeep = (int) BackendModel::get('fork.settings')->get('Blog', 'max_num_revisions', 20);
     // set type of archive
     $archiveType = $item['status'] == 'active' ? 'archived' : $item['status'];
     // get revision-ids for items to keep
     $revisionIdsToKeep = (array) $db->getColumn('SELECT i.revision_id
          FROM blog_posts AS i
          WHERE i.id = ? AND i.status = ? AND i.language = ?
          ORDER BY i.edited_on DESC
          LIMIT ?', array($item['id'], $archiveType, BL::getWorkingLanguage(), $rowsToKeep));
     // delete other revisions
     if (!empty($revisionIdsToKeep)) {
         // get meta-ids that will be deleted
         $metasIdsToRemove = (array) $db->getColumn('SELECT i.meta_id
              FROM blog_posts AS i
              WHERE i.id = ? AND revision_id NOT IN (' . implode(', ', $revisionIdsToKeep) . ')', array($item['id']));
         // get all the images of the revisions that will NOT be deleted
         $imagesToKeep = $db->getColumn('SELECT image FROM blog_posts
              WHERE id = ? AND revision_id IN (' . implode(', ', $revisionIdsToKeep) . ')', array($item['id']));
         // get the images of the revisions that will be deleted
         $imagesOfDeletedRevisions = $db->getColumn('SELECT image FROM blog_posts
             WHERE id = ? AND status = ? AND revision_id NOT IN (' . implode(', ', $revisionIdsToKeep) . ')', array($item['id'], $archiveType));
         // make sure that an image that will be deleted, is not used by a revision that is not to be deleted
         foreach ($imagesOfDeletedRevisions as $imageOfDeletedRevision) {
             if (!in_array($imageOfDeletedRevision, $imagesToKeep)) {
                 BackendModel::deleteThumbnails(FRONTEND_FILES_PATH . '/blog/images', $imageOfDeletedRevision);
             }
         }
         $db->delete('blog_posts', 'id = ? AND status = ? AND revision_id NOT IN (' . implode(', ', $revisionIdsToKeep) . ')', array($item['id'], $archiveType));
         if (!empty($metasIdsToRemove)) {
             $db->delete('meta', 'id IN (' . implode(', ', $metasIdsToRemove) . ')');
         }
     }
     // insert new version
     $item['revision_id'] = BackendModel::getContainer()->get('database')->insert('blog_posts', $item);
     // return the new revision id
     return $item['revision_id'];
 }
Ejemplo n.º 5
0
 /**
  * @param bool $allowImage
  * @return string|null
  */
 private function getImage($allowImage)
 {
     $imageFilename = array_key_exists('image', (array) $this->record['data']) ? $this->record['data']['image'] : null;
     if (!$this->frm->getField('image')->isFilled() && !$this->frm->getField('remove_image')->isChecked()) {
         return $imageFilename;
     }
     $imagePath = FRONTEND_FILES_PATH . '/pages/images';
     // delete the current image
     BackendModel::deleteThumbnails($imagePath, (string) $imageFilename);
     if (!$allowImage || $this->frm->getField('remove_image')->isChecked() && !$this->frm->getField('image')->isFilled()) {
         return null;
     }
     $imageFilename = $this->meta->getURL() . '_' . time() . '.' . $this->frm->getField('image')->getExtension();
     $this->frm->getField('image')->generateThumbnails($imagePath, $imageFilename);
     return $imageFilename;
 }
Ejemplo n.º 6
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         $recordId = $this->record['id'];
         $newParent = $this->frm->getField('parent_id')->getValue();
         if ($recordId == $newParent) {
             $this->frm->getField('parent_id')->setError(BL::err('SameCategory'));
         }
         // validate fields
         if ($this->frm->getField('image')->isFilled()) {
             $this->frm->getField('image')->isAllowedExtension(array('jpg', 'png', 'gif', 'jpeg'), BL::err('JPGGIFAndPNGOnly'));
             $this->frm->getField('image')->isAllowedMimeType(array('image/jpg', 'image/png', 'image/gif', 'image/jpeg'), BL::err('JPGGIFAndPNGOnly'));
         }
         $this->meta->validate();
         //--Validate Media
         $this->media->validate();
         if ($this->frm->isCorrect()) {
             // build item
             $item['id'] = $this->id;
             $item['language'] = $this->record['language'];
             $item['extra_id'] = $this->record['extra_id'];
             $item['title'] = $this->frm->getField('title_nl')->getValue();
             $item['parent_id'] = $this->frm->getField('parent_id')->getValue();
             $item['meta_id'] = $this->meta->save(true);
             $item['ballcolor'] = $this->frm->getField('ballcolor')->getValue();
             // the image path
             $imagePath = FRONTEND_FILES_PATH . '/' . $this->getModule() . '/categories';
             // create folders if needed
             $fs = new Filesystem();
             if (!$fs->exists($imagePath . '/150x150/')) {
                 $fs->mkdir($imagePath . '/150x150/');
             }
             if (!$fs->exists($imagePath . '/source/')) {
                 $fs->mkdir($imagePath . '/source/');
             }
             if (!$fs->exists($imagePath . '/800x')) {
                 $fs->mkdir($imagePath . '/800x');
             }
             if (!$fs->exists($imagePath . '/400x480')) {
                 $fs->mkdir($imagePath . '/400x480');
             }
             if ($this->frm->getField('delete_image')->isChecked()) {
                 BackendModel::deleteThumbnails($imagePath, $this->record['image']);
                 $item['image'] = null;
             }
             // image provided?
             if ($this->frm->getField('image')->isFilled()) {
                 // build the image name
                 $item['image'] = $this->meta->getUrl() . '.' . $this->frm->getField('image')->getExtension();
                 // upload the image & generate thumbnails
                 $this->frm->getField('image')->generateThumbnails($imagePath, $item['image']);
             }
             // update the item
             BackendCatalogModel::updateCategory($item);
             //--Add the languages
             foreach ((array) BackendModel::get('fork.settings')->get('Core', 'languages') as $key => $language) {
                 $itemLanguage = array();
                 $itemLanguage['id'] = $item['id'];
                 $itemLanguage['language'] = $language;
                 $itemLanguage['title'] = $this->frm->getField('title_' . $language)->getValue();
                 $itemLanguage['description'] = $this->frm->getField('description_' . $language)->getValue();
                 $itemLanguage['summary'] = $this->frm->getField('summary_' . $language)->getValue();
                 $itemLanguage['url'] = BackendCatalogModel::getURLForCategoryLanguage($this->frm->getField('title_' . $language)->getValue(), $item['id'], $language);
                 $itemLanguage['balltext'] = $this->frm->getField('balltext_' . $language)->getValue();
                 BackendCatalogModel::updateCategoryLanguage($itemLanguage);
             }
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_edit_category', array('item' => $item));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('categories') . '&report=edited-category&var=' . urlencode($this->frm->getField('title_nl')->getValue()) . '&highlight=row-' . $item['id']);
         }
     }
 }
Ejemplo n.º 7
0
 /**
  * This function should be called for the life cycle event @ORM\PostRemove()
  */
 public function remove()
 {
     if (static::GENERATE_THUMBNAILS && is_dir($this->getUploadRootDir())) {
         Model::deleteThumbnails($this->getUploadRootDir(), $this->fileName);
         return;
     }
     parent::remove();
 }