本文整理汇总了PHP中DomDocument::createCDATASection方法的典型用法代码示例。如果您正苦于以下问题:PHP DomDocument::createCDATASection方法的具体用法?PHP DomDocument::createCDATASection怎么用?PHP DomDocument::createCDATASection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DomDocument
的用法示例。
在下文中一共展示了DomDocument::createCDATASection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: DomDocument
function props_to_xml()
{
# make the source xml
# make doc and root
$xml = new DomDocument();
$root = $xml->createElement('request');
$root->setAttribute('controller', params('controller'));
$root->setAttribute('action', params('action'));
$root = $xml->appendChild($root);
# unpack the props into xml
foreach ($this->props as $k => $v) {
# if it will become xml, do that, otherwise make a dumb tag
if (is_object($v) && method_exists($v, 'to_xml')) {
$obj_xml = $v->to_xml(array(), true, true);
$obj_xml = $xml->importNode($obj_xml->documentElement, true);
$root->appendChild($obj_xml);
} else {
$node = $xml->createElement($k);
if (strpos($v, '<') !== false || strpos($v, '>') !== false || strpos($v, '&') !== false) {
$cdata = $xml->createCDATASection($v);
} else {
$cdata = $xml->createTextNode($v);
}
$node->appendChild($cdata);
$node = $root->appendChild($node);
}
}
return $xml;
}
示例2: getXmlAnswer
/**
* Get the answer value as an xml element
* @param \DomDocument $dom
* @param \Jazzee\Entity\Answer $answer
* @param integer $version
* @return \DomElement
*/
public function getXmlAnswer(\DomDocument $dom, \Jazzee\Entity\Answer $answer, $version)
{
$eXml = $dom->createElement('element');
$eXml->setAttribute('elementId', $this->_element->getId());
$eXml->setAttribute('title', htmlentities($this->_element->getTitle(), ENT_COMPAT, 'utf-8'));
$eXml->setAttribute('name', htmlentities($this->_element->getName(), ENT_COMPAT, 'utf-8'));
$eXml->setAttribute('type', htmlentities($this->_element->getType()->getClass(), ENT_COMPAT, 'utf-8'));
$eXml->setAttribute('weight', $this->_element->getWeight());
$elementsAnswers = $answer->getElementAnswersForElement($this->_element);
switch ($version) {
case 1:
if ($value = $this->rawValue($answer)) {
$eXml->appendChild($dom->createCDATASection(preg_replace('/[\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F]/', '', $value)));
}
break;
case 2:
$value = null;
if (isset($elementsAnswers[0])) {
$value = $this->_element->getItemById($elementsAnswers[0]->getEInteger())->getValue();
$name = $this->_element->getItemById($elementsAnswers[0]->getEInteger())->getName();
$id = $this->_element->getItemById($elementsAnswers[0]->getEInteger())->getId();
}
if ($value) {
$vXml = $dom->createElement('value');
$vXml->setAttribute('valueId', $id);
$vXml->setAttribute('name', htmlentities($name, ENT_COMPAT, 'utf-8'));
$vXml->appendChild($dom->createCDATASection(preg_replace('/[\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F]/', '', $value)));
$eXml->appendChild($vXml);
}
break;
}
return $eXml;
}
示例3: exportToXML
/**
* Exports data to xml
*
* @param string $fileName
* @return void
*/
public function exportToXML($fileName)
{
if (!$fileName) {
$fileName = 'export-' . time() . '.xml';
}
$doc = new DomDocument();
$doc->preserveWhiteSpace = FALSE;
$doc->formatOutput = TRUE;
$root = $doc->createElement('Table');
$root = $doc->appendChild($root);
$fieldsMetaData = array();
$collection = $this->getCollection();
foreach ($collection as $row) {
if (empty($fieldsMetaData)) {
$row->load($row->getId());
$fieldsMetaData = $row->getTableMetaData();
}
$rows = $doc->createElement('Row');
$rows = $root->appendChild($rows);
foreach ($this->columns as $field) {
if (isset($fieldsMetaData[$field['field']])) {
$column = $doc->createElement('Column');
$column->setAttribute('name', $fieldsMetaData[$field['field']]['COLUMN_NAME']);
$column->setAttribute('type', $fieldsMetaData[$field['field']]['DATA_TYPE']);
$cData = $doc->createCDATASection('');
$cData->appendData($row->{$field['fieldMethod']}());
$column->appendChild($cData);
$rows->appendChild($column);
}
}
}
header('Content-type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $fileName . '"');
echo $doc->saveXML();
}
示例4: loadPageHTML
static function loadPageHTML($params)
{
$params = self::_extractParams($params);
$return = '';
$return_first = !empty($params['first']) && $params['first'] == 'TRUE' ? TRUE : FALSE;
$page = false;
if (!empty($params['path']) && CI()->zone == 'website') {
$load_params = array('path' => $params['path']);
} else {
if (!empty($params['id']) && CI()->zone == 'website') {
$load_params = array('page_id' => $params['id']);
}
}
$check_cache = !empty($params['cache']) && $params['cache'] == 'FALSE' ? FALSE : TRUE;
$get_children = !empty($params['children']) && $params['children'] == 'FALSE' ? FALSE : TRUE;
$page = CI()->loadPage($load_params, 'html', FALSE, $check_cache, $get_children);
if ($page) {
// Convert to XML
$output_dom = new DomDocument('1.0', 'UTF-8');
$output = array2XML($page);
$node = $output_dom->createCDATASection($output);
$newnode = $output_dom->appendChild($node);
return $output_dom;
}
}
示例5: buildMessages
/**
* Transforms Message objects into XML
* @return mixed
*/
protected function buildMessages()
{
$data = $this->dom->createElement('data');
foreach ($this->connector->getMessages() as $Message) {
$element = $this->dom->createElement('message');
$sendername = $this->dom->createElement('sendername', $Message->getSenderName());
$text = $this->dom->createElement('text');
$recipients = $this->dom->createElement('recipients');
foreach ($Message->getRecipients() as $Recipient) {
$msisdn = $this->dom->createElement('msisdn', $Recipient);
$recipients->appendChild($msisdn);
}
$text->appendChild($this->dom->createCDATASection($Message->getContent()));
$element->appendChild($sendername);
$element->appendChild($text);
$element->appendChild($recipients);
$data->appendChild($element);
}
return $data;
}
示例6: rssObservations
public function rssObservations()
{
global $objObservation, $objInstrument, $objLocation, $objPresentations, $objObserver, $baseURL, $objUtil;
$dom = new DomDocument('1.0', 'US-ASCII');
// add root fcga -> The header
$rssInfo = $dom->createElement('rss');
$rssDom = $dom->appendChild($rssInfo);
$attr = $dom->createAttribute("version");
$rssInfo->appendChild($attr);
$attrText = $dom->createTextNode("2.0");
$attr->appendChild($attrText);
$attr = $dom->createAttribute("xmlns:content");
$rssInfo->appendChild($attr);
$attrText = $dom->createTextNode("http://purl.org/rss/1.0/modules/content/");
$attr->appendChild($attrText);
$attr = $dom->createAttribute("xmlns:dc");
$rssInfo->appendChild($attr);
$attrText = $dom->createTextNode("http://purl.org/dc/elements/1.1/");
$attr->appendChild($attrText);
$attr = $dom->createAttribute("xmlns:atom");
$rssInfo->appendChild($attr);
$attrText = $dom->createTextNode("http://www.w3.org/2005/Atom");
$attr->appendChild($attrText);
// add root - <channel>
$channelDom = $rssDom->appendChild($dom->createElement('channel'));
// add root - <channel> - <title>
$titleDom = $channelDom->appendChild($dom->createElement('title'));
$titleDom->appendChild($dom->createTextNode("DeepskyLog"));
// add root - <channel> - <description>
$descDom = $channelDom->appendChild($dom->createElement('description'));
$descDom->appendChild($dom->createTextNode("DeepskyLog - visual deepsky and comets observations"));
// add root - <channel> - <atom>
$atomDom = $channelDom->appendChild($dom->createElement('atom:link'));
$attr = $dom->createAttribute("href");
$atomDom->appendChild($attr);
$attrText = $dom->createTextNode($baseURL . "observations.rss");
$attr->appendChild($attrText);
$attr = $dom->createAttribute("rel");
$atomDom->appendChild($attr);
$attrText = $dom->createTextNode("self");
$attr->appendChild($attrText);
$attr = $dom->createAttribute("type");
$atomDom->appendChild($attr);
$attrText = $dom->createTextNode("application/rss+xml");
$attr->appendChild($attrText);
// add root - <channel> - <link>
$linkDom = $channelDom->appendChild($dom->createElement('link'));
$linkDom->appendChild($dom->createTextNode("http://www.deepskylog.org/"));
$theDate = date('r');
// add root - <channel> - <link>
$lbdDom = $channelDom->appendChild($dom->createElement('lastBuildDate'));
$lbdDom->appendChild($dom->createTextNode($theDate));
// Get the new deepsky observations of the last month
$theDate = date('Ymd', strtotime('-1 month'));
$_GET['minyear'] = substr($theDate, 0, 4);
$_GET['minmonth'] = substr($theDate, 4, 2);
$_GET['minday'] = substr($theDate, 6, 2);
$query = array("catalog" => '%', "mindate" => $objUtil->checkGetDate('minyear', 'minmonth', 'minday'));
$result = $objObservation->getObservationFromQuery($query, 'A');
while (list($key, $value) = each($result)) {
// add root - <channel> - <item>
$itemDom = $channelDom->appendChild($dom->createElement('item'));
$titleDom = $itemDom->appendChild($dom->createElement('title'));
$titleDom->appendChild($dom->createTextNode($value['observername'] . " : " . $value['objectname'] . " with " . htmlspecialchars_decode($objInstrument->getInstrumentPropertyFromId($value['instrumentid'], 'name')) . " from " . $objLocation->getLocationPropertyFromId($objObservation->getDsObservationProperty($value['observationid'], 'locationid'), 'name')));
$linkDom = $itemDom->appendChild($dom->createElement('link'));
$linkDom->appendChild($dom->createCDATASection($baseURL . "index.php?indexAction=detail_observation&observation=" . $value['observationid'] . "&QobsKey=0&dalm=D"));
$descDom = $itemDom->appendChild($dom->createElement('description'));
$descDom->appendChild($dom->createCDATASection($objPresentations->br2nl(utf8_encode($value['observationdescription']))));
$authorDom = $itemDom->appendChild($dom->createElement('dc:creator'));
$authorDom->appendChild($dom->createCDATASection($value['observername']));
$guidDom = $itemDom->appendChild($dom->createElement('guid'));
$guidDom->appendChild($dom->createTextNode("deepsky" . $value['observationid']));
$attr = $dom->createAttribute("isPermaLink");
$guidDom->appendChild($attr);
$attrText = $dom->createTextNode("false");
$attr->appendChild($attrText);
$pubDateDom = $itemDom->appendChild($dom->createElement('pubDate'));
date_default_timezone_set('UTC');
$time = -999;
$obs = $objObservation->getAllInfoDsObservation($value['observationid']);
$time = $obs['time'];
if ($time >= "0") {
$hour = (int) ($time / 100);
$minute = $time - 100 * $hour;
} else {
$hour = 0;
$minute = 0;
}
$date = $value['observationdate'];
$year = substr($date, 0, 4);
$month = substr($date, 4, 2);
$day = substr($date, 6, 2);
$pubDateDom->appendChild($dom->createTextNode(date("r", mktime($hour, $minute, 0, $month, $day, $year))));
}
include_once "cometobjects.php";
include_once "observers.php";
include_once "instruments.php";
include_once "locations.php";
include_once "cometobservations.php";
include_once "icqmethod.php";
//.........这里部分代码省略.........
示例7: createRss
private function createRss()
{
$dom = new DomDocument("1.0", "utf-8");
$dom->formatOutput = true;
$dom->preserveWhiteSpace = false;
//create $dom and done format
$rss = $dom->createElement("rss");
$dom->appendChild($rss);
//create rss
$version = $dom->createAttribute("version");
$version->value = '2.0';
//choose version
$rss->appendChild($version);
$chanel = $dom->createElement("chanel");
$title = $dom->createElement("title", self::RSS_TITLE);
$link = $dom->createElement("link", self::RSS_LINK);
$chanel->appendChild($title);
$chanel->appendChild($link);
$chanel->appendChild($link);
$rss->appendChild($chanel);
$lenta = $this->getNews();
if (!$lenta) {
return false;
}
foreach ($lenta as $news) {
$item = $dom->createElement("item");
$title = $dom->createElement("title", $news["title"]);
$category = $dom->createElement("category", $news["category"]);
//обёртка над description
$desc = $dom->createElement("description");
$cdata = $dom->createCDATASection($news["description"]);
$desc->appendChild($cdata);
$link = $dom->createElement("link", "#");
$dt = date("r", $news["datetime"]);
$pubDate = $dom->createElement("pubDate", $dt);
$item->appendChild($title);
$item->appendChild($link);
$item->appendChild($desc);
$item->appendChild($pubDate);
$item->appendChild($category);
$chanel->appendChild($item);
}
$dom->save(self::RSS_NAME);
}
示例8: manipulate
/**
* General manipulate wrapper method.
*
* @param string $input The XML fragment to be manipulated. We are only
* interested in the <extension><CSVData> fragment added in the
* MIK mappings file.
*
* @return string
* One of the manipulated XML fragment, the original input XML if the
* input is not the fragment we are interested in, or an empty string,
* which as the effect of removing the empty <extension><CSVData>
* fragement from our MODS (if there was an error, for example, we don't
* want empty extension elements in our MODS documents).
*/
public function manipulate($input)
{
$dom = new \DomDocument();
$dom->loadxml($input, LIBXML_NSCLEAN);
// Test to see if the current fragment is <extension><CSVData>.
$xpath = new \DOMXPath($dom);
$csvdatas = $xpath->query("//extension/CSVData");
// There should only be one <CSVData> fragment in the incoming
// XML. If there is 0 or more than 1, return the original.
if ($csvdatas->length === 1) {
$csvdata = $csvdatas->item(0);
$csvid = $dom->createElement('id_in_csv', $this->record_key);
$csvdata->appendChild($csvid);
$timestamp = date("Y-m-d H:i:s");
// Add the <CSVRecord> element.
$csvrecord = $dom->createElement('CSVRecord');
$now = $dom->createAttribute('timestamp');
$now->value = $timestamp;
$csvrecord->appendChild($now);
$mimetype = $dom->createAttribute('mimetype');
$mimetype->value = 'application/json';
$csvrecord->appendChild($mimetype);
try {
$metadata_path = $this->settings['FETCHER']['temp_directory'] . DIRECTORY_SEPARATOR . $this->record_key . '.metadata';
$metadata_contents = file_get_contents($metadata_path);
$metadata_contents = unserialize($metadata_contents);
$metadata_contents = json_encode($metadata_contents);
} catch (Exception $e) {
$message = "Problem creating <CSVRecord> element for object " . $this->record_key . ":" . $e->getMessage();
$this->log->addInfo("AddCsvData", array('CSV metadata warning' => $message));
return '';
}
// If the metadata contains the CDATA end delimiter, log and return.
if (preg_match('/\\]\\]>/', $metadata_contents)) {
$message = "CSV metadata for object " . $this->record_key . ' contains the CDATA end delimiter ]]>';
$this->log->addInfo("AddCsvData", array('CSV metadata warning' => $message));
return '';
}
// If we've made it this far, add the metadata to <CcvData> as
// CDATA and return the modified XML fragment.
if (strlen($metadata_contents)) {
$cdata = $dom->createCDATASection($metadata_contents);
$csvrecord->appendChild($cdata);
$csvdata->appendChild($csvrecord);
}
return $dom->saveXML($dom->documentElement);
} else {
// If current fragment is not <extension><CSVData>, return it
// unmodified.
return $input;
}
}
示例9: readDataBlock
protected function readDataBlock()
{
$v4b43b0aee35624cd95b910189b3dc231 = new XMLReader();
$v4b43b0aee35624cd95b910189b3dc231->open($this->file_path);
$v2245023265ae4cf87d02c8b6ba991139 = mainConfiguration::getInstance();
$vf7c163939469a0b7becb4e4e6a94efac = $v2245023265ae4cf87d02c8b6ba991139->includeParam('system.kernel') . 'subsystems/import/schemes/' . $this->type . '.xsd';
if (is_file($vf7c163939469a0b7becb4e4e6a94efac)) {
$v4b43b0aee35624cd95b910189b3dc231->setSchema($vf7c163939469a0b7becb4e4e6a94efac);
}
$v9a09b4dfda82e3e665e31092d1c3ec8d = new DomDocument("1.0", "utf-8");
$v07214c6750d983a32e0a33da225c4efd = array('umidump/registry/key', 'umidump/files/file', 'umidump/directories/directory', 'umidump/langs/lang', 'umidump/domains/domain', 'umidump/templates/template', 'umidump/datatypes/datatype', 'umidump/types/type', 'umidump/pages/page', 'umidump/objects/object', 'umidump/relations/relation', 'umidump/options/entity', 'umidump/restrictions/restriction', 'umidump/permissions/permission', 'umidump/hierarchy/relation');
$v95723b5e620e47cf613462b9f293282a = 0;
$v4757fe07fd492a8be0ea6a760d683d6e = 0;
$v5f0b6ebc4bea10285ba2b8a6ce78b863 = $v9a09b4dfda82e3e665e31092d1c3ec8d;
$v7aa28ed115707345d0274032757e8991 = $v4b43b0aee35624cd95b910189b3dc231->read();
while ($v7aa28ed115707345d0274032757e8991 && $v95723b5e620e47cf613462b9f293282a <= $this->block_size) {
switch ($v4b43b0aee35624cd95b910189b3dc231->nodeType) {
case XMLReader::ELEMENT:
$v3f02ab347aeca12e013036ce82046c38 = $this->__getNodePath($v5f0b6ebc4bea10285ba2b8a6ce78b863);
if (in_array($v3f02ab347aeca12e013036ce82046c38 . "/" . $v4b43b0aee35624cd95b910189b3dc231->name, $v07214c6750d983a32e0a33da225c4efd)) {
if ($v4757fe07fd492a8be0ea6a760d683d6e++ < $this->offset) {
$v7aa28ed115707345d0274032757e8991 = $v4b43b0aee35624cd95b910189b3dc231->next();
continue 2;
}
if ($v95723b5e620e47cf613462b9f293282a + 1 > $this->block_size) {
break 2;
}
$v95723b5e620e47cf613462b9f293282a++;
}
$v65c10911d8b8591219a21ebacf46da01 = $v9a09b4dfda82e3e665e31092d1c3ec8d->createElement($v4b43b0aee35624cd95b910189b3dc231->name, $v4b43b0aee35624cd95b910189b3dc231->value);
$v5f0b6ebc4bea10285ba2b8a6ce78b863->appendChild($v65c10911d8b8591219a21ebacf46da01);
if (!$v4b43b0aee35624cd95b910189b3dc231->isEmptyElement) {
$v5f0b6ebc4bea10285ba2b8a6ce78b863 = $v65c10911d8b8591219a21ebacf46da01;
}
if ($v4b43b0aee35624cd95b910189b3dc231->attributeCount) {
while ($v4b43b0aee35624cd95b910189b3dc231->moveToNextAttribute()) {
$v815be97df65d6c4b510cd07189c5347a = $v9a09b4dfda82e3e665e31092d1c3ec8d->createAttribute($v4b43b0aee35624cd95b910189b3dc231->name);
$v815be97df65d6c4b510cd07189c5347a->appendChild($v9a09b4dfda82e3e665e31092d1c3ec8d->createTextNode($v4b43b0aee35624cd95b910189b3dc231->value));
$v65c10911d8b8591219a21ebacf46da01->appendChild($v815be97df65d6c4b510cd07189c5347a);
}
}
break;
case XMLReader::END_ELEMENT:
$v5f0b6ebc4bea10285ba2b8a6ce78b863 = $v5f0b6ebc4bea10285ba2b8a6ce78b863->parentNode;
break;
case XMLReader::ATTRIBUTE:
$v815be97df65d6c4b510cd07189c5347a = $v9a09b4dfda82e3e665e31092d1c3ec8d->createAttribute($v4b43b0aee35624cd95b910189b3dc231->name);
$v815be97df65d6c4b510cd07189c5347a->appendChild($v9a09b4dfda82e3e665e31092d1c3ec8d->createTextNode($v4b43b0aee35624cd95b910189b3dc231->value));
$v5f0b6ebc4bea10285ba2b8a6ce78b863->appendChild($v815be97df65d6c4b510cd07189c5347a);
break;
case XMLReader::TEXT:
$vc7824f3d4d5f7b2f22d034758c1e9454 = $v9a09b4dfda82e3e665e31092d1c3ec8d->createTextNode($v4b43b0aee35624cd95b910189b3dc231->value);
$v5f0b6ebc4bea10285ba2b8a6ce78b863->appendChild($vc7824f3d4d5f7b2f22d034758c1e9454);
break;
case XMLReader::CDATA:
$vd9ef6bda8fb69f1c7e277bd1c2cd21d1 = $v9a09b4dfda82e3e665e31092d1c3ec8d->createCDATASection($v4b43b0aee35624cd95b910189b3dc231->value);
$v5f0b6ebc4bea10285ba2b8a6ce78b863->appendChild($vd9ef6bda8fb69f1c7e277bd1c2cd21d1);
break;
case XMLReader::NONE:
default:
}
$v7aa28ed115707345d0274032757e8991 = $v4b43b0aee35624cd95b910189b3dc231->read();
}
$this->offset += $v95723b5e620e47cf613462b9f293282a;
if (!$v7aa28ed115707345d0274032757e8991) {
$this->complete = true;
}
return $v9a09b4dfda82e3e665e31092d1c3ec8d;
}
示例10: create
/**
* Implemet the pages/create ane emails/create methods to ceate a new web
* page test or a new email test.
*
* @param string $test_type Type of the test (TYPE_PAGE||TYPE_EMAIL)
* @param array $params Parameters of the test
* @return Litmus_Test
*/
public static function create($test_type, $params)
{
$dom = new DomDocument('1.0', null);
$root = $dom->createElement('test_set');
$dom->appendChild($root);
// application element
$applications = $dom->createElement('applications');
$type = $dom->createAttribute('type');
$type->appendChild($dom->createTextNode('array'));
$applications->appendChild($type);
$root->appendChild($applications);
if (isset($params['applications'])) {
foreach ($params['applications'] as $app) {
$app_node = $dom->createElement('application');
$code_node = $dom->createElement('code', $app);
$app_node->appendChild($code_node);
$applications->appendChild($app_node);
}
}
// url node
if (isset($params['url'])) {
$node = $dom->createElement('url', $params['url']);
$root->appendChild($node);
}
// save defaults node
$node = $dom->createElement('save_defaults', isset($params['save_defaults']) && $params['save_defaults'] ? 'true' : 'false');
$root->appendChild($node);
// use defaults node
$node = $dom->createElement('use_defaults', isset($params['use_defaults']) && $params['use_defaults'] ? 'true' : 'false');
$root->appendChild($node);
if (isset($params['email_source'])) {
$email_node = $dom->createElement('email_source');
$root->appendChild($email_node);
$node = $dom->createElement('body');
$data = $dom->createCDATASection($params['email_source']['body']);
$node->appendChild($data);
$email_node->appendChild($node);
$node = $dom->createElement('subject', $params['email_source']['subject']);
$email_node->appendChild($node);
}
$request = $dom->saveXML();
$rc = Litmus_RESTful_Client::singleton();
$res = $rc->post($test_type . '.xml', $request);
$test = Litmus_Test::load($res);
return $test;
}
示例11: produceAtom
protected function produceAtom($feedArray)
{
// Atom 1.0
$doc = new DomDocument('1.0', 'utf-8');
$feed = $doc->createElement('feed');
$feed->setAttribute('xmlns:itunes', 'http://www.itunes.com/dtds/podcast-1.0.dtd');
$feed->setAttribute('xmlns', 'http://www.w3.org/2005/Atom');
$feed->setAttribute('xml:lang', $feedArray['language']);
$doc->appendChild($feed);
$title = $doc->createElement('title', $feedArray['title']);
$title->setAttribute('type', 'text');
$subtitle = $doc->createElement('subtitle', $feedArray['description']);
$subtitle->setAttribute('type', 'text');
$updated = $doc->createElement('updated', date('Y-m-d\\TH:i:sP'));
$generator = $doc->createElement('generator', ProjectConfiguration::getApplicationName() . ' Feed Module');
$link_alternate = $doc->createElement('link');
$link_alternate->setAttribute('rel', 'alternate');
$link_alternate->setAttribute('type', 'text/html');
$link_alternate->setAttribute('href', $feedArray['link']);
$link_self = $doc->createElement('link');
$link_self->setAttribute('rel', 'self');
$link_self->setAttribute('type', 'application/atom+xml');
$link_self->setAttribute('href', $feedArray['atom_link']);
$id = $doc->createElement('id', $feedArray['link']);
$author = $doc->createElement('author');
$a_name = $doc->createElement('name', ProjectConfiguration::getApplicationName());
$a_email = $doc->createElement('email', ProjectConfiguration::getApplicationEmailAddress());
$a_uri = $doc->createElement('uri', $this->getController()->genUrl('@homepage', true));
$author->appendChild($a_name);
$author->appendChild($a_email);
$author->appendChild($a_uri);
$feed->appendChild($title);
$feed->appendChild($subtitle);
$feed->appendChild($updated);
$feed->appendChild($generator);
$feed->appendChild($link_alternate);
$feed->appendChild($link_self);
$feed->appendChild($id);
$feed->appendChild($author);
$itunes_explicit = $doc->createElement('itunes:explicit', $feedArray["is_nsfw"]);
$itunes_summary = $doc->createElement('itunes:summary', substr($feedArray['description'], 0, 3999));
$itunes_category = $doc->createElement('itunes:category');
$itunes_category->setAttribute('text', 'Technology');
$itunes_subcategory = $doc->createElement('itunes:category');
$itunes_subcategory->setAttribute('text', 'Podcasting');
$itunes_category->appendChild($itunes_subcategory);
// Including the itunes:owner messes with the feed by overriding the title in iTunes.
$feed->appendChild($itunes_explicit);
$feed->appendChild($itunes_summary);
$feed->appendChild($itunes_category);
foreach ($feedArray['entries'] as $entry) {
$fentry = $doc->createElement('entry');
//$fentry->setAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
$e_title = $doc->createElement('title');
$e_title->setAttribute('type', 'html');
$cdata_title = $doc->createCDATASection($entry['title']);
$e_title->appendChild($cdata_title);
$thumbnail_tag = $entry['thumbnail'] ? '<p><img src="' . $entry['thumbnail'] . '"/></p>' : '';
$e_summary = $doc->createElement('summary');
$e_summary->setAttribute('type', 'html');
$cdata_summary = $doc->createCDATASection($thumbnail_tag . substr($entry['description'], 0, 500));
$e_summary->appendChild($cdata_summary);
$e_published = $doc->createElement('published', date('Y-m-d\\TH:i:sP', $entry['released']));
$e_updated = $doc->createElement('updated', date('Y-m-d\\TH:i:sP', $entry['modified'] > $entry['released'] ? $entry['modified'] : $entry['released']));
$e_link = $doc->createElement('link');
$e_link->setAttribute('rel', 'alternate');
$e_link->setAttribute('type', 'text/html');
$e_link->setAttribute('href', $entry['link']);
$e_id = $doc->createElement('id', $entry['link']);
$e_author = $doc->createElement('author');
$ea_name = $doc->createElement('name', $entry['author']['name']);
$e_author->appendChild($ea_name);
$e_enclosure = $doc->createElement('link');
$e_enclosure->setAttribute('rel', 'enclosure');
$audio_info = $this->getRemoteInfo($entry['audio_location']);
$e_enclosure->setAttribute('type', $audio_info['type']);
$e_enclosure->setAttribute('href', $entry['audio_location']);
$e_enclosure->setAttribute('length', $audio_info['length']);
$e_enclosure->setAttribute('title', 'Audio');
$e_content = $doc->createElement('content');
//$e_content->setAttribute('xmlns:xhtml',
// 'http://www.w3.org/1999/xhtml');
$e_content->setAttribute('type', 'xhtml');
$fragment = $doc->createDocumentFragment();
$fragment->appendXML($thumbnail_tag . $entry['content']);
$e_div = $doc->createElement('div');
$e_div->setAttribute('xmlns', 'http://www.w3.org/1999/xhtml');
$e_div->appendChild($fragment);
$e_content->appendChild($e_div);
if ($entry['reddit_post_url']) {
$e_comments = $doc->createElement('link');
$e_comments->setAttribute('rel', 'replies');
$e_comments->setAttribute('type', 'text/html');
$e_comments->setAttribute('href', $entry['reddit_post_url']);
}
$fentry->appendChild($e_title);
$fentry->appendChild($e_summary);
$fentry->appendChild($e_published);
$fentry->appendChild($e_updated);
$fentry->appendChild($e_link);
//.........这里部分代码省略.........
示例12: output_rss
/**
* generate rss feed output
*
* @param array $items post item array
* @return void
*/
function output_rss($posts, $cache = false, $file = NULL)
{
global $config;
if (!is_array($posts)) {
die('no posts ...');
}
$lastmod = strtotime($posts[0]['date']);
// http headers
header('Content-type: application/xml; charset=utf-8');
// set mime ... application/rss+xml
header('Cache-Control: max-age=300, must-revalidate');
// cache control 5 mins
header('Last-Modified: ' . gmdate('D, j M Y H:i:s T', $lastmod));
//D, j M Y H:i:s T
header('Expires: ' . gmdate('D, j M Y H:i:s T', time() + 300));
// conditional get ...
$ifmod = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] === gmdate('D, j M Y H:i:s T', $lastmod) : FALSE;
if (FALSE !== $ifmod) {
$config['DEBUG'] && error_log('[DEBUG] 304 NOT MODIFIED :)');
header('HTTP/1.0 304 Not Modified');
exit;
}
// build rss using dom
$dom = new DomDocument();
$dom->formatOutput = TRUE;
$dom->encoding = 'utf-8';
$rss = $dom->createElement('rss');
$rss->setAttribute('version', '2.0');
$rss->setAttribute('xmlns:atom', 'http://www.w3.org/2005/Atom');
// atom for self
$rss->setAttribute('xmlns:media', 'http://search.yahoo.com/mrss/');
//xmlns:media="http://search.yahoo.com/mrss/"
$dom->appendChild($rss);
$channel = $dom->createElement('channel');
$rss->appendChild($channel);
// set up feed properties
$title = $dom->createElement('title', 'My Tumblr Dashboard Feed');
$channel->appendChild($title);
$link = $dom->createElement('link', 'http://tumblr.com/dashboard');
$channel->appendChild($link);
$description = $dom->createElement('description', 'My tumblr dashboard feed');
$channel->appendChild($description);
$language = $dom->createElement('language', 'en-us');
$channel->appendChild($language);
$pubDate = $dom->createElement('pubDate', $posts[0]['date']);
$channel->appendChild($pubDate);
$lastBuild = $dom->createElement('lastBuildDate', date(DATE_RSS));
$channel->appendChild($lastBuild);
$docs = $dom->createElement('docs', 'http://blogs.law.harvard.edu/tech/rss');
$channel->appendChild($docs);
$generator = $dom->createElement('generator', 'Tumbler API');
$channel->appendChild($generator);
$managingEditor = $dom->createElement('managingEditor', 'editor@example.com (editor)');
$channel->appendChild($managingEditor);
$webMaster = $dom->createElement('webMaster', 'webmaster@example.com (webmaster)');
$channel->appendChild($webMaster);
$self = $dom->createElement('atom:link');
$self->setAttribute('href', 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
$self->setAttribute('rel', 'self');
$self->setAttribute('type', 'application/rss+xml');
$channel->appendChild($self);
// add items
foreach ($posts as $post) {
$item = $dom->createElement('item');
$link = $dom->createElement('link', $post['link']);
// $link->appendChild( $dom->createTextNode( $item['link'] ) );
$item->appendChild($link);
$title = $dom->createElement('title', $post['title']);
$item->appendChild($title);
$description = $dom->createElement('description');
// put description in cdata to avoid breakage
$cdata = $dom->createCDATASection($post['description']);
$description->appendChild($cdata);
$item->appendChild($description);
$pubDate = $dom->createElement('pubDate', $post['date']);
$item->appendChild($pubDate);
$guid = $dom->createElement('guid', $post['link']);
$item->appendChild($guid);
// if enclosure ...
if (isset($post['enclosure'])) {
//<enclosure url="http://www.webmonkey.com/monkeyrock.mpg" length="2471632" type="video/mpeg"/>
$enclosure = $dom->createElement('enclosure');
$enclosure->setAttribute('url', $post['enclosure']['url']);
$enclosure->setAttribute('length', '1024');
// this is required but doesn't need to be accurate
$enclosure->setAttribute('type', $post['enclosure']['type']);
// valid mime type
$item->appendChild($enclosure);
// media rss?
}
$channel->appendChild($item);
}
// cache output
if ($config['cache']['output'] == TRUE && is_writable($config['cache']['dir'])) {
//.........这里部分代码省略.........
示例13: createLanguageDescription
/**
* Creates a language description file for TAO using the RDF-XML language.
*
* @access public
* @author Jerome Bogaerts <jerome@taotesting.com>
* @param string code string code The language code e.g. fr-FR.
* @param string label string label The language label e.g. French in english.
* @return DomDocument
*/
public static function createLanguageDescription($code, $label)
{
$returnValue = null;
$languageType = CLASS_LANGUAGES;
$languagePrefix = 'http://www.tao.lu/Ontologies/TAO.rdf#Lang';
$rdfNs = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
$rdfsNs = 'http://www.w3.org/2000/01/rdf-schema#';
$xmlNs = 'http://www.w3.org/XML/1998/namespace';
$xmlnsNs = 'http://www.w3.org/2000/xmlns/';
$base = 'http://www.tao.lu/Ontologies/TAO.rdf#';
$doc = new DomDocument('1.0', 'UTF-8');
$doc->formatOutput = true;
$rdfNode = $doc->createElementNS($rdfNs, 'rdf:RDF');
$rdfNode->setAttributeNS($xmlNs, 'xml:base', $base);
$doc->appendChild($rdfNode);
$descriptionNode = $doc->createElementNS($rdfNs, 'rdf:Description');
$descriptionNode->setAttributeNS($rdfNs, 'rdf:about', $languagePrefix . $code);
$rdfNode->appendChild($descriptionNode);
$typeNode = $doc->createElementNS($rdfNs, 'rdf:type');
$typeNode->setAttributeNS($rdfNs, 'rdf:resource', $languageType);
$descriptionNode->appendChild($typeNode);
$labelNode = $doc->createElementNS($rdfsNs, 'rdfs:label');
$labelNode->setAttributeNS($xmlNs, 'xml:lang', DEFAULT_LANG);
$labelNode->appendChild($doc->createCDATASection($label));
$descriptionNode->appendChild($labelNode);
$valueNode = $doc->createElementNS($rdfNs, 'rdf:value');
$valueNode->appendChild($doc->createCDATASection($code));
$descriptionNode->appendChild($valueNode);
$guiUsageNode = $doc->createElementNS($base, 'tao:languageUsages');
$guiUsageNode->setAttributeNs($rdfNs, 'rdf:resource', INSTANCE_LANGUAGE_USAGE_GUI);
$descriptionNode->appendChild($guiUsageNode);
$dataUsageNode = $doc->createElementNS($base, 'tao:languageUsages');
$dataUsageNode->setAttributeNs($rdfNs, 'rdf:resource', INSTANCE_LANGUAGE_USAGE_DATA);
$descriptionNode->appendChild($dataUsageNode);
$dataUsageNode = $doc->createElementNS($base, 'tao:LanguageOrientation');
$dataUsageNode->setAttributeNs($rdfNs, 'rdf:resource', INSTANCE_ORIENTATION_LTR);
$descriptionNode->appendChild($dataUsageNode);
$returnValue = $doc;
return $returnValue;
}
示例14: authorized
}
if (!$server->isAuthorized()) {
Logger::error('main', '(webservices/applications/webapps) Server is not authorized (error_code: 2)');
webservices_return_error(2, 'Server is not authorized');
}
header('Content-Type: text/xml; charset=utf-8');
$dom = new DomDocument('1.0', 'utf-8');
$node = $dom->createElement('webapps');
$applicationDB = ApplicationDB::getInstance();
$webapp_application_DB = WebAppConfDB::getInstance();
$applications = $applicationDB->getList('webapp');
if (is_array($applications)) {
foreach ($applications as $app) {
$app_node = $dom->createElement('webapp');
$app_node->setAttribute('id', $app->getAttribute('id'));
$app_node->setAttribute('name', $app->getAttribute('name'));
$app_node->setAttribute('description', $app->getAttribute('description'));
$app_node->setAttribute('revision', $app->getAttribute('revision'));
$webapp_configuration_object = $webapp_application_DB->search($app->getAttribute('id'));
if ($webapp_configuration_object != NULL) {
$configuration = $webapp_configuration_object->getUpdatedConfguration();
$config_node = $dom->createElement('configuration');
$config_node->appendChild($dom->createCDATASection($configuration));
$app_node->appendChild($config_node);
}
$node->appendChild($app_node);
}
}
$dom->appendChild($node);
echo $dom->saveXML();
exit(0);
示例15: appendNodeIfValue
/**
* appendNodeIfValue is a helper function for buildTransactionNodes, which
* is used by buildRequestXML to construct an XML transaction.
* This function will append an XML node to the transaction being built via
* the passed-in parent node, only if the current node would have a
* non-empty value.
* @param string $value The GATEWAY's field name for the current node.
* @param DOMElement $node The parent node this node will be contained in, if it
* is determined to have a non-empty value.
* @param bool $js Probably cruft at this point. This is connected to the
* function buildTransactionFormat.
*/
protected function appendNodeIfValue($value, &$node, $js = false)
{
$nodevalue = $this->getTransactionSpecificValue($value, $js);
if ($nodevalue !== '' && $nodevalue !== false) {
$temp = $this->xmlDoc->createElement($value);
$data = null;
if (in_array($value, $this->cdata)) {
$data = $this->xmlDoc->createCDATASection($nodevalue);
} else {
$data = $this->xmlDoc->createTextNode($nodevalue);
}
$temp->appendChild($data);
$node->appendChild($temp);
}
}