1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-09 08:17:12 +02:00
This commit is contained in:
Ryan Cramer
2017-06-22 11:29:35 -04:00
parent 763963ec39
commit dbfb3e2c7e

View File

@@ -1275,6 +1275,7 @@ class WireMarkupRegions extends Wire {
if(!count($regions)) {
if($debug) $htmlDocument = str_replace($debugLandmark, "<pre>No regions</pre>$debugLandmark", $htmlDocument);
$recursionLevel--;
return 0;
}
@@ -1393,10 +1394,11 @@ class WireMarkupRegions extends Wire {
if(count($xregions) && $recursionLevel < 3) {
// see if they can be populated now
$numUpdates += $this->populate($htmlDocument, $xregions);
$numUpdates += $this->populate($htmlDocument, $xregions, $options);
}
if($this->removeRegionTags($htmlDocument)) $numUpdates++;
// remove region tags and pw-id attributes
if($recursionLevel === 1 && $this->removeRegionTags($htmlDocument)) $numUpdates++;
// if there is any leftover markup, place it above the HTML where it would usually go
if(strlen($leftoverMarkup)) {
@@ -1404,21 +1406,35 @@ class WireMarkupRegions extends Wire {
$numUpdates++;
}
$recursionLevel--;
return $numUpdates;
}
/**
* Remove any <region> or <pw-region> tags present in the markup, leaving their innerHTML contents
*
* Also removes data-pw-id and pw-id attributes
*
* @param string $html
* @return bool True if tags were removed, false if not
* @return bool True if tags or attributes were removed, false if not
*
*/
protected function removeRegionTags(&$html) {
if(stripos($html, '</region>') === false && strpos($html, '</pw-region>') === false) return false;
$updated = false;
if(stripos($html, '</region>') !== false || strpos($html, '</pw-region>') !== false) {
$html = preg_replace('!</?(?:region|pw-region)(?:\s[^>]*>|>)!i', '', $html);
//$html = str_ireplace(array('</region>', '</pw-region>'), '', $html);
return true;
$updated = true;
}
if(stripos($html, ' data-pw-id=') || stripos($html, ' pw-id=')) {
$html = preg_replace('/(<[^>]+)(?: data-pw-id| pw-id)=["\']?[^>\s"\']+["\']?/i', '$1', $html);
$updated = true;
}
return $updated;
}
/**