aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorCash Costello <cash.costello@gmail.com>2010-10-24 21:08:27 +0000
committerCash Costello <cash.costello@gmail.com>2010-10-24 21:08:27 +0000
commitda1493b95a2f0b5000a487ae373c9318c58d0b2d (patch)
treea339b053ade9fb15a1717bdf248a59afc9b3d239 /lib
parent5161b1c8fdc8ff69005f864a89127fc18db6d4ed (diff)
downloadelgg-da1493b95a2f0b5000a487ae373c9318c58d0b2d.tar.gz
elgg-da1493b95a2f0b5000a487ae373c9318c58d0b2d.tar.bz2
partial implementation of flash uploader
Diffstat (limited to 'lib')
-rw-r--r--lib/image.php20
-rw-r--r--lib/upload.php78
2 files changed, 93 insertions, 5 deletions
diff --git a/lib/image.php b/lib/image.php
index 51b31f6d7..c68560df6 100644
--- a/lib/image.php
+++ b/lib/image.php
@@ -55,12 +55,22 @@ class TidypicsImage extends ElggFile {
*
* @warning filename needs to be set first
*
- * @param string $image
+ * @param string $uploadedFilename name of the uploaded file
+ * @param int $size
*/
- public function saveImageFile($image) {
- $this->open("write");
- $this->write($image);
- $this->close();
+ public function saveImageFile($uploadedFilename, $size) {
+
+ $filename = $this->getFilenameOnFilestore();
+
+ $result = move_uploaded_file($uploadedFilename, $filename);
+ if (!$result) {
+ return false;
+ }
+
+ $owner = $this->getOwnerEntity();
+ $owner->image_repo_size = (int)$owner->image_repo_size + $size;
+
+ return true;
}
/**
diff --git a/lib/upload.php b/lib/upload.php
index a7dd7611d..ac926403d 100644
--- a/lib/upload.php
+++ b/lib/upload.php
@@ -3,6 +3,34 @@
* Helper library for working with uploads
*/
+/**
+ * Guess on the mimetype based on file extension
+ *
+ * @param string $originalName
+ * @return string
+ */
+function tp_upload_get_mimetype($originalName) {
+ $extension = substr(strrchr($originalName, '.'), 1);
+ switch ($extension) {
+ case 'png':
+ return 'image/png';
+ break;
+ case 'gif':
+ return 'image/gif';
+ break;
+ case 'jpg':
+ default:
+ return 'image/jpeg';
+ break;
+ }
+}
+
+/**
+ * Check if this is an image
+ *
+ * @param string $mime
+ * @return bool false = not image
+ */
function tp_upload_check_format($mime) {
$accepted_formats = array(
'image/jpeg',
@@ -18,6 +46,13 @@ function tp_upload_check_format($mime) {
return true;
}
+/**
+ * Check if there is enough memory to process this image
+ *
+ * @param string $image_lib
+ * @param int $num_pixels
+ * @return bool false = not enough memory
+ */
function tp_upload_memory_check($image_lib, $num_pixels) {
if ($image_lib !== 'GD') {
return true;
@@ -35,4 +70,47 @@ function tp_upload_memory_check($image_lib, $num_pixels) {
}
return true;
+}
+
+/**
+ * Check if image is within limits
+ *
+ * @param int $image_size
+ * @return bool false = too large
+ */
+function tp_upload_check_max_size($image_size) {
+ $max_file_size = (float) get_plugin_setting('maxfilesize','tidypics');
+ if (!$max_file_size) {
+ // default to 5 MB if not set
+ $max_file_size = 5;
+ }
+ // convert to bytes from MBs
+ $max_file_size = 1024 * 1024 * $max_file_size;
+ return $image_size <= $max_file_size;
+}
+
+/**
+ * Check if this image pushes user over quota
+ *
+ * @param int $image_size
+ * @param int $owner_guid
+ * @return bool false = exceed quota
+ */
+function tp_upload_check_quota($image_size, $owner_guid) {
+ static $quota;
+
+ if (!isset($quota)) {
+ $quota = get_plugin_setting('quota','tidypics');
+ $quota = 1024 * 1024 * $quota;
+ }
+
+ if ($quota == 0) {
+ // no quota
+ return true;
+ }
+
+ $image_repo_size_md = get_metadata_byname($owner_guid, "image_repo_size");
+ $image_repo_size = (int)$image_repo_size_md->value;
+
+ return ($image_repo_size + $image_size) < $quota;
} \ No newline at end of file