summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorZach Copley <zach@controlyourself.ca>2009-06-15 21:24:22 -0700
committerZach Copley <zach@controlyourself.ca>2009-06-15 21:24:22 -0700
commit44343986c31b20158ef07438f85a6bf35b93a3ab (patch)
treedb0df1a417ffbce747d59ae9bdc8647bdbd9ea31 /classes
parente7e3709ae0294b8400b85d87f2ebeade5b31858d (diff)
parent8c24a3bc92484d19ed4ba489d2d7b1172f4b355d (diff)
Merge branch '0.8.x' into userdesign
* 0.8.x: a little better query handling in redirect code a little better query handling in redirect code forgot some functions aren't available at status time redirect on non-canonical server name don't show create-a-group link if not logged in allow a configured base for cache keys Missing call to getProfile() caused verify_credentials to fail. change mods for setup script Script to set up new status networks strncmp -> strcasecmp Return network from network setup function Configurable avatar directory
Diffstat (limited to 'classes')
-rw-r--r--classes/Avatar.php30
-rw-r--r--classes/Status_network.php44
2 files changed, 68 insertions, 6 deletions
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;
}
diff --git a/classes/Status_network.php b/classes/Status_network.php
index d2b942bfb..17b688740 100644
--- a/classes/Status_network.php
+++ b/classes/Status_network.php
@@ -43,17 +43,27 @@ 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 == strcasecmp($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));
}
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;
@@ -70,9 +80,37 @@ class Status_network extends DB_DataObject
$config['site']['logo'] = $sn->logo;
}
- return true;
+ return $sn;
} else {
+ 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'];
+
+ $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;
}
+
+ header('HTTP/1.1 301 Moved Permanently');
+ header("Location: $destination");
+
+ print "<a href='$destination'>$destination</a>\n";
+
+ exit;
}
}