mod_rewrite support & many tag entries generate bad NEXT

Please report bugs here!

Moderator: Thorsten

Post Reply
Lidio
Posts: 25
Joined: Mon Dec 10, 2007 9:26 pm

mod_rewrite support & many tag entries generate bad NEXT

Post by Lidio » Sun Jun 29, 2008 2:26 am

Greetings,

if one turns on Activate mod_rewrite support feature and has tag entries that are more than one screen full, the [next] has an incomplete link something like .../tags/NN/.html

Lidio.

[By the way, the mod_rewrite feature is real cool! Nicely done.]

Lidio
Posts: 25
Joined: Mon Dec 10, 2007 9:26 pm

Post by Lidio » Wed Jul 23, 2008 10:12 pm

OK, I was kind of tired seeing 404 errors in my apache log for this so I decided to track this down.

The cause of the malformed URL lies in the file inc/Faq.php in this piece of code:

Code: Select all

            if ($next <= $pages) {
                $url = $sids.'&action=search&tagging_id='.$tagging_id.'&seite='.$next.$langs;
                $oLink = new PMF_Link(PMF_Link::getSystemRelativeUri().'?'.$url);
                $oLink->itemTitle = '';
                $oLink->text = $this->pmf_lang["msgNext"];
                $oLink->tooltip = $this->pmf_lang["msgNext"];
                $output .= '[ '.$oLink->toHtmlAnchor().' ]';
            }
in particular the line $oLink->itemTitle = '';. Since the value is not important (i.e. not really used) any non-empty string will do. I chose to change it to

Code: Select all

                $oLink->itemTitle = 'tag';
.

This also revealed two other related deficiencies. One with the .htaccess file. It needs to properly handle the "pages" for tags. So looking at / using the same technique as the categories change

Code: Select all

# PMF tags page
# * http://[...]/tags/<ID>/<HEADER>.htm
RewriteRule tags/([0-9]+)/([^\/]+)\.htm(l?)$     index.php?action=search&tagging_id=$1 [L,QSA]
to

Code: Select all

# PMF tags page with page count
# * http://[...]/tags/<ID>/<PAGE NUMBER>/<HEADER>.htm
RewriteRule tags/([0-9]+)/([0-9]+)/(.+)\.htm(l?)$   index.php?action=search&tagging_id=$1&seite=$2 [L,QSA]

# PMF tags page
# * http://[...]/tags/<ID>/<HEADER>.htm
RewriteRule tags/([0-9]+)/([^\/]+)\.htm(l?)$     index.php?action=search&tagging_id=$1 [L,QSA]
.

The other component is in inc/Link.php change

Code: Select all

                                $url .= PMF_LINK_TAGS.$getParams[PMF_LINK_GET_TAGGING_ID].PMF_LINK_SLASH.$this->getSEOItemTitle().PMF_LINK_HTML_EXTENSION;
to

Code: Select all

$url .= PMF_LINK_TAGS.$getParams[PMF_LINK_GET_TAGGING_ID];
if (isset($getParams[PMF_LINK_GET_PAGE])) {
    $url .= PMF_LINK_HTML_SLASH.$getParams[PMF_LINK_GET_PAGE];
}
$url .= PMF_LINK_SLASH.$this->getSEOItemTitle().PMF_LINK_HTML_EXTENSION;
With these changes, I also noticed that the [previous] link was not being handled properly for the mod_rewrite. To fix that in inc/Faq.php change

Code: Select all

if ($vor != 0) {
    if ($faqconfig->get('main.enableRewriteRules')) {
        $output .= "[ <a href=\"search.html?tagging_id=".$tagging_id."&seite=".$vor.$langs."\">".$this->pmf_lang["msgPrevious"]."</a> ]";
    } else {
        $output .= "[ <a href=\"index.php?".$sids."action=search&tagging_id=".$tagging_id."&seite=".$vor.$langs."\">".$this->pmf_lang["msgPrevious"]."</a> ]";
    }
} 
to

Code: Select all

if ($vor != 0) {
    $url = $sids.'&action=search&tagging_id='.$tagging_id.'&seite='.$vor.$langs;
    $oLink = new PMF_Link(PMF_Link::getSystemRelativeUri().'?'.$url);
    $oLink->itemTitle = 'tag';
    $oLink->text = $this->pmf_lang["msgPrevious"];
    $oLink->tooltip = $this->pmf_lang["msgPrevious"];
    $output .= '[ '.$oLink->toHtmlAnchor().' ]';
}
Lidio.

Thorsten
Posts: 14893
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Post by Thorsten » Fri Oct 10, 2008 11:33 am

Hi,

fixed in version 2.0.9 and 2.5.0-alpha2.

Thanks for the patch!

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist

Post Reply