From: vincent@cubedesigners.com Date: Tue, 18 Dec 2012 15:12:09 +0000 (+0000) Subject: (no commit message) X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=eba7970c5d9338a01a8802dc5598cbe7ff4c2c6a;p=cubeextranet.git --- diff --git a/fluidbook/tools/fwstk/nbproject/private/private.xml b/fluidbook/tools/fwstk/nbproject/private/private.xml index 4ffd82c24..c792dc1b3 100644 --- a/fluidbook/tools/fwstk/nbproject/private/private.xml +++ b/fluidbook/tools/fwstk/nbproject/private/private.xml @@ -2,4 +2,8 @@ + + file:/H:/Works/cubeExtranet/fluidbook/tools/fwstk/src/com/fluidbook/fwstk/Main.java + file:/H:/Works/cubeExtranet/fluidbook/tools/fwstk/src/com/fluidbook/fwstk/Link.java + diff --git a/inc/commons/class.common.core.php b/inc/commons/class.common.core.php index f2e973f18..8d4377fb5 100644 --- a/inc/commons/class.common.core.php +++ b/inc/commons/class.common.core.php @@ -464,6 +464,12 @@ class commonCore extends cubeCore { // Table Grdf $db->grdf->datas('text', 0, false); + // Table google search api + $db->google_search_api->request('varchar', 256, false); + $db->google_search_api->response('text', 0, false); + $db->google_search_api->date('integer', 0, false); + $db->google_search_api->primary('pk_google_search_api', 'request'); + try { $dbi = new CubeDbStruct($this->con); diff --git a/inc/commons/class.common.tools.php b/inc/commons/class.common.tools.php index 52c56fe30..fc0de7928 100644 --- a/inc/commons/class.common.tools.php +++ b/inc/commons/class.common.tools.php @@ -386,8 +386,8 @@ class commonTools { unlink($tmp); exit; } - - public static function css(){ + + public static function css() { } @@ -649,6 +649,57 @@ class commonTools { return $res; } + public static function googleLucky() { + + $q = $_GET['q']; + $cx = $_GET['cx']; + $keys = array('AIzaSyBdYNtOMDzG66F29SgYdq9r-4Nabzaq9q0', 'AIzaSyCfivE2-R2fMp-F9Q5nvBHjgSdKFjTu_9A'); + shuffle($keys); + $key = array_shift($keys); + + $r = self::searchGoogle($q, $cx, $key); + if (!is_null($r)) { + http::redirect($r['items'][0]['link']); + } + } + + protected function searchGoogle($q, $cx, $key) { + global $core; + + $url = 'https://www.googleapis.com/customsearch/v1?key=' . $key . '&q=' . rawurlencode($q) . '&cx=' . $cx; + $limit = TIME - (3600 * 24 * 10); // Cache de 10j + + $r = $core->con->select('SELECT response FROM google_search_api WHERE request=\'' . $core->con->escape($request) . '\''); + if ($r->count()) { + $cached = $r->response; + if ($r->date > $limit) { + return json_decode($cached, true); + } + } + + + $j = file_get_contents($url); + $json = json_decode($j, true); + if (isset($json['items'][0]['link'])) { + $c = $core->con->openCursor('google_search_api'); + $c->request = $url; + $c->response = $json; + $c->date = TIME; + try { + $c->insert(); + } catch (Exception $e) { + $c->update('WHERE url=\'' . $core->con->escape($url) . '\''); + } + return $json; + } + + if (isset($cached)) { + return json_decode($cached, true); + } else { + return null; + } + } + } ?>