channel->item as $item) { $ts = strtotime($item->pubDate); if ($lastDate == '' || $ts > $lastDate) { $post = new BlogPost(); $post->link = (string) $item->link; $post->title = (string) $item->title; $post->category = $item->category; array_push($statuses, $post); if (!$first_article) { $myfile = fopen($file, 'w') or die('Unable to open file!'); fwrite($myfile, $ts); fclose($myfile); $first_article = true; } } } $statuses = array_reverse($statuses); $mastodon = new MastodonAPI($token, $base_url); foreach ($statuses as $s) { $statusText = $s->title.' leggi su '.$s->link.' '; foreach ($s->category as $c) { $statusText = $statusText.'#'.formatHashTag($c).' '; } $status_data = [ 'status' => $statusText, 'visibility' => $visibility, 'language' => $language, ]; $mastodon->postStatus($status_data); } function formatHashTag($category) { $filtered = str_replace('/', ' ', $category); $upper = ucwords($filtered); return str_replace(' ', '', $upper); } class BlogPost { public $ts; public $link; public $category; public $title; }