aboutsummaryrefslogtreecommitdiff
path: root/classes/TidypicsImage.php
diff options
context:
space:
mode:
authorcash <cash.costello@gmail.com>2011-11-19 23:13:26 -0500
committercash <cash.costello@gmail.com>2011-11-19 23:13:26 -0500
commitc51b483f24936c8d04a54a6999412937ec21c49a (patch)
treed45e3b9ede0115e3ce3b84ea1622bfc98d7470a0 /classes/TidypicsImage.php
parent98664daa72a390fe760b69116af8bfa9327826e3 (diff)
downloadelgg-c51b483f24936c8d04a54a6999412937ec21c49a.tar.gz
elgg-c51b483f24936c8d04a54a6999412937ec21c49a.tar.bz2
uploading photos through the basic interface works now
Diffstat (limited to 'classes/TidypicsImage.php')
-rw-r--r--classes/TidypicsImage.php124
1 files changed, 105 insertions, 19 deletions
diff --git a/classes/TidypicsImage.php b/classes/TidypicsImage.php
index 652cc9e9b..c604d869e 100644
--- a/classes/TidypicsImage.php
+++ b/classes/TidypicsImage.php
@@ -3,6 +3,8 @@
* Tidypics Image class
*
* @package TidypicsImage
+ * @author Cash Costello
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2
*/
@@ -18,6 +20,29 @@ class TidypicsImage extends ElggFile {
}
/**
+ *
+ * @warning container_guid must be set first
+ *
+ * @param array $data
+ * @return bool
+ */
+ public function save($data = null) {
+
+ if (!parent::save()) {
+ return false;
+ }
+
+ if ($data) {
+ // new image
+ $this->simpletype = "image";
+ $this->saveImageFile($data);
+ $this->saveThumbnails();
+ }
+
+ return true;
+ }
+
+ /**
* Get the title of the image
*
* @return string
@@ -26,8 +51,13 @@ class TidypicsImage extends ElggFile {
return $this->title;
}
- public function getSrcUrl() {
- return "pg/photos/thumbnail/$this->guid/small/";
+ /**
+ * Get the src URL for the image
+ *
+ * @return string
+ */
+ public function getSrcUrl($size = 'small') {
+ return "photos/thumbnail/$this->guid/$size/";
}
/**
@@ -73,10 +103,8 @@ class TidypicsImage extends ElggFile {
/**
* Set the internal filenames
- *
- * @warning container needs to be set first
*/
- public function setOriginalFilename($originalName) {
+ protected function setOriginalFilename($originalName) {
$prefix = "image/" . $this->container_guid . "/";
$filestorename = elgg_strtolower(time() . $originalName);
$this->setFilename($prefix . $filestorename);
@@ -85,24 +113,23 @@ class TidypicsImage extends ElggFile {
/**
* Save the uploaded image
- *
- * @warning filename needs to be set first
*
- * @param string $uploadedFilename name of the uploaded file
- * @param int $size
+ * @param array $data
*/
- public function saveImageFile($uploadedFilename, $size) {
+ protected function saveImageFile($data) {
+ $this->checkUploadErrors($data);
// we need to make sure the directory for the album exists
// @note for group albums, the photos are distributed among the users
- $dir = tp_get_img_dir() . $this->getContainer();
+ $dir = tp_get_img_dir() . $this->getContainerGUID();
if (!file_exists($dir)) {
mkdir($dir, 0755, true);
}
+ // move the uploaded file into album directory
+ $this->setOriginalFilename($data['name']);
$filename = $this->getFilenameOnFilestore();
-
- $result = move_uploaded_file($uploadedFilename, $filename);
+ $result = move_uploaded_file($data['tmp_name'], $filename);
if (!$result) {
return false;
}
@@ -113,15 +140,42 @@ class TidypicsImage extends ElggFile {
return true;
}
+ protected function checkUploadErrors($data) {
+ // check for upload errors
+ if ($data['error']) {
+ if ($data['error'] == 1) {
+ trigger_error('Tidypics warning: image exceeded server php upload limit', E_USER_WARNING);
+ throw new Exception(elgg_echo('tidypics:image_mem'));
+ } else {
+ throw new Exception(elgg_echo('tidypics:unk_error'));
+ }
+ }
+
+ // must be an image
+ if (!tp_upload_check_format($data['type'])) {
+ throw new Exception(elgg_echo('tidypics:not_image'));
+ }
+
+ // make sure file does not exceed memory limit
+ if (!tp_upload_check_max_size($data['size'])) {
+ throw new Exception(elgg_echo('tidypics:image_mem'));
+ }
+
+ // make sure the in memory image size does not exceed memory available
+ $imginfo = getimagesize($data['tmp_name']);
+ if (!tp_upload_memory_check($image_lib, $imginfo[0] * $imginfo[1])) {
+ trigger_error('Tidypics warning: image memory size too large for resizing so rejecting', E_USER_WARNING);
+ throw new Exception(elgg_echo('tidypics:image_pixels'));
+ }
+ }
+
/**
* Save the image thumbnails
- *
- * @warning container guid and filename must be set
- *
- * @param string $imageLib
*/
- public function saveThumbnails($imageLib) {
- include_once dirname(dirname(__FILE__)) . "/lib/resize.php";
+ protected function saveThumbnails() {
+ elgg_load_library('tidypics:resize');
+
+ $imageLib = elgg_get_plugin_setting('image_lib', 'tidypics');
$prefix = "image/" . $this->container_guid . "/";
$filename = $this->getFilename();
@@ -145,6 +199,38 @@ class TidypicsImage extends ElggFile {
}
/**
+ * Get the image data of a thumbnail
+ *
+ * @param string $size
+ * @return string
+ */
+ public function getThumbnail($size) {
+ switch ($size) {
+ case 'thumb':
+ $thumb = $this->thumbnail;
+ break;
+ case 'small':
+ $thumb = $this->smallthumb;
+ break;
+ case 'large':
+ $thumb = $this->largethumb;
+ break;
+ default:
+ return '';
+ break;
+ }
+
+ if (!$thumb) {
+ return '';
+ }
+
+ $file = new ElggFile();
+ $file->owner_guid = $this->getObjectOwnerGUID();
+ $file->setFilename($thumb);
+ return $file->grabFile();
+ }
+
+ /**
* Extract EXIF Data from image
*
* @warning image file must be saved first