<?php
class Message
{
public $error;
public $language;
public function __construct($lang='english')
{
$this->error = '';
$this->language = $lang;
}
/**
* Retrieves a message given the language setting and the ID
*
* @access public
* @param $id the identification value of the message
* @author Brian Cook <hide@address.com>
* @return $message_node->nodeValue the message retrieved from the langauge file at the given IDs
*/
public function get_message($id)
{
//loads the message file into the DOM
$dom = new DOMDocument;
$dom->preserveWhiteSpace = false;
$dom->load( LANGUAGES . '/' . $this->language . '.xml' );
//set up the xpath, which actually locates the error nessage
$xpath = new DOMXPath($dom);
$message_node = $xpath->query('//message[@id="'.$id.'"]');
if(count($message_node) > 0)
{
return $message_node->item(0)->nodeValue;
}
else
{
return $this->get_message('cannot_find_message');
}
}
/**
* Retrieves a label given the language setting and the ID
*
* @access public
* @param $id the identification value of the label
* @param $file_location
* @author Brian Cook <hide@address.com>
* @return $label_node->nodeValue the label retrieved from the langauge file at the given IDs
*/
public function get_label($id, $file_location='core')
{
//loads the message file into the DOM
$dom = new DOMDocument;
$dom->preserveWhiteSpace = false;
if($file_location == 'core')
{
$dom->load( LANGUAGES . '/' . $this->language . '.xml' );
}
else
{
$dom->load( LANGUAGES . '/' . $file_location . '/' . $this->language . '.xml' );
}
//set up the xpath, which actually locates the error nessage
$xpath = new DOMXPath($dom);
$label_node = $xpath->query('//label[@id="'.$id.'"]');
if(count($label_node) > 0)
{
return $label_node->item(0)->nodeValue;
}
else
{
return $this->get_label('cannot_find_label');
}
}
public function get_messages($file_location)
{
$dom = new DOMDocument;
$dom->preserveWhiteSpace = false;
if($file_location == 'core')
{
$dom->load( LANGUAGES . '/' . $this->language . '.xml' );
}
else
{
$dom->load( MODULES . '/' . $file_location . '/' . $this->language . '.xml' );
}
$xpath = new DOMXpath($dom);
return $xpath->query('//message');
}
public function get_labels($file_location)
{
$dom = new DOMDocument;
$dom->preserveWhiteSpace = false;
if($file_location == 'core')
{
$dom->load( LANGUAGES . '/' . $this->language . '.xml' );
}
else
{
$dom->load( MODULES . '/' . $file_location . '/' . $this->language . '.xml' );
}
$xpath = new DOMXpath($dom);
return $xpath->query('//labels');
}
}
?>