CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Itemid in Joomla installs
Pages: [1]

Author Topic: Itemid in Joomla installs  (Read 11834 times)

lcdweb

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1620
  • Karma: 116
    • www.lcdservices.biz
  • CiviCRM version: many versions...
  • CMS version: Joomla/Drupal
  • MySQL version: 5.1+
  • PHP version: 5.2+
Itemid in Joomla installs
February 04, 2009, 12:01:07 pm
In Joomla, when you create a menu item, the system assigns a unique "Itemid" to the menu item, which shows up as a url variable. The value is important, as you can assign different site templates based on the menu item, and the Itemid is the mechanism used for distinguishing the page.

CiviCRM pages assigned to a menu item lose the Itemid url var when subsequent pages are accessed. The case I ran into was a profile search page. Once you click search, the Itemid is lost (which in the template assignment scenario, means the page reverts to the default template).

Form submission buttons are a little tricky to trace (finding the redirection url) as they are built dynamically with several variable options. For search pages, it looks like the page is called again (action = refresh) to display the result list. And it looks like: CRM/Core/Quickform/Action/Refresh.php is what builds that particular piece. I'm trying to insert the Itemid through that function, but haven't been able to figure it out.

Any tips on a better way to attack this? In the long term, it would be good to standardize inclusion of the Itemid in all pages when working with a Joomla install.
support CiviCRM through 'make it happen' initiatives!
http://civicrm.org/mih

nascent

  • I’m new here
  • *
  • Posts: 14
  • Karma: 3
  • CiviCRM version: 3.3
  • CMS version: Joomla 1.5
  • MySQL version: 5.0
  • PHP version: 5.2
Re: Itemid in Joomla installs
August 02, 2010, 06:54:38 am
I know this is an old thread, but having trawled for the answer and not found it, I set to work to find an answer and here's what works for me...

Open the Joomla.php file at ...\administrator\components\com_civicrm\civicrm\CRM\Utils\System\ in your favourite text editor.
Find line 171
Code: [Select]
function url($path = null, $query = null, $absolute = true,Add at line 175
Code: [Select]
$Itemid    = JRequest::getVar("Itemid");Replace lines 194 to 198 with
Code: [Select]
if ( isset( $query ) ) {
            $url = JRoute::_( "{$base}{$script}?option=com_civicrm{$separator}task={$path}{$separator}{$query}{$fragment}&Itemid=$Itemid" );
        } else {
            $url = JRoute::_( "{$base}{$script}?option=com_civicrm{$separator}task={$path}{$separator}{$fragment}&Itemid=$Itemid" );
        }

Hope this works for you too.

cheers,
n.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Itemid in Joomla installs
August 02, 2010, 09:31:46 am

ahh, seems like a very nice clean solution

lcdweb: any comments. if you agree, can we please file and issue and we'll integrate this patch into 3.2.1

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

nascent

  • I’m new here
  • *
  • Posts: 14
  • Karma: 3
  • CiviCRM version: 3.3
  • CMS version: Joomla 1.5
  • MySQL version: 5.0
  • PHP version: 5.2
Re: Itemid in Joomla installs
August 02, 2010, 12:21:39 pm
Thanks lobo.
It needs a little modification as the script above puts the administrator into a loop. Basically it needs to only apply the Itemid in the frontend.
This works better and someone more familiar than I might be able to refine it further.

Code: [Select]
if ($script == "index.php") {
        if ( isset( $query ) ) {
            $url = JRoute::_( "{$base}{$script}?option=com_civicrm{$separator}task={$path}{$separator}{$query}{$fragment}&Itemid=$Itemid" );
        } else {
            $url = JRoute::_( "{$base}{$script}?option=com_civicrm{$separator}task={$path}{$separator}{$fragment}" );
        }
} else {
if ( isset( $query ) ) {
            $url = JRoute::_( "{$base}{$script}?option=com_civicrm{$separator}task={$path}{$separator}{$query}{$fragment}" );
        } else {
            $url = JRoute::_( "{$base}{$script}?option=com_civicrm{$separator}task={$path}{$separator}{$fragment}" );
        }
}

cheers,
n

lcdweb

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1620
  • Karma: 116
    • www.lcdservices.biz
  • CiviCRM version: many versions...
  • CMS version: Joomla/Drupal
  • MySQL version: 5.1+
  • PHP version: 5.2+
Re: Itemid in Joomla installs
August 04, 2010, 07:35:24 am
this is great. we were having a discussion about this recently on another thread.
i've not had a chance to implement and test but will try to do that today or tomorrow.
support CiviCRM through 'make it happen' initiatives!
http://civicrm.org/mih

nascent

  • I’m new here
  • *
  • Posts: 14
  • Karma: 3
  • CiviCRM version: 3.3
  • CMS version: Joomla 1.5
  • MySQL version: 5.0
  • PHP version: 5.2
Re: Itemid in Joomla installs
August 13, 2010, 05:45:25 am
Still working on getting this working correctly :)

