/** * Download an attachment * * @return void */ public function downloadTask() { $file = Request::getVar('file', ''); $wishid = Request::getInt('wishid', 0); $wish = new Wish($wishid); // Ensure we have a path if (!$wish->exists() || $wish->isDeleted() || $wish->isWithdrawn()) { throw new Exception(Lang::txt('COM_WISHLIST_FILE_NOT_FOUND'), 404); } $attachment = new Attachment($file, $wishid); // Ensure we have a path if (!$attachment->exists()) { throw new Exception(Lang::txt('COM_WISHLIST_FILE_NOT_FOUND'), 404); } //make sure that file is acceptable type if (!$attachment->isAllowedType()) { throw new Exception(Lang::txt('Unknown file type.'), 404); } // Add PATH_CORE $filename = $attachment->link('file'); // Ensure the file exist if (!file_exists($filename)) { throw new Exception(Lang::txt('COM_WISHLIST_FILE_NOT_FOUND') . ' ' . $filename, 404); } // Initiate a new content server and serve up the file $xserver = new Server(); $xserver->filename($filename); $xserver->disposition('attachment'); $xserver->acceptranges(false); // @TODO fix byte range support if (!$xserver->serve()) { // Should only get here on error throw new Exception(Lang::txt('COM_WISHLIST_SERVER_ERROR'), 500); } else { exit; } return; }
/** * Create an item entry * * @param integer $id Optional ID to use * @return boolean */ public function make($id = null) { if ($this->exists()) { return true; } $id = $id ?: Request::getInt('wishid', 0); $this->_tbl->loadType($id, $this->_type); if ($this->exists()) { return true; } include_once PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'models' . DS . 'wishlist.php'; $wish = new Wish($id); if (!$wish->exists()) { $this->setError(Lang::txt('Wish not found.')); return false; } $this->set('type', $this->_type)->set('object_id', $wish->get('id'))->set('created', $wish->get('proposed'))->set('created_by', $wish->get('proposed_by'))->set('title', $wish->get('subject'))->set('description', $wish->content('clean', 200))->set('url', Route::url($wish->link())); if (!$this->store()) { return false; } return true; }