static function url($filename) { if (!self::validFilename($filename)) { // TRANS: Client exception thrown if a file upload does not have a valid name. throw new ClientException(_("Invalid filename.")); } if (common_config('site', 'private')) { return common_local_url('getfile', array('filename' => $filename)); } if (GNUsocial::useHTTPS()) { $sslserver = common_config('attachments', 'sslserver'); if (empty($sslserver)) { // XXX: this assumes that background dir == site dir + /file/ // not true if there's another server if (is_string(common_config('site', 'sslserver')) && mb_strlen(common_config('site', 'sslserver')) > 0) { $server = common_config('site', 'sslserver'); } else { if (common_config('site', 'server')) { $server = common_config('site', 'server'); } } $path = common_config('site', 'path') . '/file/'; } else { $server = $sslserver; $path = common_config('attachments', 'sslpath'); if (empty($path)) { $path = common_config('attachments', 'path'); } } $protocol = 'https'; } else { $path = common_config('attachments', 'path'); $server = common_config('attachments', 'server'); if (empty($server)) { $server = common_config('site', 'server'); } $ssl = common_config('attachments', 'ssl'); $protocol = $ssl ? 'https' : 'http'; } if ($path[strlen($path) - 1] != '/') { $path .= '/'; } if ($path[0] != '/') { $path = '/' . $path; } return $protocol . '://' . $server . $path . $filename; }