├── .gitignore
├── README.markdown
├── pom.xml
└── src
├── main
└── php
│ └── net
│ └── achingbrain
│ └── Akismet.class.php
├── site
├── doxygen
│ └── doxygen.config
└── phpdoc
│ └── phpdoc.config
└── test
└── php
└── net
└── achingbrain
└── AkismetTest.php
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | *.ipr
3 | *.iws
4 | target
5 | .DS_Store
6 |
7 |
--------------------------------------------------------------------------------
/README.markdown:
--------------------------------------------------------------------------------
1 | # Introduction
2 |
3 | This is a simple little PHP5 class that enables you use the Akismet anti-spam service in your PHP5 application.
4 |
5 | # Download
6 |
7 | Check out the git repository:
8 |
9 | git clone git@github.com:achingbrain/php5-akismet.git
10 |
11 | # Installation
12 |
13 | Once you have cloned the repo (see Download, above) copy the file at src/main/php/net/achingbrain/Akismet.class.php to somewhere accessible to your scripts. Use include or a derivative to import it into your script.
14 |
15 | Alternatively if you are running a version of PHP greater than 5.3, grab the [phar file](http://achingbrain.github.com/maven-repo/releases/net/achingbrain/php5-akismet/0.5/php5-akismet-0.5.phar) and use the following code:
16 |
17 |
20 |
21 | # Documentation
22 |
23 | See the [PHPDocs](http://achingbrain.github.com/maven-repo/documentation/php5-akismet/apidocs).
24 |
25 | # Usage
26 |
27 | Before you can use Akismet, you need a WordPress API key (they are free and getting one takes about five minutes). Once you have one, take a look at the code below:
28 |
29 | $WordPressAPIKey = 'aoeu1aoue';
30 | $MyBlogURL = 'http://www.example.com/blog/';
31 |
32 | $akismet = new Akismet($MyBlogURL ,$WordPressAPIKey);
33 | $akismet->setCommentAuthor($name);
34 | $akismet->setCommentAuthorEmail($email);
35 | $akismet->setCommentAuthorURL($url);
36 | $akismet->setCommentContent($comment);
37 | $akismet->setPermalink('http://www.example.com/blog/alex/someurl/');
38 |
39 | if($akismet->isCommentSpam())
40 | // store the comment but mark it as spam (in case of a mis-diagnosis)
41 | else
42 | // store the comment normally
43 |
44 | That's just about it. In the event that the filter wrongly tags messages, you can at a later date create a new object and populate it from your database, overriding fields where necessary and then use the following two methods to train it:
45 |
46 | $akismet->submitSpam();
47 |
48 | and
49 |
50 | $akismet->submitHam();
51 |
52 | to submit mis-diagnosed spam and ham, which improves the system for everybody. See the included documentation for a complete run-down of all available methods.
53 |
54 | ## Changelog
55 |
56 | ### Version 0.5
57 |
58 | * Deployed to GitHub instead of achingbrain.net for better collaboration in future
59 | * Converted project to use Maven for unit testing and documentation generation
60 | * Unit tests & documentaiton
61 | * Allowed overriding of user agent when submitting ham/spam (thanks Steven)
62 |
63 | ### Version 0.4
64 |
65 | * Performance – changed HTTP version from 1.1 to 1.0 (with thanks to Jan De Poorter).
66 | * Performance – No longer issues a separate HTTP request to check validity of the API key with every instantiation.
67 | * Added a new public method 'isKeyValid' to manually check validity of the API key passed to the constructor.
68 | * The method 'isCommentSpam' (rather than the constructor) will now throw an exception if the API key is invalid.
69 | * Tidied up internal structure a bit.
70 |
71 | ### Version 0.3
72 |
73 | Internal testing version
74 |
75 | ### Version 0.2
76 |
77 | Initial release
78 |
79 | ### Version 0.1
80 |
81 | Internal testing version
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 | net.achingbrain
5 | php5-akismet
6 | php
7 | PHP5 Akismet
8 | 0.5
9 | https://github.com/achingbrain/php5-akismet
10 |
11 |
12 | scm:git://github.com/achingbrain/php5-akismet.git
13 | https://github.com/achingbrain/php5-akismet
14 |
15 |
16 |
17 | GitHub
18 | https://github.com/achingbrain/php5-akismet/issues
19 |
20 |
21 |
22 |
23 |
24 | Alex Potsides
25 | http://www.achingbrain.net
26 |
27 |
28 |
29 |
30 |
31 | BSD License
32 | http://www.opensource.org/licenses/bsd-license.php
33 | repo
34 |
35 |
36 |
37 |
38 |
39 | php5-akismet-releases
40 | file:///Users/alex/Sites/maven-repo/releases
41 |
42 |
43 | false
44 | php5-akismet-snapshots
45 | file:///Users/alex/Sites/maven-repo/snapshots
46 |
47 |
48 | website
49 | file:///Users/alex/Sites/maven-repo/documentation/php5-akismet
50 |
51 |
52 |
53 |
54 |
55 | release-repos.php-maven.org
56 | PHP-Maven Release Repository
57 | http://repos.php-maven.org/releases
58 |
59 | true
60 |
61 |
62 |
63 | snapshot-repos.php-maven.org
64 | PHP-Maven Snapshot Repository
65 | http://repos.php-maven.org/snapshots
66 |
67 | false
68 |
69 |
70 | true
71 |
72 |
73 |
74 |
75 |
76 | release-repos.php-maven.org
77 | PHP-Maven Release Repository
78 | http://repos.php-maven.org/releases
79 |
80 | true
81 |
82 |
83 |
84 | snapshot-repos.php-maven.org
85 | PHP-Maven Snapshot Repository
86 | http://repos.php-maven.org/snapshots
87 |
88 | false
89 |
90 |
91 | true
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 | ${basedir}/src/main/php
100 |
101 |
102 |
103 |
104 |
105 | ${basedir}/src/test/php
106 |
107 |
108 |
109 |
110 |
111 | org.phpmaven
112 | maven-php-plugin
113 | ${maven.php.plugin.version}
114 | true
115 |
116 |
117 |
118 | org.apache.maven.plugins
119 | maven-site-plugin
120 | ${maven.site.plugin.version}
121 | true
122 |
123 |
124 |
125 | org.phpmaven
126 | maven-php-plugin
127 | ${maven.php.plugin.version}
128 |
129 | /usr/local/phpdoc/phpdoc
130 |
131 |
132 |
133 |
134 | phpdocumentor
135 |
136 |
137 |
138 |
139 |
140 | org.apache.maven.plugins
141 | maven-surefire-report-plugin
142 | ${maven.surefire.plugin.version}
143 |
144 |
145 |
146 | report-only
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 | de.phpunit
161 | PHPUnit
162 | ${phpunit.version}
163 | phar
164 | test
165 |
166 |
167 |
168 |
169 | UTF-8
170 |
171 | 2.10
172 | 3.0
173 | 2.0-SNAPSHOT
174 |
175 | 3.4.15
176 |
177 |
178 |
--------------------------------------------------------------------------------
/src/main/php/net/achingbrain/Akismet.class.php:
--------------------------------------------------------------------------------
1 |
33 | * $akismet = new Akismet('http://www.example.com/blog/', 'aoeu1aoue');
34 | * $akismet->setCommentAuthor($name);
35 | * $akismet->setCommentAuthorEmail($email);
36 | * $akismet->setCommentAuthorURL($url);
37 | * $akismet->setCommentContent($comment);
38 | * $akismet->setPermalink('http://www.example.com/blog/alex/someurl/');
39 | *
40 | * if($akismet->isCommentSpam())
41 | * // store the comment but mark it as spam (in case of a mis-diagnosis)
42 | * else
43 | * // store the comment normally
44 | *
45 | *
46 | * Optionally you may wish to check if your WordPress API key is valid as in the example below.
47 | *
48 | *
49 | * $akismet = new Akismet('http://www.example.com/blog/', 'aoeu1aoue');
50 | *
51 | * if($akismet->isKeyValid()) {
52 | * // api key is okay
53 | * } else {
54 | * // api key is invalid
55 | * }
56 | *
57 | *
58 | * @package akismet
59 | * @name Akismet
60 | * @version 0.5
61 | * @author Alex Potsides
62 | * @link http://www.achingbrain.net/
63 | */
64 | class Akismet {
65 | private $version = '0.5';
66 | private $wordPressAPIKey;
67 | private $blogURL;
68 | private $comment;
69 | private $apiPort;
70 | private $akismetServer;
71 | private $akismetVersion;
72 | private $requestFactory;
73 |
74 | // This prevents some potentially sensitive information from being sent accross the wire.
75 | private $ignore = array('HTTP_COOKIE',
76 | 'HTTP_X_FORWARDED_FOR',
77 | 'HTTP_X_FORWARDED_HOST',
78 | 'HTTP_MAX_FORWARDS',
79 | 'HTTP_X_FORWARDED_SERVER',
80 | 'REDIRECT_STATUS',
81 | 'SERVER_PORT',
82 | 'PATH',
83 | 'DOCUMENT_ROOT',
84 | 'SERVER_ADMIN',
85 | 'QUERY_STRING',
86 | 'PHP_SELF' );
87 |
88 | /**
89 | * @param string $blogURL The URL of your blog.
90 | * @param string $wordPressAPIKey WordPress API key.
91 | */
92 | public function __construct($blogURL, $wordPressAPIKey) {
93 | $this->blogURL = $blogURL;
94 | $this->wordPressAPIKey = $wordPressAPIKey;
95 |
96 | // Set some default values
97 | $this->apiPort = 80;
98 | $this->akismetServer = 'rest.akismet.com';
99 | $this->akismetVersion = '1.1';
100 | $this->requestFactory = new SocketWriteReadFactory();
101 |
102 | // Start to populate the comment data
103 | $this->comment['blog'] = $blogURL;
104 |
105 | if(isset($_SERVER['HTTP_USER_AGENT'])) {
106 | $this->comment['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
107 | }
108 |
109 | if(isset($_SERVER['HTTP_REFERER'])) {
110 | $this->comment['referrer'] = $_SERVER['HTTP_REFERER'];
111 | }
112 |
113 | /*
114 | * This is necessary if the server PHP5 is running on has been set up to run PHP4 and
115 | * PHP5 concurently and is actually running through a separate proxy al a these instructions:
116 | * http://www.schlitt.info/applications/blog/archives/83_How_to_run_PHP4_and_PHP_5_parallel.html
117 | * and http://wiki.coggeshall.org/37.html
118 | * Otherwise the user_ip appears as the IP address of the PHP4 server passing the requests to the
119 | * PHP5 one...
120 | */
121 | if(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] != getenv('SERVER_ADDR')) {
122 | $this->comment['user_ip'] = $_SERVER['REMOTE_ADDR'];
123 | } else {
124 | $this->comment['user_ip'] = getenv('HTTP_X_FORWARDED_FOR');
125 | }
126 | }
127 |
128 | /**
129 | * Makes a request to the Akismet service to see if the API key passed to the constructor is valid.
130 | *
131 | * Use this method if you suspect your API key is invalid.
132 | *
133 | * @return bool True is if the key is valid, false if not.
134 | */
135 | public function isKeyValid() {
136 | // Check to see if the key is valid
137 | $response = $this->sendRequest('key=' . $this->wordPressAPIKey . '&blog=' . $this->blogURL, $this->akismetServer, '/' . $this->akismetVersion . '/verify-key');
138 | return $response[1] == 'valid';
139 | }
140 |
141 | // makes a request to the Akismet service
142 | private function sendRequest($request, $host, $path) {
143 | $http_request = "POST " . $path . " HTTP/1.0\r\n";
144 | $http_request .= "Host: " . $host . "\r\n";
145 | $http_request .= "Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n";
146 | $http_request .= "Content-Length: " . strlen($request) . "\r\n";
147 | $http_request .= "User-Agent: Akismet PHP5 Class " . $this->version . " | Akismet/1.11\r\n";
148 | $http_request .= "\r\n";
149 | $http_request .= $request;
150 |
151 | $requestSender = $this->requestFactory->createRequestSender();
152 | $response = $requestSender->send($host, $this->apiPort, $http_request);
153 |
154 | return explode("\r\n\r\n", $response, 2);
155 | }
156 |
157 | // Formats the data for transmission
158 | private function getQueryString() {
159 | foreach($_SERVER as $key => $value) {
160 | if(!in_array($key, $this->ignore)) {
161 | if($key == 'REMOTE_ADDR') {
162 | $this->comment[$key] = $this->comment['user_ip'];
163 | } else {
164 | $this->comment[$key] = $value;
165 | }
166 | }
167 | }
168 |
169 | $query_string = '';
170 |
171 | foreach($this->comment as $key => $data) {
172 | if(!is_array($data)) {
173 | $query_string .= $key . '=' . urlencode(stripslashes($data)) . '&';
174 | }
175 | }
176 |
177 | return $query_string;
178 | }
179 |
180 | /**
181 | * Tests for spam.
182 | *
183 | * Uses the web service provided by {@link http://www.akismet.com Akismet} to see whether or not the submitted comment is spam. Returns a boolean value.
184 | *
185 | * @return bool True if the comment is spam, false if not
186 | * @throws Will throw an exception if the API key passed to the constructor is invalid.
187 | */
188 | public function isCommentSpam() {
189 | $response = $this->sendRequest($this->getQueryString(), $this->wordPressAPIKey . '.rest.akismet.com', '/' . $this->akismetVersion . '/comment-check');
190 |
191 | if($response[1] == 'invalid' && !$this->isKeyValid()) {
192 | throw new exception('The Wordpress API key passed to the Akismet constructor is invalid. Please obtain a valid one from http://wordpress.com/api-keys/');
193 | }
194 |
195 | return ($response[1] == 'true');
196 | }
197 |
198 | /**
199 | * Submit spam that is incorrectly tagged as ham.
200 | *
201 | * Using this function will make you a good citizen as it helps Akismet to learn from its mistakes. This will improve the service for everybody.
202 | */
203 | public function submitSpam() {
204 | $this->sendRequest($this->getQueryString(), $this->wordPressAPIKey . '.' . $this->akismetServer, '/' . $this->akismetVersion . '/submit-spam');
205 | }
206 |
207 | /**
208 | * Submit ham that is incorrectly tagged as spam.
209 | *
210 | * Using this function will make you a good citizen as it helps Akismet to learn from its mistakes. This will improve the service for everybody.
211 | */
212 | public function submitHam() {
213 | $this->sendRequest($this->getQueryString(), $this->wordPressAPIKey . '.' . $this->akismetServer, '/' . $this->akismetVersion . '/submit-ham');
214 | }
215 |
216 | /**
217 | * To override the user IP address when submitting spam/ham later on
218 | *
219 | * @param string $userip An IP address. Optional.
220 | */
221 | public function setUserIP($userip) {
222 | $this->comment['user_ip'] = $userip;
223 | }
224 |
225 | /**
226 | * To override the referring page when submitting spam/ham later on
227 | *
228 | * @param string $referrer The referring page. Optional.
229 | */
230 | public function setReferrer($referrer) {
231 | $this->comment['referrer'] = $referrer;
232 | }
233 |
234 | /**
235 | * A permanent URL referencing the blog post the comment was submitted to.
236 | *
237 | * @param string $permalink The URL. Optional.
238 | */
239 | public function setPermalink($permalink) {
240 | $this->comment['permalink'] = $permalink;
241 | }
242 |
243 | /**
244 | * The type of comment being submitted.
245 | *
246 | * May be blank, comment, trackback, pingback, or a made up value like "registration" or "wiki".
247 | */
248 | public function setCommentType($commentType) {
249 | $this->comment['comment_type'] = $commentType;
250 | }
251 |
252 | /**
253 | * The name that the author submitted with the comment.
254 | */
255 | public function setCommentAuthor($commentAuthor) {
256 | $this->comment['comment_author'] = $commentAuthor;
257 | }
258 |
259 | /**
260 | * The email address that the author submitted with the comment.
261 | *
262 | * The address is assumed to be valid.
263 | */
264 | public function setCommentAuthorEmail($authorEmail) {
265 | $this->comment['comment_author_email'] = $authorEmail;
266 | }
267 |
268 | /**
269 | * The URL that the author submitted with the comment.
270 | */
271 | public function setCommentAuthorURL($authorURL) {
272 | $this->comment['comment_author_url'] = $authorURL;
273 | }
274 |
275 | /**
276 | * The comment's body text.
277 | */
278 | public function setCommentContent($commentBody) {
279 | $this->comment['comment_content'] = $commentBody;
280 | }
281 |
282 | /**
283 | * Lets you override the user agent used to submit the comment.
284 | * you may wish to do this when submitting ham/spam.
285 | * Defaults to $_SERVER['HTTP_USER_AGENT']
286 | */
287 | public function setCommentUserAgent($userAgent) {
288 | $this->comment['user_agent'] = $userAgent;
289 | }
290 |
291 | /**
292 | * Defaults to 80
293 | */
294 | public function setAPIPort($apiPort) {
295 | $this->apiPort = $apiPort;
296 | }
297 |
298 | /**
299 | * Defaults to rest.akismet.com
300 | */
301 | public function setAkismetServer($akismetServer) {
302 | $this->akismetServer = $akismetServer;
303 | }
304 |
305 | /**
306 | * Defaults to '1.1'
307 | *
308 | * @param string $akismetVersion
309 | */
310 | public function setAkismetVersion($akismetVersion) {
311 | $this->akismetVersion = $akismetVersion;
312 | }
313 |
314 | /**
315 | * Used by unit tests to mock transport layer
316 | *
317 | * @param AkismetRequestFactory $requestFactory
318 | */
319 | public function setRequestFactory($requestFactory) {
320 | $this->requestFactory = $requestFactory;
321 | }
322 | }
323 |
324 | /**
325 | * Used internally by Akismet
326 | *
327 | * This class is used by Akismet to do the actual sending and receiving of data. It opens a connection to a remote host, sends some data and the reads the response and makes it available to the calling program.
328 | *
329 | * The code that makes up this class originates in the Akismet WordPress plugin, which is {@link http://akismet.com/download/ available on the Akismet website}.
330 | *
331 | * N.B. It is not necessary to call this class directly to use the Akismet class.
332 | *
333 | * @package akismet
334 | * @name SocketWriteRead
335 | * @version 0.5
336 | * @author Alex Potsides
337 | * @link http://www.achingbrain.net/
338 | */
339 | class SocketWriteRead implements AkismetRequestSender {
340 | private $response;
341 | private $errorNumber;
342 | private $errorString;
343 |
344 | public function __construct() {
345 | $this->errorNumber = 0;
346 | $this->errorString = '';
347 | }
348 |
349 | /**
350 | * Sends the data to the remote host.
351 | *
352 | * @param string $host The host to send/receive data.
353 | * @param int $port The port on the remote host.
354 | * @param string $request The data to send.
355 | * @param int $responseLength The amount of data to read. Defaults to 1160 bytes.
356 | * @throws An exception is thrown if a connection cannot be made to the remote host.
357 | * @returns The server response
358 | */
359 | public function send($host, $port, $request, $responseLength = 1160) {
360 | $response = '';
361 |
362 | $fs = fsockopen($host, $port, $this->errorNumber, $this->errorString, 3);
363 |
364 | if($this->errorNumber != 0) {
365 | throw new Exception('Error connecting to host: ' . $host . ' Error number: ' . $this->errorNumber . ' Error message: ' . $this->errorString);
366 | }
367 |
368 | if($fs !== false) {
369 | @fwrite($fs, $request);
370 |
371 | while(!feof($fs)) {
372 | $response .= fgets($fs, $responseLength);
373 | }
374 |
375 | fclose($fs);
376 | }
377 |
378 | return $response;
379 | }
380 |
381 | /**
382 | * Returns the server response text
383 | *
384 | * @return string
385 | */
386 | public function getResponse() {
387 | return $this->response;
388 | }
389 |
390 | /**
391 | * Returns the error number
392 | *
393 | * If there was no error, 0 will be returned.
394 | *
395 | * @return int
396 | */
397 | public function getErrorNumner() {
398 | return $this->errorNumber;
399 | }
400 |
401 | /**
402 | * Returns the error string
403 | *
404 | * If there was no error, an empty string will be returned.
405 | *
406 | * @return string
407 | */
408 | public function getErrorString() {
409 | return $this->errorString;
410 | }
411 | }
412 |
413 | /**
414 | * Used internally by the Akismet class and to mock the Akismet anti spam service in
415 | * the unit tests.
416 | *
417 | * N.B. It is not necessary to call this class directly to use the Akismet class.
418 | *
419 | * @package akismet
420 | * @name SocketWriteReadFactory
421 | * @version 0.5
422 | * @author Alex Potsides
423 | * @link http://www.achingbrain.net/
424 | */
425 | class SocketWriteReadFactory implements AkismetRequestFactory {
426 |
427 | public function createRequestSender() {
428 | return new SocketWriteRead();
429 | }
430 | }
431 |
432 | /**
433 | * Used internally by the Akismet class and to mock the Akismet anti spam service in
434 | * the unit tests.
435 | *
436 | * N.B. It is not necessary to implement this class to use the Akismet class.
437 | *
438 | * @package akismet
439 | * @name AkismetRequestSender
440 | * @version 0.5
441 | * @author Alex Potsides
442 | * @link http://www.achingbrain.net/
443 | */
444 | interface AkismetRequestSender {
445 |
446 | /**
447 | * Sends the data to the remote host.
448 | *
449 | * @param string $host The host to send/receive data.
450 | * @param int $port The port on the remote host.
451 | * @param string $request The data to send.
452 | * @param int $responseLength The amount of data to read. Defaults to 1160 bytes.
453 | * @throws An exception is thrown if a connection cannot be made to the remote host.
454 | * @returns The server response
455 | */
456 | public function send($host, $port, $request, $responseLength = 1160);
457 | }
458 |
459 | /**
460 | * Used internally by the Akismet class and to mock the Akismet anti spam service in
461 | * the unit tests.
462 | *
463 | * N.B. It is not necessary to implement this class to use the Akismet class.
464 | *
465 | * @package akismet
466 | * @name AkismetRequestFactory
467 | * @version 0.5
468 | * @author Alex Potsides
469 | * @link http://www.achingbrain.net/
470 | */
471 | interface AkismetRequestFactory {
472 |
473 | public function createRequestSender();
474 | }
475 |
476 | ?>
477 |
--------------------------------------------------------------------------------
/src/site/doxygen/doxygen.config:
--------------------------------------------------------------------------------
1 | ALPHABETICAL_INDEX=NO
2 | GENERATE_HTML=YES
3 | GENERATE_LATEX=NO
4 | RECURSIVE=YES
5 |
--------------------------------------------------------------------------------
/src/site/phpdoc/phpdoc.config:
--------------------------------------------------------------------------------
1 | ;; title of all the documentation
2 | ;; legal values: any string
3 | title = phpDocumentor Manual
4 |
5 | ;; parse files that start with a . like .bash_profile
6 | ;; legal values: true, false
7 | hidden = false
8 |
9 | ;; show elements marked @access private in documentation by setting this to on
10 | ;; legal values: on, off
11 | parseprivate = off
12 |
13 | ;; parse with javadoc-like description (first sentence is always the short description)
14 | ;; legal values: on, off
15 | javadocdesc = off
16 |
17 | ;; add any custom @tags separated by commas here
18 | ;; legal values: any legal tagname separated by commas.
19 | ;customtags = mytag1,mytag2
20 |
21 | ;; This is only used by the XML:DocBook/peardoc2 converter
22 | defaultcategoryname = Documentation
23 |
24 | ;; what is the main package?
25 | ;; legal values: alphanumeric string plus - and _
26 | defaultpackagename = phpDocumentor
27 |
28 | ;; output any parsing information? set to on for cron jobs
29 | ;; legal values: on
30 | ;quiet = on
31 |
32 | ;; parse a PEAR-style repository. Do not turn this on if your project does
33 | ;; not have a parent directory named "pear"
34 | ;; legal values: on/off
35 | ;pear = on
36 |
37 | ;; where should the documentation be written?
38 | ;; legal values: a legal path
39 | ;target = will generated
40 |
41 |
42 | ;; Which files should be parsed out as special documentation files, such as README,
43 | ;; INSTALL and CHANGELOG? This overrides the default files found in
44 | ;; phpDocumentor.ini (this file is not a user .ini file, but the global file)
45 | readmeinstallchangelog = README, INSTALL, FAQ, LICENSE, Release-1.4.0
46 |
47 | ;; limit output to the specified packages, even if others are parsed
48 | ;; legal values: package names separated by commas
49 | ;packageoutput = package1,package2
50 |
51 | ;; comma-separated list of files to parse
52 | ;; legal values: paths separated by commas
53 | ;filename = /path/to/file1,/path/to/file2,fileincurrentdirectory
54 |
55 | ;; comma-separated list of directories to parse
56 | ;; legal values: directory paths separated by commas
57 | ;directory = /path1,/path2,.,..,subdirectory
58 | ;directory = /home/jeichorn/cvs/pear
59 | ;directory = /home/cellog/workspace/phpdoc
60 |
61 | ;; template base directory (the equivalent directory of /phpDocumentor)
62 | ;templatebase = /path/to/my/templates
63 |
64 | ;; directory to find any example files in through @example and {@example} tags
65 | ;examplesdir = /path/to/my/templates
66 |
67 | ;; comma-separated list of files, directories or wildcards ? and * (any wildcard) to ignore
68 | ;; legal values: any wildcard strings separated by commas
69 | ;; remember, this pathing is RELATIVE to the top-most directory in your "directory" value
70 | ;ignore = path/to/ignore*,*list.php,myfile.php,subdirectory/
71 | ignore = pear-*,templates/,Documentation/,test*.php,Lexer.inc
72 |
73 | ;; comma-separated list of Converters to use in outputformat:Convertername:templatedirectory format
74 | ;; legal values: HTML:frames:default,HTML:frames:l0l33t,HTML:frames:phpdoc.de,HTML:frames:phphtmllib,
75 | ;; HTML:frames:earthli,
76 | ;; HTML:frames:DOM/default,HTML:frames:DOM/l0l33t,HTML:frames:DOM/phpdoc.de,
77 | ;; HTML:frames:DOM/phphtmllib,HTML:frames:DOM/earthli
78 | ;; HTML:Smarty:default,HTML:Smarty:PHP,HTML:Smarty:HandS
79 | ;; PDF:default:default,CHM:default:default,XML:DocBook/peardoc2:default
80 | output=HTML:frames:earthli,HTML:frames:default,HTML:frames:l0l33t,HTML:frames:phpdoc.de,HTML:frames:phphtmllib,HTML:frames:DOM/default,HTML:frames:DOM/l0l33t,HTML:frames:DOM/phpdoc.de,HTML:frames:DOM/earthli,HTML:frames:DOM/phphtmllib,HTML:frames:phpedit,HTML:Smarty:default,HTML:Smarty:PHP,HTML:Smarty:HandS
81 |
82 | ;; turn this option on if you want highlighted source code for every file
83 | ;; legal values: on/off
84 | sourcecode = on
85 |
--------------------------------------------------------------------------------
/src/test/php/net/achingbrain/AkismetTest.php:
--------------------------------------------------------------------------------
1 | requestFactory = new MockRequestFactory();
12 |
13 | $this->akismet = new Akismet('', '');
14 | $this->akismet->setRequestFactory($this->requestFactory);
15 | }
16 |
17 | function testIsKeyValid_validKey() {
18 | $this->requestFactory->setResponse("\r\n\r\nvalid");
19 | $response = $this->akismet->isKeyValid();
20 | $this->assertTrue($response);
21 | }
22 |
23 | function testIsKeyValid_invalidKey() {
24 | $this->requestFactory->setResponse("\r\n\r\ninvalid");
25 | $response = $this->akismet->isKeyValid();
26 | $this->assertFalse($response);
27 | }
28 |
29 | function testIsCommentSpam() {
30 | $this->requestFactory->setResponse("\r\n\r\ntrue");
31 | $response = $this->akismet->isCommentSpam();
32 | $this->assertTrue($response);
33 | }
34 |
35 | function testIsCommentHam() {
36 | $this->requestFactory->setResponse("\r\n\r\nfalse");
37 | $response = $this->akismet->isCommentSpam();
38 | $this->assertFalse($response);
39 | }
40 | }
41 |
42 | class MockRequestSender implements AkismetRequestSender {
43 | private $response;
44 |
45 |
46 | public function __construct($response) {
47 | $this->response = $response;
48 | }
49 |
50 | public function send($host, $port, $request, $responseLength = 1160) {
51 | return $this->response;
52 | }
53 | }
54 |
55 | class MockRequestFactory implements AkismetRequestFactory {
56 | private $response;
57 |
58 | public function createRequestSender() {
59 | return new MockRequestSender($this->response);
60 | }
61 |
62 | public function setResponse($response) {
63 | $this->response = $response;
64 | }
65 | }
66 |
67 | ?>
68 |
--------------------------------------------------------------------------------