Returns a generic JavaScript code which uses FormZ API to validate a
condition which was registered in a single JavaScript file (which is
filled in the `$javaScriptFiles` attribute of the PHP condition class).

@param array $data
@return string
178901
protected function getDefaultJavaScriptCall(array $data)
    {
        $conditionName = addslashes(get_class($this));
        $data = ArrayService::get()->arrayToJavaScriptJson($data);

        return <<<JS
Fz.Condition.validateCondition('$conditionName', form, $data)
JS;
    }
207491
public function selected( array $data )
    {
        if ( isset( $data['tags'] ) && is_string( $data['tags'] ) )
        {
            $data['tags'] = explode( static::TAG_SEPARATOR, $data['tags'] );
        }

        if ( isset( $data['tagIds'] ) && is_string( $data['tagIds'] ) )
        {
            $data['tagIds'] = explode( static::TAG_SEPARATOR, $data['tagIds'] );
        }

        if ( isset( $data['localeTags'] ) && is_string( $data['localeTags'] ) )
        {
            $data['localeTags'] = explode( static::TAG_SEPARATOR, $data['localeTags'] );
        }

        if ( isset( $data['proxyData'] ) && is_string( $data['proxyData'] ) )
        {
            $data['proxyData'] = $this->parseProxyData( $data['proxyData'] );
        }

        return parent::selected( $data );
    }
577049
private function _inlineScript($data = null) {
        // no data?
        if(is_null($data))
            return false;

        // compress
        $data = Algorithms::js($data, $this->_config['config']['js']);

        // keep a reference to avoid duplicates
        $hash = md5($data);
        if(in_array($hash, $this->inline['js']))
            return false;
        else $this->inline['js'][] = $hash;

        // output
        return "<script>{$data}</script>";
    }
1158351
private static function validateStore($data)
    {
        // custom messages for validation
        $validationMessagesTemplate = array(
          'required'=> "{{field}} can't be empty",
          'email'=>"{{field}} must be an email",
          'integer'=>"{{field}} must be a number",
        );
        $validationMessages = array();
        $validationRules = array();
        $validationValues= array();

        //setup title validation
        $isOneTitleFilled = false;
        foreach ($data['title'] as $title){
            if($title !== '') {
                $isOneTitleFilled = true;
            }
        }
        if (!$isOneTitleFilled) {
            foreach ($data['languages'] as $lang) {
                $validationMessages["title_" . $lang['slug'].".required"] = str_replace("{{field}}", "Title", $validationMessagesTemplate["required"]);
                $validationRules["title_" . $lang['slug']] = 'required';
                $validationValues["title_" . $lang['slug']] = $data['title'][$lang['slug']];
            }
        }

        // Custom fields validation
        foreach($data['formData'] as $formData){ // loop throw form data
            if ($formData['required']) { // check if input is required
                if(!$formData['translatable']) { // if input is not multilanguage
                    foreach ($data['languages'] as $lang){
                        // if it is not a file return required error
                        if($formData['type']['inputType'] != "image" && $formData['type']['inputType'] != "file") {
                            if(isset($data['status']) && $data['status'][$lang['slug']] != 'draft') {
                                $validationMessages[$formData['slug'] . "_" . $lang['slug'].".required"] = str_replace("{{field}}", $formData['name'], $validationMessagesTemplate["required"]);
                                $validationRules[$formData['slug'] . "_" . $lang['slug']] = 'required';
                                $validationValues[$formData['slug']. "_" . $lang['slug']] = $formData['value'];
                            }
                        }else{
                            if($formData['translatable']) {
                                $imageKey = $formData['slug']."_".$lang['slug'];
                            }else{
                                $imageKey = $formData['slug'];
                            }

                            if(isset($data['status']) && $data['status'][$lang['slug']] != 'draft') {
                                $validationMessages[$formData['slug'] . "_" . $lang['slug'].".required"] = str_replace("{{field}}", $formData['name'], $validationMessagesTemplate["required"]);
                                $validationRules[$formData['slug'] . "_" . $lang['slug']] = 'required';
                            }

                            if(!isset($data['files'][$imageKey])) {  // errors if images or files are not set and the language is status
                                if(isset($data['status']) && $data['status'][$lang['slug']] != 'draft') {
                                    $validationValues[$formData['slug']. "_" . $lang['slug']] = "";
                                }
                            }else{
                                $validationValues[$formData['slug']. "_" . $lang['slug']] = $data['files'][$imageKey];
                            }
                        }
                    }

                }else{ // if input is multilanguage
                    if ($formData['value']) {
                        foreach($formData['value'] as $langSlug => $value){ // loop throw the values for each language
                            if(isset($data['status']) && !is_integer($langSlug) && $data['status'][$langSlug] != 'draft') {
                                $validationMessages[$formData['slug'] . "_" . $langSlug.".required"] = str_replace("{{field}}", $formData['name'], $validationMessagesTemplate["required"]);
                                $validationRules[$formData['slug'] . "_" . $langSlug] = 'required';
                            }

                            //if is dropdown or checbox
                            if(is_array($value)) {
                                if(isset($data['status']) && !is_integer($langSlug) && $data['status'][$langSlug] != 'draft') {
                                    $validationValues[$formData['slug']. "_" . $langSlug] = $value;
                                }
                            }else {
                                if(isset($data['status']) && !is_integer($langSlug) && $data['status'][$langSlug] != 'draft') {
                                    $validationValues[$formData['slug']. "_" . $langSlug] = $value;
                                }
                            }
                        }
                    }
                }
            }

            /*
             * CUSTOM validations like email, number etc
             * */
            switch ($formData['type']['inputType']){
            case "email":
                foreach ($data['languages'] as $lang){
                    if(isset($data['status']) && $data['status'][$lang['slug']] != 'draft') {
                        $validationMessages[$formData['slug'] . "_" . $lang['slug'] . ".email"] = str_replace("{{field}}", $formData['name'], $validationMessagesTemplate["email"]);

                        //set email rule
                        if(isset($validationRules[$formData['slug'] . "_" . $lang['slug']])) {
                            $validationRules[$formData['slug'] . "_" . $lang['slug']] .= '|email';
                        }else{
                            $validationRules[$formData['slug'] . "_" . $lang['slug']] = 'email';
                        }
                    }
                }
                break;
            case "number":
                foreach ($data['languages'] as $lang){
                    if(isset($data['status']) && $data['status'][$lang['slug']] != 'draft') {
                        $validationMessages[$formData['slug'] . "_" . $lang['slug'] . ".integer"] = str_replace("{{field}}", $formData['name'], $validationMessagesTemplate["integer"]);

                        //set email rule
                        if(isset($validationRules[$formData['slug'] . "_" . $lang['slug']])) {
                            $validationRules[$formData['slug'] . "_" . $lang['slug']] .= '|integer';
                        }else{
                            $validationRules[$formData['slug'] . "_" . $lang['slug']] = 'integer';
                        }
                    }
                }
                break;
            }
        }

        // Validate tags
        if($data['isFeaturedImageRequired']) {
            if(!isset($data['files']) || !isset($data['files']['featuredImage']) || (isset($data['files']['featuredImage']) && !count($data['files']['featuredImage']))) {
                $validationMessages["files_featuredImage.required"] = str_replace("{{field}}", "Featured Image ", $validationMessagesTemplate["required"]);
                $validationRules["files_featuredImage"] = 'required';
                $validationValues["featuredImage"] = "NONE";
            }
        }

        // Validatate categories
        if($data['isCategoryRequired']) {
            $validationMessages["categories.required"] = str_replace("{{field}}", "Categories", $validationMessagesTemplate["required"]);
            $validationRules["categories"] = 'required';
            $validationValues["categories"] = $data['selectedCategories'];
        }

        // Validate tags
        if($data['isTagRequired']) {
            foreach($data['selectedTags'] as $langKey => $tags){
                if(isset($data['status']) && $data['status'][$langKey] != 'draft') {
                    $validationMessages["tags_" . $langKey .".required"] = str_replace("{{field}}", "Tags", $validationMessagesTemplate["required"]);
                    $validationRules["tags_" . $langKey] = 'required';
                    $validationValues["tags_" . $langKey] = $data['selectedTags'][$langKey];
                }
            }
        }

        $validator = \Illuminate\Support\Facades\Validator::make($validationValues, $validationRules, $validationMessages);
        return $validator->messages();
    }
