Skip to content
Snippets Groups Projects
Commit bdd738b5 authored by Aaron Klump's avatar Aaron Klump
Browse files

made _xml_field_parse_xml_string a private function; publicly use xml_field_xml instead;

more documentation
parent 2023ad6b
No related branches found
No related tags found
No related merge requests found
......@@ -94,13 +94,17 @@ $description = xml_field($node, 'description', NULL, array('check_markup', $form
Study the docblocks in the code for more info.
API:
* xml_field_xml()
* xml_field()
* xml_field_format()
API
The three main API Functions:
* xml_field_xml(): to obtain an XML object
* xml_field(): to access XML values
* xml_field_format(): to obtain a string version of any XML
* xml_field_output(): to output XML to the browser
Additional API functions:
* xml_field_is_valid_xml_string()
* xml_field_parse_xml_string()
* xml_field_xml_fields()
* theme_xml()
OTHER EXAMPLE CODE:
......
......@@ -3,6 +3,13 @@
* @file
* Defines the xml field type
*
* Comparison of API Functions:
*
* When you want a string back use: xml_field_format()
* When you want a simpleXMLElement object back: use xml_field_xml()
* When you want a node value from XML use: xml_field()
* When you want to output to browser use: xml_field_output()
*
* @ingroup xml_field XML Field
* @{
*/
......@@ -16,7 +23,7 @@
define('XML_FIELD_PRESERVE_WHITESPACE', TRUE);
/**
* Returns the xml from: entities, fields, objects, strings
* Returns the xml object from: entities, fields, objects, strings
*
* All of the following are valid input sources and will yield the same result,
it is your preference how you'd like to use this powerful function (take into
......@@ -55,8 +62,8 @@ function xml_field_xml($input, $callback_multiple = 'array_shift') {
}
// String
if (is_string($input) && xml_field_is_valid_xml_string($input)) {
return simplexml_load_string($input);
if ($xml = _xml_field_parse_xml_string($input)) {
return $xml;
}
$fields = xml_field_xml_fields();
......@@ -168,7 +175,7 @@ function xml_field($xml, $selector = NULL, $attribute = NULL, $default = '', $ca
}
/**
* Add proper formatting/sanitization to XML
* Returns formatted or sanitized XML string
*
* @param mixed $xml
* Anythign allowed by xml_field_xml()
......@@ -270,6 +277,33 @@ function xml_field_format($xml, $htmlentities = TRUE, $options = array()) {
return trim($result);
}
/**
* Returns data in XML format.
*
* Use this when serving XML as it sets the header for XML output.
*
* @param $var
* (optional) If set, the variable will be run through xml_field_format and
then output.
@see xml_field_format()
*/
function xml_field_output($var = NULL, $options = array()) {
// We are returning XML, so tell the browser.
drupal_add_http_header('Content-Type', 'text/xml');
if (!variable_get('xml_field_preserve_whitespace', XML_FIELD_PRESERVE_WHITESPACE)) {
$options += array(
'tab' => '',
'break' => '',
);
}
if (isset($var)) {
echo xml_field_format($var, FALSE, $options);
}
}
/**
* Parse an xml string and return the simpleXMLElement object
*
......@@ -302,7 +336,7 @@ function xml_field_format($xml, $htmlentities = TRUE, $options = array()) {
*
* @see http://php.net/manual/en/class.simplexmlelement.php
*/
function xml_field_parse_xml_string($xml) {
function _xml_field_parse_xml_string($xml) {
$parsed = is_string($xml) ? @simplexml_load_string($xml) : FALSE;
return $parsed instanceof SimpleXMLElement ? $parsed : FALSE;
}
......@@ -315,7 +349,7 @@ function xml_field_parse_xml_string($xml) {
* @return bool
*/
function xml_field_is_valid_xml_string($xml) {
return xml_field_parse_xml_string($xml) === FALSE ? FALSE : TRUE;
return _xml_field_parse_xml_string($xml) === FALSE ? FALSE : TRUE;
}
/**
......@@ -358,32 +392,6 @@ function xml_field_xml_fields($include_bundles_and_entity_types = FALSE) {
return $include_bundles_and_entity_types ? $entities : $field_list;
}
/**
* Returns data in XML format.
*
* Use this when serving XML as it sets the header for XML output.
*
* @param $var
* (optional) If set, the variable will be run through xml_field_format and
then output.
@see xml_field_format()
*/
function xml_field_output($var = NULL, $options = array()) {
// We are returning XML, so tell the browser.
drupal_add_http_header('Content-Type', 'text/xml');
if (!variable_get('xml_field_preserve_whitespace', XML_FIELD_PRESERVE_WHITESPACE)) {
$options += array(
'tab' => '',
'break' => '',
);
}
if (isset($var)) {
echo xml_field_format($var, FALSE, $options);
}
}
/**
* Implements hook_field_info().
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment