From 74c39a10a29c73b18b6ab759ad9aeb990454c07e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 25 Mar 2012 22:47:37 +0200 Subject: [PATCH] Work on ajax ecm module --- htdocs/core/ajax/ajaxdirpreview.php | 500 ++++++++-------------- htdocs/core/ajax/ajaxdirtree.php | 38 +- htdocs/core/class/html.formfile.class.php | 11 +- htdocs/core/lib/functions.lib.php | 2 +- htdocs/ecm/index.php | 202 +++------ htdocs/theme/auguria/style.css.php | 105 +++++ htdocs/theme/bureau2crea/style.css.php | 105 +++++ htdocs/theme/cameleo/style.css.php | 103 +++++ htdocs/theme/eldy/style.css.php | 93 +--- 9 files changed, 587 insertions(+), 572 deletions(-) diff --git a/htdocs/core/ajax/ajaxdirpreview.php b/htdocs/core/ajax/ajaxdirpreview.php index a7ae78882d0..d2130845bf7 100644 --- a/htdocs/core/ajax/ajaxdirpreview.php +++ b/htdocs/core/ajax/ajaxdirpreview.php @@ -22,10 +22,10 @@ */ /** - * \file htdocs/filemanager/ajaxshowpreview.php - * \brief Service to return a HTML preview of a file + * \file htdocs/core/ajax/ajaxdirpreview.php + * \brief Service to return a HTML preview of a directory * Call of this service is made with URL: - * ajaxpreview.php?action=preview&modulepart=repfichierconcerne&file=pathrelatifdufichier + * ajaxdirpreview.php?mode=nojs&action=preview&module=ecm§ion=0&file=xxx */ if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); // Disables token renewal @@ -33,11 +33,45 @@ if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); -// C'est un wrapper, donc header vierge -function llxHeader() { } +if (! isset($mode) || $mode != 'noajax') +{ + require_once("../../main.inc.php"); + require_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'); + require_once(DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'); + require_once(DOL_DOCUMENT_ROOT."/ecm/class/ecmdirectory.class.php"); -require("../../main.inc.php"); -require_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'); + $action=GETPOST("action"); + $file=urldecode(GETPOST('file')); + $section=GETPOST("section"); + $module=GETPOST("module"); + $urlsource=GETPOST("urlsource"); + + $upload_dir = dirname(str_replace("../","/", $conf->ecm->dir_output.'/'.$file)); + + $ecmdir = new EcmDirectory($db); + $result=$ecmdir->fetch($section); + if (! $result > 0) + { + dol_print_error($db,$ecmdir->error); + exit; + } +} +else +{ + $ecmdir = new EcmDirectory($db); + $relativepath=''; + if ($section > 0) + { + $result=$ecmdir->fetch($section); + if (! $result > 0) + { + dol_print_error($db,$ecmdir->error); + exit; + } + } + $relativepath=$ecmdir->getRelativePath(); + $upload_dir = $conf->ecm->dir_output.'/'.$relativepath; +} // Load traductions files $langs->load("ecm"); @@ -47,371 +81,189 @@ $langs->load("other"); // Security check if ($user->societe_id > 0) $socid = $user->societe_id; -// Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP). -$action=GETPOST("action"); -$file=urldecode(GETPOST('file')); -$section=GETPOST("section"); -$module=GETPOST("module"); -$urlsource=GETPOST("urlsource"); -if (! $section) -{ - dol_print_error('',"ErrorSectionParamNotDefined"); - exit; -} - -// Suppression de la chaine de caractere ../ dans $original_file -$original_file = str_replace("../","/", $file); -$original_file_osencoded=dol_osencode($original_file); // New file name encoded in OS encoding charset +//print 'xxx'.$upload_dir; // Security: // On interdit les remontees de repertoire ainsi que les pipe dans // les noms de fichiers. -if (preg_match('/\.\./',$original_file) || preg_match('/[<>|]/',$original_file)) +if (preg_match('/\.\./',$upload_dir) || preg_match('/[<>|]/',$upload_dir)) { - dol_syslog("Refused to deliver file ".$original_file); + dol_syslog("Refused to deliver file ".$upload_dir); // Do no show plain path in shown error message - dol_print_error(0,$langs->trans("ErrorFileNameInvalid",$_GET["file"])); + dol_print_error(0,$langs->trans("ErrorFileNameInvalid",$upload_dir)); exit; } -// Load ecm object -/*$ecmdir = new EcmDirectory($db); - $result=$ecmdir->fetch(GETPOST("section")); -if (! $result > 0) -{ -dol_print_error($db,$ecmdir->error); -exit; -} -$relativepath=$ecmdir->getRelativePath(); -$upload_dir = $conf->ecm->dir_output.'/'.$relativepath; -*/ - /* * Action */ -if ($action == 'remove_file') // Remove a file +/* + if ($action == 'remove_file') // Remove a file { - clearstatcache(); +clearstatcache(); - dol_syslog(__FILE__." remove $original_file $urlsource", LOG_DEBUG); +dol_syslog(__FILE__." remove $original_file $urlsource", LOG_DEBUG); - // This test should be useless. We keep it to find bug more easily - if (! file_exists($original_file_osencoded)) - { - dol_print_error(0,$langs->trans("ErrorFileDoesNotExists",$_GET["file"])); - exit; - } - - dol_delete_file($original_file); - - dol_syslog(__FILE__." back to ".urldecode($urlsource), LOG_DEBUG); - - header("Location: ".urldecode($urlsource)); - - return; +// This test should be useless. We keep it to find bug more easily +if (! file_exists($original_file_osencoded)) +{ +dol_print_error(0,$langs->trans("ErrorFileDoesNotExists",$_GET["file"])); +exit; } +dol_delete_file($original_file); + +dol_syslog(__FILE__." back to ".urldecode($urlsource), LOG_DEBUG); + +header("Location: ".urldecode($urlsource)); + +return; +} +*/ /* * View */ -// Ajout directives pour resoudre bug IE -header('Cache-Control: Public, must-revalidate'); -header('Pragma: public'); - -$filename = basename($original_file_osencoded); -$sizeoffile = filesize($original_file_osencoded); - -if (dol_is_dir($original_file)) +if (! isset($mode) || $mode != 'noajax') { - $type='directory'; -} -else -{ - // Define mime type - $type = 'application/octet-stream'; - if (GETPOST("type") != 'auto') $type=$_GET["type"]; - else $type=dol_mimetype($original_file,'text/plain'); - //print 'X'.$type.'-'.$original_file;exit; + // Ajout directives pour resoudre bug IE + header('Cache-Control: Public, must-revalidate'); + header('Pragma: public'); } -clearstatcache(); - -// Output file on browser -dol_syslog("document.php download $original_file $filename content-type=$type"); +$type='directory'; // This test if file exists should be useless. We keep it to find bug more easily -if (! file_exists($original_file_osencoded)) +if (! dol_is_dir($upload_dir)) { - dol_print_error(0,$langs->trans("ErrorFileDoesNotExists",$original_file)); + $langs->load("install"); + dol_print_error(0,$langs->trans("ErrorDirDoesNotExists",$upload_dir)); exit; } print ''."\n"; -print ''."\n"; print ''."\n"; -// Les drois sont ok et fichier trouve, et fichier texte, on l'envoie -print ''.$langs->trans("Information").'
'; -print '
'; // Dir if ($type == 'directory') { - print ''; - print ''; + $formfile=new FormFile($db); - //print $langs->trans("FullPath").': '.$original_file_osencoded.'
'; - //print $langs->trans("Mime-type").': '.$type.'
'; + $param=($sortfield?'&sortfield='.$sortfield:'').($sortorder?'&sortorder='.$sortorder:''); + $maxlengthname=40; - $info=stat($original_file_osencoded); - //print '
'."\n"; - //print $langs->trans("Owner").": ".$info['udi']."
\n"; - //print $langs->trans("Group").": ".$info['gdi']."
\n"; - //print $langs->trans("Size").": ".dol_print_size($info['size'])."
\n"; - print '\n"; - print '\n"; - //print $langs->trans("Ctime").": ".$info['ctime']."
\n"; - print '
'.$langs->trans("Directory").':  '.$original_file.'
'.$langs->trans("DateLastAccess").':  '.dol_print_date($info['atime'],'%Y-%m-%d %H:%M:%S')."
'.$langs->trans("DateLastChange").':  '.dol_print_date($info['mtime'],'%Y-%m-%d %H:%M:%S')."
'."\n"; - - print '

'; - print ''.$langs->trans("Content")."
\n"; - print '

'; - - print '
'."\n"; -} -else { - print ''; - print ''; - print ''; - print ''; - print ''; - - $info=stat($original_file_osencoded); - //print '
'."\n"; - //print $langs->trans("Owner").": ".$info['udi']."
\n"; - //print $langs->trans("Group").": ".$info['gdi']."
\n"; - print '\n"; - print '\n"; - print '\n"; - //print $langs->trans("Ctime").": ".$info['ctime']."
\n"; - $sizearray=array(); - if (preg_match('/image/i',$type)) - { - require_once(DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'); - $sizearray=dol_getImageSize($original_file_osencoded); - print ''; - print ''; - } - print '
'.$langs->trans("File").':  '.$original_file.'
'.$langs->trans("Mime-type").':  '.$type.''.$langs->trans("Download").'
'.$langs->trans("Size").':  '.dol_print_size($info['size'])."
'.$langs->trans("DateLastAccess").':  '.dol_print_date($info['atime'],'%Y-%m-%d %H:%M:%S')."
'.$langs->trans("DateLastChange").':  '.dol_print_date($info['mtime'],'%Y-%m-%d %H:%M:%S')."
'.$langs->trans("Width").':  '.$sizearray['width'].'px
'.$langs->trans("Height").':  '.$sizearray['height'].'px
'."\n"; - - // Flush content before preview generation - flush(); // This send all data to browser. Browser however may wait to have message complete or aborted before showing it. - - - // Preview - $preview=0; - if (preg_match('/text/i',$type)) - { - $minmem=64; // Minimum of memory required to use Geshi (color syntax on text files) - $maxsize=65536; // Max size of data to read for text preview - - // Define memmax (memory_limit in bytes) - $memmaxorig=@ini_get("memory_limit"); - $memmax=@ini_get("memory_limit"); - if ($memmaxorig != '') - { - preg_match('/([0-9]+)([a-zA-Z]*)/i',$memmax,$reg); - if ($reg[2]) - { - if (strtoupper($reg[2]) == 'M') $memmax=$reg[1]*1024*1024; - if (strtoupper($reg[2]) == 'K') $memmax=$reg[1]*1024; - } - } - //print "memmax php=".$memmax; - - $out=''; - $srclang=dol_mimetype($original_file,'text/plain',3); - - if (preg_match('/html/i',$type)) // If HTML file - { - print '

'; - print ''.$langs->trans("Preview")."
\n"; - print '
'; - - readfile($original_file_osencoded); - //$out=file_get_contents($original_file_osencoded); - //print $out; - } - else // If not a HTML file - { - $warn=''; - - // Check if we have enough memory for Geshi - if ($memmax < $minmem*1024*1024) - { - $warn=img_warning().' '.$langs->trans("NotEnoughMemoryForSyntaxColor"); - $warn.=' (Have '.$memmax.' - Need '.$minmem.')'; - $srclang=''; // We disable geshi - } - - if (empty($conf->global->FILEMANAGER_DISABLE_COLORSYNTAXING)) - { - $warn=' ('.$langs->trans("ColoringDisabled").')'; - $srclang=''; // We disable geshi - } - - // Try to detect srclang using first line - if ($type=='text/plain' && empty($srclang)) // Try to enhance MIME detection with first line content - { - $firstline=file_get_contents($original_file_osencoded,false,null,0,32); - $texts = preg_split("/((\r(?!\n))|((?'bash', 'sh'=>'bash', 'bash'=>'bash'); - $srclang=$converttogeshicode[$reg[1]]?$converttogeshicode[$reg[1]]:$reg[1]; - //print "ee".$srclang; - } - } - if ($srclang=='php') $srclang='php-brief'; - //if ($srclang=='perl') $srclang=''; // Perl seems to be bugged - - if (! empty($srclang)) - { - print '

'; - print ''.$langs->trans("Preview")." (".$srclang.")
\n"; - print '
'; - - // Translate with Geshi - include_once('includes/geshi/geshi.php'); - - $out=file_get_contents($original_file_osencoded,false,null,0,$maxsize); - if (! utf8_check($out)) { $isoutf='iso'; $out=utf8_encode($out); } - - $geshi = new GeSHi($out, $srclang); - $geshi->enable_strict_mode(true); - $res=''; - $res=$geshi->parse_code(); - - //print "zzzzzzzz"; - print $res; - } - else - { - print '

'; - print ''.$langs->trans("Preview").""; - if ($warn) print ' '.$warn; - print "
\n"; - print '
'; - - $maxlines=25; - $i=0;$more=0; - $handle = @fopen($original_file_osencoded, "r"); - if ($handle) - { - while (!feof($handle) && $i < $maxlines) - { - $buffer = fgets($handle, $maxsize); - if (utf8_check($buffer)) $out.=$buffer."
\n"; - else $out.=utf8_encode($buffer)."
\n"; - $i++; - } - if (!feof($handle)) $more=1; - fclose($handle); - } - else - { - print '
'.$langs->trans("ErrorFailedToOpenFile",$original_file).'
'; - } - - print $out; - - print '
'; - - if ($more) - { - print '...'.$langs->trans("More").'...
'."\n"; - } - } - } - $preview=1; - } - // Preview if image - if (preg_match('/image/i',$type)) - { - print '

'; - print ''.$langs->trans("Preview")."
\n"; - print '

'; - - - print '
500) print ' width="500"'; - print ' src="'.dol_buildpath('/filemanager/viewimage.php',1).'?modulepart=filemanager&file='.urlencode($original_file).'">
'; - $preview=1; - } - // Preview if video - if (preg_match('/video/i',$type)) - { - $typecodec=''; - if (preg_match('/ogg/i',$type)) $typecodec=' type=\'video/ogg; codecs="theora, vorbis"\''; // This works with HTML5 video - //if (preg_match('/msvideo/i',$type)) $typecodec=' type=\'video/x-msvideo;\''; // AVI - //if (preg_match('/webm/i',$type)) $typecodec=' type=\'video/webm; codecs="vp8, vorbis"\''; - //if (preg_match('/mp4/i',$type)) $typecodec=' type=\'video/mp4; codecs="avc1.42E01E, mp4a.40.2"\''; - - if ($typecodec) - { - print '

'; - print ''.$langs->trans("Preview")."
\n"; - print '

'; - - print '
'; - print ''; - print '
'; - /*