isAjax() public static method

public static isAjax ( )
Example #1
0
 /**
  * Renders blue screen.
  * @param  \Exception|\Throwable
  * @return void
  */
 public function render($exception)
 {
     if (Helpers::isAjax() && session_status() === PHP_SESSION_ACTIVE) {
         ob_start(function () {
         });
         $this->renderTemplate($exception, __DIR__ . '/assets/BlueScreen/content.phtml');
         $contentId = $_SERVER['HTTP_X_TRACY_AJAX'];
         $_SESSION['_tracy']['bluescreen'][$contentId] = ['content' => ob_get_clean(), 'dumps' => Dumper::fetchLiveData(), 'time' => time()];
     } else {
         $this->renderTemplate($exception, __DIR__ . '/assets/BlueScreen/page.phtml');
     }
 }
Example #2
0
 *  - but more importantly it will work for search engines. Then we initialise the widget and hide the now
 * useless pagination links at the bottom of the page.
 */
require_once __DIR__ . '/helpers.php';
$pages = 15;
$pageSize = 40;
$db = new Db($pages, $pageSize);
$page = isset($_GET['p']) ? (int) $_GET['p'] : 1;
try {
    $db->setCurrentPage($page);
} catch (RangeException $e) {
    header('Location: ' . $_SERVER['PHP_SELF']);
    exit;
}
$items = $db->getItemsAtPage();
if (Helpers::isAjax()) {
    Helpers::sendJson(['items' => $items]);
}
?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>Nittro Paginator widget example</title>

        <script type="application/json" id="nittro-params">
            {
                "basePath": "/examples",
                "page": {
                    "whitelistLinks": true
                }
Example #3
0
 /**
  * Renders debug bar assets.
  * @return bool
  */
 public function dispatchAssets()
 {
     $asset = isset($_GET['_tracy_bar']) ? $_GET['_tracy_bar'] : NULL;
     if ($asset === 'js') {
         header('Content-Type: text/javascript');
         header('Cache-Control: max-age=864000');
         header_remove('Pragma');
         header_remove('Set-Cookie');
         $this->renderAssets();
         return TRUE;
     }
     $this->useSession = session_status() === PHP_SESSION_ACTIVE;
     if ($this->useSession && Helpers::isAjax()) {
         header('X-Tracy-Ajax: 1');
         // session must be already locked
     }
     if ($this->useSession && preg_match('#^content(-ajax)?.(\\w+)$#', $asset, $m)) {
         $session =& $_SESSION['_tracy']['bar'][$m[2] . $m[1]];
         header('Content-Type: text/javascript');
         header('Cache-Control: max-age=60');
         header_remove('Set-Cookie');
         if (!$m[1]) {
             $this->renderAssets();
         }
         if ($session) {
             $method = $m[1] ? 'loadAjax' : 'init';
             echo "Tracy.Debug.{$method}(", json_encode($session['content']), ', ', json_encode($session['dumps']), ');';
             $session = NULL;
         }
         $session =& $_SESSION['_tracy']['bluescreen'][$m[2]];
         if ($session) {
             echo "Tracy.BlueScreen.loadAjax(", json_encode($session['content']), ', ', json_encode($session['dumps']), ');';
             $session = NULL;
         }
         return TRUE;
     }
 }
Example #4
0
 /**
  * Renders debug bar content.
  * @return bool
  */
 public function dispatchContent()
 {
     $this->dispatched = TRUE;
     if (Helpers::isAjax()) {
         header('X-Tracy-Ajax: 1');
         // session must be already locked
     }
     if (preg_match('#^content(-ajax)?.(\\w+)$#', isset($_GET['_tracy_bar']) ? $_GET['_tracy_bar'] : '', $m)) {
         $session =& $_SESSION['_tracy']['bar'][$m[2] . $m[1]];
         header('Content-Type: text/javascript');
         header('Cache-Control: max-age=60');
         header_remove('Set-Cookie');
         if ($session) {
             $method = $m[1] ? 'loadAjax' : 'init';
             echo "Tracy.Debug.{$method}(", json_encode($session['content']), ', ', json_encode($session['dumps']), ');';
             $session = NULL;
         }
         $session =& $_SESSION['_tracy']['bluescreen'][$m[2]];
         if ($session) {
             echo "Tracy.BlueScreen.loadAjax(", json_encode($session['content']), ', ', json_encode($session['dumps']), ');';
             $session = NULL;
         }
         return TRUE;
     }
 }