Ejemplo n.º 1
0
function icl_wpcf7_form_tag_filter($tag)
{
    if (!is_array($tag)) {
        return $tag;
    }
    $type = $tag['type'];
    $name = $tag['name'];
    $options = (array) $tag['options'];
    $values = (array) $tag['values'];
    $raw_values = (array) $tag['raw_values'];
    $pipes = $tag['pipes'];
    $content = $tag['content'];
    $icl_option = array();
    foreach ($options as $option) {
        if ('icl' == $option) {
            $icl_option = array('icl', null);
            break;
        } elseif (preg_match('/^icl:(.+)$/', $option, $matches)) {
            $icl_option = array('icl', $matches[1]);
            break;
        }
    }
    if (!('icl' == $type || $icl_option)) {
        return $tag;
    }
    $str_id = $icl_option[1] ? $icl_option[1] : $name;
    $new_values = array();
    if ($raw_values && $pipes && is_a($pipes, 'WPCF7_Pipes') && !$pipes->zero()) {
        $new_raw_values = array();
        foreach ($raw_values as $key => $value) {
            $string_name = icl_wpcf7_string_name($value, $str_id, $key);
            $new_raw_values[$key] = icl_wpcf7_translate($string_name, $value);
        }
        $new_pipes = new WPCF7_Pipes($new_raw_values);
        $new_values = $new_pipes->collect_befores();
        $tag['pipes'] = $new_pipes;
    } elseif ($values) {
        foreach ($values as $key => $value) {
            $string_name = icl_wpcf7_string_name($value, $str_id, $key);
            $new_values[$key] = icl_wpcf7_translate($string_name, $value);
        }
    }
    if (preg_match('/^(?:text|email|textarea|captchar|submit)[*]?$/', $type)) {
        $tag['labels'] = $tag['values'] = $new_values;
    } else {
        $tag['labels'] = $new_values;
    }
    $content = trim($content);
    if (!empty($content)) {
        $string_name = icl_wpcf7_string_name($content, $str_id);
        $content = icl_wpcf7_translate($string_name, $content);
        $tag['content'] = $content;
    }
    return $tag;
}
Ejemplo n.º 2
0
 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();
     $scanned_tag['type'] = $tag;
     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;
     }
     $content = trim($m[5]);
     $content = preg_replace("/<br\\s*\\/?>\$/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];
     }
 }
Ejemplo n.º 3
0
 private function scan_callback($m, $replace = false)
 {
     // allow [[foo]] syntax for escaping a tag
     if ($m[1] == '[' && $m[6] == ']') {
         return substr($m[0], 1, -1);
     }
     $tag = $m[2];
     $attr = $this->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->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, $replace);
     $this->scanned_tags[] = $scanned_tag;
     if ($replace) {
         $func = $this->tags[$tag]['function'];
         return $m[1] . call_user_func($func, $scanned_tag) . $m[6];
     } else {
         return $m[0];
     }
 }