aboutsummaryrefslogtreecommitdiff
path: root/mod/lightpics/actions/photos/image
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2013-12-29 20:45:58 -0200
committerSilvio Rhatto <rhatto@riseup.net>2013-12-29 20:45:58 -0200
commit97e689213ff4e829f251af526ed4e796a3cc2b71 (patch)
treeb04d03ec56305041216b72328fc9b5afde27bc76 /mod/lightpics/actions/photos/image
parent0ab6351abb7a602d96c62b0ad35413c88113a6cf (diff)
parent69e2d8c5d8732042c9319aef1fdea45a82b63e42 (diff)
downloadelgg-97e689213ff4e829f251af526ed4e796a3cc2b71.tar.gz
elgg-97e689213ff4e829f251af526ed4e796a3cc2b71.tar.bz2
Merge branch 'master' into saravea
Conflicts: .gitmodules mod/admins mod/assemblies mod/audio_html5 mod/beechat mod/crud mod/elgg-activitystreams mod/elggman mod/elggpg mod/favorites mod/federated-objects mod/friendly_time mod/group_alias mod/group_operators mod/languages mod/lightpics mod/openid_client mod/spotlight mod/suicide mod/tasks mod/videolist
Diffstat (limited to 'mod/lightpics/actions/photos/image')
-rw-r--r--mod/lightpics/actions/photos/image/save.php40
-rw-r--r--mod/lightpics/actions/photos/image/upload.php147
2 files changed, 187 insertions, 0 deletions
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");