/** * 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); }