<?php
/*
* @package LabCMS
* @copyright (c) 2006 Alexander Levin aka Loki (loki_angel@mail.ru)
* @support http://labcms.ru
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/
function core_config_skin()
{
	$result=array();
	$skins=glob(LAB_PATH_TEMPLATE.'/*', GLOB_ONLYDIR);
	foreach ($skins as $skin) {
		$key=$value=basename($skin);
		if (file_exists($skin.'/theme.xml')) {
			$xml=file_get_contents($skin.'/theme.xml');
			if (preg_match('/<name>(.+?)<\/name>/', $xml, $name)) {
				$value=$name[1];
			}
		}
		$result[$key]=$value;
	}
	return $result;
}

function core_config_url_type()
{
	$classes=glob(LAB_PATH_KERNEL.'/classes/Url/*.php');
	foreach ($classes as $k=>$v) {
		$name=basename($v, '.php');
		if ($name=='Interface') continue;
		$url[$k]=$name;
	}
	return array_combine($url, $url);
}

function core_config_default_lang()
{
	return Db::i()->selectCol("SELECT `key` AS ARRAY_KEY, `key` FROM ?_langs");
}

function core_config_auth_module()
{
	$modules=Db::i()->selectCol(
		"SELECT module AS ARRAY_KEY, m.name
		FROM ?_modules m JOIN ?_includes i ON m.module_id=i.module_id
		JOIN ?_tree t ON i.tree_id=t.tree_id
		WHERE disable=0 AND component=1 AND symlink=0 AND path IS NOT NULL AND `show`=1
		ORDER BY name"
	);
	if ($modules) foreach ($modules as $module=>$name) {
		if (!file_exists(LAB_PATH_MODULES.'/'.$module.'/class.auth.php')) unset($modules[$module]);
	}
	return $modules;
}

function core_config_user_rating_class()
{
	$classes=glob(LAB_PATH_KERNEL.'/classes/Rating/*.php');
	foreach ($classes as $k=>$v) {
		$name=basename($v, '.php');
		if ($name=='Interface') continue;
		if ($name=='Generic') continue;
		$rating[$k]=$name;
	}
	return array_combine($rating, $rating);
}