Location: PHPKode > scripts > EXPOW > expow/src/browser_functions.php
<?php
#
# Overall functions
#
# function to assist sub_tree_output()
function row_output($sub_level, &$c_browser_html, $fname = false)
{
    # name
    echo "<nobr>".$c_browser_html->sub_output($sub_level).$c_browser_html->entry($fname)
        ."</nobr></td>";
    # details
    if($c_browser_html->details_flag)
      echo $c_browser_html->table_row_details($fname);

    if ($c_browser_html->line_color == 'b')
         $c_browser_html->line_color = 'a';
    else $c_browser_html->line_color = 'b';
}

# recursive function to display sub tree.
# $level : from 0 to N where N is the top level
function sub_tree_output($level, &$c_browser_html)
{
  $sub_path_bak = $c_browser_html->sub_path;
  $level_bak = $level;
  while($c_browser_html->sub_path && $level){
    $next = $c_browser_html->up();
    $level--;
  }
  //echo "next=".$next;
  $dir = dir($c_browser_html->get_intern_path());
  $filebuf = array();
  $class = 'a';
  $nb=0;
  $sub_level = $c_browser_html->sub_tree_nblevels();

  # output
  while($fname=buf_read($dir,$filebuf,true)){
    # start tr
    if (!strcmp($c_browser_html->get_uri($fname),$next))
      echo "<tr class=opened><td><a name=open></a>";
    else
      echo "<tr class=".$c_browser_html->line_color."><td>";
    row_output($sub_level, $c_browser_html, $fname);
    echo "</tr>\n";
    # sub dir
    if (!strcmp($c_browser_html->get_uri($fname),$next)){
      if(is_dir($c_browser_html->get_intern_path($fname))){
        $sub_path_new = $c_browser_html->sub_path;
        $c_browser_html->sub_path = $sub_path_bak;
        $nb += sub_tree_output($level_bak-1,$c_browser_html);
        $c_browser_html->sub_path = $sub_path_new;
      }
    }
    $nb++;
  }
  $dir->close;
  if ($nb == 0)
    echo "<tr><td colspan=5>".$c_browser_html->sub_output($sub_level)."empty directory</td></tr>";
  $c_browser_html->sub_path = $sub_path_bak;
  return $nb;
}

function output_icons($c_browser)
{
  if (!is_dir($c_browser->get_intern_path())){
    echo "\n".$c_browser->make_icon()."\n";
    return 1;
  }
  $dir = dir($c_browser->get_intern_path());
  $nb_files = 0;
  $buf = array();
  while($fname=buf_read($dir,$buf,true)){
    echo "\n".$c_browser->make_icon($fname)."\n";
    $nb_files++;
  }
  if ( $nb_files == 0)
    echo "empty directory.";
  return $nb_files;
}

function side_tree ( $c_browser_html, $side_width = 12, $root_is_url = true )
{
  $string ="";
  $c_browser_html->zoom_percent = 100;
  while ($c_browser_html->path || $c_browser_html->sub_path){
    if ($c_browser_html->sub_path)
      $anchor = $c_browser_html->href_sub($c_browser_html->anchor2);
    else
      $anchor = $c_browser_html->href_direct($c_browser_html->anchor1);
    $string = $anchor->get()
             .$c_browser_html->img_html()."<br>"
             .nl2br(wordwrap($c_browser_html->get_entry(),$side_width,"\n",1))
             .$anchor->end()."<br>\n".$string;
    $c_browser_html->up();
  }
  if ($root_is_url)
    $anchor = $c_browser_html->href_direct($c_browser_html->anchor1);
  else
    $anchor = $c_browser_html->href_sub($c_browser_html->anchor2);
  return $anchor->get()
      .$c_browser_html->img_html()."<br>"
      .nl2br(wordwrap($c_browser_html->get_entry(),$side_width,"\n",1))
      .$anchor->end()."<br>\n".$string;
  $string = "<a href=\"".$c_browser_html->root_URL."\">"
       .$c_browser_html->img_html()."<br>"
       .nl2br(wordwrap($c_browser_html->get_entry(),$side_width,"\n",1))
       ."</a><br>\n".$string;
  return $string;
}

################################################################################
# Overall functions
#
#
################################################################################

# $dir->read() overlay that buffers normal files till no more directory
# can return directory names with trailing /
function buf_read($dir, &$file_buf, $trail_slash = false)
{
  $file = $dir->read();
  if (!$file)
    if (sizeof($file_buf) > 0)
      return array_shift($file_buf); // POP
    else
      return false; // END
  if (is_dir($dir->path.'/'.$file) && (strcmp($file,".") && strcmp($file,"..")))
    if ($trail_slash)
      return $file."/"; // PRINT
    else
      return $file;
  if (!is_dir($dir->path.'/'.$file))
    $file_buf[] = $file; // PUSH
  return buf_read($dir, $file_buf,$trail_slash);
}

#
# Other functions and
# functions on c_browser_gui_html objects
#

/*
class c_buff {

  read ($new_entry = false)
  {
    if ($law())
      return $new_entry;
    else
      $buffer[] = $new_entry; // PUSH

  }

  var $buffer;
  var $law; //function - must return boolean
} //c_buff

*/





?>

Return current item: EXPOW