X-Git-Url: http://git.pk910.de/?p=phpgitweb.git;a=blobdiff_plain;f=htdocs%2Flib%2FProjectLoader.class.php;fp=htdocs%2Flib%2FProjectLoader.class.php;h=eb1c789c11a8bc70219e7d58b41773116cd7f21d;hp=0000000000000000000000000000000000000000;hb=0a6d29345b57ef71b076003e18d13efd3478764c;hpb=c20b2789b4f1c2da70f33cf2d1e78f55478a6e19 diff --git a/htdocs/lib/ProjectLoader.class.php b/htdocs/lib/ProjectLoader.class.php new file mode 100644 index 0000000..eb1c789 --- /dev/null +++ b/htdocs/lib/ProjectLoader.class.php @@ -0,0 +1,138 @@ +. + */ + +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(" ", $entry); + + if($load_details) { + //check if project really exists + $project = $this->loadProject($entry[0], false); + if($project === NULL) + continue; + } else + $project['name'] = $entry[0]; + + $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(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']; + break; + } + } + if(!$found) + return NULL; + } + + if(file_exists($project['path'].'/description')) + $project['description'] = file_get_contents($project['path'].'/description'); + else + $project['description'] = ""; + + 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 == '.' || $file == '..') + 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']; + } +} + +?> \ No newline at end of file