[Solved] Anchor Tags Don't Work with Joomla SEF on

Started by oSa, November 23, 2006, 04:53:28 PM

Previous topic - Next topic

oSa

This time i have a problem when the joomla sef is on.

Joomla: 1.0.11
SMF: 1.1rc3
bridge: 1.1.6
Joomla Core SEF: On
SMF SEF: off

The problem is that links such as last post, PMs and Up/Down don't work as they should. When you click, they take you to the top of the page instead of the exact message/place in the page. I found a few posts related to PMs but the solutions were PMs specific only. I wonder if this can this be solved? Thanks in advance...

Edit: When i manually add #new after the urls, they work. So i think, it must be the missing part in the urls. There must be a way to add it.

Edit after Solution: I've summarized the solutions here:
For Personal Messages # problem: here.
For Up/Down, First Unread Post, and LAtest Post links: here.

oSa

Soryy to bump, but this is an important issue (i know many of the topics are important but i couldn't help myself). It is very annoying to manually scroll down everytime you enter a topic and i can't cancel sef because there are some external links to my site, so it will cause page not found errors. I would appreciate any help. Thanks...


oSa

Forum url: http://www.artifm.net/component/option,com_smf/Itemid,26/lang,tr/

p.s. you can select the english language from top of the page. It will help you on some parts of the forum.

Orstio

Find this in smf.php:

$mainframe->addCustomHeadTag( '<script language="JavaScript" type="text/javascript" src="'. $settings['default_theme_url']. '/script.js?rc2"></script>' );
$mainframe->addCustomHeadTag( '<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
var smf_theme_url = "'. $settings['theme_url']. '";
var smf_images_url = "'. $settings['images_url']. '";
var smf_scripturl = "'. un_htmlspecialchars(mambo_smf_url($scripturl)) . '";
var smf_session_id = "'. $context['session_id'] . '";
// ]]></script>' );


Replace it with this:

$mainframe->addCustomHeadTag( '<script language="JavaScript" type="text/javascript" src="'. $settings['default_theme_url']. '/script.js?fin11"></script>' );
$mainframe->addCustomHeadTag( '<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
var smf_theme_url = "'. $settings['theme_url']. '";
var smf_images_url = "'. $settings['images_url']. '";');
if ($mosConfig_sef=='1')
$mainframe->addCustomHeadTag( ob_mambofix('var smf_scripturl ="'. $scripturl . '";'));
else
$mainframe->addCustomHeadTag( 'var smf_scripturl = "'. un_htmlspecialchars(mambo_smf_url($scripturl)) . '";');

$mainframe->addCustomHeadTag( ' var smf_session_id = "'. $context['session_id'] . '";
// ]]></script>' );

oSa

#5
i've tried this, but it didn't solve the problem. It still goes to top of the page, not to the last message in the topic and the pm links still don't get you to the pm. However, up/down buttons work correctly now.

This is a sample pm link from my forums:
http://www.artifm.net/component/option,com_smf/Itemid,26/action,pm/lang,tr
and this is a sample pm link from smf forums here:
http://www.simplemachines.org/community/index.php?action=pm#37661

As you can see the pm#XXXX part is missing.

This is a sample link to a new post from my forums:
http://www.artifm.net/component/option,com_smf/Itemid,26/topic,94.msg692
and this is from smf forums:
http://www.simplemachines.org/community/index.php?topic=25008.msg530688#new

This time #new is missing.

Also there is a strange problem: the "new" icon links to a message number which doesn't exist in the topic ???


Orstio

And, as for your "new" icon link, it does the same thing on your stand alone forum:

http://www.artifm.net/forum/index.php?board=14.0

It is most likely some bad code in the theme.

oSa

Pm links are solved, thanks. But on my stand alone forum, last post links do have #new at the end of the links. i.e.
http://www.artifm.net/forum/index.php?topic=104.msg735#new
but wrapped forum doesn't have:
http://www.artifm.net/component/option,com_smf/Itemid,26/topic,104.msg735

I suppose this is has nothing to do with the theme?

Orstio

Are you sure this is bridge 1.1.6?

Can you confirm this code is in smf.php?

//Fix for anything previous to Joomla! 1.0.10
if ($_VERSION->PRODUCT != 'Joomla!' || ($_VERSION->PRODUCT == 'Joomla!' && $_VERSION->DEV_LEVEL <= '9'))
$sefurl = substr($sefurl, 0, strpos($sefurl, 'option')) . preg_replace('/(\/)([^,]*)(#)/', '$1$2,$2$3', substr($sefurl, strpos($sefurl, 'option'), strlen($sefurl)));

oSa

#10
Yes, it is 1.1.6. And here is the code you asked directly forum my smf.php
//Fix for anything previous to Joomla! 1.0.10

if ($_VERSION->PRODUCT != 'Joomla!' || ($_VERSION->PRODUCT == 'Joomla!' && $_VERSION->DEV_LEVEL <= '9'))

$sefurl = substr($sefurl, 0, strpos($sefurl, 'option')) . preg_replace('/(\/)([^,]*)(#)/', '$1$2,$2$3', substr($sefurl, strpos($sefurl, 'option'), strlen($sefurl)));


And here is the code for new.gif link from my message.index.template.php
// Is this topic new? (assuming they are logged in!)

if ($topic['new'] && $context['user']['is_logged'])

echo '

<b>';



echo '

', $topic['is_sticky'] ? '<b>' . substr($txt['quick_mod_stickyshort'], 0, 6) . ':</b> ' : '' , '<span id="msg_' . $topic['first_post']['id'] . '" title="', $topic['first_post']['preview'], '">', $topic['first_post']['link'], '</span>';



// Is this topic new? (assuming they are logged in!)

if ($topic['new'] && $context['user']['is_logged'])

echo '

<a href="', $topic['new_href'], '" id="newicon' . $topic['first_post']['id'] . '"><img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="', $txt[302], '" /></b>';


I've compared it with the default one and there isn't a difference other than the substr($txt['quick_mod_stickyshort'], 0, 6) part. Also the link comes from $topic['new_href'] i guess.

oSa

Noooo :'( Both the quote and inline edit functions stopped working after these modifications.

Orstio


oSa

1.0.10 Turkish from joomlaturkiye.org
1.0.11 update from joomla.org i guess. Is there a problem with my Joomla installation?

Orstio

Possibly.

Can you look in the file version.php in your includes folder, and post the values of $DEV_LEVEL and $PRODUCT from that file?

oSa

   var $DEV_LEVEL    = '11';
   var $PRODUCT    = 'Joomla!';

Orstio

I noticed that everything you've quoted from the code is double spaced.  What editor are you using when you make the code changes?

oSa

That's php designer 2006 - beta. But i use CuteFtp to edit the files that are on my site.

Orstio

Strange.

Alright, can you PM me an email address where I can send a file?

oSa


oSa

what was this file supposed to fix? i couldn't see any difference.

Orstio


oSa

#22
Still it doesn't make any difference. With the default smf.php, quote and inline edit works but the #new, #top and #bot are missing at the end of the links. With the other modified smf.phps neither quote & inline edit work nor #s exist.

I must say that up/down links work(they get #s at the end of links) when you go into the topic by clicking topic name, but when you click the new icon and go into the topic #s dissappear and up/down links don't work.

Orstio

Have you ever had any third party SEF engines installed?

In your includes folder there is a file named sef.php.  Can you confirm this code is there:

// check if link contained fragment identifiers (ex. #foo)
$fragment = '';
if ( isset($url['fragment']) ) {
// ensure fragment identifiers are compatible with HTML4
if (preg_match('@^[A-Za-z][A-Za-z0-9:_.-]*$@', $url['fragment'])) {
$fragment = '#'. $url['fragment'];
}
}

oSa

Yes, it is in my sef.php.

I usually try new things on my localhost first and if it works ok then i apply it to my online site.  I remember trying some 3rd party SEF engines before i've read that bridge doesn't work well with them; but i can't be sure if i've installed them to my online site. 

Orstio

What happens if you change it to this?

// check if link contained fragment identifiers (ex. #foo)
$fragment = '';
if ( isset($url['fragment']) ) {
// ensure fragment identifiers are compatible with HTML4
$fragment = '#'. $url['fragment'];
}

oSa

#26
Now we are close i think :) The links become like this, but still takes you to the top of the page:
http://www.artifm.net/component/option,com_smf/Itemid,26/topic,105.msg795#new&lang,tr

&lang,tr part seems problematic ? When i delete that part, everything works ok.

Orstio

Is it Joom!Fish that is generating that lang bit?

oSa

Yes, it's joomfish. And i forgot to say that i've tried my original smf.php not the lastest modified version you've sent me with this last code change. Was i supposed to use that one?

oSa

Sorry if you've read my last post (i've deleted now), i thought i've solved the problem but i was wrong :(

When i try to change manually
http://www.artifm.net/component/option,com_smf/Itemid,26/board,1.0#bot&lang,tr
to
http://www.artifm.net/component/option,com_smf/Itemid,26/board,1.0/lang,tr#bot
the problem is solved temporarily until i click an erroneous "new" icon link.

Orstio

You should be able to find a file named joomfish.html.php.  In that file is a function named _createHRef.

Change that entire function to this:

function _createHRef( $iso ) {
$href= "index.php";
$fragment = substr($_SERVER['QUERY_STRING'], strpos('#', $_SERVER['QUERY_STRING']), strlen($_SERVER['QUERY_STRING']));
$_SERVER['QUERY_STRING'] = substr($_SERVER['QUERY_STRING'],0,strpos('#', $_SERVER['QUERY_STRING']));
$vars = explode( "&", $_SERVER['QUERY_STRING'] );
$hrefVars = '';
if( count($vars) > 0 && $_SERVER['QUERY_STRING']) {
foreach ($vars as $var) {
if( eregi('=', $var ) ) {
list($key, $value) = explode( "=", $var);
if( $key != "lang" ) {
if( $hrefVars != "" ) $hrefVars .= "&";
$hrefVars .= "$key=$value";
}
}
}
}

if( $iso != null ) {
if( $hrefVars != "" ) $hrefVars .= "&";
$hrefVars .= "lang=$iso";
}

if( $hrefVars != "" ) {
$href .= "?$hrefVars".$fragment;
}
return sefRelToAbs( $href );
}

oSa

#31
I have changed that function, probably you have tested yourself on my site: it doesn't make any difference, still &lang,tr at the end.

It seems that only the first unread post(new icon) and latest post links have this problem.

Orstio

Sorry, had some things backwards.   ::)

function _createHRef( $iso ) {
$href= "index.php";
$fragment = substr($_SERVER['QUERY_STRING'], strpos($_SERVER['QUERY_STRING'], '#'), strlen($_SERVER['QUERY_STRING']));
$_SERVER['QUERY_STRING'] = substr($_SERVER['QUERY_STRING'],0,strpos($_SERVER['QUERY_STRING']), '#');
$vars = explode( "&", $_SERVER['QUERY_STRING'] );
$hrefVars = '';
if( count($vars) > 0 && $_SERVER['QUERY_STRING']) {
foreach ($vars as $var) {
if( eregi('=', $var ) ) {
list($key, $value) = explode( "=", $var);
if( $key != "lang" ) {
if( $hrefVars != "" ) $hrefVars .= "&";
$hrefVars .= "$key=$value";
}
}
}
}

if( $iso != null ) {
if( $hrefVars != "" ) $hrefVars .= "&";
$hrefVars .= "lang=$iso";
}

if( $hrefVars != "" ) {
$href .= "?$hrefVars".$fragment;
}
return sefRelToAbs( $href );
}

oSa

Sorry, no change. Do you think it will be better if i give up on sef :)

Orstio

You'll have the same problem without SEF.

For some reason, Joom!Fish is adding the "&lang=tr" part to the end of the URL, even if it has a fragment anchor.  What it needs to do is add that beforethe fragment, not after.

oSa

But it doesn't add &lang=tr when sef is off ??? so it works ok. If the same thing is possible with sef on, then the problem can be solved ???

Orstio

In your sef.php, is there anything added, along the lines of '&lang=' ?  I would look particularly in the sefReltoAbs function.

oSa

In sefReltoAbs function:
//multilingual code url support
if( $mosConfig_sef && ($mosConfig_mbf_content || $mosConfig_multilingual_support) && $string!='index.php' && !eregi("^(([^:/?#]+):)",$string) && !strcasecmp(substr($string,0,9),'index.php') && !eregi('lang=', $string) ) {
$string .= '&amp;lang='. $iso_client_lang;
}

and
// lang
if ( isset( $parts['lang'] ) ) {
$sefstring .= 'lang,'. $parts['lang'].'/';
}


Orstio


oSa


Orstio

THanks.

OK, change this:

//multilingual code url support
if( $mosConfig_sef && ($mosConfig_mbf_content || $mosConfig_multilingual_support) && $string!='index.php' && !eregi("^(([^:/?#]+):)",$string) && !strcasecmp(substr($string,0,9),'index.php') && !eregi('lang=', $string) ) {
$string .= '&amp;lang='. $iso_client_lang;
}


to this:

//multilingual code url support
if( $mosConfig_sef && ($mosConfig_mbf_content || $mosConfig_multilingual_support) && $string!='index.php' && !eregi("^(([^:/?#]+):)",$string) && !strcasecmp(substr($string,0,9),'index.php') && !eregi('lang=', $string) ) {
$string = substr($string,0,strpos($string, '#')-1) . '&amp;lang=' . $iso_client_lang . substr($string,strpos($string, '#'),strlen($string));
}

oSa

The links are correct and they work now, but there is antoher problem :-\ For example, my home page link:

http://www.artifm.net/component/option,com_frontpage/Itemid,1/lang,trindex.php?option,com_frontpage/

as you can see there is an extra "index.php?option,com_frontpage/" after /lang,tr.


Orstio

//multilingual code url support
if( $mosConfig_sef && ($mosConfig_mbf_content || $mosConfig_multilingual_support) && $string!='index.php' && !eregi("^(([^:/?#]+):)",$string) && !strcasecmp(substr($string,0,9),'index.php') && !eregi('lang=', $string) ) {
if (strpos($string, '#')!==0)
$string = substr($string,0,strpos($string, '#')-1) . '&amp;lang=' . $iso_client_lang . substr($string,strpos($string, '#'),strlen($string));
else
$string.= '&amp;lang=' . $iso_client_lang;
}

oSa

i think it doesn't enter the else part because links are still the same.

Orstio

How about if we turn it around?

//multilingual code url support
if( $mosConfig_sef && ($mosConfig_mbf_content || $mosConfig_multilingual_support) && $string!='index.php' && !eregi("^(([^:/?#]+):)",$string) && !strcasecmp(substr($string,0,9),'index.php') && !eregi('lang=', $string) ) {
if (strpos($string, '#')===0)
$string.= '&amp;lang=' . $iso_client_lang;
else
$string = substr($string,0,strpos($string, '#')-1) . '&amp;lang=' . $iso_client_lang . substr($string,strpos($string, '#'),strlen($string));
}

oSa

i guess i was wrong since it doesn't help.

Orstio

#46
It's closer than you think.

//multilingual code url support
if( $mosConfig_sef && ($mosConfig_mbf_content || $mosConfig_multilingual_support) && $string!='index.php' && !eregi("^(([^:/?#]+):)",$string) && !strcasecmp(substr($string,0,9),'index.php') && !eregi('lang=', $string) ) {
if (strpos($string, '#')===0){
$string.= '&amp;lang=' . $iso_client_lang;
} else {
$string = substr($string,0,strpos($string, '#')) . '&amp;lang=' . $iso_client_lang . (strpos($string, '#')===0 ? '' : substr($string,strpos($string, '#'),strlen($string)));
}
}

oSa

#47
Nope, it got worser:
http://www.artifm.net/&lang=trindex.php?option=com_smf&Itemid=26

it isn't SEF like this :)

Edit: were those triple "="s on purpose?
Edit2: It's 6.30 am here, i need to sleep and i suggest you too :)

Orstio

Yes, a triple "=" usually implies a boolean.  So 0 should be false.

//multilingual code url support
if( $mosConfig_sef && ($mosConfig_mbf_content || $mosConfig_multilingual_support) && $string!='index.php' && !eregi("^(([^:/?#]+):)",$string) && !strcasecmp(substr($string,0,9),'index.php') && !eregi('lang=', $string) ) {
if (strpos($string, '#')===false){
$string.= '&amp;lang=' . $iso_client_lang;
} else {
$string = substr($string,0,strpos($string, '#')) . '&amp;lang=' . $iso_client_lang . (strpos($string, '#')===false ? '' : substr($string,strpos($string, '#'),strlen($string)));
}
}

oSa

#49
There is nothing better than to get up in the morning and find that everyhing is working exactly as they should :) I've applied this last code change and voila!! All problems are gone now ;) I'm repeating myself but once again thank you Ortsio, for all the great support !!

I wish, this solution can be of help to other people but i guess it's a very specific one. Nevertheless, i've tried to summarize the solutions at the first message of this topic.

Advertisement: