optimize for google pagespeed insights
git-svn-id: http://78.47.251.156/svn/dev/sterntours-3@3479 f459cee4-fb09-11de-96c3-f9c5f16c3c76
This commit is contained in:
parent
a2a93aab0e
commit
7ad52c8b89
145 changed files with 105899 additions and 4408 deletions
|
|
@ -10,6 +10,9 @@ namespace AppBundle\Twig;
|
|||
use AppBundle\Service\KeywordService;
|
||||
use AppBundle\Util;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||
use Gregwar\Image\Image;
|
||||
|
||||
class AppExtension extends \Twig_Extension
|
||||
{
|
||||
|
|
@ -34,6 +37,9 @@ class AppExtension extends \Twig_Extension
|
|||
'keywords' => new \Twig_SimpleFilter('keywords', [$this, 'keywordsFilter'], [
|
||||
'is_safe' => ['html']
|
||||
]),
|
||||
'lozad' => new \Twig_SimpleFilter('lozad', [$this, 'lozadFilter'], [
|
||||
'is_safe' => ['html']
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -63,7 +69,7 @@ class AppExtension extends \Twig_Extension
|
|||
|
||||
public function getBaseTemplate()
|
||||
{
|
||||
return ($this->requestStack->getCurrentRequest()->isXmlHttpRequest() ? 'ajax' : 'base') .'.html.twig';
|
||||
return ($this->requestStack->getCurrentRequest()->isXmlHttpRequest() ? 'ajax' : 'base') . '.html.twig';
|
||||
}
|
||||
|
||||
public function getBaseUrl()
|
||||
|
|
@ -73,7 +79,7 @@ class AppExtension extends \Twig_Extension
|
|||
|
||||
public function formField($form, $label = null, $opt = null)
|
||||
{
|
||||
$this->template = $this->environment->loadTemplate( '::default/form/helpers.html.twig' );
|
||||
$this->template = $this->environment->loadTemplate('::default/form/helpers.html.twig');
|
||||
return $this->template->renderBlock('form_field', [
|
||||
'form' => $form,
|
||||
'label' => $label,
|
||||
|
|
@ -92,7 +98,7 @@ class AppExtension extends \Twig_Extension
|
|||
*/
|
||||
public function formFieldPho($form, $label = null, $opt = [])
|
||||
{
|
||||
$this->template = $this->environment->loadTemplate( '::default/form/helpers.html.twig' );
|
||||
$this->template = $this->environment->loadTemplate('::default/form/helpers.html.twig');
|
||||
|
||||
return $this->template->renderBlock('form_field_pho', [
|
||||
'form' => $form,
|
||||
|
|
@ -110,4 +116,33 @@ class AppExtension extends \Twig_Extension
|
|||
{
|
||||
return 'app_extension';
|
||||
}
|
||||
|
||||
|
||||
public function lozadFilter($html)
|
||||
{
|
||||
//(<img\s*?)src
|
||||
$dom = new \DOMDocument;
|
||||
$dom->loadHTML('<?xml encoding="utf-8" ?>'.$html);
|
||||
$images = $dom->getElementsByTagName('img');
|
||||
foreach ($images as $image) {
|
||||
|
||||
$i = Util::getRootDir().'web/'.$image->getAttribute('src');
|
||||
if(strpos($image->getAttribute('src'), 'docs')){
|
||||
$i = Util::getRootDir().'web/'.substr($image->getAttribute('src'), strpos($image->getAttribute('src'), 'docs'));
|
||||
}
|
||||
if(strpos($image->getAttribute('src'), 'uploads')){
|
||||
$i = Util::getRootDir().'web/'.substr($image->getAttribute('src'), strpos($image->getAttribute('src'), 'uploads'));
|
||||
}
|
||||
$i = Image::open($i)->cropResize(848)->guess(75);
|
||||
|
||||
// $i = image()..;
|
||||
$image->setAttribute('data-src', $i);
|
||||
$image->setAttribute('src', 'images/placeholder-image.png');
|
||||
$image->setAttribute('class', 'lozad');
|
||||
}
|
||||
$html = $dom->saveHTML();
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue