Changeset 12116

Show
Ignore:
Timestamp:
09/11/07 11:54:20 (1 year ago)
Author:
bergie
Message:

Fix NAP in sitemap (it was called in too early phase)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/midcom/de.linkm.sitemap/handler/sitemap.php

    r5624 r12116  
    4343     * @var integer 
    4444     */ 
    45     var $_root_node_id
     45    var $_root_node_id = null
    4646     
    4747    /** 
     
    6262    function _on_initialize() 
    6363    { 
    64         $this->_nap = new midcom_helper_nav(); 
    65          
     64        $this->_request_data['skip_topics'] = $this->_config->get('skip_topics'); 
     65         
     66        $site_root = $_MIDCOM->get_context_data(MIDCOM_CONTEXT_ROOTTOPIC); 
     67        // By default use the site root node 
     68        $this->_root_node_id = $site_root->id; 
     69                     
    6670        $root = $this->_config->get('root_topic'); 
    67         $this->_request_data['skip_topics'] = $this->_config->get('skip_topics'); 
    68         $user_root = ''; 
    69         if(isset($_REQUEST['de_linkm_sitemap_set_root'])) 
    70         { 
    71             $user_root = $_REQUEST['de_linkm_sitemap_set_root']; 
    72         } 
    73         if(isset($_REQUEST['de_linkm_sitemap_set_levels'])) 
     71        if (isset($_REQUEST['de_linkm_sitemap_set_root'])) 
     72        { 
     73            $root = $_REQUEST['de_linkm_sitemap_set_root']; 
     74        } 
     75 
     76        if (!empty($root)) 
     77        { 
     78            // User has specified a root topic to use in component config or request parameter 
     79            $qb = midcom_db_topic::new_query_builder(); 
     80            $qb->add_constraint('guid', '=', $root); 
     81            $qb->add_constraint('up', 'INTREE', $site_root->id); 
     82            $topics = $qb->execute(); 
     83            if (empty($topics)) 
     84            { 
     85                $_MIDCOM->generate_error(MIDCOM_ERRCRIT, "Could not open root topic with GUID {$root}, please check your setup: " . mgd_errstr()); 
     86                // This will exit 
     87            } 
     88                             
     89            $this->_root_node_id = $topics[0]->id; 
     90        } 
     91 
     92        $this->_show_levels = 99; 
     93        if (isset($_REQUEST['de_linkm_sitemap_set_levels'])) 
    7494        { 
    7595            $this->_show_levels = $_REQUEST['de_linkm_sitemap_set_levels']; 
    76         } 
    77         else 
    78         { 
    79             $this->_show_levels = 99; 
    80         } 
    81         if (   ($root != null 
    82                 && $root != '') 
    83             || ($user_root != null 
    84                 && $user_root != '') 
    85             ) 
    86         { 
    87             if (   $user_root != null 
    88                 && $user_root != '') 
    89             { 
    90                 // User has specified a root topic to use by request parameter 
    91                 $this->_root_folder = new midcom_db_topic($user_root); 
    92                 if (!$this->_root_folder) 
    93                 { 
    94                     $_MIDCOM->generate_error(MIDCOM_ERRCRIT, "Could not open root topic with GUID {$user_root} please check your component configuration: " . mgd_errstr()); 
    95                 } 
    96                 // FIXME: Use in_tree constraint with Midgard 1.8 here 
    97                 if (! mgd_is_in_topic_tree($this->_nap->get_root_node(), $this->_root_folder->id)) 
    98                 { 
    99                     $_MIDCOM->generate_error(MIDCOM_ERRCRIT, "The topic with GUID {$user_root} is not within the content tree as indicated by NAP. Check your configuration."); 
    100                 } 
    101                  
    102                 $this->_root_node_id = $this->_root_folder->id; 
    103             } 
    104             else 
    105             { 
    106                 // User has specified a root topic to use in component config 
    107                 $this->_root_folder = new midcom_db_topic($root); 
    108                 if (!$this->_root_folder) 
    109                 { 
    110                     $_MIDCOM->generate_error(MIDCOM_ERRCRIT, "Could not open root topic with GUID {$root} please check your component configuration: " . mgd_errstr()); 
    111                 } 
    112                 // FIXME: Use in_tree constraint with Midgard 1.8 here 
    113                 if (! mgd_is_in_topic_tree($this->_nap->get_root_node(), $this->_root_folder->id)) 
    114                 { 
    115                     $_MIDCOM->generate_error(MIDCOM_ERRCRIT, "The topic with GUID {$root} is not within the content tree as indicated by NAP. Check your configuration."); 
    116                 } 
    117                  
    118                 $this->_root_node_id = $this->_root_folder->id; 
    119             } 
    120         }  
    121         else  
    122         { 
    123             // Use the site root node 
    124             $this->_root_node_id = $this->_nap->get_root_node(); 
    125         } 
    126          
     96        }         
    12797    } 
    12898     
     
    149119    function _show_xml($handler_id, &$data) 
    150120    { 
     121        $this->_nap = new midcom_helper_nav(); 
    151122        midcom_show_style('xml-header'); 
    152123        $this->_get_sitemap($this->_root_node_id); 
     
    271242    function _show_sitemap($handler_id, &$data) 
    272243    { 
     244        $this->_nap = new midcom_helper_nav();     
    273245        $data['depth'] = 0; 
    274246