class wsExporter
{
- public $book_id;
- public $dao;
- public $book;
- public $action;
- public $metaAction;
- public $origVersion;
- public $origAction;
- public $version;
- public $destinationDir;
- public $destinationFile;
- public $x;
- public $ftpPassiveMode = false;
-
- const VINCENT = "paris.cubedesigners.com";
-
- public function exportCollection($collectionId, $os)
- {
- global $core;
-
-
- $ctrl = isset($_GET['ctrl']) && $_GET['ctrl'] == 'true';
- $alt = isset($_GET['alt']) && $_GET['alt'] == 'true';
-
- $run = CubeIT_Mobile_Phonegap::RUN_SYNC;
- $resetApp = false;
- if ($ctrl) {
- $resetApp = true;
- $run = CubeIT_Mobile_Phonegap::RUN_RUN;
- if ($alt) {
- $run = CubeIT_Mobile_Phonegap::RUN_CREATE;
- }
- }
-
- $compiler = new wsHTML5AppCompiler($collectionId);
- $dir = $compiler->compile($os, 'collection', $resetApp);
-
- $collection = $compiler->collection;
- $d = str_replace('.', '/', $collection->settings['namespace']);
- $dest = $d . '/www/';
-
- $phonegap = CubeIT_Mobile_Phonegap::create($os);
- $phonegap->setName($collection->nom);
- $phonegap->setId($collection->settings['namespace']);
- $phonegap->setAuthor('Fluidbook', 'contact@fluidbook.com', 'https://www.fluidbook.com');
- $phonegap->setVersion($collection->settings['version']);
- $phonegap->setBuild($collection->settings['build']);
- if ($os == 'android') {
- $phonegap->setLicenseKey($collection->settings['license_key']);
- $phonegap->setExpansion($collection->settings['android_storage'] !== 'apk');
- }
- $phonegap->setNamespace($collection->settings['namespace']);
- $phonegap->setActivity($collection->settings['activity']);
-
- $appNames = array();
-
- foreach ($compiler->langs as $l) {
- $src = $compiler->wdir . '/' . $collection->theme['splash_' . $l];
- $phonegap->setSplash($src, $l);
- $phonegap->setIcon($compiler->wdir . '/' . $collection->theme['icon'], $l);
- $appNames[$l] = $collection->contents[$l]['titrehome'];
- }
- $phonegap->setAppName($appNames);
- $phonegap->setWWWDirectory($dir);
- if ($os == 'ios') {
- $phonegap->setDistantCompiler(self::VINCENT, 'vincent', 'atacama', '/Users/vincent/Phonegap/Projects/' . $d, '/mnt/macbox/Phonegap/Projects/' . $d, 22022, SSH_KEY);
- } else if ($os == 'android') {
- $manifestType = isset($collection->settings['offline']) ? 'Offline' : 'Online';
- if (!$phonegap->getExpansion()) {
- $manifestType .= 'Standalone';
- }
- $phonegap->setManifest(WS_COMPILE_ASSETS . '/_html5app/_android/AndroidManifest' . $manifestType . '.xml');
- $phonegap->setMain(WS_COMPILE_ASSETS . '/_html5app/_android/Main' . $manifestType . '.java');
- $phonegap->setMainDir(WS_COMPILE_ASSETS . '/_html5app/_android/');
-
- if ($phonegap->getExpansion()) {
- $phonegap->addLibrary(array('from' => WS_COMPILE_ASSETS . '/_html5app/_android/lib', 'to' => '/app/src/main/java'));
- } else {
- $phonegap->addLibrary(array('from' => WS_COMPILE_ASSETS . '/_html5app/_android/lib/com/fluidbook', 'to' => '/app/src/main/java/com/fluidbook'));
- }
- $phonegap->addLibrary(array('from' => WS_COMPILE_ASSETS . '/_html5app/_android/fluidbook-dependencies', 'to' => '/fluidbook-dependencies'));
- $phonegap->addLibrary(array('from' => WS_COMPILE_ASSETS . '/_html5app/_android/res', 'to' => '/app/src/main/res'));
-
- $phonegap->setDistantCompiler(self::VINCENT, 'Vincent', 's77vpo*wu5', 'h:/Phonegap/Projects/' . $d, '/mnt/vincent/cygdrive/h/Phonegap/Projects/' . $d, 22322, SSH_KEY);
- $phonegap->setSourceVariables(array('background' => '0xff' . $collection->settings['couleurD'],
- 'orientation' => $collection->settings['orientation'])
- );
- $phonegap->fileDistantReplaceContents('// PLUGIN GRADLE EXTENSIONS START' . "\r\n" . '// PLUGIN GRADLE EXTENSIONS END',
- '// PLUGIN GRADLE EXTENSIONS START' . "\r\n" . 'apply from: "fluidbook-dependencies/catalogues-fluidbook.gradle"' . "\r\n" . '// PLUGIN GRADLE EXTENSIONS END',
- 'platforms/android/build.gradle');
- $phonegap->fileDistantReplaceContents('// PLUGIN GRADLE EXTENSIONS START' . "\n" . '// PLUGIN GRADLE EXTENSIONS END',
- '// PLUGIN GRADLE EXTENSIONS START' . "\n" . 'apply from: "fluidbook-dependencies/catalogues-fluidbook.gradle"' . "\n" . '// PLUGIN GRADLE EXTENSIONS END',
- 'platforms/android/build.gradle');
- }
-
- $phonegap->setPreference('show-splash-screen-spinner', false);
- $phonegap->setPreference('auto-hide-splash-screen', false);
- $phonegap->setPreference('ios-statusbarstyle', CubeIT_Mobile_Phonegap::BARSTYLE_TRANSLUCENT);
- $phonegap->setPreference('iosPersistentFileLocation', 'Library');
- $phonegap->setPreference('EnableViewportScale', true);
- $phonegap->addFeatures(array(
- CubeIT_Mobile_Phonegap::FEATURE_CONNECTION,
- CubeIT_Mobile_Phonegap::FEATURE_DEVICE,
- CubeIT_Mobile_Phonegap::FEATURE_FILE,
- CubeIT_Mobile_Phonegap::FEATURE_FILETRANSFER,
- CubeIT_Mobile_Phonegap::FEATURE_STORAGE,
- CubeIT_Mobile_Phonegap::FEATURE_NOTIFICATION_DIALOG,
- CubeIT_Mobile_Phonegap::FEATURE_INAPPBROWSER,
- CubeIT_Mobile_Phonegap::FEATURE_SPLASHSCREEN,
- CubeIT_Mobile_Phonegap::FEATURE_GLOBALIZATION,
- //CubeIT_Mobile_Phonegap::FEATURE_PUSHNOTIFICATION,
- CubeIT_Mobile_Phonegap::FEATURE_DEBUG
- )
- );
- if ($os == 'ios') {
- $phonegap->addFeature(CubeIT_Mobile_Phonegap::FEATURE_EXTERNALFILEUTIL);
- $phonegap->addFeature(CubeIT_Mobile_Phonegap::FEATURE_STATUSBAR);
- //$phonegap->addFeature(CubeIT_Mobile_Phonegap_IOS::FEATURE_WKWEBVIEW);
- } else if ($os == 'android') {
- $phonegap->addFeature(CubeIT_Mobile_Phonegap::FEATURE_WEBINTENT);
- }
-
-
- $allpub = $compiler->books;
-
- if (isset($collection->settings['offline']) && $collection->settings['offline']) {
- $p = $compiler->getPublishedVersionPath($os, $collection->settings['version']);
- if ($p) {
- $phonegap->addAdditionalSource('publications', $p);
-
- $exs = explode("\n", $collection->settings['offline_exclude']);
- foreach ($exs as $e) {
- $e = trim($e);
- if ($e == '') {
- continue;
- }
-
- if (stristr($e, '$id$')) {
- foreach ($allpub as $i) {
- $phonegap->addExclude('"' . str_replace('$id$', $i, $e) . '"');
- }
- } else {
- $phonegap->addExclude('"' . $e . '"');
- }
- }
-
- $add = explode("\n", $collection->settings['offline_syncs']);
- foreach ($add as $a) {
- $a = trim($a);
- if ($a == '' || substr($a, 0, 1) == '#' || substr($a, 0, 1) == ';') {
- continue;
- }
- list($to, $source) = explode(':', $a);
- $phonegap->addAdditionalSource('publications' . '/' . $to, $p . $source);
- }
- }
- }
-
- $phonegap->run($run);
- }
-
- /**
- *
- * @param string $os
- * @param wsHTML5AppCompiler $compiler
- */
- protected function _collectionAssets($os, $compiler)
- {
- if ($os == 'ios') {
- $this->_collectionAssetsIOS($os, $compiler);
- } else if ($os == 'android') {
- $this->_collectionAssetsAndroid($os, $compiler);
- }
- }
-
- protected function _collectionAssetsAndroid($os, $compiler)
- {
- $collection = $compiler->collection;
- $src = $compiler->wdir . '/' . $collection->theme['icon'];
- }
-
- protected function _collectionAssetsIOS($os, $compiler)
- {
- $collection = $compiler->collection;
- $src = $compiler->wdir . '/' . $collection->theme['icon'];
- // icones
- $icons = array(57 => 'icon', 72 => 'icon-72', 114 => 'icon@2x', 144 => 'icon-72@2x');
- $d = WS_COLLECTIONS . '/resources/' . $collection->collection_id . '/' . $os . '/icons/';
- if (!file_exists($d)) {
- mkdir($d, 0777, true);
- }
- foreach ($icons as $s => $n) {
-
- $dest = $d . $n . '.png';
- if (!$this->_testFile($src, $dest)) {
- wsPackagerPhonegap::__makeIcon($src, $dest, $s);
- }
- }
-
- // splashs
- $splashs = array('320x480' => 'Default~iphone', '640x960' => 'Default@2x~iphone', '1024x748' => 'Default-Landscape~ipad', '768x1004' => 'Default-Portrait~ipad', '2048x1496' => 'Default-Landscape@2x~ipad', '1536x2008' => 'Default-Portrait@2x~ipad', '640x1136' => 'Default-568h@2x~iphone');
-
- $langs = $compiler->langs;
-
- foreach ($langs as $l) {
- $src = $compiler->wdir . '/' . $collection->theme['splash_' . $l];
- if (!file_exists($src)) {
- continue;
- }
-
- $d = WS_COLLECTIONS . '/resources/' . $collection->collection_id . '/' . $os . '/splash/' . $l . '.lproj/';
- if (!file_exists($d)) {
- mkdir($d, 0777, true);
- }
-
-
- foreach ($splashs as $size => $name) {
- list($width, $height) = explode('x', $size);
-
- $dest = $d . $name . '.png';
-
- if (!$this->_testFile($src, $dest)) {
- $it = new cubeImageTools();
- $it->loadImage($src);
- $it->resize($width, $height, 'crop', false, 'C', 'M', 'transparent');
- $it->output('png', $dest);
- }
- }
- }
-
-
- // Transfert
- $this->_rsync(WS_COLLECTIONS . '/resources/' . $collection->collection_id . '/' . $os, "/mnt/macbox" . $this->_iosProjectDir($collection->settings['namespace']) . '/' . CubeIT_Text::str2URL($collection->nom) . '/Resources', false);
- }
-
- protected function _testFile($ref, $dest)
- {
- if (!file_exists($dest)) {
- return false;
- }
- if (filemtime($ref) > filemtime($dest)) {
- return false;
- }
- return true;
- }
-
- protected function _createProject($os, $name, $ns)
- {
- if ($os == 'ios') {
- $dir = $this->_iosProjectDir($ns);
- $sdir = '/mnt/macbox' . $dir;
- if (!file_exists($sdir)) {
- `sudo /usr/local/bin/remountmac`;
- mkdir($sdir, 0777, true);
- $cl = new CubeIT_CommandLine('/Phonegap/Cordova/bin/create');
- $cl->setArg(null, $dir);
- $cl->setArg(null, $ns);
- $cl->setArg(null, CubeIT_Text::str2URL($name));
- $cl->setSSH(self::VINCENT, 'vincent', '', 22022);
- $cl->execute();
- // Install plugins
- $this->_iosPlugin($dir, 'PushPlugin');
- $this->_iosPlugin($dir, 'ExternalFileUtil');
- }
- } elseif ($os == 'android') {
-
- }
- }
-
- protected function _iosProjectDir($ns)
- {
- return '/Phonegap/Projects/' . str_replace('.', '/', $ns);
- }
-
- protected function _iosPlugin($dir, $plugin)
- {
- // git@github.com:phonegap-build/PushPlugin.git
- $cl = new CubeIT_CommandLine('/usr/local/bin/plugman');
- $cl->setManualArg(' --platform ios');
- $cl->setManualArg(' --project ' . $dir);
- $cl->setManualArg(' --plugin /Phonegap/Plugins/' . $plugin);
- $cl->setSSH(self::VINCENT, 'vincent', '', 22022);
- $cl->execute();
- }
-
- public function export($book_id, &$x, $action = 'download', $version = 'online', $destinationDir = null, $destinationFile = null)
- {
- global $core;
- set_time_limit(0);
-
- if (is_null($destinationDir)) {
- $destinationDir = '';
- }
- if (is_null($destinationFile)) {
- $destinationFile = '';
- }
-
- $this->origVersion = $version;
- $this->origAction = $action;
-
- $this->book_id = $book_id;
- $this->x = $x;
-
- $this->dao = new wsDAOBook($core->con);
- $this->book = $this->dao->selectById($this->book_id);
-
- $this->action = $action;
- $e = explode('_', $this->action, 2);
- $this->metaAction = $e[0];
- if (count($e) > 1) {
- $this->action = $e[1];
- }
-
- $this->version = $this->_getVersion($version);
- $this->destinationDir = ltrim(trim($destinationDir), '/');
- $this->destinationFile = str_replace('/', '-', trim($destinationFile));
-
- $this->_saveDestination();
-
- if ($this->metaAction == 'download') {
- $this->_download();
- } else if ($this->metaAction == 'phonegap') {
- $this->_phonegap();
- } else if ($this->metaAction == 'install') {
- $this->_install();
- } else if ($this->metaAction == 'phonegapcollection') {
- $this->_phonegapcollection();
- }
- }
-
- protected function _haveToZip()
- {
- $yes = array('win-exe', 'mac-exe', 'win-cd');
- return in_array($this->version, $yes);
- }
-
- protected function _phonegapcollection()
- {
- $d = '/' . $this->destinationDir;
-
- $packager = new wsPackagerPhonegap($this->book_id, $d, true, false, $this->version);
- $packager->home = true;
- $packager->book->parametres->mobileVideosPath = '';
-
- return $packager->makePackage(false);
- }
-
- protected function _killFtp($book_id)
- {
- $kill = 'pkill -f "^lftp(.*)' . $book_id . '"';
- `$kill`;
- }
-
- protected function _install()
- {
- $this->_killFtp($this->book_id);
-
- $p = wsPackager::package($this->book_id, $this->version, $this->_haveToZip(), false);
-
- if (strpos($p, '/fluidbook') == 0) {
- $p = ROOT . $p;
- }
-
-
- if ($this->action == 'references') {
- //$root = 'fluidbook@www.fluidbook.com:/home/fluidbook/www/references/';
- $root = '/mnt/sshfs/fluidbook/home/fluidbook/www/references/';
- $rootURL = 'https://www.fluidbook.com/references/';
- } else if ($this->action == 'hosting') {
- $root = '/mnt/sshfs/fluidbook/data/fluidbook/hosting/';
- $rootURL = 'https://hosting.fluidbook.com/';
- } else if ($this->action == 'ftp') {
- $root = 'ftp://';
- $rootURL = null;
- }
-
- if ($this->destinationFile) {
- $pathd = $root . $this->destinationDir;
- $path = $pathd . '/' . $this->destinationFile;
- } else {
- $path = $root . $this->destinationDir;
- }
-
- if (stristr($path, 'ftp://')) {
- $this->_killFtp($this->book_id);
- $this->_lftp($p, $path, $this->ftpPassiveMode);
- } else {
- $this->_rsync($p, $path);
- }
-
- if (!is_null($rootURL)) {
- $url = $rootURL . $this->destinationDir;
- if($this->x) {
+ public $book_id;
+ public $dao;
+ public $book;
+ public $action;
+ public $metaAction;
+ public $origVersion;
+ public $origAction;
+ public $version;
+ public $destinationDir;
+ public $destinationFile;
+ public $x;
+ public $ftpPassiveMode = false;
+
+ const VINCENT = "paris.cubedesigners.com";
+
+ public function exportCollection($collectionId, $os)
+ {
+ global $core;
+
+
+ $ctrl = isset($_GET['ctrl']) && $_GET['ctrl'] == 'true';
+ $alt = isset($_GET['alt']) && $_GET['alt'] == 'true';
+
+ $run = CubeIT_Mobile_Phonegap::RUN_SYNC;
+ $resetApp = false;
+ if ($ctrl) {
+ $resetApp = true;
+ $run = CubeIT_Mobile_Phonegap::RUN_RUN;
+ if ($alt) {
+ $run = CubeIT_Mobile_Phonegap::RUN_CREATE;
+ }
+ }
+
+ $compiler = new wsHTML5AppCompiler($collectionId);
+ $dir = $compiler->compile($os, 'collection', $resetApp);
+
+ $collection = $compiler->collection;
+ $d = str_replace('.', '/', $collection->settings['namespace']);
+ $dest = $d . '/www/';
+
+ $phonegap = CubeIT_Mobile_Phonegap::create($os);
+ $phonegap->setName($collection->nom);
+ $phonegap->setId($collection->settings['namespace']);
+ $phonegap->setAuthor('Fluidbook', 'contact@fluidbook.com', 'https://www.fluidbook.com');
+ $phonegap->setVersion($collection->settings['version']);
+ $phonegap->setBuild($collection->settings['build']);
+ if ($os == 'android') {
+ $phonegap->setLicenseKey($collection->settings['license_key']);
+ $phonegap->setExpansion($collection->settings['android_storage'] !== 'apk');
+ }
+ $phonegap->setNamespace($collection->settings['namespace']);
+ $phonegap->setActivity($collection->settings['activity']);
+
+ $appNames = array();
+
+ foreach ($compiler->langs as $l) {
+ $src = $compiler->wdir . '/' . $collection->theme['splash_' . $l];
+ $phonegap->setSplash($src, $l);
+ $phonegap->setIcon($compiler->wdir . '/' . $collection->theme['icon'], $l);
+ $appNames[$l] = $collection->contents[$l]['titrehome'];
+ }
+ $phonegap->setAppName($appNames);
+ $phonegap->setWWWDirectory($dir);
+ if ($os == 'ios') {
+ $phonegap->setDistantCompiler(self::VINCENT, 'vincent', 'atacama', '/Users/vincent/Phonegap/Projects/' . $d, '/mnt/macbox/Phonegap/Projects/' . $d, 22022, SSH_KEY);
+ } else if ($os == 'android') {
+ $manifestType = isset($collection->settings['offline']) ? 'Offline' : 'Online';
+ if (!$phonegap->getExpansion()) {
+ $manifestType .= 'Standalone';
+ }
+ $phonegap->setManifest(WS_COMPILE_ASSETS . '/_html5app/_android/AndroidManifest' . $manifestType . '.xml');
+ $phonegap->setMain(WS_COMPILE_ASSETS . '/_html5app/_android/Main' . $manifestType . '.java');
+ $phonegap->setMainDir(WS_COMPILE_ASSETS . '/_html5app/_android/');
+
+ if ($phonegap->getExpansion()) {
+ $phonegap->addLibrary(array('from' => WS_COMPILE_ASSETS . '/_html5app/_android/lib', 'to' => '/app/src/main/java'));
+ } else {
+ $phonegap->addLibrary(array('from' => WS_COMPILE_ASSETS . '/_html5app/_android/lib/com/fluidbook', 'to' => '/app/src/main/java/com/fluidbook'));
+ }
+ $phonegap->addLibrary(array('from' => WS_COMPILE_ASSETS . '/_html5app/_android/fluidbook-dependencies', 'to' => '/fluidbook-dependencies'));
+ $phonegap->addLibrary(array('from' => WS_COMPILE_ASSETS . '/_html5app/_android/res', 'to' => '/app/src/main/res'));
+
+ $phonegap->setDistantCompiler(self::VINCENT, 'Vincent', 's77vpo*wu5', 'h:/Phonegap/Projects/' . $d, '/mnt/vincent/cygdrive/h/Phonegap/Projects/' . $d, 22322, SSH_KEY);
+ $phonegap->setSourceVariables(array('background' => '0xff' . $collection->settings['couleurD'],
+ 'orientation' => $collection->settings['orientation'])
+ );
+ $phonegap->fileDistantReplaceContents('// PLUGIN GRADLE EXTENSIONS START' . "\r\n" . '// PLUGIN GRADLE EXTENSIONS END',
+ '// PLUGIN GRADLE EXTENSIONS START' . "\r\n" . 'apply from: "fluidbook-dependencies/catalogues-fluidbook.gradle"' . "\r\n" . '// PLUGIN GRADLE EXTENSIONS END',
+ 'platforms/android/build.gradle');
+ $phonegap->fileDistantReplaceContents('// PLUGIN GRADLE EXTENSIONS START' . "\n" . '// PLUGIN GRADLE EXTENSIONS END',
+ '// PLUGIN GRADLE EXTENSIONS START' . "\n" . 'apply from: "fluidbook-dependencies/catalogues-fluidbook.gradle"' . "\n" . '// PLUGIN GRADLE EXTENSIONS END',
+ 'platforms/android/build.gradle');
+ }
+
+ $phonegap->setPreference('show-splash-screen-spinner', false);
+ $phonegap->setPreference('auto-hide-splash-screen', false);
+ $phonegap->setPreference('ios-statusbarstyle', CubeIT_Mobile_Phonegap::BARSTYLE_TRANSLUCENT);
+ $phonegap->setPreference('iosPersistentFileLocation', 'Library');
+ $phonegap->setPreference('EnableViewportScale', true);
+ $phonegap->addFeatures(array(
+ CubeIT_Mobile_Phonegap::FEATURE_CONNECTION,
+ CubeIT_Mobile_Phonegap::FEATURE_DEVICE,
+ CubeIT_Mobile_Phonegap::FEATURE_FILE,
+ CubeIT_Mobile_Phonegap::FEATURE_FILETRANSFER,
+ CubeIT_Mobile_Phonegap::FEATURE_STORAGE,
+ CubeIT_Mobile_Phonegap::FEATURE_NOTIFICATION_DIALOG,
+ CubeIT_Mobile_Phonegap::FEATURE_INAPPBROWSER,
+ CubeIT_Mobile_Phonegap::FEATURE_SPLASHSCREEN,
+ CubeIT_Mobile_Phonegap::FEATURE_GLOBALIZATION,
+ //CubeIT_Mobile_Phonegap::FEATURE_PUSHNOTIFICATION,
+ CubeIT_Mobile_Phonegap::FEATURE_DEBUG
+ )
+ );
+ if ($os == 'ios') {
+ $phonegap->addFeature(CubeIT_Mobile_Phonegap::FEATURE_EXTERNALFILEUTIL);
+ $phonegap->addFeature(CubeIT_Mobile_Phonegap::FEATURE_STATUSBAR);
+ //$phonegap->addFeature(CubeIT_Mobile_Phonegap_IOS::FEATURE_WKWEBVIEW);
+ } else if ($os == 'android') {
+ $phonegap->addFeature(CubeIT_Mobile_Phonegap::FEATURE_WEBINTENT);
+ }
+
+
+ $allpub = $compiler->books;
+
+ if (isset($collection->settings['offline']) && $collection->settings['offline']) {
+ $p = $compiler->getPublishedVersionPath($os, $collection->settings['version']);
+ if ($p) {
+ $phonegap->addAdditionalSource('publications', $p);
+
+ $exs = explode("\n", $collection->settings['offline_exclude']);
+ foreach ($exs as $e) {
+ $e = trim($e);
+ if ($e == '') {
+ continue;
+ }
+
+ if (stristr($e, '$id$')) {
+ foreach ($allpub as $i) {
+ $phonegap->addExclude('"' . str_replace('$id$', $i, $e) . '"');
+ }
+ } else {
+ $phonegap->addExclude('"' . $e . '"');
+ }
+ }
+
+ $add = explode("\n", $collection->settings['offline_syncs']);
+ foreach ($add as $a) {
+ $a = trim($a);
+ if ($a == '' || substr($a, 0, 1) == '#' || substr($a, 0, 1) == ';') {
+ continue;
+ }
+ list($to, $source) = explode(':', $a);
+ $phonegap->addAdditionalSource('publications' . '/' . $to, $p . $source);
+ }
+ }
+ }
+
+ $phonegap->run($run);
+ }
+
+ /**
+ *
+ * @param string $os
+ * @param wsHTML5AppCompiler $compiler
+ */
+ protected function _collectionAssets($os, $compiler)
+ {
+ if ($os == 'ios') {
+ $this->_collectionAssetsIOS($os, $compiler);
+ } else if ($os == 'android') {
+ $this->_collectionAssetsAndroid($os, $compiler);
+ }
+ }
+
+ protected function _collectionAssetsAndroid($os, $compiler)
+ {
+ $collection = $compiler->collection;
+ $src = $compiler->wdir . '/' . $collection->theme['icon'];
+ }
+
+ protected function _collectionAssetsIOS($os, $compiler)
+ {
+ $collection = $compiler->collection;
+ $src = $compiler->wdir . '/' . $collection->theme['icon'];
+ // icones
+ $icons = array(57 => 'icon', 72 => 'icon-72', 114 => 'icon@2x', 144 => 'icon-72@2x');
+ $d = WS_COLLECTIONS . '/resources/' . $collection->collection_id . '/' . $os . '/icons/';
+ if (!file_exists($d)) {
+ mkdir($d, 0777, true);
+ }
+ foreach ($icons as $s => $n) {
+
+ $dest = $d . $n . '.png';
+ if (!$this->_testFile($src, $dest)) {
+ wsPackagerPhonegap::__makeIcon($src, $dest, $s);
+ }
+ }
+
+ // splashs
+ $splashs = array('320x480' => 'Default~iphone', '640x960' => 'Default@2x~iphone', '1024x748' => 'Default-Landscape~ipad', '768x1004' => 'Default-Portrait~ipad', '2048x1496' => 'Default-Landscape@2x~ipad', '1536x2008' => 'Default-Portrait@2x~ipad', '640x1136' => 'Default-568h@2x~iphone');
+
+ $langs = $compiler->langs;
+
+ foreach ($langs as $l) {
+ $src = $compiler->wdir . '/' . $collection->theme['splash_' . $l];
+ if (!file_exists($src)) {
+ continue;
+ }
+
+ $d = WS_COLLECTIONS . '/resources/' . $collection->collection_id . '/' . $os . '/splash/' . $l . '.lproj/';
+ if (!file_exists($d)) {
+ mkdir($d, 0777, true);
+ }
+
+
+ foreach ($splashs as $size => $name) {
+ list($width, $height) = explode('x', $size);
+
+ $dest = $d . $name . '.png';
+
+ if (!$this->_testFile($src, $dest)) {
+ $it = new cubeImageTools();
+ $it->loadImage($src);
+ $it->resize($width, $height, 'crop', false, 'C', 'M', 'transparent');
+ $it->output('png', $dest);
+ }
+ }
+ }
+
+
+ // Transfert
+ $this->_rsync(WS_COLLECTIONS . '/resources/' . $collection->collection_id . '/' . $os, "/mnt/macbox" . $this->_iosProjectDir($collection->settings['namespace']) . '/' . CubeIT_Text::str2URL($collection->nom) . '/Resources', false);
+ }
+
+ protected function _testFile($ref, $dest)
+ {
+ if (!file_exists($dest)) {
+ return false;
+ }
+ if (filemtime($ref) > filemtime($dest)) {
+ return false;
+ }
+ return true;
+ }
+
+ protected function _createProject($os, $name, $ns)
+ {
+ if ($os == 'ios') {
+ $dir = $this->_iosProjectDir($ns);
+ $sdir = '/mnt/macbox' . $dir;
+ if (!file_exists($sdir)) {
+ `sudo /usr/local/bin/remountmac`;
+ mkdir($sdir, 0777, true);
+ $cl = new CubeIT_CommandLine('/Phonegap/Cordova/bin/create');
+ $cl->setArg(null, $dir);
+ $cl->setArg(null, $ns);
+ $cl->setArg(null, CubeIT_Text::str2URL($name));
+ $cl->setSSH(self::VINCENT, 'vincent', '', 22022);
+ $cl->execute();
+ // Install plugins
+ $this->_iosPlugin($dir, 'PushPlugin');
+ $this->_iosPlugin($dir, 'ExternalFileUtil');
+ }
+ } elseif ($os == 'android') {
+
+ }
+ }
+
+ protected function _iosProjectDir($ns)
+ {
+ return '/Phonegap/Projects/' . str_replace('.', '/', $ns);
+ }
+
+ protected function _iosPlugin($dir, $plugin)
+ {
+ // git@github.com:phonegap-build/PushPlugin.git
+ $cl = new CubeIT_CommandLine('/usr/local/bin/plugman');
+ $cl->setManualArg(' --platform ios');
+ $cl->setManualArg(' --project ' . $dir);
+ $cl->setManualArg(' --plugin /Phonegap/Plugins/' . $plugin);
+ $cl->setSSH(self::VINCENT, 'vincent', '', 22022);
+ $cl->execute();
+ }
+
+ public function export($book_id, &$x, $action = 'download', $version = 'online', $destinationDir = null, $destinationFile = null)
+ {
+ global $core;
+ set_time_limit(0);
+
+ if (is_null($destinationDir)) {
+ $destinationDir = '';
+ }
+ if (is_null($destinationFile)) {
+ $destinationFile = '';
+ }
+
+ $this->origVersion = $version;
+ $this->origAction = $action;
+
+ $this->book_id = $book_id;
+ $this->x = $x;
+
+ $this->dao = new wsDAOBook($core->con);
+ $this->book = $this->dao->selectById($this->book_id);
+
+ $this->action = $action;
+ $e = explode('_', $this->action, 2);
+ $this->metaAction = $e[0];
+ if (count($e) > 1) {
+ $this->action = $e[1];
+ }
+
+ $this->version = $this->_getVersion($version);
+ $this->destinationDir = ltrim(trim($destinationDir), '/');
+ $this->destinationFile = str_replace('/', '-', trim($destinationFile));
+
+ $this->_saveDestination();
+
+ if ($this->metaAction == 'download') {
+ $this->_download();
+ } else if ($this->metaAction == 'phonegap') {
+ $this->_phonegap();
+ } else if ($this->metaAction == 'install') {
+ $this->_install();
+ } else if ($this->metaAction == 'phonegapcollection') {
+ $this->_phonegapcollection();
+ }
+ }
+
+ protected function _haveToZip()
+ {
+ $yes = array('win-exe', 'mac-exe', 'win-cd');
+ return in_array($this->version, $yes);
+ }
+
+ protected function _phonegapcollection()
+ {
+ $d = '/' . $this->destinationDir;
+
+ $packager = new wsPackagerPhonegap($this->book_id, $d, true, false, $this->version);
+ $packager->home = true;
+ $packager->book->parametres->mobileVideosPath = '';
+
+ return $packager->makePackage(false);
+ }
+
+ protected function _killFtp($book_id)
+ {
+ $kill = 'pkill -f "^lftp(.*)' . $book_id . '"';
+ `$kill`;
+ }
+
+ protected function _install()
+ {
+ $this->_killFtp($this->book_id);
+
+ $p = wsPackager::package($this->book_id, $this->version, $this->_haveToZip(), false);
+
+ if (strpos($p, '/fluidbook') == 0) {
+ $p = ROOT . $p;
+ }
+
+
+ if ($this->action == 'references') {
+ //$root = 'fluidbook@www.fluidbook.com:/home/fluidbook/www/references/';
+ $root = '/mnt/sshfs/fluidbook/home/fluidbook/www/references/';
+ $rootURL = 'https://www.fluidbook.com/references/';
+ } else if ($this->action == 'hosting') {
+ $root = '/mnt/sshfs/fluidbook/data/fluidbook/hosting/';
+ $rootURL = 'https://hosting.fluidbook.com/';
+ } else if ($this->action == 'ftp') {
+ $root = 'ftp://';
+ $rootURL = null;
+ }
+
+ if ($this->destinationFile) {
+ $pathd = $root . $this->destinationDir;
+ $path = $pathd . '/' . $this->destinationFile;
+ } else {
+ $path = $root . $this->destinationDir;
+ }
+
+ if (stristr($path, 'ftp://')) {
+ $this->_killFtp($this->book_id);
+ $this->_lftp($p, $path, $this->ftpPassiveMode);
+ } else {
+ $this->_rsync($p, $path);
+ }
+
+ if (!is_null($rootURL)) {
+ $url = $rootURL . $this->destinationDir;
+ if ($this->x) {
$this->x->addTruePopup($url . '/');
}
- }
- }
-
- protected function _phonegap()
- {
- $os = $this->action;
-
- if ($this->destinationDir == '') {
- return;
- }
-
- $packager = new wsPackagerPhonegap($this->book_id, null, true, false, $os);
- $packager->cleanOnDestruct = false;
- $package = $packager->makePackage(false);
-
- $this->_transfertPhonegap($os, $package, $this->destinationDir);
- }
-
- protected function _transfertPhonegap($os, $package, $destination)
- {
- if ($os == 'android') {
- `sudo /usr/local/bin/remountvincent`;
- $this->_rsync($package, '/mnt/vincent/cygdrive/h/Works/Phonegap/Projects/' . $destination, true);
- } else if ($os == 'ios') {
- `sudo /usr/local/bin/remountmac`;
- $this->_rsync($package, '/mnt/macbox/Phonegap/Projects/' . $destination, true);
- }
- }
-
- protected function _lftp($src, $dest, $passive = false, $erase = false)
- {
- set_time_limit(0);
- $u = parse_url($dest);
-
- $file = is_file($src);
- if ($file) {
- $e = explode('/', $u['path']);
- $u['file'] = array_pop($e);
- $u['dir'] = implode('/', $e);
- } else {
- $u['dir'] = $u['path'];
- }
- if ($u['dir'] == '') {
- $u['dir'] = '/';
- }
-
- $passive = $passive ? 'on' : 'off';
-
- if (!isset($u['port'])) {
- $u['port'] = '21';
- }
-
- $commandes = array(
- 'set ftp:ssl-allow false',
- 'mkdir -p ' . $u['dir']
- );
-
- if ($file) {
- $commandes[] = 'put -O ' . $u['dir'] . ' ' . $src . ' -o ' . $u['file'];
- } else {
- $commandes[] = 'lcd ' . $src;
- $commandes[] = 'cd ' . $u['dir'];
- if ($erase) {
- $commandes[] = 'mirror -Rve';
- } else {
- $commandes[] = 'mirror -Rv';
- }
- }
-
- if (!file_exists($src)) {
- return;
- }
-
- $lftp = new CubeIT_CommandLine('lftp');
- $lftp->setArg('u', $u['user'] . ',' . $u['pass']);
- $lftp->setArg('p', $u['port']);
- $lftp->setArg('e', implode(';', $commandes));
- $lftp->setArg(null, $u['host']);
- $lftp->execute();
- $lftp->debug();
- }
-
- protected function _rsync($src, $dest, $erase = false, $chown = null)
- {
- set_time_limit(0);
- /*if (is_file($src)) {
- $dir = dirname($dest);
- if (!file_exists($dir)) {
- mkdir($dir, 0777, true);
- }
- copy($src, $dest);
- if (!is_null($chown)) {
- `chown $chown $dest`;
- }
- return;
- }*/
-
- $cl = new CubeIT_CommandLine_Rsync($src, $dest, $erase);
- $cl->setProg('/usr/bin/rsync');
- $cl->execute();
- if (!is_null($chown)) {
- `chown -R $chown $dest`;
- }
- }
-
- protected function _download()
- {
- $r = wsPackager::package($this->book_id, $this->version);
- $this->x->addRedirection($r);
- }
-
- protected function _getVersion($version)
- {
- if ($version == 'v2') {
- return 'html';
- } else if ($version == 'online') {
- if ($this->book->parametres->version == '1') {
- return 'v1';
- } elseif ($this->book->parametres->version == '2') {
- return 'html';
- }
- }
- return $version;
- }
-
- protected function _saveDestination()
- {
- $datas = $this->book->exportdatas;
- if ($datas == '') {
- $datas = array();
- } else {
- $datas = json_decode($datas, true);
- }
- if (!isset($datas[$this->origAction])) {
- $datas[$this->origAction] = array();
- }
-
- $d = array();
- if ($this->destinationDir) {
- $d['dir'] = $this->destinationDir;
- }
- if ($this->destinationFile) {
- $d['file'] = $this->destinationFile;
- }
-
- $datas[$this->origAction][$this->origVersion] = $d;
-
- $this->dao->saveExportDatas($this->book_id, $datas);
- }
+ }
+ }
+
+ protected function _phonegap()
+ {
+ $os = $this->action;
+
+ if ($this->destinationDir == '') {
+ return;
+ }
+
+ $packager = new wsPackagerPhonegap($this->book_id, null, true, false, $os);
+ $packager->cleanOnDestruct = false;
+ $package = $packager->makePackage(false);
+
+ $this->_transfertPhonegap($os, $package, $this->destinationDir);
+ }
+
+ protected function _transfertPhonegap($os, $package, $destination)
+ {
+ if ($os == 'android') {
+ `sudo /usr/local/bin/remountvincent`;
+ $this->_rsync($package, '/mnt/vincent/cygdrive/h/Works/Phonegap/Projects/' . $destination, true);
+ } else if ($os == 'ios') {
+ `sudo /usr/local/bin/remountmac`;
+ $this->_rsync($package, '/mnt/macbox/Phonegap/Projects/' . $destination, true);
+ }
+ }
+
+ protected function _lftp($src, $dest, $passive = false, $erase = false)
+ {
+ set_time_limit(0);
+ $u = parse_url($dest);
+
+ $file = is_file($src);
+ if ($file) {
+ $e = explode('/', $u['path']);
+ $u['file'] = array_pop($e);
+ $u['dir'] = implode('/', $e);
+ } else {
+ $u['dir'] = $u['path'];
+ }
+ if ($u['dir'] == '') {
+ $u['dir'] = '/';
+ }
+
+ $passive = $passive ? 'on' : 'off';
+
+ if (!isset($u['port'])) {
+ $u['port'] = '21';
+ }
+
+ $commandes = array(
+ //'set ftp:passive-mode ' . $passive,
+ 'set ftp:ssl-allow false',
+ 'mkdir -p ' . $u['dir']
+ );
+
+
+ if ($file) {
+ $commandes[] = 'put -O ' . $u['dir'] . ' ' . $src . ' -o ' . $u['file'];
+ } else {
+ $commandes[] = 'lcd ' . $src;
+ $commandes[] = 'cd ' . $u['dir'];
+ if ($erase) {
+ $commandes[] = 'mirror -Rve';
+ } else {
+ $commandes[] = 'mirror -Rv';
+ }
+ }
+
+ if (!file_exists($src)) {
+ return;
+ }
+
+ $lftp = new CubeIT_CommandLine('lftp');
+ $lftp->setArg('u', $u['user'] . ',' . $u['pass']);
+ $lftp->setArg('p', $u['port']);
+ $lftp->setArg('e', implode(';', $commandes));
+ $lftp->setArg(null, $u['host']);
+ $lftp->execute();
+ $lftp->debug();
+
+ }
+
+ protected function _rsync($src, $dest, $erase = false, $chown = null)
+ {
+ set_time_limit(0);
+ /*if (is_file($src)) {
+ $dir = dirname($dest);
+ if (!file_exists($dir)) {
+ mkdir($dir, 0777, true);
+ }
+ copy($src, $dest);
+ if (!is_null($chown)) {
+ `chown $chown $dest`;
+ }
+ return;
+ }*/
+
+ $cl = new CubeIT_CommandLine_Rsync($src, $dest, $erase);
+ $cl->setProg('/usr/bin/rsync');
+ $cl->execute();
+ if (!is_null($chown)) {
+ `chown -R $chown $dest`;
+ }
+ }
+
+ protected function _download()
+ {
+ $r = wsPackager::package($this->book_id, $this->version);
+ $this->x->addRedirection($r);
+ }
+
+ protected function _getVersion($version)
+ {
+ if ($version == 'v2') {
+ return 'html';
+ } else if ($version == 'online') {
+ if ($this->book->parametres->version == '1') {
+ return 'v1';
+ } elseif ($this->book->parametres->version == '2') {
+ return 'html';
+ }
+ }
+ return $version;
+ }
+
+ protected function _saveDestination()
+ {
+ $datas = $this->book->exportdatas;
+ if ($datas == '') {
+ $datas = array();
+ } else {
+ $datas = json_decode($datas, true);
+ }
+ if (!isset($datas[$this->origAction])) {
+ $datas[$this->origAction] = array();
+ }
+
+ $d = array();
+ if ($this->destinationDir) {
+ $d['dir'] = $this->destinationDir;
+ }
+ if ($this->destinationFile) {
+ $d['file'] = $this->destinationFile;
+ }
+
+ $datas[$this->origAction][$this->origVersion] = $d;
+
+ $this->dao->saveExportDatas($this->book_id, $datas);
+ }
}