2018-09-07 16:20:02 +00:00
|
|
|
<?php
|
2019-02-23 14:04:34 +00:00
|
|
|
// Install extension, https://github.com/datenstrom/yellow
|
2018-09-07 16:20:02 +00:00
|
|
|
|
2018-10-03 13:56:04 +00:00
|
|
|
class YellowInstall {
|
2020-10-21 10:11:06 +00:00
|
|
|
const VERSION = "0.8.38";
|
2018-10-09 12:49:48 +00:00
|
|
|
const PRIORITY = "1";
|
2020-07-24 08:18:18 +00:00
|
|
|
public $yellow; // access to API
|
2018-09-07 16:20:02 +00:00
|
|
|
|
|
|
|
// Handle initialisation
|
|
|
|
public function onLoad($yellow) {
|
|
|
|
$this->yellow = $yellow;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle request
|
|
|
|
public function onRequest($scheme, $address, $base, $location, $fileName) {
|
2020-08-04 08:29:15 +00:00
|
|
|
return $this->processRequestInstall($scheme, $address, $base, $location, $fileName);
|
2018-09-07 16:20:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Handle command
|
2020-06-25 14:46:44 +00:00
|
|
|
public function onCommand($command, $text) {
|
2020-02-24 16:00:01 +00:00
|
|
|
return $this->processCommandInstall();
|
2018-09-07 16:20:02 +00:00
|
|
|
}
|
|
|
|
|
2019-02-23 14:04:34 +00:00
|
|
|
// Process request to install website
|
2018-10-03 13:56:04 +00:00
|
|
|
public function processRequestInstall($scheme, $address, $base, $location, $fileName) {
|
2020-08-04 08:29:15 +00:00
|
|
|
$statusCode = 0;
|
|
|
|
if ($this->yellow->lookup->isContentFile($fileName) || empty($fileName)) {
|
|
|
|
$this->checkServerRequirements();
|
|
|
|
$author = trim(preg_replace("/[^\pL\d\-\. ]/u", "-", $this->yellow->page->getRequest("author")));
|
|
|
|
$email = trim($this->yellow->page->getRequest("email"));
|
|
|
|
$password = trim($this->yellow->page->getRequest("password"));
|
|
|
|
$language = trim($this->yellow->page->getRequest("language"));
|
|
|
|
$extension = trim($this->yellow->page->getRequest("extension"));
|
|
|
|
$status = trim($this->yellow->page->getRequest("status"));
|
|
|
|
$statusCode = $this->updateLog();
|
2020-08-11 18:12:05 +00:00
|
|
|
$statusCode = max($statusCode, $this->updateLanguages());
|
2020-08-04 08:29:15 +00:00
|
|
|
$this->yellow->content->pages["root/"] = array();
|
|
|
|
$this->yellow->page = new YellowPage($this->yellow);
|
|
|
|
$this->yellow->page->setRequestInformation($scheme, $address, $base, $location, $fileName);
|
|
|
|
$this->yellow->page->parseData($this->getRawDataInstall(), false, $statusCode, $this->yellow->page->get("pageError"));
|
|
|
|
if ($status=="install") $status = $this->updateExtension($extension)==200 ? "ok" : "error";
|
|
|
|
if ($status=="ok") $status = $this->updateUser($email, $password, $author, $language)==200 ? "ok" : "error";
|
|
|
|
if ($status=="ok") $status = $this->updateContent($language, "installHome", "/")==200 ? "ok" : "error";
|
|
|
|
if ($status=="ok") $status = $this->updateContent($language, "installDefault", "/shared/page-new-default")==200 ? "ok" : "error";
|
|
|
|
if ($status=="ok") $status = $this->updateContent($language, "installBlog", "/shared/page-new-blog")==200 ? "ok" : "error";
|
|
|
|
if ($status=="ok") $status = $this->updateContent($language, "installWiki", "/shared/page-new-wiki")==200 ? "ok" : "error";
|
|
|
|
if ($status=="ok") $status = $this->updateContent($language, "coreError404", "/shared/page-error-404")==200 ? "ok" : "error";
|
|
|
|
if ($status=="ok") $status = $this->updateSettings($language)==200 ? "ok" : "error";
|
|
|
|
if ($status=="ok") $status = $this->removeInstall()==200 ? "done" : "error";
|
|
|
|
if ($status=="done") {
|
|
|
|
$location = $this->yellow->lookup->normaliseUrl($scheme, $address, $base, $location);
|
|
|
|
$statusCode = $this->yellow->sendStatus(303, $location);
|
|
|
|
} else {
|
|
|
|
$statusCode = $this->yellow->sendPage();
|
|
|
|
}
|
2018-09-07 16:20:02 +00:00
|
|
|
}
|
|
|
|
return $statusCode;
|
|
|
|
}
|
|
|
|
|
2020-02-22 16:13:30 +00:00
|
|
|
// Process command to install website
|
|
|
|
public function processCommandInstall() {
|
|
|
|
$statusCode = $this->updateLog();
|
2020-08-11 18:12:05 +00:00
|
|
|
if ($statusCode==200) $statusCode = $this->updateLanguages();
|
2020-08-04 08:29:15 +00:00
|
|
|
if ($statusCode==200) $statusCode = $this->updateSettings("en");
|
2020-02-24 16:00:01 +00:00
|
|
|
if ($statusCode==200) $statusCode = $this->removeInstall();
|
2020-02-22 16:13:30 +00:00
|
|
|
if ($statusCode==200) {
|
|
|
|
$statusCode = 0;
|
|
|
|
} else {
|
|
|
|
echo "ERROR updating files: ".$this->yellow->page->get("pageError")."\n";
|
|
|
|
echo "Your website has ".($statusCode!=200 ? "not " : "")."been updated: Please run command again\n";
|
|
|
|
}
|
|
|
|
return $statusCode;
|
|
|
|
}
|
|
|
|
|
2019-03-16 07:59:37 +00:00
|
|
|
// Update log
|
|
|
|
public function updateLog() {
|
|
|
|
$statusCode = 200;
|
2020-06-25 14:46:44 +00:00
|
|
|
$fileName = $this->yellow->system->get("coreExtensionDirectory").$this->yellow->system->get("coreLogFile");
|
2019-03-16 07:59:37 +00:00
|
|
|
if (!is_file($fileName)) {
|
2020-06-21 20:47:32 +00:00
|
|
|
list($name, $version) = $this->yellow->toolbox->detectServerInformation();
|
2020-08-08 08:15:48 +00:00
|
|
|
$this->yellow->log("info", "Datenstrom Yellow ".YellowCore::RELEASE.", PHP ".PHP_VERSION.", $name $version, ".$this->getOperatingSystem());
|
2019-03-16 07:59:37 +00:00
|
|
|
if (!is_file($fileName)) {
|
|
|
|
$statusCode = 500;
|
|
|
|
$this->yellow->page->error(500, "Can't write file '$fileName'!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $statusCode;
|
|
|
|
}
|
|
|
|
|
2020-08-11 18:12:05 +00:00
|
|
|
// Update languages
|
|
|
|
public function updateLanguages() {
|
2018-09-07 16:20:02 +00:00
|
|
|
$statusCode = 200;
|
2020-06-25 14:46:44 +00:00
|
|
|
$path = $this->yellow->system->get("coreExtensionDirectory")."install-languages.zip";
|
2020-07-26 14:51:07 +00:00
|
|
|
if (is_file($path) && $this->yellow->extension->isExisting("update")) {
|
2018-09-07 16:20:02 +00:00
|
|
|
$zip = new ZipArchive();
|
|
|
|
if ($zip->open($path)===true) {
|
2020-08-11 18:12:05 +00:00
|
|
|
$pathBase = "";
|
2018-09-07 16:20:02 +00:00
|
|
|
if (preg_match("#^(.*\/).*?$#", $zip->getNameIndex(0), $matches)) $pathBase = $matches[1];
|
2019-02-25 20:50:19 +00:00
|
|
|
$fileData = $zip->getFromName($pathBase.$this->yellow->system->get("updateExtensionFile"));
|
2020-08-11 18:12:05 +00:00
|
|
|
foreach ($this->getExtensionsRequired($fileData) as $extension) {
|
|
|
|
$fileDataPhp = $zip->getFromName($pathBase."$extension/$extension.php");
|
|
|
|
$fileDataTxt = $zip->getFromName($pathBase."$extension/$extension.txt");
|
|
|
|
$fileDataIni = $zip->getFromName($pathBase."$extension/extension.ini");
|
|
|
|
$statusCode = max($statusCode, $this->updateLanguageArchive($fileDataPhp, $fileDataTxt, $fileDataIni, $pathBase, "install"));
|
2018-09-07 16:20:02 +00:00
|
|
|
}
|
2020-10-21 09:01:32 +00:00
|
|
|
$this->yellow->language->load($this->yellow->system->get("coreExtensionDirectory")."(.*).txt");
|
2018-09-07 16:20:02 +00:00
|
|
|
$zip->close();
|
|
|
|
} else {
|
|
|
|
$statusCode = 500;
|
|
|
|
$this->yellow->page->error(500, "Can't open file '$path'!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $statusCode;
|
|
|
|
}
|
|
|
|
|
2020-08-11 18:12:05 +00:00
|
|
|
// Update language archive
|
|
|
|
public function updateLanguageArchive($fileDataPhp, $fileDataTxt, $fileDataIni, $pathBase, $action) {
|
|
|
|
$statusCode = 200;
|
|
|
|
if ($this->yellow->extension->isExisting("update")) {
|
|
|
|
$settings = $this->yellow->toolbox->getTextSettings($fileDataIni, "");
|
|
|
|
$extension = lcfirst($settings->get("extension"));
|
|
|
|
$version = $settings->get("version");
|
|
|
|
$modified = strtotime($settings->get("published"));
|
|
|
|
$fileNamePhp = $this->yellow->system->get("coreExtensionDirectory").$extension.".php";
|
|
|
|
$fileNameTxt = $this->yellow->system->get("coreExtensionDirectory").$extension.".txt";
|
|
|
|
if (!empty($extension) && !empty($version) && !is_file($fileNamePhp)) {
|
|
|
|
$statusCode = $this->yellow->extension->get("update")->updateExtensionSettings($extension, $settings, $action);
|
|
|
|
if ($statusCode==200) $statusCode = $this->yellow->extension->get("update")->updateExtensionFile(
|
|
|
|
$fileNamePhp, $fileDataPhp, $modified, 0, 0, "create", $extension);
|
|
|
|
if ($statusCode==200) $statusCode = $this->yellow->extension->get("update")->updateExtensionFile(
|
|
|
|
$fileNameTxt, $fileDataTxt, $modified, 0, 0, "create", $extension);
|
|
|
|
$this->yellow->log($statusCode==200 ? "info" : "error", ucfirst($action)." extension '".ucfirst($extension)." $version'");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $statusCode;
|
|
|
|
}
|
|
|
|
|
2019-02-23 14:04:34 +00:00
|
|
|
// Update extension
|
|
|
|
public function updateExtension($extension) {
|
2018-09-07 16:20:02 +00:00
|
|
|
$statusCode = 200;
|
2020-08-11 18:12:05 +00:00
|
|
|
$path = $this->yellow->system->get("coreExtensionDirectory")."install-".$extension.".zip";
|
|
|
|
if (is_file($path) && $this->yellow->extension->isExisting("update")) {
|
|
|
|
$statusCode = $this->yellow->extension->get("update")->updateExtensionArchive($path, "install");
|
2018-09-07 16:20:02 +00:00
|
|
|
}
|
|
|
|
return $statusCode;
|
|
|
|
}
|
|
|
|
|
2019-06-04 20:39:27 +00:00
|
|
|
// Update user
|
|
|
|
public function updateUser($email, $password, $name, $language) {
|
|
|
|
$statusCode = 200;
|
2020-07-26 14:51:07 +00:00
|
|
|
if (!empty($email) && !empty($password) && $this->yellow->extension->isExisting("edit")) {
|
2019-06-04 20:39:27 +00:00
|
|
|
if (empty($name)) $name = $this->yellow->system->get("sitename");
|
2020-07-26 14:51:07 +00:00
|
|
|
$fileNameUser = $this->yellow->system->get("coreSettingDirectory").$this->yellow->system->get("coreUserFile");
|
2019-09-12 12:56:05 +00:00
|
|
|
$settings = array(
|
|
|
|
"name" => $name,
|
|
|
|
"language" => $language,
|
|
|
|
"home" => "/",
|
2019-12-17 10:46:09 +00:00
|
|
|
"access" => "create, edit, delete, upload, system, update",
|
2020-07-26 14:51:07 +00:00
|
|
|
"hash" => $this->yellow->extension->get("edit")->response->createHash($password),
|
|
|
|
"stamp" => $this->yellow->extension->get("edit")->response->createStamp(),
|
2020-01-15 18:30:45 +00:00
|
|
|
"pending" => "none",
|
2019-09-12 12:56:05 +00:00
|
|
|
"failed" => "0",
|
2020-01-15 18:30:45 +00:00
|
|
|
"modified" => time(),
|
|
|
|
"status" => "active");
|
2020-07-26 14:51:07 +00:00
|
|
|
if (!$this->yellow->user->save($fileNameUser, $email, $settings)) {
|
2019-06-04 20:39:27 +00:00
|
|
|
$statusCode = 500;
|
|
|
|
$this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
|
|
|
|
}
|
|
|
|
$this->yellow->log($statusCode==200 ? "info" : "error", "Add user '".strtok($name, " ")."'");
|
|
|
|
}
|
|
|
|
return $statusCode;
|
|
|
|
}
|
|
|
|
|
2018-09-18 11:04:15 +00:00
|
|
|
// Update content
|
2018-09-07 16:20:02 +00:00
|
|
|
public function updateContent($language, $name, $location) {
|
|
|
|
$statusCode = 200;
|
2019-04-22 09:06:04 +00:00
|
|
|
$fileName = $this->yellow->lookup->findFileFromLocation($location);
|
2020-07-23 06:36:57 +00:00
|
|
|
$fileData = str_replace("\r\n", "\n", $this->yellow->toolbox->readFile($fileName));
|
2019-04-22 09:06:04 +00:00
|
|
|
if (!empty($fileData) && $language!="en") {
|
2020-08-05 17:54:16 +00:00
|
|
|
$settingsOld = "Title: ".$this->yellow->language->getText("{$name}Title", "en")."\n".
|
|
|
|
"TitleContent: ".$this->yellow->language->getText("{$name}TitleContent", "en")."\n";
|
|
|
|
$settingsNew = "Title: ".$this->yellow->language->getText("{$name}Title", $language)."\n".
|
|
|
|
"TitleContent: ".$this->yellow->language->getText("{$name}TitleContent", $language)."\n";
|
2020-07-26 14:51:07 +00:00
|
|
|
$textOld = str_replace("\\n", "\n", $this->yellow->language->getText("{$name}Text", "en"));
|
|
|
|
$textNew = str_replace("\\n", "\n", $this->yellow->language->getText("{$name}Text", $language));
|
2020-08-05 17:54:16 +00:00
|
|
|
$fileData = str_replace($settingsOld, $settingsNew, $fileData);
|
2020-07-23 06:36:57 +00:00
|
|
|
$fileData = str_replace($textOld, $textNew, $fileData);
|
2019-04-22 09:06:04 +00:00
|
|
|
if (!$this->yellow->toolbox->createFile($fileName, $fileData)) {
|
|
|
|
$statusCode = 500;
|
|
|
|
$this->yellow->page->error($statusCode, "Can't write file '$fileName'!");
|
2018-09-07 16:20:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $statusCode;
|
|
|
|
}
|
|
|
|
|
2020-08-04 08:29:15 +00:00
|
|
|
// Update settings
|
|
|
|
public function updateSettings($language) {
|
2020-01-15 18:30:45 +00:00
|
|
|
$statusCode = 200;
|
2020-08-04 08:29:15 +00:00
|
|
|
$fileName = $this->yellow->system->get("coreSettingDirectory").$this->yellow->system->get("coreSystemFile");
|
|
|
|
if (!$this->yellow->system->save($fileName, $this->getSystemData())) {
|
|
|
|
$statusCode = 500;
|
|
|
|
$this->yellow->page->error($statusCode, "Can't write file '$fileName'!");
|
|
|
|
}
|
2020-07-26 14:51:07 +00:00
|
|
|
$fileName = $this->yellow->system->get("coreSettingDirectory").$this->yellow->system->get("coreLanguageFile");
|
2020-01-15 18:30:45 +00:00
|
|
|
$fileData = $this->yellow->toolbox->readFile($fileName);
|
2020-08-11 18:12:05 +00:00
|
|
|
if (strposu($fileData, "Language:")===false) {
|
|
|
|
if (!empty($fileData)) $fileData .= "\n";
|
2020-01-15 18:30:45 +00:00
|
|
|
$fileData .= "Language: $language\n";
|
2020-07-26 14:51:07 +00:00
|
|
|
$fileData .= "media/images/photo.jpg: ".$this->yellow->language->getText("installExampleImage", $language)."\n";
|
2020-01-15 18:30:45 +00:00
|
|
|
if (!$this->yellow->toolbox->createFile($fileName, $fileData)) {
|
|
|
|
$statusCode = 500;
|
|
|
|
$this->yellow->page->error($statusCode, "Can't write file '$fileName'!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $statusCode;
|
|
|
|
}
|
|
|
|
|
2019-02-23 14:04:34 +00:00
|
|
|
// Remove files used by installation
|
2020-02-24 16:00:01 +00:00
|
|
|
public function removeInstall() {
|
2018-10-03 11:24:52 +00:00
|
|
|
$statusCode = 200;
|
|
|
|
if (function_exists("opcache_reset")) opcache_reset();
|
2020-06-25 14:46:44 +00:00
|
|
|
$path = $this->yellow->system->get("coreExtensionDirectory");
|
2018-10-03 11:24:52 +00:00
|
|
|
foreach ($this->yellow->toolbox->getDirectoryEntries($path, "/^.*\.zip$/", true, false) as $entry) {
|
2018-10-03 13:56:04 +00:00
|
|
|
if (preg_match("/^install-(.*?)\./", basename($entry), $matches)) {
|
2018-10-03 11:24:52 +00:00
|
|
|
if (!$this->yellow->toolbox->deleteFile($entry)) {
|
|
|
|
$statusCode = 500;
|
|
|
|
$this->yellow->page->error($statusCode, "Can't delete file '$entry'!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-25 14:46:44 +00:00
|
|
|
$path = $this->yellow->system->get("coreExtensionDirectory")."install.php";
|
2018-10-03 11:24:52 +00:00
|
|
|
if ($statusCode==200 && !$this->yellow->toolbox->deleteFile($path)) {
|
|
|
|
$statusCode = 500;
|
|
|
|
$this->yellow->page->error($statusCode, "Can't delete file '$path'!");
|
|
|
|
}
|
2020-07-26 14:51:07 +00:00
|
|
|
if ($statusCode==200) unset($this->yellow->extension->data["install"]);
|
2018-10-03 11:24:52 +00:00
|
|
|
return $statusCode;
|
|
|
|
}
|
|
|
|
|
2020-02-24 16:00:01 +00:00
|
|
|
// Check web server requirements
|
|
|
|
public function checkServerRequirements() {
|
2020-06-21 20:47:32 +00:00
|
|
|
list($name) = $this->yellow->toolbox->detectServerInformation();
|
2020-02-24 16:00:01 +00:00
|
|
|
$troubleshooting = "<a href=\"https://datenstrom.se/yellow/help/troubleshooting\">See troubleshooting</a>.";
|
2020-06-23 16:20:44 +00:00
|
|
|
$this->checkServerConfiguration() || die("Datenstrom Yellow requires configuration file for $name! $troubleshooting\n");
|
2020-06-21 20:47:32 +00:00
|
|
|
$this->checkServerRewrite() || die("Datenstrom Yellow requires rewrite support for $name! $troubleshooting\n");
|
|
|
|
$this->checkServerWrite() || die("Datenstrom Yellow requires write access for $name! $troubleshooting\n");
|
2020-02-22 16:13:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check web server configuration file
|
|
|
|
public function checkServerConfiguration() {
|
2020-06-21 20:47:32 +00:00
|
|
|
list($name) = $this->yellow->toolbox->detectServerInformation();
|
|
|
|
return strtoloweru($name)!="apache" || is_file(".htaccess");
|
2020-02-12 16:25:03 +00:00
|
|
|
}
|
|
|
|
|
2020-02-22 16:13:30 +00:00
|
|
|
// Check web server rewrite support
|
|
|
|
public function checkServerRewrite() {
|
2018-09-07 16:20:02 +00:00
|
|
|
$curlHandle = curl_init();
|
2020-02-22 16:13:30 +00:00
|
|
|
list($scheme, $address, $base) = $this->yellow->getRequestInformation();
|
2020-07-26 14:51:07 +00:00
|
|
|
$location = $this->yellow->system->get("coreThemeLocation").$this->yellow->lookup->normaliseName($this->yellow->system->get("theme")).".css";
|
2018-09-07 16:20:02 +00:00
|
|
|
$url = $this->yellow->lookup->normaliseUrl($scheme, $address, $base, $location);
|
|
|
|
curl_setopt($curlHandle, CURLOPT_URL, $url);
|
|
|
|
curl_setopt($curlHandle, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; YellowCore/".YellowCore::VERSION).")";
|
|
|
|
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
curl_setopt($curlHandle, CURLOPT_CONNECTTIMEOUT, 30);
|
|
|
|
$rawData = curl_exec($curlHandle);
|
|
|
|
$statusCode = curl_getinfo($curlHandle, CURLINFO_HTTP_CODE);
|
|
|
|
curl_close($curlHandle);
|
2020-02-24 16:00:01 +00:00
|
|
|
return $statusCode==200;
|
2018-09-07 16:20:02 +00:00
|
|
|
}
|
|
|
|
|
2020-02-15 23:32:12 +00:00
|
|
|
// Check web server write access
|
2020-02-22 16:13:30 +00:00
|
|
|
public function checkServerWrite() {
|
2020-06-25 14:46:44 +00:00
|
|
|
$fileName = $this->yellow->system->get("coreSettingDirectory").$this->yellow->system->get("coreSystemFile");
|
2019-02-23 14:04:34 +00:00
|
|
|
return $this->yellow->system->save($fileName, array());
|
2018-09-07 16:20:02 +00:00
|
|
|
}
|
|
|
|
|
2020-06-23 16:20:44 +00:00
|
|
|
// Detect browser languages
|
2019-02-23 14:04:34 +00:00
|
|
|
public function detectBrowserLanguages($languagesDefault) {
|
|
|
|
$languages = array();
|
2020-06-23 16:20:44 +00:00
|
|
|
foreach (preg_split("/\s*,\s*/", $this->yellow->toolbox->getServer("HTTP_ACCEPT_LANGUAGE")) as $string) {
|
2020-06-28 17:16:07 +00:00
|
|
|
list($language, $dummy) = $this->yellow->toolbox->getTextList($string, ";", 2);
|
2020-06-23 16:20:44 +00:00
|
|
|
if (!empty($language)) array_push($languages, $language);
|
2018-09-07 16:20:02 +00:00
|
|
|
}
|
|
|
|
foreach (preg_split("/\s*,\s*/", $languagesDefault) as $language) {
|
2019-02-23 14:04:34 +00:00
|
|
|
if (!empty($language)) array_push($languages, $language);
|
2018-09-07 16:20:02 +00:00
|
|
|
}
|
2019-02-23 14:04:34 +00:00
|
|
|
return array_unique($languages);
|
2018-09-07 16:20:02 +00:00
|
|
|
}
|
|
|
|
|
2020-08-08 08:15:48 +00:00
|
|
|
// Return operating system name
|
|
|
|
public function getOperatingSystem() {
|
|
|
|
if (PHP_OS=="Darwin") {
|
|
|
|
$name = "Mac";
|
|
|
|
} else if (strtoupperu(substru(PHP_OS, 0, 3))=="WIN") {
|
|
|
|
$name = "Windows";
|
|
|
|
} else {
|
|
|
|
$name = PHP_OS;
|
|
|
|
}
|
|
|
|
return $name;
|
|
|
|
}
|
|
|
|
|
2020-02-22 16:13:30 +00:00
|
|
|
// Return system data including static information
|
2019-02-23 14:04:34 +00:00
|
|
|
public function getSystemData() {
|
2018-09-07 16:20:02 +00:00
|
|
|
$data = array();
|
|
|
|
foreach ($_REQUEST as $key=>$value) {
|
2019-02-23 14:04:34 +00:00
|
|
|
if (!$this->yellow->system->isExisting($key)) continue;
|
2019-12-12 13:51:53 +00:00
|
|
|
if ($key=="password" || $key=="status") continue;
|
2018-09-07 16:20:02 +00:00
|
|
|
$data[$key] = trim($value);
|
|
|
|
}
|
2020-06-21 20:47:32 +00:00
|
|
|
$data["coreServerTimezone"] = $this->yellow->toolbox->detectServerTimezone();
|
2020-08-11 18:12:05 +00:00
|
|
|
$data["coreStaticUrl"] = $this->yellow->toolbox->detectServerUrl();
|
2019-12-15 16:22:07 +00:00
|
|
|
if ($this->yellow->isCommandLine()) $data["coreStaticUrl"] = getenv("URL");
|
2020-08-11 18:12:05 +00:00
|
|
|
if ($this->yellow->system->get("updateNotification")=="none") $data["updateNotification"] = "website/install";
|
2018-09-07 16:20:02 +00:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2018-10-03 13:56:04 +00:00
|
|
|
// Return raw data for install page
|
|
|
|
public function getRawDataInstall() {
|
2020-07-26 14:51:07 +00:00
|
|
|
$languages = $this->yellow->system->getValues("language");
|
|
|
|
$language = $this->yellow->toolbox->detectBrowserLanguage($languages, $this->yellow->system->get("language"));
|
|
|
|
$this->yellow->language->set($language);
|
|
|
|
$rawData = "---\nTitle:".$this->yellow->language->getText("installTitle")."\nLanguage:$language\nNavigation:navigation\nHeader:none\nFooter:none\nSidebar:none\n---\n";
|
2019-02-23 14:04:34 +00:00
|
|
|
$rawData .= "<form class=\"install-form\" action=\"".$this->yellow->page->getLocation(true)."\" method=\"post\">\n";
|
2020-07-26 14:51:07 +00:00
|
|
|
$rawData .= "<p><label for=\"author\">".$this->yellow->language->getText("editSignupName")."</label><br /><input class=\"form-control\" type=\"text\" maxlength=\"64\" name=\"author\" id=\"author\" value=\"\"></p>\n";
|
|
|
|
$rawData .= "<p><label for=\"email\">".$this->yellow->language->getText("editSignupEmail")."</label><br /><input class=\"form-control\" type=\"text\" maxlength=\"64\" name=\"email\" id=\"email\" value=\"\"></p>\n";
|
|
|
|
$rawData .= "<p><label for=\"password\">".$this->yellow->language->getText("editSignupPassword")."</label><br /><input class=\"form-control\" type=\"password\" maxlength=\"64\" name=\"password\" id=\"password\" value=\"\"></p>\n";
|
|
|
|
if (count($languages)>1) {
|
2019-02-23 14:04:34 +00:00
|
|
|
$rawData .= "<p>";
|
2020-07-26 14:51:07 +00:00
|
|
|
foreach ($languages as $language) {
|
|
|
|
$checked = $language==$this->yellow->language->language ? " checked=\"checked\"" : "";
|
|
|
|
$rawData .= "<label for=\"$language\"><input type=\"radio\" name=\"language\" id=\"$language\" value=\"$language\"$checked> ".$this->yellow->language->getTextHtml("languageDescription", $language)."</label><br />";
|
2018-09-07 16:20:02 +00:00
|
|
|
}
|
2019-02-23 14:04:34 +00:00
|
|
|
$rawData .= "</p>\n";
|
|
|
|
}
|
|
|
|
if (count($this->getExtensionsInstall())>1) {
|
2020-07-26 14:51:07 +00:00
|
|
|
$rawData .= "<p>".$this->yellow->language->getText("installExtension")."<p>";
|
2019-02-23 14:04:34 +00:00
|
|
|
foreach ($this->getExtensionsInstall() as $extension) {
|
|
|
|
$checked = $extension=="website" ? " checked=\"checked\"" : "";
|
2020-07-26 14:51:07 +00:00
|
|
|
$rawData .= "<label for=\"$extension\"><input type=\"radio\" name=\"extension\" id=\"$extension\" value=\"$extension\"$checked> ".$this->yellow->language->getTextHtml("installExtension".ucfirst($extension))."</label><br />";
|
2018-09-07 16:20:02 +00:00
|
|
|
}
|
2019-02-23 14:04:34 +00:00
|
|
|
$rawData .= "</p>\n";
|
2018-09-07 16:20:02 +00:00
|
|
|
}
|
2020-07-26 14:51:07 +00:00
|
|
|
$rawData .= "<input class=\"btn\" type=\"submit\" value=\"".$this->yellow->language->getText("editOkButton")."\" />\n";
|
2019-02-23 14:04:34 +00:00
|
|
|
$rawData .= "<input type=\"hidden\" name=\"status\" value=\"install\" />\n";
|
|
|
|
$rawData .= "</form>\n";
|
2018-09-07 16:20:02 +00:00
|
|
|
return $rawData;
|
|
|
|
}
|
|
|
|
|
2019-02-23 14:04:34 +00:00
|
|
|
// Return extensions for install page
|
|
|
|
public function getExtensionsInstall() {
|
|
|
|
$extensions = array("website");
|
2020-06-25 14:46:44 +00:00
|
|
|
$path = $this->yellow->system->get("coreExtensionDirectory");
|
2018-09-07 16:20:02 +00:00
|
|
|
foreach ($this->yellow->toolbox->getDirectoryEntries($path, "/^.*\.zip$/", true, false, false) as $entry) {
|
2019-02-23 14:04:34 +00:00
|
|
|
if (preg_match("/^install-(.*?)\./", $entry, $matches) && $matches[1]!="languages") array_push($extensions, $matches[1]);
|
2018-09-07 16:20:02 +00:00
|
|
|
}
|
2019-02-23 14:04:34 +00:00
|
|
|
return $extensions;
|
2018-09-07 16:20:02 +00:00
|
|
|
}
|
2020-08-11 18:12:05 +00:00
|
|
|
|
|
|
|
// Return extensions required
|
|
|
|
public function getExtensionsRequired($fileData) {
|
|
|
|
$extensions = array();
|
2020-10-21 10:11:06 +00:00
|
|
|
$languages = array();
|
2020-08-11 18:12:05 +00:00
|
|
|
foreach ($this->yellow->toolbox->getTextLines($fileData) as $line) {
|
|
|
|
if (preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches)) {
|
|
|
|
if (!empty($matches[1]) && !empty($matches[2]) && strposu($matches[1], "/")) {
|
|
|
|
$extension = basename($matches[1]);
|
|
|
|
$extension = $this->yellow->lookup->normaliseName($extension, true, true);
|
|
|
|
list($entry, $flags) = $this->yellow->toolbox->getTextList($matches[2], ",", 2);
|
2020-09-01 08:11:20 +00:00
|
|
|
$arguments = preg_split("/\s*,\s*/", $flags);
|
2020-08-11 18:12:05 +00:00
|
|
|
$language = array_pop($arguments);
|
2020-10-21 10:11:06 +00:00
|
|
|
if (preg_match("/^(.*)\.php$/", basename($entry))) {
|
|
|
|
$languages[$language] = $extension;
|
2020-08-11 18:12:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-21 10:11:06 +00:00
|
|
|
foreach ($this->detectBrowserLanguages("en, de, fr") as $language) {
|
|
|
|
if (isset($languages[$language])) array_push($extensions, $languages[$language]);
|
|
|
|
}
|
2020-08-11 18:12:05 +00:00
|
|
|
return array_slice($extensions, 0, 3);
|
|
|
|
}
|
2018-09-07 16:20:02 +00:00
|
|
|
}
|