From 10c474f85e2254967d1d6a8ebb7c3bdfa0fe63dd Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Mon, 23 Jun 2014 09:21:18 +0000 Subject: [PATCH] --- .htaccess | 8 +- inc/commons/class.common.core.php | 8 +- inc/ws/Controlleur/class.ws.ajax.php | 39 ++---- inc/ws/Controlleur/class.ws.services.php | 118 ++++++++++-------- inc/ws/Controlleur/class.ws.url.php | 36 ++++-- .../html5/app/class.ws.html5.app.compiler.php | 2 +- 6 files changed, 112 insertions(+), 99 deletions(-) diff --git a/.htaccess b/.htaccess index 1d2e185b1..a0e56504a 100644 --- a/.htaccess +++ b/.htaccess @@ -42,10 +42,16 @@ AddCharset UTF-8 log RewriteCond %{HTTP_HOST} fluidbook RewriteRule ^favicon.ico$ images/ws/favicon.ico [L] + # Ignore static files or directories + RewriteCond %{REQUEST_FILENAME} -s [OR] + RewriteCond %{REQUEST_FILENAME} -l [OR] + RewriteCond %{REQUEST_FILENAME} -d + RewriteRule ^.*$ - [NC,L] + RewriteRule ^ajax/supprimeFichier/([0-9]+)/(.*)$ index.php/ajax/supprimeFichier/$1/$2 [L] RewriteRule ^telecharger/([0-9a-fA-F]+)/([0-9]+)/(.*)$ index.php/telecharger/$1/$2/$3 [L] RewriteRule ^telechargerr/([0-9a-fA-F]+)/([0-9]+)/(.*)$ index.php/telechargerr/$1/$2/$3 [L] - RewriteRule ^([-,_a-zA-Z0-9/]+)$ index.php/$1 [L] + RewriteRule ^([-,_a-zA-Z0-9\./]+)$ index.php/$1 [L] RewriteRule ^viewer/([0-9]+)_([0-9a-fA-F]+)_([0-9]+)/index.html$ viewer/$1_$2_$3/index [L] RewriteRule ^viewer/([0-9]+)_([0-9a-fA-F]+)_([0-9]+)/index.swf$ fluidbook/compile/index.swf [L] diff --git a/inc/commons/class.common.core.php b/inc/commons/class.common.core.php index 96f2d3713..853b3593d 100644 --- a/inc/commons/class.common.core.php +++ b/inc/commons/class.common.core.php @@ -17,7 +17,7 @@ class commonCore extends cubeCore { try { $this->authentifie(); } catch (Exception $e) { - + } if ($this->user) { @@ -444,8 +444,8 @@ class commonCore extends cubeCore { // Table des compilations de collection $db->book_collection_compile->collection_id('integer', 0, false); $db->book_collection_compile->compile_date('integer', 0, false); - $db->book_collection_compile->online_ios('integer', 0, false); - $db->book_collection_compile->online_android('integer', 0, false); + $db->book_collection_compile->online_ios('varchar', 10, false); + $db->book_collection_compile->online_android('varchar', 10, false); $db->book_collection_compile->primary('book_collection_compile', 'collection_id', 'compile_date'); // Table des notification push @@ -466,7 +466,7 @@ class commonCore extends cubeCore { $db->ws_users_tree->facturable_id('integer', 0, false); $db->ws_users_tree->facturable_entreprise_id('integer', 0, false); $db->ws_users_tree->administrateur_id('integer', 0, false); - // Clé + // Clé $db->ws_users_tree->primary('pk_utilisateur_id', 'utilisateur_id'); // Table des entreprises $db->ws_entreprises_tree->entreprise_id('integer', 0, false); diff --git a/inc/ws/Controlleur/class.ws.ajax.php b/inc/ws/Controlleur/class.ws.ajax.php index cd9adc109..1064da257 100644 --- a/inc/ws/Controlleur/class.ws.ajax.php +++ b/inc/ws/Controlleur/class.ws.ajax.php @@ -1086,14 +1086,10 @@ class wsAjax extends cubeAjax { $c = $core->con->openCursor('book_collection_compile'); $c->collection_id = $id; $c->compile_date = $time; - $c->online_ios = 0; - $c->online_android = 0; + $c->online_ios = ''; + $c->online_android = ''; $c->insert(); - if ($_GET['ctrl']) { - self::collectionVersionPublish(array('', $id, $time, 'ios'), $x); - } - $x->addReload(); } @@ -1101,18 +1097,14 @@ class wsAjax extends cubeAjax { global $core; $id = $args[1]; - $date = $args[2]; - $os = $args[3]; - - $online = 'online_' . $os; - - $c = $core->con->openCursor('book_collection_compile'); - $c->$online = 0; - $c->update('WHERE collection_id=\'' . $core->con->escape($id) . '\' AND ' . $online . '=1'); - $c = $core->con->openCursor('book_collection_compile'); - $c->$online = 1; - $c->update('WHERE collection_id=\'' . $core->con->escape($id) . '\' AND compile_date=\'' . $core->con->escape($date) . '\''); + foreach ($_POST['version'] as $version => $oss) { + $c = $core->con->openCursor('book_collection_compile'); + foreach ($oss as $os => $appver) { + $c->{'online_' . $os} = $appver; + } + $c->update('WHERE collection_id=\'' . $core->con->escape($id) . '\' AND compile_date=\'' . $core->con->escape($version) . '\''); + } self::cleanCachesCollection($id, $os); @@ -1120,17 +1112,8 @@ class wsAjax extends cubeAjax { } protected static function cleanCachesCollection($id, $os) { - $files = array('json', 'update'); - $resolutions = array(150, 300); - - foreach ($files as $f) { - foreach ($resolutions as $r) { - $ff = WS_COLLECTIONS . '/ws/' . $id . '.' . $os . '.' . $r . '.' . $f; - if (file_exists($ff)) { - unlink($ff); - } - } - } + $ff = WS_COLLECTIONS . '/ws/' . $id . '.' . $os . '.*'; + `rm $ff`; } public static function collectionVersionDelete($args, &$x) { diff --git a/inc/ws/Controlleur/class.ws.services.php b/inc/ws/Controlleur/class.ws.services.php index bace75d74..6720491a0 100644 --- a/inc/ws/Controlleur/class.ws.services.php +++ b/inc/ws/Controlleur/class.ws.services.php @@ -662,7 +662,8 @@ class wsServices extends cubeFlashGateway { $id = $this->callArgs[0]; $os = $this->callArgs[1]; $resolution = $this->callArgs[2]; - $local = (isset($this->callArgs[3])) ? $this->callArgs[3] : null; + $local = (isset($this->callArgs[3]) && $this->callArgs[3] != '0') ? $this->callArgs[3] : null; + $appver = (isset($this->callArgs[4]) && $this->callArgs[4]) ? $this->callArgs[4] : '1.0'; if (is_null($resolution)) { $resolution = 150; @@ -675,8 +676,10 @@ class wsServices extends cubeFlashGateway { $this->outputXML = false; header('Content-type: application/json'); - $cache = WS_COLLECTIONS . '/ws/' . $id . '.' . $os . '.' . $resolution . '.json'; - $update = WS_COLLECTIONS . '/ws/' . $id . '.' . $os . '.' . $resolution . '.update'; + $appverf = str_replace('.', '_', $appver); + + $cache = WS_COLLECTIONS . '/ws/' . $id . '.' . $os . '.' . $resolution . '.' . $appverf . '.json'; + $update = WS_COLLECTIONS . '/ws/' . $id . '.' . $os . '.' . $resolution . '.' . $appverf . '.update'; if (file_exists($update) && filemtime(__FILE__) > filemtime($update)) { unlink($update); @@ -689,75 +692,81 @@ class wsServices extends cubeFlashGateway { $limit = TIME - 72000; if (!file_exists($cache) || !file_exists($update) || filemtime($cache) < $limit) { - $r = $core->con->select('SELECT * FROM book_collection_compile WHERE online_' . $os . '=1 AND collection_id=\'' . $core->con->escape($id) . '\''); - $r->fetch(); - $version = $r->compile_date; + $r = $core->con->select('SELECT *,online_' . $os . ' AS v FROM book_collection_compile WHERE online_' . $os . '!=\'\' AND collection_id=\'' . $core->con->escape($id) . '\' ORDER BY compile_date DESC'); + while ($r->fetch()) { + if (version_compare($r->v, $appver, '>')) { + continue; + } - $daoCollection = new wsDAOCollection($core->con); - $collection = $daoCollection->selectById($id); + $version = $r->compile_date; - $ns = $collection->settings['namespace']; + $daoCollection = new wsDAOCollection($core->con); + $collection = $daoCollection->selectById($id); + $ns = $collection->settings['namespace']; - $vcompo = WS_COLLECTIONS . '/versions/' . $id . '/' . $version . '/composition.json'; - $composition = json_decode(file_get_contents($vcompo)); + $vcompo = WS_COLLECTIONS . '/versions/' . $id . '/' . $version . '/composition.json'; + $composition = json_decode(file_get_contents($vcompo)); - $couvertures = array(); - $vroot = WS_COLLECTIONS . '/versions/' . $id . '/' . $version . '/' . $os . '/'; + $couvertures = array(); + $vroot = WS_COLLECTIONS . '/versions/' . $id . '/' . $version . '/' . $os . '/'; - $publications = array(); - $langs = array(); + $publications = array(); + $langs = array(); - foreach ($composition as $k => $g) { - foreach ($g->publications as $l => $p) { - $publications[] = $p->id; + foreach ($composition as $k => $g) { + foreach ($g->publications as $l => $p) { + $publications[] = $p->id; + } } - } - $daoBook = new wsDAOBook($core->con); - $books = $daoBook->selectByIds($publications); - - $langsnames = array(); - foreach ($composition as $k => $g) { - foreach ($g->publications as $l => $p) { - $book = $books[$p->id]; - $root = WS_COLLECTIONS . '/versions/' . $id . '/' . $version . '/' . $os . '/' . $p->id; - $couv = $root . '/cover.jpg'; - $couvertures[$p->id] = base64_encode(file_get_contents($couv)); - $composition[$k]->publications[$l]->width = $book->parametres->width; - $composition[$k]->publications[$l]->height = $book->parametres->height; - $composition[$k]->publications[$l]->lang = $book->lang; - $langs[] = $book->lang; + $daoBook = new wsDAOBook($core->con); + $books = $daoBook->selectByIds($publications); + + $langsnames = array(); + foreach ($composition as $k => $g) { + foreach ($g->publications as $l => $p) { + $book = $books[$p->id]; + $root = WS_COLLECTIONS . '/versions/' . $id . '/' . $version . '/' . $os . '/' . $p->id; + $couv = $root . '/cover.jpg'; + $couvertures[$p->id] = base64_encode(file_get_contents($couv)); + $composition[$k]->publications[$l]->width = $book->parametres->width; + $composition[$k]->publications[$l]->height = $book->parametres->height; + $composition[$k]->publications[$l]->lang = $book->lang; + $langs[] = $book->lang; + } } - } - $langs = array_unique($langs); + $langs = array_unique($langs); - $w2h = new wiki2xhtml(); - $w2h->setOpt('active_pre', 0); + $w2h = new wiki2xhtml(); + $w2h->setOpt('active_pre', 0); - $contents = $collection->contents; - foreach ($langs as $lang) { - $langsnames[$lang] = cubeLang::getNameByCode($lang); - $contents[$lang]['apropos'] = $w2h->transform($contents[$lang]['apropos']); - } + $contents = $collection->contents; + foreach ($langs as $lang) { + $langsnames[$lang] = cubeLang::getNameByCode($lang); + $contents[$lang]['apropos'] = $w2h->transform($contents[$lang]['apropos']); + } - $traductions = array(); - $r = $core->con->select('SELECT traductions,lang_id FROM langues WHERE lang_id IN(\'' . implode('\',\'', $langs) . '\')'); - while ($r->fetch()) { - $traductions[$r->lang_id] = json_decode($r->traductions); - } + $traductions = array(); + $r = $core->con->select('SELECT traductions,lang_id FROM langues WHERE lang_id IN(\'' . implode('\',\'', $langs) . '\')'); + while ($r->fetch()) { + $traductions[$r->lang_id] = json_decode($r->traductions); + } + + $d = array('id' => $id, 'res' => $resolution, 'ns' => $ns, 'langs' => $langs, 'langnames' => $langsnames, 'time' => $version, 'datas' => $composition, 'couvertures' => $couvertures, 'traductions' => $traductions, 'contents' => $contents); + $d = array_merge($d, $this->_getManifest($publications, '/fluidbook/collections/versions/' . $id . '/' . $version . '/' . $os, $books, $resolution)); - $d = array('id' => $id, 'res' => $resolution, 'ns' => $ns, 'langs' => $langs, 'langnames' => $langsnames, 'time' => $version, 'datas' => $composition, 'couvertures' => $couvertures, 'traductions' => $traductions, 'contents' => $contents); - $d = array_merge($d, $this->_getManifest($publications, '/fluidbook/collections/versions/' . $id . '/' . $version . '/' . $os, $books, $resolution)); + $dao = new wsDAOCollection($core->con); + $col = $dao->selectById($id); - $dao = new wsDAOCollection($core->con); - $col = $dao->selectById($id); + $json = json_encode($d); + file_put_contents($cache, $json); + file_put_contents($update, $version); - $json = json_encode($d); - file_put_contents($cache, $json); - file_put_contents($update, $version); + break; + } } else { $d = json_decode(file_get_contents($cache), true); } @@ -770,6 +779,7 @@ class wsServices extends cubeFlashGateway { } } + $d['forceUpdate'] = $force; echo json_encode($d); exit; diff --git a/inc/ws/Controlleur/class.ws.url.php b/inc/ws/Controlleur/class.ws.url.php index 4e9a9c873..f599bfcad 100644 --- a/inc/ws/Controlleur/class.ws.url.php +++ b/inc/ws/Controlleur/class.ws.url.php @@ -313,6 +313,8 @@ class wsUrl { $res.='' . __('Identifiant de l\'application') . '' . form::field(array('settings[namespace]', 'namespace'), 64, 64, $collection->settings['namespace']) . ''; $res.='' . __('Certificat APNS') . ' Dev (' . __('Fichier .pem') . ')'; $res.='' . __('Certificat APNS') . ' Prod (' . __('Fichier .pem') . ')'; + $res.='' . __('Versions iOS') . '' . form::field(array('settings[v_ios]', 'namespace'), 64, 64, $collection->settings['v_ios']) . ''; + $res.='' . __('Versions Android') . '' . form::field(array('settings[v_android]', 'namespace'), 64, 64, $collection->settings['v_android']) . ''; $res.=''; $res.='

