continued :)
[phpgitweb.git] / htdocs / pages / commit.class.php
diff --git a/htdocs/pages/commit.class.php b/htdocs/pages/commit.class.php
new file mode 100644 (file)
index 0000000..17f5678
--- /dev/null
@@ -0,0 +1,97 @@
+<?php
+/* commit.class.php - phpgitweb
+ * Copyright (C) 2011-2012  Philipp Kreil (pk910)
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License 
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. 
+ */
+
+require_once('pages/shortlog.class.php');
+
+class page_commit {
+    private $page, $phpgitweb;
+       private $commitid;
+       
+    public function main($phpgitweb, $project) {
+               $this->phpgitweb = $phpgitweb;
+               if(!$project)
+                       return new ContentProvider('main', 'err400');
+               $project['refs'] = $phpgitweb->get_project_loader()->getProjectRefs($project);
+               $phpgitweb->append_header_nav("commit", null, true);
+               $phpgitweb->append_title("commit");
+               
+               $commit_loader = new CommitLoader($project);
+               
+               if(array_key_exists('h', $_GET))
+                       $commitid = $_GET['h'];
+               else
+                       $commitid = "HEAD";
+               
+               $commit = $commit_loader->load($commitid);
+               if(!$commit)
+                       return new ContentProvider('main', 'err404_object');
+               
+               ContentProvider::overall_set('project_head', $commit['id']);
+               
+               
+               $this->page = new ContentProvider('commit', 'main');
+               $this->page->set('hash', $commit['id']);
+               $this->page->set('author', htmlentities($commit['author']));
+               $this->page->set('author_mail', htmlentities($commit['author_mail']));
+               $this->page->set('author_date', gmdate('r', $commit['author_time']));
+               $author_local_time = $commit['author_time'] + Tools::parseTimeZone($commit['author_timezone']);
+               if(gmdate('H', $author_local_time) < 6)
+                       $this->page->set('author_local_date', '<span class="atnight">'.gmdate('H:i', $author_local_time).'</span>');
+               else
+                       $this->page->set('author_local_date', gmdate('H:i', $author_local_time));
+               $this->page->set('author_timezone', $commit['author_timezone']);
+               $this->page->set('committer', htmlentities($commit['committer']));
+               $this->page->set('committer_mail', htmlentities($commit['committer_mail']));
+               $this->page->set('committer_date', gmdate('r', $commit['committer_time']));
+               $committer_local_time = $commit['committer_time'] + Tools::parseTimeZone($commit['committer_timezone']);
+               if(gmdate('H', $committer_local_time) < 6)
+                       $this->page->set('committer_local_date', '<span class="atnight">'.gmdate('H:i', $committer_local_time).'</span>');
+               else
+                       $this->page->set('committer_local_date', gmdate('H:i', $committer_local_time));
+               $this->page->set('committer_timezone', $commit['committer_timezone']);
+               $this->page->set('message', htmlentities(Tools::chop_text($commit['text'], 50, 5)));
+               $this->page->set('full_message', htmlentities($commit['text']));
+               $this->page->set('tree_hash', $commit['tree']);
+               foreach($commit['parent'] as $parent) {
+                       $this->page->append('parents', new ContentProvider('commit', 'parent', array('hash' => $parent, 'head' => $commit['id'])));
+               }
+               
+               $refs = new ContentProvider('commit', 'commit_refs');
+               $found = false;
+               foreach($project['refs'] as $ref => $rhash) {
+                       if(strtolower($rhash) == strtolower($commit['id'])) {
+                               $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('commit', 'commit_ref_'.$reftype, array("name" => $refexp[2], "ref_link" => $ref)));
+                               $found = true;
+                       }
+               }
+               $this->page->set('refs', ($found ? $refs : ""));
+               
+               return $this->page;
+       }
+       
+}
+
+?>
\ No newline at end of file