tags to tags
$comment['body'] = preg_replace ('/(<|<\/)code>/iS', '\\1pre>', $comment['body']);
// Get name from comment or use configured default
$name = Misc::getArrayItem ($comment, 'name') ?: $hashover->setup->defaultName;
// Create item element
$item = $xml->createElement ('item');
// Generate comment summary item title
$title = $name . ' : ';
$single_comment = str_replace (PHP_EOL, ' ', strip_tags ($comment['body']));
if (mb_strlen ($single_comment) > 40) {
$title .= mb_substr ($single_comment, 0, 40) . '...';
} else {
$title .= $single_comment;
}
// Create item title element
$item_title = $xml->createElement ('title');
$item_title_value = $xml->createTextNode (html_entity_decode ($title, ENT_COMPAT, 'UTF-8'));
$item_title->appendChild ($item_title_value);
// Add item title element to item element
$item->appendChild ($item_title);
// Create item name element
$item_name = $xml->createElement ('name');
$item_name_value = $xml->createTextNode (html_entity_decode ($name, ENT_COMPAT, 'UTF-8'));
$item_name->appendChild ($item_name_value);
// Add item name element to item element
$item->appendChild ($item_name);
// Add HTML anchor tag to URLs (hyperlinks)
$comment['body'] = preg_replace ('/((ftp|http|https):\/\/[a-z0-9-@:%_\+.~#?&\/=]+) {0,}/iS', '\\1', $comment['body']);
// Replace newlines with break tags
$comment['body'] = str_replace (PHP_EOL, '
', $comment['body']);
// Create item description element
$item_description = $xml->createElement ('description');
$item_description_value = $xml->createTextNode ($comment['body']);
$item_description->appendChild ($item_description_value);
// Add item description element to item element
$item->appendChild ($item_description);
// Create item avatar element
$item_avatar = $xml->createElement ('avatar');
$item_avatar_value = $xml->createTextNode ($comment['avatar']);
$item_avatar->appendChild ($item_avatar_value);
// Add item avatar element to item element
$item->appendChild ($item_avatar);
if (!empty ($comment['likes'])) {
// Create item likes element
$item_likes = $xml->createElement ('likes');
$item_likes_value = $xml->createTextNode ($comment['likes']);
$item_likes->appendChild ($item_likes_value);
// Add item likes element to item element
$item->appendChild ($item_likes);
}
if ($hashover->setup->allowsDislikes === true) {
if (!empty ($comment['dislikes'])) {
// Create item dislikes element
$item_dislikes = $xml->createElement ('dislikes');
$item_dislikes_value = $xml->createTextNode ($comment['dislikes']);
$item_dislikes->appendChild ($item_dislikes_value);
// Add item dislikes element to item element
$item->appendChild ($item_dislikes);
}
}
// Create item publication date element
$item_pubDate = $xml->createElement ('pubDate');
$item_pubDate_value = $xml->createTextNode (date ('D, d M Y H:i:s O', $comment['sort-date']));
$item_pubDate->appendChild ($item_pubDate_value);
// Add item pubDate element to item element
$item->appendChild ($item_pubDate);
// URL to comment for item guide and link elements
$item_permalink_url = $metadata['url'] . '#' . $comment['permalink'];
// Create item guide element
$item_guid = $xml->createElement ('guid');
$item_guid_value = $xml->createTextNode ($item_permalink_url);
$item_guid->appendChild ($item_guid_value);
// Add item guide element to item element
$item->appendChild ($item_guid);
// Create item link element
$item_link = $xml->createElement ('link');
$item_link_value = $xml->createTextNode ($item_permalink_url);
$item_link->appendChild ($item_link_value);
// Add item link element to item element
$item->appendChild ($item_link);
// Add item element to main RSS element
$rss->appendChild ($item);
// Recursively parse replies
if (!empty ($comment['replies'])) {
foreach ($comment['replies'] as $reply) {
parse_comments ($metadata, $reply, $rss, $xml, $hashover);
}
}
}
// Add item element to main RSS element
foreach ($hashover->comments['primary'] as $comment) {
parse_comments ($metadata, $comment, $rss, $xml, $hashover);
}
// Add main RSS element to XML
$xml->appendChild ($rss);
// Return RSS XML
echo preg_replace_callback ('/^(\s+)/m', function ($spaces) {
return str_repeat ("\t", mb_strlen ($spaces[1]) / 2);
}, $xml->saveXML ());
// Return statistics
echo $hashover->statistics->executionEnd ();
}
try {
// Instantiate HashOver class
$hashover = new \HashOver ('rss', 'api');
// Set page URL from GET data
$hashover->setup->setPageURL ('request');
// Initiate comment processing
$hashover->initiate ();
// Parse primary comments into usable data
$hashover->parsePrimary ();
// Attempt to get sorting method
$method = $hashover->setup->getRequest ('sorting', 'by-date');
// Sort comments by sorting method
$hashover->sortPrimary ($method);
// Create RSS feed
create_rss ($hashover);
} catch (\Exception $error) {
echo Misc::displayError ($error->getMessage (), 'rss');
}