*/
elgg_load_library('tidypics:upload');
-
$img_river_view = elgg_get_plugin_setting('img_river_view', 'tidypics');
$guid = (int) get_input('guid');
$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->getObjectOwnerGUID(), $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());
- // we throw the notification manually here so users are not told about the new album until there
- // is at least a few photos in it
- object_notifications('create', 'object', $album);
+ // "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();
+ }
}
}
'album_river_view' => 'set',
'image_sizes' => $image_sizes,
+
+ 'notify_interval' => 60 * 60 * 24,
);
foreach ($defaults as $name => $value) {
$this->new_album = true;
}
+ if (!isset($this->last_notified)) {
+ $this->last_notified = 0;
+ }
+
if (!parent::save()) {
return false;
}
return true;
}
+ /**
+ * Has enough time elapsed between the last_notified and notify_interval setting?
+ *
+ * @return bool
+ */
+ public function shouldNotify() {
+ return time() - $this->last_notified > elgg_get_plugin_setting('notify_interval', 'tidypics');
+ }
+
/**
* Delete all the images in this album
*/
// river
'river:create:object:image' => "%s uploaded the photo %s",
- 'river:create:object:tidypics_batch' => "%s uploaded some photos",
- 'image:river:created' => "%s added the photo %s to the album %s",
+ 'image:river:created' => "%s added a photo to the album %s",
'image:river:created:multiple' => "%s added %u photos to the album %s",
'image:river:item' => "a photo",
'image:river:annotate' => "a comment on the photo",
'river:comment:object:album' => '%s commented on the album %s',
// notifications
- 'tidypics:newalbum' => 'New photo album',
-
+ 'tidypics:newalbum_subject' => 'New photo album',
+ 'tidypics:newalbum' => '%s created a new photo album',
+ 'tidypics:updatealbum' => "%s uploaded new photos to the album %s",
// Status messages
'tidypics:upl_success' => "Your images uploaded successfully.",
elgg_register_plugin_hook_handler('container_permissions_check', 'object', 'tidypics_group_permission_override');
elgg_register_plugin_hook_handler('permissions_check:metadata', 'object', 'tidypics_group_permission_override');
-/*
-
-
-
- // register for menus
- //register_elgg_event_handler('pagesetup', 'system', 'tidypics_submenus');
+ // notifications
+ register_notification_object('object', 'album', elgg_echo('tidypics:newalbum_subject'));
+ elgg_register_plugin_hook_handler('notify:entity:message', 'object', 'tidypics_notify_message');
+/*
// Register for notifications
- register_notification_object('object', 'album', elgg_echo('tidypics:newalbum'));
- register_plugin_hook('notify:entity:message', 'object', 'tidypics_notify_message');
// slideshow plugin hook
register_plugin_hook('tp_slideshow', 'album', 'tidypics_slideshow');
/**
- * Notification message handler
+ * Notification message handler.
+ *
+ * Notifies when an album is first populated via explicit call in the upload action.
+ *
* @param string $hook
* @param string $type
* @param bool $result
$entity = $params['entity'];
$to_entity = $params['to_entity'];
$method = $params['method'];
- if (($entity instanceof ElggEntity) && ($entity->getSubtype() == 'album')) {
-
- // block notification message when the album doesn't have any photos
- if ($entity->new_album == TP_NEW_ALBUM) {
+
+ if (elgg_instanceof($entity, 'object', 'album')) {
+ if ($entity->new_album) {
return false;
}
+
+ if ($entity->first_upload) {
+ $descr = $entity->description;
+ $title = $entity->title;
+ $owner = $entity->getOwnerEntity();
+ return elgg_echo('tidypics:newalbum', array($owner->name))
+ . ': ' . $title . "\n\n" . $descr . "\n\n" . $entity->getURL();
+ } else {
+ if ($entity->shouldNotify()) {
+ $descr = $entity->description;
+ $title = $entity->title;
+ $owner = $entity->getOwnerEntity();
- $descr = $entity->description;
- $title = $entity->title;
- $owner = $entity->getOwnerEntity();
- return sprintf(elgg_echo('album:river:created'), $owner->name) . ': ' . $title . "\n\n" . $descr . "\n\n" . $entity->getURL();
+ return elgg_echo('tidypics:updatealbum', array($owner->name, $title)) . ': ' . $entity->getURL();
+ }
+ }
}
+
return null;
}
}
}
}
-}
+}
\ No newline at end of file
--- /dev/null
+<?php
+/**
+ * Adds last notified metadata and sets the notify interval
+ */
+
+elgg_set_plugin_setting('notify_interval', 60 * 60 * 24, 'tidypics');
+
+$options = array(
+ 'type' => 'object',
+ 'subtype' => 'album',
+ 'limit' => 0
+);
+
+$prefix = elgg_get_config('dbprefix');
+$batch = new ElggBatch('elgg_get_entities', $options);
+
+foreach ($batch as $album) {
+ // grab earliest picture and use that as the notification time
+ // in old version of tidypics notifications went out only when a new album was populated.
+ $q = "SELECT MIN(time_created) as ts FROM {$prefix}entities WHERE container_guid = $album->guid";
+ $row = get_data_row($q);
+
+ if ($row) {
+ $album->last_notified = $row->ts;
+ }
+}
* Used for the upgrade system.
*/
-$version = 2010102801;
+$version = 2012020901;
$attachments .= '</ul>';
}
+if (count($images) == 1) {
+ $summary = elgg_echo('image:river:created', array($subject_link, $album_link));
+} else {
+ $summary = elgg_echo('image:river:created:multiple', array($subject_link, count($images), $album_link));
+}
+
echo elgg_view('river/elements/layout', array(
'item' => $vars['item'],
'attachments' => $attachments,
- 'summary' => elgg_echo('image:river:created:multiple', array($subject_link, count($images), $album_link)),
+ 'summary' => $summary
));