Beispiel #1
0
 /**
  * Determine task and execute it
  *
  * @return  void
  */
 public function execute()
 {
     $row = Quote::oneOrNew(0);
     $this->path = $row->filespace();
     parent::execute();
 }
Beispiel #2
0
 /**
  * Save a success story and show a thank you message
  *
  * @return  void
  */
 public function sendstoryTask()
 {
     if (User::isGuest()) {
         $here = Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=' . $this->_task);
         App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode($here)), Lang::txt('COM_FEEDBACK_STORY_LOGIN'), 'warning');
     }
     Request::checkToken();
     $fields = Request::getVar('fields', array(), 'post');
     $fields = array_map('trim', $fields);
     $fields['user_id'] = User::get('id');
     // Initiate class and bind posted items to database fields
     $row = Quote::oneOrNew(0)->set($fields);
     // Check that a story was entered
     if (!$row->get('quote')) {
         $this->setError(Lang::txt('COM_FEEDBACK_ERROR_MISSING_STORY'));
         return $this->storyTask($row);
     }
     // Check for an author
     if (!$row->get('fullname')) {
         $this->setError(Lang::txt('COM_FEEDBACK_ERROR_MISSING_AUTHOR'));
         return $this->storyTask($row);
     }
     // Check for an organization
     if (!$row->get('org')) {
         $this->setError(Lang::txt('COM_FEEDBACK_ERROR_MISSING_ORGANIZATION'));
         return $this->storyTask($row);
     }
     // Code cleaner for xhtml transitional compliance
     $row->set('quote', Sanitize::stripAll($row->get('quote')));
     $row->set('quote', str_replace('<br>', '<br />', $row->get('quote')));
     $row->set('date', Date::toSql());
     // Store new content
     if (!$row->save()) {
         $this->setError($row->getError());
         return $this->storyTask($row);
     }
     $addedPictures = array();
     $path = $row->filespace() . DS . $row->get('id');
     if (!is_dir($path)) {
         if (!Filesystem::makeDirectory($path)) {
             $this->setError(Lang::txt('COM_FEEDBACK_ERROR_UNABLE_TO_CREATE_UPLOAD_PATH'));
         }
     }
     // If there is a temp dir for this user then copy the contents to the newly created folder
     $tempDir = $this->tmpPath() . DS . User::get('id');
     if (is_dir($tempDir)) {
         $dirIterator = new DirectoryIterator($tempDir);
         foreach ($dirIterator as $file) {
             if ($file->isDot() || $file->isDir()) {
                 continue;
             }
             $name = $file->getFilename();
             if ($file->isFile()) {
                 if ('cvs' == strtolower($name) || '.svn' == strtolower($name)) {
                     continue;
                 }
                 if (Filesystem::move($tempDir . DS . $name, $path . DS . $name)) {
                     array_push($addedPictures, $name);
                 }
             }
         }
         // Remove temp folder
         Filesystem::deleteDirectory($tempDir);
     }
     $path = substr($row->filespace(), strlen(PATH_ROOT)) . DS . $row->get('id');
     // Set page title
     $this->_buildTitle();
     // Set the pathway
     $this->_buildPathway();
     // Output HTML
     $this->view->set('row', $row)->set('path', $path)->set('addedPictures', $addedPictures)->set('title', $this->_title)->setErrors($this->getErrors())->setLayout('thanks')->display();
 }
Beispiel #3
0
 /**
  * Save an entry
  *
  * @return  void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $fields = Request::getVar('fields', array(), 'post', 'none', 2);
     // Initiate model and bind the incoming data to it
     $row = Quote::oneOrNew($fields['id'])->set($fields);
     // Validate and save the data
     if (!$row->save()) {
         foreach ($row->getErrors() as $error) {
             Notify::error($error);
         }
         return $this->editTask($row);
     }
     // Build file path
     $path = $row->filespace() . DS . $row->get('id');
     if (is_dir($path)) {
         // Remove pictures that were marked for deletion
         $existing = Request::getVar('existingPictures', array(), 'post', 'none', 2);
         $pictures = Filesystem::files($path);
         foreach ($pictures as $picture) {
             $picture = ltrim($picture, DS);
             if (!in_array($picture, $existing)) {
                 if (!Filesystem::delete($path . DS . $picture)) {
                     Notify::error(Lang::txt('Failed to remove picture "%s"', $picture));
                 }
             }
         }
     }
     // Get the list of uploaded files
     $files = Request::getVar('files', null, 'files', 'array');
     if ($files) {
         if (!is_dir($path)) {
             Filesystem::makeDirectory($path);
         }
         foreach ($files['name'] as $fileIndex => $file) {
             Filesystem::upload($files['tmp_name'][$fileIndex], $path . DS . $files['name'][$fileIndex]);
         }
     }
     // Notify the user that the entry was saved
     Notify::success(Lang::txt('COM_FEEDBACK_QUOTE_SAVED', $row->get('fullname')));
     if ($this->_task == 'apply') {
         // Display the edit form
         return $this->editTask($row);
     }
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false));
 }