/** * Download action method * * @param int $id * @return void */ public function download($id) { if ($this->application->isRegistered('phire-media')) { $media = new \Phire\Media\Model\Media(); $media->getById($id); if (isset($media->id)) { $click = new Model\Click(); $click->saveMedia($media->file); $ext = strtolower(substr($media->file, strrpos($media->file, '.') + 1)); $mime = isset($this->mimes[$ext]) ? $this->mimes[$ext] : 'application/octet-stream'; $size = null; if (null !== $this->request->getQuery('size')) { $size = strip_tags($this->request->getQuery('size')); } if (null !== $size && file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/' . $media->library_folder . '/' . $size . '/' . $media->file)) { $file = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/' . $media->library_folder . '/' . $size . '/' . $media->file; } else { $file = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/' . $media->library_folder . '/' . $media->file; } header('Content-Type: ' . $mime); if ($this->request->getQuery('download') == 1) { header('Content-Disposition: attachment; filename="' . $media->file . '"'); } echo file_get_contents($file); } else { if ($this->application->isRegistered('phire-content')) { $controller = new \Phire\Content\Controller\IndexController($this->application, $this->request, $this->response); $controller->error(); } else { $this->error(); } } } }
/** * Save click * * @param Application $application * @return void */ public static function save(Application $application) { if (!$_POST && $application->router()->getController() instanceof \Phire\Content\Controller\IndexController) { $uri = $application->router()->getController()->request()->getRequestUri(); if ($uri != '/favicon.ico') { $click = new Model\Click(); if ($application->router()->getController()->response()->getCode() == 200) { $click->saveContent($uri, 'content'); } else { if ($application->router()->getController()->response()->getCode() == 404) { $click->saveContent($uri, 'error'); } } } } }
/** * Index action method * * @return void */ public function index() { $click = new Model\Click(); if ($this->request->isPost()) { $click->remove($this->request->getPost()); $this->sess->setRequestValue('removed', true); $this->redirect(BASE_PATH . APP_URI . '/clicks'); } else { if ($click->hasPages($this->config->pagination, $this->request->getQuery('filter'))) { $limit = $this->config->pagination; $pages = new Paginator($click->getCount($this->request->getQuery('filter')), $limit); $pages->useInput(true); } else { $limit = null; $pages = null; } $this->prepareView('index.phtml'); $this->view->title = 'ClickTrack'; $this->view->pages = $pages; $this->view->filter = $this->request->getQuery('filter'); $this->view->clicks = $click->getAll($this->request->getQuery('filter'), $limit, $this->request->getQuery('page'), $this->request->getQuery('sort')); $this->send(); } }