[RFC] Directory and URL constants

Note: We are moving the topics of this forum and it will be deleted at some point

Publish your own request for comments/change or patches for the next version of phpBB. Discuss the contributions and proposals of others. Upcoming releases are 3.2/Rhea and 3.3.
Post Reply
devTristan
Registered User
Posts: 1
Joined: Tue Jul 06, 2010 2:23 am

[RFC] Directory and URL constants

Post by devTristan »

I don't really understand what an RFC is exactly, but I think I have a fair idea. Forgive me of I do this wrong. I don't really know the format for these, so I'll just get right into it.

I think that phpBB3 handles paths and URLs poorly. If you have rewrite rules, sometimes it won't show the css properly, or link you to a page in the wrong directory. The template vars that refer to paths also seem to miss a lot. I think the system should be changed quite a bit. I think that the following should be added to the config.php file and editable through the ACP:

Code: Select all

define('EXT', substr(__FILE__, strrpos(__FILE__, '.')));
$file = explode('/', __FILE__);
array_pop($file);
$dir = implode('/', $file);

define('DIR_BASE', $dir.'/');
$dir_constants = array(
    'ADM' => 'adm/',
    'CACHE' => 'cache/',
    'DOWNLOAD' => 'download/',
    'FILES' => 'files/',
    'IMAGES' => 'images/',
    'INCLUDES' => 'includes/',
    'LANGUAGE' => 'language/',
    'STORE' => 'store/',
    'STYLES' => 'styles/',
    'THEME' => 'styles/prosilver/theme/',
    'TEMPLATE' => 'styles/prosilver/template/'
    //and so on and so on...
    );
$url_constants = array(
    'ADM' => URL_BASE.'adm/',
    'CACHE' => URL_BASE.'cache/',
    'DOWNLOAD' => URL_BASE.'download/',
    'FILES' => URL_BASE.'files/',
    'IMAGES' => URL_BASE.'images/',
    'INCLUDES' => URL_BASE.'includes/',
    'LANGUAGE' => URL_BASE.'language/',
    'STORE' => URL_BASE.'store/',
    'STYLES' => URL_BASE.'styles/',
    'THEME' => URL_BASE.'styles/prosilver/theme/',
    'TEMPLATE' => URL_BASE.'styles/prosilver/template/'
    //and so on and so on...
    );
foreach ($dir_constants as $name => $path)
    {
    define('DIR_'.$name, DIR_BASE.$path);
    }

define('URL_BASEDIR', 'phpBB3/');
$url = substr($_SERVER['REQUEST_URI'], strlen(URL_BASEDIR+1);
define('URL', $url);
$substr_count = substr_count(URL, '/');
define('URL_BASE', ($substr_count) ? str_repeat('../', $substr_count) : './');
foreach ($url_constants as $name => $path)
    {
    define('URL_'.$name, $path);
    }
 
That would define the following constants with example values:

DIR_BASE: /var/www/phpBB3/
DIR_ADM: /var/www/phpBB3/adm/
DIR_CACHE: /var/www/phpBB3/cache/
DIR_DOWNLOAD: /var/www/phpBB3/download/
DIR_FILES: /var/www/phpBB3/files/
DIR_IMAGES: /var/www/phpBB3/images/
DIR_INCLUDES: /var/www/phpBB3/includes/
DIR_LANGUAGE: /var/www/phpBB3/language/
DIR_STORE: /var/www/phpBB3/store/
DIR_STYLES: /var/www/phpBB3/styles/
DIR_THEME: /var/www/phpBB3/styles/prosilver/theme/
DIR_TEMPLATE: /var/www/phpBB3/styles/prosilver/template/
URL_BASE: ../phpBB3/
URL_ADM: ../phpBB3/adm/
URL_CACHE: ../phpBB3/cache/
URL_DOWNLOAD: ../phpBB3/download/
URL_FILES: ../phpBB3/files/
URL_IMAGES: ../phpBB3/images/
URL_INCLUDES: ../phpBB3/includes/
URL_LANGUAGE: ../phpBB3/language/
URL_STORE: ../phpBB3/store/
URL_STYLES: ../phpBB3/styles/
URL_THEME: ../phpBB3/styles/prosilver/theme/
URL_TEMPLATE: ../phpBB3/styles/prosilver/template/
URL: index.php
URL_BASEDIR: phpBB3/


The configuration would be a list of path names, input boxes for user defined paths. You could set the image url to http://my_super_awesome_cdn.com/ and use your super awesome cdn to deliver images. The dir constants would be used all over phpbb in includes/requires and other operations on local files. All of the constants would also be template variables. This would allow for flexibility in the file and url structure.

If this is too much work, I propose that only some basic constants are set, like so:

Code: Select all

define('EXT', substr(__FILE__, strrpos(__FILE__, '.')));
$file = explode('/', __FILE__);
array_pop($file);
$dir = implode('/', $file);

define('DIR_BASE', $dir.'/');

define('URL_BASEDIR', 'phpBB3/');

$url = substr($_SERVER['REQUEST_URI'], strlen(URL_BASEDIR+1);
define('URL', $url);
$substr_count = substr_count(URL, '/');
define('URL_BASE', ($substr_count) ? str_repeat('../', $substr_count) : './');
 
That would define DIR_BASE, URL_BASEDIR, URL, and URL_BASE. Also, if T_THEME_PATH and so on were based on those constants, there would be no url rewriting issues. This minimal approach wouldn't be configurable.

Post Reply