Refbase update_2021-01-28_15_58

This commit is contained in:
root
2021-01-28 15:58:21 +01:00
commit 64e7261da6
300 changed files with 164739 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
<?php
/*
This file is part of ActiveLink PHP XML Package (www.active-link.com).
Copyright (c) 2002-2004 by Zurab Davitiani
You can contact the author of this software via E-mail at
hattrick@mailcan.com
ActiveLink PHP XML Package is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
ActiveLink PHP XML Package is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with ActiveLink PHP XML Package; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import("org.active-link.xml.Tree");
/**
* Branch class is part of a Tree-Branch-Leaf trio
* @class Branch
* @package org.active-link.xml
* @author Zurab Davitiani
* @version 0.4.0
* @extends Tree
* @requires Tree
* @see Tree, Leaf
*/
class Branch extends Tree {
}
?>

View File

@@ -0,0 +1,70 @@
<?php
/*
This file is part of ActiveLink PHP XML Package (www.active-link.com).
Copyright (c) 2002-2004 by Zurab Davitiani
You can contact the author of this software via E-mail at
hattrick@mailcan.com
ActiveLink PHP XML Package is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
ActiveLink PHP XML Package is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with ActiveLink PHP XML Package; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* Leaf class is part of a Tree-Branch-Leaf trio
* @class Leaf
* @package org.active-link.xml
* @author Zurab Davitiani
* @version 0.4.0
* @see Tree, Branch
*/
class Leaf {
// protected variables
var $value;
/**
* Constructor for the object
* @method Leaf
* @param optional mixed value
* @returns none
*/
function Leaf($value = "") {
$this->setValue($value);
}
/**
* Gets Leaf object value
* @method getValue
* @returns value of the object
*/
function getValue() {
return $this->value;
}
/**
* Sets Leaf object to the specified value
* @method setValue
* @param mixed value
* @returns none
*/
function setValue($value) {
$this->value = $value;
}
}
?>

View File

@@ -0,0 +1,108 @@
<?php
/*
This file is part of ActiveLink PHP XML Package (www.active-link.com).
Copyright (c) 2002-2004 by Zurab Davitiani
You can contact the author of this software via E-mail at
hattrick@mailcan.com
ActiveLink PHP XML Package is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
ActiveLink PHP XML Package is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with ActiveLink PHP XML Package; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import("org.active-link.xml.XML");
/**
* Simple RSS class based on XML
* @class RSS
* @package org.active-link.xml
* @author Zurab Davitiani
* @version 0.4.0
* @requires XML
* @see XML
*/
class RSS {
var $xml;
var $rootTags;
var $itemBranches;
/**
* Constructor, parses the supplied RSS string into the object
* @method RSS
* @param string parseString
* @returns none
*/
function RSS($parseString) {
$this->xml = new XML($parseString);
$this->rootTags = array("rss", "rdf:RDF");
$this->itemBranches = array();
$this->parseItemBranches();
}
/**
* Returns array of references to item branches of the RSS
* @method getItemBranches
* @returns array of references to objects of type XMLBranch (item branches of RSS)
*/
function getItemBranches() {
return $this->itemBranches;
}
/**
* Returns HTML-formatted RSS items
* @method getHTMLTitlesFormatted
* @returns string HTML-formatted RSS items
*/
function getHTMLTitlesFormatted() {
$itemBranchesXML = new XML("ul");
reset($this->itemBranches);
foreach($this->itemBranches as $newsItem) {
$itemXML = new XMLBranch("li");
$itemLinkXML = new XMLBranch("a");
$itemLinkXML->setTagContent($newsItem->getTagContent("item/title"));
$itemLinkXML->setTagAttribute("href", $newsItem->getTagContent("item/link"));
$itemXML->addXMLBranch($itemLinkXML);
$itemBranchesXML->addXMLBranch($itemXML);
}
return $itemBranchesXML->getXMLString();
}
/**
* Parses RSS item branches, called from constructor
* @method parseItemBranches
* @returns true if successful, false otherwise
*/
function parseItemBranches() {
$success = false;
$rootTagName = $this->xml->getTagName();
if(in_array($rootTagName, $this->rootTags)) {
$tempBranches = array();
if($rootTagName == "rss")
$tempBranches = $this->xml->getBranches($rootTagName . "/channel", "item");
elseif($rootTagName == "rdf:RDF")
$tempBranches = $this->xml->getBranches($rootTagName, "item");
if($tempBranches !== false) {
$this->itemBranches = $tempBranches;
$success = true;
}
}
return $success;
}
}
?>

View File

@@ -0,0 +1,429 @@
<?php
/* Workaround by Richard Karnesky (refbase) for if ctype_alpha is missing */
if(! function_exists('ctype_alpha')) {
function ctype_alpha($string) {
return (!preg_match('|[^\pL]|', $string));
}
}
/*
This file is part of ActiveLink PHP XML Package (www.active-link.com).
Copyright (c) 2002-2004 by Zurab Davitiani
You can contact the author of this software via E-mail at
hattrick@mailcan.com
ActiveLink PHP XML Package is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
ActiveLink PHP XML Package is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with ActiveLink PHP XML Package; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* Tag class provides a base for parsing, modifying, outputting and creating XML tags
* @class Tag
* @package org.active-link.xml
* @author Zurab Davitiani
* @version 0.4.0
* @see XML
*/
class Tag {
// protected variables
var $tagStartOpen;
var $tagStartClose;
var $tagClose;
var $tagEndOpen;
var $tagEndClose;
var $tagName;
var $tagContent;
var $tagAttributes;
var $tagAttributeSeparator;
var $tagAttributeSeparators;
var $tagAttributeAssignment;
var $tagAttributeValueQuote;
var $FORMAT_NONE;
var $FORMAT_INDENT;
var $tagFormat;
var $tagFormatIndentLevel;
var $tagFormatEndTag;
var $tagFormatNewLine = "\n";
var $tagFormatIndent = "\t";
/**
* Constructor creates a tag object with the specified name and tag content
* @method Tag
* @param optional string name
* @param optional string content
* @returns none
*/
function Tag($name = "", $content = "") {
$this->tagStartOpen = "<";
$this->tagStartClose = ">";
$this->tagClose = "/>";
$this->tagEndOpen = "</";
$this->tagEndClose = ">";
$this->setTagName($name);
$this->setTagContent($content);
$this->tagAttributes = array();
$this->tagAttributeSeparator = " ";
$this->tagAttributeSeparators = array(" ", "\n", "\r", "\t");
$this->tagAttributeAssignment = "=";
$this->tagAttributeValueQuote = '"';
$this->FORMAT_NONE = 0;
$this->FORMAT_INDENT = 1;
$this->tagFormat = $this->FORMAT_NONE;
$this->tagFormatIndentLevel = 0;
$this->tagFormatEndTag = false;
}
/**
* Find out whether attribute exists
* @method attributeExists
* @param string attrName
* @returns true if attribute exists, false otherwise
*/
function attributeExists($attrName) {
return array_key_exists($attrName, $this->tagAttributes);
}
/**
* Get attribute value by its name
* @method getTagAttribute
* @param string attrName
* @returns string attribute value
*/
function getTagAttribute($attrName) {
return $this->tagAttributes[$attrName];
}
/**
* Get tag content string
* @method getTagContent
* @returns string tag content
*/
function getTagContent() {
return $this->tagContent;
}
/**
* Get tag name string
* @method getTagName
* @returns string tag name
*/
function getTagName() {
return $this->tagName;
}
/**
* Get complete tag string with its attributes and content
* @method getTagString
* @returns string tag string
*/
function getTagString() {
$formatTagBegin = "";
$formatTagEnd = "";
$formatContent = "";
if($this->tagFormat == $this->FORMAT_INDENT) {
if($this->tagFormatIndentLevel > 0)
$formatTagBegin = $this->tagFormatNewLine . str_repeat($this->tagFormatIndent, $this->tagFormatIndentLevel);
if($this->tagFormatEndTag)
$formatTagEnd = $this->tagFormatNewLine . str_repeat($this->tagFormatIndent, $this->tagFormatIndentLevel);
}
$tagString = $formatTagBegin . $this->getTagStringBegin() . $formatContent . $this->tagContent . $formatTagEnd . $this->getTagStringEnd();
return $tagString;
}
/**
* Get beginning of the tag string, i.e. its name attributes up until tag contents
* @method getTagStringBegin
* @returns string beginning of the tag string
*/
function getTagStringBegin() {
$tagString = "";
if($this->tagName != "") {
$tagString .= $this->tagStartOpen . $this->tagName;
foreach($this->tagAttributes as $attrName => $attrValue) {
$tagString .= $this->tagAttributeSeparator . $attrName . $this->tagAttributeAssignment . $this->tagAttributeValueQuote . $attrValue . $this->tagAttributeValueQuote;
}
if($this->tagContent == "")
$tagString .= $this->tagAttributeSeparator . $this->tagClose;
else
$tagString .= $this->tagStartClose;
}
return $tagString;
}
/**
* Get ending of the tag string, i.e. its closing tag
* @method getTagStringEnd
* @returns string close tag if tag is not short-handed, empty string otherwise
*/
function getTagStringEnd() {
$tagString = "";
if($this->tagName != "" && $this->tagContent != "")
$tagString .= $this->tagEndOpen . $this->tagName . $this->tagEndClose;
return $tagString;
}
/**
* Remove all tag attributes
* @method removeAllAttributes
* @returns none
*/
function removeAllAttributes() {
$this->tagAttributes = array();
}
/**
* Remove a tag attribute by its name
* @method removeAttribute
* @returns none
*/
function removeAttribute($attrName) {
unset($this->tagAttributes[$attrName]);
}
/**
* Reset the tag object - set name, content to empty strings, and reset all attributes
* @method resetTag
* @returns none
*/
function resetTag() {
$this->setTagName("");
$this->setTagContent("");
$this->removeAllAttributes();
}
/**
* Create or modify an existing attribute by supplying attribute name and value
* @method setAttribute
* @param string attrName
* @param string attrValue
* @returns none
*/
function setAttribute($attrName, $attrValue) {
$this->tagAttributes[$attrName] = $attrValue;
}
/**
* Set contents of the tag
* @method setTagContent
* @param string content
* @returns none
*/
function setTagContent($content) {
$this->tagContent = $content;
}
/**
* Set tag formatting option by specifying tagFormat to 0 (none), or 1 (indented)
* @method setTagFormat
* @param int tagFormat
* @param optional int tagFormatIndentLevel
* @returns none
*/
function setTagFormat($tagFormat, $tagFormatIndentLevel = 0) {
$this->tagFormat = $tagFormat;
$this->tagFormatIndentLevel = $tagFormatIndentLevel;
}
/**
* Set whether closing of the tag should be formatted or not
* @method setTagFormatEndTag
* @param optional boolean formatEndTag
* @returns none
*/
function setTagFormatEndTag($formatEndTag = true) {
$this->tagFormatEndTag = $formatEndTag;
}
/**
* Parse a string containing a tag into the tag object, this will parse the first tag found
* @method setTagFromString
* @param string tagString
* @returns array array of [0]=>index of the beginning of the tag, [1]=>index where tag ended
*/
function setTagFromString($tagString) {
$i = 0;
$j = 0;
$tagStartOpen = $tagStartClose = $tagNameStart = $tagNameEnd = $tagContentStart = $tagContentEnd = $tagEndOpen = $tagEndClose = 0;
$tagName = $tagContent = "";
$tagShort = false;
$tagAttributes = array();
$success = true;
$tagFound = false;
while(!$tagFound && $i < strlen($tagString)) {
// look for start tag character
$i = strpos($tagString, $this->tagStartOpen, $i);
if($i === false)
break;
// if tag name starts from alpha character we found the tag
if(ctype_alpha(substr($tagString, $i + 1, 1)))
$tagFound = true;
// else continue searching
else
$i ++;
}
// if no tag found set success to false
if(!$tagFound)
$success = false;
// if so far so good continue with found tag name
if($success) {
$tagStartOpen = $i;
$tagNameStart = $i + 1;
// search where tag name would end
// search for a space separator to account for attributes
$separatorPos = array();
for($counter = 0; $counter < count($this->tagAttributeSeparators); $counter ++) {
$separatorPosTemp = strpos($tagString, $this->tagAttributeSeparators[$counter], $tagStartOpen);
if($separatorPosTemp !== false)
$separatorPos[] = $separatorPosTemp;
}
//$i = strpos($tagString, $this->tagAttributeSeparator, $tagStartOpen);
if(count($separatorPos) > 0)
$i = min($separatorPos);
else
$i = false;
// search for tag close character
$j = strpos($tagString, $this->tagStartClose, $tagStartOpen);
// search for short tag (no content)
$k = strpos($tagString, $this->tagClose, $tagStartOpen);
// if tag close character is not found then no tag exists, set success to false
if($j === false)
$success = false;
// if tag short close found before tag close, then tag is short
if($k !== false && $k < $j)
$tagShort = true;
}
// if so far so good set tag name correctly
if($success) {
// if space separator not found or it is found after the tag close char
if($i === false || $i > $j) {
if($tagShort)
$tagNameEnd = $k;
else
$tagNameEnd = $j;
$tagStartClose = $j;
}
// else if tag attributes exist
else {
$tagNameEnd = $i;
$tagStartClose = $j;
// parse attributes
$tagAttributesStart = $i + strlen($this->tagAttributeSeparator);
$attrString = trim(substr($tagString, $tagAttributesStart, $j - $tagAttributesStart));
$attrArray = explode($this->tagAttributeValueQuote, $attrString);
$attrCounter = 0;
while($attrCounter < count($attrArray) - 1) {
$attributeName = trim(str_replace($this->tagAttributeAssignment, "", $attrArray[$attrCounter]));
$attributeValue = $attrArray[$attrCounter + 1];
$tagAttributes[$attributeName] = $attributeValue;
$attrCounter += 2;
}
}
$tagName = rtrim(substr($tagString, $tagNameStart, $tagNameEnd - $tagNameStart));
if(!$tagShort) {
$tagContentStart = $tagStartClose + 1;
// look for ending of the tag after tag content
$j = $tagContentStart;
$tagCloseFound = false;
// while loop will find the k-th tag close
// start with one since we have one tag open
$k = 1;
while(!$tagCloseFound && $success) {
// find k-th tag close from j
$n = $j - 1;
for($skip = 0; $skip < $k; $skip ++) {
$n ++;
$tempPos = strpos($tagString, $this->tagEndOpen . $tagName . $this->tagEndClose, $n);
if($tempPos !== false)
$n = $tempPos;
else {
$success = false;
break;
}
}
// if success, find number of tag opens before the tag close
$k = 0;
if($success) {
$tempString = substr($tagString, $j, $n - $j);
$tempNewPos = 0;
do {
$tempPos = strpos($tempString, $this->tagStartOpen . $tagName, $tempNewPos);
if($tempPos !== false) {
$tempPosChar = substr($tempString, $tempPos + strlen($this->tagStartOpen . $tagName), 1);
$tagEndArray = $this->tagAttributeSeparators;
$tagEndArray[] = $this->tagEndClose;
$tempPosTagEnded = array_search($tempPosChar, $tagEndArray);
if($tempPosTagEnded !== false && $tempPosTagEnded !== NULL) {
$tempStartClose = strpos($tempString, $this->tagStartClose, $tempPos);
$tempStartShortClose = strpos($tempString, $this->tagClose, $tempPos);
// if open tag found increase counter
if($tempStartClose !== false && ($tempStartShortClose === false || $tempStartClose < $tempStartShortClose))
$k ++;
$tempNewPos = $tempPos + strlen($this->tagStartOpen . $tagName);
}
else
$tempNewPos = $tempPos + strlen($this->tagStartOpen . $tagName);
}
} while($tempPos !== false);
}
// if no tags opened we found the tag close
if($k == 0)
$tagCloseFound = true;
// else set new j
else {
$j = $n + strlen($this->tagEndOpen . $tagName . $this->tagEndClose);
}
}
if($tagCloseFound)
$i = $n;
else
$success = false;
}
}
// if so far so good, then we have everything we need! set the object
if($success) {
if(!$tagShort) {
$tagContentEnd = $i;
$tagContent = trim(substr($tagString, $tagContentStart, $tagContentEnd - $tagContentStart));
$tagEndOpen = $i;
$tagEndClose = $tagEndOpen + strlen($this->tagEndOpen . $tagName . $this->tagEndClose);
}
else
$tagEndClose = $tagStartClose + strlen($this->tagStartClose);
$this->setTagName($tagName);
$this->setTagContent($tagContent);
$this->tagAttributes = $tagAttributes;
}
if($success)
return array($tagStartOpen, $tagEndClose);
else
return false;
}
/**
* Set tag name
* @method setTagName
* @param string name
* @returns none
*/
function setTagName($name) {
$this->tagName = $name;
}
}
?>

View File

@@ -0,0 +1,94 @@
<?php
/*
This file is part of ActiveLink PHP XML Package (www.active-link.com).
Copyright (c) 2002-2004 by Zurab Davitiani
You can contact the author of this software via E-mail at
hattrick@mailcan.com
ActiveLink PHP XML Package is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
ActiveLink PHP XML Package is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with ActiveLink PHP XML Package; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* Tree class provides a base for Tree-Branch-Leaf trio
* @class Tree
* @package org.active-link.xml
* @author Zurab Davitiani
* @version 0.4.0
* @see Branch, Leaf
*/
class Tree {
// protected variables
var $nodes;
var $id = 0;
/**
* Constructor for the object
* @method Tree
* @returns none
*/
function Tree() {
$this->nodes = array();
}
/**
* Adds given node to the Tree
* @method addNode
* @param mixed id
* @param mixed node
* @returns true if successful, false otherwise
*/
function addNode($id, $node) {
$success = true;
if($id == -1)
$this->nodes[] = $node;
else
if(isset($this->nodes[$id]))
$success = false;
else
$this->nodes[$id] = $node;
return $success;
}
/**
* Removes all nodes
* @method removeAllNodes
* @returns none
*/
function removeAllNodes () {
$this->nodes = array();
}
/**
* Removes specified node from the Tree
* @method removeNode
* @param mixed id
* @returns true if successful, false otherwise
*/
function removeNode($id) {
$success = false;
if(isset($this->nodes[$id])) {
unset($this->nodes[$id]);
$success = true;
}
return $success;
}
}
?>

View File

@@ -0,0 +1,580 @@
<?php
/*
This file is part of ActiveLink PHP XML Package (www.active-link.com).
Copyright (c) 2002-2004 by Zurab Davitiani
You can contact the author of this software via E-mail at
hattrick@mailcan.com
ActiveLink PHP XML Package is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
ActiveLink PHP XML Package is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with ActiveLink PHP XML Package; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import("org.active-link.xml.Tag");
import("org.active-link.xml.Tree");
/**
* XML class provides a tree-like structure to read/write/modify XML
* @class XML
* @package org.active-link.xml
* @author Zurab Davitiani
* @version 0.4.0
* @extends Tree
* @requires Tag, Tree, XMLBranch, XMLLeaf
* @see Tree
*/
class XML extends Tree {
// protected variables
var $tag;
var $pathSeparator;
/**
* If argument is an XML String it parses the string into XML object
* If argument is a tag path, creates appropriate branches and tags
* If argument is a simple string then sets that as a root tag name
* @method XML
* @param optional string argument
* @returns none
*/
function XML($argument = "") {
$success = false;
$this->Tree();
$this->pathSeparator = "/";
$this->tag = new Tag();
if(is_string($argument)) {
// if this is an XML string to be parsed
if(strpos($argument, $this->tag->tagEndOpen) > 0 || strpos($argument, $this->tag->tagClose) > 0)
$this->parseFromString($argument);
// else if this is a tag path to be created
elseif(strpos($argument, $this->pathSeparator) > 0) {
$tags = explode($this->pathSeparator, $argument);
$this->tag->setTagName($tags[0]);
$this->setTagContent("", $argument);
}
else
$this->tag->setTagName($argument);
$success = true;
}
else
$success = false;
return $success;
}
/**
* Adds another XML tree as a branch to the current XML object
* @method addXMLAsBranch
* @param object xml
* @param optional mixed id
* @returns true if successful, false otherwise
*/
function addXMLAsBranch($xml, $id = -1) {
$success = false;
if(is_object($xml) && strtolower(get_class($xml)) == "xml") {
$newBranch = new XMLBranch();
$newBranch->nodes = $xml->nodes;
$newBranch->tag = $xml->tag;
$success = $this->addXMLBranch($newBranch, $id);
}
return $success;
}
/**
* Adds XML Branch to the current XML object
* @method addXMLBranch
* @param object xmlBranch
* @param optional mixed id
* @returns true if successful, false otherwise
*/
function addXMLBranch($xmlBranch, $id = -1) {
$success = false;
if(is_object($xmlBranch) && strtolower(get_class($xmlBranch)) == "xmlbranch") {
$xmlBranch->setParentXML($this);
$success = $this->addNode($id, $xmlBranch);
}
return $success;
}
/**
* Adds XML Leaf to the current XML object
* @method addXMLLeaf
* @param object xmlLeaf
* @param optional mixed id
* @returns true if successful, false otherwise
*/
function addXMLLeaf($xmlLeaf, $id = -1) {
$success = false;
if(is_object($xmlLeaf) && strtolower(get_class($xmlLeaf)) == "xmlleaf") {
$xmlLeaf->setParentXML($this);
$success = $this->addNode($id, $xmlLeaf);
}
return $success;
}
/**
* Retrieves an array of references to XMLBranches within the specified path, tag name, attribute name, and attribute value
* @method getBranches
* @param optional string tagPath
* @param optional string tagName
* @param optional string attrName
* @param optional string attrValue
* @returns array of references to XMLBranch objects that meet specified criteria, or false if none found
*/
function getBranches($tagPath = "", $tagName = "", $attrName = "", $attrValue = "") {
$branchArray = array();
if($tagPath == "")
$tagPath = $this->tag->getTagName();
$tags = explode($this->pathSeparator, $tagPath);
if($this->tag->getTagName() == $tags[0]) {
if(count($tags) == 1) {
$arrKeys = array_keys($this->nodes);
for($index = 0; $index < count($arrKeys); $index ++) {
if(gettype($this->nodes[$arrKeys[$index]]) == "object" && strtolower(get_class($this->nodes[$arrKeys[$index]])) == "xmlbranch") {
if(($tagName == "" || $this->nodes[$arrKeys[$index]]->tag->getTagName() == $tagName) &&
($attrName == "" || $this->nodes[$arrKeys[$index]]->tag->attributeExists($attrName)) &&
($attrValue == "" || $this->nodes[$arrKeys[$index]]->tag->getTagAttribute($attrName) == $attrValue)) {
$branchArray[] = &$this->nodes[$arrKeys[$index]];
}
}
}
}
else {
$arrKeys = array_keys($this->nodes);
for($index = 0; $index < count($arrKeys); $index ++) {
if(gettype($this->nodes[$arrKeys[$index]]) == "object" && strtolower(get_class($this->nodes[$arrKeys[$index]])) == "xmlbranch") {
if($this->nodes[$arrKeys[$index]]->tag->getTagName() == $tags[1]) {
$newTagPath = implode($this->pathSeparator, array_slice($tags, 1));
$newArray = $this->nodes[$arrKeys[$index]]->getBranches($newTagPath, $tagName, $attrName, $attrValue);
if($newArray !== false)
$branchArray = array_merge($branchArray, $newArray);
}
}
}
}
}
if(count($branchArray) == 0)
$branchArray = false;
return $branchArray;
}
/**
* Retrieves an array of references to XMLLeaf(s) within the specified path
* @method getLeafs
* @param optional string tagPath
* @returns array of references to XMLLeaf objects in specified tag path, false if none found
*/
function getLeafs($tagPath = "") {
$leafArray = array();
if($tagPath == "")
$tagPath = $this->tag->getTagName();
$tags = explode($this->pathSeparator, $tagPath);
if($this->tag->getTagName() == $tags[0]) {
if(count($tags) == 1) {
$arrKeys = array_keys($this->nodes);
for($index = 0; $index < count($arrKeys); $index ++) {
if(gettype($this->nodes[$arrKeys[$index]]) == "object" && strtolower(get_class($this->nodes[$arrKeys[$index]])) == "xmlleaf") {
$leafArray[] = &$this->nodes[$arrKeys[$index]];
}
}
}
else {
$arrKeys = array_keys($this->nodes);
for($index = 0; $index < count($arrKeys); $index ++) {
if(gettype($this->nodes[$arrKeys[$index]]) == "object" && strtolower(get_class($this->nodes[$arrKeys[$index]])) == "xmlbranch") {
if($this->nodes[$arrKeys[$index]]->tag->getTagName() == $tags[1]) {
$newTagPath = implode($this->pathSeparator, array_slice($tags, 1));
$newArray = $this->nodes[$arrKeys[$index]]->getLeafs($newTagPath);
if($newArray !== false)
$leafArray = array_merge($leafArray, $newArray);
}
}
}
}
}
if(count($leafArray) == 0)
$leafArray = false;
return $leafArray;
}
/**
* Returns attribute value of the specified tag and tagpath
* @method getTagAttribute
* @param string attributeName
* @param optional string tagPath
* @returns attribute of the specified tag if successful, false otherwise
*/
function getTagAttribute($attributeName, $tagPath = "") {
if($tagPath == "")
$tagPath = $this->tag->getTagName();
$tags = explode($this->pathSeparator, $tagPath);
$attributeValue = false;
if($this->tag->getTagName() == $tags[0]) {
if(sizeof($tags) == 1) {
if($this->tag->attributeExists($attributeName))
$attributeValue = $this->tag->getTagAttribute($attributeName);
}
else {
foreach($this->nodes as $node) {
if(strtolower(get_class($node)) == "xmlbranch")
if($node->tag->getTagName() == $tags[1]) {
$newTagPath = implode($this->pathSeparator, array_slice($tags, 1));
$attributeValue = $node->getTagAttribute($attributeName, $newTagPath);
}
}
}
}
return $attributeValue;
}
/**
* Returns contents of the specified tag path
* @method getTagContent
* @param optional string tagPath
* @returns content of the tag from the specified path if successful, false otherwise
*/
function getTagContent($tagPath = "") {
if($tagPath == "")
$tagPath = $this->tag->getTagName();
$tags = explode($this->pathSeparator, $tagPath);
$tagValue = false;
if($this->tag->getTagName() == $tags[0]) {
if(sizeof($tags) == 1)
$tagValue = $this->getXMLContent();
else {
foreach($this->nodes as $node) {
if(strtolower(get_class($node)) == "xmlbranch")
if($node->tag->getTagName() == $tags[1]) {
$newTagPath = implode($this->pathSeparator, array_slice($tags, 1));
$tagValue = $node->getTagContent($newTagPath);
}
}
}
}
return $tagValue;
}
/**
* Retrieves the tag name of the current object
* @method getTagName
* @returns tag name
*/
function getTagName() {
return($this->tag->getTagName());
}
/**
* Gets contents from the current object
* @method getXMLContent
* @returns contents of the current XML tag
*/
function getXMLContent() {
$xmlContent = "";
foreach($this->nodes as $node) {
if(gettype($node) == "object") {
if(strtolower(get_class($node)) == "xmlbranch")
$xmlContent .= $node->getXMLString();
elseif(strtolower(get_class($node)) == "xmlleaf")
$xmlContent .= $node->getValue();
}
}
return $xmlContent;
}
/**
* Gets the whole XML string of the current object
* @method getXMLString
* @param optional mixed indent
* @returns complete XML string of current object
*/
function getXMLString($indent = false) {
$xmlString = "";
$containsBranches = false;
$containsLeafs = false;
$newIndent = false;
if($indent === false)
$newIndent = false;
else {
$newIndent = $indent + 1;
$this->tag->setTagFormat($this->tag->FORMAT_INDENT, $indent);
}
foreach($this->nodes as $node) {
if(gettype($node) == "object") {
if(strtolower(get_class($node)) == "xmlbranch") {
$this->tag->tagContent .= $node->getXMLString($newIndent);
$containsBranches = true;
}
elseif(strtolower(get_class($node)) == "xmlleaf") {
$this->tag->tagContent .= $node->getValue();
$containsLeafs = true;
}
}
}
if($containsBranches)
$this->tag->setTagFormatEndTag(true);
$xmlString = $this->tag->getTagString();
$this->tag->setTagContent("");
return $xmlString;
}
/**
* Find out whether the current object has any branches
* @method hasBranch
* @returns true if branches exist, false otherwise
*/
function hasBranch() {
$hasBranch = false;
foreach($this->nodes as $node) {
if(strtolower(get_class($node)) == "xmlbranch") {
$hasBranch = true;
break;
}
}
return $hasBranch;
}
/**
* Find out whether the current object has any leaf(s)
* @method hasLeaf
* @returns true if leaf(s) exist, false otherwise
*/
function hasLeaf() {
$hasLeaf = false;
foreach($this->nodes as $node) {
if(strtolower(get_class($node)) == "xmlleaf") {
$hasLeaf = true;
break;
}
}
return $hasLeaf;
}
/**
* Parse entire XML string into the current object; also called from constructor
* @method parseFromString
* @param string parseString
* @returns none
*/
function parseFromString($parseString) {
$tagResult = $this->tag->setTagFromString($parseString);
if($tagResult !== false) {
$this->parseNodesFromTag();
$this->tag->setTagContent("");
}
}
/**
* Parses the current tag content into Branches and Leaf(s); called from parseFromString
* @method parseNodesFromTag
* @returns none
*/
function parseNodesFromTag() {
$tempTag = new Tag();
$parseString = $this->tag->getTagContent();
while($tagParsed = $tempTag->setTagFromString($parseString)) {
if($tagParsed[0] != 0 && trim(substr($parseString, 0, $tagParsed[0]) != ""))
$this->addXMLLeaf(new XMLLeaf(trim(substr($parseString, 0, $tagParsed[0]))));
$branch = new XMLBranch();
$tempTagCopy = new Tag();
$tempTagCopy->setTagName($tempTag->getTagName());
$tempTagCopy->tagAttributes = $tempTag->tagAttributes;
$tempTagCopy->setTagContent($tempTag->getTagContent());
$branch->setTag($tempTagCopy);
$branch->parseNodesFromTag();
$branch->tag->setTagContent("");
$this->addXMLBranch($branch);
$parseString = trim(substr($parseString, $tagParsed[1]));
}
if(strlen($parseString) > 0 && trim($parseString) != "")
$this->addXMLLeaf(new XMLLeaf($parseString));
}
/**
* Removes all Branches from current object
* @method removeAllBranches
*/
function removeAllBranches() {
foreach($this->nodes as $key => $value) {
if(strtolower(get_class($value)) == "xmlbranch")
unset($this->nodes[$key]);
}
}
/**
* Removes all Leaf(s) from current object
* @method removeAllLeafs
*/
function removeAllLeafs() {
foreach($this->nodes as $key => $value) {
if(strtolower(get_class($value)) == "xmlleaf")
unset($this->nodes[$key]);
}
}
/**
* Removes Branches with the specified criteria
* @method removeBranches
* @param optional string tagPath
* @param optional string tagName
* @param optional string attrName
* @param optional string attrValue
* @returns number of branches deleted
*/
function removeBranches($tagPath = "", $tagName = "", $attrName = "", $attrValue = "") {
$branchesDeleted = 0;
$referencedBranches = array();
$tags = explode($this->pathSeparator, $tagPath);
if(count($tags) > 1) {
$parentTagName = array_pop($tags);
$parentTagPath = implode($this->pathSeparator, $tags);
$referencedBranches = $this->getBranches($parentTagPath, $parentTagName);
}
else {
$referencedBranches[] = &$this;
}
for($i = 0; $i < count($referencedBranches); $i ++) {
$arrKeys = array_keys($referencedBranches[$i]->nodes);
for($index = 0; $index < count($arrKeys); $index ++) {
if(gettype($referencedBranches[$i]->nodes[$arrKeys[$index]]) == "object" && strtolower(get_class($referencedBranches[$i]->nodes[$arrKeys[$index]])) == "xmlbranch") {
if(($tagName == "" || $referencedBranches[$i]->nodes[$arrKeys[$index]]->tag->getTagName() == $tagName) &&
($attrName == "" || $referencedBranches[$i]->nodes[$arrKeys[$index]]->tag->attributeExists($attrName)) &&
($attrValue == "" || $referencedBranches[$i]->nodes[$arrKeys[$index]]->tag->getTagAttribute($attrName) == $attrValue)) {
$referencedBranches[$i]->removeNode($arrKeys[$index]);
$branchesDeleted ++;
}
}
}
}
return $branchesDeleted;
}
/**
* Sets tag object of a branch specified by branch ID for the current object; see getBranches and setTag
* @method setBranchTag
* @param mixed branchId
* @param object tag
* @returns true on success, false otherwise
*/
function setBranchTag($branchId, $tag) {
$success = true;
if(strtolower(get_class($this->nodes[$branchId])) == "xmlbranch" && strtolower(get_class($tag)) == "tag")
$this->nodes[$branchId]->setTag($tag);
else
$success = false;
return $success;
}
/**
* Sets tag object of the current object
* @method setTag
* @param object tag
* @returns true if successful, false otherwise
*/
function setTag($tag) {
$success = true;
if(strtolower(get_class($tag)) == "tag")
$this->tag = $tag;
else
$success = false;
return $success;
}
/**
* Sets an attribute name and value on an existing tag found via tagpath string
* @method setTagAttribute
* @param string attributeName
* @param optional string attributeValue
* @param optional string tagPath
* @returns true if successful, false otherwise
*/
function setTagAttribute($attributeName, $attributeValue = "", $tagPath = "") {
if($tagPath == "")
$tagPath = $this->tag->getTagName();
$success = true;
$tags = explode($this->pathSeparator, $tagPath);
if($this->tag->getTagName() == $tags[0]) {
if(sizeof($tags) == 1)
$this->tag->setAttribute($attributeName, $attributeValue);
else {
$nodeTagFound = false;
reset($this->nodes);
$arrKeys = array_keys($this->nodes);
for($index = 0; $index < count($arrKeys); $index ++) {
$node =& $this->nodes[$arrKeys[$index]];
if(strtolower(get_class($node)) == "xmlbranch")
if($node->tag->getTagName() == $tags[1]) {
$newTagPath = implode($this->pathSeparator, array_slice($tags, 1));
$success = $node->setTagAttribute($attributeName, $attributeValue, $newTagPath);
$nodeTagFound = true;
}
}
if(!$nodeTagFound)
$success = false;
}
}
else
$success = false;
return $success;
}
/**
* Sets content of the specified tag
* @method setTagContent
* @param mixed content
* @param optional string tagPath
* @returns true if successful, false otherwise
*/
function setTagContent($content, $tagPath = "") {
if($tagPath == "")
$tagPath = $this->tag->getTagName();
$success = true;
$tags = explode($this->pathSeparator, $tagPath);
if($this->tag->getTagName() == $tags[0]) {
if(sizeof($tags) == 1) {
//$this->nodes = array(new XMLLeaf($content));
$this->removeAllNodes();
$this->addXMLLeaf(new XMLLeaf($content));
}
else {
$nodeTagFound = false;
reset($this->nodes);
$arrKeys = array_keys($this->nodes);
for($index = 0; $index < count($arrKeys); $index ++) {
$node =& $this->nodes[$arrKeys[$index]];
if(strtolower(get_class($node)) == "xmlbranch")
if($node->tag->getTagName() == $tags[1]) {
$newTagPath = implode($this->pathSeparator, array_slice($tags, 1));
$success = $node->setTagContent($content, $newTagPath);
$nodeTagFound = true;
}
}
if(!$nodeTagFound) {
$branch = new XMLBranch();
$branch->setTag(new Tag($tags[1]));
$newTagPath = implode($this->pathSeparator, array_slice($tags, 1));
$branch->setTagContent($content, $newTagPath);
$this->addXMLBranch($branch);
}
}
}
return $success;
}
}
import("org.active-link.xml.XMLBranch");
import("org.active-link.xml.XMLLeaf");
?>

View File

@@ -0,0 +1,71 @@
<?php
/*
This file is part of ActiveLink PHP XML Package (www.active-link.com).
Copyright (c) 2002-2004 by Zurab Davitiani
You can contact the author of this software via E-mail at
hattrick@mailcan.com
ActiveLink PHP XML Package is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
ActiveLink PHP XML Package is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with ActiveLink PHP XML Package; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* requires XML class
*/
import("org.active-link.xml.XML");
/**
* XMLBranch class provides a tree-like structure to read/write/modify XML
* @class XMLBranch
* @package org.active-link.xml
* @author Zurab Davitiani
* @version 0.4.0
* @extends XML
* @requires XML
* @see Tree
*/
class XMLBranch extends XML {
var $parentXML;
/**
* Gets parent object of the XML branch
* @method getParentXML
* @returns parent object of the XML branch
*/
function getParentXML() {
return $this->parentXML;
}
/**
* Sets parent object of the XML branch
* @method setParentXML
* @param object xml
* @returns true if successful, false otherwise
*/
function setParentXML(&$xml) {
$success = false;
if(strtolower(get_class($xml)) == "xml" || strtolower(get_class($xml)) == "xmlbranch") {
$this->parentXML = &$xml;
$success = true;
}
return $success;
}
}
?>

View File

@@ -0,0 +1,174 @@
<?php
/*
This file is part of ActiveLink PHP XML Package (www.active-link.com).
Copyright (c) 2002-2004 by Zurab Davitiani
You can contact the author of this software via E-mail at
hattrick@mailcan.com
ActiveLink PHP XML Package is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
ActiveLink PHP XML Package is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with ActiveLink PHP XML Package; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* requires XML, Tag and File classes
*/
import("org.active-link.xml.XML");
import("org.active-link.sys.File");
import("org.active-link.xml.Tag");
/**
* XMLDocument class provides a document class for XML
* @class XMLDocument
* @package org.active-link.xml
* @author Zurab Davitiani
* @version 0.4.0
* @extends File
* @requires File, XML, Tag
* @see XML
*/
class XMLDocument extends File {
// protected variables
var $xml;
var $tag;
/**
* If filename is set and fileOpenMode is one of the modes that allows file to be read then file is opened and its contents parsed
* If filename is set and fileOpenMode is something other than above the appropriate file is opened/created
* If filename is not set then no files are opened/parsed/created and object contains default values
* @method XMLDocument
* @param optional string filename
* @param optional string fileOpenMode
*/
function XMLDocument($filename = "", $fileOpenMode = "r") {
$success = $this->File($filename, $fileOpenMode);
$this->tag = new Tag();
$this->tag->tagStartOpen = "<?";
$this->tag->tagClose = "?>";
if($this->connected && ($this->fileOpenMode == $this->fileOpenModeRead || $this->fileOpenMode == $this->fileOpenModeReadWrite)) {
$fileContents = $this->getContents();
$this->close();
$this->parseFromString($fileContents);
}
else {
$this->setDefaultXMLTag();
$this->xml = new XML();
}
return $success;
}
/**
* Returns the XML object containing actual XML tree; in PHP 4 make sure to use =& to get a reference instead of a copy
* @method getXML
* @returns object of type XML containing actual XML tree
*/
function getXML() {
return $this->xml;
}
/**
* Returns the XML string of a complete XML document
* @method getXMLString
* @returns string containing contents of XML document
*/
function getXMLString() {
$xmlString = $this->tag->getTagString();
$xmlString .= "\n\n";
$xmlString .= $this->xml->getXMLString(0);
return $xmlString;
}
/**
* Parses XML document from supplied string, also called from constructor when parsing file contents
* @method parseFromString
* @param string XMLDocString
* @returns none
*/
function parseFromString($XMLDocString) {
$tagPos = $this->tag->setTagFromString($XMLDocString);
if($tagPos === false) {
$tagPos = array(0 => 0, 1 => 0);
$this->setDefaultXMLTag();
}
$xmlContents = trim(substr($XMLDocString, $tagPos[1]));
$this->xml = new XML($xmlContents);
}
/**
* Saves document contents to a supplied filename
* @method save
* @param string filename
* @returns true if successful, false otherwise
*/
function save($filename) {
$success = $this->open($filename, $this->fileOpenModeWrite);
if($success) {
$bytesWritten = $this->write($this->getXMLString());
if($bytesWritten <= 0)
$success = false;
$this->close();
}
return $success;
}
/**
* (Re)sets XML version/encoding to default values
* @method setDefaultXMLTag
* @returns none
*/
function setDefaultXMLTag() {
$this->tag->setTagName("xml");
$this->tag->setAttribute("version", "1.0");
$this->tag->setAttribute("encoding", "UTF-8");
}
/**
* Sets encoding of the XML document
* @method setEncoding
* @param string encoding
* @returns none
*/
function setEncoding($encoding) {
$this->tag->setAttribute("encoding", $encoding);
}
/**
* Sets version of the XML document
* @method setVersion
* @param string version
* @returns none
*/
function setVersion($version) {
$this->tag->setAttribute("version", $version);
}
/**
* Sets XML object of the XMLDocument, sets/changes/updates XML content to the supplied XML tree, uses reference no copy is created
* @method setXML
* @param object xml
* @returns true if successful, false otherwise
*/
function setXML(&$xml) {
$success = false;
if(gettype($xml) == "object" && strtolower(get_class($xml)) == "xml") {
$this->xml = &$xml;
$success = true;
}
return $success;
}
}

View File

@@ -0,0 +1,73 @@
<?php
/*
This file is part of ActiveLink PHP XML Package (www.active-link.com).
Copyright (c) 2002-2004 by Zurab Davitiani
You can contact the author of this software via E-mail at
hattrick@mailcan.com
ActiveLink PHP XML Package is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
ActiveLink PHP XML Package is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with ActiveLink PHP XML Package; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* requires XML class
*/
import("org.active-link.xml.XML");
import("org.active-link.xml.XMLBranch");
import("org.active-link.xml.Leaf");
/**
* XMLLeaf class provides means to store text values for use in XML tree
* @class XMLLeaf
* @package org.active-link.xml
* @author Zurab Davitiani
* @version 0.4.0
* @extends Leaf
* @requires Leaf
* @see XML
*/
class XMLLeaf extends Leaf {
var $parentXML;
/**
* Gets parent object of the XML leaf
* @method getParentXML
* @returns parent object of the XML leaf
*/
function getParentXML() {
return $this->parentXML;
}
/**
* Sets parent object of the XML leaf
* @method setParentXML
* @param object xml
* @returns true if successful, false otherwise
*/
function setParentXML(&$xml) {
$success = false;
if(strtolower(get_class($xml)) == "xml" || strtolower(get_class($xml)) == "xmlbranch") {
$this->parentXML = &$xml;
$success = true;
}
return $success;
}
}
?>

