Exemple #1
0
function zo_shortcode_template($settings, $value)
{
    $shortcode = $settings['shortcode'];
    $theme_dir = get_template_directory() . '/vc_templates';
    $reg = "/^({$shortcode}\\.php|{$shortcode}--.*\\.php)/";
    $files = zoFileScanDirectory($theme_dir, $reg);
    $files = array_merge(zoFileScanDirectory(ZO_TEMPLATES, $reg), $files);
    $output = "";
    $output .= "<select name=\"" . esc_attr($settings['param_name']) . "\" class=\"wpb_vc_param_value\">";
    foreach ($files as $key => $file) {
        if ($key == esc_attr($value)) {
            $output .= "<option value=\"{$key}\" selected>{$key}</option>";
        } else {
            $output .= "<option value=\"{$key}\">{$key}</option>";
        }
    }
    $output .= "</select>";
    $script = <<<SCRIPT
    <script type="text/javascript">
        jQuery('button.vc_panel-btn-save[data-save=true]').click(function(){
            jQuery('.zo_custom_param.vc_dependent-hidden').remove();
        });
    </script>
SCRIPT;
    return $output . $script;
}
Exemple #2
0
 /**
  * Add Shortcode Params
  *
  * @return none
  */
 function zoShortcodeAddParams()
 {
     $extra_params_folder = get_template_directory() . '/vc_params';
     $files = zoFileScanDirectory($extra_params_folder, '/^zo_.*\\.php/');
     if (!empty($files)) {
         foreach ($files as $file) {
             if (WPBMap::exists($file->name)) {
                 include $file->uri;
                 if (isset($params) && is_array($params)) {
                     foreach ($params as $param) {
                         if (is_array($param)) {
                             $param['group'] = __('Template', ZO_NAME);
                             $param['edit_field_class'] = isset($param['edit_field_class']) ? $param['edit_field_class'] . ' zo_custom_param vc_col-sm-12 vc_column' : 'zo_custom_param vc_col-sm-12 vc_column';
                             $param['class'] = 'zo-extra-param';
                             if (isset($param['template']) && !empty($param['template'])) {
                                 if (!is_array($param['template'])) {
                                     $param['template'] = array($param['template']);
                                 }
                                 $param['dependency'] = array("element" => "zo_template", "value" => $param['template']);
                             }
                             vc_add_param($file->name, $param);
                         }
                     }
                 }
             }
         }
     }
 }
Exemple #3
0
function zoFileScanDirectory($dir, $mask, $options = array(), $depth = 0)
{
    $options += array('nomask' => '/(\\.\\.?|CSV)$/', 'callback' => 0, 'recurse' => TRUE, 'key' => 'uri', 'min_depth' => 0);
    $options['key'] = in_array($options['key'], array('uri', 'filename', 'name')) ? $options['key'] : 'uri';
    $files = array();
    if (is_dir($dir) && ($handle = opendir($dir))) {
        while (FALSE !== ($filename = readdir($handle))) {
            if (!preg_match($options['nomask'], $filename) && $filename[0] != '.') {
                $uri = "{$dir}/{$filename}";
                if (is_dir($uri) && $options['recurse']) {
                    // Give priority to files in this folder by merging them in after any subdirectory files.
                    $files = array_merge(zoFileScanDirectory($uri, $mask, $options, $depth + 1), $files);
                } elseif ($depth >= $options['min_depth'] && preg_match($mask, $filename)) {
                    // Always use this match over anything already set in $files with the
                    // same $$options['key'].
                    $file = new stdClass();
                    $file->uri = $uri;
                    $file->filename = $filename;
                    $file->name = pathinfo($filename, PATHINFO_FILENAME);
                    $files[$filename] = $file;
                }
            }
        }
        closedir($handle);
    }
    return $files;
}
Exemple #4
0
 /**
  * 
  * @return Array(): array of all avaiable templates
  */
 protected function findShortcodeTemplates()
 {
     $theme_dir = get_template_directory() . '/vc_templates';
     $reg = "/^({$this->shortcode}\\.php|{$this->shortcode}--.*\\.php)/";
     $files = zoFileScanDirectory($theme_dir, $reg);
     $files = array_merge(zoFileScanDirectory(ZO_TEMPLATES, $reg), $files);
     return $files;
 }
function zo_shortcode_template_img($settings, $value)
{
    $shortcode = $settings['shortcode'];
    $theme_dir = get_template_directory() . '/vc_templates';
    $reg = "/^({$shortcode}\\.php|{$shortcode}--.*\\.php)/";
    $files = zoFileScanDirectory($theme_dir, $reg);
    $files = array_merge(zoFileScanDirectory(ZO_TEMPLATES, $reg), $files);
    $output = "";
    $output .= "<select style=\"display:none;\" id=\"" . $shortcode . "-select-param\" name=\"" . esc_attr($settings['param_name']) . "\" class=\"wpb_vc_param_value\">";
    foreach ($files as $key => $file) {
        if ($key == esc_attr($value)) {
            $output .= "<option value=\"{$key}\" selected>{$key}</option>";
        } else {
            $output .= "<option value=\"{$key}\">{$key}</option>";
        }
    }
    $output .= "</select>";
    $output .= "<div id=\"" . $shortcode . "-zo-img-select\">";
    foreach ($files as $key => $file) {
        $img = get_template_directory_uri() . '/vc_params/' . $shortcode . '/' . basename($key, '.php') . '.jpg';
        if ($key == esc_attr($value)) {
            $output .= "<img src=\"" . $img . "\" data-value=\"" . $key . "\" class=\"zo-img-select selected\" />";
        } else {
            $output .= "<img src=\"" . $img . "\" data-value=\"" . $key . "\" class=\"zo-img-select\" />";
        }
    }
    $output .= "</div>";
    $script = '
    <script type="text/javascript">
        jQuery(\'button.vc_panel-btn-save[data-save=true]\').click(function(){
            jQuery(\'.zo_custom_param.vc_dependent-hidden\').remove();
        });
        jQuery(document).ready(function($){
            $("#' . $shortcode . '-zo-img-select").find("img.zo-img-select").click(function(){
                var $this = $(this);
                $("#' . $shortcode . '-zo-img-select").find("img.zo-img-select").removeClass("selected");
                $this.addClass("selected");console.log($(":hidden#' . $shortcode . '-select-param"));
                $(":hidden#' . $shortcode . '-select-param").val($this.data("value")).change();
            });
        });
    </script>';
    return $output . $script;
}