Figlet.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. * Required packages
  23. */
  24. require_once 'HTML/QuickForm/CAPTCHA.php';
  25. require_once 'Text/CAPTCHA/Driver/Figlet.php';
  26. /**
  27. * Element for HTML_QuickForm to display a CAPTCHA figlet
  28. *
  29. * The HTML_QuickForm_CAPTCHA package adds an element to the
  30. * HTML_QuickForm package to display a CAPTCHA figlet
  31. *
  32. * Options for the element
  33. * <ul>
  34. * <li>'width' (integer) Width of figlet (default is 200px)</li>
  35. * <li>'output' (string) Output format: "html", "text" or
  36. * "javascript" (default is "html").</li>
  37. * <li>'length' (integer) number of letters in the figlet
  38. * (default is 6)</li>
  39. * <li>'options' (array) only index supported is "font_file", which
  40. * should either be one figlet font file path,
  41. * or an array of figlet font file paths
  42. * (one we be picked randomly)</li>
  43. * <li>'sessionVar' (string) name of session variable containing
  44. * the Text_CAPTCHA instance (defaults to
  45. * _HTML_QuickForm_CAPTCHA.)</li>
  46. * </ul>
  47. *
  48. * This package requires the use of a PHP session.
  49. *
  50. * @category HTML
  51. * @package HTML_QuickForm_CAPTCHA
  52. * @author Philippe Jausions <Philippe.Jausions@11abacus.com>
  53. * @copyright 2006-2008 by Philippe Jausions / 11abacus
  54. * @license http://www.opensource.org/licenses/bsd-license.php New BSD
  55. * @version Release: 0.3.0
  56. * @link http://pear.php.net/package/HTML_QuickForm_CAPTCHA
  57. * @see Text_CAPTCHA_Driver_Figlet
  58. */
  59. class HTML_QuickForm_CAPTCHA_Figlet extends HTML_QuickForm_CAPTCHA
  60. {
  61. /**
  62. * Default options
  63. *
  64. * @var array
  65. * @access protected
  66. */
  67. var $_options = array(
  68. 'sessionVar' => '_HTML_QuickForm_CAPTCHA',
  69. 'output' => 'html',
  70. 'width' => 200,
  71. 'length' => 6,
  72. 'phrase' => null,
  73. );
  74. /**
  75. * CAPTCHA driver
  76. *
  77. * @var string
  78. * @access protected
  79. */
  80. var $_CAPTCHA_driver = 'Figlet';
  81. /**
  82. * Returns the HTML for the CAPTCHA
  83. *
  84. * This can be overwritten by sub-classes for specific output behavior
  85. * (for instance the Image CAPTCHA displays an image)
  86. *
  87. * @access public
  88. * @return string
  89. */
  90. function toHtml()
  91. {
  92. $result = $this->_initCAPTCHA();
  93. if (PEAR::isError($result)) {
  94. return $result;
  95. }
  96. $attr = $this->_attributes;
  97. unset($attr['type']);
  98. unset($attr['value']);
  99. unset($attr['name']);
  100. $html = $this->_getTabs()
  101. . '<div' . $this->_getAttrString($attr) . '>'
  102. . $_SESSION[$this->_options['sessionVar']]->getCAPTCHA()
  103. . '</div>';
  104. return $html;
  105. }
  106. }
  107. /**
  108. * Registers the class with QuickForm
  109. */
  110. if (class_exists('HTML_QuickForm')) {
  111. HTML_QuickForm::registerElementType('CAPTCHA_Figlet',
  112. 'HTML/QuickForm/CAPTCHA/Figlet.php',
  113. 'HTML_QuickForm_CAPTCHA_Figlet');
  114. }
  115. ?>