Last active
December 29, 2015 07:19
-
-
Save jgraup/7634944 to your computer and use it in GitHub Desktop.
CodePen.io - Pulls CodePen.io User Feed
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 | |
/** | |
* CodePen.io user feed example | |
*/ | |
include_once("codepen.php"); | |
if ((isset($_REQUEST['format']) && $_REQUEST['format'] == 'xml') || | |
(isset($_REQUEST['output']) && $_REQUEST['output'] == 'xml') ) { | |
header("Content-type: text/xml; charset=utf-8"); | |
echo isset($_REQUEST['user']) | |
? CodePen::Feed($_REQUEST['user']) | |
: CodePen::Feed(); | |
exit(); | |
} | |
$data = isset($_REQUEST['user']) | |
? CodePen::FeedJSON($_REQUEST['user']) | |
: CodePen::FeedJSON(); | |
if ($data) | |
{ | |
if ($_REQUEST['callback']) { | |
// jsonp | |
header('Content-type: application/javascript'); | |
echo $_REQUEST['callback'],'(', $data,');'; | |
} else { | |
header('Content-type: application/json'); | |
echo $data; | |
} | |
} | |
else | |
{ | |
echo "Error", ""; | |
} |
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 | |
/** | |
* CodePen.io Class | |
*/ | |
class CodePen | |
{ | |
/** | |
* @param string $user | |
* @return string url of user's feed | |
*/ | |
public static function FeedUrl($user) | |
{ | |
return "https://codepen.io/{$user}/activity/feed"; | |
} | |
/** | |
* @param string $user (optional) | |
* @return string feed as string | |
*/ | |
public static function Feed($user = "justgooddesign") | |
{ | |
try { | |
return @file_get_contents(CodePen::FeedUrl($user)); | |
} | |
catch (Exception $e) { | |
return $e->getMessage(); | |
} | |
} | |
/** | |
* @param string $user (optional) | |
* @return SimpleXMLElement feed as XML object | |
*/ | |
public static function FeedXML($user = "justgooddesign") | |
{ | |
try { | |
return simplexml_load_file(CodePen::FeedUrl($user)); | |
} | |
catch (Exception $e) { | |
return $e->getMessage(); | |
} | |
} | |
/** | |
* @param string $user (optional) | |
* @return string feed as JSON | |
*/ | |
public static function FeedJSON($user = "justgooddesign") | |
{ | |
try { | |
$xml = @file_get_contents(CodePen::FeedUrl($user)); | |
$xml = preg_replace('~\s*(<([^>]*)>[^<]*</\2>|<[^>]*>)\s*~','$1',$xml); | |
$xml = simplexml_load_string($xml,'SimpleXMLElement', LIBXML_NOCDATA); | |
return json_encode($xml); | |
} | |
catch (Exception $e) { | |
return $e->getMessage(); | |
} | |
} | |
} |
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
{ | |
"@attributes": { | |
"version": "2.0" | |
}, | |
"channel": { | |
"title": "Recent Activity on CodePen", | |
"link": "http://codepen.io/justgooddesign/activity/", | |
"description": {}, | |
"item": [ | |
{ | |
"title": "\n \n\n \n\n\n\n\n\n\n\n\n \n MayconSouza\n\n hearted your Pen\n \n \"Leaflet.js\"\n \n\n\n\n\n\n ", | |
"link": "http://codepen.io/justgooddesign/activity/", | |
"guid": "http://codepen.io/justgooddesign/activity/", | |
"author": "Just Good Design", | |
"description": "\n <a href=\"http://codepen.io/MayconSouza/\" class=\"activity-avatar\"><img src=\"//gravatar.com/avatar/7e714ba044c8b008be1818b573ac8c9a?s=80\" alt=\"\" /></a><img src=\"http://codepen.io/images/activity/activity-heart.png\" /><p class=\"activity-sentence wrap-text\"><a href=\"http://codepen.io/MayconSouza\" class=\"activity-name\">MayconSouza</a><span class=\"activity-action\">hearted your Pen</span><a href=\"http://codepen.io/justgooddesign/details/HpExK\" class=\"activity-thing\">Leaflet.js</a></p>", | |
"pubDate": "2013-11-24T01:06:23-07:00" | |
} | |
] | |
} | |
} |
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
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0"> | |
<channel> | |
<title>Recent Activity on CodePen</title> | |
<link>http://codepen.io/justgooddesign/activity/</link> | |
<description/> | |
<dc:language>en</dc:language> | |
<dc:creator>[email protected]</dc:creator> | |
<dc:rights>Copyright 2013</dc:rights> | |
<dc:date>2013-11-24T01:06:23-07:00</dc:date> | |
<item> | |
<title> | |
MayconSouza hearted your Pen "Leaflet.js" | |
</title> | |
<link>http://codepen.io/justgooddesign/activity/</link> | |
<guid>http://codepen.io/justgooddesign/activity/</guid> | |
<author>Just Good Design</author> | |
<description> | |
<![CDATA[ | |
<a href="http://codepen.io/MayconSouza/" class="activity-avatar"> <img src="//gravatar.com/avatar/7e714ba044c8b008be1818b573ac8c9a?s=80" alt="" /> </a> <img src="http://codepen.io/images/activity/activity-heart.png" /> <p class="activity-sentence wrap-text"> <a href="http://codepen.io/MayconSouza" class="activity-name">MayconSouza</a> <span class="activity-action">hearted your Pen</span> <a href="http://codepen.io/justgooddesign/details/HpExK" class="activity-thing"> Leaflet.js </a> </p> | |
]]> | |
</description> | |
<pubDate>2013-11-24T01:06:23-07:00</pubDate> | |
</item> | |
</channel> | |
</rss> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment