/** * 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')); // validate meta $this->meta->validate(); // no errors? if ($this->frm->isCorrect()) { // build item $item['title'] = $this->frm->getField('title')->getValue(); $item['language'] = BL::getWorkingLanguage(); $item['meta_id'] = $this->meta->save(); $item['sequence'] = BackendSlideshowModel::getMaximumCategorySequence() + 1; // insert the item $item['id'] = BackendSlideshowModel::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=' . $item['id']); } } }
/** * Load the datagrids * * @return void */ private function loadDataGrids() { // load all categories that are in use $categories = BackendSlideshowModel::getActiveCategories(true); // run over categories and create datagrid for each one foreach ($categories as $categoryId => $categoryTitle) { // create datagrid $dataGrid = new BackendDataGridDB(BackendSlideshowModel::QRY_DATAGRID_BROWSE, array(BL::getWorkingLanguage(), $categoryId)); // disable paging $dataGrid->setPaging(false); // set colum URLs $dataGrid->setColumnURL('title', BackendModel::createURLForAction('Edit') . '&id=[id]'); // set column functions $dataGrid->setColumnFunction(array(new BackendDataGridFunctions(), 'getLongDate'), array('[publish_on]'), 'publish_on', true); $dataGrid->setColumnFunction(array(new BackendDataGridFunctions(), 'getUser'), array('[user_id]'), 'user_id', true); // set headers $dataGrid->setHeaderLabels(array('user_id' => \SpoonFilter::ucfirst(BL::lbl('Author')), 'publish_on' => \SpoonFilter::ucfirst(BL::lbl('PublishedOn')))); // enable drag and drop $dataGrid->enableSequenceByDragAndDrop(); // our JS needs to know an id, so we can send the new order $dataGrid->setRowAttributes(array('id' => '[id]')); $dataGrid->setAttributes(array('data-action' => "GallerySequence")); // create a column #images $dataGrid->addColumn('images', ucfirst(BL::lbl('Images'))); $dataGrid->setColumnFunction(array('Backend\\Modules\\Slideshow\\Engine\\Model', 'getImagesByGallery'), array('[id]', true), 'images', true); // hide columns $dataGrid->setColumnsHidden(array('category_id', 'sequence', 'filename')); // add edit column $dataGrid->addColumn('edit', null, BL::lbl('Edit'), BackendModel::createURLForAction('Edit') . '&id=[id]', BL::lbl('Edit')); // set column order $dataGrid->setColumnsSequence('dragAndDropHandle', 'title', 'images', 'user_id', 'publish_on', 'edit'); // add dataGrid to list $this->dataGrids[] = array('id' => $categoryId, 'title' => $categoryTitle, 'content' => $dataGrid->getContent()); } }
/** * Execute the action * * @return void */ public function execute() { // call parent, this will probably add some general CSS/JS or other required files 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 BackendSlideshowModel::updateCategorySequence($item); } // success output $this->output(self::OK, null, 'sequence updated'); }
/** * Execute the action * * @return void */ public function execute() { // get parameters $this->id = $this->getParameter('id', 'int'); $this->gallery_id = $this->getParameter('gallery_id', 'int'); // does the item exist if ($this->id !== null && BackendSlideshowModel::existsImage($this->id)) { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // delete item BackendSlideshowModel::deleteImage($this->id); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_delete_image', array('id' => $this->id)); // item was deleted, so redirect $this->redirect(BackendModel::createURLForAction('Edit') . '&report=deleted&var=' . '&id=' . $this->gallery_id . '#images'); } else { // something went wrong $this->redirect(BackendModel::createURLForAction('Index') . '&error=non-existing'); } }
/** * Execute the action * * @return void */ public function execute() { // get parameters $this->id = $this->getParameter('id', 'int'); // does the item exist if ($this->id !== null && BackendSlideshowModel::existsCategory($this->id)) { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // get item $this->record = BackendSlideshowModel::getCategory($this->id); // delete item BackendSlideshowModel::deleteCategory($this->id); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_delete_category', array('id' => $this->id)); // item was deleted, so redirect $this->redirect(BackendModel::createURLForAction('Categories') . '&report=deleted&var=' . urlencode($this->record['title'])); } else { // something went wrong $this->redirect(BackendModel::createURLForAction('Categories') . '&error=non-existing'); } }
/** * 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')); $this->frm->getField('categories')->isFilled(BL::err('CategoryIsRequired')); if ($this->frm->getField('width')->isFilled(BL::err('WidthIsRequired'))) { $this->frm->getField('width')->isNumeric(BL::err('NumericCharactersOnly')); } if ($this->frm->getField('height')->isFilled()) { $this->frm->getField('height')->isNumeric(BL::err('NumericCharactersOnly')); } $this->frm->getField('publish_on_date')->isValid(BL::getError('DateIsInvalid')); $this->frm->getField('publish_on_time')->isValid(BL::getError('TimeIsInvalid')); if ($this->frm->getField('filename')->isFilled()) { // correct extension? if ($this->frm->getField('filename')->isAllowedExtension(array('jpg', 'jpeg', 'gif', 'png'), BL::err('JPGGIFAndPNGOnly'))) { // correct mimetype? $this->frm->getField('filename')->isAllowedMimeType(array('image/gif', 'image/jpg', 'image/jpeg', 'image/png'), BL::err('JPGGIFAndPNGOnly')); } } // validate meta $this->meta->validate(); // no errors? if ($this->frm->isCorrect()) { // build item $item['user_id'] = BackendAuthentication::getUser()->getUserId(); $item['meta_id'] = $this->meta->save(); $item['category_id'] = $this->frm->getField('categories')->getValue(); $item['language'] = BL::getWorkingLanguage(); $item['title'] = $this->frm->getField('title')->getValue(); $item['width'] = $this->frm->getField('width')->getValue(); $item['height'] = $this->frm->getField('height')->getValue(); // set height to null if empty if (empty($item['height'])) { $item['height'] = null; } $item['description'] = $this->frm->getField('description')->getValue(true); if ($this->frm->getField('filename')->isFilled()) { // create new filename $filename = $this->meta->getURL(); $filename .= '-' . uniqid(); $filename .= '-' . BL::getWorkingLanguage(); $filename .= '.' . $this->frm->getField('filename')->getExtension(); $item['filename'] = $filename; // create thumbnail $this->frm->getField('filename')->createThumbnail(FRONTEND_FILES_PATH . '/slideshow/thumbnails/' . $filename, 100, 100, false, false, 100); // @todo fix this $this->frm->getField('filename')->moveFile(FRONTEND_FILES_PATH . '/slideshow/' . $filename); } $item['hidden'] = $this->frm->getField('hidden')->getValue(); $item['sequence'] = BackendSlideshowModel::getMaximumGallerySequence($this->frm->getField('categories')->getValue()) + 1; $item['created_on'] = BackendModel::getUTCDate(); $item['publish_on'] = BackendModel::getUTCDate(null, BackendModel::getUTCTimestamp($this->frm->getField('publish_on_date'), $this->frm->getField('publish_on_time'))); // insert the item $id = BackendSlideshowModel::insertGallery($item); // insert default settings BackendSlideshowModel::setSettings($id, $this->get('fork.settings')->getForModule('Slideshow')); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $item)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('AddImage') . '&report=added&id=' . $id); } } }
/** * 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 all images for ($i = 0; $i < $this->imageUploadFields; $i++) { // validate fields if ($this->frm->getField('image' . $i)->isFilled()) { // correct extension if ($this->frm->getField('image' . $i)->isAllowedExtension(array('jpg', 'jpeg', 'gif', 'png'), BL::err('JPGGIFAndPNGOnly'))) { // correct mimetype? $this->frm->getField('image' . $i)->isAllowedMimeType(array('image/gif', 'image/jpg', 'image/jpeg', 'image/png'), BL::err('JPGGIFAndPNGOnly')); } } } // no errors? if ($this->frm->isCorrect()) { // build item $item['language'] = $this->record['language']; $item['gallery_id'] = $this->id; for ($i = 0; $i < $this->imageUploadFields; $i++) { if ($this->frm->getField('image' . $i)->isFilled()) { // get the sequence everytime $item['sequence'] = BackendSlideshowModel::getMaximumImageSequence($this->id) + 1; // create new filename $filename = time() . $i . "." . $this->frm->getField('image' . $i)->getExtension(); // add filename to item $item['filename'] = $filename; // If height is not set, scale the image proportionally to the given width if ($this->record['height'] != 0) { // upload image width gallery dimensions $this->frm->getField('image' . $i)->createThumbnail(FRONTEND_FILES_PATH . '/slideshow/' . $filename, $this->record['width'], $this->record['height'], true, false, 100); } else { $this->frm->getField('image' . $i)->createThumbnail(FRONTEND_FILES_PATH . '/slideshow/' . $filename, $this->record['width'], null, true, true, 100); } // create thumbnail for later use $this->frm->getField('image' . $i)->createThumbnail(FRONTEND_FILES_PATH . '/slideshow/thumbnails/' . $filename, 100, 100, false, false, 100); // insert image values in database BackendSlideshowModel::insertImage($item); } } // trigger event BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $item)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('Edit') . '&report=saved&var=' . '&id=' . $this->id . '#images'); } } }
/** * 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 if ($this->frm->getField('filename')->isFilled()) { // correct extension? if ($this->frm->getField('filename')->isAllowedExtension(array('jpg', 'jpeg', 'gif', 'png'), BL::err('JPGGIFAndPNGOnly'))) { // correct mimetype? $this->frm->getField('filename')->isAllowedMimeType(array('image/gif', 'image/jpg', 'image/jpeg', 'image/png'), BL::err('JPGGIFAndPNGOnly')); } } // no errors? if ($this->frm->isCorrect()) { // build item $item['id'] = $this->id; $item['language'] = $this->record['language']; $item['title'] = $this->frm->getField('title')->getValue(); $item['caption'] = $this->frm->getField('caption')->getValue(true); $item['hidden'] = $this->frm->getField('hidden')->getValue(); // get module settings $dimensions = $this->get('fork.settings')->getForModule('Slideshow'); // the extra data $data = array('link' => null); // links if ($this->frm->getField('internal_url')->isFilled()) { $data['link'] = array('type' => 'internal', 'id' => $this->frm->getField('internal_url')->getValue()); } // external links if ($this->frm->getField('external_link')->getChecked()) { $data['link'] = array('type' => 'external', 'url' => $this->frm->getField('external_url')->getValue()); } $item['data'] = serialize($data); if ($this->frm->getField('filename')->isFilled()) { // only delete the picture when there is one allready if (!empty($this->record['filename'])) { $fs = new Filesystem(); $fs->remove(FRONTEND_FILES_PATH . '/slideshow/thumbnails/' . $this->record['filename']); $fs->remove(FRONTEND_FILES_PATH . '/slideshow/' . $this->record['filename']); } // create new filename $filename = time() . "." . $this->frm->getField('filename')->getExtension(); // add filename to item $item['filename'] = $filename; // If height is not set, scale the image proportionally to the given width if ($this->gallery['height'] != 0) { // upload image width gallery dimensions $this->frm->getField('filename')->createThumbnail(FRONTEND_FILES_PATH . '/slideshow/' . $filename, $this->gallery['width'], $this->gallery['height'], true, false, 100); } else { $this->frm->getField('filename')->createThumbnail(FRONTEND_FILES_PATH . '/slideshow/' . $filename, $this->gallery['width'], null, true, true, 100); } // create thumbnail $this->frm->getField('filename')->createThumbnail(FRONTEND_FILES_PATH . '/slideshow/thumbnails/' . $filename, 100, 100, false, false, 100); } // update image values in database BackendSlideshowModel::updateImage($item); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $item)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('Edit') . '&report=Saved&id=' . $this->galleryId . '&highlight=' . $this->id . '#images'); } } }
/** * 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')); $this->frm->getField('publish_on_date')->isValid(BL::err('DateIsInvalid')); $this->frm->getField('publish_on_time')->isValid(BL::err('TimeIsInvalid')); if ($this->frm->getField('width')->isFilled(BL::err('WidthIsRequired'))) { $this->frm->getField('width')->isNumeric(BL::err('NumericCharactersOnly')); } if ($this->frm->getField('height')->isFilled()) { $this->frm->getField('height')->isNumeric(BL::err('NumericCharactersOnly')); } if ($this->frm->getField('filename')->isFilled()) { // correct extension? if ($this->frm->getField('filename')->isAllowedExtension(array('jpg', 'jpeg', 'gif', 'png'), BL::err('JPGGIFAndPNGOnly'))) { // correct mimetype? $this->frm->getField('filename')->isAllowedMimeType(array('image/gif', 'image/jpg', 'image/jpeg', 'image/png'), BL::err('JPGGIFAndPNGOnly')); } } $this->frm->getField('categories')->isFilled(BL::err('CategoryIsRequired')); $this->meta->validate(); // no errors? if ($this->frm->isCorrect()) { //build settings item $settings['animation'] = $this->frm->getField('animation')->getValue(); $settings['direction'] = $this->frm->getField('direction')->getValue(); $settings['slideshow_speed'] = $this->frm->getField('slideshow_speed')->getValue(); $settings['animation_speed'] = $this->frm->getField('animation_speed')->getValue(); $settings['direction_navigation'] = $this->frm->getField('direction_navigation')->getChecked() ? 'true' : 'false'; $settings['control_navigation'] = $this->frm->getField('control_navigation')->getChecked() ? 'true' : 'false'; $settings['thumbnail_navigation'] = $this->frm->getField('thumbnail_navigation')->getChecked() ? 'true' : ''; $settings['keyboard'] = $this->frm->getField('keyboard')->getChecked() ? 'true' : 'false'; $settings['mousewheel'] = $this->frm->getField('mousewheel')->getChecked() ? 'true' : 'false'; $settings['touch'] = $this->frm->getField('touch')->getChecked() ? 'true' : 'false'; $settings['randomize'] = $this->frm->getField('randomize')->getChecked() ? 'true' : 'false'; $settings['auto_animate'] = $this->frm->getField('auto_animate')->getChecked() ? 'true' : 'false'; $settings['animation_loop'] = $this->frm->getField('animation_loop')->getChecked() ? 'true' : 'false'; // update settings BackendSlideshowModel::setSettings($this->id, $settings); // build item $item['id'] = $this->id; $item['meta_id'] = $this->meta->save(true); $item['language'] = $this->record['language']; $item['category_id'] = $this->frm->getField('categories')->getValue(); $item['title'] = $this->frm->getField('title')->getValue(); $item['description'] = $this->frm->getField('description')->getValue(true); $item['width'] = $this->frm->getField('width')->getValue(); $item['height'] = $this->frm->getField('height')->getValue(); // set height to null if empty if (empty($item['height'])) { $item['height'] = null; } $item['publish_on'] = BackendModel::getUTCDate(null, BackendModel::getUTCTimestamp($this->frm->getField('publish_on_date'), $this->frm->getField('publish_on_time'))); $item['edited_on'] = BackendModel::getUTCDate(); $item['hidden'] = $this->frm->getField('hidden')->getValue(); // check if the category was changed if (!BackendSlideshowModel::getChangeCategory($this->id, $item['category_id'])) { // if so, adjust the sequence to the new category $item['sequence'] = BackendSlideshowModel::getMaximumGallerySequence($this->frm->getField('categories')->getValue()) + 1; } // if the image should be deleted if ($this->frm->getField('delete_image')->isChecked()) { $fs = new Filesystem(); // delete the image $fs->remove(FRONTEND_FILES_PATH . '/slideshow/' . $this->record['filename']); //delete thumbnail $fs->remove(FRONTEND_FILES_PATH . '/slideshow/thumbnails/' . $this->record['filename']); // reset the name $item['filename'] = null; } if ($this->frm->getField('filename')->isFilled()) { // only delete the picture when there is one allready if (!empty($this->record['filename'])) { $fs = new Filesystem(); // delete the image $fs->remove(FRONTEND_FILES_PATH . '/slideshow/' . $this->record['filename']); //delete thumbnail $fs->remove(FRONTEND_FILES_PATH . '/slideshow/thumbnails/' . $this->record['filename']); } // create new filename $filename = $this->meta->getURL(); $filename .= '-' . uniqid(); $filename .= '-' . BL::getWorkingLanguage(); $filename .= '.' . $this->frm->getField('filename')->getExtension(); // add filename to item $item['filename'] = $filename; // create thumbnail $this->frm->getField('filename')->createThumbnail(FRONTEND_FILES_PATH . '/slideshow/thumbnails/' . $filename, 100, 100, false, false, 100); // @todo fix this $this->frm->getField('filename')->moveFile(FRONTEND_FILES_PATH . '/slideshow/' . $filename); } // update gallery values in database BackendSlideshowModel::updateGallery($item); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $item)); // get the gallery data $item = BackendSlideshowModel::getGallery($this->id); // trace the action and get the ids $action = $this->frm->getField('action')->getValue(); $ids = (array) $_POST['id']; // Mass image delete action if ($action == 'delete') { foreach ($ids as $id) { // double check if the image exists if ($id !== null && BackendSlideshowModel::existsImage($id)) { // get item $this->record = BackendSlideshowModel::getImage($id); $fs = new Filesystem(); // delete the image and thumbnail $fs->remove(FRONTEND_FILES_PATH . '/slideshow/thumbnails/' . $this->record['filename']); $fs->remove(FRONTEND_FILES_PATH . '/slideshow/' . $this->record['filename']); // delete item BackendSlideshowModel::deleteImage($this->record['id']); } } // redirect to edit, tab "images $this->redirect(BackendModel::createURLForAction('Edit') . '&report=deleted&id=' . $this->id . '#images'); } elseif ($action == 'publish') { // set new status BackendSlideshowModel::updatePublishedImage($ids); // redirect to edit, tab #images $this->redirect(BackendModel::createURLForAction('Edit') . '&report=saved&id=' . $this->id . '#images'); } elseif ($action == 'hide') { // set new status BackendSlideshowModel::updateHiddenImage($ids); // redirect to edit, tab #images $this->redirect(BackendModel::createURLForAction('Edit') . '&report=saved&id=' . $this->id . '#images'); } // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('Index') . '&report=saved&var=' . urlencode($item['title']) . '&highlight=' . $item['id']); } } }