It needs the "&Itemid=$Itemid" on both the urls for the frontend, otherwise when you click on 'continue' on any of the forms, you lose the itemid in the url.

Code: [Select]
if ($script == "index.php") {
        if ( isset( $query ) ) {
            $url = JRoute::_( "{$base}{$script}?option=com_civicrm{$separator}task={$path}{$separator}{$query}{$fragment}&Itemid=$Itemid" );
        } else {
            $url = JRoute::_( "{$base}{$script}?option=com_civicrm{$separator}task={$path}{$separator}{$fragment}&Itemid=$Itemid" );
        }
} else {
if ( isset( $query ) ) {
            $url = JRoute::_( "{$base}{$script}?option=com_civicrm{$separator}task={$path}{$separator}{$query}{$fragment}" );
        } else {
            $url = JRoute::_( "{$base}{$script}?option=com_civicrm{$separator}task={$path}{$separator}{$fragment}" );
        }
}

cheers,
n

bizzynate

  • I’m new here
  • *
  • Posts: 9
  • Karma: 0
Re: Itemid in Joomla installs
February 14, 2011, 02:31:47 pm
Hey folks, just bumping this topic. Is this something slated for 3.4/4.x? I didn't see it in 3.3 and it is a really important thing to get right for Joomla. Especially if it's designed to leverage Joomla 1.6's template layouts—which (among many other things in Joomla) rely on the Itemid variable to function properly.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Itemid in Joomla installs
February 14, 2011, 02:39:02 pm

not on the list for 3.4 / 4.0

i'd recommend you work with brian s (lcdweb) and/or elin w and try to get a patch in for 3.4 (J1.5) and 4.0 (J1.6).

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

lcdweb

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1620
  • Karma: 116
    • www.lcdservices.biz
  • CiviCRM version: many versions...
  • CMS version: Joomla/Drupal
  • MySQL version: 5.1+
  • PHP version: 5.2+
Re: Itemid in Joomla installs
March 06, 2011, 03:37:51 pm
we got this fixed at CiviCon/code sprint   8)

patch is here: http://issues.civicrm.org/jira/browse/CRM-7720
it will be included in 3.4/4.0

it's based on the above, but also addresses issues where the reset=1 set in the menu params could override the form process and screw things up.

we don't use joomla's component router methods, so SEF urls are only respected for the first menu item. thereafter it reverts to normal urls. but the itemid is passed through that process, so even with SEF enabled we retain the menu item reference.

i looked into feeding things through the component router, but it's considerably more involved given how civi constructs and manages urls.

would be great if one of you can apply the patch and confirm it works as expected
support CiviCRM through 'make it happen' initiatives!
http://civicrm.org/mih

nascent

  • I’m new here
  • *
  • Posts: 14
  • Karma: 3
  • CiviCRM version: 3.3
  • CMS version: Joomla 1.5
  • MySQL version: 5.0
  • PHP version: 5.2
Re: Itemid in Joomla installs
March 07, 2011, 05:33:23 am
Fabulous! Absolutely delighted there is a proper fix for this.

Just one small thing I found when I applied the patch just now...

In Joompla.php

Code: [Select]
if ( JRequest::getVar("Itemid") ) $Itemid = 'Itemid='.JRequest::getVar("Itemid");
should be

