News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Improving Joomla-SMF modules

Started by kai920, October 03, 2007, 08:23:53 AM

Previous topic - Next topic

kai920

Just noticed in my SMF error logs after installing mod_smf_newTopics.php and mod_smf_recentTopics.php:

Quote
8: Undefined variable:  sublength
File: /home/public_html/modules/mod_smf_recentTopics.php
Line: 139

Quote8: Undefined variable:  exclude
File: /home/public_html/modules/mod_smf_newTopics.php
Line: 44

Quote8: Undefined variable:  sublength
File: /home/public_html/modules/mod_smf_newTopics.php
Line: 137

Any quick fixes?

rummie

best bet is to look at the code, or post a link to the module or attach it so that others may have a crack at it.
???? hmmm?


slightly off topic, I would LOVE for the error log feature in SMF to have an
"Ignore further errors from this USER/PROGRAM" for "TODAY/FOREVER"


kai920

Code (mod_smf_recentTopics.php lines 134-140) Select

switch ($smf_rt_display)
   {
      case 0:
     echo '<table border="0" class="', $smf_rt_moduleclass_sfx, '">';
     foreach ($posts as $post) {
        $post['subject'] = strlen(un_htmlspecialchars($post['subject'])) > ($sublength+3) ? htmlspecialchars(substr(un_htmlspecialchars($post['subject']), 0, $smf_rt_sublength) . '...') : $post['subject'];
        echo '<tr>';


Code (mod_smf_newTopics.php line 44) Select

if ($exclude=="") $exclude="0";


Code (mod_smf_newTopics.php lines 132-138) Select

    switch ($smf_nt_display)
    {
        case 0:
      echo '<table border="0" class="', $smf_nt_moduleclass_sfx, '">';
      foreach ($posts as $post) {
          $post['subject'] = strlen(un_htmlspecialchars($post['subject'])) > ($sublength+3) ? htmlspecialchars(substr(un_htmlspecialchars($post['subject']), 0, $smf_nt_sublength) . '...') : $post['subject'];
          echo '<tr>';


Orstio

if ($exclude=="") $exclude="0";


That one should probably look more like this:

if (!isset($exclude) || $exclude=="") $exclude="0";

kai920

Great, solved the line 44 problem in both modules. I will try to use a similar approach for the other errors.

Orstio

$sublength should probably be changed to $smf_rt_sublength

kai920

Quote from: Orstio on October 07, 2007, 10:10:16 PM
$sublength should probably be changed to $smf_rt_sublength

That didn't work. I noticed at the beginning there is this line present:

$smf_rt_sublength = $params->get( 'smf_rt_sublength' );

Orstio

Have you edited the module parameters yet?  For most modules, the parameters are completely empty until you edit the module params, and save once.

kai920

Quote from: Orstio on October 08, 2007, 12:32:18 AM
Have you edited the module parameters yet?  For most modules, the parameters are completely empty until you edit the module params, and save once.

Yep - I checked all the modules and they all have a number entered into the "Subject Length" box.

Orstio

And you've made sure to click Save?  As I said, just because there is a value there when you look, automatically populated from the XML file, does not mean that value is actually saved in the database as a parameter.

kai920

yep - definitely saved! I've opened up the module(s) a couple times and it's in there.

I have two copies of recentTopics module, with different values for the subject length parameter.

I have just one copy of newTopics module, and it also has a subject length parameter.

kai920

#11
Orstio, I changed the newTopics variable to smf_nt_sublength. Appears to have done the trick!

recentTopics should have smf_rt_sublength.

And for good measure, I went into my modules and clicked SAVE for each.

I think this can be marked as solved. Thanks again.

Maybe someone should update the modules?

rummie

Quote from: kai920 on October 08, 2007, 01:17:12 AM
Orstio, I changed the newTopics variable to smf_nt_sublength. Appears to have done the trick!

recentTopics should have smf_rt_sublength.

And for good measure, I went into my modules and clicked SAVE for each.

I think this can be marked as solved. Thanks again.

Maybe someone should update the modules?

???

That somebody looks like YOU doesnt it! :P ..hopefully your next post will have the module as an attachment! :)

kai920

Quote from: rummie on October 08, 2007, 08:35:55 PM
Quote from: kai920 on October 08, 2007, 01:17:12 AM
Orstio, I changed the newTopics variable to smf_nt_sublength. Appears to have done the trick!

recentTopics should have smf_rt_sublength.

And for good measure, I went into my modules and clicked SAVE for each.

I think this can be marked as solved. Thanks again.

Maybe someone should update the modules?

???

That somebody looks like YOU doesnt it! :P ..hopefully your next post will have the module as an attachment! :)


lol, yes it could be ME! but I'm not sure how to repackage it, etc.... certainly don't mind doing it, but a more 'official' coder would probably do a better job!

actually the next thing I want to do would be proper SEF urls in these modules. Maybe once I've figured that out I can update the modules :)

As it is now the URLs look like


http://www.kaitech.hk/index.php?option=com_smf&Itemid=71&&topic=1756.msg6714;topicseen#new


This is with SEF in Joomla turned on. and note the two &'s

rummie

hmmm.. well upload the original zip files, then attach the files you changed and I'll give it a go!

the other thing to do too is to look at how the urls are constructed - the bridge also has its part to play as well so thats another place we will probably have to look.

kai920

#15
Here are the links to the two original modules. >LINK< (newTopics and recentTopics)

Unfortunately I am not able to attach files here.

kai920

Quote from: rummie on October 09, 2007, 02:28:59 AM
the other thing to do too is to look at how the urls are constructed - the bridge also has its part to play as well so thats another place we will probably have to look.

Just noticed that in the module, the SEF URL generated to the board is fine, but the link to the post is not.

kai920

Some additional observations.

Code (line 31 of mod_smf_recentTopics.php) Select
$myurl = $_SERVER[\'PHP_SELF\'] . \"?option=com_smf&Itemid=\" . $row[0] . \"&\" ;

If I take out that \"&\" at the end, the topic URL changes from
http://localhost/index.php?option=com_smf&Itemid=71&&topic=1761.msg6718;topicseen#new
to
http://localhost/index.php?option=com_smf&Itemid=71&topic=1761.msg6718;topicseen#new

HOWEVER, the board\'s already SEF URL changes from
http://localhost/component/option,com_smf/Itemid,71/board,1.0
to
http://localhost/index.php?option=com_smf&Itemid=71?board=1.0

Going to see if I can figure out something but if anyone has ideas...

kai920

Ah-ha! Found the extra & at line 119:

         'href' => $scripturl . 'amp;topic=' . $row['ID_TOPIC'] . '.msg' . $row['ID_MSG'] . ';topicseen#new',

should be

         'href' => $scripturl . 'topic=' . $row['ID_TOPIC'] . '.msg' . $row['ID_MSG'] . ';topicseen#new',


So the next step is... why is the board's URL SEF but the topic URL not-SEF?

kai920

OK some more progress made, but I have some questions:

1) I added a global $mosConfig_sef to the top of the smf_recentTopics.php file. Is this an acceptable practice?

2) Is ";topicseen#new" required or is just "#new" enough for appending to the end of the URL?  I noticed the forums here only use #new.

My bridge currently sends notification emails with what appears to be an incorrect "/topic,1761.new/topicseen,topicseen#new". Which is the correct URL?


rummie

are the 'bad' links clickable and resolve to the correct post/topic? if so, you may not want to change them otherwise Google may get confused and think you have created duplicate content since you know have a different URL pointing to the same data?

#new should be better than  ;topicseen#new"  but it may not be worth the trouble to change it, especially if it works

Orstio

Quote from: kai920 on October 18, 2007, 02:09:21 PM
OK some more progress made, but I have some questions:

1) I added a global $mosConfig_sef to the top of the smf_recentTopics.php file. Is this an acceptable practice?

2) Is ";topicseen#new" required or is just "#new" enough for appending to the end of the URL?  I noticed the forums here only use #new.

My bridge currently sends notification emails with what appears to be an incorrect "/topic,1761.new/topicseen,topicseen#new". Which is the correct URL?



1)  Absolutely fine.  There is no reason you can't global any of the $mosConfig variables.

2) The "topicseen" in the URL is to tell SMF to remove the "new" icon from the topic after you have clicked it.  Don't expect your 1.1.4 forum to behave exactly the same as this 2.0 beta forum. ;)

Quoteare the 'bad' links clickable and resolve to the correct post/topic? if so, you may not want to change them otherwise Google may get confused and think you have created duplicate content since you know have a different URL pointing to the same data?

I'm wondering how the Googlebot is going to receive a notification email?

kai920

Quote from: rummie on October 18, 2007, 05:26:35 PM
are the 'bad' links clickable and resolve to the correct post/topic? if so, you may not want to change them otherwise Google may get confused and think you have created duplicate content since you know have a different URL pointing to the same data?

#new should be better than  ;topicseen#new"  but it may not be worth the trouble to change it, especially if it works

If you are talking about the recent posts module, then yes the "bad" links on the module were clickable and did resolve to the post.

Orstio, what should then be the ideal SEF URL with the topicseen parameter for recent posts in 1.1.4?

