/** * Gets mobile product url * * @param $product_id * @param string $lang_code * @return bool */ function fn_twg_exim_get_product_mobile_url($product_id, $lang_code = '') { $company_id = 0; $company_url = ''; if (fn_allowed_for('ULTIMATE')) { if (Registry::get('runtime.company_id')) { $company_id = Registry::get('runtime.company_id'); } else { $company_id = db_get_field('SELECT company_id FROM ?:products WHERE product_id = ?i', $product_id); } $company_url = '&company_id=' . $company_id; } else { $company_url = ''; } $settings = TwigmoSettings::get('customer_connections.' . $company_id); $use_twg = !empty($settings['access_id']) && ($settings['use_for_phones'] == 'Y' || $settings['use_for_tablets'] == 'Y'); if ($use_twg && fn_twg_use_https_for_customer($company_id)) { $protocol = 'https'; } else { $protocol = 'http'; } $url = fn_url('products.view?product_id=' . $product_id . $company_url, 'C', $protocol, $lang_code); fn_set_hook('exim_get_product_url', $url, $product_id, $options, $lang_code); return $url; }
/** * Smarty plugin * @package Smarty * @subpackage plugins */ function smarty_block_styles($params, $content, &$smarty, &$repeat) { if ($repeat == true) { return; } $prepend_prefix = Embedded::isEnabled() ? 'html#tygh_html body#tygh_body .tygh' : ''; $styles = array(); $internal_styles = ''; //if (preg_match_all('/\<link(.*?href ?= ?"([^"]+)")?[^\>]*\>/is', $content, $m)) { if (preg_match_all('/\\<link(.*?href\\s?=\\s?(?:"|\')([^"]+)(?:"|\'))?[^\\>]*\\>/is', $content, $m)) { foreach ($m[2] as $k => $v) { $v = preg_replace('/\\?.*?$/', '', $v); $media = ''; if (strpos($m[1][$k], 'media=') !== false && preg_match('/media="(.*?)"/', $m[1][$k], $_m)) { $media = $_m[1]; } $styles[] = array('file' => str_replace(Registry::get('config.current_location'), Registry::get('config.dir.root'), $v), 'relative' => str_replace(Registry::get('config.current_location') . '/', '', $v), 'media' => $media); } } if (preg_match_all('/\\<style.*\\>(.*)\\<\\/style\\>/isU', $content, $m)) { $internal_styles = implode("\n\n", $m[1]); } if (!empty($styles) || !empty($internal_styles)) { fn_set_hook('styles_block_files', $styles); list($_area) = Registry::get('view')->getArea(); $filename = fn_merge_styles($styles, $internal_styles, $prepend_prefix, $params, $_area); $content = '<link type="text/css" rel="stylesheet" href="' . $filename . '" />'; } return $content; }
/** * Generates menu items from scheme * @param array $request request params * @return array menu items */ public function generate($request) { $menu = fn_get_schema('menu', 'menu', 'php'); $this->_request = $request; $actions = array(); foreach ($menu as $group => &$menu_data) { // Get static section foreach ($menu_data as $root => &$items) { $items['items'] = $this->_processItems($items['items'], $root, ''); if (empty($items['items'])) { unset($menu[$group][$root]); continue; } } } unset($items, $menu_data); $menu['top'] = $this->_sort($menu['top']); $menu['central'] = $this->_sort($menu['central']); $menu = $this->_getSettingsSections($menu); fn_preload_lang_vars($this->_lang_cache); $selected = $this->_selected; /** * Changes generated menu items * * @param array $request request params * @param array $menu items * @param array $actions items Action value, if exists. See: fn_get_route * @param array $this->selected Menu item, selected by the dispatch */ fn_set_hook('backend_menu_generate_post', $request, $menu, $actions, $this->_selected); return array($menu, $actions, $this->_selected); }
/** * 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); } } }
protected function getPath() { $path = Registry::get('config.dir.root'); if ($this->default) { $path .= '/var'; } $path .= '/robots.txt'; fn_set_hook('robots_get_path', $this, $path); return $path; }
function fn_get_tag_objects() { $types = array(); if (Registry::get('addons.tags.tags_for_products') == 'Y') { $types['P'] = array('name' => 'products', 'url' => 'products.manage'); } if (Registry::get('addons.tags.tags_for_pages') == 'Y') { $types['A'] = array('name' => 'pages', 'url' => 'pages.manage'); } fn_set_hook('get_tag_objects', $types); return $types; }
/** * Gets patterns absolute path * @param string $style_id style ID * @return string patterns absolute path */ public function getPath($style_id) { $path = fn_get_theme_path('[themes]/[theme]/media/images/patterns/', 'C'); /** * Modifies path to patterns * * @param object $this Patterns object * @param string $path current path * @param string $style_id style to get path for */ fn_set_hook('patterns_get_path', $this, $path, $style_id); return $path . fn_basename($style_id); }
/** * Adds new node the breadcrumbs * * @param string $lang_value name of language variable * @param string $link breadcrumb URL * @param boolean $nofollow Include or not "nofollow" attribute * @param boolean $is_first Flag that defines if parameter should be added to the beging (default false) * @return boolean True if breadcrumbs were added, false otherwise */ public function addLink($title, $link = '', $nofollow = false, $is_first = false) { if ($this->_area == 'A' && !fn_check_view_permissions($link, 'GET')) { return false; } fn_set_hook('add_breadcrumb', $title, $link); $item = array('title' => $title, 'link' => $link, 'nofollow' => $nofollow); if ($is_first) { array_unshift($this->_links, $item); } else { $this->_links[] = $item; } return true; }
function fn_get_status_params_definition($type) { $status_params = array(); if ($type == STATUSES_ORDER) { $status_params = array('color' => array('type' => 'color', 'label' => 'color'), 'notify' => array('type' => 'checkbox', 'label' => 'notify_customer', 'default_value' => 'Y'), 'notify_department' => array('type' => 'checkbox', 'label' => 'notify_orders_department'), 'notify_vendor' => array('type' => 'checkbox', 'label' => 'notify_vendor'), 'inventory' => array('type' => 'select', 'label' => 'inventory', 'variants' => array('I' => 'increase', 'D' => 'decrease')), 'remove_cc_info' => array('type' => 'checkbox', 'label' => 'remove_cc_info', 'default_value' => 'Y'), 'repay' => array('type' => 'checkbox', 'label' => 'pay_order_again'), 'appearance_type' => array('type' => 'select', 'label' => 'invoice_credit_memo', 'variants' => array('D' => 'default', 'I' => 'invoice', 'C' => 'credit_memo', 'O' => 'order'))); if (fn_allowed_for('ULTIMATE:FREE')) { unset($status_params['notify_vendor']); } elseif (fn_allowed_for('MULTIVENDOR')) { $status_params['calculate_for_payouts'] = array('type' => 'checkbox', 'label' => 'charge_to_vendor_account'); } elseif (fn_allowed_for('ULTIMATE')) { unset($status_params['notify_vendor']); } } fn_set_hook('get_status_params_definition', $status_params, $type); return $status_params; }
/** * Smarty plugin * @package Smarty * @subpackage plugins */ function smarty_block_styles($params, $content, &$smarty, &$repeat) { if ($repeat == true) { return; } $prepend_prefix = Embedded::isEnabled() ? 'html#tygh_html body#tygh_body .tygh' : ''; $current_location = Registry::get('config.current_location'); $styles = array(); $inline_styles = ''; $external_styles = array(); //if (preg_match_all('/\<link(.*?href ?= ?"([^"]+)")?[^\>]*\>/is', $content, $m)) { if (preg_match_all('/\\<link(.*?href\\s?=\\s?(?:"|\')([^"]+)(?:"|\'))?[^\\>]*\\>/is', $content, $m)) { foreach ($m[2] as $k => $v) { $v = preg_replace('/\\?.*?$/', '', $v); $media = ''; if (strpos($m[1][$k], 'media=') !== false && preg_match('/media="(.*?)"/', $m[1][$k], $_m)) { $media = $_m[1]; } if (strpos($v, $current_location) === false || strpos($m[1][$k], 'data-ca-external') !== false) { // Location is different OR style is skipped for minification $external_styles[] = str_replace(' data-ca-external="Y"', '', $m[0][$k]); } else { $styles[] = array('file' => str_replace($current_location, Registry::get('config.dir.root'), $v), 'relative' => str_replace($current_location . '/', '', $v), 'media' => $media); } } } if (preg_match_all('/\\<style.*\\>(.*)\\<\\/style\\>/isU', $content, $m)) { $inline_styles = implode("\n\n", $m[1]); } if (!empty($styles) || !empty($inline_styles)) { fn_set_hook('styles_block_files', $styles); list($_area) = Tygh::$app['view']->getArea(); $params['compressed'] = true; $filename = fn_merge_styles($styles, $inline_styles, $prepend_prefix, $params, $_area); $content = '<link type="text/css" rel="stylesheet" href="' . $filename . '" />'; if (!empty($external_styles)) { $content .= PHP_EOL . implode(PHP_EOL, $external_styles); } } return $content; }
/** * Makes store files backup * * @param array $params Extra params * backup_files - array List of files/folders to be added to backup * pack_name - string name of result pack. Will be stored in Registry::get('config.dir.backups') . 'files/' . $pack_name * fs_compress - bool Compress result dir * @return string Path to backuped files/archve */ public static function backupFiles($params = array()) { $backup_files = array('app', 'design', 'js', '.htaccess', 'api.php', 'config.local.php', 'config.php', 'index.php', 'init.php', 'robots.txt', 'var/themes_repository', 'var/snapshots'); $backup_files[] = Registry::get('config.admin_index'); if (fn_allowed_for('MULTIVENDOR')) { $backup_files[] = Registry::get('config.vendor_index'); } if (!empty($params['backup_files'])) { $backup_files = $params['backup_files']; } if (!empty($params['extra_folders'])) { $params['extra_folders'] = array_map(function ($path) { return fn_normalize_path($path); }, $params['extra_folders']); $backup_files = array_merge($backup_files, $params['extra_folders']); } fn_set_hook('data_keeper_backup_files', $backup_files); $pack_name = !empty($params['pack_name']) ? $params['pack_name'] : 'backup_' . date('dMY_His', TIME); $destination_path = fn_get_cache_path(false) . 'tmp/backup/_files/' . $pack_name; $source_path = Registry::get('config.dir.root' . '/'); fn_set_progress('step_scale', (sizeof($backup_files) + 1) * 2); fn_set_progress('echo', __('backup_files'), false); fn_rm($destination_path); fn_mkdir($destination_path); foreach ($backup_files as $file) { fn_set_progress('echo', __('uc_copy_files') . ': <b>' . $file . '</b>', true); fn_copy($source_path . $file, $destination_path . '/' . $file); } if (!empty($params['fs_compress'])) { fn_set_progress('echo', __('compressing_backup'), true); $ext = $params['fs_compress'] == 'tgz' ? '.tgz' : '.zip'; $result = fn_compress_files($pack_name . $ext, $pack_name, fn_get_cache_path(false) . 'tmp/backup/_files/'); $destination_path = rtrim($destination_path, '/'); if ($result) { fn_rename($destination_path . $ext, Registry::get('config.dir.backups') . $pack_name . $ext); } fn_rm($destination_path); $destination_path .= $ext; } return $destination_path; }
function fn_amazon_validate_cart_data($cart, $request) { $items = array(); $_items = $request->CallbackOrderCart->CallbackOrderCartItems; if (empty($_items)) { $_items = $request->ProcessedOrder->ProcessedOrderItems; foreach ($_items->ProcessedOrderItem as $item) { $items[] = $item; } } else { foreach ($_items->CallbackOrderCartItem as $item) { $items[] = $item; } } $cart_items_amount = count($cart['products']); fn_set_hook('amazon_validate_cart', $items, $cart, $cart_items_amount); if (count($items) == $cart_items_amount || count($items) - 1 == $cart_items_amount) { foreach ($items as $item) { $sku = (string) $item->Item->SKU; if (empty($sku)) { $sku = (string) $item->SKU; $qty = (string) $item->Quantity; $cart_id = (string) $item->ItemCustomData->CartID; } else { $qty = (string) $item->Item->Quantity; $cart_id = (string) $item->Item->ItemCustomData->CartID; } $is_valid = false; fn_set_hook('amazon_validate_cart_item', $cart, $sku, $qty, $cart_id, $is_valid); if ($is_valid || $sku == 'taxes' && empty($cart_id)) { continue; } elseif (!isset($cart['products'][$cart_id]) || $cart['products'][$cart_id]['amount'] != $qty) { return false; } } } else { return false; } return true; }
/** * Loads received language variables into language cache * * @param array $var_names Language variable that to be loaded * @param string $lang_code 2-letter language code * * @return boolean True if any of received language variables were added into cache; false otherwise */ public static function preloadLangVars($var_names, $lang_code = CART_LANGUAGE) { Registry::registerCache('lang_cache', array('language_values', 'ult_language_values'), Registry::cacheLevel('dispatch'), true); $values = Registry::get('lang_cache.' . $lang_code); if (empty($values)) { $values = array(); } $var_names = array_diff($var_names, array_keys($values)); if ($var_names) { foreach ($var_names as $index => $var_name) { $var_names[$index] = strtolower($var_name); if (isset($values[$var_name])) { unset($var_names[$index]); } } if (empty($var_names)) { return true; } $fields = array('lang.name' => true, 'lang.value' => true); $tables = array('?:language_values lang'); $left_join = array(); $condition = array(db_quote('lang.lang_code = ?s', $lang_code), db_quote('lang.name IN (?a)', $var_names)); $params = array(); fn_set_hook('get_lang_var', $fields, $tables, $left_join, $condition, $params); $joins = !empty($left_join) ? ' LEFT JOIN ' . implode(', ', $left_join) : ''; $new_values = db_get_hash_single_array('SELECT ' . implode(', ', array_keys($fields)) . ' FROM ' . implode(', ', $tables) . $joins . ' WHERE ' . implode(' AND ', $condition), array('name', 'value')); foreach ($var_names as $var_name) { if (!isset($new_values[$var_name])) { $new_values[$var_name] = '_' . $var_name; } } $values = fn_array_merge($values, $new_values); Registry::set('lang_cache.' . $lang_code, $values); return true; } return false; }
function fn_rssf_get_items($params, $lang_code = CART_LANGUAGE) { $items_data = $additional_data = $block_data = array(); if (!empty($params['bid']) && !empty($params['sid']) && empty($params['category_id'])) { $block_data = Block::instance()->getById($params['bid'], $params['sid'], array(), $lang_code); if (!empty($block_data['content']['filling']) && $block_data['content']['filling'] == 'products') { $_params = array('sort_by' => $block_data['properties']['filling']['products']['rss_sort_by'] == 'U' ? 'updated_timestamp' : 'timestamp', 'sort_order' => 'desc'); $max_items = !empty($block_data['properties']['max_item']) ? $block_data['properties']['max_item'] : 5; list($products) = fn_get_products($_params, $max_items, $lang_code); fn_gather_additional_products_data($products, array('get_icon' => true, 'get_detailed' => true, 'get_options' => false, 'get_discounts' => false)); $additional_data['title'] = !empty($block_data['properties']['feed_title']) ? $block_data['properties']['feed_title'] : __('products') . '::' . __('page_title', '', $lang_code); $additional_data['description'] = !empty($block_data['properties']['feed_description']) ? $block_data['properties']['feed_description'] : $additional_data['title']; $additional_data['link'] = fn_url('', 'C', 'http', $lang_code); $additional_data['language'] = $lang_code; $additional_data['lastBuildDate'] = !empty($products[0]['updated_timestamp']) ? $products[0]['updated_timestamp'] : TIME; $items_data = fn_format_products_items($products, $block_data['properties']['filling']['products'], $lang_code); } } else { //show rss feed for categories page list($items_data, $additional_data) = fn_format_categories_items($params, $lang_code); } fn_set_hook('generate_rss_feed', $items_data, $additional_data, $block_data, $lang_code); return array($items_data, $additional_data); }
function fn_get_banners($params, $lang_code = CART_LANGUAGE) { $default_params = array('items_per_page' => 0, 'sort_by' => 'name'); $params = array_merge($default_params, $params); $sortings = array('timestamp' => '?:banners.timestamp', 'name' => '?:banner_descriptions.banner'); $directions = array('asc' => 'asc', 'desc' => 'desc'); $condition = $limit = ''; if (!empty($params['limit'])) { $limit = db_quote(' LIMIT 0, ?i', $params['limit']); } if (empty($params['sort_order']) || empty($directions[$params['sort_order']])) { $params['sort_order'] = 'asc'; } if (empty($params['sort_by']) || empty($sortings[$params['sort_by']])) { $params['sort_by'] = 'name'; } $sorting = $sortings[$params['sort_by']] . ' ' . $directions[$params['sort_order']]; $condition = AREA == 'A' ? '' : " AND ?:banners.status = 'A' "; $condition .= fn_get_localizations_condition('?:banners.localization'); if (!empty($params['item_ids'])) { $condition .= db_quote(' AND ?:banners.banner_id IN (?n)', explode(',', $params['item_ids'])); } if (!empty($params['period']) && $params['period'] != 'A') { list($params['time_from'], $params['time_to']) = fn_create_periods($params); $condition .= db_quote(" AND (?:banners.timestamp >= ?i AND ?:banners.timestamp <= ?i)", $params['time_from'], $params['time_to']); } $banners = db_get_array("SELECT ?:banners.banner_id, ?:banners.type, ?:banners.target, ?:banners.status, ?:banners.url, ?:banner_descriptions.banner, ?:banner_descriptions.description FROM ?:banners LEFT JOIN ?:banner_descriptions ON ?:banner_descriptions.banner_id = ?:banners.banner_id AND ?:banner_descriptions.lang_code = ?s WHERE 1 ?p ORDER BY ?p ?p", $lang_code, $condition, $sorting, $limit); foreach ($banners as $k => $v) { $banners[$k]['main_pair'] = fn_get_image_pairs($v['banner_id'], 'banner', 'M', true, false, $lang_code); } if (!empty($params['item_ids'])) { $banners = fn_sort_by_ids($banners, explode(',', $params['item_ids']), 'banner_id'); } fn_set_hook('get_banners', $banners); return array($banners, $params); }
/** * Gets storefront URL * @param string $protocol protocol (http/https/current) * @param integer $company_id company ID * @return string storefront URL */ function fn_get_storefront_url($protocol = 'current', $company_id = 0) { $url = Registry::get('config.' . $protocol . '_location'); /** * Changes storefront URL * @param string $protocol protocol (http/https/current) * @param integer $company_id company ID * @param string $url storefront URL */ fn_set_hook('get_storefront_url', $protocol, $company_id, $url); return $url; }
/** * Gets style file path * @param string $style_id style ID * @param string $type file type (less/css/png) * @return string style file path */ public function getStyleFile($style_id, $type = 'less') { $path = $this->getStylesPath(); /** * Modifies the path to style file * * @param object $this Styles object * @param string $path current path * @param string $style_id style ID * @param string $type file type */ fn_set_hook('styles_get_style_file', $this, $path, $style_id, $type); return $path . '/' . $style_id . '.' . $type; }
function fn_update_product_filter($filter_data, $filter_id, $lang_code = DESCR_SL) { if (fn_allowed_for('ULTIMATE') && Registry::get('runtime.company_id')) { if (!empty($filter_id) && !fn_check_company_id('product_filters', 'filter_id', $filter_id)) { fn_company_access_denied_notification(); return false; } if (!empty($filter_id)) { unset($filter_data['company_id']); } } // Parse filter type if (strpos($filter_data['filter_type'], 'FF-') === 0 || strpos($filter_data['filter_type'], 'RF-') === 0 || strpos($filter_data['filter_type'], 'DF-') === 0) { $filter_data['feature_id'] = str_replace(array('RF-', 'FF-', 'DF-'), '', $filter_data['filter_type']); $filter_data['feature_type'] = db_get_field("SELECT feature_type FROM ?:product_features WHERE feature_id = ?i", $filter_data['feature_id']); } else { $filter_data['field_type'] = str_replace(array('R-', 'B-'), '', $filter_data['filter_type']); $filter_fields = fn_get_product_filter_fields(); } if (!empty($filter_id)) { db_query('UPDATE ?:product_filters SET ?u WHERE filter_id = ?i', $filter_data, $filter_id); db_query('UPDATE ?:product_filter_descriptions SET ?u WHERE filter_id = ?i AND lang_code = ?s', $filter_data, $filter_id, $lang_code); } else { $filter_data['filter_id'] = $filter_id = db_query('INSERT INTO ?:product_filters ?e', $filter_data); foreach (fn_get_translation_languages() as $filter_data['lang_code'] => $_d) { db_query("INSERT INTO ?:product_filter_descriptions ?e", $filter_data); } } fn_set_hook('update_product_filter', $filter_data, $filter_id, $lang_code); return $filter_id; }
/** * 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; }
function fn_auth_routines($request) { $status = true; $user_login = $_REQUEST['user_login']; $password = $_POST['password']; $field = Registry::get('settings.General.use_email_as_login') == 'Y' ? 'email' : 'user_login'; $user_data = db_get_row("SELECT * FROM ?:users WHERE {$field} = ?s", $user_login); if (!empty($user_data)) { $user_data['usergroups'] = fn_get_user_usergroups($user_data['user_id']); } fn_set_hook('auth_routines', $status, $user_data); if (!empty($user_data['user_type']) && $user_data['user_type'] != 'A' && AREA == 'A') { fn_set_notification('E', fn_get_lang_var('error'), fn_get_lang_var('error_area_access_denied')); $status = false; } if (!empty($user_data['status']) && $user_data['status'] == 'D') { fn_set_notification('E', fn_get_lang_var('error'), fn_get_lang_var('error_account_disabled')); $status = false; } return array($status, $user_data, $user_login, $password); }
} elseif ($mode == 'purge_undeliverable') { fn_purge_undeliverable_products($cart); fn_set_notification('N', __('notice'), __('notice_undeliverable_products_removed')); return array(CONTROLLER_STATUS_REDIRECT, 'checkout.checkout'); } elseif ($mode == 'complete') { if (!empty($_REQUEST['order_id'])) { if (empty($auth['user_id'])) { if (empty($auth['order_ids'])) { return array(CONTROLLER_STATUS_REDIRECT, 'auth.login_form?return_url=' . urlencode(Registry::get('config.current_url'))); } else { $allowed_id = in_array($_REQUEST['order_id'], $auth['order_ids']); } } else { $allowed_id = db_get_field("SELECT user_id FROM ?:orders WHERE user_id = ?i AND order_id = ?i", $auth['user_id'], $_REQUEST['order_id']); } fn_set_hook('is_order_allowed', $_REQUEST['order_id'], $allowed_id); if (empty($allowed_id)) { // Access denied return array(CONTROLLER_STATUS_DENIED); } $order_info = fn_get_order_info($_REQUEST['order_id']); if (!empty($order_info['is_parent_order']) && $order_info['is_parent_order'] == 'Y') { $order_info['child_ids'] = implode(',', db_get_fields("SELECT order_id FROM ?:orders WHERE parent_order_id = ?i", $_REQUEST['order_id'])); } if (!empty($order_info)) { Tygh::$app['view']->assign('order_info', $order_info); } } fn_add_breadcrumb(__('landing_header')); } elseif ($mode == 'process_payment') { if (fn_allow_place_order($cart, $auth) == true) {
/** * Filters path/files to exclude from list * @param string $path path to check * @return boolean true to exclude, false - otherwise */ function fn_te_filter_path($path) { $filter = array(); $fileext_filter = Registry::get('config.forbidden_file_extensions'); $filename = basename($path); fn_set_hook('te_filter_path', $filter, $path, $fileext_filter); if (in_array(fn_get_file_ext($filename), $fileext_filter)) { return true; } if (!empty($filter)) { foreach ($filter as $f) { if (strpos($path, $f) === 0) { return true; } } } return false; }
/** * Check if a user have an access to an order * @param array $response * @param array $auth */ public static function checkIfOrderAllowed($order_id, &$_auth, &$response) { $allow = true; // If user is not logged in and trying to see the order, redirect him to login form if (empty($_auth['user_id']) && empty($_auth['order_ids'])) { $response->addError('ERROR_ACCESS_DENIED', __('access_denied')); $response->returnResponse(); $allow = false; } $allowed_id = 0; if (!empty($_auth['user_id'])) { $allowed_id = db_get_field("SELECT user_id\n FROM ?:orders\n WHERE user_id = ?i AND order_id = ?i", $_auth['user_id'], $order_id); } elseif (!empty($_auth['order_ids'])) { $allowed_id = in_array($order_id, $_auth['order_ids']); } // Check order status (incompleted order) if (!empty($allowed_id)) { $status = db_get_field('SELECT status FROM ?:orders WHERE order_id = ?i', $order_id); if ($status == STATUS_INCOMPLETED_ORDER) { $allowed_id = 0; } } fn_set_hook('is_order_allowed', $order_id, $allowed_id); if (empty($allowed_id)) { // Access denied $response->addError('ERROR_ACCESS_DENIED', __('access_denied')); $response->returnResponse(); $allow = false; } return $allow; }
function fn_delete_gift_certificate($gift_cert_id, $extra = array()) { if (!empty($gift_cert_id) && fn_check_company_id('gift_certificates', 'gift_cert_id', $gift_cert_id)) { $gift_data = db_get_row("SELECT gift_cert_code, order_ids FROM ?:gift_certificates WHERE gift_cert_id = ?i", $gift_cert_id); if (!empty($gift_data['order_ids'])) { fn_set_notification('W', __('warning'), __('text_gift_cert_cannot_delete', array('[code]' => $gift_data['gift_cert_code'], '[ids]' => $gift_data['order_ids']))); return false; } db_query("DELETE FROM ?:gift_certificates WHERE gift_cert_id = ?i", $gift_cert_id); db_query("DELETE FROM ?:gift_certificates_log WHERE gift_cert_id = ?i", $gift_cert_id); fn_set_hook('delete_gift_certificate', $gift_cert_id, $extra); return true; } else { return false; } }
/** * $type values * * M-O+ change main and optional data * O- change optional data * M+ change main data * */ function fn_rma_recalculate_order_routine(&$order, &$item, $mirror_item, $type = '', $ex_data = array()) { $amount = 0; if (!isset($item['extra']['exclude_from_calculate'])) { if (in_array($type, array('M+', 'M-O+'))) { $sign = $type == 'M+' ? 1 : -1; $delta = $mirror_item['price'] * $mirror_item['extra']['returns'][$ex_data['return_id']]['amount']; $order['subtotal'] = $order['subtotal'] + $sign * $delta; $order['total'] = $order['total'] + $sign * $delta; $_discount = isset($mirror_item['extra']['discount']) ? $mirror_item['extra']['discount'] : (isset($item['extra']['discount']) ? $item['extra']['discount'] : 0); $order['discount'] = $order['discount'] + $sign * $_discount * $item['amount']; unset($mirror_item['extra']['discount'], $item['extra']['discount']); } if (in_array($type, array('O-', 'M-O+'))) { $amount = fn_rma_recalculate_product_amount($item['item_id'], $item['product_id'], @$item['extra']['product_options'], $type, $ex_data); } } else { if (in_array($type, array('O-', 'M-O+'))) { fn_rma_recalculate_product_amount($item['item_id'], $item['product_id'], @$item['extra']['product_options'], $type, $ex_data); } } fn_set_hook('rma_recalculate_order', $item, $mirror_item, $type, $ex_data, $amount); }
function fn_image_to_display($images, $image_width = 0, $image_height = 0) { if (empty($images)) { return array(); } $image_data = array(); // image pair passed if (!empty($images['icon']) || !empty($images['detailed'])) { if (!empty($images['icon'])) { $original_width = $images['icon']['image_x']; $original_height = $images['icon']['image_y']; $image_path = $images['icon']['image_path']; $absolute_path = $images['icon']['absolute_path']; $relative_path = $images['icon']['relative_path']; } else { $original_width = $images['detailed']['image_x']; $original_height = $images['detailed']['image_y']; $image_path = $images['detailed']['image_path']; $absolute_path = $images['detailed']['absolute_path']; $relative_path = $images['detailed']['relative_path']; } $detailed_image_path = !empty($images['detailed']['image_path']) ? $images['detailed']['image_path'] : ''; $alt = !empty($images['icon']['alt']) ? $images['icon']['alt'] : $images['detailed']['alt']; // single image passed only } else { $original_width = $images['image_x']; $original_height = $images['image_y']; $image_path = $images['image_path']; $alt = $images['alt']; $detailed_image_path = ''; $absolute_path = $images['absolute_path']; $relative_path = $images['relative_path']; } if (!empty($image_height) && empty($image_width) && !empty($original_height)) { $image_width = intval($image_height * $original_width / $original_height); } if (!empty($image_width) && empty($image_height) && !empty($original_width)) { $image_height = intval($image_width * $original_height / $original_width); } if (!empty($image_width) && !empty($relative_path) && !empty($absolute_path)) { $image_path = fn_generate_thumbnail($relative_path, $image_width, $image_height, Registry::get('config.tweaks.lazy_thumbnails')); } else { $image_width = $original_width; $image_height = $original_height; } if (!empty($image_path)) { $image_data = array('image_path' => $image_path, 'detailed_image_path' => $detailed_image_path, 'alt' => $alt, 'width' => $image_width, 'height' => $image_height, 'absolute_path' => $absolute_path, 'generate_image' => strpos($image_path, '&image_path=') !== false); } /** * Additionally processes image data * * @param array $image_data Image data * @param array $images Array with initial images * @param $image_width Result image width * @param $image_height Result image height */ fn_set_hook('image_to_display_post', $image_data, $images, $image_width, $image_height); return $image_data; }
public static function orderPlacementRoutines($order_id, $force_notification = array(), $clear_cart = true, $action = '') { // don't show notifications // only clear cart $order_info = fn_get_order_info($order_id, true); $display_notification = true; fn_set_hook('placement_routines', $order_id, $order_info, $force_notification, $clear_cart, $action, $display_notification); if (!empty($_SESSION['cart']['placement_action'])) { if (empty($action)) { $action = $_SESSION['cart']['placement_action']; } unset($_SESSION['cart']['placement_action']); } if (AREA == 'C' && !empty($order_info['user_id'])) { $__fake = ''; fn_save_cart_content($__fake, $order_info['user_id']); } $edp_data = fn_generate_ekeys_for_edp(array(), $order_info); fn_order_notification($order_info, $edp_data, $force_notification); // Empty cart if ($clear_cart == true && substr_count('OPT', $order_info['status']) > 0) { $_SESSION['cart'] = array('user_data' => !empty($_SESSION['cart']['user_data']) ? $_SESSION['cart']['user_data'] : array(), 'profile_id' => !empty($_SESSION['cart']['profile_id']) ? $_SESSION['cart']['profile_id'] : 0, 'user_id' => !empty($_SESSION['cart']['user_id']) ? $_SESSION['cart']['user_id'] : 0); db_query('DELETE FROM ?:user_session_products WHERE session_id = ?s AND type = ?s', Session::getId(), 'C'); } $is_twg_hook = true; $_error = false; fn_set_hook('order_placement_routines', $order_id, $force_notification, $order_info, $_error, $is_twg_hook); }
function fn_is_accessible_discussion($data, &$auth) { $access = false; if ($data['object_type'] == 'P') { //product $access = fn_get_product_data($data['object_id'], $auth, CART_LANGUAGE, $field_list = '?:products.product_id', false, false, false); } elseif ($data['object_type'] == 'C') { //category $access = fn_get_category_data($data['object_id'], '', $field_list = '?:categories.category_id', false); } elseif ($data['object_type'] == 'M') { //company $access = fn_get_company_data($data['object_id']); } elseif ($data['object_type'] == 'O') { //order if (!empty($auth['user_id'])) { $access = db_get_field("SELECT order_id FROM ?:orders WHERE order_id = ?i AND user_id = ?i", $data['object_id'], $auth['user_id']); } elseif (!empty($auth['order_ids'])) { $access = in_array($data['object_id'], $auth['order_ids']); } } elseif ($data['object_type'] == 'A') { // page $access = fn_get_page_data($data['object_id'], CART_LANGUAGE); } elseif ($data['object_type'] == 'E') { // testimonials $access = true; } fn_set_hook('is_accessible_discussion', $data, $auth, $access); return !empty($access); }
// Try to determine the service level $service_level = 'Standard'; if (preg_match('/(?:1|one).{0,1}day/i', $shipping['shipping'])) { $service_level = 'OneDay'; } elseif (preg_match('/(?:2|two).{0,1}day/i', $shipping['shipping'])) { $service_level = 'TwoDay'; } elseif (preg_match('/(?:express|expedited)/i', $shipping['shipping'])) { $service_level = 'Expedited'; } $shipping_data = array('ShippingMethodId' => $shipping['shipping'] . ' ' . $shipping['delivery_time'], 'ServiceLevel' => $service_level, 'Rate' => array('ShipmentBased' => array('Amount' => fn_format_price(array_sum($shipping['rates']) + $tax_rate), 'CurrencyCode' => $processor_data['processor_params']['currency'])), 'IncludedRegions' => array('PredefinedRegion' => 'WorldAll'), 'DisplayableShippingLabel' => $shipping['shipping'] . (empty($tax_rate) ? '' : ' (' . __('price_includes_tax') . ': $' . fn_format_price($tax_rate) . ')')); $items_shipping['ShippingMethodId'][] = $shipping['shipping'] . ' ' . $shipping['delivery_time']; $callback_response['ShippingMethods']['ShippingMethod'][] = $shipping_data; } } $amazon_products = $cart_products; fn_set_hook('amazon_products', $amazon_products, $cart); foreach ($amazon_products as $key => $product) { $sku = empty($product['product_code']) ? 'pid_' . $product['product_id'] : substr(strip_tags($product['product_code']), 0, 250); if ($tax_calculation_type == 'amazon' && isset($_taxed_products[$key])) { $tax_table_id = 'tax_' . $_taxed_products[$key]; } else { $tax_table_id = 'tax_default'; } $item = array('CallbackOrderItemId' => $sku, 'TaxTableId' => $tax_table_id, 'ShippingMethodIds' => $items_shipping); $callback_response['Response']['CallbackOrders']['CallbackOrder']['CallbackOrderItems']['CallbackOrderItem'][] = $item; } $callback_response['CartPromotionId'] = 'cart-discount'; // Update the tax info if ($tax_calculation_type == 'default' && $tax_subtotal > 0) { $tax = array('SKU' => 'taxes', 'MerchantId' => $processor_data['processor_params']['merchant_id'], 'Title' => substr($tax_description, 0, 250), 'Price' => array('Amount' => fn_format_price($tax_subtotal), 'CurrencyCode' => $processor_data['processor_params']['currency']), 'Quantity' => 1, 'UpdateType' => 'REMOVE'); $callback_response['Response']['CallbackOrders']['CallbackOrder']['UpdatedCartItems']['UpdatedCartItem'][] = $tax;
function fn_dashboard_get_graphs_data($time_from, $time_to, $is_day) { $company_condition = fn_get_company_condition('?:orders.company_id'); $graphs = array(); $graph_tabs = array(); $time_to = mktime(23, 59, 59, date("n", $time_to), date("j", $time_to), date("Y", $time_to)); if (fn_check_view_permissions("sales_reports.view", "GET")) { $graphs['dashboard_statistics_sales_chart'] = array(); $paid_statuses = array('P', 'C'); for ($i = $time_from; $i <= $time_to; $i = $i + ($is_day ? 60 * 60 : SECONDS_IN_DAY)) { $date = !$is_day ? date("Y, (n-1), j", $i) : date("H", $i); if (empty($graphs['dashboard_statistics_sales_chart'][$date])) { $graphs['dashboard_statistics_sales_chart'][$date] = array('cur' => 0, 'prev' => 0); } } $sales = db_get_array("SELECT " . "?:orders.timestamp, " . "?:orders.total " . "FROM ?:orders " . "WHERE ?:orders.timestamp BETWEEN ?i AND ?i " . "AND ?:orders.status IN (?a) " . "?p ", $time_from, $time_to, $paid_statuses, $company_condition); foreach ($sales as $sale) { $date = !$is_day ? date("Y, (n-1), j", $sale['timestamp']) : date("H", $sale['timestamp']); $graphs['dashboard_statistics_sales_chart'][$date]['cur'] += $sale['total']; } $sales_prev = db_get_array("SELECT " . "?:orders.timestamp, " . "?:orders.total " . "FROM ?:orders " . "WHERE ?:orders.timestamp BETWEEN ?i AND ?i " . "AND ?:orders.status IN (?a) " . "?p ", $time_from - ($time_to - $time_from), $time_from, $paid_statuses, $company_condition); foreach ($sales_prev as $sale) { $date = $sale['timestamp'] + ($time_to - $time_from); $date = !$is_day ? date("Y, (n-1), j", $date) : date("H", $date); $graphs['dashboard_statistics_sales_chart'][$date]['prev'] += $sale['total']; } $graph_tabs['sales_chart'] = array('title' => __('sales'), 'js' => true); } fn_set_hook('dashboard_get_graphs_data', $time_from, $time_to, $graphs, $graph_tabs, $is_day); Registry::set('navigation.tabs', $graph_tabs); return $graphs; }