/** * Checks uploaded file can be processed * @param array $uploaded_data uploaded file data * @param array $filter_by_ext allowed file extensions * @return boolean true if file can be processed, false - otherwise */ function fn_check_uploaded_data($uploaded_data, $filter_by_ext) { $result = true; $processed = false; /** * Actions before check uploaded data * * @param array $uploaded_data Uploaded data * @param array $filter_by_ext Allowed file extensions * @param bool $result Result status * @param bool $processed Processed flag */ fn_set_hook('check_uploaded_data_pre', $uploaded_data, $filter_by_ext, $result, $processed); if ($processed) { return $result; } if (!empty($uploaded_data) && is_array($uploaded_data) && !empty($uploaded_data['name'])) { $ext = fn_get_file_ext($uploaded_data['name']); if (empty($ext)) { $types = fn_get_ext_mime_types('mime'); $mime = fn_get_mime_content_type($uploaded_data['path']); $ext = isset($types[$mime]) ? $types[$mime] : ''; } if (!$processed && !empty($filter_by_ext) && !in_array(fn_strtolower($ext), $filter_by_ext)) { fn_set_notification('E', __('error'), __('text_not_allowed_to_upload_file_extension', array('[ext]' => $ext))); $result = false; $processed = true; } if (!$processed && in_array(fn_strtolower($ext), Registry::get('config.forbidden_file_extensions'))) { fn_set_notification('E', __('error'), __('text_forbidden_file_extension', array('[ext]' => $ext))); $result = false; $processed = true; } $mime_type = fn_get_mime_content_type($uploaded_data['path'], true, 'text/plain'); if (!$processed && !empty($uploaded_data['path']) && in_array($mime_type, Registry::get('config.forbidden_mime_types'))) { fn_set_notification('E', __('error'), __('text_forbidden_file_mime', array('[mime]' => $mime_type))); $result = false; $processed = true; } } /** * Actions after check uploaded data * * @param array $uploaded_data Uploaded data * @param array $filter_by_ext Allowed file extensions * @param bool $result Result status * @param bool $processed Processed flag */ fn_set_hook('check_uploaded_data_post', $uploaded_data, $filter_by_ext, $result, $processed); return $result; }
/** * Resizes image * @param string $src source image path * @param integer $new_width new image width * @param integer $new_height new image height * @param string $bg_color new image background color * @param array $custom_settings custom convertion settings * @return array - new image contents and format */ function fn_resize_image($src, $new_width = 0, $new_height = 0, $bg_color = '#ffffff', $custom_settings = array()) { static $general_settings = array(); if (empty($general_settings)) { $general_settings = Settings::instance()->getValues('Thumbnails'); } gc_collect_cycles(); $settings = empty($custom_settings) ? $general_settings : $custom_settings; /** @var \Imagine\Image\ImagineInterface $imagine */ $imagine = Tygh::$app['image']; $format = $settings['convert_to']; if ($format === 'original') { if ($original_file_type = fn_get_image_extension(fn_get_mime_content_type($src, true))) { $format = $original_file_type; } else { $format = 'png'; } } $transparency = null; if (empty($bg_color)) { $bg_color = '#FFF'; if ($format == 'png' || $format == 'gif') { $transparency = 0; } } elseif (!preg_match('/^#([0-9a-f]{3}){1,2}$/i', $bg_color)) { $bg_color = '#FFF'; } try { $image = $imagine->open($src); list($new_width, $new_height) = ImageHelper::originalProportionsFallback($image->getSize()->getWidth(), $image->getSize()->getHeight(), $new_width, $new_height); // This is a non-necessary operation // which can however trigger exceptions if isn't supported by a driver fn_catch_exception(function () use($image) { $image->usePalette(new \Imagine\Image\Palette\RGB()); }); $filter = $imagine instanceof \Imagine\Gd\Imagine ? \Imagine\Image\ImageInterface::FILTER_UNDEFINED : \Imagine\Image\ImageInterface::FILTER_LANCZOS; $new_size = new \Imagine\Image\Box($new_width, $new_height); $thumbnail = $image->thumbnail($new_size, \Imagine\Image\ImageInterface::THUMBNAIL_INSET, $filter); // In case that created thumbnail is smaller than required size, we create // an empty canvas of required size and center thumbnail on it $thumbnail_coordinates = new \Imagine\Image\Point((int) (($new_size->getWidth() - $thumbnail->getSize()->getWidth()) / 2), (int) (($new_size->getHeight() - $thumbnail->getSize()->getHeight()) / 2)); if (!$image->palette()->supportsAlpha()) { $transparency = null; } $canvas_color = $image->palette()->color($bg_color, $transparency); $canvas = $imagine->create($new_size, $canvas_color); $canvas->paste($thumbnail, $thumbnail_coordinates); unset($thumbnail, $image); $thumbnail = $canvas; $options = array('jpeg_quality' => $settings['jpeg_quality'], 'png_compression_level' => 9, 'filter' => $filter, 'flatten' => true); $return = array($thumbnail->get($format, $options), $format); unset($thumbnail); gc_collect_cycles(); return $return; } catch (\Exception $e) { $error_message = __('error_unable_to_create_thumbnail', array('[error]' => $e->getMessage(), '[file]' => $src)); if (AREA == 'A') { fn_set_notification('E', __('error'), $error_message); } gc_collect_cycles(); return false; } }
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; } }
/** * Filter data from file uploader * * @param string $name * @return array $filtered */ function fn_filter_uploaded_data($name, $filter_by_ext = array()) { $udata_local = fn_rebuild_files('file_' . $name); $udata_other = !empty($_REQUEST['file_' . $name]) ? $_REQUEST['file_' . $name] : array(); $utype = !empty($_REQUEST['type_' . $name]) ? $_REQUEST['type_' . $name] : array(); //var_dump($name);echo"<br/>"; // if($name=='p_feature_var_extra_image_detailed'){ // var_dump($utype);die(); // } if (empty($utype)) { return array(); } $filtered = array(); foreach ($utype as $id => $type) { if ($type == 'local' && !fn_is_empty(@$udata_local[$id])) { $filtered[$id] = fn_get_local_data(Bootstrap::stripSlashes($udata_local[$id])); } elseif ($type == 'server' && !fn_is_empty(@$udata_other[$id]) && AREA == 'A') { fn_get_last_key($udata_other[$id], 'fn_get_server_data', true); $filtered[$id] = $udata_other[$id]; } elseif ($type == 'url' && !fn_is_empty(@$udata_other[$id])) { fn_get_last_key($udata_other[$id], 'fn_get_url_data', true); $filtered[$id] = $udata_other[$id]; } if (isset($filtered[$id]) && $filtered[$id] === false) { unset($filtered[$id]); fn_set_notification('E', __('error'), __('cant_upload_file')); } if (!empty($filtered[$id]) && is_array($filtered[$id]) && !empty($filtered[$id]['name'])) { $filtered[$id]['name'] = str_replace(' ', '_', urldecode($filtered[$id]['name'])); // replace spaces with underscores $ext = fn_get_file_ext($filtered[$id]['name']); if (!empty($filter_by_ext) && !in_array(fn_strtolower($ext), $filter_by_ext)) { unset($filtered[$id]); fn_set_notification('E', __('error'), __('text_not_allowed_to_upload_file_extension', array('[ext]' => $ext))); } elseif (in_array(fn_strtolower($ext), Registry::get('config.forbidden_file_extensions'))) { unset($filtered[$id]); fn_set_notification('E', __('error'), __('text_forbidden_file_extension', array('[ext]' => $ext))); } } if (!empty($filtered[$id]['path']) && in_array(fn_get_mime_content_type($filtered[$id]['path'], true, 'text/plain'), Registry::get('config.forbidden_mime_types'))) { fn_set_notification('E', __('error'), __('text_forbidden_file_mime', array('[mime]' => fn_get_mime_content_type($filtered[$id]['path'], true, 'text/plain')))); unset($filtered[$id]); } } static $shutdown_inited; if (!$shutdown_inited) { $shutdown_inited = true; register_shutdown_function('fn_remove_temp_data'); } return $filtered; }
function content_55dc759c51d3e9_78524838($_smarty_tpl) { if (!is_callable('smarty_block_hook')) { include '/var/www/html/market/app/functions/smarty_plugins/block.hook.php'; } if (!is_callable('smarty_function_render_location')) { include '/var/www/html/market/app/functions/smarty_plugins/function.render_location.php'; } fn_preload_lang_vars(array('on_site_template_editing', 'on_site_live_editing')); ?> <!DOCTYPE html> <html lang="<?php echo htmlspecialchars(@constant('CART_LANGUAGE'), ENT_QUOTES, 'UTF-8'); ?> "> <head> <?php $_smarty_tpl->_capture_stack[0][] = array("page_title", null, null); ob_start(); $_smarty_tpl->smarty->_tag_stack[] = array('hook', array('name' => "index:title")); $_block_repeat = true; echo smarty_block_hook(array('name' => "index:title"), null, $_smarty_tpl, $_block_repeat); while ($_block_repeat) { ob_start(); ?> <?php if ($_smarty_tpl->tpl_vars['page_title']->value) { ?> <?php echo htmlspecialchars($_smarty_tpl->tpl_vars['page_title']->value, ENT_QUOTES, 'UTF-8'); ?> <?php } else { ?> <?php $_smarty_tpl->tpl_vars['i'] = new Smarty_Variable(); $_smarty_tpl->tpl_vars['i']->_loop = false; $_from = $_smarty_tpl->tpl_vars['breadcrumbs']->value; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); } $_smarty_tpl->tpl_vars['i']->total = $_smarty_tpl->_count($_from); $_smarty_tpl->tpl_vars['i']->iteration = 0; $_smarty_tpl->tpl_vars['i']->index = -1; foreach ($_from as $_smarty_tpl->tpl_vars['i']->key => $_smarty_tpl->tpl_vars['i']->value) { $_smarty_tpl->tpl_vars['i']->_loop = true; $_smarty_tpl->tpl_vars['i']->iteration++; $_smarty_tpl->tpl_vars['i']->index++; $_smarty_tpl->tpl_vars['i']->first = $_smarty_tpl->tpl_vars['i']->index === 0; $_smarty_tpl->tpl_vars['i']->last = $_smarty_tpl->tpl_vars['i']->iteration === $_smarty_tpl->tpl_vars['i']->total; $_smarty_tpl->tpl_vars['smarty']->value['foreach']["bkt"]['first'] = $_smarty_tpl->tpl_vars['i']->first; $_smarty_tpl->tpl_vars['smarty']->value['foreach']["bkt"]['last'] = $_smarty_tpl->tpl_vars['i']->last; ?> <?php if (!$_smarty_tpl->getVariable('smarty')->value['foreach']['bkt']['first']) { echo htmlspecialchars(preg_replace('!<[^>]*?>!', ' ', $_smarty_tpl->tpl_vars['i']->value['title']), ENT_QUOTES, 'UTF-8'); if (!$_smarty_tpl->getVariable('smarty')->value['foreach']['bkt']['last']) { ?> :: <?php } } ?> <?php } ?> <?php if (!$_smarty_tpl->tpl_vars['skip_page_title']->value && $_smarty_tpl->tpl_vars['location_data']->value['title']) { if (count($_smarty_tpl->tpl_vars['breadcrumbs']->value) > 1) { ?> - <?php } echo htmlspecialchars($_smarty_tpl->tpl_vars['location_data']->value['title'], ENT_QUOTES, 'UTF-8'); } } $_block_content = ob_get_clean(); $_block_repeat = false; echo smarty_block_hook(array('name' => "index:title"), $_block_content, $_smarty_tpl, $_block_repeat); } array_pop($_smarty_tpl->smarty->_tag_stack); ?> <?php list($_capture_buffer, $_capture_assign, $_capture_append) = array_pop($_smarty_tpl->_capture_stack[0]); if (!empty($_capture_buffer)) { if (isset($_capture_assign)) { $_smarty_tpl->assign($_capture_assign, ob_get_contents()); } if (isset($_capture_append)) { $_smarty_tpl->append($_capture_append, ob_get_contents()); } Smarty::$_smarty_vars['capture'][$_capture_buffer] = ob_get_clean(); } else { $_smarty_tpl->capture_error(); } ?> <title><?php echo trim(preg_replace('!\\s+!u', ' ', Smarty::$_smarty_vars['capture']['page_title'])); ?> </title> <?php echo $_smarty_tpl->getSubTemplate("meta.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array(), 0); ?> <link href="<?php echo htmlspecialchars(fn_query_remove($_smarty_tpl->tpl_vars['logos']->value['favicon']['image']['image_path'], 't'), ENT_QUOTES, 'UTF-8'); ?> " rel="shortcut icon" type="<?php echo htmlspecialchars(fn_get_mime_content_type($_smarty_tpl->tpl_vars['logos']->value['favicon']['image']['absolute_path']), ENT_QUOTES, 'UTF-8'); ?> " /> <?php echo $_smarty_tpl->getSubTemplate("common/styles.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('include_dropdown' => true), 0); ?> <?php if (defined("DEVELOPMENT") && @constant('DEVELOPMENT') == true) { echo '<script'; ?> type="text/javascript" data-no-defer> window.jsErrors = []; window.onerror = function(errorMessage) { document.write('<div data-ca-debug="1" style="border: 2px solid red; margin: 2px;">' + errorMessage + '</div>'); } <?php echo '</script'; ?> > <?php } ?> </head> <body> <?php if ($_smarty_tpl->tpl_vars['runtime']->value['customization_mode']['design']) { ?> <?php echo $_smarty_tpl->getSubTemplate("common/toolbar.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('title' => __("on_site_template_editing"), 'href' => "customization.disable_mode?type=design"), 0); ?> <?php } if ($_smarty_tpl->tpl_vars['runtime']->value['customization_mode']['live_editor']) { ?> <?php echo $_smarty_tpl->getSubTemplate("common/toolbar.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('title' => __("on_site_live_editing"), 'href' => "customization.disable_mode?type=live_editor"), 0); ?> <?php } if (defined("THEMES_PANEL") && !$_smarty_tpl->tpl_vars['runtime']->value['customization_mode']['live_editor']) { ?> <?php echo $_smarty_tpl->getSubTemplate("demo_theme_selector.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array(), 0); ?> <?php } ?> <div class="ty-tygh <?php if ($_smarty_tpl->tpl_vars['runtime']->value['customization_mode']['theme_editor']) { ?> te-mode<?php } ?> <?php if ($_smarty_tpl->tpl_vars['runtime']->value['customization_mode']['live_editor'] || $_smarty_tpl->tpl_vars['runtime']->value['customization_mode']['design'] || @constant('THEMES_PANEL')) { ?> ty-top-panel-padding<?php } ?> " id="tygh_container"> <?php echo $_smarty_tpl->getSubTemplate("common/loading_box.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array(), 0); ?> <?php echo $_smarty_tpl->getSubTemplate("common/notification.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array(), 0); ?> <div class="ty-helper-container" id="tygh_main_container"> <?php $_smarty_tpl->smarty->_tag_stack[] = array('hook', array('name' => "index:content")); $_block_repeat = true; echo smarty_block_hook(array('name' => "index:content"), null, $_smarty_tpl, $_block_repeat); while ($_block_repeat) { ob_start(); ?> <?php echo smarty_function_render_location(array(), $_smarty_tpl); ?> <?php $_block_content = ob_get_clean(); $_block_repeat = false; echo smarty_block_hook(array('name' => "index:content"), $_block_content, $_smarty_tpl, $_block_repeat); } array_pop($_smarty_tpl->smarty->_tag_stack); ?> <!--tygh_main_container--></div> <?php $_smarty_tpl->smarty->_tag_stack[] = array('hook', array('name' => "index:footer")); $_block_repeat = true; echo smarty_block_hook(array('name' => "index:footer"), null, $_smarty_tpl, $_block_repeat); while ($_block_repeat) { ob_start(); $_block_content = ob_get_clean(); $_block_repeat = false; echo smarty_block_hook(array('name' => "index:footer"), $_block_content, $_smarty_tpl, $_block_repeat); } array_pop($_smarty_tpl->smarty->_tag_stack); ?> <!--tygh_container--></div> <?php echo $_smarty_tpl->getSubTemplate("common/scripts.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array(), 0); ?> <?php if ($_smarty_tpl->tpl_vars['runtime']->value['customization_mode']['design']) { ?> <?php echo $_smarty_tpl->getSubTemplate("common/template_editor.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array(), 0); ?> <?php } if ($_smarty_tpl->tpl_vars['runtime']->value['customization_mode']['theme_editor']) { ?> <?php echo $_smarty_tpl->getSubTemplate("common/theme_editor.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array(), 0); ?> <?php } ?> </body> </html> <?php }
/** * Resizes image * @param string $src source image path * @param integer $new_width new image width * @param integer $new_height new image height * @param string $bg_color new image background color * @param array $custom_settings custom convertion settings * @return array - new image contents and format */ function fn_resize_image($src, $new_width = 0, $new_height = 0, $bg_color = '#ffffff', $custom_settings = array()) { static $general_settings = array(); if (empty($general_settings)) { $general_settings = Settings::instance()->getValues('Thumbnails'); } gc_collect_cycles(); $settings = empty($custom_settings) ? $general_settings : $custom_settings; /** @var \Imagine\Image\ImagineInterface $imagine */ $imagine = Tygh::$app['image']; if (!empty($bg_color) && !preg_match('/^#([0-9a-f]{3}){1,2}$/i', $bg_color)) { $bg_color = '#ffffff'; } try { $image = $imagine->open($src); $image->usePalette(new \Imagine\Image\Palette\RGB()); $filter = $imagine instanceof \Imagine\Gd\Imagine ? \Imagine\Image\ImageInterface::FILTER_UNDEFINED : \Imagine\Image\ImageInterface::FILTER_LANCZOS; $new_size = new \Imagine\Image\Box($new_width, $new_height); $thumbnail = $image->thumbnail($new_size, \Imagine\Image\ImageInterface::THUMBNAIL_INSET, $filter); // Created thumbnail is smaller than required size, so we create // an empty canvas of required size and center thumbnail on it if (!$thumbnail->getSize()->contains($new_size)) { $thumbnail_coordinates = new \Imagine\Image\Point((int) (($new_size->getWidth() - $thumbnail->getSize()->getWidth()) / 2), (int) (($new_size->getHeight() - $thumbnail->getSize()->getHeight()) / 2)); $canvas_color = empty($bg_color) ? $image->palette()->color('#FFF', 0) : $image->palette()->color($bg_color); $canvas = $imagine->create($new_size, $canvas_color); $canvas->paste($thumbnail, $thumbnail_coordinates); unset($thumbnail); $thumbnail = $canvas; } unset($image); $format = $settings['convert_to']; if ($format === 'original') { if ($original_file_type = fn_get_image_extension(fn_get_mime_content_type($src, false))) { $format = $original_file_type; } else { $format = 'png'; } } $options = array('jpeg_quality' => $settings['jpeg_quality'], 'png_compression_level' => 9, 'filter' => $filter); $return = array($thumbnail->get($format, $options), $format); unset($thumbnail); gc_collect_cycles(); return $return; } catch (\Exception $e) { gc_collect_cycles(); return false; } }