Esempio n. 1
0
 /**
  * Shared function to edit/add an app
  */
 private function editApp(App $app)
 {
     $em = $this->get('doctrine')->getManager();
     $request = $this->get('request');
     $packageManager = $this->get('keosu_core.packagemanager');
     $apps = $em->getRepository('KeosuCoreBundle:App')->findAll();
     //Find existing app to know if it's the first one
     $isFirstApp = $apps === null;
     // find package witch need to be configured
     $listPackage = $packageManager->getPackageList();
     $packageToConfigure = array();
     foreach ($listPackage as $p) {
         $config = $packageManager->getConfigPackage($p->getPath());
         if (isset($config['appParam']) && count($config['appParam'])) {
             $packageToConfigure[] = $config;
         }
     }
     //page edit form
     $formBuilder = $this->createFormBuilder($app, array('label' => 'Edit App'));
     $this->buildAppForm($formBuilder);
     $form = $formBuilder->getForm();
     //If we are in POST method, form is submit
     if ($request->getMethod() == 'POST') {
         $form->bind($request);
         if ($form->isValid()) {
             $em->persist($app);
             $em->flush();
             $em->refresh($app);
             $session = $this->get("session");
             $session->set("appid", $app->getId());
             $dispatcher = $this->get('event_dispatcher');
             $event = new PackageSaveAppEvent($form, $request, $app);
             foreach ($listPackage as $p) {
                 $dispatcher->dispatch(KeosuEvents::PACKAGE_GLOBAL_CONFIG_SAV_FORM . $p->getName(), $event);
             }
             // Persist event modification
             $em->persist($app);
             $em->flush();
             //Copy splashscreens and icons
             FilesUtil::copyFolder(Exporter::getImageDir('tmp'), Exporter::getImageDir($app->getId()));
             // export the app
             $this->container->get('keosu_core.exporter')->exportApp();
             if ($event->getResponse() !== null) {
                 return $event->getResponse();
             }
             return $this->redirect($this->generateUrl('keosu_core_app_manage'));
         }
     }
     return $this->render('KeosuCoreBundle:App:edit.html.twig', array('form' => $form->createView(), 'firstApp' => $isFirstApp, 'themeDir' => ThemeUtil::getThemeDir(), 'packageToConfigure' => $packageToConfigure));
 }
