Skip to content

Commit

Permalink
add function isajaxrequest() (#1400)
Browse files Browse the repository at this point in the history
* 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 7a59a84, reversing
changes made to 102973d.

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

This reverts commit 50fc775.

* 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
  • Loading branch information
gigago authored and rhukster committed Apr 4, 2017
1 parent d338d79 commit 4aa6dce
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions system/src/Grav/Common/Twig/TwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public function getFunctions()
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']),
];
}

Expand Down Expand Up @@ -892,4 +893,17 @@ public function rangeFunc($start = 0, $end = 100, $step = 1)
{
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');
}
}

0 comments on commit 4aa6dce

Please sign in to comment.