From c077ad0775218e6aa8660ba97129ad74b5d54773 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 15 Jun 2009 10:45:50 -0700 Subject: Configurable avatar directory Avatar directory and path are configurable. --- classes/Avatar.php | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'classes') diff --git a/classes/Avatar.php b/classes/Avatar.php index db9d78e47..5e8b315fe 100644 --- a/classes/Avatar.php +++ b/classes/Avatar.php @@ -55,19 +55,43 @@ class Avatar extends Memcached_DataObject static function path($filename) { - return INSTALLDIR . '/avatar/' . $filename; + $dir = common_config('avatar', 'dir'); + + if ($dir[strlen($dir)-1] != '/') { + $dir .= '/'; + } + + return $dir . $filename; } static function url($filename) { - return common_path('avatar/'.$filename); + $path = common_config('avatar', 'path'); + + if ($path[strlen($path)-1] != '/') { + $path .= '/'; + } + + if ($path[0] != '/') { + $path = '/'.$path; + } + + $server = common_config('avatar', 'server'); + + if (empty($server)) { + $server = common_config('site', 'server'); + } + + // XXX: protocol + + return 'http://'.$server.$path.$filename; } function displayUrl() { $server = common_config('avatar', 'server'); if ($server) { - return 'http://'.$server.'/'.$this->filename; + return Avatar::url($this->filename); } else { return $this->url; } -- cgit v1.2.3-54-g00ecf From d6ff702d7f0937451c8595c7b3cbfb9f2813a07b Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 15 Jun 2009 13:34:52 -0700 Subject: Return network from network setup function Return the network from the network setup function. Also, special-case for when we get a server name the same as the wildcard. --- classes/Status_network.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'classes') diff --git a/classes/Status_network.php b/classes/Status_network.php index d2b942bfb..96b6d9a05 100644 --- a/classes/Status_network.php +++ b/classes/Status_network.php @@ -43,12 +43,19 @@ class Status_network extends DB_DataObject { global $config; + $sn = null; + // XXX I18N, probably not crucial for hostnames // XXX This probably needs a tune up if (0 == strncasecmp(strrev($wildcard), strrev($servername), strlen($wildcard))) { - $parts = explode('.', $servername); - $sn = Status_network::staticGet('nickname', strtolower($parts[0])); + // special case for exact match + if (0 == strncmp($servername, $wildcard)) { + $sn = Status_network::staticGet('nickname', ''); + } else { + $parts = explode('.', $servername); + $sn = Status_network::staticGet('nickname', strtolower($parts[0])); + } } else { $sn = Status_network::staticGet('hostname', strtolower($servername)); } @@ -70,9 +77,9 @@ class Status_network extends DB_DataObject $config['site']['logo'] = $sn->logo; } - return true; + return $sn; } else { - return false; + return null; } } } -- cgit v1.2.3-54-g00ecf From 6532f0dff63576c94debe521d1ff8d9f594fe422 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 15 Jun 2009 14:29:25 -0700 Subject: strncmp -> strcasecmp --- classes/Status_network.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'classes') diff --git a/classes/Status_network.php b/classes/Status_network.php index 96b6d9a05..bf05ad61e 100644 --- a/classes/Status_network.php +++ b/classes/Status_network.php @@ -50,7 +50,7 @@ class Status_network extends DB_DataObject if (0 == strncasecmp(strrev($wildcard), strrev($servername), strlen($wildcard))) { // special case for exact match - if (0 == strncmp($servername, $wildcard)) { + if (0 == strcasecmp($servername, $wildcard)) { $sn = Status_network::staticGet('nickname', ''); } else { $parts = explode('.', $servername); -- cgit v1.2.3-54-g00ecf From 587b7a8b2ad0b260cc3159da260a4d439c2a5f0c Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 15 Jun 2009 16:40:53 -0700 Subject: redirect on non-canonical server name --- classes/Status_network.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'classes') diff --git a/classes/Status_network.php b/classes/Status_network.php index bf05ad61e..eef27d765 100644 --- a/classes/Status_network.php +++ b/classes/Status_network.php @@ -61,6 +61,9 @@ class Status_network extends DB_DataObject } if (!empty($sn)) { + if (!empty($sn->hostname) && 0 != strcasecmp($sn->hostname, $servername)) { + $sn->redirectToHostname(); + } $dbhost = (empty($sn->dbhost)) ? 'localhost' : $sn->dbhost; $dbuser = (empty($sn->dbuser)) ? $sn->nickname : $sn->dbuser; $dbpass = $sn->dbpass; @@ -82,4 +85,29 @@ class Status_network extends DB_DataObject return null; } } + + // Code partially mooked from http://www.richler.de/en/php-redirect/ + // (C) 2006 by Heiko Richler http://www.richler.de/ + // LGPL + + function redirectToHostname() + { + $destination = 'http://'.$this->hostname; + $destination .= $_SERVER['REQUEST_URI']. + $_SERVER['QUERY_STRING']; + + $old = 'http'. + (($_SERVER['HTTPS'] == 'on') ? 'S' : ''). + '://'. + $_SERVER['HTTP_HOST']. + $_SERVER['REQUEST_URI']. + $_SERVER['QUERY_STRING']; + if ($old == $destination) { // this would be a loop! + // error_log(...) ? + return false; + } + + common_redirect($destination, 301); + // shouldn't get here + } } -- cgit v1.2.3-54-g00ecf From 2f82a3d44c4fbb0d9c552a2652e341ec882787c1 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 15 Jun 2009 16:43:39 -0700 Subject: forgot some functions aren't available at status time --- classes/Status_network.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'classes') diff --git a/classes/Status_network.php b/classes/Status_network.php index eef27d765..128721f41 100644 --- a/classes/Status_network.php +++ b/classes/Status_network.php @@ -107,7 +107,11 @@ class Status_network extends DB_DataObject return false; } - common_redirect($destination, 301); - // shouldn't get here + header('HTTP/1.1 301 Moved Permanently'); + header("Location: $destination"); + + print "$destination\n"; + + exit; } } -- cgit v1.2.3-54-g00ecf From f80966324560d4309b3bb2d6d357719e1e90e6aa Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 15 Jun 2009 16:51:49 -0700 Subject: a little better query handling in redirect code --- classes/Status_network.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'classes') diff --git a/classes/Status_network.php b/classes/Status_network.php index 128721f41..03e8f4525 100644 --- a/classes/Status_network.php +++ b/classes/Status_network.php @@ -93,8 +93,19 @@ class Status_network extends DB_DataObject function redirectToHostname() { $destination = 'http://'.$this->hostname; - $destination .= $_SERVER['REQUEST_URI']. - $_SERVER['QUERY_STRING']; + $destination .= $_SERVER['REQUEST_URI']; + + $args = $_GET; + + if (isset($args['p'])) { + unset($args['p']); + } + + $query = http_build_query($args); + + if (strlen($query) > 0) { + $destination .= '?' . $query; + } $old = 'http'. (($_SERVER['HTTPS'] == 'on') ? 'S' : ''). -- cgit v1.2.3-54-g00ecf From 8c24a3bc92484d19ed4ba489d2d7b1172f4b355d Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 15 Jun 2009 16:55:01 -0700 Subject: a little better query handling in redirect code --- classes/Status_network.php | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'classes') diff --git a/classes/Status_network.php b/classes/Status_network.php index 03e8f4525..17b688740 100644 --- a/classes/Status_network.php +++ b/classes/Status_network.php @@ -95,18 +95,6 @@ class Status_network extends DB_DataObject $destination = 'http://'.$this->hostname; $destination .= $_SERVER['REQUEST_URI']; - $args = $_GET; - - if (isset($args['p'])) { - unset($args['p']); - } - - $query = http_build_query($args); - - if (strlen($query) > 0) { - $destination .= '?' . $query; - } - $old = 'http'. (($_SERVER['HTTPS'] == 'on') ? 'S' : ''). '://'. -- cgit v1.2.3-54-g00ecf