From: vincent@cubedesigners.com Date: Thu, 13 Dec 2018 18:08:27 +0000 (+0000) Subject: wip #2428 @8 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=b17d5903c05a031492d0355e0b9a46a0dededd6d;p=cubeextranet.git wip #2428 @8 --- diff --git a/inc/commons/class.common.core.php b/inc/commons/class.common.core.php index 6b2628367..7b2ba635b 100644 --- a/inc/commons/class.common.core.php +++ b/inc/commons/class.common.core.php @@ -541,12 +541,20 @@ class commonCore extends cubeCore // Table gpu $db->gpu->gpu('varchar', 256, false); + $db->gpu->rgpu('varchar', 256, false); $db->gpu->page('text', 0, false); $db->gpu->version('integer', 0, false); $db->gpu->date('integer', 0, false); $db->gpu->score('integer', 0, false); + $db->gpu->url('varchar', 512, false); $db->gpu->benchmark('text', 0, false); - $db->gpu->primary('pk_gpu', 'gpu', 'version'); + $db->gpu->primary('pk_gpu', 'gpu', 'rgpu', 'version'); + + // gpu log + $db->gpu_log->gpu('varchar', 256, false); + $db->gpu_log->rgpu('varchar', 256, false); + $db->gpu_log->date('integer', 0, false); + $db->gpu_log->primary('pk_gpu_log', 'gpu', 'rgpu', 'date'); try { $dbi = new CubeDbStruct($this->con); diff --git a/inc/ws/Controlleur/class.ws.services.php b/inc/ws/Controlleur/class.ws.services.php index 5910ef99d..2263a0d6c 100644 --- a/inc/ws/Controlleur/class.ws.services.php +++ b/inc/ws/Controlleur/class.ws.services.php @@ -1332,6 +1332,11 @@ class wsServices extends cubeFlashGateway return ['Direct3D', 'DirectX', 'OpenGL', 'Graphics']; } + public static function gpuTests() + { + return [546, 544, 680, 632]; + } + public function gup() { global $core; @@ -1340,7 +1345,9 @@ class wsServices extends cubeFlashGateway $gpu = base64_decode($_GET['gup']); if (preg_match('/\(([^\)]*)\)/', $gpu, $matches)) { - $gpu = $matches[1]; + if (strlen($matches[1]) > 8) { + $gpu = $matches[1]; + } } $version = 40; @@ -1355,26 +1362,23 @@ class wsServices extends cubeFlashGateway } $gpu = trim($gpu); + $rgpu = trim(base64_decode($_GET['rgup'])); - $r = $core->con->select("SELECT * FROM gpu WHERE version=" . $version . " AND gpu='" . $core->con->escape($gpu) . "'"); + $c = $core->con->openCursor('gpu_log'); + $c->gpu = $gpu; + $c->rgpu = $rgpu; + $c->date = time(); + $c->insert(); + + $r = $core->con->select("SELECT * FROM gpu WHERE version=" . $version . " AND (gpu='" . $core->con->escape($gpu) . "' OR rgpu='" . $core->con->escape($rgpu) . "')"); header('Content-type: text/plain'); + if ($r->isEmpty()) { - $ugpu = urlencode($gpu); - $url = 'https://gfxbench.com/device.jsp?benchmark=gfx' . $version . '&api=gl&hwtype=dGPU&os=Linux&hwname=' . $ugpu . '&D=' . $ugpu . '&testgroup=graphics&var=median'; - - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_VERBOSE, 1); - curl_setopt($ch, CURLOPT_HEADER, 1); - curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0'); - $response = curl_exec($ch); - $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); - $f = substr($response, $header_size); + $search = self::searchGFXDevice($c->gpu, $rgpu, $version); $doc = new DOMDocument(); $doc->strictErrorChecking = FALSE; - $doc->loadHTML($f); + $doc->loadHTML($search['body']); $xml = simplexml_import_dom($doc); $links = $xml->xpath("//a"); @@ -1401,7 +1405,7 @@ class wsServices extends cubeFlashGateway $res[$data['id']] = intval($value); } - $scoreids = [680, 544, 632, 546]; + $scoreids = self::gpuTests(); $num = 0; $score = 0; foreach ($scoreids as $scoreid) { @@ -1417,18 +1421,90 @@ class wsServices extends cubeFlashGateway $c = $core->con->openCursor('gpu'); $c->gpu = $gpu; - $c->page = $f; + $c->rgpu = $rgpu; + $c->page = $search['body']; + $c->url = $search['url']; $c->version = $version; $c->benchmark = serialize($res); $c->score = $score; $c->date = time(); $c->insert(); - - echo $score; } else { $r->fetch(); - echo $r->score; + $score = $r->score; } + ob_end_clean(); + echo $score; exit; } + + public static function searchGFXDevice($gpu, $raw, $gfxVersion = 40) + { + // First intention direct request + $ugpu = urlencode($gpu); + $url = 'https://gfxbench.com/device.jsp?benchmark=gfx' . $gfxVersion . '&hwname=' . $ugpu . '&D=' . $ugpu . '&testgroup=graphics&var=median'; + + $f = self::_curlRequest($url); + if (!stristr($f, '

