mirror of
https://github.com/processwire/processwire.git
synced 2025-08-15 11:14:12 +02:00
Update the PagefileExtra class to support some additional properties related to file size
This commit is contained in:
@@ -16,7 +16,11 @@
|
|||||||
* @property string $ext Alias of extension
|
* @property string $ext Alias of extension
|
||||||
* @property bool $exists Does the file exist?
|
* @property bool $exists Does the file exist?
|
||||||
* @property int $filesize Size of file in bytes
|
* @property int $filesize Size of file in bytes
|
||||||
|
* @property string $filesizeStr Human readable size of file
|
||||||
* @property Pagefile|Pageimage $pagefile Source Pageimage object
|
* @property Pagefile|Pageimage $pagefile Source Pageimage object
|
||||||
|
* @property int $savings Bytes saved by this extra
|
||||||
|
* @property string $savingsStr Human readable savings by this extra
|
||||||
|
* @property string $savingsPct Percent savings by this extra
|
||||||
*
|
*
|
||||||
* The following properties affect the behavior of the URL-related methods
|
* The following properties affect the behavior of the URL-related methods
|
||||||
* =======================================================================
|
* =======================================================================
|
||||||
@@ -111,6 +115,16 @@ class PagefileExtra extends WireData {
|
|||||||
return (int) @filesize($this->filename());
|
return (int) @filesize($this->filename());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return human readable file size string
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function filesizeStr() {
|
||||||
|
return wireBytesStr($this->filesize());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the full server disk path to the extra file, whether it exists or not
|
* Return the full server disk path to the extra file, whether it exists or not
|
||||||
*
|
*
|
||||||
@@ -223,6 +237,20 @@ class PagefileExtra extends WireData {
|
|||||||
case 'filesize':
|
case 'filesize':
|
||||||
$value = $this->filesize();
|
$value = $this->filesize();
|
||||||
break;
|
break;
|
||||||
|
case 'filesizeStr':
|
||||||
|
$value = $this->filesizeStr();
|
||||||
|
break;
|
||||||
|
case 'savings':
|
||||||
|
$value = $this->pagefile->filesize() - $this->filesize();
|
||||||
|
break;
|
||||||
|
case 'savingsStr':
|
||||||
|
$value = wireBytesStr($this->pagefile->filesize() - $this->filesize());
|
||||||
|
break;
|
||||||
|
case 'savingsPct':
|
||||||
|
$imageSize = $this->pagefile->filesize();
|
||||||
|
$extraSize = $this->filesize();
|
||||||
|
$value = round((($imageSize - $extraSize) / $imageSize) * 100) . '%';
|
||||||
|
break;
|
||||||
case 'url':
|
case 'url':
|
||||||
$value = $this->url();
|
$value = $this->url();
|
||||||
break;
|
break;
|
||||||
|
@@ -27,6 +27,7 @@
|
|||||||
*
|
*
|
||||||
* @property int $gridSize squared size of the admin thumbnails (default=130)
|
* @property int $gridSize squared size of the admin thumbnails (default=130)
|
||||||
* @property string $gridMode Default grid mode in admin, one of "grid", "left" or "list" (default="grid")
|
* @property string $gridMode Default grid mode in admin, one of "grid", "left" or "list" (default="grid")
|
||||||
|
* @property string $focusMode May be 'on', 'off', or 'zoom'
|
||||||
* @property array $imageSizerOptions Options to pass along to the ImageSizer class. See /wire/config.php $imageSizerOptions for details.
|
* @property array $imageSizerOptions Options to pass along to the ImageSizer class. See /wire/config.php $imageSizerOptions for details.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
@@ -624,6 +625,11 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu
|
|||||||
$sanitizer = $this->wire('sanitizer');
|
$sanitizer = $this->wire('sanitizer');
|
||||||
$thumb = $this->getAdminThumb($pagefile, false);
|
$thumb = $this->getAdminThumb($pagefile, false);
|
||||||
$fileStats = str_replace(' ', ' ', $pagefile->filesizeStr) . ", {$pagefile->width}×{$pagefile->height} ";
|
$fileStats = str_replace(' ', ' ', $pagefile->filesizeStr) . ", {$pagefile->width}×{$pagefile->height} ";
|
||||||
|
|
||||||
|
foreach($pagefile->extras() as $name => $extra) {
|
||||||
|
if($extra->exists()) $fileStats .= " • $extra->filesizeStr $name ($extra->savingsPct)";
|
||||||
|
}
|
||||||
|
|
||||||
// $gridSize = $this->gridSize;
|
// $gridSize = $this->gridSize;
|
||||||
|
|
||||||
// <div class='gridImage__overflow' style='width: {$gridSize}px; height: {$gridSize}px'>
|
// <div class='gridImage__overflow' style='width: {$gridSize}px; height: {$gridSize}px'>
|
||||||
@@ -773,8 +779,8 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu
|
|||||||
|
|
||||||
if($n) {} // ignore, $n is for hooks
|
if($n) {} // ignore, $n is for hooks
|
||||||
$pageID = $pagefile->pagefiles->page->id;
|
$pageID = $pagefile->pagefiles->page->id;
|
||||||
$variations = $this->getPagefileVariations($pagefile);
|
$variationCount = $pagefile->variations()->count();
|
||||||
$variationCount = count($variations);
|
if($pagefile->webp()->exists()) $variationCount++;
|
||||||
$editUrl = $this->getEditUrl($pagefile, $pageID);
|
$editUrl = $this->getEditUrl($pagefile, $pageID);
|
||||||
$variationUrl = $this->getVariationUrl($pagefile, $id);
|
$variationUrl = $this->getVariationUrl($pagefile, $id);
|
||||||
$buttonClass = $this->themeSettings['buttonClass'];
|
$buttonClass = $this->themeSettings['buttonClass'];
|
||||||
|
Reference in New Issue
Block a user