/** * Cancels out of the billboard edit view, makes sure to check the billboard back in for other people to edit * * @return void */ public function cancelTask() { // Incoming - we need an id so that we can check it back in $fields = Request::getVar('billboard', array(), 'post'); // Check the billboard back in $billboard = Billboard::oneOrNew($fields['id']); $billboard->checkin(); // Redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false)); }
/** * Save a billboard * * @return void */ public function saveTask() { // Check for request forgeries Request::checkToken(); if (!User::authorise('core.edit', $this->_option) && !User::authorise('core.create', $this->_option)) { App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR')); } // Incoming, make sure to allow HTML to pass through $data = Request::getVar('billboard', array(), 'post', 'array', JREQUEST_ALLOWHTML); // Create object $billboard = Billboard::oneOrNew($data['id'])->set($data); // Check to make sure collection exists $collection = Collection::oneOrNew($billboard->collection_id); if ($collection->isNew()) { $collection->set('name', 'Default Collection')->save(); $billboard->set('collection_id', $collection->id); } if (!$billboard->save()) { // Something went wrong...return errors foreach ($billboard->getErrors() as $error) { Notify::error($error); } return $this->editTask($billboard); } // See if we have an image coming in as well $billboard_image = Request::getVar('billboard-image', false, 'files', 'array'); // If so, proceed with saving the image if (isset($billboard_image['name']) && $billboard_image['name']) { // Build the upload path if it doesn't exist $image_location = $this->config->get('image_location', 'app' . DS . 'site' . DS . 'media' . DS . 'images' . DS . 'billboards'); $uploadDirectory = PATH_ROOT . DS . trim($image_location, DS) . DS; // Make sure upload directory exists and is writable if (!is_dir($uploadDirectory)) { if (!\Filesystem::makeDirectory($uploadDirectory)) { Notify::error(Lang::txt('COM_BILLBOARDS_ERROR_UNABLE_TO_CREATE_UPLOAD_PATH')); return $this->editTask($billboard); } } // Scan for viruses if (!\Filesystem::isSafe($billboard_image['tmp_name'])) { Notify::error(Lang::txt('COM_BILLBOARDS_ERROR_FAILED_VIRUS_SCAN')); return $this->editTask($billboard); } if (!move_uploaded_file($billboard_image['tmp_name'], $uploadDirectory . $billboard_image['name'])) { Notify::error(Lang::txt('COM_BILLBOARDS_ERROR_FILE_MOVE_FAILED')); return $this->editTask($billboard); } else { if ($old = $billboard->get('background_img')) { if (file_exists($uploadDirectory . $old)) { \Filesystem::delete($uploadDirectory . $old); } } // Move successful, save the image url to the billboard entry $billboard->set('background_img', $billboard_image['name']); if (!$billboard->save()) { Notify::error($billboard->getError()); return $this->editTask($billboard); } } } // Check in the billboard now that we've saved it $billboard->checkin(); // Redirect Notify::success(Lang::txt('COM_BILLBOARDS_BILLBOARD_SUCCESSFULLY_SAVED')); $this->cancelTask(); }