* @license LGPL, see license.txt for details * @link http://www.php-tools.net */ class patForms_Rule_URL extends patForms_Rule { /** * name of the rule * * @abstract * @access private */ var $ruleName = 'URL'; /** * Initialize validation codes using gettext * * Overwrite this function to add element's error codes * * @access protected * @return bool $success Always returns true. * @see $attributeDefaults */ function loadValidatiorErrorCodes() { $this->validatorErrorCodes = array( 1 => patI18n::dgettext('patForms', 'The URL has an invalid syntax.'), ); return true; } /** * method called by patForms or any patForms_Element to validate the * element or the form. * * @access public * @param object patForms form object */ function applyRule(&$element, $type = PATFORMS_RULE_BEFORE_VALIDATION) { $value = $element->getValue(false); if (empty($value)) { return true; } // prepend server name for local URLs if ('/' == $value[0]) { WBClass::load('WBString'); $value = WBString::replaceSuperPlaceholders('http://[[SERVER]]' . $value); } $ereg = "(http|ftp|https)://[-A-Za-z0-9._]+(\/([A-Za-z0-9\-\_\.\!\~\*\'\(\)\%\?]+))*/?"; if (!eregi($ereg, $value)) { $this->addValidationError(1); return false; } return true; } } ?>