A
download class.LanguageRegistry.php
Language: PHP
LOC: 61
Project Info
FreeMED Project(freemed)
Server: SourceForge
Type: cvs
...reemed\freemed\freemed\lib\
   acl.php
   API.php
   bcadd.php
   calendar-functions.php
   class.AdminModule.php
   class.Agata.php
   class.Authorizations.php
   class.BaseModule.php
   class.BillingModule.php
   class.CalendarModule.php
   class.ClaimLog.php
   class.Coverage.php
   class.Debug.php
   class.diagnosis_set.php
   class.Djvu.php
   class.EMRModule.php
   class.Fax.php
   class.FixedFormEntry.php
   ...s.FixedFormRenderer.php
   class.FormRenderer.php
   class.FreeMEDSelfTest.php
   class.GeneralConfig.php
   class.GraphModule.php
   class.Guarantor.php
   class.Handler_HL7v2.php
   ...s.Handler_HL7v2_A04.php
   ...s.Handler_HL7v2_A08.php
   ...s.Handler_HL7v2_S12.php
   ...s.Handler_HL7v2_S15.php
   class.InsuranceCompany.php
   class.LanguageRegistry.php
   class.Ledger.php
   ...s.MaintenanceModule.php
   class.Messages.php
   class.OMBS_Patient.php
   class.OMBS_Wrapper.php
   class.Parser_HL7v2.php
   class.Patient.php
   class.Payer.php
   class.PHPlot.php
   class.Physician.php
   class.Procedure.php
   class.RecordLock.php
   class.Remitt.php
   class.ReportsModule.php
   class.rxlist.php
   class.Scheduler.php
   class.TeX.php
   class.User.php
   class.UtilityModule.php
   class.vCalendar.php
   class.vCalendarEvent.php
   error_handler.php
   freemed.php
   i18n.php
   iso-set.php
   macros.php
   mail-functions.php
   settings.php
   settings.php.tmpl
   xml.php
   xmlrpc_services.php

<?php
    // $Id: class.LanguageRegistry.php,v 1.5 2003/11/05 04:40:54 rufustfirefly Exp $
    // $Author: rufustfirefly $

LoadObjectDependency('PHP.GettextXML');

// Class: FreeMED.LanguageRegistry
//
//	Class to handle FreeMED's language registry, built from entries
//	in FreeMED's "locale" folder. These are in the GettextXML format.
//
class LanguageRegistry {

	function LanguageRegistry () {

		// Get directory
		if (! ($d = dir("./locale/")) ) {
			die(get_class($this)." :: could not open directory ./locale");
		}

		// Check for serialized file
		$cache = CreateObject(
			'PHP.FileSerialize',
			'data/cache/language_registry'
		);

		// Is it cached?
		if (!$this->cached()) {
			while ($entry = $d->read()) {
				//print "entry = $entry<br/>\n";
				if (is_dir('./locale/'.$entry) and
						($entry != "template") and
						(substr($entry,0,1) != '.') and
						($entry != 'CVS') ) {
					$this->register($entry);
				}
			}

			// Write to cache
			$cache->write($this->registry);
		} else {
			// Read from cache
			$this->registry = $cache->read();
		}
	} // end constructor LanguageRegistry

	// Method: LanguageRegistry->cached
	//
	//	Determine if the language registry cache is up to date.
	//
	// Returns:
	//
	//	Boolean, true if data is up to date, false if recaching
	//	is necessary.
	//
	function cached () {
		// Check for non-existant cache file
		if (!file_exists('data/cache/language_registry')) {
		/*
			$touched = touch ('data/cache/language_registry');
			if (!$touched) {
				die(
				__("FreeMED was unable to create a file to record the language registry.")."<br/>\n".
				__("FreeMED's 'locale' directory should be owned by the user that the webserver is running as...")."<br/>\n".
				__("Usually this is 'apache'. You can also fix this by giving universal write access to the 'locale' directory of FreeMED.")."<br/>\n"
				);
			}
		*/
			return false;
		}

		// Get directory modification date
		clearstatcache();
		$dir_modified = array_element(lstat('./locale/'), 9);

		// Get cache modification date
		clearstatcache();
		$cache_modified = array_element(lstat('data/cache/language_registry'), 9);

		// If the cache is older than the directory
		if ($cache_modified < $dir_modified) {
			//print "rebuild<br/>\n";
			// Rebuild cache
			return false;
		} else {
			// Otherwise cache is up to date
			//print "fine<br/>\n";
			return true;
		}
	} // end method cached

	// Method: LanguageRegistry->register
	//
	//	Register a language directory with the FreeMED language
	//	registry.
	//
	// Parameters:
	//
	//	$dir - Directory. This should be a subdirectory of
	//	FreeMED's "locale" folder.
	//
	function register ($dir) {
		if (!file_exists('./locale/'.$dir.'/freemed.xml')) {
			print "COULD NOT INDEX $dir<br/>\n";
			return false;
		}

		// Read the using GettextXML::metainformation
		$meta = GettextXML::metainformation(
			'./locale/'.$dir.'/freemed.xml'
		);

		//print "meta[Locale] = ".$meta['Locale']."<br/>\n";
		$this->registry[$meta['LocaleName']] = $meta['Locale'];
	} // end method register

	// Method: LanguageRegistry->widget
	//
	//	Create a language selection widget based on the current
	//	language registry.
	//
	// Parameters:
	//
	//	$varname - Variable name to store the data
	//
	//	$options - Options, as passed to html_form::select_widget
	//
	// Returns:
	//
	//	XHTML-formatted language selection widget
	//
	function widget ($varname, $_options = NULL) {
		return html_form::select_widget(
			$varname,
			array_merge(
				array(__("Default Language") => DEFAULT_LANGUAGE),
				$this->registry
			),
			$_options
		);
	} // end method widget

} // end class LanguageRegistry

?>

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us