class wsFlash extends cubeFlashGateway
{
- const CNAME = __CLASS__;
-
- public static function in($args)
- {
- global $core;
- $args = cubePage::getArgs($args);
- $n = self::CNAME;
- $gateway = new $n($core->con, $args);
-
- $droits = wsDroits::getDroits();
- $gateway->addAttribute('creation', $droits->creation ? '1' : '0');
- $gateway->addAttribute('revendeur', $droits->revendeur ? '1' : '0');
- $gateway->addAttribute('admin', $droits->admin ? '1' : '0');
- if (null !== $core->user) {
- $grade = -1;
- } else {
- $grade = $core->user->ws_grade;
- }
- $gateway->addAttribute('grade', $grade);
- }
-
- public function saveConversionSettings()
- {
- global $core;
- $dao = new commonDAOUtilisateur($core->con);
- $datas = array('resolution' => $this->args['resolution'],
- 'objects' => $this->args['objects'],
- 'method' => $this->args['method'],
- 'quality' => $this->args['quality'],
- 'version' => $this->args['version']);
- $dao->sauveWSSettings($core->user->utilisateur_id, $datas);
- }
-
- public function getConversionSettings()
- {
- global $core;
- $this->xml->addChild('resolution', $core->user->ws_settings['resolution']);
- $this->xml->addChild('quality', $core->user->ws_settings['quality']);
- $this->xml->addChild('method', $core->user->ws_settings['method']);
- $this->xml->addChild('objects', $core->user->ws_settings['objects']);
- $this->xml->addChild('version', $core->user->ws_settings['version']);
- }
-
- public function uploadDocument()
- {
- cubePHP::neverStop();
- global $core;
- if (!isset($_SESSION['conversionSession'])) {
- $_SESSION['conversionSession'] = array();
- }
-
- $defaultArgs = ['resolution', 'quality', 'method', 'objects', 'version'];
- foreach ($defaultArgs as $arg) {
- if (!isset($this->args[$arg])) {
- $this->args[$arg] = $core->user->ws_settings[$arg];
- }
- }
-
- $dao = new wsDAODocument($core->con);
- $documents = [];
- foreach ($_FILES as $varname => $infos) {
- if ($infos['error']) {
- continue;
- }
- // Initialisation du document
- $data = array();
- $data['proprietaire'] = $core->user->utilisateur_id;
- $data['pages'] = 0;
- $data['version'] = 2;
- $data['file'] = cubeFiles::tidyName($infos['name']);
- $li = new wsDocumentLocalInfos($this);
- $li->fileName = $this->args['fileName'];
- $li->fileSize = $this->args['fileSize'];
- $li->creationDate = $this->args['creationDate'];
- $li->modificationDate = $this->args['modificationDate'];
- $data['localInfos'] = $li;
- $data['conversionInfos'] = new wsDocumentConversionInfos($this->args['resolution'], $this->args['method'], $this->args['quality'], $this->args['objects'], $this->args['version']);
- $document = $dao->sauve($data);
- $document->copyOriginalFromUpload($infos['tmp_name']);
- $this->xml->addChild('document_id', $document->document_id);
- $documents[] = $document->document_id;
- $_SESSION['conversionSession'][$document->document_id] = 'all';
- $_SESSION['conversionSessionReload'] = false;
- };
-
- if (isset($this->args['append'])) {
- $this->args['book_id'] = $this->args['append'];
- $this->processConversionSession(false, $_SESSION['conversionSession'], false);
- $daoBook = new wsDAOBook($core->con);
- foreach ($documents as $id) {
- $daoBook->appendDocument($this->args['book_id'], $id);
- }
- }
- }
-
- public function addDocument()
- {
- $_SESSION['conversionSession'] = array();
- $_SESSION['conversionSession'][$this->args['document_id']] = 'all';
- $_SESSION['conversionSessionReload'] = false;
- }
-
- public function reload()
- {
- global $core;
-
- if ($this->args['reloadDocs'] == '1') {
- foreach ($this->args['documents'] as $document_id => $pages) {
- $this->args['documents'][$document_id] = 'all';
- }
- }
-
- $dao = new wsDAODocument($core->con);
- $_SESSION['conversionSession'] = $this->args['documents'];
- $_SESSION['conversionSessionReload'] = true;
- foreach ($this->args['documents'] as $id => $pages) {
- $doc = $dao->selectById($id);
- $doc->conversionInfos->updatePages($pages, $this->args['resolution'], $this->args['quality'], $this->args['method'], $this->args['objects'], $this->args['version']);
- $dao->updateFromObject($doc);
- }
- }
-
- public function processConversionSession($async = true, $documents = null, $reload = false)
- {
- $_SESSION['sessionConversionGUID'] = $sessionConversionGUID = uniqid('conversion_', true);
-
- $session = new wsConversionSession($sessionConversionGUID);
- $session->reload = (isset($_SESSION['conversionSessionReload']) && $_SESSION['conversionSessionReload']) || $reload;
- if (null === $documents) {
- $session->setDocuments($_SESSION['conversionSession']);
- } else {
- $session->setDocuments($documents);
- }
- $session->setBook($this->args['book_id']);
- if (isset($_SESSION['conversionSession'])) {
- unset($_SESSION['conversionSession']);
- }
- if (isset($_SESSION['conversionSessionReload'])) {
- unset($_SESSION['conversionSessionReload']);
- }
- $session->serialize();
-
- $executable = 'php';
- if (AMARCORD) {
- $executable = '/usr/bin/php5.6';
- }
- $php = new cubeCommandLine($executable);
- $php->setPath(CONVERTER_PATH);
- $php->setArg('f', ROOT . '/index.php');
- $php->setArg('d', 'memory_limit=4G');
- $php->setManualArg('--');
- $php->setArg('user_email', $_SESSION['user_email']);
- $php->setArg('user_password', $_SESSION['user_password']);
- $php->setArg('sessionConversionGUID', $sessionConversionGUID);
- $php->setArg('PATH_INFO', '/flash/processConversionSessionAsync');
- $php->setArg('HTTP_HOST', $_SERVER['HTTP_HOST']);
- $php->setArg('SERVER_ADDR', $_SERVER['SERVER_ADDR']);
- if ($async) {
- $php->setNohup(true);
- }
- $php->execute('exec');
-
- file_put_contents(ROOT . '/../log/processConversionSession.txt', print_r($session) . "\n" . $php->commande . "\n" . $php->output);
-
- $this->xml->addChild('command', html::escapeHTML($php->command));
- if ($async) {
- exit;
- }
- }
-
- public function processConversionSessionAsync()
- {
- cubePHP::neverStop();
- try {
- $conversion = wsConversionSession::openFromGUID($_REQUEST['sessionConversionGUID']);
- $conversion->process();
- } catch (Exception $e) {
- file_put_contents(CACHE . '/conversionExceptions.txt', print_r($e, true), FILE_APPEND);
- }
- $conversion->destroy();
- }
-
- public function getConversionSessionProgress()
- {
- set_time_limit(1);
- $session = wsConversionSession::openFromGUID($_SESSION['sessionConversionGUID']);
- $p = $session->getProgress();
- $this->xml->addChild('progress', $p['progress']);
- $this->xml->addChild('processedDoc', $p['processedDoc']);
- $this->xml->addChild('totalDoc', $p['totalDoc']);
- $this->xml->addChild('currentDoc', $p['currentDoc']);
- $this->xml->addChild('currentDocPage', $p['currentDocPage']);
- $this->xml->addChild('totalDocPage', $p['totalDocPage']);
- }
-
- public function uploadThemeFile()
- {
- foreach ($_FILES as $varname => $infos) {
- if ($infos['error']) {
- continue;
- }
- $fname = cubeFiles::tidyName($infos['name']);
- $res = $fname;
- $dir = WS_THEMES . '/' . $this->args['theme_id'] . '/';
- $dest = $dir . $fname;
-
-
- if (!file_exists(WS_THEMES . '/' . $this->args['theme_id'])) {
- mkdir(WS_THEMES . '/' . $this->args['theme_id'], 0755, true);
- }
-
- move_uploaded_file($infos['tmp_name'], $dest);
-
- if (isset($this->args['type']) && $this->args['type'] == 'favicon') {
- $icotool = new cubeCommandLine('icotool');
- $icotool->setArg('c');
- $icotool->setArg('o', $dir . '/fluidbook.ico');
-
- $sizes = array(256, 128, 64, 32, 16);
-
- foreach ($sizes as $s) {
- $r = $dir . '/ico-' . $s . '.png';
- $it = new cubeImageTools();
- $it->loadImage($dest);
- $it->resize($s, $s, 'crop', true, 'C', 'M', 'transparent');
- $it->output('png', $r);
- $icotool->setArg(null, $r);
- }
-
- $icotool->execute();
- }
-
- if (in_array(strtolower(files::getExtension($dest)), array('svg'))) {
- // Optimize & rasterize SVG
- $orig = str_replace('.svg', '.o.svg', $dest);
- rename($dest, $orig);
- $png = str_replace('.svg', '.png', $dest);
-
- `/usr/local/bin/svgcleaner $orig $dest`;
- if (!file_exists($dest)) {
- copy($orig, $dest);
- }
- `convert -background none $dest $png`;
- }
-
- $this->xml->addChild('file', $fname);
- return;
- }
- }
-
- public function uploadLinkContent()
- {
- foreach ($_FILES as $varname => $infos) {
- if ($infos['error']) {
- continue;
- }
-
- if (isset($_POST['dir'])) {
- $dir = trim($_POST['dir'], '/\\ ');
- } else {
- $dir = '';
- }
-
- if ($dir != '') {
- $dir = $dir . '/';
- }
-
- $fname = cubeFiles::tidyName($infos['name']);
- $dir = WS_BOOKS . '/working/' . $this->args['book_id'] . '/' . $dir;
- if (!file_exists($dir)) {
- mkdir($dir, 0777, true);
- }
- $dest = $dir . $fname;
- move_uploaded_file($infos['tmp_name'], $dest);
- switch (strtolower(files::getExtension($dest))) {
- case 'flv':
- case 'f4v':
- case 'mp4':
- // convert uploaded file as webvideo (ogv and mp4)
- wsTools::encodeWebVideos($dest, null, true, false);
- break;
- case 'svg':
- // Optimize & rasterize SVG
- $orig = str_replace('.svg', '.o.svg', $dest);
- rename($dest, $orig);
- $png = str_replace('.svg', '.png', $dest);
- `/usr/local/bin/svgcleaner $orig $dest`;
- if (!file_exists($dest)) {
- copy($orig, $dest);
- }
- `convert -background none $dest $png`;
- break;
- default:
- break;
- }
-
- $this->xml->addChild('file', $fname);
- return;
- }
- }
-
- public function testDocuments()
- {
- global $core;
-
- $toload = $this->xml->addChild('toLoad');
- $alreadyLoaded = $this->xml->addChild('alreadyLoaded');
-
- $hash = array();
-
- foreach ($this->args['fileName'] as $k => $name) {
- $o = new wsDocumentLocalInfos();
- $o->fileName = $name;
- $o->fileSize = intval($this->args['fileSize'][$k]);
- $o->modificationDate = intval($this->args['modificationDate'][$k]);
- $o->creationDate = intval($this->args['creationDate'][$k]);
-
- $hash[$k] = md5(serialize($o));
- }
-
- $in = array();
- foreach ($hash as $h) {
- $in[] = "'" . $h . "'";
- }
-
- $sql = 'SELECT document_id,localHash FROM documents WHERE localHash';
- if (count($in) == 1) {
- $sql .= ' = ' . implode(',', $in);
- } else {
- $sql .= ' IN (' . implode(',', $in) . ')';
- }
-
- $al = array();
- $r = $core->con->select($sql);
- while ($r->fetch()) {
- $k = array_search($r->localHash, $hash);
-
- if (!file_exists(WS_DOCS . '/' . $r->document_id . '/crop.pdf')) {
- continue;
- }
-
- $al[$k] = true;
- $f = $alreadyLoaded->addChild('file', $this->args['fileName'][$k]);
- $f->addAttribute('document_id', $r->document_id);
- }
-
- foreach ($this->args['fileName'] as $k => $name) {
- if (!isset($al[$k])) {
- $toload->addChild('file', $name);
- }
- }
- }
-
- public function getPagesOfBook()
- {
- global $core;
-
- $this->json = true;
-
- $dao = new wsDAOBook($core->con);
- $book = $dao->selectById($this->args['book_id']);
- $pages = $dao->getPagesOfBook($this->args['book_id'], false);
- $this->jsonDatas['pages'] = array();
- $docs = array();
- $defaultNum = array();
- foreach ($pages as $page => $info) {
- $file = WS_DOCS . '/' . $info['document_id'] . '/p' . $info['document_page'] . '.jpg';
- if (!file_exists($file)) {
- $info['resolution'] = 150;
- $info['method'] = 1;
- $info['objects'] = 1800;
- $info['quality'] = 85;
- $info['version'] = 'stable';
- } elseif (!isset($this->jsonDatas['thumbWidth'])) {
- $dim = getimagesize($file);
- $this->jsonDatas['thumbWidth'] = $dim[0];
- $this->jsonDatas['thumbHeight'] = $dim[1];
- }
-
- $docs[] = $info['document_id'];
- $defaultNum[] = $info['defaultNum'];
-
- $this->jsonDatas['pages'][] = array($info['document_id'], $info['document_page']);
- }
- $docs = array_unique($docs);
- $this->jsonDatas['documents'] = $docs;
- $this->jsonDatas['documents_path'] = [];
- foreach ($docs as $document_id) {
- $this->jsonDatas['documents_path'][$document_id] = str_replace(WS_FILES, '', wsDocument::getDir($document_id, true));
- }
-
- if (is_null($book->numerotation) || !$book->numerotation || $book->numerotation == 'null') {
- $this->jsonDatas['numerotation'] = $defaultNum;
- } else {
- $this->jsonDatas['numerotation'] = explode(',', $book->numerotation);
- }
- }
-
- public function getTheme()
- {
- global $core;
- $dao = new wsDAOTheme($core->con);
- if (isset($this->args['theme_id'])) {
- $theme = $dao->selectById($this->args['theme_id']);
- } else {
- $theme = $dao->getThemeOfBook($this->args['book_id']);
- }
- $this->_themeToXML($theme);
- }
-
- public function saveTheme()
- {
- global $core;
- $dao = new wsDAOTheme($core->con);
- $dao->sauve($this->args);
- }
-
- public function getAllThemes()
- {
- global $core;
-
- if (isset($this->args['book_id'])) {
- $dao = new wsDAOBook($core->con);
- $book = $dao->selectById($this->args['book_id']);
- } else {
- $this->args['book_id'] = 0;
- }
-
- $demos = array(1161, 1160);
- $readOnly = array(1);
-
- $dao = new wsDAOTheme($core->con);
- $themes = $dao->getAllThemes($core->user, 'ORDER BY FIELD (theme_id,' . $this->args['book_id'] . ',' . implode(',', $demos) . ') DESC, theme_id DESC', $demos);
- foreach ($themes as $theme) {
- $t = $this->xml->addChild('theme');
- $t->addAttribute('id', $theme->theme_id);
- $t->addAttribute('nom', $theme->nom);
- if (isset($book) && $theme->theme_id == $book->theme) {
- $t->addAttribute('selected', '1');
- $mine = true;
- } else {
- $mine = false;
- }
- if (in_array($theme->theme_id, $demos)) {
- $right = 'r';
- } elseif (wsDroits::admin()) {
- $right = 'w';
- } elseif (in_array($theme->theme_id, $readOnly)) {
- $right = 'r';
- } elseif (wsDroits::revendeur() && wsDroits::creation()) {
- $right = 'w';
- } else {
- $right = 'r';
- }
-
-
- $t->addAttribute('right', $right);
- $t->addAttribute('proprietaire', $theme->proprietaire_nom);
- $t->addAttribute('books', max(($theme->nbBooks) - ($mine ? 1 : 0), 0));
- }
- }
-
- public function deleteTheme()
- {
- global $core;
-
- $dao = new wsDAOTheme($core->con);
- $dao->delete($this->args['theme_id']);
- }
-
- public function renameTheme()
- {
- global $core;
-
- $dao = new wsDAOTheme($core->con);
- $dao->rename($this->args['theme_id'], $this->args['text']);
- }
-
- public function duplicateTheme()
- {
- 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'])) {
- $dao = new wsDAOBook($core->con);
- $data = array('book_id' => $this->args['book_id'], 'theme' => $theme->theme_id);
- $dao->sauve($core->user->utilisateur_id, $data);
- }
- }
-
- public function setTheme()
- {
- global $core;
- $dao = new wsDAOBook($core->con);
- $dao->setTheme($this->args['book_id'], $this->args['theme']);
- }
-
- public function postThemeShot()
- {
- file_put_contents(WS_THEMES . '/' . $this->args['theme_id'] . '.jpg', base64_decode($this->args['data']));
- }
-
- public function getAllIcones()
- {
- global $core;
- $dao = new wsDAOIcone($core->con);
- $icones = $dao->selectAll('ORDER BY FIELD(icone_id,13,15) DESC, icone_id DESC');
- foreach ($icones as $icone) {
- $i = $this->xml->addChild('icone');
- $i->addAttribute('id', $icone->icone_id);
- $i->addAttribute('nom', $icone->nom);
- $i->addAttribute('path', ICONS . $icone->icone_id . '.png');
- $i->addAttribute('main', in_array($icone->icone_id, array(13, 15)));
- }
- }
-
- protected function _themeToXML($theme)
- {
- $t = $this->xml->addChild('theme');
- $t->addAttribute('theme_id', $theme->theme_id);
- $t->addAttribute('icones_id', $theme->icones);
- foreach ($theme->parametres as $k => $v) {
- $t->addChild($k, $v);
- }
- }
-
- public function getThemeForms()
- {
- global $core;
- $dao = new wsDAOTheme($core->con);
- $theme = $dao->selectById($this->args['theme_id']);
-
- foreach ($theme->parametres->getForms() as $name) {
- $f = $this->xml->addChild('form', json_encode($theme->parametres->getForm($name)));
- $f->addAttribute('name', $name);
- }
- }
-
- public function getFluidbookForms()
- {
- global $core;
- $dao = new wsDAOBook($core->con);
- $book = $dao->selectById($this->args['book_id']);
- foreach ($book->parametres->getForms() as $name) {
- $f = $this->xml->addChild('form', html::escapeHTML(json_encode($book->parametres->getForm($name))));
- $f->addAttribute('name', $name);
- }
- }
-
- public function saveSettings()
- {
- global $core;
- $dao = new wsDAOBook($core->con);
-
- $pages = $dao->getPagesOfBook($this->args['book_id']);
- $nb_pages = count($pages);
-
- $daoDoc = new wsDAODocument($core->con);
- $firstDoc = $daoDoc->selectById($pages[1]['document_id']);
- $size = $firstDoc->generalInfos['size'];
-
- $settings = json_decode($this->args['settings'], false);
- $settings->width = $size[0];
- $settings->height = $size[1];
-
- $dao->setSettings($this->args['book_id'], $settings);
- }
-
- public function setChapters()
- {
- global $core;
- $dao = new wsDAOBook($core->con);
- $dao->setChapters($this->args['book_id'], $this->args['chapters']);
- }
-
- public function getChapters()
- {
- global $core;
- $dao = new wsDAOBook($core->con);
- $book = $dao->selectById($this->args['book_id']);
- $this->xml->addChild('chapters', html::escapeHTML(json_encode($book->chapters)));
- }
-
- public function getLinks()
- {
- global $core;
-
- set_time_limit(0);
-
- $dao = new wsDAOBook($core->con);
- $book = $dao->selectById($this->args['book_id']);
-
-
- $pages = $dao->getPagesOfBook($this->args['book_id']);
- $nb_pages = count($pages);
-
- $daoDoc = new wsDAODocument($core->con);
- $firstDoc = $daoDoc->selectById($pages[1]['document_id']);
- $size = $firstDoc->generalInfos['size'];
- $daoDoc->getLinksAndRulers($this->args['book_id'], $links, $rulers);
-
- $this->json = false;
- $this->json = true;
-
- $types = array(1, 2, 3, 4, 5, 6, 7, 11, 13, 14, 15, 16, 17, 18, 19, 24, 25);
- if (wsDroits::revendeur()) {
- $types = array(1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 24, 25, 31, 33);
- }
- if (wsDroits::admin()) {
- $types = range(1, 100);
- $links = wsLinks::decryptLinks($links);
- }
-
- if ($this->json) {
- $this->jsonDatas['types'] = $types;
- $this->jsonDatas['pages'] = $nb_pages;
- $this->jsonDatas['numerotation'] = $book->numerotation;
- $this->jsonDatas['width'] = $size[0];
- $this->jsonDatas['height'] = $size[1];
- $this->jsonDatas['links'] = $links;
- $this->jsonDatas['rulers'] = $rulers;
- } else {
- $l = json_encode($links);
- $l = html::escapeHTML($l);
- $this->xml->addChild('width', $size[0]);
- $this->xml->addChild('height', $size[1]);
- $this->xml->addChild('pages', $nb_pages);
- $this->xml->addChild('numerotation', $book->numerotation);
- $this->xml->addChild('links', $l);
- $this->xml->addChild('rulers', json_encode($rulers));
- }
-
- $daoTheme = new wsDAOTheme($this->con);
- $theme = $daoTheme->getThemeOfBook($this->args['book_id'], true);
-
- $specials = array('backgroundImage' => 'background', 'topBar' => 'topbar', 'afterSearch' => 'aftersearch', 'externalArchives' => 'archives');
-
- foreach ($specials as $tparam => $sname) {
- $this->_addSpecialInfos($book, $theme, $tparam, $sname);
- }
- }
-
- protected function _addSpecialInfos($book, $theme, $param, $specialName)
- {
- if ($specialName == 'archives') {
- $p = $book->parametres;
- } else {
- $p = $theme->parametres;
- }
-
-
- if ($p->$param != '') {
- if ($specialName != 'archives') {
- $themeRoot = WS_THEMES . '/' . $theme->theme_id . '/';
- $dim = CubeIT_Image::getimagesize($themeRoot . $p->$param);
- $url = 'https://' . $_SERVER['HTTP_HOST'] . WEBROOT . '/fluidbook/themes/' . $theme->theme_id . '/' . $p->$param;
- } else {
- $bookRoot = WS_BOOKS . '/working/' . $book->book_id . '/';
- $dim = CubeIT_Image::getimagesize($bookRoot . $p->$param);
- $url = 'https://' . $_SERVER['HTTP_HOST'] . WEBROOT . '/fluidbook/books/working/' . $book->book_id . '/' . $p->$param;
- }
-
- if ($this->json) {
- $p = array('width' => $dim[0], 'height' => $dim[1], 'url' => $url);
- $this->jsonDatas[$specialName] = $p;
- } else {
- $b = $this->xml->addChild($specialName);
- $b->addChild('width', $dim[0]);
- $b->addChild('height', $dim[1]);
- $b->addChild('url', $url);
- }
- }
- }
-
- public function saveLinks()
- {
- global $core;
-
- $comments = isset($this->args['comments']) ? $this->args['comments'] : 'Saved from editor';
-
- $dao = new wsDAODocument($core->con);
- $dao->setLinksAndRulers($this->args['book_id'], $this->args['links'], $this->args['rulers'], $comments, $core->user->utilisateur_id, false);
-
- $daoBook = new wsDAOBook($core->con);
- $daoBook->setSpecialLinksAndRulers($this->args['book_id'], $this->args['specialLinks'], $this->args['specialRulers']);
-
- if (isset($this->args['getLinks'])) {
- $this->getLinks();
- }
- }
-
- public function formatSize($val)
- {
- $str = files::size($val);
- $str = str_replace('.', __(','), $str);
- $str = str_replace('B', __('o'), $str);
- return $str;
- }
-
- public function getExtras()
- {
- global $core;
- $dao = new wsDAOBook($core->con);
- $book = $dao->selectById($this->args['book_id']);
- if ($book->extras != '') {
- $tidy = cubeXML::tidy('<extras>' . $book->extras . '</extras>');
- $tidy = str_replace('<extras>', '', $tidy);
- $tidy = str_replace('</extras>', '', $tidy);
- $tidy = str_replace('<?xml version="1.0"?>', '', $tidy);
- $tidy = trim($tidy);
- $e = explode("\n", $tidy);
- foreach ($e as $k => $v) {
- if (substr($v, 0, 2) == ' ') {
- $v = substr($v, 2);
- }
- $e[$k] = $v;
- }
-
- $extras = implode("\n", $e);
- } else {
- $extras = '';
- }
-
- $this->xml->addChild('extras', $extras);
- }
-
- public function saveExtras()
- {
- global $core;
- $dao = new wsDAOBook($core->con);
- $res = $dao->setExtras($this->args['book_id'], $this->args['extras']);
- $this->xml->addChild('ok', $res ? '1' : '0');
- }
-
- public function getMetadata()
- {
- global $core;
-
- $dao = new wsDAOBook($core->con);
- $book = $dao->selectById($this->args['book_id']);
-
- $this->xml->addChild('title', htmlspecialchars($book->nom));
- $this->xml->addChild('date', $book->changedate);
- }
-
- public function getBookInfos()
- {
- global $core;
- $dao = new wsDAOBook($core->con);
- $book = $dao->selectById($this->args['book_id']);
- $pages = $dao->getPagesOfBook($this->args['book_id'], false);
- $daoDoc = new wsDAODocument($core->con);
- $nb_pages = count($pages);
- $this->xml->addChild('pages', $nb_pages);
- $total_size = 0;
-
- foreach ($pages as $page => $info) {
- $docdir = wsDocument::getDir($info['document_id']);
- $file = $docdir . '/p' . $info['document_page'] . '.swf';
- $total_size += filesize($file);
- }
- $average_size = $total_size / $nb_pages;
- $total = self::formatSize($total_size);
- $average = self::formatSize($average_size);
- $firstDoc = $daoDoc->selectById($pages[1]['document_id']);
- $size = $firstDoc->generalInfos['size'];
- $this->xml->addChild('width', $size[0]);
- $this->xml->addChild('height', $size[1]);
- $res = '<b>' . __('Nombre de pages') . '</b> : ';
- $res .= $nb_pages . ' ' . __('pages') . "\n";
- $res .= "\n";
- $res .= '<b>' . __('Dimensions') . '</b> : ' . "\n";
- $res .= round($size[0], 3) . ' x ' . round($size[1], 3) . ' pts' . "\n";
- $res .= "\n";
- $res .= '<b>' . __('Taille totale des pages') . '</b> : ' . "\n";
- $res .= $total . "\n";
- $res .= "\n";
- $res .= '<b>' . __('Taille moyenne des pages') . '</b> : ' . "\n";
- $res .= $average . "\n";
- $res .= "\n";
- $this->xml->addChild('infos', $res);
- }
-
- public function getLangs()
- {
- global $core;
- if (isset($this->args['book_id'])) {
- $dao = new wsDAOBook($core->con);
- $book = $dao->selectById($this->args['book_id']);
- $book->traductions = wsLang::checkTranslations($book->traductions);
- if ($book->traductions != array()) {
- //$bookLang = $this->xml->addChild('book_lang', json_encode($book->traductions));
- $bookLang = (array)$book->traductions;
- }
- }
-
- if (isset($bookLang)) {
- if (wsLang::compare($bookLang, $book->lang)) {
- unset($bookLang);
- }
- }
-
- $dao = new wsDAOLang($core->con);
- $langs = $dao->selectAll();
- foreach ($langs as $lang) {
- $nom = cubeLang::getNameByCode($lang->lang_id, $core->user->lang);
- $l = $this->xml->addChild('lang', json_encode($lang->traductions));
- $l->addAttribute('id', $lang->lang_id);
- $l->addAttribute('nom', $nom);
- if (isset($book) && $book->lang == $lang->lang_id) {
- if (!isset($bookLang)) {
- $l->addAttribute('selected', '1');
- } else {
- $trad = array_merge($lang->traductions, $bookLang);
- $bl = $this->xml->addChild('book_lang', json_encode($trad));
- $bl->addAttribute('id', $lang->lang_id);
- $bl->addAttribute('nom', $nom . ' (' . __('modifié') . ')');
- $bl->addAttribute('selected', '1');
- }
- }
- }
- }
-
- public function saveLang()
- {
- global $core;
- $dao = new wsDAOBook($core->con);
- $dao->setLang($this->args['book_id'], $this->args['lang_id'], $this->args['traductions']);
- }
-
- public function saveComposition()
- {
- global $core;
- $dao = new wsDAOBook($core->con);
- $dao->setComposition($this->args['book_id'], json_decode($this->args['pages']));
- }
-
- public function getTexts()
- {
- $this->xml->addChild('texts', json_encode($GLOBALS['__l10n']));
- }
-
- public function copyLinks()
- {
- global $core;
- $daoDocument = new wsDAODocument($core->con);
- $daoDocument->copyLinks($this->args['fromDoc'], $this->args['toDoc']);
- }
-
- public function compile()
- {
- global $core;
- wsSecureSWF::checkProtectedSWF();
- $dao = new wsDAOBook($core->con);
-
- $log = $dao->compile($this->args['book_id'], '2');
-
- $book = $dao->selectById($this->args['book_id']);
- $viewer = 'viewer';
- /*if (wsDroits::admin()) {
- $viewer = 'vieweru';
- }*/
-
- $absoluteURL = 'https://' . $_SERVER['HTTP_HOST'] . '/' . $viewer . '/' . $book->book_id . '_' . $book->hash . '_' . TIME . '/';
- $this->xml->addChild('compiledBook', $absoluteURL . 'index.swf?base=' . $absoluteURL);
- }
+ const CNAME = __CLASS__;
+
+ public static function in($args)
+ {
+ global $core;
+ $args = cubePage::getArgs($args);
+ $n = self::CNAME;
+ $gateway = new $n($core->con, $args);
+
+ $droits = wsDroits::getDroits();
+ $gateway->addAttribute('creation', $droits->creation ? '1' : '0');
+ $gateway->addAttribute('revendeur', $droits->revendeur ? '1' : '0');
+ $gateway->addAttribute('admin', $droits->admin ? '1' : '0');
+ if (null !== $core->user) {
+ $grade = -1;
+ } else {
+ $grade = $core->user->ws_grade;
+ }
+ $gateway->addAttribute('grade', $grade);
+ }
+
+ public function saveConversionSettings()
+ {
+ global $core;
+ $dao = new commonDAOUtilisateur($core->con);
+ $datas = array('resolution' => $this->args['resolution'],
+ 'objects' => $this->args['objects'],
+ 'method' => $this->args['method'],
+ 'quality' => $this->args['quality'],
+ 'version' => $this->args['version']);
+ $dao->sauveWSSettings($core->user->utilisateur_id, $datas);
+ }
+
+ public function getConversionSettings()
+ {
+ global $core;
+ $this->xml->addChild('resolution', $core->user->ws_settings['resolution']);
+ $this->xml->addChild('quality', $core->user->ws_settings['quality']);
+ $this->xml->addChild('method', $core->user->ws_settings['method']);
+ $this->xml->addChild('objects', $core->user->ws_settings['objects']);
+ $this->xml->addChild('version', $core->user->ws_settings['version']);
+ }
+
+ public function uploadDocument()
+ {
+ cubePHP::neverStop();
+ global $core;
+ if (!isset($_SESSION['conversionSession'])) {
+ $_SESSION['conversionSession'] = array();
+ }
+
+ $defaultArgs = ['resolution', 'quality', 'method', 'objects', 'version'];
+ foreach ($defaultArgs as $arg) {
+ if (!isset($this->args[$arg])) {
+ $this->args[$arg] = $core->user->ws_settings[$arg];
+ }
+ }
+
+ $dao = new wsDAODocument($core->con);
+ $documents = [];
+ foreach ($_FILES as $varname => $infos) {
+ if ($infos['error']) {
+ continue;
+ }
+ // Initialisation du document
+ $data = array();
+ $data['proprietaire'] = $core->user->utilisateur_id;
+ $data['pages'] = 0;
+ $data['version'] = 2;
+ $data['file'] = cubeFiles::tidyName($infos['name']);
+ $li = new wsDocumentLocalInfos($this);
+ $li->fileName = $this->args['fileName'];
+ $li->fileSize = $this->args['fileSize'];
+ $li->creationDate = $this->args['creationDate'];
+ $li->modificationDate = $this->args['modificationDate'];
+ $data['localInfos'] = $li;
+ $data['conversionInfos'] = new wsDocumentConversionInfos($this->args['resolution'], $this->args['method'], $this->args['quality'], $this->args['objects'], $this->args['version']);
+ $document = $dao->sauve($data);
+ $document->copyOriginalFromUpload($infos['tmp_name']);
+ $this->xml->addChild('document_id', $document->document_id);
+ $documents[] = $document->document_id;
+ $_SESSION['conversionSession'][$document->document_id] = 'all';
+ $_SESSION['conversionSessionReload'] = false;
+ };
+
+ if (isset($this->args['append'])) {
+ $this->args['book_id'] = $this->args['append'];
+ $this->processConversionSession(false, $_SESSION['conversionSession'], false);
+ $daoBook = new wsDAOBook($core->con);
+ foreach ($documents as $id) {
+ $daoBook->appendDocument($this->args['book_id'], $id);
+ }
+ }
+ }
+
+ public function addDocument()
+ {
+ $_SESSION['conversionSession'] = array();
+ $_SESSION['conversionSession'][$this->args['document_id']] = 'all';
+ $_SESSION['conversionSessionReload'] = false;
+ }
+
+ public function reload()
+ {
+ global $core;
+
+ if ($this->args['reloadDocs'] == '1') {
+ foreach ($this->args['documents'] as $document_id => $pages) {
+ $this->args['documents'][$document_id] = 'all';
+ }
+ }
+
+ $dao = new wsDAODocument($core->con);
+ $_SESSION['conversionSession'] = $this->args['documents'];
+ $_SESSION['conversionSessionReload'] = true;
+ foreach ($this->args['documents'] as $id => $pages) {
+ $doc = $dao->selectById($id);
+ $doc->conversionInfos->updatePages($pages, $this->args['resolution'], $this->args['quality'], $this->args['method'], $this->args['objects'], $this->args['version']);
+ $dao->updateFromObject($doc);
+ }
+ }
+
+ public function processConversionSession($async = true, $documents = null, $reload = false)
+ {
+ $_SESSION['sessionConversionGUID'] = $sessionConversionGUID = uniqid('conversion_', true);
+
+ $session = new wsConversionSession($sessionConversionGUID);
+ $session->reload = (isset($_SESSION['conversionSessionReload']) && $_SESSION['conversionSessionReload']) || $reload;
+ if (null === $documents) {
+ $session->setDocuments($_SESSION['conversionSession']);
+ } else {
+ $session->setDocuments($documents);
+ }
+ $session->setBook($this->args['book_id']);
+ if (isset($_SESSION['conversionSession'])) {
+ unset($_SESSION['conversionSession']);
+ }
+ if (isset($_SESSION['conversionSessionReload'])) {
+ unset($_SESSION['conversionSessionReload']);
+ }
+ $session->serialize();
+
+ $executable = 'php';
+ if (AMARCORD) {
+ $executable = '/usr/bin/php5.6';
+ }
+ $php = new cubeCommandLine($executable);
+ $php->setPath(CONVERTER_PATH);
+ $php->setArg('f', ROOT . '/index.php');
+ $php->setArg('d', 'memory_limit=4G');
+ $php->setManualArg('--');
+ $php->setArg('user_email', $_SESSION['user_email']);
+ $php->setArg('user_password', $_SESSION['user_password']);
+ $php->setArg('sessionConversionGUID', $sessionConversionGUID);
+ $php->setArg('PATH_INFO', '/flash/processConversionSessionAsync');
+ $php->setArg('HTTP_HOST', $_SERVER['HTTP_HOST']);
+ $php->setArg('SERVER_ADDR', $_SERVER['SERVER_ADDR']);
+ if ($async) {
+ $php->setNohup(true);
+ }
+ $php->execute('exec');
+
+ file_put_contents(ROOT . '/../log/processConversionSession.txt', print_r($session) . "\n" . $php->commande . "\n" . $php->output);
+
+ $this->xml->addChild('command', html::escapeHTML($php->command));
+ if ($async) {
+ exit;
+ }
+ }
+
+ public function processConversionSessionAsync()
+ {
+ cubePHP::neverStop();
+ try {
+ $conversion = wsConversionSession::openFromGUID($_REQUEST['sessionConversionGUID']);
+ $conversion->process();
+ } catch (Exception $e) {
+ file_put_contents(CACHE . '/conversionExceptions.txt', print_r($e, true), FILE_APPEND);
+ }
+ $conversion->destroy();
+ }
+
+ public function getConversionSessionProgress()
+ {
+ set_time_limit(1);
+ $session = wsConversionSession::openFromGUID($_SESSION['sessionConversionGUID']);
+ $p = $session->getProgress();
+ $this->xml->addChild('progress', $p['progress']);
+ $this->xml->addChild('processedDoc', $p['processedDoc']);
+ $this->xml->addChild('totalDoc', $p['totalDoc']);
+ $this->xml->addChild('currentDoc', $p['currentDoc']);
+ $this->xml->addChild('currentDocPage', $p['currentDocPage']);
+ $this->xml->addChild('totalDocPage', $p['totalDocPage']);
+ }
+
+ public function uploadThemeFile()
+ {
+ foreach ($_FILES as $varname => $infos) {
+ if ($infos['error']) {
+ continue;
+ }
+ $fname = cubeFiles::tidyName($infos['name']);
+ $res = $fname;
+ $dir = WS_THEMES . '/' . $this->args['theme_id'] . '/';
+ $dest = $dir . $fname;
+
+
+ if (!file_exists(WS_THEMES . '/' . $this->args['theme_id'])) {
+ mkdir(WS_THEMES . '/' . $this->args['theme_id'], 0755, true);
+ }
+
+ move_uploaded_file($infos['tmp_name'], $dest);
+
+ if (isset($this->args['type']) && $this->args['type'] == 'favicon') {
+ $icotool = new cubeCommandLine('icotool');
+ $icotool->setArg('c');
+ $icotool->setArg('o', $dir . '/fluidbook.ico');
+
+ $sizes = array(256, 128, 64, 32, 16);
+
+ foreach ($sizes as $s) {
+ $r = $dir . '/ico-' . $s . '.png';
+ $it = new cubeImageTools();
+ $it->loadImage($dest);
+ $it->resize($s, $s, 'crop', true, 'C', 'M', 'transparent');
+ $it->output('png', $r);
+ $icotool->setArg(null, $r);
+ }
+
+ $icotool->execute();
+ }
+
+ if (in_array(strtolower(files::getExtension($dest)), array('svg'))) {
+ // Optimize & rasterize SVG
+ $orig = str_replace('.svg', '.o.svg', $dest);
+ rename($dest, $orig);
+ $png = str_replace('.svg', '.png', $dest);
+
+ `/usr/local/bin/svgcleaner $orig $dest`;
+ if (!file_exists($dest)) {
+ copy($orig, $dest);
+ }
+ `convert -background none $dest $png`;
+ }
+
+ $this->xml->addChild('file', $fname);
+ return;
+ }
+ }
+
+ public function uploadLinkContent()
+ {
+ foreach ($_FILES as $varname => $infos) {
+ if ($infos['error']) {
+ continue;
+ }
+
+ if (isset($_POST['dir'])) {
+ $dir = trim($_POST['dir'], '/\\ ');
+ } else {
+ $dir = '';
+ }
+
+ if ($dir != '') {
+ $dir = $dir . '/';
+ }
+
+ $fname = cubeFiles::tidyName($infos['name']);
+ $dir = WS_BOOKS . '/working/' . $this->args['book_id'] . '/' . $dir;
+ if (!file_exists($dir)) {
+ mkdir($dir, 0777, true);
+ }
+ $dest = $dir . $fname;
+ move_uploaded_file($infos['tmp_name'], $dest);
+ switch (strtolower(files::getExtension($dest))) {
+ case 'flv':
+ case 'f4v':
+ case 'mp4':
+ // convert uploaded file as webvideo (ogv and mp4)
+ wsTools::encodeWebVideos($dest, null, true, false);
+ break;
+ case 'svg':
+ // Optimize & rasterize SVG
+ $orig = str_replace('.svg', '.o.svg', $dest);
+ rename($dest, $orig);
+ $png = str_replace('.svg', '.png', $dest);
+ `/usr/local/bin/svgcleaner $orig $dest`;
+ if (!file_exists($dest)) {
+ copy($orig, $dest);
+ }
+ `convert -background none $dest $png`;
+ break;
+ default:
+ break;
+ }
+
+ $this->xml->addChild('file', $fname);
+ return;
+ }
+ }
+
+ public function testDocuments()
+ {
+ global $core;
+
+ $toload = $this->xml->addChild('toLoad');
+ $alreadyLoaded = $this->xml->addChild('alreadyLoaded');
+
+ $hash = array();
+
+ foreach ($this->args['fileName'] as $k => $name) {
+ $o = new wsDocumentLocalInfos();
+ $o->fileName = $name;
+ $o->fileSize = intval($this->args['fileSize'][$k]);
+ $o->modificationDate = intval($this->args['modificationDate'][$k]);
+ $o->creationDate = intval($this->args['creationDate'][$k]);
+
+ $hash[$k] = md5(serialize($o));
+ }
+
+ $in = array();
+ foreach ($hash as $h) {
+ $in[] = "'" . $h . "'";
+ }
+
+ $sql = 'SELECT document_id,localHash FROM documents WHERE localHash';
+ if (count($in) == 1) {
+ $sql .= ' = ' . implode(',', $in);
+ } else {
+ $sql .= ' IN (' . implode(',', $in) . ')';
+ }
+
+ $al = array();
+ $r = $core->con->select($sql);
+ while ($r->fetch()) {
+ $k = array_search($r->localHash, $hash);
+
+ if (!file_exists(WS_DOCS . '/' . $r->document_id . '/crop.pdf')) {
+ continue;
+ }
+
+ $al[$k] = true;
+ $f = $alreadyLoaded->addChild('file', $this->args['fileName'][$k]);
+ $f->addAttribute('document_id', $r->document_id);
+ }
+
+ foreach ($this->args['fileName'] as $k => $name) {
+ if (!isset($al[$k])) {
+ $toload->addChild('file', $name);
+ }
+ }
+ }
+
+ public function getPagesOfBook()
+ {
+ global $core;
+
+ $this->json = true;
+
+ $dao = new wsDAOBook($core->con);
+ $book = $dao->selectById($this->args['book_id']);
+ $pages = $dao->getPagesOfBook($this->args['book_id'], false);
+ $this->jsonDatas['pages'] = array();
+ $docs = array();
+ $defaultNum = array();
+ foreach ($pages as $page => $info) {
+ $file = WS_DOCS . '/' . $info['document_id'] . '/p' . $info['document_page'] . '.jpg';
+ if (!file_exists($file)) {
+ $info['resolution'] = 150;
+ $info['method'] = 1;
+ $info['objects'] = 1800;
+ $info['quality'] = 85;
+ $info['version'] = 'stable';
+ } elseif (!isset($this->jsonDatas['thumbWidth'])) {
+ $dim = getimagesize($file);
+ $this->jsonDatas['thumbWidth'] = $dim[0];
+ $this->jsonDatas['thumbHeight'] = $dim[1];
+ }
+
+ $docs[] = $info['document_id'];
+ $defaultNum[] = $info['defaultNum'];
+
+ $this->jsonDatas['pages'][] = array($info['document_id'], $info['document_page']);
+ }
+ $docs = array_unique($docs);
+ $this->jsonDatas['documents'] = $docs;
+ $this->jsonDatas['documents_path'] = [];
+ foreach ($docs as $document_id) {
+ $this->jsonDatas['documents_path'][$document_id] = str_replace(WS_FILES, '', wsDocument::getDir($document_id, true));
+ }
+
+ if (is_null($book->numerotation) || !$book->numerotation || $book->numerotation == 'null') {
+ $this->jsonDatas['numerotation'] = $defaultNum;
+ } else {
+ $this->jsonDatas['numerotation'] = explode(',', $book->numerotation);
+ }
+ }
+
+ public function getTheme()
+ {
+ global $core;
+ $dao = new wsDAOTheme($core->con);
+ if (isset($this->args['theme_id'])) {
+ $theme = $dao->selectById($this->args['theme_id']);
+ } else {
+ $theme = $dao->getThemeOfBook($this->args['book_id']);
+ }
+ $this->_themeToXML($theme);
+ }
+
+ public function saveTheme()
+ {
+ global $core;
+ $dao = new wsDAOTheme($core->con);
+ $dao->sauve($this->args);
+ }
+
+ public function getAllThemes()
+ {
+ global $core;
+
+ if (isset($this->args['book_id'])) {
+ $dao = new wsDAOBook($core->con);
+ $book = $dao->selectById($this->args['book_id']);
+ } else {
+ $this->args['book_id'] = 0;
+ }
+
+ $demos = array(1161, 1160);
+ $readOnly = array(1);
+
+ $dao = new wsDAOTheme($core->con);
+ $themes = $dao->getAllThemes($core->user, 'ORDER BY FIELD (theme_id,' . $this->args['book_id'] . ',' . implode(',', $demos) . ') DESC, theme_id DESC', $demos);
+ foreach ($themes as $theme) {
+ $t = $this->xml->addChild('theme');
+ $t->addAttribute('id', $theme->theme_id);
+ $t->addAttribute('nom', $theme->nom);
+ if (isset($book) && $theme->theme_id == $book->theme) {
+ $t->addAttribute('selected', '1');
+ $mine = true;
+ } else {
+ $mine = false;
+ }
+ if (in_array($theme->theme_id, $demos)) {
+ $right = 'r';
+ } elseif (wsDroits::admin()) {
+ $right = 'w';
+ } elseif (in_array($theme->theme_id, $readOnly)) {
+ $right = 'r';
+ } elseif (wsDroits::revendeur() && wsDroits::creation()) {
+ $right = 'w';
+ } else {
+ $right = 'r';
+ }
+
+
+ $t->addAttribute('right', $right);
+ $t->addAttribute('proprietaire', $theme->proprietaire_nom);
+ $t->addAttribute('books', max(($theme->nbBooks) - ($mine ? 1 : 0), 0));
+ }
+ }
+
+ public function deleteTheme()
+ {
+ global $core;
+
+ $dao = new wsDAOTheme($core->con);
+ $dao->delete($this->args['theme_id']);
+ }
+
+ public function renameTheme()
+ {
+ global $core;
+
+ $dao = new wsDAOTheme($core->con);
+ $dao->rename($this->args['theme_id'], $this->args['text']);
+ }
+
+ public function duplicateTheme()
+ {
+ 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'])) {
+ $dao = new wsDAOBook($core->con);
+ $data = array('book_id' => $this->args['book_id'], 'theme' => $theme->theme_id);
+ $dao->sauve($core->user->utilisateur_id, $data);
+ }
+ }
+
+ public function setTheme()
+ {
+ global $core;
+ $dao = new wsDAOBook($core->con);
+ $dao->setTheme($this->args['book_id'], $this->args['theme']);
+ }
+
+ public function postThemeShot()
+ {
+ file_put_contents(WS_THEMES . '/' . $this->args['theme_id'] . '.jpg', base64_decode($this->args['data']));
+ }
+
+ public function getAllIcones()
+ {
+ global $core;
+ $dao = new wsDAOIcone($core->con);
+ $icones = $dao->selectAll('ORDER BY FIELD(icone_id,13,15) DESC, icone_id DESC');
+ foreach ($icones as $icone) {
+ $i = $this->xml->addChild('icone');
+ $i->addAttribute('id', $icone->icone_id);
+ $i->addAttribute('nom', $icone->nom);
+ $i->addAttribute('path', ICONS . $icone->icone_id . '.png');
+ $i->addAttribute('main', in_array($icone->icone_id, array(13, 15)));
+ }
+ }
+
+ protected function _themeToXML($theme)
+ {
+ $t = $this->xml->addChild('theme');
+ $t->addAttribute('theme_id', $theme->theme_id);
+ $t->addAttribute('icones_id', $theme->icones);
+ foreach ($theme->parametres as $k => $v) {
+ $t->addChild($k, $v);
+ }
+ }
+
+ public function getThemeForms()
+ {
+ global $core;
+ $dao = new wsDAOTheme($core->con);
+ $theme = $dao->selectById($this->args['theme_id']);
+
+ foreach ($theme->parametres->getForms() as $name) {
+ $f = $this->xml->addChild('form', json_encode($theme->parametres->getForm($name)));
+ $f->addAttribute('name', $name);
+ }
+ }
+
+ public function getFluidbookForms()
+ {
+ global $core;
+ $dao = new wsDAOBook($core->con);
+ $book = $dao->selectById($this->args['book_id']);
+ foreach ($book->parametres->getForms() as $name) {
+ $f = $this->xml->addChild('form', html::escapeHTML(json_encode($book->parametres->getForm($name))));
+ $f->addAttribute('name', $name);
+ }
+ }
+
+ public function saveSettings()
+ {
+ global $core;
+ $dao = new wsDAOBook($core->con);
+
+ $pages = $dao->getPagesOfBook($this->args['book_id']);
+ $nb_pages = count($pages);
+
+ $daoDoc = new wsDAODocument($core->con);
+ $firstDoc = $daoDoc->selectById($pages[1]['document_id']);
+ $size = $firstDoc->generalInfos['size'];
+
+ $settings = json_decode($this->args['settings'], false);
+ $settings->width = $size[0];
+ $settings->height = $size[1];
+
+ $dao->setSettings($this->args['book_id'], $settings);
+ }
+
+ public function setChapters()
+ {
+ global $core;
+ $dao = new wsDAOBook($core->con);
+ $dao->setChapters($this->args['book_id'], $this->args['chapters']);
+ }
+
+ public function getChapters()
+ {
+ global $core;
+ $dao = new wsDAOBook($core->con);
+ $book = $dao->selectById($this->args['book_id']);
+ $this->xml->addChild('chapters', html::escapeHTML(json_encode($book->chapters)));
+ }
+
+ public function getLinks()
+ {
+ global $core;
+
+ set_time_limit(0);
+
+ $dao = new wsDAOBook($core->con);
+ $book = $dao->selectById($this->args['book_id']);
+
+ $pages = $dao->getPagesOfBook($this->args['book_id']);
+ $nb_pages = count($pages);
+
+ $daoDoc = new wsDAODocument($core->con);
+
+
+ $maxWidth = 0;
+ $maxHeight = 0;
+ foreach ($pages as $page) {
+ $doc = $daoDoc->selectById($page['document_id']);
+ $size = $doc->generalInfos['page'][$page['document_page']]['size'];
+
+ $maxWidth = max($size[0], $maxWidth);
+ $maxHeight = max($size[1], $maxHeight);
+ }
+
+
+ $daoDoc->getLinksAndRulers($this->args['book_id'], $links, $rulers);
+
+ $this->json = false;
+ $this->json = true;
+
+ $types = array(1, 2, 3, 4, 5, 6, 7, 11, 13, 14, 15, 16, 17, 18, 19, 24, 25);
+ if (wsDroits::revendeur()) {
+ $types = array(1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 24, 25, 31, 33);
+ }
+ if (wsDroits::admin()) {
+ $types = range(1, 100);
+ $links = wsLinks::decryptLinks($links);
+ }
+
+ if ($this->json) {
+ $this->jsonDatas['types'] = $types;
+ $this->jsonDatas['pages'] = $nb_pages;
+ $this->jsonDatas['numerotation'] = $book->numerotation;
+ $this->jsonDatas['width'] = $maxWidth;
+ $this->jsonDatas['height'] = $maxHeight;
+ $this->jsonDatas['links'] = $links;
+ $this->jsonDatas['rulers'] = $rulers;
+ } else {
+ $l = json_encode($links);
+ $l = html::escapeHTML($l);
+ $this->xml->addChild('width', $maxWidth);
+ $this->xml->addChild('height', $maxHeight);
+ $this->xml->addChild('pages', $nb_pages);
+ $this->xml->addChild('numerotation', $book->numerotation);
+ $this->xml->addChild('links', $l);
+ $this->xml->addChild('rulers', json_encode($rulers));
+ }
+
+ $daoTheme = new wsDAOTheme($this->con);
+ $theme = $daoTheme->getThemeOfBook($this->args['book_id'], true);
+
+ $specials = array('backgroundImage' => 'background', 'topBar' => 'topbar', 'afterSearch' => 'aftersearch', 'externalArchives' => 'archives');
+
+ foreach ($specials as $tparam => $sname) {
+ $this->_addSpecialInfos($book, $theme, $tparam, $sname);
+ }
+ }
+
+ protected function _addSpecialInfos($book, $theme, $param, $specialName)
+ {
+ if ($specialName == 'archives') {
+ $p = $book->parametres;
+ } else {
+ $p = $theme->parametres;
+ }
+
+
+ if ($p->$param != '') {
+ if ($specialName != 'archives') {
+ $themeRoot = WS_THEMES . '/' . $theme->theme_id . '/';
+ $dim = CubeIT_Image::getimagesize($themeRoot . $p->$param);
+ $url = 'https://' . $_SERVER['HTTP_HOST'] . WEBROOT . '/fluidbook/themes/' . $theme->theme_id . '/' . $p->$param;
+ } else {
+ $bookRoot = WS_BOOKS . '/working/' . $book->book_id . '/';
+ $dim = CubeIT_Image::getimagesize($bookRoot . $p->$param);
+ $url = 'https://' . $_SERVER['HTTP_HOST'] . WEBROOT . '/fluidbook/books/working/' . $book->book_id . '/' . $p->$param;
+ }
+
+ if ($this->json) {
+ $p = array('width' => $dim[0], 'height' => $dim[1], 'url' => $url);
+ $this->jsonDatas[$specialName] = $p;
+ } else {
+ $b = $this->xml->addChild($specialName);
+ $b->addChild('width', $dim[0]);
+ $b->addChild('height', $dim[1]);
+ $b->addChild('url', $url);
+ }
+ }
+ }
+
+ public function saveLinks()
+ {
+ global $core;
+
+ $comments = isset($this->args['comments']) ? $this->args['comments'] : 'Saved from editor';
+
+ $dao = new wsDAODocument($core->con);
+ $dao->setLinksAndRulers($this->args['book_id'], $this->args['links'], $this->args['rulers'], $comments, $core->user->utilisateur_id, false);
+
+ $daoBook = new wsDAOBook($core->con);
+ $daoBook->setSpecialLinksAndRulers($this->args['book_id'], $this->args['specialLinks'], $this->args['specialRulers']);
+
+ if (isset($this->args['getLinks'])) {
+ $this->getLinks();
+ }
+ }
+
+ public function formatSize($val)
+ {
+ $str = files::size($val);
+ $str = str_replace('.', __(','), $str);
+ $str = str_replace('B', __('o'), $str);
+ return $str;
+ }
+
+ public function getExtras()
+ {
+ global $core;
+ $dao = new wsDAOBook($core->con);
+ $book = $dao->selectById($this->args['book_id']);
+ if ($book->extras != '') {
+ $tidy = cubeXML::tidy('<extras>' . $book->extras . '</extras>');
+ $tidy = str_replace('<extras>', '', $tidy);
+ $tidy = str_replace('</extras>', '', $tidy);
+ $tidy = str_replace('<?xml version="1.0"?>', '', $tidy);
+ $tidy = trim($tidy);
+ $e = explode("\n", $tidy);
+ foreach ($e as $k => $v) {
+ if (substr($v, 0, 2) == ' ') {
+ $v = substr($v, 2);
+ }
+ $e[$k] = $v;
+ }
+
+ $extras = implode("\n", $e);
+ } else {
+ $extras = '';
+ }
+
+ $this->xml->addChild('extras', $extras);
+ }
+
+ public function saveExtras()
+ {
+ global $core;
+ $dao = new wsDAOBook($core->con);
+ $res = $dao->setExtras($this->args['book_id'], $this->args['extras']);
+ $this->xml->addChild('ok', $res ? '1' : '0');
+ }
+
+ public function getMetadata()
+ {
+ global $core;
+
+ $dao = new wsDAOBook($core->con);
+ $book = $dao->selectById($this->args['book_id']);
+
+ $this->xml->addChild('title', htmlspecialchars($book->nom));
+ $this->xml->addChild('date', $book->changedate);
+ }
+
+ public function getBookInfos()
+ {
+ global $core;
+ $dao = new wsDAOBook($core->con);
+ $book = $dao->selectById($this->args['book_id']);
+ $pages = $dao->getPagesOfBook($this->args['book_id'], false);
+ $daoDoc = new wsDAODocument($core->con);
+ $nb_pages = count($pages);
+ $this->xml->addChild('pages', $nb_pages);
+ $total_size = 0;
+
+ foreach ($pages as $page => $info) {
+ $docdir = wsDocument::getDir($info['document_id']);
+ $file = $docdir . '/p' . $info['document_page'] . '.swf';
+ $total_size += filesize($file);
+ }
+ $average_size = $total_size / $nb_pages;
+ $total = self::formatSize($total_size);
+ $average = self::formatSize($average_size);
+ $firstDoc = $daoDoc->selectById($pages[1]['document_id']);
+ $size = $firstDoc->generalInfos['size'];
+ $this->xml->addChild('width', $size[0]);
+ $this->xml->addChild('height', $size[1]);
+ $res = '<b>' . __('Nombre de pages') . '</b> : ';
+ $res .= $nb_pages . ' ' . __('pages') . "\n";
+ $res .= "\n";
+ $res .= '<b>' . __('Dimensions') . '</b> : ' . "\n";
+ $res .= round($size[0], 3) . ' x ' . round($size[1], 3) . ' pts' . "\n";
+ $res .= "\n";
+ $res .= '<b>' . __('Taille totale des pages') . '</b> : ' . "\n";
+ $res .= $total . "\n";
+ $res .= "\n";
+ $res .= '<b>' . __('Taille moyenne des pages') . '</b> : ' . "\n";
+ $res .= $average . "\n";
+ $res .= "\n";
+ $this->xml->addChild('infos', $res);
+ }
+
+ public function getLangs()
+ {
+ global $core;
+ if (isset($this->args['book_id'])) {
+ $dao = new wsDAOBook($core->con);
+ $book = $dao->selectById($this->args['book_id']);
+ $book->traductions = wsLang::checkTranslations($book->traductions);
+ if ($book->traductions != array()) {
+ //$bookLang = $this->xml->addChild('book_lang', json_encode($book->traductions));
+ $bookLang = (array)$book->traductions;
+ }
+ }
+
+ if (isset($bookLang)) {
+ if (wsLang::compare($bookLang, $book->lang)) {
+ unset($bookLang);
+ }
+ }
+
+ $dao = new wsDAOLang($core->con);
+ $langs = $dao->selectAll();
+ foreach ($langs as $lang) {
+ $nom = cubeLang::getNameByCode($lang->lang_id, $core->user->lang);
+ $l = $this->xml->addChild('lang', json_encode($lang->traductions));
+ $l->addAttribute('id', $lang->lang_id);
+ $l->addAttribute('nom', $nom);
+ if (isset($book) && $book->lang == $lang->lang_id) {
+ if (!isset($bookLang)) {
+ $l->addAttribute('selected', '1');
+ } else {
+ $trad = array_merge($lang->traductions, $bookLang);
+ $bl = $this->xml->addChild('book_lang', json_encode($trad));
+ $bl->addAttribute('id', $lang->lang_id);
+ $bl->addAttribute('nom', $nom . ' (' . __('modifié') . ')');
+ $bl->addAttribute('selected', '1');
+ }
+ }
+ }
+ }
+
+ public function saveLang()
+ {
+ global $core;
+ $dao = new wsDAOBook($core->con);
+ $dao->setLang($this->args['book_id'], $this->args['lang_id'], $this->args['traductions']);
+ }
+
+ public function saveComposition()
+ {
+ global $core;
+ $dao = new wsDAOBook($core->con);
+ $dao->setComposition($this->args['book_id'], json_decode($this->args['pages']));
+ }
+
+ public function getTexts()
+ {
+ $this->xml->addChild('texts', json_encode($GLOBALS['__l10n']));
+ }
+
+ public function copyLinks()
+ {
+ global $core;
+ $daoDocument = new wsDAODocument($core->con);
+ $daoDocument->copyLinks($this->args['fromDoc'], $this->args['toDoc']);
+ }
+
+ public function compile()
+ {
+ global $core;
+ wsSecureSWF::checkProtectedSWF();
+ $dao = new wsDAOBook($core->con);
+
+ $log = $dao->compile($this->args['book_id'], '2');
+
+ $book = $dao->selectById($this->args['book_id']);
+ $viewer = 'viewer';
+ /*if (wsDroits::admin()) {
+ $viewer = 'vieweru';
+ }*/
+
+ $absoluteURL = 'https://' . $_SERVER['HTTP_HOST'] . '/' . $viewer . '/' . $book->book_id . '_' . $book->hash . '_' . TIME . '/';
+ $this->xml->addChild('compiledBook', $absoluteURL . 'index.swf?base=' . $absoluteURL);
+ }
}
\ No newline at end of file