예제 #1
0
 /**
  * Returns the site URL.
  *
  * @return string
  */
 public function getSiteUrl()
 {
     return Craft::getSiteUrl();
 }
예제 #2
0
 /**
  * Returns a URL.
  *
  * @access private
  * @param string       $path
  * @param array|string $params
  * @param              $protocol
  * @param              $dynamicBaseUrl
  * @param              $mustShowScriptName
  * @return string
  */
 private static function _getUrl($path, $params, $protocol, $dynamicBaseUrl, $mustShowScriptName)
 {
     $anchor = '';
     // Normalize the params
     if (is_array($params)) {
         foreach ($params as $name => $value) {
             if (!is_numeric($name)) {
                 if ($name == '#') {
                     $anchor = '#' . $value;
                 } else {
                     if ($value !== null && $value !== '') {
                         $params[] = $name . '=' . $value;
                     }
                 }
                 unset($params[$name]);
             }
         }
         $params = implode('&', array_filter($params));
     } else {
         $params = ltrim($params, '&?');
     }
     if ($dynamicBaseUrl) {
         $baseUrl = craft()->request->getHostInfo($protocol) . craft()->urlManager->getBaseUrl();
         if (!$mustShowScriptName && craft()->config->omitScriptNameInUrls()) {
             $baseUrl = substr($baseUrl, 0, strrpos($baseUrl, '/'));
         }
     } else {
         $baseUrl = Craft::getSiteUrl($protocol);
         if ($mustShowScriptName || !craft()->config->omitScriptNameInUrls()) {
             $baseUrl .= strrchr(craft()->urlManager->getBaseUrl(), '/');
         }
     }
     // Put it all together
     if (craft()->config->usePathInfo()) {
         return $baseUrl . ($path ? '/' . $path : '') . ($params ? '?' . $params : '') . $anchor;
     } else {
         $pathParam = craft()->urlManager->pathParam;
         return $baseUrl . ($path || $params ? '?' . ($path ? $pathParam . '=' . $path : '') . ($path && $params ? '&' : '') . $params : '') . $anchor;
     }
 }
 /**
  * Returns a list of global variables to add to the existing list.
  *
  * @return array An array of global variables
  */
 public function getGlobals()
 {
     // Keep the 'blx' variable around for now
     $craftVariable = new CraftVariable();
     $globals['craft'] = $craftVariable;
     $globals['blx'] = $craftVariable;
     $globals['now'] = DateTimeHelper::currentUTCDateTime();
     $globals['loginUrl'] = UrlHelper::getUrl(craft()->config->getLoginPath());
     $globals['logoutUrl'] = UrlHelper::getUrl(craft()->config->getLogoutPath());
     if (Craft::isInstalled()) {
         $globals['siteName'] = Craft::getSiteName();
         $globals['siteUrl'] = Craft::getSiteUrl();
         $globals['user'] = craft()->userSession->getUser();
         if (craft()->request->isSiteRequest()) {
             foreach (craft()->globals->getAllSets() as $globalSet) {
                 $globalSet->locale = craft()->language;
                 $globals[$globalSet->handle] = $globalSet;
             }
         }
     } else {
         $globals['siteName'] = null;
         $globals['siteUrl'] = null;
         $globals['user'] = null;
     }
     return $globals;
 }