home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / utilities.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  7.2 KB  |  193 lines

  1. <?php
  2. //
  3. // +------------------------------------------------------------------------+
  4. // | phpDocumentor :: docBuilder Web Interface                              |
  5. // +------------------------------------------------------------------------+
  6. // | Copyright (c) 2003 Andrew Eddie, Greg Beaver                           |
  7. // +------------------------------------------------------------------------+
  8. // | This source file is subject to version 3.00 of the PHP License,        |
  9. // | that is available at http://www.php.net/license/3_0.txt.               |
  10. // | If you did not receive a copy of the PHP license and are unable to     |
  11. // | obtain it through the world-wide-web, please send a note to            |
  12. // | license@php.net so we can mail you a copy immediately.                 |
  13. // +------------------------------------------------------------------------+
  14. //
  15.  
  16. include_once('PhpDocumentor/HTML_TreeMenu-1.1.2/TreeMenu.php');
  17.  
  18. /**
  19.  *    Allows png's with alpha transparency to be displayed in IE 6
  20.  *    @param string $src path to the source image
  21.  *    @param int $wid width on the image [optional]
  22.  *    @param int $hgt height on the image [optional]
  23.  *    @param string $alt hover text for the image [optional]
  24.  */
  25. function showImage( $src, $wid='', $hgt='', $alt='' ) {
  26.     if (strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE 6.0' ) !== false) {
  27.         return "<div style=\"height:{$hgt}px; width:{$wid}px; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='$src', sizingMethod='scale');\" ></div>";
  28.     } else {
  29.         return "<img src=\"$src\" width=\"$wid\" height=\"$hgt\" alt=\"$alt\" border=\"0\" />";
  30.     }
  31. }
  32.  
  33. /**
  34.  *    Returns a select box based on an key,value array where selected is based on key
  35.  *    @param array $arr array of the key-text pairs
  36.  *    @param string $select_name The name of the select box
  37.  *    @param string $select_attribs Additional attributes to insert into the html select tag
  38.  *    @param string $selected The key value of the selected eleme
  39.  */
  40. function htmlArraySelect( &$arr, $select_name, $select_attribs, $selected ) {
  41.     GLOBAL $AppUI;
  42.     reset( $arr );
  43.     $s = "\n<select name=\"$select_name\" $select_attribs>";
  44.     foreach ($arr as $k => $v ) {
  45.         $s .= "\n\t<option value=\"".$k."\"".($k == $selected ? " selected=\"selected\"" : '').">" . $v . "</option>";
  46.     }
  47.     $s .= "\n</select>\n";
  48.     return $s;
  49. }
  50.  
  51. function getDir($path,&$node) {
  52.     global $pd;
  53.     if (!$dir = opendir($path)) return;
  54.     
  55.     $node = new HTML_TreeNode(array('text' => basename(realpath($path)), 'link' => "", 'icon' => 'folder.gif'));
  56.     while (($file = readdir($dir)) !== false)
  57.     {
  58.         if ($file != '.' && $file != '..')
  59.         {
  60.             if (is_dir("$path$pd$file") && !is_link("$path$pd$file"))
  61.             {
  62.                 $entry[] = "$path$pd$file";
  63.             }
  64.         }
  65.     }
  66.     closedir($dir);
  67.     for($i = 0; $i < count($entry); $i++)
  68.     {
  69.         $node->addItem(new HTML_TreeNode(array('text'=>basename(realpath($entry[$i])), 'link' => "javascript:setHelp('".addslashes(realpath($entry[$i]))."');", 'icon' => 'folder.gif')));
  70.     }
  71. }
  72.  
  73. function recurseDir($path, &$node) {
  74.     global $pd;
  75.     if (!$dir = opendir($path)) {
  76.         return false;
  77.     }
  78.     $anode = new HTML_TreeNode(array('text' => basename($path), 'link' => "javascript:setHelpVal('".$path."');", 'icon' => 'folder.gif'));
  79.     $result = addslashes(realpath(stripslashes($path).$pd.".."));
  80.     if (!$node) $anode->addItem(new DirNode('..',"javascript:setHelp('".$result."');",'folder.gif'),'..');
  81.     while (($file = readdir($dir)) !== false) {
  82.         if ($file != '.' && $file != '..') {
  83.             if (is_dir("$path$pd$file")) {
  84.                 recurseDir("$path$pd$file",$anode);
  85.             }
  86.         }
  87.     }
  88.     rewinddir($dir);//
  89.     while (false){//($file = readdir($dir)) !== false) {
  90.         if ($file != '.' && $file != '..') {
  91.             if (is_file("$path$pd$file")) {
  92.                 $anode->addItem(new DirNode($file,"javascript:setHelpVal('$path$pd$file');",'branchtop.gif',"$path$pd$file"));
  93.             }
  94.         }
  95.     }
  96.     if (!$node) $node = $anode;
  97.     else
  98.     $node->addItem($anode);
  99.     closedir($dir);
  100. }
  101.  
  102. function switchDirTree($path, &$node)
  103. {
  104.     global $pd;
  105.  
  106.     // initialize recursion simulation values
  107.     // array format: path => &parent in $node itemlist
  108.     $parent = array();
  109.     $parent_indexes = array();
  110.     $parenti = 1;
  111.     
  112.     $node = new DirNode(basename($path),"javascript:setHelpVal('".$path."');",'folder.gif',$path);
  113.     $result = addslashes(realpath($path.$pd.".."));
  114.     $node->addItem(new DirNode('..',"javascript:setHelp('".$result."');",'folder.gif','..'));
  115.     $rnode = &$node;
  116.     $parent[realpath($path)] = false;
  117.     $recur = 0;
  118.     do
  119.     {
  120.         if ($recur++ > 120) return;
  121.         if (!$dir = @opendir($path)) {
  122.             // no child files or directories
  123. //                    echo "$path no child files or directories return to ";
  124.             $rnode = &$parent[realpath($path)];
  125.             $path = $rnode->path;
  126.             if (isset($parent_indexes[realpath($path)])) $parenti = $parent_indexes[realpath($path)];
  127. //                    echo "$path parenti $parenti<br>";
  128.         }
  129. //                fancy_debug($path,$parent_indexes);
  130. //                vdump_par($parent);
  131.         if (!isset($parent_indexes[realpath($path)]))
  132.         {
  133.             $file = readdir($dir);
  134.             while ($file !== false) {
  135.                 if ($file != '.' && $file != '..') {
  136.                     if (@is_dir(realpath("$path$pd$file"))) {
  137.                         if (!isset($parent_indexes[realpath($path)])) $parent_indexes[realpath($path)] = true;
  138.                         $parent[realpath("$path$pd$file")] = &$rnode;
  139. //                                echo "<br>adding new ".addslashes(realpath($path.$pd.$file))." to $path<br>";
  140.                         $rnode->addItem(new DirNode(addslashes(realpath("$path$pd$file")),"javascript:setHelpVal('".addslashes(realpath($path.$pd.$file))."');",'folder.gif',addslashes(realpath($path.$pd.$file))));
  141.                     }
  142.                 }
  143.                 $file = readdir($dir);
  144.             }
  145.         }
  146.         // go down the tree if possible
  147.         if (isset($parent_indexes[realpath($path)]))
  148.         {
  149.             if ($parenti + 1 > (count($rnode->items)))
  150.             {
  151.                 // no more children, go back up to parent
  152. //                        echo "$path no more children, go back up to parent ";
  153.                 $rnode = &$parent[realpath($path)];
  154.                 $path = $rnode->path;
  155.                 if (isset($parent_indexes[realpath($path)])) $parenti = $parent_indexes[realpath($path)];
  156. //                        echo $path." parenti $parenti<br>";
  157.             } else
  158.             {
  159.                 // go to next child
  160. //                        echo "$path go to next child ";
  161.                 $parent_indexes[realpath($path)] = $parenti+1;
  162. //                        debug("set parent ".$rnode->items[$parenti]->path." = ".$rnode->path.'<br>');
  163.                 $parent[realpath($rnode->items[$parenti]->path)] = &$rnode;
  164.                 $rnode = &$rnode->items[$parenti];
  165.                 $path = $rnode->path;
  166. //                        echo "$path<br>";
  167.                 $parenti = 0;
  168.             }
  169.         } else
  170.         {
  171.             // no children, go back up the tree to the next child
  172. //                    echo "$path no children, go back up to parent ";
  173.             $rnode = &$parent[realpath($path)];
  174.             $path = $rnode->path;
  175.             if (isset($parent_indexes[realpath($path)])) $parenti = $parent_indexes[realpath($path)];
  176. //                    echo "$path parenti $parenti<br>";
  177.         }
  178.         @closedir($dir);
  179.     } while ($path && (($parenti < (count($rnode->items))) || ($parent[realpath($path)] !== false)));
  180. }
  181.  
  182. function vdump_par($tree)
  183. {
  184.     foreach($tree as $key => $val)
  185.     {
  186.         if ($val === false)
  187.         debug($key.' -> false<br>');
  188.         else
  189.         debug($key.' -> ' .$val->path.'<br>');
  190.     }
  191.     debug('<br>');
  192. }
  193. ?>