/** * Change style id for specified layout * * @param int $layout_id Layout ID * @param string $style_id Style name (Like: "satori", "ocean", etc) * @return true if updated */ public function setStyle($layout_id, $style_id) { $result = db_query('UPDATE ?:bm_layouts SET style_id = ?s WHERE layout_id = ?i AND theme_name = ?s', $style_id, $layout_id, $this->theme_name); if ((fn_allowed_for('ULTIMATE') && !empty($this->company_id) || fn_allowed_for('MULTIVENDOR')) && !empty($layout_id) && !empty($style_id) && !empty($this->theme_name)) { $logos = fn_get_logos($this->company_id, $layout_id, $style_id); $logo_types = fn_get_logo_types(false); $have_missed = array_diff_key($logo_types, $logos); if (!empty($have_missed)) { fn_create_theme_logos_by_layout_id($this->theme_name, $layout_id, $this->company_id, false, $style_id); } } return $result; }
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'])); }
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; }
Tygh::$app['view']->assign('countries', fn_get_simple_countries(true, CART_LANGUAGE)); Tygh::$app['view']->assign('states', fn_get_all_states()); } elseif ($mode == 'update' || $mode == 'add') { if ($mode == 'add' && fn_allowed_for('ULTIMATE:FREE')) { return array(CONTROLLER_STATUS_DENIED); } $company_id = !empty($_REQUEST['company_id']) ? $_REQUEST['company_id'] : 0; $company_data = !empty($company_id) ? fn_get_company_data($company_id) : array(); if ($mode == 'update' && empty($company_data)) { return array(CONTROLLER_STATUS_NO_PAGE); } if (fn_allowed_for('MULTIVENDOR')) { if (!empty($company_id)) { $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);
/** * 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; }
list($companies, $search) = fn_get_companies($_REQUEST, $auth, Registry::get('settings.Appearance.admin_elements_per_page')); Registry::get('view')->assign('companies', $companies); Registry::get('view')->assign('search', $search); Registry::get('view')->assign('countries', fn_get_simple_countries(true, CART_LANGUAGE)); Registry::get('view')->assign('states', fn_get_all_states()); } elseif ($mode == 'update' || $mode == 'add') { $company_id = !empty($_REQUEST['company_id']) ? $_REQUEST['company_id'] : 0; $company_data = !empty($company_id) ? fn_get_company_data($company_id) : array(); if ($mode == 'update' && empty($company_data)) { return array(CONTROLLER_STATUS_NO_PAGE); } if (fn_allowed_for('MULTIVENDOR')) { if (!empty($company_id)) { $company_data['logos'] = fn_get_logos($company_id); } Registry::get('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']); Registry::get('view')->assign('current_style', $style);
/** * Creates logotypes for companies and assign it to the layout * * @param int $layout_id Layout ID * @param int $company_id Company ID * @param bool $for_company Get logos only for companies * @return array created logo IDs */ function fn_create_theme_logos_by_layout_id($theme_name, $layout_id = 0, $company_id = null, $for_company = false, $style_id = '') { $repo_dest = fn_get_theme_path('[themes]/' . $theme_name, 'C', $company_id, false); $manifest = Themes::factory($theme_name)->getManifest(); $logo_ids = array(); $logo_types = fn_get_logo_types($for_company); Registry::set('runtime.allow_upload_external_paths', true); foreach ($logo_types as $type => $logo) { if (!$for_company) { $logo['image'] = isset($logo['image']) ? $logo['image'] : ''; $image_path = fn_get_logo_image_path($logo['image'], $type, $style_id); } else { $image_path = !empty($manifest['theme']) ? $repo_dest . '/' . $manifest['theme'] : ''; } if (empty($image_path)) { continue; } $logo_ids[$type] = fn_update_logo(array('type' => $type, 'layout_id' => !empty($logo['for_layout']) ? $layout_id : 0, 'image_path' => fn_get_theme_path('[themes]/[theme]/', 'C', $company_id, false) . $image_path, 'style_id' => !empty($logo['single_logo']) ? '' : $style_id), $company_id); } Registry::set('runtime.allow_upload_external_paths', false); return $logo_ids; }
/** * 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; }
/** * Creates logos of missing logo types for given layout and style. * * @param int $layout_id Layout ID * @param string $style_id Style ID */ public function createMissedLogoTypesForLayout($layout_id, $style_id) { if ((fn_allowed_for('ULTIMATE') && !empty($this->company_id) || fn_allowed_for('MULTIVENDOR')) && !empty($layout_id) && !empty($style_id) && !empty($this->theme_name)) { $logos = fn_get_logos($this->company_id, $layout_id, $style_id); $logo_types = fn_get_logo_types(false); $missed_logo_types = array_diff_key($logo_types, $logos); if (!empty($missed_logo_types)) { fn_create_theme_logos_by_layout_id($this->theme_name, $layout_id, $this->company_id, false, $style_id, array_keys($missed_logo_types)); } } }
/** * Creates logotypes for companies and assign it to the layout * * @param int $layout_id Layout ID * @param int $company_id Company ID * @param bool $for_company Get logos only for companies * @return array created logo IDs */ function fn_create_theme_logos_by_layout_id($theme_name, $layout_id = 0, $company_id = 0, $for_company = false) { $repo_dest = fn_get_theme_path('[themes]/' . $theme_name, 'C'); $manifest = Themes::factory($theme_name)->getManifest(); $logo_ids = array(); $logo_types = fn_get_logo_types($for_company); Registry::set('runtime.allow_upload_external_paths', true); foreach ($logo_types as $type => $logo) { if (!$for_company) { $image_path = isset($manifest[$type]) ? $repo_dest . '/' . $manifest[$type] : ''; } else { $image_path = ''; } $logo_ids[$type] = fn_create_logo(array('type' => $type, 'layout_id' => !empty($logo['for_layout']) ? $layout_id : 0, 'image_path' => $image_path), $company_id); } Registry::set('runtime.allow_upload_external_paths', false); return $logo_ids; }
/** * 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) && Registry::get('runtime.company_id')) { $company_id = Registry::get('runtime.company_id'); } if (!is_null($company_id)) { $company_condition = db_quote(' AND company_id = ?i', $company_id); } $types = fn_get_logo_types(); $layout_id = !empty($layout_id) ? $layout_id : Registry::get('runtime.layout.layout_id'); $style_id = !empty($style_id) ? $style_id : Registry::get('runtime.layout.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); $missed_logo = array_diff_key($types, $logos); if (!empty($missed_logo) && (!empty($layout_id) || !empty($style_id))) { foreach ($missed_logo as $type => $type_data) { $type_data['image'] = isset($type_data['image']) ? $type_data['image'] : ''; $logo_path = fn_get_logo_image_path($type_data['image'], $type, $style_id); $_logo = array('layout_id' => $layout_id, 'style_id' => $style_id, 'type' => $type, 'image_path' => fn_get_theme_path('[themes]/[theme]/', 'C', $company_id, false) . $logo_path); if (fn_allowed_for('MULTIVENDOR') && !empty($company_id)) { // Vendors have only one global logo unset($_logo['style_id'], $_logo['layout_id']); } Registry::set('runtime.allow_upload_external_paths', true); fn_update_logo($_logo, $company_id); } $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; }
/** * Creates logotypes for companies and assign it to the layout * * @param int $layout_id Layout ID * @param int $company_id Company ID * @param bool $for_company Get logos only for companies * @return array created logo IDs */ function fn_create_theme_logos_by_layout_id($theme_name, $layout_id = 0, $company_id = null, $for_company = false, $style_id = '', $whitelist_of_logo_types = null) { $repo_dest = fn_get_theme_path('[themes]/' . $theme_name, 'C', $company_id, false); $manifest = Themes::factory($theme_name)->getManifest(); $logo_ids = array(); $logo_types = fn_get_logo_types($for_company); Registry::set('runtime.allow_upload_external_paths', true); foreach ($logo_types as $type => $logo) { // Whitelist of logo types was specified, but it doesn't contain current logo type if (is_array($whitelist_of_logo_types) && !empty($whitelist_of_logo_types) && !in_array($type, $whitelist_of_logo_types)) { continue; } if ($for_company) { $image_path = !empty($manifest['theme']) ? $repo_dest . '/' . $manifest['theme'] : ''; } else { $logo['image'] = isset($logo['image']) ? $logo['image'] : ''; $image_path = fn_get_logo_image_path($logo['image'], $type, $style_id); } if (empty($image_path)) { continue; } $logo_data = array('type' => $type, 'layout_id' => !empty($logo['for_layout']) ? $layout_id : 0, 'image_path' => $image_path, 'style_id' => !empty($logo['single_logo']) ? '' : $style_id); if (fn_allowed_for('MULTIVENDOR') && !empty($company_id)) { // Vendors have only one global logo unset($logo_data['style_id'], $logo_data['layout_id']); } $logo_ids[$type] = fn_update_logo($logo_data, $company_id); } Registry::set('runtime.allow_upload_external_paths', false); return $logo_ids; }