Location: PHPKode > scripts > PSpecialNavi > pspecialnavi/PSpecialNavi.php
<?
  // PSpecialNavi (Vesion 1.1)
  // (c) Mathias Soeken, 2002
  // P-Projekt
  
  /* Update 1.1 (12.9.2002)
   * - setAoverTD()			// Link aufrufen bei Klick auf Zelle
   * - setBorderColor()		// Rahmenfarbe von Zelle und Tabelle
   * - setAlign()           // Alignment des Zellentextes
   * - setColorsGradient()  // Funktion zur Farbsetzung mit Gradient Generation
   * - noEffect()           // keine Effects
   * - setAutoSpeed()       // automatische Berechnung der Geschwindigkeit
   * - setBorderWidth()     // Rahmenstärke von Zelle und Tabelle
   * - setType()            // Anordnung der Navigation
   * - setNoBr()            // Fügt <nobr> ein
   * BUGFIXES
   * - PSpecialNavi()
   * - drawHTML()
   */
   
  // NEU! Globale Funktionen. Bitte nicht extern verwenden!
  $h = "0123456789ABCDEF";
  $Fullrgb = "#000000";
  
  function gradientcolors($startcolor, $endcolor, $nLength)
  {
    global $Fullrgb;
	
    $len = $nLength;
	$color = "";
	$retArr = array();
	
	$start_red = $startcolor >> 16;
	$start_green = ($startcolor & 0x00ff00) >> 8;
	$start_blue = $startcolor & 0x0000ff;
	
	$end_red = $endcolor >> 16;
	$end_green = ($endcolor & 0x00ff00) >> 8;
	$end_blue = $endcolor & 0x0000ff;
			
	$incRed = floor(($end_red - $start_red) / ($len - 1));
	$incGreen = floor(($end_green - $start_green) / ($len - 1));
	$incBlue = floor(($end_blue - $start_blue) / ($len - 1));
		
	for ($x = 0; $x < $len; $x++)
	{
	  if ($start_red + $incRed >= 0x00 && $start_red + $incRed <= 0xff)
	    $start_red += $incRed;
	  if ($start_green + $incGreen >= 0x00 && $start_green + $incGreen <= 0xff)
	    $start_green += $incGreen;
	  if ($start_blue + $incBlue >= 0x00 && $start_blue + $incBlue <= 0xff)
	    $start_blue += $incBlue;
		
	  $color = hex(merge($start_red, $start_green, $start_blue));
	  $color = substr($Fullrgb, 0, 6 - strlen($color) + 1).$color;
	  
	  $retArr[count($retArr)] = $color;
	}
	
	return $retArr;
  }
  
  function merge($r, $g, $b)
  {
    return ($r << 16 | $g << 8 | $b);
  }
  
  function hex($c)
  {
    global $h;
	
    $temp = "";
	$hexStr = "";
	
	for (; $c != 0; $c >>= 4)
	{
	  $remainder = $c % 16;
	  $hexStr .= substr($h, $remainder, 1);
	}
	
	for ($i = 5; $i >= 0; $i--)
	  $temp .= substr($hexStr, $i, 1);
	  
	return $temp;
  }
  
  function hextoint16($color)
  {
    return intval("0x".substr($color, 1, 2).substr($color, 3, 2).substr($color, 5, 2), 16);
  }
  
  class PSpecialNavi
  {
    var $content;
    var $colors;
    var $size;
    var $aclass;
    var $cellspacing;
    var $paddingleft;
    var $paddingtb;
    var $speed;
	var $defaulttarget;
	var $aovertd;
	var $bordercolor;
	var $borderwidth;
	var $borderwidthin;
	var $align;
	var $type;
	var $nobr;
    
    function PSpecialNavi()
    {
      global $content, $colors, $size, $aclass, $cellspacing, $paddingleft, $paddingtb, $speed, $defaulttarget,
	         $aovertd, $bordercolor, $borderwidth, $borderwidthin, $align, $type, $nobr;
      
      $content = array();
      // $colors = array("#e46d35", "bb6237", "#82513b", "#6b4b3b", "#5f483c", "#3e3e3e");
	  // Bugfix:
	  $colors = array("#e46d35", "#bb6237", "#82513b", "#6b4b3b", "#5f483c", "#3e3e3e");
      $size = "auto";
      $aclass = "";
      $cellspacing = "0";
      $paddingleft = "5";
      $paddingtb = "2";
      $speed = "80";
	  $defaulttarget = "_self";
	  $aovertd = 0;
	  $bordercolor = "#000000";
 	  $borderwidth = "1px";
	  $borderwidthin = "1px";
	  $align = "left";
	  $type = "vertical"; // ( x | horizontal)
	  $nobr = 0;
    }
    
    function addItem($szCaption, $szUrl = "#", $szTarget = "", $szQuickInfo = "")
    {
      global $content, $defaulttarget;
      
	  if (empty($szTarget) || !isset($szTarget)) $szTarget = $defaulttarget;
      $content[count($content)] = array($szCaption, $szUrl, $szTarget, $szQuickInfo);
    }
	
	function addSeparator()
	{
	  $this->addItem("&nbsp;", "javascript;");
	}
    
    function setColors($aColors)
    {
      global $colors;
      
      $colors = $aColors;
    }
	
	function setColorsGradient($szStartColor, $szEndColor, $nLength = 6)
	{
	  global $colors;
	  
	  $colors = gradientcolors(hextoint16($szStartColor), hextoint16($szEndColor), $nLength);
	  $colors[$nLength - 1] = $szEndColor;
	}
    
    function setWidth($szSize)
    {
      global $size;
      
      $size = $szSize;
    }
    
    function setHyperlinkClass($szClass)
    {
      global $aclass;
      
      $aclass = $szClass;
    }
    
    function setSpecialHyperlinkClass()
    {
      echo "  <style type=\"text/css\">\n";
      echo "    a.specialnavi { font-family:verdana; font-size:11px; color:#cccccc; text-decoration:none }\n";
      echo "    a.specialnavi:Hover { color:#000000 }\n";
      echo "  </style>\n";
      
      $this->setHyperlinkClass("specialnavi");
    }
    
    function setCellSpacing($szSpacing)
    {
      global $cellspacing;
      
      $cellspacing = $szSpacing;
    }
    
    function setPaddingLeft($szPadding)
    {
      global $paddingleft;
      
      $paddingleft = $szPadding;
    }
    
    function setPaddingTopBottom($szPadding)
    {
      global $paddingtb;
      
      $paddingtb = $szPadding;
    }
    
    function setSpeed($szSpeed)
    {
      global $speed;
      
      $speed = $szSpeed;
    }
	
	function setAutoSpeed()
	{
	  global $colors, $speed;
	  
	  $speed = 480 / count($colors);
	}
	
	function setDefaultTarget($szDefaultTarget)
	{
	  global $defaulttarget;
	  
	  $defaulttarget = $szDefaultTarget;
	}
	
	function setAoverTD($bAoverTD = 0)
	{
	  global $aovertd;

	  $aovertd = $bAoverTD;
	}
	
	function setBorderColor($szColor)
	{
	  global $bordercolor, $colors;
	  
	  $bordercolor = $szColor == "auto" ? $colors[count($colors) - 1] : $szColor;
	}
	
	function setBorderWidth($szOut, $szIn)
	{
	  global $borderwidth, $borderwidthin;
	  
	  $borderwidth = $szOut;
	  $borderwidthin = $szIn;
	}
	
	function setAlign($szAlign)
	{
	  global $align;
	  
	  $align = $szAlign;
	}
	
	function setType($szType)
	{
	  global $type;
	  
	  if ($szType == "horizontal" || $szType == "vertical")
	    $type = $szType;
	}
	
	function setNoBr($bNoBr)
	{
	  global $nobr;
	  
	  $nobr = $bNoBr;
	}
	
	function noEffect()
	{
	  global $speed;
	  
	  $speed = "0";
	}
    
    function drawHTML()
    {
      global $colors, $content, $size, $aclass, $cellspacing, $paddingleft, $paddingtb, $speed,
	         $aovertd, $bordercolor, $borderwidth, $borderwidthin, $align, $type, $nobr;

      echo "  <script language=\"javascript\" type=\"text/javascript\">\n";
      echo "    var zaehler=0, merker=0, farben = new Array();\n";

      for ($i = 0; $i < count($colors); $i++)
        echo "    farben[$i] = \"".$colors[$i]."\";\n";
     
      echo "\n    var zeilenzahl = \"".(count($colors) - 1)."\";\n\n";
      echo "    for (i = 1; i <= zeilenzahl; i++)\n";
      echo "    {\n";
      echo "      eval(\"merkerT\" + i + \" = 0\");\n";
      echo "      eval(\"zaehlerT\" + i + \" = 0\");\n";
      echo "      eval(\"xtimerT\" + i + \" = null\");\n";
      echo "      eval(\"xT\" + i + \" = ''\");\n";
      echo "    }\n\n";
      echo "    function mOvr(nr)\n";
      echo "    {\n";
      echo "      eval(\"zaehler\" + nr + \" = 0\");\n";
      echo "      eval(\"merker\" + nr + \" = 1\");\n";
      echo "      eval(\"document.all.\" + nr + \".bgColor = '\" + farben[0] + \"'\");\n";
      echo "    }\n\n";
      echo "    function mOut(nr)\n";
      echo "    {\n";
      echo "      eval(\"merker\" + nr + \" = 0\");\n";
      echo "      xnr = nr;\n";
	  
	  if ($speed == "0")
	  {
	    echo "      eval(\"document.all.\" + nr + \".bgColor = '\" + farben[".(count($colors) - 1)."] + \"'\");\n";
	  }
	  else
	  {
        echo "      changeColor(xnr);\n";
	  }
	  
      echo "    }\n\n";
      echo "    function changeColor(bereich)\n";
      echo "    {\n";
      echo "      if (eval(\"merker\" + bereich) != 1)\n";
      echo "      {\n";
      echo "        eval(\"x\" + bereich + \" = \" + bereich);\n";
      echo "        eval(\"document.all.\" + bereich + \".bgColor = farben[\" + eval('zaehler' + bereich) + \"]\");\n";
      echo "        eval(\"zaehler\" + bereich + \"++\");\n\n";
      echo "        if (eval(\"zaehler\" + bereich) <= (farben.length - 1) && eval(\"zaehler\" + bereich) > 0)\n";
      echo "        {\n";
      echo "          eval(\"xtimer\" + bereich + \" = setTimeout(\\\"changeColor('\" + bereich + \"')\\\", $speed)\");\n";
      echo "        }\n";
      echo "      }\n";
      echo "    }\n";
      echo "  </script>\n\n";

       
      echo "\n  <table".($size == "auto" || $type == "horizontal" ? "" : " width=\"$size\"")."".($cellspacing == "auto" ? "" : " cellspacing=\"$cellspacing\"")." style=\"border:solid $borderwidth $bordercolor\">\n";
	  if ($type == "horizontal")
        echo "    <tr>\n";
		  
      for ($i = 0; $i < count($content); $i++)
      {
	    if ($type == "vertical")
          echo "    <tr>\n";
		  
        $padding = "padding-left:".$paddingleft."px; padding-right:".$paddingleft."px; padding-top:".$paddingtb."px; padding-bottom:".$paddingtb."px";
		$cursor = $aovertd ? "; cursor:hand" : "";
        $vstyle = ($i == (count($content) - 1) ? " style=\"$padding$cursor\"" : " style=\"border-".($type == "vertical" ? "bottom" : "right").":solid $borderwidthin $bordercolor; $padding$cursor\"");
		
		if ($aovertd)
		  echo "<a href=\"".$content[$i][1]."\" target=\"".$content[$i][2]."\">";
		  
        echo "      <td id=\"a$i\" bgcolor=\"".$colors[count($colors) - 1]."\"".($content[$i][3] == "" ? "" : " title=\"".$content[$i][3]."\"")." align=\"$align\" onmouseover=\"mOvr(id);\" onmouseout=\"mOut(id);\"$vstyle>";
		if ($nobr) echo "<nobr>";
		echo "<a".($aclass == "" ? "" : " class=\"$aclass\"")." href=\"".$content[$i][1]."\" target=\"".$content[$i][2]."\">".$content[$i][0]."</a>";
		if ($nobr) echo "</nobr>";
		echo "</td>";
		
		if ($aovertd)
		  echo "</a>";
		  
		echo "\n";

		if ($type == "vertical")
          echo "    </tr>\n";
      }
	  if ($type == "horizontal")
        echo "    </tr>\n";
      echo "  </table>\n";
    }
  }
?>
Return current item: PSpecialNavi