Inheritance: extends Common\Core\Model
 /**
  * Execute the action
  */
 public function execute()
 {
     // If step 1 isn't entered, redirect back to the first step of the wizard
     $this->record = \SpoonSession::get('module');
     if (!$this->record || !array_key_exists('title', $this->record)) {
         $this->redirect(Model::createURLForAction('Add'));
     }
     // If there are no fields added, redirect back to the second step of the wizard
     if (!array_key_exists('fields', $this->record) || empty($this->record['fields'])) {
         $this->redirect(Model::createURLForAction('AddStep2'));
     }
     parent::execute();
     // initialize some variables
     $this->backendPath = BACKEND_MODULES_PATH . '/' . $this->record['camel_case_name'] . '/';
     $this->frontendPath = FRONTEND_MODULES_PATH . '/' . $this->record['camel_case_name'] . '/';
     $this->variables = (array) $this->record;
     unset($this->variables['fields']);
     $this->generateFolders();
     $this->generateBaseFiles();
     $this->generateInstallerFiles();
     // Backend
     $this->generateBackendFiles();
     $this->generateBackendModel();
     $this->generateBackendActions();
     $this->generateBackendCategoryActions();
     // Frontend
     $this->generateFrontendFiles();
     $this->generateFrontendModel();
     $this->generateFrontendActions();
     $this->generateFrontendCategoryActions();
     $this->generateFrontendCategoryWidget();
     $this->parse();
     $this->display();
 }
Example #2
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     BackendAuthentication::logout();
     // redirect to login-screen
     $this->redirect(BackendModel::createURLForAction('Index', $this->getModule()));
 }
Example #3
0
 /**
  * Validates the settings form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         if ($this->frm->isCorrect()) {
             // set the base values
             $width = (int) $this->frm->getField('width_widget')->getValue();
             $height = (int) $this->frm->getField('height_widget')->getValue();
             if ($width > 800) {
                 $width = 800;
             } elseif ($width < 300) {
                 $width = $this->get('fork.settings')->get('Location', 'width_widget');
             }
             if ($height < 150) {
                 $height = $this->get('fork.settings')->get('Location', 'height_widget');
             }
             // set our settings (widgets)
             $this->get('fork.settings')->set($this->URL->getModule(), 'zoom_level_widget', (string) $this->frm->getField('zoom_level_widget')->getValue());
             $this->get('fork.settings')->set($this->URL->getModule(), 'width_widget', $width);
             $this->get('fork.settings')->set($this->URL->getModule(), 'height_widget', $height);
             $this->get('fork.settings')->set($this->URL->getModule(), 'map_type_widget', (string) $this->frm->getField('map_type_widget')->getValue());
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_saved_settings');
             // redirect to the settings page
             $this->redirect(BackendModel::createURLForAction('Settings') . '&report=saved');
         }
     }
 }
Example #4
0
 /**
  * Loops all backend modules, and builds a list of those that have an
  * api.php file in their engine.
  */
 protected function loadModules()
 {
     $modules = BackendModel::getModules();
     foreach ($modules as &$module) {
         // class names of the API file are always based on the name o/t module
         $className = 'Backend\\Modules\\' . $module . '\\Engine\\Api';
         if ($module == 'Core') {
             $className = 'Backend\\Core\\Engine\\Api';
         }
         /*
          * check if the api.php file exists for this module, and load it so our methods are
          * accessible by the Reflection API.
          */
         if (!class_exists($className)) {
             continue;
         }
         $methods = get_class_methods($className);
         // we will need the parameters + PHPDoc to generate our text fields
         foreach ($methods as $key => $method) {
             $methods[$key] = array('name' => $method, 'parameters' => $this->loadParameters($className, $method));
         }
         // properly format so an iteration can do the work for us
         $this->modules[] = array('name' => $module, 'methods' => $methods);
     }
 }
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // validate fields
         $this->meta->validate();
         if ($this->frm->isCorrect()) {
             // build item
             $item['language'] = BL::getWorkingLanguage();
             $item['meta_id'] = $this->meta->save();
             $item['sequence'] = BackendCatalogModel::getMaximumSpecificationSequence() + 1;
             // save the data
             $item['id'] = BackendCatalogModel::insertSpecification($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();
                 BackendCatalogModel::insertSpecificationLanguage($itemLanguage);
             }
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add_specification', array('item' => $item));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('specifications') . '&report=added-specification&var=' . urlencode($this->frm->getField('title_nl')->getValue()) . '&highlight=row-' . $item['id']);
         }
     }
 }
Example #6
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     // action to execute
     $action = \SpoonFilter::getGetValue('action', array('delete'), '');
     // form id
     $formId = \SpoonFilter::getGetValue('form_id', null, '', 'int');
     // no id's provided
     if (!isset($_GET['id'])) {
         $this->redirect(BackendModel::createURLForAction('Index') . '&error=no-items-selected');
     } elseif ($action == '') {
         // no action provided
         $this->redirect(BackendModel::createURLForAction('Index') . '&error=no-action-selected');
     } elseif (!BackendFormBuilderModel::exists($formId)) {
         // valid form id
         $this->redirect(BackendModel::createURLForAction('Index') . '&error=non-existing');
     } else {
         // redefine id's
         $ids = (array) $_GET['id'];
         // delete comment(s)
         if ($action == 'delete') {
             BackendFormBuilderModel::deleteData($ids);
         }
         // define report
         $report = count($ids) > 1 ? 'items-' : 'item-';
         // init var
         if ($action == 'delete') {
             $report .= 'deleted';
         }
         // redirect
         $this->redirect(BackendModel::createURLForAction('Data') . '&id=' . $formId . '&report=' . $report);
     }
 }
Example #7
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     BackendCatalogModel::deleteSpamComments();
     // item was deleted, so redirect
     $this->redirect(BackendModel::createURLForAction('comments') . '&report=deleted-spam#tabSpam');
 }
Example #8
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         $fields = $this->frm->getFields();
         // validate fields
         $fields['title']->isFilled(BL::err('TitleIsRequired'));
         if ($this->frm->isCorrect()) {
             // build item
             $item['id'] = BackendContentBlocksModel::getMaximumId() + 1;
             $item['user_id'] = BackendAuthentication::getUser()->getUserId();
             $item['template'] = count($this->templates) > 1 ? $fields['template']->getValue() : $this->templates[0];
             $item['language'] = BL::getWorkingLanguage();
             $item['title'] = $fields['title']->getValue();
             $item['text'] = $fields['text']->getValue();
             $item['hidden'] = $fields['hidden']->getValue() ? 'N' : 'Y';
             $item['status'] = 'active';
             $item['created_on'] = BackendModel::getUTCDate();
             $item['edited_on'] = BackendModel::getUTCDate();
             // insert the item
             $item['revision_id'] = BackendContentBlocksModel::insert($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $item));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('Index') . '&report=added&var=' . urlencode($item['title']) . '&highlight=row-' . $item['id']);
         }
     }
 }
Example #9
0
 /**
  * Validate the form
  */
 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 field
         $this->frm->getField('synonym')->isFilled(BL::err('SynonymIsRequired'));
         $this->frm->getField('term')->isFilled(BL::err('TermIsRequired'));
         if (BackendSearchModel::existsSynonymByTerm($this->frm->getField('term')->getValue())) {
             $this->frm->getField('term')->addError(BL::err('TermExists'));
         }
         // no errors?
         if ($this->frm->isCorrect()) {
             // build item
             $item = array();
             $item['term'] = $this->frm->getField('term')->getValue();
             $item['synonym'] = $this->frm->getField('synonym')->getValue();
             $item['language'] = BL::getWorkingLanguage();
             // insert the item
             $id = BackendSearchModel::insertSynonym($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add_synonym', array('item' => $item));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('Synonyms') . '&report=added-synonym&var=' . rawurlencode($item['term']) . '&highlight=row-' . $id);
         }
     }
 }
Example #10
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     BackendAgendaModel::deleteSubscribedSubscriptions();
     // item was deleted, so redirect
     $this->redirect(BackendModel::createURLForAction('subscriptions') . '&report=deleted-subscribed#tabSubscribed');
 }
Example #11
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     BackendCatalogModel::deleteCompletedOrders();
     // item was deleted, so redirect
     $this->redirect(BackendModel::createURLForAction('orders') . '&report=deleted-completed#tabCompleted');
 }
Example #12
0
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $fields = $this->frm->getFields();
         $fields['title']->isFilled(BL::err('TitleIsRequired'));
         if ($this->frm->isCorrect()) {
             $item = [];
             $item['title'] = $fields['title']->getValue();
             $item['capacity'] = $fields['capacity']->getValue();
             $item['price'] = $fields['price']->getValue();
             $item['count'] = $fields['count']->getValue();
             $item['image'] = null;
             $item['hotel_id'] = $this->id;
             if ($fields['image']->isFilled()) {
                 // the image path
                 $imagePath = FRONTEND_FILES_PATH . '/rooms/images';
                 // create folders if needed
                 $fs = new Filesystem();
                 $fs->mkdir(array($imagePath . '/source', $imagePath . '/128x128'));
                 $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']);
             }
             $item['id'] = BackendHotelsModel::insertRecord('hotels_rooms', $item);
             $this->redirect(BackendModel::createURLForAction('Rooms') . '&id=' . $this->id . '&report=added&var=' . urlencode($item['title']) . '&highlight=row-' . $item['id']);
         }
     }
 }
Example #13
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     // action to execute
     $action = SpoonFilter::getGetValue('action', array('deleteImages', 'deleteFiles', 'deleteVideos'), 'delete');
     if (!isset($_GET['id'])) {
         $this->redirect(BackendModel::createURLForAction('index') . '&error=no-selection');
     } else {
         // redefine id's
         $aIds = (array) $_GET['id'];
         $agendaID = (int) $_GET['agenda_id'];
         // delete media
         if ($action == 'deleteImages') {
             BackendAgendaModel::deleteImage($aIds);
         } else {
             if ($action == 'deleteFiles') {
                 BackendAgendaModel::deleteFile($aIds);
             } else {
                 if ($action == 'deleteVideos') {
                     BackendAgendaModel::deleteVideo($aIds);
                 }
             }
         }
     }
     $this->redirect(BackendModel::createURLForAction('media') . '&agenda_id=' . $agendaID . '&report=deleted');
 }
 /**
  * Validate the form
  */
 protected function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // Validation
         $fields = $this->frm->getFields();
         $fields['username']->isFilled(Language::err('FieldIsRequired'));
         if ($this->frm->isCorrect()) {
             // Build the item
             $item['username'] = $fields['username']->getValue();
             // Lookup user id
             $userObj = Helper::searchUser($item['username']);
             if (isset($userObj->data)) {
                 $userId = $userObj->data[0]->id;
                 $item['user_id'] = $userId;
             } else {
                 $this->redirect(Model::createURLForAction('Index') . '&error=api_error');
             }
             // Insert it
             $item['id'] = BackendInstagramModel::insert($item);
             Model::triggerEvent($this->getModule(), 'after_add', $item);
             $this->redirect(Model::createURLForAction('Index') . '&report=added&highlight=row-' . $item['id']);
         }
     }
 }
 /**
  * Validate the form
  */
 protected function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         $frmFields = $this->frm->getFields();
         // validate form
         if ($frmFields['twitter']->isChecked()) {
             // we need fields when search is ticked
             $frmFields['twitter_name']->isFilled(Language::err('FieldIsRequired'));
         }
         if ($this->frm->isCorrect()) {
             // if this field is checked, let's add a boolean searchable true to the chosen fields
             if ($frmFields['twitter']->isChecked()) {
                 $this->record['twitter'] = $frmFields['twitter_name']->getValue();
             } else {
                 if (array_key_exists('twitter', $this->record)) {
                     unset($this->record['twitter']);
                 }
             }
             // save the object in our session
             \SpoonSession::set('module', $this->record);
             $this->redirect(Model::createURLForAction('Generate'));
         }
     }
 }
Example #16
0
 /**
  * Execute the action
  */
 public function execute()
 {
     // get parameters
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id !== null && BackendBlogModel::exists($this->id)) {
         // call parent, this will probably add some general CSS/JS or other required files
         parent::execute();
         // set category id
         $this->categoryId = \SpoonFilter::getGetValue('category', null, null, 'int');
         if ($this->categoryId == 0) {
             $this->categoryId = null;
         }
         // get data
         $this->record = (array) BackendBlogModel::get($this->id);
         // delete item
         BackendBlogModel::delete($this->id);
         // trigger event
         BackendModel::triggerEvent($this->getModule(), 'after_delete', array('id' => $this->id));
         // delete search indexes
         BackendSearchModel::removeIndex($this->getModule(), $this->id);
         // build redirect URL
         $redirectUrl = BackendModel::createURLForAction('Index') . '&report=deleted&var=' . urlencode($this->record['title']);
         // append to redirect URL
         if ($this->categoryId != null) {
             $redirectUrl .= '&category=' . $this->categoryId;
         }
         // item was deleted, so redirect
         $this->redirect($redirectUrl);
     } else {
         // something went wrong
         $this->redirect(BackendModel::createURLForAction('Index') . '&error=non-existing');
     }
 }
Example #17
0
 /**
  * Generate an url, using the predefined callback.
  *
  * @param string $url The base-url to start from.
  * @param string $class The Fully Qualified Class Name or service name
  * @param string $method The method that needs to be called
  * @param array $parameters The parameters for the callback
  *
  * @throws Exception When the function does not exist
  *
  * @return string
  */
 public function generateURL($url, $class, $method, array $parameters = [])
 {
     // check if the class is a service
     if (Model::getContainer()->has($class)) {
         $class = Model::getContainer()->get($class);
     }
     // validate (check if the function exists)
     if (!is_callable([$class, $method])) {
         throw new Exception('The callback-method doesn\'t exist.');
     }
     // when using ->getValue() in SpoonFormText fields the function is using htmlentities(),
     // so we must decode it again first!
     $url = SpoonFilter::htmlentitiesDecode($url);
     $actualParameters = [];
     // build parameters for use in the callback
     $actualParameters[] = Uri::getUrl($url);
     // add parameters set by user
     if (!empty($parameters)) {
         foreach ($parameters as $parameter) {
             $actualParameters[] = $parameter;
         }
     }
     // get the real url
     return call_user_func_array([$class, $method], $actualParameters);
 }
Example #18
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']);
     }
 }
Example #19
0
 /**
  * Create the XML based on the locale items.
  */
 public function getContent()
 {
     $charset = BackendModel::getContainer()->getParameter('kernel.charset');
     // create XML
     $xmlOutput = BackendLocaleModel::createXMLForExport($this->locale);
     return new Response($xmlOutput, Response::HTTP_OK, ['Content-Disposition' => 'attachment; filename="locale_' . BackendModel::getUTCDate('d-m-Y') . '.xml"', 'Content-Type' => 'application/octet-stream;charset=' . $charset, 'Content-Length' => '' . mb_strlen($xmlOutput)]);
 }
 /**
  * Retrieve the unique URL for an teamMember
  *
  * @param string $url
  * @param int $id The id of the teamMember to ignore.
  * @return string
  */
 public static function getUrl($url, $id = null)
 {
     $url = CommonUri::getUrl((string) $url);
     $database = BackendModel::get('database');
     if ($id === null) {
         $urlExists = (bool) $database->getVar('SELECT 1
                FROM team_members AS i
                     INNER JOIN meta AS m
                     ON i.meta_id = m.id
               WHERE i.language = ? AND m.url = ?
               LIMIT 1', [Language::getWorkingLanguage(), $url]);
     } else {
         $urlExists = (bool) $database->getVar('SELECT 1
                FROM team_members AS i
                     INNER JOIN meta AS m
                     ON i.meta_id = m.id
               WHERE i.language = ? AND m.url = ? AND i.id != ?
               LIMIT 1', [Language::getWorkingLanguage(), $url, $id]);
     }
     if ($urlExists) {
         $url = Model::addNumber($url);
         return self::getUrl($url, $id);
     }
     return $url;
 }
Example #21
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // get fields
         $ddmGroup = $this->frm->getField('group');
         $fileFile = $this->frm->getField('file');
         $csv = array();
         // validate input
         $ddmGroup->isFilled(BL::getError('FieldIsRequired'));
         if ($fileFile->isFilled(BL::err('FieldIsRequired'))) {
             if ($fileFile->isAllowedExtension(array('csv'), sprintf(BL::getError('ExtensionNotAllowed'), 'csv'))) {
                 $csv = Csv::fileToArray($fileFile->getTempFileName());
                 if ($csv === false) {
                     $fileFile->addError(BL::getError('InvalidCSV'));
                 }
             }
         }
         if ($this->frm->isCorrect()) {
             // import the profiles
             $overwrite = $this->frm->getField('overwrite_existing')->isChecked();
             $statistics = BackendProfilesModel::importCsv($csv, $ddmGroup->getValue(), $overwrite);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_import', array('statistics' => $statistics));
             // build redirect url with the right message
             $redirectUrl = BackendModel::createURLForAction('index') . '&report=';
             $redirectUrl .= $overwrite ? 'profiles-imported-and-updated' : 'profiles-imported';
             $redirectUrl .= '&var[]=' . $statistics['count']['inserted'];
             $redirectUrl .= '&var[]=' . $statistics['count']['exists'];
             // everything is saved, so redirect to the overview
             $this->redirect($redirectUrl);
         }
     }
 }
 private function validateAuthConfigForm()
 {
     $this->get('fork.settings')->set($this->URL->getModule(), 'client_id', $this->frm->getField('client_id')->getValue());
     $this->get('fork.settings')->set($this->URL->getModule(), 'client_secret', $this->frm->getField('client_secret')->getValue());
     // We need to authenticate, redirect to oauth
     $this->redirect(BackendModel::createURLForAction('oauth'));
 }
Example #23
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']);
         }
     }
 }
Example #24
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');
     }
 }
Example #25
0
 /**
  * Execute the action.
  */
 public function execute()
 {
     // get parameters
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id !== null && BackendProfilesModel::exists($this->id)) {
         // call parent, this will probably add some general CSS/JS or other required files
         parent::execute();
         // get item
         $profile = BackendProfilesModel::get($this->id);
         // already blocked? Prolly want to unblock then
         if ($profile['status'] === 'blocked') {
             // set profile status to active
             BackendProfilesModel::update($this->id, array('status' => 'active'));
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_unblock', array('id' => $this->id));
             // redirect
             $this->redirect(BackendModel::createURLForAction('Index') . '&report=profile-unblocked&var=' . urlencode($profile['email']) . '&highlight=row-' . $this->id);
         } else {
             // delete profile session that may be active
             BackendProfilesModel::deleteSession($this->id);
             // set profile status to blocked
             BackendProfilesModel::update($this->id, array('status' => 'blocked'));
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_block', array('id' => $this->id));
             // redirect
             $this->redirect(BackendModel::createURLForAction('Index') . '&report=profile-blocked&var=' . urlencode($profile['email']) . '&highlight=row-' . $this->id);
         }
     } else {
         $this->redirect(BackendModel::createURLForAction('Index') . '&error=non-existing');
     }
 }
