From: vincent@cubedesigners.com Date: Wed, 12 Sep 2012 15:52:21 +0000 (+0000) Subject: (no commit message) X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=1efd9de4529f5423ebc51ddd06b4707349e358d4;p=cubeextranet.git --- diff --git a/fluidbook/compile/_ico/phonegap.png b/fluidbook/compile/_ico/phonegap.png new file mode 100644 index 000000000..5af011ce4 Binary files /dev/null and b/fluidbook/compile/_ico/phonegap.png differ diff --git a/inc/ws/Metier/class.ws.book.parametres.php b/inc/ws/Metier/class.ws.book.parametres.php index 780745500..3c1ec8e7b 100644 --- a/inc/ws/Metier/class.ws.book.parametres.php +++ b/inc/ws/Metier/class.ws.book.parametres.php @@ -192,8 +192,9 @@ class wsBookParametres extends wsParametres { $this->fields['linkMultimediaQuality'] = array('type' => 'float', 'default' => 1.0, 'editable' => true, 'label' => __('Qualité de rendu des animations'), 'grade' => 5); $this->fields['linkCornerSize'] = array('type' => 'integer', 'default' => '10', 'editable' => true, 'label' => __('Taille des liens de coins de page'), 'hint' => __("Pourcentage de la largeur de la page")); $this->fields['videoReset'] = array('type' => 'boolean', 'default' => false, 'editable' => true, 'label' => __('Réinitialiser les vidéos après la lecture'), 'grade' => 3); + $this->fields['videoBigPlay'] = array('type' => 'boolean', 'default' => true, 'editable' => true, 'label' => __('Afficher le gros bouton Play'), 'grade' => 3); $this->forms['multimedia'] = array('label' => __('Liens et multimédia'), - 'fieldsnames' => array('permanentLinks', 'linkBlinkTime', 'customLinkClass', 'linkTooltipManager', 'linkCornerSize', '|', 'linkTracker', 'linkTrackerRegexp', '|', 'linkMultimediaPerformanceMode', 'linkMultimediaQuality', '|', 'videoReset')); + 'fieldsnames' => array('permanentLinks', 'linkBlinkTime', 'customLinkClass', 'linkTooltipManager', 'linkCornerSize', '|', 'linkTracker', 'linkTrackerRegexp', '|', 'linkMultimediaPerformanceMode', 'linkMultimediaQuality', '|', 'videoReset', 'videoBigPlay')); //. $this->fields['externalArchives'] = array('type' => 'freefile', 'default' => '', 'editable' => true, 'label' => __('Archives'), 'grade' => 3, 'fileFilter' => $swfFilter); diff --git a/inc/ws/Util/packager/class.ws.packager.phonegap.php b/inc/ws/Util/packager/class.ws.packager.phonegap.php index 80cb045df..0bf225d0c 100644 --- a/inc/ws/Util/packager/class.ws.packager.phonegap.php +++ b/inc/ws/Util/packager/class.ws.packager.phonegap.php @@ -2,6 +2,8 @@ class wsPackagerPhonegap extends wsPackager { + protected $splashdone = array(); + public function __construct($book_id, $vdir = null, $whole = true) { parent::__construct($book_id, $vdir, $whole); $this->version = 'phonegap'; @@ -19,27 +21,106 @@ class wsPackagerPhonegap extends wsPackager { unlink($this->vdir . '/www/cache.appcache'); rmdir($this->vdir . '/data'); - $this->makeCompileScripts(); + $this->makeConfig(); } - protected function makeCompileScripts() { + protected function makeConfig() { + $config = simplexml_load_string(''); + $ns = $config->getNamespaces(); + $config->addChild('name', $this->book->parametres->title); + $config->addChild('description'); + $author = $config->addChild('author', 'Fluidbook'); + $author->addAttribute('href', 'http://www.fluidbook.com'); + $author->addAttribute('email', 'contact@fluidbook.com'); + $preferences = array('phonegap-version' => '2.0.0', + 'target-device' => 'universal', + 'fullscreen' => 'false', + 'webviewbounce' => 'false', + 'prerendered-icon' => 'true', + 'stay-in-webview' => 'false', + 'ios-statusbarstyle' => 'black-opaque', + 'exit-on-suspend' => 'false'); + + foreach ($preferences as $k => $v) { + $p = $config->addChild('preference'); + $p->addAttribute('name', $k); + $p->addAttribute('value', $v); + } + + $access = $config->addChild('access'); + $access->addAttribute('origin', '*'); + + $icon = $config->addChild('icon'); + $icon->addAttribute('src', 'icon.png'); + if ($this->theme->parametres->favicon != '') { + copy($this->themeRoot . '/' . $this->theme->parametres->favicon, $this->vdir . '/icon.png'); + } else { + copy(WS_COMPILE_ASSETS . '/_ico/phonegap.png', $this->vdir . '/icon.png'); + } + + + $ios = array('320x480', '640x960', '1024x768', '768x1024'); + $android = array('ldpi' => '320x480', 'mdpi' => '640x960', 'hdpi' => '1024x768', 'xhdpi' => '1280x1920'); + + if (!file_exists($this->vdir . '/splash')) { + mkdir($this->vdir . '/splash'); + } + + foreach ($ios as $size) { + list($width, $height) = explode('x', $size); + $this->_makeSplash($width, $height); - $projectPath = '~/Documents/PhonegapApps/Fluidbook_' . $this->book_id; - $projectName = 'Fluidbook_' . $this->book_id; + $s = $config->addChild('splash'); + $s->addAttribute('src', 'splash/' . $size . '.png', $ns['gap']); + $s->addAttribute('width', $width); + $s->addAttribute('height', $height); + } - $create = '#! /bin/sh' . "\n"; - $create .='DIR="$( cd "$( dirname "$0" )" && pwd )"' . "\n"; - $create .='rm -rf ' . $projectPath . "\n"; - $create .= '~/Documents/Cordova/bin/create ' . $projectPath . ' com.fluidbook.ios.' . $this->book_id . ' ' . $projectName . "\n"; - $create .='cp -R $DIR/www ' . $projectPath . "\n"; - $create .='open ' . $projectPath . "\n"; - file_put_contents($this->vdir . '/create', $create); - chmod($this->vdir . '/create', 0755); + foreach ($android as $density => $size) { + list($width, $height) = explode('x', $size); + $this->_makeSplash($width, $height); - $build = '#! /bin/sh' . "\n"; - $build.=$projectPath . '/cordova/debug' . "\n"; - file_put_contents($this->vdir . '/build', $build); - chmod($this->vdir . '/build', 0755); + $s = $config->addChild('splash', null, $ns['gap']); + $s->addAttribute('src', 'splash/' . $size . '.png'); + $s->addAttribute('platform', 'android', $ns['gap']); + $s->addAttribute('density', $density, $ns['gap']); + } + copy($this->vdir . '/splash/768x1024.png', $this->vdir . '/splash.png'); + file_put_contents($this->vdir . '/config.xml', $config->asXML()); + } + + protected function _makeSplash($width, $height) { + if (isset($this->splashdone[$width . 'x' . $height])) { + return; + } + + $im = imagecreatetruecolor($width, $height); + // Draw Background + $back = imagecolorhexallocate($this->theme->parametres->backgroundColor); + imagefill($im, 0, 0, $back); + // Draw image + $this->_drawBackImage($im, $width, $height); + + imagepng($im, $this->vdir . '/splash/' . $width . 'x' . $height . '.png'); + + $this->splashdone[$width . 'x' . $height] = true; + } + + protected function _drawBackImage($im, $width, $height) { + if ($this->theme->parametres->backgroundImage == '') { + return; + } + $backimage = $this->themeRoot . '/' . $this->theme->parametres->backgroundImage; + if (!file_exists($backimage)) { + return; + } + $im2 = imagecreatefromfile($backimage); + $w2 = imagesx($im2); + $h2 = imagesy($im2); + + imagecopyresampled($im, $im2, 0, 0, 0, 0, $width, $height, $w2, $h2); + + imagedestroy($im2); } public function makePackage($zip) { @@ -51,4 +132,48 @@ class wsPackagerPhonegap extends wsPackager { } +function imagecolorhexallocate($im, $hex, $alpha = 0) { + $hex = trim($hex, '#'); + if (strlen($hex) < 6) { + $diff = 6 - strlen($hex); + $hex = str_repeat('0', $diff) . $hex; + } + if (!preg_match("|[0-9a-fA-F]{6}|i", $hex)) { + return false; + } + + for ($i = 0; $i < 3; $i++) { + $temp = substr($hex, 2 * $i, 2); + $rgb[$i] = 16 * hexdec(substr($temp, 0, 1)) + hexdec(substr($temp, 1, 1)); + } + + if (!$alpha) { + return imagecolorallocate($im, $rgb[0], $rgb[1], $rgb[2]); + } else { + return imagecolorallocatealpha($im, $rgb[0], $rgb[1], $rgb[2], $alpha); + } +} + +function imagecreatefromfile($file) { + if (!file_exists($file)) { + return false; + } + + $dim = getimagesize($file); + switch ($dim[2]) { + case 1: + $format = "gif"; + break; + case 2: + $format = "jpeg"; + break; + case 3: + $format = "png"; + break; + default:; + } // switch + $function = "imagecreatefrom" . $format; + return $function($file); +} + ?>