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');
25 public function generate_shortlog($project, $head, $max, $skip, $file = null, $pages = true, $next_page = 0) {
26 $this->project = $project;
27 $content = new ContentProvider('shortlog', 'shortlog');
28 $commits = GitCommand::get_commits($project['path'], $head, $max+$skip+1, 0, $file);
30 $this->graph_data = new graph_data_generator();
32 //add all refs to the graph
33 foreach($this->project['refs'] as $ref => $rhash) {
34 if(preg_match('#^refs/heads/#i', $ref) && preg_match('/^[a-f0-9]*$/i', $rhash)) {
35 $this->graph_data->add_branch($rhash, $ref);
38 foreach($this->project['refs'] as $ref => $rhash) {
39 if(preg_match('#^refs/remotes/#i', $ref) && preg_match('/^[a-f0-9]*$/i', $rhash)) {
40 $this->graph_data->add_branch($rhash, $ref);
44 $this->graph_data->parse($commits);
47 foreach($commits as $commit) {
49 if($commit_counter < $skip)
51 if($commit_counter > $max+$skip) {
53 $content->append('entries', new ContentProvider('shortlog', 'shortlog_page', array("page" => $next_page)));
55 $content->append('entries', new ContentProvider('shortlog', 'shortlog_more'));
57 $content->append('entries', $this->shortlog_entry(($commit_counter % 2 ? 'dark' : 'light'), $commit));
63 private function shortlog_entry($class, $commit) {
64 $entry = new ContentProvider('shortlog', 'shortlog_entry');
65 $entry->set('class', $class);
66 $entry->set('hash', $commit['id']);
67 $entry->set('author', htmlentities($commit['author']));
68 $entry->set('message', htmlentities(Tools::chop_text($commit['text'], 50, 5)));
69 $age = time() - $commit['committer_time'];
70 $date_str = date("Y-m-d", ($commit['committer_time'] ? $commit['committer_time'] : $commit['author_time']));
71 $age_calc = Tools::age_calculate($commit['committer_time']);
72 $age_str = $age_calc['age_str'];
73 if($age > 60*60*24*7*2) {
74 $entry->set('date', $age_str);
75 $entry->set('age', $date_str);
77 $entry->set('date', $date_str);
78 $entry->set('age', $age_str);
80 $entry->set('graph_data', $this->graph_data->get_graph($commit['id']));
82 $entry->set('refs', $this->shortlog_commit_refs($commit['id']));
87 private function shortlog_commit_refs($hash) {
88 if(!is_array($this->project['refs']))
90 $refs = new ContentProvider('shortlog', 'shortlog_refs');
92 foreach($this->project['refs'] as $ref => $rhash) {
93 if(strtolower($rhash) == strtolower($hash)) {
94 $refexp = explode('/', $ref, 3);
95 $reftype = $refexp[1];
96 if($reftype == 'heads')
98 else if($reftype == 'remotes')
100 else if($reftype == 'tags')
102 $refs->append('refs', new ContentProvider('shortlog', 'shortlog_ref_'.$reftype, array("name" => $refexp[2], "ref_link" => $ref)));
106 return ($found ? $refs : "");
112 class page_shortlog {
113 private $page, $phpgitweb;
115 public function main($phpgitweb, $project) {
116 $this->phpgitweb = $phpgitweb;
117 $this->project = $project;
120 $project['refs'] = $phpgitweb->get_project_loader()->getProjectRefs($project);
121 $this->page = new ContentProvider('shortlog', 'main');
124 if(array_key_exists('pg', $_GET)) {
125 $skip = $_GET['pg'] * 100;
126 $next_page = $_GET['pg'] + 1;
132 $shortlog = new shortlog();
133 $this->page->set('shortlog', $shortlog->generate_shortlog($project, null, 100, $skip, null, true, $next_page));