No such device')) { + return ['url' => $url, 'body' => $f]; + } + + // Second intention is to use the search engine to lookup the gpu by name + $tests = self::gpuTests(); + $cacheLimit = max(time() - 21600, filemtime(__FILE__)); + foreach ($tests as $test) { + + // Test cache file + $cacheTest = WS_CACHE . '/gfxbench/test_' . $test; + if (!file_exists($cacheTest) || filemtime($cacheTest) < $cacheLimit) { + $f = self::_curlRequest('https://gfxbench.com/result.jsp?benchmark=gfx' . $gfxVersion . '&test=' . $test . '&order=median&base=device'); + + // Search database is stored as js variables in code + $variables = ['gpuNameLookup', 'deviceId', 'gpuName']; + $v = []; + foreach ($variables as $variable) { + if (preg_match('/var ' . $variable . ' = ([^;]*);/ui', $f, $matches)) { + eval('$v[$variable] = ' . $matches[1] . ';'); + } + } + file_put_contents($cacheTest, serialize($v)); + } else { + $v = unserialize(file_get_contents($cacheTest)); + } + + $key = null; + foreach ($v['gpuNameLookup'] as $k => $item) { + if (stristr($item, $raw)) { + $key = $k; + break; + } + } + + // If we get a device id, we have the the device page :) + if (null !== $key) { + $deviceKey = array_search($key, $v['gpuName']); + $deviceId = $v['deviceId'][$deviceKey]; + $url = 'https://gfxbench.com/device.jsp?benchmark=gfx' . $gfxVersion . '&did=' . $deviceId; + $f = self::_curlRequest($url); + if (!stristr($f, '

No such device')) { + return ['url' => $url, 'body' => $f]; + } + } + } + return ['url' => '', 'body' => '']; + } + + + protected static function _curlRequest($url) + { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_VERBOSE, 1); + curl_setopt($ch, CURLOPT_HEADER, 1); + curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0'); + $response = curl_exec($ch); + $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); + return substr($response, $header_size); + } } diff --git a/inc/ws/Util/html5/3dflip/class.ws.html5.compiler.php b/inc/ws/Util/html5/3dflip/class.ws.html5.compiler.php index ceefad95e..7d2f90744 100644 --- a/inc/ws/Util/html5/3dflip/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/3dflip/class.ws.html5.compiler.php @@ -1628,11 +1628,13 @@ class wsHTML5Compiler $left = $w; + $centerOffset = 0; if ($this->book->parametres->correctCenter) { $centerOffset = 3; $left = ($cssWidth - $centerOffset) . 'px'; $res[] = '.doublePage._3d .page.left{left:-' . ($centerOffset + 1) . 'px !important;}'; } + $lessVariables['correct-center'] = ($centerOffset * -1); $res[] = '.doublePage._3d{left:' . $left . ';}'; $res[] = '#links.right{left:-' . $left . ';}';