Tygh::$app['view']->display('views/themes/components/correct_permissions.tpl'); exit; } } else { fn_copy($source, $destination); fn_rm($source); if (defined('AJAX_REQUEST')) { Tygh::$app['ajax']->assign('force_redirection', fn_url('themes.manage')); exit; } } } if ($mode == 'install') { if (!empty($_REQUEST['theme_name'])) { // Copy theme files to design/themes directory fn_install_theme_files($_REQUEST['theme_name'], $_REQUEST['theme_name']); } return array(CONTROLLER_STATUS_OK, 'themes.manage?selected_section=general'); } if ($mode == 'delete') { fn_delete_theme($_REQUEST['theme_name']); } if ($mode == 'set') { $is_exist = Layout::instance()->getList(array('theme_name' => $_REQUEST['theme_name'])); $company_id = Registry::get('runtime.company_id'); if (empty($is_exist)) { // Create new layout fn_install_theme($_REQUEST['theme_name'], $company_id); } else { Settings::instance()->updateValue('theme_name', $_REQUEST['theme_name'], '', true, $company_id); }
/** * Installs theme * * @param int $layout_id layout ID to create logo for * @param string $theme_name theme name * @param int $company_id company ID * @return boolean always true */ function fn_install_theme($theme_name, $company_id = null, $install_layouts = true) { // Copy files fn_install_theme_files($theme_name, $theme_name, true); Settings::instance()->updateValue('theme_name', $theme_name, '', true, $company_id); $repo_dest = fn_get_theme_path('[themes]/' . $theme_name, 'C', $company_id, false); $logo_ids = array(); // Import theme layout $layouts = fn_get_dir_contents($repo_dest . '/layouts/', false, true, '.xml'); // FIXME: Backward compability for layouts if (empty($layouts) && file_exists($repo_dest . '/layouts.xml')) { $layouts = array('../layouts.xml'); } if (!empty($layouts) && $install_layouts) { foreach ($layouts as $layout_name) { $layout_path = fn_normalize_path($repo_dest . '/layouts/' . $layout_name); if (file_exists($layout_path)) { $layout_id = Exim::instance($company_id, 0, $theme_name)->importFromFile($layout_path, array('override_by_dispatch' => true, 'clean_up' => true, 'import_style' => 'create')); if (empty($layout_id)) { continue; } $layout_data = Layout::instance()->get($layout_id); $_o_ids = fn_create_theme_logos_by_layout_id($theme_name, $layout_id, $company_id, false, $layout_data['style_id']); $logo_ids = array_merge($logo_ids, $_o_ids); } } } else { $params = array('theme_name' => $theme_name); $exists = Layout::instance($company_id)->getList($params); if (empty($exists)) { $layout_id = Layout::instance($company_id)->update(array('name' => __('main'), 'theme_name' => $theme_name, 'is_default' => 1)); $layout_data = Layout::instance()->get($layout_id); $logo_ids = fn_create_theme_logos_by_layout_id($theme_name, $layout_id, $company_id, false, $layout_data['style_id']); } } return $logo_ids; }
/** * 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); }