示例#1
0
 public function updateViaFtp($content, $settings)
 {
     $this->saveBackup();
     $tmp_file = fn_create_temp_file();
     fn_put_contents($tmp_file, $content);
     $ftp_copy_result = fn_copy_by_ftp($tmp_file, $this->path, $settings);
     fn_rm($tmp_file);
     $status = $ftp_copy_result === true;
     return array($status, $ftp_copy_result);
 }
示例#2
0
 /**
  * Render PDF document from HTML code
  * @param  string  $html     HTML code
  * @param  string  $filename filename to save PDF or name of attachment to download
  * @param  boolean $save     saves to file if true, outputs if not
  * @param  array   $params   params to post along with request
  * @return mixed   true if document saved, false on failure or outputs document
  */
 public static function render($html, $filename = '', $save = false, $params = array())
 {
     if (is_array($html)) {
         $html = implode("<div style='page-break-before: always;'>&nbsp;</div>", $html);
     }
     if (self::isLocalIP(gethostbyname($_SERVER['HTTP_HOST']))) {
         $html = self::convertImages($html);
     }
     $default_params = array('content' => $html, 'page_size' => 'A4');
     $params = array_merge($default_params, $params);
     $file = fn_create_temp_file();
     $response = Http::post(self::action('/pdf/render'), json_encode($params), array('headers' => array('Content-type: application/json', 'Accept: application/pdf'), 'binary_transfer' => true, 'write_to_file' => $file));
     if (!empty($response)) {
         return self::output($file, $filename, $save);
     }
     return false;
 }
示例#3
0
/**
 * Returns image width, height, mime type and local path to image
 *
 * @param string $file path to image
 * @return array array with width, height, mime type and path
 */
function fn_get_image_size($file)
{
    // File is url, get it and store in temporary directory
    if (strpos($file, '://') !== false) {
        $tmp = fn_create_temp_file();
        if (fn_put_contents($tmp, fn_get_contents($file)) == 0) {
            return false;
        }
        $file = $tmp;
    }
    list($w, $h, $t, $a) = @getimagesize($file);
    if (empty($w)) {
        return false;
    }
    $t = image_type_to_mime_type($t);
    return array($w, $h, $t, $file);
}
示例#4
0
文件: Styles.php 项目: askzap/ask-zap
 /**
  * Converts URL (http://e.com/a.png) to CSS property ( url("../a.png") )
  * @param  string $style_id   style ID
  * @param  array  $style_data style data (fields)
  * @return array  modified style data
  */
 private function urlToCss($style_id, $style_data)
 {
     $patterns_url = Patterns::instance($this->params)->getUrl($style_id, true);
     if (!empty($this->schema['backgrounds']['fields'])) {
         foreach ($this->schema['backgrounds']['fields'] as $field) {
             if (!empty($field['properties']['pattern'])) {
                 $var_name = $field['properties']['pattern'];
                 if (!empty($style_data[$var_name]) && strpos($style_data[$var_name], '//') !== false) {
                     $url = preg_replace('/url\\([\'"]?(.*?)[\'"]?\\)/', '$1', $style_data[$var_name]);
                     if (strpos($url, '//') === 0) {
                         $url = 'http:' . $url;
                     }
                     $url = fn_normalize_path($url);
                     if (strpos($url, $patterns_url) !== false) {
                         $url = str_replace($patterns_url, '..', $url);
                         if (strpos($url, '?') !== false) {
                             // URL is parsed by Less::parseUrls method, so remove everything after ?
                             list($url) = explode('?', $url);
                         }
                     } elseif ($style_id) {
                         // external url
                         $tmp_file = fn_create_temp_file();
                         fn_put_contents($tmp_file, fn_get_contents($url));
                         $_style = Patterns::instance($this->params)->save($style_id, array('data' => $style_data), array($var_name => array('name' => fn_basename($url), 'path' => $tmp_file)));
                         $style_data = $_style['data'];
                         continue;
                         // assignment done in save method
                     }
                     $style_data[$var_name] = 'url(' . $url . ')';
                 }
             }
         }
     }
     return $style_data;
 }
