PHPマニュアル/PEARマニュアル | ユーザフォーラムで議論/質問 | マニュアル検索 | ハイライト | ハイライトオフ | ポータル | php spot

Examples | JavaScript入門&応用&リファレンスなら「JavaScriptist」

  

Examples

If you are using the Akismet API, it is recommended you build a system to enter data back into the API either by submitting missed spam, or by submitting false positives. While not strictly required, passing data back using the API will allow the service to learn from its mistakes, and will ensure the service stays relevant for your needs.

Handling User-Submitted Comments

<?php

require_once 'Services/Akismet2.php';
require_once 
'Services/Akismet2/Comment.php';

$comment = new Services_Akismet2_Comment(array(
    
'comment_author'       => 'Test Author',
    
'comment_author_email' => 'test@example.com',
    
'comment_author_url'   => 'http://example.com/',
    
'comment_content'      => 'Hello, World!'
));

try {
    
$apiKey  'AABBCCDDEEFF';
    
$akismet = new Services_Akismet2('http://blog.example.com/'$apiKey);
    if (
$akismet->isSpam($comment)) {
        
// rather than simply ignoring the spam comment, it is recommended
        // to save the comment and mark it as spam in case the comment is a
        // false positive.
    
} else {
        
// save comment as normal comment
    
}
} catch (
Services_Akismet2_InvalidApiKeyException $keyException) {
    echo 
'Invalid API key!';
} catch (
Services_Akismet2_HttpException $httpException) {
    echo 
'Error communicating with Akismet API server: ' .
        
$httpException->getMessage();
} catch (
Services_Akismet2_InvalidCommentException $commentException) {
    echo 
'Specified comment is missing one or more required fields.' .
        
$commentException->getMessage();
}

?>

Marking a Missed Comment as Spam

<?php

require_once 'Services/Akismet2.php';
require_once 
'Services/Akismet2/Comment.php';

$comment = new Services_Akismet2_Comment(array(
    
'comment_author'       => 'Test Author',
    
'comment_author_email' => 'test@example.com',
    
'comment_author_url'   => 'http://example.com/',
    
'comment_content'      => 'Hello, World!'
));

try {
    
$apiKey  'AABBCCDDEEFF';
    
$akismet = new Services_Akismet2('http://blog.example.com/'$apiKey);
    
$akismet->submitSpam($comment);
} catch (
Services_Akismet2_InvalidApiKeyException $keyException) {
    echo 
'Invalid API key!';
} catch (
Services_Akismet2_HttpException $httpException) {
    echo 
'Error communicating with Akismet API server: ' .
        
$httpException->getMessage();
} catch (
Services_Akismet2_InvalidCommentException $commentException) {
    echo 
'Specified comment is missing one or more required fields.' .
        
$commentException->getMessage();
}

?>

Marking a Comment as a False Positive

<?php

require_once 'Services/Akismet2.php';
require_once 
'Services/Akismet2/Comment.php';

$comment = new Services_Akismet2_Comment(array(
    
'comment_author'       => 'Test Author',
    
'comment_author_email' => 'test@example.com',
    
'comment_author_url'   => 'http://example.com/',
    
'comment_content'      => 'Hello, World!'
));

try {
    
$apiKey  'AABBCCDDEEFF';
    
$akismet = new Services_Akismet2('http://blog.example.com/'$apiKey);
    
$akismet->submitFalsePositive($comment);
} catch (
Services_Akismet2_InvalidApiKeyException $keyException) {
    echo 
'Invalid API key!';
} catch (
Services_Akismet2_HttpException $httpException) {
    echo 
'Error communicating with Akismet API server: ' .
        
$httpException->getMessage();
} catch (
Services_Akismet2_InvalidCommentException $commentException) {
    echo 
'Specified comment is missing one or more required fields.' .
        
$commentException->getMessage();
}

?>

忘却曲線を使ってこの知識を確実に記憶に残す

フォーラムで「Examples」について話す
各種マニュアル: PHPマニュアル | PEARマニュアル | Smarty(英語)マニュアル | PHP-GTKマニュアル | Examples」をGoogle検索
copyright © 1997-2024 PHP ドキュメント作成グループ(ライセンス). provided by php spot. マニュアル: