Last active
December 10, 2017 07:57
-
-
Save shahariaazam/716883a47e717e4a02459f483f9d6ff3 to your computer and use it in GitHub Desktop.
Get ThemeForest theme statistics and information in simple PHP script
This file contains hidden or 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 | |
/** | |
* ThemeForest specific theme information with Theme details, Total Sell Count, Total Comments, etc.. | |
* | |
* encouraged by @sohelrana820 & @aislamfaisal on a chitchat | |
* | |
* @autho: Shaharia Azam <[email protected]> | |
* @url: https://blog.shaharia.com | |
* | |
* | |
* @param null $themeUrl | |
* @return int | |
*/ | |
function loadDom($themeUrl) | |
{ | |
$ch = curl_init($themeUrl); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
$html = curl_exec($ch); | |
curl_close($ch); | |
$dom = new DOMDocument(); | |
@$dom->loadHTML($html); | |
return new DOMXPath($dom); | |
} | |
function getInfo($themeUrl = null) | |
{ | |
$x = loadDom($themeUrl); | |
//Sell count | |
foreach ($x->query('//*[@class="sidebar-stats__number"]') as $node) { | |
$possibleData[] = $node->nodeValue; | |
} | |
//Total Price | |
foreach ($x->query('//*[@class="js-purchase-price"]') as $node) { | |
$price[] = $node->nodeValue; | |
} | |
//Additional Info | |
foreach ($x->query('//*[@class="meta-attributes__attr-detail"]') as $node) { | |
$info[] = preg_replace('/\s+/', '', $node->nodeValue); | |
} | |
$y = loadDom($themeUrl . '/comments'); | |
foreach ($y->query('//*[@class="t-heading -size-s h-mb2"]') as $node) { | |
$infoComment[] = preg_replace('/\s+/', '', $node->nodeValue); | |
} | |
$data = [ | |
'sellCount' => intval($possibleData[0]), | |
'price' => $price[0], | |
'created' => date('Y-m-d', strtotime($info[0])), | |
'lastUpdated' => date('Y-m-d', strtotime($info[1])), | |
'highResolution' => $info[2], | |
'compatibleBrowsers' => $info[3], | |
'filesIncluded' => $info[4], | |
'columns' => $info[5], | |
'documentation' => $info[6], | |
'layout' => $info[7], | |
'totalComment' => intval($infoComment[0]) | |
]; | |
return $data; | |
} | |
//Provide your specific theme URL here | |
$themeUrl = "https://themeforest.net/item/car-house-car-dealer-template/17628233"; | |
print_r(getInfo($themeUrl)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi i run this code in my local php nut i will get a lot of error Undefined variable: all of the line why can you help me please!!!!:(((