All pastes #2947090 Raw Edit

rep2 api eeeor fix

public unlisted diff v1 · immutable
#2947090 ·published 2015-03-02 18:36 UTC
rendered paste body
--- D:/Projects/p2-php/lib/ThreadRead.php	Mon Mar 02 11:10:25 2015+++ D:/Projects/p2-php/ThreadRead.php	Tue Mar 03 03:28:24 2015@@ -130,7 +130,7 @@                         $this->diedat = true;                         return false;                     }-               }+                }                  include $_conf['sid2chapi_php'];                 $this->_downloadDat2chAPI($AppKey,$HMKey,$SID2chAPI,$this->length);@@ -179,7 +179,7 @@         $message = '/v1/'.$serverName[0].'/'.$this->bbs.'/'.$this->key.$sid.$AppKey;         $HB = hash_hmac("sha256", $message, $HMKey); -        $headers = "User-Agent: Mozilla/3.0 (compatible; JaneStyle/3.80..)\r\n";+        $headers = "User-Agent: Mozilla/3.0 (compatible; JaneStyle/3.80β)\r\n";         $headers .= "Connection: close\r\n";         $headers .= "Content-Type: application/x-www-form-urlencoded\r\n";         @@ -207,6 +207,7 @@         $http = array(             'method' => 'POST',             'header' => $headers,+            'ignore_errors'=> true,             'content' => http_build_query($post_values),         );         @@ -247,6 +248,31 @@                         fclose($fp);                         return false;                     }+                    //1行目を少し切り出す+                    $firstmsg = substr($body, 0, 50);+                    if(strstr($firstmsg, 'ng')) {+                        //ngで始まってたらapiのエラー+                        fclose($fp);+                        if (strstr($firstmsg, "incorrect uid length")) {+                            //sidが無効になった可能性。もう一回認証する。+                            if (!function_exists('authenticate_2chapi')) {+                                include P2_LIB_DIR . '/auth2chapi.inc.php';+                            }+                            unset($sid);+                            $sid = authenticate_2chapi($AppKey,$HMKey);+                            if (!$sid) {+                                $this->getdat_error_msg_ht .= "<p>rep2 error: API経由でのスレッド取得に失敗しました。".trim($firstmsg)."</p>";+                                $this->diedat = true;+                                return false;+                            }+                            return $this->_downloadDat2chAPI($AppKey,$HMKey,$sid,from_bytes);+                        } else {+                            $this->getdat_error_msg_ht .= "<p>rep2 error: API経由でのスレッド取得に失敗しました。".trim($firstmsg)."</p>";+                            $this->diedat = true;+                            return false;+                        }+                    }+                    unset($firstmsg);                      // 末尾の改行であぼーんチェック                     if (!$zero_read) {@@ -1007,6 +1033,9 @@                     $reason = 'kakohtml';                 }             }+        } elseif ($code == '404') {+            //APIの為404だったら過去ログと決めつけとく(fix Here)+            $reason = 'datochi';         }          $read_url = "http://{$this->host}/test/read.cgi/{$this->bbs}/{$this->key}/";--- D:/Projects/p2-php/lib/auth2chapi.inc.php	Tue Mar 03 02:44:11 2015+++ D:/Projects/p2-php/auth2chapi.inc.php	Tue Mar 03 02:43:49 2015@@ -35,7 +35,7 @@             'ignore_errors' => true,             'method' => 'POST',             'header' => implode("\r\n", array(-                'User-Agent: ',+                'User-Agent: Monazilla/1.3',                 'X-2ch-UA: JaneStyle/3.80',                 'Content-Type: application/x-www-form-urlencoded',             )),@@ -45,15 +45,24 @@         $response = '';         $response = file_get_contents($url, false, stream_context_create($options));         +        unlink($_conf['sid2chapi_php']);+                 if (strpos($response, ':') != false)         {             $sid = explode(':', $response);             +            //P2Util::pushInfoHtml($response);+            +            if($sid[0]!='SESSION-ID=Monazilla/1.00') {+                P2Util::pushInfoHtml("<p>p2 Error: 2ch API のSessionIDを取得出来ませんでした。");+                return '';+            }+                         $cont = sprintf('<?php $SID2chAPI = %s;', var_export($sid[1], true));-    		if (false === file_put_contents($_conf['sid2chapi_php'], $cont, LOCK_EX)) {-        		P2Util::pushInfoHtml("<p>p2 Error: {$_conf['sid2chapi_php']} を保存できませんでした。ログイン登録失敗。</p>");-        		return '';-    		}+            if (false === file_put_contents($_conf['sid2chapi_php'], $cont, LOCK_EX)) {+                P2Util::pushInfoHtml("<p>p2 Error: {$_conf['sid2chapi_php']} を保存できませんでした。ログイン登録失敗。</p>");+                return '';+            }                          return $sid[1];         }