diff --git a/wire/core/MarkupQA.php b/wire/core/MarkupQA.php index cb2b6f11..af973134 100644 --- a/wire/core/MarkupQA.php +++ b/wire/core/MarkupQA.php @@ -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 = '!' . '(]*?)' . // 1:"start" which includes "]+|["\']))' . // 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, ']+>)}', $value, $matches)) { + if(strpos($value, ']+>)}', $value, $matches)) { foreach($matches[0] as $key => $img) { $this->checkImgTag($value, $img, $options); } diff --git a/wire/modules/Fieldtype/FieldtypeTextareaHelper.php b/wire/modules/Fieldtype/FieldtypeTextareaHelper.php index 8843f4e7..bd86e635 100644 --- a/wire/modules/Fieldtype/FieldtypeTextareaHelper.php +++ b/wire/modules/Fieldtype/FieldtypeTextareaHelper.php @@ -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 = '' . sprintf($statusNote, '$config->applyHTMLMaxItems = ' . ($applyMax * 2)) . ';'; + $statusNote = sprintf($statusNote, '$config->applyHTMLMaxItems = ' . ($applyMax * 2) . ';'); } $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'),