]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
common function for turning a relative path into a full URL
authorEvan Prodromou <evan@prodromou.name>
Fri, 30 May 2008 16:24:29 +0000 (12:24 -0400)
committerEvan Prodromou <evan@prodromou.name>
Fri, 30 May 2008 16:24:29 +0000 (12:24 -0400)
darcs-hash:20080530162429-84dde-12336814d3a01b4937ab574741fa4987484be62d.gz

lib/common.php
lib/util.php

index 1c11bd13af081181085cf2ee11caa7f33695c64f..1954dfc2ab343a26f798067918405da2e920af86 100644 (file)
@@ -48,9 +48,7 @@ $config =
                          'title' => 'Creative Commons Attribution 3.0',
                          'image' => 'http://i.creativecommons.org/l/by/3.0/88x31.png'),
                'avatar' =>
-               array('directory' => INSTALLDIR . '/avatar',
-                         'path' => '/avatar',
-                         'default' => 
+               array('default' => 
                          array('profile' => 'theme/default/image/default-avatar-profile.png',
                                        'stream' => 'theme/default/image/default-avatar-stream.png',
                                        'mini' => 'theme/default/image/default-avatar-mini.png')));
index 2d4fc276670d485eff9a36ca2cd5e421fd45f546..72876cef734a1a26474380fda67fc6f8e3dc9923 100644 (file)
@@ -102,15 +102,15 @@ function common_show_header($pagetitle, $callable=NULL, $data=NULL) {
                                   $pagetitle . " - " . $config['site']['name']);
        common_element('link', array('rel' => 'stylesheet',
                                                                 'type' => 'text/css',
-                                                                'href' => $config['site']['path'] . 'theme/default/style/html.css',
+                                                                'href' => common_path('theme/default/style/html.css'),
                                                                 'media' => 'screen, projection, tv'));
        common_element('link', array('rel' => 'stylesheet',
                                                                 'type' => 'text/css',
-                                                                'href' => $config['site']['path'] . 'theme/default/style/layout.css',
+                                                                'href' => common_path('theme/default/style/layout.css'),
                                                                 'media' => 'screen, projection, tv'));
        common_element('link', array('rel' => 'stylesheet',
                                                                 'type' => 'text/css',
-                                                                'href' => $config['site']['path'] . 'theme/default/style/print.css',
+                                                                'href' => common_path('theme/default/style/print.css'),
                                                                 'media' => 'print'));
        if ($callable) {
                if ($data) {
@@ -407,12 +407,11 @@ function common_avatar_filename($user, $extension, $size=NULL, $extra=NULL) {
 
 function common_avatar_path($filename) {
        global $config;
-       return $config['avatar']['directory'] . '/' . $filename;
+       return INSTALLDIR . '/avatar/' . $filename;
 }
 
 function common_avatar_url($filename) {
-       global $config;
-       return "http://".$config['site']['server'].$config['avatar']['path'].'/'.$filename;
+       return common_path('avatar/'.$filename);
 }
 
 function common_default_avatar($size) {
@@ -420,11 +419,11 @@ function common_default_avatar($size) {
                                                          AVATAR_STREAM_SIZE => 'stream',
                                                          AVATAR_MINI_SIZE => 'mini');
        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) {
-       global $config;
        /* XXX: pretty URLs */
        $extra = '';
        if ($args) {
@@ -432,8 +431,13 @@ function common_local_url($action, $args=NULL) {
                        $extra .= "&${key}=${value}";
                }
        }
+       return common_path("index.php?action=${action}${extra}");
+}
+
+function common_path($relative) {
+       global $config;
        $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) {
@@ -488,9 +492,7 @@ function common_mint_tag($extra) {
 # Should make up a reasonable root URL
 
 function common_root_url() {
-       global $config;
-       $pathpart = ($config['site']['path']) ? $config['site']['path']."/" : '';
-       return "http://".$config['site']['server'].'/'.$pathpart;
+       return common_path('');
 }
 
 # returns $bytes bytes of random data as a hexadecimal string