moved page helper classes to own files
[phpgitweb.git] / htdocs / pages / commit.class.php
1 <?php
2 /* commit.class.php - phpgitweb
3  * Copyright (C) 2011-2012  Philipp Kreil (pk910)
4  * 
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  * 
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  * 
15  * You should have received a copy of the GNU General Public License 
16  * along with this program. If not, see <http://www.gnu.org/licenses/>. 
17  */
18
19 class page_commit {
20     private $page, $phpgitweb;
21         
22     public function main($phpgitweb, $project) {
23                 $this->phpgitweb = $phpgitweb;
24                 if(!$project)
25                         return new ContentProvider('main', 'err400');
26                 $project['refs'] = $phpgitweb->get_project_loader()->getProjectRefs($project);
27                 $phpgitweb->append_header_nav("commit", null, true);
28                 $phpgitweb->append_title("commit");
29                 CommitLoader::parse();
30                 
31                 $commit_loader = new CommitLoader($project);
32                 $commit = $commit_loader->load();
33                 if(!$commit)
34                         return new ContentProvider('main', 'err404_object');
35                 
36                 ContentProvider::overall_set('commit_id', $commit['id']);
37                 
38                 
39                 $this->page = new ContentProvider('commit', 'main');
40                 $this->page->set('hash', $commit['id']);
41                 $this->page->set('author', htmlentities($commit['author']));
42                 $this->page->set('author_mail', htmlentities($commit['author_mail']));
43                 $this->page->set('author_date', gmdate('r', $commit['author_time']));
44                 $author_local_time = $commit['author_time'] + Tools::parseTimeZone($commit['author_timezone']);
45                 if(gmdate('H', $author_local_time) < 6)
46                         $this->page->set('author_local_date', '<span class="atnight">'.gmdate('H:i', $author_local_time).'</span>');
47                 else
48                         $this->page->set('author_local_date', gmdate('H:i', $author_local_time));
49                 $this->page->set('author_timezone', $commit['author_timezone']);
50                 $this->page->set('committer', htmlentities($commit['committer']));
51                 $this->page->set('committer_mail', htmlentities($commit['committer_mail']));
52                 $this->page->set('committer_date', gmdate('r', $commit['committer_time']));
53                 $committer_local_time = $commit['committer_time'] + Tools::parseTimeZone($commit['committer_timezone']);
54                 if(gmdate('H', $committer_local_time) < 6)
55                         $this->page->set('committer_local_date', '<span class="atnight">'.gmdate('H:i', $committer_local_time).'</span>');
56                 else
57                         $this->page->set('committer_local_date', gmdate('H:i', $committer_local_time));
58                 $this->page->set('committer_timezone', $commit['committer_timezone']);
59                 $this->page->set('message', htmlentities(Tools::chop_text($commit['text'], 80, 5)));
60                 $this->page->set('full_message', htmlentities($commit['text']));
61                 $this->page->set('tree_hash', $commit['tree']);
62                 foreach($commit['parent'] as $parent) {
63                         $this->page->append('parents', new ContentProvider('commit', 'parent', array('hash' => $parent, 'head' => $commit['id'])));
64                 }
65                 if(count($commit['parent']) == 0)
66                         $this->page->set('parents', '');
67                 
68                 $refs = new ContentProvider('commit', 'commit_refs');
69                 $found = false;
70                 foreach($project['refs'] as $ref => $rhash) {
71                         if(strtolower($rhash) == strtolower($commit['id'])) {
72                                 $refexp = explode('/', $ref, 3);
73                                 $reftype = $refexp[1];
74                                 if($reftype == 'heads')
75                                         $reftype = 'head';
76                                 else if($reftype == 'remotes')
77                                         $reftype = 'remote';
78                                 else if($reftype == 'tags')
79                                         $reftype = 'tag';
80                                 $refs->append('refs', new ContentProvider('commit', 'commit_ref_'.$reftype, array("name" => $refexp[2], "ref_link" => $ref)));
81                                 $found = true;
82                         }
83                 }
84                 $this->page->set('refs', ($found ? $refs : ""));
85                 
86                 $difftree = new difftree();
87                 $this->page->set('difftree', $difftree->generate_difftree($project, $commit, false));
88                 
89                 return $this->page;
90         }
91         
92         
93         
94 }
95
96 ?>