added the download link to the code view
This commit is contained in:
		@ -9,6 +9,7 @@ class Code extends Controller
 | 
				
			|||||||
	var $VIEW_HISTORY = 'code_history';
 | 
						var $VIEW_HISTORY = 'code_history';
 | 
				
			||||||
	var $VIEW_REVISION = 'code_revision';
 | 
						var $VIEW_REVISION = 'code_revision';
 | 
				
			||||||
	var $VIEW_DIFF = 'code_diff';
 | 
						var $VIEW_DIFF = 'code_diff';
 | 
				
			||||||
 | 
						var $VIEW_FETCH = 'code_fetch';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	function Code ()
 | 
						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)
 | 
						function _normalize_path ($path)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		$path = preg_replace('/[\/]+/', '/', $path);
 | 
							$path = preg_replace('/[\/]+/', '/', $path);
 | 
				
			||||||
 | 
				
			|||||||
@ -155,6 +155,9 @@ else
 | 
				
			|||||||
	print anchor ("code/history/{$project->id}/{$xpar}", $this->lang->line('History'));
 | 
						print anchor ("code/history/{$project->id}/{$xpar}", $this->lang->line('History'));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					print ' | ';
 | 
				
			||||||
 | 
					print anchor ("code/fetch/{$project->id}/${xpar}{$revreq}", $this->lang->line('Download'));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
?>
 | 
					?>
 | 
				
			||||||
</div> <!-- code_blame_mainarea_menu -->
 | 
					</div> <!-- code_blame_mainarea_menu -->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -156,6 +156,11 @@ $this->load->view (
 | 
				
			|||||||
			"code/history/{$project->id}/{$xpar}", 
 | 
								"code/history/{$project->id}/{$xpar}", 
 | 
				
			||||||
			$this->lang->line('History'));
 | 
								$this->lang->line('History'));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						print ' | ';
 | 
				
			||||||
 | 
						print anchor (
 | 
				
			||||||
 | 
							"code/fetch/{$project->id}/${xpar}{$revreq}",
 | 
				
			||||||
 | 
							$this->lang->line('Download'));
 | 
				
			||||||
?>
 | 
					?>
 | 
				
			||||||
</div> <!-- code_file_mainarea_menu -->
 | 
					</div> <!-- code_file_mainarea_menu -->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user