Skip to content

Instantly share code, notes, and snippets.

@themakunga
Created September 28, 2017 19:31
Show Gist options
  • Save themakunga/1d8eec3062857d4fc0d60524bceb8f8e to your computer and use it in GitHub Desktop.
Save themakunga/1d8eec3062857d4fc0d60524bceb8f8e to your computer and use it in GitHub Desktop.
<?php
# @Author: Nicolas Martinez <nicolas>
# @Date: 2017-05-22T15:33:05-04:00
# @Email: pmartinez@allware.cl
# @Filename: cargadatos.php
# @Last modified by: nicolas
# @Last modified time: 2017-09-28T16:15:19-03:00
/*
* Install Via composer sunra/php-simple-html-dom-parser
*
*
*/
include __DIR__.'/vendor/autoload.php';
use Sunra\PhpSimple\HtmlDomParser;
header('Content-Type: application/json');
$url='http://dev.virtuemart.net/projects/virtuemart/files';
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 0);
$file_contents = curl_exec($ch);
curl_close($ch);
$dom = HtmlDomParser::str_get_html( $file_contents );
$elem = $dom->find('table.list tr] tbody', 0);
$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->loadHTML($elem);
if($table = $dom->getElementsByTagName('thead')->item(0)) {
$table->parentNode->removeChild($table);
$elem = preg_replace('/^<!DOCTYPE.+?>/', '', str_replace( array('<html>', '</html>', '<body>', '</body>'), "",$dom->saveHTML()));
}
$dom = HtmlDomParser::str_get_html( $elem );
$linkbase="https://dev.virtuemart.net";
$re = array(
'/\s/',
'/^\<(.+?)\=\"|\"(.+?)a\>/'
);
function cleanversion($str){
$regex = array('/^com(.+?)\.|\.zip$/', '/\_(.+?)$/', '/VirtueMart/');
$res = preg_replace($regex, "", $str);
return $res;
}
foreach ($dom->find('tr.file td') as $tr) { //recorre cada fila de la tabla
foreach ($tr as $t) {
if (isset($t->innertext)) {
$v = $t->find('.filename',0);
$name = $v->find('a', 0);
$co = $t->find('.created_on', 0);
$fs = $t->find('.filesize',0);
$version = cleanversion($name->innertext);
$group = preg_replace('/(.+?)\d\_|\.zip$/', "", $name->innertext);
$link = $linkbase.preg_replace($re,"",$v->innertext);
if ($group == 'extract_first') {
$out[$version][$group]['id'] = preg_replace('/^h(.+?)d\/|\/(.+?)p$/', "", $link);
$out[$version][$group]['filename'] = $name->innertext;
$out[$version][$group]['download'] = $link;
$out[$version][$group]['created_on'] = $co->innertext;
$out[$version][$group]['filezise'] = $fs->innertext;
}
}
}
}
echo json_encode($out, JSON_PRETTY_PRINT);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment