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; }
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() { $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); } }
<?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; } }