Пример #1
0
 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);
 }
Пример #2
0
/**
 * 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);
        }
    }
}
Пример #3
0
/**
 * 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;
}
Пример #4
0
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');
        }
    }
}
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'))));
        }
    }
}
Пример #6
0
/**
 * 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;
}
Пример #7
0
/**
 * 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 : '');
}
Пример #8
0
/**
 * 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));
}
Пример #9
0
    }
    $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));
    }
Пример #10
0
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);
}
Пример #11
0
/**
 * 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);
                }
            }
        }
        if (!empty($less_output)) {
            $less = new Less();
            if (!empty($params['compressed'])) {
                $less->setFormatter('compressed');
            }
            $less->setImportDir($relative_path);
            try {
                $compiled_less = $less->customCompile($less_output, Storage::instance('assets')->getAbsolutePath($relative_path), array(), $prepend_prefix, $area);
            } catch (Exception $e) {
                $skip_save = true;
                $shift = 4;
                $message = '<div style="border: 2px solid red; padding: 5px;">LESS ' . $e->getMessage();
                if (preg_match("/line: (\\d+)/", $message, $m)) {
                    $lo = explode("\n", $less_output);
                    $message .= '<br /><br /><pre>' . implode("\n", array_splice($lo, intval($m[1]) - $shift, $shift * 2)) . '</pre>';
                }
                $message .= '</div>';
                fn_set_notification('E', __('error'), $message);
            }
        }
        if (empty($skip_save)) {
            $compiled_content = $compiled_css . "\n" . $compiled_less;
            // Move all @import links to the Top of the file.
            if (preg_match_all('/@import url.*?;/', $compiled_content, $imports)) {
                $compiled_content = preg_replace('/@import url.*?;/', '', $compiled_content);
                foreach ($imports[0] as $import_link) {
                    $compiled_content = $import_link . "\n" . $compiled_content;
                }
            }
            if ($make_rtl) {
                $compiled_content = \CSSJanus::transform($compiled_content);
                $compiled_content = "body {\ndirection: rtl;\n}\n" . $compiled_content;
            }
            Storage::instance('assets')->put($relative_path . '/' . $filename, array('contents' => $header . $compiled_content, 'compress' => false, 'caching' => true));
            if (!empty($params['use_scheme'])) {
                fn_put_contents(fn_get_cache_path(false) . 'theme_editor/' . $filename, $output . '#LESS#' . $less_output);
            }
            if (!empty($params['reflect_less'])) {
                $less_reflection['import_dirs'] = array($relative_path);
                fn_put_contents(fn_get_cache_path(false) . 'less_reflection.json', json_encode($less_reflection));
            }
        }
        Debugger::checkpoint('After styles compilation');
    }
    $url = Storage::instance('assets')->getUrl($relative_path . '/' . $filename);
    return $url;
}
Пример #12
0
}
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;
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 '';
}
Пример #14
0
    $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);
Пример #15
0
 /**
  * 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;
 }
Пример #16
0
/**
 * 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;
}
Пример #17
0
    $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)) {
Пример #18
0
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) {
                    if ($option['option_type'] == 'F' && $option['required'] == 'Y' && !$update) {
                        if (empty($data['product_options'][$option['option_id']])) {
                            fn_set_notification('E', __('error'), __('product_cannot_be_added'));
                            unset($product_data[$key]);
                            return array($product_data, $cart);
                        }
                    }
                }
            }
        } else {
            if (empty($data['extra']['parent'])) {
                foreach ($_options as $option) {
                    if ($option['option_type'] == 'F' && $option['required'] == 'Y' && empty($cart['products'][$hash]['extra']['custom_files'][$option['option_id']]) && empty($data['extra']['custom_files'][$option['option_id']])) {
                        fn_set_notification('E', __('error'), __('product_cannot_be_added'));
                        unset($product_data[$key]);
                        return array($product_data, $cart);
                    }
                }
            }
        }
        if ($update) {
            foreach ($_options as $option) {
                if ($option['option_type'] == 'F' && empty($cart['products'][$key]['extra']['custom_files'][$option['option_id']])) {
                    unset($cart['products'][$key]['extra']['custom_files'][$option['option_id']]);
                    unset($cart['products'][$key]['product_options'][$option['option_id']]);
                    unset($data['product_options'][$option['option_id']]);
                }
            }
        }
        if (isset($cart['products'][$key]['extra']['custom_files'])) {
            foreach ($cart['products'][$key]['extra']['custom_files'] as $option_id => $files) {
                foreach ($files as $file) {
                    $data['extra']['custom_files'][$option_id][] = $file;
                }
                $data['product_options'][$option_id] = md5(serialize($files));
            }
        }
        $product_data[$key] = $data;
    }
    return array($product_data, $cart);
}
Пример #19
0
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']);
}
Пример #20
0
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;
    }
}
Пример #21
0
/**
 * Hook: gets images host
 * @param object $view templater object
 */