Example #26
0
 /**
  * Execute the action
  */
 public function execute()
 {
     // get parameters
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id !== null && BackendExtensionsModel::existsTemplate($this->id)) {
         // call parent, this will probably add some general CSS/JS or other required files
         parent::execute();
         // init var
         $success = false;
         // get template (we need the title)
         $item = BackendExtensionsModel::getTemplate($this->id);
         // valid template?
         if (!empty($item)) {
             // delete the page
             $success = BackendExtensionsModel::deleteTemplate($this->id);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_delete_template', array('id' => $this->id));
         }
         // page is deleted, so redirect to the overview
         if ($success) {
             $this->redirect(BackendModel::createURLForAction('ThemeTemplates') . '&theme=' . $item['theme'] . '&report=deleted-template&var=' . urlencode($item['label']));
         } else {
             $this->redirect(BackendModel::createURLForAction('ThemeTemplates') . '&error=non-existing');
         }
     } else {
         // something went wrong
         $this->redirect(BackendModel::createURLForAction('ThemeTemplates') . '&error=non-existing');
     }
 }
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     // Get api key
     $this->apiKey = BackendModel::getModuleSetting($this->getModule(), 'api_key', null);
     // Get uncompressed images list
     $this->images = BackendCompressionModel::getImagesFromFolders();
     if (!empty($this->images)) {
         // Compress each image from each folder
         $output = 'Compressing ' . count($this->images) . ' images...' . "<br />\r\n";
         BackendCompressionModel::writeToCacheFile($output, true);
         foreach ($this->images as $image) {
             $tinyPNGApi = new TinyPNGApi($this->apiKey);
             // Shrink the image and check if succesful
             if ($tinyPNGApi->shrink($image['full_path'])) {
                 // Check if the file was successfully downloaded.
                 if ($tinyPNGApi->download($image['full_path'])) {
                     $output = 'Compression succesful for image ' . $image['filename'] . '. Saved ' . number_format($tinyPNGApi->getSavingSize() / 1024, 2) . ' KB' . ' bytes. (' . $tinyPNGApi->getSavingPercentage() . '%)';
                     BackendCompressionModel::writeToCacheFile($output);
                     // Save to db
                     $imageInfo = array('filename' => $image['filename'], 'path' => $image['full_path'], 'original_size' => $tinyPNGApi->getInputSize(), 'compressed_size' => $tinyPNGApi->getOutputSize(), 'saved_bytes' => $tinyPNGApi->getSavingSize(), 'saved_percentage' => $tinyPNGApi->getSavingPercentage(), 'checksum_hash' => sha1_file($image['full_path']), 'compressed_on' => BackendModel::getUTCDate());
                     BackendCompressionModel::insertImageHistory($imageInfo, $image['file_compressed_before']);
                 }
             } else {
                 BackendCompressionModel::writeToCacheFile($tinyPNGApi->getErrorMessage());
             }
         }
         BackendCompressionModel::writeToCacheFile("...Done!");
     } else {
         BackendCompressionModel::writeToCacheFile('There are no images that can be compressed.', true);
     }
     // Print the output for debug purposes
     $output = BackendCompressionModel::readCacheFile();
     print $output;
 }
Example #28
0
 /**
  * @return bool
  */
 private function isValid()
 {
     $fields = $this->form->getFields();
     if (!$fields['start_date']->isFilled(Language::err('FieldIsRequired')) || !$fields['end_date']->isFilled(Language::err('FieldIsRequired'))) {
         return $this->form->isCorrect();
     }
     if (!$fields['start_date']->isValid(Language::err('DateIsInvalid')) || !$fields['end_date']->isValid(Language::err('DateIsInvalid'))) {
         return $this->form->isCorrect();
     }
     $newStartDate = Model::getUTCTimestamp($fields['start_date']);
     $newEndDate = Model::getUTCTimestamp($fields['end_date']);
     // startdate cannot be before 2005 (earliest valid google startdate)
     if ($newStartDate < mktime(0, 0, 0, 1, 1, 2005)) {
         $fields['start_date']->setError(Language::err('DateRangeIsInvalid'));
     }
     // enddate cannot be in the future
     if ($newEndDate > time()) {
         $fields['start_date']->setError(Language::err('DateRangeIsInvalid'));
     }
     // enddate cannot be before the startdate
     if ($newStartDate > $newEndDate) {
         $fields['start_date']->setError(Language::err('DateRangeIsInvalid'));
     }
     return $this->form->isCorrect();
 }
 /**
  * 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') . '&amp;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') . '&amp;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());
     }
 }
Example #30
0
 /**
  * Execute the action
  */
 public function execute()
 {
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id !== null && BackendBlogModel::existsCategory($this->id)) {
         // get data
         $this->record = (array) BackendBlogModel::getCategory($this->id);
         // allowed to delete the category?
         if (BackendBlogModel::deleteCategoryAllowed($this->id)) {
             // call parent, this will probably add some general CSS/JS or other required files
             parent::execute();
             // delete item
             BackendBlogModel::deleteCategory($this->id);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_delete_category', array('id' => $this->id));
             // category was deleted, so redirect
             $this->redirect(BackendModel::createURLForAction('Categories') . '&report=deleted-category&var=' . rawurlencode($this->record['title']));
         } else {
             $this->redirect(BackendModel::createURLForAction('Categories') . '&error=delete-category-not-allowed&var=' . rawurlencode($this->record['title']));
         }
     } else {
         // something went wrong
         $this->redirect(BackendModel::createURLForAction('Categories') . '&error=non-existing');
     }
 }