Code: [Select]
if ( JRequest::getVar("Itemid") ) $Itemid = '&Itemid='.JRequest::getVar("Itemid");
It was missing the ampersand before Itemid. ;)

cheers, n.


« Last Edit: March 07, 2011, 05:35:00 am by nascent »

nascent

  • I’m new here
  • *
  • Posts: 14
  • Karma: 3
  • CiviCRM version: 3.3
  • CMS version: Joomla 1.5
  • MySQL version: 5.0
  • PHP version: 5.2
Re: Itemid in Joomla installs
April 19, 2011, 01:56:50 pm
Hi guys,
Found another small issue with this that came to light using CiviEvents.

In joomla.php (lines 210-214) I needed to change this...
Code: [Select]
        // gross hack for joomla, we are in the backend and want to send a frontend url
        if ( $frontend &&
             $config->userFramework == 'Joomla' ) {
            $url = str_replace( '/administrator/index2.php', '/index.php', $url );
        }

to this...

Code: [Select]
  // gross hack for joomla, we are in the backend and want to send a frontend url
         if ( $config->userFrameworkFrontend &&
              $config->userFramework == 'Joomla' ) {
            $url = str_replace( '/administrator', '', $url );
        }

cheers, n.

lcdweb

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1620
  • Karma: 116
    • www.lcdservices.biz
  • CiviCRM version: many versions...
  • CMS version: Joomla/Drupal
  • MySQL version: 5.1+
  • PHP version: 5.2+
Re: Itemid in Joomla installs
April 19, 2011, 02:15:45 pm
i don't think we want to do that. the index2 needs to be switch to index.php
what errors or odd behaviors were you getting?
support CiviCRM through 'make it happen' initiatives!
http://civicrm.org/mih

lcdweb

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1620
  • Karma: 116
    • www.lcdservices.biz
  • CiviCRM version: many versions...
  • CMS version: Joomla/Drupal
  • MySQL version: 5.1+
  • PHP version: 5.2+
Re: Itemid in Joomla installs
April 19, 2011, 09:02:03 pm
looked into this some more --

in v3.4 we need to keep the string replacement as is
in v4.0 your modification should be implemented

or we could just add both replacements to cover both version. i'll file an issue
support CiviCRM through 'make it happen' initiatives!
http://civicrm.org/mih

nascent

  • I’m new here
  • *
  • Posts: 14
  • Karma: 3
  • CiviCRM version: 3.3
  • CMS version: Joomla 1.5
  • MySQL version: 5.0
  • PHP version: 5.2
Re: Itemid in Joomla installs
April 19, 2011, 11:02:35 pm
Thanks for looking into it.
Site where this is being used here.
The main issue was that all the event links were coming up with administrator/index.php in them.
As far as I ccould see it wasn't reading the $frontend variable in Joomla.php, so first I took it out and, as expected, that broke the backend. Then I replaced it with $config->userFrameworkFrontend, and at least then it identified that I was in the frontend, but that still didn't change the url. I needed to change the str_replace too.

You're right, it probably needs to cover both index2 and index.

cheers, n.

Jeremy Proffitt

  • I post occasionally
  • **
  • Posts: 63
  • Karma: 2
    • Mobius New Media
  • CiviCRM version: 4.4.x
  • CMS version: Joomla 2.5.x/3.x / D7
  • MySQL version: 5.1.x
  • PHP version: 5.3.10+, 5.4.x
Re: Itemid in Joomla installs
April 02, 2012, 08:23:21 am
Either this patch was not actually included in the 3.4 releases, or the installation process did not correctly update /components/com_civicrm/civicrm.php in the process. I upgraded a client installation that was having the "disappearing Itemid" issue for frontend profiles with SEF from 3.2.5 to 3.4.8 and was still having the problem until I manually applied the patch.

Also, the code should be referencing a JRequest object, rather than directly accessing $_GET, as this would add additional protection against query string attacks.
 
Jeremy Proffitt
Mobius New Media
IRC: JP_EzoD

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Itemid in Joomla installs

This forum was archived on 2017-11-26.