Beispiel #1
0
 function zip_flatten($zipfile, $filter)
 {
     @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
     //if a temp dir already exists remove it and create a new one
     if (is_dir($this->paths['tempdir'])) {
         $this->delete_folder($this->paths['tempdir']);
     }
     //create a new
     $tempdir = avia_backend_create_folder($this->paths['tempdir'], false);
     if (!$tempdir) {
         exit('Wasn\'t able to create temp folder');
     }
     $zip = new ZipArchive();
     if ($zip->open($zipfile)) {
         for ($i = 0; $i < $zip->numFiles; $i++) {
             $entry = $zip->getNameIndex($i);
             if (!empty($filter)) {
                 $delete = true;
                 $matches = array();
                 foreach ($filter as $regex) {
                     preg_match("!" . $regex . "!", $entry, $matches);
                     if (!empty($matches)) {
                         $delete = false;
                         break;
                     }
                 }
             }
             if (substr($entry, -1) == '/' || !empty($delete)) {
                 continue;
             }
             // skip directories and non matching files
             $fp = $zip->getStream($entry);
             $ofp = fopen($this->paths['tempdir'] . '/' . basename($entry), 'w');
             if (!$fp) {
                 exit('Unable to extract the file.');
             }
             while (!feof($fp)) {
                 fwrite($ofp, fread($fp, 8192));
             }
             fclose($fp);
             fclose($ofp);
         }
         $zip->close();
     } else {
         exit('Wasn\'t able to work with Zip Archive');
     }
     return true;
 }
 function avia_generate_stylesheet($options = false)
 {
     global $avia;
     $safe_name = avia_backend_safe_string($avia->base_data['prefix']);
     $safe_name = apply_filters('avf_dynamic_stylesheet_filename', $safe_name);
     if (defined('AVIA_CSSFILE') && AVIA_CSSFILE === FALSE) {
         $dir_flag = update_option('avia_stylesheet_dir_writable' . $safe_name, 'false');
         $stylesheet_flag = update_option('avia_stylesheet_exists' . $safe_name, 'false');
         return;
     }
     $wp_upload_dir = wp_upload_dir();
     $stylesheet_dir = $wp_upload_dir['basedir'] . '/dynamic_avia';
     $stylesheet_dir = str_replace('\\', '/', $stylesheet_dir);
     $stylesheet_dir = apply_filters('avia_dyn_stylesheet_dir_path', $stylesheet_dir);
     $isdir = avia_backend_create_folder($stylesheet_dir);
     /*
      * directory could not be created (WP upload folder not write able)
      * @todo save error in db and output error message for user.
      * @todo maybe add mkdirfix: http://php.net/manual/de/function.mkdir.php
      */
     if ($isdir === false) {
         $dir_flag = update_option('avia_stylesheet_dir_writable' . $safe_name, 'false');
         $stylesheet_flag = update_option('avia_stylesheet_exists' . $safe_name, 'false');
         return;
     }
     /*
      *  Go ahead - WP managed to create the folder as expected
      */
     $stylesheet = trailingslashit($stylesheet_dir) . $safe_name . '.css';
     $stylesheet = apply_filters('avia_dyn_stylesheet_file_path', $stylesheet);
     //import avia_superobject and reset the options array
     $avia_superobject = $GLOBALS['avia'];
     $avia_superobject->reset_options();
     //regenerate style array after saving options page so we can create a new css file that has the actual values and not the ones that were active when the script was called
     avia_prepare_dynamic_styles();
     //generate stylesheet content
     $generate_style = new avia_style_generator($avia_superobject, false, false, false);
     $styles = $generate_style->create_styles();
     $created = avia_backend_create_file($stylesheet, $styles, true);
     if ($created === true) {
         $dir_flag = update_option('avia_stylesheet_dir_writable' . $safe_name, 'true');
         $stylesheet_flag = update_option('avia_stylesheet_exists' . $safe_name, 'true');
         $dynamic_id = update_option('avia_stylesheet_dynamic_version' . $safe_name, uniqid());
     }
 }