1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-09 08:17:12 +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:
Ryan Cramer
2021-08-18 11:14:31 -04:00
parent 51117dbea8
commit 2862114021
2 changed files with 40 additions and 13 deletions

View File

@@ -17,7 +17,7 @@
*
* 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
*
*/
@@ -409,17 +409,26 @@ class MarkupQA extends Wire {
}
if($ignored) continue;
// get the page ID for the path
$pageID = $this->wire('pages')->getByPath($path, array(
'getID' => true,
// get the page for the path
$getByPathOptions = array(
'useLanguages' => $languages ? true : false,
'allowUrlSegments' => 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) {
// resolved to a page
$urlSegments = $page->get('_urlSegments');
$urlSegmentStr = is_array($urlSegments) ? implode('/', $urlSegments) : '';
if($languages) {
$page = $this->wire('pages')->get($pageID);
/** @var Language $language */
$language = $this->wire('modules')->get('LanguageSupportPageNames')->getPagePathLanguage($path, $page);
$pwid = !$language || $language->isDefault() ? $pageID : "$pageID-$language";
@@ -427,6 +436,10 @@ class MarkupQA extends Wire {
$language = null;
$pwid = $pageID;
}
if($urlSegmentStr) {
// append url segment path to the pwid
$pwid .= "/$urlSegmentStr";
}
$replacements[$full] = "$start\tdata-pwid=$pwid$href$path$end";
$counts['internal']++;
if($debug) {
@@ -472,22 +485,23 @@ class MarkupQA extends Wire {
* a potential "/subdir/" that wouldn't be recognized as a page path.
*
* @param $value
* @return array Returns array of replacements that were made (3.0.184+)
*
*/
public function wakeupLinks(&$value) {
// 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 = '!' .
'(<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
'([-_./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.
'!i';
if(!preg_match_all($re, $value, $matches)) return;
if(!preg_match_all($re, $value, $matches)) return array();
$replacements = array();
$languages = $this->wire('languages');
@@ -498,6 +512,12 @@ class MarkupQA extends Wire {
foreach($matches[2] as $key => $pwid) {
if(strpos($pwid, '/')) {
list($pwid, $urlSegmentStr) = explode('/', $pwid, 2);
} else {
$urlSegmentStr = '';
}
if(strpos($pwid, '-')) {
list($pageID, $languageID) = explode('-', $pwid);
} else {
@@ -522,6 +542,11 @@ class MarkupQA extends Wire {
'language' => $language
));
if($urlSegmentStr) {
$livePath = rtrim($livePath, '/') . "/$urlSegmentStr";
if(substr($path, '-1') === '/') $livePath .= '/';
}
if(strlen($rootURL) > 1) {
$livePath = rtrim($rootURL, '/') . $livePath;
$href = ' ' . ltrim($href); // immunity to wakeupUrls(), replacing tab with space
@@ -572,6 +597,8 @@ class MarkupQA extends Wire {
if(count($replacements)) {
$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()) {
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) {
$this->checkImgTag($value, $img, $options);
}

View File

@@ -184,7 +184,7 @@ class FieldtypeTextareaHelper extends Wire {
$statusNote = ' ' .
$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.');
$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';
@@ -202,14 +202,14 @@ class FieldtypeTextareaHelper extends Wire {
$types = array(
'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'),
'files' => $good . $this->_x('%d file/asset references', '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'),
'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'),
'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_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'),