/** * Copy style * @param string $from style ID to copy from * @param string $to style ID to copy to * @return boolean true on success, false otherwise */ public function copy($from, $to) { $from = fn_basename($from); $to = fn_basename($to); $style_file_from = $this->getStyleFile($from); $style_file_to = $this->getStyleFile($to, 'less'); if (is_file($style_file_from)) { if (fn_copy($style_file_from, $style_file_to)) { $types = array('css'); foreach ($types as $type) { $style_file_from = $this->getStyleFile($from, $type); if (file_exists($style_file_from)) { fn_copy($style_file_from, $this->getStyleFile($to, $type)); } } fn_copy(Patterns::instance($this->params)->getPath($from), Patterns::instance($this->params)->getPath($to)); $content = fn_get_contents($style_file_to); $content = str_replace('/patterns/' . $from . '/', '/patterns/' . $to . '/', $content); fn_put_contents($style_file_to, $content); // Clone logos for new style $logos = db_get_array('SELECT * FROM ?:logos WHERE style_id = ?s AND company_id = ?i', $from, $this->company_id); foreach ($logos as $logo) { $object_id = fn_update_logo(array('type' => $logo['type'], 'layout_id' => $logo['layout_id'], 'style_id' => $to), $this->company_id); fn_clone_image_pairs($object_id, $logo['logo_id'], 'logos'); } return true; } } return false; }
function fn_gift_certificates_install($d, $action) { if ($action == 'install') { if (fn_allowed_for('ULTIMATE')) { $company_ids = fn_get_all_companies_ids(); } else { $company_ids = array(0); } Registry::set('runtime.allow_upload_external_paths', true); foreach ($company_ids as $company_id) { fn_update_logo(array('type' => 'gift_cert', 'image_path' => fn_get_theme_path('[themes]/[theme]/mail/media/', 'C', $company_id, false) . 'images/gift_cert_logo.png'), $company_id); } Registry::set('runtime.allow_upload_external_paths', false); } else { fn_delete_logo('gift_cert'); } }
/** * @deprecated * * Adds logo * * @param array $logo_data logo data (layout_id, image path, type) * @param integer $company_id company ID * @return integer ID of created logo */ function fn_create_logo($logo_data, $company_id = null) { fn_update_logo($logo_data, $company_id); }
/** * 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; }
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_update_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); }
/** * 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); } $style_ids = db_get_hash_single_array('SELECT type, style_id FROM ?:logos WHERE layout_id = ?i AND company_id = ?i', array('type', 'style_id'), $to_layout_id, $target_company_id); // Copy logos $types = fn_get_logo_types(); foreach ($types as $type => $data) { if (!empty($data['for_layout'])) { $object_ids[$type] = fn_update_logo(array('type' => $type, 'layout_id' => $to_layout_id, 'style_id' => $style_ids[$type]), $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; }