<?php

global $config, $option;

function config($name, $echo = true)
{
	global $config;
	$page = explode('.', $name);
	$data = null;
	if ($config[$page[0]])
		$data = $config[$page[0]];
	else {
		$page_id = get_id_by_slug($page[0]);
		if (function_exists('get_fields'))
			$data = $config[$page[0]] = get_fields($page_id);
	}
	if ($data) {
		$rs = $data;
		foreach ($page as $k => $p)
			if ($k > 0)
				$rs = $rs[$p];

		if (!$echo)
			return $rs;
		echo $rs;
	}
}

function config_image($name)
{
	$image = config($name, false);
	if ($image) {
		return [
			'url' => $image['url'],
			'alt' => $image['alt'] ? $image['alt'] : $image['name'],
		];
	}
}