/topic,1761.msg6718/topicseen,#new
or
/topic,1761.new/topicseen,topicseen#new
or
something else?  If I am correct ';topicseen#new' is not SEF with the semicolon in there.

kai920

#23
Quote from: Orstio on October 18, 2007, 06:46:38 PM
2) The "topicseen" in the URL is to tell SMF to remove the "new" icon from the topic after you have clicked it.  Don't expect your 1.1.4 forum to behave exactly the same as this 2.0 beta forum. ;)

I used sefReltoAbs on a non-SEF URL that had ;topicseen#new appended, and the result was /topicseen,topicseen#new

So is the latter the correct and "official" SEF URL, like in the notification email?



edit - I clicked on an URL without the topicseen inside my board index. (http://localhost/component/option,com_smf/Itemid,71/topic,1761.msg6594#new) and it made the "new icon" disappear. So is topicseen really needed?

kai920

Sorry, another question about the URLs.

This is not a standard bridged SMF URL:  /index.php?option=com_smf&Itemid=71&?[/b]board=1.0.

It should be /index.php?option=com_smf&Itemid=71&[/b]board=1.0 correct?

I'm getting a bit confused about the role of "&" and "?"s in Joomla and SMF URLs.

rummie

Quote from: kai920 on October 19, 2007, 04:17:19 AM
Sorry, another question about the URLs.

This is not a standard bridged SMF URL:  /index.php?option=com_smf&Itemid=71&?[/b]board=1.0.

It should be /index.php?option=com_smf&Itemid=71&[/b]board=1.0 correct?

I'm getting a bit confused about the role of "&" and "?"s in Joomla and SMF URLs.


I believe the ? separates the url resource from the parameter list and is required.


the & separates the different parameters themselves

i.e. index.php?oneparm=1&anotherparam=2

kai920

so the ? is for SMF-only URLs..

the & is for Joomla URLs.

correct?

Kindred

no... the ? is for the first parameter
index.php?param

the & separated parameters in the list
index.php?pama1&param2

this is true regardless of SMF or Joomla.

the &? is incorrect...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

kai920

Quote from: Kindred on October 19, 2007, 08:25:45 AM
no... the ? is for the first parameter
index.php?param

the & separated parameters in the list
index.php?pama1&param2

this is true regardless of SMF or Joomla.

the &? is incorrect...

OK... since it's a Joomla module, the only place where a ? would exist is index.php?option=com_smf........ right?

So I can safely take out any other ?s in the code for example ?topic or ?board... ???

kai920

Regarding the "new" icon... should that link generated be the same as the post URL?

On the text URL I'm getting
http://localhost/component/option,com_smf/Itemid,71/topic,1746.msg6711/topicseen,topicseen#new

versus new icon
http://localhost/component/option,com_smf/Itemid,71/topic,1746.msg6594/topicseen,topicseen#new


I also need to know about topicseen:
Quote from: kai920 on October 19, 2007, 02:44:03 AM
I used sefReltoAbs on a non-SEF URL that had ;topicseen#new appended, and the result was /topicseen,topicseen#new

So is the latter the correct and "official" SEF URL, like in the notification email?



edit - I clicked on an URL without the topicseen inside my board index. (http://localhost/component/option,com_smf/Itemid,71/topic,1761.msg6594#new) and it made the "new icon" disappear. So is topicseen really needed?


Orstio

Yes, it will need to be topicseen,topicseen because Joomla will omit the "topicseen" from the URL before it gets to SMF if there is no value.

kai920

1) OK, but the ;topicseen really is necessary? You said "The "topicseen" in the URL is to tell SMF to remove the "new" icon from the topic after you have clicked it"  but it seems that just the #new also accomplishes the same thing - or am I mistaken?

2) Should the links of the new icon and text link really be different?

Orstio

1) No.  The #new is a HTML reference to a page anchor.  It causes the browser to move the page to that anchor.

2)  Yes.  The "New" icon takes you to the newest post.  The text link takes you to the topic.


kai920

Quote from: Orstio on October 19, 2007, 09:55:30 PM
1) No.  The #new is a HTML reference to a page anchor.  It causes the browser to move the page to that anchor.

Right, but after I read the new message on the #new anchor, will the new icon not disappear automatically? It seems to do that. ???

Quote
2)  Yes.  The "New" icon takes you to the newest post.  The text link takes you to the topic.
So the text link should take me to the first post of the topic? can you explain why the different topic,1746.msgxxxx?


On the text URL I'm getting
http://localhost/component/option,com_smf/Itemid,71/topic,1746.msg6711/topicseen,topicseen#new

versus new icon
http://localhost/component/option,com_smf/Itemid,71/topic,1746.msg6594/topicseen,topicseen#new

Orstio

The text link should be giving you just a link to the topic, not to the first new post.  It should not have a #new on the end.

kai920

Quote from: Orstio on October 20, 2007, 07:50:40 AM
The text link should be giving you just a link to the topic, not to the first new post.  It should not have a #new on the end.

OK. On the board index I see what you mean:
the text link is http://localhost/component/option,com_smf/Itemid,71/topic,1746.0
and the new icon is http://localhost/component/option,com_smf/Itemid,71/topic,1746.msg6594#new

1) Sorry, I'm still not understanding why the "topicseen" is needed as it's not present in the above URLs.

2) On the recent posts module the above behavior is (currently) not duplicated.

text link:
http://localhost/component/option,com_smf/Itemid,71/topic,1746.msg6711/topicseen,topicseen#new

Not sure where that msg6711 is coming from, but it should just be 0.

Would it be better to just make both text link and new icon in the recent posts module point to the newest post, since it is a "recent posts" module?

Orstio

The "new" icon, and the "topicseen" in the URL should only be visible for topics that have been updated and you have not viewed.

All of the code you need to look at is in SSI.php.  Everything in the module should reflect exactly what SSI.php would output.

kai920

#37
I see, so the topicseen and new icon always go together?

Is there something wrong with this URL, if msg 6594 is NOT part of topic 1746? http://localhost/component/option,com_smf/Itemid,71/topic,1746.msg6594#new

kai920

#38
Orstio, I emailed you a php file. Did you get it?

I used it on my live server but interesting it does NOT convert the links to SEF, whereas on localhost it does.
Nevermind, figured out it has to do with SEF Advance.

kai920

I tried to force SEF output by using sefReltoAbs (without checking for $mosConfig_sef) but the URL still comes out non-SEF. What would be possible reasons for this?

Orstio

Quote from: kai920 on October 25, 2007, 02:17:37 AM
Orstio, I emailed you a php file. Did you get it?

I used it on my live server but interesting it does NOT convert the links to SEF, whereas on localhost it does.
Nevermind, figured out it has to do with SEF Advance.

Yes, I did, but I have not had a chance to look at them.

Quote from: kai920 on November 05, 2007, 02:35:42 AM
I tried to force SEF output by using sefReltoAbs (without checking for $mosConfig_sef) but the URL still comes out non-SEF. What would be possible reasons for this?

Is it the entire URL?

sefReltoAbs in Joomla needs a relative URL as input, and will not convert absolute URLs.

So:

sefReltoAbs('index.php?option=com_smf&Itemid=99'); will convert to SEF.

sefReltoAbs('http://www.site.com/index.php?option=com_smf&Itemid=99'); will not.

kai920

#41
Quote from: Orstio on November 07, 2007, 07:24:49 PM
sefReltoAbs('index.php?option=com_smf&Itemid=99'); will convert to SEF.

1. Does a slash in front matter? i.e. will sefReltoAbs convert the following URL?

            /index.php?option=com_smf&Itemid=71&board=1.0

2. If I want to remove the first slash, would this be the recommended way:
substr( ($post['board']['href']), 1)

3. I used sefReltoAbs on 'index.php?option=com_smf&Itemid=71&action=profile;u=2', and it came out as http://localhost/option,com_smf/Itemid,71/action,profile;u,2/

The correct URL should be http://localhost/option,com_smf/Itemid,71/action,profile/u,2

Orstio

1. The leading slash definitely makes a difference.  It shouldn't be there.

2. That will work.

3. After the sefReltoAbs, you will probably have to do a str_replace for the semi-colons.  That's a quirk in SMF URLs that Joomla's SEF won't be able to interpret.

kai920

Quote from: Orstio on November 21, 2007, 12:04:55 AM
3. After the sefReltoAbs, you will probably have to do a str_replace for the semi-colons.  That's a quirk in SMF URLs that Joomla's SEF won't be able to interpret.

1. OK: for the username, I used a str_replace after sefReltoAbs to weed out the semi-colon. I got pretty close but my SEF program tacks on an extra "/" at the end of the URL. Do you know if these two URLs will cause any "penalties" in search engines?

http://localhost/option,com_smf/Itemid,71/action,profile/u,2/ vs.
http://localhost/option,com_smf/Itemid,71/action,profile/u,2

2. I was looking at this code for the new icon, and noticed that it's outputting perfect SEF URLs. Why is is that sefReltoAbs is not needed on this?

<a href="' . $scripturl . '?topic=' . $post['topic'] . '.msg' . $post['new_from'] . ';topicseen#new">

kai920

#44
Quote from: kai920 on November 21, 2007, 05:11:06 AM
I was looking at this code for the new icon, and noticed that it's outputting perfect SEF URLs. Why is is that sefReltoAbs is not needed on this?

<a href="' . $scripturl . '?topic=' . $post['topic'] . '.msg' . $post['new_from'] . ';topicseen#new">

1. The above code translates to the following (note the "?" in the URL). Somehow the "?" is making the difference. The URL is automatically outputted into SEF URLs on any forum page.

<a href="/index.php?option=com_smf&Itemid=71&?topic=1756.msg6719;topicseen#new"> becomes

http://localhost/option,com_smf/Itemid,71/topic,1756.msg6719/topicseen,topicseen#new

What do you think of this? It's not technically correct, but it works on any forum page - The same behavior is observed for the board URL and username URL.

2. **** However on Joomla's frontpage the URL is not "magically" SEF'd... The "?" doesn't make a difference and the URL output is http://localhost/index.php?option=com_smf&Itemid=71&?topic=1756.msg6714;topicseen#new. If I take out the ? I get a normal Joomla URL that is not SEF'd.

