Ejemplo n.º 1
0
/**
 * 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;
}
Ejemplo n.º 2
0
/**
 * 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;
}
Ejemplo n.º 3
0
 /**
  * Registers block cache
  *
  * @param string $cache_name   Cache name
  * @param array  $block_schema Block schema data
  * @param array  $block_data   Block data from DB
  *
  * @return bool Whether cache have been registered or not
  */
 public static function registerBlockCacheIfNeeded($cache_name, $block_schema, $block_data)
 {
     // @TODO: remove Registry calls and use RenderManager::$_location instead. This method should be non-static.
     $dispatch = Registry::get('runtime.controller') . '.' . Registry::get('runtime.mode');
     // Use parameters for current dispatch with fallback to common params
     if (!empty($block_schema['cache_overrides_by_dispatch'][$dispatch])) {
         $cache_params = $block_schema['cache_overrides_by_dispatch'][$dispatch];
     } elseif (!empty($block_schema['cache'])) {
         $cache_params = $block_schema['cache'];
     } else {
         return false;
     }
     $cookie_data = fn_get_session_data();
     $cookie_data['all'] = $cookie_data;
     $callable_handlers_variables = compact('block_schema', 'block_data');
     $disable_cache = false;
     // Check conditions that disable block caching
     if (!empty($cache_params['disable_cache_when'])) {
         $disable_cache |= self::findHandlerParamsAtData($cache_params['disable_cache_when'], 'request_handlers', $_REQUEST);
         $disable_cache |= self::findHandlerParamsAtData($cache_params['disable_cache_when'], 'session_handlers', $_SESSION);
         $disable_cache |= self::findHandlerParamsAtData($cache_params['disable_cache_when'], 'cookie_handlers', $cookie_data);
         $disable_cache |= self::findHandlerParamsAtData($cache_params['disable_cache_when'], 'auth_handlers', $_SESSION['auth']);
         // Disable cache if any of callable handlers returns true
         if (!empty($cache_params['disable_cache_when']['callable_handlers'])) {
             self::execCallableHandlers(function ($handler_name, $handler_result) use(&$disable_cache) {
                 $disable_cache |= $handler_result;
             }, (array) $cache_params['disable_cache_when']['callable_handlers'], $callable_handlers_variables);
         }
     }
     if ($disable_cache) {
         return false;
     }
     // Generate suffix to cache key using dependencies specified at schema
     $cache_key_suffix = '';
     $generate_additional_level = function ($param_name, $param_value) use(&$cache_key_suffix) {
         $cache_key_suffix .= '|' . $param_name . '=' . md5(serialize($param_value));
     };
     self::findHandlerParamsAtData($cache_params, 'request_handlers', $_REQUEST, $generate_additional_level);
     self::findHandlerParamsAtData($cache_params, 'session_handlers', $_SESSION, $generate_additional_level);
     self::findHandlerParamsAtData($cache_params, 'cookie_handlers', $cookie_data, $generate_additional_level);
     self::findHandlerParamsAtData($cache_params, 'auth_handlers', $_SESSION['auth'], $generate_additional_level);
     if (!empty($cache_params['callable_handlers'])) {
         self::execCallableHandlers($generate_additional_level, (array) $cache_params['callable_handlers'], $callable_handlers_variables);
     }
     $cache_key_suffix .= '|path=' . Registry::get('config.current_path');
     $cache_key_suffix .= Embedded::isEnabled() ? '|embedded' : '';
     $cache_key_suffix = empty($cache_key_suffix) ? '' : md5($cache_key_suffix);
     $default_update_handlers = fn_get_schema('block_manager', 'block_cache_properties');
     if (isset($cache_params['update_handlers']) && is_array($cache_params['update_handlers'])) {
         $handlers = array_merge($cache_params['update_handlers'], $default_update_handlers['update_handlers']);
     } else {
         $handlers = $default_update_handlers['update_handlers'];
     }
     $cache_level = isset($cache_params['cache_level']) ? $cache_params['cache_level'] : Registry::cacheLevel('html_blocks');
     Registry::registerCache($cache_name, $handlers, $cache_level . '__' . $cache_key_suffix);
     // Check conditions that trigger block cache regeneration
     $regenerate_cache = false;
     if (!empty($cache_params['regenerate_cache_when'])) {
         $regenerate_cache |= self::findHandlerParamsAtData($cache_params['regenerate_cache_when'], 'request_handlers', $_REQUEST);
         $regenerate_cache |= self::findHandlerParamsAtData($cache_params['regenerate_cache_when'], 'session_handlers', $_SESSION);
         $regenerate_cache |= self::findHandlerParamsAtData($cache_params['regenerate_cache_when'], 'cookie_handlers', $cookie_data);
         $regenerate_cache |= self::findHandlerParamsAtData($cache_params['regenerate_cache_when'], 'auth_handlers', $_SESSION['auth']);
         // Regenerate cache if any of callable handlers returns true
         if (!empty($cache_params['regenerate_cache_when']['callable_handlers'])) {
             self::execCallableHandlers(function ($handler_name, $handler_result) use(&$regenerate_cache) {
                 $regenerate_cache |= $handler_result;
             }, (array) $cache_params['regenerate_cache_when']['callable_handlers'], $callable_handlers_variables);
         }
     }
     if ($regenerate_cache) {
         Registry::del($cache_name);
     }
     return true;
 }
