Skip to content
This repository has been archived by the owner on May 12, 2022. It is now read-only.

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pdincubus committed Mar 30, 2012
1 parent 3e74acc commit a1beb91
Show file tree
Hide file tree
Showing 8 changed files with 566 additions and 0 deletions.
69 changes: 69 additions & 0 deletions snippet.JSONDerulo.DeliciousFeed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
$cacheTime = 43200; // 12 hours
$feedUrl = 'http://feeds.delicious.com/v2/json/{username}?count={limit}';

$ch = null;

$tpl = $modx->getOption('tpl', $scriptProperties, '');
$limit = $modx->getOption('limit', $scriptProperties, 2);
$excludeEmpty = explode(',', $modx->getOption('excludeEmpty', $scriptProperties, 'd'));
$feeds = explode(',', $modx->getOption('users', $scriptProperties, ''));

$rawFeedData = array();

foreach ($feeds as $username) {
$cacheId = 'deliciousfeed-'.$username;

if (($json = $modx->cacheManager->get($cacheId)) === null) {
if ($ch === null) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
}

curl_setopt_array($ch, array(
CURLOPT_URL => str_replace(array('{username}', '{limit}'), array($username, $limit), $feedUrl),
));

$json = curl_exec($ch);
if (empty($json)) {
continue;
}

$modx->cacheManager->set($cacheId, $json, $cacheTime);
}

$feed = json_decode($json);

if ($feed === null) {
continue;
}


foreach ($feed as $item) {
foreach ($excludeEmpty as $k) {
if ($item->$k == '') {
continue 2;
}
}

$rawFeedData[] = array(
'title' => $item->d,
'link' => $item->u,
'date' => strtotime($item->dt),
'username' => $username,
);

}

}

if ($ch !== null) {
curl_close($ch);
}

$output = '';
foreach ($rawFeedData as $item) {
$output .= $modx->getChunk($tpl, $item);
}

return $output;
70 changes: 70 additions & 0 deletions snippet.JSONDerulo.FlickrFeed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
$cacheTime = 43200; // 12 hours
$feedUrl = 'http://api.flickr.com/services/rest/?method=flickr.photos.search&format=json&nojsoncallback=1&api_key={apikey}&user_id={userid}&per_page={limit}&extras=url_m,date_upload';

$ch = null;

$tpl = $modx->getOption('tpl', $scriptProperties, '');
$limit = $modx->getOption('limit', $scriptProperties, 2);
$excludeEmpty = explode(',', $modx->getOption('excludeEmpty', $scriptProperties, 'url_m'));
$feeds = explode(',', $modx->getOption('users', $scriptProperties, '22342246@N03'));
$apiKey = $modx->getOption('apiKey', $scriptProperties, '');
$userName = $modx->getOption('userName', $scriptProperties, '');

$rawFeedData = array();

foreach ($feeds as $userId) {
$cacheId = 'flickrfeed-'.$userId;

if (($json = $modx->cacheManager->get($cacheId)) === null) {
if ($ch === null) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
}

curl_setopt_array($ch, array(
CURLOPT_URL => str_replace(array('{apikey}', '{userid}', '{limit}'), array($apiKey, $userId, $limit), $feedUrl),
));


$json = curl_exec($ch);
if (empty($json)) {
continue;
}

$modx->cacheManager->set($cacheId, $json, $cacheTime);
}

$feed = json_decode($json);

if ($feed === null) {
continue;
}

foreach ($feed->photos->photo as $photo) {
foreach ($excludeEmpty as $k) {
if ($photo->$k == '') {
continue 2;
}
}

$rawFeedData[] = array(
'id' => $photo->id,
'created' => $photo->dateupload,
'picture' => $photo->url_m,
'title' => $photo->title,
'username' => $userName,
);
}
}

if ($ch !== null) {
curl_close($ch);
}

$output = '';
foreach ($rawFeedData as $photo) {
$output .= $modx->getChunk($tpl, $photo);
}

return $output;
73 changes: 73 additions & 0 deletions snippet.JSONDerulo.LastFmFeed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
$cacheTime = 43200; // 12 hours
$feedUrl = 'http://ws.audioscrobbler.com/2.0/?method=user.getlovedtracks&user={username}&api_key={apikey}&format=json&limit={limit}';

$ch = null;

$tpl = $modx->getOption('tpl', $scriptProperties, '');
$limit = $modx->getOption('limit', $scriptProperties, 2);
$excludeEmpty = explode(',', $modx->getOption('excludeEmpty', $scriptProperties, 'name'));
$feeds = explode(',', $modx->getOption('users', $scriptProperties, ''));
$apiKey = $modx->getOption('apiKey', $scriptProperties, '');

$rawFeedData = array();

