section of HTML Document generation.
================================
*/
static function renderCss() {
echo ' '.PHP_EOL;
foreach(self::$modules as $module) {
if (file_exists('modules/'.$module.'.css')) {
echo ' '.PHP_EOL;
}
}
}
/*
================================
static function renderProgram()
This function checks for and calls each Module's onRender member function.
================================
*/
static function renderProgram() {
echo '
',PHP_EOL;
foreach(self::$modules as $module) {
if (method_exists('ktk\\MediaServe\\'.$module, 'onRender')) {
call_user_func('ktk\\MediaServe\\'.$module.'::onRender');
}
}
echo '
',PHP_EOL;
}
/*
================================
static function closeProgram()
This function checks for and calls each Module's onRender member function.
================================
*/
static function closeProgram() {
foreach(self::$modules as $module) {
if (method_exists('ktk\\MediaServe\\'.$module, 'onClose')) {
call_user_func('ktk\\MediaServe\\'.$module.'::onClose');
}
}
}
/*
================================
static function reportError($context, $subcontext, $error)
This function is used to report program/Module errors. The recommended calling style is:
MediaServer::reportError(__CLASS__, __FUNCTION__, "A description of the error");
Params:
$context - context of the error, generally __CLASS__
$subcontext - sub-context of the error, generally __FUNCTION__
$error - String describing the error
TODO: Probably should combine reportError and reportWarning into the same function, wherein errors can be classified by the user.
================================
*/
static function reportError($context, $subcontext, $error) {
if(!self::$errors[$context."::".$subcontext])
self::$errors[$context."::".$subcontext] = array();
array_push(self::$errors[$context."::".$subcontext], $error);
}
static function reportWarning($context, $subcontext, $warning) {
if(!self::$warnings[$context."::".$subcontext])
self::$warnings[$context."::".$subcontext] = array();
array_push(self::$warnings[$context."::".$subcontext], $warning);
}
/*
================================
static function loadConf($file)
This function takes a configuration name parameter and attempts to load a configuration .ini file within the conf/ sub-directory, i.e., "conf/some_config.ini". It returns an Array of the configuration if existing, or an empty Array otherwise.
Params:
$file - name of configuration to load, without any extensions
Returns:
Empty Array on failure
Array on success
================================
*/
static function loadConf($file) {
if (file_exists('conf/'.$file.'.ini')) {
return parse_ini_file('conf/'.$file.'.ini', 1);
} else {
self::reportWarning(__CLASS__, __FUNCTION__, "Could not load ".'conf/'.$file.'.ini');
}
return array();
}
/*
================================
static function saveConf($file, $data)
This function takes in a config name, as per loadConf, and attempts to write the passed Array as an .ini file within the conf/ sub-directory, i.e., "conf/some_config.ini".
Params:
$file - Configuration to save to, without extensions
$data - Array of data to save
Returns:
FALSE on failure
TRUE on success
================================
*/
static function saveConf($file, $data) {
if ($fp = fopen('conf/'.$file.'.ini', 'w')) {
self::writeData_r($fp, $data);
fclose($fp);
} else {
MediaServe::reportError(__CLASS__, __FUNCTION__, "Could not write to \"".$data."\", please check your permissions!");
return FALSE;
}
return TRUE;
}
/*
================================
static function writeData_r($handle, $value)
This is an internal recursive function used to write multi-dimensional arrays into PHP INI format.
Params:
$handle - file handle to write to
$value - Array or value to write
================================
*/
static function writeData_r($handle, $value) {
foreach ($data as $key=>$value) {
if (is_array($value)) {
fwrite($handle, '['.$key.']'.PHP_EOL);
self::writeData_r($handle, $value);
} else {
fwrite($handle, $key.'='.$value.PHP_EOL);
}
}
}
/*
================================
static function storeData($var, $data)
This function is used to store SESSION-specific data. It is reset when the client closes the connection or clears session data.
Params:
$var - variable name to store
$data - data to store
Returns:
Pointer to stored variable
================================
*/
static function &storeData($var, $data) {
$_SESSION[$var] = $data;
return $_SESSION[$var];
}
/*
================================
static function &getData($data)
This function returns a pointer to some SESSION-specific data.
Params:
$var - variable name to snag
Returns:
NULL on failure
Pointer on successful data load
================================
*/
static function &getData($var) {
if (isset($_SESSION[$var])) {
return $_SESSION[$var];
} else {
return NULL;
}
}
}
?>