If you are using the googleSearch component / module with sh404SEF, and you encounter the following error:
JFolder::folder: Path is not a folder: /languageThis article shows you how to fix this error.
Note: Special thanks to Fernando for his help and patience in sending me an entire Joomla setup that replicates the error, in getting the bug fixed, and in testing the final solution.
If you are interested, you can also see the entire thread of discussions started by lightningbit here.
Solution
There are two things you need to do to run googleSearch with sh404SEF:
- Make sh404SEF skip the googleSearch component
- Change one line in the sh404SEF code
- First, log in as Administrator.
- Go to Components - sh404SEF, and click "sh404SEF configuration".
- Now click the tab "by component".
- For the component "googleSearch", in column 1, change it from "(use default handler)" to "skip".
- Don't forget to click the "Save" button in the top right-hand corner. Note that it will ask you:
"Do you want to clear the URL cache? This is highly recommended after changing configuration. To generate again the cache, you should browse again your homepage, or better: generate a sitemap for your site."
Click OK only if you're sure about this.
- Open the file sh404sef.class.php in the folder "administrator/components/com_sh404sef"
- Around line 2171, replace the highlighted line
- Save the file.
function shGetFrontEndActiveLanguages() {
$shLangs = array();
// Initialize some variables
$client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int'));
with the following:
function shGetFrontEndActiveLanguages() { $shLangs = array(); // Initialize some variables if (preg_match('/com_googlesearch/', JRequest::getVar('option', ''))) { $client =& JApplicationHelper::getClientInfo(JFactory::getApplication()->getClientId()); } else { $client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int')); }
Once you have done (A) and (B), your googleSearch should be able to work with sh404SEF.
Explanation of the Bug
If you're interested, here's an explanation of the bug - how and why it occurs.
- The bug seems to occur in only Joomla 1.5 and above.
- If you're familiar with Google Adsense Search, your Google Adsense ID is passed to Google with the URL parameter client.
- Internally in Joomla 1.5, there is also a "client identifier" with the value 0, 1, 2 or 3. If you're interested, you can get a more detailed explanation about this client identifier in the file:
libraries/joomla/application/helper.php
, class JApplicationHelper, function &getClientInfo(). - If you take a look at the original function in
administrator/components/com_sh404sef/sh404sef.class.php
to retrieve the client identifier as highlighted above:
function shGetFrontEndActiveLanguages() {
$shLangs = array();
// Initialize some variables
$client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int'));
The first parameter is the parameter name 'client'. The second is the default value, which is '0'. The third is '', which in this case refers to $_REQUEST
. The last is the data type, which is 'int'.
Because of the third parameter '' which refers to $_REQUEST
, if you've specified your Google Adsense ID, the highlighted line above will read your Google Adsense ID and returned it as the client identifier. Note: this is the main reason why the error disappears if you did not specify your Google Adsense ID.
The last parameter 'int' will force your Google Sense ID (e.g. pub-1234567812345678 which is an alphanumeric value) to be converted to an integer, which usually results in a large negative integer value. However, in Joomla, the client identifier can only have the value 0, 1, 2 or 3.
As a result of the above, JApplicationHelper::getClientInfo() doesn't return a valid ClientInfo class.
And the following line
$path = JLanguage::getLanguagePath($client->path);
causes the infamous error
JFolder::folder: Path is not a folder: /languageJFactory::getApplication()->getClientId()
with a valid client identifier, I can proceed to retrieve a valid ClientInfo class:
$client =& JApplicationHelper::getClientInfo(JFactory::getApplication()->getClientId());
Of course, we'll only do this if we're running googleSearch. Hence the conditional statement:
if (JRequest::getVar('option', '')=='com_googlesearch') {
function shGetFrontEndActiveLanguages() { $shLangs = array(); // Initialize some variables if (preg_match('/com_googlesearch/', JRequest::getVar('option', ''))) {) { $client =& JApplicationHelper::getClientInfo(JFactory::getApplication()->getClientId()); } else { $client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int')); }
Comments
$client =& JApplicationHelper::getClientInfo(JFactory::getApp lication()->getClientId());
} else {
$client =& JApplicationHelper::getClientInfo(JRequest::getVar ('client', '0', '', 'int'));
}
RSS feed for comments to this post