Author Topic: Mọi người giúp tớ sủa lỗi phần này với  (Read 1330 times)

hieu_geotech

  • PHP Starter
  • *
  • Posts: 2
    • View Profile
Mọi người giúp tớ sủa lỗi phần này với
« on: March 04, 2012, 06:16:23 PM »
Khi truy cập nó Thông báo lỗi như sau:
Code: [Select]
[b]Fatal error: Call to a member function hasChildNodes() on a non-object in /home/thanhoai/public_html/ilovemuzic.tk/shoutbox/lib/St_XmlParser.class.php on line 42[/b]
Còn đây là toàn bộ code của file St_XmlParser.class.php
Code: [Select]
<?php

/**
* Class for parsing Smiletag specific XML file
*
* This class is intended to serialize and deserialize array from/to XML file.
*
* @package Smiletag
* @author Yuniar Setiawan <yuniarsetiawan@smiletag.com>
* @since 2.3
*/
global $num_total_message;
global $aaa;
global $bbb;
class St_XmlParser{

/**
* Parse XML from the specified configuration filename into array
* The config file (path-config.xml,smiletag-config.xml) has simple xml structure
* Apply locking to synchronize operation among users 
*
* @access public
* @return array if the file has contents, null if empty
*/
function parseMainConfigToArray($fileName) {
$file = @fopen($fileName,'r') or die("Could not open file $fileName or permission denied");

flock($file,LOCK_SH);
while(!feof($file)){
   $buffer[] = fgets($file,4096);
}
flock($file,LOCK_UN);
fclose($file);

$textData implode($buffer);
if(!empty($textData)){

$xmlDoc = new DOMIT_Lite_Document();
$xmlDoc->parseXML($textData,false);
$rootElement =& $xmlDoc->documentElement;
//dong trong the [b] la dong 42
[b]if($rootElement->hasChildNodes()){[/b]
$childNodes =& $rootElement->childNodes;
$childCount =& $rootElement->childCount;
global $aaa;
$aaa $childCount;
for($i=0;$i $childCount;$i++){
$childArray[trim($childNodes[$i]->nodeName)] = trim($childNodes[$i]->childNodes[0]->nodeValue);
}


}

return $childArray;
}else{
return null;
}

}

/**
* Updates global configuration
*
* @param string $fileName The configuration filename
* @param array $configuration The configuration which will be updated
* @access public
* @return boolean true if no error
*/
function updateConfiguration($fileName,$configuration){
$originalConfig $this->parseMainConfigToArray($fileName);


$textData '<?xml version="1.0"?>
'."\n".'<smiletag_config>'."\n".'</smiletag_config>';

$xmlDoc = new DOMIT_Lite_Document();
$xmlDoc->parseXML($textData,false);

$rootElement =& $xmlDoc->documentElement;

foreach ($originalConfig as $key=>$value){
if(isset($configuration[$key])){
$value = $configuration[$key];
}
$configElement =& $xmlDoc->createElement($key);
$configElement->appendChild($xmlDoc->createCDATASection($value));
$rootElement->appendChild($configElement);
}

$buffer = '<?xml version="1.0"?>'."\n".$xmlDoc->toNormalizedString(false);

//save backs to file
$file = @fopen($fileName,'w') or die("Could not open file $fileName or permission denied");       
flock($file,LOCK_EX);
fwrite($file,$buffer);
flock($file,LOCK_UN);
        fclose($file);

        return true;
}

/**
* Parse XML from the message.xml into array
* Apply locking to synchronize operation among users
*
* @access public
* @return array if the file has contents, null if empty
*/
function parseMessagesToArray($fileName) {
$file = @fopen($fileName,'r') or die("Could not open file $fileName or permission denied");

flock($file,LOCK_SH);
while(!feof($file)){
   $buffer[] = fgets($file,4096);
}
flock($file,LOCK_UN);
fclose($file);
//load data from file
$textData = implode($buffer);

if(!empty($textData)){

$xmlDoc = new DOMIT_Lite_Document();
$xmlDoc->parseXML($textData,false);
$rootElement =& $xmlDoc->documentElement;

//traverse to nodes and save the values into childArray
if($rootElement->hasChildNodes()){
$rowNodes =& $rootElement->childNodes;
$childCount =& $rootElement->childCount;
for($i=0;$i < $childCount;$i++){

$currentNode      =& $rowNodes[$i];
$currentNodeCount =& $currentNode->childCount;

for($j=0;$j< $currentNodeCount;$j++){
$childArray[$i][trim($currentNode->childNodes[$j]->nodeName)] = trim($currentNode->childNodes[$j]->childNodes[0]->nodeValue);
}


}
}
return $childArray;
}else{
return null;
}



/**
* Parse XML from the smiley-config.xml into array
* Apply locking to synchronize operation among users
* Currently this function has the same functional as parseMessagesToArray
*
* @access public
* @return array if the file has contents, null if empty
*/
function parseSmiliesToArray($fileName) {
return $this->parseMessagesToArray($fileName);

/**
* Parse the badword list specified in the $fileName into array
*
* @access public
* @param string $fileName badword configuration file
* @return array containing pattern and its replacement
*/
function parseBadwordToArray($fileName){

$file = @fopen($fileName,'r') or die("Could not open file $fileName or permission denied");

flock($file,LOCK_SH);
while(!feof($file)){
   $buffer[] = fgets($file,4096);
}
flock($file,LOCK_UN);
fclose($file);
//load data from file
$textData = implode($buffer);

if(!empty($textData)){

$xmlDoc = new DOMIT_Lite_Document();
$xmlDoc->parseXML($textData,false);

//gets the replacement words
$replacement   = $xmlDoc->getElementsByTagName('replacement');
$replacement   = $replacement->item(0);
$replacement   = $replacement->getText(); //currently replacement is not an array

//gets the bad words
$badwordList   = $xmlDoc->getElementsByPath('/badword_config/badwords/word');
$max    = $badwordList->getLength();


if($max != 0){
for($i=0;$i<$max;$i++){
$currentNode =& $badwordList->item($i);
$badwords[]  = trim($currentNode->getText());
}
}else{
$badwords = null;
}

$badwordArray['replacement'] = $replacement;
$badwordArray['badwords'] = $badwords;

return $badwordArray;

}else{
return null;
}
}


/**
* Append input message to the specified XML file
*
* @param string $fileName Message file name
* @param integer $maxMessageRotation The maximum allowed number of messages stored in file, if set to 0 then unlimited
* @param array $newMessage The new messages input
* @return boolean true on succeeded
*/
function appendMessage($fileName,$maxMessageRotation,$newMessage){

$file = @fopen($fileName,'r') or die("Could not open file $fileName or permission denied");

flock($file,LOCK_SH);
while(!feof($file)){
   $buffer[] = fgets($file,4096); //load data from file
}
flock($file,LOCK_UN);
fclose($file);

$textData = trim(implode($buffer));

if(empty($textData)){
$textData = '<?xml version="1.0"?>'."\n".'<smiletag_message>'."\n".'</smiletag_message>';
};

$xmlDoc = new DOMIT_Lite_Document();
$xmlDoc->parseXML($textData,false);

$rootElement =& $xmlDoc->documentElement;

//apply message rotation if applied and maximum number reached
//delete the unwanted childs
if($maxMessageRotation != 0){
if(($rootElement->childCount) >= $maxMessageRotation){
while (($rootElement->childCount) >= $maxMessageRotation) {
$rootElement->removeChild($rootElement->lastChild);
}
}
}

//create new element, and insert it before the first child
$rowElement =& $xmlDoc->createElement('row');
$nameElement =& $xmlDoc->createElement('name');
$urlElement =& $xmlDoc->createElement('url');
$messageElement =& $xmlDoc->createElement('message');
$datetimeElement =& $xmlDoc->createElement('datetime');
$ipaddressElement =& $xmlDoc->createElement('ipaddress');

//domit hacks
//replace all '&amp;' into '&' to support unicode encoding (multilanguage character support)
$nameElement->appendChild($xmlDoc->createCDATASection(str_replace('&amp;','&',$newMessage['name'])));
$urlElement->appendChild($xmlDoc->createCDATASection($newMessage['url']));
$messageElement->appendChild($xmlDoc->createCDATASection(str_replace('&amp;','&',$newMessage['message'])));
$datetimeElement->appendChild($xmlDoc->createTextNode($newMessage['datetime']));
$ipaddressElement->appendChild($xmlDoc->createTextNode($newMessage['ipaddress']));

$rowElement->appendChild($nameElement);
$rowElement->appendChild($urlElement);
$rowElement->appendChild($messageElement);
$rowElement->appendChild($datetimeElement);
$rowElement->appendChild($ipaddressElement);

$rootElement->insertBefore($rowElement,$rootElement->firstChild);


$buffer = '<?xml version="1.0"?>'."\n".$xmlDoc->toNormalizedString(false);

//save backs to file
$file = @fopen($fileName,'w') or die("Could not open file $fileName or permission denied");       
flock($file,LOCK_EX);
fwrite($file,$buffer);
flock($file,LOCK_UN);
        fclose($file);

        return true;
}

/**
* Delete selected message
*
* @param string $fileName Message file name
* @param array $messageId The message timestamp which will be deleted
* @return boolean true on succeeded
*/
function deleteMessage($fileName,$messageId){

$messageArray = array_reverse($this->parseMessagesToArray($fileName));

$textData = '<?xml version="1.0"?>'."\n".'<smiletag_message>'."\n".'</smiletag_message>';


$xmlDoc = new DOMIT_Lite_Document();
$xmlDoc->parseXML($textData,false);

$rootElement =& $xmlDoc->documentElement;

foreach ($messageArray as $key=>$value){
if(!in_array($value['datetime'],$messageId)){

//create new element, and insert it before the first child
$rowElement =& $xmlDoc->createElement('row');
$nameElement =& $xmlDoc->createElement('name');
$urlElement =& $xmlDoc->createElement('url');
$messageElement =& 
Mong mọi người giúp đỡ! Xin cảm ơn
« Last Edit: March 04, 2012, 06:19:20 PM by hieu_geotech »

thienha20

  • PHP Intermediate
  • *
  • Posts: 228
    • View Profile
Re: Mọi người giúp tớ sủa lỗi phần này với
« Reply #1 on: March 04, 2012, 11:13:50 PM »
$rootElement khai báo là không chính xác chuyển wa dùng cái khác DOMIT_Lite_Document
+Nhận chỉnh sửa, viết addon cscart , opencart từ a->z
+Nhận bảo trì, sửa chữa website với bất kỳ cms hay FW nào miễn không bị mã hóa
Liên hệ : 01266371311

hieu_geotech

  • PHP Starter
  • *
  • Posts: 2
    • View Profile
Re: Mọi người giúp tớ sủa lỗi phần này với
« Reply #2 on: March 06, 2012, 11:12:03 PM »
$rootElement khai báo là không chính xác chuyển wa dùng cái khác DOMIT_Lite_Document
Cảm ơn bạn! nhưng ý bạn là thay $rootElement bằng hàm DOMIT_Lite_Document này ah

thienha20

  • PHP Intermediate
  • *
  • Posts: 228
    • View Profile
Re: Mọi người giúp tớ sủa lỗi phần này với
« Reply #3 on: March 07, 2012, 04:44:16 PM »
DOMIT_Lite_Document của bạn là không support nên nó chẳng thể gọi hàm. Bạn có thể dùng vài cái khác để đọc xml
+Nhận chỉnh sửa, viết addon cscart , opencart từ a->z
+Nhận bảo trì, sửa chữa website với bất kỳ cms hay FW nào miễn không bị mã hóa
Liên hệ : 01266371311