Build multipart message when sending notifications about shared calendars.
authorJan Schneider <jan@horde.org>
Thu, 2 Dec 2010 18:27:33 +0000 (19:27 +0100)
committerJan Schneider <jan@horde.org>
Thu, 2 Dec 2010 18:27:57 +0000 (19:27 +0100)
kronolith/config/hooks.php.dist
kronolith/lib/Kronolith.php
kronolith/templates/share/notification.html.php [new file with mode: 0644]
kronolith/templates/share/notification.plain.php [new file with mode: 0644]
kronolith/themes/default/graphics/big_share.png [new file with mode: 0644]

index a6b01f8..53d6cfb 100644 (file)
@@ -31,40 +31,4 @@ class Kronolith_Hooks
 //
 //        throw new Horde_Exception('Unknown action');
 //     }
-
-    /**
-     * Generates the e-mail notification message when the share owner changes.
-     *
-     * @param string $user        The new owner.
-     * @param Horde_Share $share  A calendar or tasklist.
-     */
-//     public function shareOwnerNotification($user, Horde_Share $share)
-//     {
-//         return 'Some fancy text including the ' . $user . ' and the ' . $share->get('name');
-//     }
-
-    /**
-     * Generates the e-mail notification message when the share permissions
-     * change.
-     *
-     * @param string $user        A user who has been added to the permissions.
-     * @param Horde_Share $share  A calendar or tasklist.
-     */
-//     public function shareUserNotification($user, Horde_Share $share)
-//     {
-//         return 'Some fancy text including the ' . $user . ' and the ' . $share->get('name');
-//     }
-
-    /**
-     * Generates the e-mail notification message when the share permissions
-     * change.
-     *
-     * @param mixed $group        The id of a group that has been added to the
-     *                            permissions.
-     * @param Horde_Share $share  A calendar or tasklist.
-     */
-//     public function shareGroupNotification($group, Horde_Share $share)
-//     {
-//         return 'Some fancy text including the ' . $group . ' and the ' . $share->get('name');
-//     }
 }
index 227599a..e659ae8 100644 (file)
@@ -1735,12 +1735,21 @@ class Kronolith
             $identity = $GLOBALS['injector']
                 ->getInstance('Horde_Core_Factory_Identity')
                 ->create();
-            $userName = $identity->getName();
             $mail = new Horde_Mime_Mail(
                 array('from' => $identity->getDefaultFromAddress(true),
                       'charset' => 'UTF-8')
                 );
             $mail->addHeader('User-Agent', 'Kronolith ' . $GLOBALS['registry']->getVersion());
+            $image = self::getImagePart('big_share.png');
+            $view = new Horde_View(array('templatePath' => KRONOLITH_TEMPLATES . '/share'));
+            new Horde_View_Helper_Text($view);
+            $view->user = $identity->getName();
+            $view->calendar = $share->get('name');
+            $view->imageId = $image->getContentId();
+            if ($GLOBALS['conf']['share']['hidden']) {
+                $view->subscribe = Horde::url('calendars/subscribe.php', true)->add('calendar', $share->getName());
+            }
+            $multipart = Kronolith::buildMimeMessage($view, 'notification', $image);
         }
 
         // Process owner and owner permissions.
@@ -1764,7 +1773,7 @@ class Kronolith
                         $message = Horde::callHook('shareOwnerNotification', array($new_owner, $share));
                     } catch (Horde_Exception_HookNotSet $e) {
                         $message = sprintf(_("%s has assigned the ownership of \"%s\" to you"),
-                                           $userName,
+                                           $view->user,
                                            $share->get('name'));
                     }
                     $mail->addHeader('Subject', _("Ownership assignment"));
@@ -1859,15 +1868,6 @@ class Kronolith
             $perm->removeCreatorPermission(Kronolith::PERMS_DELEGATE, false);
         }
 
-        // Build subscription link if necessary.
-        $subscription = $sublink = '';
-        if ($GLOBALS['conf']['share']['hidden']) {
-            $sublink = Horde::url('calendars/subscribe.php', true)->add('calendar', $share->getName());
-            $subscription = "\n"
-                . _("To subscribe to this calendar, you need to click the following link:")
-                . ' ' . $sublink;
-        }
-
         // Process user permissions.
         $u_names = Horde_Util::getFormData('u_names');
         $u_show = Horde_Util::getFormData('u_show');
