Zend_Service_Akismet.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.service.akismet">
  4. <title>Zend_Service_Akismet</title>
  5. <sect2 id="zend.service.akismet.introduction">
  6. <title>Introduction</title>
  7. <para>
  8. <classname>Zend_Service_Akismet</classname> provides a client for the <ulink
  9. url="http://akismet.com/development/api/">Akismet API</ulink>.
  10. The Akismet service is used to determine if incoming data is
  11. potentially spam; it also exposes methods for submitting data as
  12. known spam or as false positives (ham). Originally intended to help
  13. categorize and identify spam for Wordpress, it can be used for any
  14. type of data.
  15. </para>
  16. <para>
  17. Akismet requires an API key for usage. You may get one for signing
  18. up for a <ulink url="http://wordpress.com/">WordPress.com</ulink>
  19. account. You do not need to activate a blog; simply acquiring the
  20. account will provide you with the API key.
  21. </para>
  22. <para>
  23. Additionally, Akismet requires that all requests contain a URL to
  24. the resource for which data is being filtered, and, because of
  25. Akismet's origins in WordPress, this resource is called the blog
  26. url. This value should be passed as the second argument to the
  27. constructor, but may be reset at any time using the
  28. <code>setBlogUrl()</code> accessor, or overridden by specifying a
  29. 'blog' key in the various method calls.
  30. </para>
  31. </sect2>
  32. <sect2 id="zend.service.akismet.verifykey">
  33. <title>Verify an API key</title>
  34. <para>
  35. <classname>Zend_Service_Akismet::verifyKey($key)</classname> is used to
  36. verify that an Akismet API key is valid. In most cases, you
  37. will not need to check, but if you need a sanity check, or
  38. to determine if a newly acquired key is active, you may do
  39. so with this method.
  40. </para>
  41. <programlisting language="php"><![CDATA[
  42. // Instantiate with the API key and a URL to the application or
  43. // resource being used
  44. $akismet = new Zend_Service_Akismet($apiKey,
  45. 'http://framework.zend.com/wiki/');
  46. if ($akismet->verifyKey($apiKey) {
  47. echo "Key is valid.\n";
  48. } else {
  49. echo "Key is not valid\n";
  50. }
  51. ]]></programlisting>
  52. <para>
  53. If called with no arguments, <code>verifyKey()</code> uses
  54. the API key provided to the constructor.
  55. </para>
  56. <para>
  57. <code>verifyKey()</code> implements Akismet's
  58. <code>verify-key</code> REST method.
  59. </para>
  60. </sect2>
  61. <sect2 id="zend.service.akismet.isspam">
  62. <title>Check for spam</title>
  63. <para>
  64. <classname>Zend_Service_Akismet::isSpam($data)</classname> is used to
  65. determine if the data provided is considered spam by
  66. Akismet. It accepts an associative array as the sole
  67. argument. That array requires the following keys be set:
  68. </para>
  69. <itemizedlist>
  70. <listitem>
  71. <para>
  72. <code>user_ip</code>, the IP address of the user
  73. submitting the data (not your IP address, but that
  74. of a user on your site).
  75. </para>
  76. </listitem>
  77. <listitem>
  78. <para>
  79. <code>user_agent</code>, the reported UserAgent
  80. string (browser and version) of the user submitting
  81. the data.
  82. </para>
  83. </listitem>
  84. </itemizedlist>
  85. <para>
  86. The following keys are also recognized specifically by the
  87. API:
  88. </para>
  89. <itemizedlist>
  90. <listitem>
  91. <para>
  92. <code>blog</code>, the fully qualified URL to the
  93. resource or application. If not specified, the URL
  94. provided to the constructor will be used.
  95. </para>
  96. </listitem>
  97. <listitem>
  98. <para>
  99. <code>referrer</code>, the content of the
  100. HTTP_REFERER header at the time of submission. (Note
  101. spelling; it does not follow the header name.)
  102. </para>
  103. </listitem>
  104. <listitem>
  105. <para>
  106. <code>permalink</code>, the permalink location, if
  107. any, of the entry the data was submitted to.
  108. </para>
  109. </listitem>
  110. <listitem>
  111. <para>
  112. <code>comment_type</code>, the type of data
  113. provided. Values specifically specified in the API
  114. include 'comment', 'trackback', 'pingback', and an
  115. empty string (''), but it may be any value.
  116. </para>
  117. </listitem>
  118. <listitem>
  119. <para>
  120. <code>comment_author</code>, name of the person
  121. submitting the data.
  122. </para>
  123. </listitem>
  124. <listitem>
  125. <para>
  126. <code>comment_author_email</code>, email of the
  127. person submitting the data.
  128. </para>
  129. </listitem>
  130. <listitem>
  131. <para>
  132. <code>comment_author_url</code>, URL or home page of the
  133. person submitting the data.
  134. </para>
  135. </listitem>
  136. <listitem>
  137. <para>
  138. <code>comment_content</code>, actual data content
  139. submitted.
  140. </para>
  141. </listitem>
  142. </itemizedlist>
  143. <para>
  144. You may also submit any other environmental variables you
  145. feel might be a factor in determining if data is spam.
  146. Akismet suggests the contents of the entire $_SERVER array.
  147. </para>
  148. <para>
  149. The <code>isSpam()</code> method will return either true or
  150. false, and throw an exception if the API key is invalid.
  151. </para>
  152. <example id="zend.service.akismet.isspam.example-1">
  153. <title>isSpam() Usage</title>
  154. <programlisting language="php"><![CDATA[
  155. $data = array(
  156. 'user_ip' => '111.222.111.222',
  157. 'user_agent' => 'Mozilla/5.0 ' . (Windows; U; Windows NT ' .
  158. '5.2; en-GB; rv:1.8.1) Gecko/20061010 ' .
  159. 'Firefox/2.0',
  160. 'comment_type' => 'contact',
  161. 'comment_author' => 'John Doe',
  162. 'comment_author_email' => 'nospam@myhaus.net',
  163. 'comment_content' => "I'm not a spammer, honest!"
  164. );
  165. if ($akismet->isSpam($data)) {
  166. echo "Sorry, but we think you're a spammer.";
  167. } else {
  168. echo "Welcome to our site!";
  169. }
  170. ]]></programlisting>
  171. </example>
  172. <para>
  173. <code>isSpam()</code> implements the <code>comment-check</code>
  174. Akismet API method.
  175. </para>
  176. </sect2>
  177. <sect2 id="zend.service.akismet.submitspam">
  178. <title>Submitting known spam</title>
  179. <para>
  180. Occasionally spam data will get through the filter. If in your
  181. review of incoming data you discover spam that you feel should have
  182. been caught, you can submit it to Akismet to help improve their
  183. filter.
  184. </para>
  185. <para>
  186. <classname>Zend_Service_Akismet::submitSpam()</classname> takes the same data
  187. array as passed to <code>isSpam()</code>, but does not return a
  188. value. An exception will be raised if the API key used is invalid.
  189. </para>
  190. <example id="zend.service.akismet.submitspam.example-1">
  191. <title>submitSpam() Usage</title>
  192. <programlisting language="php"><![CDATA[
  193. $data = array(
  194. 'user_ip' => '111.222.111.222',
  195. 'user_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.2;' .
  196. 'en-GB; rv:1.8.1) Gecko/20061010 Firefox/2.0',
  197. 'comment_type' => 'contact',
  198. 'comment_author' => 'John Doe',
  199. 'comment_author_email' => 'nospam@myhaus.net',
  200. 'comment_content' => "I'm not a spammer, honest!"
  201. );
  202. $akismet->submitSpam($data));
  203. ]]></programlisting>
  204. </example>
  205. <para>
  206. <code>submitSpam()</code> implements the <code>submit-spam</code>
  207. Akismet API method.
  208. </para>
  209. </sect2>
  210. <sect2 id="zend.service.akismet.submitham">
  211. <title>Submitting false positives (ham)</title>
  212. <para>
  213. Occasionally data will be trapped erroneously as spam by Akismet.
  214. For this reason, you should probably keep a log of all data
  215. trapped as spam by Akismet and review it periodically. If you find
  216. such occurrences, you can submit the data to Akismet as "ham", or a
  217. false positive (ham is good, spam is not).
  218. </para>
  219. <para>
  220. <classname>Zend_Service_Akismet::submitHam()</classname> takes the same data
  221. array as passed to <code>isSpam()</code> or
  222. <code>submitSpam()</code>, and, like <code>submitSpam()</code>, does
  223. not return a value. An exception will be raised if the API key used
  224. is invalid.
  225. </para>
  226. <example id="zend.service.akismet.submitham.example-1">
  227. <title>submitHam() Usage</title>
  228. <programlisting language="php"><![CDATA[
  229. $data = array(
  230. 'user_ip' => '111.222.111.222',
  231. 'user_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.2;' .
  232. 'en-GB; rv:1.8.1) Gecko/20061010 Firefox/2.0',
  233. 'comment_type' => 'contact',
  234. 'comment_author' => 'John Doe',
  235. 'comment_author_email' => 'nospam@myhaus.net',
  236. 'comment_content' => "I'm not a spammer, honest!"
  237. );
  238. $akismet->submitHam($data));
  239. ]]></programlisting>
  240. </example>
  241. <para>
  242. <code>submitHam()</code> implements the <code>submit-ham</code>
  243. Akismet API method.
  244. </para>
  245. </sect2>
  246. <sect2 id="zend.service.akismet.accessors">
  247. <title>Zend-specific Accessor Methods</title>
  248. <para>
  249. While the Akismet API only specifies four methods,
  250. <classname>Zend_Service_Akismet</classname> has several additional accessors
  251. that may be used for modifying internal properties.
  252. </para>
  253. <itemizedlist>
  254. <listitem>
  255. <para>
  256. <code>getBlogUrl()</code> and <code>setBlogUrl()</code>
  257. allow you to retrieve and modify the blog URL used in
  258. requests.
  259. </para>
  260. </listitem>
  261. <listitem>
  262. <para>
  263. <code>getApiKey()</code> and <code>setApiKey()</code>
  264. allow you to retrieve and modify the API key used in
  265. requests.
  266. </para>
  267. </listitem>
  268. <listitem>
  269. <para>
  270. <code>getCharset()</code> and <code>setCharset()</code>
  271. allow you to retrieve and modify the character set used to
  272. make the request.
  273. </para>
  274. </listitem>
  275. <listitem>
  276. <para>
  277. <code>getPort()</code> and <code>setPort()</code>
  278. allow you to retrieve and modify the TCP port used to make
  279. the request.
  280. </para>
  281. </listitem>
  282. <listitem>
  283. <para>
  284. <code>getUserAgent()</code> and <code>setUserAgent()</code>
  285. allow you to retrieve and modify the HTTP user agent used to
  286. make the request. Note: this is not the user_agent used in
  287. data submitted to the service, but rather the value provided
  288. in the HTTP User-Agent header when making a request to the
  289. service.
  290. </para>
  291. <para>
  292. The value used to set the user agent should be of the form
  293. <code>some user agent/version | Akismet/version</code>. The
  294. default is <code>Zend Framework/ZF-VERSION | Akismet/1.11</code>, where <code>ZF-VERSION</code> is the current Zend Framework version as stored in the <classname>Zend_Framework::VERSION</classname> constant.
  295. </para>
  296. </listitem>
  297. </itemizedlist>
  298. </sect2>
  299. </sect1>
  300. <!--
  301. vim:se ts=4 sw=4 et:
  302. -->