Ejemplo n.º 1
0
 /**
  * Loads location data, containers, grids and blocks
  *
  * @param string $dispatch       URL dispatch (controller.mode.action)
  * @param string $area           Area ('A' for admin or 'C' for custom
  * @param array  $dynamic_object
  * @param int    $location_id
  * @param string $lang_code      2 letters language code
  */
 public function __construct($dispatch, $area, $dynamic_object = array(), $location_id = 0, $lang_code = DESCR_SL)
 {
     Debugger::checkpoint('Start render location');
     // Try to get location for this dispatch
     if ($location_id > 0) {
         $this->_location = Location::instance()->getById($location_id, $lang_code);
     } else {
         $this->_location = Location::instance()->get($dispatch, $dynamic_object, $lang_code);
     }
     $this->_area = $area;
     if (!empty($this->_location)) {
         if (isset($dynamic_object['object_id']) && $dynamic_object['object_id'] > 0) {
             $this->_containers = Container::getListByArea($this->_location['location_id'], 'C');
         } else {
             $this->_containers = Container::getListByArea($this->_location['location_id'], $this->_area);
         }
         $this->_grids = Grid::getList(array('container_ids' => Container::getIds($this->_containers)));
         $blocks = Block::instance()->getList(array('?:bm_snapping.*', '?:bm_blocks.*', '?:bm_blocks_descriptions.*'), Grid::getIds($this->_grids), $dynamic_object, null, null, $lang_code);
         $this->_blocks = $blocks;
         $this->_view = Registry::get('view');
         $this->_theme = self::_getThemePath($this->_area);
         $this->_dynamic_object_scheme = SchemesManager::getDynamicObject($this->_location['dispatch'], 'C');
     }
 }
Ejemplo n.º 2
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
}
Ejemplo n.º 3
0
function fn_get_selected_location($params)
{
    if (isset($params['selected_location']) && !empty($params['selected_location'])) {
        $selected_location = Location::instance()->getById($params['selected_location'], DESCR_SL);
    } else {
        $selected_location = Location::instance()->getDefault(DESCR_SL);
    }
    return $selected_location;
}
Ejemplo n.º 4
0
 /**
  * Copy all layout data from one layout to another by ID
  * @param  integer $from_layout_id source layout ID
  * @param  integer $to_layout_id   target layout ID
  * @return boolean true on success, false - otherwise
  */
 public function copyById($from_layout_id, $to_layout_id)
 {
     $from_layout = $this->get($from_layout_id);
     if (empty($from_layout)) {
         return false;
     }
     $object_ids = array();
     $location = Location::instance($from_layout_id)->copy($to_layout_id);
     $target_company_id = 0;
     if (fn_allowed_for('ULTIMATE')) {
         $target_company_id = db_get_field("SELECT company_id FROM ?:bm_layouts WHERE layout_id = ?i", $to_layout_id);
     }
     // Copy logos
     $types = fn_get_logo_types();
     foreach ($types as $type => $data) {
         if (!empty($data['for_layout'])) {
             $object_ids[$type] = fn_create_logo(array('type' => $type, 'layout_id' => $to_layout_id), $target_company_id);
         }
     }
     $logo_ids = db_get_hash_single_array("SELECT logo_id, type FROM ?:logos WHERE layout_id = ?i AND type IN (?a)", array('type', 'logo_id'), $from_layout_id, array_keys($object_ids));
     foreach ($logo_ids as $type => $logo_id) {
         fn_clone_image_pairs($object_ids[$type], $logo_id, 'logos');
     }
     return true;
 }
Ejemplo n.º 5
0
/**
 * Uninstalles addon
 *
 * @param string $addon_name Addon name to be uninstalled
 * @param bool $show_message If defined as true, additionally show notification
 * @return bool True if addons uninstalled successfully, false otherwise
 */
function fn_uninstall_addon($addon_name, $show_message = true)
{
    $addon_scheme = SchemesManager::getScheme($addon_name);
    if ($addon_scheme != false) {
        // Unmanaged addons can be uninstalled via console only
        if ($addon_scheme->getUnmanaged() && !defined('CONSOLE')) {
            return false;
        }
        // Check dependencies
        $dependencies = SchemesManager::getUninstallDependencies($addon_name);
        if (!empty($dependencies)) {
            fn_set_notification('W', __('warning'), __('text_addon_uninstall_dependencies', array('[addons]' => implode(',', $dependencies))));
            return false;
        }
        // Execute custom functions for uninstall
        $addon_scheme->callCustomFunctions('uninstall');
        $addon_description = db_get_field("SELECT name FROM ?:addon_descriptions WHERE addon = ?s and lang_code = ?s", $addon_name, CART_LANGUAGE);
        // Delete options
        db_query("DELETE FROM ?:addons WHERE addon = ?s", $addon_name);
        db_query("DELETE FROM ?:addon_descriptions WHERE addon = ?s", $addon_name);
        // Delete settings
        $section = Settings::instance()->getSectionByName($addon_name, Settings::ADDON_SECTION);
        if (isset($section['section_id'])) {
            Settings::instance()->removeSection($section['section_id']);
        }
        // Delete language variables
        $addon_scheme->uninstallLanguageValues();
        // Revert database structure
        $addon_scheme->processQueries('uninstall', Registry::get('config.dir.addons') . $addon_name);
        // Remove product tabs
        ProductTabs::instance()->deleteAddonTabs($addon_name);
        fn_uninstall_addon_templates(fn_basename($addon_name));
        if (file_exists(Registry::get('config.dir.addons') . $addon_name . '/layouts.xml')) {
            $xml = simplexml_load_file(Registry::get('config.dir.addons') . $addon_name . '/layouts.xml', '\\Tygh\\ExSimpleXmlElement', LIBXML_NOCDATA);
            foreach ($xml->location as $location) {
                if (fn_allowed_for('ULTIMATE')) {
                    foreach (fn_get_all_companies_ids() as $company) {
                        $layouts = Layout::instance($company)->getList();
                        foreach ($layouts as $layout_id => $layout) {
                            Location::instance($layout_id)->removeByDispatch((string) $location['dispatch']);
                        }
                    }
                } else {
                    $layouts = Layout::instance()->getList();
                    foreach ($layouts as $layout_id => $layout) {
                        Location::instance($layout_id)->removeByDispatch((string) $location['dispatch']);
                    }
                }
            }
        }
        if ($show_message) {
            fn_set_notification('N', __('notice'), __('text_addon_uninstalled', array('[addon]' => $addon_scheme->getName())));
        }
        //Clean Registry
        Registry::del('addons.' . $addon_name);
        $hooks = Registry::get('hooks');
        Registry::del('hooks');
        if (!empty($hooks)) {
            foreach ($hooks as $hook_name => $hooks_data) {
                foreach ($hooks_data as $key => $hook_data) {
                    if ($hook_data['addon'] === $addon_name) {
                        unset($hooks[$hook_name][$key]);
                    }
                }
            }
        }
        Registry::set('hooks', $hooks);
        // Clean cache
        fn_clear_cache();
        return true;
    } else {
        return false;
    }
}
Ejemplo n.º 6
0
/**
 * Get blocks from central container
 * @param string $controller - controller.method
 * @return array ([block_id] => block_name)
 */
