Created
May 19, 2014 19:01
-
-
Save drogers98/ccde50cf873f94154540 to your computer and use it in GitHub Desktop.
4good json feed
This file contains hidden or 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 | |
//include parsedown.php, to format the descriptions parsedown markup | |
include '../plugins/parsedown.php'; | |
// header needed for https workaround | |
$opts = array('http'=>array('header' => "User-Agent:MyAgent/1.0\r\n")); | |
$context = stream_context_create($opts); | |
$content = file_get_contents('https://4good.org/library-feed/Your_Feed_Here/latest.json',false,$context); | |
// function to remove the {by} in the description | |
function delete_all_between($beginning, $end, $description) { | |
$beginningPos = strpos($description, $beginning); | |
$endPos = strpos($description, $end); | |
if (!$beginningPos || !$endPos) { | |
return $description; | |
} | |
$textToDelete = substr($description, $beginningPos, ($endPos + strlen($end)) - $beginningPos); | |
return str_replace($textToDelete, '', $description); | |
} | |
//Now decode and print | |
$json = json_decode($content, true); | |
foreach($json['results'] as $item) { | |
// define some vars | |
$Parsedown = new Parsedown(); | |
$description = $item['description']; | |
// remove the weird {by} | |
$description = delete_all_between('{', '}', $description); | |
// If there is an image, lets show it | |
if ($item['image_thumb_url']){ | |
echo "<a href='" . $item['url'] . "'><img class='FeedImage' src='https://4good.org" . $item['image_thumb_url'] . "'></a>"; | |
} | |
//title, linked to content | |
echo "<h2><a href='" . $item['url'] . "'>" . $item['title'] . "</a></h2>"; | |
//Author info and link | |
echo "<p class='meta'><a href='" . $item['owner_url'] . "'>" . $item['owner_name'] . "</a></p>"; | |
//show the description | |
echo $Parsedown->text($description); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
uses Parsedown (https://github.com/erusev/parsedown)