[Owncloud] URLRouting was: Re: GSoC 2012 Ideas page: time to add those ideas!

Roland van Laar roland at micite.net
Sun Mar 4 01:46:26 UTC 2012


On 03/02/2012 08:21 AM, Thomas Müller wrote:
> Am Freitag, den 02.03.2012 um 8:17 schrieb Klaas Freitag:
>> On 01.03.2012 21:00, Roland van Laar wrote:
>>
>>> <snip> 
>>> 2) Better urls, i.e. have a routing structure for urls.
>>> -- get rid of the .php extension for urls
>>> -- register php functions or files with urls so that not every php file
>>> is accessible from the web.
>> Couldn't agree more, we need to work on the routing. However, I don't
>> think its a GSoC task, but rather a bug. You should file a bug report on
>> this topic.
>>
> FYI: There is already a feature request on this topic:
> http://bugs.owncloud.org/thebuggenie/owncloud/issues/oc-135

Thank you, I hadn't seen this one before.
I started working and toying with a few ideas about this and would like 
to have some feedback.
Especially on the urls.php format.

1) I've used .htaccess to _not_ rewrite these urls so that static files 
continue to work:
(core|files|search|settings|3rdparty)/(ajax|css|js|img)
/apps/(.*)/(ajax|css|js|img)

2) A way to define regex based url patterns:

urls.php:
$urlPatterns = Array(
     Array('url' => '@^/$@', 'function' => 'index.php'),
     Array('url' => '@^/files@', 'url_include' => 'files/urls.php')
);

files/urls.php:
$urlPatterns = Array(
     Array('url' => '@^/$@', 'function' => 'index.php'),
     Array('url' => '@^/download$@', 'function' => 'download.php')
);

In file 'urls.php':
The second line defines the '/' pattern to call the index.php.
The 'function' key can be either a file (for now) or a function in the 
future.
The third line defines that when the url is '/files/whatever' the urls 
file: 'files/urls.php'
is included.

An example getUrlFunction for the dispatcher:

function getUrlFunction($urlPath){
     foreach ($urlPatterns as $pattern)  {
         if (!preg_match($pattern['url'], $urlPath, $match)) {
             continue;
         }
         if (isset($pattern['url_include'])) {
             //ToDo: include the new url patterns
             $newPath = str_replace($match, '', $urlPath);
             return getUrlFunction($urlPath);
         }
         return $pattern['function'];
     }
}

When this works, it would be possible to add more functionality,
such as name based urls:
Array('url' => ' @^/$@', 'function' => 'index.php', 'name' => 'rootIndex')
with a resolve function e.g. getUrlByName that returns a
url based on the name.

Regards,

Roland
>
>> regards,
>>
>> Klaas
>>




More information about the Owncloud mailing list