Exemplo n.º 1
0
/**
 * Init template engine
 *
 * @return boolean always true
 */
function fn_init_templater($area = AREA)
{
    $auth = Tygh::$app['session']['auth'];
    $view = new SmartyCore();
    \SmartyException::$escape = false;
    /**
     * Change templater pre-init parameters
     *
     * @param object $view Templater object
     */
    fn_set_hook('init_templater', $view);
    $view->_dir_perms = DEFAULT_DIR_PERMISSIONS;
    $view->_file_perms = DEFAULT_FILE_PERMISSIONS;
    $view->registerResource('tygh', new Tygh\SmartyEngine\FileResource());
    // resource for shared templates loaded from backend
    $view->registerResource('backend', new Tygh\SmartyEngine\BackendResource());
    if ($area == 'A') {
        if (!empty($auth['user_id'])) {
            // Auto-tooltips for admin panel
            $view->registerFilter('pre', array('Tygh\\SmartyEngine\\Filters', 'preFormTooltip'));
            if (fn_allowed_for('ULTIMATE')) {
                // Enable sharing for objects
                $view->registerFilter('output', array('Tygh\\SmartyEngine\\Filters', 'outputSharing'));
            }
        }
        $view->registerFilter('pre', array('Tygh\\SmartyEngine\\Filters', 'preScript'));
    }
    if ($area == 'C') {
        $view->registerFilter('pre', array('Tygh\\SmartyEngine\\Filters', 'preTemplateWrapper'));
        if (Registry::get('runtime.customization_mode.design')) {
            $view->registerFilter('output', array('Tygh\\SmartyEngine\\Filters', 'outputTemplateIds'));
        }
        if (Registry::get('runtime.customization_mode.live_editor')) {
            $view->registerFilter('output', array('Tygh\\SmartyEngine\\Filters', 'outputLiveEditorWrapper'));
        }
        $view->registerFilter('output', array('Tygh\\SmartyEngine\\Filters', 'outputScript'));
    }
    if (Embedded::isEnabled()) {
        $view->registerFilter('output', array('Tygh\\SmartyEngine\\Filters', 'outputEmbeddedUrl'));
    }
    // CSRF form protection
    if (fn_is_csrf_protection_enabled($auth)) {
        $view->registerFilter('output', array('Tygh\\SmartyEngine\\Filters', 'outputSecurityHash'));
    }
    // Language variable retrieval optimization
    $view->registerFilter('post', array('Tygh\\SmartyEngine\\Filters', 'postTranslation'));
    $smarty_plugins_dir = $view->getPluginsDir();
    $view->setPluginsDir(Registry::get('config.dir.functions') . 'smarty_plugins');
    $view->addPluginsDir($smarty_plugins_dir);
    $view->error_reporting = E_ALL & ~E_NOTICE;
    $view->registerDefaultPluginHandler(array('Tygh\\SmartyEngine\\Filters', 'smartyDefaultHandler'));
    $view->setArea($area);
    $view->use_sub_dirs = false;
    $view->compile_check = Development::isEnabled('compile_check') || Debugger::isActive() || fn_is_development() ? true : false;
    $view->setLanguage(CART_LANGUAGE);
    $view->assign('ldelim', '{');
    $view->assign('rdelim', '}');
    $view->assign('currencies', Registry::get('currencies'), false);
    $view->assign('primary_currency', CART_PRIMARY_CURRENCY, false);
    $view->assign('secondary_currency', CART_SECONDARY_CURRENCY, false);
    $view->assign('languages', Registry::get('languages'));
    if ($area == 'A') {
        $view->assign('addon_permissions_text', fn_get_addon_permissions_text());
    }
    if (!fn_allowed_for('ULTIMATE:FREE')) {
        $view->assign('localizations', fn_get_localizations(CART_LANGUAGE, true));
        if (defined('CART_LOCALIZATION')) {
            $view->assign('localization', fn_get_localization_data(CART_LOCALIZATION));
        }
    }
    if (defined('THEMES_PANEL')) {
        if (fn_allowed_for('ULTIMATE')) {
            $storefronts = db_get_array('SELECT storefront, company, company_id FROM ?:companies');
            Registry::set('demo_theme.storefronts', $storefronts);
        }
        $view->assign('demo_theme', Registry::get('demo_theme'));
    }
    Tygh::$app['view'] = $view;
    /**
     * Change templater parameters
     *
     * @param object $view Templater object
     */
    fn_set_hook('init_templater_post', $view);
    return array(INIT_STATUS_OK);
}
Exemplo n.º 2
0
/**
 * Installes addon
 *
 * @param string $addon Addon to install
 * @param bool $show_notification Display notification if set to true
 * @param bool $install_demo If defined as true, addon's demo data will be installed
 * @return bool True if addons installed successfully, false otherwise
 */
