| 57 | | function _handler_sitemap($handler_id, $args, &$data) |
|---|
| 58 | | { |
|---|
| 59 | | $root = $this->_config->get('root_topic'); |
|---|
| 60 | | if ( $root != null |
|---|
| 61 | | && $root != '') |
|---|
| 62 | | { |
|---|
| 63 | | // User has specified a root topic to use |
|---|
| 64 | | $topic = new midcom_db_topic($root); |
|---|
| 65 | | if (!$topic) |
|---|
| 66 | | { |
|---|
| 67 | | $_MIDCOM->generate_error(MIDCOM_ERRCRIT, "Could not open root topic with GUID {$root} please check your component configuration: " . mgd_errstr()); |
|---|
| 68 | | } |
|---|
| 69 | | // FIXME: Use in_tree constraint with Midgard 1.8 here |
|---|
| 70 | | if (! mgd_is_in_topic_tree($this->_nav->get_root_node(), $topic->id)) |
|---|
| 71 | | { |
|---|
| 72 | | $_MIDCOM->generate_error(MIDCOM_ERRCRIT, "The topic with GUID {$root} is not within the content tree as indicated by NAP. Check your configuration."); |
|---|
| 73 | | } |
|---|
| 74 | | |
|---|
| 75 | | $this->_root_node_id = $topic->id; |
|---|
| 76 | | } |
|---|
| 77 | | else |
|---|
| 78 | | { |
|---|
| 79 | | // Use the site root node |
|---|
| 80 | | $this->_root_node_id = $this->_nav->get_root_node(); |
|---|
| 81 | | } |
|---|
| 82 | | |
|---|
| 83 | | $data['view_title'] = $this->_topic->extra; |
|---|
| 84 | | $_MIDCOM->set_pagetitle($data['view_title']); |
|---|
| 85 | | |
|---|
| 86 | | if ( $this->_topic->can_do('midgard:update') |
|---|
| 87 | | && $this->_topic->can_do('midcom:component_config')) |
|---|
| 88 | | { |
|---|
| 89 | | $this->_node_toolbar->add_item(Array( |
|---|
| 90 | | MIDCOM_TOOLBAR_URL => 'config.html', |
|---|
| 91 | | MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('component configuration'), |
|---|
| 92 | | MIDCOM_TOOLBAR_HELPTEXT => $this->_l10n_midcom->get('component configuration helptext'), |
|---|
| 93 | | MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/stock_folder-properties.png', |
|---|
| 94 | | )); |
|---|
| 95 | | } |
|---|
| 96 | | |
|---|
| 97 | | return true; |
|---|
| 98 | | } |
|---|
| 99 | | |
|---|
| 100 | | function _show_sitemap($handler_id, &$data) |
|---|
| 101 | | { |
|---|
| 102 | | $data['depth'] = 0; |
|---|
| 103 | | |
|---|
| 104 | | midcom_show_style('begin-sitemap'); |
|---|
| 105 | | midcom_show_style('enter-level'); |
|---|
| 106 | | |
|---|
| 107 | | if ($this->_config->get('display_root')) |
|---|
| 108 | | { |
|---|
| 109 | | if (!$this->_show_node($this->_root_node_id, $data)) |
|---|
| 110 | | { |
|---|
| 111 | | $_MIDCOM->generate_error(MIDCOM_ERRCRIT, "An error occured: de_linkm_sitemap_viewer::_show_node({$this->_root_node_id}) returned false. Aborting."); |
|---|
| 112 | | } |
|---|
| 113 | | } |
|---|
| 114 | | else |
|---|
| 115 | | { |
|---|
| 116 | | $subnodes = $this->_nav->list_nodes($this->_root_node_id); |
|---|
| 117 | | if ($subnodes === false) |
|---|
| 118 | | { |
|---|
| 119 | | $_MIDCOM->generate_error(MIDCOM_ERRCRIT, 'An error occured: de_linkm_sitemap_viewer::show: Could not list root\'s subnodes'); |
|---|
| 120 | | } |
|---|
| 121 | | |
|---|
| 122 | | foreach ($subnodes as $id) |
|---|
| 123 | | { |
|---|
| 124 | | if (!$this->_show_node($id, $data)) |
|---|
| 125 | | { |
|---|
| 126 | | $_MIDCOM->generate_error(MIDCOM_ERRCRIT, "An error occured: de_linkm_sitemap_viewer::_show_node({$id}) returned false. Aborting."); |
|---|
| 127 | | } |
|---|
| 128 | | } |
|---|
| 129 | | |
|---|
| 130 | | } |
|---|
| 131 | | |
|---|
| 132 | | midcom_show_style('leave-level'); |
|---|
| 133 | | midcom_show_style('end-sitemap'); |
|---|
| 134 | | } |
|---|
| 135 | | |
|---|
| 136 | | function _show_node($nodeid, &$data) |
|---|
| 137 | | { |
|---|
| 138 | | // Load the node |
|---|
| 139 | | $previous = $this->_current_node; |
|---|
| 140 | | $this->_current_node = $this->_nav->get_node($nodeid); |
|---|
| 141 | | |
|---|
| 142 | | // Start a new node and display it |
|---|
| 143 | | $data['node'] = $this->_current_node; |
|---|
| 144 | | midcom_show_style('node-start'); |
|---|
| 145 | | midcom_show_style('node'); |
|---|
| 146 | | |
|---|
| 147 | | // Try to load Child elements |
|---|
| 148 | | $subnodes = $this->_nav->list_nodes($nodeid); |
|---|
| 149 | | $leaves = null; |
|---|
| 150 | | if ($subnodes === false) |
|---|
| 151 | | { |
|---|
| 152 | | midcom_show_style('node-end'); |
|---|
| 153 | | return false; |
|---|
| 154 | | } |
|---|
| 155 | | if ($this->_config->get('hide_leaves') == false) |
|---|
| 156 | | { |
|---|
| 157 | | $leaves = $this->_nav->list_leaves($nodeid, $data); |
|---|
| 158 | | if ($leaves === false) |
|---|
| 159 | | { |
|---|
| 160 | | midcom_show_style('node-end'); |
|---|
| 161 | | return false; |
|---|
| 162 | | } |
|---|
| 163 | | } |
|---|
| 164 | | |
|---|
| 165 | | // Now display all subnodes and the leaves in the right order |
|---|
| 166 | | if ($this->_config->get('leaves_first')) |
|---|
| 167 | | { |
|---|
| 168 | | if (! $this->_show_leaves($leaves, $data)) |
|---|
| 169 | | { |
|---|
| 170 | | midcom_show_style('node-end'); |
|---|
| 171 | | return false; |
|---|
| 172 | | } |
|---|
| 173 | | |
|---|
| 174 | | if (!$this->_show_subnodes($subnodes, $data)) |
|---|
| 175 | | { |
|---|
| 176 | | midcom_show_style('node-end'); |
|---|
| 177 | | return false; |
|---|
| 178 | | } |
|---|
| 179 | | } |
|---|
| 180 | | else |
|---|
| 181 | | { |
|---|
| 182 | | if (! $this->_show_subnodes($subnodes, $data)) |
|---|
| 183 | | { |
|---|
| 184 | | midcom_show_style('node-end'); |
|---|
| 185 | | return false; |
|---|
| 186 | | } |
|---|
| 187 | | |
|---|
| 188 | | if (! $this->_show_leaves($leaves, $data)) |
|---|
| 189 | | { |
|---|
| 190 | | midcom_show_style('node-end'); |
|---|
| 191 | | return false; |
|---|
| 192 | | } |
|---|
| 193 | | } |
|---|
| 194 | | |
|---|
| 195 | | // Close current node |
|---|
| 196 | | midcom_show_style('node-end'); |
|---|
| 197 | | |
|---|
| 198 | | // Clean up |
|---|
| 199 | | $this->_current_node = $previous; |
|---|
| 200 | | |
|---|
| 201 | | return true; |
|---|
| 202 | | } |
|---|
| 203 | | |
|---|
| 204 | | function _show_leaves($leaves, &$data) |
|---|
| 205 | | { |
|---|
| 206 | | if (is_null($leaves)) |
|---|
| 207 | | { |
|---|
| 208 | | // hide_leaves seems to be set. |
|---|
| 209 | | return true; |
|---|
| 210 | | } |
|---|
| 211 | | |
|---|
| 212 | | if (count($leaves) > 0) |
|---|
| 213 | | { |
|---|
| 214 | | // Begin leaves listing |
|---|
| 215 | | midcom_show_style('begin-leaves'); |
|---|
| 216 | | |
|---|
| 217 | | // Iterate over the leaves and display them |
|---|
| 218 | | foreach ($leaves as $id) |
|---|
| 219 | | { |
|---|
| 220 | | $data['leaf'] = $this->_nav->get_leaf($id); |
|---|
| 221 | | if ( $this->_config->get('hide_index_articles') |
|---|
| 222 | | && $data['leaf'][MIDCOM_NAV_URL] == '') |
|---|
| 223 | | { |
|---|
| 224 | | // This is an index article, skip |
|---|
| 225 | | continue; |
|---|
| 226 | | } |
|---|
| 227 | | |
|---|
| 228 | | midcom_show_style('leaf'); |
|---|
| 229 | | } |
|---|
| 230 | | |
|---|
| 231 | | // End leaves listing |
|---|
| 232 | | midcom_show_style('end-leaves'); |
|---|
| 233 | | } |
|---|
| 234 | | |
|---|
| 235 | | return true; |
|---|
| 236 | | } |
|---|
| 237 | | |
|---|
| 238 | | function _show_subnodes($subnodes, &$data) |
|---|
| 239 | | { |
|---|
| 240 | | if (count($subnodes) > 0) |
|---|
| 241 | | { |
|---|
| 242 | | // First we have to decend a level for the subnode-listing |
|---|
| 243 | | $data['depth']++; |
|---|
| 244 | | |
|---|
| 245 | | midcom_show_style('enter-level'); |
|---|
| 246 | | |
|---|
| 247 | | // Iterate over the nodes and display them |
|---|
| 248 | | foreach ($subnodes as $id) |
|---|
| 249 | | { |
|---|
| 250 | | if (!$this->_show_node($id, $data)) |
|---|
| 251 | | { |
|---|
| 252 | | $data['depth']--; |
|---|
| 253 | | midcom_show_style('leave-level'); |
|---|
| 254 | | return false; |
|---|
| 255 | | } |
|---|
| 256 | | } |
|---|
| 257 | | |
|---|
| 258 | | // Finally we have to ascend back up to the previous level |
|---|
| 259 | | midcom_show_style('leave-level'); |
|---|
| 260 | | |
|---|
| 261 | | $data['depth']--; |
|---|
| 262 | | } |
|---|
| 263 | | |
|---|
| 264 | | return true; |
|---|
| 265 | | } |
|---|
| 266 | | |
|---|
| | 67 | /** |
|---|
| | 68 | * Get the list of root nodes |
|---|
| | 69 | * |
|---|
| | 70 | * @access static public |
|---|
| | 71 | */ |
|---|