Issues (11)

code/RemoveImageSourceAttribute.php (2 issues)

1
<?php
2
3
class RemoveImageSourceAttribute extends Extension
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
    /**
6
     * Remove src attributes from images, instead use foundations responsive image loader.
7
     *
8
     * @param string $html HTML content of the page
9
     */
10
    public function ResponsiveTinyMCEImages($html)
0 ignored issues
show
Method name "RemoveImageSourceAttribute::ResponsiveTinyMCEImages" is not in camel caps format
Loading history...
11
    {
12
        $dom = Injector::inst()->create('HTMLValue', $html);
13
        if ($images = $dom->getElementsByTagName('img')) {
14
            foreach ($images as $img) {
15
                $cssclass = $img->getAttribute('class');
16
                $pos = strpos($cssclass, 'tinymce');
17
                if ($pos !== false) {
18
                    $img->removeAttribute('src');
19
                }
20
            }
21
        }
22
        return $dom->getContent();
23
    }
24
}
25