コード例 #1
0
 /**
  * validate field in editing comment
  * @see extension/ezcomments/classes/ezcomFormTool#validateField($field, $value)
  */
 protected function validateField($field, $value)
 {
     switch ($field) {
         case 'website':
             return ezcomUtility::validateURLString($value);
         default:
             return true;
     }
     return true;
 }
コード例 #2
0
 public function testValidateURLString()
 {
     $url1 = 'javascript:alert();';
     $url2 = 'mailto:xc@ez.no';
     $url3 = 'JavaScript:alert()';
     $url4 = 'mAilto:xc@ez.no';
     $url5 = 'http://ez.no';
     $result = ezcomUtility::validateURLString($url1);
     $this->assertType('string', $result);
     $result = ezcomUtility::validateURLString($url2);
     $this->assertType('string', $result);
     $result = ezcomUtility::validateURLString($url3);
     $this->assertType('string', $result);
     $result = ezcomUtility::validateURLString($url4);
     $this->assertType('string', $result);
     $result = ezcomUtility::validateURLString($url5);
     $this->assertSame(true, $result);
 }
コード例 #3
0
 /**
  * Implement the validatation in adding comment
  * @see extension/ezcomments/classes/ezcomFormTool#validateField($field)
  */
 protected function validateField($field, $value)
 {
     switch ($field) {
         case 'website':
             return ezcomUtility::validateURLString($value);
         case 'email':
             // just validate anonymous's input email
             $user = eZUser::currentUser();
             if ($user->isAnonymous()) {
                 $result = eZMail::validate($value);
                 if (!$result) {
                     return ezpI18n::tr('ezcomments/comment/add', 'Not a valid email address.');
                 }
             }
             return true;
         case 'recaptcha':
             require_once 'recaptchalib.php';
             $ini = eZINI::instance('ezcomments.ini');
             $privateKey = $ini->variable('RecaptchaSetting', 'PrivateKey');
             $http = eZHTTPTool::instance();
             if ($http->hasPostVariable('recaptcha_challenge_field') && $http->hasPostVariable('recaptcha_response_field')) {
                 $ip = $_SERVER["REMOTE_ADDR"];
                 $challengeField = $http->postVariable('recaptcha_challenge_field');
                 $responseField = $http->postVariable('recaptcha_response_field');
                 $capchaResponse = recaptcha_check_answer($privateKey, $ip, $challengeField, $responseField);
                 if (!$capchaResponse->is_valid) {
                     return ezpI18n::tr('ezcomments/comment/add', 'The words you input are incorrect.');
                 }
             } else {
                 return ezpI18n::tr('ezcomments/comment/add', 'Captcha parameter error.');
             }
             return true;
         default:
             return true;
     }
 }