Skip to content

Instantly share code, notes, and snippets.

@ldjb
Last active April 28, 2017 15:54
Show Gist options
  • Save ldjb/2770c2648a78cf262d2254192a6a8b6d to your computer and use it in GitHub Desktop.
Save ldjb/2770c2648a78cf262d2254192a6a8b6d to your computer and use it in GitHub Desktop.
<?php
define("ATOM_FEED", "https://mastodon.social/@Gargron.atom");
define("NEW_STATUS_BY", "New status by");
header("Content-type: application/atom+xml; charset=utf-8");
$data = new SimpleXMLElement(file_get_contents(ATOM_FEED));
$toRemove = [];
for ($i=0; $i<count($data->entry); ++$i) {
if (strpos($data->entry[$i]->title, NEW_STATUS_BY) !== 0) {
array_unshift($toRemove, $i);
}
else {
$data->entry[$i]->content = strip_tags($data->entry[$i]->content, "<p><br>");
if (strpos($data->entry[$i]->content, "<p>@") === 0) {
array_unshift($toRemove, $i);
}
else {
$data->entry[$i]->content = str_replace("@", "[AT]", $data->entry[$i]->content);
}
}
}
foreach($toRemove as $i) {
unset($data->entry[$i]);
}
echo $data->asXML();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment