2 /* shortlog.class.php - phpgitweb
3 * Copyright (C) 2011-2012 Philipp Kreil (pk910)
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.
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.
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/>.
19 require_once('lib/graph.class.php');
24 private $first_commit;
25 private $have_more = false;
27 public function generate_shortlog($project, $head, $max, $skip, $file = null, $pages = true, $next_page = 0) {
28 $this->project = $project;
29 $content = new ContentProvider('shortlog', 'shortlog');
31 if(GitConfig::GITGRAPH_ENABLE) {
32 if($max+$skip >= 2000) { //only load the last 2k commits
33 $real_skip = ($max+$skip) - 2000;
42 $commits = GitCommand::get_commits($project['path'], $head, $max+$skip+1, $real_skip, $file);
44 if(GitConfig::GITGRAPH_ENABLE) {
45 $this->graph_data = new graph_data_generator();
47 //add all refs to the graph
48 foreach($this->project['refs'] as $ref => $rhash) {
49 if(preg_match('#^refs/heads/#i', $ref) && preg_match('/^[a-f0-9]*$/i', $rhash)) {
50 $this->graph_data->add_branch($rhash, $ref);
53 foreach($this->project['refs'] as $ref => $rhash) {
54 if(preg_match('#^refs/remotes/#i', $ref) && preg_match('/^[a-f0-9]*$/i', $rhash)) {
55 $this->graph_data->add_branch($rhash, $ref);
59 $this->graph_data->parse($commits);
60 $content->set('graph_data', $this->graph_data->get_header_graph());
64 $this->first_commit = $commits[0];
65 foreach($commits as $commit) {
67 if($commit_counter < $skip)
69 if($commit_counter > $max+$skip) {
70 $this->have_more = true;
72 $content->append('entries', new ContentProvider('shortlog', 'shortlog_page', array("page" => $next_page)));
74 $content->append('entries', new ContentProvider('shortlog', 'shortlog_more'));
76 $content->append('entries', $this->shortlog_entry(($commit_counter % 2 ? 'dark' : 'light'), $commit));
82 public function get_first_commit() {
83 return $this->first_commit;
86 public function get_have_more() {
87 return $this->have_more;
90 private function shortlog_entry($class, $commit) {
91 $entry = new ContentProvider('shortlog', 'shortlog_entry');
92 $entry->set('class', $class);
93 $entry->set('hash', $commit['id']);
94 $entry->set('author', htmlentities($commit['author']));
95 $entry->set('message', htmlentities(Tools::chop_text($commit['text'], 50, 5)));
96 $age = time() - $commit['committer_time'];
97 $date_str = date("Y-m-d", ($commit['committer_time'] ? $commit['committer_time'] : $commit['author_time']));
98 $age_calc = Tools::age_calculate($commit['committer_time']);
99 $age_str = $age_calc['age_str'];
100 if($age > 60*60*24*7*2) {
101 $entry->set('date', $age_str);
102 $entry->set('age', $date_str);
104 $entry->set('date', $date_str);
105 $entry->set('age', $age_str);
107 if(GitConfig::GITGRAPH_ENABLE)
108 $entry->set('graph_data', $this->graph_data->get_graph($commit['id']));
110 $entry->set('refs', $this->shortlog_commit_refs($this->project, $commit['id']));
115 public function shortlog_commit_refs($project, $hash) {
116 if(!is_array($project['refs']))
118 $refs = new ContentProvider('shortlog', 'shortlog_refs');
120 foreach($project['refs'] as $ref => $rhash) {
121 if(strtolower($rhash) == strtolower($hash)) {
122 $refexp = explode('/', $ref, 3);
123 $reftype = $refexp[1];
124 if($reftype == 'heads')
126 else if($reftype == 'remotes')
128 else if($reftype == 'tags')
130 $refs->append('refs', new ContentProvider('shortlog', 'shortlog_ref_'.$reftype, array("name" => $refexp[2], "ref_link" => $ref)));
134 return ($found ? $refs : "");
140 class page_shortlog {
141 private $page, $phpgitweb;
143 public function main($phpgitweb, $project) {
144 $this->phpgitweb = $phpgitweb;
145 $this->project = $project;
147 return new ContentProvider('main', 'err400');
148 $project['refs'] = $phpgitweb->get_project_loader()->getProjectRefs($project);
149 $phpgitweb->append_header_nav("shortlog", null, true);
150 $phpgitweb->append_title("shortlog");
152 $this->page = new ContentProvider('shortlog', 'main');
155 if(array_key_exists('pg', $_GET)) {
159 $skip = $_GET['pg'] * 100;
160 $next_page = $_GET['pg'] + 1;
167 $subnav = new ContentProvider('shortlog', 'shortlog_subnav');
168 $phpgitweb->append_sub_nav($subnav);
171 $subnav->set('first', new ContentProvider('shortlog', 'shortlog_subnav_first_link'));
172 $subnav->set('prev', new ContentProvider('shortlog', 'shortlog_subnav_prev_link', array('page' => ($pg - 1))));
174 $subnav->set('first', new ContentProvider('shortlog', 'shortlog_subnav_first'));
175 $subnav->set('prev', new ContentProvider('shortlog', 'shortlog_subnav_prev'));
178 $shortlog = new shortlog();
179 $this->page->set('shortlog', $shortlog->generate_shortlog($project, null, 100, $skip, null, true, $next_page));
181 if($shortlog->get_have_more())
182 $subnav->set('next', new ContentProvider('shortlog', 'shortlog_subnav_next_link', array('page' => ($pg + 1))));
184 $subnav->set('next', new ContentProvider('shortlog', 'shortlog_subnav_next'));