function fn_install_addon($addon, $show_notification = true, $install_demo = false)
{
    $status = db_get_field("SELECT status FROM ?:addons WHERE addon = ?s", $addon);
    // Return true if addon is installed
    if (!empty($status)) {
        return true;
    }
    $addon_scheme = SchemesManager::getScheme($addon);
    if (empty($addon_scheme)) {
        // Required add-on was not found in store.
        return false;
    }
    // Unmanaged addons can be installed via console only
    if ($addon_scheme->getUnmanaged() && !defined('CONSOLE')) {
        return false;
    }
    if ($addon_scheme != false) {
        // Register custom classes
        Registry::get('class_loader')->add('', Registry::get('config.dir.addons') . $addon);
        if ($addon_scheme->isPromo()) {
            $texts = fn_get_addon_permissions_text();
            fn_set_notification('E', __('error'), $texts['text']);
            return false;
        }
        $_data = array('addon' => $addon_scheme->getId(), 'priority' => $addon_scheme->getPriority(), 'dependencies' => implode(',', $addon_scheme->getDependencies()), 'conflicts' => implode(',', $addon_scheme->getConflicts()), 'requirements' => $addon_scheme->getRequirements(), 'version' => $addon_scheme->getVersion(), 'separate' => $addon_scheme->getSettingsLayout() == 'separate' ? 1 : 0, 'has_icon' => $addon_scheme->hasIcon(), 'unmanaged' => $addon_scheme->getUnmanaged(), 'status' => 'D');
        // Check system requirements (needed versions, installed extensions, etc.)
        if (!$addon_scheme->checkRequirements($_data['requirements'])) {
            return false;
        }
        $dependencies = SchemesManager::getInstallDependencies($_data['addon']);
        if (!empty($dependencies)) {
            fn_set_notification('W', __('warning'), __('text_addon_install_dependencies', array('[addon]' => implode(',', $dependencies))));
            return false;
        }
        if ($addon_scheme->callCustomFunctions('before_install') == false) {
            fn_uninstall_addon($addon, false);
            return false;
        }
        // Add add-on to registry
        Registry::set('addons.' . $addon, array('status' => 'D', 'priority' => $_data['priority']));
        // Execute optional queries
        if ($addon_scheme->processQueries('install', Registry::get('config.dir.addons') . $addon) == false) {
            fn_uninstall_addon($addon, false);
            return false;
        }
        if (fn_update_addon_settings($addon_scheme) == false) {
            fn_uninstall_addon($addon, false);
            return false;
        }
        db_query("REPLACE INTO ?:addons ?e", $_data);
        foreach ($addon_scheme->getAddonTranslations() as $translation) {
            db_query("REPLACE INTO ?:addon_descriptions ?e", array('lang_code' => $translation['lang_code'], 'addon' => $addon_scheme->getId(), 'name' => $translation['value'], 'description' => $translation['description']));
        }
        if ($original = $addon_scheme->getOriginals()) {
            db_query("REPLACE INTO ?:original_values ?e", array('msgctxt' => 'Addon:' . $addon, 'msgid' => $original['name']));
            db_query("REPLACE INTO ?:original_values ?e", array('msgctxt' => 'AddonDescription:' . $addon, 'msgid' => $original['description']));
        }
        // Install templates
        fn_install_addon_templates($addon_scheme->getId());
        // Put this addon settings to the registry
        $settings = Settings::instance()->getValues($addon_scheme->getId(), Settings::ADDON_SECTION, false);
        if (!empty($settings)) {
            Registry::set('settings.' . $addon, $settings);
            $addon_data = Registry::get('addons.' . $addon);
            Registry::set('addons.' . $addon, fn_array_merge($addon_data, $settings));
        }
        // Add optional language variables
        $language_variables = $addon_scheme->getLanguageValues(false);
        if (!empty($language_variables)) {
            db_query('REPLACE INTO ?:language_values ?m', $language_variables);
        }
        // Get only original values
        $language_variables = $addon_scheme->getLanguageValues(true);
        if (!empty($language_variables)) {
            db_query('REPLACE INTO ?:original_values ?m', $language_variables);
        }
        if (fn_allowed_for('ULTIMATE')) {
            foreach (fn_get_all_companies_ids() as $company) {
                ProductTabs::instance($company)->createAddonTabs($addon_scheme->getId(), $addon_scheme->getTabOrder());
            }
        } else {
            ProductTabs::instance()->createAddonTabs($addon_scheme->getId(), $addon_scheme->getTabOrder());
        }
        // Execute custom functions
        if ($addon_scheme->callCustomFunctions('install') == false) {
            fn_uninstall_addon($addon, false);
            return false;
        }
        if ($show_notification == true) {
            fn_set_notification('N', __('notice'), __('text_addon_installed', array('[addon]' => $addon_scheme->getName())));
        }
        // If we need to activate addon after install, call "update status" procedure
        if ($addon_scheme->getStatus() != 'D') {
            fn_update_addon_status($addon, $addon_scheme->getStatus(), false);
        }
        if (file_exists(Registry::get('config.dir.addons') . $addon . '/layouts.xml')) {
            if (fn_allowed_for('ULTIMATE')) {
                foreach (fn_get_all_companies_ids() as $company) {
                    $layouts = Layout::instance($company)->getList();
                    foreach ($layouts as $layout_id => $layout) {
                        Exim::instance($company, $layout_id)->importFromFile(Registry::get('config.dir.addons') . $addon . '/layouts.xml');
                    }
                }
            } else {
                $layouts = Layout::instance()->getList();
                foreach ($layouts as $layout_id => $layout) {
                    Exim::instance(0, $layout_id)->importFromFile(Registry::get('config.dir.addons') . $addon . '/layouts.xml');
                }
            }
        }
        // Clean cache
        fn_clear_cache();
        if ($install_demo) {
            $addon_scheme->processQueries('demo', Registry::get('config.dir.addons') . $addon);
            if ($addon_scheme->callCustomFunctions('demo') == false) {
                fn_uninstall_addon($addon, false);
                return false;
            }
        }
        return true;
    } else {
        // Addon was not installed because scheme is not exists.
        return false;
    }
}
Exemplo n.º 3
0
/**
 * Init template engine
 *
 * @return boolean always true
 */
function fn_init_templater($area = AREA)
{
    $view = new SmartyCore();
    \SmartyException::$escape = false;
    /**
     * Change templater pre-init parameters
     *
     * @param object $view Templater object
     */
    fn_set_hook('init_templater', $view);
    $view->registerResource('tygh', new Tygh\SmartyEngine\FileResource());
    if ($area == 'A' && !empty($_SESSION['auth']['user_id'])) {
        // Auto-tooltips for admin panel
        $view->registerFilter('pre', array('Tygh\\SmartyEngine\\Filters', 'preFormTooltip'));
    }
    // Customization mode
    if ($area == 'C') {
        $view->registerFilter('pre', array('Tygh\\SmartyEngine\\Filters', 'preTemplateWrapper'));
        if (Registry::get('runtime.customization_mode.design')) {
            $view->registerFilter('output', array('Tygh\\SmartyEngine\\Filters', 'outputTemplateIds'));
        }
    }
    if (Registry::get('config.tweaks.anti_csrf') == true) {
        // CSRF form protection
        $view->registerFilter('output', array('Tygh\\SmartyEngine\\Filters', 'outputSecurityHash'));
    }
    if (Embedded::isEnabled()) {
        $view->registerFilter('output', array('Tygh\\SmartyEngine\\Filters', 'outputEmbeddedUrl'));
    }
    if (fn_allowed_for('ULTIMATE')) {
        // Enable sharing for objects
        $view->registerFilter('output', array('Tygh\\SmartyEngine\\Filters', 'outputSharing'));
    }
    // Language variable retrieval optimization
    $view->registerFilter('post', array('Tygh\\SmartyEngine\\Filters', 'postTranslation'));
    // Translation mode
    if (Registry::get('runtime.customization_mode.translation')) {
        $view->registerFilter('output', array('Tygh\\SmartyEngine\\Filters', 'outputTranslateWrapper'));
    }
    if (Registry::get('settings.General.debugging_console') == 'Y') {
        if (empty($_SESSION['debugging_console']) && !empty($_SESSION['auth']['user_id'])) {
            $user_type = db_get_field("SELECT user_type FROM ?:users WHERE user_id = ?i", $_SESSION['auth']['user_id']);
            if ($user_type == 'A') {
                $_SESSION['debugging_console'] = true;
            }
        }
        if (isset($_SESSION['debugging_console']) && $_SESSION['debugging_console'] == true) {
            error_reporting(0);
            $view->debugging = true;
        }
    }
    $smarty_plugins_dir = $view->getPluginsDir();
    $view->setPluginsDir(Registry::get('config.dir.functions') . 'smarty_plugins');
    $view->addPluginsDir($smarty_plugins_dir);
    $view->error_reporting = E_ALL & ~E_NOTICE;
    $view->registerDefaultPluginHandler(array('Tygh\\SmartyEngine\\Filters', 'smartyDefaultHandler'));
    $view->setArea($area);
    $view->use_sub_dirs = false;
    $view->compile_check = Development::isEnabled('compile_check') || Debugger::isActive() || defined('DEVELOPMENT') ? true : false;
    $view->setLanguage(CART_LANGUAGE);
    $view->assign('ldelim', '{');
    $view->assign('rdelim', '}');
    $view->assign('currencies', Registry::get('currencies'), false);
    $view->assign('primary_currency', CART_PRIMARY_CURRENCY, false);
    $view->assign('secondary_currency', CART_SECONDARY_CURRENCY, false);
    $view->assign('languages', Registry::get('languages'));
    if ($area == 'A') {
        $view->assign('addon_permissions_text', fn_get_addon_permissions_text());
    }
    if (!fn_allowed_for('ULTIMATE:FREE')) {
        $view->assign('localizations', fn_get_localizations(CART_LANGUAGE, true));
        if (defined('CART_LOCALIZATION')) {
            $view->assign('localization', fn_get_localization_data(CART_LOCALIZATION));
        }
    }
    if (defined('THEMES_PANEL')) {
        if (fn_allowed_for('ULTIMATE')) {
            $storefronts = db_get_array('SELECT storefront, company, company_id FROM ?:companies');
            Registry::set('demo_theme.storefronts', $storefronts);
        }
        $view->assign('demo_theme', Registry::get('demo_theme'));
    }
    Registry::set('view', $view);
    /**
     * Change templater parameters
     *
     * @param object $view Templater object
     */
    fn_set_hook('init_templater_post', $view);
    return array(INIT_STATUS_OK);
}