Exemple #1
0
/**
 * Dispathes the execution control to correct controller
 *
 * @return nothing
 */
function fn_dispatch($controller = '', $mode = '', $action = '', $dispatch_extra = '', $area = AREA)
{
    Debugger::checkpoint('After init');
    $auth = $_SESSION['auth'];
    $controller = empty($controller) ? Registry::get('runtime.controller') : $controller;
    $mode = empty($mode) ? Registry::get('runtime.mode') : $mode;
    $action = empty($action) ? Registry::get('runtime.action') : $action;
    $dispatch_extra = empty($dispatch_extra) ? Registry::get('runtime.dispatch_extra') : $dispatch_extra;
    fn_set_hook('before_dispatch', $controller, $mode, $action, $dispatch_extra, $area);
    $view = Registry::get('view');
    $run_controllers = true;
    $external = false;
    $status = CONTROLLER_STATUS_NO_PAGE;
    // CSRF protection
    if (fn_is_csrf_protection_enabled($auth) && !fn_csrf_validate_request(array('server' => $_SERVER, 'request' => $_REQUEST, 'session' => $_SESSION, 'controller' => $controller, 'mode' => $mode, 'action' => $action, 'dispatch_extra' => $dispatch_extra, 'area' => $area, 'auth' => $auth))) {
        fn_set_notification('E', __('error'), __('text_csrf_attack'));
        fn_redirect(fn_url());
    }
    // If $config['http_host'] was different from the domain name, there was redirection to $config['http_host'] value.
    if (strtolower(Registry::get('config.current_host')) != strtolower(REAL_HOST) && $_SERVER['REQUEST_METHOD'] == 'GET' && !defined('CONSOLE')) {
        if (!empty($_SERVER['REDIRECT_URL'])) {
            $qstring = $_SERVER['REDIRECT_URL'];
        } else {
            if (!empty($_SERVER['REQUEST_URI'])) {
                $qstring = $_SERVER['REQUEST_URI'];
            } else {
                $qstring = Registry::get('config.current_url');
            }
        }
        $curent_path = Registry::get('config.current_path');
        if (!empty($curent_path) && strpos($qstring, $curent_path) === 0) {
            $qstring = substr_replace($qstring, '', 0, fn_strlen($curent_path));
        }
        fn_redirect(Registry::get('config.current_location') . $qstring, false, true);
    }
    $upload_max_filesize = Bootstrap::getIniParam('upload_max_filesize');
    $post_max_size = Bootstrap::getIniParam('post_max_size');
    if (!defined('AJAX_REQUEST') && isset($_SERVER['CONTENT_LENGTH']) && ($_SERVER['CONTENT_LENGTH'] > fn_return_bytes($upload_max_filesize) || $_SERVER['CONTENT_LENGTH'] > fn_return_bytes($post_max_size))) {
        $max_size = fn_return_bytes($upload_max_filesize) < fn_return_bytes($post_max_size) ? $upload_max_filesize : $post_max_size;
        fn_set_notification('E', __('error'), __('text_forbidden_uploaded_file_size', array('[size]' => $max_size)));
        fn_redirect($_SERVER['HTTP_REFERER']);
    }
    // If URL contains session ID, remove it
    if (!defined('AJAX_REQUEST') && !empty($_REQUEST[Session::getName()]) && $_SERVER['REQUEST_METHOD'] == 'GET') {
        fn_redirect(fn_query_remove(Registry::get('config.current_url'), Session::getName()));
    }
    // If demo mode is enabled, check permissions FIX ME - why did we need one more user login check?
    if ($area == 'A') {
        if (Registry::get('config.demo_mode') == true) {
            $run_controllers = fn_check_permissions($controller, $mode, 'demo');
            if ($run_controllers == false) {
                fn_set_notification('W', __('demo_mode'), __('demo_mode_content_text'), 'K', 'demo_mode');
                if (defined('AJAX_REQUEST')) {
                    exit;
                }
                fn_delete_notification('changes_saved');
                $status = CONTROLLER_STATUS_REDIRECT;
                $_REQUEST['redirect_url'] = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : fn_url('');
            }
        } else {
            $run_controllers = fn_check_permissions($controller, $mode, 'admin', '', $_REQUEST);
            if ($run_controllers == false) {
                if (defined('AJAX_REQUEST')) {
                    $_info = Debugger::isActive() || fn_is_development() ? ' ' . $controller . '.' . $mode : '';
                    fn_set_notification('W', __('warning'), __('access_denied') . $_info);
                    exit;
                }
                $status = CONTROLLER_STATUS_DENIED;
            }
        }
    }
    if ($_SERVER['REQUEST_METHOD'] != 'POST' && !defined('AJAX_REQUEST')) {
        if ($area == 'A' && empty($_REQUEST['keep_location']) && !defined('CONSOLE')) {
            if (!defined('HTTPS') && Registry::get('settings.Security.secure_admin') == 'Y') {
                fn_redirect(Registry::get('config.https_location') . '/' . Registry::get('config.current_url'));
            } elseif (defined('HTTPS') && Registry::get('settings.Security.secure_admin') != 'Y') {
                fn_redirect(Registry::get('config.http_location') . '/' . Registry::get('config.current_url'));
            }
        } elseif ($area == 'C') {
            $secure_controllers = fn_get_secure_controllers();
            // if we are not on https but controller is secure, redirect to https
            if (!defined('HTTPS') && (Registry::get('settings.Security.secure_storefront') == 'full' || isset($secure_controllers[$controller]) && $secure_controllers[$controller] == 'active')) {
                fn_redirect(Registry::get('config.https_location') . '/' . Registry::get('config.current_url'), false, true);
            }
            // if we are on https and the controller is insecure, redirect to http
            if (defined('HTTPS') && Registry::get('settings.Security.secure_storefront') != 'full' && !isset($secure_controllers[$controller]) && Registry::get('settings.Security.keep_https') != 'Y') {
                fn_redirect(Registry::get('config.http_location') . '/' . Registry::get('config.current_url'), false, true);
            }
        }
    }
    LastView::instance()->prepare($_REQUEST);
    $controllers_cascade = array();
    $controllers_list = array('init');
    if ($run_controllers == true) {
        $controllers_list[] = $controller;
        $controllers_list = array_unique($controllers_list);
    }
    foreach ($controllers_list as $ctrl) {
        $core_controllers = fn_init_core_controllers($ctrl);
        list($addon_controllers) = fn_init_addon_controllers($ctrl);
        if (empty($core_controllers) && empty($addon_controllers)) {
            //$controllers_cascade = array(); // FIXME: controllers_cascade contains INIT. We should not clear initiation code.
            $status = CONTROLLER_STATUS_NO_PAGE;
            $run_controllers = false;
            break;
        }
        if (count($core_controllers) + count($addon_controllers) > 1) {
            throw new DeveloperException('Duplicate controller ' . $controller . var_export(array_merge($core_controllers, $addon_controllers), true));
        }
        $core_pre_controllers = fn_init_core_controllers($ctrl, GET_PRE_CONTROLLERS);
        $core_post_controllers = fn_init_core_controllers($ctrl, GET_POST_CONTROLLERS);
        list($addon_pre_controllers) = fn_init_addon_controllers($ctrl, GET_PRE_CONTROLLERS);
        list($addon_post_controllers, $addons) = fn_init_addon_controllers($ctrl, GET_POST_CONTROLLERS);
        // we put addon post-controller to the top of post-controller cascade if current addon serves this request
        if (count($addon_controllers)) {
            $addon_post_controllers = fn_reorder_post_controllers($addon_post_controllers, $addon_controllers[0]);
        }
        $controllers_cascade = array_merge($controllers_cascade, $addon_pre_controllers, $core_pre_controllers, $core_controllers, $addon_controllers, $core_post_controllers, $addon_post_controllers);
        if (empty($controllers_cascade)) {
            throw new DeveloperException("No controllers for: {$ctrl}");
        }
    }
    if ($mode == 'add') {
        $tpl = 'update.tpl';
    } elseif (strpos($mode, 'add_') === 0) {
        $tpl = str_replace('add_', 'update_', $mode) . '.tpl';
    } else {
        $tpl = $mode . '.tpl';
    }
    $view = Registry::get('view');
    if ($view->templateExists('views/' . $controller . '/' . $tpl)) {
        // try to find template in base views
        $view->assign('content_tpl', 'views/' . $controller . '/' . $tpl);
    } elseif (defined('LOADED_ADDON_PATH') && $view->templateExists('addons/' . LOADED_ADDON_PATH . '/views/' . $controller . '/' . $tpl)) {
        // try to find template in addon views
        $view->assign('content_tpl', 'addons/' . LOADED_ADDON_PATH . '/views/' . $controller . '/' . $tpl);
    } elseif (!empty($addons)) {
        // try to find template in addon views that extend base views
        foreach ($addons as $addon => $_v) {
            if ($view->templateExists('addons/' . $addon . '/views/' . $controller . '/' . $tpl)) {
                $view->assign('content_tpl', 'addons/' . $addon . '/views/' . $controller . '/' . $tpl);
                break;
            }
        }
    }
    /**
     * Performs actions after template assignment and before controller run
     *
     * @param string $controller          controller name
     * @param string $mode                controller mode name
     * @param string $area                current working area
     * @param array  $controllers_cascade list of controllers to run
     */
    fn_set_hook('dispatch_assign_template', $controller, $mode, $area, $controllers_cascade);
    foreach ($controllers_cascade as $item) {
        $_res = fn_run_controller($item, $controller, $mode, $action, $dispatch_extra);
        // 0 - status, 1 - url
        $url = !empty($_res[1]) ? $_res[1] : '';
        $external = !empty($_res[2]) ? $_res[2] : false;
        $permanent = !empty($_res[3]) ? $_res[3] : false;
        // Status could be changed only if we allow to run controllers despite of init controller
        if ($run_controllers == true) {
            $status = !empty($_res[0]) ? $_res[0] : CONTROLLER_STATUS_OK;
        }
        if ($status == CONTROLLER_STATUS_OK && !empty($url)) {
            $redirect_url = $url;
        } elseif ($status == CONTROLLER_STATUS_REDIRECT && !empty($url)) {
            $redirect_url = $url;
            break;
        } elseif ($status == CONTROLLER_STATUS_DENIED || $status == CONTROLLER_STATUS_NO_PAGE) {
            break;
        }
    }
    LastView::instance()->init($_REQUEST);
    // In console mode, just stop here
    if (defined('CONSOLE')) {
        $notifications = fn_get_notifications();
        $exit_code = 0;
        foreach ($notifications as $n) {
            fn_echo('[' . $n['title'] . '] ' . $n['message'] . "\n");
            if ($n['type'] == 'E') {
                $exit_code = 1;
            }
        }
        exit($exit_code);
    }
    if (!empty($auth['this_login']) && Registry::ifGet($auth['this_login'], 'N') === 'Y') {
        fn_set_notification('E', __('error'), __(ACCOUNT_TYPE . LOGIN_STATUS_USER_DISABLED));
        $status = CONTROLLER_STATUS_DENIED;
    }
    // [Block manager]
    // block manager is disabled for vendors.
    if (!(fn_allowed_for('MULTIVENDOR') && Registry::get('runtime.company_id') || fn_allowed_for('ULTIMATE') && !Registry::get('runtime.company_id'))) {
        if (fn_check_permissions('block_manager', 'manage', 'admin')) {
            $dynamic_object = SchemesManager::getDynamicObject($_REQUEST['dispatch'], $area, $_REQUEST);
            if (!empty($dynamic_object)) {
                if ($area == 'A' && Registry::get('runtime.mode') != 'add' && !empty($_REQUEST[$dynamic_object['key']])) {
                    $object_id = $_REQUEST[$dynamic_object['key']];
                    $location = Location::instance()->get($dynamic_object['customer_dispatch'], $dynamic_object, CART_LANGUAGE);
                    if (!empty($location) && $location['is_default'] != 1) {
                        $params = array('dynamic_object' => array('object_type' => $dynamic_object['object_type'], 'object_id' => $object_id), $dynamic_object['key'] => $object_id, 'manage_url' => Registry::get('config.current_url'));
                        Registry::set('navigation.tabs.blocks', array('title' => __('layouts'), 'href' => 'block_manager.manage_in_tab?' . http_build_query($params), 'ajax' => true));
                    }
                }
            }
        }
    }
    // [/Block manager]
    // Redirect if controller returned successful/redirect status only
    if (in_array($status, array(CONTROLLER_STATUS_OK, CONTROLLER_STATUS_REDIRECT)) && !empty($_REQUEST['redirect_url']) && !$external) {
        $redirect_url = $_REQUEST['redirect_url'];
    }
    // If controller returns "Redirect" status, check if redirect url exists
    if ($status == CONTROLLER_STATUS_REDIRECT && empty($redirect_url)) {
        $status = CONTROLLER_STATUS_NO_PAGE;
    }
    // In backend show "changes saved" notification
    if ($area == 'A' && $_SERVER['REQUEST_METHOD'] == 'POST' && in_array($status, array(CONTROLLER_STATUS_OK, CONTROLLER_STATUS_REDIRECT))) {
        if (strpos($mode, 'update') !== false && $mode != 'update_status' && $mode != 'update_mode' && !fn_notification_exists('extra', 'demo_mode') && !fn_notification_exists('type', 'E')) {
            fn_set_notification('N', __('notice'), __('text_changes_saved'), 'I', 'changes_saved');
        }
    }
    // Attach params and redirect if needed
    if (in_array($status, array(CONTROLLER_STATUS_OK, CONTROLLER_STATUS_REDIRECT)) && !empty($redirect_url)) {
        if (!isset($_REQUEST['return_to_list'])) {
            $params = array('page', 'selected_section', 'active_tab');
            $url_params = array();
            foreach ($params as $param) {
                if (!empty($_REQUEST[$param])) {
                    $url_params[$param] = $_REQUEST[$param];
                }
            }
            if (!empty($url_params)) {
                $redirect_url = fn_link_attach($redirect_url, http_build_query($url_params));
            }
        }
        if (!isset($external)) {
            $external = false;
        }
        if (!isset($permanent)) {
            $permanent = false;
        }
        fn_redirect($redirect_url, $external, $permanent);
    }
    if (!$view->getTemplateVars('content_tpl') && $status == CONTROLLER_STATUS_OK) {
        // FIXME
        $status = CONTROLLER_STATUS_NO_PAGE;
    }
    if ($status != CONTROLLER_STATUS_OK) {
        if ($status == CONTROLLER_STATUS_NO_PAGE) {
            if ($area == 'A' && empty($auth['user_id'])) {
                // If admin is not logged in redirect to login page from not found page
                fn_set_notification('W', __('page_not_found'), __('page_not_found_text'));
                fn_redirect("auth.login_form");
            }
            header(' ', true, 404);
        }
        $view->assign('exception_status', $status);
        if ($area == 'A') {
            $view->assign('content_tpl', 'exception.tpl');
            // for backend only
        }
        if ($status == CONTROLLER_STATUS_DENIED) {
            $view->assign('page_title', __('access_denied'));
        } elseif ($status == CONTROLLER_STATUS_NO_PAGE) {
            $view->assign('page_title', __('page_not_found'));
        }
    }
    fn_set_hook('dispatch_before_display');
    Debugger::checkpoint('Before TPL');
    // Pass current URL to ajax response only if we render whole page
    if (defined('AJAX_REQUEST') && Registry::get('runtime.root_template') == 'index.tpl') {
        Registry::get('ajax')->assign('current_url', fn_url(Registry::get('config.current_url'), $area, 'current'));
    }
    Registry::get('view')->display(Registry::get('runtime.root_template'));
    Debugger::checkpoint('After TPL');
    Debugger::display();
    fn_set_hook('complete');
    if (defined('AJAX_REQUEST')) {
        // HHVM workaround. Destroy Ajax object manually if it has been created.
        $ajax = Registry::get('ajax');
        $ajax = null;
    }
    exit;
    // stop execution
}
    function content_55dc759d4d9594_75538719($_smarty_tpl)
    {
        if (!is_callable('smarty_function_set_id')) {
            include '/var/www/html/market/app/functions/smarty_plugins/function.set_id.php';
        }
        if ($_smarty_tpl->tpl_vars['runtime']->value['customization_mode']['design'] == "Y" && @constant('AREA') == "C") {
            $_smarty_tpl->_capture_stack[0][] = array("template_content", null, null);
            ob_start();
            ?>
<div class="cm-notification-container notification-container">
<?php 
            if (!defined("AJAX_REQUEST")) {
                $_smarty_tpl->tpl_vars["message"] = new Smarty_Variable();
                $_smarty_tpl->tpl_vars["message"]->_loop = false;
                $_smarty_tpl->tpl_vars["key"] = new Smarty_Variable();
                $_from = fn_get_notifications('');
                if (!is_array($_from) && !is_object($_from)) {
                    settype($_from, 'array');
                }
                foreach ($_from as $_smarty_tpl->tpl_vars["message"]->key => $_smarty_tpl->tpl_vars["message"]->value) {
                    $_smarty_tpl->tpl_vars["message"]->_loop = true;
                    $_smarty_tpl->tpl_vars["key"]->value = $_smarty_tpl->tpl_vars["message"]->key;
                    if ($_smarty_tpl->tpl_vars['message']->value['type'] == "I") {
                        ?>
    <div class="ui-widget-overlay" data-ca-notification-key="<?php 
                        echo htmlspecialchars($_smarty_tpl->tpl_vars['key']->value, ENT_QUOTES, 'UTF-8');
                        ?>
"></div>
    <div class="cm-notification-content cm-notification-content-extended notification-content-extended<?php 
                        if ($_smarty_tpl->tpl_vars['message']->value['message_state'] == "I") {
                            ?>
 cm-auto-hide<?php 
                        }
                        ?>
" data-ca-notification-key="<?php 
                        echo htmlspecialchars($_smarty_tpl->tpl_vars['key']->value, ENT_QUOTES, 'UTF-8');
                        ?>
">
        <h1><?php 
                        echo htmlspecialchars($_smarty_tpl->tpl_vars['message']->value['title'], ENT_QUOTES, 'UTF-8');
                        ?>
<span class="cm-notification-close <?php 
                        if ($_smarty_tpl->tpl_vars['message']->value['message_state'] == "S") {
                            ?>
 cm-notification-close-ajax<?php 
                        }
                        ?>
"></span></h1>
        <div class="notification-body-extended">
            <?php 
                        echo $_smarty_tpl->tpl_vars['message']->value['message'];
                        ?>

        </div>
    </div>
<?php 
                    } elseif ($_smarty_tpl->tpl_vars['message']->value['type'] == "O") {
                        ?>
    <div class="cm-notification-content notification-content alert-error" data-ca-notification-key="<?php 
                        echo htmlspecialchars($_smarty_tpl->tpl_vars['key']->value, ENT_QUOTES, 'UTF-8');
                        ?>
">
        <button type="button" class="close cm-notification-close" <?php 
                        if ($_smarty_tpl->tpl_vars['message']->value['message_state'] != "S") {
                            ?>
data-dismiss="alert"<?php 
                        }
                        ?>
>×</button>
        <?php 
                        echo $_smarty_tpl->tpl_vars['message']->value['message'];
                        ?>

    </div>
<?php 
                    } else {
                        ?>
    <div class="cm-notification-content notification-content<?php 
                        if ($_smarty_tpl->tpl_vars['message']->value['message_state'] == "I") {
                            ?>
 cm-auto-hide<?php 
                        }
                        ?>
 <?php 
                        if ($_smarty_tpl->tpl_vars['message']->value['type'] == "N") {
                            ?>
alert-success<?php 
                        } elseif ($_smarty_tpl->tpl_vars['message']->value['type'] == "W") {
                            ?>
alert-warning<?php 
                        } else {
                            ?>
alert-error<?php 
                        }
                        ?>
" data-ca-notification-key="<?php 
                        echo htmlspecialchars($_smarty_tpl->tpl_vars['key']->value, ENT_QUOTES, 'UTF-8');
                        ?>
">
        <button type="button" class="close cm-notification-close <?php 
                        if ($_smarty_tpl->tpl_vars['message']->value['message_state'] == "S") {
                            ?>
 cm-notification-close-ajax<?php 
                        }
                        ?>
" <?php 
                        if ($_smarty_tpl->tpl_vars['message']->value['message_state'] != "S") {
                            ?>
data-dismiss="alert"<?php 
                        }
                        ?>
>×</button>
        <strong><?php 
                        echo htmlspecialchars($_smarty_tpl->tpl_vars['message']->value['title'], ENT_QUOTES, 'UTF-8');
                        ?>
</strong>
        <?php 
                        echo $_smarty_tpl->tpl_vars['message']->value['message'];
                        ?>

    </div>
<?php 
                    }
                }
            }
            ?>
</div><?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();
            }
            if (trim(Smarty::$_smarty_vars['capture']['template_content'])) {
                if ($_smarty_tpl->tpl_vars['auth']->value['area'] == "A") {
                    ?>
<span class="cm-template-box template-box" data-ca-te-template="common/notification.tpl" id="<?php 
                    echo smarty_function_set_id(array('name' => "common/notification.tpl"), $_smarty_tpl);
                    ?>
"><div class="cm-template-icon icon-edit ty-icon-edit hidden"></div><?php 
                    echo Smarty::$_smarty_vars['capture']['template_content'];
                    ?>
<!--[/tpl_id]--></span><?php 
                } else {
                    echo Smarty::$_smarty_vars['capture']['template_content'];
                }
            }
        } else {
            ?>
<div class="cm-notification-container notification-container">
<?php 
            if (!defined("AJAX_REQUEST")) {
                $_smarty_tpl->tpl_vars["message"] = new Smarty_Variable();
                $_smarty_tpl->tpl_vars["message"]->_loop = false;
                $_smarty_tpl->tpl_vars["key"] = new Smarty_Variable();
                $_from = fn_get_notifications('');
                if (!is_array($_from) && !is_object($_from)) {
                    settype($_from, 'array');
                }
                foreach ($_from as $_smarty_tpl->tpl_vars["message"]->key => $_smarty_tpl->tpl_vars["message"]->value) {
                    $_smarty_tpl->tpl_vars["message"]->_loop = true;
                    $_smarty_tpl->tpl_vars["key"]->value = $_smarty_tpl->tpl_vars["message"]->key;
                    if ($_smarty_tpl->tpl_vars['message']->value['type'] == "I") {
                        ?>
    <div class="ui-widget-overlay" data-ca-notification-key="<?php 
                        echo htmlspecialchars($_smarty_tpl->tpl_vars['key']->value, ENT_QUOTES, 'UTF-8');
                        ?>
"></div>
    <div class="cm-notification-content cm-notification-content-extended notification-content-extended<?php 
                        if ($_smarty_tpl->tpl_vars['message']->value['message_state'] == "I") {
                            ?>
 cm-auto-hide<?php 
                        }
                        ?>
" data-ca-notification-key="<?php 
                        echo htmlspecialchars($_smarty_tpl->tpl_vars['key']->value, ENT_QUOTES, 'UTF-8');
                        ?>
">
        <h1><?php 
                        echo htmlspecialchars($_smarty_tpl->tpl_vars['message']->value['title'], ENT_QUOTES, 'UTF-8');
                        ?>
<span class="cm-notification-close <?php 
                        if ($_smarty_tpl->tpl_vars['message']->value['message_state'] == "S") {
                            ?>
 cm-notification-close-ajax<?php 
                        }
                        ?>
"></span></h1>
        <div class="notification-body-extended">
            <?php 
                        echo $_smarty_tpl->tpl_vars['message']->value['message'];
                        ?>

        </div>
    </div>
<?php 
                    } elseif ($_smarty_tpl->tpl_vars['message']->value['type'] == "O") {
                        ?>
    <div class="cm-notification-content notification-content alert-error" data-ca-notification-key="<?php 
                        echo htmlspecialchars($_smarty_tpl->tpl_vars['key']->value, ENT_QUOTES, 'UTF-8');
                        ?>
">
        <button type="button" class="close cm-notification-close" <?php 
                        if ($_smarty_tpl->tpl_vars['message']->value['message_state'] != "S") {
                            ?>
data-dismiss="alert"<?php 
                        }
                        ?>
>×</button>
        <?php 
                        echo $_smarty_tpl->tpl_vars['message']->value['message'];
                        ?>

    </div>
<?php 
                    } else {
                        ?>
    <div class="cm-notification-content notification-content<?php 
                        if ($_smarty_tpl->tpl_vars['message']->value['message_state'] == "I") {
                            ?>
 cm-auto-hide<?php 
                        }
                        ?>
 <?php 
                        if ($_smarty_tpl->tpl_vars['message']->value['type'] == "N") {
                            ?>
alert-success<?php 
                        } elseif ($_smarty_tpl->tpl_vars['message']->value['type'] == "W") {
                            ?>
alert-warning<?php 
                        } else {
                            ?>
alert-error<?php 
                        }
                        ?>
" data-ca-notification-key="<?php 
                        echo htmlspecialchars($_smarty_tpl->tpl_vars['key']->value, ENT_QUOTES, 'UTF-8');
                        ?>
">
        <button type="button" class="close cm-notification-close <?php 
                        if ($_smarty_tpl->tpl_vars['message']->value['message_state'] == "S") {
                            ?>
 cm-notification-close-ajax<?php 
                        }
                        ?>
" <?php 
                        if ($_smarty_tpl->tpl_vars['message']->value['message_state'] != "S") {
                            ?>
data-dismiss="alert"<?php 
                        }
                        ?>
>×</button>
        <strong><?php 
                        echo htmlspecialchars($_smarty_tpl->tpl_vars['message']->value['title'], ENT_QUOTES, 'UTF-8');
                        ?>
</strong>
        <?php 
                        echo $_smarty_tpl->tpl_vars['message']->value['message'];
                        ?>

    </div>
<?php 
                    }
                }
            }
            ?>
</div><?php 
        }
    }
Exemple #3
0
    public function destruct($content = '')
    {
        static $called = false;
        if ($called == false && $this->_internal_request) {
            $called = true;
            $text = $this->_request_type != self::REQUEST_COMET ? ob_get_clean() : '';
            if (empty($text) && !empty($content)) {
                $text = $content;
            }
            if (!empty($this->result_ids)) {
                $result_ids = array();
                // get the matching ids
                foreach ($this->result_ids as $r_id) {
                    if (strpos($r_id, '*')) {
                        $clear_id = str_replace('*', '\\w+?', $r_id);
                        preg_match_all('/<[^>]*?id=(?:\'|")(' . $clear_id . '\\w*?)(?:\'|")[^>]*?>/isS', $text, $ids);
                        if (!empty($ids[1])) {
                            foreach ($ids[1] as $r_id2) {
                                $result_ids[] = $r_id2;
                            }
                        }
                    } else {
                        $result_ids[] = $r_id;
                    }
                }
                foreach ($result_ids as $r_id) {
                    if (strpos($text, ' id="' . $r_id . '">') !== false) {
                        $start = strpos($text, ' id="' . $r_id . '">') + strlen(' id="' . $r_id . '">');
                        $end = strpos($text, '<!--' . $r_id . '--></');
                        $this->assignHtml($r_id, substr($text, $start, $end - $start));
                        // Assume that all data should be put to div with this ID
                    } elseif ($this->_skip_result_ids_check == true) {
                        $this->assignHtml($r_id, $text);
                    }
                }
                if ($this->full_render && preg_match('/<title>(.*?)<\\/title>/s', $text, $m)) {
                    $this->assign('title', html_entity_decode($m[1], ENT_QUOTES));
                }
                // Fix for payment processor form, should be removed after payments refactoring
                if (Embedded::isEnabled() && empty($this->_result['html']) && $this->_skip_result_ids_check == false && !empty($text)) {
                    foreach ($this->result_ids as $r_id) {
                        $text .= '<script type="text/javascript">if (document.process) { document.process.target="_parent"; document.process.submit(); }</script>';
                        $this->assignHtml($r_id, $text);
                        break;
                    }
                }
                $text = '';
            }
            if (empty($this->_result['non_ajax_notifications'])) {
                $this->assign('notifications', fn_get_notifications());
            }
            if (Embedded::isEnabled()) {
                $this->assign('session_data', array('name' => Session::getName(), 'id' => Session::getId()));
            }
            if (!empty($this->anchor)) {
                $this->assign('anchor', $this->anchor);
            }
            // we call session saving directly
            session_write_close();
            // Prepare response
            $response = $this->_result;
            if (fn_string_not_empty($text)) {
                $response['text'] = trim($text);
            }
            $response = json_encode($response, JSON_UNESCAPED_UNICODE);
            if (!headers_sent()) {
                header(' ', true, 200);
                // force 200 header, because we still need to return content
                if (Embedded::isEnabled() || $this->_request_type == self::REQUEST_JSONP_POST) {
                    header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');
                    // for IE cors
                }
            }
            if ($this->_request_type == self::REQUEST_XML) {
                // Return json object
                header('Content-type: ' . $this->_content_type . '; charset=' . CHARSET);
            } elseif ($this->_request_type == self::REQUEST_JSONP) {
                // Return jsonp object
                header('Content-type: ' . $this->_content_type . '; charset=' . CHARSET);
                $response = $this->callback . '(' . $response . ');';
            } elseif ($this->_request_type == self::REQUEST_JSONP_POST) {
                // Return jsonp object
                header("X-Frame-Options: ", true);
                $response = '<script type="text/javascript" src="' . Registry::get('config.current_location') . '/js/lib/jquery/jquery.min.js' . '"></script>
                             <script type="text/javascript" src="' . Registry::get('config.current_location') . '/js/lib/postmessage/jquery.ba-postmessage.js' . '"></script>
                             <script type="text/javascript">

                                var Tygh = {};
                                Tygh.$ = jQuery.noConflict(true);
                             </script>
                             <script type="text/javascript">Tygh.$.postMessage(
                                "' . fn_js_escape($response) . '",\'' . Embedded::getUrl() . '\');</script>';
            } else {
                // Return html textarea object
                $response = '<textarea>' . fn_html_escape($response) . '</textarea>';
            }
            fn_echo($response);
        }
    }
    function content_55ccdf863d9d98_15684438($_smarty_tpl)
    {
        if (!defined("AJAX_REQUEST")) {
            ?>

<?php 
            $_smarty_tpl->_capture_stack[0][] = array("notification_content", null, null);
            ob_start();
            $_smarty_tpl->tpl_vars["message"] = new Smarty_Variable();
            $_smarty_tpl->tpl_vars["message"]->_loop = false;
            $_smarty_tpl->tpl_vars["key"] = new Smarty_Variable();
            $_from = fn_get_notifications('');
            if (!is_array($_from) && !is_object($_from)) {
                settype($_from, 'array');
            }
            foreach ($_from as $_smarty_tpl->tpl_vars["message"]->key => $_smarty_tpl->tpl_vars["message"]->value) {
                $_smarty_tpl->tpl_vars["message"]->_loop = true;
                $_smarty_tpl->tpl_vars["key"]->value = $_smarty_tpl->tpl_vars["message"]->key;
                if ($_smarty_tpl->tpl_vars['message']->value['type'] == "I") {
                    ?>
<div class="cm-notification-content cm-notification-content-extended notification-content-extended <?php 
                    if ($_smarty_tpl->tpl_vars['message']->value['message_state'] == "I") {
                        ?>
 cm-auto-hide<?php 
                    }
                    ?>
" data-ca-notification-key="<?php 
                    echo htmlspecialchars($_smarty_tpl->tpl_vars['key']->value, ENT_QUOTES, 'UTF-8');
                    ?>
"><h1><?php 
                    echo htmlspecialchars($_smarty_tpl->tpl_vars['message']->value['title'], ENT_QUOTES, 'UTF-8');
                    ?>
<span class="cm-notification-close close <?php 
                    if ($_smarty_tpl->tpl_vars['message']->value['message_state'] == "S") {
                        ?>
 cm-notification-close-ajax<?php 
                    }
                    ?>
"></span></h1><div class="notification-body-extended"><?php 
                    echo $_smarty_tpl->tpl_vars['message']->value['message'];
                    ?>
</div></div><?php 
                } else {
                    ?>
<div class="alert cm-notification-content<?php 
                    if ($_smarty_tpl->tpl_vars['message']->value['type'] == "N") {
                        ?>
 alert-success<?php 
                    } elseif ($_smarty_tpl->tpl_vars['message']->value['type'] == "W") {
                        ?>
 alert-warning<?php 
                    } elseif ($_smarty_tpl->tpl_vars['message']->value['type'] == "E") {
                        ?>
 alert-error<?php 
                    } elseif ($_smarty_tpl->tpl_vars['message']->value['type'] == "S") {
                        ?>
 alert-info<?php 
                    }
                    ?>
 <?php 
                    if ($_smarty_tpl->tpl_vars['message']->value['message_state'] == "I") {
                        ?>
 cm-auto-hide<?php 
                    }
                    ?>
" id="notification_<?php 
                    echo htmlspecialchars($_smarty_tpl->tpl_vars['key']->value, ENT_QUOTES, 'UTF-8');
                    ?>
" data-ca-notification-key="<?php 
                    echo htmlspecialchars($_smarty_tpl->tpl_vars['key']->value, ENT_QUOTES, 'UTF-8');
                    ?>
"><button type="button" class="close cm-notification-close<?php 
                    if ($_smarty_tpl->tpl_vars['message']->value['message_state'] == "S") {
                        ?>
 cm-notification-close-ajax<?php 
                    }
                    ?>
" <?php 
                    if ($_smarty_tpl->tpl_vars['message']->value['message_state'] != "S") {
                        ?>
data-dismiss="alert"<?php 
                    }
                    ?>
>×</button><strong><?php 
                    echo htmlspecialchars($_smarty_tpl->tpl_vars['message']->value['title'], ENT_QUOTES, 'UTF-8');
                    ?>
</strong><?php 
                    echo $_smarty_tpl->tpl_vars['message']->value['message'];
                    ?>
</div><?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();
            }
            ?>

<?php 
            if ($_smarty_tpl->tpl_vars['view_mode']->value == "simple") {
                ?>
    <?php 
                echo Smarty::$_smarty_vars['capture']['notification_content'];
                ?>

<?php 
            }
            ?>

<div class="cm-notification-container alert-wrap <?php 
            if ($_smarty_tpl->tpl_vars['view_mode']->value == "simple") {
                ?>
notification-container-top<?php 
            }
            ?>
">
    <?php 
            if ($_smarty_tpl->tpl_vars['view_mode']->value != "simple") {
                ?>
        <?php 
                echo Smarty::$_smarty_vars['capture']['notification_content'];
                ?>

    <?php 
            }
            ?>
</div>

<?php 
        }
    }
Exemple #5
0
function fn_twg_set_internal_errors(&$response, $error_code)
{
    $notifications = fn_get_notifications();
    if (empty($notifications)) {
        return false;
    }
    $err_counter = 1;
    foreach ($notifications as $n) {
        if ($n['type'] != 'N') {
            $response->addError($error_code . $err_counter, $n['message']);
            $err_counter++;
        }
    }
    if ($err_counter > 1) {
        return true;
    }
    return false;
}
 public function respond($data = array(), $meta = array())
 {
     if (empty($meta['notifications'])) {
         $meta['notifications'] = array();
     }
     $meta['notifications'] = array_merge($meta['notifications'], fn_get_notifications());
     echo $this->prepareData($data, $meta);
     die;
 }
Exemple #7
0
 /**
  * Destructor: cache output and display valid javascript code
  */
 function __destruct()
 {
     static $called = false;
     if ($called == false && !defined('AJAX_REDIRECT')) {
         $called = true;
         $text = ob_get_clean();
         if (!empty($this->result_ids)) {
             foreach ($this->result_ids as $r_id) {
                 if (strpos($text, ' id="' . $r_id . '">') !== false) {
                     $start = strpos($text, ' id="' . $r_id . '">') + strlen(' id="' . $r_id . '">');
                     $end = strpos($text, '<!--' . $r_id . '--></');
                     $this->assign_html($r_id, substr($text, $start, $end - $start));
                 }
             }
             $text = '';
         }
         $this->assign('notifications', fn_get_notifications());
         // we call session saving directly
         session_write_close();
         if ($this->request_type == self::REQUEST_XML) {
             header('Content-type: ' . $this->content_type);
             // Return json object
             echo '{text: ' . $this->php2js(trim($text)) . ', data : ' . $this->php2js($this->_result) . '}';
         } else {
             // Return html textarea object
             echo '<textarea>' . fn_html_escape('{text: ' . $this->php2js(trim($text)) . ', data : ' . $this->php2js($this->_result) . '}') . '</textarea>';
         }
     }
 }
 public function returnResponse($xml_root_node = 'data')
 {
     $this->addPaymentNotifications();
     $notifications = fn_get_notifications();
     // Clear all the user notifications
     $_SESSION['notifications'] = array();
     $this->setMeta(empty($notifications) ? array() : array_values($notifications), 'notifications');
     $this->setMeta(TwigmoConnector::getAccessID(), 'access_id');
     $this->setMeta(TWIGMO_VERSION, 'twigmo_version');
     $this->setMeta(PRODUCT_VERSION, 'cart_version');
     $this->setMeta(PRODUCT_EDITION, 'cart_edition');
     $this->setMeta($this->getPageUrl($_REQUEST), 'page_url');
     $doc = $this->getAsDoc($this->format, $xml_root_node);
     self::showResponse($doc, $this->format);
 }
Exemple #9
0
            $response->setData($order);
            $response->returnResponse('order');
        } elseif ($object == 'products') {
            $product = fn_twg_get_api_product_data($_REQUEST['id'], $lang_code);
            if (empty($product)) {
                $response->addError('ERROR_OBJECT_WAS_NOT_FOUND', str_replace('[object]', $object, __('twgadmin_object_was_not_found')));
                $response->returnResponse();
            }
            $response->setData($product);
            $response->returnResponse('product');
        } elseif ($object == 'users') {
            if (fn_allowed_for('ULTIMATE')) {
                $controller = 'profiles';
                Registry::set('runtime.controller', 'profiles');
                if (!fn_ult_check_store_permission(array('user_id' => $_REQUEST['id']), $controller)) {
                    $notification = reset(fn_get_notifications());
                    $response->addError('ERROR_OBJECT_WAS_NOT_FOUND', $notification['message']);
                    $response->returnResponse();
                }
            }
            $user_data = fn_twg_get_user_info($_REQUEST['id']);
            $response->setData($user_data);
            $response->returnResponse();
        }
    }
}
function fn_twg_get_logs($params = array())
{
    $items_per_page = TWG_RESPONSE_ITEMS_LIMIT;
    $page = empty($params['page']) ? 1 : $params['page'];
    $condition = db_quote(" WHERE type IN('users',  'products',  'orders') AND action != 'session'");
Exemple #10
0
 /**
  * Sends request
  *
  * Method does not return result. It's exit from script.
  */
 public function send()
 {
     if (fn_notification_exists('extra', 'company_access_denied')) {
         $this->status = Response::STATUS_FORBIDDEN;
     } elseif (fn_notification_exists('extra', '404')) {
         $this->status = Response::STATUS_NOT_FOUND;
     }
     if ($this->status == self::STATUS_UNAUTHORIZED) {
         header('WWW-Authenticate: Basic realm="User email/API key"');
     }
     $this->sendStatusCode($this->status);
     if ($this->status == self::STATUS_NO_CONTENT) {
         exit;
     }
     header('Content-type: ' . $this->content_type);
     if (!self::isSuccessStatus($this->status)) {
         $messages = array();
         if (is_array($this->body)) {
             if (!empty($this->body['message'])) {
                 $messages = array($this->body['message']);
             } else {
                 $messages = $this->body;
             }
         } elseif (!empty($this->body)) {
             $messages = array($this->body);
         }
         $this->body = array();
         $codes = self::getAvailableCodes();
         $this->body['message'] = $codes[$this->status];
         $notifications = fn_get_notifications();
         foreach ($notifications as $notice) {
             if ($notice['type'] == 'E') {
                 $messages[] = $notice['message'];
             }
         }
         foreach ($notifications as $notice) {
             if ($notice['type'] == 'W') {
                 $messages[] = $notice['message'];
             }
         }
         if (!empty($messages)) {
             $this->body['message'] .= ': ' . implode('. ', $messages);
         }
         $this->body['status'] = $this->status;
     }
     $body = FormatManager::instance()->encode($this->body, $this->content_type);
     echo $body;
     exit;
 }