News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

[3.0] Some ideas for improving work with standard urls

Started by Bugo, May 01, 2024, 10:27:55 AM

Previous topic - Next topic

Bugo

Part 1: Actions

Extend Utils class:
[php]public static function route(string $name, array $parameters = []): string
{
  $queryString = http_build_query($parameters, '', ';');

  return Config::$scripturl . '?action=' . $name . rtrim(';' . $queryString, ';');
}[/php]

Additionally, one can provide a short alias for this method (in root index.php or Subs-Compat.php):
[php]if (!function_exists('route')) {
  function route(string $name, array $parameters = []): string
  {
    return Utils::route($name, $parameters);
  }
}[/php]

Example:

Current syntax:
[php]<a href="' . Config::$scripturl . '?action=profile;area=notification;sa=markread;', Utils::$context['session_var'], '=', Utils::$context['session_id'], '">...</a>[/php]
Suggested syntax:
[php]<a href="' . Utils::route('profile', [
  'area' => 'notification',
  'sa' => 'markread',
  Utils::$context['session_var'] => Utils::$context['session_id']
]) . '">...</a>[/php]


Part 2: Boards and topics

Extend Topic class:
[php]public static function url(string $pattern, array $parameters = []): string
{
  $path = sprintf($pattern, ...$parameters);

  return Config::$scripturl . '?topic=' . $path;
}[/php]

Possible short alias:
[php]if (!function_exists('topic')) {
  function topic(string $pattern, array $parameters = []): string
  {
    return Topic::url($pattern, $parameters);
  }
}[/php]

Extend Board class:
[php]public static function url(string $pattern, array $parameters = []): string
{
  $path = sprintf($pattern, ...$parameters);

  return Config::$scripturl . '?board=' . $path;
}[/php]

Possible short alias:
[php]if (!function_exists('board')) {
  function board(string $pattern, array $parameters = []): string
  {
    return Board::url($pattern, $parameters);
  }
}[/php]

Example:

Current syntax:
[php]<a href="' . Config::$scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '" rel="nofollow">...</a>[/php]
Suggested syntax:
[php]<a href="' . Topic::url('%1$d.msg%2$d#msg%2$d', [$row['id_topic'], $row['id_msg']]) . '" rel="nofollow">...</a>[/php]

Added code tags ~ Steve

Arantor

Honestly 3.0 should just adopt actual pretty URLs.

If you're already going to the trouble of refitting for the above, might as well refit for the actual good stuff.

Bugo

Quote from: Arantor on May 01, 2024, 01:14:58 PMHonestly 3.0 should just adopt actual pretty URLs.
I agree.. Unfortunately, this is still not even on the roadmap.

Arantor

It's never going to be on the roadmap because there are too many people who don't see the value it brings.

Diego Andrés


SMF Tricks - Free & Premium Responsive Themes for SMF.

Arantor

Being feature-friendly doesn't mean all the features that are proposed are wanted. Especially for something like that which is a major backwards-compatible break, which as far as I can tell from the roadmap is to be avoided at all apparent cost.

Diego Andrés

If they make sense I don't see why not. There is a Reactions WIP already, all it takes is initiative.
So far the only NO I've seen is regarding the annoying SCEditor.

SMF Tricks - Free & Premium Responsive Themes for SMF.

Arantor

Reactions is a significantly smaller workload than proper pretty URLs.

No-one is going to want to sit and refit every single place URLs are generated in the platform. It's larger than you think.

Similarly, moving on from PHP templates to something safer for people, another job that *really* should be done at this point in time but no-one's ever going to want to invest the time because it's astronomical.

(Converting the templates to something nearer to Twig, about a thousand hours of effort for a competent developer. Ask me how I know.)

Sesquipedalian

Quote from: Arantor on May 04, 2024, 03:39:17 PMIt's never going to be on the roadmap because there are too many people who don't see the value it brings.

False. I see the value it brings, and I have not ruled it out. Rather, as you more accurately said in your later replies, it is a big undertaking, and therefore I am not adding it to the roadmap until we reach a point where it seems feasible to do so. Given that I spent the better part of a year refactoring nearly the entire codebase to make it object oriented, I think it should be clear that I am not one to set my sights low regarding what is feasible.

But I don't intend to let 3.0 spend years in development hell, and I have no problem saying that a worthwhile new feature like this can be planned for a subsequent release if it takes too long. If it ends up being something that can be implemented in a reasonable time frame for 3.0, awesome. If it has to wait for a later release, fine. I'll make the call on that when the time comes.
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

Arantor


Sesquipedalian

Ah. Well, I'm the one who decides what's on the roadmap. :)
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

Oldiesmann

Reactions is taking on a life of its own at this point. I have an idea of what I want to do with it - I just need to get that code implemented, which could be more difficult than I thought (I'm still relatively new to OOP in PHP. I did do some OOP stuff with C#/ASP .NET in college but that was well over a decade ago and that's a whole different world there)
Michael Eshom
Christian Metal Fans

Advertisement: