* changed indents back to tabs (ung)
* fixed several bugs in the issue list git-svn-id: svn://netflint.net/xmpphp@45 ef36c318-a008-4979-b6e8-6b496270793b
This commit is contained in:
@@ -19,9 +19,9 @@
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category xmpphp
|
||||
* @package XMPPHP
|
||||
* @author Nathanael C. Fritz <JID: fritzy@netflint.net>
|
||||
* @author Stephan Wentz <JID: stephan@jabber.wentz.it>
|
||||
* @package XMPPHP
|
||||
* @author Nathanael C. Fritz <JID: fritzy@netflint.net>
|
||||
* @author Stephan Wentz <JID: stephan@jabber.wentz.it>
|
||||
* @copyright 2008 Nathanael C. Fritz
|
||||
*/
|
||||
|
||||
@@ -29,127 +29,127 @@
|
||||
* XMPPHP XML Object
|
||||
*
|
||||
* @category xmpphp
|
||||
* @package XMPPHP
|
||||
* @author Nathanael C. Fritz <JID: fritzy@netflint.net>
|
||||
* @author Stephan Wentz <JID: stephan@jabber.wentz.it>
|
||||
* @package XMPPHP
|
||||
* @author Nathanael C. Fritz <JID: fritzy@netflint.net>
|
||||
* @author Stephan Wentz <JID: stephan@jabber.wentz.it>
|
||||
* @copyright 2008 Nathanael C. Fritz
|
||||
* @version $Id$
|
||||
* @version $Id$
|
||||
*/
|
||||
class XMPPHP_XMLObj {
|
||||
/**
|
||||
* Tag name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* Namespace
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $ns;
|
||||
|
||||
/**
|
||||
* Attributes
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $attrs = array();
|
||||
|
||||
/**
|
||||
* Subs?
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $subs = array();
|
||||
|
||||
/**
|
||||
* Node data
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $data = '';
|
||||
/**
|
||||
* Tag name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* Namespace
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $ns;
|
||||
|
||||
/**
|
||||
* Attributes
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $attrs = array();
|
||||
|
||||
/**
|
||||
* Subs?
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $subs = array();
|
||||
|
||||
/**
|
||||
* Node data
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $data = '';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $ns
|
||||
* @param array $attrs
|
||||
* @param string $data
|
||||
*/
|
||||
public function __construct($name, $ns = '', $attrs = array(), $data = '') {
|
||||
$this->name = strtolower($name);
|
||||
$this->ns = $ns;
|
||||
if(is_array($attrs) && count($attrs)) {
|
||||
foreach($attrs as $key => $value) {
|
||||
$this->attrs[strtolower($key)] = $value;
|
||||
}
|
||||
}
|
||||
$this->data = $data;
|
||||
}
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $ns
|
||||
* @param array $attrs
|
||||
* @param string $data
|
||||
*/
|
||||
public function __construct($name, $ns = '', $attrs = array(), $data = '') {
|
||||
$this->name = strtolower($name);
|
||||
$this->ns = $ns;
|
||||
if(is_array($attrs) && count($attrs)) {
|
||||
foreach($attrs as $key => $value) {
|
||||
$this->attrs[strtolower($key)] = $value;
|
||||
}
|
||||
}
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump this XML Object to output.
|
||||
*
|
||||
* @param integer $depth
|
||||
*/
|
||||
public function printObj($depth = 0) {
|
||||
print str_repeat("\t", $depth) . $this->name . " " . $this->ns . ' ' . $this->data;
|
||||
print "\n";
|
||||
foreach($this->subs as $sub) {
|
||||
$sub->printObj($depth + 1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Dump this XML Object to output.
|
||||
*
|
||||
* @param integer $depth
|
||||
*/
|
||||
public function printObj($depth = 0) {
|
||||
print str_repeat("\t", $depth) . $this->name . " " . $this->ns . ' ' . $this->data;
|
||||
print "\n";
|
||||
foreach($this->subs as $sub) {
|
||||
$sub->printObj($depth + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return this XML Object in xml notation
|
||||
*
|
||||
* @param string $str
|
||||
*/
|
||||
public function toString($str = '') {
|
||||
$str .= "<{$this->name} xmlns='{$this->ns}' ";
|
||||
foreach($this->attrs as $key => $value) {
|
||||
if($key != 'xmlns') {
|
||||
$value = htmlspecialchars($value);
|
||||
$str .= "$key='$value' ";
|
||||
}
|
||||
}
|
||||
$str .= ">";
|
||||
foreach($this->subs as $sub) {
|
||||
$str .= $sub->toString();
|
||||
}
|
||||
$body = htmlspecialchars($this->data);
|
||||
$str .= "$body</{$this->name}>";
|
||||
return $str;
|
||||
}
|
||||
/**
|
||||
* Return this XML Object in xml notation
|
||||
*
|
||||
* @param string $str
|
||||
*/
|
||||
public function toString($str = '') {
|
||||
$str .= "<{$this->name} xmlns='{$this->ns}' ";
|
||||
foreach($this->attrs as $key => $value) {
|
||||
if($key != 'xmlns') {
|
||||
$value = htmlspecialchars($value);
|
||||
$str .= "$key='$value' ";
|
||||
}
|
||||
}
|
||||
$str .= ">";
|
||||
foreach($this->subs as $sub) {
|
||||
$str .= $sub->toString();
|
||||
}
|
||||
$body = htmlspecialchars($this->data);
|
||||
$str .= "$body</{$this->name}>";
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Has this XML Object the given sub?
|
||||
*
|
||||
* @param string $name
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasSub($name) {
|
||||
foreach($this->subs as $sub) {
|
||||
if($sub->name == $name) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Has this XML Object the given sub?
|
||||
*
|
||||
* @param string $name
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasSub($name) {
|
||||
foreach($this->subs as $sub) {
|
||||
if($sub->name == $name) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a sub
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $attrs
|
||||
* @param string $ns
|
||||
*/
|
||||
public function sub($name, $attrs = null, $ns = null) {
|
||||
foreach($this->subs as $sub) {
|
||||
if($sub->name == $name) {
|
||||
return $sub;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Return a sub
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $attrs
|
||||
* @param string $ns
|
||||
*/
|
||||
public function sub($name, $attrs = null, $ns = null) {
|
||||
foreach($this->subs as $sub) {
|
||||
if($sub->name == $name) {
|
||||
return $sub;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user