protected function prepare() { $this->assign('wa_url', $this->system->getRootUrl()); $this->assign('wa_backend_url', waSystem::getInstance()->getConfig()->getBackendUrl(true)); $this->assign('wa_app', $this->system->getApp()); $this->assign('wa_app_url', $this->system->getAppUrl(null, true)); $this->assign('wa_app_static_url', $this->system->getAppStaticUrl()); if (!$this->helper) { $this->helper = new waViewHelper($this); } $this->assign('wa', $this->helper); }
public function authAdapters($return_array = false) { $adapters = $this->wa->getAuthAdapters(); if ($return_array) { return $adapters; } if (!$adapters) { return ''; } $html = '<div class="wa-auth-adapters"><ul>'; $url = $this->wa->getRootUrl(false, true) . 'oauth.php?app=' . $this->app() . '&provider='; foreach ($adapters as $adapter) { /** * @var waAuthAdapter $adapter */ $html .= '<li><a href="' . $url . $adapter->getId() . '"><img alt="' . $adapter->getName() . '" src="' . $adapter->getIcon() . '">' . $adapter->getName() . '</a></li>'; } $html .= '</ul><p>'; $html .= _ws("Authorize either by entering your contact information, or through one of the websites listed above."); $html .= '</p></div>'; $html .= <<<HTML <script> \$("div.wa-auth-adapters a").click(function () { var left = (screen.width - 600) / 2; var top = (screen.height - 400) / 2; window.open(\$(this).attr('href'),'oauth', "width=600,height=400,left="+left+",top="+top+",status=no,toolbar=no,menubar=no"); return false; }); </script> HTML; return $html; }
public function getUrl($path, $params = array(), $absolute = false) { if (is_bool($params)) { $absolute = $params; $params = array(); } $parts = explode('/', $path); $app = $parts[0]; if (!$app) { $app = $this->system->getApp(); } if (isset($parts[1])) { $params['module'] = $parts[1]; } if (isset($parts[2])) { $params['action'] = $parts[2]; } $routes = array(); if (!$this->route || $this->route['app'] != $app || !isset($this->route['module']) && isset($params['module']) && $params['module'] != 'frontend' || isset($this->route['module']) && isset($params['module']) && $this->route['module'] != $params['module']) { // find base route if (isset($params['domain'])) { $routes[$params['domain']] = $this->getRoutes($params['domain']); unset($params['domain']); } else { $routes = $this->routes; } // filter by app and module foreach ($routes as $domain => $domain_routes) { foreach ($domain_routes as $r_id => $r) { if (!isset($r['app']) || $r['app'] != $app || isset($params['module']) && isset($r['module']) && $r['module'] != $params['module']) { unset($routes[$domain][$r_id]); } } if (!$routes[$domain]) { unset($routes[$domain]); } } } else { $routes[$this->getDomain()] = array($this->route); } $max = -1; $result = null; foreach ($routes as $domain => $domain_routes) { foreach ($domain_routes as $r) { $i = $this->countParams($r, $params); if (isset($params['module']) && isset($r['module'])) { $i++; } if ($absolute || $this->getDomain() != $domain) { $root_url = self::getUrlByRoute($r, $domain); } else { $root_url = $this->system->getRootUrl(false, true) . self::clearUrl($r['url']); } if ($i > $max) { $max = $i; $result = $root_url; } $app_routes = $this->getAppRoutes($r['app'], $r); foreach ($app_routes as $app_r) { $j = $i + $this->countParams($app_r, $params); if (!isset($params['action']) && !isset($app_r['action'])) { $j++; } $u = $app_r['url']; if (preg_match_all('/<([a-z_]+):?([^>]*)?>/ui', $u, $match, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { $offset = 0; foreach ($match as $m) { $v = $m[1][0]; if (isset($params[$v])) { $u = substr($u, 0, $m[0][1] + $offset) . $params[$v] . substr($u, $m[0][1] + $offset + strlen($m[0][0])); $offset += strlen($params[$v]) - strlen($m[0][0]); $j++; } else { if (substr($u, $m[0][1] - 1, 1) === '(' && substr($u, $m[0][1] + strlen($m[0][0]), 3) === '/)?') { $u = substr($u, 0, $m[0][1] - 1) . substr($u, $m[0][1] + strlen($m[0][0]) + 3); } else { continue 2; } } } } if ($j >= $max || $result === null) { if ($j == $max && $this->getDomain() && $domain != $this->getDomain() && $result) { } else { $max = $j; $result = $root_url . self::clearUrl($u); } } } } } return $result; }
public function url($absolute = false) { return $this->wa->getRootUrl($absolute); }