' . __('Applications offline') . '

'; @@ -338,8 +340,14 @@ class wsUrl { $res.=''; $res.='

'; $res.='

' . __('Versions') . '

'; + $res.='
'; $res.='' . $core->typo->Ajouter(__('Créer une version')) . '

'; $r = $core->con->select('SELECT * FROM book_collection_compile WHERE collection_id=\'' . $collection->collection_id . '\' ORDER BY compile_date DESC'); + + $v_ios = self::getSelectVersions($collection->settings['v_ios']); + $v_android = self::getSelectVersions($collection->settings['v_android']); + + if (!$r->count()) { $res.=__('Aucune version de la collection n\'a été crée'); } else { @@ -353,22 +361,16 @@ class wsUrl { $del = '
' . __('Effacer') . '
'; } - if ($r->online_ios) { - $pub_ios = __('Publiée'); - } else { - $pub_ios = '
' . __('Publier') . '
'; - } + $pub_ios = form::combo('version[' . $r->compile_date . '][ios]', $v_ios, $r->online_ios); + $pub_android = form::combo('version[' . $r->compile_date . '][android]', $v_android, $r->online_android); - if ($r->online_android) { - $pub_android = __('Publiée'); - } else { - $pub_android = '
' . __('Publier') . '
'; - } $res.='' . date('Y-m-d H:i:s', $r->compile_date) . '' . $pub_ios . '' . $pub_android . '' . $del . ''; } $res.=''; } - + $res.='' . $core->typo->Ajouter(__('Enregistrer')) . ''; + $res.='
'; + $res.='

'; $res.='

' . __('Notifications') . '

'; $res.='

' . __('Indiquez le texte de la notification à envoyer aux utilisateurs') . ' (' . __('Max 200 caractères') . ').
' . __('Laissez vide si vous souhaitez simplement afficher un badge') . '

'; $res.='
'; @@ -386,6 +388,18 @@ class wsUrl { return $res; } + public static function getSelectVersions($versions) { + fb($versions); + $res = array('-----' => ''); + $e = explode(',', $versions); + + foreach ($e as $ee) { + $ee = trim($ee); + $res[$ee] = $ee; + } + return $res; + } + public static function listeCollections($dashboard = null, $settings = null) { global $core; diff --git a/inc/ws/Util/html5/app/class.ws.html5.app.compiler.php b/inc/ws/Util/html5/app/class.ws.html5.app.compiler.php index 8720cab6c..5082c6eb9 100644 --- a/inc/ws/Util/html5/app/class.ws.html5.app.compiler.php +++ b/inc/ws/Util/html5/app/class.ws.html5.app.compiler.php @@ -152,7 +152,7 @@ class wsHTML5AppCompiler { unset($c->manifestPub); $config['collection'] = $c; } - + $config['appver'] = $this->collection->settings['version']; file_put_contents($this->vdir . '/data/app.js', 'DATAS = ' . CubeIT_Util_Json::encode($config) . ';'); } -- 2.39.5