add function isajaxrequest() (#1400)

* Update Taxonomy.php

* Update TwigExtension.php

* Update TwigExtension.php

Incorrect comment updated.

* Update TwigExtension.php

Add function ishuman() to detect agent disposition.

* Update TwigExtension.php

* Revert "Merge remote-tracking branch 'origin/develop' into develop"

This reverts commit 7a59a84290, reversing
changes made to 102973d22c.

* Revert "Revert "Merge remote-tracking branch 'origin/develop' into develop""

This reverts commit 50fc775c69.

* Attempt to resolve conflicts

* param comment corrected

* Update TwigExtension.php

* Update TwigExtension.php

* Update TwigExtension.php

* Update TwigExtension.php

* add isajaxrequest

Check HTTP_X_REQUESTED_WITH header. Non critical use only. Handy for
streamlining ajax presentation.

* remove ishuman

* remove Browser class
This commit is contained in:
Gilles van Eeden
2017-04-04 16:53:27 +02:00
committed by Andy Miller
parent d338d79acb
commit 4aa6dce853

View File

@@ -119,6 +119,7 @@ class TwigExtension extends \Twig_Extension
new \Twig_SimpleFunction('get_cookie', [$this, 'getCookie']),
new \Twig_SimpleFunction('redirect_me', [$this, 'redirectFunc']),
new \Twig_SimpleFunction('range', [$this, 'rangeFunc']),
new \Twig_SimpleFunction('isajaxrequest', [$this, 'isAjaxFunc']),
];
}
@@ -892,4 +893,17 @@ class TwigExtension extends \Twig_Extension
{
return range($start, $end, $step);
}
/**
* Check if HTTP_X_REQUESTED_WITH has been set to xmlhttprequest,
* in which case we may unsafely assume ajax. Non critical use only.
*
* @return true if HTTP_X_REQUESTED_WITH exists and has been set to xmlhttprequest
*/
public function isAjaxFunc()
{
return (
!empty($_SERVER['HTTP_X_REQUESTED_WITH'])
&& strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
}
}