/** * 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; }
/** * Set and get a specific wish * * @param integer $id Wish ID * @return object */ public function wish($id = null) { if (!$this->_cache['wish'] instanceof Wish || $id !== null && (int) $this->_cache['wish']->get('id') != $id) { $this->_cache['wish'] = null; if ($this->_cache['wishes.list'] instanceof ItemList) { foreach ($this->_cache['wishes.list'] as $key => $wish) { if ((int) $wish->get('id') == $id || (string) $wish->get('alias') == $id) { $this->_cache['wish'] = $wish; break; } } } if (!$this->_cache['wish']) { $this->_cache['wish'] = Wish::getInstance($id, $this->get('scope'), $this->get('scope_id')); } if (!$this->_cache['wish']->exists()) { $this->_cache['wish']->set('scope', $this->get('scope')); $this->_cache['wish']->set('scope_id', $this->get('scope_id')); } } return $this->_cache['wish']; }
/** * 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; }