blank.gif
triangle.gif Du er her: /  Forsiden  /  Kildekoden  /  Util  /  Url   Login nu   Login
blank.gif
blank.gif
triangle.gif Basic Base Component Db Dto Form Form-elements Jquery Layout Menu Menu-fisheye Mvc Tab Table Template Util 
blank.gif
blank.gif
 
arrow-headline.gif Index
 
  Tilbage

Navn : Url.php


Sample code, tutorial

Sådan benyttes komponenten Url klassen

Først skal du inkludere den fil der beskriver komponenten, som en klasse fil

  • <?
    require_once(HTML_PACKAGE_PATH.'/Url.php');
    ?>

Dernæst kan du enten benytte komponenten som et taglib (statiske metoder):

  • <?
    Url
    ::display($param1, $param2, $param3, ...);
    ?>

eller du kan lave en instance af komponenten og benytte metoderne direkte:

  • <?
    $object
    = new Url($param1, $param2, $param3, ...);
    print
    $object->getHtml();
    ?>

Parent html

Sådan vises komponenten Url klassen

Der er ikke fundet noget

PHP source code

Den fulde PHP kildekode for Url klassen

<?
/**
* @package util
* @see HTML_UTIL_COMPONENT_PATH.'/Url.php'
* @copyright (c) http://Finn-Rasmussen.com
* @license http://Finn-Rasmussen.com/license/ myPHP License conditions
* @author http://Finn-Rasmussen.com
* @version 1.10
* @since 22-feb-2007
*/

/**
* The required files
*/
require_once(HTML_BASE_UTIL_PATH.'/Link.php');
require_once(
HTML_BASIC_UTIL_PATH.'/Message.php');
if (
defined('HTML_LOG_UTIL_PATH')) {
    require_once(
HTML_LOG_UTIL_PATH.'/Log.php');
}
if (
defined('HTML_LANGUAGE_UTIL_PATH')) {
    require_once(
HTML_LANGUAGE_UTIL_PATH.'/Translate.php');
}

/**
* Get the url or Link from the specified key
* <code>
* Usage:
*   $key = 'URL_HOME';
*   $url = new Url();
*   print $url->get($key);
*   print $url->link($key);
* Or
*   $fileName    = '/jquery.js';
*   $filePath    = HTML_JQUERY_PATH;
*   $packageName = MYPHP_JQUERY_NAME;
*   $packagePath = HTML_JQUERY_PATH;
*   $src         = Url::src($fileName, $filePath, $packageName, $packagePath);
* Or
*   print Url::get($key);
* Or
*   print Url::link($key);
* </code>
* @package util
*/

