<?php
/**
 * This file is part of the mobileOK Pythia plug-in for Wordpress and defines the
 * {@link WURFLServiceConfiguration} class.
 * 
 * @author Sylvain Lequeux
 * @author Francois Daoust <fd@w3.org>
 * @package mobileOKPythia
 * @subpackage Wordpress
 * @version $Revision: 1.4 $
 * @license http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231.html W3C Software Notice and License
 * @copyright Copyright (c) 2009, W3C (MIT, ERCIM, Keio)
 */

require_once(dirname(__FILE__) . '/../common/plugins/DDRServiceConfigurationFactory.php');
require_once(dirname(__FILE__) . '/../common/ddrsimpleapi/interface/systemException.php');


/**
 * The WURFLServiceConfiguration class defines the settings required
 * to instantiate a working {@link WURFLService}.   
 *
 * @author Sylvain Lequeux
 * @author Francois Daoust <fd@w3.org>
 * @package mobileOKPythia
 * @subpackage Wordpress
 * @version $Revision: 1.4 $
 * @license http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231.html W3C Software Notice and License
 * @copyright Copyright (c) 2009, W3C (MIT, ERCIM, Keio)
 */
class WURFLServiceConfiguration implements DDRServiceConfiguration {
	/**
	 * Retrieves the configuration settings to use to instantiate
	 * a {@link WURFLService}. The method throws an exception when
	 * the path to the WURFL database is incorrect. 
	 * 
	 * @return array<string=>string> An array with a 'wurfl_path'
	 *   key whose value is the path to the folder that contains
	 *   the prepared WURFL database.
	 */
	function getConfig(){
		$path = get_option('mobileOKPythia_wurfl_path');
		
		// Make sure the path ends up with a '/'
		$lastChar = substr($path, strlen($path) -1);
		if($lastChar != '/' && $lastChar != '\\'){
			$path .= '/';
		}
		
		if(!file_exists($path)){
			throw new SystemException(
					"The path to the WURFL database does not exist",
					SystemException::$CANNOT_PROCEED
				);
		}
		return array('wurfl_path' => $path);
	}
	
	function addOptions() {
		add_option("mobileOKPythia_wurfl_path", dirname(__FILE__), '', 'yes');
	}
	
	function printOptions() {
		echo '<br/>';
		_e('The WURFL database must be <em>prepared</em> before it may be used. If you would like to update or patch the version of the WURFL database used by this plug-in, please follow the steps described in the <a href="../wp-content/plugins/mobileOKPythia/common/ddrsimpleapi/implementation/WURFL/WURFLPrepareDatabase.php">WURFL preparation for use in AskPythia</a> page.', 'mobileOKPythia');
		echo ' ';
		_e('Once prepared, make sure the following path points to the folder that contains the prepared files.', 'mobileOKPythia');
		echo '<br/>';
		echo '<input type="text" name="mobileOKPythia_wurfl_path" value="' . get_option('mobileOKPythia_wurfl_path') . '" size="70" />';
	}
	
	function getOptions() {
		return "mobileOKPythia_wurfl_path,";
	}
}
?>