View File

@@ -0,0 +1,120 @@
<?php
/*
This file is part of ActiveLink PHP XML Package (www.active-link.com).
Copyright (c) 2002-2004 by Zurab Davitiani
You can contact the author of this software via E-mail at
hattrick@mailcan.com
ActiveLink PHP XML Package is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
ActiveLink PHP XML Package is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with ActiveLink PHP XML Package; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* requires HTTPClient, XML and XMLDocument classes
*/
import("org.active-link.net.HTTPClient");
import("org.active-link.xml.XML");
import("org.active-link.xml.XMLDocument");
/**
* XMLRPCClient class provides XML-RPC client capabilities
* @class XMLRPCClient
* @package org.active-link.xml
* @author Zurab Davitiani
* @version 0.4.0
* @extends HTTPClient
* @requires HTTPClient, XML, XMLDocument
* @see HTTPClient
*/
class XMLRPCClient extends HTTPClient {
var $xml;
var $xmlDoc;
var $params;
/**
* XMLRPCClient client class constructor accepts host (required) and port (optional, default 80) arguments
* @method XMLRPCClient
* @param string host
* @param optional int port
*/
function XMLRPCClient($host, $port = 80) {
$this->HTTPClient($host, $port);
$this->setRequestMethod("POST");
$this->addRequestHeaderRaw("Content-type: text/xml");
$this->xml = new XML("methodCall");
$this->xml->setTagContent("", "methodCall/methodName");
$this->xml->setTagContent("", "methodCall/params");
$this->xmlDoc = new XMLDocument();
$this->xmlDoc->setXML($this->xml);
$paramsBranchArray = &$this->xml->getBranches("methodCall", "params");
$this->params = &$paramsBranchArray[0];
// this call not necessary if we can somehow update body before HTTPClient->sendRequest
$this->setRequestBody($this->xmlDoc->getXMLString());
}
/**
* Adds a parameter to a method call in XMLRPC request
* @method addParam
* @param string paramType
* @param mixed paramValue
* @returns none
*/
function addParam($paramType, $paramValue) {
$newParam = new XMLBranch("param");
$newParam->setTagContent($paramValue, "param/value/$paramType");
$this->params->addXMLBranch($newParam);
// this call not necessary if we can somehow update body before HTTPClient->sendRequest
$this->setRequestBody($this->xmlDoc->getXMLString());
}
/**
* Sets method name in XMLRPC request
* @method setMethodName
* @param string methodName
* @returns none
*/
function setMethodName ($methodName) {
$this->xml->setTagContent($methodName, "methodCall/methodName");
// this call not necessary if we can somehow update body before HTTPClient->sendRequest
$this->setRequestBody($this->xmlDoc->getXMLString());
}
/**
* Sets XMLRPC request by supplying an XMLDocument object
* @method setRequestXML
* @param object XMLDocument
* @returns true if successful, false otherwise
*/
function setRequestXML(&$XMLDocument) {
if(is_object($XMLDocument) && strtolower(get_class($XMLDocument)) == "xmldocument") {
$this->xmlDoc = &$XMLDocument;
$this->xml = &$this->xmlDoc->getXML();
$this->params = &$this->xml->getBranches("methodCall", "params");
// this call not necessary if we can somehow update body before HTTPClient->sendRequest
$this->setRequestBody(htmlspecialchars($this->xmlDoc->getXMLString()));
$success = true;
}
else
$success = false;
return $success;
}
}
?>

View File

@@ -0,0 +1,46 @@
<?php
/*
This file is part of ActiveLink PHP XML Package (www.active-link.com).
Copyright (c) 2002-2004 by Zurab Davitiani
You can contact the author of this software via E-mail at
hattrick@mailcan.com
ActiveLink PHP XML Package is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
ActiveLink PHP XML Package is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with ActiveLink PHP XML Package; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* requires XML class
*/
import("org.active-link.xml.XML");
/**
* XPath class provides XPath interface to XML object
* @class XPath
* @package org.active-link.xml
* @author Zurab Davitiani
* @version 0.4.0
* @see XML
*/
class XPath {
var $xml;
}
?>