Orstio

QuoteIt's not technically correct, but it works on any forum page - The same behavior is observed for the board URL and username URL.

Quote**** However on Joomla's frontpage the URL is not "magically" SEF'd... The "?" doesn't make a difference and the URL output is http://localhost/index.php?option=com_smf&Itemid=71&?topic=1756.msg6714;topicseen#new. If I take out the ? I get a normal Joomla URL that is not SEF'd.

Take a look at the ob_mambofix function in the bridge.  This function is exectued on all bridge pages because it is part of the bridge component.  However, on non-bridge component pages, like the Joomla front page, it is not.

You need to make your module have correct output for non-bridge component pages, and therefore, you need to remove the leading slash.

kai920

Quote from: Orstio on November 23, 2007, 06:14:16 AM
Take a look at the ob_mambofix function in the bridge.  This function is exectued on all bridge pages because it is part of the bridge component.  However, on non-bridge component pages, like the Joomla front page, it is not.

If I sefReltoAbs this:
index.php?option=com_smf&Itemid=71&topic=1689.msg6769;topicseen#new

I get this:
option,com_smf/Itemid,71/topic,1689.msg6769;topicseen/#new

Even after I replace the ";" with a "/" and take out the "/" in front of "#" it still does not match this:
option,com_smf/Itemid,71/topic,1689.msg6769/topicseen,topicseen#new

Is ob_mambofix responsible for the double "topicseen"s?

Orstio

QuoteIs ob_mambofix responsible for the double "topicseen"s?

Yes.  It does everything necessary to make the URLs work with both Joomla and SMF.

kai920

#48
Quote from: Orstio on November 28, 2007, 07:36:17 PM
Yes.  It does everything necessary to make the URLs work with both Joomla and SMF.

I assume it's the last part of the function that's responsible for the double topicseen?... the part that comes after "// and now for SEF" (line 224)

PS. even if it's a yes, I have no idea which lines are responsible..

Orstio

It's this line:

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

kai920

Cool, thanks for the hint - even if I have 0% chance of understanding what it does, I'll give it a go  :P

Orstio

#51
It looks through the URL, starting at the point where it finds "option", then replaces any set of characters surrounded by two semi-colons or a semi-colon and a "#" without a "=" or a "#" in the string with itself twice with a "=" in between.

Simply, it turns ";topicseen#" into ";topicseen=topicseen#".  It does the same for things like posting a poll (poll=poll).

Note:  In the old 3.1x bridges, this was done by a lookup in an array of strings that would need to be duplicated.  In the new SMF 1.1 bridges, I switched to a regex, because it is not only faster than the array lookup, but it also accounts for strings that are added by third party SMF mods.

kai920

Thanks for the explanation :)

Here's what I've come up with. I haven't tried to "fix" this. hey if it works...



$nqsefurl = substr($post['href'], 0, strpos($post['href'], 'option')) . str_replace("?", "", substr($post['href'], strpos($post['href'], 'option')));

          if (!empty($mosConfig_sef) && $mosConfig_sef == '1')
        {
          $nqsefurl = substr($nqsefurl, 0, strpos($nqsefurl, 'option')) . preg_replace('/([img alt=;)]http://www.simplemachines.org/community/Smileys/simple/wink.gif[/img]([^=#]*)([;#"])/', '$1$2=$2$3', substr($nqsefurl, strpos($nqsefurl, 'option'), strlen($nqsefurl)));
         
          $sefurl = sefReltoAbs(substr($nqsefurl,strpos($nqsefurl, 'index')));
        $sefurl = str_replace(";", "/", $sefurl);
        $sefurl = str_replace("/#", "#", $sefurl);
        }
   
         echo '<tr><td valign="top"><a href="', ($mosConfig_sef == 1 ? $sefurl : $nqsefurl) , '">', $post['subject'], '</a> ';


This gives identical SEF and non-SEF URLs on the non-forum pages :)


Advertisement: