Enhance website module

This commit is contained in:
Laurent Destailleur 2020-03-20 18:58:45 +01:00
parent f904ff5240
commit a2f9f72973
4 changed files with 70 additions and 49 deletions

View File

@ -562,57 +562,54 @@ function getStructuredData($type, $data = array())
}
elseif ($type == 'blogpost')
{
if ($websitepage->fk_user_creat > 0)
if (! empty($websitepage->author_alias))
{
include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
$tmpuser = new User($db);
$restmpuser = $tmpuser->fetch($websitepage->fk_user_creat);
//include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
//$tmpuser = new User($db);
//$restmpuser = $tmpuser->fetch($websitepage->fk_user_creat);
if ($restmpuser > 0)
{
$pageurl = $websitepage->pageurl;
$title = $websitepage->title;
$image = $websitepage->image;
$companyname = $mysoc->name;
$description = $websitepage->description;
$pageurl = $websitepage->pageurl;
$title = $websitepage->title;
$image = $websitepage->image;
$companyname = $mysoc->name;
$description = $websitepage->description;
$pageurl = str_replace('__WEBSITE_KEY__', $website->ref, $pageurl);
$title = str_replace('__WEBSITE_KEY__', $website->ref, $title);
$image = str_replace('__WEBSITE_KEY__', $website->ref, $image);
$companyname = str_replace('__WEBSITE_KEY__', $website->ref, $companyname);
$description = str_replace('__WEBSITE_KEY__', $website->ref, $description);
$pageurl = str_replace('__WEBSITE_KEY__', $website->ref, $pageurl);
$title = str_replace('__WEBSITE_KEY__', $website->ref, $title);
$image = str_replace('__WEBSITE_KEY__', $website->ref, $image);
$companyname = str_replace('__WEBSITE_KEY__', $website->ref, $companyname);
$description = str_replace('__WEBSITE_KEY__', $website->ref, $description);
$ret = '<!-- Add structured data for blog post -->'."\n";
$ret .= '<script type="application/ld+json">'."\n";
$ret .= '{
"@context": "https://schema.org",
"@type": "NewsArticle",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "'.dol_escape_json($pageurl).'"
},
"headline": "'.dol_escape_json($title).'",
"image": [
"'.dol_escape_json($image).'"
],
"datePublished": "'.dol_print_date($websitepage->date_creation, 'dayhourrfc').'",
"dateModified": "'.dol_print_date($websitepage->date_modification, 'dayhourrfc').'",
"author": {
"@type": "Person",
"name": "'.$tmpuser->getFullName($weblangs).'"
},
"publisher": {
"@type": "Organization",
"name": "'.dol_escape_json($companyname).'",
"logo": {
"@type": "ImageObject",
"url": "/viewimage.php?modulepart=mycompany&file=logos%2F'.urlencode($mysoc->logo).'"
}
},
"description": "'.dol_escape_json($description).'"
}'."\n";
$ret .= '</script>'."\n";
}
$ret = '<!-- Add structured data for blog post -->'."\n";
$ret .= '<script type="application/ld+json">'."\n";
$ret .= '{
"@context": "https://schema.org",
"@type": "NewsArticle",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "'.dol_escape_json($pageurl).'"
},
"headline": "'.dol_escape_json($title).'",
"image": [
"'.dol_escape_json($image).'"
],
"datePublished": "'.dol_print_date($websitepage->date_creation, 'dayhourrfc').'",
"dateModified": "'.dol_print_date($websitepage->date_modification, 'dayhourrfc').'",
"author": {
"@type": "Person",
"name": "'.dol_escape_json($websitepage->author_alias).'"
},
"publisher": {
"@type": "Organization",
"name": "'.dol_escape_json($companyname).'",
"logo": {
"@type": "ImageObject",
"url": "/viewimage.php?modulepart=mycompany&file=logos%2F'.urlencode($mysoc->logo).'"
}
},
"description": "'.dol_escape_json($description).'"
}'."\n";
$ret .= '</script>'."\n";
}
}
elseif ($type == 'product')

View File

@ -0,0 +1,2 @@
<!-- Before this is the imported content -->
<?php includeContainer('blogpost-footer'); ?>

View File

@ -0,0 +1,4 @@
<?php includeContainer('blogpost-header'); ?>
<h1><?php echo $websitepage->title ?></h1>
<!-- After this is the imported content -->

View File

@ -42,7 +42,7 @@ $websiteref = empty($argv[2])?'':$argv[2];
$joomlaserverinfo = empty($argv[3])?'':$argv[3];
$image = 'image/__WEBSITE_KEY__/images/stories/dolibarr.png';
$max = empty($argv[4])?'10':$argv[4];
$max = (empty($argv[4]) && $argv[4] !== '0')?'10':$argv[4];
if (empty($argv[3]) || !in_array($argv[1], array('test', 'confirm')) || empty($websiteref)) {
print '***** '.$script_file.' *****'."\n";
@ -95,6 +95,19 @@ if (! $resql) {
exit;
}
$blogpostheader = file_get_contents($path.'blogpost-header.txt');
if ($blogpostheader === false) {
print "Error: Failed to load file content of 'blogpost-header.txt'\n";
exit(-1);
}
$blogpostfooter = file_get_contents($path.'blogpost-footer.txt');
if ($blogpostfooter === false) {
print "Error: Failed to load file content of 'blogpost-footer.txt'\n";
exit(-1);
}
$db->begin();
$i = 0; $nbimported = 0; $nbalreadyexists = 0;
@ -107,12 +120,17 @@ while ($obj = $dbjoomla->fetch_object($resql)) {
//$description = dol_string_nohtmltag($obj->introtext);
$description = trim(dol_trunc(dol_string_nohtmltag($obj->metadesc), 250));
if (empty($description)) $description = trim(dol_trunc(dol_string_nohtmltag($obj->introtext), 250));
$htmltext = '<section id="mysectionnews" contenteditable="true">'."\n";
$htmltext = "";
if ($blogpostheader) $htmltext .= $blogpostheader."\n";
$htmltext .= '<section id="mysectionnews" contenteditable="true">'."\n";
$htmltext .= $obj->introtext;
if ($obj->fulltext) {
$htmltext .= '<br>'."\n".'<hr>'."\n".'<br>'."\n".$obj->fulltext;
}
$htmltext .= "\n</section>";
if ($blogpostfooter) $htmltext .= "\n".$blogpostfooter;
$language = ($obj->language && $obj->language != '*' ? $obj->language : 'en');
$keywords = $obj->metakey;
$author_alias = $obj->username;