Page 1 of 1

Media Library in Sidebar as Recursive Tree view (solved)

Posted: Sun Oct 10, 2010 12:02 am
by evanslee2
RE: Media Library in Sidebar as Recursive Tree view (solved)

I saved this code in the root of serendipity as test.php, which does what I need

Code: Select all

<style "text/css">
a:link,
a:active,
a:visited {
    color: #235587;
    text-decoration: none;
}
a:hover {
    color: #5f90ba;
    text-decoration: underline;
}
blockquote {
    border-left: 4px solid #2a5a8a;
    padding-left: 10px;
}
body {
text-align: left;

font-family: "trebuchet ms", "bitstream vera sans", arial, sans-serif;
font-size: 12;
color: #333;
}
</style>
<?php
$path = "uploads";  //define the path as relative
$webpath ="uploads"; //not needed
$dir_handle = @opendir($path) or die("Unable to open $path");  //using the opendir function

function num_files($dir, $recursive=false, $counter=0) {
    
	static $counter;
    if(is_dir($dir)) {
      if($dh = opendir($dir)) {
        while(($file = readdir($dh)) !== false) {
          if($file != "." && $file != ".." && !strpos($file, '..',1) && !strpos($file, 'serendipityThumb',1) && $file !='Thumb.db' ) {
              $counter = (is_dir($dir."/".$file)) ? num_files($dir."/".$file, $recursive, $counter) : $counter+1;
          }
        }
        closedir($dh);
      }
    }
    return $counter;
  }

  // Usage:
  $nfiles = num_files($path, false, 0); // count all files that resides under $path, including subdirs
  
echo "<strong>$path/</strong> ($nfiles)<br/><br/>";

list_dir($dir_handle,$path);

function list_dir($dir_handle,$path)
{
    // print_r ($dir_handle);
    //running the while loop
    while (false !== ($file = readdir($dir_handle))) {
        $dir =$path.'/'.$file;
        if(is_dir($dir) && $file != '.' && $file !='..' )
        {
			 echo "<br><strong>uploads/$file/</strong><br>";
			 $handle = @opendir($dir) or die("unable to open file $file");
			 list_dir($handle, $dir);
        } 
		
		elseif($file != '.' && $file !='..' && !strpos($file, '..',1) && !strpos($file, 'serendipityThumb',1) && $file !='Thumb.db' && $file !='*')
        
		{
          echo "&nbsp;&nbsp;<a href='$dir' target='_blank' >$file</a> \n<br>";
        }
    }
    closedir($dir_handle);   //closing the directory 
}
?>
How can I put this into a plugin?

Which hook do i need to use, to enable me to move it about the sidebar via the admin area and to display it bottom right side of the blog...?


Regards,
Lee

Re: Media Library in Sidebar as Tree view (How?)

Posted: Sun Oct 10, 2010 12:34 pm
by evanslee2
Its ok figured out the easy way, here is what I did it...

Used the html nugget plugin, to include my php file as an iframe... I put this in as my html in the html nugget.

<Iframe src="test.php" width="100%" height="auto" scrollbars="auto" frameborder="0" MARGINWIDTH="0" MARGINHEIGHT="0" ></Iframe>