]> _ Git - cubeextranet.git/commitdiff
wip #2428 @8
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Thu, 13 Dec 2018 18:08:27 +0000 (18:08 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Thu, 13 Dec 2018 18:08:27 +0000 (18:08 +0000)
inc/commons/class.common.core.php
inc/ws/Controlleur/class.ws.services.php
inc/ws/Util/html5/3dflip/class.ws.html5.compiler.php

index 6b2628367c02ebf98b050cde09f78a00e34fe4de..7b2ba635b1fa2044775f447d89669cde3ae8e5af 100644 (file)
@@ -541,12 +541,20 @@ class commonCore extends cubeCore
 \r
                // Table gpu\r
                $db->gpu->gpu('varchar', 256, false);\r
+               $db->gpu->rgpu('varchar', 256, false);\r
                $db->gpu->page('text', 0, false);\r
                $db->gpu->version('integer', 0, false);\r
                $db->gpu->date('integer', 0, false);\r
                $db->gpu->score('integer', 0, false);\r
+               $db->gpu->url('varchar', 512, false);\r
                $db->gpu->benchmark('text', 0, false);\r
-               $db->gpu->primary('pk_gpu', 'gpu', 'version');\r
+               $db->gpu->primary('pk_gpu', 'gpu', 'rgpu', 'version');\r
+\r
+               // gpu log\r
+               $db->gpu_log->gpu('varchar', 256, false);\r
+               $db->gpu_log->rgpu('varchar', 256, false);\r
+               $db->gpu_log->date('integer', 0, false);\r
+               $db->gpu_log->primary('pk_gpu_log', 'gpu', 'rgpu', 'date');\r
 \r
                try {\r
                        $dbi = new CubeDbStruct($this->con);\r
index 5910ef99d9c9ba2617e2fba4e3817263fa22884c..2263a0d6c4f5f4e37bd05616bbd906e08cad68bf 100644 (file)
@@ -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, '<p class="label1">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, '<p class="label1">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);
+       }
 }
index ceefad95e006a246742205b90690f07293e4b587..7d2f907440096e63a8c0c3667216f8314987379a 100644 (file)
@@ -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 . ';}';