X-Git-Url: http://git.pk910.de/?p=phpgitweb.git;a=blobdiff_plain;f=htdocs%2Fpages%2Fshortlog.class.php;fp=htdocs%2Fpages%2Fshortlog.class.php;h=a7293c80c5c2444197beb3c4648b125f0c14c417;hp=0000000000000000000000000000000000000000;hb=0a6d29345b57ef71b076003e18d13efd3478764c;hpb=c20b2789b4f1c2da70f33cf2d1e78f55478a6e19 diff --git a/htdocs/pages/shortlog.class.php b/htdocs/pages/shortlog.class.php new file mode 100644 index 0000000..a7293c8 --- /dev/null +++ b/htdocs/pages/shortlog.class.php @@ -0,0 +1,140 @@ +. + */ + +require_once('lib/graph.class.php'); + +class shortlog { + private $project; + private $graph_data; + + public function generate_shortlog($project, $head, $max, $skip, $file = null, $pages = true, $next_page = 0) { + $this->project = $project; + $content = new ContentProvider('shortlog', 'shortlog'); + $commits = GitCommand::get_commits($project['path'], $head, $max+$skip+1, 0, $file); + + $this->graph_data = new graph_data_generator(); + if($head == null) { + //add all refs to the graph + foreach($this->project['refs'] as $ref => $rhash) { + if(preg_match('#^refs/heads/#i', $ref) && preg_match('/^[a-f0-9]*$/i', $rhash)) { + $this->graph_data->add_branch($rhash, $ref); + } + } + foreach($this->project['refs'] as $ref => $rhash) { + if(preg_match('#^refs/remotes/#i', $ref) && preg_match('/^[a-f0-9]*$/i', $rhash)) { + $this->graph_data->add_branch($rhash, $ref); + } + } + } + $this->graph_data->parse($commits); + + $commit_counter = 0; + foreach($commits as $commit) { + $commit_counter++; + if($commit_counter < $skip) + continue; + if($commit_counter > $max+$skip) { + if($pages) { + $content->append('entries', new ContentProvider('shortlog', 'shortlog_page', array("page" => $next_page))); + } else + $content->append('entries', new ContentProvider('shortlog', 'shortlog_more')); + } else + $content->append('entries', $this->shortlog_entry(($commit_counter % 2 ? 'dark' : 'light'), $commit)); + } + + return $content; + } + + private function shortlog_entry($class, $commit) { + $entry = new ContentProvider('shortlog', 'shortlog_entry'); + $entry->set('class', $class); + $entry->set('hash', $commit['id']); + $entry->set('author', htmlentities($commit['author'])); + $entry->set('message', htmlentities(Tools::chop_text($commit['text'], 50, 5))); + $age = time() - $commit['committer_time']; + $date_str = date("Y-m-d", ($commit['committer_time'] ? $commit['committer_time'] : $commit['author_time'])); + $age_calc = Tools::age_calculate($commit['committer_time']); + $age_str = $age_calc['age_str']; + if($age > 60*60*24*7*2) { + $entry->set('date', $age_str); + $entry->set('age', $date_str); + } else { + $entry->set('date', $date_str); + $entry->set('age', $age_str); + } + $entry->set('graph_data', $this->graph_data->get_graph($commit['id'])); + + $entry->set('refs', $this->shortlog_commit_refs($commit['id'])); + + return $entry; + } + + private function shortlog_commit_refs($hash) { + if(!is_array($this->project['refs'])) + return ""; + $refs = new ContentProvider('shortlog', 'shortlog_refs'); + $found = false; + foreach($this->project['refs'] as $ref => $rhash) { + if(strtolower($rhash) == strtolower($hash)) { + $refexp = explode('/', $ref, 3); + $reftype = $refexp[1]; + if($reftype == 'heads') + $reftype = 'head'; + else if($reftype == 'remotes') + $reftype = 'remote'; + else if($reftype == 'tags') + $reftype = 'tag'; + $refs->append('refs', new ContentProvider('shortlog', 'shortlog_ref_'.$reftype, array("name" => $refexp[2], "ref_link" => $ref))); + $found = true; + } + } + return ($found ? $refs : ""); + } + +} + + +class page_shortlog { + private $page, $phpgitweb; + + public function main($phpgitweb, $project) { + $this->phpgitweb = $phpgitweb; + $this->project = $project; + if(!$this->project) + return; + $project['refs'] = $phpgitweb->get_project_loader()->getProjectRefs($project); + $this->page = new ContentProvider('shortlog', 'main'); + + //pages + if(array_key_exists('pg', $_GET)) { + $skip = $_GET['pg'] * 100; + $next_page = $_GET['pg'] + 1; + } else { + $skip = 0; + $next_page = 1; + } + + $shortlog = new shortlog(); + $this->page->set('shortlog', $shortlog->generate_shortlog($project, null, 100, $skip, null, true, $next_page)); + + return $this->page; + } + +} + +?> \ No newline at end of file