Figlet.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. /**
  4. * Element for HTML_QuickForm to display a CAPTCHA figlet
  5. *
  6. * The HTML_QuickForm_CAPTCHA package adds an element to the
  7. * HTML_QuickForm package to display a CAPTCHA figlet.
  8. *
  9. * This package requires the use of a PHP session.
  10. *
  11. * PHP versions 4 and 5
  12. *
  13. * @category HTML
  14. * @package HTML_QuickForm_CAPTCHA
  15. * @author Philippe Jausions <Philippe.Jausions@11abacus.com>
  16. * @copyright 2006-2008 by Philippe Jausions / 11abacus
  17. * @license http://www.opensource.org/licenses/bsd-license.php New BSD
  18. * @version CVS: $Id: Figlet.php,v 1.1 2008/04/26 23:27:30 jausions Exp $
  19. * @link http://pear.php.net/package/HTML_QuickForm_CAPTCHA
  20. */
  21. /**
  22. * Element for HTML_QuickForm to display a CAPTCHA figlet
  23. *
  24. * The HTML_QuickForm_CAPTCHA package adds an element to the
  25. * HTML_QuickForm package to display a CAPTCHA figlet
  26. *
  27. * Options for the element
  28. * <ul>
  29. * <li>'width' (integer) Width of figlet (default is 200px)</li>
  30. * <li>'output' (string) Output format: "html", "text" or
  31. * "javascript" (default is "html").</li>
  32. * <li>'length' (integer) number of letters in the figlet
  33. * (default is 6)</li>
  34. * <li>'options' (array) only index supported is "font_file", which
  35. * should either be one figlet font file path,
  36. * or an array of figlet font file paths
  37. * (one we be picked randomly)</li>
  38. * <li>'sessionVar' (string) name of session variable containing
  39. * the Text_CAPTCHA instance (defaults to
  40. * _HTML_QuickForm_CAPTCHA.)</li>
  41. * </ul>
  42. *
  43. * This package requires the use of a PHP session.
  44. *
  45. * @category HTML
  46. * @package HTML_QuickForm_CAPTCHA
  47. * @author Philippe Jausions <Philippe.Jausions@11abacus.com>
  48. * @copyright 2006-2008 by Philippe Jausions / 11abacus
  49. * @license http://www.opensource.org/licenses/bsd-license.php New BSD
  50. * @version Release: 0.3.0
  51. * @link http://pear.php.net/package/HTML_QuickForm_CAPTCHA
  52. * @see Text_CAPTCHA_Driver_Figlet
  53. */
  54. class HTML_QuickForm_CAPTCHA_Figlet extends HTML_QuickForm_CAPTCHA
  55. {
  56. /**
  57. * Default options
  58. *
  59. * @var array
  60. * @access protected
  61. */
  62. var $_options = array(
  63. 'sessionVar' => '_HTML_QuickForm_CAPTCHA',
  64. 'output' => 'html',
  65. 'width' => 200,
  66. 'length' => 6,
  67. 'phrase' => null,
  68. );
  69. /**
  70. * CAPTCHA driver
  71. *
  72. * @var string
  73. * @access protected
  74. */
  75. var $_CAPTCHA_driver = 'Figlet';
  76. /**
  77. * Returns the HTML for the CAPTCHA
  78. *
  79. * This can be overwritten by sub-classes for specific output behavior
  80. * (for instance the Image CAPTCHA displays an image)
  81. *
  82. * @access public
  83. * @return string
  84. */
  85. function toHtml()
  86. {
  87. $result = $this->_initCAPTCHA();
  88. if (PEAR::isError($result)) {
  89. return $result;
  90. }
  91. $attr = $this->_attributes;
  92. unset($attr['type']);
  93. unset($attr['value']);
  94. unset($attr['name']);
  95. $html = $this->_getTabs()
  96. . '<div' . $this->_getAttrString($attr) . '>'
  97. . $_SESSION[$this->_options['sessionVar']]->getCAPTCHA()
  98. . '</div>';
  99. return $html;
  100. }
  101. }