I spotted jQuery File Tree and created a working simple example from the code with very little modification, With the intent of first adding it as part of a theme I'm developing to test it and then hopefully create a seperate module.

The current filebrowser module doesn't do what I want at all. I would like to just be able to add file repository content simply by adding a div with class or id tags to content so that it can be placed in blocks or content etc. Not a separate node as is with the filebrowser module.
A filebrowser is an app, So using some jquery on it so that the page doesn't refresh when navigating through directories is also important.

The jQuery File Tree is here :

http://abeautifulsite.net/notebook/58

I uploaded what I have cludged so far here :

http://www.zshare.net/download/5430358560bdbd3f/

It basically works outside of drupal as a standalone, Just navigate to the folder on a server running php.

So, I set about adding it to drupal but I have found that it doesn't work inside drupal and I believe I have narrowed the problem down to the connector code and would appreciate some feedback as how to create a working connector.

Using the working demo that I uploaded, I have done the following :

Added the following code to my jQuery javascript file that handles any jquery stuff I want to use :

			$(document).ready(function() {

				$('#fileTreeDemo_3').fileTree({ root: '/files/', script: '/index/themes/rainmaker/jqueryFileTree.php', folderEvent: 'click', expandSpeed: 750, collapseSpeed: 750, expandEasing: 'easeOutBounce', collapseEasing: 'easeOutBounce', loadMessage: 'Un momento...' }, function(file) { 
					openFile(file);
				});

			});

Added the css from jqueryFileTree.css to the theme's css file, The example and demo classes from index.html to the theme's css, Included jqueryFileTree.js & jquery.easing.js in the theme's .info file so that it loads on every page, Checking the source proves that they are loading, Along with drupal's built in jquery.js, Placed jqueryFileTree.php in the theme's directory, Created the folder "files" On the root of the server and created a new page with :

		<div class="example">

			<div id="fileTreeDemo_3" class="demo"></div>
		</div>

Inside.

To test that the script jqueryFileTree.php is being loaded into the content, I added :

echo "The script has been found."

Above the closing php tag in jqueryFileTree.php, Which results in the content displaying :
"The script has been found." Which confirms that the script is being called and run by the jQuery code.

So at that point everything except the php connector appears to working.
The php connector is the file jqueryFileTree.php and looks like this :

<?php
//
// jQuery File Tree PHP Connector
//
// Version 1.01
//
// Cory S.N. LaViska
// A Beautiful Site (http://abeautifulsite.net/)
// 24 March 2008
//
// History:
//
// 1.01 - updated to work with foreign characters in directory/file names (12 April 2008)
// 1.00 - released (24 March 2008)
//
// Output a list of files for jQuery File Tree
//

$_POST['dir'] = urldecode($_POST['dir']);

if( file_exists($root . $_POST['dir']) ) {
	$files = scandir($root . $_POST['dir']);
	natcasesort($files);
	if( count($files) > 2 ) { /* The 2 accounts for . and .. */
		echo "<ul class=\"jqueryFileTree\" style=\"display: none;\">";
		// All dirs
		foreach( $files as $file ) {
			if( file_exists($root . $_POST['dir'] . $file) && $file != '.' && $file != '..' && is_dir($root . $_POST['dir'] . $file) ) {
				echo "<li class=\"directory collapsed\"><a href=\"$file\" rel=\"" . htmlentities($_POST['dir'] . $file) . "/\">" . htmlentities($file) . "</a></li>";
			}
		}
		// All files
		foreach( $files as $file ) {
			if( file_exists($root . $_POST['dir'] . $file) && $file != '.' && $file != '..' && !is_dir($root . $_POST['dir'] . $file) ) {
				$ext = preg_replace('/^.*\./', '', $file);
				echo "<li class=\"file ext_$ext\"><a href=\"" . htmlentities($_POST['dir'] . $file) . "\" rel=\"" . htmlentities($_POST['dir'] . $file) . "\">" . htmlentities($file) . "</a></li>";
			}
		}
		echo "</ul>";	
	}
}
echo "The script has been found."
?>

It generates the urls to the files and creates the content inside div#fileTreeDemo_3.

So does anyone know exactly why the php connector jqueryFileTree.php doesn't work or how to find out what is conflicting?

Is there anything really obvious that just will not work in drupal in the jqueryFileTree.php code above?
Do I need to declare the variables somewhere in drupal first to use them or could it be that the paths being used in the connector are being taken from drupal's url, So the script is looking in the wrong place for the files and in the wrong directory because it is looking inside a folder based on the url for the page the content is on?

Any help would be greatly appreciated,
Tony.

Comments

T White’s picture

In case anyone is interested, I solved it.
It was a path issue concerning the built in php variables in the connector.

All instances of the $root variable should be $_SERVER['DOCUMENT_ROOT'] instead, In jqueryFileTree.php and I removed the trailing ?> to follow the coding standards.

I'll post up the example when the site is up, Code the module when I've completed the site template and created a separate drupal development environment.

The main thing is though, It works!

trailboss’s picture

was is hard to get it working?

alexharries’s picture

'ello! I run a site with several thousand nodes, almost all of which are sited on the main (primary links) menu in a structured format.

This code, with a little adjustment (and the use of the right-click module), could make an excellent "parent select" replacement for the node menu selector, and could also be used to build a very simple-to-use content manager for all users with content on the site.

I would love to have a copy of your working code, if possible?

This is all looking very interesting!

I_L_Russia’s picture

Sorry for my english, but I don't know how to thanks you!!!

I was working on it, on this script to work on my local server for a 10 hours in 2 days without results. Even a native instruction couldn't help me to turn on it. until I saw your article.
THANK YOU VERY VERY much. Good job, friend!

joelstein’s picture

You might also check out the File Tree module.