function getResultsThemeForest($searchterm)
{
    $searchterm = urlencode($searchterm);
    //if chached version is available
    if (file_exists('_searches/' . $searchterm . '.json')) {
        $json = file_get_contents('_searches/' . $searchterm . '.json');
        //no cached version available - get it
    } else {
        $url = 'http://marketplace.envato.com/api/v3/search:themeforest,,' . str_replace('+', '|', $searchterm) . '.json';
        $useragent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
        curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $json = curl_exec($ch);
        curl_close($ch);
        //we reached the API limit - switch to wikipedia
        if (empty($json)) {
            return getResultsFromWikipedia($searchterm);
        }
        file_put_contents('_searches/' . $searchterm . '.json', $json);
    }
    $obj = json_decode($json);
    $results = array();
    $i = 0;
    foreach ($obj->search as $item) {
        if (++$i > 10) {
            continue;
        }
        $array = array('href' => $item->url . '?ref=revaxarts', 'text' => '<strong>' . $item->description . '</strong>', 'img' => $item->item_info->thumbnail);
        array_push($results, $array);
    }
    //and put a little info at the beginning
    if (!empty($results)) {
        array_unshift($results, array('href' => '#', 'text' => '<strong>The results are from Themeforest. It\'s very easy to adopt it to your own search results!</strong>'));
    }
    return $results;
}
Esempio n. 2
0
function getResultsThemeForest($searchterm)
{
    $searchterm = urlencode($searchterm);
    //if chached version is available
    if (file_exists('_searches/' . $searchterm . '.json')) {
        $json = file_get_contents('_searches/' . $searchterm . '.json');
        //no cached version available - get it
    } else {
        $url = 'http://marketplace.envato.com/api/v3/search:themeforest,,' . str_replace('+', '|', $searchterm) . '.json';
        $useragent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
        curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $json = curl_exec($ch);
        curl_close($ch);
        // we reached the API limit - switch to wikipedia
        if (empty($json)) {
            return getResultsFromWikipedia($searchterm);
        }
        file_put_contents('_searches/' . $searchterm . '.json', $json);
    }
    $obj = json_decode($json);
    $results = array();
    $i = 0;
    foreach ($obj->search as $item) {
        if (++$i > 10) {
            continue;
        }
        $array = array('href' => $item->url . '?ref=Stammi', 'title' => $item->description, 'descr' => 'Price: $' . intval($item->item_info->cost), 'img' => $item->item_info->thumbnail);
        array_push($results, $array);
    }
    return $results;
}