Services_Akismet
[ class tree: Services_Akismet ] [ index: Services_Akismet ] [ all elements ]

Class: Services_Akismet

Source Location: /Services_Akismet-1.0.1/Akismet.php

Class Overview


Class to use Akismet API from PHP


Author(s):

Copyright:

  • 2007-2008 Bret Kuhns, 2008 silverorange

Methods


Inherited Variables

Inherited Methods


Class Details

[line 251]
Class to use Akismet API from PHP

Example usage:

  1.  /**
  2.   * Handling user-posted comments
  3.   */
  4.  
  5.  $comment = new Services_Akismet_Comment();
  6.  $comment->setAuthor('Test Author');
  7.  $comment->setAuthorEmail('test@example.com');
  8.  $comment->setAuthorUri('http://example.com/');
  9.  $comment->setContent('Hello, World!');
  10.  
  11.  try {
  12.      $apiKey 'AABBCCDDEEFF';
  13.      $akismet = new Services_Akismet('http://blog.example.com/'$apiKey);
  14.      if ($akismet->isSpam($comment)) {
  15.          // rather than simply ignoring the spam comment, it is recommended
  16.          // to save the comment and mark it as spam in case the comment is a
  17.          // false positive.
  18.      else {
  19.          // save comment as normal comment
  20.      }
  21.  catch (Services_Akismet_InvalidApiKeyException $keyException{
  22.      echo 'Invalid API key!';
  23.  catch (Services_Akismet_CommunicationException $comException{
  24.      echo 'Error communicating with Akismet API server: ' .
  25.          $comException->getMessage();
  26.  catch (Services_Akismet_InvalidCommentException $commentException{
  27.      echo 'Specified comment is missing one or more required fields.' .
  28.          $commentException->getMessage();
  29.  }
  30.  
  31.  /**
  32.   * Submitting a comment as known spam
  33.   */
  34.  
  35.  $comment = new Services_Akismet_Comment();
  36.  $comment->setAuthor('Test Author');
  37.  $comment->setAuthorEmail('test@example.com');
  38.  $comment->setAuthorUri('http://example.com/');
  39.  $comment->setContent('Hello, World!');
  40.  
  41.  try {
  42.      $apiKey 'AABBCCDDEEFF';
  43.      $akismet = new Services_Akismet('http://blog.example.com/'$apiKey);
  44.      $akismet->submitSpam($comment);
  45.  catch (Services_Akismet_InvalidApiKeyException $keyException{
  46.      echo 'Invalid API key!';
  47.  catch (Services_Akismet_CommunicationException $comException{
  48.      echo 'Error communicating with Akismet API server: ' .
  49.          $comException->getMessage();
  50.  catch (Services_Akismet_InvalidCommentException $commentException{
  51.      echo 'Specified comment is missing one or more required fields.' .
  52.          $commentException->getMessage();
  53.  }
  54.  
  55.  /**
  56.   * Submitting a comment as a false positive
  57.   */
  58.  
  59.  $comment = new Services_Akismet_Comment();
  60.  $comment->setAuthor('Test Author');
  61.  $comment->setAuthorEmail('test@example.com');
  62.  $comment->setAuthorUri('http://example.com/');
  63.  $comment->setContent('Hello, World!');
  64.  
  65.  try {
  66.      $apiKey 'AABBCCDDEEFF';
  67.      $akismet = new Services_Akismet('http://blog.example.com/'$apiKey);
  68.      $akismet->submitFalsePositive($comment);
  69.  catch (Services_Akismet_InvalidApiKeyException $keyException{
  70.      echo 'Invalid API key!';
  71.  catch (Services_Akismet_CommunicationException $comException{
  72.      echo 'Error communicating with Akismet API server: ' .
  73.          $comException->getMessage();
  74.  catch (Services_Akismet_InvalidCommentException $commentException{
  75.      echo 'Specified comment is missing one or more required fields.' .
  76.          $commentException->getMessage();
  77.  }



[ Top ]


Method Detail

__construct (Constructor)   [line 337]

Services_Akismet __construct( string $blogUri, string $apiKey, [string $httpClientImplementation = 'sockets'])

Creates a new Akismet object
  • Throws: Services_Akismet_InvalidApiKeyException if the provided Wordpress API key is not valid.
  • Throws: Services_Akismet_CommunicationException if there is an error communicating with the Akismet API server.
  • Throws: PEAR_Exception if the specified HTTP client implementation may not be used with this PHP installation or if the specified HTTP client implementation does not exist.
  • Access: public

Parameters:

string   $blogUri   —  the URI of the webblog homepage.
string   $apiKey   —  the Wordpress API key to use for Akismet services.
string   $httpClientImplementation   —  optional. The name of the HTTP client implementation to use. This must be one of the implementations specified by Services_Akismet_HttpClient. If not specified, defaults to 'sockets'.

[ Top ]

isSpam   [line 370]

boolean isSpam( Services_Akismet_Comment $comment)

Checks whether or not a comment is spam
  • Return: true if the comment is spam and false if it is not.
  • Throws: Services_Akismet_InvalidCommentException if the specified comment is missing required fields.
  • Throws: Services_Akismet_CommunicationException if there is an error communicating with the Akismet API server.
  • Access: public

Parameters:

Services_Akismet_Comment   $comment   —  the comment to check.

[ Top ]

setHttpClientImplementation   [line 455]

void setHttpClientImplementation( string $implementation)

Sets the HTTP client implementation to use for this Akismet object

Available implementations are:

  • sockets
  • streams
  • curl

  • See: Services_Akismet_HttpClient
  • Throws: PEAR_Exception if the specified HTTP client implementation may not be used with this PHP installation or if the specified HTTP client implementation does not exist.
  • Access: public

Parameters:

string   $implementation   —  the name of the HTTP client implementation to use. This must be one of the implementations specified by Services_Akismet_HttpClient.

[ Top ]

submitFalsePositive   [line 424]

void submitFalsePositive( Services_Akismet_Comment $comment)

Submits a false-positive comment to the Akismet server

Use this method to submit comments that are detected as spam but are not actually spam.

  • Throws: Services_Akismet_InvalidCommentException if the specified comment is missing required fields.
  • Throws: Services_Akismet_CommunicationException if there is an error communicating with the Akismet API server.
  • Access: public

Parameters:

Services_Akismet_Comment   $comment   —  the comment that is <em>not</em> spam.

[ Top ]

submitSpam   [line 397]

void submitSpam( Services_Akismet_Comment $comment)

Submits a comment as an unchecked spam to the Akismet server

Use this method to submit comments that are spam but are not detected by Akismet.

  • Throws: Services_Akismet_InvalidCommentException if the specified comment is missing required fields.
  • Throws: Services_Akismet_CommunicationException if there is an error communicating with the Akismet API server.
  • Access: public

Parameters:

Services_Akismet_Comment   $comment   —  the comment to submit as spam.

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:21:08 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.