]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/File.php
Merge commit 'origin/testing' into 0.9.x
[quix0rs-gnu-social.git] / classes / File.php
index 8d91ce50094222117edad8913ac4a1190e0a26c7..4ecd3b959aa9aaef12f4e459decbb173b8f0f7a6 100644 (file)
@@ -169,7 +169,11 @@ class File extends Memcached_DataObject
     {
         require_once 'MIME/Type/Extension.php';
         $mte = new MIME_Type_Extension();
-        $ext = $mte->getExtension($mimetype);
+        try {
+            $ext = $mte->getExtension($mimetype);
+        } catch ( Exception $e) {
+            $ext = strtolower(preg_replace('/\W/', '', $mimetype));
+        }
         $nickname = $profile->nickname;
         $datestamp = strftime('%Y%m%dT%H%M%S', time());
         $random = strtolower(common_confirmation_code(32));
@@ -181,7 +185,7 @@ class File extends Memcached_DataObject
      */
     static function validFilename($filename)
     {
-        return preg_match('^/[A-Za-z0-9._-]+$/', $filename);
+        return preg_match('/^[A-Za-z0-9._-]+$/', $filename);
     }
 
     /**
@@ -228,9 +232,20 @@ class File extends Memcached_DataObject
                 $server = common_config('site', 'server');
             }
 
-            // XXX: protocol
+            $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;
+                }
+            }
 
-            return 'http://'.$server.$path.$filename;
+            $protocol = ($ssl) ? 'https' : 'http';
+
+            return $protocol.'://'.$server.$path.$filename;
         }
     }
 
@@ -275,5 +290,12 @@ class File extends Memcached_DataObject
         }
         return $enclosure;
     }
+
+    // quick back-compat hack, since there's still code using this
+    function isEnclosure()
+    {
+        $enclosure = $this->getEnclosure();
+        return !empty($enclosure);
+    }
 }