示例#5
0
/**
 * Function get local uploaded
 *
 * @param array $val
 * @staticvar array $cache
 * @return array
 */
function fn_get_local_data($val)
{
    $cache = Registry::get('temp_fs_data');
    if (!isset($cache[$val['path']])) {
        // cache file to allow multiple usage
        $tempfile = fn_create_temp_file();
        if (move_uploaded_file($val['path'], $tempfile) == true) {
            @chmod($tempfile, DEFAULT_FILE_PERMISSIONS);
            clearstatcache(true, $tempfile);
            $cache[$val['path']] = $tempfile;
        } else {
            $cache[$val['path']] = '';
        }
        Registry::set('temp_fs_data', $cache);
    }
    if (defined('KEEP_UPLOADED_FILES')) {
        $tempfile = fn_create_temp_file();
        fn_copy($cache[$val['path']], $tempfile);
        $val['path'] = $tempfile;
    } else {
        $val['path'] = $cache[$val['path']];
    }
    return !empty($val['size']) ? $val : false;
}
示例#6
0
/**
 * Function get local uploaded
 *
 * @param unknown_type $val
 * @staticvar array $cache
 * @return unknown
 */
function fn_get_local_data($val)
{
    $cache =& Registry::get('temp_fs_data');
    if (!isset($cache[$val['path']])) {
        // cache file to allow multiple usage
        $tempfile = fn_create_temp_file();
        //	var_dump($tempfile);
        /*error_reporting(E_ALL);
        		ini_set('display_errors', '1');
        		*/
        if (move_uploaded_file($val['path'], $tempfile) == true) {
            @chmod($tempfile, DEFAULT_FILE_PERMISSIONS);
            $cache[$val['path']] = $tempfile;
        } else {
            $cache[$val['path']] = '';
        }
    }
    if (defined('KEEP_UPLOADED_FILES')) {
        $tempfile = fn_create_temp_file();
        fn_copy($cache[$val['path']], $tempfile);
        clearstatcache();
        $val['path'] = $tempfile;
    } else {
        $val['path'] = $cache[$val['path']];
        //	$val['path'] = $val['path'];
    }
    return $val;
}
示例#7
0
 private static function fn_twg_get_image_by_api_data($api_image)
 {
     if (empty($api_image['data']) || empty($api_image['file_name']) && empty($api_image['type'])) {
         return false;
     }
     if (empty($api_image['file_name'])) {
         $api_image['file_name'] = 'image_' . strtolower(fn_generate_code('', 4)) . '.' . $api_image['type'];
     }
     $_data = base64_decode($api_image['data']);
     $image = array('name' => $api_image['file_name'], 'path' => fn_create_temp_file(), 'size' => strlen($_data));
     $file_descriptor = fopen($image['path'], 'wb');
     if (!$file_descriptor) {
         return false;
     }
     fwrite($file_descriptor, $_data, $image['size']);
     fclose($file_descriptor);
     @chmod($image['path'], DEFAULT_FILE_PERMISSIONS);
     return $image;
 }