@@ -1924,16 +1924,8 @@ class Kronolith
                     ->getInstance('Horde_Core_Factory_Identity')
                     ->create($user)
                     ->getDefaultFromAddress(true);
-                try {
-                    $message = Horde::callHook('shareUserNotification', array($user, $share, $sublink));
-                } catch (Horde_Exception_HookNotSet $e) {
-                    $message = sprintf(_("%s has given you access to \"%s\"."),
-                                       $userName,
-                                       $share->get('name'))
-                        . $subscription;
-                }
                 $mail->addHeader('To', $to, 'UTF-8', false);
-                $mail->setBody($message, 'UTF-8');
+                $mail->setBasePart($multipart);
                 $mail->send($GLOBALS['injector']->getInstance('Horde_Mail'));
             }
         }
@@ -1980,17 +1972,8 @@ class Kronolith
                 !isset($current[$group]) && $has_perms) {
                 $groupOb = $GLOBALS['injector']->getInstance('Horde_Group')->getGroupById($group);
                 if (!empty($groupOb->data['email'])) {
-                    try {
-                        $message = Horde::callHook('shareGroupNotification', array($group, $share, $sublink));
-                    } catch (Horde_Exception_HookNotSet $e) {
-                        $message = sprintf(_("%s has given your group \"%s\" access to \"%s\"."),
-                                           $userName,
-                                           $groupOb->getName(),
-                                           $share->get('name'))
-                            . $subscription;
-                    }
                     $mail->addHeader('To', $groupOb->getName() . ' <' . $groupOb->data['email'] . '>', 'UTF-8', false);
-                    $mail->setBody($message, 'UTF-8');
+                    $mail->setBasePart($multipart);
                     $mail->send($GLOBALS['injector']->getInstance('Horde_Mail'));
                 }
             }
diff --git a/kronolith/templates/share/notification.html.php b/kronolith/templates/share/notification.html.php
new file mode 100644 (file)
index 0000000..9513310
--- /dev/null
@@ -0,0 +1,23 @@
+<p><font size="4"><strong><?php printf(_("Invitation from %s to the calendar %s"), $this->h($this->user), $this->h($this->calendar)) ?></strong></font></p>
+
+<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>
+  <td width="140" valign="top">
+    <img src="cid:<?php echo $this->imageId ?>" />
+  </td>
+  <td valign="top">
+    <table width="100%" border="0" cellpadding="5" cellspacing="0">
+      <tr>
+        <td>
+          <font size="2">
+            <?php printf(_("%s wants to share the calendar %s with you to grant you access to all events in this calendar."), '<strong>' . $this->h($this->user) . '</strong>', '<strong>' . $this->h($this->calendar) . '</strong>') ?>
+            <?php if ($this->subscribe): ?>
+            <?php echo _("To subscribe to this calendar, you need to click the following link:") ?>
+            <br><br>
+            <strong><a href="<?php echo $this->h($this->subscribe) ?>"><?php echo $this->h($this->subscribe) ?></a></strong>
+            <?php endif ?>
+          </font>
+        </td>
+      </tr>
+    </table>
+  </td>
+</tr></table>
diff --git a/kronolith/templates/share/notification.plain.php b/kronolith/templates/share/notification.plain.php
new file mode 100644 (file)
index 0000000..dbd9424
--- /dev/null
@@ -0,0 +1,10 @@
+<?php printf(_("Invitation from %s to the calendar \"%s\""), $this->user, $this->calendar) ?>
+
+
+<?php printf(_("%s wants to share the calendar \"%s\" with you to grant you access to all events in this calendar."), $this->user, $this->calendar) ?>
+<?php if ($this->subscribe): ?>
+ <?php echo _("To subscribe to this calendar, you need to click the following link:") ?>
+
+
+<?php echo $this->subscribe ?>
+<?php endif ?>
diff --git a/kronolith/themes/default/graphics/big_share.png b/kronolith/themes/default/graphics/big_share.png
new file mode 100644 (file)
index 0000000..02652ca
Binary files /dev/null and b/kronolith/themes/default/graphics/big_share.png differ