public function themeAction() { $app_id = $this->getAppId(); $theme_id = waRequest::get('theme'); $parent_themes = array(); $apps = wa()->getApps(); $current_theme = null; foreach ($apps as $theme_app_id => $app) { if (!empty($app['themes']) && ($themes = wa()->getThemes($theme_app_id))) { $themes_data = array(); foreach ($themes as $id => $theme) { if ($app_id == $theme_app_id && $theme_id == $id) { $current_theme = $theme; } $themes_data[$id] = $theme->name; } if ($themes_data) { $parent_themes[$theme_app_id] = array('name' => $app['name'], 'img' => $app['img'], 'themes' => $themes_data); } } } if (!$current_theme) { if (isset($parent_themes[$app_id]) && count($parent_themes[$app_id]['themes']) && ($default = key($parent_themes[$app_id]['themes']))) { $this->displayJson(array('redirect' => "{$this->design_url}theme={$default}&action=theme")); } else { $this->displayJson(array('redirect' => $this->themes_url)); } } else { $this->display(array('design_url' => $this->design_url, 'app' => wa()->getAppInfo($app_id), 'theme' => $current_theme, 'options' => $this->options, 'parent_themes' => $parent_themes, 'path' => waTheme::getThemesPath($app_id)), $this->getConfig()->getRootPath() . '/wa-system/design/templates/Theme.html'); } }
public function themeAction() { $app_id = $this->getAppId(); $theme_id = waRequest::get('theme'); $parent_themes = array(); $apps = wa()->getApps(); /** * @var waTheme $current_theme */ $current_theme = null; foreach ($apps as $theme_app_id => $app) { if (!empty($app['themes']) && ($themes = wa()->getThemes($theme_app_id))) { $themes_data = array(); foreach ($themes as $id => $theme) { if ($app_id == $theme_app_id && $theme_id == $id) { $current_theme = $theme; } $themes_data[$id] = $theme->name; } if ($themes_data) { $parent_themes[$theme_app_id] = array('name' => $app['name'], 'img' => $app['img'], 'themes' => $themes_data); } } } if (!$current_theme) { if (isset($parent_themes[$app_id]) && count($parent_themes[$app_id]['themes']) && ($default = key($parent_themes[$app_id]['themes']))) { $this->displayJson(array('redirect' => "{$this->design_url}theme={$default}&action=theme")); } else { $this->displayJson(array('redirect' => $this->themes_url)); } } else { $settings = $current_theme->getSettings(); if ($current_theme->parent_theme) { $parent_settings = $current_theme->parent_theme->getSettings(); foreach ($parent_settings as &$s) { $s['parent'] = 1; } unset($s); foreach ($settings as $k => $v) { $parent_settings[$k] = $v; } $settings = $parent_settings; } $routes = $this->getRoutes(); $theme_routes = array(); $preview_url = false; foreach ($routes as $r) { if (!$preview_url && $r['app'] == $app_id) { $preview_url = $r['_url'] . '?theme_hash=' . $this->getThemeHash() . '&set_force_theme=' . $theme_id; } } foreach ($this->getRoutes(true) as $r) { if (empty($r['theme'])) { $r['theme'] = 'default'; } if (empty($r['theme_mobile'])) { $r['theme_mobile'] = 'default'; } if ($r['theme'] == $theme_id || $r['theme_mobile'] == $theme_id) { $theme_routes[] = $r; } } $cover = false; if (file_exists($current_theme->getPath() . '/cover.png')) { $cover = $current_theme->getUrl() . 'cover.png'; } elseif ($current_theme->parent_theme && file_exists($current_theme->parent_theme->getPath() . '/cover.png')) { $cover = $current_theme->parent_theme->getUrl() . 'cover.png'; } $route_url = false; if ($_d = waRequest::get('domain')) { $domain_routes = wa()->getRouting()->getByApp(wa()->getApp(), $_d); if (isset($domain_routes[waRequest::get('route')])) { $route_url = htmlspecialchars($_d . '/' . $domain_routes[waRequest::get('route')]['url']); } } if ($current_theme['type'] == waTheme::OVERRIDDEN) { $theme_original = new waTheme($current_theme->id, $current_theme->app_id, waTheme::ORIGINAL); $theme_original_version = $theme_original->version; } else { $theme_original_version = false; } if ($current_theme->parent_theme && $current_theme->parent_theme->type == waTheme::OVERRIDDEN) { $theme_parent_original = new waTheme($current_theme->parent_theme->id, $current_theme->parent_theme->app_id, waTheme::ORIGINAL); $theme_parent_original_version = $theme_parent_original->version; } else { $theme_parent_original_version = false; } $this->display(array('routes' => $routes, 'domains' => wa()->getRouting()->getDomains(), 'preview_url' => $preview_url, 'settings' => $settings, 'design_url' => $this->design_url, 'app' => wa()->getAppInfo($app_id), 'theme' => $current_theme, 'theme_original_version' => $theme_original_version, 'theme_parent_original_version' => $theme_parent_original_version, 'options' => $this->options, 'parent_themes' => $parent_themes, 'theme_routes' => $theme_routes, 'path' => waTheme::getThemesPath($app_id), 'cover' => $cover, 'route_url' => $route_url), $this->getConfig()->getRootPath() . '/wa-system/design/templates/Theme.html'); } }
public function themeAction() { $app_id = $this->getAppId(); $theme_id = waRequest::get('theme'); $parent_themes = array(); $apps = wa()->getApps(); /** * @var waTheme $current_theme */ $current_theme = null; foreach ($apps as $theme_app_id => $app) { if (!empty($app['themes']) && ($themes = wa()->getThemes($theme_app_id))) { $themes_data = array(); foreach ($themes as $id => $theme) { if ($app_id == $theme_app_id && $theme_id == $id) { $current_theme = $theme; } $themes_data[$id] = $theme->name; } if ($themes_data) { $parent_themes[$theme_app_id] = array('name' => $app['name'], 'img' => $app['img'], 'themes' => $themes_data); } } } if (!$current_theme) { if (isset($parent_themes[$app_id]) && count($parent_themes[$app_id]['themes']) && ($default = key($parent_themes[$app_id]['themes']))) { $this->displayJson(array('redirect' => "{$this->design_url}theme={$default}&action=theme")); } else { $this->displayJson(array('redirect' => $this->themes_url)); } } else { $settings = $current_theme->getSettings(); if ($current_theme->parent_theme) { $parent_settings = $current_theme->parent_theme->getSettings(); foreach ($parent_settings as &$s) { $s['parent'] = 1; } unset($s); foreach ($settings as $k => $v) { $parent_settings[$k] = $v; } $settings = $parent_settings; } $routes = $this->getRoutes(); $theme_routes = array(); $preview_url = false; foreach ($routes as $r) { if ($r['theme'] == $theme_id) { $theme_routes[] = $r; } if (!$preview_url && $r['app'] == $app_id) { $preview_url = $r['_url'] . '?theme_hash=' . $this->getThemeHash() . '&set_force_theme=' . $theme_id; } } $this->display(array('routes' => $routes, 'domains' => wa()->getRouting()->getDomains(), 'preview_url' => $preview_url, 'settings' => $settings, 'design_url' => $this->design_url, 'app' => wa()->getAppInfo($app_id), 'theme' => $current_theme, 'options' => $this->options, 'parent_themes' => $parent_themes, 'theme_routes' => $theme_routes, 'path' => waTheme::getThemesPath($app_id)), $this->getConfig()->getRootPath() . '/wa-system/design/templates/Theme.html'); } }