]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #3131. Added generic liking notification text.
authorBrett Profitt <brett.profitt@gmail.com>
Thu, 25 Aug 2011 20:49:32 +0000 (13:49 -0700)
committerBrett Profitt <brett.profitt@gmail.com>
Thu, 25 Aug 2011 20:49:32 +0000 (13:49 -0700)
mod/likes/actions/likes/add.php
mod/likes/languages/en.php
mod/likes/start.php

index b76c1bea9413ffa03e1af992c6cb4d4fcbc5def8..a6a8d6c45133cce6817d559c614f25083a8e33dc 100644 (file)
@@ -41,18 +41,7 @@ if (!$annotation) {
 // notify if poster wasn't owner
 if ($entity->owner_guid != $user->guid) {
 
-       notify_user($entity->owner_guid,
-                               $user->guid,
-                               elgg_echo('likes:email:subject'),
-                               elgg_echo('likes:email:body', array(
-                                       $user->name,
-                                       $entity->title,
-                                       //$comment_text,
-                                       $entity->getURL(),
-                                       $user->name,
-                                       $user->getURL()
-                               ))
-                       );
+       likes_notify_user($entity->getOwnerEntity(), $user, $entity);
 }
 
 system_message(elgg_echo("likes:likes"));
index aad2a7f24b0e1819a143e2d79a162222e329f095..29b379506544ca0167ab3c782f68cd655ea3cbf9 100644 (file)
@@ -17,9 +17,28 @@ $english = array(
        'likes:userlikedthis' => '%s like',
        'likes:userslikedthis' => '%s likes',
        'likes:river:annotate' => 'likes',
-       'likes:email:body' => '%s liked %s',
-       'likes:email:subject' => 'A user liked one of your objects',
+
        'river:likes' => 'likes %s %s',
+
+       // notifications. yikes.
+       'likes:notifications:subject' => '%s likes your post "%s"',
+       'likes:notifications:body' =>
+'Hi %1$s,
+
+%2$s likes your post "%3$s" on %4$s!
+
+See your original post here:
+
+%5$s
+
+or view %2$s\'s profile here:
+
+%6$s
+
+Thanks,
+%4$s
+',
+       
 );
 
 add_translation('en', $english);
index d45fb96b3da6f6e95d2fe00db6515ea336bbb6e3..64be8b2394a3aaf2a82d67d310a03e439b7e38d3 100644 (file)
@@ -109,3 +109,76 @@ function likes_count($entity) {
                return $entity->countAnnotations('likes');
        }
 }
+
+/**
+ * Notify $user that $liker liked his $entity.
+ *
+ * @param type $user
+ * @param type $liker
+ * @param type $entity 
+ */
+function likes_notify_user(ElggUser $user, ElggUser $liker, ElggEntity $entity) {
+       
+       if (!$user instanceof ElggUser) {
+               return false;
+       }
+       
+       if (!$liker instanceof ElggUser) {
+               return false;
+       }
+       
+       if (!$entity instanceof ElggEntity) {
+               return false;
+       }
+
+       // get language for entity type / subtype
+       // would be nice to have standardized languages....
+       // we can have:
+       //  item:object:<subtype>
+       //      subtype
+       //      subtype:subtype
+       $type = $entity->getType();
+       $subtype = $entity->getSubtype();
+
+       $strings = array(
+               "item:$type:$subtype",
+               $subtype,
+               "$subtype:$subtype"
+       );
+
+       $type_str = elgg_echo('likes:content');
+       foreach ($strings as $string) {
+               $tmp = elgg_echo($string);
+               if ($tmp != $string) {
+                       $type_str = $tmp;
+                       break;
+               }
+       }
+
+       $title_str = $entity->title;
+       if (!$title_str) {
+               $title_str = elgg_get_excerpt($entity->description);
+       }
+
+       $site = get_config('site');
+
+       $subject = elgg_echo('likes:notifications:subject', array(
+                                       $liker->name,
+                                       $title_str
+                               ));
+
+       $body = elgg_echo('likes:notifications:body', array(
+                                       $user->name,
+                                       $liker->name,
+                                       $title_str,
+                                       $site->name,
+                                       $entity->getURL(),
+                                       $liker->getURL()
+                               ));
+
+       notify_user($user->guid,
+                               $liker->guid,
+                               $subject,
+                               $body
+                       );
+}
\ No newline at end of file