Mercurial > defr > DualBlog
comparison includes/akismet.class.php @ 89:e37ef9a81737 tip
Merge
| author | Franck Deroche <franck@defr.org> |
|---|---|
| date | Thu, 13 Dec 2018 00:55:42 +0100 |
| parents | efb93800fe10 |
| children |
comparison
equal
deleted
inserted
replaced
| 88:1f2410012dbc | 89:e37ef9a81737 |
|---|---|
| 122 var $blogUrl; | 122 var $blogUrl; |
| 123 var $errors = array(); | 123 var $errors = array(); |
| 124 | 124 |
| 125 | 125 |
| 126 // Constructor | 126 // Constructor |
| 127 function AkismetHttpClient($host, $blogUrl, $apiKey, $port = 80) { | 127 function __construct($host, $blogUrl, $apiKey, $port = 80) { |
| 128 $this->host = $host; | 128 $this->host = $apiKey . '.' . $host; |
| 129 $this->port = $port; | 129 $this->port = $port; |
| 130 $this->blogUrl = $blogUrl; | 130 $this->blogUrl = $blogUrl; |
| 131 $this->apiKey = $apiKey; | 131 $this->apiKey = $apiKey; |
| 132 } | 132 } |
| 133 | 133 |
| 137 $this->_connect(); | 137 $this->_connect(); |
| 138 | 138 |
| 139 if($this->con && !$this->isError(AKISMET_SERVER_NOT_FOUND)) { | 139 if($this->con && !$this->isError(AKISMET_SERVER_NOT_FOUND)) { |
| 140 $request = | 140 $request = |
| 141 strToUpper($type)." /{$this->akismetVersion}/$path HTTP/1.1\r\n" . | 141 strToUpper($type)." /{$this->akismetVersion}/$path HTTP/1.1\r\n" . |
| 142 "Host: ".((!empty($this->apiKey)) ? $this->apiKey."." : null)."{$this->host}\r\n" . | 142 "Host: {$this->host}\r\n" . |
| 143 "Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n" . | 143 "Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n" . |
| 144 "Content-Length: ".strlen($request)."\r\n" . | 144 "Content-Length: ".strlen($request)."\r\n" . |
| 145 "User-Agent: Akismet PHP4 Class\r\n" . | 145 "User-Agent: Akismet PHP4 Class\r\n" . |
| 146 "\r\n" . | 146 "\r\n" . |
| 147 $request | 147 $request |
| 164 } | 164 } |
| 165 | 165 |
| 166 | 166 |
| 167 // Connect to the Akismet server and store that connection in the instance variable $con | 167 // Connect to the Akismet server and store that connection in the instance variable $con |
| 168 function _connect() { | 168 function _connect() { |
| 169 if(!($this->con = @fsockopen($this->host, $this->port))) { | 169 if(!($this->con = @fsockopen('ssl://' . $this->host, $this->port, $errno, $errstr))) { |
| 170 $this->setError(AKISMET_SERVER_NOT_FOUND, "Could not connect to akismet server."); | 170 $this->setError(AKISMET_SERVER_NOT_FOUND, "Could not connect to akismet server: " . $errstr); |
| 171 } | 171 } |
| 172 } | 172 } |
| 173 | 173 |
| 174 | 174 |
| 175 // Close the connection to the Akismet server | 175 // Close the connection to the Akismet server |
| 185 | 185 |
| 186 | 186 |
| 187 // The controlling class. This is the ONLY class the user should instantiate in | 187 // The controlling class. This is the ONLY class the user should instantiate in |
| 188 // order to use the Akismet service! | 188 // order to use the Akismet service! |
| 189 class Akismet extends AkismetObject { | 189 class Akismet extends AkismetObject { |
| 190 var $apiPort = 80; | 190 var $apiPort = 443; |
| 191 var $akismetServer = 'rest.akismet.com'; | 191 var $akismetServer = 'rest.akismet.com'; |
| 192 var $akismetVersion = '1.1'; | 192 var $akismetVersion = '1.1'; |
| 193 var $http; | 193 var $http; |
| 194 | 194 |
| 195 var $ignore = array( | 195 var $ignore = array( |
| 221 * @param String $blogUrl The URL to your own blog | 221 * @param String $blogUrl The URL to your own blog |
| 222 * @param String $apiKey Your wordpress API key | 222 * @param String $apiKey Your wordpress API key |
| 223 * @param String[] $comment A formatted comment array to be examined by the Akismet service | 223 * @param String[] $comment A formatted comment array to be examined by the Akismet service |
| 224 * @return Akismet | 224 * @return Akismet |
| 225 */ | 225 */ |
| 226 function Akismet($blogUrl, $apiKey, $comment = array()) { | 226 function __construct($blogUrl, $apiKey, $comment = array()) { |
| 227 $this->blogUrl = $blogUrl; | 227 $this->blogUrl = $blogUrl; |
| 228 $this->apiKey = $apiKey; | 228 $this->apiKey = $apiKey; |
| 229 $this->setComment($comment); | 229 $this->setComment($comment); |
| 230 | 230 |
| 231 // Connect to the Akismet server and populate errors if they exist | 231 // Connect to the Akismet server and populate errors if they exist |
| 232 $this->http = new AkismetHttpClient($this->akismetServer, $blogUrl, $apiKey); | 232 $this->http = new AkismetHttpClient($this->akismetServer, $blogUrl, $apiKey, $this->apiPort); |
| 233 if($this->http->errorsExist()) { | 233 if($this->http->errorsExist()) { |
| 234 $this->errors = array_merge($this->errors, $this->http->getErrors()); | 234 $this->errors = array_merge($this->errors, $this->http->getErrors()); |
| 235 } | 235 } |
| 236 | 236 |
| 237 // Check if the API key is valid | 237 // Check if the API key is valid |
