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') elseif ($type == 'blogpost')
{ {
if ($websitepage->fk_user_creat > 0) if (! empty($websitepage->author_alias))
{ {
include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; //include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
$tmpuser = new User($db); //$tmpuser = new User($db);
$restmpuser = $tmpuser->fetch($websitepage->fk_user_creat); //$restmpuser = $tmpuser->fetch($websitepage->fk_user_creat);
if ($restmpuser > 0) $pageurl = $websitepage->pageurl;
{ $title = $websitepage->title;
$pageurl = $websitepage->pageurl; $image = $websitepage->image;
$title = $websitepage->title; $companyname = $mysoc->name;
$image = $websitepage->image; $description = $websitepage->description;
$companyname = $mysoc->name;
$description = $websitepage->description;
$pageurl = str_replace('__WEBSITE_KEY__', $website->ref, $pageurl); $pageurl = str_replace('__WEBSITE_KEY__', $website->ref, $pageurl);
$title = str_replace('__WEBSITE_KEY__', $website->ref, $title); $title = str_replace('__WEBSITE_KEY__', $website->ref, $title);
$image = str_replace('__WEBSITE_KEY__', $website->ref, $image); $image = str_replace('__WEBSITE_KEY__', $website->ref, $image);
$companyname = str_replace('__WEBSITE_KEY__', $website->ref, $companyname); $companyname = str_replace('__WEBSITE_KEY__', $website->ref, $companyname);
$description = str_replace('__WEBSITE_KEY__', $website->ref, $description); $description = str_replace('__WEBSITE_KEY__', $website->ref, $description);
$ret = '<!-- Add structured data for blog post -->'."\n"; $ret = '<!-- Add structured data for blog post -->'."\n";
$ret .= '<script type="application/ld+json">'."\n"; $ret .= '<script type="application/ld+json">'."\n";
$ret .= '{ $ret .= '{
"@context": "https://schema.org", "@context": "https://schema.org",
"@type": "NewsArticle", "@type": "NewsArticle",
"mainEntityOfPage": { "mainEntityOfPage": {
"@type": "WebPage", "@type": "WebPage",
"@id": "'.dol_escape_json($pageurl).'" "@id": "'.dol_escape_json($pageurl).'"
}, },
"headline": "'.dol_escape_json($title).'", "headline": "'.dol_escape_json($title).'",
"image": [ "image": [
"'.dol_escape_json($image).'" "'.dol_escape_json($image).'"
], ],
"datePublished": "'.dol_print_date($websitepage->date_creation, 'dayhourrfc').'", "datePublished": "'.dol_print_date($websitepage->date_creation, 'dayhourrfc').'",
"dateModified": "'.dol_print_date($websitepage->date_modification, 'dayhourrfc').'", "dateModified": "'.dol_print_date($websitepage->date_modification, 'dayhourrfc').'",
"author": { "author": {
"@type": "Person", "@type": "Person",
"name": "'.$tmpuser->getFullName($weblangs).'" "name": "'.dol_escape_json($websitepage->author_alias).'"
}, },
"publisher": { "publisher": {
"@type": "Organization", "@type": "Organization",
"name": "'.dol_escape_json($companyname).'", "name": "'.dol_escape_json($companyname).'",
"logo": { "logo": {
"@type": "ImageObject", "@type": "ImageObject",
"url": "/viewimage.php?modulepart=mycompany&file=logos%2F'.urlencode($mysoc->logo).'" "url": "/viewimage.php?modulepart=mycompany&file=logos%2F'.urlencode($mysoc->logo).'"
} }
}, },
"description": "'.dol_escape_json($description).'" "description": "'.dol_escape_json($description).'"
}'."\n"; }'."\n";
$ret .= '</script>'."\n"; $ret .= '</script>'."\n";
}
} }
} }
elseif ($type == 'product') 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]; $joomlaserverinfo = empty($argv[3])?'':$argv[3];
$image = 'image/__WEBSITE_KEY__/images/stories/dolibarr.png'; $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)) { if (empty($argv[3]) || !in_array($argv[1], array('test', 'confirm')) || empty($websiteref)) {
print '***** '.$script_file.' *****'."\n"; print '***** '.$script_file.' *****'."\n";
@ -95,6 +95,19 @@ if (! $resql) {
exit; 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(); $db->begin();
$i = 0; $nbimported = 0; $nbalreadyexists = 0; $i = 0; $nbimported = 0; $nbalreadyexists = 0;
@ -107,12 +120,17 @@ while ($obj = $dbjoomla->fetch_object($resql)) {
//$description = dol_string_nohtmltag($obj->introtext); //$description = dol_string_nohtmltag($obj->introtext);
$description = trim(dol_trunc(dol_string_nohtmltag($obj->metadesc), 250)); $description = trim(dol_trunc(dol_string_nohtmltag($obj->metadesc), 250));
if (empty($description)) $description = trim(dol_trunc(dol_string_nohtmltag($obj->introtext), 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; $htmltext .= $obj->introtext;
if ($obj->fulltext) { if ($obj->fulltext) {
$htmltext .= '<br>'."\n".'<hr>'."\n".'<br>'."\n".$obj->fulltext; $htmltext .= '<br>'."\n".'<hr>'."\n".'<br>'."\n".$obj->fulltext;
} }
$htmltext .= "\n</section>"; $htmltext .= "\n</section>";
if ($blogpostfooter) $htmltext .= "\n".$blogpostfooter;
$language = ($obj->language && $obj->language != '*' ? $obj->language : 'en'); $language = ($obj->language && $obj->language != '*' ? $obj->language : 'en');
$keywords = $obj->metakey; $keywords = $obj->metakey;
$author_alias = $obj->username; $author_alias = $obj->username;