Location: PHPKode > projects > Multimedia Files Scanner > filedialog.php
<?php
	/* 
	Name: FileDialog 1.0
	
	Credits: Written by Aaron Bishell. Homepage: http://binary.gamer.net.nz/.
	
	Description: A module to provide a way to explore the directory structure and select files or 
	folders similar to that in Windows.
	
	Useage: Do a require somewhere near the start of your program, e.g. require("filedialog.php");
		Use the following line when you want to popup the filedialog: 
		$selection=filedialog($title, $displayFiles, $gotoDir);
	
	Notes: 	$selection is a string containing the full path of the selected file or folder.
		$title is a string describing the title displayed at the top left of the window.
		$displayFiles is a bool, if set to FALSE will not display files.
		$gotoDir is a string containing the full path to a directory you want the file dialog to goto on startup.
	*/
	
	/*
	Linux Support added by aaff hide@address.com
	*/
	
	
	// The PHPGTK binary.
	if (!class_exists("gtk")) 
	{
		if (strtoupper(substr(PHP_OS, 0, 3)) == "WIN")
		{
			dl("php_gtk.dll");
		}
		else
		{
			dl("php_gtk.so");
		}
	}
	
	function filedialog($title, $dispFiles, $dir="")
	{
		$filedialog=new filedialog($title, $dispFiles, $dir);
		return $filedialog->selection;
	}
	
	class filedialog
	{
		// Globals.
		var $selection;		// Stores the full path of the node that was selected when ok was clicked.
		var $lastSelection;	// The last node that was expanded.
		var $ws;		// An array of all the widget objects.
		var $images; 		// An array of gdk and gtk pixmap objects.
		var $dispFiles;		// If set to false it hides all files.
		var $dir;		// If not an empty string it automatically goes to this dir on startup.
		var $slash;
		
		function filedialog($title, $dispFiles, $dir)
		{

     		if (strtoupper(substr(PHP_OS, 0, 3)) == "WIN")
     		{
     		  $this->slash = "\\";
     		  
         }
         else
         {
            $this->slash = "/";
         }

			$this->dispFiles=$dispFiles;
			
			$this->createDialog($title, $dispFiles);
			$this->popCtree();
			
			if( $dir != "" )
			{
				$this->gotoDir($dir);	
			}
			
			Gtk::main();
		}
		
		// Creates the dialog.
		function createDialog($title)
		{
			// Create the window.
			$this->ws['window']=new GtkWindow(GTK_WINDOW_DIALOG);
			$this->ws['window']->set_title($title);
			$this->ws['window']->set_usize(380, 320);
			$this->ws['window']->set_border_width(5);
			$this->ws['window']->set_position(GTK_WIN_POS_CENTER);
			$this->ws['window']->set_modal(TRUE);
			
			// Retrieve the GdkWindow.
			$this->ws['window']->realize();
			$this->loadImages($this->ws['window']->window);
			
			// Create the main vbox.
			$this->ws['vbox1']=new GtkVBox();
			$this->ws['vbox1']->set_spacing(5);
			$this->ws['window']->add($this->ws['vbox1']);
			
				// The top most horizontal box.
				$this->ws['hbox1']=new GtkHBox();
				$this->ws['hbox1']->set_spacing(5);
				$this->ws['vbox1']->pack_start($this->ws['hbox1'], FALSE, TRUE, 0);
				
					// The path entry.
					$this->ws['path_entry']=new GtkEntry();
					$this->ws['path_entry']->set_sensitive(FALSE);
					$this->ws['hbox1']->pack_start($this->ws['path_entry'], TRUE, TRUE, 0);
				
					// The "up" button.
					$this->ws['b_up']=new GtkButton();
					$this->ws['hbox1']->pack_start($this->ws['b_up'], FALSE, TRUE, 0);
					
					$this->ws['up_vbox']=new GTKVBox();
					$this->ws['up_vbox']->pack_start($this->images['gtk']['up_away'], FALSE, FALSE, 0);
					$this->ws['b_up']->add($this->ws['up_vbox']);
			
				// The scrolled window.
				$this->ws['swindow']=new GtkScrolledWindow();
				$this->ws['swindow']->set_policy(GTK_POLICY_NEVER ,GTK_POLICY_AUTOMATIC);
				$this->ws['vbox1']->pack_start($this->ws['swindow'], TRUE, TRUE, 0);
			
					// The ctree.
					$this->ws['ctree']=new GtkCTree(1,0);
					$this->ws['ctree']->set_line_style(GTK_CTREE_LINES_NONE);
					$this->ws['ctree']->set_indent(20);
					$this->ws['ctree']->unset_flags(GTK_CAN_FOCUS);
					$this->ws['ctree']->set_selection_mode(GTK_SELECTION_BROWSE);
					$this->ws['swindow']->add($this->ws['ctree']);
					
				// The button box at the bottom.
				$this->ws['bbox']=new GtkHButtonBox();
				$this->ws['bbox']->set_layout(GTK_BUTTONBOX_END);
				$this->ws['bbox']->expand=FALSE;
				$this->ws['bbox']->set_spacing(5);
				$this->ws['bbox']->set_child_size(0, 0);
				$this->ws['bbox']->set_child_ipadding(0, 0);
				$this->ws['vbox1']->pack_start($this->ws['bbox'], FALSE, FALSE, 0);
			
					$this->ws['b_ok']=new GtkButton("Ok");
					$this->ws['b_ok']->set_usize(75, 24);
					$this->ws['b_ok']->set_sensitive(FALSE);
					$this->ws['bbox']->add($this->ws['b_ok']);
					
					$this->ws['b_cancel']=new GtkButton("Cancel");
					$this->ws['b_cancel']->set_usize(75, 24);
					$this->ws['bbox']->add($this->ws['b_cancel']);
				
			// Connects the signals			
			$this->ws['window']->connect("destroy", array(& $this, "b_cancel"));
			$this->ws['b_up']->connect("clicked", array(& $this, "b_up_clicked"));
			$this->ws['b_up']->connect("enter", array(& $this, "b_up_over"));
			$this->ws['b_up']->connect("leave", array(& $this, "b_up_away"));
			$this->ws['ctree']->connect("tree-expand", array(& $this, "expandNode"));//maybe use connect_after***
			$this->ws['ctree']->connect("tree-select-row", array(& $this, "selectRow"));
			$this->ws['ctree']->connect("tree-unselect-row", array(& $this, "unselectRow"));
			$this->ws['b_ok']->connect("clicked", array(& $this, "b_ok"));
			$this->ws['b_cancel']->connect("clicked", array(& $this, "b_cancel"));
			
			// Shows the dialog and goes into the main loop.
			$this->ws['window']->show_all();
		}
		
		/* Event callbacks. */
		
		// If a node is expanded.
		function expandNode($ctree, $node)
		{
			$this->ws['ctree']->freeze();
			
			// Get the dir of the node that was expanded.
			list($nodeData, $fillerNode)=$this->ws['ctree']->node_get_row_data($node);
			
			if( $nodeData != "ROOT" )
			{
				$this->lastSelection=& $node;
				
				// Remove the filer node.
				$this->ws['ctree']->remove_node($fillerNode);
				
				// Get the list for that directory and adds it to the node.
				$fsNodes=$this->getDirContents($nodeData);
				$pending=array();
				foreach($fsNodes as $fsNode)
				{	
					// If its a directory add it instantly.
					if( is_dir($fsNode) )
					{
						$dirData=explode($this->slash, $fsNode);
						//$dirOnly=$dirData[count($dirData) - 1]; // will be end() better? uh?
						$dirOnly = end($dirData);
						$newNode=$this->ws['ctree']->insert_node($node, NULL, array($dirOnly), 5, $this->images['gdk']['closed_folder'], $this->images['mask']['closed_folder'], $this->images['gdk']['open_folder'], $this->images['mask']['open_folder'], FALSE, FALSE);	
						$fillerNode=$this->ws['ctree']->insert_node($newNode, NULL, array("should not see this"), 5, NULL, NULL, NULL, NULL, FALSE, FALSE);	
						$this->ws['ctree']->node_set_row_data($newNode, array($fsNode, $fillerNode));	
					}
					// Otherwise add it to the pending array.
					else
					{
						$pending[]=$fsNode;	
					}
				}
				
				// Process the pending files.
				foreach($pending as $file)
				{
					$fileData=explode($this->slash, $file);
					//$filenameOnly=$fileData[count($fileData) - 1]; // end()
					$filenameOnly = end($fileData);
					$newNode=$this->ws['ctree']->insert_node($node, NULL, array($filenameOnly), 5, $this->images['gdk']['file'], $this->images['mask']['file'], $this->images['gdk']['file'], $this->images['mask']['file'], FALSE, FALSE);
					$this->ws['ctree']->node_set_row_data($newNode, array($file, $fillerNode));
				}
			}
			
			$this->ws['ctree']->thaw();
		}
		
		// If a row is selected.
		function selectRow($ctree, $node)
		{
			list($nodeData, $fillerNode)=$this->ws['ctree']->node_get_row_data($node);
			if( is_dir($nodeData) )
			{
				$nodeData .= $this->slash;
			}
			$this->ws['path_entry']->set_text($nodeData);
			$this->ws['b_ok']->set_sensitive(TRUE);
		}
		
		// If a row is deselected.
		function unselectRow()
		{
			$this->ws['path_entry']->set_text("");
			$this->ws['b_ok']->set_sensitive(FALSE);	
		}
		
		/* Signal callbacks. */
		
		// If the button ok is pressed.	
		function b_ok()
		{
			$node=$this->ws['ctree']->selection[0];
			list($nodeData, $fillerNode)=$this->ws['ctree']->node_get_row_data($node);
			if( is_dir($nodeData) )
			{
				$nodeData .= $this->slash;
			}
			$this->ws['path_entry']->set_text($nodeData);
			$this->selection=$nodeData;
			$this->b_cancel();
		}
		
		// If the button cancel is pressed.
		function b_cancel()
		{
			$this->ws['window']->hide();
			$this->ws['window']->destroy();
			Gtk::main_quit();
		}
		
		/* Misc functions. */
		
		// Takes a full path of a directory and expands all nodes in the path.
		function gotoDir($dir)
		{
			$dir=trim($dir);
			
			// Trims any trailing slashes.
			if( $dir{strlen($dir) - 1} == $this->slash )
			{
				$dir=substr($dir, 0, (strlen($dir) - 1));
			}
			
			$currentNode=$this->ws['ctree']->node_nth(0);			// Sets the parent node to be ROOT.
			$dirParts=explode($this->slash, $dir);
			$dirPartsLevel=0;
			for($i=0; $i < count($dirParts); $i++)
			{
				$currentNodeChildren=$currentNode->children;
				foreach($currentNodeChildren as $childNode)
				{
					list($nodeData, $fillerNode)=$this->ws['ctree']->node_get_row_data($childNode);
					$nodeDataParts=explode($this->slash, $nodeData);
					$nodeText=$nodeDataParts[$dirPartsLevel];
					
					if( $nodeText == $dirParts[$dirPartsLevel] )
					{
						$dirPartsLevel++;
						$this->ws['ctree']->expand($childNode);
						$currentNode=$childNode;
						break;
					}
				}	
			}
		}
		
		// Loads the xpm's.
		function loadImages($gdkwindow)
		{
			$transparent=new GdkColor(0, 0, 0);
			
			$pixmapRoot=array( 		
			/* width height num_colors chars_per_pixel */
			"    16    16       64            2",
			/* colors */
			"`` c none",
			"`. c #1caefc",
			"`# c #9893aa",
			"`a c #94e6fc",
			"`b c #9cb6a4",
			"`c c #41befc",
			"`d c #d0cddb",
			"`e c #70689c",
			"`f c #7e7cac",
			"`g c #e8e7ec",
			"`h c #a2a3b8",
			"`i c #b5b1cb",
			"`j c #8cbed4",
			"`k c #e2e1e9",
			"`l c #7f7ecf",
			"`m c #6199e1",
			"`n c #767099",
			"`o c #c2c0d5",
			"`p c #a2a5cf",
			"`q c #d6d4e1",
			"`r c #8987ab",
			"`s c #70d3fc",
			"`t c #7274bf",
			"`u c #9492c4",
			"`v c #64b2f4",
			"`w c #f7f9f7",
			"`x c #8990c4",
			"`y c #88d8f8",
			"`z c #a5ecfc",
			"`A c #a0b0d4",
			"`B c #bab8d9",
			"`C c #777699",
			"`D c #aca9d4",
			"`E c #3c9ae4",
			"`F c #44aaec",
			"`G c #b4d2dc",
			"`H c #bffbfc",
			"`I c #54bafc",
			"`J c #74cefc",
			"`K c #94bee0",
			"`L c #8c8abc",
			"`M c #54b6f4",
			"`N c #849edc",
			"`O c #acc2d4",
			"`P c #749adc",
			"`Q c #8adffc",
			"`R c #f2f0f0",
			"`S c #b4e2ec",
			"`T c #5ac7fc",
			"`U c #6c66c4",
			"`V c #8c82a4",
			"`W c #7c76ac",
			"`X c #9c9ebc",
			"`Y c #a0aec0",
			"`Z c #acaac0",
			"`0 c #999ecc",
			"`1 c #3cb6fc",
			"`2 c #8482ac",
			"`3 c #c4c6dc",
			"`4 c #7cd2fc",
			"`5 c #acaed4",
			"`6 c #8cc6ec",
			"`7 c #74b2ec",
			"`8 c #9793b9",
			/* pixels */
			"`````````````R`k`d``````````````",
			"`R`g`k`q`o`i`Z`p`x`X`k``````````",
			"`d`o`h`Y`O`G`S`z`6`p`3`o`3`q`d`k",
			"`d`j`Q`z`H`H`H`z`y`D`g`g`q`D`l`W",
			"`q`K`Q`a`z`z`z`a`4`0`o`D`t`U`t`e",
			"`k`K`s`y`Q`Q`Q`y`J`N`B`p`t`u`L`e",
			"`R`A`T`J`s`s`s`J`T`P`B`D`2`f`f`n",
			"```5`I`c`T`T`T`T`c`m`B`D`2`x`x`n",
			"```B`F`c`c`c`I`I`m`x`B`5`L`u`2`e",
			"```q`E`.`1`v`P`l`D`D`5`5`r`W`2`C",
			"```q`P`7`0`l`U`U`o`3`B`p`f`#`b`C",
			"`g`q`B`d`3`0`W`t`0`8`D`5`h`#`n`#",
			"`d`w`w`w`q`i`u`2`p`L`h`h`2`V`3``",
			"`o`k`R`k`q`B`X`r`p`n`d```q``````",
			"`k`Z`o`q`q`B`X`8`n`V````````````",
			"```g`i`#`V`C`C`V`i``````````````"			
			); 		
			list ($this->images['gdk']['root'], $this->images['mask']['root'])=gdk::pixmap_create_from_xpm_d($gdkwindow, $transparent, $pixmapRoot);
			$this->images['gtk']['root']=new GtkPixmap($this->images['gdk']['root'], $this->images['mask']['root']);
			
			$pixmapDrive=array( 		
			"    16    16       64            2",
			/* colors */
			"`` c #34322c",
			"`. c #8c8e8c",
			"`# c #cccecc",
			"`a c none",
			"`b c #6c6a74",
			"`c c #acaeac",
			"`d c #eceaec",
			"`e c #9c9e9c",
			"`f c #848684",
			"`g c #4c4a4c",
			"`h c #dcdedc",
			"`i c #747674",
			"`j c #545664",
			"`k c #9c9abc",
			"`l c #bcbebc",
			"`m c #f4f6f4",
			"`n c #949694",
			"`o c #d4d6d4",
			"`p c #9c9ec4",
			"`q c #747274",
			"`r c #acaaac",
			"`s c #5c5e5c",
			"`t c #949294",
			"`u c #d4d2e4",
			"`v c #6c6e74",
			"`w c #bcbabc",
			"`x c #f4f2f4",
			"`y c #a4a2a4",
			"`z c #8c8a8c",
			"`A c #54525c",
			"`B c #e4e6e4",
			"`C c #7c7a7c",
			"`D c #c4c6c4",
			"`E c #44424c",
			"`F c #fcfefc",
			"`G c #d4d2d4",
			"`H c #b4b2b4",
			"`I c #e4e2e4",
			"`J c #c4c2c4",
			"`K c #fcfafc",
			"`L c #9c9a9c",
			"`M c #dcdadc",
			"`N c #5c5a64",
			"`O c #4c4e54",
			"`P c #eceeec",
			"`Q c #8c8e94",
			"`R c #6c6a7c",
			"`S c #84868c",
			"`T c #74767c",
			"`U c #5c5e64",
			"`V c #a4a2ac",
			"`W c #000000",
			"`X c #000000",
			"`Y c #000000",
			"`Z c #000000",
			"`0 c #000000",
			"`1 c #000000",
			"`2 c #000000",
			"`3 c #000000",
			"`4 c #000000",
			"`5 c #000000",
			"`6 c #000000",
			"`7 c #000000",
			"`8 c #000000",
			/* pixels */
			"`a`a`a`a`a`a`a`a`a`a`a`a`a`a`a`a",
			"`a`a`a`a`a`a`a`a`a`a`a`a`a`a`a`a",
			"`a`a`a`a`a`a`a`a`a`a`a`a`a`a`a`a",
			"`a`a`a`a`a`a`a`a`a`a`a`a`a`a`a`a",
			"`a`a`a`a`G`G`G`M`G`#`M`a`a`a`a`a",
			"`d`I`D`t`z`w`x`F`x`M`I`M`#`#`a`a",
			"`l`#`G`J`o`M`d`K`P`h`P`m`u`y`f`a",
			"`r`y`H`J`o`I`M`o`o`D`r`t`N`b`k`q",
			"`w`n`r`y`e`c`#`H`f`q`C`q```b`k`q",
			"`a`a`n`y`r`y`z`t`g`s`i`q`A`N`q`a",
			"`a`a`a`a`L`.`.`y`N`E`O`N`f`a`a`a",
			"`a`a`a`a`a`a`e`f`N`b`a`a`a`a`a`a",
			"`a`a`a`a`a`a`a`a`a`a`a`a`a`a`a`a",
			"`a`a`a`a`a`a`a`a`a`a`a`a`a`a`a`a",
			"`a`a`a`a`a`a`a`a`a`a`a`a`a`a`a`a",
			"`a`a`a`a`a`a`a`a`a`a`a`a`a`a`a`a"
			); 		
			list ($this->images['gdk']['drive'], $this->images['mask']['drive'])=gdk::pixmap_create_from_xpm_d($gdkwindow, $transparent, $pixmapDrive);
			$this->images['gtk']['drive']=new GtkPixmap($this->images['gdk']['drive'], $this->images['mask']['drive']);
			
			$pixmapOpenFolder=array( 		
			/* width height num_colors chars_per_pixel */
			"    16    16       64            2",
			/* colors */
			"`` c none",
			"`. c #cea222",
			"`# c #ffffff",
			"`a c #c69a19",
			"`b c #ffff9c",
			"`c c #fff39c",
			"`d c #fff38c",
			"`e c #9d7b1a",
			"`f c #ffeb84",
			"`g c #e2c150",
			"`h c #b18919",
			"`i c #ffd784",
			"`j c #dabf6c",
			"`k c #fffbf7",
			"`l c #ffe784",
			"`m c #a17e19",
			"`n c #fdd570",
			"`o c #f7f089",
			"`p c #ffc75b",
			"`q c #fbf996",
			"`r c #9b7b19",
			"`s c #e2b343",
			"`t c #c9a021",
			"`u c #ffffa5",
			"`v c #fff794",
			"`w c #e7be53",
			"`x c #cebc5c",
			"`y c #a5730d",
			"`z c #cfa226",
			"`A c #d7b840",
			"`B c #efba43",
			"`C c #656565",
			"`D c #c69a1a",
			"`E c #f0e47a",
			"`F c #ffe37c",
			"`G c #ffdf7c",
			"`H c #deb243",
			"`I c #c79c1c",
			"`J c #ffd76c",
			"`K c #bf9929",
			"`L c #717171",
			"`M c #898989",
			"`N c #000000",
			"`O c #000000",
			"`P c #000000",
			"`Q c #000000",
			"`R c #000000",
			"`S c #000000",
			"`T c #000000",
			"`U c #000000",
			"`V c #000000",
			"`W c #000000",
			"`X c #000000",
			"`Y c #000000",
			"`Z c #000000",
			"`0 c #000000",
			"`1 c #000000",
			"`2 c #000000",
			"`3 c #000000",
			"`4 c #000000",
			"`5 c #000000",
			"`6 c #000000",
			"`7 c #000000",
			"`8 c #000000",
			/* pixels */
			"````````````````````````````````",
			"`````.`.`.`.````````````````````",
			"```.`#`#`#`#`a``````````````````",
			"`a`#`b`b`b`b`#`a`a`a`a`a`a``````",
			"`a`c`d`d`d`d`d`#`#`#`#`#`a`e````",
			"`a`f`g`a`a`a`a`a`a`a`a`a`a`a`h``",
			"`a`i`a`j`#`#`k`#`#`#`#`#`l`#`m``",
			"`a`n`a`o`b`b`b`b`b`b`b`b`p`q`r``",
			"`a`s`t`u`v`v`v`v`v`v`v`v`w`x`y``",
			"`a`z`A`b`f`f`f`f`f`f`f`l`B`a`C``",
			"`a`D`E`b`F`F`F`F`F`F`F`G`H`e`C``",
			"`a`I`b`J`J`J`J`J`J`J`J`J`K`y`L``",
			"```y`y`y`y`y`y`y`y`y`y`y`y`C`M``",
			"`````M`L`L`L`L`L`L`L`L`L`L`M````",
			"````````````````````````````````",
			"````````````````````````````````" 			
			); 		
			list ($this->images['gdk']['open_folder'], $this->images['mask']['open_folder'])=gdk::pixmap_create_from_xpm_d($gdkwindow, $transparent, $pixmapOpenFolder);
			$this->images['gtk']['open_folder']=new GtkPixmap($this->images['gdk']['open_folder'], $this->images['mask']['open_folder']);
					 	
			
			$pixmapClosedFolder=array(
			"    16    16       64            2",
			/* colors */
			"`` c none",
			"`. c #cc9934",
			"`# c #cb9833",
			"`a c #c99631",
			"`b c #c7942f",
			"`c c #ffffff",
			"`d c #c28f2a",
			"`e c #ffff99",
			"`f c #bd8a25",
			"`g c #ba8722",
			"`h c #b7841f",
			"`i c #b5821d",
			"`j c #b3811b",
			"`k c #b07e18",
			"`l c #fff791",
			"`m c #fff48e",
			"`n c #ae7c16",
			"`o c #8c8c8c",
			"`p c #ffeb85",
			"`q c #ffe681",
			"`r c #c5922d",
			"`s c #c08d28",
			"`t c #bc8924",
			"`u c #b88520",
			"`v c #b4811c",
			"`w c #ffe07b",
			"`x c #a3710b",
			"`y c #ffd46f",
			"`z c #f8c560",
			"`A c #a06e08",
			"`B c #6e6e6e",
			"`C c #ffcc67",
			"`D c #efbc57",
			"`E c #9e6c06",
			"`F c #6d6d6d",
			"`G c #e6b34e",
			"`H c #9c6a04",
			"`I c #bf8c27",
			"`J c #dca944",
			"`K c #9a6802",
			"`L c #d3a03b",
			"`M c #996701",
			"`N c #ab7913",
			"`O c #a87610",
			"`P c #a5730d",
			"`Q c #4c4c4c",
			"`R c #838383",
			"`S c #000000",
			"`T c #000000",
			"`U c #000000",
			"`V c #000000",
			"`W c #000000",
			"`X c #000000",
			"`Y c #000000",
			"`Z c #000000",
			"`0 c #000000",
			"`1 c #000000",
			"`2 c #000000",
			"`3 c #000000",
			"`4 c #000000",
			"`5 c #000000",
			"`6 c #000000",
			"`7 c #000000",
			"`8 c #000000",
			/* pixels */
			"````````````````````````````````",
			"`````.`#`a`b````````````````````",
			"```.`c`c`c`c`d``````````````````",
			"`.`c`e`e`e`e`c`f`g`h`i`j`k``````",
			"`#`l`m`m`m`m`m`c`c`c`c`c`n`o````",
			"`a`p`q`r`r`r`r`r`r`s`t`u`v`j`j``",
			"`b`w`r`c`c`c`c`c`c`c`c`c`q`c`x`o",
			"`r`y`.`e`e`e`e`e`e`e`e`e`z`e`A`B",
			"`d`C`#`e`l`l`l`l`l`l`l`l`D`e`E`F",
			"`s`C`r`e`p`p`p`p`p`p`p`p`G`e`H`F",
			"`f`C`I`e`w`w`w`w`w`w`w`w`J`e`K`F",
			"`g`C`u`e`y`y`y`y`y`y`y`y`L`e`M`B",
			"```i`j`k`n`N`O`P`x`A`E`H`K`M`Q`R",
			"`````R`F`F`F`F`F`F`F`F`F`F`F`R``",
			"````````````````````````````````",
			"````````````````````````````````"			
			); 	
			list ($this->images['gdk']['closed_folder'], $this->images['mask']['closed_folder'])=gdk::pixmap_create_from_xpm_d($gdkwindow, $transparent, $pixmapClosedFolder);
			$this->images['gtk']['closed_folder']=new GtkPixmap($this->images['gdk']['closed_folder'], $this->images['mask']['closed_folder']);
			
			$pixmapFile=array( 		
			/* width height num_colors chars_per_pixel */
			"    16    16       64            2",
			/* colors */
			"`` c #040204",
			"`. c #04a604",
			"`# c #848384",
			"`a c #bcc6cc",
			"`b c #c4e2dc",
			"`c c #d40204",
			"`d c #545458",
			"`e c #cc9aac",
			"`f c #e4e2bc",
			"`g c #a4a298",
			"`h c #e4f2d4",
			"`i c #fccec4",
			"`j c #65676c",
			"`k c #040284",
			"`l c #d4d4ca",
			"`m c #f4f2f0",
			"`n c #b48aac",
			"`o c #949396",
			"`p c #acaea5",
			"`q c #dccacc",
			"`r c #747474",
			"`s c #fcfee4",
			"`t c #cccab4",
			"`u c #3c3e84",
			"`v c #442e2c",
			"`w c #8c8d8c",
			"`x c #745e6c",
			"`y c #bcb9be",
			"`z c #fce2dc",
			"`A c #fcfefb",
			"`B c #4c4ca0",
			"`C c #e4e6dc",
			"`D c #dcdec4",
			"`E c #c47e4c",
			"`F c #4486a4",
			"`G c none",
			"`H c #040474",
			"`I c #0402fc",
			"`J c #34ae3c",
			"`K c #cc7ebc",
			"`L c #ecb2d4",
			"`M c #d48afc",
			"`N c #2c2a7c",
			"`O c #fcdafc",
			"`P c #5c5e94",
			"`Q c #d8eae4",
			"`R c #2c32b4",
			"`S c #e4dec4",
			"`T c #e4f6fc",
			"`U c #c4eefc",
			"`V c #6c6a94",
			"`W c #3c3aa8",
			"`X c #0c0e7c",
			"`Y c #acaaa8",
			"`Z c #b4b6b4",
			"`0 c #7c7a78",
			"`1 c #9c9a98",
			"`2 c #ecfef8",
			"`3 c #ccccc8",
			"`4 c #c4c3c1",
			"`5 c #b4b2ad",
			"`6 c #eceae4",
			"`7 c #3436a4",
			"`8 c #e4e2d4",
			/* pixels */
			"`G`4`1`5`p`p`p`p`p`p`Y`o`G`G`G`G",
			"`G`5`s`A`A`A`A`A`A`A`A`g`#`G`G`G",
			"`G`5`8`A`A`A`A`A`A`A`A`3`m`0`G`G",
			"`G`5`6`A`A`A`A`A`A`A`A`t`r```w`G",
			"`G`5`A`S`v`k`H`H`X`V`P`u`r`Y`1`G",
			"`G`Y`A`D`x`R`W`7`W`B`B`N`#`A`w`G",
			"`G`5`s`y`s`A`A`A`A`A`A`f`0`A`w`G",
			"`G`5`m`y`2`i`e`U`A`C`A`y`r`A`w`G",
			"`G`5`A`a`T`c`E`I`M`.`F`z`r`A`w`G",
			"`G`5`s`y`2`n`A`K`L`J`b`q`r`A`o`G",
			"`G`Y`A`4`s`Q`A`h`A`O`A`l`r`A`w`G",
			"`G`5`A`5`g`l`4`3`4`3`l`w`j`A`#`G",
			"`G`5`A`4`d`j`j`j`j`j`j`d`l`6`o`G",
			"`G`5`S`A`A`A`A`A`A`A`A`A`A`3`o`G",
			"`G`5`A`A`A`A`A`A`A`A`A`A`A`m`o`G",
			"`G`y`r`#`#`#`#`#`#`#`#`#`w`j`Y`G"	
			); 		
			list ($this->images['gdk']['file'], $this->images['mask']['file'])=gdk::pixmap_create_from_xpm_d($gdkwindow, $transparent, $pixmapFile);
			$this->images['gtk']['file']=new GtkPixmap($this->images['gdk']['file'], $this->images['mask']['file']);
			
			$pixmapUpAway=array( 		
			/* width height num_colors chars_per_pixel */
			"    24    24       64            2",
			/* colors */
			"`` c #046604",
			"`. c #14900c",
			"`# c #9cb24c",
			"`a c #8cf25c",
			"`b c #e7d194",
			"`c c #fcee88",
			"`d c #cc9c08",
			"`e c #50c028",
			"`f c #deb739",
			"`g c #e8eee4",
			"`h c #5c9a5c",
			"`i c #e4d9a9",
			"`j c #21a711",
			"`k c none",
			"`l c #2c8228",
			"`m c #dcc064",
			"`n c #f0de78",
			"`o c #fcfd98",
			"`p c #dbaf34",
			"`q c #107b0a",
			"`r c #fcfdd0",
			"`s c #349624",
			"`t c #74d840",
			"`u c #44a629",
			"`v c #fcd078",
			"`w c #ecc856",
			"`x c #fcfcaf",
			"`y c #fcfdef",
			"`z c #ecdaa4",
			"`A c #e4ae2c",
			"`B c #208a14",
			"`C c #189e0c",
			"`D c #90ba8c",
			"`E c #c4dac4",
			"`F c #84a848",
			"`G c #fc36d4",
			"`H c #66cd34",
			"`I c #247604",
			"`J c #3ca024",
			"`K c #a4c6a4",
			"`L c #2fb31c",
			"`M c #d4e2d4",
			"`N c #f4c664",
			"`O c #4c924c",
			"`P c #4ab427",
			"`Q c #f1e5bf",
			"`R c #f8f0d4",
			"`S c #fcf2bc",
			"`T c #9fc05c",
			"`U c #80e44c",
			"`V c #3e8936",
			"`W c #208014",
			"`X c #7cae74",
			"`Y c #2ca214",
			"`Z c #2c921b",
			"`0 c #fce27f",
			"`1 c #14700e",
			"`2 c #dfc779",
			"`3 c #fce6a4",
			"`4 c #d4a417",
			"`5 c #fcd874",
			"`6 c #ecda9c",
			"`7 c #5cc23c",
			"`8 c #94fe64",
			/* pixels */
			"`k`k`k`k`k`k`k`k`k`k`k`k`k`k`k`k`k`k`k`k`k`k`k`k",
			"`k`k`k`k`k`k`k`k`k`k`k`K```D`k`k`k`k`k`k`k`k`k`k",
			"`k`k`k`k`k`k`k`k`k`k`k`1`.`q`V`k`k`k`k`k`k`k`k`k",
			"`k`k`k`k`k`k`k`k`k`k`O`.`j`L`Y`I`X`k`k`k`k`k`k`k",
			"`k`k`k`k`k`k`k`k`k`k`1`j`L`L`P`P`Z`l`k`k`k`k`k`k",
			"`k`k`k`k`k`k`k`k`k`1`C`L`L`P`e`H`H`P`1`F`k`k`k`k",
			"`k`k`k`k`k`k`k`k`O`.`L`Y`P`e`H`H`P`B`W```h`k`k`k",
			"`k`k`k`k`A`A`p`A```1`V`V`B`H`H`H`Z`k`k`k`k`k`k`k",
			"`k`k`k`4`b`R`y`r`Q`2`g`g`I`P`H`t`Z`k`k`k`k`k`k`k",
			"`k`k`k`A`R`o`o`o`r`z`f`A`T`u`t`t`Z`k`k`k`k`k`k`k",
			"`k`k`k`A`x`o`o`o`o`x`o`o`o`u`t`U`Z`A`4`A`k`k`k`k",
			"`k`k`k`4`o`o`o`o`o`o`o`o`A`J`U`U`Z`Q`Q`y`d`k`k`k",
			"`k`k`k`4`3`c`c`c`c`c`5`f`y`u`U`a`Z`y`y`Q`d`k`k`k",
			"`k`k`k`4`3`0`w`A`f`f`f`R`x`u`a`a`l`y`y`d`k`k`k`k",
			"`k`k`k`4`v`N`2`y`r`x`x`x`x`u`a`7`F`r`S`d`k`k`k`k",
			"`k`k`k`d`v`A`R`o`o`o`o`o`T`u`a`B`n`r`d`k`k`k`k`k",
			"`k`k`k`d`N`f`r`o`o`o`o`o`W`8`s`T`0`x`m`k`k`k`k`k",
			"`k`k`k`d`N`b`S`c`o`c`c`T`J`s`F`o`0`d`k`k`k`k`k`k",
			"`k`k`k`d`A`R`c`c`c`c`c`V`1`T`c`0`v`d`k`k`k`k`k`k",
			"`k`k`k`d`A`y`0`0`5`0`5`#`w`f`A`d`4`k`k`k`k`k`k`k",
			"`k`k`k`d`m`3`5`v`w`f`4`d`4`m`k`k`k`k`k`k`k`k`k`k",
			"`k`k`k`d`Q`A`4`d`p`k`k`k`k`k`k`k`k`k`k`k`k`k`k`k",
			"`k`k`k`d`d`k`k`k`k`k`k`k`k`k`k`k`k`k`k`k`k`k`k`k",
			"`k`k`k`k`k`k`k`k`k`k`k`k`k`k`k`k`k`k`k`k`k`k`k`k",
			); 		
			list ($this->images['gdk']['up_away'], $this->images['mask']['up_away'])=gdk::pixmap_create_from_xpm_d($gdkwindow, $transparent, $pixmapUpAway);
			$this->images['gtk']['up_away']=new GtkPixmap($this->images['gdk']['up_away'], $this->images['mask']['up_away']);
			
			$pixmapUpOver=array( 		
			/* width height num_colors chars_per_pixel */
			"    24    24       64            2",
			/* colors */
			"`` c #045104",
			"`. c #0c8608",
			"`# c #bc8204",
			"`a c #acc2a4",
			"`b c #e0c47c",
			"`c c #fce870",
			"`d c #c48604",
			"`e c #e0e8dc",
			"`f c #d6a320",
			"`g c #49bd1e",
			"`h c #fc02c4",
			"`i c #dcca94",
			"`j c #136b0b",
			"`k c #4c824c",
			"`l c #fcf4d0",
			"`m c #ce9416",
			"`n c #d9b657",
			"`o c #fcf484",
			"`p c #1f9f0c",
			"`q c #f9d563",
			"`r c #2c6e14",
			"`s c #fcfbed",
			"`t c #cc9a34",
			"`u c #fcf29c",
			"`v c #076204",
			"`w c #dcb63c",
			"`x c #68dc34",
			"`y c #e6d098",
			"`z c #087804",
			"`A c #d59c23",
			"`B c #f2e9c7",
			"`C c #289013",
			"`D c #8c9e34",
			"`E c #84fe4c",
			"`F c #44b224",
			"`G c #7ca27c",
			"`H c #94b290",
			"`I c #faca59",
			"`J c #649430",
			"`K c #f0ba50",
			"`L c #58cc2c",
			"`M c #e9dbb3",
			"`N c #74ec41",
			"`O c #8fb03f",
			"`P c #f8e89c",
			"`Q c #34ac14",
			"`R c #ccd6c4",
			"`S c none",
			"`T c #0c9104",
			"`U c #fcdb6c",
			"`V c #387438",
			"`W c #efba3c",
			"`X c #1c7b0e",
			"`Y c #5c8e5c",
			"`Z c #32a114",
			"`0 c #eceadc",
			"`1 c #fcfecb",
			"`2 c #fcfc82",
			"`3 c #e4a634",
			"`4 c #c68c0e",
			"`5 c #fcfea5",
			"`6 c #145614",
			"`7 c #d9ba71",
			"`8 c #145c11",
			/* pixels */
			"`S`S`S`S`S`S`S`S`S`S`S`S`S`S`S`S`S`S`S`S`S`S`S`S",
			"`S`S`S`S`S`S`S`S`S`S`S`a`6`H`S`S`S`S`S`S`S`S`S`S",
			"`S`S`S`S`S`S`S`S`S`S`0`6`z`v`V`S`S`S`S`S`S`S`S`S",
			"`S`S`S`S`S`S`S`S`S`S`k`z`T`p`.`j`G`S`S`S`S`S`S`S",
			"`S`S`S`S`S`S`S`S`S`S`v`T`p`p`Q`Z`X`r`S`S`S`S`S`S",
			"`S`S`S`S`S`S`S`S`S```.`p`p`Q`Q`g`g`Z`8`Y`S`S`S`S",
			"`S`S`S`S`S`S`S`S`k`z`p`C`p`Q`g`g`Z`j`j```Y`S`S`S",
			"`S`S`S`S`A`A`A`f```8`V`V`j`g`g`g`X`S`S`S`S`S`S`S",
			"`S`S`S`m`y`l`1`1`B`7`S`S`8`Z`g`L`X`S`S`S`S`S`S`S",
			"`S`S`S`A`5`2`2`2`5`y`A`A`O`C`L`L`X`S`S`S`S`S`S`S",
			"`S`S`S`A`2`2`2`2`2`2`2`2`2`C`L`x`X`m`m`A`S`S`S`S",
			"`S`S`S`m`2`2`2`2`2`2`2`o`f`C`x`x`X`M`P`s`d`S`S`S",
			"`S`S`S`m`c`c`c`c`c`c`q`f`l`C`x`N`X`s`s`M`d`S`S`S",
			"`S`S`S`m`U`q`W`A`f`A`f`l`5`C`N`N`j`s`s`d`S`S`S`S",
			"`S`S`S`4`I`W`n`1`1`5`5`5`2`C`N`F`J`1`u`d`S`S`S`S",
			"`S`S`S`d`I`A`B`2`2`2`2`2`O`C`N`j`q`5`#`S`S`S`S`S",
			"`S`S`S`d`K`A`1`2`2`2`2`o`j`E`X`O`U`u`n`S`S`S`S`S",
			"`S`S`S`#`K`b`u`c`o`c`c`O`C`X`J`o`U`#`S`S`S`S`S`S",
			"`S`S`S`d`3`B`c`c`c`c`c`r```O`c`c`I`d`S`S`S`S`S`S",
			"`S`S`S`#`A`l`q`q`q`q`q`D`w`3`m`d`4`S`S`S`S`S`S`S",
			"`S`S`S`#`n`U`I`I`W`f`m`#`m`7`S`S`S`S`S`S`S`S`S`S",
			"`S`S`S`#`B`A`4`d`t`S`S`S`S`S`S`S`S`S`S`S`S`S`S`S",
			"`S`S`S`#`#`S`S`S`S`S`S`S`S`S`S`S`S`S`S`S`S`S`S`S",
			"`S`S`S`S`S`S`S`S`S`S`S`S`S`S`S`S`S`S`S`S`S`S`S`S"
			); 		
			list ($this->images['gdk']['up_over'], $this->images['mask']['up_over'])=gdk::pixmap_create_from_xpm_d($gdkwindow, $transparent, $pixmapUpOver);
			$this->images['gtk']['up_over']=new GtkPixmap($this->images['gdk']['up_over'], $this->images['mask']['up_over']);
		}
				
		// If the "up" button is clicked.
		function b_up_clicked()
		{
			$node=$this->lastSelection;
			list($nodeData, $fillerNode)=$this->ws['ctree']->node_get_row_data($node);
			
			if( $nodeData != "ROOT" )
			{
				$this->ws['ctree']->freeze();
				
				$children=$node->children;
				foreach($children as $child)
				{
					$this->ws['ctree']->remove_node($child);
				}
				
				if( count($children) > 0 )
				{
					$fillerNode=$this->ws['ctree']->insert_node($node, NULL, array("should not see this"), 5, NULL, NULL, NULL, NULL, FALSE, FALSE);
					$this->ws['ctree']->node_set_row_data($node, array($nodeData, $fillerNode));			
				}
				
				$this->lastSelection=$node->parent;
				
				$this->ws['ctree']->collapse($node);
				$this->ws['ctree']->thaw();
			}
			
		}
		
		// If the "up" button is hovered over.
		function b_up_over()
		{
			$this->ws['up_vbox']->remove($this->images['gtk']['up_away']);
			$this->ws['up_vbox']->pack_start($this->images['gtk']['up_over'], FALSE, FALSE, 0);			
			$this->ws['b_up']->show_all();				
		}
		
		// If the "up" button is not hovered over.
		function b_up_away()
		{
			$this->ws['up_vbox']->remove($this->images['gtk']['up_over']);
			$this->ws['up_vbox']->pack_start($this->images['gtk']['up_away'], FALSE, FALSE, 0);			
			$this->ws['b_up']->show_all();	
		}		
		
		// Adds the drives to the file dialog.
		function popCtree()
		{
			// The root node.
			$rootNode=$this->ws['ctree']->insert_node(NULL, NULL, array("My Computer"), 5, $this->images['gdk']['root'], $this->images['mask']['root'], $this->images['gdk']['root'], $this->images['mask']['root'], FALSE, TRUE);
			$this->ws['ctree']->node_set_selectable($rootNode, FALSE);	
			$this->ws['ctree']->node_set_row_data($rootNode, array("ROOT", NULL));
			
			// The drives.
			
   	   $oldFileDialog=&new GtkFileselection("irrelevant");
			
   		if (strtoupper(substr(PHP_OS, 0, 3)) == "WIN")
   		{
   			$oldFileDialog->set_filename("C:".$this->slash);
  			}
  			else
  			{
            $oldFileDialog->set_filename($this->slash);
		   }
		   
		   $oldFileDialog->hide();
			
			$drive_list=$oldFileDialog->dir_list;
			for ($i=0; ; $i++)
			{
				@ $text=$drive_list->get_text($i, 0);	
				if ($text == "")
				{
					break;
				}
				else if ( $text == "./" || $text == "../" )
				{
				  continue;
            }
				else if ( strstr($text, ":") || strtoupper(substr(PHP_OS,0,3)) != "WIN" )
				{
				
				  if(strtoupper(substr(PHP_OS,0,3)) != "WIN")
				  {
				     $text = $this->slash.$text;
              }
					// Create the node.
					$driveNode=$this->ws['ctree']->insert_node($rootNode, NULL, array($text), 5, $this->images['gdk']['drive'], $this->images['mask']['drive'], $this->images['gdk']['drive'], $this->images['mask']['drive'], FALSE, FALSE);	
					
					// Sets an arbitrary filler so it appears as an expandable node.	
					$fillerNode=$this->ws['ctree']->insert_node($driveNode, NULL, array("should not see this"), 5, NULL, NULL, NULL, NULL, FALSE, FALSE);
					
					// Set the filler node and dir text as node data.
					$this->ws['ctree']->node_set_row_data($driveNode, array(substr($text, 0, strlen($text) - 1), $fillerNode));
				}
			}
			
			$this->lastSelection=& $driveNode;
		}
		
		// Returns an array of filesytem nodes for a particular directory.
		function getDirContents($dir)
		{
		
			$array=array();  
			@ $dp=opendir($dir);
			while ( @ $fsNode = readdir($dp) )
			{	
				if( ($fsNode != ".") && ($fsNode != ".." ) )
				{
							
					$fullPath=$dir.$this->slash.$fsNode;
					$fullPath=str_replace($this->slash.$this->slash, $this->slash, $fullPath);
						
					if( ($this->dispFiles == TRUE) || (is_dir($fullPath)) )
					{
						$array[]=$fullPath;
					}
					
				}
			}
			@ closedir($dp);
			sort($array, SORT_STRING);
			
			return $array;
		}
	}
?>
Return current item: Multimedia Files Scanner