]> _ Git - fluidbook-v3.git/commitdiff
wip #6407 @1.5
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Wed, 18 Oct 2023 07:31:58 +0000 (07:31 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Wed, 18 Oct 2023 07:31:58 +0000 (07:31 +0000)
framework/application/Fluidbook/ToolboxAPI.php [new file with mode: 0644]
framework/application/configs/application.ini
framework/application/controllers/AjaxController.php
framework/application/controllers/MaintenanceController.php

diff --git a/framework/application/Fluidbook/ToolboxAPI.php b/framework/application/Fluidbook/ToolboxAPI.php
new file mode 100644 (file)
index 0000000..0f61acb
--- /dev/null
@@ -0,0 +1,120 @@
+<?php\r
+\r
+class Fluidbook_ToolboxAPI extends Zend_Rest_Client\r
+{\r
+    protected $token;\r
+\r
+    public function __construct($uri = null, $token = null)\r
+    {\r
+        if (null === $uri) {\r
+            $uri = 'https://toolbox.fluidbook.com/';\r
+        }\r
+        if (null !== $token) {\r
+            $this->token = $token;\r
+        }\r
+        parent::__construct($uri);\r
+        self::getHttpClient()->setConfig([\r
+            'timeout' => 1800]);\r
+\r
+    }\r
+\r
+    public function clearCache($tag = null)\r
+    {\r
+        set_time_limit(300);\r
+        return $this->restPost('/api/cache/clear' . (null === $tag ? '' : '/' . $tag), ['api_token' => $this->token]);\r
+    }\r
+\r
+    public function renameTheme($theme_id, $newname)\r
+    {\r
+        return $this->restPut('/api/fluidbook-theme/' . $theme_id . '/rename', ['api_token' => $this->token, 'newname' => $newname]);\r
+    }\r
+\r
+    public function cloneTheme($theme_id)\r
+    {\r
+        return $this->restPost('/api/fluidbook-theme/' . $theme_id . '/clone', ['api_token' => $this->token]);\r
+    }\r
+\r
+    public function updateTheme($data)\r
+    {\r
+        return $this->restPut('/api/fluidbook-theme/' . $data['theme_id'], ['api_token' => $this->token, 'data' => $data]);\r
+    }\r
+\r
+    public function deleteTheme($themeId)\r
+    {\r
+        return $this->restDelete('/api/fluidbook-theme/' . $themeId, ['api_token' => $this->token]);\r
+    }\r
+\r
+    public function uploadThemeFile($themeId, $field, $path)\r
+    {\r
+        return $this->restPut('/api/fluidbook-theme/' . $themeId . '/uploadfile/' . $field, ['api_token' => $this->token, 'path' => $path]);\r
+    }\r
+\r
+    public function getPublicationMetadata($id)\r
+    {\r
+        return json_decode($this->restGet('/api/fluidbook-publication/' . $id . '/metadata', ['api_token' => $this->token])->getBody());\r
+    }\r
+\r
+    public function downloadPublication($id, $version = 'online')\r
+    {\r
+        return $this->restGet('/api/fluidbook-publication/' . $id . '/download/' . $version, ['api_token' => $this->token])->getBody();\r
+    }\r
+\r
+    public function installBookIfNeeded($id, $dir, $timestamp = 'auto', $version = 'online')\r
+    {\r
+        if ($timestamp == 'auto') {\r
+            $timestamp = max($this->getPublicationMetadata($id)->date, time() - (3600 * 48));\r
+        }\r
+\r
+        $install = false;\r
+        if (!file_exists($dir) || (!file_exists($dir . '/TIME') && !file_exists($dir . '/_TIME')) || !file_exists($dir . '/index.html')) {\r
+            $install = true;\r
+        } else if ($timestamp != 'skip') {\r
+            if (file_exists($dir . '/TIME')) {\r
+                $date = file_get_contents($dir . '/TIME');\r
+            } else {\r
+                $date = file_get_contents($dir . '/_TIME');\r
+            }\r
+            if ($date < $timestamp) {\r
+                $install = true;\r
+            }\r
+        }\r
+\r
+        if ($install) {\r
+            return $this->installBook($id, $dir, $version);\r
+        }\r
+        return false;\r
+    }\r
+\r
+    public function installBook($id, $dir, $version = 'online', $tries = 3, $beforeInstallCallback = null)\r
+    {\r
+        $url = $this->downloadPublication($id, $version);\r
+        set_time_limit(0);\r
+        // Unzip\r
+        $tmp = CubeIT_Files::tempnam() . '.zip';\r
+        copy($url, $tmp);\r
+        $tdir = $dir . '.temp';\r
+        CubeIT_Util_Zip::extract($tmp, $tdir);\r
+        unlink($tmp);\r
+        file_put_contents($tdir . '/TIME', time());\r
+\r
+        set_time_limit(0);\r
+        CubeIT_Files::rmdir($dir);\r
+\r
+        if (null !== $beforeInstallCallback && is_callable($beforeInstallCallback)) {\r
+            call_user_func($beforeInstallCallback);\r
+        }\r
+        mkdir($dir, 0777, true);\r
+        echo `mv -f $tdir/* $dir`;\r
+        if (!file_exists($dir . '/_TIME')) {\r
+            file_put_contents($dir . '/_TIME', time());\r
+        }\r
+        CubeIT_Files::rmdir($tdir);\r
+        return false;\r
+    }\r
+\r
+    public static function getResponseBody(Zend_Http_Response $response)\r
+    {\r
+        return $response->getBody();\r
+    }\r
+\r
+}
\ No newline at end of file
index 367c018755976d49a455a8485f84b4aa0877b59d..dbe95a50ef9c3d83e901f476e55f6496fadeb7c9 100644 (file)
@@ -41,7 +41,7 @@ navigation.containers.Sitemap = -4;
 
 webhost = www.fluidbook.com
 
-locales.redirect = true
+locales.redirect = false
 locales.fr = www.fluidbook.com
 locales.en = en.fluidbook.com
 
index a6d0330b9334b4abf578c229c3f3a1ad2a921fa8..c8c8bc0373781d1bdec8e9d0802d10c94e7d0afc 100644 (file)
@@ -5,6 +5,8 @@ class AjaxController extends CubeIT_Controller_AjaxController
 
     public function requestQuote($formID = null)
     {
+        @file_put_contents(FRAMEWORK_PATH . '/log/quote.' . time() . '.log', var_export($_POST, true));
+
         CubeIT_Util_PHP::neverStop();
 
         $form = new Fluidbook_Form_RequestQuote();
@@ -23,10 +25,8 @@ class AjaxController extends CubeIT_Controller_AjaxController
                 $data['gclid'] = Bootstrap::getInstance()->getSession()->gclid;
             }
 
-//            $url = 'https://workshop.fluidbook.com/ajax/demandeDevis?devis_form=' . base64_encode(json_encode($data));
-//            file_get_contents($url);
-
             $url = 'https://toolbox.fluidbook.com/fluidbook-quote/create-from-website?data=' . base64_encode(json_encode($data));
+
             $this->_datas->addDebug($url);
             $json = json_decode(file_get_contents($url));
             $this->_datas->addDebug($json);
@@ -43,12 +43,17 @@ class AjaxController extends CubeIT_Controller_AjaxController
             }
 
             $this->_datas->addGAEvent('form', 'sent', 'quote');
