/** * * create directory tree html */ public function getDirectoryTree($path, $skip_files = false, $link_prefix = '') { $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST); $dom = new DomDocument("1.0"); $li = $dom; $ul = $dom->createElement('ul'); $li->appendChild($ul); $el = $dom->createElement('li', 'Home'); $at = $dom->createAttribute('clink'); $at->value = $link_prefix; $el->appendChild($at); $ul->appendChild($el); $node = $ul; $depth = -1; foreach ($objects as $object) { $name = $object->getFilename(); // skip unwanted files if ($name == '.' || $name == '..' || in_array($name, gatorconf::get('restricted_files'))) { continue; } $path = str_replace('\\', '/', $object->getPathname()); $isDir = is_dir($path); $link = str_replace(gatorconf::get('repository'), '', $path); $link = gator::encodeurl(ltrim($link, '/\\')); $skip = false; if ($isDir == false && $skip_files == true) { // skip unwanted files $skip = true; } elseif ($isDir == false) { // this is regural file, no links here $link = ''; } else { // this is dir $link = $link; } if ($objects->getDepth() == $depth) { //the depth hasnt changed so just add another li if (!$skip) { $el = $dom->createElement('li', $name); $at = $dom->createAttribute('clink'); $at->value = $link_prefix . $this->encrypt($link); $el->appendChild($at); if (!$isDir) { $el->appendChild($dom->createAttribute('isfile')); } $node->appendChild($el); } } elseif ($objects->getDepth() > $depth) { //the depth increased, the last li is a non-empty folder $li = $node->lastChild; $ul = $dom->createElement('ul'); $li->appendChild($ul); if (!$skip) { $el = $dom->createElement('li', $name); $at = $dom->createAttribute('clink'); $at->value = $link_prefix . $this->encrypt($link); $el->appendChild($at); if (!$isDir) { $el->appendChild($dom->createAttribute('isfile')); } $ul->appendChild($el); } $node = $ul; } else { //the depth decreased, going up $difference directories $difference = $depth - $objects->getDepth(); for ($i = 0; $i < $difference; $difference--) { $node = $node->parentNode->parentNode; } if (!$skip) { $el = $dom->createElement('li', $name); $at = $dom->createAttribute('clink'); $at->value = $link_prefix . $this->encrypt($link); $el->appendChild($at); if (!$isDir) { $el->appendChild($dom->createAttribute('isfile')); } $node->appendChild($el); } } $depth = $objects->getDepth(); } return $dom->saveHtml(); }
?> </td> <td class="filetime"><?php echo date(gatorconf::get('time_format'), $file['time']); ?> </td> <?php if (gator::checkPermissions('r')) { ?> <td class="actions"> <button type="button" class="action-info" data-type="<?php echo $file['type']; ?> " data-link="<?php echo gator::encodeurl($file['link']); ?> " data-name="<?php echo $file['name']; ?> " data-crypt="<?php echo $file['crypt']; ?> " data-size="<?php echo $file['size']; ?> " data-time="<?php echo date(gatorconf::get('time_format'), $file['time']); ?> "></button> </td>