Skip to content

Instantly share code, notes, and snippets.

@zaigham
Last active October 5, 2016 19:47
Show Gist options
  • Save zaigham/c32f8bd8854d4cc41f18 to your computer and use it in GitHub Desktop.
Save zaigham/c32f8bd8854d4cc41f18 to your computer and use it in GitHub Desktop.
MODX Themes details from ThemeForest JSON API
<article class="col-sm-6 col-md-6 col-lg-6">
<div><a href="[[+url]]?ref=[[+ref]]"><img class="img-responsive" src="[[+live_preview_url]]" alt="[[+item]]"></a></div>
<div style="min-height: 6em;"><h4><a href="[[+url]]?ref=[[+ref]]">[[+item]]<br/><small>USD$[[+cost]]</small></h4></a></div>
</article>
//<?
$output = '';
$agent = 'MODX-LINK';
$ch = curl_init('http://marketplace.envato.com/api/v3/search:themeforest,cms-themes,modx.json');
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$themes_list = curl_exec($ch);
//curl_close($ch); // Close curl connection
// return $output = $themes_list;
$themes = $modx->fromJSON($themes_list);
// return $output = "<pre>" . print_r($themes, true);
if(!empty($themes)) {
foreach($themes['search'] as $theme) {
$theme_id = $theme['id'];
$theme_detail_url = 'http://marketplace.envato.com/api/v3/item:'.$theme_id.'.json'; // details, thumbnails etc. live on this feed
$ch = curl_init($theme_detail_url);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$theme_details = curl_exec($ch);
//curl_close($ch); // Close curl connection
$theme = $modx->fromJSON($theme_details);
$output .= $modx->getChunk($tpl, $theme['item']); // template your snippet! http://rtfm.modx.com/revolution/2.x/developing-in-modx/basic-development/snippets/templating-your-snippets
}
} else {
$output = "Something is wrong!";
return $output;
}
curl_close($ch); // Close curl connection
return $output;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment