Пример #1
0
 public function setSplashscreenA960x720(File $splashscreen)
 {
     if (StringUtil::endsWith($splashscreen->getClientOriginalName(), '.9.png')) {
         $splashscreen->move($this->getUploadRootDir("android"), "splashscreenA960x720.9.png");
     } else {
         $splashscreen->move($this->getUploadRootDir("android"), "splashscreenA960x720.png");
     }
 }
Пример #2
0
 /**
  * This work for gadget only
  * @param $gadgetName name of the gadget
  * @return array with list of html template
  */
 public function getListTemplateForGadget($gadgetName)
 {
     $pathToGadget = $this->getPath($gadgetName);
     $kernel = $this->container->get('kernel');
     // test good gadget type
     $config = $this->getConfigPackage($pathToGadget);
     if ($config['type'] !== $this::TYPE_PACKAGE_GADGET) {
         throw new \LogicException('This action works only on gadget type package');
     }
     // get list of template
     $ret = array();
     $templates = scandir($pathToGadget . '/templates');
     $templatesGadgetFolder = $kernel->getRootDir() . $this::ROOT_DIR_TEMPLATE . $gadgetName . '/';
     if (!is_dir($templatesGadgetFolder)) {
         mkdir($templatesGadgetFolder);
     }
     foreach ($templates as $t) {
         if ($t == '.' || $t == '..') {
             continue;
         }
         if (StringUtil::endsWith($t, '.html')) {
             $ret[$t] = $t;
         }
     }
     return $ret;
 }
Пример #3
0
 public function export($appId)
 {
     $em = $this->doctrine->getManager();
     $baseurl = $this->container->getParameter('url_base');
     $dispatcher = $this->container->get('event_dispatcher');
     $pages = $em->getRepository('KeosuCoreBundle:Page')->findByAppId($appId);
     $this->cleanDir();
     //Export theme
     $app = $em->getRepository('KeosuCoreBundle:App')->find($appId);
     $json = json_encode(array('name' => $app->getName(), 'host' => $baseurl . $this->container->getParameter('url_param'), 'appId' => $appId));
     FilesUtil::copyContent($json, $this->getExportAbsolutePath() . '/simulator/www/data/globalParam.json');
     FilesUtil::copyFolder(ThemeUtil::getAbsolutePath() . $app->getTheme() . '/style', $this->getExportAbsolutePath() . '/simulator/www/theme');
     //cordova_plugins.json
     copy(TemplateUtil::getAbsolutePath() . '/main-header/cordova_plugins.js', $this->getExportAbsolutePath() . '/simulator/www/cordova_plugins.js');
     copy(TemplateUtil::getAbsolutePath() . '/main-header/index.html', $this->getExportAbsolutePath() . '/simulator/www/index.html');
     //Copy all theme/header/js dir to web/export/www/js
     FilesUtil::copyFolder(ThemeUtil::getAbsolutePath() . $app->getTheme() . '/header/js', $this->getExportAbsolutePath() . '/simulator/www/js');
     //Copy Splashcreens and icons
     FilesUtil::copyFolder($this::getImageDir($app->getId()) . '/', $this->getExportAbsolutePath() . '/simulator/www/res/');
     // list of imported gadgets
     $importedPackages = array();
     $httpLinks = array();
     $jsInit = $jsCore = $jsEnd = '';
     $css = '';
     // load index.html (main template)
     $indexHtml = new SmartDOMDocument();
     $fileContent = file_get_contents($this->getExportAbsolutePath() . '/simulator/www/index.html');
     @$indexHtml->loadHTML($fileContent);
     ///////////////////////////////////////////////////
     // Generate config.xml
     //////////////////////////////////////////////////
     $configXml = new \DOMDocument('1.0', 'UTF-8');
     $configXml->formatOutput = true;
     $widget = $configXml->createElement('widget');
     $widget->setAttribute('xmlns', 'http://www.w3.org/ns/widgets');
     $widget->setAttribute('xmlns:gap', 'http://phonegap.com/ns/1.0');
     $widget->setAttribute('id', $app->getPackageName());
     $configXml->appendChild($widget);
     $widget->appendChild($configXml->createElement('name', $app->getName()));
     $widget->appendChild($configXml->createElement('description', $app->getDescription()));
     $author = $configXml->createElement('author', $app->getAuthor());
     $author->setAttribute('href', $app->getWebsite());
     $author->setAttribute('email', $app->getEmail());
     $widget->setAttribute('version', $app->getVersion());
     $widget->setAttribute('versionCode', $app->getVersion());
     $widget->appendChild($author);
     $mainPage = null;
     $paramGadget = array();
     $paramGadget['host'] = $baseurl . $this->container->getParameter('url_param');
     ////////////////////////////////////////
     // Generate Keosu's base
     ////////////////////////////////////////
     try {
         $this->importPackage('keosu-base', $indexHtml, $configXml, $jsInit, $jsCore, $jsEnd, $css, $importedPackages, $app, $httpLinks);
     } catch (\Exception $e) {
         throw new \LogicException('Unable to import keosu-base because ' . $e->getMessage());
     }
     ////////////////////////////////////////
     // Generate view for each page
     ////////////////////////////////////////
     foreach ($pages as $page) {
         if ($mainPage == null) {
             $mainPage = $page->getId();
         }
         if ($page->getIsMain()) {
             $mainPage = $page->getId();
         }
         $document = new SmartDOMDocument();
         $fileContent = file_get_contents(TemplateUtil::getPageTemplateAbsolutePath() . $page->getTemplateId());
         @$document->loadHTML($fileContent);
         $finder = new \DOMXPath($document);
         $classname = "zone";
         //Find all the zone div in page template
         $zones = $finder->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' {$classname} ')]");
         foreach ($zones as $zone) {
             $zoneId = $zone->getAttribute('id');
             //Look if there is a shared gadget in this zone
             $gadget = $em->getRepository('KeosuCoreBundle:Gadget')->findSharedByZoneAndApp($zoneId, $appId);
             //If there is no share gadget we try to find the specific one
             if ($gadget == null) {
                 //Find the gadget associated with page and zone
                 $gadget = $em->getRepository('KeosuCoreBundle:Gadget')->findOneBy(array('zone' => $zoneId, 'page' => $page->getId()));
             }
             if ($gadget != null) {
                 // import if it's needed
                 if (array_search($gadget->getName(), $importedPackages) === false) {
                     try {
                         $this->importPackage($gadget->getName(), $indexHtml, $configXml, $jsInit, $jsCore, $jsEnd, $css, $importedPackages, $app, $httpLinks);
                     } catch (\Exception $e) {
                         throw new \LogicException('Unable to import ' . $gadget->getName() . ' because ' . $e->getMessage());
                     }
                 }
                 $package = $this->packageManager->findPackage($gadget->getName());
                 $packageConfig = $this->packageManager->getConfigPackage($package->getPath());
                 // set param for gadgets
                 $paramGadget['gadgetId'] = $gadget->getId();
                 $paramGadget['pageId'] = $page->getId();
                 $paramGadget['gadgetParam'] = array();
                 $paramGadget['gadgetParam'] = $this->secureParameters($gadget->getConfig(), $packageConfig);
                 // globalParam
                 $paramGadget['appParam'] = array();
                 if (isset($app->getConfigPackages()[$gadget->getName()])) {
                     $paramGadget['appParam'] = $this->secureParameters($app->getConfigPackages()[$gadget->getName()], $packageConfig);
                 }
                 $event = new ExportConfigPackageEvent($paramGadget);
                 $dispatcher->dispatch(KeosuEvents::PACKAGE_EXPORT_CONFIG . $package->getName(), $event);
                 if ($event->getNewConfig() !== null) {
                     $paramGadget = $event->getNewConfig();
                 }
                 $dataEvent = new ExportDataPackageEvent($appId, $paramGadget);
                 $dispatcher->dispatch(KeosuEvents::PACKAGE_EXPORT_DATA . $package->getName(), $dataEvent);
                 if ($dataEvent->getData() !== null) {
                     if ($dataEvent->getFileName() != null) {
                         $this->writeFile($dataEvent->getData(), $dataEvent->getFileName(), '/simulator/www/data/');
                     } else {
                         $this->writeFile($dataEvent->getData(), $gadget->getId() . ".json", '/simulator/www/data/');
                     }
                 }
                 //Copy in HTML
                 $gadgetTemplateHtml = file_get_contents($package->getPath() . '/templates/' . $gadget->getTemplate());
                 $zone->nodeValue = $gadgetTemplateHtml;
                 //Add the angularJS directive to zone
                 // import param
                 $zone->setAttribute('ng-controller', $gadget->getName() . 'Controller');
                 $zone->setAttribute('ng-init', 'init(' . json_encode($paramGadget) . ')');
                 //Saving node
                 $zone->ownerDocument->saveXML($zone);
             }
         }
         $bodyEl = $document->getElementsByTagName('body')->item(0);
         $html = $this->domInnerHtml($bodyEl);
         $html = StringUtil::decodeString($html);
         $this->writeFile($html, $page->getFileName(), '/simulator/www/');
     }
     ///////////////////////////////////////////////////
     // Generate main view index.html
     ///////////////////////////////////////////////////
     // import theme in index.html
     $tmpthemeHeader = new SmartDOMDocument();
     $fileContent = file_get_contents(ThemeUtil::getAbsolutePath() . $app->getTheme() . '/header/header.html');
     @$tmpthemeHeader->loadHTML($fileContent);
     $children = $tmpthemeHeader->getElementsByTagName('head')->item(0)->childNodes;
     foreach ($children as $child) {
         $indexHtml->getElementsByTagName('head')->item(0)->appendChild($indexHtml->importNode($child));
     }
     // import weinre if the app is in debug mode
     // @see https://people.apache.org/~pmuellr/weinre/docs/latest/Home.html
     if ($app->getDebugMode() == true) {
         $script = $indexHtml->createElement('script');
         $domainName = parse_url($baseurl);
         $script->setAttribute('src', 'http://' . $domainName['host'] . ':8080/target/target-script-min.js#anonymous');
         $indexHtml->getElementsByTagName('head')->item(0)->appendChild($script);
     }
     // this should always be at the end
     $script = $indexHtml->createElement('script');
     $script->setAttribute('src', 'js/app.js');
     $indexHtml->getElementsByTagName('head')->item(0)->appendChild($script);
     $link = $indexHtml->createElement('link');
     $link->setAttribute('rel', 'stylesheet');
     $link->setAttribute('type', 'text/css');
     $link->setAttribute('href', 'js/app.css');
     $indexHtml->getElementsByTagName('head')->item(0)->appendChild($link);
     $this->writeFile(StringUtil::decodeString($indexHtml->saveHTML()), 'index.html', '/simulator/www/');
     ////////////////////////////////////////////////////
     // import all gadget required controller
     ////////////////////////////////////////////////////
     $appJs = 'var importedPackages = ' . \json_encode($importedPackages) . ";\n";
     $appJs .= $jsInit . $jsCore . $jsEnd;
     $this->writeFile($appJs, 'app.js', '/simulator/www/js/');
     // import CSS of all packages
     $this->writeFile($css, 'app.css', '/simulator/www/js/');
     //Enable individual API permissions here.
     //The "device" permission is required for the 'deviceready' event.
     $basePlugin = array('org.apache.cordova.device', 'org.apache.cordova.device-motion', 'org.apache.cordova.device-orientation', 'org.apache.cordova.dialogs');
     foreach ($basePlugin as $plugin) {
         $device = $configXml->createElement('gap:plugin');
         $device->setAttribute('name', $plugin);
         $widget->appendChild($device);
     }
     // Render preferences
     $preferences = $app->getPreferences();
     foreach ($preferences as $p) {
         $preference = $configXml->createElement('preference');
         $preference->setAttribute('name', $p['key']);
         $preference->setAttribute('value', $p['value']);
         $widget->appendChild($preference);
     }
     // Define app icon for each platform.
     $icons = array(array("src" => "icon.png"), array("src" => "res/icons/android/iconA36.png", "gap:platform" => "android", "gap:density" => "ldpi"), array("src" => "res/icons/android/iconA48.png", "gap:platform" => "android", "gap:density" => "mdpi"), array("src" => "res/icons/android/iconA72.png", "gap:platform" => "android", "gap:density" => "hdpi"), array("src" => "res/icons/android/iconA96.png", "gap:platform" => "android", "gap:density" => "xhdpi"), array("src" => "res/icons/ios/iconI57.png", "gap:platform" => "ios", "width" => "57", "height" => "57"), array("src" => "res/icons/ios/iconI72.png", "gap:platform" => "ios", "width" => "72", "height" => "72"), array("src" => "res/icons/ios/iconI114.png", "gap:platform" => "ios", "width" => "114", "height" => "114"), array("src" => "res/icons/ios/iconI120.png", "gap:platform" => "ios", "width" => "120", "height" => "120"), array("src" => "res/icons/ios/iconI76.png", "gap:platform" => "ios", "width" => "76", "height" => "76"), array("src" => "res/icons/ios/iconI152.png", "gap:platform" => "ios", "width" => "152", "height" => "152"), array("src" => "res/icons/ios/iconI144.png", "gap:platform" => "ios", "width" => "144", "height" => "144"));
     foreach ($icons as $i) {
         $icon = $configXml->createElement('icon');
         foreach ($i as $k => $v) {
             $icon->setAttribute($k, $v);
         }
         $widget->appendChild($icon);
     }
     // Define app splash screen for each platform.
     $splashScreen = array(array("src" => $this->getAndroidSplashscreenPath("splashscreenA320x436"), "gap:platform" => "android", "gap:density" => "ldpi"), array("src" => $this->getAndroidSplashscreenPath("splashscreenA320x470"), "gap:platform" => "android", "gap:density" => "mdpi"), array("src" => $this->getAndroidSplashscreenPath("splashscreenA640x480"), "gap:platform" => "android", "gap:density" => "hdpi"), array("src" => $this->getAndroidSplashscreenPath("splashscreenA960x720"), "gap:platform" => "android", "gap:density" => "xhdpi"), array("src" => "res/splashscreens/ios/splashscreenI320x480.png", "gap:platform" => "ios", "width" => "320", "height" => "480"), array("src" => "res/splashscreens/ios/splashscreenI640x960.png", "gap:platform" => "ios", "width" => "640", "height" => "960"), array("src" => "res/splashscreens/ios/splashscreenI640x1136.png", "gap:platform" => "ios", "width" => "640", "height" => "1136"), array("src" => "res/splashscreens/ios/splashscreenI1024x768.png", "gap:platform" => "ios", "width" => "1024", "height" => "768"), array("src" => "res/splashscreens/ios/splashscreenI768x1024.png", "gap:platform" => "ios", "width" => "768", "height" => "1024"), array("src" => "res/splashscreens/ios/splashscreenI2048x1536.png", "gap:platform" => "ios", "width" => "2048", "height" => "1536"), array("src" => "res/splashscreens/ios/splashscreenI1536x2048.png", "gap:platform" => "ios", "width" => "1536", "height" => "2048"), array("src" => "res/splashscreens/ios/splashscreenI750x1334.png", "gap:platform" => "ios", "width" => "750", "height" => "1334"), array("src" => "res/splashscreens/ios/splashscreenI1242x2208.png", "gap:platform" => "ios", "width" => "1242", "height" => "2208"), array("src" => "res/splashscreens/ios/splashscreenI2208x1242.png", "gap:platform" => "ios", "width" => "2208", "height" => "1242"));
     foreach ($splashScreen as $asplash) {
         $splash = $configXml->createElement('gap:splash');
         foreach ($asplash as $k => $v) {
             $splash->setAttribute($k, $v);
         }
         $widget->appendChild($splash);
     }
     // Define access to external domains.
     // <access), - a blank access tag denies access to all external resources.
     // <access origin="*"), - a wildcard access tag allows access to all external resource.
     // Otherwise, you can specify specific domains:
     // <access origin="http://phonegap.com"), - allow any secure requests to http://phonegap.com/
     // <access origin="http://phonegap.com" subdomains="true"), - same as above, but including subdomains, such as http://build.phonegap.com/
     // <access origin="http://phonegap.com" browserOnly="true"), - only allows http://phonegap.com to be opened by the child browser.
     $access = array(array('origin' => '*'));
     foreach ($access as $a) {
         $accesses = $configXml->createElement('access');
         foreach ($a as $k => $v) {
             $accesses->setAttribute($k, $v);
         }
         $widget->appendChild($accesses);
     }
     $configXml->save($this->getExportAbsolutePath() . DIRECTORY_SEPARATOR . 'simulator' . DIRECTORY_SEPARATOR . 'www' . DIRECTORY_SEPARATOR . 'config.xml');
     /**
      * Duplicate Export for cordova and phonegapbuild
      */
     //For ios
     FilesUtil::copyFolder($this->getExportAbsolutePath() . '/simulator/www', $this->getExportAbsolutePath() . '/cordova/www');
     copy($this->getExportAbsolutePath() . '/cordova/www/config.xml', $this->getExportAbsolutePath() . '/cordova/config/config.xml');
     unlink($this->getExportAbsolutePath() . '/cordova/www/config.xml');
     //For phonegapbuild
     FilesUtil::copyFolder($this->getExportAbsolutePath() . '/simulator/www', $this->getExportAbsolutePath() . '/phonegapbuild/www');
     copy(TemplateUtil::getAbsolutePath() . '/main-header/ios/cordova.js', $this->getExportAbsolutePath() . '/simulator/www/cordova.js');
     //Generate ZIP files for all
     //Cordova
     ZipUtil::ZipFolder($this->getExportAbsolutePath() . '/cordova/www', $this->getExportAbsolutePath() . '/cordova/export.zip');
     ZipUtil::ZipFolder($this->getExportAbsolutePath() . '/cordova/config', $this->getExportAbsolutePath() . '/cordova/config.zip');
     //Phonegapbuild
     ZipUtil::ZipFolder($this->getExportAbsolutePath() . '/phonegapbuild/www', $this->getExportAbsolutePath() . '/phonegapbuild/export.zip');
 }