common function for turning a relative path into a full URL

darcs-hash:20080530162429-84dde-12336814d3a01b4937ab574741fa4987484be62d.gz
This commit is contained in:
Evan Prodromou 2008-05-30 12:24:29 -04:00
parent c501b7b925
commit f8a070394f
2 changed files with 15 additions and 15 deletions

View File

@ -48,9 +48,7 @@ $config =
'title' => 'Creative Commons Attribution 3.0', 'title' => 'Creative Commons Attribution 3.0',
'image' => 'http://i.creativecommons.org/l/by/3.0/88x31.png'), 'image' => 'http://i.creativecommons.org/l/by/3.0/88x31.png'),
'avatar' => 'avatar' =>
array('directory' => INSTALLDIR . '/avatar', array('default' =>
'path' => '/avatar',
'default' =>
array('profile' => 'theme/default/image/default-avatar-profile.png', array('profile' => 'theme/default/image/default-avatar-profile.png',
'stream' => 'theme/default/image/default-avatar-stream.png', 'stream' => 'theme/default/image/default-avatar-stream.png',
'mini' => 'theme/default/image/default-avatar-mini.png'))); 'mini' => 'theme/default/image/default-avatar-mini.png')));

View File

@ -102,15 +102,15 @@ function common_show_header($pagetitle, $callable=NULL, $data=NULL) {
$pagetitle . " - " . $config['site']['name']); $pagetitle . " - " . $config['site']['name']);
common_element('link', array('rel' => 'stylesheet', common_element('link', array('rel' => 'stylesheet',
'type' => 'text/css', 'type' => 'text/css',
'href' => $config['site']['path'] . 'theme/default/style/html.css', 'href' => common_path('theme/default/style/html.css'),
'media' => 'screen, projection, tv')); 'media' => 'screen, projection, tv'));
common_element('link', array('rel' => 'stylesheet', common_element('link', array('rel' => 'stylesheet',
'type' => 'text/css', 'type' => 'text/css',
'href' => $config['site']['path'] . 'theme/default/style/layout.css', 'href' => common_path('theme/default/style/layout.css'),
'media' => 'screen, projection, tv')); 'media' => 'screen, projection, tv'));
common_element('link', array('rel' => 'stylesheet', common_element('link', array('rel' => 'stylesheet',
'type' => 'text/css', 'type' => 'text/css',
'href' => $config['site']['path'] . 'theme/default/style/print.css', 'href' => common_path('theme/default/style/print.css'),
'media' => 'print')); 'media' => 'print'));
if ($callable) { if ($callable) {
if ($data) { if ($data) {
@ -407,12 +407,11 @@ function common_avatar_filename($user, $extension, $size=NULL, $extra=NULL) {
function common_avatar_path($filename) { function common_avatar_path($filename) {
global $config; global $config;
return $config['avatar']['directory'] . '/' . $filename; return INSTALLDIR . '/avatar/' . $filename;
} }
function common_avatar_url($filename) { function common_avatar_url($filename) {
global $config; return common_path('avatar/'.$filename);
return "http://".$config['site']['server'].$config['avatar']['path'].'/'.$filename;
} }
function common_default_avatar($size) { function common_default_avatar($size) {
@ -420,11 +419,11 @@ function common_default_avatar($size) {
AVATAR_STREAM_SIZE => 'stream', AVATAR_STREAM_SIZE => 'stream',
AVATAR_MINI_SIZE => 'mini'); AVATAR_MINI_SIZE => 'mini');
global $config; global $config;
return "http://".$config['site']['server'].$config['site']['path'].'/'.$config['avatar']['default'][$sizenames[$size]];
return common_path($config['avatar']['default'][$sizenames[$size]]);
} }
function common_local_url($action, $args=NULL) { function common_local_url($action, $args=NULL) {
global $config;
/* XXX: pretty URLs */ /* XXX: pretty URLs */
$extra = ''; $extra = '';
if ($args) { if ($args) {
@ -432,8 +431,13 @@ function common_local_url($action, $args=NULL) {
$extra .= "&${key}=${value}"; $extra .= "&${key}=${value}";
} }
} }
return common_path("index.php?action=${action}${extra}");
}
function common_path($relative) {
global $config;
$pathpart = ($config['site']['path']) ? $config['site']['path']."/" : ''; $pathpart = ($config['site']['path']) ? $config['site']['path']."/" : '';
return "http://".$config['site']['server'].'/'.$pathpart."index.php?action=${action}${extra}"; return "http://".$config['site']['server'].'/'.$pathpart.$relative;
} }
function common_date_string($dt) { function common_date_string($dt) {
@ -488,9 +492,7 @@ function common_mint_tag($extra) {
# Should make up a reasonable root URL # Should make up a reasonable root URL
function common_root_url() { function common_root_url() {
global $config; return common_path('');
$pathpart = ($config['site']['path']) ? $config['site']['path']."/" : '';
return "http://".$config['site']['server'].'/'.$pathpart;
} }
# returns $bytes bytes of random data as a hexadecimal string # returns $bytes bytes of random data as a hexadecimal string