class Url {
   
/**
    * Constructor
    */
    
function Url() {
    }
    
    
/**
     * Get the SRC to the url for the *.js or *.gif or *.css files
     * <code>
     * Usage:
     *    $fileName    = '/jquery.js';
     *    $filePath    = HTML_JQUERY_PATH;
     *    $packageName = MYPHP_JQUERY_NAME;
     *    $packagePath = HTML_JQUERY_PATH;
     *    $src         = Url::src($fileName, $filePath, $packageName, $packagePath);
     * </code>
     * @param  String $fileName    The name of the javascript file. I.e. '/foo.js'
     * @param  String $filePath    The path to the javascript file. I.e. '/js'
     * @param  String $packageName The name of the package, where the javascript file is located
     * @param  String $packagePath The Path to the package, where the javascript file is located
     * @return String The calculated SRC for the src include files
     */
    
function src($fileName, $filePath='', $packageName='', $packagePath='') {
        
$url = PROJECT_URL;
        if (
$packageName != '') {
            
$url = $url.MYPHP_PREFIX.CURRENT_VERSION;
            
$url = $url.'/'.basename($packageName);
        }
        if (
$packagePath != '') {
            
$url = $url.'/'.basename($packagePath);
        }
        if (
$filePath != '') {
            
$url = $url.'/'.basename($filePath);
        }
        if (
$fileName != '') {
            
$url = $url.'/'.basename($fileName);
        }
        return
$url;
    }

   
/**
    * Returns the full link for the specified key
    * <code>
    * Usage:
    *   $key = 'URL_HOME';
    *   $url = new Url();
    *   print $url->link($key);
    * Or
    *   print Url::link($key);
    * </code>
    * @static
    * @param  String $key The key to the url to get
    * @return String the complete link or '' if not found
    */
    
function link($key) {
        
$html = '';
          
$href  = Url::get($key);
          if (
$href != null) {
              
$text = $href;
            if (
defined('HTML_LANGUAGE_UTIL_PATH')) {
                
$text = Translate::get($text);
            }
            
/**
             * TODO how to specify the relative url ?
             */
              
$link = new Link($text,$href);
              
$html .= $link->getHtml();
          } else {
              
$msg = "Url Not found in GLOBALS[DEFINE_URL], key:$key";
            if (
defined('DEBUG_LEVEL') && DEBUG_LEVEL & DEBUG_LEVEL_SHOW_INFO) {
                
Log::error(__FILE__,__LINE__,$msg);
                
//Message::add($msg, __FILE__, __LINE__);
            
} else {
                
Message::add($msg, __FILE__, __LINE__);
            }
        }
        return
$html;
    }

   
/**
    * Returns the url for the specified key
    * @see HTML_BASE_RESOURCE_PATH/Define.php
    * <code>
    * Usage:
    *   $key = 'URL_HOME';
    *   $url = new Url();
    *   print $url->get($key);
    * Or
    *   print Url::get($key);
    * </code>
    * @static
    * @param  String $key The key to the url to get
    * @return String the complete url or null if not found
    */
    
function get($key) {
        
$url = null;
          
$theKey = md5($key);
          if (
array_key_exists($theKey,$GLOBALS[DEFINE_URL])) {
              
$url = $GLOBALS[DEFINE_URL][$theKey];
          } else {
              
$msg = "Key not Not found in GLOBALS[DEFINE_URL], key:$key - md5:$theKey";
            if (
defined('DEBUG_LEVEL') && DEBUG_LEVEL & DEBUG_LEVEL_SHOW_INFO) {
                
Log::error(__FILE__,__LINE__,$msg);
                
//Message::add($msg, __FILE__, __LINE__);
            
} else {
                
Message::add($msg, __FILE__, __LINE__);
            }
        }
        return
$url;
    }
    
    
/**
     * Get the real subdomain name, if the domain is a subdomain
     * or return "" if a real domain name
     * Special handling for my own subdomains
     * sample: test.eksperter.dk => eksperter.dk
     * <code>
     * Usage:
     *   $domain = 'test.eksperter.dk';
     *   $subdomain = Url::subdomain($domain);
     *   print $subdomain; // eksperter.dk
     * Or
     *   $domain = 'eksperter.dk';
     *   $subdomain = Url::subdomain($domain);
     *   print $subdomain; // ""
     * </code>
     * @static
     * @param  String $subdomain The subdomain name. Escape special chars like '.'
     * @retrun String The real domain name, stripped away the subdomain or empty ""
     */
    
function subdomain($subdomain) {
        
$domainname = '';
        
$names = split("\.", $subdomain);
        if (
count($names) == 3) {
            
$domainname = $names[1].'.'.$names[2];
            if (
$subdomain != $domainname) {
                
$domainname = 'http:/'.'/'.$domainname;
            }
        }
        return
$domainname;
    }
}
?>

HTML source code

Den fulde HTML kildekode for Url klassen

Der er ikke fundet noget

Class methods

Her er 'klasse metoderne' for Url klassen:

  • url
  • src
  • link
  • get
  • subdomain

Object vars

Her er 'objekt variable' for Url klassen:


 
triangle.gif

danmark

Germany

England

France

Italy

Norge

Sverige

USA


 
blank.gif
blank.gif
blank.gif