--- /dev/null
+<?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
webhost = www.fluidbook.com
-locales.redirect = true
+locales.redirect = false
locales.fr = www.fluidbook.com
locales.en = en.fluidbook.com
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();
$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);
}
$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');
}
+
+
+
}
}
/**
* @return CubeIT_Services_Fluidbook
*/
- protected static function getFluidbookAPI()
+ protected static function getWorkshopAPI()
{
$res = new CubeIT_Services_Fluidbook();
$res->login('api@fluidbook.com', '#fTJAx!Ea5kanhX');
set_time_limit(0);
ignore_user_abort(true);
- $ws = self::getFluidbookAPI();
+ $ws = self::getWorkshopAPI();
+
$references = Fluidbook_Model_Reference::factory()->find();
if (isset($_GET['id'])) {
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);
}
}