]> _ Git - cubeextranet.git/commitdiff
(no commit message)
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 18 Dec 2012 15:12:09 +0000 (15:12 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 18 Dec 2012 15:12:09 +0000 (15:12 +0000)
fluidbook/tools/fwstk/nbproject/private/private.xml
inc/commons/class.common.core.php
inc/commons/class.common.tools.php

index 4ffd82c2462382b8a9ccf59c15a3ee79930199c7..c792dc1b35ef5c623064ec2137a23e58f0b6d95d 100644 (file)
@@ -2,4 +2,8 @@
 <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
index f2e973f18853ef757883dbfcf8d0c73c55b79700..8d4377fb5932780d2b5f570aae25667a80cbb285 100644 (file)
@@ -464,6 +464,12 @@ class commonCore extends cubeCore {
                // 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
index 52c56fe30b7056c534f35f7311e6955a87764626..fc0de79285b833ee2e022b584e149b817ac9ffa6 100644 (file)
@@ -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;
+               }
+       }
+
 }
 
 ?>