1371778
private function confirm($data){
		$content = '';
		$hidden = '';
		foreach( $this->init_cols as $column_name ){
			$column_definition = $this->table_definition->columns->$column_name;
			// var_dump($column_definition);
			if( !$this->exdb->is_editable_column( $column_definition ) ){
				continue;
			}
			$type_info = $this->exdb->form_elements()->get_type_info($column_definition->type);
			$form_elm = $this->form_endpoint->render(
				$type_info['templates']['preview'],
				array(
					'value'=>@$data[$column_definition->name],
					'name'=>@$column_definition->name,
					'def'=>@$column_definition,
				)
			);
			$content .= $this->form_endpoint->render(
				'form_elms_unit.html',
				array(
					'label'=>@$column_definition->label,
					'content'=>$form_elm,
					'def'=>@$column_definition,
					'error'=>@$errors[$column_definition->name],
				)
			);
			$hidden .= '<input type="hidden" name="'.htmlspecialchars($column_definition->name).'" value="'.htmlspecialchars(@$data[$column_definition->name]).'"/>';
		}

		$rtn = $this->form_endpoint->render(
			'form_edit_confirm.html',
			array(
				'href_backto'=>$this->options['href_backto'],
				'action'=>'?',
				'content'=>$content,
				'hidden'=>$hidden,
			)
		);

		$rtn = $this->form_endpoint->wrap_theme($rtn);
		return $rtn;
	}
1110472
public function generate(array $data): string
    {
        /** @var RecordFinder $recordFinder */
        $recordFinder = GeneralUtility::makeInstance(RecordFinder::class);
        $staticdataUids = $recordFinder->findUidsOfStaticdata();
        // Return only one element
        return (string)current($staticdataUids);
    }
660662
public function xssFunc($data)
    {
        if (!\is_array($data)) {
            return Security::detectXss($data);
        }

        $results = Security::detectXssFromArray($data);
        $results_parts = array_map(function($value, $key) {
            return $key.': \''.$value . '\'';
        }, array_values($results), array_keys($results));

        return implode(', ', $results_parts);
    }
839586
public static function validate($data) {
        if ( ! is_array($data) ) return '$data must be an array';
        $id = U::get($data, 'id');
        if ( $id ) {
            if ( ! is_int($id) ) return "id must be an an integer";
        }
        $uk1 = U::get($data, 'uk1');
        if ( $uk1 ) {
            if ( ! is_string($uk1) ) return "uk1 must be a string";
            if ( strlen($uk1) < 1 || strlen($uk1) > 150 ) return "uk1 must be no more than 150 characters";
        }
        $sk1 = U::get($data, 'sk1');
        if ( $sk1 ) {
            if ( ! is_string($sk1) ) return "sk1 must be a string";
            if ( strlen($sk1) < 1 || strlen($sk1) > 75 ) return "sk1 must be no more than 75 characters";
        }
        $tk1 = U::get($data, 'tk1');
        if ( $tk1 ) {
            if ( ! is_string($tk1) ) return "tk1 must be a string";
            if ( strlen($tk1) < 1 ) return "tk1 cannot be empty";
        }
        $co1 = U::get($data, 'co1');
        if ( $co1 ) {
            if ( ! is_string($co1) ) return "co1 must be a string";
            if ( strlen($co1) < 1 || strlen($co1) > 150 ) return "co1 must be no more than 150 characters";
        }
        $co2 = U::get($data, 'co2');
        if ( $co2 ) {
            if ( ! is_string($co2) ) return "co2 must be a string";
            if ( strlen($co2) < 1 || strlen($co2) > 150 ) return "co2 must be no more than 150 characters";
        }
        return true;
    }
80609
private function httpBuildQuery(array $data): string
    {
        $queryString = http_build_query($data, '', '&');

        return $this->postProcessHttpQueryString($queryString, $data);
    }
105379
private static function wringer($data)
    {
        if (is_object($data)) {
            if ($data instanceof \BootPress\Blog\Twig\Object) {
                $data = $data->properties + $data->methods;
            } elseif ($data instanceof \BootPress\Blog\Twig\Page) {
                $data = $data->html + $data->methods;
            } else {
                $data = get_class($data).' Object';
            }
        }
        if (is_array($data)) {
            $cloner = array();
            foreach ($data as $key => $value) {
                $cloner[$key] = self::wringer($value);
            }

            return $cloner;
        }
        if (is_string($data)) {
            $data = str_replace(array("\r", "\n", "\t"), array('\\r', '\\n', '\\t'), $data);
        }

        return $data;
    }
1258273
function validation($data, $files) {
        global $USER;
        $errors = parent::validation($data, $files);
        $reason = null;

        // ignore submitted username
        if (!$user = authenticate_user_login($USER->username, $data['password'], true, $reason, false)) {
            $errors['password'] = get_string('invalidlogin');
            return $errors;
        }

        if ($data['newpassword1'] <> $data['newpassword2']) {
            $errors['newpassword1'] = get_string('passwordsdiffer');
            $errors['newpassword2'] = get_string('passwordsdiffer');
            return $errors;
        }

        if ($data['password'] == $data['newpassword1']){
            $errors['newpassword1'] = get_string('mustchangepassword');
            $errors['newpassword2'] = get_string('mustchangepassword');
            return $errors;
        }

        if (user_is_previously_used_password($USER->id, $data['newpassword1'])) {
            $errors['newpassword1'] = get_string('errorpasswordreused', 'core_auth');
            $errors['newpassword2'] = get_string('errorpasswordreused', 'core_auth');
        }

        $errmsg = '';//prevents eclipse warnings
        if (!check_password_policy($data['newpassword1'], $errmsg)) {
            $errors['newpassword1'] = $errmsg;
            $errors['newpassword2'] = $errmsg;
            return $errors;
        }

        return $errors;
    }
875388
protected function formatWeappMessage(array $data = [])
    {
        $params = $this->baseFormat($data, $this->weappMessage);

        $params['data'] = $this->formatData($params['data'] ?? []);

        return $params;
    }
111767
public function showHtmlFormGroup($data = [])
    {
        $html = '<div class="form-group">
                                <label class="col-md-3 control-label">' . $data['label'] . '</label>
                                <div class="col-md-' . $data['col'] . '">
                                    <input name="' . $data['name'] . '" value="' . $data['value'] . '" placeholder="' . $data['placeholder'] . '" type="' . $data['type'] . '" class="form-control">
                                    <p class="help-block">' . $data['help-block'] . '</p>
                                </div>
                            </div>';

        return $html;
    }
708332
public function validate(array $data)
    {
        $rules = $this->getRules();
        foreach ($rules as $field => $rule) {
            if ((isset($rule['required']) && $rule['required'] === true && isset($data[$field]))
                || ((!isset($rule['required']) || !$rule['required'])) && isset($data[$field])) {
                foreach ($rule as $key => $value) {
                    if ($key !== 'required') {
                        foreach ($value as $validator) {
                            if (!is_array($validator)) {
                                $validator = [$validator];
                            }
                            if (!Validator::validate($validator[0], $field,
                                    $data, $validator)) {
                                $this->addError($field,
                                    isset($rule['errorMessage']) ? $rule['errorMessage']
                                            : false);
                            }
                        }
                    }
                }
            } elseif (isset($rule['required']) && $rule['required'] === true) {
                $this->addError($field,
                    isset($rule['errorMessage']) ? $rule['errorMessage'] : false);
            }
        }
        return !$this->hasErrors();
    }
127311
public static function check(array $data = null)
    {
        if ($data === null) {
            return self::$defaults;
        }
        foreach (self::$defaults as $section => $default) {
            if (array_key_exists($section, $data)) {
                $value = $data[$section];
                if (is_array($default)) {
                    if (!is_array($value)) {
                        throw new InvalidSection($section, 'must be an array');
                    }
                    if (array_values($value) !== $value) {
                        throw new InvalidSection($section, 'must be a numeric array');
                    }
                } elseif (is_array($value)) {
                    throw new InvalidSection($section, 'must be a string');
                }
            } else {
                if (in_array($section, self::$required)) {
                    throw new InvalidSection($section, 'is required, but not specified');
                }
                $data[$section] = $default;
            }
        }
        if (!in_array($data['version'], [3, '3'], true)) {
            throw new UnsupportedVersion($data['version']);
        }
        if (count(array_diff_key($data['sourcesContent'], $data['sources'])) > 0) {
            throw new InvalidSection('sourcesContent', 'does not correspond to sources');
        }
        return $data;
    }
692569
function getValidationScript($options = null)
    {
        $regex = isset($this->_data[$this->name]) ? $this->_data[$this->name] : $options;

        return array("  var regex = " . $regex . ";\n", "{jsVar} != '' && !regex.test({jsVar})");
    }
817390
private function html($data)
    {
        if (!is_array($data)) {
            return $data;
        }
        $return = '';
        foreach ($data as $key => $value) {
            $return .= '<li>' . $key . ': ' . (is_array($value) ? $this->html($value) : $value) . '</li>';
        }
        return '<ul>' . $return . '</ul>';
    }