public function execute() { $name = mb_strtolower(rtrim(waRequest::post('name'), '/')); $domain_model = new siteDomainModel(); $data = array(); if (!preg_match('!^[a-z0-9/\\._-]+$!i', $name)) { $data['title'] = $name; $idna = new waIdna(); $name = $idna->encode($name); } $data['name'] = $name; if ($domain_model->getByName($name)) { $this->errors = sprintf(_w("Website with a domain name %s is already registered in this Webasyst installation. Delete %s website (Site app > Settings > %s) to be able to use it's domain name for another website."), $name, $name, $name); return; } $this->response['id'] = $domain_model->insert($data); $this->log('site_add'); // add default routing $path = $this->getConfig()->getPath('config', 'routing'); if (file_exists($path)) { $routes = (include $path); } else { $routes = array(); } if (!isset($routes[$name])) { $routes[$name]['site'] = array('url' => '*', 'app' => 'site'); waUtils::varExportToFile($routes, $path); } }
public function defaultAction() { $app_id = $this->getAppId(); $app = wa()->getAppInfo($app_id); if (empty($app['themes'])) { throw new waException('App does not support themes.'); } $themes = wa()->getThemes($app_id); $routes = $this->getRoutes(); $themes_routes = $this->getThemesRoutes($themes, $routes); $themes = $this->sortThemes($themes, $themes_routes); $template = $this->getConfig()->getRootPath() . '/wa-system/design/templates/Design.html'; $routing_url = false; if (wa()->appExists('site') && $routes) { reset($routes); $r = current($routes); wa('site'); $domain_model = new siteDomainModel(); $d = $domain_model->getByName($r['_domain']); if ($this->getUser()->getRights('site', 'domain.' . $d['id'])) { $routing_url = wa()->getAppUrl('site') . '?domain_id=' . $d['id'] . '#/routing/' . $r['_id'] . '/'; } } $this->display(array('template_path' => $this->getConfig()->getRootPath() . '/wa-system/design/templates/', 'design_url' => $this->design_url, 'themes_url' => $this->themes_url, 'themes' => $themes, 'themes_routes' => $themes_routes, 'app_id' => $app_id, 'app' => $app, 'routing_url' => $routing_url, 'options' => $this->options), $template); }
public function execute() { $domain_model = new siteDomainModel(); $domain = $domain_model->getByName($this->domain); if (!$domain) { return; } // get all routes of the app site $routes = $this->getRoutes(); $page_model = new sitePageModel(); foreach ($routes as $r) { $exclude_ids = isset($r['_exclude']) ? $r['_exclude'] : array(); $sql = "SELECT id, name, title, url, create_datetime, update_datetime FROM " . $page_model->getTableName() . ' WHERE domain_id = i:domain_id AND status = 1' . ($exclude_ids ? " AND id NOT IN (:ids)" : '') . ' ORDER BY sort'; $pages = $page_model->query($sql, array('domain_id' => $domain['id'], 'ids' => $exclude_ids))->fetchAll('id'); // get part of url by route $u = $this->getUrlByRoute($r); foreach ($pages as $p) { if (!$p['url']) { $priority = 1; $change = self::CHANGE_WEEKLY; } else { $priority = 0.2; $change = self::CHANGE_MONTHLY; } $p['url'] = $u . $p['url']; if (strpos($p['url'], '<') === false) { $this->addUrl($p['url'], $p['update_datetime'], $change, $priority); } } } }
public function execute() { $name = rtrim(waRequest::post('name'), '/'); $domain_model = new siteDomainModel(); $data = array(); if (!preg_match('!^[a-z0-9/\\._-]+$!i', $name)) { $data['title'] = $name; $idna = new waIdna(); $name = $idna->encode($name); } $data['name'] = $name; $this->response['id'] = $domain_model->insert($data); $this->log('site_add'); // add default routing $path = $this->getConfig()->getPath('config', 'routing'); if (file_exists($path)) { $routes = (include $path); } else { $routes = array(); } if (!isset($routes[$name])) { $routes[$name]['site'] = array('url' => '*', 'app' => 'site'); waUtils::varExportToFile($routes, $path); } }
public function execute() { $domain_model = new siteDomainModel(); $domain = $domain_model->getByName($this->domain); if (!$domain) { return; } // get all routes of the app site $routes = $this->getRoutes(); $page_model = new sitePageModel(); foreach ($routes as $r) { $sql = "SELECT id, parent_id, name, title, full_url as url, create_datetime, update_datetime\n FROM " . $page_model->getTableName() . ' WHERE domain_id = i:domain_id AND route = s:route AND status = 1 ORDER BY sort'; $pages = $page_model->query($sql, array('domain_id' => $domain['id'], 'route' => $r['url']))->fetchAll('id'); // get part of url by route $u = $this->getUrlByRoute($r); foreach ($pages as $p) { if (!$p['url']) { $priority = 1; $change = self::CHANGE_WEEKLY; } else { $priority = $p['parent_id'] ? 0.2 : 0.6; $change = self::CHANGE_MONTHLY; } $p['url'] = $u . $p['url']; if (strpos($p['url'], '<') === false) { $this->addUrl($p['url'], $p['update_datetime'], $change, $priority); } } } }
public function updateRoute($domain, $old_route, $new_route) { $domain_model = new siteDomainModel(); $domain = $domain_model->getByName($domain); if ($domain) { return $this->updateByField(array('domain_id' => $domain['id'], 'route' => $old_route), array('route' => $new_route)); } }
public function moveAction() { $page_model = $this->getPageModel(); $parent_id = waRequest::post('parent_id'); if (!$parent_id) { $domain_model = new siteDomainModel(); $domain = $domain_model->getByName(waRequest::post('domain')); $parent_id = array('domain_id' => $domain ? $domain['id'] : 0, 'route' => waRequest::post('route')); } $result = $page_model->move(waRequest::post('id', 0, 'int'), $parent_id, waRequest::post('before_id', 0, 'int')); $this->displayJson($result, $result ? null : _w('Database error')); }
public function pages($parent_id = 0, $with_params = true) { if (is_bool($parent_id)) { $with_params = $parent_id; $parent_id = 0; } try { $domain_model = new siteDomainModel(); $domain = $domain_model->getByName(waSystem::getInstance()->getRouting()->getDomain(null, true)); $page_model = new sitePageModel(); $exclude_ids = waRequest::param('_exclude'); $sql = "SELECT id, parent_id, name, title, full_url, url, create_datetime, update_datetime FROM " . $page_model->getTableName() . ' WHERE domain_id = i:domain_id AND route = s:route AND status = 1' . ($exclude_ids ? " AND id NOT IN (:ids)" : '') . ' ORDER BY sort'; $pages = $page_model->query($sql, array('domain_id' => $domain['id'], 'ids' => $exclude_ids, 'route' => wa()->getRouting()->getRoute('url')))->fetchAll('id'); if ($with_params) { $page_params_model = new sitePageParamsModel(); $data = $page_params_model->getByField('page_id', array_keys($pages), true); foreach ($data as $row) { $pages[$row['page_id']][$row['name']] = $row['value']; } } // get current rool url $url = $this->wa->getAppUrl(null, true); foreach ($pages as &$page) { $page['url'] = $url . $page['full_url']; if (!isset($page['title']) || !$page['title']) { $page['title'] = $page['name']; } foreach ($page as $k => $v) { if ($k != 'content') { $page[$k] = htmlspecialchars($v); } } } unset($page); // make tree foreach ($pages as $page_id => $page) { if ($page['parent_id'] && isset($pages[$page['parent_id']])) { $pages[$page['parent_id']]['childs'][] =& $pages[$page_id]; } } foreach ($pages as $page_id => $page) { if ($page['parent_id']) { unset($pages[$page_id]); } } return $pages; } catch (Exception $e) { return array(); } }
protected function getDomainId() { if (!$this->domain_id) { $domain = $this->getDomain(); $domain_model = new siteDomainModel(); if ($d = $domain_model->getByName($domain)) { $this->domain_id = $d['id']; } else { if (substr($domain, 0, 4) == 'www.') { $domain = substr($domain, 4); } else { $domain = 'www.' . $domain; } if ($d = $domain_model->getByName($domain)) { $this->domain_id = $d['id']; } } } return $this->domain_id; }
public function execute() { $domain_id = waRequest::post('domain_id'); if ($domain_id) { // check domain $domain_model = new siteDomainModel(); $domain = $domain_model->getById($domain_id); $route = waRequest::post('route'); if ($domain) { // delete from routing $path = $this->getConfig()->getPath('config', 'routing'); if (file_exists($path)) { $routes = (include $path); if (isset($routes[$domain['name']])) { // delete route if ($route && isset($routes[$domain['name']][$route])) { unset($routes[$domain['name']][$route]); // save new routing config waUtils::varExportToFile($routes, $path); } elseif (!$route) { unset($routes[$domain['name']]); // save new routing config waUtils::varExportToFile($routes, $path); } } } if (!$route) { // delete site files (favicon, etc.) waFiles::delete(wa()->getDataPath('data/' . $domain['name']), true); // delete site from db $domain_model->deleteById($domain_id); $this->logAction('site_delete'); } } } }
public static function getDomains($full = false) { if (!self::$domains) { $domain_model = new siteDomainModel(); $q = $domain_model->select('*'); if (!wa()->getUser()->isAdmin('site')) { $domain_ids = wa()->getUser()->getRights('site', 'domain.%', false); if ($domain_ids) { $q->where("id IN ('" . implode("','", $domain_ids) . "')"); } else { $q->where('0'); } } self::$domains = $q->fetchAll('id'); if (wa()->getUser()->isAdmin('site')) { $routes = wa('wa-system')->getConfig()->getRouting(); // hide default routing (for all domains) if (isset($routes['default'])) { unset($routes['default']); } $ds = array(); foreach (self::$domains as $d) { $ds[] = $d['name']; } foreach ($routes as $r_id => $r) { if (!is_array($r)) { unset($routes[$r_id]); } } $new_domains = array_diff(array_keys($routes), $ds); if ($new_domains) { foreach ($new_domains as $d) { $domain_model->insert(array('name' => $d)); } self::$domains = $domain_model->select('*')->fetchAll('id'); } if (!self::$domains) { $domain_model->insert(array('name' => wa()->getConfig()->getDomain())); self::$domains = $domain_model->select('*')->fetchAll('id'); } } // hide default routing (for all domains) if (isset(self::$domains['default'])) { unset(self::$domains['default']); } } $result = array(); foreach (self::$domains as $id => $d) { $result[$id] = $d['title'] ? $d['title'] : $d['name']; if ($full) { $result[$id] = array('name' => $d['name'], 'title' => $result[$id], 'style' => $d['style']); } } return $result; }
protected function getThemesRoutes(&$themes, $routes) { $hash = $this->getThemeHash(); $themes_routes = array(); $preview_url = ''; if (wa()->appExists('site')) { wa('site'); $model = new siteDomainModel(); $domains = $model->select('id,name')->fetchAll('name', true); $routing_url = wa()->getAppUrl('site'); } else { $domains = array(); } $domain = wa()->getRouting()->getDomain(); foreach ($routes as $r) { $t_id = isset($r['theme']) ? $r['theme'] : 'default'; if (!isset($themes[$t_id])) { $t_id = 'default'; } $r['theme'] = $t_id; $themes[$t_id]['is_used'] = true; if (isset($r['theme_mobile'])) { $themes[$r['theme_mobile']]['is_used'] = true; } $url = $r['_url']; if (!$preview_url && $r['_domain'] == $domain) { $preview_url = $url; } $r['_preview_url'] = $url; if (isset($domains[$r['_domain']]) && $this->getUser()->getRights('site', 'domain.' . $domains[$r['_domain']])) { $r['_routing_url'] = $routing_url . '?module=routing&action=edit&domain_id=' . $domains[$r['_domain']] . '&route=' . $r['_id']; } $themes_routes[] = $r; } $preview_params = strpos($preview_url, '?') === false ? '?' : '&'; $preview_params .= 'theme_hash=' . $hash . '&set_force_theme='; foreach ($themes as $t_id => $theme) { if (!isset($theme['preview_url'])) { $themes[$t_id]['preview_url'] = $preview_url ? $preview_url . $preview_params . $t_id : ''; } $themes[$t_id]['preview_name'] = preg_replace('/^.*?\\/\\/(.*?)\\?.*$/', '$1', $themes[$t_id]['preview_url']); if (!$theme['is_used']) { $themes_routes[] = $t_id; } } return $themes_routes; }
public function execute() { $path = $this->getConfig()->getPath('config', 'routing'); if (file_exists($path)) { $routes = (include $path); } else { $routes = array(); } $domain = siteHelper::getDomain(); $url = mb_strtolower(rtrim(waRequest::post('url'), '/')); if ($url != $domain) { $domain_model = new siteDomainModel(); // domain already exists if ($domain_model->getByName($url)) { $this->errors = sprintf(_w("Website with a domain name %s is already registered in this Webasyst installation. Delete %s website (Site app > %s > Settings) to be able to use it's domain name for another website."), $url, $url, $url); return; } $domain_model->updateById(siteHelper::getDomainId(), array('name' => $url)); $routes[$url] = $routes[$domain]; unset($routes[$domain]); // move configs $old = $this->getConfig()->getConfigPath('domains/' . $domain . '.php'); if (file_exists($old)) { waFiles::move($old, $this->getConfig()->getConfigPath('domains/' . $url . '.php')); } $old = wa()->getDataPath('data/' . $domain . '/', true, 'site', false); if (file_exists($old)) { waFiles::move($old, wa()->getDataPath('data/' . $url . '/', true)); clearstatcache(); try { waFiles::delete($old, true); } catch (waException $e) { } } $domain = $url; siteHelper::setDomain(siteHelper::getDomainId(), $domain); } // save wa_apps $domain_config_path = $this->getConfig()->getConfigPath('domains/' . $domain . '.php'); if (file_exists($domain_config_path)) { $domain_config = (include $domain_config_path); } else { $domain_config = array(); } $title = waRequest::post('title'); $style = waRequest::post('background'); if (!$style || substr($style, 0, 1) == '.') { if ($s = $this->saveBackground()) { $style = '.' . $s; } } $domain_model = new siteDomainModel(); $domain_model->updateById(siteHelper::getDomainId(), array('title' => $title, 'style' => $style)); $save_config = false; if ($title) { $domain_config['name'] = $title; $save_config = true; } else { if (isset($domain_config['name'])) { unset($domain_config['name']); $save_config = true; } } waUtils::varExportToFile($routes, $path); if (waRequest::post('wa_apps_type')) { $apps = waRequest::post('apps'); if (!$domain_config) { // create directory waFiles::create($domain_config_path); } $domain_config['apps'] = array(); foreach ($apps['url'] as $i => $u) { $domain_config['apps'][] = array('url' => $u, 'name' => $apps['name'][$i]); } $save_config = true; } else { if (isset($domain_config['apps'])) { unset($domain_config['apps']); $save_config = true; } } if (waRequest::post('cdn')) { $domain_config['cdn'] = waRequest::post('cdn'); $save_config = true; } elseif (!empty($domain_config['cdn'])) { unset($domain_config['cdn']); $save_config = true; } // save other settings foreach (array('head_js', 'google_analytics') as $key) { if (!empty($domain_config[$key]) || waRequest::post($key)) { $domain_config[$key] = waRequest::post($key); $save_config = true; } } if ($save_config && !waUtils::varExportToFile($domain_config, $domain_config_path)) { $this->errors = sprintf(_w('Settings could not be saved due to the insufficient file write permissions for the "%s" folder.'), 'wa-config/apps/site/domains'); } $this->saveFavicon(); $this->saveTouchicon(); $this->saveRobots(); $this->logAction('site_edit'); }
public function execute() { $domain_model = new siteDomainModel(); $this->response['domains'] = $domain_model->getAll(); }
<?php $domain_model = new siteDomainModel(); $domain = $this->getDomain(); if ($d = $domain_model->getByName($domain)) { $domain_id = $d['id']; } else { $domain_id = $domain_model->insert(array('name' => $domain)); } $page_model = new sitePageModel(); $data = array('domain_id' => $domain_id, 'name' => _w('Welcome'), 'title' => '', 'content' => file_get_contents(dirname(__FILE__) . '/data/welcome.html'), 'url' => '', 'full_url' => '', 'status' => 1); $routes = wa()->getRouting()->getRoutes($domain); foreach ($routes as $r_id => $r) { if (is_array($r) && isset($r['app']) && $r['app'] == 'site') { $data['route'] = $r['url']; $page_model->add($data); break; } }
public function pages($parent_id = 0, $with_params = true) { if (is_bool($parent_id)) { $with_params = $parent_id; $parent_id = 0; } try { $domain_model = new siteDomainModel(); $domain = $domain_model->getByName(waSystem::getInstance()->getRouting()->getDomain(null, true)); $page_model = new sitePageModel(); $sql = "SELECT id, parent_id, name, title, full_url, url, create_datetime, update_datetime FROM " . $page_model->getTableName() . ' WHERE domain_id = i:domain_id AND route = s:route AND status = 1 ORDER BY sort'; if (wa()->getApp() == 'site') { $route = wa()->getRouting()->getRoute('url'); $url = $this->wa->getAppUrl(null, true); } else { $routes = wa()->getRouting()->getByApp('site', $domain['name']); if ($routes) { $route = current($routes); $route = $route['url']; $url = wa()->getRootUrl(false, true) . waRouting::clearUrl($route); } else { return array(); } } $pages = $page_model->query($sql, array('domain_id' => $domain['id'], 'route' => $route))->fetchAll('id'); if ($with_params) { $page_params_model = new sitePageParamsModel(); $data = $page_params_model->getByField('page_id', array_keys($pages), true); foreach ($data as $row) { $pages[$row['page_id']][$row['name']] = $row['value']; } } foreach ($pages as &$page) { $page['url'] = $url . $page['full_url']; if (!isset($page['title']) || !$page['title']) { $page['title'] = $page['name']; } foreach ($page as $k => $v) { if ($k != 'content') { $page[$k] = htmlspecialchars($v); } } } unset($page); // make tree foreach ($pages as $page_id => $page) { if ($page['parent_id'] && isset($pages[$page['parent_id']])) { $pages[$page['parent_id']]['childs'][] =& $pages[$page_id]; } } if ($parent_id) { return isset($pages[$parent_id]['childs']) ? $pages[$parent_id]['childs'] : array(); } foreach ($pages as $page_id => $page) { if ($page['parent_id'] && $page_id != $parent_id) { unset($pages[$page_id]); } } return $pages; } catch (Exception $e) { return array(); } }
public function init() { $model = new siteDomainModel(); $items = $model->select('id, name')->fetchAll('id', true); $this->addItem('domain', _w('Available sites'), 'list', array('items' => $items, 'value' => bindec('11111111'))); }
/** * @param $domain * @param string $domain_name * @param bool $escape * @return array */ public function getFrontendApps($domain, $domain_name = null, $escape = false) { $routes = $this->getRouting()->getRoutes($domain); $path = waRouting::getDomainUrl($domain, false); $apps = array(); $all_apps = $this->getApps(); foreach ($routes as $r) { if (isset($r['app']) && isset($all_apps[$r['app']])) { if (!empty($r['private'])) { continue; } $url = $r['url']; $url = waRouting::clearUrl($url); if (strpos($url, '<') !== false) { continue; } if (isset($r['_name'])) { $name = $r['_name']; } elseif ($r['app'] == 'site') { if ($domain_name) { $name = $domain_name; } else { if (!isset(self::$instances['site'])) { self::getInstance('site'); } if (!isset($domain_info)) { $domain_model = new siteDomainModel(); $domain_info = $domain_model->getByName($domain); } $name = $domain_info && $domain_info['title'] ? $domain_info['title'] : $this->accountName(); } } else { $name = $all_apps[$r['app']]['name']; } $apps[] = array('url' => $path . '/' . $url, 'name' => $escape ? htmlspecialchars($name) : $name); } } return array_reverse($apps); }
public function execute() { $path = $this->getConfig()->getPath('config', 'routing'); if (file_exists($path)) { $routes = (include $path); } else { $routes = array(); } $domain = siteHelper::getDomain(); $url = waRequest::post('url'); if ($url != $domain) { $domain_model = new siteDomainModel(); $domain_model->updateById(siteHelper::getDomainId(), array('name' => $url)); $routes[$url] = $routes[$domain]; unset($routes[$domain]); } // save wa_apps $domain_config_path = $this->getConfig()->getConfigPath('domains/' . $domain . '.php'); if (file_exists($domain_config_path)) { $domain_config = (include $domain_config_path); } else { $domain_config = array(); } $title = waRequest::post('title'); $style = waRequest::post('background'); if (!$style || substr($style, 0, 1) == '.') { if ($s = $this->saveBackground()) { $style = '.' . $s; } } $domain_model = new siteDomainModel(); $domain_model->updateById(siteHelper::getDomainId(), array('title' => $title, 'style' => $style)); $save_config = false; if ($title) { $domain_config['name'] = $title; $save_config = true; } else { if (isset($domain_config['name'])) { unset($domain_config['name']); $save_config = true; } } waUtils::varExportToFile($routes, $path); if (waRequest::post('wa_apps_type')) { $apps = waRequest::post('apps'); if (!$domain_config) { // create directory waFiles::create($domain_config_path); } $domain_config['apps'] = array(); foreach ($apps['url'] as $i => $u) { $domain_config['apps'][] = array('url' => $u, 'name' => $apps['name'][$i]); } $save_config = true; } else { if (isset($domain_config['apps'])) { unset($domain_config['apps']); $save_config = true; } } // save other settings foreach (array('head_js', 'google_analytics') as $key) { if (!empty($domain_config[$key]) || waRequest::post($key)) { $domain_config[$key] = waRequest::post($key); $save_config = true; } } if ($save_config && !waUtils::varExportToFile($domain_config, $domain_config_path)) { $this->errors = sprintf(_w('Settings could not be saved due to the insufficient file write permissions for the "%s" folder.'), 'wa-config/apps/site/domains'); } $this->saveFavicon(); $this->saveRobots(); $this->saveAuthSettings(); $this->log('site_edit'); }