示例#1
0
文件: core.php 项目: schiz/scrollax
/**
 *
 */
function miss_is_sprite_writable()
{
    # check if sprite folder exists, if not try to create it
    if (!@is_dir(THEME_SPRITES_DIR)) {
        if (!wp_mkdir_p(THEME_SPRITES_DIR)) {
            return false;
        }
    }
    # check if styles folder is writable, if not try to chmod
    if (!miss_is_writable_dir(THEME_SPRITES_DIR)) {
        if (!@chmod(THEME_SPRITE, 0777)) {
            return false;
        }
    }
    return true;
}
示例#2
0
 /**
  *
  */
 function file_export($export_file)
 {
     $skin_zip = $this->stylesdir . '/skin_zip/';
     # check if styles folder is writable
     if (!miss_is_styles_writable()) {
         return array('success' => false, 'message' => $this->json_response($args = array('type' => 'not_exported', 'name' => $export_file)));
     }
     # make skin_zip folder to create zip
     if (!wp_mkdir_p($skin_zip)) {
         return array('success' => false, 'message' => $this->json_response($args = array('type' => 'not_exported', 'name' => $export_file)));
     }
     # check if skin_zip folder is writable, if not try to chmod
     if (!miss_is_writable_dir($skin_zip)) {
         if (!@chmod($skin_zip, 0777)) {
             return array('success' => false, 'message' => $this->json_response($args = array('type' => 'not_exported', 'name' => $export_file)));
         }
     }
     # get stylesheet contents
     if ($this->get_contents($export_file)) {
         $input_data = $this->get_contents($export_file);
     } else {
         return array('success' => false, 'message' => $this->json_response($args = array('type' => 'not_exported_2', 'name' => $export_file)));
     }
     # Set artificially high memory_limit
     # preg match all RGB colours
     # preg match all image urls
     preg_match_all('/url\\(([^\\)]*)\\)/', $input_data, $matches);
     # loop through all matches and create $images path string array
     $images = array();
     for ($i = 0; $i < count($matches[1]); $i++) {
         $image_filter = $this->image_filter($matches[1][$i], $export = true);
         if (isset($image_filter['directory'])) {
             $images[$i]['directory'] = $image_filter['directory'];
         }
         if (isset($image_filter['url'])) {
             $images[$i]['url'] = $image_filter['url'];
         }
     }
     # if $images array !empty loop thourgh and move to skin_zip
     if (!empty($images)) {
         require_once THEME_ADMIN_CLASSES . '/get-image.php';
         $get_image = new GetImage();
         $get_image_error = array();
         $images_to_zip = array();
         foreach ($images as $image) {
             # if we have a dir path first try and copy image
             if (!empty($image['directory'])) {
                 $path_parts = pathinfo($image['directory']);
                 if (@copy($image['directory'], $skin_zip . $path_parts['basename'])) {
                     $images_to_zip[$path_parts['basename']] = $skin_zip . $path_parts['basename'];
                     @chmod($skin_zip . $path_parts['basename'], 0666);
                     unset($image['url']);
                 }
             }
             # get image
             if (!empty($image['url'])) {
                 $path_parts = pathinfo($image['url']);
                 $get_image->source = $image['url'];
                 $get_image->save_to = $skin_zip;
                 # Use curl if it exists
                 if (function_exists('curl_init') && !ini_get('safe_mode') && !ini_get('open_basedir')) {
                     if ($get_image->download('curl')) {
                         $images_to_zip[$path_parts['basename']] = $skin_zip . $path_parts['basename'];
                         unset($image['url']);
                     }
                     # Use gd if it exists
                 } elseif (function_exists('gd_info')) {
                     if ($get_image->download('gd')) {
                         $images_to_zip[$path_parts['basename']] = $skin_zip . $path_parts['basename'];
                         unset($image['url']);
                     }
                     # Use fread
                 } else {
                     if ($get_image->download('fread')) {
                         $images_to_zip[$path_parts['basename']] = $skin_zip . $path_parts['basename'];
                         unset($image['url']);
                     }
                 }
             }
             if (!empty($image['url'])) {
                 $get_image_error[] = $image['url'];
             }
         }
     }
     # zip file name
     $zip_name = str_replace('.css', '', $export_file);
     # preg_replace new image path in stylesheet if $images_to_zip !empty
     if (!empty($images_to_zip)) {
         foreach ($images_to_zip as $image => $val) {
             $new_path = 'url(' . $zip_name . '/' . $image;
             $patterns = "/url\\((.*\\/){$image}/";
             $input_data = @preg_replace($patterns, $new_path, $input_data);
         }
     }
     # write new image paths to stylesheet
     $css_writable = true;
     define('PCLZIP_TEMPORARY_DIR', $skin_zip);
     # create zip file
     if ($css_writable) {
         if (!class_exists('PclZip')) {
             require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
         }
         $archive = new PclZip($skin_zip . $zip_name . '.zip');
         $v_list = $archive->create($skin_zip . $export_file, PCLZIP_OPT_REMOVE_ALL_PATH);
         if ($v_list != 0) {
             # if $images_to_zip array !empty add images to zip
             if ($v_list != 0 && !empty($images_to_zip)) {
                 $archive = new PclZip($skin_zip . $zip_name . '.zip');
                 $v_list = $archive->add($images_to_zip, PCLZIP_OPT_REMOVE_ALL_PATH, PCLZIP_OPT_ADD_PATH, $zip_name);
                 # error adding images to zip
                 if ($v_list == 0) {
                     die("Error : " . $archive->errorInfo(true));
                     $get_image_error = array_merge((array) $get_image_error, array_keys($images_to_zip));
                 }
             }
             # couldn't create zip file
         } else {
             return array('success' => false, 'message' => $this->json_response($args = array('type' => 'not_exported_2', 'name' => $export_file)));
         }
         # couldn't write to css file
     } else {
         return array('success' => false, 'message' => $this->json_response($args = array('type' => 'not_exported', 'name' => $export_file)));
     }
     # if $get_image_error !empty
     if (!empty($get_image_error)) {
         foreach ($get_image_error as $image) {
             $path_parts = pathinfo($image);
             if ($path_parts['basename'] != 'none') {
                 $image_error[] = '&quot;' . $path_parts['basename'] . '&quot;';
             }
         }
         if (!empty($image_error)) {
             $return_zip['message'] = $this->json_response($args = array('type' => 'not_exported_img', 'image_error' => $image_error));
         }
         $return_zip['image_error'] = true;
     }
     $return_zip['dl_skin'] = THEME_JS_INIT . '/dl-skin.php';
     $return_zip['zip'] = $skin_zip . $zip_name . '.zip';
     $return_zip['rmdir'] = $skin_zip;
     $return_zip['success'] = true;
     return $return_zip;
 }