/** * Returns a field in specified format * * @param moscomprofilerFields $field * @param moscomprofilerUser $user * @param string $output 'html', 'xml', 'json', 'php', 'csvheader', 'csv', 'rss', 'fieldslist', 'htmledit' * @param string $reason 'profile' for user profile view, 'edit' for profile edit, 'register' for registration, 'list' for user-lists * @param int $list_compare_types IF reason == 'search' : 0 : simple 'is' search, 1 : advanced search with modes, 2 : simple 'any' search * @return mixed */ function getField(&$field, &$user, $output, $reason, $list_compare_types) { global $ueConfig; $value = $user->get($field->name); switch ($output) { case 'html': case 'rss': if ($value == null) { return ''; } elseif ($ueConfig['allow_website'] == 1) { $oReturn = $this->_explodeCBvalues($value); if (count($oReturn) < 2) { $oReturn[1] = $oReturn[0]; } return '<a href="http://' . htmlspecialchars($oReturn[0]) . '" target="_blank" rel="nofollow">' . htmlspecialchars($oReturn[1]) . '</a>'; } else { return htmlspecialchars($value); } break; case 'htmledit': if ($field->rows != 2) { $oReturn = $this->_fieldEditToHtml($field, $user, $reason, 'input', 'text', $value, ''); } else { $oValuesArr = $this->_explodeCBvalues($value); if (count($oValuesArr) < 2) { $oValuesArr[1] = ''; } $oReturn = '<span class="webUrlSpan">' . '<span class="subTitleSpan">' . _UE_WEBURL . ':</span>' . '<span class="subFieldSpan">' . $this->_fieldEditToHtml($field, $user, $reason, 'input', 'text', $oValuesArr[0], '') . '</span></span>'; $saveFieldName = $field->name; $saveFieldTitle = $field->title; $field->name = $saveFieldName . 'Text'; $field->title = $field->title . ': ' . _UE_WEBTEXT; $oReturn .= '<span class="webTextSpan">' . '<span class="subTitleSpan">' . _UE_WEBTEXT . ':</span>' . '<span class="subFieldSpan">' . $this->_fieldEditToHtml($field, $user, $reason, 'input', 'text', $oValuesArr[1], '') . '</span></span>'; $field->name = $saveFieldName; $field->title = $saveFieldTitle; } if ($reason == 'search') { $oReturn = $this->_fieldSearchModeHtml($field, $user, $oReturn, 'text', $list_compare_types); } return $oReturn; break; case 'json': case 'php': case 'xml': case 'csvheader': case 'fieldslist': case 'csv': default: return parent::getField($field, $user, $output, $reason, $list_compare_types); break; } return '*' . CBTxt::T('Unknown Output Format') . '*'; }
/** * 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; }
/** * @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; }