Your IP : 216.73.216.240
<?php
/*
* @package Tech Fry Library
* @license https://www.gnu.org/licenses/gpl-3.0.en.html
*/
namespace TechFry\Library\View\Sd;
defined('_JEXEC') or die;
use Joomla\CMS\Uri\Uri;
// https://developers.google.com/search/docs/appearance/structured-data/discussion-forum
class SdDiscussionForum
{
public static function get_output($data = array())
{
$uri = Uri::getInstance();
$comments = $data['answers'] ?? $data['comments'] ?? array();
$description = $data['text'] ?? $data['description'] ?? $data['introtext'];
$published_date = Sd::get_date($data['publish_up'] ?? $data['created']);
$author = Sd::get_author('Person', $data['created_by']);
$uri = Uri::getInstance();
$json = array(
"@context" => "https://schema.org",
"@type" => "DiscussionForumPosting",
"headline" => $data['title'] ?? $data['name'],
"text" => strip_tags($description),
"datePublished" => $published_date,
"author" => $author,
"url" => $uri,
);
foreach ($comments as $comment)
{
$comment = (array) $comment;
$published_date = Sd::get_date($comment['publish_up'] ?? $comment['created']);
$author = Sd::get_author('Person', $comment['created_by']);
$json["comment"][] = array(
"@type" => "Comment",
"text" => $comment['text'] ?? $comment['description'],
"datePublished" => $published_date,
"author" => $author,
);
}
Sd::display_sd($json);
}
}