Example #1
0
         fn_install_theme($_REQUEST['theme_name'], $company_id);
     } else {
         Settings::instance()->updateValue('theme_name', $_REQUEST['theme_name'], '', true, $company_id);
     }
     $layout = Layout::instance($company_id)->getDefault($_REQUEST['theme_name']);
     if (!empty($_REQUEST['style'])) {
         $theme = Themes::factory(fn_get_theme_path('[theme]', 'C'));
         $theme_manifest = $theme->getManifest();
         if (empty($theme_manifest['converted_to_css'])) {
             Styles::factory($_REQUEST['theme_name'])->setStyle($layout['layout_id'], $_REQUEST['style']);
         } else {
             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']}"))));
         }
     }
     // We need to re-init layout
     fn_init_layout(array('s_layout' => $layout['layout_id']));
     // Delete compiled CSS file
     fn_clear_cache('assets');
 }
 if ($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('assets');
         } 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']}"))));
         }
Example #2
0
 /**
  * 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);
 }