mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
NEW Add a way to enter LICENSE file content in property of website
This commit is contained in:
parent
6c947c9f9e
commit
6406fbdc7e
|
|
@ -533,6 +533,27 @@ function dolSaveReadme($file, $content)
|
|||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save content of a page on disk
|
||||
*
|
||||
* @param string $file Full path of filename to generate
|
||||
* @param string $content Content of file
|
||||
* @return boolean True if OK
|
||||
*/
|
||||
function dolSaveLicense($file, $content)
|
||||
{
|
||||
global $conf, $pathofwebsite;
|
||||
|
||||
dol_syslog("Save LICENSE file into ".$file);
|
||||
|
||||
dol_mkdir($pathofwebsite);
|
||||
$result = file_put_contents($file, $content);
|
||||
if (!empty($conf->global->MAIN_UMASK)) {
|
||||
@chmod($file, octdec($conf->global->MAIN_UMASK));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show list of themes. Show all thumbs of themes/skins
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@ WEBSITE_HTML_HEADER=Addition at bottom of HTML Header (common to all pages)
|
|||
WEBSITE_ROBOT=Robot file (robots.txt)
|
||||
WEBSITE_HTACCESS=Website .htaccess file
|
||||
WEBSITE_MANIFEST_JSON=Website manifest.json file
|
||||
WEBSITE_README=README.md file
|
||||
WEBSITE_KEYWORDSDesc=Use a comma to separate values
|
||||
EnterHereLicenseInformation=Enter here meta data or license information to fille a README.md file. if you distribute your website as a template, the file will be included into the temptate package.
|
||||
EnterHereReadmeInformation=Enter here a description of the website. If you distribute your website as a template, the file will be included into the temptate package.
|
||||
EnterHereLicenseInformation=Enter here the LICENSE of the code of the website. If you distribute your website as a template, the file will be included into the temptate package.
|
||||
HtmlHeaderPage=HTML header (specific to this page only)
|
||||
PageNameAliasHelp=Name or alias of the page.<br>This alias is also used to forge a SEO URL when website is ran from a Virtual host of a Web server (like Apacke, Nginx, ...). Use the button "<strong>%s</strong>" to edit this alias.
|
||||
EditTheWebSiteForACommonHeader=Note: If you want to define a personalized header for all pages, edit the header on the site level instead of on the page/container.
|
||||
|
|
|
|||
|
|
@ -979,6 +979,9 @@ class Website extends CommonObject
|
|||
dol_syslog("Copy pages from ".$srcdir." into ".$destdir);
|
||||
dolCopyDir($srcdir, $destdir, 0, 1, $arrayreplacementinfilename, 2, array('old', 'back'));
|
||||
|
||||
// Copy file README.md from containers to root
|
||||
dol_copy($conf->website->dir_temp.'/'.$website->ref.'/containers/README.md', $conf->website->dir_temp.'/'.$website->ref.'/README.md');
|
||||
|
||||
// Copy files into medias/image
|
||||
$srcdir = DOL_DATA_ROOT.'/medias/image/'.$website->ref;
|
||||
$destdir = $conf->website->dir_temp.'/'.$website->ref.'/medias/image/websitekey';
|
||||
|
|
|
|||
|
|
@ -243,6 +243,7 @@ $fileindex = $pathofwebsite.'/index.php';
|
|||
$filewrapper = $pathofwebsite.'/wrapper.php';
|
||||
$filemanifestjson = $pathofwebsite.'/manifest.json.php';
|
||||
$filereadme = $pathofwebsite.'/README.md';
|
||||
$filelicense = $pathofwebsite.'/LICENSE';
|
||||
$filemaster = $pathofwebsite.'/master.inc.php';
|
||||
|
||||
// Define $urlwithroot
|
||||
|
|
@ -1191,6 +1192,11 @@ if ($action == 'addcontainer' && $usercanedit) {
|
|||
$result = dolSaveReadme($filereadme, $readmecontent);
|
||||
}
|
||||
|
||||
if (!dol_is_file($filelicense)) {
|
||||
$licensecontent = "MIT License";
|
||||
$result = dolSaveLicense($filelicense, $licensecontent);
|
||||
}
|
||||
|
||||
$action = 'preview';
|
||||
}
|
||||
}
|
||||
|
|
@ -1669,6 +1675,43 @@ if ($action == 'updatecss' && $usercanedit) {
|
|||
$error++;
|
||||
}
|
||||
|
||||
$dataposted = trim(GETPOST('WEBSITE_LICENSE', 'restricthtml'));
|
||||
$dataposted = str_replace('<?=', '<?php', $dataposted);
|
||||
|
||||
// LICENSE file
|
||||
$phpfullcodestringold = '';
|
||||
$phpfullcodestring = dolKeepOnlyPhpCode($dataposted);
|
||||
|
||||
// Security analysis
|
||||
$errorphpcheck = checkPHPCode($phpfullcodestringold, $phpfullcodestring); // Contains the setEventMessages
|
||||
|
||||
if (!$errorphpcheck) {
|
||||
$licensecontent = '';
|
||||
|
||||
/*$readmecontent.= "<?php // BEGIN PHP\n";
|
||||
$readmecontent.= '$websitekey=basename(__DIR__);'."\n";
|
||||
$readmecontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once __DIR__.'/master.inc.php'; } // Load env if not already loaded"."\n"; // For the css, we need to set path of master using the dirname of css file.
|
||||
$readmecontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
|
||||
$readmecontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
|
||||
$readmecontent.= "ob_start();\n";
|
||||
$readmecontent.= "header('Cache-Control: max-age=3600, public, must-revalidate');\n";
|
||||
$readmecontent.= "header('Content-type: application/manifest+json');\n";
|
||||
$readmecontent.= "// END PHP ?>\n";*/
|
||||
|
||||
$licensecontent .= $dataposted."\n";
|
||||
|
||||
/*$readmecontent.= '<?php // BEGIN PHP'."\n";
|
||||
$readmecontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "manifest");'."\n";
|
||||
$readmecontent.= "// END PHP ?>"."\n";*/
|
||||
|
||||
$result = dolSaveLicense($filelicense, $licensecontent);
|
||||
if (!$result) {
|
||||
$error++;
|
||||
setEventMessages('Failed to write file '.$filelicense, null, 'errors');
|
||||
}
|
||||
} else {
|
||||
$error++;
|
||||
}
|
||||
|
||||
// Save wrapper.php
|
||||
$result = dolSaveIndexPage($pathofwebsite, '', '', $filewrapper, $object);
|
||||
|
|
@ -3365,6 +3408,17 @@ if ($action == 'editcss') {
|
|||
//$readmecontent.="";
|
||||
}
|
||||
|
||||
if (!GETPOSTISSET('WEBSITE_LICENSE')) {
|
||||
$licensecontent = @file_get_contents($filelicense);
|
||||
// Clean the readme file to remove php code and get only html part
|
||||
$licensecontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $licensecontent);
|
||||
} else {
|
||||
$licensecontent = GETPOST('WEBSITE_LICENSE', 'none');
|
||||
}
|
||||
if (!trim($licensecontent)) {
|
||||
//$readmecontent.="";
|
||||
}
|
||||
|
||||
print dol_get_fiche_head();
|
||||
|
||||
print '<!-- Edit Website properties -->'."\n";
|
||||
|
|
@ -3507,8 +3561,8 @@ if ($action == 'editcss') {
|
|||
|
||||
// README.md
|
||||
print '<tr><td class="tdtop">';
|
||||
$htmlhelp = $langs->trans("EnterHereLicenseInformation");
|
||||
print $form->textwithpicto($langs->trans('WEBSITE_README'), $htmlhelp, 1, 'help', '', 0, 2, 'readmetooltip');
|
||||
$htmlhelp = $langs->trans("EnterHereReadmeInformation");
|
||||
print $form->textwithpicto($langs->trans("File").' README.md', $htmlhelp, 1, 'help', '', 0, 2, 'readmetooltip');
|
||||
print '</td><td>';
|
||||
|
||||
$poscursor = array('x'=>GETPOST('WEBSITE_README_x'), 'y'=>GETPOST('WEBSITE_README_y'));
|
||||
|
|
@ -3517,6 +3571,18 @@ if ($action == 'editcss') {
|
|||
|
||||
print '</td></tr>';
|
||||
|
||||
// LICENSE
|
||||
print '<tr><td class="tdtop">';
|
||||
$htmlhelp = $langs->trans("EnterHereLicenseInformation");
|
||||
print $form->textwithpicto($langs->trans("File").' LICENSE', $htmlhelp, 1, 'help', '', 0, 2, 'licensetooltip');
|
||||
print '</td><td>';
|
||||
|
||||
$poscursor = array('x'=>GETPOST('WEBSITE_LICENSE_x'), 'y'=>GETPOST('WEBSITE_LICENSE_y'));
|
||||
$doleditor = new DolEditor('WEBSITE_LICENSE', $licensecontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '', $poscursor);
|
||||
print $doleditor->Create(1, '', true, $langs->trans("File").' LICENSE', 'text');
|
||||
|
||||
print '</td></tr>';
|
||||
|
||||
// RSS
|
||||
print '<tr><td class="tdtop">';
|
||||
$htmlhelp = $langs->trans('RSSFeedDesc');
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user