mollom / client
Mollom REST API 的通用 PHP 库。
此包的规范仓库似乎已消失,因此该包已被冻结。
This package is not auto-updated.
Last update: 2024-01-20 13:15:04 UTC
README
通用的 Mollom 客户端 PHP 类。
此基类旨在简化将 Mollom 内容审核服务集成到基于 PHP 的应用程序中的过程。该类实现了 Mollom 客户端所需的必要代码逻辑,并提供了许多辅助函数来与 Mollom 的 REST API 进行通信。
请确保您的服务器时间与世界时钟同步,并且不要将您的私钥与任何人共享。
要提交错误报告和功能建议,或跟踪更改: https://github.com/Mollom/MollomPHP/issues
需求
- PHP 5.3.4 或更高版本
使用
-
扩展您的平台的 Mollom 类。至少,您需要实现以下方法
<?php class MollomMyPlatform extends Mollom { public function loadConfiguration($name) {} public function saveConfiguration($name, $value) {} public function deleteConfiguration($name) {} public function getClientInformation() {} protected function request($method, $server, $path, $query = NULL, array $headers = array()) {} }
这些方法在 Mollom 类中有详细说明。
-
例如,检查帖子是否为垃圾邮件
<?php // When a comment is submitted: $mollom = new MollomMyPlatform(); $comment = $_POST['comment']; $result = $mollom->checkContent(array( 'checks' => array('spam'), 'postTitle' => $comment['title'], 'postBody' => $comment['body'], 'authorName' => $comment['name'], 'authorUrl' => $comment['homepage'], 'authorIp' => $_SERVER['REMOTE_ADDR'], 'authorId' => $userid, // If the author is logged in. )); // You might want to make the fallback case configurable: if (!is_array($result) || !isset($result['id'])) { print "The content moderation system is currently unavailable. Please try again later."; die(); } // Check the final spam classification. switch ($result['spamClassification']) { case 'ham': // Do nothing. (Accept content.) break; case 'spam': // Discard (block) the form submission. print "Your submission has triggered the spam filter and will not be accepted."; die(); break; case 'unsure': // Require to solve a CAPTCHA to get the post submitted. $captcha = $mollom->createCaptcha(array( 'contentId' => $result['id'], 'type' => 'image', )); if (!is_array($captcha) || !isset($captcha['id'])) { print "The content moderation system is currently unavailable. Please try again later."; die(); } // Output the CAPTCHA. print '<img src="' . $captcha['url'] . '" alt="Type the characters you see in this picture." />'; print '<input type="text" name="captcha" size="10" value="" autocomplete="off" />'; // Re-inject the submitted form values, re-render the form, // and ask the user to solve the CAPTCHA. break; default: // If we end up here, Mollom responded with a unknown spamClassification. // Normally, this should not happen. break; }
示例
这些是 Mollom 类实现的示例。如上述代码片段所示,该类仅负责与 Mollom 通信的基本逻辑。每个实现仍然需要特定于应用程序的代码来处理 Mollom 提供的结果。
API
此库被认为是稳定的,并且正在积极使用,但 API 变更可能无法避免。
配置
PHP <5.4 作为 CGI:处理传入的 CMP OAuth 请求
对于低于 5.4 的 PHP 版本,并且如果 PHP 以 CGI(而不是 Apache 模块/mod_php
)运行,您可能需要启用 mod_rewrite
并将以下重写规则放置在您的虚拟主机配置或 .htaccess
文件中
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
从 PHP 5.4.0 开始,getallheaders() 也在 FastCGI 下可用。在较早的 PHP 版本中,当 PHP 以 CGI 运行时,HTTP Authorization
请求头不会被转发到 PHP 环境变量。
许可证
您可以根据 MIT 许可证或 GNU 通用公共许可证(GPL)版本 2 的条款使用此软件。
请参阅 LICENSE-MIT.txt 和 LICENSE-GPL.txt。