]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #11. Added notifications back.
authorBrett Profitt <brett.profitt@gmail.com>
Mon, 13 Feb 2012 23:39:45 +0000 (15:39 -0800)
committerBrett Profitt <brett.profitt@gmail.com>
Mon, 13 Feb 2012 23:40:52 +0000 (15:40 -0800)
actions/photos/image/upload.php
activate.php
classes/TidypicsAlbum.php
languages/en.php
start.php
upgrades/2010102801.php
upgrades/2012020901.php [new file with mode: 0644]
version.php
views/default/river/object/tidypics_batch/create.php

index 3a1970367e177ede0dc8f49fdf8f42180fc8e7a7..29df59b636f9c6e4ede699962863b5de982023d8 100644 (file)
@@ -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();
+               }
        }
 }
 
index 86706d9a6ce9ffad9b69a132f26139e20ac7edcc..6b83904066081942cf08b5628bcf8d69bc775b7e 100644 (file)
@@ -41,6 +41,8 @@ $defaults = array(
        'album_river_view' => 'set',
 
        'image_sizes' => $image_sizes,
+
+       'notify_interval' => 60 * 60 * 24,
 );
 
 foreach ($defaults as $name => $value) {
index e04344a6bbf38c36ac4a76c1d90ce07ca9bfac42..d069117bfe00fc2261a39b7ed59dad4bd32d7f53 100644 (file)
@@ -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;
                }
@@ -267,6 +271,15 @@ class TidypicsAlbum extends ElggObject {
                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
         */
index dc109dd05aa00499fd36a98cb712cb754b302cc1..69ba9d24575c128dc98050ec71be5e03ce367daf 100644 (file)
@@ -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.",
index ad540bc8f170cb47ff00baac9f924e73c34cf646..a2dc75ab184a97686c2175692149b5022d79475d 100644 (file)
--- 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;
 }
 
index 9190912fe6083c97df852d12c421e22fb297e826..5bd5f78b425fd3322ca57a307f822e6b0d973610 100644 (file)
@@ -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 (file)
index 0000000..793279b
--- /dev/null
@@ -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;
+       }
+}
index d125847d8560dc37093c7a7dff7a64329a175698..f2817c5e9664c0c6b418d4d61061ef4254e6df36 100644 (file)
@@ -5,4 +5,4 @@
  * Used for the upgrade system.
  */
 
-$version = 2010102801;
+$version = 2012020901;
index 44c40c110f0313582f7ffb6596c6739bba6e7b62..418cf1ac33197298dddedb95ad7d7e8b8886b6de 100644 (file)
@@ -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
 ));