1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-15 03:05:26 +02:00

Various minor unrelated updates

This commit is contained in:
Ryan Cramer
2019-08-08 14:14:36 -04:00
parent f22302aaaf
commit 8982c976c5
37 changed files with 98 additions and 3255 deletions

View File

@@ -99,7 +99,17 @@ class Pagefile extends WireData {
$this->set('modified', 0);
$this->set('created', 0);
}
/**
* Clone Pagefile
*
* #pw-internal
*
*/
public function __clone() {
$this->extras = array();
parent::__clone();
}
/**
* Set the filename associated with this Pagefile.

View File

@@ -138,12 +138,12 @@ class Pageimage extends Pagefile {
protected $error = '';
/**
* Last Pageimage::size() $options argument
* Last used Pageimage::size() $options argument
*
* @var array
*
*/
static protected $lastSizeOptions = array();
protected $sizeOptions = array();
/**
* Construct a new Pageimage
@@ -174,7 +174,6 @@ class Pageimage extends Pagefile {
public function __clone() {
$this->imageInfo['width'] = 0;
$this->imageInfo['height'] = 0;
$this->extras = array();
parent::__clone();
}
@@ -356,6 +355,23 @@ class Pageimage extends Pagefile {
return $this;
}
/**
* Set property
*
* @param string $key
* @param mixed $value
* @return Pageimage|WireData
*
*/
public function set($key, $value) {
if($key === 'sizeOptions' && is_array($value)) {
$this->sizeOptions = $value;
return $this;
} else {
return parent::set($key, $value);
}
}
/**
* Get a property from this Pageimage
@@ -426,6 +442,9 @@ class Pageimage extends Pagefile {
if(!$this->pageimageDebugInfo) $this->pageimageDebugInfo = new PageimageDebugInfo($this);
$value = $this->pageimageDebugInfo;
break;
case 'sizeOptions':
$value = $this->sizeOptions;
break;
default:
$value = parent::get($key);
}
@@ -626,10 +645,12 @@ class Pageimage extends Pagefile {
} else {
$result = $this->___size($width, $height, $options);
}
$options['_width'] = $width;
$options['_height'] = $height;
self::$lastSizeOptions = $options;
if($result) {
$options['_width'] = $width;
$options['_height'] = $height;
$result->set('sizeOptions', $options);
}
return $result;
}
@@ -1572,9 +1593,9 @@ class Pageimage extends Pagefile {
/** @var PagefileExtra $webp */
$webp = $event->object;
$webp->unlink();
if($original) {
if($original && isset($this->sizeOptions['_width'])) {
// we are in an image resized from an original
$options = self::$lastSizeOptions;
$options = $this->sizeOptions;
$width = $options['_width'];
$height = $options['_height'];
} else {
@@ -1591,7 +1612,9 @@ class Pageimage extends Pagefile {
}
$options['webpAdd'] = true;
$original->size($width, $height, $options);
$event->return = empty($this->error);
$error = $this->error;
$event->return = empty($error);
}
/**

View File

@@ -472,7 +472,8 @@ class Templates extends WireSaveableItems {
*
* @param Template $template
* @param bool $checkAccess Whether or not to check for user access to do this (default=false).
* @param bool $getAll Specify true to return all possible parents (makes method always return a PageArray)
* @param bool|int $getAll Specify true to return all possible parents (makes method always return a PageArray)
* Or specify int of maximum allowed `Page::status*` constant for items in returned PageArray (since 3.0.138).
* @return Page|NullPage|null|PageArray
*
*/
@@ -481,6 +482,7 @@ class Templates extends WireSaveableItems {
$foundParent = null;
$foundParents = $getAll ? $this->wire('pages')->newPageArray() : null;
$foundParentQty = 0;
$maxStatus = is_int($getAll) && $getAll ? ($getAll * 2) : 0;
if($template->noShortcut || !count($template->parentTemplates)) return $foundParents;
if($template->noParents == -1) {
@@ -502,7 +504,11 @@ class Templates extends WireSaveableItems {
// sort=status ensures that a non-hidden page is given preference to a hidden page
$include = $checkAccess ? "unpublished" : "all";
$selector = "templates_id=$parentTemplate->id, include=$include, sort=status";
if(!$getAll) $selector .= ", limit=2";
if($maxStatus) {
$selector .= ", status<$maxStatus";
} else if(!$getAll) {
$selector .= ", limit=2";
}
$parentPages = $this->wire('pages')->find($selector);
$numParentPages = count($parentPages);
@@ -556,11 +562,13 @@ class Templates extends WireSaveableItems {
*
* @param Template $template
* @param bool $checkAccess Specify true to exclude parent pages that user doesn't have access to add pages to (default=false)
* @param int $maxStatus Max allowed `Page::status*` constant (default=0 which means not applicable). Since 3.0.138
* @return PageArray
*
*/
public function getParentPages(Template $template, $checkAccess = false) {
return $this->getParentPage($template, $checkAccess, true);
public function getParentPages(Template $template, $checkAccess = false, $maxStatus = 0) {
$getAll = $maxStatus ? $maxStatus : true;
return $this->getParentPage($template, $checkAccess, $getAll);
}
/**

View File

@@ -95,7 +95,9 @@ class WireInputData extends Wire implements \ArrayAccess, \IteratorAggregate, \C
*/
public function __construct(&$input = array(), $lazy = false) {
$this->useFuel(false);
$this->stripSlashes = get_magic_quotes_gpc();
if(version_compare(PHP_VERSION, '5.4.0', '<') && function_exists('get_magic_quotes_gpc')) {
$this->stripSlashes = get_magic_quotes_gpc();
}
if(!empty($input)) {
if($lazy) {
$this->data = &$input;