errorMessage = "File $fileName doesn't exist"; return FALSE; } else { if(!($this->getXmlArray($fileName))) return FALSE; $this->galleryDir = "$wgServer$wgScriptPath$dirName"; $this->albumName = $this->dataArray['album']['albumName']; $this->count = $this->dataArray['album']['albumItemCount']; return TRUE; } } function getThumbnailsPrint($showLarge = 1, $multiSet = 1) { $mwOut = "\n\t\n"; if($this->count > 1){ /*a bug repaired 05.11.2007*/ foreach ($this->dataArray['album']['images']['image'] as $key => $value) { if ($showLarge){ $mwOut .= "\t\t".''."\n"; } $mwOut .= "\t\t\t".''."\n"; //$mwOut .= preg_replace('/<.*[\\]+p>/i', '',$value['itemCaption']); if ($showLarge) $mwOut .= "\t\t\n"; } } else { $value = $this->dataArray['album']['images']['image']; if ($showLarge) $mwOut .= "\t\t".''."\n"; $mwOut .= "\t\t\t".''."\n"; if ($showLarge) $mwOut .= "\t\t\n"; } $mwOut .= "\t\n"; return $mwOut; } function getErrorMessage() { return $this->errorMessage; } function getCount() { return $this->count; } function getName() { return $this->albumName; } function getXmlArray($xmlFile) { /** * getXmlArray - an abstraction layer on xml_parse_into_struct that * returns a nice nested array. based on dudus at onet dot pl's: * http://www.php.net/manual/en/function.xml-parse-into-struct.php#49154 * * @param $xmlFileName - xml file which will be fed into * xml_parse_into_struct() * @return array object GalleryStatus a status code * array a nested php array containing xml data. */ $xmlParser = xml_parser_create(); xml_parser_set_option($xmlParser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($xmlParser, XML_OPTION_SKIP_WHITE, 1); $vals = array(); if(!$fp = fopen($xmlFile, "r")) { $this->errorMessage = "File opening ($xmlFile) failed"; return FALSE; } while ($data = fread($fp, 4096)) { $rawXml .= $data; } xml_parse_into_struct($xmlParser, $rawXml, $vals); xml_parser_free($xmlParser); $_tmp = ''; foreach ($vals as $xmlElem) { $xTag = $xmlElem['tag']; $xLevel = $xmlElem['level']; $xType = $xmlElem['type']; if (($xLevel != 1) && ($xType == 'close')) { if (isset($multiKey[$xTag][$xLevel])) { $multiKey[$xTag][$xLevel] = 1; } else { $multiKey[$xTag][$xLevel] = 0; } } if (($xLevel != 1) && ($xType == 'complete')) { if ($_tmp == $xTag) { $multiKey[$xTag][$xLevel] = 1; } $_tmp = $xTag; } } foreach ($vals as $xmlElem) { $xTag = $xmlElem['tag']; $xLevel = $xmlElem['level']; $xType = $xmlElem['type']; if ($xType == 'open') { $level[$xLevel] = $xTag; } $startLevel = 1; $phpStmt = '$xmlArray'; if ($xType == 'close' && $xLevel != 1) { $multiKey[$xTag][$xLevel]++; } while($startLevel < $xLevel) { $phpStmt .= '[$level[' . $startLevel . ']]'; if ((isset($multiKey[$level[$startLevel]][$startLevel])) && ($multiKey[$level[$startLevel]][$startLevel])) { $phpStmt .= '[' . ($multiKey[$level[$startLevel]][$startLevel]-1) . ']'; } $startLevel++; } $add = ''; if ((isset($multiKey[$xTag][$xLevel])) && ($multiKey[$xTag][$xLevel]) && (($xType == 'open') || ($xType == 'complete'))) { if (!isset($multiKey2[$xTag][$xLevel])) { $multiKey2[$xTag][$xLevel] = 0; } else { $multiKey2[$xTag][$xLevel]++; } $add = '[' . $multiKey2[$xTag][$xLevel] . ']'; } if ((isset($xmlElem['value'])) && (trim($xmlElem['value']) != '') && (!array_key_exists('attributes', $xmlElem))) { if ($xType == 'open') { $phpStmtMain = $phpStmt . '[$xType]' . $add . '[\'content\'] = $xmlElem[\'value\'];'; } else { $phpStmtMain = $phpStmt . '[$xTag]' . $add . ' = trim($xmlElem[\'value\']);'; } eval($phpStmtMain); } if (array_key_exists('attributes', $xmlElem)) { if (isset($xmlElem['value'])) { $phpStmtMain = $phpStmt . '[$xTag]' . $add . '[\'content\'] = $xmlElem[\'value\'];'; eval($phpStmtMain); } foreach ($xmlElem['attributes'] as $key => $value) { $phpStmtAtt = $phpStmt . '[$xTag]' . $add . '[\'attributes\'][$key] = $value;'; eval($phpStmtAtt); } } } if (!isset($xmlArray)) { $this->errorMessage = 'Error parsing XML'; return FALSE; } $this->dataArray = $xmlArray; return TRUE; } } ?>