Habari\Site::get_url PHP Method

get_url() public static method

get_url returns a fully-qualified URL 'host' returns http://www.habariproject.org 'habari' returns http://www.habariproject.org/habari, if you have Habari installed into a /habari/ sub-directory 'site' returns http://www.habariproject.org/site if you are installing with a subdirectory path 'user' returns one of the following: http://www.habariproject.org/user http://www.habariproject.org/user/sites/x.y.z 'theme' returns one of the following: http://www.habariproject.org/user/themes/theme_name http://www.habariproject.org/user/sites/x.y.z/themes/theme_name 'admin' returns http://www.habariproject.org/admin 'admin_theme' returns http://www.habariproject.org/system/admin 'login' returns http://www.habariproject.org/auth/login 'logout' returns http://www.habariproject.org/auth/logout 'system' returns http://www.habariproject.org/system 'vendor' returns http://www.habariproject.org/system/vendor 'scripts' returns http://www.habariproject.org/system/vendor '3rdparty' returns http://www.habariproject.org/3rdparty if /3rdparty does not exists, /system/vendor will be returned 'hostname' returns www.habariproject.org
public static get_url ( string $name, boolean | string $trail = false ) : string
$name string the name of the URL to return
$trail boolean | string whether to include a trailing slash, or a string to use as the trailing value. Default: false
return string URL
    public static function get_url($name, $trail = false)
    {
        $url = '';
        switch (strtolower($name)) {
            case 'host':
                $protocol = 'http';
                // If we're running on a port other than 80, i
                // add the port number to the value returned
                // from host_url
                $port = 80;
                // Default in case not set.
                $port = Config::get('custom_http_port', isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : $port);
                $portpart = '';
                $host = Site::get_url('hostname');
                // if the port isn't a standard port, and isn't part of $host already, add it
                if ($port != 80 && $port != 443 && MultiByte::substr($host, MultiByte::strlen($host) - strlen($port)) != $port) {
                    $portpart = ':' . $port;
                }
                if (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
                    $protocol = 'https';
                }
                $protocol = Config::get('custom_http_protocol', $protocol);
                $url = $protocol . '://' . $host . $portpart;
                break;
            case 'habari':
                if (self::$habari_url == null) {
                    self::$habari_url = Site::get_url('host');
                    // Am I installed into a subdir?
                    $path = trim(dirname(Site::script_name()), '/\\');
                    if ('' != $path) {
                        self::$habari_url .= '/' . $path;
                    }
                }
                $url = self::$habari_url;
                break;
            case 'site':
                $url = Site::get_url('habari');
                // Am I in a Habari subdir site?
                if (self::$config_type == Site::CONFIG_SUBDIR) {
                    $url = Utils::end_in_slash($url) . self::$config_urldir;
                }
                break;
            case 'user':
                $url = Site::get_url('habari', true) . Site::get_path('user');
                break;
            case 'theme':
                $theme = Themes::get_theme_dir();
                if (file_exists(Site::get_dir('config') . '/themes/' . $theme)) {
                    $url = Site::get_url('user') . '/themes/' . $theme;
                } elseif (file_exists(HABARI_PATH . '/user/themes/' . $theme)) {
                    $url = Site::get_url('habari') . '/user/themes/' . $theme;
                } elseif (file_exists(HABARI_PATH . '/3rdparty/themes/' . $theme)) {
                    $url = Site::get_url('habari') . '/3rdparty/themes/' . $theme;
                } else {
                    $url = Site::get_url('habari') . '/system/themes/' . $theme;
                }
                break;
            case 'admin':
                $url = Site::get_url('site') . '/admin';
                break;
            case 'admin_theme':
                $url = Site::get_url('habari') . '/system/admin';
                break;
            case 'login':
                $url = Site::get_url('site') . '/auth/login';
                break;
            case 'logout':
                $url = Site::get_url('site') . '/auth/logout';
                break;
            case 'system':
                $url = Site::get_url('habari') . '/system';
                break;
            case 'vendor':
            case 'scripts':
                $url = Site::get_url('system') . '/vendor';
                break;
            case '3rdparty':
                // this should be removed at a later date as it will cause problems
                // once 'vendor' is adopted, dump the condition!
                if (file_exists(HABARI_PATH . '/3rdparty')) {
                    $url = Site::get_url('habari') . '/3rdparty';
                } else {
                    $url = Site::get_url('vendor');
                }
                break;
            case 'hostname':
                // HTTP_HOST is not set for HTTP/1.0 requests
                $url = $_SERVER['SERVER_PROTOCOL'] == 'HTTP/1.0' || !isset($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] : $_SERVER['HTTP_HOST'];
                break;
        }
        $url .= Utils::trail($trail);
        $url = Plugins::filter('site_url_' . $name, $url);
        return $url;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Handle incoming requests for RSD
  *
  * @todo Move the internal list of supported feeds into options to allow dynamic editing of capabilities
  */
 public function act_rsd()
 {
     Utils::check_request_method(array('GET', 'HEAD', 'POST'));
     /**
      * List of APIs supported by the RSD
      * Refer to namespace for required elements/attributes.
      */
     $apis_list = array('Atom' => array('preferred' => 'true', 'apiLink' => URL::get('atom_feed', 'index=1'), 'blogID' => '1'));
     $apis_list = Plugins::filter('rsd_api_list', $apis_list);
     $cache_xml = null;
     if (Cache::has('atom:rsd:apis')) {
         $cache_apis = Cache::get('atom:rsd:apis');
         if ($cache_apis === $apis_list && Cache::has('atom:rsd:xml')) {
             $cache_xml = Cache::get('atom:rsd:xml');
             $cache_xml = simplexml_load_string($cache_xml);
         }
     } else {
         Cache::set('atom:rsd:apis', $apis_list);
     }
     if ($cache_xml instanceof SimpleXMLElement) {
         $xml = $cache_xml;
     } else {
         $xml = new SimpleXMLElement('<rsd version="1.0" xmlns="http://archipelago.phrasewise.com/rsd"></rsd>');
         $rsd_service = $xml->addChild('service');
         $service_engine_name = $rsd_service->addChild('engineName', 'Habari');
         $service_engine_link = $rsd_service->addChild('engineLink', 'http://www.habariproject.org/');
         $service_home_page_link = $rsd_service->addChild('homePageLink', Site::get_url('habari'));
         $service_apis = $rsd_service->addChild('apis');
         if (!isset($apis_list) || count($apis_list) < 1) {
             return false;
         }
         foreach ($apis_list as $api_name => $atts) {
             if (!isset($atts['preferred'], $atts['apiLink'], $atts['blogID'])) {
                 continue;
             }
             $apis_api = $service_apis->addChild('api');
             $apis_api->addAttribute('name', $api_name);
             $apis_api->addAttribute('preferred', $atts['preferred']);
             $apis_api->addAttribute('apiLink', $atts['apiLink']);
             $apis_api->addAttribute('blogID', $atts['blogID'] == '' ? '1' : $atts['blogID']);
             if (!isset($atts['settings']) || count($atts['settings']) < 1) {
                 continue;
             }
             $api_settings = $apis_api->addChild('settings');
             foreach ($atts['settings'] as $setting_name => $setting_value) {
                 switch ($setting_name) {
                     case 'docs':
                     case 'notes':
                         $settings_setting = $api_settings->addChild($setting_name, $setting_value);
                         break;
                     case 'setting':
                         foreach ($setting_value as $setting_array) {
                             $settings_setting = $api_settings->addChild('setting', $setting_array['value']);
                             $settings_setting->addAttribute('name', $setting_array['name']);
                         }
                         break;
                 }
             }
         }
         Cache::set('atom:rsd:xml', $xml->asXML());
     }
     Plugins::act('rsd', $xml, $this->handler_vars);
     $xml = $xml->asXML();
     ob_clean();
     header('Content-Type: application/rsd+xml');
     print $xml;
 }
All Usage Examples Of Habari\Site::get_url