Browse Source

Méthode de test d'un appel AJAX

Simounet 5 years ago
parent
commit
9500f0b797
2 changed files with 9 additions and 3 deletions
  1. 7 0
      Functions.class.php
  2. 2 3
      action.php

+ 7 - 0
Functions.class.php

@@ -366,5 +366,12 @@ class Functions
         foreach($chunks as $chunk) $languages []= substr($chunk, 0, 2);
         return array_unique($languages);
     }
+
+    /**
+    * @return boolean
+    */
+    public static function isAjaxCall() {
+        return !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
+    }
 }
 ?>

+ 2 - 3
action.php

@@ -11,7 +11,6 @@ require_once("common.php");
 
 ///@TODO: déplacer dans common.php?
 $commandLine = 'cli'==php_sapi_name();
-$ajaxCall = !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
 
 if ($commandLine) {
     $action = 'commandLine';
@@ -77,7 +76,7 @@ switch ($action){
         if(isset($_['feed']))$whereClause['feed'] = $_['feed'];
         if(isset($_['last-event-id']))$whereClause['id'] = '<= ' . $_['last-event-id'];
         $eventManager->change(array('unread'=>'0'),$whereClause);
-        if(!$ajaxCall){
+        if(!Functions::isAjaxCall()){
             header('location: ./index.php');
         }
     break;
@@ -93,7 +92,7 @@ switch ($action){
             $eventManager->change(array('unread'=>'0'),$whereClause);
         }
 
-        if (!$ajaxCall){
+        if (!Functions::isAjaxCall()){
             header('location: ./index.php');
         }