Esempio n. 1
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired'));
         // no errors?
         if ($this->frm->isCorrect()) {
             // build item
             $item['title'] = $this->frm->getField('title')->getValue();
             $item['language'] = BL::getWorkingLanguage();
             $item['publish_on'] = BackendModel::getUTCDate('Y-m-d H:i:s');
             $item['hidden'] = $this->frm->getField('hidden')->getValue();
             // get the highest sequence available
             $item['sequence'] = BackendGalleryModel::getMaximumCategorySequence() + 1;
             // insert the item
             $item['id'] = BackendGalleryModel::insertCategory($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add_category', array('item' => $item));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('categories') . '&report=added-category&var=' . urlencode($item['title']) . '&highlight=row-' . $item['id']);
         }
     }
 }
Esempio n. 2
0
 /**
  * Execute the action
  */
 public function execute()
 {
     // get parameters
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id !== null && BackendGalleryModel::existsAlbum($this->id)) {
         // call parent, this will probably add some general CSS/JS or other required files
         parent::execute();
         // get album
         $this->album = BackendGalleryModel::getAlbumFromId($this->id);
         // is this album allowed to be deleted?
         if (!BackendGalleryModel::deleteAlbumAllowed($this->id)) {
             $this->redirect(BackendModel::createURLForAction('albums') . '&error=album-not-deletable');
         } else {
             // delete the item
             BackendGalleryModel::deleteAlbumById($this->id);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_delete_album', array('id' => $this->id));
             // item was deleted, so redirect
             $this->redirect(BackendModel::createURLForAction('albums') . '&report=album-deleted&var=' . urlencode($this->album['title']));
         }
     } else {
         $this->redirect(BackendModel::createURLForAction('albums') . '&error=non-existing');
     }
 }
Esempio n. 3
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     //--Get the id
     $id = \SpoonFilter::getPostValue('id', null, '', 'string');
     //--Check if the id is not empty
     if (!empty($id)) {
         //--Delete file
         BackendGalleryModel::delete($id);
     }
     // success output
     $this->output(self::OK, null, 'image deleted');
 }
Esempio n. 4
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     //--Get the ids as array
     $ids = \SpoonFilter::getPostValue('ids', null, '', 'array');
     //--Check if the id is not empty
     if (!empty($ids)) {
         foreach ($ids as $id) {
             //--Delete file
             BackendGalleryModel::delete($id);
         }
     }
     // success output
     $this->output(self::OK, null, 'images deleted');
 }
Esempio n. 5
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     //--Get the ids and split them
     $id = \SpoonFilter::getPostValue('id', null, '', 'string');
     //--Get new name for image
     $nameGet = \SpoonFilter::getPostValue('name', null, '', 'string');
     //--Check if the id is not empty
     if (!empty($id)) {
         //--Get image
         $image = BackendGalleryModel::get($id);
         //--Clean new name for file
         $name = preg_replace("([^\\w\\s\\d\\-_~,;:\\[\\]\\(\\).])", '', $nameGet);
         //--Get all image folders defined by sizes
         $folders = BackendModel::getThumbnailFolders(FRONTEND_FILES_PATH . '/Gallery/Images', true);
         //--Create filesystem for file actions
         $fs = new Filesystem();
         //--Get extention
         $extension = pathinfo($image['filename'], PATHINFO_EXTENSION);
         //--Get path to files
         $path = FRONTEND_FILES_PATH . '/Gallery/Images/';
         //--If old and new name is not the same -> do rename
         if ($image['filename'] != $name . '.' . $extension) {
             //--Rename files on disk
             if (!$fs->exists($path . '/Source/' . $name . '.' . $extension)) {
                 if ($fs->exists($path . '/Source/' . $image['filename'])) {
                     $fs->rename($path . '/Source/' . $image['filename'], $path . '/Source/' . $name . '.' . $extension);
                 }
                 foreach ($folders as $folder) {
                     if ($fs->exists($path . $folder['dirname'] . '/' . $image['filename'])) {
                         $fs->rename($path . $folder['dirname'] . '/' . $image['filename'], $path . $folder['dirname'] . '/' . $name . '.' . $extension);
                     }
                 }
                 //--Rename file
                 $image['filename'] = $name . '.' . $extension;
                 BackendGalleryModel::update($image);
                 $this->output(self::OK, null, 'file renamed');
             } else {
                 $this->output(self::ERROR, null, 'file name already exists');
             }
         } else {
             $this->output(self::OK, null, 'file name is the same');
         }
     }
 }
Esempio n. 6
0
 /**
  * Execute the action
  */
 public function execute()
 {
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id !== null && BackendGalleryModel::existsCategory($this->id)) {
         parent::execute();
         // is this category allowed to be deleted?
         if (!BackendGalleryModel::deleteCategoryAllowed($this->id)) {
             $this->redirect(BackendModel::createURLForAction('categories') . '&error=category-not-deletable');
         } else {
             // get category
             $this->record = BackendGalleryModel::getCategoryFromId($this->id);
             // delete category
             BackendGalleryModel::deleteCategoryById($this->id);
             BackendModel::triggerEvent($this->getModule(), 'after_delete_category', array('id' => $this->id));
             $this->redirect(BackendModel::createURLForAction('categories') . '&report=category-deleted&var=' . urlencode($this->record['title']));
         }
     } else {
         $this->redirect(BackendModel::createURLForAction('categories') . '&error=non-existing');
     }
 }
Esempio n. 7
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     // get parameters
     $newIdSequence = trim(\SpoonFilter::getPostValue('new_id_sequence', null, '', 'string'));
     // list id
     $ids = (array) explode(',', rtrim($newIdSequence, ','));
     // loop id's and set new sequence
     foreach ($ids as $i => $id) {
         // build item
         $item['id'] = (int) $id;
         // change sequence
         $item['sequence'] = $i + 1;
         // update sequence
         if (BackendGalleryModel::existsAlbum($item['id'])) {
             BackendGalleryModel::updateAlbum($item);
         }
     }
     // success output
     $this->output(self::OK, null, 'sequence updated');
 }
Esempio n. 8
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     //--Get the ids and split them
     $ids = explode(',', trim(\SpoonFilter::getPostValue('ids', null, '', 'string')));
     //--Check if the id is not empty
     if (!empty($ids)) {
         //--Set the sequence to 1
         $sequence = 1;
         //--Loop the id's
         foreach ($ids as $id) {
             //--Set the item array
             $item = array();
             $item["id"] = (int) $id;
             $item["sequence"] = $sequence;
             BackendGalleryModel::exists($item["id"]) ? BackendGalleryModel::update($item) : null;
             //--Add the sequence for each id
             $sequence++;
         }
     }
     // success output
     $this->output(self::OK, null, 'sequence updated');
 }
Esempio n. 9
0
 /**
  * Validate the form delete image
  *
  * @return void
  */
 private function validateFormDeleteImage()
 {
     //--Check if the delete-image form is submitted
     if ($this->frmDeleteImage->isSubmitted()) {
         //--Clean up fields in the form
         $this->frmDeleteImage->cleanupFields();
         //--Check if the image-array is not empty.
         if (!empty($this->images)) {
             //--Loop the images
             foreach ($this->images as $row) {
                 //--Check if the delete parameter is filled in.
                 if (\SpoonFilter::getPostValue("delete_" . $row["id"], null, "") == "Y") {
                     //--Delete the image
                     BackendGalleryModel::delete($row["id"]);
                 }
                 //--Update item
                 $item['id'] = $row['id'];
                 $item['language'] = $row['language'];
                 $item['description'] = \SpoonFilter::getPostValue("description_" . $row["id"], null, "");
                 BackendGalleryModel::updateImage($item);
             }
             $this->redirect(BackendModel::createURLForAction('edit_album') . '&id=' . $this->id . '&report=deleted-images#tabImages');
         }
     }
 }
Esempio n. 10
0
 /**
  * Validate the form
  *
  * @return void
  */
 private function validateForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired'));
         // no errors?
         if ($this->frm->isCorrect()) {
             // build album array
             $album['language'] = BL::getWorkingLanguage();
             $album['meta_id'] = $this->meta->save();
             $album['title'] = (string) $this->frm->getField('title')->getValue();
             $album['sequence'] = (int) BackendGalleryModel::getMaximumAlbumSequence() + 1;
             $album['hidden'] = (string) $this->frm->getField('hidden')->getValue();
             $album['show_in_overview'] = (string) $this->frm->getField('show_in_overview')->getValue();
             $album['category_id'] = (int) $this->frm->getField('category')->getValue();
             $album['publish_on'] = BackendModel::getUTCDate();
             $album['description'] = (string) $this->frm->getField('description')->getValue();
             // first, insert the album
             $album['id'] = BackendGalleryModel::insertAlbum($album, (bool) $this->frm->getField('gallery')->getValue(), (bool) $this->frm->getField('slideshow')->getValue());
             // save the tags
             BackendTagsModel::saveTags($album['id'], $this->frm->getField('tags')->getValue(), $this->URL->getModule());
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add_album', array('item' => $album));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('albums') . '&report=added-album&var=' . urlencode($album['title']) . '&highlight=row-' . $album['id']);
         }
     }
 }
