diff --git a/codepot/src/codepot/controllers/code.php b/codepot/src/codepot/controllers/code.php index a1104d33..9140274d 100644 --- a/codepot/src/codepot/controllers/code.php +++ b/codepot/src/codepot/controllers/code.php @@ -9,6 +9,7 @@ class Code extends Controller var $VIEW_HISTORY = 'code_history'; var $VIEW_REVISION = 'code_revision'; var $VIEW_DIFF = 'code_diff'; + var $VIEW_FETCH = 'code_fetch'; function Code () { @@ -363,6 +364,75 @@ class Code extends Controller } } + function fetch ($projectid = '', $path = '', $rev = SVN_REVISION_HEAD) + { + $this->load->model ('ProjectModel', 'projects'); + $this->load->model ('SubversionModel', 'subversion'); + + $login = $this->login->getUser (); + if (CODEPOT_SIGNIN_COMPULSORY && $login['id'] == '') + redirect ("main/signin/" . $this->converter->AsciiTohex(current_url())); + $data['login'] = $login; + + $path = $this->converter->HexToAscii ($path); + if ($path == '.') $path = ''; /* treat a period specially */ + $path = $this->_normalize_path ($path); + + $project = $this->projects->get ($projectid); + if ($project === FALSE) + { + $data['message'] = 'DATABASE ERROR'; + $this->load->view ($this->VIEW_ERROR, $data); + } + else if ($project === NULL) + { + $data['message'] = + $this->lang->line('MSG_NO_SUCH_PROJECT') . + " - {$projectid}"; + $this->load->view ($this->VIEW_ERROR, $data); + } + else + { + if ($project->public !== 'Y' && $login['id'] == '') + { + // non-public projects require sign-in. + redirect ("main/signin/" . $this->converter->AsciiTohex(current_url())); + } + + $file = $this->subversion->getFile ($projectid, $path, $rev); + if ($file === FALSE) + { + $data['project'] = $project; + $data['message'] = 'Failed to get file'; + $this->load->view ($this->VIEW_ERROR, $data); + } + else if ($file['type'] == 'file') + { + header ('Content-Description: File Transfer'); + header('Content-Type: application/octet-stream'); + header ('Content-Disposition: attachment; filename='. basename($path)); + header ('Content-Transfer-Encoding: binary'); + header ('Content-Length: ' . strlen($file['content'])); + flush (); + print $file['content']; + } + else + { + $data['project'] = $project; + $data['headpath'] = $path; + $data['file'] = $file; + + $data['revision'] = $rev; + $data['prev_revision'] = + $this->subversion->getPrevRev ($projectid, $path, $rev); + $data['next_revision'] = + $this->subversion->getNextRev ($projectid, $path, $rev); + + $this->load->view ($this->VIEW_FOLDER, $data); + } + } + } + function _normalize_path ($path) { $path = preg_replace('/[\/]+/', '/', $path); diff --git a/codepot/src/codepot/views/code_blame.php b/codepot/src/codepot/views/code_blame.php index 03e485e8..a4e07cc1 100644 --- a/codepot/src/codepot/views/code_blame.php +++ b/codepot/src/codepot/views/code_blame.php @@ -155,6 +155,9 @@ else print anchor ("code/history/{$project->id}/{$xpar}", $this->lang->line('History')); } +print ' | '; +print anchor ("code/fetch/{$project->id}/${xpar}{$revreq}", $this->lang->line('Download')); + ?> diff --git a/codepot/src/codepot/views/code_file.php b/codepot/src/codepot/views/code_file.php index 8e6100f4..f47c612f 100644 --- a/codepot/src/codepot/views/code_file.php +++ b/codepot/src/codepot/views/code_file.php @@ -156,6 +156,11 @@ $this->load->view ( "code/history/{$project->id}/{$xpar}", $this->lang->line('History')); } + + print ' | '; + print anchor ( + "code/fetch/{$project->id}/${xpar}{$revreq}", + $this->lang->line('Download')); ?>