Jump to content


- - - - -

makeUrl that obeys "friendly_alias_urls" setting


  • You cannot reply to this topic
3 replies to this topic

#1 Mitch

    Etomite Forum Newbie

  • Member
  • 8 posts

Posted 07 March 2005 - 07:49 PM

I noticed that the makeUrl function in the Etomite API does not take the "friendly_alias_urls" setting into account. This results in the links that are generated are always in the format of <friendlyurlprefix><pageid><friendlyurlsuffix>. But when the "Friendly aliases" option is enabled in the config then the link should look like this I think (if an alias is available for that page) <friendlyurlprefix><pagealias><friendlyurlsuffix>. The [~pageid~] thingy already seems to work this way. The makeUrl function below fixes the behaviour. Just replace the old function with the one below.

Example:
Page Test
- id=2
- alias="testing"
Friendly URL settings
- Prefix = ""
- Suffix = ".html"
- Friendly aliases = enabled

Normal makeUrl would return "2.html"
New makeUrl returns "testing.html"

function makeUrl($id, $alias='', $args='') {
  if(!is_numeric($id)) {
 	 $this->messageQuit("`$id` is not numeric and may not be passed to makeUrl()");
  }
  if($this->config['friendly_urls']==1 && $alias!='') {
 	 return $alias.$args;
  } elseif($this->config['friendly_urls']==1 && $alias=='') {

      // If friendly alias URL's are configured
      if ($this->config['friendly_alias_urls']==1) {
      // Check if the document has an alias
      $docalias = '';

   	 $limit_tmp = count($this->aliasListing);
   	 for ($i_tmp=0; $i_tmp<$limit_tmp && $docalias==''; $i_tmp++) {
        if ($this->aliasListing[$i_tmp]['id'] == $id) {
           $docalias = $this->aliasListing[$i_tmp]['alias'];
        }
   	 }

      if ($docalias=='') {
         $docalias=$id;
      }
     	 return $this->config['friendly_url_prefix'].$docalias.$this->config['friendly_url_suffix'].$args;
      } else {
      return $this->config['friendly_url_prefix'].$id.$this->config['friendly_url_suffix'].$args;
      }
  } else {
 	 return "index.php?id=$id$args";
  }
	}

PS: I was not sure if it is a bug and I didn't really know where to post this so I assumed it was mostly a mod so I posted it here. Let me know if there is a better place.

#2 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 07 March 2005 - 09:05 PM

I'm not sure that this would be considered a bug... I actually like the idea of not having to have a suffix automatically attached to my Friendly aliases, but that's just me... I can always add whatever suffix I want if I desire there to be one on the alias... I'm sure that some members might find this to be a nice Mod, however... B)

#3 Mitch

    Etomite Forum Newbie

  • Member
  • 8 posts

Posted 08 March 2005 - 05:38 PM

rad14701, on Mar 7 2005, 11:05 PM, said:

I actually like the idea of not having to have a suffix automatically attached to my Friendly aliases, but that's just me... I can always add whatever suffix I want if I desire there to be one on the alias...
Thats what the Friendly Aliases option is for if I understood correctly. This is what the text with the Friendly Aliases option says:

By setting this option to 'yes', the friendly URL prefix and suffix will also be applied to the alias. For example, if your document with ID 1 has an alias of `introduction`, and you've set a prefix of `` and a suffix of `.html`, setting this option to `yes` will generate `introduction.html`. If there's no alias, Etomite will generate `1.html` as link.
So if you don't want to have a prefix/suffix with your aliases you should just let this option disabled.

I had the opposite. I wanted the prefix/suffix with my aliases and I noticed that some snippets produced links like <prefix><id><suffix> instead of <prefix><alias><suffix> which I expected since I had the Friendly Alias option enabled. I traced it back to the makeUrl function and that resulted in the modification above.

#4 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 08 March 2005 - 07:50 PM

Again, this may or may not have been a bug as it all depends on how Alex decided to write the API function and how accurately its use was documented... Alex is the only one who knows that for sure, or at least we hope he does... :lol: As I stated earlier, I like having the option of not having to have a suffix on my Friendly Aliases, but definitely want a suffix on those pages not having an alias... That being said, neither setting would completely suit my needs if I were to modify the makeUrl function... That was the point I was originally trying to make, not to debate over whether this was a bug or not... Actually, one additional checkbox for selecting whether or not to have extensions on Friendly Aliases would solve the issue, along with your modified code, which would satisfy most all scenarios... You just never know what the 0.7/1.0 release will have to offer as far as options... B)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users