/** * Gets all logos * @TODO Remove "create" functionality from Getter * * @param int $company_id company ID * @param int $layout_id layout ID * @param string $style_id Style ID * @return array logos list */ function fn_get_logos($company_id = null, $layout_id = 0, $style_id = '') { /** * Changes params before selecting logo * * @param int $company_id company ID * @param int $layout_id layout ID * @param string $style_id Style ID */ fn_set_hook('get_logos_pre', $company_id, $layout_id, $style_id); $condition = array(); $company_condition = ''; if (is_null($company_id)) { if (Registry::get('runtime.company_id')) { $company_id = Registry::get('runtime.company_id'); } elseif (fn_allowed_for('MULTIVENDOR')) { $company_id = 0; } } if (!is_null($company_id)) { $company_condition = db_quote(' AND company_id = ?i', $company_id); } if (!empty($company_id) && fn_allowed_for('ULTIMATE')) { $layout_data = Layout::instance($company_id)->getDefault(); } else { $layout_data = array('layout_id' => Registry::get('runtime.layout.layout_id'), 'style_id' => Registry::get('runtime.layout.style_id')); } $layout_id = !empty($layout_id) ? $layout_id : $layout_data['layout_id']; $style_id = !empty($style_id) ? $style_id : $layout_data['style_id']; $condition[] = db_quote('IF(layout_id = 0, 1, IF(layout_id = ?i, 1, 0))', $layout_id); if (!empty($style_id)) { $condition[] = db_quote('IF(style_id = \'\', 1, IF(style_id = ?s, 1, 0))', $style_id); } /** * Changes conditions before selecting logo * * @param int $company_id company ID * @param int $layout_id layout ID * @param string $style_id Style ID * @param array $condition Selecting conditions * @param string $company_condition Condition by companies */ fn_set_hook('get_logos', $company_id, $layout_id, $style_id, $condition, $company_condition); $logos = db_get_hash_array("SELECT * FROM ?:logos WHERE ?p ?p", 'type', implode(' AND ', $condition), $company_condition); $logo_ids = array(); foreach ($logos as $l) { $logo_ids[] = $l['logo_id']; } $images = fn_get_image_pairs($logo_ids, 'logos', 'M', true, false); foreach ($logos as $k => $v) { if (empty($images[$v['logo_id']])) { $logos[$k]['image'] = array(); continue; } $image = reset($images[$v['logo_id']]); $logos[$k]['image'] = $image['icon']; } /** * Changes logos before returning * * @param int $company_id company ID * @param int $layout_id layout ID * @param string $style_id Style ID * @param array $logos Selected logos */ fn_set_hook('get_logos_post', $company_id, $layout_id, $style_id, $logos); return $logos; }
/** * 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; } }
} exit; } return array(CONTROLLER_STATUS_OK, 'themes.manage'); } if ($mode == 'manage') { if (fn_allowed_for('ULTIMATE') && !Registry::get('runtime.company_id')) { return array(CONTROLLER_STATUS_OK); } $available_themes = fn_get_available_themes(Registry::get('settings.theme_name')); if (!empty($available_themes['repo']) && !empty($available_themes['installed'])) { $available_themes['repo'] = array_diff_key($available_themes['repo'], $available_themes['installed']); } Tygh::$app['view']->assign('themes_prefix', fn_get_theme_path('[relative]', 'C')); Tygh::$app['view']->assign('repo_prefix', fn_get_theme_path('[repo]', 'C')); Registry::set('navigation.tabs', array('installed_themes' => array('title' => __('installed_themes'), 'js' => true), 'browse_all_available_themes' => array('title' => __('browse_all_available_themes'), 'js' => true))); $theme_name = fn_get_theme_path('[theme]', 'C'); $layout = Layout::instance()->getDefault($theme_name); $style = Styles::factory($theme_name)->get($layout['style_id']); $layout['style_name'] = empty($style['name']) ? '' : $style['name']; Tygh::$app['view']->assign('layout', $layout); foreach ($available_themes['installed'] as $theme_id => $theme) { $layouts_params = array('theme_name' => $theme_id); $available_themes['installed'][$theme_id]['layouts'] = Layout::instance()->getList($layouts_params); if ($theme_id == $theme_name) { $available_themes['current']['layouts'] = $available_themes['installed'][$theme_id]['layouts']; } } Tygh::$app['view']->assign('available_themes', $available_themes); Tygh::$app['view']->assign('dev_modes', Development::get()); }
private static function _installTheme($company_id = null) { $theme_name = 'basic'; $style = 'satori'; fn_install_theme($theme_name, $company_id); $layout = Layout::instance($company_id)->getDefault($theme_name); Styles::factory($theme_name)->setStyle($layout['layout_id'], $style); }
if ($theme_id == $theme_name) { $available_themes['current']['layouts'] = $available_themes['installed'][$theme_id]['layouts']; } } Registry::get('view')->assign('available_themes', $available_themes); Registry::get('view')->assign('dev_modes', Development::get()); } elseif ($mode == 'styles') { if ($action == 'update_status') { $theme = Themes::factory(fn_get_theme_path('[theme]', 'C')); $theme_manifest = $theme->getManifest(); if (empty($theme_manifest['converted_to_css'])) { Styles::factory(fn_get_theme_path('[theme]', 'C'))->setStyle($_REQUEST['id'], $_REQUEST['status']); // Delete compiled CSS file fn_clear_cache('statics'); } else { $layout = Layout::instance(Registry::get('runtime.company_id'))->getDefault(); fn_set_notification('E', __('error'), __('theme_editor.error_theme_converted_to_css', array('[url]' => fn_url("customization.update_mode?type=theme_editor&status=enable&s_layout={$layout['layout_id']}")))); } } return array(CONTROLLER_STATUS_OK, 'themes.manage'); } elseif ($mode == 'update_dev_mode') { if (!empty($_REQUEST['dev_mode'])) { if (!empty($_REQUEST['state'])) { Development::enable($_REQUEST['dev_mode']); } else { Development::disable($_REQUEST['dev_mode']); } if ($_REQUEST['dev_mode'] == 'compile_check') { if (!empty($_REQUEST['state'])) { fn_set_notification('W', __('warning'), __('warning_store_optimization_dev', array('[link]' => fn_url('themes.manage')))); } else {
public static function restoreSettingsAndCSS($upgrade_dirs) { // Restore langvars - for all languages except EN and RU $languages = Lang::getLanguages(); $except_langs = array('en', 'ru'); foreach ($languages as $language) { $backup_file = $upgrade_dirs['backup_settings'] . 'lang_' . $language['lang_code'] . '.bak'; if (!in_array($language['lang_code'], $except_langs) and file_exists($backup_file)) { LanguageValues::updateLangVar(unserialize(fn_get_contents($backup_file)), $language['lang_code']); } } // Restore blocks $old_company_id = Registry::get('runtime.company_id'); foreach ($upgrade_dirs['backup_company_settings'] as $company_id => $dir) { Registry::set('runtime.company_id', $company_id); $backup_file = $dir . 'blocks.xml'; if (file_exists($backup_file)) { if (version_compare(PRODUCT_VERSION, '4.1.1', '>=')) { Registry::set('runtime.layout', Layout::instance()->getDefault()); } Exim::instance($company_id, fn_twg_get_default_layout_id())->importFromFile($backup_file); } } Registry::set('runtime.company_id', $old_company_id); // Restore settings if addon was connected $restored_settings = array('my_private_key', 'my_public_key', 'his_public_key', 'email', 'customer_connections', 'admin_connection'); $settings = array(); foreach ($_SESSION['twigmo_backup_settings'] as $setting => $value) { if (in_array($setting, $restored_settings)) { $settings[$setting] = $value; } } $settings['version'] = TWIGMO_VERSION; unset($_SESSION['twigmo_backup_settings']); TwigmoSettings::set($settings); $connector = new TwigmoConnector(); if (!$connector->updateConnections(true)) { $connector->disconnect(array(), true); } // Restore images self::copyFiles($upgrade_dirs['backup_files']['media_frontend'], $upgrade_dirs['installed']['media_frontend']); return true; }
/** * Deletes theme * @param string $theme_name theme name to delete. If empty - deletes all themes * @return boolean true if deleted, false if not */ function fn_delete_theme($theme_name) { $themes_dest = fn_get_theme_path('[themes]/' . $theme_name, 'C'); $can_delete = true; if (fn_allowed_for('ULTIMATE')) { $company_themes = Settings::instance()->getAllVendorsValues('theme_name'); if (in_array($theme_name, $company_themes)) { fn_set_notification('E', __('error'), __('error_delete_theme_company')); $can_delete = false; } } else { if ($theme_name == Registry::get('runtime.layout.theme_name')) { $can_delete = false; fn_set_notification('E', __('error'), __('cannot_remove_active_theme')); } } $layouts = db_get_array('SELECT layout_id, is_default FROM ?:bm_layouts WHERE theme_name = ?s', $theme_name); if ($can_delete && fn_rm($themes_dest)) { // Delete layout foreach ($layouts as $layout) { Layout::instance()->delete($layout['layout_id']); } return true; } return false; }
function fn_delete_company($company_id) { if (empty($company_id)) { return false; } if (fn_allowed_for('MULTIVENDOR')) { // Do not delete vendor if there're any orders associated with this company if (db_get_field("SELECT COUNT(*) FROM ?:orders WHERE company_id = ?i", $company_id)) { fn_set_notification('W', __('warning'), __('unable_delete_vendor_orders_exists'), '', 'company_has_orders'); return false; } } fn_set_hook('delete_company_pre', $company_id); $result = db_query("DELETE FROM ?:companies WHERE company_id = ?i", $company_id); // deleting categories $cat_ids = db_get_fields("SELECT category_id FROM ?:categories WHERE company_id = ?i", $company_id); foreach ($cat_ids as $cat_id) { fn_delete_category($cat_id, false); } // deleting products $product_ids = db_get_fields("SELECT product_id FROM ?:products WHERE company_id = ?i", $company_id); foreach ($product_ids as $product_id) { fn_delete_product($product_id); } // deleting shipping $shipping_ids = db_get_fields("SELECT shipping_id FROM ?:shippings WHERE company_id = ?i", $company_id); foreach ($shipping_ids as $shipping_id) { fn_delete_shipping($shipping_id); } if (fn_allowed_for('ULTIMATE')) { // deleting layouts $layouts = Layout::instance($company_id)->getList(); foreach ($layouts as $layout_id => $layout) { Layout::instance($company_id)->delete($layout_id); } } $blocks = Block::instance($company_id)->getAllUnique(); foreach ($blocks as $block) { Block::instance($company_id)->remove($block['block_id']); } $product_tabs = ProductTabs::instance($company_id)->getList(); foreach ($product_tabs as $product_tab) { ProductTabs::instance($company_id)->delete($product_tab['tab_id'], true); } $_menus = Menu::getList(db_quote(" AND company_id = ?i", $company_id)); foreach ($_menus as $menu) { Menu::delete($menu['menu_id']); } db_query("DELETE FROM ?:company_descriptions WHERE company_id = ?i", $company_id); // deleting product_options $option_ids = db_get_fields("SELECT option_id FROM ?:product_options WHERE company_id = ?i", $company_id); foreach ($option_ids as $option_id) { fn_delete_product_option($option_id); } // deleting company admins and users if (Registry::get('settings.Stores.share_users') != 'Y') { $users_condition = db_quote(' OR company_id = ?i', $company_id); } else { $users_condition = ''; // Unassign users from deleted company db_query('UPDATE ?:users SET company_id = 0 WHERE company_id = ?i', $company_id); } $user_ids = db_get_fields("SELECT user_id FROM ?:users WHERE company_id = ?i AND user_type = ?s ?p", $company_id, 'V', $users_condition); foreach ($user_ids as $user_id) { fn_delete_user($user_id); } // deleting pages $page_ids = db_get_fields("SELECT page_id FROM ?:pages WHERE company_id = ?i", $company_id); foreach ($page_ids as $page_id) { fn_delete_page($page_id); } // deleting promotions $promotion_ids = db_get_fields("SELECT promotion_id FROM ?:promotions WHERE company_id = ?i", $company_id); fn_delete_promotions($promotion_ids); // deleting features $feature_ids = db_get_fields("SELECT feature_id FROM ?:product_features WHERE company_id = ?i", $company_id); foreach ($feature_ids as $feature_id) { fn_delete_feature($feature_id); } // deleting logos $types = fn_get_logo_types(); foreach ($types as $type => $data) { fn_delete_logo($type, $company_id); } $payment_ids = db_get_fields('SELECT payment_id FROM ?:payments WHERE company_id = ?i', $company_id); foreach ($payment_ids as $payment_id) { fn_delete_payment($payment_id); } // Delete sitemap sections and links $params = array('company_id' => $company_id); $section_ids = fn_get_sitemap_sections($params); fn_delete_sitemap_sections(array_keys($section_ids)); fn_set_hook('delete_company', $company_id, $result); return $result; }
/** * Compile chunk of LESS output and save the result in the file * * @param string $less_output Chunk of LESS output * @param string $css_path The path where the precompiled LESS will be saved * * @return boolean Result */ protected function convertChunkToCss($less_output, $css_path) { $less = $this->getLess(); $less_reflection = $this->getLessReflection(); $less->setImportDir($less_reflection['import_dirs']); Registry::set('runtime.layout', Layout::instance()->getDefault($this->theme_name)); $from_path = Storage::instance('assets')->getAbsolutePath($this->relative_path . '/css'); $compiled_less = $less->customCompile($less_output, $from_path, array(), '', 'C'); $res = fn_put_contents($css_path . '/' . self::$compiled_less_filename, $compiled_less); if ($res === false) { return false; } return true; }
Registry::get('view')->assign('dynamic_object_scheme', SchemesManager::getDynamicObjectByType($_REQUEST['object_type'])); } } elseif ($mode == 'update_status') { $type = empty($_REQUEST['type']) ? 'block' : $_REQUEST['type']; if ($type == 'block') { Block::instance()->updateStatus($_REQUEST); } elseif ($type == 'grid') { Grid::update($_REQUEST); } elseif ($type == 'container') { Container::update($_REQUEST); } exit; } elseif ($mode == 'delete_layout') { Layout::instance()->delete($_REQUEST['layout_id']); return array(CONTROLLER_STATUS_OK, 'block_manager.manage'); } elseif ($mode == 'set_default_layout') { if (!empty($_REQUEST['layout_id'])) { Layout::instance()->setDefault($_REQUEST['layout_id']); fn_set_notification('N', __('notice'), __('text_changes_saved')); } return array(CONTROLLER_STATUS_OK, 'block_manager.manage'); } 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; }
/** * 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(); }
/** * Init layout * * @param array $params request parameters * @return boolean always true */ function fn_init_layout($params) { if (fn_allowed_for('ULTIMATE')) { if (!Registry::get('runtime.company_id')) { return array(INIT_STATUS_OK); } } $key_name = 'stored_layout' . (Embedded::isEnabled() ? '_embedded' : ''); $stored_layout = fn_get_session_data($key_name); if (!empty($params['s_layout'])) { $stored_layout = $params['s_layout']; fn_set_session_data($key_name, $params['s_layout']); } // Replace default theme with selected for current area if (!empty($stored_layout)) { $layout = Layout::instance()->get($stored_layout); if (!isset($layout['theme_name']) || $layout['theme_name'] != fn_get_theme_path('[theme]', 'C')) { unset($layout); } } if (empty($layout)) { $layout = Layout::instance()->getDefault(); // get default } $available_styles = Styles::factory($layout['theme_name'])->getList(array('short_info' => true)); if (!isset($available_styles[$layout['style_id']])) { $layout['style_id'] = Styles::factory($layout['theme_name'])->getDefault(); } Registry::set('runtime.layout', $layout); return array(INIT_STATUS_OK); }
function fn_clone_layouts($data, $from, $to) { // We need to clone logos, not attached to any layout too $logos = fn_get_logos($from, 0); if (!empty($logos)) { Registry::set('runtime.allow_upload_external_paths', true); foreach ($logos as $type => $logo) { fn_create_logo(array('type' => $logo['type'], 'layout_id' => $logo['layout_id'], 'image_path' => !empty($logo['image']['absolute_path']) ? $logo['image']['absolute_path'] : ''), $to); } Registry::set('runtime.allow_upload_external_paths', false); } return Layout::instance($from)->copy($to); }
$company_data['logos'] = fn_get_logos($company_id); } Tygh::$app['view']->assign('logo_types', fn_get_logo_types(true)); } $restored_company_data = fn_restore_post_data('company_data'); if (!empty($restored_company_data) && $mode == 'add') { if (!empty($restored_company_data['shippings'])) { $restored_company_data['shippings'] = implode(',', $restored_company_data['shippings']); } $company_data = fn_array_merge($company_data, $restored_company_data); } if (fn_allowed_for('ULTIMATE')) { if ($mode == 'update') { $available_themes = fn_get_available_themes(fn_get_theme_path('[theme]', 'C', $company_id)); $theme_name = fn_get_theme_path('[theme]', 'C', $company_id); $layout = Layout::instance($company_id)->getDefault($theme_name); $style = Styles::factory($theme_name)->get($layout['style_id']); Tygh::$app['view']->assign('current_style', $style); Tygh::$app['view']->assign('theme_info', $available_themes['current']); } $countries_list = fn_get_simple_countries(); if (!empty($company_data['countries_list'])) { if (!is_array($company_data['countries_list'])) { $company_countries = explode(',', $company_data['countries_list']); } else { $company_countries = $company_data['countries_list']; } $_countries = array(); foreach ($company_countries as $code) { if (isset($countries_list[$code])) { $_countries[$code] = $countries_list[$code];
/** * Returns object instance if Location class or create it if not exists * @static * @param int $company_id Company identifier * @param string $class_name ClassName * @return Location */ public static function instance($layout_id = 0) { if (empty(self::$_instance)) { self::$_instance = new Location(); } if (empty($layout_id)) { $layout = Layout::instance()->get(Registry::get('runtime.layout.layout_id')); $layout_id = $layout['layout_id']; } self::$_instance->_layout_id = $layout_id; return self::$_instance; }
function fn_theme_editor($params, $lang_code = CART_LANGUAGE) { $view = Tygh::$app['view']; $theme_name = Registry::get('runtime.layout.theme_name'); $layout_id = Registry::get('runtime.layout.layout_id'); if (!Registry::get('runtime.layout.style_id')) { $default_style_id = Styles::factory($theme_name)->getDefault(); db_query('UPDATE ?:bm_layouts SET style_id = ?s WHERE layout_id = ?i', $default_style_id, $layout_id); Registry::set('runtime.layout.style_id', $default_style_id); } $style_id = Registry::get('runtime.layout.style_id'); // Backward presets compatibility Registry::set('runtime.layout.preset_id', $style_id); // get current style $current_style = Styles::factory($theme_name)->get($style_id, array('parse' => true)); // get all styles $styles_list = Styles::factory($theme_name)->getList(); $schema = Styles::factory($theme_name)->getSchema(); $sections = array('te_general' => 'theme_editor.general', 'te_logos' => 'theme_editor.logos', 'te_colors' => 'theme_editor.colors', 'te_fonts' => 'theme_editor.fonts', 'te_backgrounds' => 'theme_editor.backgrounds', 'te_css' => 'theme_editor.css'); foreach ($sections as $section_id => $section) { if ($section_id == 'te_logos') { // Logos is hardcoded section, no need to define it in schema continue; } $section_id = str_replace('te_', '', $section_id); if (!isset($schema[$section_id])) { unset($sections['te_' . $section_id]); } } if (empty($params['selected_section']) || !isset($sections[$params['selected_section']])) { reset($sections); $params['selected_section'] = key($sections); } $theme = Themes::factory($theme_name); $theme_manifest = $theme->getManifest(); if (!empty($theme_manifest['converted_to_css'])) { if (empty($params['selected_css_file'])) { $params['selected_css_file'] = Themes::$compiled_less_filename; } $view->assign('selected_css_file', $params['selected_css_file']); $view->assign('css_files_list', $theme->getCssFilesList()); $view->assign('css_content', $theme->getCssContents($params['selected_css_file'])); } $view->assign('cse_logo_types', fn_get_logo_types()); $view->assign('cse_logos', fn_get_logos(Registry::get('runtime.company_id'))); $view->assign('selected_section', $params['selected_section']); $view->assign('te_sections', $sections); $view->assign('current_style', $current_style); $view->assign('props_schema', $schema); $view->assign('theme_patterns', Patterns::instance()->get($style_id)); $view->assign('styles_list', $styles_list); // FIXME: Backward compatibility $view->assign('presets_list', $styles_list); $view->assign('current_preset', $current_style); $view->assign('manifest', Styles::factory($theme_name)->getManifest()); $view->assign('theme_manifest', $theme_manifest); $view->assign('layouts', Layout::instance()->getList(array('theme_name' => $theme_name))); $view->assign('layout_data', Layout::instance()->get($layout_id)); $view->assign('theme_url', fn_url(empty($params['theme_url']) ? '' : $params['theme_url'])); }
/** * Copy all layouts from one company to another * @param integer $to_company_id target company ID * @return mixed true on success, false - otherwise */ public function copy($to_company_id) { $from_layout = $this->getList(); if (empty($from_layout)) { return false; } foreach ($from_layout as $layout) { $original_layout_id = $layout['layout_id']; unset($layout['layout_id'], $layout['company_id']); $layout['name'] .= ' (' . __('clone') . ')'; $layout['company_id'] = $to_company_id; $layout['from_layout_id'] = $original_layout_id; $new_layout_id = Layout::instance($to_company_id)->update($layout, 0); $this->copyById($original_layout_id, $new_layout_id); } return true; }
if (!empty($selected_location['dispatch'])) { Tygh::$app['view']->assign('dynamic_object_scheme', SchemesManager::getDynamicObject($selected_location['dispatch'], 'C')); } $theme = Themes::factory(fn_get_theme_path('[theme]', 'C')); Tygh::$app['view']->assign('theme_manifest', $theme->getManifest()); $params = array('theme_name' => $theme->getThemeName()); Tygh::$app['view']->assign('layouts', Layout::instance()->getList($params)); Tygh::$app['view']->assign('all_layouts', Layout::instance()->getList()); Tygh::$app['view']->assign('default_layouts_sources', fn_get_default_layouts_sources('responsive')); Tygh::$app['view']->assign('themes', fn_get_available_themes($theme->getThemeName())); $http_url = fn_get_storefront_url('http'); $https_url = fn_get_storefront_url('https'); Tygh::$app['view']->assign('widget_http_url', urlencode($http_url)); Tygh::$app['view']->assign('widget_https_url', urlencode($https_url)); if ($mode == 'manage') { Tygh::$app['view']->assign('layout_data', Layout::instance()->get(Registry::get('runtime.layout.layout_id'))); } else { Tygh::$app['view']->display('views/block_manager/manage_in_tab.tpl'); exit; } } elseif ($mode == 'update_block') { $snapping_data = array(); $editable_content = true; $editable_template_name = true; $editable_wrapper = false; if (!empty($_REQUEST['dynamic_object'])) { $dynamic_object = $_REQUEST['dynamic_object']; $editable_template_name = false; } else { $dynamic_object = array(); }
/** * Creates a clone of the theme. * * @param string $clone_name Name of the new theme * @param array $clone_data Array with "title" and "description" fields for the new theme * @param int $company_id ID of the owner company for the new theme * * @return bool Whether cloning has succeed */ public function cloneAs($clone_name, $clone_data = array(), $company_id = 0) { $cloned = new self($clone_name); if (file_exists($cloned->getThemePath())) { fn_set_notification('W', __('warning'), __('warning_theme_clone_dir_exists')); return false; } if (!fn_install_theme_files($this->getThemeName(), $cloned->getThemeName(), false)) { return false; } // Layouts that belong to the theme $layouts = Layout::instance()->getList(array('theme_name' => $this->getThemeName())); // Clone layouts one by one foreach ($layouts as $layout) { $src_layout_id = $layout['layout_id']; unset($layout['layout_id']); $layout['theme_name'] = $cloned->getThemeName(); $layout['from_layout_id'] = $src_layout_id; $dst_layout_id = Layout::instance()->update($layout); if (!empty($layout['is_default'])) { // Re-init layout data fn_init_layout(array('s_layout' => $dst_layout_id)); } } $manifest = $cloned->getManifest(); if (isset($clone_data['title'])) { $manifest['title'] = $clone_data['title']; } if (isset($clone_data['description'])) { $manifest['description'] = $clone_data['description']; } // Put logos of current layout to manifest $logos = fn_get_logos(Registry::get('runtime.company_id')); foreach ($logos as $type => $logo) { if (!empty($logo['image'])) { $filename = fn_basename($logo['image']['relative_path']); Storage::instance('images')->export($logo['image']['relative_path'], $cloned->getThemePath() . '/media/images/' . $filename); $manifest[$type] = 'media/images/' . $filename; } } $cloned->setManifest($manifest); $cloned->saveManifest(); fn_install_theme($cloned->getThemeName(), $company_id, false); $cloned->overrideSettings(null, $company_id); }