php Tygh-Storage类(方法)实例源码

下面列出了php Tygh-Storage 类(方法)源码代码实例,从而了解它的用法。

作者:ambient-loung    项目:sit   
public static function getDirCommerceML()
 {
     self::$path_commerceml = fn_get_files_dir_path() . 'exim/1C_' . date('dmY') . '/';
     self::$url_commerceml = Registry::get('config.http_location') . '/' . fn_get_rel_dir(self::$path_commerceml);
     self::$url_images = Storage::instance('images')->getAbsolutePath('from_1c/');
     return array(self::$path_commerceml, self::$url_commerceml, self::$url_images);
 }

作者:ambient-loung    项目:sit   
/**
 * Check detail image sizes ration
 *
 * @param array $image_data Image data
 * @param array $images Array with initial images
 */
function fn_image_zoom_check_image(&$image_data, &$images)
{
    $precision = 80;
    $ratio_detailed = round(round($images['detailed']['image_x'] / $images['detailed']['image_y'] * $precision) / $precision, 2);
    $ratio_original = round(round($image_data['width'] / $image_data['height'] * $precision) / $precision, 2);
    if ($ratio_detailed != $ratio_original) {
        if ($ratio_detailed < $ratio_original) {
            $new_x = ceil($images['detailed']['image_y'] / $image_data['height'] * $image_data['width']);
            $new_y = $images['detailed']['image_y'];
        } else {
            $new_y = ceil($images['detailed']['image_x'] / $image_data['width'] * $image_data['height']);
            $new_x = $images['detailed']['image_x'];
        }
        $file_path = fn_generate_thumbnail($images['detailed']['relative_path'], $new_x, $new_y, false, true);
        /**
         * Post hook for check detail image sizes ration
         * @param string $file_path File path
         * @param array $image_data Image data
         * @param array $images Array with initial images
         */
        fn_set_hook('image_zoom_check_image_post', $file_path, $image_data, $images);
        if ($file_path) {
            $image_data['detailed_image_path'] = \Tygh\Storage::instance('images')->getUrl($file_path);
        }
    }
}

作者:heg-arc-n    项目:cscar   
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */
function smarty_block_scripts($params, $content, &$smarty, &$repeat)
{
    if ($repeat == true) {
        Registry::set('runtime.inside_scripts', 1);
        return;
    }
    if (Registry::get('config.tweaks.dev_js')) {
        $content .= smarty_helper_inline_scripts($params, $content, $smarty, $repeat);
        return $content;
    }
    $scripts = array();
    $external_scripts = array();
    $dir_root = Registry::get('config.dir.root');
    $return = '';
    $current_location = Registry::get('config.current_location');
    if (preg_match_all('/\\<script(.*?)\\>(.*?)\\<\\/script\\>/s', $content, $m)) {
        $contents = '';
        foreach ($m[1] as $src) {
            if (!empty($src) && preg_match('/src ?= ?"([^"]+)"/', $src, $_m)) {
                if (strpos($_m[1], $current_location) !== false) {
                    $scripts[] = str_replace($current_location, '', preg_replace('/\\?.*?$/', '', $_m[1]));
                } else {
                    $external_scripts[] = $_m[1];
                }
            }
        }
        // Check file changes in dev mode
        $names = $scripts;
        if (Development::isEnabled('compile_check')) {
            foreach ($names as $index => $name) {
                if (is_file($dir_root . '/' . $name)) {
                    $names[$index] .= filemtime($dir_root . '/' . $name);
                }
            }
        }
        $filename = 'js/tygh/scripts-' . md5(implode(',', $names)) . fn_get_storage_data('cache_id') . '.js';
        if (!Storage::instance('statics')->isExist($filename)) {
            foreach ($scripts as $src) {
                $contents .= fn_get_contents(Registry::get('config.dir.root') . $src);
            }
            $contents = str_replace('[files]', implode("\n", $scripts), Registry::get('config.js_css_cache_msg')) . $contents;
            $contents = Minifier::minify($contents, array('flaggedComments' => false));
            Storage::instance('statics')->put($filename, array('contents' => $contents, 'compress' => false, 'caching' => true));
        }
        $return = '<script type="text/javascript" src="' . Storage::instance('statics')->getUrl($filename) . '?ver=' . PRODUCT_VERSION . '"></script>' . "\n";
        if (!empty($external_scripts)) {
            foreach ($external_scripts as $sc) {
                $return .= '<script type="text/javascript" src="' . $sc . '"></script>' . "\n";
            }
        }
        foreach ($m[2] as $sc) {
            if (!empty($sc)) {
                $return .= '<script type="text/javascript">' . $sc . '</script>' . "\n";
            }
        }
        $return .= smarty_helper_inline_scripts($params, $content, $smarty, $repeat);
    }
    return $return;
}

作者:heg-arc-n    项目:cscar   
function fn_settings_actions_addons_hidpi(&$new_value, $old_value)
{
    Storage::instance('images')->deleteDir('thumbnails');
    if ($new_value == 'A') {
        $formats = fn_check_gd_formats();
        // Set thumbnail generation format to png to improve quality
        if (!empty($formats['png'])) {
            Settings::instance()->updateValue('convert_to', 'png', 'Thumbnails');
        }
    }
}

