2 /* ProjectLoader.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/>.
20 private $projects = NULL;
22 private function loadProjects($load_details = true) {
23 $this->projects = array();
24 if(GitConfig::PROJECT_LIST) {
25 foreach(file(GitConfig::PROJECT_LIST) as $entry) {
26 $entry = explode(" ", $entry);
29 //check if project really exists
30 $project = $this->loadProject($entry[0], false);
34 $project['name'] = $entry[0];
36 $project['owner'] = $entry[1];
37 $this->projects[] = $project;
40 //walk through PROJECT_ROOT
45 private function loadProject($name, $check_strict_export = true) {
47 $project['name'] = $name;
49 $dir_seperator = (substr(GitConfig::PROJECT_ROOT, -1) == '/' ? '' : '/');
50 if(is_dir(GitConfig::PROJECT_ROOT.$dir_seperator.$name))
51 $project['path'] = GitConfig::PROJECT_ROOT.$dir_seperator.$name;
52 else if(is_dir(GitConfig::PROJECT_ROOT.$dir_seperator.$name.".git"))
53 $project['path'] = GitConfig::PROJECT_ROOT.$dir_seperator.$name.".git";
56 if(is_dir($project['path'].'/.git'))
57 $project['path'] .= '/.git';
59 if(GitConfig::EXPORT_FILE && !file_exists($project['path'].'/'.GitConfig::EXPORT_FILE))
62 if(GitConfig::STRICT_EXPORT && $check_strict_export) {
63 if($this->projects === NULL)
64 $this->loadProjects(false);
66 foreach($this->projects as $p) {
67 if(strtolower($p['name']) == strtolower($name)) {
69 $project['name'] = $p['name'];
77 if(file_exists($project['path'].'/description'))
78 $project['description'] = file_get_contents($project['path'].'/description');
80 $project['description'] = "";
82 if(GitConfig::PROJECT_OWNER)
83 $project['owner'] = GitConfig::PROJECT_OWNER;
85 $project['owner'] = fileowner($project['path']);
86 $owner = posix_getpwuid($project['owner']);
87 if($owner && $owner['name'])
88 $project['owner'] = $owner['name'];
94 public function getProjectList() {
95 $this->loadProjects();
96 return $this->projects;
99 public function getProject($name) {
100 return $this->loadProject($name);
103 public function getLastChange($project) {
104 if(!array_key_exists('last_activity', $project)) {
105 $project['last_activity'] = GitCommand::last_activity($project['path']);
106 if(!$project['last_activity'])
107 $project['last_activity'] = 0;
109 return $project['last_activity'];
112 private function getProjectRefsRecursive(&$project, $cref) {
113 if ($dh = opendir($project['path'].'/'.$cref)) {
114 while (($file = readdir($dh)) !== false) {
115 if($file == '.' || $file == '..')
117 if(is_dir($project['path'].'/'.$cref.'/'.$file))
118 $this->getProjectRefsRecursive($project, $cref.'/'.$file);
120 $refval = file($project['path'].'/'.$cref.'/'.$file);
121 $project['refs'][$cref.($cref == '' ? '' : '/').$file] = str_replace(array("\r", "\n"), array("", ""), $refval[0]);
127 public function getProjectRefs($project) {
128 if(!array_key_exists('refs', $project)) {
129 if(is_dir($project['path'].'/refs')) {
130 $project['refs'] = array();
131 $this->getProjectRefsRecursive($project, 'refs');
134 return $project['refs'];