Refactored code and some cleanup

This commit is contained in:
markseu 2020-01-16 11:58:00 +01:00
parent 7a724d7806
commit 0df1efec6c
2 changed files with 27 additions and 47 deletions

View file

@ -4,7 +4,7 @@
// This file may be used and distributed under the terms of the public license.
class YellowEdit {
const VERSION = "0.8.18";
const VERSION = "0.8.19";
const TYPE = "feature";
public $yellow; //access to API
public $response; //web response
@ -1468,31 +1468,6 @@ class YellowEditResponse {
return $titleText.$titleNumber;
}
// Normalise text lines, convert line endings
public function normaliseLines($text, $endOfLine = "lf") {
if ($endOfLine=="lf") {
$text = preg_replace("/\R/u", "\n", $text);
} else {
$text = preg_replace("/\R/u", "\r\n", $text);
}
return $text;
}
// Create browser cookies
public function createCookies($scheme, $address, $base, $email) {
$expire = time() + $this->yellow->system->get("editLoginSessionTimeout");
$authToken = $this->extension->users->createAuthToken($email, $expire);
$csrfToken = $this->extension->users->createCsrfToken();
setcookie("authtoken", $authToken, $expire, "$base/", "", $scheme=="https", true);
setcookie("csrftoken", $csrfToken, $expire, "$base/", "", $scheme=="https", false);
}
// Destroy browser cookies
public function destroyCookies($scheme, $address, $base) {
setcookie("authtoken", "", 1, "$base/", "", $scheme=="https", true);
setcookie("csrftoken", "", 1, "$base/", "", $scheme=="https", false);
}
// Send mail to user
public function sendMail($scheme, $address, $base, $email, $action) {
if ($action=="approve") {
@ -1531,6 +1506,21 @@ class YellowEditResponse {
$mailMessage = "$message\r\n\r\n$url\r\n-- \r\n$footer";
return mail($mailTo, $mailSubject, $mailMessage, $mailHeaders);
}
// Create browser cookies
public function createCookies($scheme, $address, $base, $email) {
$expire = time() + $this->yellow->system->get("editLoginSessionTimeout");
$authToken = $this->extension->users->createAuthToken($email, $expire);
$csrfToken = $this->extension->users->createCsrfToken();
setcookie("authtoken", $authToken, $expire, "$base/", "", $scheme=="https", true);
setcookie("csrftoken", $csrfToken, $expire, "$base/", "", $scheme=="https", false);
}
// Destroy browser cookies
public function destroyCookies($scheme, $address, $base) {
setcookie("authtoken", "", 1, "$base/", "", $scheme=="https", true);
setcookie("csrftoken", "", 1, "$base/", "", $scheme=="https", false);
}
// Change content file
public function editContentFile($page, $action) {
@ -1559,6 +1549,16 @@ class YellowEditResponse {
}
}
// Normalise text lines, convert line endings
public function normaliseLines($text, $endOfLine = "lf") {
if ($endOfLine=="lf") {
$text = preg_replace("/\R/u", "\n", $text);
} else {
$text = preg_replace("/\R/u", "\r\n", $text);
}
return $text;
}
// Check if meta data has been modified
public function isMetaModified($pageSource, $pageOther) {
return substrb($pageSource->rawData, 0, $pageSource->metaDataOffsetBytes) !=

View file

@ -4,7 +4,7 @@
// This file may be used and distributed under the terms of the public license.
class YellowMeta {
const VERSION = "0.8.10";
const VERSION = "0.8.11";
const TYPE = "feature";
public $yellow; //access to API
@ -14,26 +14,6 @@ class YellowMeta {
$this->yellow->system->setDefault("metaDefaultImage", "icon");
}
// Handle update
public function onUpdate($action) {
if ($action=="update") { //TODO: remove later, converts old settings
$path = $this->yellow->system->get("coreContentDir");
foreach ($this->yellow->toolbox->getDirectoryEntriesRecursive($path, "/^.*\.md$/", true, false) as $entry) {
$fileData = $fileDataNew = $this->yellow->toolbox->readFile($entry);
$fileDataNew = preg_replace("/SocialtagsImage:/i", "Image:", $fileDataNew);
$fileDataNew = preg_replace("/SocialtagsImageAlt:/i", "ImageAlt:", $fileDataNew);
if ($fileData!=$fileDataNew) {
$modified = $this->yellow->toolbox->getFileModified($entry);
if (!$this->yellow->toolbox->deleteFile($entry) ||
!$this->yellow->toolbox->createFile($entry, $fileDataNew) ||
!$this->yellow->toolbox->modifyFile($entry, $modified)) {
$this->yellow->log("error", "Can't write file '$entry'!");
}
}
}
}
}
// Handle page extra data
public function onParsePageExtra($page, $name) {
$output = null;