/** * @param SimpleXMLElement $xml * @return Metadata * @throws InvalidGPXException */ public static function fromXML(SimpleXMLElement $xml) { $metadata = new Metadata(); if (!empty($xml->name)) { $metadata->setName((string) $xml->name[0]); } if (!empty($xml->desc)) { $metadata->setDescription((string) $xml->desc[0]); } if (!empty($xml->author)) { $metadata->setAuthor(Person::fromXML($xml->author[0])); } if (!empty($xml->copyright)) { $metadata->setCopyright(Copyright::fromXML($xml->copyright[0])); } if (!empty($xml->link)) { $links = []; foreach ($xml->link as $link) { array_push($links, Link::fromXML($link)); } $metadata->setLinks($links); } if (!empty($xml->time)) { $metadata->setTime(strtotime((string) $xml->time[0])); } if (!empty($xml->keywords)) { $metadata->setKeywords((string) $xml->keywords[0]); } if (!empty($xml->bounds)) { $metadata->setBounds(Bounds::fromXML($xml->bounds0[0])); } if (!empty($xml->extensions)) { $metadata->setExtensions(Extensions::fromXML($xml->extensions[0])); } return $metadata; }
/** * Save metadata field. * * @param array $values */ public static function saveNewMetadata(array $values) { $metadata = new Metadata(); $metadata->setName($values['name']); $metadata->setDisplayName($values['display_name']); $metadata->setType($values['type']); $metadata->setDefaultValue($values['default_value']); $metadata->save(); }
public function saveConfiguration($values) { // Restore database from backup? if ($values['template'] == 'backup') { if (!Curry_Backend_DatabaseHelper::restoreFromFile('db.txt')) { $this->addMessage('Unable to restore database content from db.txt', self::MSG_WARNING); } } // Create admin user if ($values['admin']['username']) { $access = array('*', 'Curry_Backend_Content/*'); $adminRole = self::createRole('Super', $access); $adminUser = self::createUser($values['admin']['username'], $values['admin']['password'], $adminRole); if ($adminUser->isNew()) { self::createFilebrowserAccess($adminRole, 'Root', ''); } $adminUser->save(); } // Create light user if ($values['user']['username']) { $access = array('Curry_Backend_FileBrowser', 'Curry_Backend_Page', 'Curry_Backend_Profile', 'Curry_Backend_Translations', 'Curry_Backend_Content/*'); $userRole = self::createRole('User', $access); $user = self::createUser($values['user']['username'], $values['user']['password'], $userRole); if ($user->isNew()) { $user->save(); self::createFilebrowserAccess($user, 'Home', 'user-content/' . $user->getUserId() . '/'); self::createFilebrowserAccess($userRole, 'Shared', 'content/'); } $user->save(); } if ($values['template'] != 'backup') { // Create default meta-data items $metadatas = array('Title' => 'text', 'Keywords' => 'textarea', 'Description' => 'textarea', 'Image' => 'previewImage'); foreach ($metadatas as $name => $type) { $metadata = new Metadata(); $metadata->setName($name); $metadata->setDisplayName($name); $metadata->setType($type); $metadata->save(); } $page = new Page(); $page->setName("Home"); $page->setURL("/"); $page->setVisible(true); $page->setEnabled(true); $page->makeRoot(); $page->save(); $page->createDefaultRevisions(); $page->save(); $pageRev = $page->getWorkingPageRevision(); $pageRev->setTemplate('Root.html'); $pageRev->save(); $pa = new PageAccess(); $pa->setPage($page); $pa->setPermSubpages(true); $pa->setPermVisible(true); $pa->setPermCreatePage(true); $pa->setPermCreateModule(true); $pa->setPermPublish(true); $pa->setPermProperties(true); $pa->setPermContent(true); $pa->setPermMeta(true); $pa->setPermModules(true); $pa->setPermRevisions(true); $pa->setPermPermissions(true); $pa->save(); } // Create template root $templateRoot = Curry_Core::$config->curry->template->root; if (!file_exists($templateRoot)) { @mkdir($templateRoot, 0777, true); } switch ($values['template']) { case 'empty': case 'curry': $source = Curry_Util::path(Curry_Core::$config->curry->wwwPath, 'shared', 'backend', 'common', 'templates', 'project-empty.html'); $templateFile = Curry_Util::path($templateRoot, 'Root.html'); if (!file_exists($templateFile)) { @copy($source, $templateFile); } break; case 'twitter-bootstrap': case 'html5boilerplate': } if (file_exists(Curry_Core::$config->curry->configPath)) { $config = new Zend_Config(require Curry_Core::$config->curry->configPath, true); $config->curry->name = $values['name']; $config->curry->adminEmail = $values['email']; if ($values['base_url']) { $config->curry->baseUrl = $values['base_url']; } else { unset($config->curry->baseUrl); } $config->curry->developmentMode = (bool) $values['development_mode']; $config->curry->secret = sha1(uniqid(mt_rand(), true) . microtime()); $writer = new Zend_Config_Writer_Array(); $writer->write(Curry_Core::$config->curry->configPath, $config); } return true; }
public function saveConfiguration($values) { // Create admin role $access = array('*', 'Curry_Backend_Content/*'); $adminRole = self::createRole('Administrator', $access); if ($adminRole->isNew()) { self::createFilebrowserAccess($adminRole, 'Root', ''); } // Create editor role $access = array('Curry_Backend_FileBrowser', 'Curry_Backend_Page', 'Curry_Backend_Profile', 'Curry_Backend_Translations', 'Curry_Backend_Content/*'); $editorRole = self::createRole('Editor', $access); if ($editorRole->isNew()) { self::createFilebrowserAccess($editorRole, 'Shared', 'content/shared/'); } // Create admin user if ($values['admin']['username']) { $adminUser = self::createUser($values['admin']['username'], $values['admin']['password'], $adminRole); $adminUser->save(); } // Create default meta-data items $metadatas = array('Title' => 'text', 'Keywords' => 'textarea', 'Description' => 'textarea', 'Image' => 'previewImage'); foreach ($metadatas as $name => $type) { $metadata = new \Metadata(); $metadata->setName($name); $metadata->setDisplayName($name); $metadata->setType($type); $metadata->save(); } // Create pages $rootPage = new \Page(); $rootPage->setName("Root"); $rootPage->setURL("root/"); $rootPage->setVisible(true); $rootPage->setEnabled(true); $rootPage->makeRoot(); $rootPage->save(); $rootPage->createDefaultRevisions($rootPage); $rootPage->save(); $templatePage = new \Page(); $templatePage->setName('Templates'); $templatePage->setURL("templates/"); $templatePage->setIncludeInIndex(false); $templatePage->insertAsLastChildOf($rootPage); $templatePage->save(); $templatePage->createDefaultRevisions(); $pageRevision = $templatePage->getWorkingPageRevision(); $pageRevision->setTemplate('Root.html.twig'); $templatePage->save(); $homePage = new \Page(); $homePage->setName('Home'); $homePage->setURL("/"); $homePage->setVisible(true); $homePage->setEnabled(true); $homePage->insertAsLastChildOf($rootPage); $homePage->save(); $homePage->createDefaultRevisions($templatePage); $homePage->save(); // Create page access objects $pa = new \PageAccess(); $pa->setUserRole($adminRole); $pa->setPage($rootPage); $pa->setPermSubpages(true); $pa->setPermVisible(true); $pa->setPermCreatePage(true); $pa->setPermCreateModule(true); $pa->setPermPublish(true); $pa->setPermProperties(true); $pa->setPermContent(true); $pa->setPermMeta(true); $pa->setPermModules(true); $pa->setPermRevisions(true); $pa->setPermPermissions(true); $pa->save(); $pa = new \PageAccess(); $pa->setUserRole($editorRole); $pa->setPage($rootPage); $pa->setPermSubpages(true); $pa->setPermVisible(true); $pa->setPermCreatePage(true); $pa->setPermCreateModule(true); $pa->setPermPublish(true); $pa->setPermProperties(true); $pa->setPermContent(true); $pa->setPermMeta(true); $pa->setPermModules(true); $pa->setPermRevisions(true); $pa->setPermPermissions(false); $pa->save(); $pa = new \PageAccess(); $pa->setUserRole($editorRole); $pa->setPage($templatePage); $pa->setPermSubpages(true); $pa->setPermVisible(false); $pa->setPermCreatePage(false); $pa->setPermCreateModule(false); $pa->setPermPublish(false); $pa->setPermProperties(false); $pa->setPermContent(false); $pa->setPermMeta(false); $pa->setPermModules(false); $pa->setPermRevisions(false); $pa->setPermPermissions(false); $pa->save(); // Create template root $templateRoot = $this->app['template.root']; if (!file_exists($templateRoot)) { @mkdir($templateRoot, 0777, true); } if (file_exists($this->app['configPath'])) { $config = $this->app->openConfiguration(); $config->name = $values['name']; $config->adminEmail = $values['email']; if (!isset($config->backend)) { $config->backend = array(); } $config->backend->templatePage = $templatePage->getPageId(); if ($values['base_url']) { $config->baseUrl = $values['base_url']; } else { unset($config->baseUrl); } $config->developmentMode = (bool) $values['development_mode']; $config->secret = sha1(uniqid(mt_rand(), true) . microtime()); $this->app->writeConfiguration($config); } return true; }