Exemplo n.º 1
0
function wpcf7_quiz_ajax_refill($items)
{
    if (!is_array($items)) {
        return $items;
    }
    $fes = wpcf7_scan_form_tags(array('type' => 'quiz'));
    if (empty($fes)) {
        return $items;
    }
    $refill = array();
    foreach ($fes as $fe) {
        $name = $fe['name'];
        $pipes = $fe['pipes'];
        if (empty($name)) {
            continue;
        }
        if ($pipes instanceof WPCF7_Pipes && !$pipes->zero()) {
            $pipe = $pipes->random_pipe();
            $question = $pipe->before;
            $answer = $pipe->after;
        } else {
            // default quiz
            $question = '1+1=?';
            $answer = '2';
        }
        $answer = wpcf7_canonicalize($answer);
        $refill[$name] = array($question, wp_hash($answer, 'wpcf7_quiz'));
    }
    if (!empty($refill)) {
        $items['quiz'] = $refill;
    }
    return $items;
}
Exemplo n.º 2
0
function wpcf7_file_form_enctype_filter($enctype)
{
    $multipart = (bool) wpcf7_scan_form_tags(array('type' => array('file', 'file*')));
    if ($multipart) {
        $enctype = 'multipart/form-data';
    }
    return $enctype;
}
Exemplo n.º 3
0
function wpcf7_acceptance_filter($accepted)
{
    if (!$accepted) {
        return $accepted;
    }
    $fes = wpcf7_scan_form_tags(array('type' => 'acceptance'));
    foreach ($fes as $fe) {
        $name = $fe['name'];
        $options = (array) $fe['options'];
        if (empty($name)) {
            continue;
        }
        $value = !empty($_POST[$name]) ? 1 : 0;
        $invert = (bool) preg_grep('%^invert$%', $options);
        if ($invert && $value || !$invert && !$value) {
            $accepted = false;
        }
    }
    return $accepted;
}
Exemplo n.º 4
0
function wpcf7_count_form_tag_handler($tag)
{
    $tag = new WPCF7_FormTag($tag);
    if (empty($tag->name)) {
        return '';
    }
    $targets = wpcf7_scan_form_tags(array('name' => $tag->name));
    $maxlength = $minlength = null;
    while ($targets) {
        $target = array_shift($targets);
        $target = new WPCF7_FormTag($target);
        if ('count' != $target->type) {
            $maxlength = $target->get_maxlength_option();
            $minlength = $target->get_minlength_option();
            break;
        }
    }
    if ($maxlength && $minlength && $maxlength < $minlength) {
        $maxlength = $minlength = null;
    }
    if ($tag->has_option('down')) {
        $value = (int) $maxlength;
        $class = 'wpcf7-character-count down';
    } else {
        $value = '0';
        $class = 'wpcf7-character-count up';
    }
    $atts = array();
    $atts['id'] = $tag->get_id_option();
    $atts['class'] = $tag->get_class_option($class);
    $atts['data-target-name'] = $tag->name;
    $atts['data-starting-value'] = $value;
    $atts['data-current-value'] = $value;
    $atts['data-maximum-value'] = $maxlength;
    $atts['data-minimum-value'] = $minlength;
    $atts = wpcf7_format_atts($atts);
    $html = sprintf('<span %1$s>%2$s</span>', $atts, $value);
    return $html;
}
Exemplo n.º 5
0
 public function invalidate($context, $message)
 {
     if ($context instanceof WPCF7_FormTag) {
         $tag = $context;
     } elseif (is_array($context)) {
         $tag = new WPCF7_FormTag($context);
     } elseif (is_string($context)) {
         $tags = wpcf7_scan_form_tags(array('name' => trim($context)));
         $tag = $tags ? new WPCF7_FormTag($tags[0]) : null;
     }
     $name = !empty($tag) ? $tag->name : null;
     if (empty($name) || !wpcf7_is_name($name)) {
         return;
     }
     if ($this->is_valid($name)) {
         $id = $tag->get_id_option();
         if (empty($id) || !wpcf7_is_name($id)) {
             $id = null;
         }
         $this->invalid_fields[$name] = array('reason' => (string) $message, 'idref' => $id);
     }
 }
Exemplo n.º 6
0
function wpcf7_akismet_submitted_params()
{
    $params = array('author' => '', 'author_email' => '', 'author_url' => '', 'content' => '');
    $has_akismet_option = false;
    foreach ((array) $_POST as $key => $val) {
        if ('_wpcf7' == substr($key, 0, 6) || '_wpnonce' == $key) {
            continue;
        }
        if (is_array($val)) {
            $val = implode(', ', wpcf7_array_flatten($val));
        }
        $val = trim($val);
        if (0 == strlen($val)) {
            continue;
        }
        if ($tags = wpcf7_scan_form_tags(array('name' => $key))) {
            $tag = $tags[0];
            $tag = new WPCF7_FormTag($tag);
            $akismet = $tag->get_option('akismet', '(author|author_email|author_url)', true);
            if ($akismet) {
                $has_akismet_option = true;
                if ('author' == $akismet) {
                    $params[$akismet] = trim($params[$akismet] . ' ' . $val);
                } elseif ('' == $params[$akismet]) {
                    $params[$akismet] = $val;
                }
            }
        }
        $params['content'] .= "\n\n" . $val;
    }
    if (!$has_akismet_option) {
        return false;
    }
    $params['content'] = trim($params['content']);
    return $params;
}
Exemplo n.º 7
0
function wpcf7_checkbox_posted_data($posted_data)
{
    $tags = wpcf7_scan_form_tags(array('type' => array('checkbox', 'checkbox*', 'radio')));
    if (empty($tags)) {
        return $posted_data;
    }
    foreach ($tags as $tag) {
        $tag = new WPCF7_FormTag($tag);
        if (!isset($posted_data[$tag->name])) {
            continue;
        }
        $posted_items = (array) $posted_data[$tag->name];
        if ($tag->has_option('free_text')) {
            if (WPCF7_USE_PIPE) {
                $values = $tag->pipes->collect_afters();
            } else {
                $values = $tag->values;
            }
            $last = array_pop($values);
            $last = html_entity_decode($last, ENT_QUOTES, 'UTF-8');
            if (in_array($last, $posted_items)) {
                $posted_items = array_diff($posted_items, array($last));
                $free_text_name = sprintf('_wpcf7_%1$s_free_text_%2$s', $tag->basetype, $tag->name);
                $free_text = $posted_data[$free_text_name];
                if (!empty($free_text)) {
                    $posted_items[] = trim($last . ' ' . $free_text);
                } else {
                    $posted_items[] = $last;
                }
            }
        }
        $posted_data[$tag->name] = $posted_items;
    }
    return $posted_data;
}
Exemplo n.º 8
0
function wpcf7_captcha_ajax_refill($items)
{
    if (!is_array($items)) {
        return $items;
    }
    $fes = wpcf7_scan_form_tags(array('type' => 'captchac'));
    if (empty($fes)) {
        return $items;
    }
    $refill = array();
    foreach ($fes as $fe) {
        $name = $fe['name'];
        $options = $fe['options'];
        if (empty($name)) {
            continue;
        }
        $op = wpcf7_captchac_options($options);
        if ($filename = wpcf7_generate_captcha($op)) {
            $captcha_url = wpcf7_captcha_url($filename);
            $refill[$name] = $captcha_url;
        }
    }
    if (!empty($refill)) {
        $items['captcha'] = $refill;
    }
    return $items;
}
Exemplo n.º 9
0
function wpcf7_scan_shortcode($cond = null)
{
    wpcf7_deprecated_function(__FUNCTION__, '4.6', 'wpcf7_scan_form_tags');
    return wpcf7_scan_form_tags($cond);
}