yellow = $yellow;
$this->response = new YellowEditResponse($yellow);
$this->users = new YellowEditUsers($yellow);
$this->merge = new YellowEditMerge($yellow);
$this->yellow->system->setDefault("editLocation", "/edit/");
$this->yellow->system->setDefault("editUploadNewLocation", "/media/@group/@filename");
$this->yellow->system->setDefault("editUploadExtensions", ".gif, .jpg, .pdf, .png, .svg, .tgz, .zip");
$this->yellow->system->setDefault("editKeyboardShortcuts", "ctrl+b bold, ctrl+i italic, ctrl+k strikethrough, ctrl+e code, ctrl+s save, ctrl+alt+p preview");
$this->yellow->system->setDefault("editToolbarButtons", "auto");
$this->yellow->system->setDefault("editEndOfLine", "auto");
$this->yellow->system->setDefault("editUserFile", "user.ini");
$this->yellow->system->setDefault("editUserPasswordMinLength", "8");
$this->yellow->system->setDefault("editUserHashAlgorithm", "bcrypt");
$this->yellow->system->setDefault("editUserHashCost", "10");
$this->yellow->system->setDefault("editUserHome", "/");
$this->yellow->system->setDefault("editNewFile", "page-new-(.*).md");
$this->yellow->system->setDefault("editLoginRestriction", "0");
$this->yellow->system->setDefault("editLoginSessionTimeout", "2592000");
$this->yellow->system->setDefault("editBruteForceProtection", "25");
$this->users->load($this->yellow->system->get("settingDir").$this->yellow->system->get("editUserFile"));
}
// Handle request
public function onRequest($scheme, $address, $base, $location, $fileName) {
$statusCode = 0;
if ($this->checkRequest($location)) {
$scheme = $this->yellow->system->get("serverScheme");
$address = $this->yellow->system->get("serverAddress");
$base = rtrim($this->yellow->system->get("serverBase").$this->yellow->system->get("editLocation"), "/");
list($scheme, $address, $base, $location, $fileName) = $this->yellow->getRequestInformation($scheme, $address, $base);
$this->yellow->page->setRequestInformation($scheme, $address, $base, $location, $fileName);
$statusCode = $this->processRequest($scheme, $address, $base, $location, $fileName);
}
return $statusCode;
}
// Handle page meta data
public function onParseMeta($page) {
if ($page==$this->yellow->page && $this->response->isActive()) {
if ($this->response->isUser()) {
if (empty($this->response->rawDataSource)) $this->response->rawDataSource = $page->rawData;
if (empty($this->response->rawDataEdit)) $this->response->rawDataEdit = $page->rawData;
if (empty($this->response->rawDataEndOfLine)) $this->response->rawDataEndOfLine = $this->response->getEndOfLine($page->rawData);
if ($page->statusCode==434) $this->response->rawDataEdit = $this->response->getRawDataNew($page, true);
}
if (empty($this->response->language)) $this->response->language = $page->get("language");
if (empty($this->response->action)) $this->response->action = $this->response->isUser() ? "none" : "login";
if (empty($this->response->status)) $this->response->status = "none";
if ($this->response->status=="error") $this->response->action = "error";
}
}
// Handle page content of shortcut
public function onParseContentShortcut($page, $name, $text, $type) {
$output = null;
if ($name=="edit" && $type=="inline") {
$editText = "$name $text";
if (substru($text, 0, 2)=="- ") $editText = trim(substru($text, 2));
$output = "get("pageEdit")."\">".htmlspecialchars($editText)."";
}
return $output;
}
// Handle page extra data
public function onParsePageExtra($page, $name) {
$output = null;
if ($name=="header" && $this->response->isActive()) {
$extensionLocation = $this->yellow->system->get("serverBase").$this->yellow->system->get("extensionLocation");
$output = "\n";
$output .= "\n";
$output .= "\n";
}
return $output;
}
// Handle command
public function onCommand($args) {
list($command) = $args;
switch ($command) {
case "user": $statusCode = $this->processCommandUser($args); break;
default: $statusCode = 0;
}
return $statusCode;
}
// Handle command help
public function onCommandHelp() {
return "user [option email password name]\n";
}
// Handle update
public function onUpdate($action) {
if ($action=="update") {
$fileNameUser = $this->yellow->system->get("settingDir").$this->yellow->system->get("editUserFile");
$fileData = $this->yellow->toolbox->readFile($fileNameUser);
foreach ($this->yellow->toolbox->getTextLines($fileData) as $line) {
preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches);
if (!empty($matches[1]) && !empty($matches[2]) && $matches[1][0]!="#") {
list($hash, $name, $language, $status, $stamp, $modified, $errors, $pending, $home) = explode(",", $matches[2]);
if ($status!="active" && $status!="inactive") {
unset($this->users->users[$matches[1]]);
continue;
}
$pending = "none";
$this->users->set($matches[1], $hash, $name, $language, $status, $stamp, $modified, $errors, $pending, $home);
$fileDataNew .= "$matches[1]: $hash,$name,$language,$status,$stamp,$modified,$errors,$pending,$home\n";
} else {
$fileDataNew .= $line;
}
}
if ($fileData!=$fileDataNew) $this->yellow->toolbox->createFile($fileNameUser, $fileDataNew);
}
}
// Process command to update user account
public function processCommandUser($args) {
list($command, $option) = $args;
switch ($option) {
case "": $statusCode = $this->userShow($args); break;
case "add": $statusCode = $this->userAdd($args); break;
case "change": $statusCode = $this->userChange($args); break;
case "remove": $statusCode = $this->userRemove($args); break;
default: $statusCode = 400; echo "Yellow $command: Invalid arguments\n";
}
return $statusCode;
}
// Show user accounts
public function userShow($args) {
list($command) = $args;
foreach ($this->users->getData() as $line) {
echo "$line\n";
}
if (!$this->users->getNumber()) echo "Yellow $command: No user accounts\n";
return 200;
}
// Add user account
public function userAdd($args) {
$status = "ok";
list($command, $option, $email, $password, $name) = $args;
if (empty($email) || empty($password)) $status = $this->response->status = "incomplete";
if (empty($name)) $name = $this->yellow->system->get("sitename");
if ($status=="ok") $status = $this->getUserAccount($email, $password, "add");
if ($status=="ok" && $this->users->isTaken($email)) $status = "taken";
switch ($status) {
case "incomplete": echo "ERROR updating settings: Please enter email and password!\n"; break;
case "invalid": echo "ERROR updating settings: Please enter a valid email!\n"; break;
case "taken": echo "ERROR updating settings: Please enter a different email!\n"; break;
case "weak": echo "ERROR updating settings: Please enter a different password!\n"; break;
}
if ($status=="ok") {
$fileNameUser = $this->yellow->system->get("settingDir").$this->yellow->system->get("editUserFile");
$status = $this->users->save($fileNameUser, $email, $password, $name, "", "active") ? "ok" : "error";
if ($status=="error") echo "ERROR updating settings: Can't write file '$fileNameUser'!\n";
$this->yellow->log($status=="ok" ? "info" : "error", "Add user '".strtok($name, " ")."'");
}
if ($status=="ok") {
$algorithm = $this->yellow->system->get("editUserHashAlgorithm");
$status = substru($this->users->getHash($email), 0, 10)!="error-hash" ? "ok" : "error";
if ($status=="error") echo "ERROR updating settings: Hash algorithm '$algorithm' not supported!\n";
}
$statusCode = $status=="ok" ? 200 : 500;
echo "Yellow $command: User account ".($statusCode!=200 ? "not " : "")."added\n";
return $statusCode;
}
// Change user account
public function userChange($args) {
$status = "ok";
list($command, $option, $email, $password, $name) = $args;
if (empty($email)) $status = $this->response->status = "invalid";
if ($status=="ok") $status = $this->getUserAccount($email, $password, "change");
if ($status=="ok" && !$this->users->isExisting($email)) $status = "unknown";
switch ($status) {
case "invalid": echo "ERROR updating settings: Please enter a valid email!\n"; break;
case "unknown": echo "ERROR updating settings: Can't find email '$email'!\n"; break;
case "weak": echo "ERROR updating settings: Please enter a different password!\n"; break;
}
if ($status=="ok") {
$fileNameUser = $this->yellow->system->get("settingDir").$this->yellow->system->get("editUserFile");
$status = $this->users->save($fileNameUser, $email, $password, $name) ? "ok" : "error";
if ($status=="error") echo "ERROR updating settings: Can't write file '$fileNameUser'!\n";
}
$statusCode = $status=="ok" ? 200 : 500;
echo "Yellow $command: User account ".($statusCode!=200 ? "not " : "")."changed\n";
return $statusCode;
}
// Remove user account
public function userRemove($args) {
$status = "ok";
list($command, $option, $email) = $args;
$name = $this->users->getName($email);
if (empty($email)) $status = $this->response->status = "invalid";
if (empty($name)) $name = $this->yellow->system->get("sitename");
if ($status=="ok") $status = $this->getUserAccount($email, "", "remove");
if ($status=="ok" && !$this->users->isExisting($email)) $status = "unknown";
switch ($status) {
case "invalid": echo "ERROR updating settings: Please enter a valid email!\n"; break;
case "unknown": echo "ERROR updating settings: Can't find email '$email'!\n"; break;
}
if ($status=="ok") {
$fileNameUser = $this->yellow->system->get("settingDir").$this->yellow->system->get("editUserFile");
$status = $this->users->remove($fileNameUser, $email) ? "ok" : "error";
if ($status=="error") echo "ERROR updating settings: Can't write file '$fileNameUser'!\n";
$this->yellow->log($status=="ok" ? "info" : "error", "Remove user '".strtok($name, " ")."'");
}
$statusCode = $status=="ok" ? 200 : 500;
echo "Yellow $command: User account ".($statusCode!=200 ? "not " : "")."removed\n";
return $statusCode;
}
// Process request
public function processRequest($scheme, $address, $base, $location, $fileName) {
$statusCode = 0;
if ($this->checkUserAuth($scheme, $address, $base, $location, $fileName)) {
switch ($_REQUEST["action"]) {
case "": $statusCode = $this->processRequestShow($scheme, $address, $base, $location, $fileName); break;
case "login": $statusCode = $this->processRequestLogin($scheme, $address, $base, $location, $fileName); break;
case "logout": $statusCode = $this->processRequestLogout($scheme, $address, $base, $location, $fileName); break;
case "quit": $statusCode = $this->processRequestQuit($scheme, $address, $base, $location, $fileName); break;
case "account": $statusCode = $this->processRequestAccount($scheme, $address, $base, $location, $fileName); break;
case "about": $statusCode = $this->processRequestAbout($scheme, $address, $base, $location, $fileName); break;
case "update": $statusCode = $this->processRequestUpdate($scheme, $address, $base, $location, $fileName); break;
case "create": $statusCode = $this->processRequestCreate($scheme, $address, $base, $location, $fileName); break;
case "edit": $statusCode = $this->processRequestEdit($scheme, $address, $base, $location, $fileName); break;
case "delete": $statusCode = $this->processRequestDelete($scheme, $address, $base, $location, $fileName); break;
case "preview": $statusCode = $this->processRequestPreview($scheme, $address, $base, $location, $fileName); break;
case "upload": $statusCode = $this->processRequestUpload($scheme, $address, $base, $location, $fileName); break;
}
} elseif ($this->checkUserUnauth($scheme, $address, $base, $location, $fileName)) {
$this->yellow->lookup->requestHandler = "core";
switch ($_REQUEST["action"]) {
case "": $statusCode = $this->processRequestShow($scheme, $address, $base, $location, $fileName); break;
case "signup": $statusCode = $this->processRequestSignup($scheme, $address, $base, $location, $fileName); break;
case "forgot": $statusCode = $this->processRequestForgot($scheme, $address, $base, $location, $fileName); break;
case "confirm": $statusCode = $this->processRequestConfirm($scheme, $address, $base, $location, $fileName); break;
case "approve": $statusCode = $this->processRequestApprove($scheme, $address, $base, $location, $fileName); break;
case "recover": $statusCode = $this->processRequestRecover($scheme, $address, $base, $location, $fileName); break;
case "reactivate": $statusCode = $this->processRequestReactivate($scheme, $address, $base, $location, $fileName); break;
case "verify": $statusCode = $this->processRequestVerify($scheme, $address, $base, $location, $fileName); break;
case "change": $statusCode = $this->processRequestChange($scheme, $address, $base, $location, $fileName); break;
case "remove": $statusCode = $this->processRequestRemove($scheme, $address, $base, $location, $fileName); break;
}
}
if ($statusCode==0) $statusCode = $this->yellow->processRequest($scheme, $address, $base, $location, $fileName, false);
$this->checkUserFailed($scheme, $address, $base, $location, $fileName);
return $statusCode;
}
// Process request to show file
public function processRequestShow($scheme, $address, $base, $location, $fileName) {
$statusCode = 0;
if (is_readable($fileName)) {
$statusCode = $this->yellow->processRequest($scheme, $address, $base, $location, $fileName, false);
} else {
if ($this->yellow->lookup->isRedirectLocation($location)) {
$location = $this->yellow->lookup->isFileLocation($location) ? "$location/" : "/".$this->yellow->getRequestLanguage()."/";
$location = $this->yellow->lookup->normaliseUrl($scheme, $address, $base, $location);
$statusCode = $this->yellow->sendStatus(301, $location);
} else {
$this->yellow->page->error($this->response->isUserRestriction() ? 404 : 434);
$statusCode = $this->yellow->processRequest($scheme, $address, $base, $location, $fileName, false);
}
}
return $statusCode;
}
// Process request for user login
public function processRequestLogin($scheme, $address, $base, $location, $fileName) {
$fileNameUser = $this->yellow->system->get("settingDir").$this->yellow->system->get("editUserFile");
if ($this->users->save($fileNameUser, $this->response->userEmail)) {
$home = $this->users->getHome($this->response->userEmail);
if (substru($location, 0, strlenu($home))==$home) {
$location = $this->yellow->lookup->normaliseUrl($scheme, $address, $base, $location);
$statusCode = $this->yellow->sendStatus(303, $location);
} else {
$location = $this->yellow->lookup->normaliseUrl($scheme, $address, $base, $home);
$statusCode = $this->yellow->sendStatus(302, $location);
}
} else {
$this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
$statusCode = $this->yellow->processRequest($scheme, $address, $base, $location, $fileName, false);
}
return $statusCode;
}
// Process request for user logout
public function processRequestLogout($scheme, $address, $base, $location, $fileName) {
$this->response->userEmail = "";
$this->response->destroyCookies($scheme, $address, $base);
$location = $this->yellow->lookup->normaliseUrl(
$this->yellow->system->get("serverScheme"),
$this->yellow->system->get("serverAddress"),
$this->yellow->system->get("serverBase"),
$location);
$statusCode = $this->yellow->sendStatus(302, $location);
return $statusCode;
}
// Process request for user signup
public function processRequestSignup($scheme, $address, $base, $location, $fileName) {
$this->response->action = "signup";
$this->response->status = "ok";
$name = trim(preg_replace("/[^\pL\d\-\. ]/u", "-", $_REQUEST["name"]));
$email = trim($_REQUEST["email"]);
$password = trim($_REQUEST["password"]);
$consent = trim($_REQUEST["consent"]);
if (empty($name) || empty($email) || empty($password) || empty($consent)) $this->response->status = "incomplete";
if ($this->response->status=="ok") $this->response->status = $this->getUserAccount($email, $password, $this->response->action);
if ($this->response->status=="ok" && $this->response->isLoginRestriction()) $this->response->status = "next";
if ($this->response->status=="ok" && $this->users->isTaken($email)) $this->response->status = "next";
if ($this->response->status=="ok") {
$fileNameUser = $this->yellow->system->get("settingDir").$this->yellow->system->get("editUserFile");
$language = $this->yellow->lookup->findLanguageFromFile($fileName, $this->yellow->system->get("language"));
$this->response->status = $this->users->save($fileNameUser, $email, $password, $name, $language, "unconfirmed") ? "ok" : "error";
if ($this->response->status=="error") $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
}
if ($this->response->status=="ok") {
$algorithm = $this->yellow->system->get("editUserHashAlgorithm");
$this->response->status = substru($this->users->getHash($email), 0, 10)!="error-hash" ? "ok" : "error";
if ($this->response->status=="error") $this->yellow->page->error(500, "Hash algorithm '$algorithm' not supported!");
}
if ($this->response->status=="ok") {
$this->response->status = $this->response->sendMail($scheme, $address, $base, $email, "confirm") ? "next" : "error";
if ($this->response->status=="error") $this->yellow->page->error(500, "Can't send email on this server!");
}
$statusCode = $this->yellow->processRequest($scheme, $address, $base, $location, $fileName, false);
return $statusCode;
}
// Process request to confirm user signup
public function processRequestConfirm($scheme, $address, $base, $location, $fileName) {
$this->response->action = "confirm";
$this->response->status = "ok";
$email = $_REQUEST["email"];
$this->response->status = $this->getUserStatus($email, $_REQUEST["action"]);
if ($this->response->status=="ok") {
$fileNameUser = $this->yellow->system->get("settingDir").$this->yellow->system->get("editUserFile");
$this->response->status = $this->users->save($fileNameUser, $email, "", "", "", "unapproved") ? "ok" : "error";
if ($this->response->status=="error") $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
}
if ($this->response->status=="ok") {
$this->response->status = $this->response->sendMail($scheme, $address, $base, $email, "approve") ? "done" : "error";
if ($this->response->status=="error") $this->yellow->page->error(500, "Can't send email on this server!");
}
$statusCode = $this->yellow->processRequest($scheme, $address, $base, $location, $fileName, false);
return $statusCode;
}
// Process request to approve user signup
public function processRequestApprove($scheme, $address, $base, $location, $fileName) {
$this->response->action = "approve";
$this->response->status = "ok";
$email = $_REQUEST["email"];
$this->response->status = $this->getUserStatus($email, $_REQUEST["action"]);
if ($this->response->status=="ok") {
$fileNameUser = $this->yellow->system->get("settingDir").$this->yellow->system->get("editUserFile");
$this->response->status = $this->users->save($fileNameUser, $email, "", "", "", "active") ? "ok" : "error";
if ($this->response->status=="error") $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
$this->yellow->log($this->response->status=="ok" ? "info" : "error", "Add user '".strtok($this->users->getName($email), " ")."'");
}
if ($this->response->status=="ok") {
$this->response->status = $this->response->sendMail($scheme, $address, $base, $email, "welcome") ? "done" : "error";
if ($this->response->status=="error") $this->yellow->page->error(500, "Can't send email on this server!");
}
$statusCode = $this->yellow->processRequest($scheme, $address, $base, $location, $fileName, false);
return $statusCode;
}
// Process request for forgotten password
public function processRequestForgot($scheme, $address, $base, $location, $fileName) {
$this->response->action = "forgot";
$this->response->status = "ok";
$email = trim($_REQUEST["email"]);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) $this->response->status = "invalid";
if ($this->response->status=="ok" && !$this->users->isExisting($email)) $this->response->status = "next";
if ($this->response->status=="ok") {
$this->response->status = $this->response->sendMail($scheme, $address, $base, $email, "recover") ? "next" : "error";
if ($this->response->status=="error") $this->yellow->page->error(500, "Can't send email on this server!");
}
$statusCode = $this->yellow->processRequest($scheme, $address, $base, $location, $fileName, false);
return $statusCode;
}
// Process request to recover password
public function processRequestRecover($scheme, $address, $base, $location, $fileName) {
$this->response->action = "recover";
$this->response->status = "ok";
$email = trim($_REQUEST["email"]);
$password = trim($_REQUEST["password"]);
$this->response->status = $this->getUserStatus($email, $_REQUEST["action"]);
if ($this->response->status=="ok") {
if (empty($password)) $this->response->status = "password";
if ($this->response->status=="ok") $this->response->status = $this->getUserAccount($email, $password, $this->response->action);
if ($this->response->status=="ok") {
$fileNameUser = $this->yellow->system->get("settingDir").$this->yellow->system->get("editUserFile");
$this->response->status = $this->users->save($fileNameUser, $email, $password) ? "ok" : "error";
if ($this->response->status=="error") $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
}
if ($this->response->status=="ok") {
$this->response->destroyCookies($scheme, $address, $base);
$this->response->status = "done";
}
}
$statusCode = $this->yellow->processRequest($scheme, $address, $base, $location, $fileName, false);
return $statusCode;
}
// Process request to reactivate account
public function processRequestReactivate($scheme, $address, $base, $location, $fileName) {
$this->response->action = "reactivate";
$this->response->status = "ok";
$email = $_REQUEST["email"];
$this->response->status = $this->getUserStatus($email, $_REQUEST["action"]);
if ($this->response->status=="ok") {
$fileNameUser = $this->yellow->system->get("settingDir").$this->yellow->system->get("editUserFile");
$this->response->status = $this->users->save($fileNameUser, $email, "", "", "", "active") ? "done" : "error";
if ($this->response->status=="error") $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
}
$statusCode = $this->yellow->processRequest($scheme, $address, $base, $location, $fileName, false);
return $statusCode;
}
// Process request to verify email
public function processRequestVerify($scheme, $address, $base, $location, $fileName) {
$this->response->action = "verify";
$this->response->status = "ok";
$email = $emailSource = $_REQUEST["email"];
$this->response->status = $this->getUserStatus($email, $_REQUEST["action"]);
if ($this->response->status=="ok") {
$emailSource = $this->users->getPending($email);
if ($this->users->getStatus($emailSource)!="active") $this->response->status = "done";
}
if ($this->response->status=="ok") {
$fileNameUser = $this->yellow->system->get("settingDir").$this->yellow->system->get("editUserFile");
$this->response->status = $this->users->save($fileNameUser, $email, "", "", "", "unchanged") ? "ok" : "error";
if ($this->response->status=="error") $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
}
if ($this->response->status=="ok") {
$this->response->status = $this->response->sendMail($scheme, $address, $base, $emailSource, "change") ? "done" : "error";
if ($this->response->status=="error") $this->yellow->page->error(500, "Can't send email on this server!");
}
$statusCode = $this->yellow->processRequest($scheme, $address, $base, $location, $fileName, false);
return $statusCode;
}
// Process request to change email or password
public function processRequestChange($scheme, $address, $base, $location, $fileName) {
$this->response->action = "change";
$this->response->status = "ok";
$email = $emailSource = trim($_REQUEST["email"]);
$this->response->status = $this->getUserStatus($email, $_REQUEST["action"]);
if ($this->response->status=="ok") {
list($email, $hash) = explode(":", $this->users->getPending($email), 2);
if (!$this->users->isExisting($email) || empty($hash)) $this->response->status = "done";
}
if ($this->response->status=="ok") {
$this->users->users[$email]["hash"] = $hash;
$this->users->users[$email]["pending"] = "none";
$fileNameUser = $this->yellow->system->get("settingDir").$this->yellow->system->get("editUserFile");
$this->response->status = $this->users->save($fileNameUser, $email, "", "", "", "active") ? "ok" : "error";
if ($this->response->status=="error") $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
}
if ($this->response->status=="ok" && $email!=$emailSource) {
$fileNameUser = $this->yellow->system->get("settingDir").$this->yellow->system->get("editUserFile");
$this->response->status = $this->users->remove($fileNameUser, $emailSource) ? "ok" : "error";
if ($this->response->status=="error") $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
}
if ($this->response->status=="ok") {
$this->response->destroyCookies($scheme, $address, $base);
$this->response->status = "done";
}
$statusCode = $this->yellow->processRequest($scheme, $address, $base, $location, $fileName, false);
return $statusCode;
}
// Process request to quit account
public function processRequestQuit($scheme, $address, $base, $location, $fileName) {
$this->response->action = "quit";
$this->response->status = "ok";
$name = trim($_REQUEST["name"]);
$email = $this->response->userEmail;
if (empty($name)) $this->response->status = "none";
if ($this->response->status=="ok" && $name!=$this->users->getName($email)) $this->response->status = "mismatch";
if ($this->response->status=="ok") $this->response->status = $this->getUserAccount($email, "", $this->response->action);
if ($this->response->status=="ok") {
$this->response->status = $this->response->sendMail($scheme, $address, $base, $email, "remove") ? "next" : "error";
if ($this->response->status=="error") $this->yellow->page->error(500, "Can't send email on this server!");
}
$statusCode = $this->yellow->processRequest($scheme, $address, $base, $location, $fileName, false);
return $statusCode;
}
// Process request to remove account
public function processRequestRemove($scheme, $address, $base, $location, $fileName) {
$this->response->action = "remove";
$this->response->status = "ok";
$email = $_REQUEST["email"];
$this->response->status = $this->getUserStatus($email, $_REQUEST["action"]);
if ($this->response->status=="ok") {
$fileNameUser = $this->yellow->system->get("settingDir").$this->yellow->system->get("editUserFile");
$this->response->status = $this->users->save($fileNameUser, $email, "", "", "", "removed") ? "ok" : "error";
if ($this->response->status=="error") $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
$this->yellow->log($this->response->status=="ok" ? "info" : "error", "Remove user '".strtok($this->users->getName($email), " ")."'");
}
if ($this->response->status=="ok") {
$this->response->status = $this->response->sendMail($scheme, $address, $base, $email, "goodbye") ? "ok" : "error";
if ($this->response->status=="error") $this->yellow->page->error(500, "Can't send email on this server!");
}
if ($this->response->status=="ok") {
$fileNameUser = $this->yellow->system->get("settingDir").$this->yellow->system->get("editUserFile");
$this->response->status = $this->users->remove($fileNameUser, $email) ? "ok" : "error";
if ($this->response->status=="error") $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
}
if ($this->response->status=="ok") {
$this->response->destroyCookies($scheme, $address, $base);
$this->response->status = "done";
}
$statusCode = $this->yellow->processRequest($scheme, $address, $base, $location, $fileName, false);
return $statusCode;
}
// Process request to change account settings
public function processRequestAccount($scheme, $address, $base, $location, $fileName) {
$this->response->action = "account";
$this->response->status = "ok";
$email = trim($_REQUEST["email"]);
$emailSource = $this->response->userEmail;
$password = trim($_REQUEST["password"]);
$name = trim(preg_replace("/[^\pL\d\-\. ]/u", "-", $_REQUEST["name"]));
$language = trim($_REQUEST["language"]);
if ($email!=$emailSource || !empty($password)) {
if (empty($email)) $this->response->status = "invalid";
if ($this->response->status=="ok") $this->response->status = $this->getUserAccount($email, $password, $this->response->action);
if ($this->response->status=="ok" && $email!=$emailSource && $this->users->isTaken($email)) $this->response->status = "taken";
if ($this->response->status=="ok" && $email!=$emailSource) {
$pending = $emailSource;
$home = $this->users->getHome($emailSource);
$fileNameUser = $this->yellow->system->get("settingDir").$this->yellow->system->get("editUserFile");
$this->response->status = $this->users->save($fileNameUser, $email, "no", $name, $language, "unverified", "", "", "", $pending, $home) ? "ok" : "error";
if ($this->response->status=="error") $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
}
if ($this->response->status=="ok") {
$pending = $email.":".(empty($password) ? $this->users->getHash($emailSource) : $this->users->createHash($password));
$fileNameUser = $this->yellow->system->get("settingDir").$this->yellow->system->get("editUserFile");
$this->response->status = $this->users->save($fileNameUser, $emailSource, "", $name, $language, "", "", "", "", $pending) ? "ok" : "error";
if ($this->response->status=="error") $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
}
if ($this->response->status=="ok") {
$action = $email!=$emailSource ? "verify" : "change";
$this->response->status = $this->response->sendMail($scheme, $address, $base, $email, $action) ? "next" : "error";
if ($this->response->status=="error") $this->yellow->page->error(500, "Can't send email on this server!");
}
} else {
if ($this->response->status=="ok") {
$fileNameUser = $this->yellow->system->get("settingDir").$this->yellow->system->get("editUserFile");
$this->response->status = $this->users->save($fileNameUser, $email, "", $name, $language) ? "done" : "error";
if ($this->response->status=="error") $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
}
}
if ($this->response->status=="done") {
$location = $this->yellow->lookup->normaliseUrl($scheme, $address, $base, $location);
$statusCode = $this->yellow->sendStatus(303, $location);
} else {
$statusCode = $this->yellow->processRequest($scheme, $address, $base, $location, $fileName, false);
}
return $statusCode;
}
// Process request to show website version and updates
public function processRequestAbout($scheme, $address, $base, $location, $fileName) {
$this->response->action = "about";
$this->response->status = "ok";
if ($this->yellow->extensions->isExisting("update")) {
list($statusCodeCurrent, $dataCurrent) = $this->yellow->extensions->get("update")->getExtensionsVersion();
list($statusCodeLatest, $dataLatest) = $this->yellow->extensions->get("update")->getExtensionsVersion(true);
list($statusCodeModified, $dataModified) = $this->yellow->extensions->get("update")->getExtensionsModified();
$statusCode = max($statusCodeCurrent, $statusCodeLatest, $statusCodeModified);
if ($this->response->isUserWebmaster()) {
foreach ($dataCurrent as $key=>$value) {
if (strnatcasecmp($dataCurrent[$key], $dataLatest[$key])<0) {
++$updates;
$rawData = htmlspecialchars(ucfirst($key)." $dataLatest[$key]")."
\n";
$this->response->rawDataOutput .= $rawData;
}
}
if ($updates==0) {
foreach ($dataCurrent as $key=>$value) {
if (!is_null($dataModified[$key]) && !is_null($dataLatest[$key])) {
$rawData = $this->yellow->text->getTextHtml("editAboutUpdateModified", $this->response->language)." - yellow->toolbox->normaliseArgs("extension:$key/option:force")."\">".$this->yellow->text->getTextHtml("editAboutUpdateForce", $this->response->language)."
\n";
$rawData = preg_replace("/@extension/i", htmlspecialchars(ucfirst($key)." $dataLatest[$key]"), $rawData);
$this->response->rawDataOutput .= $rawData;
}
}
}
$this->response->status = $updates ? "updates" : "done";
} else {
foreach ($dataCurrent as $key=>$value) {
if (strnatcasecmp($dataCurrent[$key], $dataLatest[$key])<0) ++$updates;
}
$this->response->status = $updates ? "warning" : "done";
}
if ($statusCode!=200) $this->response->status = "error";
}
$statusCode = $this->yellow->processRequest($scheme, $address, $base, $location, $fileName, false);
return $statusCode;
}
// Process request to update website
public function processRequestUpdate($scheme, $address, $base, $location, $fileName) {
$statusCode = 0;
if ($this->yellow->extensions->isExisting("update") && $this->response->isUserWebmaster()) {
$extension = trim($_REQUEST["extension"]);
$option = trim($_REQUEST["option"]);
$statusCode = $this->yellow->command("update", $extension, $option);
if ($statusCode==200) {
$location = $this->yellow->lookup->normaliseUrl($scheme, $address, $base, $location);
$statusCode = $this->yellow->sendStatus(303, $location);
}
}
return $statusCode;
}
// Process request to create page
public function processRequestCreate($scheme, $address, $base, $location, $fileName) {
$statusCode = 0;
if (!$this->response->isUserRestriction() && !empty($_REQUEST["rawdataedit"])) {
$this->response->rawDataSource = $_REQUEST["rawdatasource"];
$this->response->rawDataEdit = $_REQUEST["rawdatasource"];
$this->response->rawDataEndOfLine = $_REQUEST["rawdataendofline"];
$rawData = $_REQUEST["rawdataedit"];
$page = $this->response->getPageNew($scheme, $address, $base, $location, $fileName,
$rawData, $this->response->getEndOfLine());
if (!$page->isError()) {
if ($this->yellow->toolbox->createFile($page->fileName, $page->rawData, true)) {
$location = $this->yellow->lookup->normaliseUrl($scheme, $address, $base, $page->location);
$statusCode = $this->yellow->sendStatus(303, $location);
} else {
$this->yellow->page->error(500, "Can't write file '$page->fileName'!");
$statusCode = $this->yellow->processRequest($scheme, $address, $base, $location, $fileName, false);
}
} else {
$this->yellow->page->error(500, $page->get("pageError"));
$statusCode = $this->yellow->processRequest($scheme, $address, $base, $location, $fileName, false);
}
}
return $statusCode;
}
// Process request to edit page
public function processRequestEdit($scheme, $address, $base, $location, $fileName) {
$statusCode = 0;
if (!$this->response->isUserRestriction() && !empty($_REQUEST["rawdataedit"])) {
$this->response->rawDataSource = $_REQUEST["rawdatasource"];
$this->response->rawDataEdit = $_REQUEST["rawdataedit"];
$this->response->rawDataEndOfLine = $_REQUEST["rawdataendofline"];
$rawDataFile = $this->yellow->toolbox->readFile($fileName);
$page = $this->response->getPageEdit($scheme, $address, $base, $location, $fileName,
$this->response->rawDataSource, $this->response->rawDataEdit, $rawDataFile, $this->response->rawDataEndOfLine);
if (!$page->isError()) {
if ($this->yellow->lookup->isFileLocation($location)) {
if ($this->yellow->toolbox->renameFile($fileName, $page->fileName, true) &&
$this->yellow->toolbox->createFile($page->fileName, $page->rawData)) {
$location = $this->yellow->lookup->normaliseUrl($scheme, $address, $base, $page->location);
$statusCode = $this->yellow->sendStatus(303, $location);
} else {
$this->yellow->page->error(500, "Can't write file '$page->fileName'!");
$statusCode = $this->yellow->processRequest($scheme, $address, $base, $location, $fileName, false);
}
} else {
if ($this->yellow->toolbox->renameDirectory(dirname($fileName), dirname($page->fileName), true) &&
$this->yellow->toolbox->createFile($page->fileName, $page->rawData)) {
$location = $this->yellow->lookup->normaliseUrl($scheme, $address, $base, $page->location);
$statusCode = $this->yellow->sendStatus(303, $location);
} else {
$this->yellow->page->error(500, "Can't write file '$page->fileName'!");
$statusCode = $this->yellow->processRequest($scheme, $address, $base, $location, $fileName, false);
}
}
} else {
$this->yellow->page->error(500, $page->get("pageError"));
$statusCode = $this->yellow->processRequest($scheme, $address, $base, $location, $fileName, false);
}
}
return $statusCode;
}
// Process request to delete page
public function processRequestDelete($scheme, $address, $base, $location, $fileName) {
$statusCode = 0;
if (!$this->response->isUserRestriction() && is_file($fileName)) {
$this->response->rawDataSource = $_REQUEST["rawdatasource"];
$this->response->rawDataEdit = $_REQUEST["rawdatasource"];
$this->response->rawDataEndOfLine = $_REQUEST["rawdataendofline"];
$rawDataFile = $this->yellow->toolbox->readFile($fileName);
$page = $this->response->getPageDelete($scheme, $address, $base, $location, $fileName,
$rawDataFile, $this->response->rawDataEndOfLine);
if (!$page->isError()) {
if ($this->yellow->lookup->isFileLocation($location)) {
if ($this->yellow->toolbox->deleteFile($fileName, $this->yellow->system->get("trashDir"))) {
$location = $this->yellow->lookup->normaliseUrl($scheme, $address, $base, $location);
$statusCode = $this->yellow->sendStatus(303, $location);
} else {
$this->yellow->page->error(500, "Can't delete file '$fileName'!");
$statusCode = $this->yellow->processRequest($scheme, $address, $base, $location, $fileName, false);
}
} else {
if ($this->yellow->toolbox->deleteDirectory(dirname($fileName), $this->yellow->system->get("trashDir"))) {
$location = $this->yellow->lookup->normaliseUrl($scheme, $address, $base, $location);
$statusCode = $this->yellow->sendStatus(303, $location);
} else {
$this->yellow->page->error(500, "Can't delete file '$fileName'!");
$statusCode = $this->yellow->processRequest($scheme, $address, $base, $location, $fileName, false);
}
}
} else {
$this->yellow->page->error(500, $page->get("pageError"));
$statusCode = $this->yellow->processRequest($scheme, $address, $base, $location, $fileName, false);
}
}
return $statusCode;
}
// Process request to show preview
public function processRequestPreview($scheme, $address, $base, $location, $fileName) {
$page = $this->response->getPagePreview($scheme, $address, $base, $location, $fileName,
$_REQUEST["rawdataedit"], $_REQUEST["rawdataendofline"]);
$statusCode = $this->yellow->sendData(200, $page->outputData, "", false);
if (defined("DEBUG") && DEBUG>=1) {
$parser = $page->get("parser");
echo "YellowEdit::processRequestPreview parser:$parser
\n";
}
return $statusCode;
}
// Process request to upload file
public function processRequestUpload($scheme, $address, $base, $location, $fileName) {
$data = array();
$fileNameTemp = $_FILES["file"]["tmp_name"];
$fileNameShort = preg_replace("/[^\pL\d\-\.]/u", "-", basename($_FILES["file"]["name"]));
$fileSizeMax = $this->yellow->toolbox->getNumberBytes(ini_get("upload_max_filesize"));
$extension = strtoloweru(($pos = strrposu($fileNameShort, ".")) ? substru($fileNameShort, $pos) : "");
$extensions = preg_split("/\s*,\s*/", $this->yellow->system->get("editUploadExtensions"));
if (!$this->response->isUserRestriction() && is_uploaded_file($fileNameTemp) &&
filesize($fileNameTemp)<=$fileSizeMax && in_array($extension, $extensions)) {
$file = $this->response->getFileUpload($scheme, $address, $base, $location, $fileNameTemp, $fileNameShort);
if (!$file->isError() && $this->yellow->toolbox->copyFile($fileNameTemp, $file->fileName, true)) {
$data["location"] = $file->getLocation();
} else {
$data["error"] = "Can't write file '$file->fileName'!";
}
} else {
$data["error"] = "Can't write file '$fileNameShort'!";
}
$statusCode = $this->yellow->sendData(is_null($data["error"]) ? 200 : 500, json_encode($data), "a.json", false);
return $statusCode;
}
// Check request
public function checkRequest($location) {
$locationLength = strlenu($this->yellow->system->get("editLocation"));
$this->response->active = substru($location, 0, $locationLength)==$this->yellow->system->get("editLocation");
return $this->response->isActive();
}
// Check user authentication
public function checkUserAuth($scheme, $address, $base, $location, $fileName) {
if ($this->isRequestSameSite("POST", $scheme, $address) || $_REQUEST["action"]=="") {
if ($_REQUEST["action"]=="login") {
$email = $_REQUEST["email"];
$password = $_REQUEST["password"];
if ($this->users->checkAuthLogin($email, $password)) {
$this->response->createCookies($scheme, $address, $base, $email);
$this->response->userEmail = $email;
$this->response->userRestriction = $this->getUserRestriction($email, $location, $fileName);
$this->response->language = $this->getUserLanguage($email);
} else {
$this->response->userFailedError = "login";
$this->response->userFailedEmail = $email;
$this->response->userFailedExpire = PHP_INT_MAX;
}
} elseif (isset($_COOKIE["authtoken"]) && isset($_COOKIE["csrftoken"])) {
if ($this->users->checkAuthToken($_COOKIE["authtoken"], $_COOKIE["csrftoken"], $_POST["csrftoken"], $_REQUEST["action"]=="")) {
$this->response->userEmail = $email = $this->users->getAuthEmail($_COOKIE["authtoken"]);
$this->response->userRestriction = $this->getUserRestriction($email, $location, $fileName);
$this->response->language = $this->getUserLanguage($email);
} else {
$this->response->userFailedError = "auth";
$this->response->userFailedEmail = $this->users->getAuthEmail($_COOKIE["authtoken"]);
$this->response->userFailedExpire = $this->users->getAuthExpire($_COOKIE["authtoken"]);
}
}
}
return $this->response->isUser();
}
// Check user without authentication
public function checkUserUnauth($scheme, $address, $base, $location, $fileName) {
$ok = false;
if ($_REQUEST["action"]=="" || $_REQUEST["action"]=="signup" || $_REQUEST["action"]=="forgot") {
$ok = true;
} elseif (isset($_REQUEST["actiontoken"])) {
if ($this->users->checkActionToken($_REQUEST["actiontoken"], $_REQUEST["email"], $_REQUEST["action"], $_REQUEST["expire"])) {
$ok = true;
$this->response->language = $this->getActionLanguage($_REQUEST["language"]);
} else {
$this->response->userFailedError = "action";
$this->response->userFailedEmail = $_REQUEST["email"];
$this->response->userFailedExpire = $_REQUEST["expire"];
}
}
return $ok;
}
// Check user failed
public function checkUserFailed($scheme, $address, $base, $location, $fileName) {
if (!empty($this->response->userFailedError)) {
if ($this->response->userFailedExpire>time() && $this->users->isExisting($this->response->userFailedEmail)) {
$email = $this->response->userFailedEmail;
$modified = $this->users->getModified($email);
$errors = $this->users->getErrors($email)+1;
$fileNameUser = $this->yellow->system->get("settingDir").$this->yellow->system->get("editUserFile");
$status = $this->users->save($fileNameUser, $email, "", "", "", "", "", $modified, $errors) ? "ok" : "error";
if ($status=="error") $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
if ($errors==$this->yellow->system->get("editBruteForceProtection")) {
$statusBeforeProtection = $this->users->getStatus($email);
$statusAfterProtection = ($statusBeforeProtection=="active" || $statusBeforeProtection=="inactive") ? "inactive" : "failed";
if ($status=="ok") {
$status = $this->users->save($fileNameUser, $email, "", "", "", $statusAfterProtection, "", $modified, $errors) ? "ok" : "error";
if ($status=="error") $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
}
if ($status=="ok" && $statusBeforeProtection=="active") {
$status = $this->response->sendMail($scheme, $address, $base, $email, "reactivate") ? "done" : "error";
if ($status=="error") $this->yellow->page->error(500, "Can't send email on this server!");
}
}
}
if ($this->response->userFailedError=="login" || $this->response->userFailedError=="auth") {
$this->response->destroyCookies($scheme, $address, $base);
$this->response->status = "error";
$this->yellow->page->error(430);
} else {
$this->response->status = "error";
$this->yellow->page->error(500, "Link has expired!");
}
}
}
// Return user status changes
public function getUserStatus($email, $action) {
switch ($action) {
case "confirm": $statusExpected = "unconfirmed"; break;
case "approve": $statusExpected = "unapproved"; break;
case "recover": $statusExpected = "active"; break;
case "reactivate": $statusExpected = "inactive"; break;
case "verify": $statusExpected = "unverified"; break;
case "change": $statusExpected = "active"; break;
case "remove": $statusExpected = "active"; break;
}
return $this->users->getStatus($email)==$statusExpected ? "ok" : "done";
}
// Return user account changes
public function getUserAccount($email, $password, $action) {
$status = null;
foreach ($this->yellow->extensions->extensions as $key=>$value) {
if (method_exists($value["obj"], "onEditUserAccount")) {
$status = $value["obj"]->onEditUserAccount($email, $password, $action, $this->users);
if (!is_null($status)) break;
}
}
if (is_null($status)) {
$status = "ok";
if (!empty($password) && strlenu($password)<$this->yellow->system->get("editUserPasswordMinLength")) $status = "weak";
if (!empty($email) && !filter_var($email, FILTER_VALIDATE_EMAIL)) $status = "invalid";
}
return $status;
}
// Return user restriction
public function getUserRestriction($email, $location, $fileName) {
$userRestriction = null;
foreach ($this->yellow->extensions->extensions as $key=>$value) {
if (method_exists($value["obj"], "onEditUserRestriction")) {
$userRestriction = $value["obj"]->onEditUserRestriction($email, $location, $fileName, $this->users);
if (!is_null($userRestriction)) break;
}
}
if (is_null($userRestriction)) {
$userRestriction = substru($location, 0, strlenu($this->users->getHome($email)))!=$this->users->getHome($email);
$userRestriction |= empty($fileName) || strlenu(dirname($fileName))>128 || strlenu(basename($fileName))>128;
}
return $userRestriction;
}
// Return user language
public function getUserLanguage($email) {
$language = $this->users->getLanguage($email);
if (!$this->yellow->text->isLanguage($language)) $language = $this->yellow->system->get("language");
return $language;
}
// Return action language
public function getActionLanguage($language) {
if (!$this->yellow->text->isLanguage($language)) $language = $this->yellow->system->get("language");
return $language;
}
// Check if request came from same site
public function isRequestSameSite($method, $scheme, $address) {
if (preg_match("#^(\w+)://([^/]+)(.*)$#", $_SERVER["HTTP_REFERER"], $matches)) $origin = "$matches[1]://$matches[2]";
if (isset($_SERVER["HTTP_ORIGIN"])) $origin = $_SERVER["HTTP_ORIGIN"];
return $_SERVER["REQUEST_METHOD"]==$method && $origin=="$scheme://$address";
}
}
class YellowEditResponse {
public $yellow; //access to API
public $extension; //access to extension
public $active; //location is active? (boolean)
public $userEmail; //user email
public $userRestriction; //user with restriction? (boolean)
public $userFailedError; //error of failed authentication
public $userFailedEmail; //email of failed authentication
public $userFailedExpire; //expiration time of failed authentication
public $rawDataSource; //raw data of page for comparison
public $rawDataEdit; //raw data of page for editing
public $rawDataOutput; //raw data of dynamic output
public $rawDataEndOfLine; //end of line format for raw data
public $language; //response language
public $action; //response action
public $status; //response status
public function __construct($yellow) {
$this->yellow = $yellow;
$this->extension = $yellow->extensions->get("edit");
}
// Return new page
public function getPageNew($scheme, $address, $base, $location, $fileName, $rawData, $endOfLine) {
$page = new YellowPage($this->yellow);
$page->setRequestInformation($scheme, $address, $base, $location, $fileName);
$page->parseData($this->normaliseLines($rawData, $endOfLine), false, 0);
$this->editContentFile($page, "create");
if ($this->yellow->content->find($page->location)) {
$page->location = $this->getPageNewLocation($page->rawData, $page->location, $page->get("pageNewLocation"));
$page->fileName = $this->getPageNewFile($page->location, $page->fileName, $page->get("published"));
while ($this->yellow->content->find($page->location) || empty($page->fileName)) {
$rawData = $this->yellow->toolbox->setMetaData($page->rawData, "title", $this->getTitleNext($page->rawData));
$page->rawData = $this->normaliseLines($rawData, $endOfLine);
$page->location = $this->getPageNewLocation($page->rawData, $page->location, $page->get("pageNewLocation"));
$page->fileName = $this->getPageNewFile($page->location, $page->fileName, $page->get("published"));
if (++$pageCounter>999) break;
}
if ($this->yellow->content->find($page->location) || empty($page->fileName)) {
$page->error(500, "Page '".$page->get("title")."' is not possible!");
}
} else {
$page->fileName = $this->getPageNewFile($page->location);
}
if ($this->extension->getUserRestriction($this->userEmail, $page->location, $page->fileName)) {
$page->error(500, "Page '".$page->get("title")."' is restricted!");
}
return $page;
}
// Return modified page
public function getPageEdit($scheme, $address, $base, $location, $fileName, $rawDataSource, $rawDataEdit, $rawDataFile, $endOfLine) {
$page = new YellowPage($this->yellow);
$page->setRequestInformation($scheme, $address, $base, $location, $fileName);
$rawData = $this->extension->merge->merge(
$this->normaliseLines($rawDataSource, $endOfLine),
$this->normaliseLines($rawDataEdit, $endOfLine),
$this->normaliseLines($rawDataFile, $endOfLine));
$page->parseData($this->normaliseLines($rawData, $endOfLine), false, 0);
$pageSource = new YellowPage($this->yellow);
$pageSource->setRequestInformation($scheme, $address, $base, $location, $fileName);
$pageSource->parseData($this->normaliseLines($rawDataSource, $endOfLine), false, 0);
$this->editContentFile($page, "edit");
if ($this->isMetaModified($pageSource, $page) && $page->location!=$this->yellow->content->getHomeLocation($page->location)) {
$page->location = $this->getPageNewLocation($page->rawData, $page->location, $page->get("pageNewLocation"), true);
$page->fileName = $this->getPageNewFile($page->location, $page->fileName, $page->get("published"));
if ($page->location!=$pageSource->location && ($this->yellow->content->find($page->location) || empty($page->fileName))) {
$page->error(500, "Page '".$page->get("title")."' is not possible!");
}
}
if (empty($page->rawData)) $page->error(500, "Page has been modified by someone else!");
if ($this->extension->getUserRestriction($this->userEmail, $page->location, $page->fileName) ||
$this->extension->getUserRestriction($this->userEmail, $pageSource->location, $pageSource->fileName)) {
$page->error(500, "Page '".$page->get("title")."' is restricted!");
}
return $page;
}
// Return deleted page
public function getPageDelete($scheme, $address, $base, $location, $fileName, $rawData, $endOfLine) {
$page = new YellowPage($this->yellow);
$page->setRequestInformation($scheme, $address, $base, $location, $fileName);
$page->parseData($this->normaliseLines($rawData, $endOfLine), false, 0);
$this->editContentFile($page, "delete");
if ($this->extension->getUserRestriction($this->userEmail, $page->location, $page->fileName)) {
$page->error(500, "Page '".$page->get("title")."' is restricted!");
}
return $page;
}
// Return preview page
public function getPagePreview($scheme, $address, $base, $location, $fileName, $rawData, $endOfLine) {
$page = new YellowPage($this->yellow);
$page->setRequestInformation($scheme, $address, $base, $location, $fileName);
$page->parseData($this->normaliseLines($rawData, $endOfLine), false, 200);
$this->yellow->text->setLanguage($page->get("language"));
$class = "page-preview layout-".$page->get("layout");
$output = "