[Bugfix] ItemId not calculated correctly

For Joomla! 1.0 Coding related discussions.
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Mon Jan 08, 2007 10:22 am

[Bugfix] ItemId not calculated correctly

Post by rjonker » Mon Mar 12, 2007 7:30 am

According to my findings in this thread I would like to share this part of code. For a more detailed description of the problem please see my original thread. The bug I found affects 1.0.12 (and most probably, 1.0.11 as well).

In index.php (around line 99) a value of 99999999 gets assigned to $Itemid if none is found:

Code: Select all

if ( !$Itemid ) {
// when no Itemid give a default value
	$Itemid = 99999999;
This causes two if statements a couple of lines ahead to be never executed (index.php, around line 111):

Code: Select all

// checking if we can find the Itemid thru the content
if ( $option == 'com_content' && $Itemid === 0 ) {
	$id 	= intval( mosGetParam( $_REQUEST, 'id', 0 ) );
	$Itemid = $mainframe->getItemid( $id );

/** do we have a valid Itemid yet?? */
if ( $Itemid === 0 ) {
	/** Nope, just use the homepage then. */
	$query = "SELECT id"
	. "\n FROM #__menu"
	. "\n WHERE menutype = 'mainmenu'"
	. "\n AND published = 1"
	. "\n ORDER BY parent, ordering"
	$database->setQuery( $query, 0, 1 );
	$Itemid = $database->loadResult();
Because these if conditions never return true the inner code is unreachable. I haven't investigated the impact of this on the rest of the code. What I do know is that it caused the problem in my thread here.

The solution to this is simple. Just move the first snippet of code to below the second if condition (I moved it to line 127). This causes the $Itemid to be set correctly and solve my problem (and maybe/probably other problems as well).

I hope I described this clearly. If needed, I can provide a diff file.

Best regards,
Robert Jonker
Last edited by rjonker on Mon Mar 12, 2007 7:32 am, edited 1 time in total.

User avatar
Joomla! Master
Joomla! Master
Posts: 15745
Joined: Thu Aug 18, 2005 10:41 am

Re: [Bugfix] ItemId not calculated correctly

Post by Robin » Mon Mar 12, 2007 1:15 pm

[Q&T Note] Also linking to Q&T forum, see http://forum.joomla.org/index.php/topic,149558.0.html


Return to “Joomla! 1.0 Coding”