r4279 index.php: merge and clean up the code from download.php into "download" module
authorDenis Ovsienko <infrastation@yandex.ru>
Thu, 3 Mar 2011 12:56:14 +0000 (12:56 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Thu, 3 Mar 2011 12:56:14 +0000 (12:56 +0000)
download.php: sayonara
renderFile(): update respectively
renderFileDownloader(): idem
renderCell(): idem
getFilePreviewCode(): idem

wwwroot/download.php [deleted file]
wwwroot/inc/interface.php
wwwroot/index.php

diff --git a/wwwroot/download.php b/wwwroot/download.php
deleted file mode 100644 (file)
index e5b55c0..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-<?php
-ob_start();
-try {
-       require 'inc/init.php';
-       // purely for renderAccessDenied()
-       require 'inc/interface.php';
-
-       assertUIntArg ('file_id');
-       $pageno = 'file';
-       $tabno = 'download';
-       fixContext();
-       if (!permitted())
-               renderAccessDenied();
-
-       $asattach = (isset ($_REQUEST['asattach']) and $_REQUEST['asattach'] == 'no') ? FALSE : TRUE;
-       $file = getFile ($_REQUEST['file_id']);
-       if ($file != NULL) 
-       {
-               header("Content-Type: {$file['type']}");
-               header("Content-Length: {$file['size']}");
-               if ($asattach)
-                       header("Content-Disposition: attachment; filename={$file['name']}");
-               echo $file['contents'];
-       }
-       ob_end_flush();
-}
-catch (Exception $e)
-{
-       ob_end_clean();
-       printException($e);
-}
-?>
index 4b2a9a26423c007f04cb1cc30f8ea602e19d8b9b..5202ae3e9935efad5c68f45fd111b33a2e5d2fd3 100644 (file)
@@ -6625,7 +6625,7 @@ function renderFile ($file_id)
        echo "<tr><th width='50%' class=tdright>Size:</th><td class=tdleft>";
        if (isolatedPermission ('file', 'download', $file))
        {
-               echo "<a href='download.php?file_id=${file_id}'>";
+               echo "<a href='?module=download&file_id=${file_id}'>";
                printImageHREF ('download', 'Download file');
                echo '</a>&nbsp;';
        }
@@ -6700,7 +6700,7 @@ function renderFileReuploader ()
 
 function renderFileDownloader ($file_id)
 {
-       echo "<br><center><a target='_blank' href='download.php?file_id=${file_id}&asattach=1'>";
+       echo "<br><center><a target='_blank' href='?module=download&file_id=${file_id}&asattach=1'>";
        printImageHREF ('DOWNLOAD');
        echo '</a></center>';
 }
@@ -7013,7 +7013,8 @@ function renderCell ($cell)
                echo '</td></tr><tr><td>';
                if (isolatedPermission ('file', 'download', $cell))
                {
-                       echo "<a href='download.php?file_id=${cell['id']}'>";
+                       // FIXME: reuse renderFileDownloader()
+                       echo "<a href='?module=download&file_id=${cell['id']}'>";
                        printImageHREF ('download', 'Download file');
                        echo '</a>&nbsp;';
                }
@@ -7180,7 +7181,7 @@ function getFilePreviewCode ($file)
                                $resampled = TRUE;
                        }
                        if ($resampled)
-                               $ret .= "<a href='download.php?file_id=${file['id']}&asattach=no'>";
+                               $ret .= "<a href='?module=download&file_id=${file['id']}&asattach=no'>";
                        $ret .= "<img width=${width} height=${height} src='render_image.php?img=preview&file_id=${file['id']}'>";
                        if ($resampled)
                                $ret .= '</a><br>(click to zoom)';
index 857e30b907b6a9667440d507562c6dd6b9e2aacb..edcd156cff113d7e402eafc5cf5d1e65ce869551 100644 (file)
@@ -10,9 +10,28 @@ if (array_key_exists ('module', $_REQUEST))
                genericAssertion ('uri', 'string');
                proxyStaticURI ($_REQUEST['uri']);
                break;
+       case 'download':
+               $pageno = 'file';
+               $tabno = 'download';
+               fixContext();
+               if (!permitted())
+               {
+                       require_once 'inc/interface.php';
+                       renderAccessDenied();
+               }
+
+               $asattach = (isset ($_REQUEST['asattach']) and $_REQUEST['asattach'] == 'no') ? FALSE : TRUE;
+               $file = getFile (getBypassValue());
+               header("Content-Type: {$file['type']}");
+               header("Content-Length: {$file['size']}");
+               if ($asattach)
+                       header("Content-Disposition: attachment; filename={$file['name']}");
+               echo $file['contents'];
+               break;
        default:
                throw new InvalidRequestArgException ('module', $_REQUEST['module']);
        }
+       ob_end_flush();
        exit;
 }