Esempio n. 11
0
 /**
  * Validate the form add image
  *
  * @return void
  */
 private function validateForm()
 {
     //--Check if the add-image form is submitted
     if ($this->frm->isSubmitted()) {
         //--Clean up fields in the form (NOT ALLOWED: fields from plupload like name are deleted)
         //$this->frm->cleanupFields();
         //--Get image field
         $filImage = $this->frm->getField('images');
         //--Check if the field is filled in
         if ($filImage->isFilled()) {
             //--Image extension and mime type
             $filImage->isAllowedExtension(array('jpg', 'png', 'gif', 'jpeg'), BL::err('JPGGIFAndPNGOnly'));
             $filImage->isAllowedMimeType(array('image/jpg', 'image/png', 'image/gif', 'image/jpeg'), BL::err('JPGGIFAndPNGOnly'));
             //--Check if there are no errors.
             $strError = $filImage->getErrors();
             if ($strError === null) {
                 //--Get the filename
                 $strFilename = BackendGalleryModel::checkFilename(substr($_REQUEST["name"], 0, 0 - (strlen($filImage->getExtension()) + 1)), $filImage->getExtension());
                 //--Fill in the item
                 $item = array();
                 $item["album_id"] = (int) $this->id;
                 $item["user_id"] = BackendAuthentication::getUser()->getUserId();
                 $item["language"] = BL::getWorkingLanguage();
                 $item["filename"] = $strFilename;
                 $item["description"] = "";
                 $item["publish_on"] = BackendModel::getUTCDate();
                 $item["hidden"] = "N";
                 $item["sequence"] = BackendGalleryModel::getMaximumImageSequence($this->id) + 1;
                 //--the image path
                 $imagePath = FRONTEND_FILES_PATH . '/Gallery/Images';
                 //--create folders if needed
                 $resolutions = $this->get('fork.settings')->get("Gallery", 'resolutions', false);
                 foreach ($resolutions as $res) {
                     if (!\SpoonDirectory::exists($imagePath . '/' . $res)) {
                         \SpoonDirectory::create($imagePath . '/' . $res);
                         // Create filesystem object
                         $filesystem = new Filesystem();
                         // Create var dir for ease of use
                         $dir = $imagePath;
                         // Check if dir exists
                         if ($filesystem->exists($dir . '/Source/')) {
                             // Create Finder object for the files
                             $finderFiles = new Finder();
                             // Get all the files in the source-dir
                             $files = $finderFiles->files()->in($dir . '/Source/');
                             // Check if $files is not empty
                             if (!empty($files)) {
                                 // Explode the dir-name
                                 $chunks = explode("x", $res, 2);
                                 // Create folder array
                                 $folder = array();
                                 $folder['width'] = $chunks[0] != '' ? (int) $chunks[0] : null;
                                 $folder['height'] = $chunks[1] != '' ? (int) $chunks[1] : null;
                                 // Loop all the files
                                 foreach ($files as $file) {
                                     set_time_limit(150);
                                     // Check if the file exists
                                     if (!$filesystem->exists($imagePath . '/' . $res . '/' . $file->getBasename())) {
                                         // generate the thumbnail
                                         $thumbnail = new \SpoonThumbnail($dir . '/Source/' . $file->getBasename(), $folder['width'], $folder['height']);
                                         $thumbnail->setAllowEnlargement(true);
                                         // if the width & height are specified we should ignore the aspect ratio
                                         if ($folder['width'] !== null && $folder['height'] !== null) {
                                             $thumbnail->setForceOriginalAspectRatio(false);
                                         }
                                         $thumbnail->parseToFile($imagePath . '/' . $res . '/' . $file->getBasename());
                                     }
                                 }
                             }
                         }
                     }
                 }
                 if (!\SpoonDirectory::exists($imagePath . '/Source')) {
                     \SpoonDirectory::create($imagePath . '/Source');
                 }
                 if (!\SpoonDirectory::exists($imagePath . '/128x128')) {
                     \SpoonDirectory::create($imagePath . '/128x128');
                 }
                 if (!\SpoonDirectory::exists($imagePath . '/800x')) {
                     \SpoonDirectory::create($imagePath . '/800x');
                 }
                 if (!\SpoonDirectory::exists($imagePath . '/200x')) {
                     \SpoonDirectory::create($imagePath . '/200x');
                 }
                 if (!\SpoonDirectory::exists($imagePath . '/400x300')) {
                     \SpoonDirectory::create($imagePath . '/400x300');
                 }
                 //--image provided?
                 if ($filImage->isFilled()) {
                     //--upload the image & generate thumbnails
                     $filImage->generateThumbnails($imagePath, $item["filename"]);
                 }
                 //--Add item to the database
                 $idInsert = BackendGalleryModel::insert($item);
                 $item['id'] = $idInsert;
                 //--Create html for ajax
                 $tpl = new Template();
                 $txtDescription = $this->frm->addTextarea("description_" . $idInsert, $item['description']);
                 $item['field_description'] = $txtDescription->setAttribute('style', 'resize: none;')->parse();
                 //--Parse filename to get name
                 $path_parts = pathinfo(FRONTEND_FILES_PATH . '/Gallery/Images/Source/' . $item['filename']);
                 $item['name'] = $path_parts['filename'];
                 $folders = BackendModel::getThumbnailFolders(FRONTEND_FILES_PATH . '/Gallery/Images', true);
                 foreach ($folders as $folder) {
                     $item['image_' . $folder['dirname']] = $folder['url'] . '/' . $folder['dirname'] . '/' . $item['filename'];
                 }
                 $tpl->assign('images', array($item));
                 $html = $tpl->getContent(BACKEND_MODULES_PATH . '/Gallery/Layout/Templates/Ajax/Image.tpl');
                 //Send html (ajax response)
                 $this->output(self::OK, $html, BL::msg('Success'));
             }
         }
     }
 }
Esempio n. 12
0
 /**
  * Validate the form
  *
  * @return void
  */
 private function validateForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired'));
         // no errors?
         if ($this->frm->isCorrect()) {
             // first, build the category array
             $category['id'] = (int) $this->id;
             $category['title'] = (string) $this->frm->getField('title')->getValue();
             $category['language'] = (string) BL::getWorkingLanguage();
             $category['hidden'] = (string) $this->frm->getField('hidden')->getValue();
             // ... then, update the category
             $category_update = BackendGalleryModel::updateCategory($category);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_edit_category', array('item' => $category));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('categories') . '&report=edited-category&var=' . urlencode($category['title']) . '&highlight=row-' . $category['id']);
         }
     }
 }