/** * serialize() * * create an xml string from the provided profile * * @param Zend_Tool_Project_Profile $profile * @return string */ public function serialize(Zend_Tool_Project_Profile $profile) { $profile = clone $profile; $this->_profile = $profile; $xmlElement = new SimpleXMLElement('<projectProfile />'); if ($profile->hasAttribute('type')) { $xmlElement->addAttribute('type', $profile->getAttribute('type')); } if ($profile->hasAttribute('version')) { $xmlElement->addAttribute('version', $profile->getAttribute('version')); } self::_serializeRecurser($profile, $xmlElement); $doc = new DOMDocument('1.0'); $doc->formatOutput = true; $domnode = dom_import_simplexml($xmlElement); $domnode = $doc->importNode($domnode, true); $domnode = $doc->appendChild($domnode); return $doc->saveXML(); }
public function generateSiteMap($sitemap = 'sitemap.xml', $siteURL = null) { $siteData = singleton('SiteDataService'); $pages = $siteData->getItems(); $xml = new SimpleXMLElement('<urlset></urlset>'); $xml->addAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9'); $xml->addAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); $xml->addAttribute('xsi:schemaLocation', 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd'); if (!$siteURL) { $siteURL = self::config()->get('base_url'); if (!$siteURL) { $siteURL = Director::absoluteBaseURL(); } } $siteURL = rtrim($siteURL, '/') . '/'; if (!strpos($siteURL, ':/')) { $siteURL = $this->config()->protocol . '://' . $siteURL; } foreach ($pages as $page) { $url = $xml->addChild('url'); $url->addChild('loc', $siteURL . $page->Link); $url->addChild('changefreq', $page->ChangeFreq); $url->addChild('priority', $page->Priority); } file_put_contents($sitemap, $xml->asXML()); }
/** * Add item index and level to class attribute * * @param SimpleXMLElement $node The node to add the index and level to * @param array $args Callback arguments */ public static function index(SimpleXMLElement $node, $args) { if ($node->getName() == 'ul') { // set up level $level = $args['level'] / 2 + 1; if ($level > 1) { $node->addAttribute('class', 'uk-nav uk-nav-navbar'); } else { $node->addAttribute('class', 'uk-navbar-nav'); } } if ($node->getName() == 'li') { $css = ''; // parent if (isset($node->div)) { $css .= ' uk-parent'; $node->addAttribute('data-uk-dropdown', ''); } // add li css classes $node->attributes()->class = trim($node->attributes()->class . $css); // add a/span css classes $children = $node->children(); if ($firstChild = $children[0]) { $firstChild->addAttribute('class', trim($firstChild->attributes()->class . $css)); } } unset($node->attributes()->icon); }
/** * Funkce pro přidání tagu <Extension name="..." value="..." /> * * @param \SimpleXMLElement &$parentSimpleXmlElement * @param string $extensionName * @param string $extensionValue * @param string|null $extensionExtender */ protected function addExtensionElement(\SimpleXMLElement &$parentSimpleXmlElement, $extensionName, $extensionValue, $extensionExtender = null, $groupExtensions = true) { if ($groupExtensions && count($parentSimpleXmlElement->Extension) > 0) { //TODO tohle nefunguje v rámci nového serveru... /** @noinspection PhpUndefinedFieldInspection */ $siblinkElement = $parentSimpleXmlElement->Extension[0]; $siblinkElementDom = dom_import_simplexml($siblinkElement); //připravení elementu pro připojení $extensionElement = new \SimpleXMLElement('<Extension />'); $extensionElement->addAttribute('name', $extensionName); $extensionElement->addAttribute('value', $extensionValue); if ($extensionExtender !== null) { $extensionElement->addAttribute('extender', $extensionExtender); } $extensionElementDom = $siblinkElementDom->ownerDocument->importNode(dom_import_simplexml($extensionElement), true); $siblinkElementDom->parentNode->insertBefore($extensionElementDom, $siblinkElementDom); } else { $extensionElement = $parentSimpleXmlElement->addChild('Extension'); $extensionElement->addAttribute('name', $extensionName); $extensionElement->addAttribute('value', $extensionValue); if ($extensionExtender !== null) { $extensionElement->addAttribute('extender', $extensionExtender); } } }
/** * @param SmartHome $smartHome */ public function __construct(SmartHome $smartHome) { $this->smartHome = $smartHome; $reflectionClass = new \ReflectionClass($this); $this->request = new \SimpleXMLElement('<BaseRequest xmlns:xsd="http://www.w3.org/2001/XMLSchema" />'); $this->request->addAttribute('xsi:type', $reflectionClass->getShortName(), 'http://www.w3.org/2001/XMLSchema-instance'); }
/** * Save the setup data * @param array $dbconfig * @param array $preferences * * <?xml version="1.0" encoding="UTF-8"?> <shineisp> <config> <database> <hostname>localhost</hostname> <db>shineisp</db> <username>shineisp</username> <password>shineisp2013</password> </database> </config> </shineisp> */ public static function saveConfig($dbconfig, $version = null) { try { $xml = new SimpleXMLElement('<shineisp></shineisp>'); if (!empty($version)) { $xml->addAttribute('version', $version); } $xml->addAttribute('setupdate', date('Ymdhis')); $config = $xml->addChild('config'); // Database Configuration $database = $config->addChild('database'); $database->addChild('hostname', $dbconfig->hostname); $database->addChild('username', $dbconfig->username); $database->addChild('password', $dbconfig->password); $database->addChild('database', $dbconfig->database); // Get the xml string $xmlstring = $xml->asXML(); // Prettify and save the xml configuration $dom = new DOMDocument(); $dom->loadXML($xmlstring); $dom->formatOutput = true; $dom->saveXML(); // Save the config xml file if (@$dom->save(APPLICATION_PATH . "/configs/config.xml")) { Shineisp_Commons_Utilities::log("Update ShineISP config xml file"); return true; } else { throw new Exception("Error on saving the xml file in " . APPLICATION_PATH . "/configs/config.xml <br/>Please check the folder permissions"); } } catch (Exception $e) { throw new Exception($e->getMessage()); } return false; }
public function render() { $root = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><response/>'); $root->addAttribute("client", $_SERVER['REMOTE_ADDR']); $root->addAttribute("time", time()); $this->_encode($this->rootElement, $this->_params, $root); echo $root->asXML(); }
public function asElement() { $element = new \SimpleXMLElement('<payment/>'); $element->addAttribute('method', $this->_method); $element->addAttribute('currency', $this->_currency); $element->addChild('amount', $this->_amount); return $element; }
/** * getting the response * * @param UDate $time * * @return SimpleXMLElement */ protected function _getResponse(UDate $time) { Core::setUser(UserAccount::get(UserAccount::ID_SYSTEM_ACCOUNT)); //TODO $response = new SimpleXMLElement('<Response />'); $response->addAttribute('Time', trim($time)); $response->addAttribute('TimeZone', trim($time->getTimeZone()->getName())); return $response; }
/** * Transforms CannedResponse into a SimpleXMLElement * * @param SimpleXMLElement $root the node to which the CannedResponse is attached (passed by reference) * * @return void */ public function exportToXML($root) { // if old ids are important, modify code here if (false) { $root->addAttribute('id', $this->id); $root->addAttribute('tracker', $this->tracker->id); } $root->addChild('title', $this->title); $root->addChild('body', $this->body); }
/** * @covers src\Element\TextField::render * @todo Implement testRender(). */ public function testRender() { $html = $this->object->render(); $this->assertInstanceOf('\\SimpleXMLElement', simplexml_load_string($html)); $xmlElement = new \SimpleXMLElement('<input/>'); $xmlElement->addAttribute('id', 'textField'); $xmlElement->addAttribute('value', 'value'); $xmlElement->addAttribute('type', 'text'); $this->assertEquals($xmlElement, simplexml_load_string($html)); }
/** * define base xml tree * * return void */ protected function setBaseXml() { $this->baseXml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><urlset/>'); $this->baseXml->addAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9'); foreach ($this->spaces as $space => $schema) { if ($this->isType($space)) { $this->baseXml->addAttribute('xmlns:xmlns:' . $space, $schema); } } }
/** * Set general info */ protected function setGeneralInfo() { if (strlen(SessionAccountHandler::getName()) > 0) { $this->XML->AthleteLog->Athlete->addAttribute('Name', SessionAccountHandler::getName()); } $this->Activity->addAttribute('StartTime', $this->timeToString($this->Context->activity()->timestamp())); $this->Activity->Duration->addAttribute('TotalSeconds', (int) $this->Context->activity()->duration()); $this->Activity->Distance->addAttribute('TotalMeters', 1000 * $this->Context->activity()->distance()); $this->Activity->Calories->addAttribute('TotalCal', $this->Context->activity()->calories()); }
/** * @param string $title * @param string $link * @param string $description * @return SimpleXMLElement */ public static function getMrssXml($title, $link = null, $description = null) { $mrss = new SimpleXMLElement('<rss/>'); $mrss->addAttribute('version', '2.0'); $mrss->addAttribute('xmlns:content', 'http://www.w3.org/2001/XMLSchema-instance'); $channel = $mrss->addChild('channel'); $channel->addChild('title', self::stringToSafeXml($title)); $channel->addChild('link', $link); $channel->addChild('description', self::stringToSafeXml($description)); return $mrss; }
/** * {@inheritDoc} */ public function toXml(\SimpleXMLElement $parent = null) { if (null !== $parent) { $xml = $parent->addChild('Station'); } else { $xml = new \SimpleXMLElement('<Station />'); } $xml->addAttribute('name', $this->name); $xml->addAttribute('externalId', $this->id); return $xml; }
public function asElement() { $element = new \SimpleXMLElement('<shopping-basket/>'); $element->addAttribute('amount', $this->_amount); $element->addAttribute('currency', $this->_currency); $items = $element->addChild('items'); foreach ($this->_items as $item) { XmlUtils::sxml_append($items, $item->asElement()); } return $element; }
public function __construct(ResourceNode $node, array $resources = []) { $this->node = $node; $this->resources = $resources; // Create Manifest container $this->xml = new \SimpleXMLElement('<manifest></manifest>'); $this->xml->addAttribute('identifier', 'scorm_' . $node->getId()); $this->addMetadata(); $this->addOrganizations(); $this->addResources(); }
/** * Parse to XML * * @return string */ public function parse() { // Create root element $root = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><message/>'); // Add metadata $root->addAttribute("client", $_SERVER['REMOTE_ADDR']); $root->addAttribute("time", time()); // Start encoding $this->encode($this->root_element, $this->_data, &$root); return $root->asXML(); }
/** * Transforms Criteria into a SimpleXMLElement * * @param SimpleXMLElement $root the node to which the Criteria is attached (passed by reference) */ public function exportToXML($root, $xmlMapping) { $root->addAttribute('rank', $this->rank); if ($this->is_advanced) { $root->addAttribute('is_advanced', $this->is_advanced); } // if old ids are important, modify code here if (false) { $root->addAttribute('id', $this->id); $root->addAttribute('report', $this->report->id); } $root->addChild('field')->addAttribute('REF', array_search($this->field->id, $xmlMapping)); }
public static function generateSitemapWithoutPing() { global $SITEURL; $filenames = getFiles(GSDATAPAGESPATH); if (count($filenames)) { foreach ($filenames as $file) { if (isFile($file, GSDATAPAGESPATH, 'xml')) { $data = getXML(GSDATAPAGESPATH . $file); if ($data->url != '404' && $data->private != 'Y') { $pagesArray[] = array('url' => (string) $data->url, 'parent' => (string) $data->parent, 'date' => (string) $data->pubDate, 'menuStatus' => (string) $data->menuStatus); } } } } $pagesSorted = subval_sort($pagesArray, 'menuStatus'); $languages = return_i18n_available_languages(); $deflang = return_i18n_default_language(); $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><urlset></urlset>'); $xml->addAttribute('xsi:schemaLocation', 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd', 'http://www.w3.org/2001/XMLSchema-instance'); $xml->addAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9'); if (count($pagesSorted)) { foreach ($pagesSorted as $page) { // set <loc> if (count($languages) > 1) { $pos = strrpos($page['url'], '_'); if ($pos !== false) { $pageLoc = find_i18n_url(substr($page['url'], 0, $pos), $page['parent'], substr($page['url'], $pos + 1)); } else { $pageLoc = find_i18n_url($page['url'], $page['parent'], $deflang); } } else { $pageLoc = find_i18n_url($page['url'], $page['parent']); } // set <lastmod> $pageLastMod = makeIso8601TimeStamp(date("Y-m-d H:i:s", strtotime($page['date']))); // set <changefreq> $pageChangeFreq = 'weekly'; // set <priority> $pagePriority = $page['menuStatus'] == 'Y' ? '1.0' : '0.5'; //add to sitemap $url_item = $xml->addChild('url'); $url_item->addChild('loc', htmlspecialchars($pageLoc)); $url_item->addChild('lastmod', $pageLastMod); $url_item->addChild('changefreq', $pageChangeFreq); $url_item->addChild('priority', $pagePriority); } } //create xml file $file = GSROOTPATH . 'sitemap.xml'; XMLsave($xml, $file); }
private function exportProjectInfo(Project $project, SimpleXMLElement $project_node) { $access_value = $project->isPublic() ? Project::ACCESS_PUBLIC : Project::ACCESS_PRIVATE; $project_node->addAttribute('unix-name', $project->getUnixName()); $project_node->addAttribute('full-name', $project->getPublicName()); $project_node->addAttribute('description', $project->getDescription()); $project_node->addAttribute('access', $access_value); $project_node->addChild('long-description', ''); $services_node = $project_node->addChild('services'); foreach ($project->getServices() as $service) { $service_node = $services_node->addChild('service'); $service_node->addAttribute('shortname', $service->getShortName()); $service_node->addAttribute('enabled', $service->isUsed()); } }
/** * * @Route("/dashboard/series/timeline.xml") */ public function seriesTimelineAction(Request $request) { $repo = $this->get('doctrine_mongodb')->getManager()->getRepository('PumukitSchemaBundle:Series'); $series = $repo->findAll(); $XML = new \SimpleXMLElement("<data></data>"); $XML->addAttribute('wiki-url', $request->getUri()); $XML->addAttribute('wiki-section', 'Pumukit2 time-line Feed'); foreach ($series as $s) { $XMLSeries = $XML->addChild('event', $s->getTitle()); $XMLSeries->addAttribute('start', $s->getPublicDate()->format("M j Y H:i:s \\G\\M\\TP")); $XMLSeries->addAttribute('title', $s->getTitle()); $XMLSeries->addAttribute('link', $this->get('router')->generate('pumukit_webtv_series_index', array('id' => $s->getId()), true)); } return new Response($XML->asXML(), 200, array('Content-Type' => 'text/xml')); }
public function getDataSet($fixtures = array()) { $db = Database::get(); if (count($this->tables)) { $partial = new SimpleXMLElement('<schema></schema>'); $partial->addAttribute('version', '0.3'); $xml = simplexml_load_file(DIR_BASE_CORE . '/config/db.xml'); foreach ($xml->table as $t) { $name = (string) $t['name']; if (in_array($name, $this->tables)) { $this->appendXML($partial, $t); } } $schema = \Concrete\Core\Database\Schema\Schema::loadFromXMLElement($partial, $db); $platform = $db->getDatabasePlatform(); $queries = $schema->toSql($platform); foreach ($queries as $query) { $db->query($query); } } if (empty($fixtures)) { $fixtures = $this->fixtures; } $reflectionClass = new ReflectionClass(get_called_class()); $fixturePath = dirname($reflectionClass->getFilename()) . DIRECTORY_SEPARATOR . 'fixtures'; $compositeDs = new PHPUnit_Extensions_Database_DataSet_CompositeDataSet(array()); foreach ((array) $fixtures as $fixture) { $path = $fixturePath . DIRECTORY_SEPARATOR . "{$fixture}.xml"; $ds = $this->createMySQLXMLDataSet($path); $compositeDs->addDataSet($ds); } return $compositeDs; }
public static function sitemap() { $xml = new SimpleXMLElement('<urlset />'); $xml->addAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9'); $_GET = array(); URL::absolute(true); $links = array(); $Page = new Content_Page(); foreach ($Page->findShortList(array('IsEnabled = 1', 'Link <> '), 'Position asc') as $Page) { if (!in_array($Page->Link, $links)) { $links[] = $Page->Link; foreach ($Page->getController()->getSitemapNode() as $link) { $node = $xml->addChild('url'); $node->addChild('loc', $link); } } } $xml = $xml->asXML(); $xml = str_replace('<?xml version="1.0"?>', '<?xml version="1.0" encoding="UTF-8"?>', $xml); $dom = new DOMDocument('1.0'); $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $dom->loadXML($xml); $xml = $dom->saveXML(); file_put_contents(FILES_DIR . '/sitemap.xml', $xml); }
/** * @return string */ protected function prepareRequest() { $p = $this->plugin; $xml = new SimpleXMLElement("<{$this->getAPIName()}Request/>"); $xml->addAttribute('USERID', $p->user_id); $xml->addChild('Option'); $xml->addChild('Revision', 2); $xml->addChild('ImageParameters'); $this->addSenderInfo($xml); $this->addRecipientInfo($xml); //$xml->addChild('Container', 'FLATRATEBOX'); $this->addShippingContentsInfo($xml); if ($this->service['id'] != 'FirstClass') { $xml->addChild('InsuredAmount', $this->getPrice()); } $xml->addChild('GrossPounds', $this->getWeight('pounds')); $xml->addChild('GrossOunces', $this->getWeight('ounces')); $xml->addChild('ContentType', $p->content_type); if ($p->content_type == 'OTHER') { $xml->addChild('ContentTypeOther', $p->other_content_type); } $xml->addChild('Agreement', 'Y'); $xml->addChild('ImageType', 'PDF'); $xml->addChild('ImageLayout', 'ALLINONEFILE'); $xml->addChild('CustomerRefNo', $this->params['order_id']); if ($this->service['id'] != 'FirstClass' && $this->plugin->po_zip) { $xml->addChild('POZipCode', $this->plugin->po_zip); } $xml->addChild('Size', $p->package_size); // cut out xml header $xml = preg_replace("!^<\\?xml .*?\\?>!", "", $xml->saveXML()); return $xml; }
private function createImagesListXML($imagesList) { sort($imagesList); $imagesListXML = new SimpleXMLElement('<' . self::LIST_XML_LABEL_ITEMS . '/>'); foreach ($imagesList as $image) { if ($image == self::METADATA_XML_NAME) { continue; } $imageNode = $imagesListXML->addChild(self::LIST_XML_LABEL_ITEM); $imageNode->addChild(self::LIST_XML_LABEL_NAME, $image); } $imagesListXML->addAttribute(self::LIST_XML_ATTRIBUTE_METADATA, self::METADATA_XML_NAME); $count = count($imagesList); $imagesListXML->addAttribute(self::LIST_XML_ATTRIBUTE_COUNT, $count ? $count - 1 : 0); return $imagesListXML; }
public function setXml($xml) { if (is_a($xml, 'SimpleXMLElement')) { $this->_xml = $xml; } if (file_exists($xml)) { $this->_xml = simplexml_load_file($xml); $this->_xml->addAttribute('src', $xml); } else { if (is_string($xml)) { $this->_xml = simplexml_load_string($xml); } } if ($this->_xml) { $data = array(); foreach ($this->_xml->{$this->grouptag} as $params) { if (!isset($params['group'])) { continue; } $group = (string) $params['group']; foreach ($params->children() as $param) { if (!isset($param['default'])) { continue; } $data[$group][(string) $param['name']] = (string) $param['default']; } } if (!$this->_data) { $this->_data = $data; } else { $this->_data = array_merge($data, $this->_data); } } return $this; }
/** * Method to create a Picasa Album * * @param string $userID ID of user * @param string $title New album title * @param string $access New album access settings * @param string $summary New album summary * @param string $location New album location * @param int $time New album timestamp * @param array $keywords New album keywords * * @return mixed Data from Google. * * @since 12.3 */ public function createAlbum($userID = 'default', $title = '', $access = 'private', $summary = '', $location = '', $time = false, $keywords = array()) { if ($this->isAuthenticated()) { $time = $time ? $time : time(); $title = $title != '' ? $title : date('F j, Y'); $xml = new SimpleXMLElement('<entry></entry>'); $xml->addAttribute('xmlns', 'http://www.w3.org/2005/Atom'); $xml->addChild('title', $title); $xml->addChild('summary', $summary); $xml->addChild('gphoto:location', $location, 'http://schemas.google.com/photos/2007'); $xml->addChild('gphoto:access', $access); $xml->addChild('gphoto:timestamp', $time); $media = $xml->addChild('media:group', '', 'http://search.yahoo.com/mrss/'); $media->addChild('media:keywords', implode($keywords, ', ')); $cat = $xml->addChild('category', ''); $cat->addAttribute('scheme', 'http://schemas.google.com/g/2005#kind'); $cat->addAttribute('term', 'http://schemas.google.com/photos/2007#album'); $url = 'https://picasaweb.google.com/data/feed/api/user/' . urlencode($userID); $jdata = $this->query($url, $xml->asXML(), array('GData-Version' => 2, 'Content-type' => 'application/atom+xml'), 'post'); $xml = $this->safeXML($jdata->body); return new JGoogleDataPicasaAlbum($xml, $this->options, $this->auth); } else { return false; } }
protected static function _recursiveXmlEncode($valueToEncode, $rootNodeName = 'data', &$xml = null) { if (null == $xml) { $xml = new SimpleXMLElement('<' . $rootNodeName . '/>'); } foreach ($valueToEncode as $key => $value) { if (is_numeric($key)) { $key = $rootNodeName; } if ($key == self::XML_ATTRIBUTES) { foreach ($value as $attrName => $attrValue) { $xml->addAttribute($attrName, $attrValue); } } else { // Filter non valid XML characters $key = preg_replace('/[^a-z0-9\\-\\_\\.\\:]/i', '', $key); if (is_array($value)) { $node = self::_isAssoc($value) ? $xml->addChild($key) : $xml; self::_recursiveXmlEncode($value, $key, $node); } else { $value = htmlspecialchars($value, null, 'UTF-8'); // $value = htmlentities($value, null, 'UTF-8'); $xml->addChild($key, $value); } } } return $xml; }
public function exportDetails(\SimpleXMLElement $sx) { $default = self::getDefault(); if (is_object($default) && $default->getTreeID() == $this->getTreeID()) { $sx->addAttribute('default', 1); } }