mirror of
https://github.com/processwire/processwire.git
synced 2025-08-10 08:44:46 +02:00
Various minor updates: add a $config->version($minVersion) function, add @since tags in Sanitizer, update count() => wireCount() in FieldtypePageTable and add PHPdoc hints where phpstorm is asking for them, update InputfieldImage to track change for the field when an action manipulates the image file, plus some other minor odds and ends.
This commit is contained in:
@@ -1040,6 +1040,7 @@ $config->substituteModules = array(
|
|||||||
* #property string module Name of WireMail module to use or blank to auto-detect. (default='')
|
* #property string module Name of WireMail module to use or blank to auto-detect. (default='')
|
||||||
* #property string from Default from email address, when none provided at runtime. (default=$config->adminEmail)
|
* #property string from Default from email address, when none provided at runtime. (default=$config->adminEmail)
|
||||||
* #property string fromName Default from name string, when none provided at runtime. (default='')
|
* #property string fromName Default from name string, when none provided at runtime. (default='')
|
||||||
|
* #property string newline What to use for newline if different from RFC standard of "\r\n" (optional).
|
||||||
* #property array headers Default additional headers to send in email, key=value. (default=[])
|
* #property array headers Default additional headers to send in email, key=value. (default=[])
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
* @property bool $isSuperuser
|
* @property bool $isSuperuser
|
||||||
* @property bool $isEditor
|
* @property bool $isEditor
|
||||||
* @property bool $isLoggedIn
|
* @property bool $isLoggedIn
|
||||||
* @property bool $isModal
|
* @property bool|string $isModal
|
||||||
* @property bool|int $useAsLogin
|
* @property bool|int $useAsLogin
|
||||||
* @method array getUserNavArray()
|
* @method array getUserNavArray()
|
||||||
*
|
*
|
||||||
|
@@ -415,10 +415,33 @@ class Config extends WireData {
|
|||||||
*
|
*
|
||||||
* @param string|null $minVersion
|
* @param string|null $minVersion
|
||||||
* @return bool
|
* @return bool
|
||||||
|
* @since 3.0.101
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function phpVersion($minVersion) {
|
public function phpVersion($minVersion) {
|
||||||
return version_compare(PHP_VERSION, $minVersion) >= 0;
|
return version_compare(PHP_VERSION, $minVersion) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if current ProcessWire version is equal to or newer than given versino
|
||||||
|
*
|
||||||
|
* If no version argument is given, it simply returns the current ProcessWire version.
|
||||||
|
*
|
||||||
|
* ~~~~~
|
||||||
|
* if($config->version('3.0.100')) {
|
||||||
|
* // ProcessWire version is 3.0.100 or newer
|
||||||
|
* }
|
||||||
|
* ~~~~~
|
||||||
|
*
|
||||||
|
* @param string $minVersion Specify version string if you want to compare against current version
|
||||||
|
* @return bool|string Returns current version if no argument given, OR boolean if given a version argument:
|
||||||
|
* - If given version is older than current, returns false.
|
||||||
|
* - If given version is equal to or newer than current, returns true.
|
||||||
|
* @since 3.0.106
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function version($minVersion = '') {
|
||||||
|
return version_compare($this->version, $minVersion) >= 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -989,14 +989,14 @@ class Sanitizer extends Wire {
|
|||||||
* - `stripTags` (bool): strip markup tags? (default=true).
|
* - `stripTags` (bool): strip markup tags? (default=true).
|
||||||
* - `stripMB4` (bool): strip emoji and other 4-byte UTF-8? (default=false).
|
* - `stripMB4` (bool): strip emoji and other 4-byte UTF-8? (default=false).
|
||||||
* - `stripQuotes` (bool): strip out any "quote" or 'quote' characters? Specify true, or character to replace with. (default=false)
|
* - `stripQuotes` (bool): strip out any "quote" or 'quote' characters? Specify true, or character to replace with. (default=false)
|
||||||
* - `stripSpace` (bool|string): strip whitespace? Specify true or character to replace whitespace with (default=false).
|
* - `stripSpace` (bool|string): strip whitespace? Specify true or character to replace whitespace with (default=false). Since 3.0.105
|
||||||
* - `reduceSpace` (bool|string): reduce consecutive whitespace to single? Specify true or character to reduce to (default=false).
|
* - `reduceSpace` (bool|string): reduce consecutive whitespace to single? Specify true or character to reduce to (default=false).
|
||||||
* Note that the reduceSpace option is an alternative to the stripSpace option, they should not be used together.
|
* Note that the reduceSpace option is an alternative to the stripSpace option, they should not be used together. Since 3.0.105
|
||||||
* - `allowableTags` (string): markup tags that are allowed, if stripTags is true (use same format as for PHP's `strip_tags()` function.
|
* - `allowableTags` (string): markup tags that are allowed, if stripTags is true (use same format as for PHP's `strip_tags()` function.
|
||||||
* - `multiLine` (bool): allow multiple lines? if false, then $newlineReplacement below is applicable (default=false).
|
* - `multiLine` (bool): allow multiple lines? if false, then $newlineReplacement below is applicable (default=false).
|
||||||
* - `convertEntities` (bool): convert HTML entities to equivalent character(s)? (default=false).
|
* - `convertEntities` (bool): convert HTML entities to equivalent character(s)? (default=false). Since 3.0.105
|
||||||
* - `newlineReplacement` (string): character to replace newlines with, OR specify boolean true to remove extra lines (default=" ").
|
* - `newlineReplacement` (string): character to replace newlines with, OR specify boolean true to remove extra lines (default=" ").
|
||||||
* - `truncateTail` (bool): if truncate necessary for maxLength, truncate from end/tail? Use false to truncate head (default=true).
|
* - `truncateTail` (bool): if truncate necessary for maxLength, truncate from end/tail? Use false to truncate head (default=true). Since 3.0.105
|
||||||
* - `inCharset` (string): input character set (default="UTF-8").
|
* - `inCharset` (string): input character set (default="UTF-8").
|
||||||
* - `outCharset` (string): output character set (default="UTF-8").
|
* - `outCharset` (string): output character set (default="UTF-8").
|
||||||
* @return string
|
* @return string
|
||||||
@@ -1019,7 +1019,7 @@ class Sanitizer extends Wire {
|
|||||||
'newlineReplacement' => ' ', // character to replace newlines with, OR specify boolean TRUE to remove extra lines
|
'newlineReplacement' => ' ', // character to replace newlines with, OR specify boolean TRUE to remove extra lines
|
||||||
'inCharset' => 'UTF-8', // input charset
|
'inCharset' => 'UTF-8', // input charset
|
||||||
'outCharset' => 'UTF-8', // output charset
|
'outCharset' => 'UTF-8', // output charset
|
||||||
'trunateTail' => true, // if truncate necessary for maxLength, remove chars from tail? False to truncate from head.
|
'truncateTail' => true, // if truncate necessary for maxLength, remove chars from tail? False to truncate from head.
|
||||||
'trim' => true, // trim whitespace from beginning/end, or specify character(s) to trim, or false to disable
|
'trim' => true, // trim whitespace from beginning/end, or specify character(s) to trim, or false to disable
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -1154,11 +1154,11 @@ class Sanitizer extends Wire {
|
|||||||
* - `maxBytes` (int): maximum bytes allowed (default=0, which implies maxLength*3 or 48kb).
|
* - `maxBytes` (int): maximum bytes allowed (default=0, which implies maxLength*3 or 48kb).
|
||||||
* - `stripTags` (bool): strip markup tags? (default=true).
|
* - `stripTags` (bool): strip markup tags? (default=true).
|
||||||
* - `stripMB4` (bool): strip emoji and other 4-byte UTF-8? (default=false).
|
* - `stripMB4` (bool): strip emoji and other 4-byte UTF-8? (default=false).
|
||||||
* - `stripIndents` (bool): Remove indents (space/tabs) at the beginning of lines? (default=false)
|
* - `stripIndents` (bool): Remove indents (space/tabs) at the beginning of lines? (default=false). Since 3.0.105
|
||||||
* - `reduceSpace` (bool|string): reduce consecutive whitespace to single? Specify true or character to reduce to (default=false).
|
* - `reduceSpace` (bool|string): reduce consecutive whitespace to single? Specify true or character to reduce to (default=false). Since 3.0.105
|
||||||
* - `allowableTags` (string): markup tags that are allowed, if stripTags is true (use same format as for PHP's `strip_tags()` function.
|
* - `allowableTags` (string): markup tags that are allowed, if stripTags is true (use same format as for PHP's `strip_tags()` function.
|
||||||
* - `convertEntities` (bool): convert HTML entities to equivalent character(s)? (default=false).
|
* - `convertEntities` (bool): convert HTML entities to equivalent character(s)? (default=false). Since 3.0.105
|
||||||
* - `truncateTail` (bool): if truncate necessary for maxLength, truncate from end/tail? Use false to truncate head (default=true).
|
* - `truncateTail` (bool): if truncate necessary for maxLength, truncate from end/tail? Use false to truncate head (default=true). Since 3.0.105
|
||||||
* - `allowCRLF` (bool): allow CR+LF newlines (i.e. "\r\n")? (default=false, which means "\r\n" is replaced with "\n").
|
* - `allowCRLF` (bool): allow CR+LF newlines (i.e. "\r\n")? (default=false, which means "\r\n" is replaced with "\n").
|
||||||
* - `inCharset` (string): input character set (default="UTF-8").
|
* - `inCharset` (string): input character set (default="UTF-8").
|
||||||
* - `outCharset` (string): output character set (default="UTF-8").
|
* - `outCharset` (string): output character set (default="UTF-8").
|
||||||
@@ -1881,7 +1881,7 @@ class Sanitizer extends Wire {
|
|||||||
*
|
*
|
||||||
* @param string $str String to remove entities from
|
* @param string $str String to remove entities from
|
||||||
* @param int|bool $flags See PHP html_entity_decode function for flags,
|
* @param int|bool $flags See PHP html_entity_decode function for flags,
|
||||||
* OR specify boolean true to convert all entities and remove any that cannot be converted.
|
* OR specify boolean true to convert all entities and remove any that cannot be converted (since 3.0.105).
|
||||||
* @param string $encoding Encoding (default="UTF-8").
|
* @param string $encoding Encoding (default="UTF-8").
|
||||||
* @return string String with entities removed.
|
* @return string String with entities removed.
|
||||||
* @see Sanitizer::entities()
|
* @see Sanitizer::entities()
|
||||||
@@ -1992,6 +1992,7 @@ class Sanitizer extends Wire {
|
|||||||
* - `html` (bool): Remove/replace HTML whitespace entities too? (default=true)
|
* - `html` (bool): Remove/replace HTML whitespace entities too? (default=true)
|
||||||
* - `allow` (array): Array of whitespace characters that may remain. (default=[])
|
* - `allow` (array): Array of whitespace characters that may remain. (default=[])
|
||||||
* @return string
|
* @return string
|
||||||
|
* @since 3.0.105
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function removeWhitespace($str, $options = array()) {
|
public function removeWhitespace($str, $options = array()) {
|
||||||
@@ -2040,6 +2041,7 @@ class Sanitizer extends Wire {
|
|||||||
*
|
*
|
||||||
* @param bool|int $html Also include HTML entities that represent whitespace? false=no, true=both, 1=only-html (default=false)
|
* @param bool|int $html Also include HTML entities that represent whitespace? false=no, true=both, 1=only-html (default=false)
|
||||||
* @return array
|
* @return array
|
||||||
|
* @since 3.0.105
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function getWhitespaceArray($html = false) {
|
public function getWhitespaceArray($html = false) {
|
||||||
@@ -2123,6 +2125,7 @@ class Sanitizer extends Wire {
|
|||||||
* - `convertEntities` (bool): Convert HTML entities to non-entity characters? (default=false)
|
* - `convertEntities` (bool): Convert HTML entities to non-entity characters? (default=false)
|
||||||
* - `noEndSentence` (string): Strings that sentence may not end with, space-separated values (default='Mr. Mrs. …')
|
* - `noEndSentence` (string): Strings that sentence may not end with, space-separated values (default='Mr. Mrs. …')
|
||||||
* @return string
|
* @return string
|
||||||
|
* @since 3.0.101
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function truncate($str, $maxLength = 300, $options = array()) {
|
function truncate($str, $maxLength = 300, $options = array()) {
|
||||||
@@ -2767,6 +2770,7 @@ class Sanitizer extends Wire {
|
|||||||
* Get instance of WireTextTools
|
* Get instance of WireTextTools
|
||||||
*
|
*
|
||||||
* @return WireTextTools
|
* @return WireTextTools
|
||||||
|
* @since 3.0.101
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function getTextTools() {
|
public function getTextTools() {
|
||||||
|
@@ -318,7 +318,7 @@ class WireMail extends WireData implements WireMailInterface {
|
|||||||
}
|
}
|
||||||
if($name) $this->mail['replyToName'] = $this->sanitizeHeader($name);
|
if($name) $this->mail['replyToName'] = $this->sanitizeHeader($name);
|
||||||
$this->mail['replyTo'] = $email;
|
$this->mail['replyTo'] = $email;
|
||||||
if(empty($name)) $name = $this->mail['replyToName'];
|
if(empty($name) && !empty($this->mail['replyToName'])) $name = $this->mail['replyToName'];
|
||||||
if(strlen($name)) $email = $this->bundleEmailAndName($email, $name);
|
if(strlen($name)) $email = $this->bundleEmailAndName($email, $name);
|
||||||
$this->header('Reply-To', $email);
|
$this->header('Reply-To', $email);
|
||||||
return $this;
|
return $this;
|
||||||
|
@@ -8,6 +8,8 @@
|
|||||||
* ProcessWire 3.x, Copyright 2018 by Ryan Cramer
|
* ProcessWire 3.x, Copyright 2018 by Ryan Cramer
|
||||||
* https://processwire.com
|
* https://processwire.com
|
||||||
*
|
*
|
||||||
|
* @since 3.0.101
|
||||||
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -47,6 +49,9 @@ class WireTextTools extends Wire {
|
|||||||
|
|
||||||
if(strpos($str, '>') !== false) {
|
if(strpos($str, '>') !== false) {
|
||||||
|
|
||||||
|
// strip out everything up to and including </head>, if present
|
||||||
|
if(strpos($str, '</head>') !== false) list(, $str) = explode('</head>', $str);
|
||||||
|
|
||||||
// ensure tags are separated by whitespace
|
// ensure tags are separated by whitespace
|
||||||
$str = str_replace('><', '> <', $str);
|
$str = str_replace('><', '> <', $str);
|
||||||
|
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
* Code by Ryan Cramer
|
* Code by Ryan Cramer
|
||||||
* Sponsored by Avoine
|
* Sponsored by Avoine
|
||||||
*
|
*
|
||||||
* ProcessWire 3.x, Copyright 2016 by Ryan Cramer
|
* ProcessWire 3.x, Copyright 2018 by Ryan Cramer
|
||||||
* https://processwire.com
|
* https://processwire.com
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -43,6 +43,8 @@ class FieldtypePageTable extends FieldtypeMulti implements Module {
|
|||||||
*
|
*
|
||||||
* Used to delete references to the page in any PageTable tables
|
* Used to delete references to the page in any PageTable tables
|
||||||
*
|
*
|
||||||
|
* @param HookEvent $event
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public function hookPagesDelete(HookEvent $event) {
|
public function hookPagesDelete(HookEvent $event) {
|
||||||
$page = $event->arguments(0);
|
$page = $event->arguments(0);
|
||||||
@@ -64,6 +66,8 @@ class FieldtypePageTable extends FieldtypeMulti implements Module {
|
|||||||
* This is really only applicable when PageTable pages are stored somewhere other than as children of the
|
* This is really only applicable when PageTable pages are stored somewhere other than as children of the
|
||||||
* deleted page.
|
* deleted page.
|
||||||
*
|
*
|
||||||
|
* @param HookEvent $event
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public function hookPagesDeleteReady(HookEvent $event) {
|
public function hookPagesDeleteReady(HookEvent $event) {
|
||||||
$page = $event->arguments(0);
|
$page = $event->arguments(0);
|
||||||
@@ -72,8 +76,9 @@ class FieldtypePageTable extends FieldtypeMulti implements Module {
|
|||||||
if(is_null($field->trashOnDelete) && !is_null($field->autoTrash)) $field->trashOnDelete = $field->autoTrash;
|
if(is_null($field->trashOnDelete) && !is_null($field->autoTrash)) $field->trashOnDelete = $field->autoTrash;
|
||||||
if(!$field->parent_id || !$field->trashOnDelete) continue;
|
if(!$field->parent_id || !$field->trashOnDelete) continue;
|
||||||
$value = $page->getUnformatted($field->name);
|
$value = $page->getUnformatted($field->name);
|
||||||
if(!count($value)) continue;
|
if(!wireCount($value)) continue;
|
||||||
foreach($value as $item) {
|
foreach($value as $item) {
|
||||||
|
/** @var Page $item */
|
||||||
$deleted = false;
|
$deleted = false;
|
||||||
if($field->trashOnDelete == 2) {
|
if($field->trashOnDelete == 2) {
|
||||||
$this->wire('pages')->message("Auto Delete PageTable Item: $item->url", Notice::debug);
|
$this->wire('pages')->message("Auto Delete PageTable Item: $item->url", Notice::debug);
|
||||||
@@ -96,6 +101,8 @@ class FieldtypePageTable extends FieldtypeMulti implements Module {
|
|||||||
/**
|
/**
|
||||||
* Hook called when a page has been trashed
|
* Hook called when a page has been trashed
|
||||||
*
|
*
|
||||||
|
* @param HookEvent $event
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public function hookPagesTrashed(HookEvent $event) {
|
public function hookPagesTrashed(HookEvent $event) {
|
||||||
$page = $event->arguments(0);
|
$page = $event->arguments(0);
|
||||||
@@ -103,8 +110,9 @@ class FieldtypePageTable extends FieldtypeMulti implements Module {
|
|||||||
if(!$field->type instanceof FieldtypePageTable) continue;
|
if(!$field->type instanceof FieldtypePageTable) continue;
|
||||||
if(!$field->parent_id || !$field->unpubOnTrash) continue;
|
if(!$field->parent_id || !$field->unpubOnTrash) continue;
|
||||||
$value = $page->getUnformatted($field->name);
|
$value = $page->getUnformatted($field->name);
|
||||||
if(!count($value)) continue;
|
if(!wireCount($value)) continue;
|
||||||
foreach($value as $item) {
|
foreach($value as $item) {
|
||||||
|
/** @var Page $item */
|
||||||
$this->wire('pages')->message("Auto Unpublish PageTable Item: $item->url", Notice::debug);
|
$this->wire('pages')->message("Auto Unpublish PageTable Item: $item->url", Notice::debug);
|
||||||
$of = $item->of();
|
$of = $item->of();
|
||||||
$item->of(false);
|
$item->of(false);
|
||||||
@@ -118,6 +126,8 @@ class FieldtypePageTable extends FieldtypeMulti implements Module {
|
|||||||
/**
|
/**
|
||||||
* Hook called when a page has been unpublished
|
* Hook called when a page has been unpublished
|
||||||
*
|
*
|
||||||
|
* @param HookEvent $event
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public function hookPagesUnpublished(HookEvent $event) {
|
public function hookPagesUnpublished(HookEvent $event) {
|
||||||
$page = $event->arguments(0);
|
$page = $event->arguments(0);
|
||||||
@@ -125,8 +135,9 @@ class FieldtypePageTable extends FieldtypeMulti implements Module {
|
|||||||
if(!$field->type instanceof FieldtypePageTable) continue;
|
if(!$field->type instanceof FieldtypePageTable) continue;
|
||||||
if(!$field->parent_id || !$field->unpubOnUnpub) continue;
|
if(!$field->parent_id || !$field->unpubOnUnpub) continue;
|
||||||
$value = $page->getUnformatted($field->name);
|
$value = $page->getUnformatted($field->name);
|
||||||
if(!count($value)) continue;
|
if(!wireCount($value)) continue;
|
||||||
foreach($value as $item) {
|
foreach($value as $item) {
|
||||||
|
/** @var Page $item */
|
||||||
$of = $item->of();
|
$of = $item->of();
|
||||||
$item->of(false);
|
$item->of(false);
|
||||||
if($field->unpubOnUnpub == 2) {
|
if($field->unpubOnUnpub == 2) {
|
||||||
@@ -145,6 +156,8 @@ class FieldtypePageTable extends FieldtypeMulti implements Module {
|
|||||||
/**
|
/**
|
||||||
* Hook called when a page has been published
|
* Hook called when a page has been published
|
||||||
*
|
*
|
||||||
|
* @param HookEvent $event
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public function hookPagesPublished(HookEvent $event) {
|
public function hookPagesPublished(HookEvent $event) {
|
||||||
$page = $event->arguments(0);
|
$page = $event->arguments(0);
|
||||||
@@ -152,8 +165,9 @@ class FieldtypePageTable extends FieldtypeMulti implements Module {
|
|||||||
if(!$field->type instanceof FieldtypePageTable) continue;
|
if(!$field->type instanceof FieldtypePageTable) continue;
|
||||||
if(!$field->parent_id || $field->unpubOnUnpub != 2) continue;
|
if(!$field->parent_id || $field->unpubOnUnpub != 2) continue;
|
||||||
$value = $page->getUnformatted($field->name);
|
$value = $page->getUnformatted($field->name);
|
||||||
if(!count($value)) continue;
|
if(!wireCount($value)) continue;
|
||||||
foreach($value as $item) {
|
foreach($value as $item) {
|
||||||
|
/** @var Page $item */
|
||||||
if(!$item->hasStatus(Page::statusHidden)) continue;
|
if(!$item->hasStatus(Page::statusHidden)) continue;
|
||||||
$of = $item->of();
|
$of = $item->of();
|
||||||
$item->of(false);
|
$item->of(false);
|
||||||
@@ -181,6 +195,8 @@ class FieldtypePageTable extends FieldtypeMulti implements Module {
|
|||||||
$page = $event->arguments(0);
|
$page = $event->arguments(0);
|
||||||
$copy = $event->arguments(1);
|
$copy = $event->arguments(1);
|
||||||
|
|
||||||
|
if($page) {} // ignore
|
||||||
|
|
||||||
if(in_array($copy->id, $clonedIDs)) return;
|
if(in_array($copy->id, $clonedIDs)) return;
|
||||||
$clonedIDs[] = $copy->id;
|
$clonedIDs[] = $copy->id;
|
||||||
|
|
||||||
@@ -189,7 +205,7 @@ class FieldtypePageTable extends FieldtypeMulti implements Module {
|
|||||||
//if(!$field->parent_id) continue; // let that be handled manually since recursive clones are already an option
|
//if(!$field->parent_id) continue; // let that be handled manually since recursive clones are already an option
|
||||||
$parent = $field->parent_id ? $this->wire('pages')->get($field->parent_id) : $copy;
|
$parent = $field->parent_id ? $this->wire('pages')->get($field->parent_id) : $copy;
|
||||||
$value = $copy->getUnformatted($field->name);
|
$value = $copy->getUnformatted($field->name);
|
||||||
if(!count($value)) continue;
|
if(!wireCount($value)) continue;
|
||||||
$newValue = $this->wire('pages')->newPageArray();
|
$newValue = $this->wire('pages')->newPageArray();
|
||||||
foreach($value as $item) {
|
foreach($value as $item) {
|
||||||
try {
|
try {
|
||||||
@@ -270,14 +286,15 @@ class FieldtypePageTable extends FieldtypeMulti implements Module {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function getInputfield(Page $page, Field $field) {
|
public function getInputfield(Page $page, Field $field) {
|
||||||
|
/** @var InputfieldPageTable $inputfield */
|
||||||
$inputfield = $this->modules->get('InputfieldPageTable');
|
$inputfield = $this->modules->get('InputfieldPageTable');
|
||||||
$value = $page->getUnformatted($field->name);
|
$value = $page->getUnformatted($field->name);
|
||||||
$inputfield->attr('value', $value);
|
$inputfield->attr('value', $value);
|
||||||
$templateID = $field->template_id;
|
$templateID = $field->template_id;
|
||||||
|
|
||||||
if(!$field->parent_id && !empty($templateID) && $page->numChildren > count($value)) {
|
if(!$field->parent_id && !empty($templateID) && $page->numChildren > wireCount($value)) {
|
||||||
$orphans = $this->findOrphans($page, $field);
|
$orphans = $this->findOrphans($page, $field);
|
||||||
if(count($orphans)) $inputfield->setOrphans($orphans);
|
if(wireCount($orphans)) $inputfield->setOrphans($orphans);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $inputfield;
|
return $inputfield;
|
||||||
@@ -293,7 +310,7 @@ class FieldtypePageTable extends FieldtypeMulti implements Module {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function sanitizeValue(Page $page, Field $field, $value) {
|
public function sanitizeValue(Page $page, Field $field, $value) {
|
||||||
if(is_array($value) && count($value)) $value = $this->wakeupValue($page, $field, $value);
|
if(is_array($value) && wireCount($value)) $value = $this->wakeupValue($page, $field, $value);
|
||||||
if(!$value instanceof PageArray) return $this->wire('pages')->newPageArray();
|
if(!$value instanceof PageArray) return $this->wire('pages')->newPageArray();
|
||||||
foreach($value as $item) {
|
foreach($value as $item) {
|
||||||
if($this->isValidItem($page, $field, $item)) continue;
|
if($this->isValidItem($page, $field, $item)) continue;
|
||||||
@@ -312,6 +329,7 @@ class FieldtypePageTable extends FieldtypeMulti implements Module {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
protected function isValidItem(Page $page, Field $field, Page $item) {
|
protected function isValidItem(Page $page, Field $field, Page $item) {
|
||||||
|
if($page) {} // ignore
|
||||||
$template_id = $field->template_id;
|
$template_id = $field->template_id;
|
||||||
if(is_array($template_id)) {
|
if(is_array($template_id)) {
|
||||||
if(in_array($item->template->id, $template_id)) return true;
|
if(in_array($item->template->id, $template_id)) return true;
|
||||||
@@ -388,7 +406,7 @@ class FieldtypePageTable extends FieldtypeMulti implements Module {
|
|||||||
*/
|
*/
|
||||||
public function ___wakeupValue(Page $page, Field $field, $value) {
|
public function ___wakeupValue(Page $page, Field $field, $value) {
|
||||||
|
|
||||||
if(!is_array($value) || !count($value) || empty($field->template_id)) return $this->getBlankValue($page, $field);
|
if(!is_array($value) || !wireCount($value) || empty($field->template_id)) return $this->getBlankValue($page, $field);
|
||||||
|
|
||||||
$template_id = $field->get('template_id');
|
$template_id = $field->get('template_id');
|
||||||
|
|
||||||
@@ -396,7 +414,7 @@ class FieldtypePageTable extends FieldtypeMulti implements Module {
|
|||||||
$template_id = $template_id ? array($template_id) : array();
|
$template_id = $template_id ? array($template_id) : array();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(count($template_id) == 1) {
|
if(wireCount($template_id) == 1) {
|
||||||
$template = $this->wire('templates')->get(reset($template_id));
|
$template = $this->wire('templates')->get(reset($template_id));
|
||||||
} else {
|
} else {
|
||||||
$template = null;
|
$template = null;
|
||||||
@@ -413,7 +431,7 @@ class FieldtypePageTable extends FieldtypeMulti implements Module {
|
|||||||
foreach(explode(',', $sortfields) as $sortfield) {
|
foreach(explode(',', $sortfields) as $sortfield) {
|
||||||
$sorts[] = $this->wire('sanitizer')->name(trim($sortfield));
|
$sorts[] = $this->wire('sanitizer')->name(trim($sortfield));
|
||||||
}
|
}
|
||||||
if(count($sorts)) $items->sort($sorts);
|
if(wireCount($sorts)) $items->sort($sorts);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($items as $item) {
|
foreach($items as $item) {
|
||||||
@@ -486,7 +504,7 @@ class FieldtypePageTable extends FieldtypeMulti implements Module {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$data['template_id'] = 0;
|
$data['template_id'] = 0;
|
||||||
if(count($errorTemplates)) {
|
if(wireCount($errorTemplates)) {
|
||||||
$data['errors']['template_id'] = "Unable to find template(s): " . implode(', ', $errorTemplates);
|
$data['errors']['template_id'] = "Unable to find template(s): " . implode(', ', $errorTemplates);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -22,7 +22,6 @@ function ckeGetProcessWireConfig(editor) {
|
|||||||
configName = configName.replace('Inputfield_', 'InputfieldCKEditor_');
|
configName = configName.replace('Inputfield_', 'InputfieldCKEditor_');
|
||||||
|
|
||||||
if(typeof ProcessWire.config[configName] == "undefined" && configName.indexOf('_repeater') > 0) {
|
if(typeof ProcessWire.config[configName] == "undefined" && configName.indexOf('_repeater') > 0) {
|
||||||
console.log('configName=' + configName);
|
|
||||||
configName = configName.replace(/_repeater[0-9]+/, '');
|
configName = configName.replace(/_repeater[0-9]+/, '');
|
||||||
$repeaterItem = $('#' + editorName).closest('.InputfieldRepeaterItem');
|
$repeaterItem = $('#' + editorName).closest('.InputfieldRepeaterItem');
|
||||||
}
|
}
|
||||||
|
@@ -1 +1 @@
|
|||||||
function ckeGetProcessWireConfig(c){var e=typeof c=="string"?c:c.name;var d=e.replace("Inputfield_","InputfieldCKEditor_");var a="";var b={};d=d.replace("Inputfield_","InputfieldCKEditor_");if(typeof ProcessWire.config[d]=="undefined"&&d.indexOf("_repeater")>0){console.log("configName="+d);d=d.replace(/_repeater[0-9]+/,"");a=$("#"+e).closest(".InputfieldRepeaterItem")}if(typeof ProcessWire.config[d]=="undefined"&&d.indexOf("_ckeditor")>0){d=d.replace(/_ckeditor$/,"")}if(typeof ProcessWire.config[d]=="undefined"){b.error="Cannot find CKEditor settings for "+d}else{b=ProcessWire.config[d]}if(a.length){b.repeaterItem=a}else{b.repeaterItem=""}return b}function ckeLoadPlugins(){for(var a in ProcessWire.config.InputfieldCKEditor.plugins){var b=ProcessWire.config.InputfieldCKEditor.plugins[a];CKEDITOR.plugins.addExternal(a,b,"")}}ckeLoadPlugins();function ckeBlurEvent(b){var a=b.editor;var c=$(a.element.$);if(a.checkDirty()){if(c.length){if(c.is("textarea")){c.change()}c.closest(".Inputfield").addClass("InputfieldStateChanged")}}}function ckeFocusEvent(b){var a=b.editor;var c=$(a.element.$);c.trigger("pw-focus")}function ckeResizeEvent(b){var a=b.editor;var c=$(a.element.$);if(c.length){c.closest(".Inputfield").trigger("heightChanged")}}function ckeUploadEvent(e){var g=e.data.fileLoader.xhr;var b=e.data.fileLoader;var d=ckeGetProcessWireConfig(e.editor);var c=d?d.pwUploadField:"_unknown";var f=$("#Inputfield_"+c);if(typeof d.repeaterItem!="undefined"&&d.repeaterItem.length){var a=d.repeaterItem.find(".InputfieldImage:not(.InputfieldFileSingle)");if(a.length){f=a}}if(f.length){g.open("POST",b.uploadUrl,true);f.trigger("pwimageupload",{name:b.fileName,file:b.file,xhr:g});e.stop()}else{if(typeof d.error!="undefined"&&d.error.length){ProcessWire.alert(d.error)}else{ProcessWire.alert("Unable to find images field for upload")}e.stop();return false}}function ckeInitEvents(b){b.on("blur",ckeBlurEvent);b.on("focus",ckeFocusEvent);b.on("change",ckeBlurEvent);b.on("resize",ckeResizeEvent);b.on("fileUploadRequest",ckeUploadEvent,null,null,4);var c=$(b.element.$);var a=c.closest(".Inputfield.InputfieldColumnWidth");if(a.length){setTimeout(function(){a.trigger("heightChanged")},1000)}}function ckeSaveReadyInline(b){if(!b.length){return}var a=b.hasClass(".InputfieldCKEditorInline")?b:b.find(".InputfieldCKEditorInline");if(a.length){a.each(function(){var f=$(this);var d;if(f.hasClass("InputfieldCKEditorLoaded")){var c=CKEDITOR.instances[f.attr("id")];if(typeof c!="undefined"){if(c.focusManager.hasFocus){c.focusManager.focus(true);c.focus()}d=c.getData()}}else{d=f.html()}var e=f.next("input");e.attr("value",d)})}}function ckeSaveReadyNormal(b){var a=b.hasClass("InputfieldCKEditorNormal")?b:b.find(".InputfieldCKEditorNormal");a.each(function(){var d=$(this);if(!d.hasClass("InputfieldCKEditorLoaded")){return}var c=CKEDITOR.instances[d.attr("id")];c.updateElement()})}function ckeInlineMouseoverEvent(b){var d=$(this);if(d.hasClass("InputfieldCKEditorLoaded")){return}d.effect("highlight",{},500);d.attr("contenteditable","true");var c=d.attr("data-configName");var a=CKEDITOR.inline($(this).attr("id"),ProcessWire.config[c]);ckeInitEvents(a);d.addClass("InputfieldCKEditorLoaded")}function ckeInitTab(c,e){var h=e.newTab;var d=h.find("a");if(d.hasClass("InputfieldCKEditor_init")){return}var a=d.attr("data-editorID");var g=d.attr("data-configName");var b=CKEDITOR.replace(a,config[g]);ckeInitEvents(b);d.addClass("InputfieldCKEditor_init");e.oldTab.find("a").addClass("InputfieldCKEditor_init");var f=$("#"+a);f.addClass("InputfieldCKEditorLoaded")}function ckeInitNormal(a){var f=$("#"+a);var e=f.parent();if(typeof ProcessWire.config.InputfieldCKEditor.editors[a]!="undefined"){var d=ProcessWire.config.InputfieldCKEditor.editors[a]}else{var d=f.attr("data-configName")}if(e.hasClass("ui-tabs-panel")&&e.css("display")=="none"){var g=f.parent().attr("id");var c=e.closest(".ui-tabs, .langTabs").find("a[href=#"+g+"]");c.attr("data-editorID",a).attr("data-configName",d);e.closest(".ui-tabs, .langTabs").on("tabsactivate",ckeInitTab)}else{var b=CKEDITOR.replace(a,ProcessWire.config[d]);ckeInitEvents(b);f.addClass("InputfieldCKEditorLoaded")}}$(document).ready(function(){CKEDITOR.timestamp=ProcessWire.config.InputfieldCKEditor.timestamp;for(var a in ProcessWire.config.InputfieldCKEditor.editors){ckeInitNormal(a)}$(document).on("reloaded",".InputfieldCKEditor",function(){var b=$(this).find(".InputfieldCKEditorNormal:not(.InputfieldCKEditorLoaded)");b.each(function(){ckeInitNormal($(this).attr("id"))});return false});CKEDITOR.disableAutoInline=true;$(document).on("mouseover",".InputfieldCKEditorInlineEditor",ckeInlineMouseoverEvent);$(document).on("submit","form.InputfieldForm",function(){ckeSaveReadyInline($(this))});$(document).on("saveReady",".InputfieldCKEditor",function(){ckeSaveReadyNormal($(this));ckeSaveReadyInline($(this))})});
|
function ckeGetProcessWireConfig(c){var e=typeof c=="string"?c:c.name;var d=e.replace("Inputfield_","InputfieldCKEditor_");var a="";var b={};d=d.replace("Inputfield_","InputfieldCKEditor_");if(typeof ProcessWire.config[d]=="undefined"&&d.indexOf("_repeater")>0){d=d.replace(/_repeater[0-9]+/,"");a=$("#"+e).closest(".InputfieldRepeaterItem")}if(typeof ProcessWire.config[d]=="undefined"&&d.indexOf("_ckeditor")>0){d=d.replace(/_ckeditor$/,"")}if(typeof ProcessWire.config[d]=="undefined"){b.error="Cannot find CKEditor settings for "+d}else{b=ProcessWire.config[d]}if(a.length){b.repeaterItem=a}else{b.repeaterItem=""}return b}function ckeLoadPlugins(){for(var a in ProcessWire.config.InputfieldCKEditor.plugins){var b=ProcessWire.config.InputfieldCKEditor.plugins[a];CKEDITOR.plugins.addExternal(a,b,"")}}ckeLoadPlugins();function ckeBlurEvent(b){var a=b.editor;var c=$(a.element.$);if(a.checkDirty()){if(c.length){if(c.is("textarea")){c.change()}c.closest(".Inputfield").addClass("InputfieldStateChanged")}}}function ckeFocusEvent(b){var a=b.editor;var c=$(a.element.$);c.trigger("pw-focus")}function ckeResizeEvent(b){var a=b.editor;var c=$(a.element.$);if(c.length){c.closest(".Inputfield").trigger("heightChanged")}}function ckeUploadEvent(e){var g=e.data.fileLoader.xhr;var b=e.data.fileLoader;var d=ckeGetProcessWireConfig(e.editor);var c=d?d.pwUploadField:"_unknown";var f=$("#Inputfield_"+c);if(typeof d.repeaterItem!="undefined"&&d.repeaterItem.length){var a=d.repeaterItem.find(".InputfieldImage:not(.InputfieldFileSingle)");if(a.length){f=a}}if(f.length){g.open("POST",b.uploadUrl,true);f.trigger("pwimageupload",{name:b.fileName,file:b.file,xhr:g});e.stop()}else{if(typeof d.error!="undefined"&&d.error.length){ProcessWire.alert(d.error)}else{ProcessWire.alert("Unable to find images field for upload")}e.stop();return false}}function ckeInitEvents(b){b.on("blur",ckeBlurEvent);b.on("focus",ckeFocusEvent);b.on("change",ckeBlurEvent);b.on("resize",ckeResizeEvent);b.on("fileUploadRequest",ckeUploadEvent,null,null,4);var c=$(b.element.$);var a=c.closest(".Inputfield.InputfieldColumnWidth");if(a.length){setTimeout(function(){a.trigger("heightChanged")},1000)}}function ckeSaveReadyInline(b){if(!b.length){return}var a=b.hasClass(".InputfieldCKEditorInline")?b:b.find(".InputfieldCKEditorInline");if(a.length){a.each(function(){var f=$(this);var d;if(f.hasClass("InputfieldCKEditorLoaded")){var c=CKEDITOR.instances[f.attr("id")];if(typeof c!="undefined"){if(c.focusManager.hasFocus){c.focusManager.focus(true);c.focus()}d=c.getData()}}else{d=f.html()}var e=f.next("input");e.attr("value",d)})}}function ckeSaveReadyNormal(b){var a=b.hasClass("InputfieldCKEditorNormal")?b:b.find(".InputfieldCKEditorNormal");a.each(function(){var d=$(this);if(!d.hasClass("InputfieldCKEditorLoaded")){return}var c=CKEDITOR.instances[d.attr("id")];c.updateElement()})}function ckeInlineMouseoverEvent(b){var d=$(this);if(d.hasClass("InputfieldCKEditorLoaded")){return}d.effect("highlight",{},500);d.attr("contenteditable","true");var c=d.attr("data-configName");var a=CKEDITOR.inline($(this).attr("id"),ProcessWire.config[c]);ckeInitEvents(a);d.addClass("InputfieldCKEditorLoaded")}function ckeInitTab(c,e){var h=e.newTab;var d=h.find("a");if(d.hasClass("InputfieldCKEditor_init")){return}var a=d.attr("data-editorID");var g=d.attr("data-configName");var b=CKEDITOR.replace(a,config[g]);ckeInitEvents(b);d.addClass("InputfieldCKEditor_init");e.oldTab.find("a").addClass("InputfieldCKEditor_init");var f=$("#"+a);f.addClass("InputfieldCKEditorLoaded")}function ckeInitNormal(a){var f=$("#"+a);var e=f.parent();if(typeof ProcessWire.config.InputfieldCKEditor.editors[a]!="undefined"){var d=ProcessWire.config.InputfieldCKEditor.editors[a]}else{var d=f.attr("data-configName")}if(e.hasClass("ui-tabs-panel")&&e.css("display")=="none"){var g=f.parent().attr("id");var c=e.closest(".ui-tabs, .langTabs").find("a[href=#"+g+"]");c.attr("data-editorID",a).attr("data-configName",d);e.closest(".ui-tabs, .langTabs").on("tabsactivate",ckeInitTab)}else{var b=CKEDITOR.replace(a,ProcessWire.config[d]);ckeInitEvents(b);f.addClass("InputfieldCKEditorLoaded")}}$(document).ready(function(){CKEDITOR.timestamp=ProcessWire.config.InputfieldCKEditor.timestamp;for(var a in ProcessWire.config.InputfieldCKEditor.editors){ckeInitNormal(a)}$(document).on("reloaded",".InputfieldCKEditor",function(){var b=$(this).find(".InputfieldCKEditorNormal:not(.InputfieldCKEditorLoaded)");b.each(function(){ckeInitNormal($(this).attr("id"))});return false});CKEDITOR.disableAutoInline=true;$(document).on("mouseover",".InputfieldCKEditorInlineEditor",ckeInlineMouseoverEvent);$(document).on("submit","form.InputfieldForm",function(){ckeSaveReadyInline($(this))});$(document).on("saveReady",".InputfieldCKEditor",function(){ckeSaveReadyNormal($(this));ckeSaveReadyInline($(this))})});
|
@@ -1446,6 +1446,11 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu
|
|||||||
$success = $this->processUnknownFileAction($pagefile, $action, $label);
|
$success = $this->processUnknownFileAction($pagefile, $action, $label);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($success) {
|
||||||
|
$pagefile->trackChange("action-$action");
|
||||||
|
$this->trackChange('value');
|
||||||
|
}
|
||||||
|
|
||||||
if($success && $showSuccess) {
|
if($success && $showSuccess) {
|
||||||
$this->message(sprintf($this->_('Executed action “%1$s” on file %2$s'), $label, $pagefile->basename));
|
$this->message(sprintf($this->_('Executed action “%1$s” on file %2$s'), $label, $pagefile->basename));
|
||||||
} else if($success === false) {
|
} else if($success === false) {
|
||||||
|
Reference in New Issue
Block a user