mirror of
https://github.com/getgrav/grav.git
synced 2026-03-05 12:01:37 +01:00
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 commit7a59a84290, reversing changes made to102973d22c. * Revert "Revert "Merge remote-tracking branch 'origin/develop' into develop"" This reverts commit50fc775c69. * 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:
committed by
Andy Miller
parent
d338d79acb
commit
4aa6dce853
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user