Exemple #1
0
 protected function robotsToString($app_id, $route, $robots)
 {
     $url = waRouting::getDomainUrl($this->domain, false) . '/' . waRouting::clearUrl($route);
     $result = "# wa " . $app_id . " " . $route . "\n";
     foreach ($robots as $row) {
         if (strpos($row[1], '[URL]') !== false) {
             $row[1] = str_replace('[URL]', $url, $row[1]);
         }
         $result .= $row[0] . ": " . $row[1] . "\n";
     }
     $result .= "# wa " . $app_id . "\n";
     return $result;
 }
 /**
  * Returns subtree
  *
  * @param int $id
  * @param int $depth related depth default is unlimited
  * @param bool $escape
  * @param array $where
  * @return array
  */
 public function getTree($id, $depth = null, $escape = false, $route = null)
 {
     $where = array();
     if ($id) {
         $parent = $this->getById($id);
         $left = (int) $parent[$this->left];
         $right = (int) $parent[$this->right];
     } else {
         $left = $right = 0;
     }
     if (!$id && $depth == null && $route && ($cache = wa('shop')->getCache())) {
         $cache_key = waRouting::clearUrl($route);
         $data = $cache->get($cache_key, 'categories');
     }
     if (empty($data)) {
         $sql = "SELECT c.* FROM {$this->table} c";
         if ($id) {
             $where[] = "c.`{$this->left}` >= i:left";
             $where[] = "c.`{$this->right}` <= i:right";
         }
         if ($depth !== null) {
             $depth = max(0, intval($depth));
             if ($id && $parent) {
                 $depth += (int) $parent[$this->depth];
             }
             $where[] = "c.`{$this->depth}` <= i:depth";
         }
         if ($route) {
             $sql .= " LEFT JOIN shop_category_routes cr ON c.id = cr.category_id";
             $where[] = "c.status = 1";
             $where[] = "cr.route IS NULL OR cr.route = '" . $this->escape($route) . "'";
         }
         if ($where) {
             $sql .= " WHERE (" . implode(') AND (', $where) . ')';
         }
         $sql .= " ORDER BY c.`{$this->left}`";
         $data = $this->query($sql, array('left' => $left, 'right' => $right, 'depth' => $depth))->fetchAll($this->id);
         if (!$id && $depth == null && $route && $cache) {
             $cache->set($cache_key, $data, 3600, 'categories');
         }
     }
     if ($escape) {
         foreach ($data as &$item) {
             $item['name'] = htmlspecialchars($item['name']);
         }
         unset($item);
     }
     return $data;
 }
 protected function getRoutes()
 {
     $routes = wa()->getRouting()->getByApp($this->getAppId());
     $result = array();
     $domain = siteHelper::getDomain();
     if (isset($routes[$domain])) {
         foreach ($routes[$domain] as $route_id => $route) {
             $route['_id'] = $route_id;
             $route['_domain'] = $domain;
             $route['_url'] = waRouting::getUrlByRoute($route, $domain);
             $route['_url_title'] = $domain . '/' . waRouting::clearUrl($route['url']);
             $result[] = $route;
         }
     }
     return $result;
 }
 /**
  * @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 pages($parent_id = 0, $with_params = true)
 {
     if (is_bool($parent_id)) {
         $with_params = $parent_id;
         $parent_id = 0;
     }
     try {
         $page_model = $this->getPageModel();
         $domain = wa()->getRouting()->getDomain(null, true);
         if ($this->wa->getConfig()->getApplication() == wa()->getRouting()->getRoute('app')) {
             $route = wa()->getRouting()->getRoute('url');
             $url = $this->wa->getAppUrl(null, true);
         } else {
             $routes = wa()->getRouting()->getByApp($this->wa->getConfig()->getApplication(), $domain);
             if ($routes) {
                 $route = end($routes);
                 $route = $route['url'];
                 $url = wa()->getRootUrl(false, true) . waRouting::clearUrl($route);
             } else {
                 return array();
             }
         }
         $pages = null;
         $cache_key = $domain . '/' . waRouting::clearUrl($route);
         if ($cache = $this->wa->getCache()) {
             $pages = $cache->get($cache_key, 'pages');
         }
         if ($pages === null) {
             $pages = $page_model->getPublishedPages($domain, $route);
             if ($with_params && $pages) {
                 $page_params_model = $page_model->getParamsModel();
                 $data = $page_params_model->getByField('page_id', array_keys($pages), true);
                 foreach ($data as $row) {
                     if (isset($pages[$row['page_id']])) {
                         $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);
             foreach ($pages as $page_id => $page) {
                 if ($page['parent_id'] && isset($pages[$page['parent_id']])) {
                     $pages[$page['parent_id']]['childs'][] =& $pages[$page_id];
                 }
             }
             if ($cache) {
                 $cache->set($cache_key, $pages, 3600, 'pages');
             }
         }
         if ($parent_id) {
             return isset($pages[$parent_id]['childs']) ? $pages[$parent_id]['childs'] : array();
         }
         foreach ($pages as $page_id => $page) {
             if ($page['parent_id']) {
                 unset($pages[$page_id]);
             }
         }
         return $pages;
     } catch (Exception $e) {
         return array();
     }
 }
 protected function getRoutes($all = false)
 {
     $routes = wa()->getRouting()->getByApp($this->getAppId());
     $result = array();
     foreach ($routes as $d => $domain_routes) {
         foreach (array_reverse($domain_routes, true) as $route_id => $route) {
             $route['_id'] = $route_id;
             $route['_domain'] = $d;
             $route['_url'] = waRouting::getUrlByRoute($route, $d);
             $route['_url_title'] = $d . '/' . waRouting::clearUrl($route['url']);
             $result[] = $route;
         }
     }
     return $result;
 }
 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];
             }
         }
         foreach ($pages as $page_id => $page) {
             if ($page['parent_id']) {
                 unset($pages[$page_id]);
             }
         }
         return $pages;
     } catch (Exception $e) {
         return array();
     }
 }