Created
April 26, 2016 09:05
-
-
Save mauricesvay/3efe87959db8a623fe2cb39e7a9b9eda to your computer and use it in GitHub Desktop.
Sketchfab RSS Feed for Staff Picks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"require": { | |
"suin/php-rss-writer": "^1.3", | |
"erusev/parsedown": "^1.6" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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