Inject config class into projectlist
[gitphp.git] / include / git / projectlist / ProjectListBase.class.php
blob:a/include/git/projectlist/ProjectListBase.class.php -> blob:b/include/git/projectlist/ProjectListBase.class.php
--- a/include/git/projectlist/ProjectListBase.class.php
+++ b/include/git/projectlist/ProjectListBase.class.php
@@ -276,10 +276,12 @@
 
 		$compat = $project->GetCompat();
 
+		$loader = null;
 		if ($compat) {
 			$project->SetStrategy(new GitPHP_ProjectLoad_Git($this->exe));
 		} else {
-			$project->SetStrategy(new GitPHP_ProjectLoad_Raw());
+			$loader = new GitPHP_GitObjectLoader($project);
+			$project->SetStrategy(new GitPHP_ProjectLoad_Raw($loader));
 		}
 
 		$headListStrategy = null;
@@ -300,13 +302,11 @@
 		$tagList = new GitPHP_TagList($project, $tagListStrategy);
 		$project->SetTagList($tagList);
 
-		if (!$compat) {
-			$loader = new GitPHP_GitObjectLoader($project);
-			$project->SetObjectLoader($loader);
-		}
-
 		$manager = new GitPHP_GitObjectManager($project);
 		$manager->SetCompat($compat);
+		if (!$compat) {
+			$manager->SetObjectLoader($loader);
+		}
 		$manager->SetExe($this->exe);
 		if ($this->memoryCache) {
 			$manager->SetMemoryCache($this->memoryCache);
@@ -362,6 +362,8 @@
 
 		if ($config->HasValue('gitphp.description')) {
 			$project->SetDescription($config->GetValue('gitphp.description'));
+		} else if ($config->HasValue('gitweb.description')) {
+			$project->SetDescription($config->GetValue('gitweb.description'));
 		}
 
 		if ($config->HasValue('gitphp.category')) {
@@ -396,6 +398,10 @@
 			$project->SetAbbreviateLength($config->GetValue('core.abbrev'));
 		}
 
+		if ($config->HasValue('gitphp.allowedusers')) {
+			$project->SetAllowedUsers($config->GetValue('gitphp.allowedusers', true));
+		}
+
 	}
 
 	/**
@@ -411,19 +417,19 @@
 		if (!$this->config)
 			return;
 
-		if ($this->config->HasKey('cloneurl')) {
+		if ($this->config->GetValue('cloneurl')) {
 			$project->SetCloneUrl(GitPHP_Util::AddSlash($this->config->GetValue('cloneurl'), false) . $project->GetProject());
 		}
 
-		if ($this->config->HasKey('pushurl')) {
+		if ($this->config->GetValue('pushurl')) {
 			$project->SetPushUrl(GitPHP_Util::AddSlash($this->config->GetValue('pushurl'), false) . $project->GetProject());
 		}
 
-		if ($this->config->HasKey('bugpattern')) {
+		if ($this->config->GetValue('bugpattern')) {
 			$project->SetBugPattern($this->config->GetValue('bugpattern'));
 		}
 
-		if ($this->config->HasKey('bugurl')) {
+		if ($this->config->GetValue('bugurl')) {
 			$project->SetBugUrl($this->config->GetValue('bugurl'));
 		}
 
@@ -434,6 +440,10 @@
 		if ($this->config->HasKey('uniqueabbrev')) {
 			$project->SetUniqueAbbreviation($this->config->GetValue('uniqueabbrev'));
 		}
+
+		if ($this->config->GetValue('abbreviateurl')) {
+			$project->SetUniqueAbbreviation(true);
+		}
 	}
 
 	/**
@@ -448,6 +458,19 @@
 		$this->Sort();
 
 		$this->ApplySettings();
+	}
+
+	/**
+	 * Filter projects by user access
+	 *
+	 * @param string $username username
+	 */
+	public function FilterByUser($username)
+	{
+		foreach ($this->projects as $path => $project) {
+			if (!$project->UserCanAccess($username))
+				unset($this->projects[$path]);
+		}
 	}
 
 	/**
@@ -601,6 +624,9 @@
 		if (isset($projData['website']) && is_string($projData['website'])) {
 			$project->SetWebsite($projData['website']);
 		}
+		if (!empty($projData['allowedusers'])) {
+			$project->SetAllowedUsers($projData['allowedusers']);
+		}
 	}
 
 	/**

comments