public function editAction() { $app_id = $this->getAppId(); $app = wa()->getAppInfo($app_id); $theme_id = waRequest::get('theme'); $theme = new waTheme($theme_id, $app_id); if (($f = waRequest::get('file')) !== '') { if (!$f) { $files = $theme['files']; if (isset($files['index.html'])) { $f = 'index.html'; } else { ksort($files); $f = key($files); } } $file = $theme->getFile($f); $file['id'] = $f; if ($theme->parent_theme_id && $file['parent']) { if (!waTheme::exists($theme->parent_theme_id, $app_id)) { $theme_id = $theme->parent_theme_id; if (strpost($theme_id, ':') !== false) { list($app_id, $theme_id) = explode(':', $theme_id, 2); $app = wa()->getAppInfo($app_id); } throw new waException(sprintf(_ws('Theme %s for “%s” app not found.'), $theme_id, $app['name'])); } $path = $theme->parent_theme->getPath(); $parent_file = $theme->parent_theme->getFile($f); if (empty($file['description'])) { $file['description'] = $parent_file['description']; } } else { $path = $theme->getPath(); } $path .= '/' . $f; $content = file_exists($path) ? file_get_contents($path) : ''; $file['content'] = $content; if ($theme->type == waTheme::OVERRIDDEN) { $file['has_original'] = $theme['type'] == file_exists(wa()->getAppPath('themes/' . $theme_id, $app_id) . '/' . $f); } } else { $file = array('id' => null, 'description' => '', 'custom' => true, 'content' => ''); } $template = $this->getConfig()->getRootPath() . '/wa-system/design/templates/DesignEdit.html'; $data = array('options' => $this->options, 'app_id' => $app_id, 'design_url' => $this->design_url, 'app' => $app, 'file' => $file, 'theme_id' => $theme_id, 'theme' => $theme); if ($theme->parent_theme_id) { $data['parent_theme'] = $theme->parent_theme; } $this->display($data, $template); }
public function editAction() { $app_id = $this->getAppId(); $app = wa()->getAppInfo($app_id); $theme_id = waRequest::get('theme'); $theme = new waTheme($theme_id, $app_id); $theme_files = $theme['files']; if ($theme->parent_theme_id) { foreach ($theme_files as $file => &$f) { if (!empty($f['parent'])) { $parent_file = $theme->parent_theme->getFile($file); if (!empty($parent_file['modified'])) { $f['modified'] = $parent_file['modified']; } } } unset($f); } if (($f = waRequest::get('file')) !== '') { if (!$f) { $files = $theme['files']; if (isset($files['index.html'])) { $f = 'index.html'; } else { ksort($files); $f = key($files); } } $file = $theme->getFile($f); if (!$file && !file_exists($theme->getPath() . '/' . $f)) { $f = 'index.html'; $file = $theme->getFile($f); } $file['id'] = $f; if ($theme->parent_theme_id && !empty($file['parent'])) { if (!waTheme::exists($theme->parent_theme_id, $app_id)) { $theme_id = $theme->parent_theme_id; if (strpos($theme_id, ':') !== false) { list($app_id, $theme_id) = explode(':', $theme_id, 2); $app = wa()->getAppInfo($app_id); } throw new waException(sprintf(_ws('Theme %s for “%s” app not found.'), $theme_id, $app['name'])); } $path = $theme->parent_theme->getPath(); $parent_file = $theme->parent_theme->getFile($f); if (empty($file['description'])) { $file['description'] = ifset($parent_file['description'], ''); } if (!empty($parent_file['modified'])) { $file['modified'] = $parent_file['modified']; } if ($theme->parent_theme->type == waTheme::OVERRIDDEN) { $file['has_original'] = $theme->parent_theme['type'] == file_exists(wa()->getAppPath('themes/' . $theme->parent_theme->id, $theme->parent_theme->app_id) . '/' . $f); } } else { $path = $theme->getPath(); if ($theme->type == waTheme::OVERRIDDEN) { $file['has_original'] = $theme['type'] == file_exists(wa()->getAppPath('themes/' . $theme_id, $app_id) . '/' . $f); } } $path .= '/' . $f; $content = file_exists($path) ? file_get_contents($path) : ''; $file['content'] = $content; } else { $file = array('id' => null, 'description' => '', 'custom' => true, 'content' => ''); } $routes = $this->getRoutes(true); $theme_usages = array(); foreach ($routes as $r) { if (empty($r['theme'])) { $r['theme'] = 'default'; } if ($r['theme'] == $theme_id && $r['_domain'] != waRequest::get('domain') && $r['_id'] != waRequest::get('route')) { $theme_usages[] = htmlspecialchars($r['_domain'] . '/' . $r['url']); } } $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']); } } $template = $this->getConfig()->getRootPath() . '/wa-system/design/templates/DesignEdit.html'; $data = array('options' => $this->options, 'app_id' => $app_id, 'design_url' => $this->design_url, 'app' => $app, 'file' => $file, 'theme_id' => $theme_id, 'theme' => $theme, 'theme_usages' => $theme_usages, 'route_url' => $route_url, 'theme_files' => $theme_files); if ($theme->parent_theme_id) { $data['parent_theme'] = $theme->parent_theme; } $this->display($data, $template); }
/** * Returns id of design theme used in current frontend page. * * @return string */ public static function getTheme() { $app_id = wa()->getConfig()->getApplication(); $key = wa()->getRouting()->getDomain() . '/theme'; if (($theme_hash = self::get('theme_hash')) && ($theme = self::get('set_force_theme')) !== null) { $app_settings_model = new waAppSettingsModel(); $hash = $app_settings_model->get($app_id, 'theme_hash'); $global_hash = $app_settings_model->get('webasyst', 'theme_hash'); if ($theme_hash == md5($hash)) { if ($theme && waTheme::exists($theme)) { wa()->getStorage()->set($app_id . '/' . $key, $theme); return $theme; } else { wa()->getStorage()->del($app_id . '/' . $key); } } elseif ($global_hash && $theme_hash == md5($global_hash)) { if ($theme && waTheme::exists($theme)) { wa()->getStorage()->set($key, $theme); return $theme; } else { wa()->getStorage()->del($key); } } } elseif ((($theme = wa()->getStorage()->get($app_id . '/' . $key)) || ($theme = wa()->getStorage()->get($key))) && waTheme::exists($theme)) { return $theme; } if (self::isMobile()) { return self::param('theme_mobile', 'default'); } return self::param('theme', 'default'); }
/** * Returns the list of previously added JavaScript file URLs. * * @param bool $html Determines whether method must return an HTML string for including JavaScript files or an array of URLs * @param bool $strict Determines whether XHTML format must be used instead of default HTML * @return string|array HTML string or array of URLs */ public function getJs($html = true, $strict = false) { if (!$html) { return $this->js; } $result = ''; foreach ($this->js as $url) { $result .= '<script' . ($strict ? ' type="text/javascript"' : '') . ' src="' . $url . '"></script>' . PHP_EOL; } if (wa()->getEnv() == 'frontend') { $app_id = wa()->getApp(); $key = wa()->getRouting()->getDomain() . '/theme'; $hash = false; if (waRequest::get('theme_hash') && ($theme = waRequest::get('set_force_theme')) !== null) { $hash = waRequest::get('theme_hash'); } elseif (($theme = wa()->getStorage()->get($app_id . '/' . $key)) || ($theme = wa()->getStorage()->get($key))) { $app_settings_model = new waAppSettingsModel(); $hash = $app_settings_model->get($app_id, 'theme_hash'); if (!$hash) { $hash = $app_settings_model->get('webasyst', 'theme_hash'); } if ($hash) { $hash = md5($hash); } } if (!$hash || !$theme || !waTheme::exists($theme)) { return $result; } $theme = new waTheme($theme, $app_id); $theme = $theme['name']; $url = '?theme_hash=' . $hash . '&set_force_theme='; $result .= ' <script type="text/javascript"> $(function () { var div = $("<div></div>"); div.css({ position: "fixed", bottom: 0, left: 0, right: 0, opacity: 0.9, padding: "15px", "text-align": "center", background: "#ffd", "border-top": "4px solid #eea", "border-image": "url(\'' . wa()->getUrl() . 'wa-content/img/recovery-mode-background.png\') 10 10 10 10 repeat", "font-family": "Lucida Grande", "font-size": "14px", "z-index": 100500, }); div.html("' . sprintf(_ws('<strong>%s</strong> theme preview in action'), $theme) . '");'; if (wa()->getUser()->isAuth() && wa()->getUser()->getRights('shop')) { $result .= ' div.prepend(\'<a href="' . $url . '" style="float: right;">' . _ws('Stop preview session') . '</a>\'); div.find("a").click(function () { $("body").append($(\'<iframe style="display:none" src="\' + $(this).attr("href") + \'" />\').load(function () { $(this).remove(); div.remove(); if (location.href.indexOf("theme_hash") != -1) { location.href = location.href.replace(/(theme_hash|set_force_theme)=[^&]*&?/g, ""); } })); return false; });'; } $result .= ' $("body").append(div); }); </script>'; } return $result; }