Example #1
0
 public function add($id, $title, $callback, $options = array())
 {
     $id = trim($id);
     if ('' === $id || !wpcf7_is_name($id)) {
         return false;
     }
     $this->panels[$id] = array('title' => $title, 'content' => 'tag-generator-panel-' . $id, 'options' => $options, 'callback' => $callback);
     return true;
 }
function wpcf7_ajax_json_echo()
{
    if ('POST' != $_SERVER['REQUEST_METHOD'] || !isset($_POST['_wpcf7_is_ajax_call'])) {
        return;
    }
    $echo = '';
    if (isset($_POST['_wpcf7'])) {
        $id = (int) $_POST['_wpcf7'];
        $unit_tag = wpcf7_sanitize_unit_tag($_POST['_wpcf7_unit_tag']);
        if ($contact_form = wpcf7_contact_form($id)) {
            WPCF7_ContactForm::set_current($contact_form);
            $items = array('mailSent' => false, 'into' => '#' . $unit_tag, 'captcha' => null);
            $result = $contact_form->submit(true);
            if (!empty($result['message'])) {
                $items['message'] = $result['message'];
            }
            if ($result['mail_sent']) {
                $items['mailSent'] = true;
            }
            if (!$result['valid']) {
                $invalids = array();
                foreach ($result['invalid_reasons'] as $name => $reason) {
                    $invalid = array('into' => 'span.wpcf7-form-control-wrap.' . sanitize_html_class($name), 'message' => $reason);
                    if (isset($result['invalid_fields'][$name]) && wpcf7_is_name($result['invalid_fields'][$name])) {
                        $invalid['idref'] = $result['invalid_fields'][$name];
                    }
                    $invalids[] = $invalid;
                }
                $items['invalids'] = $invalids;
            }
            if ($result['spam']) {
                $items['spam'] = true;
            }
            if (!empty($result['scripts_on_sent_ok'])) {
                $items['onSentOk'] = $result['scripts_on_sent_ok'];
            }
            if (!empty($result['scripts_on_submit'])) {
                $items['onSubmit'] = $result['scripts_on_submit'];
            }
            $items = apply_filters('wpcf7_ajax_json_echo', $items, $result);
            WPCF7_ContactForm::reset_current();
        }
    }
    $echo = json_encode($items);
    if (wpcf7_is_xhr()) {
        @header('Content-Type: application/json; charset=' . get_option('blog_charset'));
        echo $echo;
    } else {
        @header('Content-Type: text/html; charset=' . get_option('blog_charset'));
        echo '<textarea>' . $echo . '</textarea>';
    }
    exit;
}
 function do_shortcode_tag($m)
 {
     // allow [[foo]] syntax for escaping a tag
     if ($m[1] == '[' && $m[6] == ']') {
         return substr($m[0], 1, -1);
     }
     $tag = $m[2];
     $attr = $this->shortcode_parse_atts($m[3]);
     $scanned_tag = array('type' => $tag, 'basetype' => trim($tag, '*'), 'name' => '', 'options' => array(), 'raw_values' => array(), 'values' => array(), 'pipes' => null, 'labels' => array(), 'attr' => '', 'content' => '');
     if (is_array($attr)) {
         if (is_array($attr['options'])) {
             if ($this->shortcode_tags[$tag]['has_name'] && !empty($attr['options'])) {
                 $scanned_tag['name'] = array_shift($attr['options']);
                 if (!wpcf7_is_name($scanned_tag['name'])) {
                     return $m[0];
                 }
                 // Invalid name is used. Ignore this tag.
             }
             $scanned_tag['options'] = (array) $attr['options'];
         }
         $scanned_tag['raw_values'] = (array) $attr['values'];
         if (WPCF7_USE_PIPE) {
             $pipes = new WPCF7_Pipes($scanned_tag['raw_values']);
             $scanned_tag['values'] = $pipes->collect_befores();
             $scanned_tag['pipes'] = $pipes;
         } else {
             $scanned_tag['values'] = $scanned_tag['raw_values'];
         }
         $scanned_tag['labels'] = $scanned_tag['values'];
     } else {
         $scanned_tag['attr'] = $attr;
     }
     $scanned_tag['values'] = array_map('trim', $scanned_tag['values']);
     $scanned_tag['labels'] = array_map('trim', $scanned_tag['labels']);
     $content = trim($m[5]);
     $content = preg_replace("/<br[\r\n\t ]*\\/?>\$/m", '', $content);
     $scanned_tag['content'] = $content;
     $scanned_tag = apply_filters('wpcf7_form_tag', $scanned_tag, $this->exec);
     $this->scanned_tags[] = $scanned_tag;
     if ($this->exec) {
         $func = $this->shortcode_tags[$tag]['function'];
         return $m[1] . call_user_func($func, $scanned_tag) . $m[6];
     } else {
         return $m[0];
     }
 }
Example #4
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);
     }
 }
Example #5
0
 public function add_panel($id, $title, $callback)
 {
     if (wpcf7_is_name($id)) {
         $this->panels[$id] = array('title' => $title, 'callback' => $callback);
     }
 }
Example #6
0
 public function screen_reader_response()
 {
     $class = 'screen-reader-response';
     $role = '';
     $content = '';
     if ($this->is_posted()) {
         // Post response output for non-AJAX
         $role = 'alert';
         $result = self::get_submission_status($this->id);
         if (!empty($result['message'])) {
             $content = esc_html($result['message']);
             if (!empty($result['invalid_reasons'])) {
                 $content .= "\n" . '<ul>' . "\n";
                 foreach ((array) $result['invalid_reasons'] as $k => $v) {
                     if (isset($result['invalid_fields'][$k]) && wpcf7_is_name($result['invalid_fields'][$k])) {
                         $link = sprintf('<a href="#%1$s">%2$s</a>', $result['invalid_fields'][$k], esc_html($v));
                         $content .= sprintf('<li>%s</li>', $link);
                     } else {
                         $content .= sprintf('<li>%s</li>', esc_html($v));
                     }
                     $content .= "\n";
                 }
                 $content .= '</ul>' . "\n";
             }
         }
     }
     $atts = array('class' => trim($class), 'role' => trim($role));
     $atts = wpcf7_format_atts($atts);
     $output = sprintf('<div %1$s>%2$s</div>', $atts, $content);
     return $output;
 }
Example #7
0
 private function validate()
 {
     if ($this->invalid_fields) {
         return false;
     }
     $result = array('valid' => true, 'reason' => array(), 'idref' => array());
     $tags = $this->contact_form->form_scan_shortcode();
     foreach ($tags as $tag) {
         $result = apply_filters('wpcf7_validate_' . $tag['type'], $result, $tag);
     }
     $result = apply_filters('wpcf7_validate', $result);
     if ($result['valid']) {
         return true;
     } else {
         foreach ((array) $result['reason'] as $name => $reason) {
             $field = array('reason' => $reason);
             if (isset($result['idref'][$name]) && wpcf7_is_name($result['idref'][$name])) {
                 $field['idref'] = $result['idref'][$name];
             } else {
                 $field['idref'] = null;
             }
             $this->invalid_fields[$name] = $field;
         }
         return false;
     }
 }