mirror of
https://github.com/processwire/processwire.git
synced 2025-08-09 16:26:59 +02:00
Fix issue processwire/processwire-issues#1116 - MarkupQA handling of abstracted URLs that also contain URL segments appended to them.
This commit is contained in:
@@ -17,7 +17,7 @@
|
|||||||
*
|
*
|
||||||
* Runtime errors are logged to: /site/assets/logs/markup-qa-errors.txt
|
* Runtime errors are logged to: /site/assets/logs/markup-qa-errors.txt
|
||||||
*
|
*
|
||||||
* ProcessWire 3.x, Copyright 2019 by Ryan Cramer
|
* ProcessWire 3.x, Copyright 2021 by Ryan Cramer
|
||||||
* https://processwire.com
|
* https://processwire.com
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -409,17 +409,26 @@ class MarkupQA extends Wire {
|
|||||||
}
|
}
|
||||||
if($ignored) continue;
|
if($ignored) continue;
|
||||||
|
|
||||||
// get the page ID for the path
|
// get the page for the path
|
||||||
$pageID = $this->wire('pages')->getByPath($path, array(
|
$getByPathOptions = array(
|
||||||
'getID' => true,
|
|
||||||
'useLanguages' => $languages ? true : false,
|
'useLanguages' => $languages ? true : false,
|
||||||
|
'allowUrlSegments' => true,
|
||||||
'useHistory' => true
|
'useHistory' => true
|
||||||
));
|
);
|
||||||
|
$page = $this->wire()->pages->getByPath($path, $getByPathOptions);
|
||||||
|
if(!$page->id) {
|
||||||
|
// if not found try again with non-urlSegment partial matching
|
||||||
|
$getByPathOptions['allowUrlSegments'] = false;
|
||||||
|
$page = $this->wire()->pages->getByPath($path, $getByPathOptions);
|
||||||
|
}
|
||||||
|
$pageID = $page->id;
|
||||||
|
|
||||||
if($pageID) {
|
if($pageID) {
|
||||||
// resolved to a page
|
// resolved to a page
|
||||||
|
$urlSegments = $page->get('_urlSegments');
|
||||||
|
$urlSegmentStr = is_array($urlSegments) ? implode('/', $urlSegments) : '';
|
||||||
|
|
||||||
if($languages) {
|
if($languages) {
|
||||||
$page = $this->wire('pages')->get($pageID);
|
|
||||||
/** @var Language $language */
|
/** @var Language $language */
|
||||||
$language = $this->wire('modules')->get('LanguageSupportPageNames')->getPagePathLanguage($path, $page);
|
$language = $this->wire('modules')->get('LanguageSupportPageNames')->getPagePathLanguage($path, $page);
|
||||||
$pwid = !$language || $language->isDefault() ? $pageID : "$pageID-$language";
|
$pwid = !$language || $language->isDefault() ? $pageID : "$pageID-$language";
|
||||||
@@ -427,6 +436,10 @@ class MarkupQA extends Wire {
|
|||||||
$language = null;
|
$language = null;
|
||||||
$pwid = $pageID;
|
$pwid = $pageID;
|
||||||
}
|
}
|
||||||
|
if($urlSegmentStr) {
|
||||||
|
// append url segment path to the pwid
|
||||||
|
$pwid .= "/$urlSegmentStr";
|
||||||
|
}
|
||||||
$replacements[$full] = "$start\tdata-pwid=$pwid$href$path$end";
|
$replacements[$full] = "$start\tdata-pwid=$pwid$href$path$end";
|
||||||
$counts['internal']++;
|
$counts['internal']++;
|
||||||
if($debug) {
|
if($debug) {
|
||||||
@@ -472,22 +485,23 @@ class MarkupQA extends Wire {
|
|||||||
* a potential "/subdir/" that wouldn't be recognized as a page path.
|
* a potential "/subdir/" that wouldn't be recognized as a page path.
|
||||||
*
|
*
|
||||||
* @param $value
|
* @param $value
|
||||||
|
* @return array Returns array of replacements that were made (3.0.184+)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function wakeupLinks(&$value) {
|
public function wakeupLinks(&$value) {
|
||||||
|
|
||||||
// if there's no data-pwid attribute present, then there's nothing to do here
|
// if there's no data-pwid attribute present, then there's nothing to do here
|
||||||
if(strpos($value, 'data-pwid=') === false) return;
|
if(strpos($value, 'data-pwid=') === false) return array();
|
||||||
|
|
||||||
$re = '!' .
|
$re = '!' .
|
||||||
'(<a[^\t<>]*?)' . // 1:"start" which includes "<a" and everything up until data-pwid attribute
|
'(<a[^\t<>]*?)' . // 1:"start" which includes "<a" and everything up until data-pwid attribute
|
||||||
'\tdata-pwid=([-\d]+)' . // 2:"pwid" integer of page id ($pageID) referenced by the link
|
'\tdata-pwid=([-\d]+(?:/[-_./a-z0-9]+)?)' . // 2:"pwid" integer of page id ($pageID) referenced by the link (123-11/urlSegmentStr)
|
||||||
'([\t ]+href=(?:["\'](?:https?:)?//[^/"\'\s<>]+|["\']))' . // 3:"href" attribute and optional scheme+hostname
|
'([\t ]+href=(?:["\'](?:https?:)?//[^/"\'\s<>]+|["\']))' . // 3:"href" attribute and optional scheme+hostname
|
||||||
'([-_./a-z0-9]+)' . // 4:"path" in PW page name format
|
'([-_./a-z0-9]+)' . // 4:"path" in PW page name format
|
||||||
'([^<>]*>)' . // 5:"end" which includes everything else and closing ">", i.e. query string, other attrs, etc.
|
'([^<>]*>)' . // 5:"end" which includes everything else and closing ">", i.e. query string, other attrs, etc.
|
||||||
'!i';
|
'!i';
|
||||||
|
|
||||||
if(!preg_match_all($re, $value, $matches)) return;
|
if(!preg_match_all($re, $value, $matches)) return array();
|
||||||
|
|
||||||
$replacements = array();
|
$replacements = array();
|
||||||
$languages = $this->wire('languages');
|
$languages = $this->wire('languages');
|
||||||
@@ -498,6 +512,12 @@ class MarkupQA extends Wire {
|
|||||||
|
|
||||||
foreach($matches[2] as $key => $pwid) {
|
foreach($matches[2] as $key => $pwid) {
|
||||||
|
|
||||||
|
if(strpos($pwid, '/')) {
|
||||||
|
list($pwid, $urlSegmentStr) = explode('/', $pwid, 2);
|
||||||
|
} else {
|
||||||
|
$urlSegmentStr = '';
|
||||||
|
}
|
||||||
|
|
||||||
if(strpos($pwid, '-')) {
|
if(strpos($pwid, '-')) {
|
||||||
list($pageID, $languageID) = explode('-', $pwid);
|
list($pageID, $languageID) = explode('-', $pwid);
|
||||||
} else {
|
} else {
|
||||||
@@ -522,6 +542,11 @@ class MarkupQA extends Wire {
|
|||||||
'language' => $language
|
'language' => $language
|
||||||
));
|
));
|
||||||
|
|
||||||
|
if($urlSegmentStr) {
|
||||||
|
$livePath = rtrim($livePath, '/') . "/$urlSegmentStr";
|
||||||
|
if(substr($path, '-1') === '/') $livePath .= '/';
|
||||||
|
}
|
||||||
|
|
||||||
if(strlen($rootURL) > 1) {
|
if(strlen($rootURL) > 1) {
|
||||||
$livePath = rtrim($rootURL, '/') . $livePath;
|
$livePath = rtrim($rootURL, '/') . $livePath;
|
||||||
$href = ' ' . ltrim($href); // immunity to wakeupUrls(), replacing tab with space
|
$href = ' ' . ltrim($href); // immunity to wakeupUrls(), replacing tab with space
|
||||||
@@ -572,6 +597,8 @@ class MarkupQA extends Wire {
|
|||||||
if(count($replacements)) {
|
if(count($replacements)) {
|
||||||
$value = str_replace(array_keys($replacements), array_values($replacements), $value);
|
$value = str_replace(array_keys($replacements), array_values($replacements), $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $replacements;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -708,7 +735,7 @@ class MarkupQA extends Wire {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function checkImgTags(&$value, array $options = array()) {
|
public function checkImgTags(&$value, array $options = array()) {
|
||||||
if(strpos($value, '<img ') !== false && preg_match_all('{(<img [^>]+>)}', $value, $matches)) {
|
if(strpos($value, '<img ') !== false && preg_match_all('{(<' . 'img [^>]+>)}', $value, $matches)) {
|
||||||
foreach($matches[0] as $key => $img) {
|
foreach($matches[0] as $key => $img) {
|
||||||
$this->checkImgTag($value, $img, $options);
|
$this->checkImgTag($value, $img, $options);
|
||||||
}
|
}
|
||||||
|
@@ -184,7 +184,7 @@ class FieldtypeTextareaHelper extends Wire {
|
|||||||
$statusNote = ' ' .
|
$statusNote = ' ' .
|
||||||
$this->_('There are still more pages to apply. Check the box again to apply remaining pages.') . ' ' .
|
$this->_('There are still more pages to apply. Check the box again to apply remaining pages.') . ' ' .
|
||||||
$this->_('Need to apply more pages at a time? You can add a %s setting to your /site/config.php file.');
|
$this->_('Need to apply more pages at a time? You can add a %s setting to your /site/config.php file.');
|
||||||
$statusNote = '<code>' . sprintf($statusNote, '$config->applyHTMLMaxItems = ' . ($applyMax * 2)) . ';</code>';
|
$statusNote = sprintf($statusNote, '<code>$config->applyHTMLMaxItems = ' . ($applyMax * 2) . ';</code>');
|
||||||
}
|
}
|
||||||
|
|
||||||
$logFile = $this->wire('config')->paths->logs . 'markup-qa-errors.txt';
|
$logFile = $this->wire('config')->paths->logs . 'markup-qa-errors.txt';
|
||||||
@@ -202,14 +202,14 @@ class FieldtypeTextareaHelper extends Wire {
|
|||||||
|
|
||||||
$types = array(
|
$types = array(
|
||||||
'external' => $good . $this->_x('%d external a[href] tags', 'link-type'),
|
'external' => $good . $this->_x('%d external a[href] tags', 'link-type'),
|
||||||
'href' => $good . $this->_('%d local a[href] tags', 'link-type'),
|
'href' => $good . $this->_x('%d local a[href] tags', 'link-type'),
|
||||||
'internal' => $good . $this->_x('%d internal/abstract page links', 'link-type'),
|
'internal' => $good . $this->_x('%d internal/abstract page links', 'link-type'),
|
||||||
'files' => $good . $this->_x('%d file/asset references', 'link-type'),
|
'files' => $good . $this->_x('%d file/asset references', 'link-type'),
|
||||||
'relative' => $good . $this->_x('%d relative a[href] tags updated', 'link-type'),
|
'relative' => $good . $this->_x('%d relative a[href] tags updated', 'link-type'),
|
||||||
'other' => $ques . $this->_x('%d local a[href] non-page/unrecognized tags', 'link-type'),
|
'other' => $ques . $this->_x('%d local a[href] non-page/unrecognized tags', 'link-type'),
|
||||||
'nohttp' => $good . $this->_x('%d non-http a[href] links like mailto, tel, etc.', 'link-type'),
|
'nohttp' => $good . $this->_x('%d non-http a[href] links like mailto, tel, etc.', 'link-type'),
|
||||||
'unresolved' => $fail . $this->_x('%d unresolved a[href] tags', 'link-type'),
|
'unresolved' => $fail . $this->_x('%d unresolved a[href] tags', 'link-type'),
|
||||||
'src' => $good . $this->_('%d local img[src] tags', 'link-type'),
|
'src' => $good . $this->_x('%d local img[src] tags', 'link-type'),
|
||||||
'img_unresolved' => $fail . $this->_x('%d unresolved img[src] tags', 'link-type'),
|
'img_unresolved' => $fail . $this->_x('%d unresolved img[src] tags', 'link-type'),
|
||||||
'img_fixed' => $good . $this->_x('%d unresolved and fixed img[src] tags', 'link-type'),
|
'img_fixed' => $good . $this->_x('%d unresolved and fixed img[src] tags', 'link-type'),
|
||||||
'img_noalt' => $good . $this->_x('%d blank img[alt] tags to be populated at runtime', 'link-type'),
|
'img_noalt' => $good . $this->_x('%d blank img[alt] tags to be populated at runtime', 'link-type'),
|
||||||
|
Reference in New Issue
Block a user