コード例 #1
0
ファイル: admin.php プロジェクト: JalpMi/v2contact
function op_asset_file_list($asset)
{
    $file_list = array();
    $path = OP_ASSETS . 'addon/' . $asset;
    $dir = @dir($path);
    $prefix = 'assets/' . $asset . '/';
    if ($dir) {
        while (($file = $dir->read()) !== false) {
            if ($file != '.' && $file != '..' && $file != 'index.php' && strpos($file, '.') !== 0) {
                if (is_dir($path . '/' . $file)) {
                    $file_list = array_merge($file_list, op_asset_file_list($asset . '/' . $file, $prefix));
                } else {
                    $file_list[$path . '/' . $file] = $prefix . $file;
                }
            }
        }
    }
    return $file_list;
}
コード例 #2
0
ファイル: live_editor.php プロジェクト: denis-chmel/wordpress
    function export_layout()
    {
        global $wpdb;
        $error = null;
        if (!class_exists('ZipArchive')) {
            exit(json_encode(array('error' => __('You must have ZipArchive enabled on your server to complete the operation.', OP_SN))));
        }
        if (!($layout_name = op_post('layout_name'))) {
            exit(json_encode(array('error' => __('Please supply a name for your layout', OP_SN))));
        }
        if (!($layout_description = op_post('layout_description'))) {
            exit(json_encode(array('error' => __('Please supply a description for your layout', OP_SN))));
        }
        if (!($image = op_post('image')) || !file_exists($image)) {
            exit(json_encode(array('error' => __('Please supply an image for your layout', OP_SN))));
        }
        if (!($layout_category = op_post('layout_category'))) {
            exit(json_encode(array('error' => __('Please supply a category for your layout', OP_SN))));
        } else {
            $layout_category = $wpdb->get_var($wpdb->prepare("SELECT name FROM `{$wpdb->prefix}optimizepress_layout_categories` WHERE `id` = %d", $layout_category));
        }
        $this->save_page();
        $settings = apply_filters('op_export_settings_array', array('membership', 'theme', 'header_layout', 'feature_area', 'feature_title', 'footer_area', 'color_scheme_template', 'typography', 'color_scheme_advanced', 'mobile_redirect', 'seo', 'scripts', 'fb_share', 'lightbox', 'exit_redirect', 'launch_gateway', 'launch_funnel', 'size_color', 'landing_bg'));
        $layouts = op_post('layouts');
        if (!is_array($layouts)) {
            $layouts = array();
        }
        $layouts = array_keys($layouts);
        $config_str = '<?php';
        $image_filename = basename($image);
        $vars = array('name', 'description', 'category');
        foreach ($vars as $var) {
            $value = 'layout_' . $var;
            $value = ${$value};
            $value = str_replace(array('�', '’', '”', '“', "'"), array("'", "'", '&quot;', '&quot;', "\\'"), stripslashes($value));
            $config_str .= '
$config[\'' . $var . '\'] = \'' . $value . '\';';
        }
        $config_str .= '
$config[\'image\'] = \'' . str_replace("'", "\\'", $image_filename) . '\';
$config[\'settings\'] = array();
$config[\'layouts\'] = array();
';
        $url = site_url('/');
        if (preg_match('{(http|https)://(www.)?(.*?)$}i', $url, $matches)) {
            $url = $matches[3];
        }
        $imgregex = '{(["\']*)(http|https)://(www.)?' . $url . '(.*?)(\\.[gif|png|jpg|jpeg]+)[*\\1]*\\1}i';
        foreach ($settings as $setting) {
            $conf = op_page_option($setting);
            if (is_array($conf)) {
                $conf = $this->_check_for_images($imgregex, $conf, array($setting));
            }
            $config_str .= "\$config['settings']['" . $setting . "'] = '" . base64_encode(serialize($conf)) . "';\n";
        }
        $tags = op_assets_parse_list();
        $regex = op_shortcode_regex(join('|', array_map('preg_quote', array_keys($tags))));
        $images = array();
        $assets = array();
        $new_layouts = array();
        foreach ($layouts as $layout_str) {
            $layout = op_page_layout($layout_str, true);
            $new_layout = array();
            /**/
            foreach ($layout as $row) {
                $row_image_match = preg_match_all($imgregex, $row['row_style'], $matches);
                if ($row_image_match > 0) {
                    for ($i = 0; $i < $row_image_match; $i++) {
                        $path = $matches[4][$i] . $matches[5][$i];
                        $row['row_style'] = str_replace(trim($matches[0][$i], $matches[1][$i]), '{op_filename="' . $path . '"}', $row['row_style']);
                        $temp = base64_decode($row['row_data_style']);
                        $temp = str_replace(trim($matches[0][$i], $matches[1][$i]), '{op_filename=\\"' . $path . '\\"}', $temp);
                        $row['row_data_style'] = base64_encode($temp);
                        $this->zip_images[$path] = trim($matches[0][$i], '"');
                    }
                }
                $new_row = array('row_class' => $row['row_class'], 'row_style' => $row['row_style'], 'row_data_style' => $row['row_data_style'], 'children' => array());
                if (isset($row['children']) && count($row['children']) > 0) {
                    foreach ($row['children'] as $col) {
                        $new_col = array('col_class' => $col['col_class'], 'children' => array());
                        if (!empty($col['children']) && count($col['children']) > 0) {
                            foreach ($col['children'] as $child) {
                                switch ($child['type']) {
                                    case 'subcolumn':
                                        $subcol['type'] = 'subcolumn';
                                        $subcol['subcol_class'] = $child['subcol_class'];
                                        $subcol['children'] = array();
                                        if (!empty($child['children']) && count($child['children']) > 0) {
                                            $nr = 0;
                                            foreach ($child['children'] as $kid) {
                                                $subcol['children'][$nr]['type'] = 'element';
                                                $sc = trim(stripslashes($kid['object']));
                                                $mc = preg_match_all($imgregex, $sc, $matches);
                                                if ($mc > 0) {
                                                    for ($i = 0; $i < $mc; $i++) {
                                                        $path = $matches[4][$i] . $matches[5][$i];
                                                        $sc = str_replace(trim($matches[0][$i], $matches[1][$i]), '{op_filename="' . $path . '"}', $sc);
                                                        $this->zip_images[$path] = trim($matches[0][$i], '"');
                                                    }
                                                }
                                                $child_sc = '';
                                                if (preg_match('/' . op_shortcode_regex('op_liveeditor_elements') . '/s', $sc, $matches)) {
                                                    $child_sc = $matches[0];
                                                    $assets = array_merge($assets, $this->_check_tags($child_sc, $regex, $tags));
                                                    $sc = str_replace($child_sc, '#OP_CHILD_ELEMENTS#', $sc);
                                                }
                                                $assets = array_merge($assets, $this->_check_tags($sc, $regex, $tags));
                                                $sc = str_replace(OP_ASSETS_URL, '#OP_ASSETS_URL#', $sc);
                                                $sc = str_replace('#OP_CHILD_ELEMENTS#', $child_sc, $sc);
                                                //$element['object'] = str_replace('$', '&#36;', addslashes(stripslashes($sc)));
                                                $subcol['children'][$nr]['object'] = $sc;
                                                $subcol['children'][$nr]['element_class'] = $kid['element_class'];
                                                $subcol['children'][$nr]['element_data_style'] = $kid['element_data_style'];
                                                $nr++;
                                            }
                                        }
                                        $new_col['children'][] = $subcol;
                                        break;
                                    case 'element':
                                        $element['type'] = 'element';
                                        $sc = trim(stripslashes($child['object']));
                                        $mc = preg_match_all($imgregex, $sc, $matches);
                                        if ($mc > 0) {
                                            for ($i = 0; $i < $mc; $i++) {
                                                $path = $matches[4][$i] . $matches[5][$i];
                                                $sc = str_replace(trim($matches[0][$i], $matches[1][$i]), '{op_filename="' . $path . '"}', $sc);
                                                $this->zip_images[$path] = trim($matches[0][$i], '"');
                                            }
                                        }
                                        $child_sc = '';
                                        if (preg_match('/' . op_shortcode_regex('op_liveeditor_elements') . '/s', $sc, $matches)) {
                                            $child_sc = $matches[0];
                                            $assets = array_merge($assets, $this->_check_tags($child_sc, $regex, $tags));
                                            $sc = str_replace($child_sc, '#OP_CHILD_ELEMENTS#', $sc);
                                        }
                                        $assets = array_merge($assets, $this->_check_tags($sc, $regex, $tags));
                                        $sc = str_replace(OP_ASSETS_URL, '#OP_ASSETS_URL#', $sc);
                                        $sc = str_replace('#OP_CHILD_ELEMENTS#', $child_sc, $sc);
                                        //$element['object'] = str_replace('$', '&#36;', addslashes(stripslashes($sc)));
                                        $element['object'] = $sc;
                                        $element['element_class'] = $child['element_class'];
                                        $element['element_data_style'] = $child['element_data_style'];
                                        $new_col['children'][] = $element;
                                        break;
                                }
                            }
                        }
                        $new_row['children'][] = $new_col;
                    }
                }
                $new_layout[] = $new_row;
            }
            /**/
            $new_layouts[$layout_str] = $new_layout;
        }
        $dirname = md5($layout_name);
        if (!file_exists(OP_LIB . 'content_layouts/export')) {
            mkdir(OP_LIB . 'content_layouts/export');
        }
        $dir_base = OP_LIB . 'content_layouts/export';
        $full_dir = $dir_base . '/' . $dirname;
        $tmpdirname = $dirname;
        $counter = 0;
        while (file_exists($full_dir)) {
            $counter++;
            $tmpdirname = $dirname . ($counter > 0 ? '-' . $counter : '');
            $full_dir = $dir_base . '/' . $tmpdirname;
        }
        mkdir($full_dir);
        $filename = preg_replace(array('/\\s+/', '/[^a-zA-Z0-9\\_]/', '/_{2,}/'), array('_', '', '_'), $layout_name);
        $zip = new ZipArchive();
        $zip->open($full_dir . '/' . $filename . '.zip', ZIPARCHIVE::CREATE);
        $zip->addFile(dirname($image) . DIRECTORY_SEPARATOR . $image_filename, $image_filename);
        $zip->addEmptyDir('images');
        $added_images = array();
        $new_images = array();
        foreach ($this->zip_images as $path => $url) {
            $file = basename($path);
            $new_filename = $file;
            if (isset($added_images[$file])) {
                $f = explode('.', $file);
                $ext = array_pop($f);
                $f = implode('.', $f);
                $counter = 1;
                while (isset($added_images[$new_filename])) {
                    $new_filename = $f . $counter . '.' . $ext;
                    $counter++;
                }
            }
            $new_images[$path] = $new_filename;
            $added_images[$new_filename] = true;
            if (file_exists(ABSPATH . $path)) {
                $zip->addFile(ABSPATH . $path, 'images/' . $new_filename);
            }
        }
        $config_str .= "\$config['layouts'] = '" . base64_encode(serialize($new_layouts)) . "';\n";
        $config_str .= "\$config['images'] = '" . base64_encode(serialize($new_images)) . "';\n";
        $config_str .= "\$config['settings_images'] = '" . base64_encode(serialize($this->used_images)) . "';\n";
        $zip->addFromString('config.php', $config_str);
        if (count($assets) > 0) {
            $assets = array_keys($assets);
            $file_list = array();
            foreach ($assets as $asset) {
                $file_list = array_merge($file_list, op_asset_file_list($asset));
            }
            foreach ($file_list as $local => $zipname) {
                if (file_exists($local)) {
                    $zip->addFile($local, $zipname);
                }
            }
        }
        $zip->close();
        $out = array('output' => '<a style="color: #2e82bc !important; font-sze:15px !important;" href="' . OP_LIB_URL . 'content_layouts/export/' . $tmpdirname . '/' . $filename . '.zip">' . __('Download your layout', OP_SN) . '</a> | <a style="color: #2e82bc !important; font-sze:15px !important;" href="#delete" class="delete-file">' . __('Delete File', OP_SN) . '</a><input type="hidden" name="zip_filename" id="zip_filename" value="' . $full_dir . '/' . $filename . '.zip" />');
        exit(json_encode($out));
    }