/** * Set default data for the form. */ public function __construct() { $this->packageName = 'com.keosu.demo'; $this->description = 'Keosu demo'; $this->author = 'keosu team'; $this->website = 'http://keosu.com'; $this->email = '*****@*****.**'; $this->version = '1.0'; $this->theme = array_keys(ThemeUtil::getThemeList())[0]; $this->preferences = array(array("key" => "permissions", "value" => "none"), array("key" => "phonegap-version", "value" => "cli-5.2.0"), array("key" => "orientation", "value" => "default"), array("key" => "target-device", "value" => "universal"), array("key" => "Fullscreen", "value" => "true"), array("key" => "webviewbounce", "value" => "true"), array("key" => "prerendered-icon", "value" => "true"), array("key" => "stay-in-webview", "value" => "false"), array("key" => "ios-statusbarstyle", "value" => "black-opaque"), array("key" => "detect-data-types", "value" => "true"), array("key" => "exit-on-suspend", "value" => "true"), array("key" => "Show-splash-screen-spinner", "value" => "true"), array("key" => "auto-hide-splash-screen", "value" => "false"), array("key" => "disable-cursor", "value" => "false"), array("key" => "android-minSdkVersion", "value" => "7"), array("key" => "android-installLocation", "value" => "auto"), array("key" => "disallowOverscroll", "value" => "true"), array("key" => "SplashScreenDelay", "value" => "3000")); }
/** * Edit App form */ private function buildAppForm($formBuilder) { $formBuilder->add('name', 'text')->add('packageName', 'text')->add('version', 'text')->add('description', 'textarea')->add('author', 'text', array('required' => false))->add('website', 'url', array('required' => false))->add('email', 'email', array('required' => false))->add('debugMode', 'checkbox', array('required' => false))->add('theme', 'choice', array('choices' => ThemeUtil::getThemeList(), 'expanded' => true))->add('configPackages', new ConfigPackageType($this->container, $this->get('request')), array('label' => false))->add('splashscreens', new SplashscreensType())->add('icons', new IconsType())->add('preferences', 'collection', array('type' => new PreferenceType(), 'required' => false, 'label' => "Edit preference", 'allow_add' => true, 'allow_delete' => true, 'by_reference' => true, 'options' => array('label' => false))); }
/** * Shared function to edit/add an app */ private function editTheme($theme) { // Find existing app to know if it's the first one $error = null; $em = $this->get('doctrine')->getManager(); // page edit form $formBuilder = $this->createFormBuilder($theme, array('label' => 'Edit Theme')); $this->buildThemeForm($formBuilder); $form = $formBuilder->getForm(); $request = $this->get('request'); // If we are in POST method, form is submit if ($request->getMethod() == 'POST') { $form->bind($request); if ($form->isValid()) { // Storing pag if (($error = $theme->upload()) !== null) { return $this->render('KeosuCoreBundle:Theme:edit.html.twig', array('form' => $form->createView(), 'theme' => $theme, 'error' => $error)); } $themesData = $em->getRepository('KeosuCoreBundle:Theme')->findAll(); $themes = ThemeUtil::getThemeList(); foreach ($themes as $themetmp) { if ($this->themeExists($themetmp, $themesData, FALSE) === FALSE) { $theme->setName($themetmp); $session = $this->get("session"); $session->set("themeid", $theme->getId()); $em->persist($theme); } } $em->flush(); $themesData = $em->getRepository('KeosuCoreBundle:Theme')->findAll(); return $this->render('KeosuCoreBundle:Theme:manage.html.twig', array('themes' => $themesData, 'msg' => "Your upload succeeded.")); } } return $this->render('KeosuCoreBundle:Theme:edit.html.twig', array('form' => $form->createView(), 'theme' => $theme, 'error' => $error)); }
/** * @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'); } }