function fn_twg_get_location_page_title($controller = 'twigmo.post')
{
    $location = Location::instance()->get($controller);
    return $location['title'];
}
Ejemplo n.º 7
0
        }
    }
}
if (empty($_REQUEST['product_id']) && empty($_REQUEST['category_id'])) {
    unset(Tygh::$app['session']['current_category_id']);
}
$dispatch = $_REQUEST['dispatch'];
$dynamic_object = array();
if (!empty($_REQUEST['dynamic_object'])) {
    $dynamic_object = $_REQUEST['dynamic_object'];
}
$dynamic_object_scheme = SchemesManager::getDynamicObject($dispatch, AREA, $_REQUEST);
if (!empty($dynamic_object_scheme)) {
    $dispatch = $dynamic_object_scheme['customer_dispatch'];
}
Tygh::$app['view']->assign('location_data', Location::instance()->get($dispatch, $dynamic_object, CART_LANGUAGE));
Tygh::$app['view']->assign('layout_data', Registry::get('runtime.layout'));
Tygh::$app['view']->assign('current_mode', fn_get_current_mode($_REQUEST));
// Init cart if not set
if (empty(Tygh::$app['session']['cart'])) {
    fn_clear_cart(Tygh::$app['session']['cart']);
}
if (!empty(Tygh::$app['session']['continue_url'])) {
    Tygh::$app['session']['continue_url'] = fn_url_remove_service_params(Tygh::$app['session']['continue_url']);
}
if (Registry::get('config.demo_mode') && (!empty($_REQUEST['demo_customize_theme']) && $_REQUEST['demo_customize_theme'] == 'Y' || !empty(Tygh::$app['session']['demo_customize_theme']))) {
    Tygh::$app['session']['demo_customize_theme'] = true;
    Registry::set('runtime.customization_mode.theme_editor', true);
    if (!empty($_REQUEST['demo_customize_theme'])) {
        $current_url = Registry::get('config.current_url');
        $current_url = fn_query_remove($current_url, 'demo_customize_theme');
Ejemplo n.º 8
0
        Registry::get('view')->display('views/tabs/manage_in_tab.tpl');
        exit;
    }
} elseif ($mode == 'delete') {
    if (!empty($_REQUEST['tab_id'])) {
        ProductTabs::instance()->delete($_REQUEST['tab_id']);
    }
    return array(CONTROLLER_STATUS_OK, "tabs.manage");
} elseif ($mode == 'update') {
    $tab_id = isset($_REQUEST['tab_data']['tab_id']) ? $_REQUEST['tab_data']['tab_id'] : 0;
    $tab_type = isset($_REQUEST['tab_data']['tab_type']) ? $_REQUEST['tab_data']['tab_type'] : 'T';
    if (!empty($_REQUEST['dynamic_object'])) {
        Registry::get('view')->assign('dynamic_object', $_REQUEST['dynamic_object']);
    }
    $dynamic_object_scheme = SchemesManager::getDynamicObjectByType('products');
    $selected_location = Location::instance()->get('products.view', array(), DESCR_SL);
    Registry::get('view')->assign('location', $selected_location);
    Registry::get('view')->assign('dynamic_object_scheme', $dynamic_object_scheme);
    if (!empty($_REQUEST['tab_data'])) {
        $tab_data = $_REQUEST['tab_data'];
    } else {
        $tab_data = array();
    }
    // If edit block
    if ($tab_id > 0 && empty($_REQUEST['tab_data']['content'])) {
        $tab_data = current(ProductTabs::instance()->getList(db_quote(' AND ?:product_tabs.tab_id=?i', $tab_id), 0, DESCR_SL));
    }
    if (isset($tab_data['block_id']) && $tab_data['block_id'] > 0) {
        if (!empty($_REQUEST['dynamic_object'])) {
            $dynamic_object = $_REQUEST['dynamic_object'];
        } else {
Ejemplo n.º 9
0
 public static function backupSettings($upgrade_dirs)
 {
     // Backup addon's settings to the session
     $_SESSION['twigmo_backup_settings'] = TwigmoSettings::get();
     // Backup twigmo blocks
     $old_company_id = Registry::get('runtime.company_id');
     $old_layout_id = Registry::get('runtime.layout.layout_id');
     foreach ($upgrade_dirs['backup_company_settings'] as $company_id => $dir) {
         Registry::set('runtime.company_id', $company_id);
         $default_layout_id = fn_twg_get_default_layout_id();
         Registry::set('runtime.layout.layout_id', $default_layout_id);
         $location = Location::instance($default_layout_id)->get('twigmo.post');
         if ($location) {
             $exim = Exim::instance($company_id, $default_layout_id);
             if (version_compare(PRODUCT_VERSION, '4.1.1', '>=')) {
                 $content = $exim->export($default_layout_id, array($location['location_id']));
             } else {
                 $content = $exim->export(array($location['location_id']));
             }
             if ($content) {
                 fn_twg_write_to_file($dir . '/blocks.xml', $content, false);
             }
         }
     }
     Registry::set('runtime.company_id', $old_company_id);
     Registry::set('runtime.layout.layout_id', $old_layout_id);
     // Backup twigmo langvars
     $languages = Lang::getLanguages();
     foreach ($languages as $language) {
         // Prepare langvars for backup
         $langvars = Lang::getAllLangVars($language['lang_code']);
         $langvars_formated = array();
         foreach ($langvars as $name => $value) {
             $langvars_formated[] = array('name' => $name, 'value' => $value);
         }
         fn_twg_write_to_file($upgrade_dirs['backup_settings'] . '/lang_' . $language['lang_code'] . '.bak', $langvars_formated);
     }
     if (fn_allowed_for('ULTIMATE')) {
         db_export_to_file($upgrade_dirs['backup_settings'] . 'lang_ult.sql', array(db_quote('?:ult_language_values')), 'Y', 'Y', false, false, false);
     }
     return true;
 }
Ejemplo n.º 10
0
 /**
  * Get blocks for the twigmo homepage
  * @param  string $dispatch        Dispatch of needed location
  * @param  array  $allowed_objects - array of blocks types
  * @return array  blocks
  */
 public static final function getBlocksForLocation($dispatch, $allowed_objects)
 {
     $allowed_page_types = array('T', 'L', 'F');
     $blocks = array();
     $location = Location::instance(fn_twg_get_default_layout_id())->get($dispatch);
     if (!$location) {
         return $blocks;
     }
     $get_cont_params = array('location_id' => $location['location_id']);
     $container = Container::getList($get_cont_params);
     if (!$container or !$container['CONTENT']) {
         return $blocks;
     }
     $grids_params = array('container_ids' => $container['CONTENT']['container_id']);
     $grids = Grid::getList($grids_params);
     if (!$grids) {
         return $blocks;
     }
     $block_grids = Block::instance()->getList(array('?:bm_snapping.*', '?:bm_blocks.*', '?:bm_blocks_descriptions.*'), Grid::getIds($grids));
     $image_params = TwigmoSettings::get('images.catalog');
     foreach ($block_grids as $block_grid) {
         foreach ($block_grid as $block) {
             if ($block['status'] != 'A' or !in_array($block['type'], $allowed_objects)) {
                 continue;
             }
             $block_data = array('block_id' => $block['block_id'], 'title' => $block['name'], 'hide_header' => isset($block['properties']['hide_header']) ? $block['properties']['hide_header'] : 'N', 'user_class' => $block['user_class']);
             $block_scheme = SchemesManager::getBlockScheme($block['type'], array());
             if ($block['type'] == 'html_block') {
                 // Html block
                 if (isset($block['content']['content']) and fn_string_not_empty($block['content']['content'])) {
                     $block_data['html'] = $block['content']['content'];
                 }
             } elseif (!empty($block_scheme['content']) and !empty($block_scheme['content']['items'])) {
                 // Products and categories: get items
                 $template_variable = 'items';
                 $field = $block_scheme['content']['items'];
                 fn_set_hook('render_block_content_pre', $template_variable, $field, $block_scheme, $block);
                 $items = RenderManager::getValue($template_variable, $field, $block_scheme, $block);
                 // Filter pages - only texts, links and forms posible
                 if ($block['type'] == 'pages') {
                     foreach ($items as $item_id => $item) {
                         if (!in_array($item['page_type'], $allowed_page_types)) {
                             unset($items[$item_id]);
                         }
                     }
                 }
                 if (empty($items)) {
                     continue;
                 }
                 $block_data['total_items'] = count($items);
                 // Images
                 if ($block['type'] == 'products' or $block['type'] == 'categories') {
                     $object_type = $block['type'] == 'products' ? 'product' : 'category';
                     foreach ($items as $items_id => $item) {
                         if (!empty($item['main_pair'])) {
                             $main_pair = $item['main_pair'];
                         } else {
                             $main_pair = fn_get_image_pairs($item[$object_type . '_id'], $object_type, 'M', true, true);
                         }
                         if (!empty($main_pair)) {
                             $items[$items_id]['icon'] = TwigmoImage::getApiImageData($main_pair, $object_type, 'icon', $image_params);
                         }
                     }
                 }
                 // Banners properties
                 if ($block['type'] == 'banners') {
                     $rotation = $block['properties']['template'] == 'addons/banners/blocks/carousel.tpl' ? 'Y' : 'N';
                     $block_data['delay'] = $rotation == 'Y' ? $block['properties']['delay'] : 0;
                     $block_data['hide_navigation'] = isset($block['properties']['navigation']) && $block['properties']['navigation'] == 'N' ? 'Y' : 'N';
                 }
                 $block_data[$block['type']] = Api::getAsList($block['type'], $items);
             }
             $blocks[$block['block_id']] = $block_data;
         }
     }
     return $blocks;
 }
Ejemplo n.º 11
0
 /**
  * Copies all layout data from one layout to another by their IDs.
  *
  * @param integer $source_layout_id Source layout ID
  * @param integer $target_layout_id Target layout ID
  *
  * @return boolean True on success, false - otherwise
  */
 public function copyById($source_layout_id, $target_layout_id)
 {
     $source_layout = $this->get($source_layout_id);
     if (empty($source_layout)) {
         return false;
     }
     // Copy locations, their containers, grids and blocks to the target layout
     Location::instance($source_layout_id)->copy($target_layout_id);
     $source_layout_company_id = 0;
     $target_layout_company_id = 0;
     if (fn_allowed_for('ULTIMATE')) {
         $source_layout_company_id = $source_layout['company_id'];
         $target_layout_company_id = db_get_field("SELECT company_id FROM ?:bm_layouts WHERE layout_id = ?i", $target_layout_id);
     }
     // Copy logos
     /**
      * Get the list of logos, bounded to source layout and given company.
      * List has the following format:
      *
      * [
      *   logo_type => [
      *      style_id => logo_id,
      *      ...
      *   ],
      *   ...
      * ]
      */
     $source_layout_logos = db_get_hash_multi_array('SELECT `type`, `style_id`, `logo_id` FROM ?:logos WHERE `layout_id` = ?i AND `company_id` = ?i', array('type', 'style_id', 'logo_id'), $source_layout_id, $source_layout_company_id);
     $logo_types = fn_get_logo_types();
     foreach ($logo_types as $logo_type => $logo_type_metadata) {
         if (empty($logo_type_metadata['for_layout']) || empty($source_layout_logos[$logo_type])) {
             continue;
         }
         foreach ($source_layout_logos[$logo_type] as $source_layout_style_id => $source_layout_logo_id) {
             $created_target_layout_logo_id = fn_update_logo(array('type' => $logo_type, 'layout_id' => $target_layout_id, 'style_id' => $source_layout_style_id), $target_layout_company_id);
             fn_clone_image_pairs($created_target_layout_logo_id, $source_layout_logo_id, 'logos');
         }
     }
     return true;
 }
Ejemplo n.º 12
0
 /**
  * Checks is there are at least one active block of given type on current location
  *
  * @param  string $block_type Type of block
  * @return bool   True, if block of given type is active, false otherwise.
  */
 public function isBlockTypeActiveOnCurrentLocation($block_type)
 {
     $dispatch = !empty($_REQUEST['dispatch']) ? $_REQUEST['dispatch'] : 'index.index';
     $dynamic_object = array();
     $dynamic_object_scheme = SchemesManager::getDynamicObject($dispatch, AREA);
     if (!empty($dynamic_object_scheme) && !empty($_REQUEST[$dynamic_object_scheme['key']])) {
         $dynamic_object['object_type'] = $dynamic_object_scheme['object_type'];
         $dynamic_object['object_id'] = $_REQUEST[$dynamic_object_scheme['key']];
     }
     $current_location = Location::instance()->get($dispatch, $dynamic_object);
     if (!empty($current_location['location_id'])) {
         $blocks = $this->getBlocksByTypeForLocation($block_type, $current_location['location_id']);
         if (!empty($blocks)) {
             if (!empty($dynamic_object['object_id']) && !empty($dynamic_object['object_type'])) {
                 $dynamic_object_statuses = db_get_hash_array('SELECT * FROM ?:bm_block_statuses WHERE object_type = ?s AND FIND_IN_SET(?i, object_ids)', 'snapping_id', $dynamic_object['object_type'], $dynamic_object['object_id']);
                 foreach (array_keys($dynamic_object_statuses) as $snapping_id) {
                     if (isset($blocks[$snapping_id])) {
                         // reverse block status
                         $blocks[$snapping_id] = $blocks[$snapping_id] == 'A' ? 'D' : 'A';
                     }
                 }
             }
             foreach ($blocks as $status) {
                 if ($status == 'A') {
                     return true;
                 }
             }
         }
     }
     return false;
 }
Ejemplo n.º 13
0
    if (empty($_SESSION['store_access_key']) || $_SESSION['store_access_key'] != Registry::get('settings.General.store_access_key')) {
        if (defined('AJAX_REQUEST')) {
            fn_set_notification('E', __('notice'), __('text_store_closed'));
            exit;
        }
        Development::showStub();
    }
}
if (empty($_REQUEST['product_id']) && empty($_REQUEST['category_id'])) {
    unset($_SESSION['current_category_id']);
}
$dynamic_object = array();
if (!empty($_REQUEST['dynamic_object'])) {
    $dynamic_object = $_REQUEST['dynamic_object'];
}
Registry::get('view')->assign('location_data', Location::instance()->get($_REQUEST['dispatch'], $dynamic_object, CART_LANGUAGE));
Registry::get('view')->assign('layout_data', Registry::get('runtime.layout'));
Registry::get('view')->assign('current_mode', fn_get_current_mode($_REQUEST));
// Init cart if not set
if (empty($_SESSION['cart'])) {
    fn_clear_cart($_SESSION['cart']);
}
if (!empty($_SESSION['continue_url'])) {
    $_SESSION['continue_url'] = fn_url_remove_service_params($_SESSION['continue_url']);
}
if (Registry::get('config.demo_mode') && (!empty($_REQUEST['demo_customize_theme']) && $_REQUEST['demo_customize_theme'] == 'Y' || !empty($_SESSION['demo_customize_theme']))) {
    $_SESSION['demo_customize_theme'] = true;
    Registry::set('runtime.customization_mode.theme_editor', true);
    if (!empty($_REQUEST['demo_customize_theme'])) {
        $current_url = Registry::get('config.current_url');
        $current_url = fn_query_remove($current_url, 'demo_customize_theme');
Ejemplo n.º 14
0
 /**
  * Export blocks to XML structure
  *
  * @param  array              $location_ids
  * @param  array              $params
  * @param  string             $lang_code
  * @return ExSimpleXmlElement
  */
 public function export($layout_id, $location_ids = array(), $params = array(), $lang_code = DESCR_SL)
 {
     /* Exclude unnecessary fields*/
     $except_location_fields = array('location_id', 'company_id');
     $except_container_fields = array('container_id', 'location_id', 'dispatch', 'is_default', 'company_id', 'default');
     $except_grid_fields = array('container_id', 'location_id', 'position', 'grid_id', 'parent_id', 'order', 'children');
     $except_layout_fields = array('layout_id', 'theme_name', 'company_id');
     $except_location_fields = array_flip($except_location_fields);
     $except_container_fields = array_flip($except_container_fields);
     $except_grid_fields = array_flip($except_grid_fields);
     $except_layout_fields = array_flip($except_layout_fields);
     $layout_data = Layout::instance($this->_company_id)->get($layout_id);
     $layout_data = array_diff_key($layout_data, $except_layout_fields);
     $xml_root = new ExSimpleXmlElement('<block_scheme></block_scheme>');
     $xml_root->addAttribute('scheme', '1.0');
     $settings = $xml_root->addChild('settings');
     $settings->addChild('default_language', $lang_code);
     $layout_xml = $xml_root->addChild('layout');
     foreach ($layout_data as $field_name => $field_value) {
         $layout_xml->addChild($field_name, $field_value);
     }
     if (empty($location_ids)) {
         $location_ids = Location::instance($this->_layout_id)->getList(array(), $lang_code);
         $location_ids = array_keys($location_ids);
     }
     foreach ($location_ids as $location_id) {
         $location = Location::instance($this->_layout_id)->getById($location_id);
         $containers = Container::getList(array('location_id' => $location_id));
         $xml_location = $xml_root->addChild('location');
         $location = array_diff_key($location, $except_location_fields);
         foreach ($location as $attr => $value) {
             $xml_location->addAttribute($attr, $value);
         }
         $xml_containers = $xml_location->addChild('containers');
         $xml_translations = $xml_location->addChild('translations');
         $translations = Location::instance($this->_layout_id)->getAllDescriptions($location_id);
         foreach ($translations as $translation) {
             if ($translation['lang_code'] == $lang_code) {
                 // We do not needed default language
                 continue;
             }
             $xml_translation = $xml_translations->addChild('translation');
             $xml_translation->addChildCData('meta_keywords', $translation['meta_keywords']);
             $xml_translation->addChildCData('page_title', $translation['title']);
             $xml_translation->addChildCData('meta_description', $translation['meta_description']);
             $xml_translation->addChild('name', $translation['name']);
             $xml_translation->addAttribute('lang_code', $translation['lang_code']);
         }
         unset($xml_translations);
         foreach ($containers as $position => $container) {
             $grids = Grid::getList(array('container_ids' => $container['container_id']));
             $xml_container = $xml_containers->addChild('container');
             foreach ($container as $attr => $value) {
                 $xml_container->addAttribute($attr, $value);
             }
             if (!empty($grids) && isset($grids[$container['container_id']])) {
                 $grids = $grids[$container['container_id']];
                 $grids = fn_build_hierarchic_tree($grids, 'grid_id');
                 $container = array_diff_key($container, $except_container_fields);
                 $this->_buildGridStructure($xml_container, $grids, $except_grid_fields, $lang_code);
             }
         }
     }
     return $xml_root->asXML();
 }