1<?php 2/******************************** 3OSBib: 4A collection of PHP classes to manage bibliographic formatting for OS bibliography software 5using the OSBib standard. Taken from WIKINDX (http://wikindx.sourceforge.net). 6 7Released through http://bibliophile.sourceforge.net under the GPL licence. 8Do whatever you like with this -- some credit to the author(s) would be appreciated. 9 10If you make improvements, please consider contacting the administrators at bibliophile.sourceforge.net 11so that your improvements can be added to the release package. 12 13Mark Grimshaw 2005 14http://bibliophile.sourceforge.net 15********************************/ 16/***** 17* LOADSTYLE class 18* 19*****/ 20class LOADSTYLE 21{ 22 function LOADSTYLE() 23 { 24 } 25/** 26* Read $stylesDir directory for XML style files and return an associative array. Each XML file should 27* be within its own folder within $stylesDir. This folder name should match the first part of the XML file name e.g. 28* apa/APA.xml or chicago/CHICAGO.xml 29* 30* @author Mark Grimshaw 31* @version 1 32* 33* @param $stylesDir Path to styles directory 34* @return Sorted assoc. array - keys = filename (less '.xml'), values = Style description. 35*/ 36 function loadDir($stylesDir) 37 { 38 $handle = opendir($stylesDir); 39 while(FALSE !== ($dir = readdir($handle))) 40 { 41 $fileName = strtoupper($dir) . ".xml"; 42 if(is_dir($stylesDir . '/' . $dir) 43 && file_exists($stylesDir . '/' . $dir . "/" . $fileName)) 44 { 45 if($fh = fopen($stylesDir . '/' . $dir . "/" . $fileName, "r")) 46 { 47 preg_match("/<description>(.*)<\\/description>/i", fgets($fh), $matches); 48 $array[strtoupper($dir)] = $matches[1]; 49 } 50 fclose($fh); 51 } 52 } 53 if(!isset($array)) 54 return $array = array(); 55/** 56* Sort alphabetically on the key. 57*/ 58 ksort($array); 59 return $array; 60 } 61} 62?> 63