aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCash Costello <cash.costello@gmail.com>2012-07-13 22:23:52 -0400
committerCash Costello <cash.costello@gmail.com>2012-07-13 22:23:52 -0400
commit54bc5844dfe6cb684c7aecaf1be5ee8071d98fe0 (patch)
tree90f4166d6cd605eb4d7e95d63682732a1c5476a5
parent695651451b262c526d6aaf9d0988ce557ff50e95 (diff)
parent894ea6758f3f99c49807df99ef4bbd95f74273dc (diff)
downloadelgg-54bc5844dfe6cb684c7aecaf1be5ee8071d98fe0.tar.gz
elgg-54bc5844dfe6cb684c7aecaf1be5ee8071d98fe0.tar.bz2
Merged notifications update from Brett's fork
-rw-r--r--actions/photos/image/upload.php25
-rw-r--r--activate.php2
-rw-r--r--classes/TidypicsAlbum.php13
-rw-r--r--languages/en.php8
-rw-r--r--start.php44
-rw-r--r--upgrades/2010102801.php2
-rw-r--r--upgrades/2012020901.php26
-rw-r--r--version.php2
-rw-r--r--views/default/river/object/tidypics_batch/create.php8
9 files changed, 102 insertions, 28 deletions
diff --git a/actions/photos/image/upload.php b/actions/photos/image/upload.php
index 3a1970367..29df59b63 100644
--- a/actions/photos/image/upload.php
+++ b/actions/photos/image/upload.php
@@ -7,7 +7,6 @@
*/
elgg_load_library('tidypics:upload');
-
$img_river_view = elgg_get_plugin_setting('img_river_view', 'tidypics');
$guid = (int) get_input('guid');
@@ -86,17 +85,35 @@ if (count($uploaded_images)) {
$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();
+ }
}
}
diff --git a/activate.php b/activate.php
index 86706d9a6..6b8390406 100644
--- a/activate.php
+++ b/activate.php
@@ -41,6 +41,8 @@ $defaults = array(
'album_river_view' => 'set',
'image_sizes' => $image_sizes,
+
+ 'notify_interval' => 60 * 60 * 24,
);
foreach ($defaults as $name => $value) {
diff --git a/classes/TidypicsAlbum.php b/classes/TidypicsAlbum.php
index e04344a6b..d069117bf 100644
--- a/classes/TidypicsAlbum.php
+++ b/classes/TidypicsAlbum.php
@@ -38,6 +38,10 @@ class TidypicsAlbum extends ElggObject {
$this->new_album = true;
}
+ if (!isset($this->last_notified)) {
+ $this->last_notified = 0;
+ }
+
if (!parent::save()) {
return false;
}
@@ -268,6 +272,15 @@ class TidypicsAlbum extends ElggObject {
}
/**
+ * 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
*/
protected function deleteImages() {
diff --git a/languages/en.php b/languages/en.php
index dc109dd05..69ba9d245 100644
--- a/languages/en.php
+++ b/languages/en.php
@@ -219,8 +219,7 @@ The photo can be viewed here: %s",
// 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",
@@ -234,8 +233,9 @@ The photo can be viewed here: %s",
'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.",
diff --git a/start.php b/start.php
index ad540bc8f..a2dc75ab1 100644
--- a/start.php
+++ b/start.php
@@ -73,17 +73,13 @@ function tidypics_init() {
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');
@@ -370,7 +366,10 @@ function tidypics_group_permission_override($hook, $type, $result, $params) {
/**
- * 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
@@ -381,18 +380,29 @@ function tidypics_notify_message($hook, $type, $result, $params) {
$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;
}
diff --git a/upgrades/2010102801.php b/upgrades/2010102801.php
index 9190912fe..5bd5f78b4 100644
--- a/upgrades/2010102801.php
+++ b/upgrades/2010102801.php
@@ -23,4 +23,4 @@ while ($item = mysql_fetch_object($river_items)) {
}
}
}
-}
+} \ No newline at end of file
diff --git a/upgrades/2012020901.php b/upgrades/2012020901.php
new file mode 100644
index 000000000..793279b38
--- /dev/null
+++ b/upgrades/2012020901.php
@@ -0,0 +1,26 @@
+<?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;
+ }
+}
diff --git a/version.php b/version.php
index d125847d8..f2817c5e9 100644
--- a/version.php
+++ b/version.php
@@ -5,4 +5,4 @@
* Used for the upgrade system.
*/
-$version = 2010102801;
+$version = 2012020901;
diff --git a/views/default/river/object/tidypics_batch/create.php b/views/default/river/object/tidypics_batch/create.php
index 44c40c110..418cf1ac3 100644
--- a/views/default/river/object/tidypics_batch/create.php
+++ b/views/default/river/object/tidypics_batch/create.php
@@ -43,8 +43,14 @@ if (count($images)) {
$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
));