mirror of
https://github.com/e107inc/e107.git
synced 2025-08-20 05:11:42 +02:00
#5422 Support for schema. News schema added and FAQs schema template simplified.
This commit is contained in:
@@ -385,11 +385,6 @@ class faq
|
||||
$sc->tag = htmlspecialchars(varset($tag), ENT_QUOTES, 'utf-8');
|
||||
$sc->category = varset($category);
|
||||
|
||||
if(!empty($schemaTemplate['start']))
|
||||
{
|
||||
$schema = $tp->parseSchemaTemplate($schemaTemplate['start'],false,$sc);
|
||||
}
|
||||
|
||||
if(!empty($_GET['id'])) // expand one specific FAQ.
|
||||
{
|
||||
$sc->item =intval($_GET['id']);
|
||||
@@ -407,7 +402,7 @@ class faq
|
||||
// $text = $tp->parseTemplate($FAQ_START, true, $sc);
|
||||
|
||||
// $text = "";
|
||||
|
||||
$start = false;
|
||||
|
||||
|
||||
if($this->pref['list_type'] == 'ol')
|
||||
@@ -419,17 +414,14 @@ class faq
|
||||
$FAQ_LISTALL['end'] = str_replace($tsrch,$trepl, $FAQ_LISTALL['end']);
|
||||
}
|
||||
|
||||
$schemaItems = [];
|
||||
|
||||
foreach ($data as $rw)
|
||||
{
|
||||
$rw['faq_sef'] = eHelper::title2sef($tp->toText($rw['faq_question']),'dashl');
|
||||
|
||||
$sc->setVars($rw);
|
||||
|
||||
if(!empty($schemaTemplate['item']))
|
||||
{
|
||||
$schemaItems[] = $tp->parseSchemaTemplate($schemaTemplate['item'],false,$sc);
|
||||
}
|
||||
|
||||
|
||||
if($sc->item == $rw['faq_id'])
|
||||
{
|
||||
@@ -445,7 +437,7 @@ class faq
|
||||
}
|
||||
$text .= "\n\n<!-- FAQ Start ".$rw['faq_info_order']."-->\n\n";
|
||||
$text .= $tp->parseTemplate($FAQ_LISTALL['start'], true, $sc);
|
||||
$start = TRUE;
|
||||
$start = true;
|
||||
}
|
||||
|
||||
$text .= $tp->parseTemplate($FAQ_LISTALL['item'], true, $sc);
|
||||
@@ -453,24 +445,27 @@ class faq
|
||||
$sc->counter++;
|
||||
}
|
||||
|
||||
if(!empty($schemaItems))
|
||||
{
|
||||
$schema .= implode(",", $schemaItems);
|
||||
}
|
||||
|
||||
|
||||
$text .= ($start) ? $tp->parseTemplate($FAQ_LISTALL['end'], true, $sc) : "";
|
||||
|
||||
if(!empty($schemaTemplate['end']))
|
||||
if(!empty($schemaTemplate))
|
||||
{
|
||||
$schema .= $tp->parseSchemaTemplate($schemaTemplate['end'],false,$sc);
|
||||
}
|
||||
if(isset($schemaTemplate['end']) && isset($schemaTemplate['item']) && isset($schemaTemplate['start']))
|
||||
{
|
||||
$schemaTpl = $schemaTemplate['start']."\n".$schemaTemplate['item']."\n".$schemaTemplate['end'];
|
||||
$schema = $tp->parseSchemaTemplate($schemaTpl, true, $sc, $data);
|
||||
}
|
||||
elseif(is_string($schemaTemplate))
|
||||
{
|
||||
$schema = $tp->parseSchemaTemplate($schemaTemplate, true, $sc, $data);
|
||||
}
|
||||
|
||||
if(!empty($schema))
|
||||
{
|
||||
|
||||
e107::schema($schema);
|
||||
if(!empty($schema))
|
||||
{
|
||||
e107::schema($schema);
|
||||
}
|
||||
}
|
||||
// $text .= $tp->parseTemplate($FAQ_END, true, $sc);
|
||||
|
||||
return $text;
|
||||
|
||||
|
@@ -80,7 +80,7 @@ class faqs_shortcodes extends e_shortcode
|
||||
}
|
||||
|
||||
|
||||
function sc_faq_question($parm='')
|
||||
function sc_faq_question($parm=[])
|
||||
{
|
||||
$tp = e107::getParser();
|
||||
$parm = eHelper::scDualParams($parm);
|
||||
@@ -93,7 +93,7 @@ class faqs_shortcodes extends e_shortcode
|
||||
|
||||
$faqNew = ($this->var['faq_datestamp'] > $newDate) ? " faq-new" : "";
|
||||
|
||||
if($param == 'expand' && !empty($this->var['faq_answer']))
|
||||
if($param === 'expand' && !empty($this->var['faq_answer']))
|
||||
{
|
||||
|
||||
$id = "faq_".$this->var['faq_id'];
|
||||
@@ -130,6 +130,11 @@ class faqs_shortcodes extends e_shortcode
|
||||
}
|
||||
else
|
||||
{
|
||||
if(isset($parm['html']) && empty($parm['html']))
|
||||
{
|
||||
return e107::getParser()->toText($this->var['faq_question']);
|
||||
}
|
||||
|
||||
$text = $tp->toHTML($this->var['faq_question'],true, 'TITLE');
|
||||
}
|
||||
return $text;
|
||||
@@ -154,8 +159,13 @@ class faqs_shortcodes extends e_shortcode
|
||||
return "<a class='faq-question' href='". e107::url('faqs', 'item', $this->var)."' >".$tp -> toHTML($this->var['faq_question'],true,'TITLE')."</a>";
|
||||
}
|
||||
|
||||
function sc_faq_answer()
|
||||
function sc_faq_answer($parm=[])
|
||||
{
|
||||
if(isset($parm['html']) && empty($parm['html']))
|
||||
{
|
||||
return e107::getParser()->toText($this->var['faq_answer']);
|
||||
}
|
||||
|
||||
return e107::getParser()->toHTML($this->var['faq_answer'],true,'BODY');
|
||||
}
|
||||
|
||||
|
@@ -35,20 +35,20 @@ $FAQS_TEMPLATE['caption'] = "{FAQ_CAPTION} <small>{FAQ_COUNT}</small>";
|
||||
|
||||
|
||||
/** @experimental */
|
||||
$FAQS_TEMPLATE['schema']['start'] = '{
|
||||
$FAQS_TEMPLATE['schema'] = '
|
||||
{
|
||||
"@context": "https://schema.org",
|
||||
"@type": "FAQPage",
|
||||
"mainEntity": [';
|
||||
|
||||
$FAQS_TEMPLATE['schema']['item'] = '{
|
||||
"@type": "Question",
|
||||
"name": "{FAQ_QUESTION}",
|
||||
"acceptedAnswer": {
|
||||
"@type": "Answer",
|
||||
"text": "{FAQ_ANSWER}"
|
||||
}
|
||||
}';
|
||||
|
||||
$FAQS_TEMPLATE['schema']['end'] = ']
|
||||
}
|
||||
';
|
||||
"mainEntity": [
|
||||
{
|
||||
"@type": "Question",
|
||||
"name": "{FAQ_QUESTION: html=0}",
|
||||
"acceptedAnswer":
|
||||
{
|
||||
"@type": "Answer",
|
||||
"text": "{FAQ_ANSWER: html=0}"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
';
|
||||
|
@@ -44,6 +44,8 @@ class news_front
|
||||
private $tagAuthor = null;
|
||||
private $comments = array();
|
||||
private $pagination;
|
||||
|
||||
private $schema = '';
|
||||
// private $interval = 1;
|
||||
|
||||
function __construct()
|
||||
@@ -824,6 +826,7 @@ class news_front
|
||||
$e107cache->set($cache_tag."_diz", defined("META_DESCRIPTION") ? META_DESCRIPTION : '');
|
||||
|
||||
$e107cache->set($cache_tag."_rows", e107::serialize($rowData,'json'));
|
||||
$e107cache->set($cache_tag."_schema", $this->schema);
|
||||
|
||||
}
|
||||
|
||||
@@ -1238,6 +1241,12 @@ class news_front
|
||||
$this->setNewsFrontMeta($rows);
|
||||
$text = $this->renderCache($caption, $newsCachedPage); // This exits if cache used
|
||||
$this->comments = $rows;
|
||||
|
||||
if($shema = $this->getNewsCache($this->cacheString,'schema'))
|
||||
{
|
||||
e107::schema($shema);
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
else
|
||||
@@ -1354,6 +1363,12 @@ class news_front
|
||||
$render = true;
|
||||
}
|
||||
|
||||
if(!empty($tmp['schema']))
|
||||
{
|
||||
$this->schema = e107::getParser()->parseSchemaTemplate($tmp['schema'], true, $nsc);
|
||||
e107::schema($this->schema);
|
||||
}
|
||||
|
||||
unset($tmp);
|
||||
}
|
||||
|
||||
|
@@ -88,6 +88,7 @@ $NEWS_VIEW_TEMPLATE['default']['item'] = '
|
||||
';
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* <hr />
|
||||
<h3>About the Author</h3>
|
||||
@@ -101,6 +102,38 @@ $NEWS_VIEW_TEMPLATE['default']['item'] = '
|
||||
</div>
|
||||
*/
|
||||
|
||||
$NEWS_VIEW_TEMPLATE['default']['schema'] = '
|
||||
{
|
||||
"@context": "https://schema.org",
|
||||
"@type": "NewsArticle",
|
||||
"mainEntityOfPage": {
|
||||
"@type": "WebPage",
|
||||
"@id": "{NEWS_URL: full=1}"
|
||||
},
|
||||
"headline": "{NEWS_TITLE}",
|
||||
"description": "{NEWS_DESCRIPTION}",
|
||||
"image": [
|
||||
"{SETIMAGE: w=800&h=800}{NEWS_IMAGE: item=1&return=url}"
|
||||
],
|
||||
"author": {
|
||||
"@type": "Person",
|
||||
"name": "{NEWS_AUTHOR=nolink}"
|
||||
},
|
||||
"publisher": {
|
||||
"@type": "Organization",
|
||||
"name": "{ORGANIZATION}",
|
||||
"logo": {
|
||||
"@type": "ImageObject",
|
||||
"url": "{SITEBUTTON: type=url}"
|
||||
}
|
||||
},
|
||||
"datePublished": "{NEWS_DATE=atom}",
|
||||
"dateModified": "{NEWS_MODIFIED=atom}",
|
||||
"articleBody": "{NEWS_BODY=raw}"
|
||||
|
||||
}
|
||||
';
|
||||
|
||||
|
||||
// @todo add more templates. eg. 'videos' , 'slideshow images', 'full width image' - help and ideas always appreciated.
|
||||
|
||||
|
@@ -15,12 +15,8 @@ class siteinfo_shortcodes // must match the folder name of the plugin.
|
||||
{
|
||||
$path = e107::getParser()->replaceConstants($_POST['sitebutton']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$path = (strpos(SITEBUTTON, 'http:') !== false ? SITEBUTTON : e_IMAGE.SITEBUTTON);
|
||||
}
|
||||
|
||||
if(varset($parm['type']) == 'email' || $parm == 'email') // (retain {} constants )
|
||||
if(varset($parm['type']) == 'email' || $parm == 'email' || varset($parm['type']) == 'url') // (retain {} constants )
|
||||
{
|
||||
$h = !empty($parm['h']) ? $parm['h'] : 100;
|
||||
|
||||
@@ -35,9 +31,19 @@ class siteinfo_shortcodes // must match the folder name of the plugin.
|
||||
|
||||
if(defined('e_MEDIA') && is_writable(e_MEDIA."temp/") && ($resized = e107::getMedia()->resizeImage($path, e_MEDIA."temp/".basename($realPath),'h='.$h)))
|
||||
{
|
||||
$path = e107::getParser()->createConstants($resized);
|
||||
$path = e107::getParser()->createConstants($resized,'mix');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$path = (strpos(SITEBUTTON, 'http:') !== false || strpos(SITEBUTTON, e_IMAGE_ABS) !== false ? SITEBUTTON : e_IMAGE.SITEBUTTON);
|
||||
}
|
||||
|
||||
if(varset($parm['type']) == 'url')
|
||||
{
|
||||
// return $path;
|
||||
return e107::getParser()->replaceConstants($path,'full');
|
||||
}
|
||||
|
||||
if(!empty($path))
|
||||
{
|
||||
@@ -196,8 +202,14 @@ class siteinfo_shortcodes // must match the folder name of the plugin.
|
||||
$opts['h'] = $dimensions[1];
|
||||
}
|
||||
|
||||
// $imageStyle = (empty($dimensions)) ? '' : " style='width: ".$dimensions[0]."px; height: ".$dimensions[1]."px' ";
|
||||
// $image = "<img class='logo img-responsive' src='".$logo."' ".$imageStyle." alt='".SITENAME."' />\n";
|
||||
if(varset($parm['type']) == 'url')
|
||||
{
|
||||
return $tp->replaceConstants($logo, 'full');
|
||||
}
|
||||
elseif(varset($parm['type']) == 'email')
|
||||
{
|
||||
return $logo;
|
||||
}
|
||||
|
||||
$image = $tp->toImage($logo,$opts);
|
||||
|
||||
@@ -222,4 +234,13 @@ class siteinfo_shortcodes // must match the folder name of the plugin.
|
||||
return (defined('THEME_DISCLAIMER') && $pref['displaythemeinfo'] ? THEME_DISCLAIMER : '');
|
||||
}
|
||||
|
||||
function sc_organization()
|
||||
{
|
||||
$c = e107::getPref('contact_info');
|
||||
|
||||
$text = !empty($c['organization']) ? $c['organization'] : SITENAME;
|
||||
|
||||
return e107::getParser()->toText($text);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user