diff --git a/wire/core/Pages.php b/wire/core/Pages.php
index 9688c733..4f7ae235 100644
--- a/wire/core/Pages.php
+++ b/wire/core/Pages.php
@@ -8,7 +8,7 @@
*
* This is the most used object in the ProcessWire API.
*
- * ProcessWire 3.x, Copyright 2021 by Ryan Cramer
+ * ProcessWire 3.x, Copyright 2022 by Ryan Cramer
* https://processwire.com
*
* @link http://processwire.com/api/variables/pages/ Offical $pages Documentation
@@ -211,7 +211,7 @@ class Pages extends Wire {
*
*/
public function init() {
- $this->loader->getById($this->wire('config')->preloadPageIDs);
+ $this->loader->getById($this->wire()->config->preloadPageIDs);
}
/****************************************************************************************************************
@@ -746,7 +746,7 @@ class Pages extends Wire {
if($template instanceof Template) {
// cool, cool
} else if(is_int($template) || is_string($template)) {
- $template = $this->wire('templates')->get($template);
+ $template = $this->wire()->templates->get($template);
} else {
$template = null;
}
@@ -1775,7 +1775,7 @@ class Pages extends Wire {
'action' => (string) $action,
'details' => (string) $details,
'result' => (string) $result
- );
+ );
}
/**
@@ -1790,7 +1790,7 @@ class Pages extends Wire {
*
*/
public function getDebugLog($action = '') {
- if(!$this->wire('config')->debug) return array();
+ if(!$this->wire()->config->debug) return array();
if(!$action) return $this->debugLog;
$debugLog = array();
foreach($this->debugLog as $item) if($item['action'] == $action) $debugLog[] = $item;
@@ -1798,7 +1798,7 @@ class Pages extends Wire {
}
/**
- * Return a PageFinder object, ready to use
+ * Return a new PageFinder object, ready to use
*
* #pw-internal
*
@@ -1950,7 +1950,7 @@ class Pages extends Wire {
*
*/
public function executeQuery(\PDOStatement $query, $throw = true, $maxTries = 3) {
- return $this->wire('database')->execute($query, $throw, $maxTries);
+ return $this->wire()->database->execute($query, $throw, $maxTries);
}
/**
@@ -1965,11 +1965,26 @@ class Pages extends Wire {
*
*/
public function __invoke($key) {
- if(empty($key)) return $this; // no argument
- if(is_int($key)) return $this->get($key); // page ID
- if(is_array($key) && ctype_digit(implode('', $key))) return $this->getById($key); // array of page IDs
- if(is_string($key) && strpos($key, '/') !== false && $this->sanitizer->pagePathName($key) === $key) return $this->get($key); // page path
- return $this->find($key); // selector string or array
+ // no argument
+ if(empty($key)) return $this;
+
+ // page ID
+ if(is_int($key)) return $this->get($key);
+
+ // array of page IDs
+ if(is_array($key) && ctype_digit(implode('', $key))) {
+ return $this->getById($key);
+ }
+
+ // page path
+ if(is_string($key) && strpos($key, '/') !== false) {
+ if($this->wire()->sanitizer->pagePathName($key) === $key) {
+ return $this->get($key);
+ }
+ }
+
+ // selector string or array
+ return $this->find($key);
}
/**
@@ -1983,8 +1998,8 @@ class Pages extends Wire {
*
*/
public function log($str, Page $page) {
- if(!in_array('pages', $this->wire('config')->logs)) return parent::___log();
- if($this->wire('process') != 'ProcessPageEdit') $str .= " [From URL: " . $this->wire('input')->url() . "]";
+ if(!in_array('pages', $this->wire()->config->logs)) return parent::___log();
+ if($this->wire()->process != 'ProcessPageEdit') $str .= " [From URL: " . $this->wire()->input->url() . "]";
$options = array('name' => 'pages', 'url' => $page->path);
return parent::___log($str, $options);
}
@@ -2150,9 +2165,7 @@ class Pages extends Wire {
$str = "Saved page";
if(count($changes)) $str .= " (Changes: " . implode(', ', $changes) . ")";
$this->log($str, $page);
- /** @var WireCache $cache */
- $cache = $this->wire('cache');
- $cache->maintenance($page);
+ $this->wire()->cache->maintenance($page);
foreach($this->types as $manager) {
if($manager->hasValidTemplate($page)) $manager->saved($page, $changes, $values);
}
@@ -2301,9 +2314,7 @@ class Pages extends Wire {
public function ___deleted(Page $page, array $options = array()) {
if($options) {}
if(empty($options['_deleteBranch'])) $this->log("Deleted page", $page);
- /** @var WireCache $cache */
- $cache = $this->wire('cache');
- $cache->maintenance($page);
+ $this->wire()->cache->maintenance($page);
foreach($this->types as $manager) {
if($manager->hasValidTemplate($page)) $manager->deleted($page);
}
diff --git a/wire/core/PagesLoader.php b/wire/core/PagesLoader.php
index 908d2218..1fe00797 100644
--- a/wire/core/PagesLoader.php
+++ b/wire/core/PagesLoader.php
@@ -92,7 +92,7 @@ class PagesLoader extends Wire {
}
/**
- * Set whether loaded pages have their outputFormatting turn on or off
+ * Set whether loaded pages have their outputFormatting turned on or off
*
* By default, it is turned on.
*
@@ -102,7 +102,13 @@ class PagesLoader extends Wire {
public function setOutputFormatting($outputFormatting = true) {
$this->outputFormatting = $outputFormatting ? true : false;
}
-
+
+ /**
+ * Get whether loaded pages have their outputFormatting turned on or off
+ *
+ * @return bool
+ *
+ */
public function getOutputFormatting() {
return $this->outputFormatting;
}
@@ -118,8 +124,14 @@ class PagesLoader extends Wire {
*/
public function setAutojoin($autojoin = true) {
$this->autojoin = $autojoin ? true : false;
- }
-
+ }
+
+ /**
+ * Get whether autojoin is enabled for page loading queries
+ *
+ * @return bool
+ *
+ */
public function getAutojoin() {
return $this->autojoin;
}
@@ -142,7 +154,7 @@ class PagesLoader extends Wire {
} else if($selector === '/' || $selector === 'path=/') {
// normalize selectors that indicate homepage to just be ID 1
- $selector = (int) $this->wire('config')->rootPageID;
+ $selector = (int) $this->wire()->config->rootPageID;
} else if($selector[0] === '/') {
// if selector begins with a slash, it is referring to a path
@@ -166,7 +178,7 @@ class PagesLoader extends Wire {
}
} else if(!Selectors::stringHasOperator($selector)) {
// no operator indicates this is just referring to a page name
- $sanitizer = $this->wire('sanitizer');
+ $sanitizer = $this->wire()->sanitizer;
if($sanitizer->pageNameUTF8($selector) === $selector) {
// sanitized value consistent with a page name
// optimize selector rather than determining value here
@@ -1503,7 +1515,7 @@ class PagesLoader extends Wire {
$path = trim($path, '/');
if($templatesID) {
- $template = $this->wire('templates')->get($templatesID);
+ $template = $this->wire()->templates->get($templatesID);
if($template->slashUrls) $path .= '/';
}
@@ -1866,7 +1878,10 @@ class PagesLoader extends Wire {
if(empty($selector)) {
if(empty($options)) {
// optimize away a simple site-wide total count
- return (int) $this->wire('database')->query("SELECT COUNT(*) FROM pages")->fetch(\PDO::FETCH_COLUMN);
+ $query = $this->wire()->database->query("SELECT COUNT(*) FROM pages");
+ $count = (int) $query->fetch(\PDO::FETCH_COLUMN);
+ $query->closeCursor();
+ return (int) $count;
} else {
// no selector string, but options specified
$selector = "id>0";
@@ -1923,8 +1938,8 @@ class PagesLoader extends Wire {
*/
public function getNativeColumns() {
if(empty($this->nativeColumns)) {
- $query = $this->wire('database')->prepare("SELECT * FROM pages WHERE id=:id");
- $query->bindValue(':id', $this->wire('config')->rootPageID, \PDO::PARAM_INT);
+ $query = $this->wire()->database->prepare("SELECT * FROM pages WHERE id=:id");
+ $query->bindValue(':id', $this->wire()->config->rootPageID, \PDO::PARAM_INT);
$query->execute();
$row = $query->fetch(\PDO::FETCH_ASSOC);
foreach(array_keys($row) as $colName) {
@@ -1948,13 +1963,14 @@ class PagesLoader extends Wire {
public function getNativeColumnValue($id, $column) {
$id = (is_object($id) ? (int) "$id" : (int) $id);
if($id < 1) return false;
- $database = $this->wire('database');
+ $database = $this->wire()->database;
if($database->escapeCol($column) !== $column) throw new WireException("Invalid column name: $column");
$query = $database->prepare("SELECT `$column` FROM pages WHERE id=:id");
$query->bindValue(':id', $id, \PDO::PARAM_INT);
$query->execute();
$value = $query->fetchColumn();
$query->closeCursor();
+ if(ctype_digit("$value") && strpos($column, 'name') !== 0) $value = (int) $value;
return $value;
}
diff --git a/wire/core/PagesLoaderCache.php b/wire/core/PagesLoaderCache.php
index 299eb926..b403eac6 100644
--- a/wire/core/PagesLoaderCache.php
+++ b/wire/core/PagesLoaderCache.php
@@ -156,13 +156,13 @@ class PagesLoaderCache extends Wire {
public function uncacheAll(Page $page = null, array $options = array()) {
if($page) {} // to ignore unused parameter inspection
- $user = $this->wire('user');
- $language = $this->wire('languages') ? $user->language : null;
+ $user = $this->wire()->user;
+ $language = $this->wire()->languages ? $user->language : null;
$cnt = 0;
$this->pages->sortfields(true); // reset
- if($this->wire('config')->debug) {
+ if($this->wire()->config->debug) {
$this->pages->debugLog('uncacheAll', 'pageIdCache=' . count($this->pageIdCache) . ', pageSelectorCache=' .
count($this->pageSelectorCache));
}
@@ -306,8 +306,8 @@ class PagesLoaderCache extends Wire {
}
// cache non-default languages separately
- if($this->wire('languages')) {
- $language = $this->wire('user')->language;
+ if($this->wire()->languages) {
+ $language = $this->wire()->user->language;
if(!$language->isDefault()) {
$selector .= ", _lang=$language->id"; // for caching purposes only, not recognized by PageFinder
}
diff --git a/wire/core/Templates.php b/wire/core/Templates.php
index 46085c6a..45febf27 100644
--- a/wire/core/Templates.php
+++ b/wire/core/Templates.php
@@ -816,6 +816,10 @@ class Templates extends WireSaveableItems {
$pageClass = "\\$pageClass";
} else {
// class is not available for instantiation
+ $this->warning(
+ "Template '$template' page class '$pageClass' is not available",
+ Notice::debug | Notice::superuser | Notice::admin
+ );
$pageClass = '';
// do not cache because maybe class will be available later
$cacheable = false;
diff --git a/wire/modules/Fieldtype/FieldtypeRepeater/FieldtypeRepeater.module b/wire/modules/Fieldtype/FieldtypeRepeater/FieldtypeRepeater.module
index e3cd35cd..6a24d06c 100644
--- a/wire/modules/Fieldtype/FieldtypeRepeater/FieldtypeRepeater.module
+++ b/wire/modules/Fieldtype/FieldtypeRepeater/FieldtypeRepeater.module
@@ -166,6 +166,7 @@ class FieldtypeRepeater extends Fieldtype implements ConfigurableModule {
$user = $this->wire()->user;
$config = $this->wire()->config;
$input = $this->wire()->input;
+ $modules = $this->wire()->modules;
$inEditor = $process == 'ProcessPageEdit' || $process == 'ProcessProfile';
$isSuperuser = $user->isSuperuser();
@@ -212,7 +213,11 @@ class FieldtypeRepeater extends Fieldtype implements ConfigurableModule {
$this->addHookAfter('PagePermissions::pageEditable', $this, 'hookPagePermissionsPageEditableAjax');
}
- $this->addHookBefore('PageFinder::getQuery', $this, 'hookPageFinderGetQuery');
+ $this->addHookBefore('PageFinder::getQuery', $this, 'hookPageFinderGetQuery');
+
+ $class = $this->className() . 'Matrix';
+ if($this->useLazy && $modules->isInstalled($class)) $modules->get($class);
+
}
/**
diff --git a/wire/modules/Inputfield/InputfieldCKEditor/plugins/pwimage/plugin.js b/wire/modules/Inputfield/InputfieldCKEditor/plugins/pwimage/plugin.js
index 32456973..0b522edc 100644
--- a/wire/modules/Inputfield/InputfieldCKEditor/plugins/pwimage/plugin.js
+++ b/wire/modules/Inputfield/InputfieldCKEditor/plugins/pwimage/plugin.js
@@ -303,8 +303,7 @@
var $img = jQuery("#selected_image", $i);
$iframe.dialog("disable");
- $iframe.setTitle(" " +
- ProcessWire.config.InputfieldCKEditor.pwimage.savingNote); // Saving Image
+ $iframe.setTitle(ProcessWire.config.InputfieldCKEditor.pwimage.savingNote); // Saving Image
$img.removeClass("resized");
var width = $img.attr('width');
@@ -352,7 +351,7 @@
];
$iframe.setButtons(buttons);
- $iframe.setTitle(" " + $i.find('title').html());
+ $iframe.setTitle($i.find('title').html());
} else {
buttons = [];
diff --git a/wire/modules/Inputfield/InputfieldCKEditor/plugins/pwimage/plugin.min.js b/wire/modules/Inputfield/InputfieldCKEditor/plugins/pwimage/plugin.min.js
index 17b97f9f..ef2ade8d 100644
--- a/wire/modules/Inputfield/InputfieldCKEditor/plugins/pwimage/plugin.min.js
+++ b/wire/modules/Inputfield/InputfieldCKEditor/plugins/pwimage/plugin.min.js
@@ -1 +1 @@
-(function(){CKEDITOR.plugins.add("pwimage",{requires:"dialog",init:function(editor){var pluginName="pwimage";var allowed="img[alt,id,!src,title,width](align_left,align_center,align_right,hidpi,align-left,align-center,align-right);"+"a[!href];"+"figure{width}(align_left,align_center,align_right,hidpi,align-left,align-center,align-right);"+"figcaption;";var required="img[alt,src]";editor.addCommand(pluginName,{allowedContent:allowed,requiredContent:required,exec:loadIframeImagePicker});editor.ui.addButton("PWImage",{label:editor.lang.common.image,command:pluginName,hidpi:true,icon:CKEDITOR.env.hidpi?this.path+"images/hidpi/pwimage.png":this.path+"images/pwimage.png"});editor.on("doubleclick",function(evt){var element=evt.data.element;if(element.is("img")&&!element.data("cke-realelement")&&!element.isReadOnly()){evt.cancel();editor.commands.pwimage.exec()}});if(editor.addMenuItems){editor.addMenuItems({image:{label:editor.lang.image.menu,command:"pwimage",group:"image"}})}if(editor.contextMenu){editor.contextMenu.addListener(function(element,selection){if(getSelectedImage(editor,element))return{image:CKEDITOR.TRISTATE_OFF}})}}});function getSelectedImage(editor,element){if(!element){var sel=editor.getSelection();element=sel.getSelectedElement()}if(element&&element.is("img")&&!element.data("cke-realelement")&&!element.isReadOnly())return element}function loadIframeImagePicker(editor){var $in=jQuery("#Inputfield_id");var page_id;if($in.length){page_id=$in.val()}else{page_id=jQuery("#"+editor.name).closest(".Inputfield").attr("data-pid")}var edit_page_id=page_id;var file="";var imgClass="";var imgWidth=0;var imgHeight=0;var imgDescription="";var imgLink="";var hidpi=false;var selection=editor.getSelection();var se=selection.getSelectedElement();var node=selection.getStartElement();var $node=jQuery(node);var nodeParent=node.getParent();var nodeGrandparent=nodeParent.getParent();var src=$node.attr("src");var $linkWrapper=null;var $figureWrapper=null;var $figureCaption=null;var nodeParentName=nodeParent.$.nodeName.toUpperCase();var nodeGrandparentName=nodeGrandparent?nodeGrandparent.$.nodeName.toUpperCase():"";var figureNodeSafari=null;var $repeaterItem=jQuery("#"+editor.name).closest(".InputfieldRepeaterItem");if(selection.getType()==CKEDITOR.SELECTION_TEXT){if(nodeParentName=="FIGURE"){figureNodeSafari=nodeParent}else if(nodeGrandparentName=="FIGURE"){figureNodeSafari=nodeGrandparent}if(figureNodeSafari){selection.reset();selection.removeAllRanges();figureNodeSafari.$.style.display="block";selection.selectElement(figureNodeSafari)}}if($repeaterItem.length&&$repeaterItem.find(".InputfieldImage").length){var dataPageAttr=$repeaterItem.attr("data-page");if(typeof dataPageAttr!=="undefined")page_id=parseInt(dataPageAttr)}selection.lock();editor.lockSelection();if(nodeGrandparentName=="FIGURE"){$figureWrapper=jQuery(nodeGrandparent.getOuterHtml());$figureCaption=$figureWrapper.find("figcaption");$figureWrapper.find("img").remove()}else if(nodeParentName=="FIGURE"){$figureWrapper=jQuery(nodeParent.getOuterHtml());$figureCaption=$figureWrapper.find("figcaption");$figureWrapper.find("img").remove()}if(nodeParentName==="A"){$linkWrapper=jQuery(nodeParent.getOuterHtml());$linkWrapper.find("img").remove()}if(src){imgClass=$figureWrapper?$figureWrapper.attr("class"):$node.attr("class");hidpi=imgClass&&imgClass.indexOf("hidpi")>-1;imgWidth=$node.attr("width");imgHeight=$node.attr("height");imgDescription=$node.attr("alt");imgLink=nodeParentName==="A"?nodeParent.$.href:"";var parts=src.split("/");file=parts.pop();parts=parts.reverse();page_id="";for(var n=0;n "+ProcessWire.config.InputfieldCKEditor.pwimage.selectLabel,open:function(){if(jQuery(".cke_maximized").length>0){jQuery(".ui-dialog").css("z-index",9999);jQuery(".ui-widget-overlay").css("z-index",9998)}}};var $iframe=pwModalWindow(modalUri+queryString,modalSettings,"large");$iframe.load(function(){var $i=$iframe.contents();var buttons;if($i.find("#selected_image").length>0){buttons=[{html:" "+ProcessWire.config.InputfieldCKEditor.pwimage.insertBtn,click:function(){function insertImage(src){var $i=$iframe.contents();var $img=jQuery("#selected_image",$i);var width=$img.attr("width");var height=$img.attr("height");var alt=jQuery("#selected_image_description",$i).val();var caption=jQuery("#selected_image_caption",$i).is(":checked")?true:false;var hidpi=jQuery("#selected_image_hidpi",$i).is(":checked")?true:false;var cls=$img.removeClass("ui-resizable No Alignment resizable_setup").removeClass("rotate90 rotate180 rotate270 rotate-90 rotate-180 rotate-270").removeClass("flip_vertical flip_horizontal").attr("class");var $linkToLarger=jQuery("#selected_image_link",$i);var link=$linkToLarger.is(":checked")?$linkToLarger.val():"";var $insertHTML=jQuery("
").attr("src",src).attr("alt",alt);if(hidpi)cls+=(cls.length>0?" ":"")+"hidpi";if(caption===false)$insertHTML.addClass(cls);if(width>0&&$img.attr("data-nosize")!="1")$insertHTML.attr("width",width);if($linkWrapper){if(link&&link.length>0){$linkWrapper.attr("href",link).attr("data-cke-saved-href",link)}else if($linkToLarger.attr("data-was-checked")==1){$linkWrapper=null}if($linkWrapper!==null){$linkWrapper.append($insertHTML);$insertHTML=$linkWrapper}}else if(link&&link.length>0){var $a=jQuery("").attr("href",link).append($insertHTML);$insertHTML=$a}if(caption){var $figure=jQuery("");if(cls.length)$figure.addClass(cls);if(!$figureCaption){$figureCaption=jQuery("");if(alt.length>1){$figureCaption.append(alt)}else{$figureCaption.append(ProcessWire.config.InputfieldCKEditor.pwimage.captionLabel)}}if($figureCaption)$figure.append($figureCaption);$figure.prepend($insertHTML);$insertHTML=$figure}if(nodeGrandparentName==="FIGURE"){editor.unlockSelection();selection.unlock();selection.selectElement(nodeGrandparent)}else if(nodeParentName==="A"||nodeParentName=="FIGURE"){editor.unlockSelection();selection.unlock();selection.selectElement(nodeParent)}var html=$insertHTML[0].outerHTML;if(figureNodeSafari)figureNodeSafari.remove();editor.insertHtml(html);editor.fire("change");$iframe.dialog("close")}var $i=$iframe.contents();var $img=jQuery("#selected_image",$i);$iframe.dialog("disable");$iframe.setTitle(" "+ProcessWire.config.InputfieldCKEditor.pwimage.savingNote);$img.removeClass("resized");var width=$img.attr("width");if(!width)width=$img.width();var height=$img.attr("height");if(!height)height=$img.height();var file=$img.attr("src");var page_id=jQuery("#page_id",$i).val();var hidpi=jQuery("#selected_image_hidpi",$i).is(":checked")?1:0;var rotate=parseInt(jQuery("#selected_image_rotate",$i).val());file=file.substring(file.lastIndexOf("/")+1);var resizeURL=modalUri+"resize?id="+page_id+"&file="+file+"&width="+width+"&height="+height+"&hidpi="+hidpi;if(rotate)resizeURL+="&rotate="+rotate;if($img.hasClass("flip_horizontal"))resizeURL+="&flip=h";else if($img.hasClass("flip_vertical"))resizeURL+="&flip=v";jQuery.get(resizeURL,function(data){var $div=jQuery("").html(data);var src=$div.find("#selected_image").attr("src");insertImage(src)})}},{html:" "+ProcessWire.config.InputfieldCKEditor.pwimage.selectBtn,class:"ui-priority-secondary",click:function(){var $i=$iframe.contents();var page_id=jQuery("#page_id",$i).val();$iframe.attr("src",modalUri+"?id="+page_id+"&modal=1");$iframe.setButtons({})}},{html:" "+ProcessWire.config.InputfieldCKEditor.pwimage.cancelBtn,class:"ui-priority-secondary",click:function(){$iframe.dialog("close")}}];$iframe.setButtons(buttons);$iframe.setTitle(" "+$i.find("title").html())}else{buttons=[];jQuery("button.pw-modal-button, button[type=submit]:visible",$i).each(function(){var $button=jQuery(this);var button={html:$button.html(),click:function(){$button.click()}};buttons.push(button);if(!$button.hasClass("pw-modal-button-visible"))$button.hide()});var cancelButton={html:" "+ProcessWire.config.InputfieldCKEditor.pwimage.cancelBtn,class:"ui-priority-secondary",click:function(){$iframe.dialog("close")}};buttons.push(cancelButton);$iframe.setButtons(buttons)}})}})();
\ No newline at end of file
+(function(){CKEDITOR.plugins.add("pwimage",{requires:"dialog",init:function(editor){var pluginName="pwimage";var allowed="img[alt,id,!src,title,width](align_left,align_center,align_right,hidpi,align-left,align-center,align-right);"+"a[!href];"+"figure{width}(align_left,align_center,align_right,hidpi,align-left,align-center,align-right);"+"figcaption;";var required="img[alt,src]";editor.addCommand(pluginName,{allowedContent:allowed,requiredContent:required,exec:loadIframeImagePicker});editor.ui.addButton("PWImage",{label:editor.lang.common.image,command:pluginName,hidpi:true,icon:CKEDITOR.env.hidpi?this.path+"images/hidpi/pwimage.png":this.path+"images/pwimage.png"});editor.on("doubleclick",function(evt){var element=evt.data.element;if(element.is("img")&&!element.data("cke-realelement")&&!element.isReadOnly()){evt.cancel();editor.commands.pwimage.exec()}});if(editor.addMenuItems){editor.addMenuItems({image:{label:editor.lang.image.menu,command:"pwimage",group:"image"}})}if(editor.contextMenu){editor.contextMenu.addListener(function(element,selection){if(getSelectedImage(editor,element))return{image:CKEDITOR.TRISTATE_OFF}})}}});function getSelectedImage(editor,element){if(!element){var sel=editor.getSelection();element=sel.getSelectedElement()}if(element&&element.is("img")&&!element.data("cke-realelement")&&!element.isReadOnly())return element}function loadIframeImagePicker(editor){var $in=jQuery("#Inputfield_id");var page_id;if($in.length){page_id=$in.val()}else{page_id=jQuery("#"+editor.name).closest(".Inputfield").attr("data-pid")}var edit_page_id=page_id;var file="";var imgClass="";var imgWidth=0;var imgHeight=0;var imgDescription="";var imgLink="";var hidpi=false;var selection=editor.getSelection();var se=selection.getSelectedElement();var node=selection.getStartElement();var $node=jQuery(node);var nodeParent=node.getParent();var nodeGrandparent=nodeParent.getParent();var src=$node.attr("src");var $linkWrapper=null;var $figureWrapper=null;var $figureCaption=null;var nodeParentName=nodeParent.$.nodeName.toUpperCase();var nodeGrandparentName=nodeGrandparent?nodeGrandparent.$.nodeName.toUpperCase():"";var figureNodeSafari=null;var $repeaterItem=jQuery("#"+editor.name).closest(".InputfieldRepeaterItem");if(selection.getType()==CKEDITOR.SELECTION_TEXT){if(nodeParentName=="FIGURE"){figureNodeSafari=nodeParent}else if(nodeGrandparentName=="FIGURE"){figureNodeSafari=nodeGrandparent}if(figureNodeSafari){selection.reset();selection.removeAllRanges();figureNodeSafari.$.style.display="block";selection.selectElement(figureNodeSafari)}}if($repeaterItem.length&&$repeaterItem.find(".InputfieldImage").length){var dataPageAttr=$repeaterItem.attr("data-page");if(typeof dataPageAttr!=="undefined")page_id=parseInt(dataPageAttr)}selection.lock();editor.lockSelection();if(nodeGrandparentName=="FIGURE"){$figureWrapper=jQuery(nodeGrandparent.getOuterHtml());$figureCaption=$figureWrapper.find("figcaption");$figureWrapper.find("img").remove()}else if(nodeParentName=="FIGURE"){$figureWrapper=jQuery(nodeParent.getOuterHtml());$figureCaption=$figureWrapper.find("figcaption");$figureWrapper.find("img").remove()}if(nodeParentName==="A"){$linkWrapper=jQuery(nodeParent.getOuterHtml());$linkWrapper.find("img").remove()}if(src){imgClass=$figureWrapper?$figureWrapper.attr("class"):$node.attr("class");hidpi=imgClass&&imgClass.indexOf("hidpi")>-1;imgWidth=$node.attr("width");imgHeight=$node.attr("height");imgDescription=$node.attr("alt");imgLink=nodeParentName==="A"?nodeParent.$.href:"";var parts=src.split("/");file=parts.pop();parts=parts.reverse();page_id="";for(var n=0;n "+ProcessWire.config.InputfieldCKEditor.pwimage.selectLabel,open:function(){if(jQuery(".cke_maximized").length>0){jQuery(".ui-dialog").css("z-index",9999);jQuery(".ui-widget-overlay").css("z-index",9998)}}};var $iframe=pwModalWindow(modalUri+queryString,modalSettings,"large");$iframe.load(function(){var $i=$iframe.contents();var buttons;if($i.find("#selected_image").length>0){buttons=[{html:" "+ProcessWire.config.InputfieldCKEditor.pwimage.insertBtn,click:function(){function insertImage(src){var $i=$iframe.contents();var $img=jQuery("#selected_image",$i);var width=$img.attr("width");var height=$img.attr("height");var alt=jQuery("#selected_image_description",$i).val();var caption=jQuery("#selected_image_caption",$i).is(":checked")?true:false;var hidpi=jQuery("#selected_image_hidpi",$i).is(":checked")?true:false;var cls=$img.removeClass("ui-resizable No Alignment resizable_setup").removeClass("rotate90 rotate180 rotate270 rotate-90 rotate-180 rotate-270").removeClass("flip_vertical flip_horizontal").attr("class");var $linkToLarger=jQuery("#selected_image_link",$i);var link=$linkToLarger.is(":checked")?$linkToLarger.val():"";var $insertHTML=jQuery("
").attr("src",src).attr("alt",alt);if(hidpi)cls+=(cls.length>0?" ":"")+"hidpi";if(caption===false)$insertHTML.addClass(cls);if(width>0&&$img.attr("data-nosize")!="1")$insertHTML.attr("width",width);if($linkWrapper){if(link&&link.length>0){$linkWrapper.attr("href",link).attr("data-cke-saved-href",link)}else if($linkToLarger.attr("data-was-checked")==1){$linkWrapper=null}if($linkWrapper!==null){$linkWrapper.append($insertHTML);$insertHTML=$linkWrapper}}else if(link&&link.length>0){var $a=jQuery("").attr("href",link).append($insertHTML);$insertHTML=$a}if(caption){var $figure=jQuery("");if(cls.length)$figure.addClass(cls);if(!$figureCaption){$figureCaption=jQuery("");if(alt.length>1){$figureCaption.append(alt)}else{$figureCaption.append(ProcessWire.config.InputfieldCKEditor.pwimage.captionLabel)}}if($figureCaption)$figure.append($figureCaption);$figure.prepend($insertHTML);$insertHTML=$figure}if(nodeGrandparentName==="FIGURE"){editor.unlockSelection();selection.unlock();selection.selectElement(nodeGrandparent)}else if(nodeParentName==="A"||nodeParentName=="FIGURE"){editor.unlockSelection();selection.unlock();selection.selectElement(nodeParent)}var html=$insertHTML[0].outerHTML;if(figureNodeSafari)figureNodeSafari.remove();editor.insertHtml(html);editor.fire("change");$iframe.dialog("close")}var $i=$iframe.contents();var $img=jQuery("#selected_image",$i);$iframe.dialog("disable");$iframe.setTitle(ProcessWire.config.InputfieldCKEditor.pwimage.savingNote);$img.removeClass("resized");var width=$img.attr("width");if(!width)width=$img.width();var height=$img.attr("height");if(!height)height=$img.height();var file=$img.attr("src");var page_id=jQuery("#page_id",$i).val();var hidpi=jQuery("#selected_image_hidpi",$i).is(":checked")?1:0;var rotate=parseInt(jQuery("#selected_image_rotate",$i).val());file=file.substring(file.lastIndexOf("/")+1);var resizeURL=modalUri+"resize?id="+page_id+"&file="+file+"&width="+width+"&height="+height+"&hidpi="+hidpi;if(rotate)resizeURL+="&rotate="+rotate;if($img.hasClass("flip_horizontal"))resizeURL+="&flip=h";else if($img.hasClass("flip_vertical"))resizeURL+="&flip=v";jQuery.get(resizeURL,function(data){var $div=jQuery("").html(data);var src=$div.find("#selected_image").attr("src");insertImage(src)})}},{html:" "+ProcessWire.config.InputfieldCKEditor.pwimage.selectBtn,class:"ui-priority-secondary",click:function(){var $i=$iframe.contents();var page_id=jQuery("#page_id",$i).val();$iframe.attr("src",modalUri+"?id="+page_id+"&modal=1");$iframe.setButtons({})}},{html:" "+ProcessWire.config.InputfieldCKEditor.pwimage.cancelBtn,class:"ui-priority-secondary",click:function(){$iframe.dialog("close")}}];$iframe.setButtons(buttons);$iframe.setTitle($i.find("title").html())}else{buttons=[];jQuery("button.pw-modal-button, button[type=submit]:visible",$i).each(function(){var $button=jQuery(this);var button={html:$button.html(),click:function(){$button.click()}};buttons.push(button);if(!$button.hasClass("pw-modal-button-visible"))$button.hide()});var cancelButton={html:" "+ProcessWire.config.InputfieldCKEditor.pwimage.cancelBtn,class:"ui-priority-secondary",click:function(){$iframe.dialog("close")}};buttons.push(cancelButton);$iframe.setButtons(buttons)}})}})();
\ No newline at end of file