cvs: pear /XML_Feed_Parser/Parser Atom.php AtomElement.php
| From: | James Stewart | Date: | Sun, 16 Oct 2005 14:23:02 +0000 |
| Subject: | cvs: pear /XML_Feed_Parser/Parser Atom.php AtomElement.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-35594@lists.php.net to get a copy of this message | ||
jystewart Sun Oct 16 10:23:02 2005 EDT
Modified files:
/pear/XML_Feed_Parser/Parser Atom.php AtomElement.php
Log:
Added support for accessing attributes of text/content constructs in atom
Added support for getting atom text constructs by offset
http://cvs.php.net/diff.php/pear/XML_Feed_Parser/Parser/Atom.php?r1=1.3&r2=1.4&ty=u
Index: pear/XML_Feed_Parser/Parser/Atom.php
diff -u pear/XML_Feed_Parser/Parser/Atom.php:1.3 pear/XML_Feed_Parser/Parser/Atom.php:1.4
--- pear/XML_Feed_Parser/Parser/Atom.php:1.3 Sat Oct 15 11:06:22 2005
+++ pear/XML_Feed_Parser/Parser/Atom.php Sun Oct 16 10:22:58 2005
@@ -17,7 +17,7 @@
* @author James Stewart <james@jystewart.net>
* @copyright 2005 James Stewart <james@jystewart.net>
* @license http://www.gnu.org/copyleft/lesser.html GNU LGPL
2.1
- * @version CVS: $Id: Atom.php,v 1.3 2005/10/15 15:06:22 jystewart Exp $
+ * @version CVS: $Id: Atom.php,v 1.4 2005/10/16 14:22:58 jystewart Exp $
* @link http://dev.jystewart.net/XML_Feed_Parser/
*/
@@ -179,8 +179,6 @@
* Get a text construct. This is probably our most complex basic type as
* we will want the option to return attributes.
*
- * @todo Build in attribute support
- * @todo Handle elements that recur
* @todo Clarify overlap with getContent()
* @param string $method The name of the text construct we want
* @param array $arguments An array which we hope gives a 'param'
@@ -188,17 +186,28 @@
*/
protected function getText($method, $arguments)
{
+ $offset = empty($arguments[0]) ? 0: $arguments[0];
+ $attribute = empty($arguments[1]) ? false : $arguments[1];
$tags = $this->model->getElementsByTagName($method);
- if ($tags->length == 0) {
+
+ if ($tags->length == 0 or $tags->length < $offset) {
return false;
}
- $content = $tags->item(0);
+ $content = $tags->item($offset);
+
+ if (! $content->hasAttribute("type")) {
+ $content->setAttribute("type", "text");
+ }
+ $type = $content->getAttribute("type");
- if ($content->hasAttribute("type")) {
- $type = $content->getAttribute("type");
- } else {
- $type = "text";
+ if (! empty($attribute))
+ {
+ if ($content->hasAttribute($attribute))
+ {
+ return $content->getAttribute($attribute)->value;
+ }
+ return false;
}
switch ($type) {
http://cvs.php.net/diff.php/pear/XML_Feed_Parser/Parser/AtomElement.php?r1=1.3&r2=1.4&ty=u
Index: pear/XML_Feed_Parser/Parser/AtomElement.php
diff -u pear/XML_Feed_Parser/Parser/AtomElement.php:1.3
pear/XML_Feed_Parser/Parser/AtomElement.php:1.4
--- pear/XML_Feed_Parser/Parser/AtomElement.php:1.3 Sat Oct 15 11:06:22 2005
+++ pear/XML_Feed_Parser/Parser/AtomElement.php Sun Oct 16 10:22:58 2005
@@ -17,7 +17,7 @@
* @author James Stewart <james@jystewart.net>
* @copyright 2005 James Stewart <james@jystewart.net>
* @license http://www.gnu.org/copyleft/lesser.html GNU LGPL
2.1
- * @version CVS: $Id: AtomElement.php,v 1.3 2005/10/15 15:06:22 jystewart Exp $
+ * @version CVS: $Id: AtomElement.php,v 1.4 2005/10/16 14:22:58 jystewart Exp $
* @link http://dev.jystewart.net/XML_Feed_Parser/
*/
@@ -133,25 +133,35 @@
* we return the value of that instead.
*
* @todo Work out overlap with general text construct
- * @todo Get clarity on what to do with other mime-typed content
* @return string|false
*/
- function getContent()
- {
+ function getContent($method, $arguments = array())
+ {
+
+ $attribute = empty($arguments[0]) ? false : $arguments[0];
$tags = $this->model->getElementsByTagName('content');
+
if ($tags->length == 0) {
return false;
}
$content = $tags->item(0);
- if ($content->getAttribute('src')) {
- return $this->addBase($content->getAttribute('src'), $content);
+ if (! $content->hasAttribute("type")) {
+ $content->setAttribute("type", "text");
+ }
+ $type = $content->getAttribute("type");
+
+ if (! empty($attribute)) {
+ if ($content->hasAttribute($attribute))
+ {
+ return $content->getAttribute($attribute);
+ }
+ return false;
}
- if ($content->hasAttribute("type")) {
- $type = $content->getAttribute("type");
- } else {
- $type = "text";
+
+ if ($content->hasAttribute("src")) {
+ return $content->getAttribute("src");
}
switch ($type) {