12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- namespace app\components\amp;
- use Yii;
- use magyarandras\AMPConverter\TagConverterInterface;
- class AMPSpan implements TagConverterInterface
- {
- private $necessary_scripts = [];
- public function convert(\DOMDocument $doc)
- {
- /* $query = '//div';
- $xpath = new \DOMXPath($doc);
- $entries = $xpath->query($query);
- $allowed_attributes = ['class', 'id'];
- foreach ($entries as $tag) {
- $div = $doc->createElement('div');
- $br = $doc->createElement('br');
- foreach ($allowed_attributes as $attribute) {
- if ($tag->hasAttribute($attribute)) {
- $div->setAttribute($attribute, $tag->getAttribute($attribute));
- }
- }
- if ($tag->hasChildNodes()) {
- foreach ($tag->childNodes as $node) {
- $ch = $node->cloneNode(true);
- if( $ch->nodeName == 'div' && $ch->getAttribute('id') == 'inject'){
- //$div->removeChild($ch);
- }else{
- $div->appendChild( $ch );
- }
- }
- }
-
- $tag->parentNode->replaceChild($div, $tag);
- }*/
- $ahrefs = $doc->getElementsByTagName('span');
- foreach($ahrefs as $element){
- for ( $k = $element->attributes->length - 1; $k >= 0; --$k) {
- if( $element->attributes->item($k)->nodeName != 'id' && $element->attributes->item($k)->nodeName != 'class' ){
- $element->removeAttributeNode( $element->attributes->item($k));
- }
- }
- }
- return $doc;
- }
- public function getNecessaryScripts()
- {
- return $this->necessary_scripts;
- }
- }
|