Thread: Changing URLs
View Single Post
Old 24.05.2005, 19:25   #4 (permalink)
GRAM
Senior Mamber
 
GRAM's Avatar
 
Join Date: Aug 2004
Location: Southern California
Posts: 131
GRAM has a spectacular aura about
Default Re: Changing URLs

harshad,

Sorry for the long post, its a deep issue.

That last number on your url's is an Itemid, which mambo uses to set display parameters and access permissions for the content item. It has nothing to do with selecting what item to display.

If your url that goes to that content item does not have an Itemid on the command line, mambo will assign one based on a best guess method, or it will use the Itemid for the first item on your main_menu (usually the front_page component). This only applies to url's that do not have that last number in them.

Unfortunately, the solution is not contained in just one section of code. You may need to look into hacking the code for each module that creates a url that references a content item. To reduce query times, most modules do not look for indiviual menu entries for content items, they look for section or category menuitems instead. The solution will depend upon the method you employ to access that content item. In most cases mambo will assign the Itemid from the primary menu pick (the section list or content category) to your content item's url.

You could start by reducing the number of access methods you employ for getting to that content item (singular menu item for that section, or that category) to reduce the number of Itemids that could be attached to a singular content item.

The next thing you may need to tackle will be your modules (most popular, latest etc..). Here's a sample of the code from the 'most read' module that came with 4.5.1b:

PHP Code:
// needed to reduce queries used by getItemid
$bs $mainframe->getBlogSectionCount();
$bc $mainframe->getBlogCategoryCount();
$gbs $mainframe->getGlobalBlogSectionCount();
echo 
'<ul>';
foreach (
$rows as $row) {
        
$Itemid $mainframe->getItemid$row->id00$bs$bc$gbs );
        
// Blank itemid checker for SEF
        
if ($Itemid == NULL) {
                
$Itemid "";
        } else {
                
$Itemid "&amp;Itemid=".$Itemid;
        }
        echo 
'<li><a href="' .sefRelToAbs'index.php?option=com_content&amp;task=view&amp;id='$row->id $Itemid ) .'">'$row->title .'</a></li>';
}
echo 
'</ul>'
And here's some sampl code from mainframe->getItemid:

PHP Code:
                if ($_Itemid == '' && $bc) {
                        
// Search in specific blog category
                        
$this->_db->setQuery"SELECT m.id "
                        
."\nFROM #__content AS i"
                        
."\nLEFT JOIN #__categories AS c ON i.catid=c.id"
                        
."\nLEFT JOIN #__menu AS m ON m.componentid=c.id "
                        
."\nWHERE m.type='content_blog_category' AND m.published='1' AND i.id=".$id );
                        
$_Itemid $this->_db->loadResult();
                } 
The code has several sections just like this one, each of which attempts to identify a menu item (see WHERE statement: m.type=, this will exclude anything that does not have a correlating entry in the mos_menu table) that correlates to either that item specifically, or a content section or category that that contains the content item. It executes each section (like the one above) in turn until it finds a valid Itemid, then it returns the Itemid it finds.

mainframe->getItemid first checks for a typed item menu entry that correlates to the item, then for a linked content item (the mod_mostread.php files disables both of these), then it will check to see if the content item is included in a section that is in one of your menus.

If it can't find a menu entry that correlates to either the section for that item, or the category for the item, it will return the current page's url to be used by the mostread module (or whatever routine or script called it). The mostread module will use what it gets back from mainframe->getItemid, and append it onto the url for that item.

It would be complicated to fix, due to the number of scripts (modules) in Mambo that can create a url for a content item. Fortunately most will use this mainframe routine, so you may be able to resolve this by planning around that function for the most part.

Here's a couple of options:

Use a consistant menu linking strategy:

Ensure that each content item has a singular content section path through your menus (each content section should have only one menuentry - not for example both blog AND table entries), and be sure that that menuitem is a content section. If you don't want to have an actual menu entry displayed for that section, create it in a new menu (has to be published) that is displayed in a non used module position.

Category and content_item menu links will have their own Itemids that correlate to their menuitem numbers (thus complicating your problem). You can sompensate for this as follows:

Change any category menu item to a url instead of using mambo's category menu options, and make the url whatever you get in your broswer bar when you go to that category from the primary section menu item (for example click on your section menu item, than select the category you want to make a menuitem for, then copy the url you end up on into your new url menu entry for that category). This new url should have the same Itemid that the section menu item had.

For individual menuitems for content_items within that content section, you would need to change their menu entry types to url as well. Use the same methodology you would use for a category section to get the appropriate url.

The drawback to this approach is lack of control over singular content item displays. Mambo will use the display parameters for that content section since you are using its Itemid.

Or hack your modules (more work to maintain):

You could modify the call to mainframe->getItemid in the mostread module (or whichever module you want to affect) and set it to check for individual item entries in your mos_menu table for content items (it does not do this to reduce query time for each link it creates). Change this line in /modules/mod_mostread.php:

PHP Code:
        $Itemid $mainframe->getItemid$row->id00$bs$bc$gbs ); 
To this:

PHP Code:
        $Itemid $mainframe->getItemid$row->id01$bs$bc$gbs ); 
The third parameter in the mainframe->getItemid function tells this function to look for individual content item entries in your mos_menu table that match this content item.

Next create a phony published menu (set to an unused module position) and create menu items for every content item you want to have a sticky consistant Itemid for that do not already have menu entries in any of your other menus. This would be a pain in the butt to maintain as you would have to create correlating menu items for every content item you want to affect.

It would also slow page rendering very slightly as the affected modules would now be doing one more query per url they create.

This would provide for control over the display of individual pages using the individual menu entrys (Itemid) for each item.

OR do both, and only create phony menu entries for content items that need special handling at display time.

Good luck, it will require some consistant methodology to resolve, but you should be able to do it
__________________
GRAM

Road Star Clinic / MLSHomeQuest.com
GRAM is offline   Reply With Quote