/** * 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; } }
/** * Installs theme files * * @param string $source_theme source theme name * @param string $dest_theme destination theme name * @param boolean $from_repo flag, if set to true, theme files are copied from themes_repository * @return boolean true if theme was installed, false otherwise */ function fn_install_theme_files($source_theme, $dest_theme, $from_repo = true) { $path_dest = fn_get_theme_path('[themes]/' . $dest_theme, 'C'); if (!fn_is_theme_installed($dest_theme)) { if (!fn_mkdir($path_dest)) { fn_set_notification('E', __('error'), __('text_cannot_create_directory', array('[directory]' => fn_get_rel_dir($path_dest)))); return false; } $path_repo_base = ''; if ($from_repo) { $path_repo = fn_get_theme_path('[repo]/' . $source_theme, 'C'); $manifest = Themes::factory($source_theme)->getRepoManifest(); $parent_theme = isset($manifest['parent_theme']) ? $manifest['parent_theme'] : Registry::get('config.base_theme'); if (!empty($parent_theme) && $source_theme != $parent_theme) { $path_repo_base = fn_get_theme_path('[repo]/' . $parent_theme, 'C'); } } else { $path_repo = fn_get_theme_path('[themes]/' . $source_theme, 'C'); } fn_set_progress('parts', fn_dirs_count($path_repo_base) + fn_dirs_count($path_repo) + 1); // FIXME: Backward compatibility. Create manifest.json if theme only has manifest.ini if (file_exists($path_repo . '/' . THEME_MANIFEST_INI) && !file_exists($path_repo . '/' . THEME_MANIFEST)) { $content = parse_ini_file($path_repo . '/' . THEME_MANIFEST_INI); fn_put_contents($path_repo . '/' . THEME_MANIFEST, json_encode($content)); } if (!empty($path_repo_base)) { fn_copy($path_repo_base, $path_dest, false); // Clear layouts and styles data fn_rm($path_dest . '/styles'); fn_rm($path_dest . '/layouts'); // FIXME: Backward compatibility fn_rm($path_dest . '/presets'); } fn_copy($path_repo, $path_dest, false); } // Re-install add-ons template files list($installed_addons) = fn_get_addons(array('type' => 'installed')); foreach ($installed_addons as $addon) { fn_install_addon_templates($addon['addon']); } return true; }