Browse code

Amélioration gestion pb réseau sur post

bruno.spyckerelle authored on 16/10/2016 15:48:20
Showing 2 changed files
... ...
@@ -320,7 +320,7 @@ function BoardPost(board, msg) {
320 320
                 html: true,
321 321
                 placement: 'top',
322 322
                 trigger: 'focus',
323
-                content: error
323
+                content: xhr.responseText
324 324
             }).popover('show');
325 325
         } else {
326 326
             BoardPostResult(board, xhr);
... ...
@@ -5,9 +5,7 @@
5 5
   curl_setopt($ch, CURLOPT_URL, $_REQUEST['posturl']);
6 6
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
7 7
   curl_setopt($ch, CURLOPT_HEADER, true);
8
-  // curl_setopt($ch, CURLINFO_HEADER_OUT, true);
9
-
10
-  //  error_reporting(0);
8
+  curl_setopt($ch, CURLINFO_HEADER_OUT, true);
11 9
 
12 10
   if (isset($_REQUEST['ua'])) {
13 11
     $ua = $_REQUEST['ua'];
... ...
@@ -15,8 +13,7 @@
15 13
   else {
16 14
     $ua = "olcc-me/" . $VERSION;
17 15
   }
18
-  // $message = $_SERVER['QUERY_STRING'];
19
-  // $message = substr($message, strpos($message, 'postdata=')+9);
16
+
20 17
   $message = $_REQUEST['postdata'];
21 18
   $message = str_replace(array('#{plus}#', '#{amp}#', '#{dcomma}#', '#{percent}#'), array(urlencode('+'), urlencode('&'), '%3B', '%25'), $message);
22 19
   $referer = $_REQUEST['posturl'];
... ...
@@ -30,7 +27,7 @@
30 27
   curl_setopt($ch, CURLOPT_HTTPHEADER, $rheaders);
31 28
   curl_setopt($ch, CURLOPT_USERAGENT, $ua);
32 29
   if (get_magic_quotes_gpc()) {
33
-    curl_setopt($ch, CURLOPT_POSTFIELDS, stripslashes($message)); // stripslashes(utf8_encode($message)));
30
+    curl_setopt($ch, CURLOPT_POSTFIELDS, stripslashes($message));
34 31
   }
35 32
   else {
36 33
     curl_setopt($ch, CURLOPT_POSTFIELDS, $message);
... ...
@@ -39,33 +36,34 @@
39 36
     curl_setopt($ch, CURLOPT_COOKIE, $_REQUEST['cookie']);
40 37
   }
41 38
   $res = curl_exec($ch);
42
-  // error_log( "[olcc] " . $res); // curl_getinfo($ch, CURLINFO_HEADER_OUT));
43
-  // var_dump(curl_getinfo($ch));
44
-  // echo "UA=$ua<br />referer=$referer<br />cookie=".$_REQUEST['cookie']."<br />Data=".stripslashes(utf8_encode($message))."<br />Query_string=".$_SERVER['QUERY_STRING']."<br />";
45 39
 
46
-    echo('({');
47 40
   if ($res === false) {
48
-    echo( "'error':'". curl_error($ch) ."'," );
49
-  }
50
-  else {
51
-    $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
52
-    $headers = preg_split("\n", substr($res, 0, $header_size));
53
-    foreach ($headers as $header) {
54
-      if (strpos($header, ':') > 0) {
55
-        list($name, $val) = preg_split(":", $header);
56
-        $tval = trim($val);
57
-        if (!empty($tval)) {
58
-          echo( "'" . trim(str_replace("-", "", $name)) . "':'" . addslashes($tval) . "'," );
41
+      if(curl_errno($ch) == CURLE_OPERATION_TIMEOUTED) {
42
+          $http_code = 408;
43
+      } else {
44
+          $http_code = 500;
45
+      }
46
+      http_response_code($http_code);
47
+      echo( "Erreur ".$http_code." : ". curl_error($ch));
48
+  } else {
49
+      echo('({');
50
+      $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
51
+      $headers = preg_split("\n", substr($res, 0, $header_size));
52
+      foreach ($headers as $header) {
53
+        if (strpos($header, ':') > 0) {
54
+          list($name, $val) = preg_split(":", $header);
55
+          $tval = trim($val);
56
+          if (!empty($tval)) {
57
+            echo("'" . trim(str_replace("-", "", $name)) . "':'" . addslashes($tval) . "',");
58
+          }
59 59
         }
60 60
       }
61
-    }
62 61
       $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
63 62
       http_response_code($http_code);
64
-    echo( "'referer':\"" . $referer . "\"," );
65
-    echo( "'httpcode':" . $http_code . "," );
66
-    //echo "UA=$ua<br />referer=$referer<br />cookie=".$_REQUEST['cookie']."<br />Data=".$message."<br />Query_string=".$_SERVER['QUERY_STRING']."<br />";
67
-    // echo $res;
63
+      echo("'referer':\"" . $referer . "\",");
64
+      echo("'httpcode':" . $http_code . ",");
65
+      echo("'result':\"".str_replace("\n","\\n",addslashes(substr($res, $header_size, strlen($res))))."\"");
66
+
67
+      echo('})');
68 68
   }
69
-  echo("'result':\"".str_replace("\n","\\n",addslashes(substr($res, $header_size, strlen($res))))."\"");
70
-  echo('})');
71
-?>
69
+