aboutsummaryrefslogtreecommitdiff
path: root/mod/lightpics/actions/photos
diff options
context:
space:
mode:
Diffstat (limited to 'mod/lightpics/actions/photos')
-rw-r--r--mod/lightpics/actions/photos/admin/create_thumbnails.php70
-rw-r--r--mod/lightpics/actions/photos/admin/imtest.php18
-rw-r--r--mod/lightpics/actions/photos/admin/settings.php29
-rw-r--r--mod/lightpics/actions/photos/admin/upgrade.php52
-rw-r--r--mod/lightpics/actions/photos/album/save.php48
-rw-r--r--mod/lightpics/actions/photos/album/set_cover.php23
-rw-r--r--mod/lightpics/actions/photos/album/sort.php21
-rw-r--r--mod/lightpics/actions/photos/batch/edit.php42
-rw-r--r--mod/lightpics/actions/photos/delete.php48
-rw-r--r--mod/lightpics/actions/photos/image/save.php40
-rw-r--r--mod/lightpics/actions/photos/image/upload.php147
11 files changed, 538 insertions, 0 deletions
diff --git a/mod/lightpics/actions/photos/admin/create_thumbnails.php b/mod/lightpics/actions/photos/admin/create_thumbnails.php
new file mode 100644
index 000000000..dfb5d4ed1
--- /dev/null
+++ b/mod/lightpics/actions/photos/admin/create_thumbnails.php
@@ -0,0 +1,70 @@
+<?php
+/**
+ * Tidypics Thumbnail Creation Test
+ *
+ * Called through ajax, but registered as an Elgg action.
+ *
+ */
+
+elgg_load_library('tidypics:resize');
+
+$guid = get_input('guid');
+$image = get_entity($guid);
+
+if (!$image || !($image instanceof TidypicsImage)) {
+ register_error(elgg_echo('tidypics:thumbnail_tool:unknown_image'));
+ forward(REFERER);
+}
+
+$filename = $image->getFilename();
+$container_guid = $image->container_guid;
+if (!$filename || !$container_guid) {
+ register_error(elgg_echo('tidypics:thumbnail_tool:invalid_image_info'));
+ forward(REFERER);
+}
+
+$title = $image->getTitle();
+$prefix = "image/$container_guid/";
+$filestorename = substr($filename, strlen($prefix));
+
+$image_lib = elgg_get_plugin_setting('image_lib', 'tidypics');
+if (!$image_lib) {
+ $image_lib = "GD";
+}
+
+// ImageMagick command line
+if ($image_lib == 'ImageMagick') {
+ if (!tp_create_im_cmdline_thumbnails($image, $prefix, $filestorename)) {
+ trigger_error('Tidypics warning: failed to create thumbnails - ImageMagick command line', E_USER_WARNING);
+ register_error(elgg_echo('tidypics:thumbnail_tool:create_failed'));
+ forward(REFERER);
+ }
+
+// imagick PHP extension
+} else if ($image_lib == 'ImageMagickPHP') {
+ if (!tp_create_imagick_thumbnails($image, $prefix, $filestorename)) {
+ trigger_error('Tidypics warning: failed to create thumbnails - ImageMagick PHP', E_USER_WARNING);
+ register_error(elgg_echo('tidypics:thumbnail_tool:create_failed'));
+ forward(REFERER);
+ }
+// gd
+} else {
+ if (!tp_create_gd_thumbnails($image, $prefix, $filestorename)) {
+ trigger_error('Tidypics warning: failed to create thumbnails - GD', E_USER_WARNING);
+ register_error(elgg_echo('tidypics:thumbnail_tool:create_failed'));
+ forward(REFERER);
+ }
+}
+
+$url = elgg_normalize_url("photos/thumbnail/$guid/large");
+system_message(elgg_echo('tidypics:thumbnail_tool:created'));
+
+if (elgg_is_xhr()) {
+ echo json_encode(array(
+ 'guid' => $guid,
+ 'title' => $title,
+ 'thumbnail_src' => $url
+ ));
+}
+
+forward(REFERER); \ No newline at end of file
diff --git a/mod/lightpics/actions/photos/admin/imtest.php b/mod/lightpics/actions/photos/admin/imtest.php
new file mode 100644
index 000000000..a58643d0e
--- /dev/null
+++ b/mod/lightpics/actions/photos/admin/imtest.php
@@ -0,0 +1,18 @@
+<?php
+/**
+ * Tidypics ImageMagick Location Test
+ *
+ * Called through ajax. Not a registered Elgg action.
+ */
+
+$location = $_GET['location'];
+
+$command = $location . "convert -version";
+
+$result = system($command, $return_val);
+
+if ($return_val == 0) {
+ echo $result;
+} else {
+ echo "Unable to run ImageMagick. Please check the path.";
+}
diff --git a/mod/lightpics/actions/photos/admin/settings.php b/mod/lightpics/actions/photos/admin/settings.php
new file mode 100644
index 000000000..aa607756d
--- /dev/null
+++ b/mod/lightpics/actions/photos/admin/settings.php
@@ -0,0 +1,29 @@
+<?php
+/**
+ * Save Tidypics plugin settings
+ *
+ * @author Cash Costello
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2
+ */
+
+$params = get_input('params');
+foreach ($params as $k => $v) {
+ if (!elgg_set_plugin_setting($k, $v, 'lightpics')) {
+ register_error(elgg_echo('plugins:settings:save:fail', array('lightpics')));
+ forward(REFERER);
+ }
+}
+
+// image sizes
+$image_sizes = array();
+$image_sizes['large_image_width'] = get_input('large_image_width');
+$image_sizes['large_image_height'] = get_input('large_image_height');
+$image_sizes['small_image_width'] = get_input('small_image_width');
+$image_sizes['small_image_height'] = get_input('small_image_height');
+$image_sizes['tiny_image_width'] = get_input('tiny_image_width');
+$image_sizes['tiny_image_height'] = get_input('tiny_image_height');
+elgg_set_plugin_setting('image_sizes', serialize($image_sizes), 'lightpics');
+
+
+system_message(elgg_echo('tidypics:settings:save:ok'));
+forward(REFERER);
diff --git a/mod/lightpics/actions/photos/admin/upgrade.php b/mod/lightpics/actions/photos/admin/upgrade.php
new file mode 100644
index 000000000..db09ed035
--- /dev/null
+++ b/mod/lightpics/actions/photos/admin/upgrade.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * Tidypics upgrade action
+ */
+
+$plugins_path = elgg_get_plugins_path();
+
+require_once "{$plugins_path}lightpics/version.php";
+
+$local_version = elgg_get_plugin_setting('version', 'tidypics');
+
+$local_version = 2009082901;
+if ($version <= $local_version) {
+ register_error('No upgrade required');
+ forward(REFERER);
+}
+
+set_time_limit(0);
+
+$base_dir = "{$plugins_path}lightpics/upgrades";
+
+
+// taken from engine/lib/version.php
+if ($handle = opendir($base_dir)) {
+ $upgrades = array();
+
+ while ($updatefile = readdir($handle)) {
+ // Look for upgrades and add to upgrades list
+ if (!is_dir("$base_dir/$updatefile")) {
+ if (preg_match('/^([0-9]{10})\.(php)$/', $updatefile, $matches)) {
+ $plugin_version = (int) $matches[1];
+ if ($plugin_version > $local_version) {
+ $upgrades[] = "$base_dir/$updatefile";
+ }
+ }
+ }
+ }
+
+ // Sort and execute
+ asort($upgrades);
+
+ if (sizeof($upgrades) > 0) {
+ foreach ($upgrades as $upgrade) {
+ include($upgrade);
+ }
+ }
+}
+
+elgg_set_plugin_setting('version', $version, 'tidypics');
+
+system_message("Tidypics has been upgraded");
+forward(REFERER);
diff --git a/mod/lightpics/actions/photos/album/save.php b/mod/lightpics/actions/photos/album/save.php
new file mode 100644
index 000000000..cc7181678
--- /dev/null
+++ b/mod/lightpics/actions/photos/album/save.php
@@ -0,0 +1,48 @@
+<?php
+/**
+ * Save album action
+ *
+ * @author Cash Costello
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2
+ */
+
+
+// Get input data
+$title = get_input('title');
+$description = get_input('description');
+$tags = get_input('tags');
+$access_id = get_input('access_id');
+$container_guid = get_input('container_guid', elgg_get_logged_in_user_guid());
+$guid = get_input('guid');
+
+elgg_make_sticky_form('tidypics');
+
+if (empty($title)) {
+ register_error(elgg_echo("album:blank"));
+ forward(REFERER);
+}
+
+if ($guid) {
+ $album = get_entity($guid);
+} else {
+ $album = new TidypicsAlbum();
+}
+
+$album->container_guid = $container_guid;
+$album->owner_guid = elgg_get_logged_in_user_guid();
+$album->access_id = $access_id;
+$album->title = $title;
+$album->description = $description;
+if ($tags) {
+ $album->tags = string_to_tag_array($tags);
+}
+
+if (!$album->save()) {
+ register_error(elgg_echo("album:error"));
+ forward(REFERER);
+}
+
+elgg_clear_sticky_form('tidypics');
+
+system_message(elgg_echo("album:created"));
+forward($album->getURL());
diff --git a/mod/lightpics/actions/photos/album/set_cover.php b/mod/lightpics/actions/photos/album/set_cover.php
new file mode 100644
index 000000000..b37bb9c90
--- /dev/null
+++ b/mod/lightpics/actions/photos/album/set_cover.php
@@ -0,0 +1,23 @@
+<?php
+/**
+ * Set album cover image
+ */
+
+// Get input data
+$album_guid = get_input('album_guid');
+$image_guid = get_input('image_guid');
+
+$album = get_entity($album_guid);
+
+if (!elgg_instanceof($album, 'object', 'album')) {
+ register_error(elgg_echo('album:invalid_album'));
+ forward(REFERER);
+}
+
+if ($album->setCoverImageGuid($image_guid)) {
+ system_message(elgg_echo('album:save_cover_image'));
+ forward(REFERER);
+} else {
+ register_error(elgg_echo('album:cannot_save_cover_image'));
+ forward(REFERER);
+} \ No newline at end of file
diff --git a/mod/lightpics/actions/photos/album/sort.php b/mod/lightpics/actions/photos/album/sort.php
new file mode 100644
index 000000000..fd62a7ba7
--- /dev/null
+++ b/mod/lightpics/actions/photos/album/sort.php
@@ -0,0 +1,21 @@
+<?php
+/**
+ * Sorting album action - takes a comma separated list of image guids
+ */
+
+$album_guid = get_input('album_guid');
+$album = get_entity($album_guid);
+if (!$album) {
+
+}
+
+$guids = get_input('guids');
+$guids = explode(',', $guids);
+
+if ($album->setImageList($guids)) {
+ system_message(elgg_echo('tidypics:album:sorted', array($album->getTitle())));
+} else {
+ register_error(elgg_echo('tidypics:album:could_not_sort', array($album->getTitle())));
+}
+
+forward($album->getURL()); \ No newline at end of file
diff --git a/mod/lightpics/actions/photos/batch/edit.php b/mod/lightpics/actions/photos/batch/edit.php
new file mode 100644
index 000000000..6d376a9db
--- /dev/null
+++ b/mod/lightpics/actions/photos/batch/edit.php
@@ -0,0 +1,42 @@
+<?php
+/**
+ * Edit the images in a batch
+ *
+ * @author Cash Costello
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2
+ */
+
+$guids = get_input('guid');
+$titles = get_input('title');
+$captions = get_input('caption');
+$tags = get_input('tags');
+
+$not_updated = array();
+foreach ($guids as $key => $guid) {
+ $image = get_entity($guid);
+
+ if ($image->canEdit()) {
+
+ // set title appropriately
+ if ($titles[$key]) {
+ $image->title = $titles[$key];
+ } else {
+ $image->title = substr($image->originalfilename, 0, strrpos($image->originalfilename, '.'));
+ }
+
+ // set description appropriately
+ $image->description = $captions[$key];
+ $image->tags = string_to_tag_array($tags[$key]);
+
+ if (!$image->save()) {
+ array_push($not_updated, $image->getGUID());
+ }
+ }
+}
+
+if (count($not_updated) > 0) {
+ register_error(elgg_echo("images:notedited"));
+} else {
+ system_message(elgg_echo("images:edited"));
+}
+forward($image->getContainerEntity()->getURL());
diff --git a/mod/lightpics/actions/photos/delete.php b/mod/lightpics/actions/photos/delete.php
new file mode 100644
index 000000000..f8d194e55
--- /dev/null
+++ b/mod/lightpics/actions/photos/delete.php
@@ -0,0 +1,48 @@
+<?php
+/**
+ * Delete album or image
+ *
+ * @author Cash Costello
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2
+ */
+
+$guid = (int) get_input('guid');
+$entity = get_entity($guid);
+if (!$entity) {
+ // unable to get Elgg entity
+ register_error(elgg_echo("tidypics:deletefailed"));
+ forward(REFERER);
+}
+
+if (!$entity->canEdit()) {
+ // user doesn't have permissions
+ register_error(elgg_echo("tidypics:deletefailed"));
+ forward(REFERER);
+}
+
+$container = $entity->getContainerEntity();
+
+$subtype = $entity->getSubtype();
+switch ($subtype) {
+ case 'album':
+ if (elgg_instanceof($container, 'user')) {
+ $forward_url = "photos/owner/$container->username";
+ } else {
+ $forward_url = "photos/group/$container->guid/all";
+ }
+ break;
+ case 'image':
+ $forward_url = $container->getURL();
+ break;
+ default:
+ forward(REFERER);
+ break;
+}
+
+if ($entity->delete()) {
+ system_message(elgg_echo("tidypics:deleted"));
+} else {
+ register_error(elgg_echo("tidypics:deletefailed"));
+}
+
+forward($forward_url);
diff --git a/mod/lightpics/actions/photos/image/save.php b/mod/lightpics/actions/photos/image/save.php
new file mode 100644
index 000000000..1cb65b1e8
--- /dev/null
+++ b/mod/lightpics/actions/photos/image/save.php
@@ -0,0 +1,40 @@
+<?php
+/**
+ * Save image action
+ *
+ * @author Cash Costello
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2
+ */
+
+// Get input data
+$title = get_input('title');
+$description = get_input('description');
+$tags = get_input('tags');
+$access_id = get_input('access_id');
+$guid = get_input('guid');
+
+elgg_make_sticky_form('tidypics');
+
+if (empty($title)) {
+ register_error(elgg_echo("image:blank"));
+ forward(REFERER);
+}
+
+$image = get_entity($guid);
+
+$image->access_id = $access_id;
+$image->title = $title;
+$image->description = $description;
+if ($tags) {
+ $image->tags = string_to_tag_array($tags);
+}
+
+if (!$image->save()) {
+ register_error(elgg_echo("image:error"));
+ forward(REFERER);
+}
+
+elgg_clear_sticky_form('tidypics');
+
+system_message(elgg_echo("image:saved"));
+forward($image->getURL());
diff --git a/mod/lightpics/actions/photos/image/upload.php b/mod/lightpics/actions/photos/image/upload.php
new file mode 100644
index 000000000..268712666
--- /dev/null
+++ b/mod/lightpics/actions/photos/image/upload.php
@@ -0,0 +1,147 @@
+<?php
+/**
+ * Multi-image uploader action
+ *
+ * @author Cash Costello
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2
+ */
+
+elgg_load_library('tidypics:upload');
+$img_river_view = elgg_get_plugin_setting('img_river_view', 'tidypics');
+
+$guid = (int) get_input('guid');
+$album = get_entity($guid);
+if (!$album) {
+ register_error(elgg_echo('tidypics:baduploadform'));
+ forward(REFERER);
+}
+
+// post limit exceeded
+if (count($_FILES) == 0) {
+ trigger_error('Tidypics warning: user exceeded post limit on image upload', E_USER_WARNING);
+ register_error(elgg_echo('tidypics:exceedpostlimit'));
+ forward(REFERER);
+}
+
+// test to make sure at least 1 image was selected by user
+$num_images = 0;
+foreach($_FILES['images']['name'] as $name) {
+ if (!empty($name)) {
+ $num_images++;
+ }
+}
+if ($num_images == 0) {
+ // have user try again
+ register_error(elgg_echo('tidypics:noimages'));
+ forward(REFERER);
+}
+
+// create the image object for each upload
+$uploaded_images = array();
+$not_uploaded = array();
+$error_msgs = array();
+foreach ($_FILES['images']['name'] as $index => $value) {
+ $data = array();
+ foreach ($_FILES['images'] as $key => $values) {
+ $data[$key] = $values[$index];
+ }
+
+ if (empty($data['name'])) {
+ continue;
+ }
+ $name = htmlspecialchars($data['name'], ENT_QUOTES, 'UTF-8', false);
+
+ $mime = tp_upload_get_mimetype($name);
+
+ $image = new TidypicsImage();
+ $image->title = $name;
+ $image->container_guid = $album->getGUID();
+ $image->setMimeType($mime);
+ $image->access_id = $album->access_id;
+
+ try {
+ $result = $image->save($data);
+ } catch (Exception $e) {
+ array_push($not_uploaded, $name);
+ array_push($error_msgs, $e->getMessage());
+ }
+
+ if ($result) {
+ array_push($uploaded_images, $image->getGUID());
+
+ if ($img_river_view == "all") {
+ add_to_river('river/object/image/create', 'create', $image->getOwnerGUID(), $image->getGUID());
+ }
+ }
+}
+
+if (count($uploaded_images)) {
+ // Create a new batch object to contain these photos
+ $batch = new ElggObject();
+ $batch->subtype = "tidypics_batch";
+ $batch->access_id = $album->access_id;
+ $batch->container_guid = $album->getGUID();
+ if ($batch->save()) {
+ foreach ($uploaded_images as $uploaded_guid) {
+ add_entity_relationship($uploaded_guid, "belongs_to_batch", $batch->getGUID());
+ }
+ }
+
+ $album->prependImageList($uploaded_images);
+
+ // "added images to album" river
+ if ($img_river_view == "batch" && $album->new_album == false) {
+ add_to_river('river/object/tidypics_batch/create', 'create', $batch->getOwnerGUID(), $batch->getGUID());
+ }
+
+ // "created album" river
+ if ($album->new_album) {
+ $album->new_album = false;
+ $album->first_upload = true;
+
+ add_to_river('river/object/album/create', 'create', $album->getOwnerGUID(), $album->getGUID());
+
+ // "created album" notifications
+ // we throw the notification manually here so users are not told about the new album until
+ // there are at least a few photos in it
+ if ($album->shouldNotify()) {
+ object_notifications('create', 'object', $album);
+ $album->last_notified = time();
+ }
+ } else {
+ // "added image to album" notifications
+ if ($album->first_upload) {
+ $album->first_upload = false;
+ }
+
+ if ($album->shouldNotify()) {
+ object_notifications('create', 'object', $album);
+ $album->last_notified = time();
+ }
+ }
+}
+
+if (count($not_uploaded) > 0) {
+ if (count($uploaded_images) > 0) {
+ $error = sprintf(elgg_echo("tidypics:partialuploadfailure"), count($not_uploaded), count($not_uploaded) + count($uploaded_images)) . '<br />';
+ } else {
+ $error = elgg_echo("tidypics:completeuploadfailure") . '<br />';
+ }
+
+ $num_failures = count($not_uploaded);
+ for ($i = 0; $i < $num_failures; $i++) {
+ $error .= "{$not_uploaded[$i]}: {$error_msgs[$i]} <br />";
+ }
+ register_error($error);
+
+ if (count($uploaded_images) == 0) {
+ //upload failed, so forward to previous page
+ forward(REFERER);
+ } else {
+ // some images did upload so we fall through
+ }
+} else {
+ system_message(elgg_echo('tidypics:upl_success'));
+}
+
+forward("photos/edit/$batch->guid");