CMS Made Simple Forums
https://forum.cmsmadesimple.org/

[SOLVED] News & Pretty URL's with MLE & hierarchy Off
https://forum.cmsmadesimple.org/viewtopic.php?f=41&t=47461
Page 1 of 1

Author:  beattie [ Sat Sep 18, 2010 11:45 pm ]
Post subject:  [SOLVED] News & Pretty URL's with MLE & hierarchy Off

Many thanks to Owens for providing the solution to having nice URLs with the News Modules for users with multinlingual sites using MLE and with hierarchy set to false in the config file.

See also this post for information on the origins of this post:
http://forum.cmsmadesimple.org/index.php/topic,43037.0.html

I have a site in English and Spanish. You may have to tweak some of the below code to get it to work for you, but this might help someone who finds themselves in my situation. Just to be clear, the below code has been kindly provided by Owens, I am just grouping it together to make it easier for MLE users to implement.

Step 1
Add the below code to your .htaccess file:

Code:
RewriteCond %{HTTP_HOST} ^yoursite.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.yoursite.com$
# News Pretty URL Fix
RewriteRule ^news/([^/][0-9]+)/([^/][a-zA-Z]+_[a-zA-Z]+)/([^/][0-9]+)/([^/][a-zA-Z]+)/(.+)$ index.php?mact=News,cntnt01,detail,0&cntnt01articleid=$1&cntnt01lang=$2&cntnt01returnid=$3&hl=$4 [NC,L]
RewriteRule ^news/([^/][0-9]+)/([^/][0-9]+)/([^/][a-zA-Z]+)/(.+)$ index.php?mact=News,cntnt01,detail,0&cntnt01articleid=$1&cntnt01returnid=$2&hl=$3 [NC,L]


Step 2
Create a User Defined Tag (UDT) and name it news_no_hierarchy_url
(you can create a UDT in admin under the Extensions menu).
Copy and paste the below code and save your UDT.

Code:
preg_match('/articleid=[0-9]*/i',$params['ugly'], $matches);
$id = preg_replace('/articleid=/i','',$matches[0]);
preg_match('/lang=[a-zA-Z\{2}_[a-zA-Z]{2}/i',$params['ugly'], $matches);
$lang = preg_replace('/lang=/i','',$matches[0]);
preg_match('/returnid=[0-9]*/i',$params['ugly'], $matches);
$rid = preg_replace('/returnid=/i','',$matches[0]);
preg_match('/hl=[a-z]*/i',$params['ugly'], $matches);
$hl = preg_replace('/hl=/i','',$matches[0]);
$title = preg_replace('/ /','-',$params['title']);
if ($lang != '') {
  echo '/news/'.$id.'/'.$rid.'/'.$hl.'/'.$title.'.html';
} else {
  echo '/news/'.$id.'/'.$rid.'/'.$hl.'/'.$title.'.html';
}


Step 3
Add the below code to your news summary template just below the code {foreach from=$items item=entry}

Code:
{capture assign="cleantitle"}{$entry->title|cms_escape:htmlall}{/capture}
{capture assign="uglyurl"}{$entry->moreurl}{/capture}


Step 4
Replace this code:
Code:
<a href="{$entry->moreurl}" title="{$entry->title|cms_escape:htmlall}">


With this code:
Code:
<a href="{news_no_hierarchy_url ugly="$uglyurl" title="$cleantitle"}">


Here is a copy of my news summary template for your information:

Code:
<!-- Start News Display Template -->
{if $pagecount > 1}
  <p><strong>More articles:</strong>
{if $pagenumber > 1}
{$firstpage} {$prevpage} 
{/if}
{$pagetext} {$pagenumber} {$oftext} {$pagecount}
{if $pagenumber < $pagecount}
 {$nextpage} {$lastpage}
{/if}
</p>
{/if}

{foreach from=$items item=entry}

{capture assign="cleantitle"}{$entry->title|cms_escape:htmlall}{/capture}
{capture assign="uglyurl"}{$entry->moreurl}{/capture}


<div>

<div style="color:#ec008c;padding-top:8px;"><h2>
<a href="{news_no_hierarchy_url ugly="$uglyurl" title="$cleantitle"}">{$entry->title|cms_escape:htmlall}</a></h2></div>

{if $entry->writer}
   <div>
       {$entry->writer}
   </div>
{/if}

{if $entry->postdate}   
      <div style="padding-top:5px;"><strong>{$entry->postdate|cms_date_format}</strong> </div>
{/if}
<div style="padding-top:5px;"><em>{$category_label} {$entry->category}</em><br></div>

{if $entry->article_summary}
   <div style="padding-top:5px;">
      {eval var=$entry->article_summary}
   </div>


<div style="padding-top:10px">

      <img src="images/bullet.gif" alt="bullet"> <a href="{news_no_hierarchy_url ugly="$uglyurl" title="$cleantitle"}">full article</a> <img src="images/bullet.gif" alt="bullet">
   
</div>

{else if $entry->content}

      {eval var=$entry->content}
   
{/if}



<div style="border-bottom: 1px dashed #ec008c; width:100%;padding-top:20px;"></div>
</div>
{/foreach}
{if $pagecount > 1}
  <p><strong>More articles:</strong>
{if $pagenumber > 1}
{$firstpage} {$prevpage} 
{/if}
{$pagetext} {$pagenumber} {$oftext} {$pagecount}
{if $pagenumber < $pagecount}
 {$nextpage} {$lastpage}
{/if}
</p>
{/if}
<!-- End News Display Template -->

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/