function wpcf7_quiz_ajax_refill($items) { if (!is_array($items)) { return $items; } $fes = wpcf7_scan_shortcode(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 (is_a($pipes, '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; }
function wpcf7_akismet_submitted_params() { $params = array('author' => '', 'author_email' => '', 'author_url' => ''); $content = ''; $fes = wpcf7_scan_shortcode(); foreach ($fes as $fe) { if (!isset($fe['name']) || !isset($_POST[$fe['name']])) { continue; } $value = $_POST[$fe['name']]; if (is_array($value)) { $value = implode(', ', wpcf7_array_flatten($value)); } $value = trim($value); $options = (array) $fe['options']; if (preg_grep('%^akismet:author$%', $options)) { $params['author'] = trim($params['author'] . ' ' . $value); } elseif (preg_grep('%^akismet:author_email$%', $options)) { if ('' == $params['author_email']) { $params['author_email'] = $value; } } elseif (preg_grep('%^akismet:author_url$%', $options)) { if ('' == $params['author_url']) { $params['author_url'] = $value; } } $content = trim($content . "\n\n" . $value); } $params = array_filter($params); if (!$params) { return false; } $params['content'] = $content; return $params; }
function wpcf7_count_shortcode_handler($tag) { $tag = new WPCF7_Shortcode($tag); if (empty($tag->name)) { return ''; } $target = wpcf7_scan_shortcode(array('name' => $tag->name)); $maxlength = $minlength = null; if ($target) { $target = new WPCF7_Shortcode($target[0]); $maxlength = $target->get_maxlength_option(); $minlength = $target->get_minlength_option(); 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; }
function wpcf7_file_form_enctype_filter($enctype) { $multipart = (bool) wpcf7_scan_shortcode(array('type' => array('file', 'file*'))); if ($multipart) { $enctype = ' enctype="multipart/form-data"'; } return $enctype; }
function wpcf7_acceptance_filter($accepted) { $fes = wpcf7_scan_shortcode(array('type' => 'acceptance')); foreach ($fes as $fe) { $name = $fe['name']; $options = (array) $fe['options']; if (empty($name)) { continue; } $value = $_POST[$name] ? 1 : 0; $invert = (bool) preg_grep('%^invert$%', $options); if ($invert && $value || !$invert && !$value) { $accepted = false; } } return $accepted; }
public function invalidate($context, $message) { if ($context instanceof WPCF7_Shortcode) { $tag = $context; } elseif (is_array($context)) { $tag = new WPCF7_Shortcode($context); } elseif (is_string($context)) { $tags = wpcf7_scan_shortcode(array('name' => trim($context))); $tag = $tags ? new WPCF7_Shortcode($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); } }
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_shortcode(array('name' => $key))) { $tag = $tags[0]; $tag = new WPCF7_Shortcode($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; }
function wpcf7_akismet($spam) { global $akismet_api_host, $akismet_api_port; if (!function_exists('akismet_get_key') || !akismet_get_key()) { return false; } $akismet_ready = false; $author = $author_email = $author_url = $content = ''; $fes = wpcf7_scan_shortcode(); foreach ($fes as $fe) { if (!isset($fe['name']) || !is_array($fe['options'])) { continue; } if (preg_grep('%^akismet:author$%', $fe['options'])) { $author .= ' ' . $_POST[$fe['name']]; $author = trim($author); $akismet_ready = true; } if (preg_grep('%^akismet:author_email$%', $fe['options']) && '' == $author_email) { $author_email = trim($_POST[$fe['name']]); $akismet_ready = true; } if (preg_grep('%^akismet:author_url$%', $fe['options']) && '' == $author_url) { $author_url = trim($_POST[$fe['name']]); $akismet_ready = true; } if ('' != $content) { $content .= "\n\n"; } $content .= $_POST[$fe['name']]; } if (!$akismet_ready) { return false; } $c['blog'] = get_option('home'); $c['blog_lang'] = get_locale(); $c['blog_charset'] = get_option('blog_charset'); $c['user_ip'] = preg_replace('/[^0-9., ]/', '', $_SERVER['REMOTE_ADDR']); $c['user_agent'] = $_SERVER['HTTP_USER_AGENT']; $c['referrer'] = $_SERVER['HTTP_REFERER']; $c['comment_type'] = 'contactform7'; if ($permalink = get_permalink()) { $c['permalink'] = $permalink; } if ('' != $author) { $c['comment_author'] = $author; } if ('' != $author_email) { $c['comment_author_email'] = $author_email; } if ('' != $author_url) { $c['comment_author_url'] = $author_url; } if ('' != $content) { $c['comment_content'] = $content; } $ignore = array('HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW'); foreach ($_SERVER as $key => $value) { if (!in_array($key, (array) $ignore)) { $c["{$key}"] = $value; } } $query_string = ''; foreach ($c as $key => $data) { $query_string .= $key . '=' . urlencode(stripslashes((string) $data)) . '&'; } $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port); if ('true' == $response[1]) { $spam = true; } return $spam; }
function wpcf7_captcha_ajax_refill($items) { if (!is_array($items)) { return $items; } $fes = wpcf7_scan_shortcode(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; }
function wpcf7_checkbox_posted_data($posted_data) { $tags = wpcf7_scan_shortcode(array('type' => array('checkbox', 'checkbox*', 'radio'))); if (empty($tags)) { return $posted_data; } foreach ($tags as $tag) { $tag = new WPCF7_Shortcode($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; }
function cf7bs_captcha_ajax_refill($items) { if (!is_array($items)) { return $items; } $fes = wpcf7_scan_shortcode(array('type' => 'captchar')); if (empty($fes)) { return $items; } $refill = array(); foreach ($fes as $fe) { if (cf7bs_captchar_has_captchac($fe)) { $fe = cf7bs_captchar_to_captchac($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 (count($refill) > 0) { if (!isset($items['captcha'])) { $items['captcha'] = $refill; } else { $items['captcha'] = array_merge($items['captcha'], $refill); } } return $items; }