Browse Source

System update (winter remix)

markseu 9 năm trước cách đây
mục cha
commit
0d4eab8e01
3 tập tin đã thay đổi với 32 bổ sung20 xóa
  1. 0 1
      system/config/config.ini
  2. 26 15
      system/plugins/commandline.php
  3. 6 4
      system/plugins/core.php

+ 0 - 1
system/config/config.ini

@@ -22,7 +22,6 @@ TemplateDir: system/themes/templates/
 MediaDir: media/
 ImageDir: media/images/
 StaticDir: cache/
-StaticAccessFile: .htaccess
 StaticDefaultFile: index.html
 StaticErrorFile: 404.html
 ContentDir: content/

+ 26 - 15
system/plugins/commandline.php

@@ -5,7 +5,7 @@
 // Command line plugin
 class YellowCommandline
 {
-	const Version = "0.6.1";
+	const Version = "0.6.2";
 	var $yellow;					//access to API
 	var $content;					//number of content pages
 	var $media;						//number of media files
@@ -88,21 +88,26 @@ class YellowCommandline
 		return $statusCode;
 	}
 		
-	// Build static pages
+	// Build static files
 	function buildCommand($args)
 	{
 		$statusCode = 0;
 		list($dummy, $command, $path, $location) = $args;
 		if(empty($location) || $location[0]=='/')
 		{
-			if($this->checkStaticConfig())
+			if($this->checkStaticConfig() && $this->checkStaticFilesystem())
 			{
 				$statusCode = $this->buildStatic($path, $location);
 			} else {
 				$statusCode = 500;
 				list($this->content, $this->media, $this->system, $this->error) = array(0, 0, 0, 1);
-				$fileName = $this->yellow->config->get("configDir").$this->yellow->config->get("configFile");
-				echo "ERROR bulding pages: Please configure ServerScheme, ServerName, ServerBase, ServerTime in file '$fileName'!\n";
+				if(!$this->checkStaticFilesystem())
+				{
+					echo "ERROR building files: Static website not supported on Windows file system!\n";
+				} else {
+					$fileName = $this->yellow->config->get("configDir").$this->yellow->config->get("configFile");
+					echo "ERROR building files: Please configure ServerScheme, ServerName, ServerBase, ServerTime in file '$fileName'!\n";
+				}
 			}
 			echo "Yellow $command: $this->content content, $this->media media, $this->system system";
 			echo ", $this->error error".($this->error!=1 ? 's' : '');
@@ -114,7 +119,7 @@ class YellowCommandline
 		return $statusCode;
 	}
 	
-	// Build static pages and files
+	// Build static directories and files
 	function buildStatic($path, $location)
 	{
 		$this->yellow->toolbox->timerStart($time);
@@ -231,6 +236,7 @@ class YellowCommandline
 		preg_match_all("/<a(.*?)href=\"([^\"]+)\"(.*?)>/i", $text, $matches);
 		foreach($matches[2] as $match)
 		{
+			if(preg_match("/^(.*?)#(.*)$/", $match, $tokens)) $match = $tokens[1];
 			if(preg_match("/^\w+:\/+(.*?)(\/.*)$/", $match, $tokens))
 			{
 				if($tokens[1] != $serverName) continue;
@@ -258,7 +264,7 @@ class YellowCommandline
 		}
 	}
 	
-	// Clean static pages
+	// Clean static files
 	function cleanCommand($args)
 	{
 		$statusCode = 0;
@@ -266,7 +272,7 @@ class YellowCommandline
 		if(empty($location) || $location[0]=='/')
 		{
 			$statusCode = $this->cleanStatic($path, $location);
-			echo "Yellow $command: Static page".(empty($location) ? "s" : "")." ".($statusCode!=200 ? "not " : "")."cleaned\n";
+			echo "Yellow $command: Static file".(empty($location) ? "s" : "")." ".($statusCode!=200 ? "not " : "")."cleaned\n";
 		} else {
 			$statusCode = 400;
 			echo "Yellow $command: Invalid arguments\n";
@@ -293,12 +299,12 @@ class YellowCommandline
 	function cleanStaticDirectory($path)
 	{
 		$statusCode = 200;
-		if(is_dir($path))
+		if(is_dir($path) && $this->checkStaticDirectory($path))
 		{
-			if(!$this->checkStaticDirectory($path) || !$this->yellow->toolbox->deleteDirectory($path, true))
+			if(!$this->yellow->toolbox->deleteDirectory($path, true))
 			{
 				$statusCode = 500;
-				echo "ERROR cleaning pages: Can't delete directory '$path'!\n";
+				echo "ERROR cleaning files: Can't delete directory '$path'!\n";
 			}
 		}
 		return $statusCode;
@@ -311,10 +317,10 @@ class YellowCommandline
 		$fileName = $this->getStaticFile($path, $location, $statusCode);
 		if(is_file($fileName))
 		{
-			if(!$this->checkStaticDirectory($path) || !$this->yellow->toolbox->deleteFile($fileName))
+			if(!$this->yellow->toolbox->deleteFile($fileName))
 			{
 				$statusCode = 500;
-				echo "ERROR cleaning pages: Can't delete file '$fileName'!\n";
+				echo "ERROR cleaning files: Can't delete file '$fileName'!\n";
 			}
 		}
 		return $statusCode;
@@ -383,6 +389,12 @@ class YellowCommandline
 			$this->yellow->lookup->isValidLocation($serverBase) && $serverBase!="/";
 	}
 	
+	// Check static filesystem
+	function checkStaticFilesystem()
+	{
+		return strtoupperu(substru(PHP_OS, 0, 3)) != "WIN";
+	}
+	
 	// Check static directory
 	function checkStaticDirectory($path)
 	{
@@ -390,7 +402,7 @@ class YellowCommandline
 		if(!empty($path))
 		{
 			if($path == rtrim($this->yellow->config->get("staticDir"), '/')) $ok = true;
-			if(is_file("$path/".$this->yellow->config->get("staticAccessFile"))) $ok = true;
+			if(is_file("$path/".$this->yellow->config->get("staticDefaultFile"))) $ok = true;
 			if(is_file("$path/yellow.php")) $ok = false;
 		}
 		return $ok;
@@ -442,7 +454,6 @@ class YellowCommandline
 			$files[$fileName] = $path.$this->yellow->config->get("themeLocation").basename($fileName);
 		}
 		$fileNames = array();
-		array_push($fileNames, $this->yellow->config->get("staticAccessFile"));
 		array_push($fileNames, $this->yellow->config->get("configDir").$this->yellow->config->get("robotsFile"));
 		foreach($fileNames as $fileName) $files[$fileName] = "$path/".basename($fileName);
 		return $files;

+ 6 - 4
system/plugins/core.php

@@ -45,9 +45,8 @@ class YellowCore
 		$this->config->setDefault("mediaDir", "media/");
 		$this->config->setDefault("imageDir", "media/images/");
 		$this->config->setDefault("staticDir", "cache/");
-		$this->config->setDefault("staticAccessFile", ".htaccess");
 		$this->config->setDefault("staticDefaultFile", "index.html");
-		$this->config->setDefault("staticErrorFile", "error.html");
+		$this->config->setDefault("staticErrorFile", "404.html");
 		$this->config->setDefault("contentDir", "content/");
 		$this->config->setDefault("contentRootDir", "default/");
 		$this->config->setDefault("contentHomeDir", "home/");
@@ -548,7 +547,7 @@ class YellowPage
 				if(empty($text))
 				{
 					$serverSoftware = $this->yellow->toolbox->getServerSoftware();
-					$output .= "Yellow ".YellowCore::Version.", PHP ".PHP_VERSION.", $serverSoftware\n";
+					$output .= "Yellow ".YellowCore::Version.", PHP ".PHP_VERSION.", $serverSoftware<br />\n";
 				} else if($text == "version") {
 					foreach($this->yellow->plugins->getData() as $key=>$value)
 					{
@@ -2265,7 +2264,10 @@ class YellowToolbox
 	// Return server name from current HTTP request
 	function getServerName()
 	{
-		return $_SERVER["SERVER_NAME"];
+		$serverName = $_SERVER["SERVER_NAME"];
+		$serverPort = $_SERVER["SERVER_PORT"];
+		if($serverPort!=80 && $serverPort!=443) $serverName .= ":$serverPort";
+		return $serverName;
 	}
 	
 	// Return server base from current HTTP request