Skip to content

Instantly share code, notes, and snippets.

@mauricesvay
Created April 26, 2016 09:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mauricesvay/3efe87959db8a623fe2cb39e7a9b9eda to your computer and use it in GitHub Desktop.
Save mauricesvay/3efe87959db8a623fe2cb39e7a9b9eda to your computer and use it in GitHub Desktop.
Sketchfab RSS Feed for Staff Picks
{
"require": {
"suin/php-rss-writer": "^1.3",
"erusev/parsedown": "^1.6"
}
}
<?php
require_once 'vendor/autoload.php';
use Suin\RSSWriter\Channel;
use Suin\RSSWriter\Feed;
use Suin\RSSWriter\Item;
$Parsedown = new Parsedown();
$feed = new Feed();
$url = 'https://api.sketchfab.com/v2/models?flag=staffpicked&sort_by=-publishedAt%2C-processedAt';
$json = file_get_contents($url);
$results = json_decode($json);
$channel = new Channel();
$channel
->title("Sketchfab Staff Picks")
->description("Sketchfab Staff Picks")
->url('https://sketchfab.com/models/staffpicks')
->appendTo($feed);
$description = '';
function compareThumbnail($a, $b) {
return $b->width - $a->width;
}
foreach ($results->results as $model) {
$thumbs = usort($model->thumbnails->images, 'compareThumbnail');
$thumbnail = $model->thumbnails->images[0];
$thumbnailHtml = "<a href='" . $model->viewerUrl . "'><img src='" . $model->thumbnails->images[0]->url . "' alt='" . htmlspecialchars($model->name) . "' width='" . $model->thumbnails->images[0]->width . "' height='" . $model->thumbnails->images[0]->height . "'></a>";
$description = $thumbnailHtml . "<br>" . $Parsedown->text($model->description);
$item = new Item();
$item
->title($model->name . ' by ' . $model->user->displayName)
->description($description)
->url($model->viewerUrl)
->appendTo($channel);
}
header('Content-Type: application/rss+xml');
echo $feed;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment