From 5e3b2bac28da61363c59f2bddde2210645064183 Mon Sep 17 00:00:00 2001 From: Loic d'Anterroches Date: Tue, 5 Aug 2008 15:44:27 +0200 Subject: [PATCH] Added a download counter. Because we like stats, even if not really reliable :) --- src/IDF/Form/UpdateUpload.php | 1 + src/IDF/Upload.php | 7 ++++++- src/IDF/Views/Download.php | 18 ++++++++++++++++++ src/IDF/conf/views.php | 6 ++++++ src/IDF/templates/downloads/view.html | 4 +++- 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/IDF/Form/UpdateUpload.php b/src/IDF/Form/UpdateUpload.php index 6620faf..a5a47ad 100644 --- a/src/IDF/Form/UpdateUpload.php +++ b/src/IDF/Form/UpdateUpload.php @@ -132,6 +132,7 @@ class IDF_Form_UpdateUpload extends Pluf_Form } // Create the upload $this->upload->summary = trim($this->cleaned_data['summary']); + $this->upload->modif_dtime = gmdate('Y-m-d H:i:s'); $this->upload->update(); $this->upload->batchAssoc('IDF_Tag', $tags); return $this->upload; diff --git a/src/IDF/Upload.php b/src/IDF/Upload.php index 2031fdd..4af3e28 100644 --- a/src/IDF/Upload.php +++ b/src/IDF/Upload.php @@ -137,7 +137,12 @@ class IDF_Upload extends Pluf_Model { if ($this->id == '') { $this->creation_dtime = gmdate('Y-m-d H:i:s'); + $this->modif_dtime = gmdate('Y-m-d H:i:s'); } - $this->modif_dtime = gmdate('Y-m-d H:i:s'); + } + + function getAbsoluteUrl($project) + { + return Pluf::f('url_media').'/upload/'.$project->shortname.'/files/'.$this->file; } } \ No newline at end of file diff --git a/src/IDF/Views/Download.php b/src/IDF/Views/Download.php index acd3ecc..b973b85 100644 --- a/src/IDF/Views/Download.php +++ b/src/IDF/Views/Download.php @@ -77,6 +77,9 @@ class IDF_Views_Download { $prj = $request->project; $upload = Pluf_Shortcuts_GetObjectOr404('IDF_Upload', $match[2]); + if ($upload->project != $prj->id) { + throw new Pluf_HTTP_Error404(); + } $title = sprintf(__('Download %s'), $upload->summary); $form = false; if ($request->method == 'POST' and @@ -111,6 +114,21 @@ class IDF_Views_Download $request); } + /** + * Download a file. + */ + public function download($request, $match) + { + $prj = $request->project; + $upload = Pluf_Shortcuts_GetObjectOr404('IDF_Upload', $match[2]); + if ($upload->project != $prj->id) { + throw new Pluf_HTTP_Error404(); + } + $upload->downloads += 1; + $upload->update(); + return new Pluf_HTTP_Response_Redirect($upload->getAbsoluteUrl($prj)); + } + /** * Submit a new file for download. */ diff --git a/src/IDF/conf/views.php b/src/IDF/conf/views.php index 10741f2..7360263 100644 --- a/src/IDF/conf/views.php +++ b/src/IDF/conf/views.php @@ -159,6 +159,12 @@ $ctl[] = array('regex' => '#^/p/(\w+)/downloads/(\d+)/$#', 'model' => 'IDF_Views_Download', 'method' => 'view'); +$ctl[] = array('regex' => '#^/p/(\w+)/downloads/(\d+)/get/$#', + 'base' => $base, + 'priority' => 4, + 'model' => 'IDF_Views_Download', + 'method' => 'download'); + $ctl[] = array('regex' => '#^/p/(\w+)/downloads/create/$#', 'base' => $base, 'priority' => 4, diff --git a/src/IDF/templates/downloads/view.html b/src/IDF/templates/downloads/view.html index 0a49126..3b35569 100644 --- a/src/IDF/templates/downloads/view.html +++ b/src/IDF/templates/downloads/view.html @@ -3,7 +3,7 @@ {block body}
-{$file} - {$file.filesize|size} +{$file} - {$file.filesize|size}
@@ -47,6 +47,8 @@

{trans 'Uploaded:'} {$file.creation_dtime|dateago} {blocktrans}by {$submitter}{/blocktrans}

{trans 'Updated:'} {$file.modif_dtime|dateago}

+

+{trans 'Downloads:'} {$file.downloads}

{assign $tags = $file.get_tags_list()}{if $tags.count()}

{trans 'Labels:'}