Skip to main content
Topic: SEF URLs .. Yes I know it's been discussed (Read 1506 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Re: SEF URLs .. Yes I know it's been discussed

Reply #30
That part is quite easy in Nginx. But others, I am not so sure.
Well .. the PHP code itself is very complexe ..
But .. the most entrys can be done with hooks.

Fel
Many are stubborn in relation to the path, a few in relation to the target.
Visit our new Forum Project on https://www.portamx.com

Re: SEF URLs .. Yes I know it's been discussed

Reply #31
Hi Feline, canĀ“t you write the SEF Mod for Elkarte or do you want to keep this just for your own PortaMX forum ?


Re: SEF URLs .. Yes I know it's been discussed

Reply #32
I don't write code for Elkarte ... only for our Forum version.
Many are stubborn in relation to the path, a few in relation to the target.
Visit our new Forum Project on https://www.portamx.com

Re: SEF URLs .. Yes I know it's been discussed

Reply #33
Let's use that just because it's the first topic that came up from the search.
Today I started[1] playing with semantic urls.

The current progress is this one:
https://github.com/elkarte/Elkarte/compare/development...emanuele45:semantic_urls?expand=1

The general idea is:
  • Url_Generator stores all the possible alternative "url generators",
  • "Standard" is the normal one, no whistles, current ?topic=123 etc. and it will be the default fallback in case a "type" of URL is not known (I'm not entirely sure if this feature is actually needed, but it seemed fit into the design, so I added it, or maybe at the time I was thinking to use it differently... who knows.),
  • the semantic URLs will be created by another class, and in case something "special" is required, it can be dealt with by adding new types.

The way the code works should be somehow easy I think, I created a function that calls the singleton (yeah, again, I know, I just didn't know where to put the darn stuff, so for the time being I stuffed it in a singleton that looks nicer that $context to me, at least for this kind of things).
The example I used is:
Code: [Select]
'url' => $scripturl . '?action=markasread;sa=all;bi;' . $context['session_var'] . '=' . $context['session_id']
that becomes:
Code: [Select]
'url' => getUrl('action', array('action' => 'markasread', 'sa' => 'all', 'bi', $context['session_var'] => $context['session_id']))
I'm pretty sure purist of speed will frown at the fact it needs a function call... feel free to stick with your buffer rewrite. :P

Of course, this is just the easy part, now the two difficult ones:
  • parse the GET,
  • replace all the URLs in the code base

And since 2 is massive, I decided to post it here to get some feedback regarding the code, if anyone sees problems or lacks of features, because I would like to avoid having to redo everything two times. O:-)
well, it's not true because the code was laying around since quite a while and it was not even committed, so I've been quite lucky I didn't delete it while doing some cleaning. xD
Bugs creator.
Features destroyer.
Template killer.

Re: SEF URLs .. Yes I know it's been discussed

Reply #34
Quick look I think its good

May want to consider moving the session var and id stuff to the getUrl() function, maybe as a third param done as true/false.  True by default with an false option not to add it (I guess that may be needed somewhere maybe?)
Squish squish. squish, squish, squish.
Find a bug,
Make a wish.

Re: SEF URLs .. Yes I know it's been discussed

Reply #35
Good point.
Maybe, though, false by default, I think the number cases we do not want session is far greater than when we want it?
I'll try to get some number later.
Bugs creator.
Features destroyer.
Template killer.


 

Re: SEF URLs .. Yes I know it's been discussed

Reply #37
Getting all fancy on me ... I like it !
Squish squish. squish, squish, squish.
Find a bug,
Make a wish.

Re: SEF URLs .. Yes I know it's been discussed

Reply #38
Any idea why in certain list where the url is sprintf'ed, $scripturl has an strtr to replace single % to %%?
Code: [Select]
'format' => '<a href="' . strtr($scripturl, array('%' => '%%')) . '?action=profile;u=%1$d">%2$s</a>',
Bugs creator.
Features destroyer.
Template killer.

Re: SEF URLs .. Yes I know it's been discussed

Reply #39
I kind of found my answer. It was randomly applied in few places during the very first implementation of createList, but apparently without any real schema: in certain places it was added, in others it was not.
So, unless anyone has any objection, I'm going to drop them all and go for the "without strtr" version.
Bugs creator.
Features destroyer.
Template killer.

Re: SEF URLs .. Yes I know it's been discussed

Reply #40
Okay, few months after I have the prototype up and working locally.
It doesn't come with any configuration yet (not even the "enable") is not yet completed because I replaced only the potentially bot-facing urls in the controllers and subs (still have to touch the template) and is probably buggy, but it's a start.
I went for:
* index.php?b/{boardname}-{id}/page-{number}
* index.php?t/{subject}-{id}/page-{number}
* index.php?p/{username}-{id}
and then after that a question mark and any other parameter.

It's yet another re-inventing the wheel kind of thing, but... well, it was easier for now to write it rather than learn how to use existing stuff. xD

Here it is the code:
https://github.com/elkarte/Elkarte/compare/development...emanuele45:semantic_urls?expand=1

When the templates will be done I'll send the pull request. If anyone is interested in helping with this, it may do with some testing (and a working example of htaccess to hide the index.php? part would be very helpful! xD), and if you are interested enough to do some coding, you can send PRs to my own repo. ;)
Bugs creator.
Features destroyer.
Template killer.