/** * Installs 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 * @param bool $allow_unmanaged Whether to allow installing unmanaged addons in non-console environment * * @return bool True if addons installed successfully, false otherwise */ function fn_install_addon($addon, $show_notification = true, $install_demo = false, $allow_unmanaged = 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() && !($allow_unmanaged || defined('CONSOLE'))) { return false; } if ($addon_scheme != false) { // Register custom classes Tygh::$app['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', 'install_datetime' => time()); // 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, $allow_unmanaged); 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, $allow_unmanaged); return false; } if (fn_update_addon_settings($addon_scheme) == false) { fn_uninstall_addon($addon, false, $allow_unmanaged); 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' => isset($translation['description']) ? $translation['description'] : '')); } foreach ($addon_scheme->getLanguages() as $lang_code => $_v) { $lang_code = strtolower($lang_code); $path = $addon_scheme->getPoPath($lang_code); if (!empty($path)) { Languages::installLanguagePack($path, array('reinstall' => true, 'validate_lang_code' => $lang_code)); } } // 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, $allow_unmanaged); 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, false, $allow_unmanaged); } // Install layouts individually for each theme foreach (fn_get_installed_themes() as $theme_name) { $addon_layouts_path = fn_get_addon_layouts_path($addon, $theme_name); if ($addon_layouts_path) { if (fn_allowed_for('ULTIMATE')) { foreach (fn_get_all_companies_ids() as $company) { $layouts = Layout::instance($company)->getList(array('theme_name' => $theme_name)); foreach ($layouts as $layout_id => $layout) { Exim::instance($company, $layout_id)->importFromFile($addon_layouts_path); } } } else { $layouts = Layout::instance()->getList(array('theme_name' => $theme_name)); foreach ($layouts as $layout_id => $layout) { Exim::instance(0, $layout_id)->importFromFile($addon_layouts_path); } } } } // 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, $allow_unmanaged); return false; } } return true; } else { // Addon was not installed because scheme is not exists. return false; } }
/** * Installs theme * * @param int $layout_id layout ID to create logo for * @param string $theme_name theme name * @param int $company_id company ID * @return boolean always true */ function fn_install_theme($theme_name, $company_id = null, $install_layouts = true) { // Copy files fn_install_theme_files($theme_name, $theme_name, true); Settings::instance()->updateValue('theme_name', $theme_name, '', true, $company_id); $repo_dest = fn_get_theme_path('[themes]/' . $theme_name, 'C', $company_id, false); $logo_ids = array(); // Import theme layout $layouts = fn_get_dir_contents($repo_dest . '/layouts/', false, true, '.xml'); // FIXME: Backward compability for layouts if (empty($layouts) && file_exists($repo_dest . '/layouts.xml')) { $layouts = array('../layouts.xml'); } $created_layouts = array(); if (!empty($layouts) && $install_layouts) { foreach ($layouts as $layout_name) { $layout_path = fn_normalize_path($repo_dest . '/layouts/' . $layout_name); if (file_exists($layout_path)) { $layout_id = Exim::instance($company_id, 0, $theme_name)->importFromFile($layout_path, array('override_by_dispatch' => true, 'clean_up' => true, 'import_style' => 'create')); if (empty($layout_id)) { continue; } $created_layouts[] = $layout_id; $layout_data = Layout::instance()->get($layout_id); $_o_ids = fn_create_theme_logos_by_layout_id($theme_name, $layout_id, $company_id, false, $layout_data['style_id']); $logo_ids = array_merge($logo_ids, $_o_ids); } } } else { $params = array('theme_name' => $theme_name); $exists = Layout::instance($company_id)->getList($params); if (empty($exists)) { $layout_id = Layout::instance($company_id)->update(array('name' => __('main'), 'theme_name' => $theme_name, 'is_default' => 1)); $created_layouts[] = $layout_id; $layout_data = Layout::instance()->get($layout_id); $logo_ids = fn_create_theme_logos_by_layout_id($theme_name, $layout_id, $company_id, false, $layout_data['style_id']); } } // Import addons layouts for all theme layouts list($addons) = fn_get_addons(array('type' => 'installed')); foreach ($addons as $addon_name => $addon) { $addon_layouts_path = fn_get_addon_layouts_path($addon_name); if ($addon_layouts_path) { foreach ($created_layouts as $layout_id) { Exim::instance($company_id, $layout_id)->importFromFile($addon_layouts_path); } } } return $logo_ids; }