示例#8
0
文件: pdf.php 项目: askzap/ultimate
                            $counter->out();
                        }
                    } else {
                        $tbl .= fn_price_list_print_product_data($product, $selected_fields, $style, $price_schema);
                        $fill = !$fill;
                    }
                    $counter->out();
                }
                $tbl .= '</table>';
                $counter->out();
                Pdf::batchAdd($tbl);
            }
        }
    }
    //Close and output PDF document
    $temp_filename = fn_create_temp_file();
    $imp_filename = $temp_filename . '.pdf';
    fn_rename($temp_filename, $imp_filename);
    Pdf::batchRender($imp_filename, true);
    Storage::instance('assets')->put($filename, array('file' => $imp_filename, 'caching' => true));
    fn_echo('<br />' . __('done'));
}
/**
 *
 * Adds product data in HTML format to price list table
 * @param array $product Product data
 * @param array $selected_fields Product fields that should be in price list
 * @param string $style Product row style (similar to the HTML style attribute, e.g.: style="background-color: #EEEEEE")
 * @param array $price_schema Price list columns scheme
 * @param array $options_variants Product options variants
 *
示例#9
0
 /**
  * Creates PO file for specified Language
  *
  * @param string $lang_code 2-letters language code (Example: "en", "ru")
  * @param string $output    Output destination
  *      screen - Output countent direct to browser page
  *      download - Force file downloading
  *      server - upload file to the config.dir.lang_packs directory
  * @param string $output_file Default name is $lang_code . '.po'
  */
 public static function createPoFile($lang_code, $output = 'download', $output_file = '')
 {
     // Translation packs should not include "Not translated" language data
     $allow_overlap = $lang_code == 'en' ? true : false;
     $filename = fn_create_temp_file();
     if (empty($output_file)) {
         $output_file = $lang_code . '.po';
     }
     $langs = self::get(array('lang_code' => $lang_code));
     $lang = $langs[$lang_code];
     Po::createHeader($filename, $lang);
     // Export Language values
     list($values) = LanguageValues::getVariables(array(), 0, $lang_code);
     $original_values = self::getOriginalValues('Languages');
     foreach ($values as $_id => $value) {
         $values[$_id]['original_value'] = isset($original_values['Languages::' . $value['name']]) ? $original_values['Languages::' . $value['name']]['msgid'] : '';
     }
     $values = Po::convert($values, array(), $allow_overlap);
     Po::putValues('Languages', $values, $filename);
     // Export "SettingsVariants"
     $values = Settings::instance()->getVariants('', '', '', 'all', $lang_code);
     $original_values = self::getOriginalValues('SettingsVariants');
     foreach ($values as $_id => $value) {
         $values[$_id]['original_value'] = isset($original_values['SettingsVariants::' . $_id]) ? $original_values['SettingsVariants::' . $_id]['msgid'] : '';
     }
     $values = Po::convert($values, array('id' => '%key'), $allow_overlap);
     Po::putValues('SettingsVariants', $values, $filename);
     // Export Settings Sections
     $values = Settings::instance()->getCoreSections($lang_code);
     $original_values = self::getOriginalValues('SettingsSections');
     foreach ($values as $_id => $value) {
         $values[$_id]['original_value'] = isset($original_values['SettingsSections::' . $value['section_id']]) ? $original_values['SettingsSections::' . $value['section_id']]['msgid'] : '';
     }
     $values = Po::convert($values, array('id' => 'section_id', 'value' => 'description'), $allow_overlap);
     Po::putValues('SettingsSections', $values, $filename);
     // Export Settings Options
     $values = Settings::instance()->getList(0, 0, true, null, $lang_code);
     $original_values = self::getOriginalValues('SettingsOptions');
     foreach ($values as $_id => $value) {
         $values[$_id]['original_value'] = isset($original_values['SettingsOptions::' . $value['name']]) ? $original_values['SettingsOptions::' . $value['name']]['msgid'] : '';
     }
     $values = Po::convert($values, array('id' => 'name', 'value' => 'description'), $allow_overlap);
     Po::putValues('SettingsOptions', $values, $filename);
     // Export Addons data (name, description)
     list($addons) = fn_get_addons(array('type' => 'installed'), 0, $lang_code);
     $values = array();
     foreach ($addons as $addon_id => $addon) {
         $values[] = array('name' => $addon_id, 'value' => $addon['name'], 'original_value' => $addon['originals']['name']);
     }
     $values = Po::convert($values, array(), $allow_overlap);
     Po::putValues('Addon', $values, $filename);
     $values = array();
     foreach ($addons as $addon_id => $addon) {
         $values[] = array('name' => $addon_id, 'value' => $addon['description'], 'original_value' => $addon['originals']['description']);
     }
     $values = Po::convert($values, array(), $allow_overlap);
     Po::putValues('AddonDescription', $values, $filename);
     // Export Profile fields
     $profile_fields = fn_get_profile_fields('ALL', array(), $lang_code);
     $original_values = self::getOriginalValues('ProfileFields');
     $values = array();
     foreach ($profile_fields as $zone => $fields) {
         foreach ($fields as $field_id => $field) {
             $values[] = array('name' => $field['field_name'], 'value' => $field['description'], 'original_value' => isset($original_values['ProfileFields::' . $field['field_name']]) ? $original_values['ProfileFields::' . $field['field_name']]['msgid'] : '');
         }
     }
     $values = Po::convert($values, array(), $allow_overlap);
     Po::putValues('ProfileFields', $values, $filename);
     switch ($output) {
         case 'screen':
             header("Content-type: text/plain");
             readfile($filename);
             exit;
             break;
         case 'server':
             fn_copy($filename, Registry::get('config.dir.lang_packs') . $output_file);
             break;
         case 'download':
             fn_get_file($filename, $output_file);
             break;
     }
 }
