Clean urls (hack)

Discuss, ask and suggest about Usability and Accessability with CMS Made Simple
Locked
tsw
Power Poster
Power Poster
Posts: 1408
Joined: Tue Dec 13, 2005 10:50 pm
Location: Finland

Clean urls (hack)

Post by tsw »

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: Select all

 
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: Select all

                        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: Select all

                        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: Select all

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  ;)
phdm

Re: Clean urls (hack)

Post by phdm »

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)
j2the3rd

Re: Clean urls (hack)

Post by j2the3rd »

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.
3stripe

Re: Clean urls (hack)

Post by 3stripe »

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
tsw
Power Poster
Power Poster
Posts: 1408
Joined: Tue Dec 13, 2005 10:50 pm
Location: Finland

Re: Clean urls (hack)

Post by tsw »

actually that hack is kind of old and Im trying to push new way for this in future relase..
nils73
Power Poster
Power Poster
Posts: 520
Joined: Wed Sep 08, 2004 3:32 pm

Re: Clean urls (hack)

Post by nils73 »

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
3stripe

Re: Clean urls (hack)

Post by 3stripe »

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...
tsw
Power Poster
Power Poster
Posts: 1408
Joined: Tue Dec 13, 2005 10:50 pm
Location: Finland

Re: Clean urls (hack)

Post by tsw »

0.13 will have clean urls integrated, and much better than this hack does :)
nils73
Power Poster
Power Poster
Posts: 520
Joined: Wed Sep 08, 2004 3:32 pm

Re: Clean urls (hack)

Post by nils73 »

tsw wrote: 0.13 will have clean urls integrated, and much better than this hack does :)
That is just what I said ...  ;)

Cheers,
Nils
tsw
Power Poster
Power Poster
Posts: 1408
Joined: Tue Dec 13, 2005 10:50 pm
Location: Finland

Re: Clean urls (hack)

Post by tsw »

oh  :P

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

Return to “[locked] Accessability and Usability”