<project-private xmlns="http://www.netbeans.org/ns/project-private/1">\r
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>\r
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>\r
+ <open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/1">\r
+ <file>file:/H:/Works/cubeExtranet/fluidbook/tools/fwstk/src/com/fluidbook/fwstk/Main.java</file>\r
+ <file>file:/H:/Works/cubeExtranet/fluidbook/tools/fwstk/src/com/fluidbook/fwstk/Link.java</file>\r
+ </open-files>\r
</project-private>\r
// Table Grdf\r
$db->grdf->datas('text', 0, false);\r
\r
+ // Table google search api\r
+ $db->google_search_api->request('varchar', 256, false);\r
+ $db->google_search_api->response('text', 0, false);\r
+ $db->google_search_api->date('integer', 0, false);\r
+ $db->google_search_api->primary('pk_google_search_api', 'request');\r
+\r
\r
try {\r
$dbi = new CubeDbStruct($this->con);\r
unlink($tmp);
exit;
}
-
- public static function css(){
+
+ public static function css() {
}
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;
+ }
+ }
+
}
?>