foreach ($feeds as $username) {
$cacheId = 'lastfmfeed-'.$username;

if (($json = $modx->cacheManager->get($cacheId)) === null) {
if ($ch === null) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
}

curl_setopt_array($ch, array(
CURLOPT_URL => str_replace(array('{apikey}', '{username}', '{limit}'), array($apiKey, $username, $limit), $feedUrl),
));

$json = curl_exec($ch);
if (empty($json)) {
continue;
}

$modx->cacheManager->set($cacheId, $json, $cacheTime);
}

$feed = json_decode($json);

if ($feed === null) {
continue;
}

$feedtracks = $feed->lovedtracks;

foreach ($feedtracks->track as $item) {
foreach ($excludeEmpty as $k) {
if ($item->$k == '') {
continue 2;
}
}

$rawFeedData[] = array(
'track' => $item->name,
'artist' => $item->artist->name,
'link' => $item->url,
'picture' => $item->image[3]->{'#text'},
'date' => $item->date->uts,
'username' => $username,
);

}

}

if ($ch !== null) {
curl_close($ch);
}

$output = '';
foreach ($rawFeedData as $item) {
$output .= $modx->getChunk($tpl, $item);
}

return $output;
73 changes: 73 additions & 0 deletions snippet.JSONDerulo.LastFmListensFeed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
$cacheTime = 43200; // 12 hours
$feedUrl = 'http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user={username}&api_key={apikey}&format=json&limit={limit}';

$ch = null;

$tpl = $modx->getOption('tpl', $scriptProperties, '');
$limit = $modx->getOption('limit', $scriptProperties, 2);
$excludeEmpty = explode(',', $modx->getOption('excludeEmpty', $scriptProperties, 'name'));
$feeds = explode(',', $modx->getOption('users', $scriptProperties, ''));
$apiKey = $modx->getOption('apiKey', $scriptProperties, '');

$rawFeedData = array();

foreach ($feeds as $username) {
$cacheId = 'lastfmlistensfeed-'.$username;

if (($json = $modx->cacheManager->get($cacheId)) === null) {
if ($ch === null) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
}

curl_setopt_array($ch, array(
CURLOPT_URL => str_replace(array('{apikey}', '{username}', '{limit}'), array($apiKey, $username, $limit), $feedUrl),
));

$json = curl_exec($ch);
if (empty($json)) {
continue;
}

$modx->cacheManager->set($cacheId, $json, $cacheTime);
}

$feed = json_decode($json);

if ($feed === null) {
continue;
}

$feedtracks = $feed->recenttracks;

foreach ($feedtracks->track as $item) {
foreach ($excludeEmpty as $k) {
if ($item->$k == '') {
continue 2;
}
}

$rawFeedData[] = array(
'track' => $item->name,
'artist' => $item->artist->name,
'link' => $item->url,
'picture' => $item->image[3]->{'#text'},
'date' => $item->date->uts,
'username' => $username,
);

}

}

if ($ch !== null) {
curl_close($ch);
}

$output = '';
foreach ($rawFeedData as $item) {
$output .= $modx->getChunk($tpl, $item);
}

return $output;
68 changes: 68 additions & 0 deletions snippet.JSONDerulo.TwitterFeed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
$cacheTime = 43200; // 12 hours
$feedUrl = 'https://api.twitter.com/1/statuses/user_timeline.json?screen_name={username}&count={limit}';

$ch = null;

$tpl = $modx->getOption('tpl', $scriptProperties, '');
$limit = $modx->getOption('limit', $scriptProperties, 2);
$excludeEmpty = explode(',', $modx->getOption('excludeEmpty', $scriptProperties, 'text'));
$feeds = explode(',', $modx->getOption('users', $scriptProperties, 'twitter'));

$rawFeedData = array();

foreach ($feeds as $username) {
$cacheId = 'twitterfeed-'.$username;

if (($json = $modx->cacheManager->get($cacheId)) === null) {
if ($ch === null) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
}

curl_setopt_array($ch, array(
CURLOPT_URL => str_replace(array('{username}', '{limit}'), array($username, $limit), $feedUrl),
));

$json = curl_exec($ch);
if (empty($json)) {
continue;
}

$modx->cacheManager->set($cacheId, $json, $cacheTime);
}

$feed = json_decode($json);

if ($feed === null) {
continue;
}

foreach ($feed as $message) {
foreach ($excludeEmpty as $k) {
if ($message->$k == '') {
continue 2;
}
}

$rawFeedData[] = array(
'id' => $message->id_str,
'message' => $message->text,
'created' => strtotime($message->created_at),
'picture' => $message->user->profile_image_url,
'title' => $message->user->name,
'username' => $message->user->screen_name,
);
}
}

if ($ch !== null) {
curl_close($ch);
}

$output = '';
foreach ($rawFeedData as $message) {
$output .= $modx->getChunk($tpl, $message);
}

return $output;
Loading

0 comments on commit a1beb91

Please sign in to comment.