Skip to content

Commit c2ad4fb

Browse files
author
Kousuke Ebihara
committed
a value of the string type node is now valid string (it can be escaped string or cdata)
1 parent 77d444c commit c2ad4fb

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

lib/api/opAPIMember.class.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,13 @@ public function createEntryByInstance(Doctrine_Record $member, SimpleXMLElement
116116
if ($profile->getProfile()->isPreset())
117117
{
118118
$i18n = sfContext::getInstance()->getI18N();
119-
$child = $profiles->addChild('div', $i18n->__((string)$profile));
119+
$child = $profiles->addChild('div');
120+
$entry->addValidStringToNode($child, $i18n->__((string)$profile));
120121
}
121122
else
122123
{
123-
$child = $profiles->addChild('div', $profile);
124+
$child = $profiles->addChild('div');
125+
$entry->addValidStringToNode($child, $profile);
124126
}
125127
$child->addAttribute('id', $profile->getName());
126128
}

lib/api/opGDataDocument.class.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,6 @@ public function publish()
4444
$elements = $this->getElements();
4545
$result = $elements->asXML();
4646

47-
if (Doctrine::getTable('SnsConfig')->get('op_web_api_plugin_using_cdata', false))
48-
{
49-
$result = preg_replace('/<content type="(.+?)">(.+?)<\/content>/ims', '<content type="$1"><![CDATA[$2]]></content>', $result, -1, $count);
50-
$result = preg_replace('/<title type="(.+?)">(.+?)<\/title>/ims', '<title type="$1"><![CDATA[$2]]></title>', $result, -1, $count);
51-
}
52-
5347
return $result;
5448
}
5549

@@ -59,4 +53,21 @@ public function getElements()
5953
{
6054
return $this->elements;
6155
}
56+
57+
public function addValidStringToNode($node, $string)
58+
{
59+
$domNode = dom_import_simplexml($node);
60+
$doc = $domNode->ownerDocument;
61+
62+
if (Doctrine::getTable('SnsConfig')->get('op_web_api_plugin_using_cdata', false))
63+
{
64+
$child = $doc->createCDataSection($string);
65+
}
66+
else
67+
{
68+
$child = $doc->createTextNode($string);
69+
}
70+
71+
$domNode->appendChild($child);
72+
}
6273
}

lib/api/opGDataDocumentEntry.class.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ protected function getRootXMLString()
4444

4545
public function setTitle($title, $type = 'text')
4646
{
47-
$element = $this->getElements()->addChild('title', $title);
47+
$element = $this->getElements()->addChild('title');
48+
49+
$this->addValidStringToNode($element, $title);
50+
4851
$element->addAttribute('type', $type);
4952
}
5053

@@ -105,7 +108,10 @@ public function setUpdated($updated)
105108

106109
public function setContent($content, $type = 'text')
107110
{
108-
$element = $this->getElements()->addChild('content', $content);
111+
$element = $this->getElements()->addChild('content');
112+
113+
$this->addValidStringToNode($element, $content);
114+
109115
$element->addAttribute('type', $type);
110116
}
111117

0 commit comments

Comments
 (0)