Ejemplo n.º 4
0
/**
 * Gets current URL taking into account embedded mode
 * @return string current URL
 */
function fn_sb_get_url()
{
    $url = fn_url(Registry::get('config.current_url'));
    if (Embedded::isEnabled()) {
        $url = Embedded::getUrl() . '#!/' . fn_url(Registry::get('config.current_url'), AREA, 'rel');
    }
    return $url;
}
Ejemplo n.º 5
0
/**
 * Gets current URL taking into account embedded mode
 * @return string current URL
 */
function fn_sb_get_url()
{
    $url = fn_url(Registry::get('config.current_url'));
    if (Embedded::isEnabled()) {
        // If SEO addon is enabled, the relative url will contain the current path,
        // which is not what expected and therefore removed here
        $_url = fn_url(Registry::get('config.current_url'), AREA, 'rel');
        $_path = Registry::get('config.current_path');
        if (!empty($_path) && strpos($_url, $_path) === 0) {
            $_url = substr($_url, strlen($_path));
        }
        $url = Embedded::getUrl() . '#!/' . $_url;
    }
    return $url;
}
Ejemplo n.º 6
0
/**
* Redirect browser to the new location
*
* @param string $location - destination of redirect
* @param bool $allow_external_redirect - allow redirection to external resource
* @param bool $is_permanent - if true, perform 301 redirect
* @return
*/
function fn_redirect($location, $allow_external_redirect = false, $is_permanent = false)
{
    $external_redirect = false;
    $protocol = defined('HTTPS') ? 'https' : 'http';
    $meta_redirect = false;
    // Cleanup location from &amp; signs and call fn_url()
    $location = fn_url(str_replace(array('&amp;', "\n", "\r"), array('&', '', ''), $location));
    // Convert absolute link with location to relative one
    if (strpos($location, '://') !== false || substr($location, 0, 7) == 'mailto:') {
        if (strpos($location, Registry::get('config.http_location')) !== false) {
            $location = str_replace(array(Registry::get('config.http_location') . '/', Registry::get('config.http_location')), '', $location);
            $protocol = 'http';
        } elseif (strpos($location, Registry::get('config.https_location')) !== false) {
            $location = str_replace(array(Registry::get('config.https_location') . '/', Registry::get('config.https_location')), '', $location);
            $protocol = 'https';
        } else {
            if ($allow_external_redirect == false) {
                // if external redirects aren't allowed, redirect to index script
                $location = '';
            } else {
                $external_redirect = true;
            }
        }
        // Convert absolute link without location to relative one
    } else {
        $_protocol = "";
        $_location = "";
        $http_path = Registry::get('config.http_path');
        $https_path = Registry::get('config.https_path');
        if (!empty($http_path) && substr($location, 0, strlen($http_path)) == $http_path) {
            $_location = substr($location, strlen($http_path) + 1);
            $_protocol = 'http';
        }
        if (!empty($https_path) && substr($location, 0, strlen($https_path)) == $https_path) {
            // if https path partially equal to http path check if https path is not just a part of http path
            // e. g. http://example.com/pathsimple & https://example.com/path
            if ($_protocol != 'http' || empty($http_path) || substr($http_path, 0, strlen($https_path)) != $https_path) {
                $_location = substr($location, strlen($https_path) + 1);
                $_protocol = 'https';
            }
        }
        $protocol = Registry::get('config.http_path') != Registry::get('config.https_path') && !empty($_protocol) ? $_protocol : $protocol;
        $location = !empty($_protocol) ? $_location : $location;
    }
    if ($external_redirect == false) {
        fn_set_hook('redirect', $location);
        $protocol_changed = defined('HTTPS') && $protocol == 'http' || !defined('HTTPS') && $protocol == 'https';
        // For correct redirection, location must be absolute with path
        $location = ($protocol == 'http' ? Registry::get('config.http_location') : Registry::get('config.https_location')) . '/' . ltrim($location, '/');
        // Parse the query string
        $fragment = '';
        $query_array = array();
        $parsed_location = parse_url($location);
        if (!empty($parsed_location['query'])) {
            parse_str($parsed_location['query'], $query_array);
            $location = str_replace('?' . $parsed_location['query'], '', $location);
        }
        if (!empty($parsed_location['fragment'])) {
            $fragment = '#' . $parsed_location['fragment'];
            $location = str_replace($fragment, '', $location);
        }
        if ($protocol_changed && (Registry::get('config.http_host') != Registry::get('config.https_host') || Registry::get('config.http_path') != Registry::get('config.https_path'))) {
            $query_array[Session::getName()] = Session::getId();
        }
        // If this is not ajax request, remove ajax specific parameters
        if (!defined('AJAX_REQUEST')) {
            unset($query_array['is_ajax']);
            unset($query_array['result_ids']);
        } else {
            $query_array['result_ids'] = implode(',', Tygh::$app['ajax']->result_ids);
            $query_array['is_ajax'] = Tygh::$app['ajax']->redirect_type;
            $query_array['full_render'] = !empty($_REQUEST['full_render']) ? $_REQUEST['full_render'] : false;
            $query_array['callback'] = Tygh::$app['ajax']->callback;
            $ajax_assigned_vars = Tygh::$app['ajax']->getAssignedVars();
            if (!empty($ajax_assigned_vars['html'])) {
                unset($ajax_assigned_vars['html']);
            }
            $query_array['_ajax_data'] = $ajax_assigned_vars;
        }
        if (!empty($query_array)) {
            $location .= '?' . http_build_query($query_array) . $fragment;
        }
        // Redirect from https to http location
        if ($protocol_changed && defined('HTTPS')) {
            $meta_redirect = true;
        }
    }
    fn_set_hook('redirect_complete', $meta_redirect);
    if (!defined('AJAX_REQUEST') && Embedded::isEnabled()) {
        if (strpos($location, Registry::get('config.http_location')) === 0) {
            $location = str_replace(Registry::get('config.http_location'), '', $location);
        } elseif (strpos($location, Registry::get('config.https_location')) === 0) {
            $location = str_replace(Registry::get('config.https_location'), '', $location);
        }
        $location = Embedded::getUrl() . '#!' . urlencode($location);
        $meta_redirect = true;
    }
    if (defined('AJAX_REQUEST')) {
        // make in-script redirect during ajax request
        $_purl = parse_url($location);
        $_GET = array();
        $_POST = array();
        if (!empty($_purl['query'])) {
            parse_str($_purl['query'], $_GET);
        }
        $_REQUEST = Bootstrap::safeInput($_GET);
        $_SERVER['REQUEST_METHOD'] = 'GET';
        $_SERVER['REQUEST_URI'] = $_purl['path'];
        $_SERVER['QUERY_STRING'] = !empty($_purl['query']) ? $_purl['query'] : '';
        fn_get_route($_REQUEST);
        Registry::save();
        // save registry cache to execute cleanup handlers
        fn_init_settings();
        fn_init_addons();
        Registry::clearCacheLevels();
        Tygh::$app['ajax']->updateRequest();
        return fn_dispatch();
    } elseif (!ob_get_contents() && !headers_sent() && !$meta_redirect) {
        if ($is_permanent) {
            header('HTTP/1.0 301 Moved Permanently');
        }
        header('Location: ' . $location);
        exit;
    } else {
        $delay = (Debugger::isActive() || fn_is_development()) && !Registry::get('runtime.comet') ? 10 : 0;
        if ($delay != 0) {
            fn_echo('<a href="' . htmlspecialchars($location) . '" style="text-transform: lowercase;">' . __('continue') . '</a>');
        }
        fn_echo('<meta http-equiv="Refresh" content="' . $delay . ';URL=' . htmlspecialchars($location) . '" />');
    }
    fn_flush();
    exit;
}
Ejemplo n.º 7
0
/**
 * Create HTML form with payment data and submit it.
 *
 * @param string $submit_url URL to send payment data
 * @param array $data Payment data to be submitted
 * @param string $payment_name Payment name to be displayed duron form submitting
 * @param boolean $exclude_empty_values Define that payment data elements with empty values should be excluded from payment form
 * @param string $method form submit method (get/post)
 */
