blank.gif
triangle.gif Du er her: /  Forsiden  /  Kildekoden  /  Component  /  Imagerotator   Login nu   Login
blank.gif
 ««« Se kilde koden
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
http://www.hvepseeksperten.dk (31)
 
  Tilbage

Navn : Imagerotator.php


Sample code, tutorial

Sådan benyttes komponenten Imagerotator klassen

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

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

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

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

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

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

Parent html

Sådan vises komponenten Imagerotator klassen

http://www.hvepseeksperten.dk (29)

PHP source code

Den fulde PHP kildekode for Imagerotator klassen

<?
/**
* @package component
* @filesource
* @see HTML_COMPONENT_PAGE_PATH.'/Imagerotator.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_COMMON_PATH.'/Html.php');
require_once(
HTML_BASIC_UTIL_PATH.'/Message.php');
require_once(
HTML_BASE_UTIL_PATH.'/Image.php');
require_once(
HTML_BASE_UTIL_PATH.'/Link.php');

/**
* Image Rotator. An image is shown in an round robin fasion in an interval
* Note: At the moment of writing, only numbers between 00,01,02,...,99 are supported
* <code>
* Usage:
*   $imagerotator = new Imagerotator($path,$image,$start,$end);
*   print $imagerotator->getHtml();
* Or
*   Imagerotator::display($path,$image,$start,$end);
* </code>
* @package component
*/

class Imagerotator extends Html {
    var
$path  = '';
    var
$image = '';
    var
$start = ''; // The start name of picture to rotate
    
var $end   = ''; // The end name of picture to rotate

    /**
     * Constructor
     * @param String $path  The path to the images
     * @param String $image The image to use for now
     * @param String $start The start of the image name to use for now
     * @param String $end   The end of the image name to use for now
     */
    
function Imagerotator($path='',$image='',$start='',$end='') {
        
$this->Html();
        
$this->path  = $path!=''?$path:IMAGE_ROTATOR_PATH;
        
$this->image = $image!=''?$image:'';
        
$this->start = $start!=''?$start:IMAGE_ROTATOR_START;
        
$this->end   = $end!=''?$end:IMAGE_ROTATOR_END;
        if (
$this->end>IMAGE_ROTATOR_END) {
            die(
$this->getClassName()."(), The max rotator end:".$this->end." is greater than ".IMAGE_ROTATOR_END."<br />\r\n");
        }
    }

    
/**
     * Get the name of the image to rotate
     * The name is prepended with zero if the name is smaller than 10
     * so the images must be named i.e. 00,01,02,..99
     * @return String The name
     */
    
function getName() {
        
$name = rand($this->start,$this->end);
        
$length = strlen($this->end - $this->start);
        
$start  = strlen($name);
        for (
$i=$start;$i<$length;$i*=10) {
            
$name = '0'.$name;
        }
        return
$name;
    }

    
/**
     * Builds the html, and return it for an Image Rotator object
     * @return String The html
     */
    
function getHtml() {
        
$html  = $this->html;
        if (
defined('COMPONENT_SHOW') && COMPONENT_SHOW & COMPONENT_SHOW_IMAGEROTATOR && HTTP_USER_AGENT!=HTTP_USER_AGENT_P900) {
            if (
defined('CREATE_RUNTIME_KERNEL') && CREATE_RUNTIME_KERNEL) {
                
$html .= '<?$imagerotator = new Imagerotator();print $imagerotator->getHtml();?>';
            } else {
                
$name = $this->getName();
                
$text  = '';
                
$title = IMAGE_ROTATOR_LINK.' ('.$name.')';
                
$link  = new Link($text, IMAGE_ROTATOR_LINK,CSS_LINK_COLOR,$title,LINK_LAYOUT_BR);
                
//if (file_exists(PROJECT_PATH.$this->path.'/'.$name.'.jpg')) {
                
$image = new Image($this->path.'/'.$name.'.jpg','','',$title,CSS_LINK_COLOR);
                
$link->add($image);
                
//} else {
                //    $msg = $this->getClassName()."->getHtml(), Unable to find image=".PORTAL_PATH.$this->path.'/'.$name.".jpg<br />\r\n";
                // Message::add($msg,__FILE__,__LINE__);
                //}
                
$html .= $link->getHtml();
            }
        } else {
            if (
defined('DEBUG_LEVEL') && DEBUG_LEVEL & DEBUG_LEVEL_SHOW_INFO) {
                
$html .= "<!-- No Image Rotator object -->\r\n";
            }
        }
        return
$html;
    }

    
/**
     * Display html
     * <code>
     * Usage:
     *    Imagerotator::display($path,$image,$start,$end);
     * </code>
     * @static
     * @param String $path  The path to the images to rotate
     * @param String $image The image to use for now
     * @param String $start The start of the image name to use for now
     * @param String $end   The end of the image name to use for now
     */
    
function display($path='',$image='',$start='',$end='') {
        
$html = new Imagerotator($path,$image,$start,$end);
        
$html->addHtml();
    }
}
?>

HTML source code

Den fulde HTML kildekode for Imagerotator klassen

<?
<a id="Link40" class="baseLinkColor" href="http://www.hvepseeksperten.dk" title="http://www.hvepseeksperten.dk (50)"><img src="/images/w200/50.jpg" alt="http://www.hvepseeksperten.dk (50)" class="baseLinkColor" />
</
a><br />

?>

Class methods

Her er 'klasse metoderne' for Imagerotator klassen:

  • object
  • getclassname
  • getmsg
  • addhtml
  • gethtml
  • tostring
  • getcachefilename
  • save
  • content
  • html
  • setobject
  • set
  • get
  • getattribute
  • gettag
  • add
  • getsizeof
  • getelement
  • getelements
  • gettoogle
  • getmaximize
  • getminimize
  • newtriangle
  • display
  • showsource
  • imagerotator
  • getname

Object vars

Her er 'objekt variable' for Imagerotator klassen:

  • html =>
  • sql =>
  • elements => Array
  • sizeof => 0
  • path => /w200
  • image =>
  • start => 0
  • end => 76

 
triangle.gif

danmark

Germany

England

France

Italy

Norge

Sverige

USA


 
blank.gif