]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/File.php
Fix option settings on oauth_post_notice.php
[quix0rs-gnu-social.git] / classes / File.php
index 18ad828925359f27c22c6b765f3ba3d4397ba35c..da029e39b69b0641262faca5895971791ca1e593 100644 (file)
@@ -29,7 +29,6 @@ require_once INSTALLDIR.'/classes/File_to_post.php';
 /**
  * Table Definition for file
  */
-
 class File extends Memcached_DataObject
 {
     ###START_AUTOCODE
@@ -140,7 +139,7 @@ class File extends Memcached_DataObject
                     $redir_data = array();
                 } else {
                     // TRANS: Server exception thrown when a URL cannot be processed.
-                    throw new ServerException(_("Cannot process URL '$given_url'"));
+                    throw new ServerException(sprintf(_("Cannot process URL '%s'"), $given_url));
                 }
                 // TODO: max field length
                 if ($redir_url === $given_url || strlen($redir_url) > 255 || !$followRedirects) {
@@ -262,22 +261,41 @@ class File extends Memcached_DataObject
             // TRANS: Client exception thrown if a file upload does not have a valid name.
             throw new ClientException(_("Invalid filename."));
         }
-        if(common_config('site','private')) {
+
+        if (common_config('site','private')) {
 
             return common_local_url('getfile',
                                 array('filename' => $filename));
 
-        } else {
-            $path = common_config('attachments', 'path');
+        }
 
-            if ($path[strlen($path)-1] != '/') {
-                $path .= '/';
-            }
+        if (StatusNet::isHTTPS()) {
 
-            if ($path[0] != '/') {
-                $path = '/'.$path;
+            $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)) {
@@ -286,19 +304,18 @@ class File extends Memcached_DataObject
 
             $ssl = common_config('attachments', 'ssl');
 
-            if (is_null($ssl)) { // null -> guess
-                if (common_config('site', 'ssl') == 'always' &&
-                    !common_config('attachments', 'server')) {
-                    $ssl = true;
-                } else {
-                    $ssl = false;
-                }
-            }
-
             $protocol = ($ssl) ? 'https' : 'http';
+        }
 
-            return $protocol.'://'.$server.$path.$filename;
+        if ($path[strlen($path)-1] != '/') {
+            $path .= '/';
         }
+
+        if ($path[0] != '/') {
+            $path = '/'.$path;
+        }
+
+        return $protocol.'://'.$server.$path.$filename;
     }
 
     function getEnclosure(){