+
+            @file_put_contents(FRAMEWORK_PATH . '/log/quote.' . time() . '.details.log', var_export($_POST, true) . "\n\n" . json_encode($data) . "\n\n" . base64_encode(json_encode($data)));
         } else {
             $this->_datas->refreshForm($form); // Respond with validation errors
             $this->_datas->addAction('eval', "displayErrors('$formID')");
             $this->_datas->addGAEvent('form', 'error', 'quote');
         }
 
+
+
+
     }
 
 }
index 09e74ea419d0fd1c1d13f3a1a0b8e945dd2c8d16..fd0c31ad8b47cc80532a2ccde4a12132ca583b21 100644 (file)
@@ -24,7 +24,7 @@ class MaintenanceController extends CubeIT_Controller_MaintenanceController
     /**
      * @return CubeIT_Services_Fluidbook
      */
-    protected static function getFluidbookAPI()
+    protected static function getWorkshopAPI()
     {
         $res = new CubeIT_Services_Fluidbook();
         $res->login('api@fluidbook.com', '#fTJAx!Ea5kanhX');
@@ -36,7 +36,8 @@ class MaintenanceController extends CubeIT_Controller_MaintenanceController
         set_time_limit(0);
         ignore_user_abort(true);
 
-        $ws = self::getFluidbookAPI();
+        $ws = self::getWorkshopAPI();
+
         $references = Fluidbook_Model_Reference::factory()->find();
 
         if (isset($_GET['id'])) {
@@ -62,37 +63,59 @@ class MaintenanceController extends CubeIT_Controller_MaintenanceController
                 break;
             }
             try {
-                $meta = $ws->getMetadata($fluidbook);
-                $dir = PUBLIC_PATH . '/references/' . $fluidbook . '-' . CubeIT_Text::str2URL(trim($meta->title));
-
-                try {
-                    $res = $ws->installBookIfNeeded($fluidbook, $dir, isset($_GET['force']) ? time() : 'auto');
-                    if ($res) {
-                        $n++;
-                    }
-                } catch (exception $e) {
-                    echo 'Error installing book '.$fluidbook . '<br />';
-                    exit;
+                $res = self::importReference($id, true);
+                if ($res) {
+                    $n++;
                 }
             } catch (exception $e) {
-                echo 'Error getting metadata for book '.$fluidbook . '<br />';
+                echo 'Error installing book ' . $fluidbook . '<br />';
                 exit;
             }
         }
     }
 
 
