Zend_Service-ReCaptcha.xml 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.service.recaptcha">
  4. <title>Zend_Service_ReCaptcha</title>
  5. <sect2 id="zend.service.recaptcha.introduction">
  6. <title>Introduction</title>
  7. <para>
  8. <classname>Zend_Service_ReCaptcha</classname> provides a client for the <ulink
  9. url="http://recaptcha.net/">reCAPTCHA Web Service</ulink>.
  10. Per the reCAPTCHA site, "reCAPTCHA is a free CAPTCHA service that
  11. helps to digitize books." Each reCAPTCHA requires the user to input
  12. two words, the first of which is the actual CAPTCHA, and the second
  13. of which is a word from some scanned text that Optical Character
  14. Recognition (OCR) software has been unable to identify.
  15. The assumption is that if a user correctly provides the first
  16. word, the second is likely correctly entered as well, and can be
  17. used to improve OCR software for digitizing books.
  18. </para>
  19. <para>
  20. In order to use the reCAPTCHA service, you will need to <ulink
  21. url="http://recaptcha.net/whyrecaptcha.html">sign up for an
  22. account</ulink> and register one or more domains with the
  23. service in order to generate public and private keys.
  24. </para>
  25. </sect2>
  26. <sect2 id="zend.service.recaptcha.simplestuse">
  27. <title>Simplest use</title>
  28. <para>
  29. Instantiate a <classname>Zend_Service_ReCaptcha</classname> object, passing it
  30. your public and private keys:
  31. </para>
  32. <example id="zend.service.recaptcha.example-1">
  33. <title>Creating an instance of the reCAPTCHA service</title>
  34. <programlisting language="php"><![CDATA[
  35. $recaptcha = new Zend_Service_ReCaptcha($pubKey, $privKey);
  36. ]]></programlisting>
  37. </example>
  38. <para>
  39. To render the reCAPTCHA, simply call the <methodname>getHTML()</methodname>
  40. method:
  41. </para>
  42. <example id="zend.service.recaptcha.example-2">
  43. <title>Displaying the reCAPTCHA</title>
  44. <programlisting language="php"><![CDATA[
  45. echo $recaptcha->getHTML();
  46. ]]></programlisting>
  47. </example>
  48. <para>
  49. When the form is submitted, you should receive two fields,
  50. 'recaptcha_challenge_field' and 'recaptcha_response_field'. Pass
  51. these to the reCAPTCHA object's <methodname>verify()</methodname> method:
  52. </para>
  53. <example id="zend.service.recaptcha.example-3">
  54. <title>Verifying the form fields</title>
  55. <programlisting language="php"><![CDATA[
  56. $result = $recaptcha->verify(
  57. $_POST['recaptcha_challenge_field'],
  58. $_POST['recaptcha_response_field']
  59. );
  60. ]]></programlisting>
  61. </example>
  62. <para>
  63. Once you have the result, test against it to see if it is valid. The
  64. result is a <classname>Zend_Service_ReCaptcha_Response</classname> object,
  65. which provides an <methodname>isValid()</methodname> method.
  66. </para>
  67. <example id="zend.service.recaptcha.example-4">
  68. <title>Validating the reCAPTCHA</title>
  69. <programlisting language="php"><![CDATA[
  70. if (!$result->isValid()) {
  71. // Failed validation
  72. }
  73. ]]></programlisting>
  74. </example>
  75. <para>
  76. It is even simpler to use <link
  77. linkend="zend.captcha.adapters.recaptcha">the reCAPTCHA</link>
  78. <classname>Zend_Captcha</classname> adapter, or to use that adapter as a
  79. backend for the <link
  80. linkend="zend.form.standardElements.captcha">CAPTCHA form
  81. element</link>. In each case, the details of rendering and
  82. validating the reCAPTCHA are automated for you.
  83. </para>
  84. </sect2>
  85. <sect2 id="zend.service.recaptcha.mailhide">
  86. <title>Hiding email addresses</title>
  87. <para>
  88. <classname>Zend_Service_ReCaptcha_MailHide</classname> can be used to hide email
  89. addresses. It will replace a part of an email address with a link that opens a popup
  90. window with a reCAPTCHA challenge. Solving the challenge will reveal the complete
  91. email address.
  92. </para>
  93. <para>
  94. In order to use this component you will need
  95. <ulink url="http://recaptcha.net/whyrecaptcha.html">an account</ulink> to generate
  96. public and private keys for the mailhide <acronym>API</acronym>.
  97. </para>
  98. <example id="zend.service.recaptcha.mailhide.example-1">
  99. <title>Using the mail hide component</title>
  100. <programlisting language="php"><![CDATA[
  101. // The mail address we want to hide
  102. $mail = 'mail@example.com';
  103. // Create an instance of the mailhide component, passing it your public
  104. // and private keys, as well as the mail address you want to hide
  105. $mailHide = new Zend_Service_ReCaptcha_MailHide();
  106. $mailHide->setPublicKey($pubKey);
  107. $mailHide->setPrivateKey($privKey);
  108. $mailHide->setEmail($mail);
  109. // Display it
  110. print($mailHide);
  111. ]]></programlisting>
  112. </example>
  113. <para>
  114. The example above will display "m...@example.com" where "..." has a link that opens up
  115. a popup window with a reCAPTCHA challenge.
  116. </para>
  117. <para>
  118. The public key, private key, and the email address can also be specified in the
  119. constructor of the class. A fourth argument also exists that enables you to set some
  120. options for the component. The available options are listed in the following table:
  121. <table id="zend.service.recaptcha.mailhide.options.table">
  122. <title>Zend_Service_ReCaptcha_MailHide options</title>
  123. <tgroup cols="4">
  124. <thead>
  125. <row>
  126. <entry>Option</entry>
  127. <entry>Description</entry>
  128. <entry>Expected Values</entry>
  129. <entry>Default Value</entry>
  130. </row>
  131. </thead>
  132. <tbody>
  133. <row>
  134. <entry>linkTitle</entry>
  135. <entry>The title attribute of the link</entry>
  136. <entry>string</entry>
  137. <entry>'Reveal this e-mail address'</entry>
  138. </row>
  139. <row>
  140. <entry>linkHiddenText</entry>
  141. <entry>The text that includes the popup link</entry>
  142. <entry>string</entry>
  143. <entry>'...'</entry>
  144. </row>
  145. <row>
  146. <entry>popupWidth</entry>
  147. <entry>The width of the popup window</entry>
  148. <entry>int</entry>
  149. <entry>500</entry>
  150. </row>
  151. <row>
  152. <entry>popupHeight</entry>
  153. <entry>The height of the popup window</entry>
  154. <entry>int</entry>
  155. <entry>300</entry>
  156. </row>
  157. </tbody>
  158. </tgroup>
  159. </table>
  160. </para>
  161. <para>
  162. The configuration options can be set by sending them as the fourth argument to the
  163. constructor or by calling <methodname>setOptions($options)</methodname>, which takes
  164. an associative array or an instance of <link linkend="zend.config">Zend_Config</link>.
  165. </para>
  166. <example id="zend.service.recaptcha.mailhide.example-2">
  167. <title>Generating many hidden email addresses</title>
  168. <programlisting language="php"><![CDATA[
  169. // Create an instance of the mailhide component, passing it your public
  170. // and private keys, as well as some configuration options
  171. $mailHide = new Zend_Service_ReCaptcha_MailHide();
  172. $mailHide->setPublicKey($pubKey);
  173. $mailHide->setPrivateKey($privKey);
  174. $mailHide->setOptions(array(
  175. 'linkTitle' => 'Click me',
  176. 'linkHiddenText' => '+++++',
  177. ));
  178. // The mail addresses we want to hide
  179. $mailAddresses = array(
  180. 'mail@example.com',
  181. 'johndoe@example.com',
  182. 'janedoe@example.com',
  183. );
  184. foreach ($mailAddresses as $mail) {
  185. $mailHide->setEmail($mail);
  186. print($mailHide);
  187. }
  188. ]]></programlisting>
  189. </example>
  190. </sect2>
  191. </sect1>
  192. <!--
  193. vim:se ts=4 sw=4 et:
  194. -->