public function output(\Pagemill_Data $data, \Pagemill_Stream $stream) { $this->pluginTemplate = "/downloads/downloads.plug.html"; $data = $data->fork(); $downloads = new Model_Download_File(); $downloads->where('siteid = ?', Typeframe::CurrentPage()->siteid()); $data['downloads'] = $downloads; parent::output($data, $stream); }
<?php $query = new Model_Download_File(); $query->where('encodedtitle = ?', pathinfo(Typeframe::CurrentPage()->pathInfo(), PATHINFO_FILENAME)); $query->where('siteid = ?', Typeframe::CurrentPage()->siteid()); $download = $query->getFirst(); if ($download->exists()) { $fullname = TYPEF_DIR . '/files/public/downloads/' . $download['filename']; $extension = pathinfo($download['filename'], PATHINFO_EXTENSION); if (file_exists($fullname) && is_file($fullname)) { $download['downloads'] = $download['downloads'] + 1; $download->save(); header('Pragma: public'); header('Content-Type: application/force-download'); header('Content-Disposition: attachment; filename="' . $download['encodedtitle'] . '.' . $extension . '"'); readfile($fullname); exit; } } http_response_code(404); Typeframe::SetPageTemplate('/404.html');
<?php $downloads = new Model_Download_File(); $downloads->where('siteid = ?', Typeframe::CurrentPage()->siteid()); $pm->setVariable('downloads', $downloads);