/** * @Route("category/edit", name="admin/category/edit") * @Access("download: manage categories") * @Request({"id": "int"}) */ public function editCategoryAction($id = 0) { if (!($category = Category::where(compact('id'))->related('files')->first())) { if ($id) { App::abort(404, __('Invalid file id.')); } $category = Category::create(['status' => 1, 'slug' => '']); $category->set('markdown', $this->download->config('markdown')); } return ['$view' => ['title' => $id ? __('Edit category') : __('Add category'), 'name' => 'bixie/download/admin/category.php'], '$data' => ['roles' => array_values(Role::findAll()), 'category' => $category], 'category' => $category]; }
/** * @Route("/{id}", name="id") * @Request({"id": "integer", "key": "string", "pkey": "string"}) * @param integer $id File id * @param string $key session key * @param string $purchaseKey optional purchase key * @return BinaryFileResponse */ public function downloadAction($id, $key, $purchaseKey) { //todo return proper errors if (!($file = File::where(['id = ?', 'status = ?'], [$id, 1])->first())) { App::abort(404, __('File not found.')); } if (!$file->hasAccess(App::user())) { App::abort(403, __('Insufficient User Rights.')); } if (!$this->download->checkDownloadKey($file, $key, $purchaseKey)) { App::abort(400, __('Key not valid.')); } $file->updateDownloadCount(); // Generate response $response = new BinaryFileResponse($file->path); $response->headers->set('Content-Disposition', $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, basename($file->path), mb_convert_encoding(basename($file->path), 'ASCII'))); return $response; }
/** * @Route("/{id}", name="id") * @Request({"id":"int", "category_id":"int"}) */ public function fileAction($id = 0, $category_id = 0) { /** @var File $file */ if (!($file = File::where(['id = ?', 'status = ?'], [$id, '1'])->where(function ($query) { return $query->where('roles IS NULL')->whereInSet('roles', App::user()->roles, false, 'OR'); })->first())) { App::abort(404, __('File not found.')); } $file->setActiveCategory($category_id); App::trigger('bixie.prepare.file', [$file, App::view()]); $file->content = App::content()->applyPlugins($file->content, ['file' => $file, 'markdown' => $file->get('markdown')]); $previous = File::getPrevious($file); $next = File::getNext($file); /** @var Category $category */ if ($category_id && !($category = Category::where(['id = ?', 'status = ?'], [$category_id, '1'])->where(function ($query) { return $query->where('roles IS NULL')->whereInSet('roles', App::user()->roles, false, 'OR'); })->related('files')->first())) { App::abort(404, __('Category not found.')); } if ($breadcrumbs = App::module('bixie/breadcrumbs')) { if ($category_id) { $cat = $category; $crumbs = [['title' => $category->title, 'url' => $category->getUrl()]]; while ($parent_id = $cat->parent_id) { if ($cat = $cat->find($parent_id, true)) { $crumbs[] = ['title' => $cat->title, 'url' => $cat->getUrl()]; } } foreach (array_reverse($crumbs) as $data) { $breadcrumbs->addUrl($data); } } //add file $breadcrumbs->addUrl(['title' => $file->title, 'url' => $file->getUrl()]); } return ['$view' => ['title' => __($file->title), 'name' => 'bixie/download/file.php'], 'download' => $this->download, 'config' => $this->download->config(), 'previous' => $previous, 'next' => $next, 'file' => $file, 'node' => App::node()]; }