Zend_Service_Akismet.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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 <acronym>API</acronym></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). It was originally intended to help
  13. categorize and identify spam for Wordpress, but it can be used for any
  14. type of data.
  15. </para>
  16. <para>
  17. Akismet requires an <acronym>API</acronym> key for usage. You can get one by 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 <acronym>API</acronym> key.
  21. </para>
  22. <para>
  23. Akismet requires that all requests contain a <acronym>URL</acronym> to
  24. the resource for which data is being filtered. Because of
  25. Akismet's origins in WordPress, this resource is called the blog
  26. <acronym>URL</acronym>. This value should be passed as the second argument to the
  27. constructor, but may be reset at any time using the
  28. <methodname>setBlogUrl()</methodname> method, 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. <methodname>Zend_Service_Akismet::verifyKey($key)</methodname> is used to
  36. verify that an Akismet <acronym>API</acronym> 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, <methodname>verifyKey()</methodname> uses
  54. the <acronym>API</acronym> key provided to the constructor.
  55. </para>
  56. <para>
  57. <methodname>verifyKey()</methodname> 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. <methodname>Zend_Service_Akismet::isSpam($data)</methodname> 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. <acronym>API</acronym>:
  88. </para>
  89. <itemizedlist>
  90. <listitem>
  91. <para>
  92. <code>blog</code>, the fully qualified <acronym>URL</acronym> to the
  93. resource or application. If not specified, the <acronym>URL</acronym>
  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 specified in the <acronym>API</acronym>
  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>, the name of the person
  121. submitting the data.
  122. </para>
  123. </listitem>
  124. <listitem>
  125. <para>
  126. <code>comment_author_email</code>, the email of the
  127. person submitting the data.
  128. </para>
  129. </listitem>
  130. <listitem>
  131. <para>
  132. <code>comment_author_url</code>, the <acronym>URL</acronym> or home page of the
  133. person submitting the data.
  134. </para>
  135. </listitem>
  136. <listitem>
  137. <para>
  138. <code>comment_content</code>, the 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 <methodname>isSpam()</methodname> method will return either
  150. <constant>TRUE</constant> or <constant>FALSE</constant>, or throw an exception if the
  151. <acronym>API</acronym> key is invalid.
  152. </para>
  153. <example id="zend.service.akismet.isspam.example-1">
  154. <title>isSpam() Usage</title>
  155. <programlisting language="php"><![CDATA[
  156. $data = array(
  157. 'user_ip' => '111.222.111.222',
  158. 'user_agent' => 'Mozilla/5.0 ' . (Windows; U; Windows NT ' .
  159. '5.2; en-GB; rv:1.8.1) Gecko/20061010 ' .
  160. 'Firefox/2.0',
  161. 'comment_type' => 'contact',
  162. 'comment_author' => 'John Doe',
  163. 'comment_author_email' => 'nospam@myhaus.net',
  164. 'comment_content' => "I'm not a spammer, honest!"
  165. );
  166. if ($akismet->isSpam($data)) {
  167. echo "Sorry, but we think you're a spammer.";
  168. } else {
  169. echo "Welcome to our site!";
  170. }
  171. ]]></programlisting>
  172. </example>
  173. <para>
  174. <methodname>isSpam()</methodname> implements the <code>comment-check</code>
  175. Akismet <acronym>API</acronym> method.
  176. </para>
  177. </sect2>
  178. <sect2 id="zend.service.akismet.submitspam">
  179. <title>Submitting known spam</title>
  180. <para>
  181. Spam data will occasionally get through the filter. If you discover spam that you feel
  182. should have been caught, you can submit it to Akismet to help improve their filter.
  183. </para>
  184. <para>
  185. <methodname>Zend_Service_Akismet::submitSpam()</methodname> takes the same data
  186. array as passed to <methodname>isSpam()</methodname>, but does not return a
  187. value. An exception will be raised if the <acronym>API</acronym> key used is invalid.
  188. </para>
  189. <example id="zend.service.akismet.submitspam.example-1">
  190. <title>submitSpam() Usage</title>
  191. <programlisting language="php"><![CDATA[
  192. $data = array(
  193. 'user_ip' => '111.222.111.222',
  194. 'user_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.2;' .
  195. 'en-GB; rv:1.8.1) Gecko/20061010 Firefox/2.0',
  196. 'comment_type' => 'contact',
  197. 'comment_author' => 'John Doe',
  198. 'comment_author_email' => 'nospam@myhaus.net',
  199. 'comment_content' => "I'm not a spammer, honest!"
  200. );
  201. $akismet->submitSpam($data));
  202. ]]></programlisting>
  203. </example>
  204. <para>
  205. <methodname>submitSpam()</methodname> implements the <code>submit-spam</code>
  206. Akismet <acronym>API</acronym> method.
  207. </para>
  208. </sect2>
  209. <sect2 id="zend.service.akismet.submitham">
  210. <title>Submitting false positives (ham)</title>
  211. <para>
  212. Data will occasionally be trapped erroneously as spam by Akismet. For this reason,
  213. you should probably keep a log of all data trapped as spam by Akismet and review it
  214. periodically. If you find such occurrences, you can submit the data to Akismet as
  215. "ham", or a false positive (ham is good, spam is not).
  216. </para>
  217. <para>
  218. <methodname>Zend_Service_Akismet::submitHam()</methodname> takes the same data
  219. array as passed to <methodname>isSpam()</methodname> or
  220. <methodname>submitSpam()</methodname>, and, like <methodname>submitSpam()</methodname>,
  221. does not return a value. An exception will be raised if the <acronym>API</acronym> key
  222. used is invalid.
  223. </para>
  224. <example id="zend.service.akismet.submitham.example-1">
  225. <title>submitHam() Usage</title>
  226. <programlisting language="php"><![CDATA[
  227. $data = array(
  228. 'user_ip' => '111.222.111.222',
  229. 'user_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.2;' .
  230. 'en-GB; rv:1.8.1) Gecko/20061010 Firefox/2.0',
  231. 'comment_type' => 'contact',
  232. 'comment_author' => 'John Doe',
  233. 'comment_author_email' => 'nospam@myhaus.net',
  234. 'comment_content' => "I'm not a spammer, honest!"
  235. );
  236. $akismet->submitHam($data));
  237. ]]></programlisting>
  238. </example>
  239. <para>
  240. <methodname>submitHam()</methodname> implements the <code>submit-ham</code>
  241. Akismet <acronym>API</acronym> method.
  242. </para>
  243. </sect2>
  244. <sect2 id="zend.service.akismet.accessors">
  245. <title>Zend-specific Methods</title>
  246. <para>
  247. While the Akismet <acronym>API</acronym> only specifies four methods,
  248. <classname>Zend_Service_Akismet</classname> has several additional methods
  249. that may be used for retrieving and modifying internal properties.
  250. </para>
  251. <itemizedlist>
  252. <listitem>
  253. <para>
  254. <methodname>getBlogUrl()</methodname> and <methodname>setBlogUrl()</methodname>
  255. allow you to retrieve and modify the blog <acronym>URL</acronym> used in
  256. requests.
  257. </para>
  258. </listitem>
  259. <listitem>
  260. <para>
  261. <methodname>getApiKey()</methodname> and <methodname>setApiKey()</methodname>
  262. allow you to retrieve and modify the <acronym>API</acronym> key used in
  263. requests.
  264. </para>
  265. </listitem>
  266. <listitem>
  267. <para>
  268. <methodname>getCharset()</methodname> and <methodname>setCharset()</methodname>
  269. allow you to retrieve and modify the character set used to make the request.
  270. </para>
  271. </listitem>
  272. <listitem>
  273. <para>
  274. <methodname>getPort()</methodname> and <methodname>setPort()</methodname>
  275. allow you to retrieve and modify the <acronym>TCP</acronym> port used to make
  276. the request.
  277. </para>
  278. </listitem>
  279. <listitem>
  280. <para>
  281. <methodname>getUserAgent()</methodname> and
  282. <methodname>setUserAgent()</methodname> allow you to retrieve and modify the
  283. <acronym>HTTP</acronym> user agent used to make the request. Note: this is not
  284. the user_agent used in data submitted to the service, but rather the value
  285. provided in the <acronym>HTTP</acronym> User-Agent header when making a request
  286. to the service.
  287. </para>
  288. <para>
  289. The value used to set the user agent should be of the form
  290. <code>some user agent/version | Akismet/version</code>. The default is
  291. <code>Zend Framework/ZF-VERSION | Akismet/1.11</code>, where
  292. <code>ZF-VERSION</code> is the current Zend Framework version as stored in the
  293. <constant>Zend_Framework::VERSION</constant> constant.
  294. </para>
  295. </listitem>
  296. </itemizedlist>
  297. </sect2>
  298. </sect1>
  299. <!--
  300. vim:se ts=4 sw=4 et:
  301. -->