Created
May 19, 2016 03:23
-
-
Save gabeb1920/61b81b6a0eb6b020ed887738fce4d90b to your computer and use it in GitHub Desktop.
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 | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, "https://cloud.feedly.com/v3/subscriptions"); | |
$headers = array("Authorization: OAuth [Add your dev token here]"); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | |
$output = curl_exec($ch); | |
curl_close($ch); | |
$subscriptions = json_decode($output); | |
class category { | |
public $label; | |
public $subscriptions = array(); | |
} | |
class subscription { | |
public $title; | |
public $feed; | |
} | |
$categories = array(); | |
$titleStr = "title"; | |
$categoriesStr = "categories"; | |
$catLabelStr = "label"; | |
$feedStr = "id"; | |
foreach($subscriptions as $subs) { | |
$categroyExists = false; | |
$catObj = $subs->$categoriesStr; | |
foreach($categories as $cat) { | |
if(strcmp($catObj[0]->$catLabelStr, $cat->label) == 0) { | |
//echo "category exists " . $catObj[0]->$catLabelStr . "<br>"; | |
$categroyExists = true; | |
$tempSubscription = new subscription(); | |
$tempSubscription->title = $subs->$titleStr; | |
$tempSubscription->feed = substr($subs->$feedStr, 5); | |
array_push($cat->subscriptions, $tempSubscription); | |
break; | |
} | |
} | |
if(!$categroyExists) { | |
// echo "new category " . $catObj[0]->$catLabelStr . "<br>"; | |
$tempSubscription = new subscription(); | |
$tempSubscription->title = $subs->$titleStr; | |
$tempSubscription->feed = substr($subs->$feedStr, 5); | |
$tempCategory = new category(); | |
$tempCategory->label = $catObj[0]->$catLabelStr; | |
$tempCategory->subscriptions = array($tempSubscription); | |
array_push($categories, $tempCategory); | |
} | |
} | |
foreach($categories as $cat) { | |
echo "<h2>" . $cat->label . "</h2><ul>"; | |
foreach($cat->subscriptions as $sub) { | |
echo "<li><a href=\"" . $sub->feed . "\" target=\"_blank\">" . $sub->title . "</a></li>"; | |
} | |
echo "</ul>"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment