/**
  * Set template to current active builder
  */
 function set_layout_ajaxify()
 {
     global $ThemifyBuilder;
     check_ajax_referer('tfb_load_nonce', 'nonce');
     $template_slug = $_POST['layout_slug'];
     $current_builder_id = (int) $_POST['current_builder_id'];
     $builtin_layout = $_POST['builtin_layout'];
     $builder_data = '';
     $response = array();
     if ($builtin_layout == 'yes') {
         $file = THEMIFY_BUILDER_INCLUDES_DIR . '/data/' . $template_slug;
         if (is_file($file)) {
             $cache_dir = themify_get_cache_dir();
             $extract_file = $cache_dir['path'] . basename($template_slug);
             WP_Filesystem();
             $extract_action = unzip_file($file, $extract_file);
             /* extract the file */
             if (is_wp_error($extract_action)) {
                 $response['msg'] = $extract_action->get_error_message();
             } else {
                 $extract_file = $cache_dir['path'] . basename($template_slug) . '/builder_data_export.txt';
                 /* use include to read the file, seems safer than wp_filesystem */
                 ob_start();
                 include $extract_file;
                 $builder_data = ob_get_clean();
             }
         } else {
             $response['msg'] = __('Layout does not exist.', 'themify');
         }
     } else {
         $args = array('name' => $template_slug, 'post_type' => $this->layout->post_type_name, 'post_status' => 'publish', 'numberposts' => 1);
         $template = get_posts($args);
         if ($template) {
             $builder_data = $ThemifyBuilder->get_builder_data($template[0]->ID);
         } else {
             $response['msg'] = __('Requested layout not found.', 'themify');
         }
     }
     if (!empty($builder_data)) {
         $GLOBALS['ThemifyBuilder_Data_Manager']->save_data($builder_data, $current_builder_id);
         $response['status'] = 'success';
         $response['msg'] = '';
     } else {
         $response['status'] = 'failed';
         if (!isset($response['msg'])) {
             $response['msg'] = __('Something went wrong', 'themify');
         }
     }
     wp_send_json($response);
     die;
 }
Example #2
0
/**
 * Get the path to the sample content file
 *
 * @return string
 * @since 2.3.7
 */
function themify_get_sample_content_file()
{
    $resource_file = get_template_directory() . '/sample/sample-content.zip';
    $cache_dir = themify_get_cache_dir();
    $extract_file = $cache_dir['path'] . 'sample-content.xml';
    if (!file_exists($resource_file)) {
        // fallback
        $resource_file = get_template_directory() . '/sample/sample-content.gz';
        themify_uncompress_gzip($resource_file, $extract_file);
    } else {
        WP_Filesystem();
        if (1 == unzip_file($resource_file, $extract_file)) {
            $extract_file = $cache_dir['path'] . 'sample-content.xml/sample-content.xml';
        }
    }
    $parse_file = file_exists($extract_file) ? $extract_file : $resource_file;
    return $parse_file;
}
/**
 * Performs importing the sample contents to replicate the theme's demo site
 *
 * @since 1.7.6
 */
function themify_do_import_sample_contents()
{
    do_action('themify_before_demo_import');
    themify_import_sample_content_setup();
    $resource_file = get_template_directory() . '/sample/sample-content.gz';
    $cache_dir = themify_get_cache_dir();
    $extract_file = $cache_dir['path'] . 'sample-content.xml';
    themify_uncompress_gzip($resource_file, $extract_file);
    $parse_file = file_exists($extract_file) ? $extract_file : $resource_file;
    $import = new Themify_Import();
    $import->fetch_attachments = true;
    $import->import($parse_file);
    // remove extract file
    if (file_exists($extract_file)) {
        unlink($extract_file);
    }
    if (file_exists(THEME_DIR . '/sample/demo-settings.php')) {
        require_once THEME_DIR . '/sample/demo-settings.php';
    }
    do_action('themify_after_demo_import');
}