Marco's Blog

All content personal opinions or work.
en eo

Added support for Zoom in Sitemap module

2005-08-21 2 min read Joomla marco

Easy – peasy! Well, I had enough experience with the Zoom internals when I attempted this. The Mambomap module is an easy to use module for the display of a sitemap. It takes a series of options (which I ignored) and allows you to display all content on your site in an easy-to-use tree.

The only changes required are to the mambomap.html.php file. There, you register a function to handle Zoom (here you would add a hook for an option to display or not the galleries) and one to retrieve and display all galleries. I chose to implement the latter as two functions: one retrieves the galleries, the other recurses into them to build a tree.

It took a long while (about 4h), but then I got the hang of it. Spent most of the time debating with myself how to pass by reference and by value in PHP.

Now for the changes. (Note: you probably want to run mac2unix on the files before looking at them if you are on Linux.)

1. After line 56, (handling of PHPShop) add the lines:

<font size="2"> //if( $this->mambomap_cfg->expand_zoom )<br></br> if( isset($row['component']) && $row['component'] == 'zOOm Media Gallery Admin') {<br></br>     $row['subtree'] = $this->getZoomAlbums($row);<br></br> }<br></br></font>

This registers the function getZoomAlbums as part of the sitemap handling.

2. Somewhere outside a function definition, but inside the class, insert the lines:

<font size="2">    function &recAppendGallery( &$parent, $rows ) {<br></br>        $result = array();<br></br>        foreach($rows as $row) {<br></br>            if ($row['subcat_id'] == $parent['catid']) {<br></br>                $item = array();<br></br>                $item['id']     = $parent['id'];<br></br>                $item['browserNav'] = $parent['browserNav'];<br></br>                $item['prelink']        = $parent['prelink'];<br></br>                $item['link'] = $item['prelink'].'&amp;catid='.$row['catid'];<br></br>                $item['name'] = $row['catname'];<br></br>                $item['parent'] = $parent;<br></br>                $item['catid'] = $row['catid'];<br></br>                $item['subtree'] = $this->recAppendGallery($item, $rows);<br></br>                $result[] = $item;<br></br>            }<br></br>        }<br></br>        return $result;<br></br>    }<br></br>    // Return an array with all galleries in zOOm<br></br>    function &getZoomAlbums( &$parent ) {<br></br>        global $database;<br></br><br></br>        $parent['prelink']      = $parent['link'];<br></br>        $parent['catid'] = 0;<br></br>        $query = "SELECT catid, catname, subcat_id FROM #__zoom WHERE published = '1'";<br></br>        // this translates the '#__' prefix into the real database prefix<br></br>        $database->setQuery( $query );<br></br>        $rows = $database->loadAssocList();<br></br>        return $this->recAppendGallery($parent, $rows);<br></br>    }</font><br></br>

This adds the handling of categories.

Notice how getZoomAlbums first retrieves all published categories, then recurses into the tree built by the responses. Really neat!