12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?php
- namespace app\components\amp;
- use Yii;
- use magyarandras\AMPConverter\TagConverterInterface;
- class AMPP implements TagConverterInterface
- {
- private $necessary_scripts = [];
- public function convert(\DOMDocument $doc)
- {
- $query = '//ul|//li|//strong|//table';
- $xpath = new \DOMXPath($doc);
- $entries = $xpath->query($query);
- $allowed_attributes = ['class', 'id'];
- foreach($entries as $element){
- for ( $k = $element->attributes->length - 1; $k >= 0; --$k) {
- if( array_search( $element->attributes->item($k)->nodeName, $allowed_attributes ) === false ){
- $element->removeAttributeNode( $element->attributes->item($k));
- }
- }
- }
- $ahrefs = $doc->getElementsByTagName('p');
- foreach($ahrefs as $element){
- for ( $k = $element->attributes->length - 1; $k >= 0; --$k) {
- $element->removeAttributeNode( $element->attributes->item($k));
- }
- }
- return $doc;
- }
- public function getNecessaryScripts()
- {
- return $this->necessary_scripts;
- }
- }
|