Tree functions

This is a discussion on Tree functions within the PHP Language forums, part of the PHP Programming Forums category; Hello! I need a tree (of folders), can anyone give me some ideas/input, how do I control collapse, explode ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-25-2007
jodleren
 
Posts: n/a
Default Tree functions

Hello!

I need a tree (of folders), can anyone give me some ideas/input, how
do I control collapse, explode etc?

Showing the entire tree will be too much, so I need to show a part of
it only....

BR
Sonnich

Reply With Quote
  #2 (permalink)  
Old 03-26-2007
shimmyshack
 
Posts: n/a
Default Re: Tree functions

On 25 Mar, 21:37, "jodleren" <sonn...@hot.ee> wrote:
> Hello!
>
> I need a tree (of folders), can anyone give me some ideas/input, how
> do I control collapse, explode etc?
>
> Showing the entire tree will be too much, so I need to show a part of
> it only....
>
> BR
> Sonnich


You could use jquery's tree view:
http://be.twixt.us/jquery/treeView.php

with an XHR call.

An example would be a tree of mp3s to be browsed.

You could return using XHR the exact folders paths as xhtml snippets,
(or pure json if a purist)
<ul>
<li><a class="dir" href="/path/to/folder">/path/to/folder</a></li>
<li><a class="file" href="/path/to/folder/track01.mp3">/path/to/
folder/track01.mp3</a></li>
</ul>

you would insert this into the DOM at the node clicked on, and bind an
onclick even to the link.
I guess you could use jQuery of prototype/scriptaculous, perhaps
behaviour to bind based on className

when clicked it would XHR to list.php which returns the next snippet,
or sends the URL to an embedded player.

You would get the actual tree like so, sorry for any typos:

function returnData($strDir,$strReturnType)
{
$arrResults = array();
$entry = '';
$d = '';
$boolDirs = false;
$boolFiles = false;
if($strReturnType =='files')
{
$boolFiles = true;
}
else
{
$boolDirs = true;
}
$d = dir($strDir);
while ( false !== ($entry = $d->read()) )
{
if( $boolDirs )
{
if( is_dir($strDir.$entry) && ($entry!='.') && ($entry!='..') )
{
$arrResults[] = $entry;
}
}
else
{
if( !is_dir($strDir.$entry)
&& (strpos($entry,'tmp') === false)
&& ($entry!='404.mp3'))
{
$arrResults[] = $entry;
}
}
}
$d->close();
return $arrResults;
}

calling it like this:

$arrResults = returnData($strDir,$strReturnType);
$arrResultsFiles = returnData($strDir,"files");

it's inefficient I guess, but would get you what you need


For a more apache based way, you could use javascript to hijack the
link returning false, but using XHR to request the page which
using rewrites would change the requested path from
/music/path/to/folder to
/list.php?path=/music/path/to/folder

I guess the key is hijacking the links, so your javascript is
unobtrusive, and using javascript/rewrites to request the appropriate
data, which you then insert as first child of the parent node (you
clicked on)
Fisheye has uses something similar to browse the code
http://fisheye5.cenqua.com
bottom left

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 05:29 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0