function fn_create_payment_form($submit_url, $data, $payment_name = '', $exclude_empty_values = true, $method = 'post', $parse_url = true, $target = 'form')
{
    Embedded::leave();
    if (Embedded::isEnabled()) {
        list($submit_url, $data, $method, $payment_name) = Embedded::processPaymentForm($submit_url, $data, $payment_name, $exclude_empty_values, $method);
    }
    if ($parse_url) {
        $parsed_url = parse_url($submit_url);
        if (!empty($parsed_url['query'])) {
            $_data = array();
            parse_str($parsed_url['query'], $_data);
            $data = fn_array_merge($data, $_data);
            $submit_url = $parsed_url['scheme'] . '://' . $parsed_url['host'] . $parsed_url['path'];
        }
    }
    echo <<<EOT
        <form method="{$method}" action="{$submit_url}" name="process">
EOT;
    foreach ($data as $name => $value) {
        if (!empty($value) || empty($value) && $exclude_empty_values === false) {
            echo '<input type="hidden" name="' . htmlentities($name, ENT_QUOTES, 'UTF-8') . '" value="' . htmlentities($value, ENT_QUOTES, 'UTF-8') . '" />' . "\n";
        }
    }
    if (!empty($payment_name)) {
        echo __('text_cc_processor_connection', array('[processor]' => $payment_name));
    }
    echo <<<EOT
        </form>
        <script type="text/javascript">
            window.onload = function(){
EOT;
    if ($target == 'parent') {
        echo <<<EOT
                window.parent.location='{$submit_url}';
EOT;
    } elseif ($target == 'form') {
        echo <<<EOT
                document.process.submit();
EOT;
    }
    echo <<<EOT
            };
        </script>
        </body>
    </html>
EOT;
    exit;
}
Ejemplo n.º 8
0
function fn_order_placement_routines($action = '', $order_id = 0, $force_notification = array(), $clear_cart = true, $area = AREA)
{
    if (Embedded::isLeft() && !Embedded::isEnabled()) {
        Embedded::enable();
    }
    if ($action == 'checkout_redirect') {
        if ($area == 'A') {
            fn_redirect("order_management.edit?order_id=" . reset($_SESSION['cart']['processed_order_id']));
        } else {
            fn_redirect('checkout.' . (Registry::get('settings.General.checkout_style') != 'multi_page' ? 'checkout' : 'summary'));
        }
    } elseif (in_array($action, array('save', 'repay', 'route')) && !empty($order_id)) {
        $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);
        $_error = false;
        if ($action == 'save') {
            if ($display_notification) {
                fn_set_notification('N', __('congratulations'), __('text_order_saved_successfully'));
            }
        } else {
            if ($order_info['status'] == STATUS_PARENT_ORDER) {
                $child_orders = db_get_hash_single_array("SELECT order_id, status FROM ?:orders WHERE parent_order_id = ?i", array('order_id', 'status'), $order_id);
                $status = reset($child_orders);
                $child_orders = array_keys($child_orders);
            } else {
                $status = $order_info['status'];
            }
            if (in_array($status, fn_get_order_paid_statuses())) {
                if ($action == 'repay') {
                    fn_set_notification('N', __('congratulations'), __('text_order_repayed_successfully'));
                } else {
                    fn_set_notification('N', __('order_placed'), __('text_order_placed_successfully'));
                }
            } elseif ($status == STATUS_BACKORDERED_ORDER) {
                fn_set_notification('W', __('important'), __('text_order_backordered'));
            } else {
                if ($area == 'A' || $action == 'repay') {
                    if ($status != STATUS_CANCELED_ORDER) {
                        $_payment_info = db_get_field("SELECT data FROM ?:order_data WHERE order_id = ?i AND type = 'P'", $order_id);
                        if (!empty($_payment_info)) {
                            $_payment_info = unserialize(fn_decrypt_text($_payment_info));
                            $_msg = !empty($_payment_info['reason_text']) ? $_payment_info['reason_text'] : '';
                            $_msg .= empty($_msg) ? __('text_order_placed_error') : '';
                            fn_set_notification('E', '', $_msg);
                        }
                    }
                } else {
                    $_error = true;
                    if (!empty($child_orders)) {
                        array_unshift($child_orders, $order_id);
                    } else {
                        $child_orders = array();
                        $child_orders[] = $order_id;
                    }
                    $_SESSION['cart'][$status == STATUS_INCOMPLETED_ORDER ? 'processed_order_id' : 'failed_order_id'] = $child_orders;
                }
                if ($status == STATUS_INCOMPLETED_ORDER || $action == 'repay' && $status == STATUS_CANCELED_ORDER) {
                    fn_set_notification('W', __('important'), __('text_transaction_cancelled'));
                }
            }
        }
        // Empty cart
        if ($clear_cart == true && $_error == false) {
            $_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);
            $_SESSION['shipping_rates'] = array();
            unset($_SESSION['shipping_hash']);
            db_query('DELETE FROM ?:user_session_products WHERE session_id = ?s AND type = ?s', Session::getId(), 'C');
        }
        fn_set_hook('order_placement_routines', $order_id, $force_notification, $order_info, $_error);
        if ($area == 'A') {
            fn_redirect("orders.details?order_id={$order_id}");
        } else {
            fn_redirect('checkout.' . ($_error == true ? Registry::get('settings.General.checkout_style') != 'multi_page' ? 'checkout' : 'summary' : "complete?order_id={$order_id}"));
        }
    } elseif ($action == 'index_redirect') {
        fn_redirect(fn_url('', 'C', 'http'));
    } else {
        fn_redirect(fn_url($action, 'C', 'http'));
    }
}
Ejemplo n.º 9
0
/**
 * Init user
 *
 * @return boolean always true
 */
