public function update($only_if_not_modified = true) { if (!$this->path_custom || $this->type != self::OVERRIDDEN) { return true; } $files = $this->getFiles(); $modified = array(); foreach ($files as $f_id => $f) { if (!empty($f['modified'])) { $modified[] = $f_id; break; } } if ($only_if_not_modified && $modified) { return false; } $img_files = array(); foreach ($this->getSettings() as $s) { if (ifset($s['control_type']) == 'image' && !empty($s['value'])) { $img_files[] = $s['value']; } } $source_path = $this->path_original; $target_path = $this->path_custom; $list_files = waFiles::listdir($source_path); $skip_pattern = '/\\.(files\\.md5|cvs|svn|git|php\\d*)$/'; foreach ($list_files as $f) { // ignore files if ($f !== 'build.php') { foreach ((array) $skip_pattern as $pattern) { if (preg_match($pattern, $f)) { continue 2; } } } // ignore image settings and modified if ($f == 'theme.xml' || in_array($f, $img_files) || in_array($f, $modified)) { continue; } try { waFiles::copy($source_path . '/' . $f, $target_path . '/' . $f); } catch (waException $e) { } } if ($this->type == self::OVERRIDDEN) { $theme_original = new waTheme($this->id, $this->app_id, self::ORIGINAL); $this->version = $theme_original->version; foreach ($theme_original->getFiles(true) as $f_id => $f) { if (empty($files[$f_id])) { $this->setFiles(array($f_id => $f)); } } foreach ($theme_original->getSettings('full') as $var => $s) { if (!isset($this->info['settings'][$var])) { $this->info['settings'][$var] = $s; $this->settings[$var]['value'] = ifset($s['value'], ''); $this->changed['settings'][$var] = true; } else { $old_s = $this->info['settings'][$var]; if (ifset($old_s['control_type']) != ifset($s['control_type']) || ifset($old_s['options']) != ifset($s['options'])) { $s['value'] = ifset($old_s['value'], ''); $this->info['settings'][$var] = $s; $this->settings[$var]['value'] = $s['value']; $this->changed['settings'][$var] = true; } } } $this->save(); } return true; }
/** * @param string $theme_id * @return array */ public function themeSettings($theme_id) { $app_id = $this->wa->getConfig()->getApplication(); $theme = new waTheme($theme_id, $app_id); return $theme->getSettings(true); }
/** * Set template directory and global valiables. * * @param waTheme $theme Instance of theme object * @param string $template Path to template or resource string specifying template * @return bool */ public function setThemeTemplate($theme, $template) { $this->assign('wa_active_theme_path', $theme->path); $this->assign('wa_active_theme_url', $this->getStaticUrl($theme->url)); $theme_settings = $theme->getSettings(true); $theme_settings_config = $theme->getSettings(); $locales = $theme->getLocales(); $version = $theme->version(true); $file = $theme->getFile($template); if ($parent_theme = $theme->parent_theme) { $edition = $theme->edition + $parent_theme->edition; if (!empty($file['parent'])) { if ($parent_theme->version($edition) > $version) { $version = $parent_theme->version($edition); } else { $version = $theme->version($edition); } $theme = $parent_theme; } $this->assign('wa_parent_theme_url', $this->getStaticUrl($parent_theme->url)); $this->assign('wa_parent_theme_path', $parent_theme->path); if ($parent_settings = $parent_theme->getSettings(true)) { $theme_settings = $theme_settings + $parent_settings; foreach ($parent_theme->getSettings() as $k => $v) { if (!isset($theme_settings_config[$k])) { $v['parent'] = 1; $theme_settings_config[$k] = $v; } } } if ($parent_theme->getLocales()) { $locales += $parent_theme->getLocales(); } } $this->assign('wa_theme_version', $version); waLocale::setStrings($locales); $this->assign('theme_settings', $theme_settings); $this->assign('theme_settings_config', $theme_settings_config); $this->assign('wa_theme_url', $this->getStaticUrl($theme->url)); $this->assign('wa_real_theme_url', $theme->url); $this->setTemplateDir($theme->path); return file_exists($theme->path . '/' . $template); }
/** * Set template directory and global valiables. * * @param waTheme $theme Instance of theme object * @param string $template Path to template or resource string specifying template * @return bool */ public function setThemeTemplate($theme, $template) { $this->assign('wa_active_theme_path', $theme->path); $this->assign('wa_active_theme_url', $theme->url); $this->assign('wa_theme_version', $theme->version()); $theme_settings = $theme->getSettings(true); $locales = $theme->getLocales(); $file = $theme->getFile($template); if ($parent_theme = $theme->parent_theme) { if (!empty($file['parent'])) { $theme = $parent_theme; } $this->assign('wa_parent_theme_url', $parent_theme->url); $this->assign('wa_parent_theme_path', $parent_theme->path); if ($parent_settings = $parent_theme->getSettings(true)) { $theme_settings = $theme_settings + $parent_settings; } if ($parent_theme->getLocales()) { $locales += $parent_theme->getLocales(); } } waLocale::setStrings($locales); $this->assign('theme_settings', $theme_settings); $this->assign('wa_theme_url', $theme->url); $this->setTemplateDir($theme->path); return file_exists($theme->path . '/' . $template); }