Esempio n. 2
0
 /**
  * @param string $packageName name of the package to import
  * @param DOMDocument $indexDocument index.html file
  * @param DOMDocument $configXml config.xml document
  * @param string $jsInit js init part
  * @param string $jsCore main part of the js
  * @param string $jsEnd end part of the js
  * @param string $css CSS stylesheet
  * @param array $importedPackages list of imported gadget
  * @param App $app app to export
  * @param array of http link already imported
  */
 private function importPackage($packageName, \DOMDocument &$indexDocument, \DOMDocument &$configXml, &$jsInit, &$jsCore, &$jsEnd, &$css, &$importedPackages, App &$app, &$jsHttpLink)
 {
     $package = $this->packageManager->findPackage($packageName);
     $importedPackages[] = $package->getName();
     $config = $this->packageManager->getConfigPackage($package->getPath());
     $simulatorPath = $this->getExportAbsolutePath() . DIRECTORY_SEPARATOR . 'simulator' . DIRECTORY_SEPARATOR . 'www' . DIRECTORY_SEPARATOR;
     // check dependency
     if (isset($config['require'])) {
         $require = $config['require'];
         if (count($require)) {
             foreach ($require as $r) {
                 if (array_search($r['name'], $importedPackages) === false) {
                     $this->importPackage($r['name'], $indexDocument, $configXml, $jsInit, $jsCore, $jsEnd, $css, $importedPackages, $app, $jsHttpLink);
                 }
             }
         }
     }
     // getApp config for gadget
     $appConfig = array();
     if (isset($app->getConfigPackages()[$package->getName()])) {
         $appConfig = $app->getConfigPackages()[$package->getName()];
     }
     // config Xml
     if (isset($config['configCordova'])) {
         $configCordova = $config['configCordova'];
         if (count($configCordova)) {
             $this->convertToXml($configCordova, $configXml, $configXml->getElementsByTagName('widget')->item(0), $appConfig);
         }
     }
     //Plugins to install manually
     if (isset($config['pluginToInstall'])) {
         $pluginsToInstall = $config['pluginToInstall'];
         if (count($pluginsToInstall)) {
             file_put_contents($this->getExportAbsolutePath() . '/cordova/config/required-cordova-plugins.txt', json_encode($pluginsToInstall) . PHP_EOL, FILE_APPEND);
         }
     }
     // javascript lib
     if (isset($config['libJs'])) {
         $libJs = $config['libJs'];
         if (count($libJs)) {
             foreach ($libJs as $l) {
                 $script = $indexDocument->createElement('script');
                 if (substr($l, 0, 8) === 'https://' || substr($l, 0, 7) === 'http://') {
                     if (array_search($l, $jsHttpLink) === false) {
                         $jsHttpLink[] = $l;
                         $script->setAttribute('src', $l);
                     }
                 } else {
                     copy($package->getPath() . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . $l, $simulatorPath . 'js' . DIRECTORY_SEPARATOR . $l);
                     $script->setAttribute('src', 'js/' . $l);
                 }
                 $indexDocument->getElementsByTagName('head')->item(0)->appendChild($script);
             }
         }
     }
     // javascript script
     if (is_file($package->getPath() . DIRECTORY_SEPARATOR . 'init.js')) {
         $jsInit .= file_get_contents($package->getPath() . DIRECTORY_SEPARATOR . 'init.js');
     }
     if (is_file($package->getPath() . DIRECTORY_SEPARATOR . 'core.js')) {
         $jsCore .= file_get_contents($package->getPath() . DIRECTORY_SEPARATOR . 'core.js');
     }
     if (is_file($package->getPath() . DIRECTORY_SEPARATOR . 'end.js')) {
         $jsEnd .= file_get_contents($package->getPath() . DIRECTORY_SEPARATOR . 'end.js');
     }
     // CSS stylesheet
     $packageStylesheet = ThemeUtil::getAbsolutePath() . $app->getTheme() . '/style/packages/' . $packageName . '.css';
     if (is_file($packageStylesheet)) {
         // If there's a CSS stylesheet for this package in the current theme
         $css .= file_get_contents($packageStylesheet);
     } else {
         // Otherwise, we check if there's one in the package directory
         $packageStylesheet = $package->getPath() . DIRECTORY_SEPARATOR . 'style.css';
         if (is_file($packageStylesheet)) {
             $css .= file_get_contents($packageStylesheet);
         }
     }
     // event to add new feature
     $dispatcher = $this->container->get('event_dispatcher');
     $event = new ExportPackageEvent($indexDocument, $configXml);
     $dispatcher->dispatch(KeosuEvents::PACKAGE_EXPORT . $package->getName(), $event);
     if ($event->getJsInit() !== null) {
         $jsInit .= $event->getJsInit();
     }
     if ($event->getJsCore() !== null) {
         $jsCore .= $event->getJsCore();
     }
     if ($event->getJsEnd() !== null) {
         $jsEnd .= $event->getJsEnd();
     }
     // export template for plugins
     if ($package->getType() === PackageManager::TYPE_PACKAGE_PLUGIN && is_dir($package->getPath() . DIRECTORY_SEPARATOR . 'templates')) {
         mkdir($simulatorPath . 'plugins' . DIRECTORY_SEPARATOR . $package->getName() . DIRECTORY_SEPARATOR . 'templates', 0777, true);
         FilesUtil::copyFolder($package->getPath() . DIRECTORY_SEPARATOR . 'templates', $simulatorPath . 'plugins' . DIRECTORY_SEPARATOR . $package->getName() . DIRECTORY_SEPARATOR . 'templates');
     }
 }