Skip to content

Commit

Permalink
Merge pull request #715 from ucfopen/issue/713-disable-link-rules
Browse files Browse the repository at this point in the history
Issue/713 disable link rules
  • Loading branch information
bagofarms authored Nov 16, 2021
2 parents 1702d81 + 9ff90fe commit d19ef66
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
5 changes: 4 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ MESSENGER_TRANSPORT_DSN=doctrine://default

###> phpally ###
# Rule exclusion list as a comma-separated list of rule IDs.
PHPALLY_EXCLUDED_RULES=""
PHPALLY_EXCLUDED_RULES="
BrokenLink,
RedirectedLink
"
# Rules to be treated as suggestions rather than errors. Comma-separated list of rule IDs.
PHPALLY_SUGGESTION_RULES="
AnchorLinksToMultiMediaRequireTranscript,
Expand Down
21 changes: 14 additions & 7 deletions src/Services/PhpAllyService.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
use CidiLabs\PhpAlly\PhpAlly;

class PhpAllyService {

protected $phpAlly;

/** @var App\Service\HtmlService */
protected $htmlService;

protected $util;

public function __construct(HtmlService $htmlService, UtilityService $util)
{
$this->phpAlly = new PhpAlly();
$this->phpAlly = new PhpAlly();
$this->htmlService = $htmlService;
$this->util = $util;
}
Expand All @@ -34,7 +34,7 @@ public function scanContentItem(ContentItem $contentItem)
'vimeoApiKey' => !empty($_ENV['VIMEO_API_KEY']) ? $_ENV['VIMEO_API_KEY'] : '',
'youtubeApiKey' => !empty($_ENV['YOUTUBE_API_KEY']) ? $_ENV['YOUTUBE_API_KEY'] : ''
];

return $this->phpAlly->checkMany($html, $this->getRules(), $options);
}

Expand All @@ -52,7 +52,7 @@ public function scanHtml($html, $rules = [])
'vimeoApiKey' => !empty($_ENV['VIMEO_API_KEY']) ? $_ENV['VIMEO_API_KEY'] : '',
'youtubeApiKey' => !empty($_ENV['YOUTUBE_API_KEY']) ? $_ENV['YOUTUBE_API_KEY'] : ''
];

return $this->phpAlly->checkMany($html, $rules, $options);
}

Expand All @@ -68,12 +68,19 @@ public function getRules()

protected function getEnvExcludedRules()
{
return array_map('trim', explode(',', $_ENV['PHPALLY_EXCLUDED_RULES']));
$excluded = array_map('trim', explode(',', $_ENV['PHPALLY_EXCLUDED_RULES']));

return array_map(array($this, 'addRulePath'), $excluded);
}

protected function getDbExcludedRules()
{
// TODO: To be implemented with the admin section
return [];
}
}

private function addRulePath($rule)
{
return "CidiLabs\\PhpAlly\\Rule\\" . $rule;
}
}

0 comments on commit d19ef66

Please sign in to comment.