Zend_Service-ReCaptcha.xml 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- EN-Revision: 24249 -->
  3. <!-- Reviewed: no -->
  4. <sect1 id="zend.service.recaptcha">
  5. <title>Zend_Service_ReCaptcha</title>
  6. <sect2 id="zend.service.recaptcha.introduction">
  7. <title>Introduction</title>
  8. <para>
  9. <classname>Zend_Service_ReCaptcha</classname> fournit un client pour le <ulink
  10. url="http://recaptcha.net/">Service Web reCAPTCHA</ulink>. D'après le site de reCAPTCHA,
  11. "reCAPTCHA est un service gratuit de CAPTCHA qui aide à la numérisation de livres."
  12. Chaque reCAPTCHA requière que l'utilisateur saisisse 2 mots, le premier est le CAPTCHA,
  13. et le second est issu de texte scanné que les OCR (Optical Character Recognition) ne
  14. peuvent identifier.
  15. </para>
  16. <para>
  17. Pour utiliser le service reCAPTCHA, vous devez <ulink
  18. url="http://recaptcha.net/whyrecaptcha.html">créer un compte</ulink> et enregistrer un
  19. ou plusieurs domaines d'utilisation afin de générer une clé publique et une
  20. privée.
  21. </para>
  22. </sect2>
  23. <sect2 id="zend.service.recaptcha.simplestuse">
  24. <title>Utilisation la plus simple</title>
  25. <para>
  26. Instanciez un objet <classname>Zend_Service_ReCaptcha</classname> en lui passant
  27. vos clés publique et privée :
  28. </para>
  29. <example id="zend.service.recaptcha.example-1">
  30. <title>Créer une instance de service ReCaptcha</title>
  31. <programlisting language="php"><![CDATA[
  32. $recaptcha = new Zend_Service_ReCaptcha($pubKey, $privKey);
  33. ]]></programlisting>
  34. </example>
  35. <para>
  36. Pour rendre le reCAPTCHA, appelez simplement la méthode <methodname>getHTML()</methodname>
  37. :
  38. </para>
  39. <example id="zend.service.recaptcha.example-2">
  40. <title>Afficher le ReCaptcha</title>
  41. <programlisting language="php"><![CDATA[
  42. echo $recaptcha->getHTML();
  43. ]]></programlisting>
  44. </example>
  45. <para>
  46. Lorsque le formulaire est envoyé, vous devriez recevoir 2 champs
  47. 'recaptcha_challenge_field' et 'recaptcha_response_field'. Passez les alors à la méthode
  48. <methodname>verify()</methodname> :
  49. </para>
  50. <programlisting language="php"><![CDATA[
  51. $result = $recaptcha->verify(
  52. $_POST['recaptcha_challenge_field'],
  53. $_POST['recaptcha_response_field']
  54. );
  55. ]]></programlisting>
  56. <para>
  57. Une fois que vous possédez le résultat, vérifiez sa validité. Il s'agit d'un objet
  58. <classname>Zend_Service_ReCaptcha_Response</classname> qui possède une méthode
  59. <methodname>isValid()</methodname>.
  60. </para>
  61. <example id="zend.service.recaptcha.example-3">
  62. <title>Vérifier les champs de formulaire</title>
  63. <programlisting language="php"><![CDATA[
  64. if (!$result->isValid()) {
  65. // Validation échouée
  66. }
  67. ]]></programlisting>
  68. </example>
  69. <para>
  70. Encore plus simple : utilisez <link
  71. linkend="zend.captcha.adapters.recaptcha">l'adaptateur ReCaptcha</link> de
  72. <classname>Zend_Captcha</classname>, ou utilisez cet adaptateur comme backend pour <link
  73. linkend="zend.form.standardElements.captcha">l'élément formulaire Captcha</link>. Dans
  74. ces 2 cas, le rendu et la validation du reCAPTCHA sont assurés pour vous.
  75. </para>
  76. </sect2>
  77. <sect2 id="zend.service.recaptcha.mailhide">
  78. <title>Hiding email addresses</title>
  79. <para>
  80. <classname>Zend_Service_ReCaptcha_MailHide</classname> can be used to hide email
  81. addresses. It will replace a part of an email address with a link that opens a popup
  82. window with a ReCaptcha challenge. Solving the challenge will reveal the complete
  83. email address.
  84. </para>
  85. <para>
  86. In order to use this component you will need
  87. <ulink url="http://recaptcha.net/whyrecaptcha.html">an account</ulink>, and generate
  88. public and private keys for the mailhide API.
  89. </para>
  90. <example id="zend.service.recaptcha.mailhide.example-1">
  91. <title>Using the mail hide component</title>
  92. <programlisting language="php"><![CDATA[
  93. // The mail address we want to hide
  94. $mail = 'mail@example.com';
  95. // Create an instance of the mailhide component, passing it your public and private keys as well as
  96. // the mail address you want to hide
  97. $mailHide = new Zend_Service_ReCaptcha_MailHide();
  98. $mailHide->setPublicKey($pubKey);
  99. $mailHide->setPrivateKey($privKey);
  100. $mailHide->setEmail($mail);
  101. // Display it
  102. print($mailHide);
  103. ]]></programlisting>
  104. </example>
  105. <para>
  106. The example above will display "m...@example.com" where "..." has a link that opens up
  107. a popup windows with a ReCaptcha challenge.
  108. </para>
  109. <para>
  110. The public key, private key and the email address can also be specified in the
  111. constructor of the class. A fourth argument also exists that enables you to set some
  112. options for the component. The available options are listed in the following table:
  113. <table id="zend.service.recaptcha.mailhide.options.table">
  114. <title>Zend_Service_ReCaptcha_MailHide options</title>
  115. <tgroup cols="4">
  116. <thead>
  117. <row>
  118. <entry>Option</entry>
  119. <entry>Description</entry>
  120. <entry>Expected Values</entry>
  121. <entry>Default Value</entry>
  122. </row>
  123. </thead>
  124. <tbody>
  125. <row>
  126. <entry>linkTitle</entry>
  127. <entry>The title attribute of the link</entry>
  128. <entry>string</entry>
  129. <entry>'Reveal this e-mail address'</entry>
  130. </row>
  131. <row>
  132. <entry>linkHiddenText</entry>
  133. <entry>The text that includes the popup link</entry>
  134. <entry>string</entry>
  135. <entry>'...'</entry>
  136. </row>
  137. <row>
  138. <entry>popupWidth</entry>
  139. <entry>The width of the popup window</entry>
  140. <entry>int</entry>
  141. <entry>500</entry>
  142. </row>
  143. <row>
  144. <entry>popupHeight</entry>
  145. <entry>The height of the popup window</entry>
  146. <entry>int</entry>
  147. <entry>300</entry>
  148. </row>
  149. </tbody>
  150. </tgroup>
  151. </table>
  152. </para>
  153. <para>
  154. The configuration options can be set by sending it as the fourth argument to the
  155. constructor or by calling the <methodname>setOptions($options)</methodname> which takes
  156. an associative array or an instance of <link linkend="zend.config">Zend_Config</link>.
  157. </para>
  158. <example id="zend.service.recaptcha.mailhide.example-2">
  159. <title>Generating many hidden email addresses</title>
  160. <programlisting language="php"><![CDATA[
  161. // Create an instance of the mailhide component, passing it your public and private keys as well as
  162. // well the mail address you want to hide
  163. $mailHide = new Zend_Service_ReCaptcha_MailHide();
  164. $mailHide->setPublicKey($pubKey);
  165. $mailHide->setPrivateKey($privKey);
  166. $mailHide->setOptions(array(
  167. 'linkTitle' => 'Click me',
  168. 'linkHiddenText' => '+++++',
  169. ));
  170. // The addresses we want to hide
  171. $mailAddresses = array(
  172. 'mail@example.com',
  173. 'johndoe@example.com',
  174. 'janedoe@example.com',
  175. );
  176. foreach ($mailAddresses as $mail) {
  177. $mailHide->setEmail($mail);
  178. print($mailHide);
  179. }
  180. ]]></programlisting>
  181. </example>
  182. </sect2>
  183. </sect1>