diff --git a/system/extensions/core.php b/system/extensions/core.php index 312ed50..f640394 100644 --- a/system/extensions/core.php +++ b/system/extensions/core.php @@ -1,6 +1,6 @@ system->setDefault("coreUserFile", "yellow-user.ini"); $this->system->setDefault("coreExtensionFile", "yellow-extension.ini"); $this->system->setDefault("coreWebsiteFile", "yellow-website.log"); + $this->system->setDefault("coreAssetLocation", "/assets/"); $this->system->setDefault("coreMediaLocation", "/media/"); $this->system->setDefault("coreDownloadLocation", "/media/downloads/"); $this->system->setDefault("coreImageLocation", "/media/images/"); $this->system->setDefault("coreThumbnailLocation", "/media/thumbnails/"); - $this->system->setDefault("coreExtensionLocation", "/media/extensions/"); $this->system->setDefault("coreMultiLanguageMode", "0"); $this->system->setDefault("coreDebugMode", "0"); } @@ -82,7 +82,8 @@ class YellowCore { $this->system->set("coreServerInstallDirectory", $pathInstall); $this->system->set("coreServerRootDirectory", $pathRoot); $this->system->set("coreServerHomeDirectory", $pathHome); - $this->system->set("coreThemeLocation", "/media/extensions/"); // TODO: remove later, for backwards compatibility + $this->system->set("coreExtensionLocation", "/assets/"); // TODO: remove later, for backwards compatibility + $this->system->set("coreThemeLocation", "/assets/"); // TODO: remove later, for backwards compatibility register_shutdown_function(array($this, "processFatalError")); if ($this->system->get("coreDebugMode")>=1) { ini_set("display_errors", 1); @@ -1289,18 +1290,8 @@ class YellowLookup { // Return media location from file path public function findMediaLocationFromFile($fileName) { $location = ""; - $themeDirectoryLength = strlenu($this->yellow->system->get("coreThemeDirectory")); - $workerDirectoryLength = strlenu($this->yellow->system->get("coreWorkerDirectory")); $mediaDirectoryLength = strlenu($this->yellow->system->get("coreMediaDirectory")); - if (substru($fileName, 0, $themeDirectoryLength)==$this->yellow->system->get("coreThemeDirectory")) { - if ($this->isSafeFile($fileName)) { - $location = $this->yellow->system->get("coreExtensionLocation").substru($fileName, $themeDirectoryLength); - } - } elseif (substru($fileName, 0, $workerDirectoryLength)==$this->yellow->system->get("coreWorkerDirectory")) { - if ($this->isSafeFile($fileName)) { - $location = $this->yellow->system->get("coreExtensionLocation").substru($fileName, $workerDirectoryLength); - } - } elseif (substru($fileName, 0, $mediaDirectoryLength)==$this->yellow->system->get("coreMediaDirectory")) { + if (substru($fileName, 0, $mediaDirectoryLength)==$this->yellow->system->get("coreMediaDirectory")) { $location = "/".$fileName; } return $location; @@ -1309,15 +1300,8 @@ class YellowLookup { // Return file path from media location public function findFileFromMediaLocation($location) { $fileName = ""; - $extensionLocationLength = strlenu($this->yellow->system->get("coreExtensionLocation")); $mediaLocationLength = strlenu($this->yellow->system->get("coreMediaLocation")); - if (substru($location, 0, $extensionLocationLength)==$this->yellow->system->get("coreExtensionLocation")) { - if ($this->isSafeFile($location)) { - $fileNameOne = $this->yellow->system->get("coreThemeDirectory").substru($location, $extensionLocationLength); - $fileNameTwo = $this->yellow->system->get("coreWorkerDirectory").substru($location, $extensionLocationLength); - $fileName = is_file($fileNameOne) ? $fileNameOne : $fileNameTwo; - } - } elseif (substru($location, 0, $mediaLocationLength)==$this->yellow->system->get("coreMediaLocation")) { + if (substru($location, 0, $mediaLocationLength)==$this->yellow->system->get("coreMediaLocation")) { $fileName = substru($location, 1); } return $fileName; @@ -1343,6 +1327,49 @@ class YellowLookup { return substru($key, -8, 8)=="Location" ? $this->findFileFromMediaLocation($this->yellow->system->get($key)) : ""; } + // Return media location from file path + public function findSystemLocationFromFile($fileName) { + $location = ""; + $layoutDirectoryLength = strlenu($this->yellow->system->get("coreLayoutDirectory")); + $themeDirectoryLength = strlenu($this->yellow->system->get("coreThemeDirectory")); + $workerDirectoryLength = strlenu($this->yellow->system->get("coreWorkerDirectory")); + if (substru($fileName, 0, $layoutDirectoryLength)==$this->yellow->system->get("coreLayoutDirectory")) { + if ($this->isSafeFile($fileName)) { + $location = $this->yellow->system->get("coreAssetLocation").substru($fileName, $layoutDirectoryLength); + } + } elseif (substru($fileName, 0, $themeDirectoryLength)==$this->yellow->system->get("coreThemeDirectory")) { + if ($this->isSafeFile($fileName)) { + $location = $this->yellow->system->get("coreAssetLocation").substru($fileName, $themeDirectoryLength); + } + } elseif (substru($fileName, 0, $workerDirectoryLength)==$this->yellow->system->get("coreWorkerDirectory")) { + if ($this->isSafeFile($fileName)) { + $location = $this->yellow->system->get("coreAssetLocation").substru($fileName, $workerDirectoryLength); + } + } + return $location; + } + + // Return file path from media location + public function findFileFromSystemLocation($location) { + $fileName = ""; + $assetLocationLength = strlenu($this->yellow->system->get("coreAssetLocation")); + if (substru($location, 0, $assetLocationLength)==$this->yellow->system->get("coreAssetLocation")) { + if ($this->isSafeFile($location)) { + $fileNameLayout = $this->yellow->system->get("coreLayoutDirectory").substru($location, $assetLocationLength); + $fileNameTheme = $this->yellow->system->get("coreThemeDirectory").substru($location, $assetLocationLength); + $fileNameWorker = $this->yellow->system->get("coreWorkerDirectory").substru($location, $assetLocationLength); + if (is_file($fileNameLayout)) { + $fileName = $fileNameLayout; + } elseif (is_file($fileNameTheme)) { + $fileName = $fileNameTheme; + } elseif (is_file($fileNameWorker)) { + $fileName = $fileNameWorker; + } + } + } + return $fileName; + } + // Return file or directory that matches token public function findFileDirectory($path, $token, $fileExtension, $directory, $default, &$found, &$invalid) { if ($this->normaliseToken($token, $fileExtension)!=$token) $invalid = true; @@ -1613,6 +1640,7 @@ class YellowLookup { } $location = substru($this->yellow->toolbox->detectServerLocation(), strlenu($base)); $fileName = ""; + if (is_string_empty($fileName)) $fileName = $this->findFileFromSystemLocation($location); if (is_string_empty($fileName)) $fileName = $this->findFileFromMediaLocation($location); if (is_string_empty($fileName)) $fileName = $this->findFileFromContentLocation($location); return array($scheme, $address, $base, $location, $fileName); @@ -3305,20 +3333,20 @@ class YellowPage { } } if ($name=="header") { - $extensionLocation = $this->yellow->system->get("coreServerBase").$this->yellow->system->get("coreExtensionLocation"); + $assetLocation = $this->yellow->system->get("coreServerBase").$this->yellow->system->get("coreAssetLocation"); $fileNameTheme = $this->yellow->system->get("coreThemeDirectory").$this->yellow->lookup->normaliseName($this->get("theme")).".css"; if (is_file($fileNameTheme)) { - $fileLocation = $extensionLocation.$this->yellow->lookup->normaliseName($this->get("theme")).".css"; + $fileLocation = $assetLocation.$this->yellow->lookup->normaliseName($this->get("theme")).".css"; $output .= "\n"; } $fileNameScript = $this->yellow->system->get("coreThemeDirectory").$this->yellow->lookup->normaliseName($this->get("theme")).".js"; if (is_file($fileNameScript)) { - $fileLocation = $extensionLocation.$this->yellow->lookup->normaliseName($this->get("theme")).".js"; + $fileLocation = $assetLocation.$this->yellow->lookup->normaliseName($this->get("theme")).".js"; $output .= "\n"; } $fileNameFavicon = $this->yellow->system->get("coreThemeDirectory").$this->yellow->lookup->normaliseName($this->get("theme")).".png"; if (is_file($fileNameFavicon)) { - $fileLocation = $extensionLocation.$this->yellow->lookup->normaliseName($this->get("theme")).".png"; + $fileLocation = $assetLocation.$this->yellow->lookup->normaliseName($this->get("theme")).".png"; $output .= "\n"; } } diff --git a/system/workers/generate.php b/system/workers/generate.php index 9713f61..99e954a 100755 --- a/system/workers/generate.php +++ b/system/workers/generate.php @@ -2,7 +2,7 @@ // Generate extension, https://github.com/annaesvensson/yellow-generate class YellowGenerate { - const VERSION = "0.9.1"; + const VERSION = "0.9.2"; public $yellow; // access to API public $files; // number of files public $errors; // number of errors @@ -74,6 +74,7 @@ class YellowGenerate { } $statusCode = max($statusCode, $this->generateStaticContent($path, $location, "\rGenerating static website", 5, 95)); $statusCode = max($statusCode, $this->generateStaticMedia($path, $location)); + $statusCode = max($statusCode, $this->generateStaticSystem($path, $location)); echo "\rGenerating static website 100%... done\n"; return $statusCode; } @@ -120,14 +121,22 @@ class YellowGenerate { foreach ($this->getMediaLocations() as $location) { $statusCode = max($statusCode, $this->generateStaticFile($path, $location)); } - foreach ($this->getExtraLocations($path) as $location) { + } + return $statusCode; + } + + // Generate static system + public function generateStaticSystem($path, $locationFilter) { + $statusCode = 200; + if (is_string_empty($locationFilter)) { + foreach ($this->getSystemLocations($path) as $location) { $statusCode = max($statusCode, $this->generateStaticFile($path, $location)); } $statusCode = max($statusCode, $this->generateStaticFile($path, "/error/", false, false, true)); } return $statusCode; } - + // Generate static file public function generateStaticFile($path, $location, $analyse = false, $probe = false, $error = false) { $this->yellow->content->pages = array(); @@ -381,58 +390,66 @@ class YellowGenerate { // Return media locations public function getMediaLocations() { $locations = array(); - $mediaPath = $this->yellow->system->get("coreMediaDirectory"); - $fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive($mediaPath, "/.*/", false, false); + $path = $this->yellow->system->get("coreMediaDirectory"); + $fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive($path, "/.*/", false, false); foreach ($fileNames as $fileName) { - array_push($locations, $this->yellow->lookup->findMediaLocationFromFile($fileName)); + $location = $this->yellow->lookup->findMediaLocationFromFile($fileName); + if (!is_string_empty($location)) array_push($locations, $location); } - $themePath = $this->yellow->system->get("coreThemeDirectory"); - $fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive($themePath, "/.*/", false, false); + return $locations; + } + + // Return system locations + public function getSystemLocations($pathIgnore) { + $locations = array(); + $path = $this->yellow->system->get("coreWorkerDirectory"); + $fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive($path, "/.*/", false, false); foreach ($fileNames as $fileName) { - array_push($locations, $this->yellow->lookup->findMediaLocationFromFile($fileName)); + $location = $this->yellow->lookup->findSystemLocationFromFile($fileName); + if (!is_string_empty($location)) array_push($locations, $location); } - $workerPath = $this->yellow->system->get("coreWorkerDirectory"); - $fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive($workerPath, "/.*/", false, false); + $path = $this->yellow->system->get("coreThemeDirectory"); + $fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive($path, "/.*/", false, false); foreach ($fileNames as $fileName) { - array_push($locations, $this->yellow->lookup->findMediaLocationFromFile($fileName)); + $location = $this->yellow->lookup->findSystemLocationFromFile($fileName); + if (!is_string_empty($location)) array_push($locations, $location); } - return array_diff($locations, $this->getMediaLocationsIgnore()); + $path = $this->yellow->system->get("coreLayoutDirectory"); + $fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive($path, "/.*/", false, false); + foreach ($fileNames as $fileName) { + $location = $this->yellow->lookup->findSystemLocationFromFile($fileName); + if (!is_string_empty($location)) array_push($locations, $location); + } + $regexIgnore = "#^(/". + $this->yellow->system->get("coreContentDirectory")."|/". + $this->yellow->system->get("coreMediaDirectory")."|/". + $this->yellow->system->get("coreSystemDirectory")."|/". + $this->yellow->system->get("generateStaticDirectory")."|/$pathIgnore/|/yellow.php)#"; + $fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive(".", "/.*/", false, false); + foreach ($fileNames as $fileName) { + $location = substru($fileName, 1); + if (!preg_match($regexIgnore, $location)) array_push($locations, $location); + } + return array_diff($locations, $this->getSystemLocationsIgnore()); } - // Return media locations to ignore - public function getMediaLocationsIgnore() { - $locations = array(""); - $workerPath = $this->yellow->system->get("coreWorkerDirectory"); + // Return system locations to ignore + public function getSystemLocationsIgnore() { + $locations = array(); + $path = $this->yellow->system->get("coreWorkerDirectory"); $workerDirectoryLength = strlenu($this->yellow->system->get("coreWorkerDirectory")); if ($this->yellow->extension->isExisting("bundle")) { - foreach ($this->yellow->toolbox->getDirectoryEntries($workerPath, "/^bundle-(.*)/", false, false) as $entry) { + foreach ($this->yellow->toolbox->getDirectoryEntries($path, "/^bundle-(.*)/", false, false) as $entry) { list($locationsBundle) = $this->yellow->extension->get("bundle")->getBundleInformation($entry); $locations = array_merge($locations, $locationsBundle); } } if ($this->yellow->extension->isExisting("edit")) { - foreach ($this->yellow->toolbox->getDirectoryEntries($workerPath, "/^edit\.(.*)/", false, false) as $entry) { - $location = $this->yellow->system->get("coreExtensionLocation").substru($entry, $workerDirectoryLength); + foreach ($this->yellow->toolbox->getDirectoryEntries($path, "/^edit(\-|\.)(.*)/", false, false) as $entry) { + $location = $this->yellow->system->get("coreAssetLocation").substru($entry, $workerDirectoryLength); array_push($locations, $location); } } return array_unique($locations); } - - // Return extra locations - public function getExtraLocations($path) { - $locations = array(); - $pathIgnore = "($path/|". - $this->yellow->system->get("generateStaticDirectory")."|". - $this->yellow->system->get("coreContentDirectory")."|". - $this->yellow->system->get("coreMediaDirectory")."|". - $this->yellow->system->get("coreSystemDirectory").")"; - $fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive(".", "/.*/", false, false); - foreach ($fileNames as $fileName) { - $fileName = substru($fileName, 2); - if (preg_match("#^$pathIgnore#", $fileName) || $fileName=="yellow.php") continue; - array_push($locations, "/".$fileName); - } - return $locations; - } }