作者:ambient-loung    项目:sit   
function fn_settings_actions_addons_hidpi(&$new_value, $old_value)
{
    Storage::instance('images')->deleteDir('thumbnails');
    if ($new_value == 'A') {
        $formats = fn_get_supported_image_format_variants();
        // Set thumbnail generation format to png to improve quality
        if (!empty($formats['png'])) {
            Settings::instance()->updateValue('convert_to', 'png', 'Thumbnails');
            fn_set_notification('W', __('warning'), __('addons.hidpi.thumbnail_format_changed', array('[settings_url]' => fn_url('settings.manage?section_id=Thumbnails'))));
        }
    }
}

作者:OneataBogda    项目:lead_coriola   
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */
function smarty_block_scripts($params, $content, &$smarty, &$repeat)
{
    if ($repeat == true) {
        return;
    }
    if (Registry::get('config.tweaks.dev_js')) {
        return $content;
    }
    $scripts = array();
    $dir_root = Registry::get('config.dir.root');
    $return = '';
    if (preg_match_all('/\\<script(.*?)\\>(.*?)\\<\\/script\\>/s', $content, $m)) {
        $contents = '';
        foreach ($m[1] as $src) {
            if (!empty($src) && preg_match('/src ?= ?"([^"]+)"/', $src, $_m)) {
                $scripts[] = str_replace(Registry::get('config.current_location'), '', preg_replace('/\\?.*?$/', '', $_m[1]));
            }
        }
        // Check file changes in dev mode
        $names = $scripts;
        if (Development::isEnabled('compile_check')) {
            foreach ($names as $index => $name) {
                if (is_file($dir_root . '/' . $name)) {
                    $names[$index] .= filemtime($dir_root . '/' . $name);
                }
            }
        }
        $gz_suffix = Registry::get('config.tweaks.gzip_css_js') ? '.gz' : '';
        $filename = 'js/tygh/scripts-' . md5(implode(',', $names)) . fn_get_storage_data('cache_id') . '.js';
        if (!Storage::instance('statics')->isExist($filename . $gz_suffix)) {
            foreach ($scripts as $src) {
                $contents .= fn_get_contents(Registry::get('config.dir.root') . $src);
            }
            $contents = str_replace('[files]', implode("\n", $scripts), Registry::get('config.js_css_cache_msg')) . $contents;
            Storage::instance('statics')->put($filename . $gz_suffix, array('contents' => $contents, 'compress' => Registry::get('config.tweaks.gzip_css_js'), 'caching' => true));
        }
        $return = '<script type="text/javascript" src="' . Storage::instance('statics')->getUrl($filename) . '?ver=' . PRODUCT_VERSION . '"></script>';
        foreach ($m[2] as $sc) {
            if (!empty($sc)) {
                $return .= '<script type="text/javascript">' . $sc . '</script>' . "\n";
            }
        }
    }
    return $return;
}

作者:arpad    项目:bygmarke   
/**
 * Export image (moves to selected directory on filesystem)
 *
 * @param int $image_id ID of the image
 * @param string $object object to export image for (product, category, etc...)
 * @param string $backup_path path to export image
 * @return string path to the exported image
 */
function fn_export_image($image_id, $object, $backup_path = '', $include_alt = true)
{
    if (empty($backup_path)) {
        $backup_path = 'exim/backup/images/' . $object . '/';
    }
    $backup_path = rtrim(fn_normalize_path($backup_path), '/');
    $images_path = fn_get_files_dir_path() . $backup_path;
    // if backup dir does not exist then try to create it
    fn_mkdir($images_path);
    $image_data = db_get_row("SELECT image_id, image_path FROM ?:images WHERE image_id = ?i", $image_id);
    if (empty($image_data)) {
        return '';
    }
    if ($include_alt) {
        $alt_data = db_get_hash_single_array("SELECT lang_code, description FROM ?:common_descriptions WHERE ?:common_descriptions.object_id = ?i AND ?:common_descriptions.object_holder = 'images'", array('lang_code', 'description'), $image_id);
        $alt_text = '#{';
        if (!empty($alt_data)) {
            foreach ($alt_data as $lang_code => $text) {
                $alt_text .= '[' . $lang_code . ']:' . $text . ';';
            }
        }
        $alt_text .= '}';
    }
    $path = $images_path . '/' . fn_basename($image_data['image_path']);
    Storage::instance('images')->export($object . '/' . floor($image_id / MAX_FILES_IN_DIR) . '/' . $image_data['image_path'], $path);
    return $backup_path . '/' . fn_basename($image_data['image_path']) . (!empty($alt_data) && $include_alt ? $alt_text : '');
}

作者:OneataBogda    项目:lead_coriola   
/**
 * Hook: deletes HiDPI image
 * @param int $image_id
 * @param int $pair_id
 * @param string $object_type
 * @param string $_image_file
 */
