. */ class ProjectLoader { private $projects = NULL; private function loadProjects($load_details = true) { $this->projects = array(); if(GitConfig::PROJECT_LIST) { foreach(file(GitConfig::PROJECT_LIST) as $entry) { $entry = explode(" ", str_replace(array("\r", "\n"), array("", ""), $entry)); if($load_details) { //check if project really exists $project = $this->loadProject($entry[0], false); if($project === NULL) continue; } else $project['name'] = $entry[0]; if(count($entry) > 1) $project['owner'] = $entry[1]; $this->projects[] = $project; } } else { //walk through PROJECT_ROOT } } private function loadProject($name, $check_strict_export = true) { $project = array(); $project['name'] = $name; $dir_seperator = (substr(GitConfig::PROJECT_ROOT, -1) == '/' ? '' : '/'); if(!Validation::validate_path($name)) return NULL; if(is_dir(GitConfig::PROJECT_ROOT.$dir_seperator.$name)) $project['path'] = GitConfig::PROJECT_ROOT.$dir_seperator.$name; else if(is_dir(GitConfig::PROJECT_ROOT.$dir_seperator.$name.".git")) $project['path'] = GitConfig::PROJECT_ROOT.$dir_seperator.$name.".git"; else return NULL; if(is_dir($project['path'].'/.git')) $project['path'] .= '/.git'; if(GitConfig::EXPORT_FILE && !file_exists($project['path'].'/'.GitConfig::EXPORT_FILE)) return NULL; if(GitConfig::STRICT_EXPORT && $check_strict_export) { if($this->projects === NULL) $this->loadProjects(false); $found = false; foreach($this->projects as $p) { if(strtolower($p['name']) == strtolower($name)) { $found = true; $project['name'] = $p['name']; if(isset($p['owner'])) $project['owner'] = $p['owner']; break; } } if(!$found) return NULL; } if(file_exists($project['path'].'/description')) $project['description'] = file_get_contents($project['path'].'/description'); else $project['description'] = ""; if(!array_key_exists('owner', $project) || $project['owner'] == null) { if(GitConfig::PROJECT_OWNER) $project['owner'] = GitConfig::PROJECT_OWNER; else { $project['owner'] = fileowner($project['path']); $owner = posix_getpwuid($project['owner']); if($owner && $owner['name']) $project['owner'] = $owner['name']; } } return $project; } public function getProjectList() { $this->loadProjects(); return $this->projects; } public function getProject($name) { return $this->loadProject($name); } public function getLastChange($project) { if(!array_key_exists('last_activity', $project)) { $project['last_activity'] = GitCommand::last_activity($project['path']); if(!$project['last_activity']) $project['last_activity'] = 0; } return $project['last_activity']; } private function getProjectRefsRecursive(&$project, $cref) { if ($dh = opendir($project['path'].'/'.$cref)) { while (($file = readdir($dh)) !== false) { if($file[0] == '.') continue; if(is_dir($project['path'].'/'.$cref.'/'.$file)) $this->getProjectRefsRecursive($project, $cref.'/'.$file); else { $refval = file($project['path'].'/'.$cref.'/'.$file); $project['refs'][$cref.($cref == '' ? '' : '/').$file] = str_replace(array("\r", "\n"), array("", ""), $refval[0]); } } } } public function getProjectRefs($project) { if(!array_key_exists('refs', $project)) { if(is_dir($project['path'].'/refs')) { $project['refs'] = array(); $this->getProjectRefsRecursive($project, 'refs'); } } return $project['refs']; } } ?>