function fn_hidpi_init_templater_post(&$view)
{
    $url = Storage::instance('images')->getUrl();
    $view->assign('hidpi_image_host', parse_url($url, PHP_URL_HOST));
}
Пример #22
0
function fn_reorder($order_id, &$cart, &$auth)
{
    $order_info = fn_get_order_info($order_id, false, false, false, true);
    unset(Tygh::$app['session']['shipping_hash']);
    unset(Tygh::$app['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']);
        unset($order_info['products'][$k]['extra']['promotions']);
        unset($order_info['products'][$k]['promotions']);
        $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;
            // Check if the product price with options modifiers equals to zero
            $price = fn_get_product_price($v['product_id'], $amount, $auth);
            $zero_price_action = db_get_field("SELECT zero_price_action FROM ?:products WHERE product_id = ?i", $v['product_id']);
            if (!floatval($price) && $zero_price_action == 'A') {
                if (isset($v['custom_user_price'])) {
                    $price = $v['custom_user_price'];
                }
            }
            $price = fn_apply_options_modifiers($v['product_options'], $price, 'P', array(), array('product_data' => $v));
            if (!floatval($price)) {
                $data['price'] = isset($data['price']) ? fn_parse_price($data['price']) : 0;
                if (AREA == 'C' && ($zero_price_action == 'R' || $zero_price_action == 'A' && floatval($data['price']) < 0)) {
                    if ($zero_price_action == 'A') {
                        fn_set_notification('E', __('error'), __('incorrect_price_warning'));
                    } else {
                        fn_set_notification('W', __('warning'), __('warning_zero_price_restricted_product', array('[product]' => $v['product'])));
                    }
                    unset($cart['products'][$k]);
                    continue;
                }
            }
            // 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']);
}
Пример #23
0
/**
 * Function delete product's attachments
 *
 * @param int $product_id product id
 */
function fn_attachments_delete_product_post(&$product_id)
{
    $attachments = db_get_fields("SELECT attachment_id FROM ?:attachments WHERE object_type = 'product' AND object_id = ?i", $product_id);
    Storage::instance('attachments')->deleteDir('product/' . $product_id);
    foreach ($attachments as $attachment_id) {
        db_query("DELETE FROM ?:attachments WHERE attachment_id = ?i", $attachment_id);
        db_query("DELETE FROM ?:attachment_descriptions WHERE attachment_id = ?i", $attachment_id);
    }
}
Пример #24
0
             }
             // Update manifest
             if (file_exists($theme_path . '/' . THEME_MANIFEST)) {
                 $manifest_content = fn_get_contents($theme_path . '/' . THEME_MANIFEST);
                 $manifest = json_decode($manifest_content, true);
             } else {
                 $manifest = parse_ini_file($theme_path . '/' . THEME_MANIFEST_INI);
             }
             $manifest['title'] = $_REQUEST['theme_data']['title'];
             $manifest['description'] = $_REQUEST['theme_data']['description'];
             // Put logos of current layout to manifest
             $logos = fn_get_logos(Registry::get('runtime.company_id'));
             foreach ($logos as $type => $logo) {
                 if (!empty($logo['image'])) {
                     $filename = fn_basename($logo['image']['relative_path']);
                     Storage::instance('images')->export($logo['image']['relative_path'], $theme_path . '/media/images/' . $filename);
                     $manifest[$type] = 'media/images/' . $filename;
                 }
             }
             fn_put_contents($theme_path . '/' . THEME_MANIFEST, json_encode($manifest));
             fn_install_theme($theme_dest, Registry::get('runtime.company_id'), false);
         }
     } else {
         fn_set_notification('W', __('warning'), __('warning_theme_clone_dir_exists'));
     }
 } elseif ($mode == 'upload') {
     $theme_pack = fn_filter_uploaded_data('theme_pack', Registry::get('config.allowed_pack_exts'));
     if (empty($theme_pack[0])) {
         fn_set_notification('E', __('error'), __('text_allowed_to_upload_file_extension', array('[ext]' => implode(',', Registry::get('config.allowed_pack_exts')))));
     } else {
         $theme_pack = $theme_pack[0];
Пример #25
0
 /**
  * Session data garbage collector handler.
  *
  * @param int $max_lifetime Max session data lifetime
  *
  * @return boolean Always true
  */
 public function gc($max_lifetime)
 {
     $this->storage_driver->gc($max_lifetime);
     // Cleanup stored sessions
     db_query('DELETE FROM ?:stored_sessions WHERE expiry < ?i', TIME - SESSIONS_STORAGE_ALIVE_TIME);
     // Delete custom files (garbage) from unlogged customers
     $files = Storage::instance('custom_files')->getList('sess_data');
     if (is_array($files)) {
         foreach ($files as $file) {
             $fdate = fileatime(Storage::instance('custom_files')->getAbsolutePath('sess_data/' . $file));
             if ($fdate < TIME - SESSIONS_STORAGE_ALIVE_TIME) {
                 Storage::instance('custom_files')->delete('sess_data/' . $file);
             }
         }
     }
     return true;
 }
Пример #26
0
    $remove_cc = db_get_field("SELECT COUNT(*) FROM ?:status_data WHERE type = 'O' AND param = 'remove_cc_info' AND value = 'N'");
    $remove_cc = $remove_cc > 0 ? true : false;
    Registry::get('view')->assign('remove_cc', $remove_cc);
    Registry::get('view')->assign('orders', $orders);
    Registry::get('view')->assign('search', $search);
    Registry::get('view')->assign('totals', $totals);
    Registry::get('view')->assign('display_totals', fn_display_order_totals($orders));
    Registry::get('view')->assign('shippings', $shippings);
    $payments = fn_get_payments(array('simple' => true));
    Registry::get('view')->assign('payments', $payments);
} elseif ($mode == 'get_custom_file') {
    if (!empty($_REQUEST['file']) && !empty($_REQUEST['order_id'])) {
        $file_path = 'order_data/' . $_REQUEST['order_id'] . '/' . $_REQUEST['file'];
        if (Storage::instance('custom_files')->isExist($file_path)) {
            $filename = !empty($_REQUEST['filename']) ? $_REQUEST['filename'] : '';
            Storage::instance('custom_files')->get($file_path, $filename);
        }
    }
}
//
// Calculate gross total and totally paid values for the current set of orders
//
function fn_display_order_totals($orders)
{
    $result = array();
    $result['gross_total'] = 0;
    $result['totally_paid'] = 0;
    if (is_array($orders)) {
        foreach ($orders as $k => $v) {
            $result['gross_total'] += $v['total'];
            if ($v['status'] == 'C' || $v['status'] == 'P') {
Пример #27
0
/**
 * Gets path to user public files
 * @return string public files path
 */
function fn_get_public_files_path()
{
    $path = Storage::instance('images')->getAbsolutePath('');
    $company_id = Registry::get('runtime.simple_ultimate') ? Registry::get('runtime.forced_company_id') : Registry::get('runtime.company_id');
    if (!empty($company_id)) {
        $path .= 'companies/' . $company_id . '/';
    }
    return $path;
}
Пример #28
0
}
//
// Delete image
//
if ($mode == 'create') {
    $result_image = '';
    if (!empty($_SERVER['REQUEST_URI'])) {
        $path = defined('HTTPS') ? Registry::get('config.https_path') : Registry::get('config.http_path');
        $image_file = str_replace($path . '/images/', '', $_SERVER['REQUEST_URI']);
        $watermarked_file = WATERMARKS_DIR_NAME . $image_file;
        if (Storage::instance('images')->isExist($watermarked_file)) {
            $result_image = Storage::instance('images')->getUrl($watermarked_file);
        } elseif (Storage::instance('images')->isExist($image_file)) {
            $image_name = fn_basename($image_file);
            $image_id = db_get_field("SELECT image_id FROM ?:images WHERE image_path LIKE ?l", "%{$image_name}%");
            $image_link = db_get_row("SELECT * FROM ?:images_links WHERE image_id = ?i OR detailed_id = ?i", $image_id, $image_id);
            if (!empty($image_link)) {
                $is_detailed = $image_link['detailed_id'] == $image_id;
                $image_type = $is_detailed ? 'detailed' : 'icons';
                $generate_watermark = fn_is_need_watermark($image_link['object_type'], $is_detailed, Registry::get('runtime.company_id'));
                if (fn_watermark_create($image_file, $watermarked_file, $is_detailed, Registry::get('runtime.company_id'), $generate_watermark)) {
                    $result_image = Storage::instance('images')->getUrl($watermarked_file);
                }
            }
        }
    }
    if (!empty($result_image)) {
        header('Location: ' . $result_image);
    }
    exit;
}
Пример #29
0
/**
 * Generate thumbnail with given size from image
 *
 * @param string $image_path Path to image
 * @param int $width Thumbnail width
 * @param int $height Thumbnail height
 * @param bool $lazy lazy generation - returns script URL that generates thumbnail
 * @return array array with width, height, mime type and path
 */
function fn_generate_thumbnail($image_path, $width, $height = 0, $lazy = false)
{
    /**
     * Actions before thumbnail generate
     *
     * @param string $image_path Path to image
     * @param int    $width      Width of thumbnail
     * @param int    $height     Height of thumbnail
     * @param bool   $make_box   If true create rectangle border
     */
    fn_set_hook('generate_thumbnail_pre', $image_path, $width, $height, $make_box);
    if (empty($image_path)) {
        return '';
    }
    $filename = 'thumbnails/' . $width . (empty($height) ? '' : '/' . $height) . '/' . $image_path;
    if (Registry::get('settings.Thumbnails.convert_to') != 'original') {
        $filename = preg_replace("/\\.[^.]*?\$/", "." . Registry::get('settings.Thumbnails.convert_to'), $filename);
    }
    $th_filename = '';
    if ($lazy || Storage::instance('images')->isExist($filename)) {
        $th_filename = $filename;
    } else {
        // for lazy thumbnails: find original filename
        if (Registry::get('config.tweaks.lazy_thumbnails') && Registry::get('settings.Thumbnails.convert_to') != 'original' && !Storage::instance('images')->isExist($image_path)) {
            foreach (array('png', 'jpg', 'jpeg') as $ext) {
                $image_path = preg_replace("/\\.[^.]*?\$/", "." . $ext, $image_path);
                if (Storage::instance('images')->isExist($image_path)) {
                    break;
                }
            }
        }
        /**
         * Actions before thumbnail generate, if thumbnail is not exists, after validations
         *
         * @param string $real_path Real path to image
         * @param string $lazy lazy generation - returns script URL that generates thumbnail
         */
        fn_set_hook('generate_thumbnail_file_pre', $image_path, $lazy, $filename, $width, $height);
        list(, , , $tmp_path) = fn_get_image_size(Storage::instance('images')->getAbsolutePath($image_path));
        if (!empty($tmp_path)) {
            list($cont, $format) = fn_resize_image($tmp_path, $width, $height, Registry::get('settings.Thumbnails.thumbnail_background_color'));
            if (!empty($cont)) {
                list(, $th_filename) = Storage::instance('images')->put($filename, array('contents' => $cont, 'caching' => true));
            }
        }
    }
    /**
     * Actions after thumbnail generate
     *
     * @param string $th_filename Thumbnail path
     * @param string $lazy        lazy generation - returns script URL that generates thumbnail
     */
    fn_set_hook('generate_thumbnail_post', $th_filename, $lazy);
    return !empty($th_filename) ? Storage::instance('images')->getUrl($th_filename) : '';
}
Пример #30
0
                        $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
 *
 * @return string Product data row in HTML format
 */
function fn_price_list_print_product_data($product, $selected_fields, $style, $price_schema, $options_variants = array())
{