Work on filemanager for websites

This commit is contained in:
Laurent Destailleur 2018-09-24 15:14:32 +02:00
parent eeda176ed6
commit ea517da85c
4 changed files with 96 additions and 64 deletions

View File

@ -38,15 +38,18 @@ if (empty($module)) $module='ecm';
$permtoadd = 0;
$permtoupload = 0;
$showroot = 0;
if ($module == 'ecm')
{
$permtoadd = $user->rights->ecm->setup;
$permtoupload = $user->rights->ecm->upload;
$showroot = 0;
}
if ($module == 'medias')
{
$permtoadd = ($user->rights->mailing->creer || $user->rights->website->write);
$permtoupload = ($user->rights->mailing->creer || $user->rights->website->write);
$showroot = 1;
}
@ -69,29 +72,25 @@ if (($action == 'delete' || $action == 'file_manager_delete') && empty($conf->us
print '<div class="inline-block toolbarbutton centpercent">';
// Toolbar
//if (preg_match('/\/ecm/', $_SERVER['PHP_SELF'])) {
//if ($module == 'ecm') {
if ($permtoadd)
{
print '<a href="'.DOL_URL_ROOT.'/ecm/dir_add_card.php?action=create&module='.urlencode($module).($websitekey?'&website='.$websitekey:'').($pageid?'&pageid='.$pageid:'').'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?file_manager=1&website='.$websitekey.'&pageid='.$pageid).'" class="inline-block valignmiddle toolbarbutton" title="'.dol_escape_htmltag($langs->trans('ECMAddSection')).'">';
print '<img class="toolbarbutton" border="0" src="'.DOL_URL_ROOT.'/theme/common/folder-new.png">';
print '</a>';
}
else
{
print '<a href="#" class="inline-block valignmiddle toolbarbutton" title="'.$langs->trans("NotAllowed").'">';
print '<img class="toolbarbutton" border="0" src="'.DOL_URL_ROOT.'/theme/common/folder-new.png">';
print '</a>';
}
if ($module == 'ecm')
{
$tmpurl=((! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE_JS))?'#':($_SERVER["PHP_SELF"].'?action=refreshmanual'.($module?'&amp;module='.$module:'').($section?'&amp;section='.$section:'')));
print '<a href="'.$tmpurl.'" class="inline-block valignmiddle toolbarbutton" title="'.dol_escape_htmltag($langs->trans('ReSyncListOfDir')).'">';
print '<img id="refreshbutton" class="toolbarbutton" border="0" src="'.DOL_URL_ROOT.'/theme/common/view-refresh.png">';
print '</a>';
}
//}
if ($permtoadd)
{
print '<a href="'.DOL_URL_ROOT.'/ecm/dir_add_card.php?action=create&module='.urlencode($module).($websitekey?'&website='.$websitekey:'').($pageid?'&pageid='.$pageid:'').'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?file_manager=1&website='.$websitekey.'&pageid='.$pageid).'" class="inline-block valignmiddle toolbarbutton" title="'.dol_escape_htmltag($langs->trans('ECMAddSection')).'">';
print '<img class="toolbarbutton" border="0" src="'.DOL_URL_ROOT.'/theme/common/folder-new.png">';
print '</a>';
}
else
{
print '<a href="#" class="inline-block valignmiddle toolbarbutton" title="'.$langs->trans("NotAllowed").'">';
print '<img class="toolbarbutton" border="0" src="'.DOL_URL_ROOT.'/theme/common/folder-new.png">';
print '</a>';
}
if ($module == 'ecm')
{
$tmpurl=((! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE_JS))?'#':($_SERVER["PHP_SELF"].'?action=refreshmanual'.($module?'&amp;module='.$module:'').($section?'&amp;section='.$section:'')));
print '<a href="'.$tmpurl.'" class="inline-block valignmiddle toolbarbutton" title="'.dol_escape_htmltag($langs->trans('ReSyncListOfDir')).'">';
print '<img id="refreshbutton" class="toolbarbutton" border="0" src="'.DOL_URL_ROOT.'/theme/common/view-refresh.png">';
print '</a>';
}
// Start "Add new file" area
$nameforformuserfile = 'formuserfileecm';
@ -148,7 +147,7 @@ if (empty($action) || $action == 'editfile' || $action == 'file_manager' || preg
print '<!-- Title for manual directories -->'."\n";
print '<tr class="liste_titre">'."\n";
print '<th class="liste_titre" align="left" colspan="6">';
print '<th class="liste_titre" align="left">';
print '&nbsp;'.$langs->trans("ECMSections");
print '</th></tr>';
@ -159,9 +158,17 @@ if (empty($action) || $action == 'editfile' || $action == 'file_manager' || preg
if (! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE_JS))
{
print '<tr><td colspan="6">';
// Show the link to "Root"
if ($showroot)
{
print '<tr><td><div style="padding-left: 5px; padding-right: 5px;"><a href="'.$_SERVER["PHP_SELF"].'?file_manager=1&pageid='.$pageid.'">'.$langs->trans("Root").'</a></div></td></tr>';
}
// Show filemanager tree (will be filled by call of ajax enablefiletreeajax.tpl.php that execute ajaxdirtree.php)
print '<tr><td>';
// Show filemanager tree (will be filled by call of ajax /ecm/tpl/enablefiletreeajax.tpl.php that execute ajaxdirtree.php)
print '<div id="filetree" class="ecmfiletree"></div>';
if ($action == 'deletefile') print $form->formconfirm('eeeee', $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', '', 'deletefile');
@ -170,7 +177,7 @@ if (empty($action) || $action == 'editfile' || $action == 'file_manager' || preg
}
else
{
print '<tr><td colspan="6" style="padding-left: 20px">';
print '<tr><td style="padding-left: 20px">';
$_POST['modulepart'] = $module;
$_POST['openeddir'] = GETPOST('openeddir');

View File

@ -27,7 +27,7 @@ if (empty($conf) || ! is_object($conf))
?>
<!-- BEGIN PHP TEMPLATE ecm/tpl/enablefiletreeajax.tpl.php -->
<!-- Doc of fileTree plugin at http://www.abeautifulsite.net/blog/2008/03/jquery-file-tree/ -->
<!-- Doc of fileTree plugin at https://www.abeautifulsite.net/jquery-file-tree: http://www.abeautifulsite.net/blog/2008/03/jquery-file-tree/ -->
<script type="text/javascript">

View File

@ -4430,7 +4430,7 @@ td.gminorheading {
.ecmfiletree {
width: 99%;
height: 99%;
background: #FFF;
/* background: #FFF; */
padding-left: 2px;
font-weight: normal;
}

View File

@ -109,15 +109,30 @@ if ($websitekey)
}
$website = $object;
// Define pageid if pageif and pageref not received as parameter
if (empty($pageid) && empty($pageref) && $object->id > 0 && $action != 'createcontainer')
{
$pageid = $object->fk_default_home;
if (empty($pageid))
{
$array=$objectpage->fetchAll($object->id, 'ASC,ASC', 'type_container,pageurl');
if (! is_array($array) && $array < 0) dol_print_error('', $objectpage->error, $objectpage->errors);
$atleastonepage=(is_array($array) && count($array) > 0);
$firstpageid=0;$homepageid=0;
foreach($array as $key => $valpage)
{
if (empty($firstpageid)) $firstpageid=$valpage->id;
if ($object->fk_default_home && $key == $object->fk_default_home) $homepageid=$valpage->id;
}
$pageid=($homepageid?$homepageid:$firstpageid); // We choose home page and if not defined yet, we take first page
}
}
if ($pageid < 0) $pageid = 0;
if (($pageid > 0 || $pageref) && $action != 'addcontainer')
{
$res = $objectpage->fetch($pageid, ($object->id > 0 ? $object->id : null), $pageref);
//var_dump($res);exit;
//if ($res == 0) // Page ref not found, we check in alias
//{
// $res = $objectpage->fetch($pageid, ($object->id > 0 ? $object->id : null), $pageref);
//}
// Check if pageid is inside the new website, if not we reset param pageid
if ($object->id > 0 && ($objectpage->fk_website != $object->id))
@ -1566,7 +1581,7 @@ if (! GETPOST('hide_websitemenu'))
//var_dump($objectpage);exit;
print '<div class="centpercent websitebar">';
if (count($object->records) > 0)
if (count($object->records) > 0) // There is at least one web site
{
// ***** Part for web sites
@ -2508,31 +2523,34 @@ if ($action == 'editmenu')
if ($action == 'editsource')
{
/*
* Editing with source editor
*/
// Editing with source editor
$contentforedit = '';
/*$contentforedit.='<style scoped>'."\n"; // "scoped" means "apply to parent element only". Not yet supported by browsers
$contentforedit.=$csscontent;
$contentforedit.='</style>'."\n";*/
//$contentforedit.='<style scoped>'."\n"; // "scoped" means "apply to parent element only". Not yet supported by browsers
//$contentforedit.=$csscontent;
//$contentforedit.='</style>'."\n";
$contentforedit .= $objectpage->content;
//var_dump($_SESSION["dol_screenheight"]);
$maxheightwin=480;
if (isset($_SESSION["dol_screenheight"]))
{
if ($_SESSION["dol_screenheight"] > 680) $maxheightwin = $_SESSION["dol_screenheight"]-400;
if ($_SESSION["dol_screenheight"] > 800) $maxheightwin = $_SESSION["dol_screenheight"]-490;
}
//var_dump($_SESSION["dol_screenheight"]);
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
$doleditor=new DolEditor('PAGE_CONTENT',$contentforedit,'',500,'Full','',true,true,'ace',ROWS_5,'90%');
$doleditor=new DolEditor('PAGE_CONTENT',$contentforedit,'',$maxheightwin,'Full','',true,true,'ace',ROWS_5,'40%');
$doleditor->Create(0, '', false, 'HTML Source', 'php');
}
if ($action == 'editcontent')
/*if ($action == 'editcontent')
{
/*
* Editing with default ckeditor
*/
// Editing with default ckeditor
$contentforedit = '';
/*$contentforedit.='<style scoped>'."\n"; // "scoped" means "apply to parent element only". Not yet supported by browsers
$contentforedit.=$csscontent;
$contentforedit.='</style>'."\n";*/
//$contentforedit.='<style scoped>'."\n"; // "scoped" means "apply to parent element only". Not yet supported by browsers
//$contentforedit.=$csscontent;
//$contentforedit.='</style>'."\n";
$contentforedit .= $objectpage->content;
$contentforedit = preg_replace('/(<img.*src=")(?!http)/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $contentforedit, -1, $nbrep);
@ -2540,7 +2558,7 @@ if ($action == 'editcontent')
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
$doleditor=new DolEditor('PAGE_CONTENT',$contentforedit,'',500,'Full','',true,true,true,ROWS_5,'90%');
$doleditor->Create(0, '', false);
}
}*/
print "</div>\n</form>\n";
@ -2562,11 +2580,16 @@ if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpa
// Include a html so we can benefit of the header of page.
// Note: We can't use iframe as it can be used to include another external html file
// Note: We can't use frame as it is deprecated.
/*if ($includepageintoaframeoradiv == 'iframe')
{
$out .= "<iframe><body></html>";
}*/
$out.="\n<html><head>\n";
$out.=dolWebsiteReplacementOfLinks($object, $objectpage->htmlheader, 1);
$out.="</head>\n";
$out.="\n<body>";
$out.='<div id="websitecontentundertopmenu" class="websitecontentundertopmenu">'."\n";
// REPLACEMENT OF LINKS When page called by website editor
@ -2603,25 +2626,30 @@ if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpa
//$out.='<div id="bodywebsite" class="bodywebsite"'.($objectpage->grabbed_from ? ' contenteditable="true"' : '').'>'."\n";
$out.='<div id="bodywebsite" class="bodywebsite">'."\n";
// TODO Add the contenteditable="true" when mode Edit Inline is on
$newcontent = $objectpage->content;
// If mode WEBSITE_SUBCONTAINERSINLINE is on
if (! empty($conf->global->WEBSITE_SUBCONTAINERSINLINE))
{
define('USEDOLIBARRSERVER', 1);
//var_dump($filetpl);
$filephp = $filetpl;
ob_start();
include $filephp;
$newcontent = ob_get_contents();
ob_end_clean();
}
// Change the contenteditable to "true" or "false" when mode Edit Inline is on or off
if (empty($conf->global->WEBSITE_EDITINLINE))
{
$newcontent = preg_replace('/(div|section)(\s[^\>]*)contenteditable="true"/', '\1\2', $newcontent);
}
else
{
// TODO Add the contenteditable="true" when mode Edit Inline is on
}
/*
$filephp = $objectpage->
ob_start();
include $filephp;
$newcontent = ob_get_contents();
ob_end_clean();
*/
$out.=dolWebsiteReplacementOfLinks($object, $newcontent)."\n";
$out.='</div>';
@ -2636,9 +2664,6 @@ if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpa
$out.= "\n".'<!-- End page content '.$filetpl.' -->'."\n\n";
// For jqueryscoped (does not work as expected)
//$out.="<script>$.scoped();</script>";
print $out;
/*file_put_contents($filetpl, $out);