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

Clean urls (hack)
https://forum.cmsmadesimple.org/viewtopic.php?f=23&t=2653
Page 1 of 1

Author:  tsw [ Sat Jan 07, 2006 12:04 pm ]
Post subject:  Clean urls (hack)

Clean url by default doesnt take into account the hierarchy of the links, here is a hack to have urls like "http://www.domain.tld/parent1/parent2/parentN/page.html"

in lib/misc.functions.php add

Code:
 
function clean_urls($my_ID) {
  global $gCms;
  global $config;

  $thispage = $page;

  $thispage = $my_ID;


  $trail = "";
  $delimiter = "/";

#Make an array for all pages
  $allcontent = array();

#Load current content
  $onecontent = ContentManager::LoadContentFromId($thispage, false);

  if ($onecontent !== FALSE)
    {
      array_push($allcontent, $onecontent);

#Grab all parents and put them into the array as well
      while ($onecontent->ParentId() > 0)
        {
          $onecontent = ContentManager::LoadContentFromId($onecontent->ParentId(), false);
          // tdh add / modify next 5 lines
          if (isset($params['root']))
            {
              if (strtolower($onecontent->Alias()) != strtolower($params['root']))
                {
                                        array_push($allcontent, $onecontent);
                }
            }
          else
            {
              array_push($allcontent, $onecontent);
            }
        }

#Pull them one by one in reverse order to construct a breadcrumb list
      $first=1;
      while ($onecontent = array_pop($allcontent))
        {
          if($first) {
            $trail = $onecontent->getURL();
            $strip = count_chars($config["page_extension"]);
            $trail = substr($trail, 0, -5);
            $trail .= $delimiter;
            $first=0;
          } else {
            $trail .= $onecontent->MenuText() . $delimiter;
          }
        }
      $trail = substr($trail, 0, -1);
      $trail .= $config["page_extension"];
      return $trail;
    }
}
 


before ?> at the end

in modules/CSSMenu/CSSMenu.module.php edit lines
Code:
                        if ($onecontent->Id() == $gCms->variables['content_id'])
                        {
                               $menu .= "<li class=\"menuactive\"><a href=\"".$onecontent->GetURL()."\"";
                        }
                        else
                        {
                               $menu .= "<li><a href=\"".$onecontent->GetURL()."\"";
                        }




to read
Code:
                        if ($onecontent->Id() == $gCms->variables['content_id'])
                        {
#                               $menu .= "<li class=\"menuactive\"><a href=\"".$onecontent->GetURL()."\"";
                                $menu .= "<li class=\"menuactive\"><a href=\"".clean_urls($onecontent->Id())."\"";
                        }
                        else
                        {
#                               $menu .= "<li><a href=\"".$onecontent->GetURL()."\"";
                                $menu .= "<li><a href=\"".clean_urls($onecontent->Id())."\"";
                        }



new .htaccess file

Code:
RewriteEngine On
#Rewrites anything/page.shtml as index.php?page
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^(.*/)?([a-zA-Z0-9\.]+)\.html$ index.php?page=$2 [QSA]


in config change
$config['page_extension'] = '.html';
$config['assume_mod_rewrite'] = true;


try it, tested with news module and it should fallback to "messyURL"  ???

thanks go to breadcrumbs, most of the function is copy paste from there  ;)

Author:  phdm [ Sun Jan 08, 2006 7:51 am ]
Post subject:  Re: Clean urls (hack)

tsw wrote:
Clean url by default doesnt take into account the hierarchy of the links, here is a hack to have urls like "http://www.domain.tld/parent1/parent2/parentN/page.html"


I am just discovering CMSMS and I haven't tested this hack yet and the poblem you mention with modules. But your hack seems very interesting. From a usability point of view, such "clean URLs" seem much better than the existing one.

We could imagine that such clean URLs could be an option for CMSMS (the 2 other options would be: 1) no clean URL, 2) the existing clean URLs system).

@mitiƩs

Philippe (phdm)

Author:  j2the3rd [ Fri Jan 20, 2006 3:17 pm ]
Post subject:  Re: Clean urls (hack)

THIS is exactly what i'm looking for... but it doesn't seem to be playing nice...

I have a brand new fresh install, with nothing but the default content in and once I implement each of the steps here, I get 404 errors off the home page.

only about 1/2 the main links work, and none of the 2nd level pages work at all.

Clean urls were working fine with the fresh install, but I really want this type of hierarchy in the links.

Is this working with the latest release of CMSMS? Any help would be appreciated.

Author:  3stripe [ Tue Apr 11, 2006 5:23 pm ]
Post subject:  Re: Clean urls (hack)

I've just installed CMSMS for the first time - is it safe to try using the hack above?

I'm also very keen to make the urls more (search-engine) friendly....

Cheers

Author:  tsw [ Wed Apr 12, 2006 12:49 pm ]
Post subject:  Re: Clean urls (hack)

actually that hack is kind of old and Im trying to push new way for this in future relase..

Author:  nils73 [ Mon Apr 24, 2006 9:17 am ]
Post subject:  Re: Clean urls (hack)

No more need for hacks guys: 0.13beta1 is out and takes care of all these things. Congratulations, Ted! If you'd like to know how to use Clean URLs (pretty urls) when you upgrade to 0.13, please have a look here.

There are some modifications available for creating path-like URLs and furthermore modules URLs look much prettier this way. Cheers to all who made this possible.

Regards,
Nils

Author:  3stripe [ Tue Apr 25, 2006 9:56 am ]
Post subject:  Re: Clean urls (hack)

Wow great  ;D

I was about to give up on my first attempt at using cmsms because I had no idea how to get the urls to play nice... maybe I will now...

Author:  tsw [ Tue Apr 25, 2006 1:58 pm ]
Post subject:  Re: Clean urls (hack)

0.13 will have clean urls integrated, and much better than this hack does :)

Author:  nils73 [ Tue Apr 25, 2006 3:39 pm ]
Post subject:  Re: Clean urls (hack)

tsw wrote:
0.13 will have clean urls integrated, and much better than this hack does :)


That is just what I said ...  ;)

Cheers,
Nils

Author:  tsw [ Tue Apr 25, 2006 5:17 pm ]
Post subject:  Re: Clean urls (hack)

oh  :P

note to self: read more than just the latest reply!

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