Add detection of mime_type to display files inline or download as needed; If mime_type is text or not defined, at least output a filename for download; formatting;

This commit is contained in:
Miles Lott 2004-02-21 13:56:18 +00:00
parent 265b36c9eb
commit 15011a496e

View File

@ -18,7 +18,6 @@
class uifilemanager
{
var $public_functions = array(
'index' => True,
'help' => True,
@ -41,7 +40,6 @@
var $target;
var $prefs;//array
var $groups_applications;
@ -89,6 +87,7 @@
function uifilemanager()
{
// error_reporting(8);
$GLOBALS['phpgw']->browser = CreateObject('phpgwapi.browser');
$this->now = date('Y-m-d');
@ -254,12 +253,18 @@
/* This just prevents // in some cases */
if($this->path == '/')
{
$this->dispsep = '';
}
else
{
$this->dispsep = '/';
}
if(!($this->lesspath = substr($this->path, 0, strrpos($this->path, '/'))))
{
$this->lesspath = '/';
}
# Get their readable groups to be used throughout the script
$groups = array();
@ -369,14 +374,16 @@
$this->can_add = True;
}
# Default is to sort by name
if(!$this->sortby)
{
$this->sortby = 'name';
}
if($this->debug) $this->debug_filemanager();
if($this->debug)
{
$this->debug_filemanager();
}
# main action switch
// FIXME this will become a switch
@ -434,7 +441,6 @@
$this->readFilesInfo();
$this->fileListing();
}
}
function fileListing()
@ -465,7 +471,6 @@
$this->t->set_var($vars);
$this->t->pparse('out','filemanager_header');
###
# Start File Table Column Headers
# Reads values from $file_attributes array and preferences
@ -516,7 +521,6 @@
$this->t->parse('columns','column',True);
}
$this->t->set_var('row_tr_color',$tr_color);
$this->t->parse('rows','row');
$this->t->pparse('out','row');
@ -653,8 +657,14 @@
# Date modified
if($this->prefs['modified'])
{
if ($files['modified'] != '0000-00-00') $col_data=$files['modified'];
else $col_data='';
if($files['modified'] != '0000-00-00')
{
$col_data=$files['modified'];
}
else
{
$col_data='';
}
$this->t->set_var('col_data',$col_data);
$this->t->parse('columns','column',True);
@ -725,8 +735,6 @@
$this->t->parse('columns','column',True);
}
if($files['mime_type'] == 'Directory')
{
$usedspace += $fileinfo[0];
@ -751,12 +759,8 @@
$this->t->parse('rows','row');
$this->t->pparse('out','row');
}
}
// The file and directory information
$vars[lang_files_in_this_dir]=lang('Files in this directory');
$vars[files_in_this_dir]=$this->numoffiles;
@ -776,10 +780,8 @@
$ls_array = $this->bo->vfs->ls($tmp_arr);
$vars[lang_total_files]=lang('Total Files');
$vars[total_files]= count($ls_array);
}
$this->t->set_var($vars);
@ -787,7 +789,6 @@
$GLOBALS['phpgw']->common->phpgw_footer();
$GLOBALS['phpgw']->common->phpgw_exit();
}
function readFilesInfo()
@ -805,7 +806,12 @@
$this->bo->vfs->mkdir(array('string' => $GLOBALS['homedir'], 'relatives' => array(RELATIVE_NONE)));
}
$ls_array = $this->bo->vfs->ls (array ( 'string' => $GLOBALS['homedir'], 'relatives' => array (RELATIVE_NONE), 'checksubdirs' => False, 'nofiles' => True ) );
$ls_array = $this->bo->vfs->ls(array(
'string' => $GLOBALS['homedir'],
'relatives' => array(RELATIVE_NONE),
'checksubdirs' => False,
'nofiles' => True
));
$this->files_array[] = $ls_array[0];
$this->numoffiles++;
@ -822,7 +828,10 @@
if(!$this->bo->vfs->file_exists(array('string' => $GLOBALS['fakebase'].'/'.$group_array['account_name'],'relatives' => array(RELATIVE_NONE))))
{
$this->bo->vfs->override_acl = 1;
$this->bo->vfs->mkdir (array ( 'string' => $GLOBALS['fakebase'].'/'.$group_array['account_name'], 'relatives' => array (RELATIVE_NONE) ) );
$this->bo->vfs->mkdir(array(
'string' => $GLOBALS['fakebase'].'/'.$group_array['account_name'],
'relatives' => array(RELATIVE_NONE)
));
$this->bo->vfs->override_acl = 0;
@ -838,7 +847,13 @@
}
else
{
$ls_array = $this->bo->vfs->ls (array ( 'string' => $this->path, 'relatives' => array (RELATIVE_NONE), 'checksubdirs' => False, 'nofiles' => False, 'orderby' => $this->sortby ) );
$ls_array = $this->bo->vfs->ls(array(
'string' => $this->path,
'relatives' => array(RELATIVE_NONE),
'checksubdirs' => False,
'nofiles' => False,
'orderby' => $this->sortby
));
if($phpwh_debug)
{
@ -862,6 +877,7 @@
}
// end file count
}
function toolbar($type)
{
switch($type)
@ -956,8 +972,6 @@
// $toolbar.='</tr></table>';
if(!$this->rename_x && !$this->edit_comments_x)
{
// copy and move buttons
if($this->path != '/' && $this->path != $GLOBALS['fakebase'])
{
@ -999,14 +1013,12 @@
default:$x='';
}
if($toolbar)
{
return $toolbar;
}
}
// move to bo
# Handle File Uploads
function fileUpload()
@ -1113,7 +1125,6 @@
$this->readFilesInfo();
$this->filelisting();
}
}
# Handle Editing comments
@ -1127,7 +1138,13 @@
continue;
}
$this->bo->vfs->set_attributes (array ( 'string' => $file, 'relatives' => array (RELATIVE_ALL), 'attributes' => array ( 'comment' => stripslashes ($this->comment_files[$file]) ) ) );
$this->bo->vfs->set_attributes(array(
'string' => $file,
'relatives' => array(RELATIVE_ALL),
'attributes' => array(
'comment' => stripslashes($this->comment_files[$file])
)
));
$this->messages=lang('Updated comment for %1', $this->path.'/'.$file);
}
@ -1151,7 +1168,10 @@
{
$this->messages=$GLOBALS['phpgw']->common->error_list(array(lang("File names cannot contain \\ or /")));
}
elseif (!$this->bo->vfs->mv (array ( 'from' => $from, 'to' => $to )) )
elseif(!$this->bo->vfs->mv(array(
'from' => $from,
'to' => $to
)))
{
$this->messages= $GLOBALS['phpgw']->common->error_list(array(lang('Could not rename %1 to %2', $this->disppath.'/'.$from, $this->disppath.'/'.$to)));
}
@ -1198,7 +1218,11 @@
{
while(list($num, $file) = each($this->fileman))
{
if ($this->bo->vfs->cp (array ( 'from' => $file, 'to' => $this->todir . '/' . $file, 'relatives' => array (RELATIVE_ALL, RELATIVE_NONE) )) )
if($this->bo->vfs->cp(array(
'from' => $file,
'to' => $this->todir . '/' . $file,
'relatives' => array(RELATIVE_ALL, RELATIVE_NONE)
)))
{
$copied++;
$this->message .= lang('Copied %1 to %2', $this->disppath.'/'.$file, $this->todir.'/'.$file);
@ -1216,7 +1240,6 @@
$this->readFilesInfo();
$this->filelisting();
}
function createdir()
@ -1228,6 +1251,7 @@
$this->messages= $GLOBALS['phpgw']->common->error_list(array($this->bo->html_encode(lang('Directory names cannot contain "%1"', $badchar), 1)));
}
/* TODO is this right or should it be a single $ ? */
if($$this->newfile_or_dir[strlen($this->newfile_or_dir)-1] == ' ' || $this->newfile_or_dir[0] == ' ')
{
$this->messages= $GLOBALS['phpgw']->common->error_list(array(lang('Cannot create directory because it begins or ends in a space')));
@ -1271,7 +1295,6 @@
$this->readFilesInfo();
$this->filelisting();
}
}
function delete()
@ -1299,7 +1322,6 @@
$this->filelisting();
}
function debug_filemanager()
{
error_reporting(8);
@ -1318,8 +1340,6 @@
echo '<p></p>';
var_dump($this);
}
function showUploadboxes()
@ -1398,8 +1418,10 @@
$this->fileListing();
}
if ($this->bo->vfs->touch (array ( 'string' => $this->createfile, 'relatives' => array (RELATIVE_ALL) )) )
if($this->bo->vfs->touch(array(
'string' => $this->createfile,
'relatives' => array(RELATIVE_ALL)
)))
{
$this->fileman = array();
$this->fileman[0] = $this->createfile;
@ -1439,7 +1461,6 @@
}
elseif($this->edit_save_x || $this->edit_save_done_x)
{
$content = $this->edit_file_content;
//die( $content);
if($this->bo->vfs->write(array(
@ -1473,7 +1494,10 @@
continue;
}
if ($this->fileman[$j] && $this->bo->vfs->file_exists (array ( 'string' => $this->fileman[$j], 'relatives' => array (RELATIVE_ALL) )) )
if($this->fileman[$j] && $this->bo->vfs->file_exists(array(
'string' => $this->fileman[$j],
'relatives' => array(RELATIVE_ALL)
)))
{
if($this->edit_file)
{
@ -1493,12 +1517,10 @@
{
if($this->fileman[$i]) $value='value="'.$this->fileman[$i].'"';
$vars[filemans_hidden]='<input type="hidden" name="fileman['.$i.']" '.$value.' />';
}
$vars[file_content]=$content;
$vars[buttonPreview]=$this->inputImage('edit_preview','edit_preview',lang('Preview %1', $this->bo->html_encode($this->fileman[$j], 1)));
$vars[buttonSave]=$this->inputImage('edit_save','save',lang('Save %1', $this->bo->html_encode($this->fileman[$j], 1)));
$vars[buttonDone]=$this->inputImage('edit_save_done','ok',lang('Save %1, and go back to file listing ', $this->bo->html_encode($this->fileman[$j], 1)));
@ -1511,8 +1533,6 @@
}
}
function history()
{
if($this->file)
@ -1565,14 +1585,11 @@
{
echo lang('No version history for this file/directory');
}
}
}
function view()
{
if($this->file)
{
$ls_array = $this->bo->vfs->ls(array(
@ -1590,8 +1607,17 @@
{
$mime_type = 'text/plain';
}
$viewable = array('','text/plain','text/csv','text/html','text/text');
if(in_array($mime_type,$viewable))
{
header('Content-type: ' . $mime_type);
header('Content-disposition: filename="' . $this->file . '"');
}
else
{
$GLOBALS['phpgw']->browser->content_header($this->file,$mime_type);
}
echo $this->bo->vfs->read(array(
'string' => $this->path.'/'.$this->file,
'relatives' => array(RELATIVE_NONE)
@ -1689,7 +1715,6 @@
return $options;
}
/* seek icon for mimetype else return an unknown icon */
function mime_icon($mime_type, $size=16)
{
@ -1706,7 +1731,6 @@
function buttonImage($link,$img='',$help='')
{
$image=$GLOBALS['phpgw']->common->image('filemanager','button_'.strtolower($img));
if($img)
@ -1727,8 +1751,6 @@
<input title="'.$help.'" name="'.$name.'" type="image" alt="'.$name.'" src="'.$image.'" value="clicked" />
</td>';
}
}
function html_form_input($type = NULL, $name = NULL, $value = NULL, $maxlength = NULL, $size = NULL, $checked = NULL, $string = '', $return = 1)
@ -1780,7 +1802,6 @@
return '<option'.$text.'>'.$displayed.'</option>';
}
function encode_href($href = NULL, $args = NULL , $extra_args)
{
$href = $this->bo->string_encode($href, 1);
@ -1789,7 +1810,6 @@
$address = $GLOBALS['phpgw']->link($href, $all_args);
return $address;
}
function html_link($href = NULL, $args = NULL , $extra_args, $text = NULL, $return = 1, $encode = 1, $linkonly = 0, $target = NULL)
@ -1804,7 +1824,6 @@
{
// $href = $this->bo->string_encode($href, 1);
$all_args = $args.'&'.$extra_args;
}
###
# This decodes / back to normal
@ -1812,7 +1831,6 @@
// $all_args = preg_replace("/%2F/", "/", $all_args);
// $href = preg_replace("/%2F/", "/", $href);
/* Auto-detect and don't disturb absolute links */
if(!preg_match("|^http(.{0,1})://|", $href))
{
@ -1856,21 +1874,30 @@
function html_table_begin($width = NULL, $border = NULL, $cellspacing = NULL, $cellpadding = NULL, $rules = NULL, $string = '', $return = 0)
{
if($width != NULL && $width)
{
$width = "width=$width";
}
if(is_int($border) && $border >= 0)
{
$border = "border=$border";
}
if(is_int($cellspacing) && $cellspacing >= 0)
{
$cellspacing = "cellspacing=$cellspacing";
}
if(is_int($cellpadding) && $cellpadding >= 0)
{
$cellpadding = "cellpadding=$cellpadding";
}
if($rules != NULL && $rules)
{
$rules = "rules=$rules";
}
$rstring = "<table $width $border $cellspacing $cellpadding $rules $string>";
return($this->bo->eor($rstring, $return));
}
function html_table_end($return = 0)
{
$rstring = "</table>";
@ -1880,13 +1907,21 @@
function html_table_row_begin($align = NULL, $halign = NULL, $valign = NULL, $bgcolor = NULL, $string = '', $return = 0)
{
if($align != NULL && $align)
{
$align = "align=$align";
}
if($halign != NULL && $halign)
{
$halign = "halign=$halign";
}
if($valign != NULL && $valign)
{
$valign = "valign=$valign";
}
if($bgcolor != NULL && $bgcolor)
{
$bgcolor = "bgcolor=$bgcolor";
}
$rstring = "<tr $align $halign $valign $bgcolor $string>";
return($this->bo->eor($rstring, $return));
}
@ -1900,15 +1935,25 @@
function html_table_col_begin($align = NULL, $halign = NULL, $valign = NULL, $rowspan = NULL, $colspan = NULL, $string = '', $return = 0)
{
if($align != NULL && $align)
{
$align = "align=$align";
}
if($halign != NULL && $halign)
{
$halign = "halign=$halign";
}
if($valign != NULL && $valign)
{
$valign = "valign=$valign";
}
if(is_int($rowspan) && $rowspan >= 0)
{
$rowspan = "rowspan=$rowspan";
}
if(is_int($colspan) && $colspan >= 0)
{
$colspan = "colspan=$colspan";
}
$rstring = "<td $align $halign $valign $rowspan $colspan $string>";
return($this->bo->eor($rstring, $return));
@ -1919,5 +1964,4 @@
$rstring = "</td>";
return($this->bo->eor($rstring, $return));
}
}