Changeset 2629
- Timestamp:
- 5/22/2012 4:48:22 AM (12 months ago)
- Location:
- trunk/website
- Files:
-
- 2 edited
-
download.php (modified) (2 diffs)
-
scripts/SourceForge.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/website/download.php
r2627 r2629 9 9 try 10 10 { 11 $download = new Download(intval($_GET['id'])); 12 11 $download = new Download(intval($_GET['id'])); 12 13 13 //Check for supersedence 14 14 if (!$download->Superseded) … … 75 75 <td>6.0.8.2343</td> 76 76 <td>6/11/2011 1:30pm</td> 77 <td> </td>77 <td><?php echo SourceForge::GetDownloads('http://sourceforge.net/projects/eraser/files/Eraser%206/6.0.9/Eraser%206.0.9.2343.exe/download'); ?></td> 78 78 </tr> 79 79 <tr> -
trunk/website/scripts/SourceForge.php
r2248 r2629 39 39 $pathComponents = explode('/', $urlInfo['path']); 40 40 41 //The first three components is the page we need to download. 42 $downloadPage = implode('/', array_slice($pathComponents, 0, 4)); 41 //Retain all path components except the final /download 42 $downloadPage = implode('/', array_merge(array_slice($pathComponents, 0, -1), array('stats', 'json'))); 43 $downloadPage .= '?start_date=2001-10-04&end_date=' . date('Y-m-d'); 43 44 44 //Parse the download page. 45 $document = new DOMDocument(); 46 47 //Get the download page, using the cache if it exists. 48 $document->loadHTML(SourceForge::Download('http://sourceforge.net' . $downloadPage, 60 * 60)); 49 foreach ($document->getElementsByTagName('a') as $element) 45 //Get the JSON and parse it 46 $document = json_decode(SourceForge::Download('http://sourceforge.net' . $downloadPage, 60 * 60)); 47 if (!empty($document->total)) 50 48 { 51 if (!is_a($element, 'DOMElement')) 52 continue; 53 54 //$parent is the <td> node. 55 $parent = $element->parentNode; 56 if (is_a($parent, 'DOMElement') && $parent->tagName == 'td' && 57 $parent->getAttribute('class') == 'tree') 58 { 59 $downloadUrlInfo = parse_url(urldecode($element->getAttribute('href'))); 60 if ($urlInfo['path'] == $downloadUrlInfo['path']) 61 { 62 //$grandParent is the <tr> node. 63 $grandParent = $parent->parentNode; 64 65 //Find the download column (currently the 5th) 66 $i = 0; 67 foreach ($grandParent->getElementsByTagName('td') as $cell) 68 { 69 if (++$i == 5) 70 { 71 //We are at the 5th column, return the contents as an integer. 72 $result = str_replace(',', '', $cell->textContent); 73 return intval($result); 74 } 75 } 76 } 77 } 49 return intval($document->total); 78 50 } 79 51 80 throw new Exception('Could not find the node containing the download.');52 throw new Exception('Could not find the node containing the number of downloads.'); 81 53 } 82 54
Note: See TracChangeset
for help on using the changeset viewer.
