Skip to content

Commit

Permalink
Enhance fetch of external page for module website
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Oct 1, 2017
1 parent f785203 commit 8180967
Showing 1 changed file with 172 additions and 13 deletions.
185 changes: 172 additions & 13 deletions htdocs/websites/index.php
Expand Up @@ -312,7 +312,8 @@ function llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0,
$filename = 'image/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain;
$tmp = preg_replace('/'.preg_quote($regs[0][$key],'/').'/i', '<img'.$regs[1][$key].'src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file='.$filename.'"'.$regs[3][$key].'>', $tmp);
}
//print dol_escape_htmltag($tmp);exit;

//print dol_escape_htmltag($tmp);exit;
$objectpage->content = $tmp;

$objectpage->grabbed_from = $urltograb;
Expand Down Expand Up @@ -357,6 +358,33 @@ function llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0,
$error++;
setEventMessages($objectpage->error, $objectpage->errors, 'errors');
}
}
if (! $error)
{
if (! empty($objectpage->content))
{
$filealias=$pathofwebsite.'/'.$objectpage->pageurl.'.php';
$filetpl=$pathofwebsite.'/page'.$objectpage->id.'.tpl.php';

// Save page alias
$result=dolSavePageAlias($filealias, $object, $objectpage);
if (! $result) setEventMessages('Failed to write file '.$filealias, null, 'errors');

// Save page of content
$result=dolSavePageContent($filetpl, $object, $objectpage);
if ($result)
{
setEventMessages($langs->trans("Saved"), null, 'mesgs');
//header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website.'&pageid='.$pageid);
//exit;
}
else
{
setEventMessages('Failed to write file '.$filetpl, null, 'errors');
//header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website.'&pageid='.$pageid);
//exit;
}
}
}
if (! $error)
{
Expand All @@ -371,8 +399,35 @@ function llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0,

if (! $error)
{
$action = 'preview';
$pageid = $objectpage->id;

// To generate the CSS, robot and htmlheader file.

if (! dol_is_file($filehtmlheader))
{
$htmlheadercontent = "<!-- HTML header content (common for all pages) -->";
$result=dolSaveHtmlHeader($filehtmlheader, $htmlheadercontent);
}

if (! dol_is_file($filecss))
{
$csscontent = "/* CSS content (all pages) */\nbody.bodywebsite { margin: 0; }'";
$result=dolSaveCssFile($filecss, $csscontent);
}

if (! dol_is_file($filerobot))
{
$robotcontent = "# Robot file. Generated with Dolibarr\nUser-agent: *\nAllow: /public/\nDisallow: /administrator/";
$result=dolSaveRobotFile($filerobot, $robotcontent);
}

if (! dol_is_file($filehtaccess))
{
$htaccesscontent = "# Order allow,deny\n# Deny from all";
$result=dolSaveHtaccessFile($filehtaccess, $htaccesscontent);
}

$action = 'preview';
}
}

Expand Down Expand Up @@ -445,18 +500,8 @@ function llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0,

$htmlheadercontent = trim($htmlheadercontent)."\n";

dol_syslog("Save html header into ".$filehtmlheader);
dolSaveHtmlHeader($filehtmlheader, $htmlheadercontent);

dol_mkdir($pathofwebsite);
$result = file_put_contents($filehtmlheader, $htmlheadercontent);
if (! empty($conf->global->MAIN_UMASK))
@chmod($filehtmlheader, octdec($conf->global->MAIN_UMASK));

if (! $result)
{
$error++;
setEventMessages('Failed to write file '.$filehtmlheader, null, 'errors');
}

// Css file
$csscontent ='';
Expand Down Expand Up @@ -1782,3 +1827,117 @@ function dolSavePageContent($filetpl, $object, $objectpage)

return $result;
}


/**
* Save content of a page on disk
*
* @param string $filetpl Full path of filename to generate
* @param string $htmlheadercontent Content of file
* @return boolean True if OK
*/
function dolSaveHtmlHeader($filehtmlheader, $htmlheadercontent)
{
global $conf, $pathofwebsite;

dol_syslog("Save html header into ".$filehtmlheader);

dol_mkdir($pathofwebsite);
$result = file_put_contents($filehtmlheader, $htmlheadercontent);
if (! empty($conf->global->MAIN_UMASK))
@chmod($filehtmlheader, octdec($conf->global->MAIN_UMASK));

if (! $result)
{
$error++;
setEventMessages('Failed to write file '.$filehtmlheader, null, 'errors');
return false;
}

return true;
}

/**
* Save content of a page on disk
*
* @param string $filecss Full path of filename to generate
* @param string $csscontent Content of file
* @return boolean True if OK
*/
function dolSaveCssFile($filecss, $csscontent)
{
global $conf, $pathofwebsite;

dol_syslog("Save html header into ".$filecss);

dol_mkdir($pathofwebsite);
$result = file_put_contents($filecss, $csscontent);
if (! empty($conf->global->MAIN_UMASK))
@chmod($filecss, octdec($conf->global->MAIN_UMASK));

if (! $result)
{
$error++;
setEventMessages('Failed to write file '.$filecss, null, 'errors');
return false;
}

return true;
}

/**
* Save content of a page on disk
*
* @param string $filerobot Full path of filename to generate
* @param string $robotcontent Content of file
* @return boolean True if OK
*/
function dolSaveRobotFile($filerobot, $robotcontent)
{
global $conf, $pathofwebsite;

dol_syslog("Save html header into ".$filerobot);

dol_mkdir($pathofwebsite);
$result = file_put_contents($filerobot, $robotcontent);
if (! empty($conf->global->MAIN_UMASK))
@chmod($filerobot, octdec($conf->global->MAIN_UMASK));

if (! $result)
{
$error++;
setEventMessages('Failed to write file '.$filerobot, null, 'errors');
return false;
}

return true;
}

/**
* Save content of a page on disk
*
* @param string $filehtaccess Full path of filename to generate
* @param string $htaccess Content of file
* @return boolean True if OK
*/
function dolSaveHtaccessFile($filehtaccess, $htaccess)
{
global $conf, $pathofwebsite;

dol_syslog("Save html header into ".$filehtaccess);

dol_mkdir($pathofwebsite);
$result = file_put_contents($filehtaccess, $htaccess);
if (! empty($conf->global->MAIN_UMASK))
@chmod($filehtaccess, octdec($conf->global->MAIN_UMASK));

if (! $result)
{
$error++;
setEventMessages('Failed to write file '.$filehtaccess, null, 'errors');
return false;
}

return true;
}

0 comments on commit 8180967

Please sign in to comment.