function fn_hidpi_delete_image($image_id, $pair_id, $object_type, $_image_file)
{
    Storage::instance('images')->delete(fn_hdpi_form_name($_image_file));
}

作者:heg-arc-n    项目:cscar   
}
    $type = empty($_REQUEST['type']) ? 'T' : $_REQUEST['type'];
    $image_path = 'sess_data/' . fn_basename($_REQUEST['image']);
    if (Storage::instance('custom_files')->isExist($image_path)) {
        $real_path = Storage::instance('custom_files')->getAbsolutePath($image_path);
        list(, , $image_type, $tmp_path) = fn_get_image_size($real_path);
        if ($type == 'T') {
            $thumb_path = $image_path . '_thumb';
            if (!Storage::instance('custom_files')->isExist($thumb_path)) {
                // Output a thumbnail image
                list($cont, $format) = fn_resize_image($tmp_path, Registry::get('settings.Thumbnails.product_lists_thumbnail_width'), Registry::get('settings.Thumbnails.product_lists_thumbnail_height'), Registry::get('settings.Thumbnails.thumbnail_background_color'));
                if (!empty($cont)) {
                    Storage::instance('custom_files')->put($thumb_path, array('contents' => $cont));
                }
            }
            $real_path = Storage::instance('custom_files')->getAbsolutePath($thumb_path);
        }
        header('Content-type: ' . $image_type);
        fn_echo(fn_get_contents($real_path));
        exit;
    }
    // Not image file. Display spacer instead.
    header('Content-type: image/gif');
    readfile(fn_get_theme_path('[themes]/[theme]') . '/media/images/spacer.gif');
    exit;
} elseif ($mode == 'thumbnail') {
    $img = fn_generate_thumbnail($_REQUEST['image_path'], $_REQUEST['w'], $_REQUEST['h']);
    if (!empty($img)) {
        header('Content-type: ' . fn_get_file_type($img));
        fn_echo(fn_get_contents($img));
    }

作者:askza    项目:ask-za   
function fn_rus_exim_1c_get_dir_1c()
{
    $dir_1c = fn_get_files_dir_path() . 'exim/1C_' . date('dmY') . '/';
    $dir_1c_url = Registry::get('config.http_location') . '/' . fn_get_rel_dir($dir_1c);
    $dir_1c_images = Storage::instance('images')->getAbsolutePath('from_1c/');
    return array($dir_1c, $dir_1c_url, $dir_1c_images);
}

作者:arpad    项目:bygmarke   
/**
 * Merges css and less files
 *
 * @param array $files Array with style files
 * @param string $styles Style code
 * @param string $prepend_prefix Prepend prefix
 * @param array $params additional params
 */
function fn_merge_styles($files, $styles = '', $prepend_prefix = '', $params = array(), $area = AREA)
{
    $prefix = !empty($prepend_prefix) ? 'embedded' : 'standalone';
    $make_rtl = false;
    if (fn_is_rtl_language()) {
        $prefix .= '-rtl';
        $make_rtl = true;
    }
    $output = '';
    $less_output = '';
    $less_reflection = array();
    $compiled_less = '';
    $compiled_css = '';
    $relative_path = fn_get_theme_path('[relative]/[theme]/css', $area);
    $hashes = array();
    $names = array_map(function ($v) {
        return !empty($v['relative']) ? $v['relative'] : false;
    }, $files);
    // Check file changes
    if (Development::isEnabled('compile_check') || Debugger::isActive()) {
        $dir_root = Registry::get('config.dir.root');
        foreach ($names as $index => $name) {
            if (file_exists($dir_root . '/' . $name)) {
                $hashes[] = $name . filemtime($dir_root . '/' . $name);
            }
        }
    }
    $hashes[] = md5(implode('|', $names));
    $hashes[] = md5($styles);
    if ($area == 'C') {
        $hashes[] = Registry::get('runtime.layout.layout_id');
        $hashes[] = Registry::get('runtime.layout.style_id');
    }
    arsort($hashes);
    $hash = md5(implode(',', $hashes) . PRODUCT_VERSION) . fn_get_storage_data('cache_id');
    $filename = $prefix . '.' . $hash . '.css';
    $theme_manifest = Themes::factory(fn_get_theme_path('[theme]', 'C'))->getManifest();
    if (!Storage::instance('assets')->isExist($relative_path . '/' . $filename)) {
        Debugger::checkpoint('Before styles compilation');
        foreach ($files as $src) {
            $m_prefix = '';
            $m_suffix = '';
            if (!empty($src['media'])) {
                $m_prefix = "\n@media " . $src['media'] . " {\n";
                $m_suffix = "\n}\n";
            }
            if (strpos($src['file'], '.css') !== false) {
                $output .= "\n" . $m_prefix . fn_get_contents($src['file']) . $m_suffix;
            } elseif ($area != 'C' || empty($theme_manifest['converted_to_css'])) {
                $less_output_chunk = '';
                if (file_exists($src['file'])) {
                    if ($area == 'C' && (empty($theme_manifest['parent_theme']) || $theme_manifest['parent_theme'] == 'basic')) {
                        $less_output_chunk = "\n" . $m_prefix . fn_get_contents($src['file']) . $m_suffix;
                    } else {
                        $less_output_chunk = "\n" . $m_prefix . '@import "' . str_replace($relative_path . '/', '', $src['relative']) . '";' . $m_suffix;
                    }
                }
                if (!empty($params['reflect_less'])) {
                    if (preg_match('{/addons/([^/]+)/}is', $src['relative'], $m)) {
                        $less_reflection['output']['addons'][$m[1]] .= $less_output_chunk;
                    } else {
                        $less_reflection['output']['main'] .= $less_output_chunk;
                    }
                }
                $less_output .= $less_output_chunk;
            }
        }
        $header = str_replace('[files]', implode("\n", $names), Registry::get('config.js_css_cache_msg'));
        if (!empty($styles)) {
            $less_output .= $styles;
        }
        // Prepend all styles with prefix
        if (!empty($prepend_prefix)) {
            $less_output = $output . "\n" . $less_output;
            $output = '';
        }
        if (!empty($output)) {
            $compiled_css = Less::parseUrls($output, Storage::instance('assets')->getAbsolutePath($relative_path), fn_get_theme_path('[themes]/[theme]/media', $area));
        }
        if (!empty($theme_manifest['converted_to_css']) && $area == 'C') {
            $theme_css_path = fn_get_theme_path('[themes]/[theme]', $area) . '/css';
            $pcl_filepath = $theme_css_path . '/' . Themes::$compiled_less_filename;
            if (file_exists($pcl_filepath)) {
                $compiled_css .= fn_get_contents($pcl_filepath);
            }
            list($installed_addons) = fn_get_addons(array('type' => 'active'));
            foreach ($installed_addons as $addon) {
                $addon_pcl_filpath = $theme_css_path . "/addons/{$addon['addon']}/" . Themes::$compiled_less_filename;
                if (file_exists($pcl_filepath)) {
                    $compiled_css .= fn_get_contents($addon_pcl_filpath);
                }
            }
//.........这里部分代码省略.........

作者:askza    项目:ultimat   
}
if (Registry::get('config.demo_mode')) {
    // ElFinder should not work in demo mode
    $message = json_encode(array('error' => __('error_demo_mode')));
    exit($message);
}
if (AREA == 'C') {
    if (!Registry::get('runtime.customization_mode.live_editor')) {
        die('Access denied');
    }
}
$private_files_path = fn_get_files_dir_path();
$public_files_path = fn_get_public_files_path();
fn_mkdir($private_files_path);
fn_mkdir($public_files_path);
$start_path = '';
if (!empty($_REQUEST['init']) && !empty($_REQUEST['start_path'])) {
    unset($_GET['target']);
    $start_path = fn_normalize_path($private_files_path . $_REQUEST['start_path']);
    if (strpos($start_path, $private_files_path) !== 0) {
        $start_path = '';
    }
}
$extra_path = str_replace(Storage::instance('images')->getAbsolutePath(''), '', $public_files_path);
$opts = array('roots' => array(array('driver' => 'Tygh\\ElFinder\\Volume', 'uploadDeny' => Registry::get('config.forbidden_mime_types'), 'fileMode' => DEFAULT_FILE_PERMISSIONS, 'dirMode' => DEFAULT_DIR_PERMISSIONS, 'uploadMaxSize' => Bootstrap::getIniParam('upload_max_filesize', true), 'alias' => __('private_files'), 'tmbPath' => '', 'path' => $private_files_path, 'startPath' => $start_path, 'mimeDetect' => 'internal', 'archiveMimes' => array('application/zip'), 'icon' => Registry::get('config.current_location') . '/js/lib/elfinder/img/volume_icon_local.png'), array('driver' => 'Tygh\\ElFinder\\Volume', 'uploadDeny' => Registry::get('config.forbidden_mime_types'), 'fileMode' => DEFAULT_FILE_PERMISSIONS, 'dirMode' => DEFAULT_DIR_PERMISSIONS, 'uploadMaxSize' => Bootstrap::getIniParam('upload_max_filesize', true), 'alias' => __('public_files'), 'tmbPath' => '', 'path' => $public_files_path, 'URL' => Storage::instance('images')->getUrl($extra_path), 'mimeDetect' => 'internal', 'archiveMimes' => array('application/zip'), 'icon' => Registry::get('config.current_location') . '/js/lib/elfinder/img/volume_icon_local.png')));
if ($mode == 'images') {
    unset($opts['roots'][0]);
}
$connector = new \elFinderConnector(new Core($opts));
$connector->run();
exit;

作者:OneataBogda    项目:lead_coriola   
function fn_exim_export_file($product_id, $path)
{
    $path = fn_get_files_dir_path() . fn_normalize_path($path);
    $files = db_get_array("SELECT file_path, preview_path, pfolder.folder_id FROM ?:product_files as pfiles" . " LEFT JOIN ?:product_file_folders as pfolder ON pfolder.folder_id = pfiles.folder_id" . " WHERE pfiles.product_id = ?i", $product_id);
    if (!empty($files)) {
        // If backup path is set, check if it exists and copy files there
        if (!empty($path)) {
            if (!fn_mkdir($path)) {
                fn_set_notification('E', __('error'), __('text_cannot_create_directory', array('[directory]' => fn_get_rel_dir($path))));
                return '';
            }
        }
        $_data = array();
        foreach ($files as $file) {
            Storage::instance('downloads')->export($product_id . '/' . $file['file_path'], $path . '/' . $file['file_path']);
            if (!empty($file['preview_path'])) {
                Storage::instance('downloads')->export($product_id . '/' . $file['preview_path'], $path . '/' . $file['preview_path']);
            }
            $file_data = $file['file_path'];
            if (!empty($file['folder_id'])) {
                $file_data = $file['folder_id'] . '/' . $file_data;
            }
            if (!empty($file['preview_path'])) {
                $file_data = $file_data . '#' . $file['preview_path'];
            }
            $_data[] = $file_data;
        }
        return implode(', ', $_data);
    }
    return '';
}

作者:askza    项目:ultimat   
$redirect_mode = empty($_REQUEST['redirect_mode']) ? 'cart' : $_REQUEST['redirect_mode'];
    return array(CONTROLLER_STATUS_REDIRECT, 'checkout.' . $redirect_mode);
} elseif ($mode == 'get_custom_file' && isset($_REQUEST['cart_id']) && isset($_REQUEST['option_id']) && isset($_REQUEST['file'])) {
    if (isset($cart['products'][$_REQUEST['cart_id']]['extra']['custom_files'][$_REQUEST['option_id']][$_REQUEST['file']])) {
        $file = $cart['products'][$_REQUEST['cart_id']]['extra']['custom_files'][$_REQUEST['option_id']][$_REQUEST['file']];
        Storage::instance('custom_files')->get($file['path'], $file['name']);
    }
} elseif ($mode == 'delete_file' && isset($_REQUEST['cart_id'])) {
    if (isset($cart['products'][$_REQUEST['cart_id']]['extra']['custom_files'][$_REQUEST['option_id']][$_REQUEST['file']])) {
        // Delete saved custom file
        $product = $cart['products'][$_REQUEST['cart_id']];
        $option_id = $_REQUEST['option_id'];
        $file_id = $_REQUEST['file'];
        $file = $product['extra']['custom_files'][$option_id][$file_id];
        Storage::instance('custom_files')->delete($file['path']);
        Storage::instance('custom_files')->delete($file['path'] . '_thumb');
        unset($product['extra']['custom_files'][$option_id][$file_id]);
        if (!empty($product['extra']['custom_files'][$option_id])) {
            $product['product_options'][$option_id] = md5(serialize($product['extra']['custom_files'][$option_id]));
        } else {
            unset($product['product_options'][$option_id]);
        }
        $product['extra']['product_options'] = empty($product['product_options']) ? array() : $product['product_options'];
        $cart['products'][$_REQUEST['cart_id']] = $product;
    }
    fn_save_cart_content($cart, $auth['user_id']);
    $cart['recalculate'] = true;
    if (defined('AJAX_REQUEST')) {
        fn_set_notification('N', __('notice'), __('text_product_file_has_been_deleted'));
        if (Registry::get('runtime.action') == 'from_status') {
            fn_calculate_cart_content($cart, $auth, 'S', true, 'F', true);

作者:askza    项目:ultimat   
/**
  * Compile chunk of LESS output and save the result in the file
  *
  * @param string $less_output Chunk of LESS output
  * @param string $css_path    The path where the precompiled LESS will be saved
  *
  * @return boolean Result
  */
 protected function convertChunkToCss($less_output, $css_path)
 {
     $less = $this->getLess();
     $less_reflection = $this->getLessReflection();
     $less->setImportDir($less_reflection['import_dirs']);
     Registry::set('runtime.layout', Layout::instance()->getDefault($this->theme_name));
     $from_path = Storage::instance('assets')->getAbsolutePath($this->relative_path . '/css');
     $compiled_less = $less->customCompile($less_output, $from_path, array(), '', 'C');
     $res = fn_put_contents($css_path . '/' . self::$compiled_less_filename, $compiled_less);
     if ($res === false) {
         return false;
     }
     return true;
 }

作者:OneataBogda    项目:lead_coriola   
/**
 * Download product file
 *
 * @param int $file_id file ID
 * @param boolean $is_preview flag indicates that we download file itself or just preview
 * @param string $ekey temporary key to download file from customer area
 * @param string $area current working area
 * @return file starts to download on success, boolean false in case of fail
 */
function fn_get_product_file($file_id, $is_preview = false, $ekey = '', $area = AREA)
{
    if (!empty($file_id)) {
        $column = $is_preview ? 'preview_path' : 'file_path';
        $file_data = db_get_row("SELECT {$column}, product_id FROM ?:product_files WHERE file_id = ?i", $file_id);
        if (fn_allowed_for('MULTIVENDOR') && $area == 'A' && !fn_company_products_check($file_data['product_id'], true)) {
            return false;
        }
        if (!empty($ekey)) {
            $ekey_info = fn_get_product_edp_info($file_data['product_id'], $ekey);
            if (empty($ekey_info) || $ekey_info['file_id'] != $file_id) {
                return false;
            }
            // Increase downloads for this file
            $max_downloads = db_get_field("SELECT max_downloads FROM ?:product_files WHERE file_id = ?i", $file_id);
            $file_downloads = db_get_field("SELECT downloads FROM ?:product_file_ekeys WHERE ekey = ?s AND file_id = ?i", $ekey, $file_id);
            if (!empty($max_downloads)) {
                if ($file_downloads >= $max_downloads) {
                    return false;
                }
            }
            db_query('UPDATE ?:product_file_ekeys SET ?u WHERE file_id = ?i AND product_id = ?i AND order_id = ?i', array('downloads' => $file_downloads + 1), $file_id, $file_data['product_id'], $ekey_info['order_id']);
        }
        Storage::instance('downloads')->get($file_data['product_id'] . '/' . $file_data[$column]);
    }
    return false;
}

作者:heg-arc-n    项目:cscar   
$storage_data = fn_restore_post_data('storage_data');
    if (empty($storage_data)) {
        $storage_data = Registry::get('runtime.storage');
    }
    Registry::get('view')->assign('current_storage', Registry::get('runtime.storage.storage'));
    Registry::get('view')->assign('storage_data', $storage_data);
    Registry::get('view')->assign('amazon_data', array('regions' => fn_get_amazon_regions()));
} elseif ($mode == 'clear_cache') {
    fn_clear_cache();
    fn_set_notification('N', __('notice'), __('cache_cleared'));
    if (empty($_REQUEST['redirect_url'])) {
        $_REQUEST['redirect_url'] = 'index.index';
    }
    return array(CONTROLLER_STATUS_REDIRECT);
} elseif ($mode == 'clear_thumbnails') {
    Storage::instance('images')->deleteDir('thumbnails');
    fn_set_notification('N', __('notice'), __('thumbnails_removed'));
    if (empty($_REQUEST['redirect_url'])) {
        $_REQUEST['redirect_url'] = 'index.index';
    }
    return array(CONTROLLER_STATUS_REDIRECT);
} elseif ($mode == 'cdn') {
    $stored_cdn_data = fn_restore_post_data('cdn_data');
    if (Cdn::instance()->getOption('is_active') === false && Cdn::instance()->isActive()) {
        Cdn::instance()->save(array('is_active' => true));
        fn_set_notification('N', __('notice'), __('text_cdn_setup'));
    }
    if (Cdn::instance()->getHost()) {
        Registry::get('view')->assign('cdn_test_url', 'http://' . Cdn::instance()->getHost() . '/js/tygh/core.js');
    }
    if (!empty($stored_cdn_data)) {

作者:heg-arc-n    项目:cscar   
function fn_add_product_options_files($product_data, &$cart, &$auth, $update = false, $location = 'cart')
{
    // Check if products have cusom images
    if (!$update) {
        $uploaded_data = fn_filter_uploaded_data('product_data');
    } else {
        $uploaded_data = fn_filter_uploaded_data('cart_products');
    }
    // Check for the already uploaded files
    if (!empty($product_data['custom_files']['uploaded'])) {
        foreach ($product_data['custom_files']['uploaded'] as $file_id => $file_data) {
            if (Storage::instance('images')->isExist('sess_data/' . fn_basename($file_data['path']))) {
                $id = $file_data['product_id'] . $file_data['option_id'] . $file_id;
                $uploaded_data[$id] = array('name' => $file_data['name'], 'path' => 'sess_data/' . fn_basename($file_data['path']));
                $product_data['custom_files'][$id] = $file_data['product_id'] . '_' . $file_data['option_id'];
            }
        }
    }
    if (!empty($uploaded_data) && !empty($product_data['custom_files'])) {
        $files_data = array();
        foreach ($uploaded_data as $key => $file) {
            $file_info = fn_pathinfo($file['name']);
            $file['extension'] = empty($file_info['extension']) ? '' : $file_info['extension'];
            $file['is_image'] = fn_get_image_extension($file['type']);
            $_data = explode('_', $product_data['custom_files'][$key]);
            $product_id = empty($_data[0]) ? 0 : $_data[0];
            $option_id = empty($_data[1]) ? 0 : $_data[1];
            $file_id = str_replace($option_id . $product_id, '', $key);
            if (empty($file_id)) {
                $files_data[$product_id][$option_id][] = $file;
            } else {
                $files_data[$product_id][$option_id][$file_id] = $file;
            }
        }
    }
    unset($product_data['custom_files']);
    foreach ($product_data as $key => $data) {
        $product_id = !empty($data['product_id']) ? $data['product_id'] : $key;
        // Check if product has cusom images
        if ($update || isset($files_data[$key])) {
            $hash = $key;
        } else {
            $hash = $product_id;
        }
        $_options = fn_get_product_options($product_id);
        if (!empty($files_data[$hash]) && is_array($files_data[$hash])) {
            foreach ($files_data[$hash] as $option_id => $files) {
                foreach ($files as $file_id => $file) {
                    // Check for the allowed extensions
                    if (!empty($_options[$option_id]['allowed_extensions'])) {
                        if (empty($file['extension']) && !empty($_options[$option_id]['allowed_extensions']) || !preg_match("/\\b" . $file['extension'] . "\\b/i", $_options[$option_id]['allowed_extensions'])) {
                            fn_set_notification('E', __('error'), $file['name'] . ': ' . __('text_forbidden_uploaded_file_extension', array('[ext]' => $file['extension'], '[exts]' => $_options[$option_id]['allowed_extensions'])));
                            unset($files_data[$hash][$option_id][$file_id]);
                            continue;
                        }
                    }
                    // Check for the max file size
                    if (!empty($_options[$option_id]['max_file_size'])) {
                        if (empty($file['size'])) {
                            $file['size'] = filesize($file['path']);
                        }
                        if ($file['size'] > $_options[$option_id]['max_file_size'] * 1024) {
                            fn_set_notification('E', __('error'), $file['name'] . ': ' . __('text_forbidden_uploaded_file_size', array('[size]' => $_options[$option_id]['max_file_size'] . ' kb')));
                            unset($files_data[$hash][$option_id][$file_id]);
                            continue;
                        }
                    }
                    $_file_path = 'sess_data/file_' . uniqid(TIME);
                    list(, $_file_path) = Storage::instance('custom_files')->put($_file_path, array('file' => $file['path']));
                    if (!$_file_path) {
                        fn_set_notification('E', __('error'), __('text_cannot_create_file', array('[file]' => $file['name'])));
                        unset($files_data[$hash][$option_id][$file_id]);
                        continue;
                    }
                    $file['path'] = $_file_path;
                    $file['file'] = fn_basename($file['path']);
                    if ($file['is_image']) {
                        $file['thumbnail'] = 'image.custom_image?image=' . $file['file'] . '&type=T';
                        $file['detailed'] = 'image.custom_image?image=' . $file['file'] . '&type=D';
                    }
                    $file['location'] = $location;
                    if ($update) {
                        $cart['products'][$key]['extra']['custom_files'][$option_id][] = $file;
                    } else {
                        $data['extra']['custom_files'][$option_id][] = $file;
                    }
                }
                if ($update) {
                    if (!empty($cart['products'][$key]['product_options'][$option_id])) {
                        $cart['products'][$key]['product_options'][$option_id] = md5(serialize($cart['products'][$key]['extra']['custom_files'][$option_id]));
                    }
                } else {
                    if (!empty($data['extra']['custom_files'][$option_id])) {
                        $data['product_options'][$option_id] = md5(serialize($data['extra']['custom_files'][$option_id]));
                    }
                }
            }
            // Check the required options
            if (empty($data['extra']['parent'])) {
                foreach ($_options as $option) {
//.........这里部分代码省略.........

作者:heg-arc-n    项目:cscar   
function fn_reorder($order_id, &$cart, &$auth)
{
    $order_info = fn_get_order_info($order_id, false, false, false, true);
    unset($_SESSION['shipping_hash']);
    unset($_SESSION['edit_step']);
    fn_set_hook('reorder', $order_info, $cart, $auth);
    foreach ($order_info['products'] as $k => $item) {
        // refresh company id
        $company_id = db_get_field("SELECT company_id FROM ?:products WHERE product_id = ?i", $item['product_id']);
        $order_info['products'][$k]['company_id'] = $company_id;
        unset($order_info['products'][$k]['extra']['ekey_info']);
        $order_info['products'][$k]['product_options'] = empty($order_info['products'][$k]['extra']['product_options']) ? array() : $order_info['products'][$k]['extra']['product_options'];
        $order_info['products'][$k]['main_pair'] = fn_get_cart_product_icon($item['product_id'], $order_info['products'][$k]);
    }
    if (!empty($cart) && !empty($cart['products'])) {
        $cart['products'] = fn_array_merge($cart['products'], $order_info['products']);
    } else {
        $cart['products'] = $order_info['products'];
    }
    foreach ($cart['products'] as $k => $v) {
        $_is_edp = db_get_field("SELECT is_edp FROM ?:products WHERE product_id = ?i", $v['product_id']);
        if ($amount = fn_check_amount_in_stock($v['product_id'], $v['amount'], $v['product_options'], $k, $_is_edp, 0, $cart)) {
            $cart['products'][$k]['amount'] = $amount;
            // Change the path of custom files
            if (!empty($v['extra']['custom_files'])) {
                foreach ($v['extra']['custom_files'] as $option_id => $_data) {
                    if (!empty($_data)) {
                        foreach ($_data as $file_id => $file) {
                            $cart['products'][$k]['extra']['custom_files'][$option_id][$file_id]['path'] = 'sess_data/' . fn_basename($file['path']);
                        }
                    }
                }
            }
        } else {
            unset($cart['products'][$k]);
        }
    }
    // Restore custom files for editing
    $dir_path = 'order_data/' . $order_id;
    if (Storage::instance('custom_files')->isExist($dir_path)) {
        Storage::instance('custom_files')->copy($dir_path, 'sess_data');
    }
    // Redirect customer to step three after reordering
    $cart['payment_updated'] = true;
    fn_save_cart_content($cart, $auth['user_id']);
    unset($cart['product_groups']);
}

作者:askza    项目:ultimat   
function fn_watermark_create($source_filepath, $target_filepath, $is_detailed = false, $company_id = null, $generate_watermark = true)
{
    $original_abs_path = Storage::instance('images')->getAbsolutePath($source_filepath);
    list(, , , $original_abs_path) = fn_get_image_size($original_abs_path);
    if (!$generate_watermark) {
        Storage::instance('images')->put($target_filepath, array('file' => $original_abs_path, 'keep_origins' => true));
        return true;
    }
    $settings = fn_get_watermark_settings($company_id);
    if (empty($settings)) {
        return false;
    }
    list($settings['horizontal_position'], $settings['vertical_position']) = explode('_', $settings['position']);
    /** @var \Imagine\Image\ImagineInterface $imagine */
    $imagine = Tygh::$app['image'];
    try {
        $image = $imagine->open($original_abs_path);
        $image->usePalette(new \Imagine\Image\Palette\RGB());
        $filter = $imagine instanceof \Imagine\Gd\Imagine ? \Imagine\Image\ImageInterface::FILTER_UNDEFINED : \Imagine\Image\ImageInterface::FILTER_LANCZOS;
        if ($settings['type'] == WATERMARK_TYPE_GRAPHIC) {
            $watermark_image_file_path = false;
            if ($is_detailed) {
                if (!empty($settings['image_pair']['detailed']['absolute_path'])) {
                    $watermark_image_file_path = $settings['image_pair']['detailed']['absolute_path'];
                }
            } elseif (!empty($settings['image_pair']['icon']['absolute_path'])) {
                $watermark_image_file_path = $settings['image_pair']['icon']['absolute_path'];
            }
            if (!$watermark_image_file_path) {
                return false;
            }
            list(, , , $watermark_image_file_path) = fn_get_image_size($watermark_image_file_path);
            $watermark_image = $imagine->open($watermark_image_file_path);
            $watermark_image->usePalette(new \Imagine\Image\Palette\RGB());
            // Watermark image > canvas image
            $watermark_size = $watermark_image->getSize()->increase(WATERMARK_PADDING);
            if (!$image->getSize()->contains($watermark_size)) {
                $ratio = min(array($image->getSize()->getWidth() / $watermark_size->getWidth(), $image->getSize()->getHeight() / $watermark_size->getHeight()));
                $watermark_image->resize($watermark_size->scale($ratio), $filter);
            }
            $watermark_position = ImageHelper::positionLayerOnCanvas($image->getSize(), $watermark_image->getSize(), $settings['horizontal_position'], $settings['vertical_position'], new \Imagine\Image\Box(WATERMARK_PADDING, WATERMARK_PADDING));
            $image->paste($watermark_image, $watermark_position);
        } elseif ($settings['type'] == WATERMARK_TYPE_TEXT) {
            $font_path = Registry::get('config.dir.lib') . 'other/fonts/' . $settings['font'] . '.ttf';
            $font_size = $is_detailed ? $settings['font_size_detailed'] : $settings['font_size_icon'];
            $font_alpha_blend = 100;
            switch ($settings['font_color']) {
                case 'white':
                    $font_color = array(255, 255, 255);
                    break;
                case 'black':
                    $font_color = array(0, 0, 0);
                    break;
                case 'gray':
                    $font_color = array(120, 120, 120);
                    break;
                case 'clear_gray':
                default:
                    $font_color = array(120, 120, 120);
                    $font_alpha_blend = WATERMARK_FONT_ALPHA;
                    break;
            }
            $font = $imagine->font($font_path, $font_size, $image->palette()->color($font_color, $font_alpha_blend));
            $text_layer_size = ImageHelper::calculateTextSize($settings['text'], $font);
            $watermark_position = ImageHelper::positionLayerOnCanvas($image->getSize(), $text_layer_size, $settings['horizontal_position'], $settings['vertical_position'], new \Imagine\Image\Box(WATERMARK_PADDING, WATERMARK_PADDING));
            $image->draw()->text($settings['text'], $font, $watermark_position);
        }
        $settings = Settings::instance()->getValues('Thumbnails');
        $options = array('jpeg_quality' => $settings['jpeg_quality'], 'png_compression_level' => 9, 'filter' => $filter);
        if ($original_file_type = fn_get_image_extension(fn_get_mime_content_type($original_abs_path, false))) {
            $format = $original_file_type;
        } else {
            $format = 'png';
        }
        Storage::instance('images')->put($target_filepath, array('contents' => $image->get($format, $options)));
        return true;
    } catch (\Exception $e) {
        return false;
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号