function fn_init_user($area = AREA)
{
    $user_info = array();
    if (!empty(Tygh::$app['session']['auth']['user_id'])) {
        $user_info = fn_get_user_short_info(Tygh::$app['session']['auth']['user_id']);
        if (empty($user_info)) {
            // user does not exist in the database, but exists in session
            Tygh::$app['session']['auth'] = array();
        } else {
            Tygh::$app['session']['auth']['usergroup_ids'] = fn_define_usergroups(array('user_id' => Tygh::$app['session']['auth']['user_id'], 'user_type' => $user_info['user_type']));
        }
    }
    $first_init = false;
    if (empty(Tygh::$app['session']['auth'])) {
        $udata = array();
        $user_id = fn_get_session_data($area . '_user_id');
        if ($area == 'A' && defined('CONSOLE')) {
            $user_id = 1;
        }
        if ($user_id) {
            fn_define('LOGGED_VIA_COOKIE', true);
        }
        fn_login_user($user_id);
        if (!defined('NO_SESSION')) {
            Tygh::$app['session']['cart'] = isset(Tygh::$app['session']['cart']) ? Tygh::$app['session']['cart'] : array();
        }
        if (defined('LOGGED_VIA_COOKIE') && !empty(Tygh::$app['session']['auth']['user_id']) || ($cu_id = fn_get_session_data('cu_id'))) {
            $first_init = true;
            if (!empty($cu_id)) {
                fn_define('COOKIE_CART', true);
            }
            // Cleanup cached shipping rates
            unset(Tygh::$app['session']['shipping_rates']);
            $_utype = empty(Tygh::$app['session']['auth']['user_id']) ? 'U' : 'R';
            $_uid = empty(Tygh::$app['session']['auth']['user_id']) ? $cu_id : Tygh::$app['session']['auth']['user_id'];
            fn_extract_cart_content(Tygh::$app['session']['cart'], $_uid, 'C', $_utype);
            fn_save_cart_content(Tygh::$app['session']['cart'], $_uid, 'C', $_utype);
            if (!empty(Tygh::$app['session']['auth']['user_id'])) {
                Tygh::$app['session']['cart']['user_data'] = fn_get_user_info(Tygh::$app['session']['auth']['user_id']);
                $user_info = fn_get_user_short_info(Tygh::$app['session']['auth']['user_id']);
            }
        }
    }
    if (fn_is_expired_storage_data('cart_products_next_check', SECONDS_IN_HOUR * 12)) {
        db_query("DELETE FROM ?:user_session_products WHERE user_type = 'U' AND timestamp < ?i", TIME - SECONDS_IN_DAY * 30);
    }
    if (!fn_allowed_for('ULTIMATE:FREE')) {
        // If administrative account has usergroup, it means the access restrictions are in action
        if ($area == 'A' && !empty(Tygh::$app['session']['auth']['usergroup_ids'])) {
            fn_define('RESTRICTED_ADMIN', true);
        }
    }
    if (!empty($user_info) && $user_info['user_type'] == 'A' && (empty($user_info['company_id']) || fn_allowed_for('ULTIMATE') && $user_info['company_id'] == Registry::get('runtime.company_id'))) {
        $customization_mode = fn_array_combine(explode(',', Registry::get('settings.customization_mode')), true);
        if (!empty($customization_mode)) {
            Registry::set('runtime.customization_mode', $customization_mode);
            if ($area == 'A' || Embedded::isEnabled()) {
                Registry::set('runtime.customization_mode.live_editor', false);
            }
        }
    }
    fn_set_hook('user_init', Tygh::$app['session']['auth'], $user_info, $first_init);
    Registry::set('user_info', $user_info);
    return array(INIT_STATUS_OK);
}
Ejemplo n.º 10
0
/**
 * Init layout
 *
 * @param array $params request parameters
 * @return boolean always true
 */
