Zend_Captcha-Adapters.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.captcha.adapters">
  4. <title>CAPTCHA Adapters</title>
  5. <para>
  6. The following adapters are shipped with Zend Framework by default.
  7. </para>
  8. <sect2 id="zend.captcha.adapters.word">
  9. <title>Zend_Captcha_Word</title>
  10. <para>
  11. <classname>Zend_Captcha_Word</classname> is an abstract adapter that serves as the base
  12. class for most other <acronym>CAPTCHA</acronym> adapters. It provides mutators for
  13. specifying word length, session <acronym>TTL</acronym>, the session namespace object
  14. to use, and the session namespace class to use for persistence if
  15. you do not wish to use <classname>Zend_Session_Namespace</classname>.
  16. <classname>Zend_Captcha_Word</classname> encapsulates validation logic.
  17. </para>
  18. <para>
  19. By default, the word length is 8 characters, the session timeout is
  20. 5 minutes, and <classname>Zend_Session_Namespace</classname> is used for persistence
  21. (using the namespace "<classname>Zend_Form_Captcha_&lt;captcha ID&gt;</classname>").
  22. </para>
  23. <para>
  24. In addition to the methods required by the
  25. <classname>Zend_Captcha_Adapter</classname> interface,
  26. <classname>Zend_Captcha_Word</classname> exposes the following methods:
  27. </para>
  28. <itemizedlist>
  29. <listitem>
  30. <para>
  31. <methodname>setWordLen($length)</methodname> and
  32. <methodname>getWordLen()</methodname> allow you to specify the length of the
  33. generated "word" in characters, and to retrieve the current value.
  34. </para>
  35. </listitem>
  36. <listitem>
  37. <para>
  38. <methodname>setTimeout($ttl)</methodname> and
  39. <methodname>getTimeout()</methodname> allow you to specify the time-to-live of
  40. the session token, and to retrieve the current value. <varname>$ttl</varname>
  41. should be specified in seconds.
  42. </para>
  43. </listitem>
  44. <listitem>
  45. <para>
  46. <methodname>setUseNumbers($numbers)</methodname> and
  47. <methodname>getUseNumbers()</methodname> allow you to specify if numbers will be
  48. considered as possible characters for the random work or only letters would be
  49. used.
  50. </para>
  51. </listitem>
  52. <listitem>
  53. <para>
  54. <methodname>setSessionClass($class)</methodname> and
  55. <methodname>getSessionClass()</methodname> allow you to specify an
  56. alternate <classname>Zend_Session_Namespace</classname> implementation to
  57. use to persist the <acronym>CAPTCHA</acronym> token and to retrieve the
  58. current value.
  59. </para>
  60. </listitem>
  61. <listitem>
  62. <para>
  63. <methodname>getId()</methodname> allows you to retrieve the current token
  64. identifier.
  65. </para>
  66. </listitem>
  67. <listitem>
  68. <para>
  69. <methodname>getWord()</methodname> allows you to retrieve the generated
  70. word to use with the <acronym>CAPTCHA</acronym>. It will generate the word for
  71. you if none has been generated yet.
  72. </para>
  73. </listitem>
  74. <listitem>
  75. <para>
  76. <methodname>setSession(Zend_Session_Namespace $session)</methodname> allows
  77. you to specify a session object to use for persisting the
  78. <acronym>CAPTCHA</acronym> token. <methodname>getSession()</methodname> allows
  79. you to retrieve the current session object.
  80. </para>
  81. </listitem>
  82. </itemizedlist>
  83. <para>
  84. All word <acronym>CAPTCHA</acronym>s allow you to pass an array of options to the
  85. constructor, or, alternately, pass them to
  86. <methodname>setOptions()</methodname>. You can also pass a
  87. <classname>Zend_Config</classname> object to <methodname>setConfig()</methodname>. By
  88. default, the <emphasis>wordLen</emphasis>, <emphasis>timeout</emphasis>, and
  89. <emphasis>sessionClass</emphasis> keys may all be used. Each concrete
  90. implementation may define additional keys or utilize the options in
  91. other ways.
  92. </para>
  93. <note>
  94. <para>
  95. <classname>Zend_Captcha_Word</classname> is an abstract class and may not be
  96. instantiated directly.
  97. </para>
  98. </note>
  99. </sect2>
  100. <sect2 id="zend.captcha.adapters.dumb">
  101. <title>Zend_Captcha_Dumb</title>
  102. <para>
  103. The <classname>Zend_Captch_Dumb</classname> adapter is mostly self-descriptive. It
  104. provides a random string that must be typed in reverse to validate. As such, it's
  105. not a good <acronym>CAPTCHA</acronym> solution and should only be used for
  106. testing. It extends <classname>Zend_Captcha_Word</classname>.
  107. </para>
  108. </sect2>
  109. <sect2 id="zend.captcha.adapters.figlet">
  110. <title>Zend_Captcha_Figlet</title>
  111. <para>
  112. The <classname>Zend_Captcha_Figlet</classname> adapter utilizes <link
  113. linkend="zend.text.figlet"><classname>Zend_Text_Figlet</classname></link> to present
  114. a figlet to the user.
  115. </para>
  116. <para>
  117. Options passed to the constructor will also be passed to the <link
  118. linkend="zend.text.figlet"><classname>Zend_Text_Figlet</classname></link> object.
  119. See the <link linkend="zend.text.figlet"><classname>Zend_Text_Figlet</classname></link>
  120. documentation for details on what configuration options are available.
  121. </para>
  122. </sect2>
  123. <sect2 id="zend.captcha.adapters.image">
  124. <title>Zend_Captcha_Image</title>
  125. <para>
  126. The <classname>Zend_Captcha_Image</classname> adapter takes the generated word and
  127. renders it as an image, performing various skewing permutations to make it
  128. difficult to automatically decipher. It
  129. requires the <ulink url="http://php.net/gd">GD extension</ulink>
  130. compiled with TrueType or Freetype support. Currently, the
  131. <classname>Zend_Captcha_Image</classname> adapter can only generate
  132. <acronym>PNG</acronym> images.
  133. </para>
  134. <para>
  135. <classname>Zend_Captcha_Image</classname> extends
  136. <classname>Zend_Captcha_Word</classname>, and additionally exposes the
  137. following methods:
  138. </para>
  139. <itemizedlist>
  140. <listitem>
  141. <para>
  142. <methodname>setExpiration($expiration)</methodname> and
  143. <methodname>getExpiration()</methodname> allow you to specify a maximum
  144. lifetime the <acronym>CAPTCHA</acronym> image may reside on the filesystem.
  145. This is typically a longer than the session lifetime. Garbage
  146. collection is run periodically each time the <acronym>CAPTCHA</acronym> object
  147. is invoked, deleting all images that have expired.
  148. Expiration values should be specified in seconds.
  149. </para>
  150. </listitem>
  151. <listitem>
  152. <para>
  153. <methodname>setGcFreq($gcFreq)</methodname> and
  154. <methodname>getGcFreg()</methodname> allow you to specify how frequently garbage
  155. collection should run. Garbage collection will run every
  156. <command>1/$gcFreq</command> calls. The default is 100.
  157. </para>
  158. </listitem>
  159. <listitem>
  160. <para>
  161. <methodname>setFont($font)</methodname> and <methodname>getFont()</methodname>
  162. allow you to specify the font you will use. <varname>$font</varname>
  163. should be a fully qualified path to the font file.
  164. This value is required; the <acronym>CAPTCHA</acronym> will throw an
  165. exception during generation if the font file has not been specified.
  166. </para>
  167. </listitem>
  168. <listitem>
  169. <para>
  170. <methodname>setFontSize($fsize)</methodname> and
  171. <methodname>getFontSize()</methodname> allow you to specify the font size in
  172. pixels for generating the <acronym>CAPTCHA</acronym>. The default is 24px.
  173. </para>
  174. </listitem>
  175. <listitem>
  176. <para>
  177. <methodname>setHeight($height)</methodname> and
  178. <methodname>getHeight()</methodname> allow you to specify the height in pixels
  179. of the generated <acronym>CAPTCHA</acronym> image. The default is 50px.
  180. </para>
  181. </listitem>
  182. <listitem>
  183. <para>
  184. <methodname>setWidth($width)</methodname> and
  185. <methodname>getWidth()</methodname> allow you to specify the width in pixels of
  186. the generated <acronym>CAPTCHA</acronym> image. The default is 200px.
  187. </para>
  188. </listitem>
  189. <listitem>
  190. <para>
  191. <methodname>setImgDir($imgDir)</methodname> and
  192. <methodname>getImgDir()</methodname> allow you to specify the directory for
  193. storing <acronym>CAPTCHA</acronym> images. The default is
  194. "<filename>./images/captcha/</filename>", relative to the bootstrap script.
  195. </para>
  196. </listitem>
  197. <listitem>
  198. <para>
  199. <methodname>setImgUrl($imgUrl)</methodname> and
  200. <methodname>getImgUrl()</methodname> allow you to specify the relative path to
  201. a <acronym>CAPTCHA</acronym> image to use for <acronym>HTML</acronym> markup.
  202. The default is "<filename>/images/captcha/</filename>".
  203. </para>
  204. </listitem>
  205. <listitem>
  206. <para>
  207. <methodname>setSuffix($suffix)</methodname> and
  208. <methodname>getSuffix()</methodname> allow you to specify the filename suffix
  209. for the <acronym>CAPTCHA</acronym> image. The default is
  210. "<filename>.png</filename>". Note: changing this value will not change the type
  211. of the generated image.
  212. </para>
  213. </listitem>
  214. <listitem>
  215. <para>
  216. <methodname>setDotNoiseLevel($level)</methodname> and
  217. <methodname>getDotNoiseLevel()</methodname>, along with
  218. <methodname>setLineNoiseLevel($level)</methodname> and
  219. <methodname>getLineNoiseLevel()</methodname>,
  220. allow you to control how much "noise" in the form of random dots and lines the
  221. image would contain. Each unit of <varname>$level</varname> produces one random
  222. dot or line. The default is 100 dots and 5 lines. The noise is added twice -
  223. before and after the image distortion transformation.
  224. </para>
  225. </listitem>
  226. </itemizedlist>
  227. <para>
  228. All of the above options may be passed to the
  229. constructor by simply removing the 'set' method prefix and casting
  230. the initial letter to lowercase: "suffix", "height", "imgUrl", etc.
  231. </para>
  232. </sect2>
  233. <sect2 id="zend.captcha.adapters.recaptcha">
  234. <title>Zend_Captcha_ReCaptcha</title>
  235. <para>
  236. The <classname>Zend_Captcha_ReCaptcha</classname> adapter uses <link
  237. linkend="zend.service.recaptcha">Zend_Service_ReCaptcha</link>
  238. to generate and validate <acronym>CAPTCHA</acronym>s. It exposes the following
  239. methods:
  240. </para>
  241. <itemizedlist>
  242. <listitem>
  243. <para>
  244. <methodname>setPrivKey($key)</methodname> and
  245. <methodname>getPrivKey()</methodname> allow you to specify the private key to
  246. use for the ReCaptcha service. This must be specified during construction,
  247. although it may be overridden at any point.
  248. </para>
  249. </listitem>
  250. <listitem>
  251. <para>
  252. <methodname>setPubKey($key)</methodname> and
  253. <methodname>getPubKey()</methodname> allow you to specify the public key to use
  254. with the ReCaptcha service. This must be specified during construction, although
  255. it may be overridden at any point.
  256. </para>
  257. </listitem>
  258. <listitem>
  259. <para>
  260. <methodname>setService(Zend_Service_ReCaptcha $service)</methodname> and
  261. <methodname>getService()</methodname> allow you to set and get
  262. the ReCaptcha service object.
  263. </para>
  264. </listitem>
  265. <listitem>
  266. <para>
  267. <methodname>isValid($value, $context = null)</methodname> validates the user's
  268. input against the ReCaptcha service. <varname>$value</varname> is an array with the following
  269. keys:
  270. <itemizedlist>
  271. <listitem>
  272. <para>
  273. <varname>recaptcha_challenge_field</varname> - Value of the ReCaptcha widget's
  274. challenge field (hidden)
  275. </para>
  276. </listitem>
  277. <listitem>
  278. <para>
  279. <varname>recaptcha_response_field</varname> - Value of the ReCaptcha widget's
  280. user input field
  281. </para>
  282. </listitem>
  283. </itemizedlist>
  284. </para>
  285. </listitem>
  286. </itemizedlist>
  287. </sect2>
  288. </sect1>
  289. <!--
  290. vim:se ts=4 sw=4 et:
  291. -->