|
|
|
PHP program code utility with TREE JAVASCRIPT TREE VIEW output of a recursive scandir php command
Get the tree from http://www.destroydrop.com/javascript/tree
|
<?php
/*
========================================================================
Name Program : dtree_scandir.php
Author : Aitor Solozabal Merino (Spain)
Email : aitor-3@euskalnet.net
Date : 04-04-2008
Type : php program code utility
Description : DTREE JAVASCRIPT TREE VIEW output of a recursive scandir php command
========================================================================
*/
function build_dtree_tree($directory)
{
//dtree creation
//d = new dTree('d');
//The value for the root node parent has to be -1.
//d.add(0,-1,'ROOT TREE');
//
//configuration
//Variable Type Default Description
//target String true Target for all the nodes.
//folderLinks Boolean true Should folders be links.
//useSelection Boolean true Nodes can be selected(highlighted).
//useCookies Boolean true The tree uses cookies to rember it's state.
//useLines Boolean true Tree is drawn with lines.
//useIcons Boolean true Tree is drawn with icons.
//useStatusText Boolean false Displays node names in the statusbar instead of the url.
//closeSameLevel Boolean false Only one node within a parent can be expanded at the same time. openAll() and closeAll() functions do not work when this is enabled.
//inOrder Boolean false If parent nodes are always added before children, setting this to true speeds up the tree.
//samples: how to configure
//d.config.useLines=false;
//d.config.useStatusText=true;
//d.config.useCookies=false;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>DIRECTORY TREEVIEW</title>
<link rel="StyleSheet" href="dtree.css" type="text/css">
<script type="text/javascript" src="dtree.js"></script>
</head>
<body>
<h3>DIR TREEVIEW PHP with dTree 2.05<br />
<a href="http://www.destroydrop.com/javascripts/tree/default.html">www.destroydrop.com/javascript/tree</a></h3>
<div class="dtree">
<p><a href="javascript: d.openAll();">open all</a> | <a href="javascript: d.closeAll();">close all</a></p>
<script type="text/javascript">
<!--
d = new dTree('d');
d.config.target="mytarget";
d.config.folderLinks =false;
d.config.useSelection =true;
d.config.useCookies =true;
d.config.useLines=true;
d.config.useIcons=true;
d.config.useStatusText=true;
d.config.closeSameLevel=false;
d.config.inOrder =true;
d.add(0,-1,'<? echo $directory; ?>','','');
<?
}
function create_dtree_node($id, $pid, $name, $url = '', $title = '', $target = '',
$icon = '', $iconopen = '', $open = '')
{
//parameters to add node
//Variable Type Description
//id Number Unique identity number.
//pid Number Number refering to the parent node. The value for the root node has to be -1.
//name String Text label for the node.
//url String Url for the node.
//title String Title for the node.
//target String Target for the node.
//icon String Image file to use as the icon. Uses default if not specified.
//iconOpen String Image file to use as the open icon. Uses default if not specified.
//open Boolean Is the node open.
if ($pid == '' || $pid == 'null')
$pid = 0;
?>
d.add(<? echo $id; ?>, <? echo $pid; ?>,'<? echo $name; ?>','<? echo $url; ?>','<? echo $title; ?>','<? echo $target; ?>');
<?
}
function show_dtree_tree()
{
?>
document.write(d);
//-->
</script>
</div>
</body>
</html>
<?
}
function scandir_dtree($SCAN_DIRECTORY, $id_node = 0, $parent_node = 0, $DIRECTORY_LIST =
"")
{
global $current_pos;
if (is_array($DIRECTORY_LIST)) {
foreach ($DIRECTORY_LIST as $key => $value) {
if (($value <> '.') and ($value <> '..')) {
$value = scandir_dtree($SCAN_DIRECTORY, $id_node, $parent_node, $value);
}
}
return;
} else {
$SCAN_DIRECTORY .= "/" . $DIRECTORY_LIST;
$SCAN_DIRECTORY = str_ireplace("//","/",$SCAN_DIRECTORY);
if (is_dir($SCAN_DIRECTORY)) {
if ($DIRECTORY_LIST != '') {
$id_node = $current_pos++;
create_dtree_node($id_node, $parent_node, $DIRECTORY_LIST);
$parent_node = $id_node;
}
return scandir_dtree($SCAN_DIRECTORY, $id_node, $parent_node, SCANDIR($SCAN_DIRECTORY));
} else {
$id_node = $current_pos++;
$url=str_ireplace("///","//",$SCAN_DIRECTORY);
create_dtree_node($id_node, $parent_node, $DIRECTORY_LIST,$url,$url,$url);
return strval($DIRECTORY_LIST);
}
}
}
$current_pos = 1;
$dir_to_scan = dirname($_SERVER['SCRIPT_FILENAME']);
// or $_SERVER['DOCUMENT_ROOT'];
// or 'C:/xampp/htdocs/aitor/ejemplos';
$dir_to_scan = str_ireplace(PATH_SEPARATOR,"/",$dir_to_scan);
if (is_dir($dir_to_scan)) {
build_dtree_tree($dir_to_scan);
scandir_dtree($dir_to_scan);
show_dtree_tree();
} else {
echo "<br>" . $dir_to_scan . " is not a valid directory" . "<br>";
}
/*
This program code is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation in any version
of the License.
This program is non professional and distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
?> | | |
|
| phpYellow Pages Standard Categories : PHP, Complete Programs, Databases, Directories, Search | | | Pull Down Surfing - Surf on Change Categories : Java Script, MySQL, HTML and PHP, PHP, Databases | | | Upload any fixed type of files, control file type through javascript and encrypt filename using php so file not get overwrite Categories : PHP, Java Script, Functions, PHP References, Form Processing | | | How to check if JavaScript is enabled on a remote browser with PHP Categories : PHP, Java Script | | | PHP and javascript mouseover, mouseout, and mousedown events Categories : PHP, Java Script, Form Processing, Beginner Guides | | | List the content of the directory of your webserver where this small PHP Script resides. Categories : PHP, Filesystem, Directories, CSS | | | Validator 98 - a PHP-script to generate form-validation-code in JavaScript. Categories : Complete Programs, Java Script, PHP, HTML and PHP | | | Dynamic Loading of XML array data into ComboBox and Display XML data using PHP + DOM + Javascript. Categories : PHP, Java Script, DOM XML, XML, Arrays | | | Classic guest book made with PHP and Flash Categories : PHP, Flash, Java Script | | | filesystem Show Files Script Categories : PHP, Filesystem, Java Script | | | Menu in sliding bar or tree style. Handles frames by using small amount of javascript. Handles external and internal pages. Allows custom code to replace a menu item. Categories : PHP Classes, PHP, Java Script, DHTML | | | Zephyr: AJAX Based Framework for PHP5 Developers Categories : PHP, AJAX, Frameworks, Java Script, Web Applications | | | A Complete table(ADD,EDIT,VIEW,DELETE) management System PHP,MYSQL, JAVASCRIPT Categories : PHP, MySQL, Java Script, Databases | | | PHP Calendar Categories : PHP, Calendar, Date Time, Java Script, CSS | | | A Simple sign up script with PHP and JavaScript validations. Categories : PHP, Java Script, MySQL, Databases | |
|
|