Location: PHPKode > scripts > DX0 > dx0/etc/parser.php
<?php 
 //
 // For ~user directories..
 //
 //$DOCUMENT_ROOT = "";
 //$REDIRECT_URL = eregi_replace("~kroford", "home/kroford/public_html", $REDIRECT_URL);

 // CHANGE TO DIRECTORY OF YOUR INCLUDE
 $DX0_INCLUDE_DIR = "/home/httpd/includes/dx0/";
 require $DX0_INCLUDE_DIR."dx0.inc";
 
 $topLineNum = 1;

 function DX0_ERROR ($errMsg) {
   echo "
<HTML>
<HEAD>
<TITLE>DX0 Parser Error</TITLE>
</HEAD>
<BODY><CODE>
<FONT COLOR=\"RED\"><B>DX0 ERROR:</B></FONT>".$errMsg."
</CODE>
</BODY>
</HTML>
";
   exit();
 }

 function parseDX0 ($file) { 
   global $fp;
   global $topLineNum;

     $buf =  ""; 
       if ($fp = fopen ($file,  "r")) { 
         while ($str = fgets ($fp, 4096)) { 
             $buf .= parseline (" ".$str); 
	     $topLineNum++;
         } 
         fclose ($fp); 
       } 
     //
     // add in style sheets and javascript
     //
     $prepBuf = dx0stylesheet();
     $buf = eregi_replace("<dx0prep>", $prepBuf, $buf);
     $jsBuf = dx0javascript();
     $buf = eregi_replace("<dx0basic>", $jsBuf, $buf);
     return $buf; 
 } 

 function ripOutAttributes($exampleTag) {
   $tagPlace = 0;
   while ($tagPlace < strlen($exampleTag)) {
     $testStr = substr($exampleTag, $tagPlace);
     if (strpos($testStr, "=") < 1) break;
     if (ereg('^[[:space:]]*([-[:alnum:]]+)[[:space:]]*=[[:space:]]*[\'"]+([^"\']+)[\'"]+', $testStr, $parts)) {
       $results[$parts[1]] = $parts[2];
     } else if (ereg('^[[:space:]]*([-A-Za-z0-9]+)[[:space:]]*=[[:space:]]*([-A-Za-z0-9]+)', $testStr, $parts)) {
       $results[$parts[1]] = $parts[2];
     } else break;
     $tagPlace += strlen($parts[0]);
   }
   return $results;
 }
 
 function parseline ($str) {
   global $fp;
   global $topLineNum;
   $parseObjID = "";
   $parseObjCLASS = "";
   $parseObjATTR = array();

   //
   // locate all dx0tags and yank out attributes
   //
   $tagPos = 0;
   DX0_DEBUGPASS("STRING :: ".htmlspecialchars($str)."<BR>\n");
   while ($tagPos = strpos($str, "<", $tagPos + 1)) {
     //
     // append next line if no closing tag
     //
     DX0_DEBUGPASS("TAG AT POSITION ".$tagPos."<BR>\n");
     $tagBuf = substr($str, $tagPos);
     $addtlLinesRead = 0;
     if (!ereg("^</?[Dd][Xx]0", $tagBuf)) continue; 
     $parseErr = "The DX0 parser found an incomplete tag that caused an error.  The bad tag begins on line ".$topLineNum;
     while (strpos($tagBuf, ">") < 1) {
       if (strpos($tagBuf, "<") > 0) {
         DX0_ERROR($parseErr);
       }
       if ($checkStr = fgets($fp, 4096)) {
         $tagBuf .= $checkStr;
	 $addtlLinesRead++;
       } else {
         DX0_ERROR($parseErr);
       }
     }

     //
     // replace tag with real HTML tag
     //
     if (ereg("^<(/?[Dd][Xx]0[^[:space:]>]*)([^>]*)>", $tagBuf, $tagParts)) {
       $tagName = $tagParts[1];
       $tagAttrs = $tagParts[2];
       DX0_DEBUGPASS("PRELIM :: ".$tagName." :: ".$tagAttrs."<BR>\n");
       $tagEndPos = strpos($tagBuf, ">") + 1;
       if ($tagName[0] != "/") {
         unset($parseObjCLASS);
         unset($parseObjID);
         unset($parseObjATTR);
         //
	 // handle opening tags
	 //
         DX0_DEBUGPASS("FOUND OPEN TAG :: ".$tagName."<BR>\n");
         $parseObjCLASS = $tagName;
	 $tagParts = ripOutAttributes($tagAttrs);
	 //
	 // handle valid arguments
	 //
         if (count($tagParts) > 0) {
           while (list($attrKey, $attrVal) = each($tagParts)) {
             $attrKey = trim($attrKey);
             DX0_DEBUGPASS("ATTRIBUTE :::: ".$attrKey." &gt;&gt; ".$attrVal."<BR>\n");
             if (ereg("^[Ii][Dd]$", $attrKey)) {
               $parseObjID = $attrVal;
             } else {
               $parseObjATTR[$attrKey] = $attrVal;
             } 
	   }
         }
         switch ($parseObjCLASS) {
           case "dx0basic":
           case "dx0prep":
             break;
           case "dx0include":
             include $GLOBALS['DX0_INCLUDE_DIR'].$parseObjATTR['file'];
             $tagBuf = substr($tagBuf, $tagEndPos); 
             break;
           default:
             eval("\$GLOBALS['".$parseObjID."'] = new ".$parseObjCLASS."(\$parseObjID, \$parseObjATTR);");
             $openTagBuf = $GLOBALS[$parseObjID]->openTag();
             $GLOBALS['DX0_OPEN_CLASS'][$GLOBALS['DX0_TAG_DEPTH']] = $parseObjID;
             DX0_DEBUGPASS("TAG CONSTRUCTED :::: ".htmlspecialchars($openTagBuf)."<BR>\n");
             $tagBuf = $openTagBuf.substr($tagBuf, $tagEndPos);
         }
       } else {
         //
	 // handle closing tags
	 //
         $tagName = substr($tagName, 1);
	 DX0_DEBUGPASS("FOUND CLOSING TAG :: ".$tagName."<BR>\n");
         $parseObjID = $GLOBALS['DX0_TAG_DEPTH'];
         $parseObjID = $GLOBALS['DX0_OPEN_CLASS'][$parseObjID];
         DX0_DEBUGPASS("OBJECT :: ".$parseObjID."<BR>\n");
         $tagBuf = $GLOBALS[$parseObjID]->closeTag().substr($tagBuf, $tagEndPos);
       }
     }
     $str = substr($str, 0, $tagPos).$tagBuf;
     $topLineNum += $addtlLinesRead;
   }
   return substr($str, 1);
 }


 if ($REDIRECT_URL) { 
    echo parseDX0($DOCUMENT_ROOT . $REDIRECT_URL); 
 }


?>
Return current item: DX0