From 8a9a9133bf64469841c80323c1570c7bc873c556 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Fri, 14 May 2021 19:03:45 +0000 Subject: [PATCH] wip #4464 @2 --- inc/ws/Controlleur/class.ws.flash.php | 1 + inc/ws/Controlleur/class.ws.url.php | 6 +- inc/ws/DAO/class.ws.dao.theme.php | 319 ++++++++++-------- inc/ws/Metier/class.ws.book.php | 2 +- inc/ws/Metier/class.ws.theme.php | 4 +- inc/ws/Util/class.ws.ws3api.php | 12 +- .../html5/master/class.ws.html5.links.php | 3 + 7 files changed, 192 insertions(+), 155 deletions(-) diff --git a/inc/ws/Controlleur/class.ws.flash.php b/inc/ws/Controlleur/class.ws.flash.php index 36b32541b..48a1fe7ce 100644 --- a/inc/ws/Controlleur/class.ws.flash.php +++ b/inc/ws/Controlleur/class.ws.flash.php @@ -490,6 +490,7 @@ class wsFlash extends cubeFlashGateway { global $core; $dao = new wsDAOTheme($core->con); + $theme = $dao->duplicate($this->args['theme_id'], $core->user->utilisateur_id); $this->xml->addChild('theme_id', $theme->theme_id); if (isset($this->args['book_id'])) { diff --git a/inc/ws/Controlleur/class.ws.url.php b/inc/ws/Controlleur/class.ws.url.php index c6c2199bc..390570219 100644 --- a/inc/ws/Controlleur/class.ws.url.php +++ b/inc/ws/Controlleur/class.ws.url.php @@ -1217,7 +1217,11 @@ html,body{height:100%;cursor: wait;font-family: "Open Sans", Arial;background-co } self::logReferer($book_id); - $html = file_get_contents(WS_BOOKS . '/html5' . $dir . '/' . $book_id . '/index' . $version . '.html'); + $htmlFile = WS_BOOKS . '/html5' . $dir . '/' . $book_id . '/index' . $version . '.html'; + $html = ''; + if (file_exists($htmlFile)) { + $html = file_get_contents($htmlFile); + } foreach ($replace as $from => $to) { $html = str_replace($from, $to, $html); } diff --git a/inc/ws/DAO/class.ws.dao.theme.php b/inc/ws/DAO/class.ws.dao.theme.php index 4769e5ce6..c54492abf 100644 --- a/inc/ws/DAO/class.ws.dao.theme.php +++ b/inc/ws/DAO/class.ws.dao.theme.php @@ -1,149 +1,174 @@ theme_id = $r->theme_id; - $theme->nom = $r->nom; - $theme->date = $r->date; - $theme->proprietaire = $r->proprietaire; - if ($r->exists('nbBooks')) { - $theme->nbBooks = $r->nbBooks; - } - if ($r->exists('proprietaire_nom')) { - $theme->proprietaire_nom = $r->proprietaire_nom; - } - $theme->signature = $r->signature; - $theme->icones = $r->icones; - $p = unserialize($r->parametres); - if (!$p) { - $p = new wsThemeParametres($theme); - } else { - $p->setParent($theme); - } - $theme->parametres = $p; - - return $theme; - } - - public function selectById($theme_id, $table = 'themes_vue') { - $r = $this->con->select('SELECT * FROM ' . $table . ' WHERE theme_id=\'' . $this->con->escape($theme_id) . '\' LIMIT 1'); - return $this->singleton($r); - } - - public function getThemeOfBook($book_id, $basic = false) { - if ($basic) { - $table = 'themes'; - } else { - $table = 'themes_vue'; - } - $r = $this->con->select('SELECT * FROM ' . $table . ' WHERE theme_id IN (SELECT theme FROM books WHERE book_id=\'' . $this->con->escape($book_id) . '\') LIMIT 1'); - return $this->singleton($r); - } - - public function getAllThemes($user, $order = '', $demos = null) { - if (wsDroits::admin(false)) { - $sql = 'SELECT * FROM themes_vue'; - } else { - $or = ''; - if (wsDroits::revendeur() && !is_null($demos)) { - $or = ' OR theme_id IN(' . implode(',', $demos) . ')'; - } - $sql = 'SELECT * FROM themes_vue WHERE theme_id IN (SELECT theme FROM books WHERE proprietaire IN(' . $user->ws_rights . ') ' . $or . ')'; - } - $r = $this->con->select($sql . ' ' . $order); - return $this->factory($r); - } - - public function sauve($data) { - $parent = $this->selectById($data['theme_id']); - $c = $this->con->openCursor('themes'); - $c->date = TIME; - $p = new wsThemeParametres($parent); - foreach ($data as $k => $v) { - if (!isset($p->$k)) { - continue; - } - $p->$k = $v; - } - $c->parametres = serialize($p); - $c->update('WHERE theme_id=\'' . $this->con->escape($data['theme_id']) . '\''); - if (file_exists(WS_THEMES . '/' . $data['theme_id'] . '.jpg')) { - unlink(WS_THEMES . '/' . $data['theme_id'] . '.jpg'); - } - } - - protected function getNextId() { - $r = $this->con->select('SELECT MAX(theme_id) AS theme_id FROM themes'); - if ($r->theme_id < 1000) { - return 1000; - } - return $r->theme_id + 1; - } - - public function delete($theme_id, $onlyFiles = false) { - if (is_null($theme_id) || $theme_id == '') { - return; - } - if (!$onlyFiles) { - $this->con->execute('DELETE FROM themes WHERE theme_id=\'' . $this->con->escape($theme_id) . '\''); - } - $fref = WS_THEMES . '/' . $theme_id; - if (file_exists($fref)) { - files::deltree($fref); - } - if (file_exists($fref . '.jpg')) { - unlink($fref . '.jpg'); - } - } - - public function rename($theme_id, $newname) { - $c = $this->con->openCursor('themes'); - $c->nom = $newname; - $c->update('WHERE theme_id=\'' . $this->con->escape($theme_id) . '\''); - } - - public function duplicate($theme_id, $proprietaire) { - if (is_null($theme_id) || $theme_id == '') { - return; - } - $theme = $this->selectById($theme_id); - // Copie des données - $c = $this->con->openCursor('themes'); - $c->theme_id = $this->getNextId(); - $c->nom = $theme->nom . ' (copy)'; - $c->parametres = serialize($theme->parametres); - $c->signature = $theme->signature; - $c->icones = $theme->icones; - $c->proprietaire = $proprietaire; - $c->date = TIME; - $c->insert(); - - $this->delete($c->theme_id, true); - // Copie des fichiers - $from = WS_THEMES . '/' . $theme_id; - $to = WS_THEMES . '/' . $c->theme_id; - $dr = opendir($from); - if (!file_exists($to)) { - mkdir($to, 0777, true); - } else { - files::deltree($to); - mkdir($to, 0777, true); - } //. - while ($file = readdir($dr)) { - if ($file == '.' || $file == '..') { - continue; - } - copy($from . '/' . $file, $to . '/' . $file); - } - if (file_exists($from . '.jpg')) { - copy($from . '.jpg', $to . '.jpg'); - } - - return $this->selectById($c->theme_id); - } - -} - -?> \ No newline at end of file +class wsDAOTheme extends commonDAO +{ + + protected function singleton($r) + { + $theme = new wsTheme(); + $theme->theme_id = $r->theme_id; + $theme->nom = $r->nom; + $theme->date = $r->date; + $theme->proprietaire = $r->proprietaire; + if ($r->exists('nbBooks')) { + $theme->nbBooks = $r->nbBooks; + } + if ($r->exists('proprietaire_nom')) { + $theme->proprietaire_nom = $r->proprietaire_nom; + } + $theme->signature = $r->signature; + $theme->icones = $r->icones; + $p = unserialize($r->parametres); + if (!$p) { + $p = new wsThemeParametres($theme); + } else { + $p->setParent($theme); + } + $theme->parametres = $p; + + return $theme; + } + + public function selectById($theme_id, $table = 'themes_vue') + { + $r = $this->con->select('SELECT * FROM ' . $table . ' WHERE theme_id=\'' . $this->con->escape($theme_id) . '\' LIMIT 1'); + return $this->singleton($r); + } + + public function getThemeOfBook($book_id, $basic = false) + { + if ($basic) { + $table = 'themes'; + } else { + $table = 'themes_vue'; + } + $r = $this->con->select('SELECT * FROM ' . $table . ' WHERE theme_id IN (SELECT theme FROM books WHERE book_id=\'' . $this->con->escape($book_id) . '\') LIMIT 1'); + return $this->singleton($r); + } + + public function getAllThemes($user, $order = '', $demos = null) + { + if (wsDroits::admin(false)) { + $sql = 'SELECT * FROM themes_vue'; + } else { + $or = ''; + if (wsDroits::revendeur() && !is_null($demos)) { + $or = ' OR theme_id IN(' . implode(',', $demos) . ')'; + } + $sql = 'SELECT * FROM themes_vue WHERE theme_id IN (SELECT theme FROM books WHERE proprietaire IN(' . $user->ws_rights . ') ' . $or . ')'; + } + $r = $this->con->select($sql . ' ' . $order); + return $this->factory($r); + } + + public function sauve($data) + { + $parent = $this->selectById($data['theme_id']); + $c = $this->con->openCursor('themes'); + $c->date = TIME; + $p = new wsThemeParametres($parent); + foreach ($data as $k => $v) { + if (!isset($p->$k)) { + continue; + } + $p->$k = $v; + } + $c->parametres = serialize($p); + $c->update('WHERE theme_id=\'' . $this->con->escape($data['theme_id']) . '\''); + if (file_exists(WS_THEMES . '/' . $data['theme_id'] . '.jpg')) { + unlink(WS_THEMES . '/' . $data['theme_id'] . '.jpg'); + } + } + + protected function getNextId() + { + $r = $this->con->select('SELECT MAX(theme_id) AS theme_id FROM themes'); + if ($r->theme_id < 1000) { + return 1000; + } + return $r->theme_id + 1; + } + + public function delete($theme_id, $onlyFiles = false) + { + if (is_null($theme_id) || $theme_id == '') { + return; + } + if (!$onlyFiles) { + $this->con->execute('DELETE FROM themes WHERE theme_id=\'' . $this->con->escape($theme_id) . '\''); + $api = new ws3API(); + $api->deleteTheme($theme_id); + } + $fref = WS_THEMES . '/' . $theme_id; + if (file_exists($fref)) { + files::deltree($fref); + } + if (file_exists($fref . '.jpg')) { + unlink($fref . '.jpg'); + } + } + + public function rename($theme_id, $newname) + { + $c = $this->con->openCursor('themes'); + $c->nom = $newname; + $c->update('WHERE theme_id=\'' . $this->con->escape($theme_id) . '\''); + + $theme = $this->selectById($theme_id); + $theme->nom = $newname; + $api = new ws3API(); + $api->updateTheme($theme); + } + + public function duplicate($theme_id, $proprietaire) + { + if (is_null($theme_id) || $theme_id == '') { + return; + } + $theme = $this->selectById($theme_id); + // Copie des données + $c = $this->con->openCursor('themes'); + $c->theme_id = $this->getNextId(); + $c->nom = $theme->nom . ' (copy)'; + $c->parametres = serialize($theme->parametres); + $c->signature = $theme->signature; + $c->icones = $theme->icones; + $c->proprietaire = $proprietaire; + $c->date = TIME; + $c->insert(); + + $this->delete($c->theme_id, true); + // Copie des fichiers + $from = WS_THEMES . '/' . $theme_id; + $to = WS_THEMES . '/' . $c->theme_id; + $dr = opendir($from); + if (!file_exists($to)) { + mkdir($to, 0777, true); + } else { + files::deltree($to); + mkdir($to, 0777, true); + } //. + while ($file = readdir($dr)) { + if ($file == '.' || $file == '..') { + continue; + } + copy($from . '/' . $file, $to . '/' . $file); + } + if (file_exists($from . '.jpg')) { + copy($from . '.jpg', $to . '.jpg'); + } + + + $theme=$this->selectById($c->theme_id); + try { + $api = new ws3API(); + $api->createTheme($theme); + }catch (Exception $e){ + print_r($e); + exit; + } + + return $theme; + } + +} \ No newline at end of file diff --git a/inc/ws/Metier/class.ws.book.php b/inc/ws/Metier/class.ws.book.php index 5049d22ee..68e9bf4f5 100644 --- a/inc/ws/Metier/class.ws.book.php +++ b/inc/ws/Metier/class.ws.book.php @@ -112,7 +112,7 @@ class wsBook extends cubeMetier public function getAssetDirId() { - return !$this->parametres->assetsDir ? $this->book_id : trim($this->parametres->assetsDir); + return !isset($this->parametres->assetsDir) || !$this->parametres->assetsDir ? $this->book_id : trim($this->parametres->assetsDir); } public static function getAssetDirOfBook($book_id, $sub = '') diff --git a/inc/ws/Metier/class.ws.theme.php b/inc/ws/Metier/class.ws.theme.php index b926cb916..93953e307 100644 --- a/inc/ws/Metier/class.ws.theme.php +++ b/inc/ws/Metier/class.ws.theme.php @@ -24,6 +24,4 @@ class wsTheme extends cubeMetier { protected $parametres; protected $proprietaire_nom; protected $nbBooks = 0; -} - -?> \ No newline at end of file +} \ No newline at end of file diff --git a/inc/ws/Util/class.ws.ws3api.php b/inc/ws/Util/class.ws.ws3api.php index 2ddaedd9f..b5033a10e 100644 --- a/inc/ws/Util/class.ws.ws3api.php +++ b/inc/ws/Util/class.ws.ws3api.php @@ -6,7 +6,7 @@ class ws3API extends Zend_Rest_Client public function __construct($uri = null) { if (null === $uri) { - $uri = 'https://toolbox.fluidbook.com/api/'; + $uri = 'https://toolbox.fluidbook.com/'; } parent::__construct($uri); @@ -19,13 +19,19 @@ class ws3API extends Zend_Rest_Client public function createTheme($theme) { global $core; - $this->restPost('fluidbook-theme', ['api_token' => $core->user->api_token, 'theme' => $this->_themeData($theme)]); + return $this->restPost('/api/fluidbook-theme', ['api_token' => $core->user->api_token, 'theme' => $this->_themeData($theme)]); } public function updateTheme($theme) { global $core; - $this->restPut('fluidbook-theme/' . $theme->theme_id, ['api_token' => $core->user->api_token, 'theme' => $this->_themeData($theme)]); + return $this->restPut('/api/fluidbook-theme/' . $theme->theme_id, ['api_token' => $core->user->api_token, 'theme' => $this->_themeData($theme)]); + } + + public function deleteTheme($themeId) + { + global $core; + return $this->restDelete('/api/fluidbook-theme/' . $themeId, ['api_token' => $core->user->api_token]); } /** diff --git a/inc/ws/Util/html5/master/class.ws.html5.links.php b/inc/ws/Util/html5/master/class.ws.html5.links.php index 3304ff036..2094144e9 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.links.php +++ b/inc/ws/Util/html5/master/class.ws.html5.links.php @@ -44,6 +44,9 @@ class wsHTML5Link public $borderColor = '#ffffff'; public $maxWidth = 0; public $wdir; + public $gamifyCoins = 0; + public $tooltipColor = null; + public $tooltipBackgroundColor = null; protected $role = 'button'; protected $_init; -- 2.39.5