コード例 #1
0
 /**
  * Validator:
  * Validates $value for $field->required and other rules
  * Override
  *
  * @param  moscomprofilerFields  $field
  * @param  moscomprofilerUser    $user        RETURNED populated: touch only variables related to saving this field (also when not validating for showing re-edit)
  * @param  string                $columnName  Column to validate
  * @param  string                $value       (RETURNED:) Value to validate, Returned Modified if needed !
  * @param  array                 $postdata    Typically $_POST (but not necessarily), filtering required.
  * @param  string                $reason      'edit' for save profile edit, 'register' for registration, 'search' for searches
  * @return boolean                            True if validate, $this->_setErrorMSG if False
  */
 function validate(&$field, &$user, $columnName, &$value, &$postdata, $reason)
 {
     $validate = parent::validate($field, $user, $columnName, $value, $postdata, $reason);
     if ($validate && $value != null) {
         if (!cbIsValidEmail($value)) {
             $this->_setValidationError($field, $user, $reason, sprintf(_UE_EMAIL_NOVALID, htmlspecialchars($value)));
             $validate = false;
         }
     }
     return $validate;
 }
コード例 #2
0
ファイル: cb.core.php プロジェクト: bobozhangshao/HeartCare
 /**
  * Validator:
  * Validates $value for $field->required and other rules
  * Override
  *
  * @param  FieldTable  $field
  * @param  UserTable   $user        RETURNED populated: touch only variables related to saving this field (also when not validating for showing re-edit)
  * @param  string      $columnName  Column to validate
  * @param  string      $value       (RETURNED:) Value to validate, Returned Modified if needed !
  * @param  array       $postdata    Typically $_POST (but not necessarily), filtering required.
  * @param  string      $reason      'edit' for save user edit, 'register' for save registration
  * @return boolean                  True if validate, $this->_setErrorMSG if False
  */
 public function validate(&$field, &$user, $columnName, &$value, &$postdata, $reason)
 {
     $isRequired = $this->_isRequired($field, $user, $reason);
     $col = $field->get('name');
     $colChoice = $col . '__choice';
     $choice = stripslashes(cbGetParam($postdata, $colChoice));
     switch ($choice) {
         case 'upload':
             if (!$field->params->get('audio_allow_uploads', 1)) {
                 $this->_setValidationError($field, $user, $reason, CBTxt::T('UE_NOT_AUTHORIZED', 'You are not authorized to view this page!'));
                 return false;
             } elseif (!isset($value['tmp_name']) || empty($value['tmp_name']) || $value['error'] != 0 || !is_uploaded_file($value['tmp_name'])) {
                 if ($isRequired) {
                     $this->_setValidationError($field, $user, $reason, CBTxt::T('Please select a audio file before uploading'));
                 }
                 return false;
             } else {
                 $uploadSizeLimitMax = $field->params->get('fieldValidateAudio_sizeMax', 1024);
                 $uploadSizeLimitMin = $field->params->get('fieldValidateAudio_sizeMin', 0);
                 $uploadExtensionLimit = $this->allowedExtensions();
                 $uploadedExt = strtolower(preg_replace('/[^-a-zA-Z0-9_]/', '', pathinfo($value['name'], PATHINFO_EXTENSION)));
                 if (!$uploadedExt || !in_array($uploadedExt, $uploadExtensionLimit)) {
                     $this->_setValidationError($field, $user, $reason, sprintf(CBTxt::T('Please upload only %s'), implode(', ', $uploadExtensionLimit)));
                     return false;
                 }
                 $uploadedSize = $value['size'];
                 if ($uploadedSize / 1024 > $uploadSizeLimitMax) {
                     $this->_setValidationError($field, $user, $reason, sprintf(CBTxt::T('The audio file size exceeds the maximum of %s'), $this->formattedFileSize($uploadSizeLimitMax * 1024)));
                     return false;
                 }
                 if ($uploadedSize / 1024 < $uploadSizeLimitMin) {
                     $this->_setValidationError($field, $user, $reason, sprintf(CBTxt::T('The audio file is too small, the minimum is %s'), $this->formattedFileSize($uploadSizeLimitMin * 1024)));
                     return false;
                 }
             }
             break;
         case 'link':
             if (!$field->params->get('audio_allow_links', 1)) {
                 $this->_setValidationError($field, $user, $reason, CBTxt::T('UE_NOT_AUTHORIZED', 'You are not authorized to view this page!'));
                 return false;
             }
             $validated = parent::validate($field, $user, $columnName, $value, $postdata, $reason);
             if ($validated && $value !== '' && $value !== null) {
                 $linkExists = false;
                 try {
                     $request = new \GuzzleHttp\Client();
                     $header = $request->head($value);
                     if ($header !== false && $header->getStatusCode() == 200) {
                         $linkExists = true;
                     }
                 } catch (Exception $e) {
                 }
                 if (!$linkExists) {
                     $this->_setValidationError($field, $user, $reason, CBTxt::T('Please input a audio file url before linking'));
                     return false;
                 }
                 $linkExtLimit = $this->allowedExtensions();
                 $linkExt = strtolower(pathinfo($value, PATHINFO_EXTENSION));
                 if (!$linkExt || !in_array($linkExt, $linkExtLimit)) {
                     $this->_setValidationError($field, $user, $reason, sprintf(CBTxt::T('Please link only %s'), implode(', ', $linkExtLimit)));
                     return false;
                 }
             }
             return $validated;
             break;
         default:
             $valCol = $field->get('name');
             if ($isRequired && (!$user || !isset($user->{$valCol}) || !$user->get($valCol))) {
                 if (!$value) {
                     $this->_setValidationError($field, $user, $reason, CBTxt::T('UE_FIELDREQUIRED', 'This Field is required'));
                     return false;
                 }
             }
             break;
     }
     return true;
 }
コード例 #3
0
ファイル: cbinvites.php プロジェクト: kosmosby/medicine-prof
	/**
	 * @param FieldTable $field
	 * @param UserTable  $user
	 * @param string     $columnName
	 * @param string     $value
	 * @param array      $postdata
	 * @param string     $reason
	 * @return bool
	 */
	public function validate( &$field, &$user, $columnName, &$value, &$postdata, $reason )
	{
		$validated				=	parent::validate( $field, $user, $columnName, $value, $postdata, $reason );

		if ( $validated ) {
			if ( ( $user->get( $columnName ) != $value ) && $value ) {
				$invite			=	new cbinvitesInviteTable();

				$invite->load( array( 'code' => $value ) );

				if ( ! $invite->get( 'id' ) ) {
					$this->_setValidationError( $field, $user, $reason, CBTxt::T( 'Invite code not valid.' ) );

					$validated	=	false;
				} elseif ( $invite->isAccepted() && ( $user->get( 'id' ) != $invite->get( 'user' ) ) ) {
					$this->_setValidationError( $field, $user, $reason, CBTxt::T( 'Invite code already used.' ) );

					$validated	=	false;
				}
			}
		}

		return $validated;
	}