function fn_init_layout($params)
{
    if (fn_allowed_for('ULTIMATE')) {
        if (!Registry::get('runtime.company_id')) {
            return array(INIT_STATUS_OK);
        }
    }
    $key_name = 'stored_layout' . (Embedded::isEnabled() ? '_embedded' : '');
    $stored_layout = fn_get_session_data($key_name);
    if (!empty($params['s_layout'])) {
        $stored_layout = $params['s_layout'];
        fn_set_session_data($key_name, $params['s_layout']);
    }
    // Replace default theme with selected for current area
    if (!empty($stored_layout)) {
        $layout = Layout::instance()->get($stored_layout);
        if (!isset($layout['theme_name']) || $layout['theme_name'] != fn_get_theme_path('[theme]', 'C')) {
            unset($layout);
        }
    }
    if (empty($layout)) {
        $layout = Layout::instance()->getDefault();
        // get default
    }
    $available_styles = Styles::factory($layout['theme_name'])->getList(array('short_info' => true));
    if (!isset($available_styles[$layout['style_id']])) {
        $layout['style_id'] = Styles::factory($layout['theme_name'])->getDefault();
    }
    Registry::set('runtime.layout', $layout);
    return array(INIT_STATUS_OK);
}
Ejemplo n.º 11
0
function fn_paypal_get_checkout_payment_buttons(&$cart, &$cart_products, &$auth, &$checkout_buttons, &$checkout_payments, &$payment_id)
{
    $processor_data = fn_get_processor_data($payment_id);
    if ($processor_data['processor_script'] !== 'paypal_express.php') {
        return;
    }
    $form_url = fn_url('paypal_express.express');
    if (!empty($processor_data) && empty($checkout_buttons[$payment_id]) && Registry::get('runtime.mode') == 'cart') {
        $merchant_id = $processor_data['processor_params']['merchant_id'];
        if (isset($processor_data['processor_params']['in_context']) && $processor_data['processor_params']['in_context'] == 'Y' && $merchant_id && !\Tygh\Embedded::isEnabled()) {
            $environment = $processor_data['processor_params']['mode'] == 'live' ? 'production' : 'sandbox';
            if ($environment == 'sandbox') {
                fn_set_cookie('PPDEBUG', true);
            }
            $checkout_buttons[$payment_id] = '
                <form name="pp_express" id="pp_express_' . $payment_id . '" action="' . $form_url . '" method="post">
                    <input name="payment_id" value="' . $payment_id . '" type="hidden" />
                </form>
                <script type="text/javascript">
                    (function(_, $) {
                        if (window.paypalCheckoutReady) {
                            $.redirect(_.current_url);
                        } else {
                            window.paypalCheckoutReady = function() {
                                paypal.checkout.setup("' . $merchant_id . '", {
                                    environment: "' . $environment . '",
                                    container: "pp_express_' . $payment_id . '",
                                    click: function(e) {
                                        e.preventDefault();
                                        paypal.checkout.initXO();

                                        $.ceAjax("request", "' . $form_url . '", {
                                            method: "post",
                                            data: {
                                                in_context: 1,
                                                payment_id: "' . $payment_id . '"
                                            },
                                            callback: function(response) {
                                                var data = JSON.parse(response.text);
                                                if (data.token) {
                                                    var url = paypal.checkout.urlPrefix + data.token;
                                                    paypal.checkout.startFlow(url);
                                                }
                                                if (data.error) {
                                                    paypal.checkout.closeFlow();
                                                }
                                            }
                                        });
                                    }
                                });
                            };
                        }
                        $.getScript("//www.paypalobjects.com/api/checkout.js");
                    })(Tygh, Tygh.$);
                </script>
            ';
        } else {
            $checkout_buttons[$payment_id] = '
                <form name="pp_express" id="pp_express" action="' . $form_url . '" method="post">
                    <input name="payment_id" value="' . $payment_id . '" type="hidden" />
                    <input src="https://www.paypalobjects.com/webstatic/en_US/i/buttons/checkout-logo-small.png" type="image" />
                </form>
            ';
        }
    }
}
Ejemplo n.º 12
0
 /**
  * Registers block cache
  * @param string $cache_name   Cache name
  * @param array  $block_scheme Block scheme data
  */
 private static function _registerBlockCache($cache_name, $block_scheme)
 {
     if (isset($block_scheme['cache'])) {
         $additional_level = '';
         $default_handlers = fn_get_schema('block_manager', 'block_cache_properties');
         if (isset($block_scheme['cache']['update_handlers']) && is_array($block_scheme['cache']['update_handlers'])) {
             $handlers = $block_scheme['cache']['update_handlers'];
         } else {
             $handlers = array();
         }
         $cookie_data = fn_get_session_data();
         $cookie_data['all'] = $cookie_data;
         $additional_level .= self::_generateAdditionalCacheLevel($block_scheme['cache'], 'request_handlers', $_REQUEST);
         $additional_level .= self::_generateAdditionalCacheLevel($block_scheme['cache'], 'session_handlers', $_SESSION);
         $additional_level .= self::_generateAdditionalCacheLevel($block_scheme['cache'], 'cookie_handlers', $cookie_data);
         $additional_level .= self::_generateAdditionalCacheLevel($block_scheme['cache'], 'auth_handlers', $_SESSION['auth']);
         $additional_level .= '|path=' . Registry::get('config.current_path');
         $additional_level .= Embedded::isEnabled() ? '|embedded' : '';
         $additional_level = !empty($additional_level) ? md5($additional_level) : '';
         $handlers = array_merge($handlers, $default_handlers['update_handlers']);
         $cache_level = isset($block_scheme['cache']['cache_level']) ? $block_scheme['cache']['cache_level'] : Registry::cacheLevel('html_blocks');
         Registry::registerCache($cache_name, $handlers, $cache_level . '__' . $additional_level);
     }
 }