Skip to content
This repository has been archived by the owner on Nov 26, 2017. It is now read-only.

Let JFactory::getXML() opt to receive a SimpleXMLElement. #1222

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libraries/joomla/access/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ public static function getActionsFromFile($file, $xpath = "/access/section[@name
else
{
// Else return the actions from the xml.
return self::getActionsFromData(JFactory::getXML($file, true), $xpath);
return self::getActionsFromData(JFactory::getXML($file, true, false), $xpath);
}
}

Expand All @@ -521,7 +521,7 @@ public static function getActionsFromData($data, $xpath = "/access/section[@name
// Attempt to load the XML if a string.
if (is_string($data))
{
$data = JFactory::getXML($data, false);
$data = JFactory::getXML($data, false, false);

// Make sure the XML loaded correctly.
if (!$data)
Expand Down
24 changes: 17 additions & 7 deletions libraries/joomla/factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,32 +372,41 @@ public static function getFeedParser($url, $cache_time = 0)
/**
* Reads a XML file.
*
* @param string $data Full path and file name.
* @param boolean $isFile true to load a file or false to load a string.
* @param string $data Full path and file name.
* @param boolean $isFile true to load a file or false to load a string.
* @param boolean $jxmlement true to load a JXMLElement otherwise loads as SimpleXMLElement.
*
* @return mixed JXMLElement on success or false on error.
* @return mixed JXMLElement or SimpleXMLElement on success or false on error.
*
* @see JXMLElement
* @since 11.1
* @note This method will return SimpleXMLElement object in the future. Do not rely on JXMLElement's methods.
* @todo This may go in a separate class - error reporting may be improved.
*/
public static function getXML($data, $isFile = true)
public static function getXML($data, $isFile = true, $jxmlement = true)
{
jimport('joomla.utilities.xmlelement');
if ($jxmlement)
{
jimport('joomla.utilities.xmlelement');
$class = 'JXMLElement';
}
else
{
$class = 'SimpleXMLElement';
}

// Disable libxml errors and allow to fetch error information as needed
libxml_use_internal_errors(true);

if ($isFile)
{
// Try to load the XML file
$xml = simplexml_load_file($data, 'JXMLElement');
$xml = simplexml_load_file($data, $class);
}
else
{
// Try to load the XML string
$xml = simplexml_load_string($data, 'JXMLElement');
$xml = simplexml_load_string($data, $class);
}

if (empty($xml))
Expand All @@ -415,6 +424,7 @@ public static function getXML($data, $isFile = true)
}
}

libxml_clear_errors();
return $xml;
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/joomla/language/language.php
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,7 @@ public static function parseXMLLanguageFiles($dir = null)
public static function parseXMLLanguageFile($path)
{
// Try to load the file
if (!$xml = JFactory::getXML($path))
if (!$xml = JFactory::getXML($path, true, false))
{
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions libraries/joomla/utilities/xmlelement.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class JXMLElement extends SimpleXMLElement
*/
public function name()
{
JLog::add('JXMLElement::name() is deprecated, use SimpleXMLElement::getName() instead.', JLog::WARNING, 'deprecated');
JLog::add('JXMLElement::name() is deprecated. Use SimpleXMLElement::getName() instead.', JLog::WARNING, 'deprecated');
return (string) $this->getName();
}

Expand All @@ -47,7 +47,7 @@ public function name()
*/
public function asFormattedXML($compressed = false, $indent = "\t", $level = 0)
{
JLog::add('JXMLElement::asFormattedXML() is deprecated, use SimpleXMLElement::asXML() instead.', JLog::WARNING, 'deprecated');
JLog::add('JXMLElement::asFormattedXML() is deprecated. Use SimpleXMLElement::asXML() instead.', JLog::WARNING, 'deprecated');
$out = '';

// Start a new line, indent by the number indicated in $level
Expand Down
2 changes: 1 addition & 1 deletion libraries/legacy/application/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public static function parseXMLInstallFile($path)
public static function parseXMLLangMetaFile($path)
{
// Read the file to see if it's a valid component XML file
$xml = JFactory::getXML($path);
$xml = JFactory::getXML($path, true, false);

if (!$xml)
{
Expand Down
2 changes: 1 addition & 1 deletion libraries/legacy/help/help.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public static function createSiteList($pathToXml)

if (!empty($pathToXml))
{
$xml = JFactory::getXML($pathToXml);
$xml = JFactory::getXML($pathToXml, true, false);
}

if (!$xml)
Expand Down