Skip to content

Commit

Permalink
Updated image upload for Robert
Browse files Browse the repository at this point in the history
  • Loading branch information
markseuffert committed Apr 23, 2024
1 parent 707e8da commit 9ef0ce3
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 20 deletions.
12 changes: 6 additions & 6 deletions system/extensions/update-available.ini
Expand Up @@ -148,14 +148,14 @@ system/themes/copenhagen.css: copenhagen.css, create, update, careful
system/themes/copenhagen.png: copenhagen.png, create

Extension: Core
Version: 0.9.4
Version: 0.9.5
Description: Core functionality of your website.
Developer: Anna Svensson
Tag: feature
DownloadUrl: https://github.com/annaesvensson/yellow-core/archive/refs/heads/main.zip
DocumentationUrl: https://github.com/annaesvensson/yellow-core
DocumentationLanguage: en, de, sv
Published: 2024-04-21 11:10:25
Published: 2024-04-23 10:16:44
Status: available
system/workers/core.php: core.php, create, update
system/extensions/core.php: coreupdate.txt, update
Expand Down Expand Up @@ -212,14 +212,14 @@ Status: available
system/workers/dutch.php: dutch.php, create, update

Extension: Edit
Version: 0.9.4
Version: 0.9.5
Description: Edit your website in a web browser.
Developer: Anna Svensson
Tag: feature
DownloadUrl: https://github.com/annaesvensson/yellow-edit/archive/refs/heads/main.zip
DocumentationUrl: https://github.com/annaesvensson/yellow-edit
DocumentationLanguage: en, de, sv
Published: 2024-04-20 15:10:16
Published: 2024-04-23 11:37:34
Status: available
system/workers/edit.php: edit.php, create, update
system/workers/edit.css: edit.css, create, update
Expand Down Expand Up @@ -431,14 +431,14 @@ system/workers/icon.css: icon.css, create, update
system/workers/icon.woff: icon.woff, create, update

Extension: Image
Version: 0.9.2
Version: 0.9.3
Description: Add images and thumbnails.
Developer: Anna Svensson
Tag: feature
DownloadUrl: https://github.com/annaesvensson/yellow-image/archive/refs/heads/main.zip
DocumentationUrl: https://github.com/annaesvensson/yellow-image
DocumentationLanguage: en, de, sv
Published: 2024-04-20 15:25:01
Published: 2024-04-23 11:44:38
Status: available
system/workers/image.php: image.php, create, update
media/images/photo.jpg: photo.jpg, create, optional
Expand Down
12 changes: 6 additions & 6 deletions system/extensions/yellow-extension.ini
@@ -1,14 +1,14 @@
# Datenstrom Yellow extension settings

Extension: Core
Version: 0.9.4
Version: 0.9.5
Description: Core functionality of your website.
Developer: Anna Svensson
Tag: feature
DownloadUrl: https://github.com/annaesvensson/yellow-core/archive/refs/heads/main.zip
DocumentationUrl: https://github.com/annaesvensson/yellow-core
DocumentationLanguage: en, de, sv
Published: 2024-04-21 11:10:25
Published: 2024-04-23 10:16:44
Status: available
system/workers/core.php: core.php, create, update
system/extensions/core.php: coreupdate.txt, update
Expand All @@ -20,14 +20,14 @@ system/layouts/navigation.html: navigation.html, create, update, careful
system/layouts/pagination.html: pagination.html, create, update, careful

Extension: Edit
Version: 0.9.4
Version: 0.9.5
Description: Edit your website in a web browser.
Developer: Anna Svensson
Tag: feature
DownloadUrl: https://github.com/annaesvensson/yellow-edit/archive/refs/heads/main.zip
DocumentationUrl: https://github.com/annaesvensson/yellow-edit
DocumentationLanguage: en, de, sv
Published: 2024-04-20 15:10:16
Published: 2024-04-23 11:37:34
Status: available
system/workers/edit.php: edit.php, create, update
system/workers/edit.css: edit.css, create, update
Expand All @@ -48,14 +48,14 @@ Status: available
system/workers/generate.php: generate.php, create, update

Extension: Image
Version: 0.9.2
Version: 0.9.3
Description: Add images and thumbnails.
Developer: Anna Svensson
Tag: feature
DownloadUrl: https://github.com/annaesvensson/yellow-image/archive/refs/heads/main.zip
DocumentationUrl: https://github.com/annaesvensson/yellow-image
DocumentationLanguage: en, de, sv
Published: 2024-04-20 15:25:01
Published: 2024-04-23 11:44:38
Status: available
system/workers/image.php: image.php, create, update
media/images/photo.jpg: photo.jpg, create, optional
Expand Down
9 changes: 7 additions & 2 deletions system/workers/core.php
Expand Up @@ -2,7 +2,7 @@
// Core extension, https://github.com/annaesvensson/yellow-core

class YellowCore {
const VERSION = "0.9.4";
const VERSION = "0.9.5";
const RELEASE = "0.9";
public $content; // content files
public $media; // media files
Expand Down Expand Up @@ -2244,6 +2244,11 @@ public function getFileDeleted($fileName) {
return $deleted;
}

// Return file size
public function getFileSize($fileName) {
return is_file($fileName) ? filesize($fileName) : 0;
}

// Return file type
public function getFileType($fileName) {
return strtoloweru(($pos = strrposu($fileName, ".")) ? substru($fileName, $pos+1) : "");
Expand Down Expand Up @@ -3073,7 +3078,7 @@ public function parseMetaData() {
if ($this->get("status")=="shared") $this->available = false;
if ($this->get("status")=="unlisted") $this->visible = false;
} else {
$this->set("size", filesize($this->fileName));
$this->set("size", $this->yellow->toolbox->getFileSize($this->fileName));
$this->set("type", $this->yellow->toolbox->getFileType($this->fileName));
$this->set("group", $this->yellow->toolbox->getFileGroup($this->fileName, $this->yellow->system->get("coreMediaDirectory")));
$this->set("modified", date("Y-m-d H:i:s", $this->yellow->toolbox->getFileModified($this->fileName)));
Expand Down
9 changes: 6 additions & 3 deletions system/workers/edit.php
Expand Up @@ -2,7 +2,7 @@
// Edit extension, https://github.com/annaesvensson/yellow-edit

class YellowEdit {
const VERSION = "0.9.4";
const VERSION = "0.9.5";
public $yellow; // access to API
public $response; // web response
public $merge; // text merge
Expand Down Expand Up @@ -1083,6 +1083,7 @@ public function getPageNew($scheme, $address, $base, $location, $fileName, $rawD
if ($this->yellow->content->find($page->location)) {
$page->location = $this->getPageNewLocation($page->rawData, $page->location, $page->get("editNewLocation"));
$page->fileName = $this->getPageNewFile($page->location, $page->fileName, $page->get("published"));
$pageCounter = 0;
while ($this->yellow->content->find($page->location) || is_string_empty($page->fileName)) {
$page->rawData = $this->yellow->toolbox->setMetaData($page->rawData, "title", $this->getTitleNext($page->rawData));
$page->rawData = $this->yellow->lookup->normaliseLines($page->rawData, $endOfLine);
Expand Down Expand Up @@ -1175,10 +1176,10 @@ public function getPagePreview($scheme, $address, $base, $location, $fileName, $
// Return uploaded file
public function getFileUpload($scheme, $address, $base, $pageLocation, $fileNameTemp, $fileNameShort) {
$file = new YellowPage($this->yellow);
$file->setRequestInformation($scheme, $address, $base, "/".$fileNameTemp, $fileNameTemp, false);
$file->setRequestInformation($scheme, $address, $base, "/".$fileNameShort, $fileNameShort, false);
$file->parseMeta(null);
$file->set("fileNameTemp", $fileNameTemp);
$file->set("fileNameShort", $fileNameShort);
$file->set("type", $this->yellow->toolbox->getFileType($fileNameShort));
if ($file->get("type")=="html" || $file->get("type")=="svg") {
$fileData = $this->yellow->toolbox->readFile($fileNameTemp);
$fileData = $this->yellow->lookup->normaliseData($fileData, $file->get("type"));
Expand All @@ -1187,8 +1188,10 @@ public function getFileUpload($scheme, $address, $base, $pageLocation, $fileName
}
}
$this->editMediaFile($file, "upload", $this->userEmail);
$fileNameShort = basename($file->fileName);
$file->location = $this->getFileNewLocation($fileNameShort, $pageLocation, $file->get("fileNewLocation"));
$file->fileName = substru($file->location, 1);
$fileCounter = 0;
while (is_file($file->fileName)) {
$fileNameShort = $this->getFileNext(basename($file->fileName));
$file->location = $this->getFileNewLocation($fileNameShort, $pageLocation, $file->get("fileNewLocation"));
Expand Down
19 changes: 16 additions & 3 deletions system/workers/image.php
Expand Up @@ -2,7 +2,7 @@
// Image extension, https://github.com/annaesvensson/yellow-image

class YellowImage {
const VERSION = "0.9.2";
const VERSION = "0.9.3";
public $yellow; // access to API

// Handle initialisation
Expand All @@ -12,6 +12,7 @@ public function onLoad($yellow) {
$this->yellow->system->setDefault("imageUploadHeightMax", "1280");
$this->yellow->system->setDefault("imageUploadJpegQuality", "80");
$this->yellow->system->setDefault("imageThumbnailJpegQuality", "80");
$this->yellow->system->setDefault("imageJpegExtension", "auto");
}

// Handle update
Expand Down Expand Up @@ -54,7 +55,7 @@ public function onParseContentElement($page, $name, $text, $attributes, $type) {
// Handle media file changes
public function onEditMediaFile($file, $action, $email) {
if ($action=="upload") {
$fileName = $file->fileName;
$fileName = $file->get("fileNameTemp");
list($widthInput, $heightInput, $orientation, $type) =
$this->yellow->toolbox->detectImageInformation($fileName, $file->get("type"));
$widthMax = $this->yellow->system->get("imageUploadWidthMax");
Expand All @@ -76,6 +77,10 @@ public function onEditMediaFile($file, $action, $email) {
}
}
}
if ($type=="jpeg") {
$file->fileName = dirname($file->fileName)."/".pathinfo($file->fileName, PATHINFO_FILENAME).$this->getImageExtension($file->fileName, $type);
$file->set("type", $this->yellow->toolbox->getFileType($file->fileName));
}
}
}

Expand All @@ -93,7 +98,7 @@ public function getImageInformation($fileName, $widthOutput, $heightOutput) {
$pathThumb = $this->yellow->lookup->findMediaDirectory("coreThumbnailLocation");
$fileNameThumb = ltrim(str_replace(array("/", "\\", "."), "-", dirname($fileNameShort)."/".pathinfo($fileName, PATHINFO_FILENAME)), "-");
$fileNameThumb .= "-".$widthOutput."x".$heightOutput;
$fileNameThumb .= ".".pathinfo($fileName, PATHINFO_EXTENSION);
$fileNameThumb .= $this->getImageExtension($fileName, $type);
$fileNameOutput = $pathThumb.$fileNameThumb;
if ($this->isFileNotUpdated($fileName, $fileNameOutput)) {
$image = $this->loadImage($fileName, $type);
Expand Down Expand Up @@ -121,6 +126,14 @@ public function getImageDimensionsFit($widthInput, $heightInput, $widthMax, $hei
}
return array(intval($widthOutput), intval($heightOutput));
}

// Return image extension
public function getImageExtension($fileName, $type) {
$jpegExtension = $this->yellow->system->get("imageJpegExtension");
$fileExtension = ".".pathinfo($fileName, PATHINFO_EXTENSION);
if ($jpegExtension!="auto" && $type=="jpeg") $fileExtension = $jpegExtension;
return $fileExtension;
}

// Load image from file
public function loadImage($fileName, $type) {
Expand Down

0 comments on commit 9ef0ce3

Please sign in to comment.