-    public static function importReference($id)
+    public static function importReference($id, $onlyIfNeeded = false)
     {
-        $ws = self::getFluidbookAPI();
+        if ($id < 30000) {
+            return self::importWSReference($id, $onlyIfNeeded);
+        }
+        return self::importToolboxReference($id, $onlyIfNeeded);
+    }
+
+    public static function importToolboxReference($id, $onlyIfNeeded = false)
+    {
+        $api = self::getToolboxAPI();
+        $meta = $api->getPublicationMetadata($id);
+        return self::_install($api, $id, $meta, $onlyIfNeeded);
+    }
+
+    /**
+     * @return Fluidbook_ToolboxAPI
+     */
+    public static function getToolboxAPI()
+    {
+        return new Fluidbook_ToolboxAPI('https://toolbox.fluidbook.com/', 'Dxsm2nqsvbV4ubH8KUEMRpbfsRrsDZagJkCZV2Nvuy83oPqsSEKC6ircWdC2');
+    }
+
+    public static function importWSReference($id, $onlyIfNeeded = false)
+    {
+        $ws = self::getWorkshopAPI();
         $meta = $ws->getMetadata($id);
+
+        return self::_install($ws, $id, $meta, $onlyIfNeeded);
+    }
+
+    protected static function _install($api, $id, $meta, $onlyIfNeeded)
+    {
         $dir = PUBLIC_PATH . '/references/' . $id . '-' . CubeIT_Text::str2URL(trim($meta->title));
-        $res = $ws->installBook($id, $dir, 'online', 3, function () use ($id) {
+        if ($onlyIfNeeded) {
+            return $api->installBookIfNeeded($id, $dir, isset($_GET['force']) ? time() : 'auto');
+        }
+        return $api->installBook($id, $dir, 'online', 3, function () use ($id) {
             $delete = PUBLIC_PATH . '/references/' . $id . '-*';
             $deleteCmd = "rm -rf $delete !(*.temp)";
             `$deleteCmd`;
         });
-
-        echo $id . ' : ' . $dir . ' // ' . print_r($res, true);
     }
 }