示例#10
0
function fn_find_file($prefix, $file)
{
    $file = fn_strip_slashes($file);
    // Absolute path
    if (is_file($file)) {
        return realpath($file);
    }
    // Path is relative to prefix
    if (is_file($prefix . '/' . $file)) {
        return realpath($prefix . '/' . $file);
    }
    // Url
    if (strpos($file, '://') !== false) {
        $content = fn_get_contents($file);
        if (!empty($content)) {
            $fname = basename($file);
            if (empty($fname) || strpos($fname, '?') !== false) {
                $fname = basename(fn_create_temp_file());
            }
            if (fn_put_contents(DIR_COMPILED . $fname, $content)) {
                return DIR_COMPILED . $fname;
            }
        }
    }
    return false;
}
示例#11
0
 private static final function getApiImageBinData($icon, $params, $type = 'product')
 {
     if (!empty($icon['absolute_path'])) {
         $image_file = $icon['absolute_path'];
     } else {
         $_image_file = db_get_field("SELECT image_path FROM ?:images WHERE image_id = ?i", $params['image_id']);
         $image_file = Registry::get('config.dir.images') . $type . '/' . $_image_file;
     }
     if (extension_loaded('gd') && (!empty($params['image_x']) || !empty($params['image_y']))) {
         $new_image_x = !empty($params['image_x']) ? $params['image_x'] : $params['image_y'] / $icon['image_y'] * $icon['image_x'];
         $new_image_y = !empty($params['image_y']) ? $params['image_y'] : $params['image_x'] / $icon['image_x'] * $icon['image_y'];
         $new_image_gd = imagecreatetruecolor($new_image_x, $new_image_y);
         list(, , $mime_type) = fn_get_image_size($image_file);
         $ext = fn_get_image_extension($mime_type);
         if ($ext == 'gif' && function_exists('imagegif')) {
             $image_gd = imagecreatefromgif($image_file);
         } elseif ($ext == 'jpg' && function_exists('imagejpeg')) {
             $image_gd = imagecreatefromjpeg($image_file);
         } elseif ($ext == 'png' && function_exists('imagepng')) {
             $image_gd = imagecreatefrompng($image_file);
         } else {
             return false;
         }
         imagecopyresized($new_image_gd, $image_gd, 0, 0, 0, 0, $new_image_x, $new_image_y, $icon['image_x'], $icon['image_y']);
         $tmp_file = fn_create_temp_file();
         if ($ext == 'gif') {
             imagegif($new_image_gd, $tmp_file);
         } elseif ($ext == 'jpg') {
             imagejpeg($new_image_gd, $tmp_file, 50);
         } elseif ($ext == 'png') {
             imagepng($new_image_gd, $tmp_file, 0);
         }
         if (!($image_data = fn_get_contents($tmp_file))) {
             return false;
         }
         $icon['data'] = base64_encode($image_data);
         $icon['image_x'] = $new_image_x;
         $icon['image_y'] = $new_image_y;
     } elseif (fn_get_contents($image_file)) {
         $image_data = fn_get_contents($image_file);
         $icon['data'] = base64_encode($image_data);
     }
     return $icon;
 }