Exemplo n.º 1
0
/**
 * Creates XML structure with all modules wich can respond to "p_id" parameter in _GET (such as content and menus in catalog mode)
 *
 * @param array $options XML options:
 *                       root (string) : root node name
 *                       use (array)   : modules to scan (items or "*")
 *                       skip (array)  : filter array with modules names to use
 * @return DOMDocument
 */
function aliasCatchersAsXML($options = array('root' => 'alias-catchers', 'use' => array('*'), 'skip' => array()))
{
    $xml = new DOMDOcument('1.0', 'utf-8');
    $root_node_name = get_array_value($options, 'root', 'alias-catchers');
    $xml->appendChild($root_node = $xml->createElement($root_node_name));
    $skip_modules = get_array_value($options, 'skip', array());
    $use_modules = get_array_value($options, 'skip', array('*'));
    // content module
    if ((in_array('*', $use_modules) || in_array('content', $use_modules)) && !in_array('content', $skip_modules)) {
        if (($content_config_ok = module_get_config('content', $content_config)) && ($pages_table = get_array_value($content_config['config'], 'table', false, REGEXP_IDENTIFIER)) != false) {
            $root_node->appendChild($module_node = $xml->createElement('module'))->setAttribute('name', 'Страницы');
            $query = CMS::$DB->query("select alias, title from `{$pages_table}` order by title");
            while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
                $module_node->appendChild($catcher_node = $xml->createElement('catcher'));
                $catcher_node->appendChild($xml->createElement('title'))->nodeValue = $row['title'];
                $catcher_node->appendChild($xml->createElement('alias'))->nodeValue = $row['alias'];
            }
        }
    }
    // menu module
    if ((in_array('*', $use_modules) || in_array('menu', $use_modules)) && !in_array('menu', $skip_modules)) {
        if ($menu_config_ok = module_get_config('menu', $menu_config)) {
            $root_node->appendChild($module_node = $xml->createElement('module'))->setAttribute('name', 'Каталоги');
            if (($menu_table = get_array_value($menu_config['config'], 'table_menu', false, REGEXP_IDENTIFIER)) != false) {
                $query = CMS::$DB->query("select alias, caption from `{$menu_table}` where alias > ''order by caption");
                while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
                    $module_node->appendChild($catcher_node = $xml->createElement('catcher'));
                    $catcher_node->appendChild($xml->createElement('title'))->nodeValue = $row['caption'];
                    $catcher_node->appendChild($xml->createElement('alias'))->nodeValue = $row['alias'];
                }
            }
        }
    }
    return $xml;
}