From 770c717baa092900d0cd06c86c50a6f73e02e0c7 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Wed, 15 Mar 2017 14:04:49 -0400 Subject: [PATCH] Updates related to WireMarkupRegions discussion in issue processwire/processwire-issues#195 - fix behavior of boolean pw-before/pw-after attributes, and add support for `` or `` tags. --- wire/core/WireMarkupRegions.php | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/wire/core/WireMarkupRegions.php b/wire/core/WireMarkupRegions.php index 23879b64..7e18e03d 100644 --- a/wire/core/WireMarkupRegions.php +++ b/wire/core/WireMarkupRegions.php @@ -1248,7 +1248,11 @@ class WireMarkupRegions extends Wire { $attrs = $region['attrs']; $attrStr = count($attrs) ? ' ' . $this->renderAttributes($attrs, false) : ''; if(!strlen(trim($attrStr))) $attrStr = ''; - $regionHTML = str_replace($region['open'], "<$region[name]$attrStr>", $regionHTML); + if($region['actionType'] == 'bool') { + $regionHTML = $region['region']; + } else { + $regionHTML = str_replace($region['open'], "<$region[name]$attrStr>", $regionHTML); + } } if($debug) { @@ -1332,7 +1336,9 @@ class WireMarkupRegions extends Wire { // see if they can be populated now $numUpdates += $this->populate($htmlDocument, $xregions); } - + + if($this->removeRegionTags($htmlDocument)) $numUpdates++; + // if there is any leftover markup, place it above the HTML where it would usually go if(strlen($leftoverMarkup)) { $htmlDocument = $leftoverMarkup . $htmlDocument; @@ -1342,6 +1348,20 @@ class WireMarkupRegions extends Wire { return $numUpdates; } + /** + * Remove any or tags present in the markup, leaving their innerHTML contents + * + * @param string $html + * @return bool True if tags were removed, false if not + * + */ + protected function removeRegionTags(&$html) { + if(stripos($html, '') === false && strpos($html, '') === false) return false; + $html = preg_replace('!]*>|>)!i', '', $html); + //$html = str_ireplace(array('', ''), '', $html); + return true; + } + /** * Is the given HTML markup likely to have regions? *