]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/EmailReminder/EmailReminderPlugin.php
Merge branch 'direct-feed-sub' into 'master'
[quix0rs-gnu-social.git] / plugins / EmailReminder / EmailReminderPlugin.php
index b2fc02d2e88c4d02aedff9ac26bfcc7d2eb22fc6..9ac6275537afd6535de0a64f4e1aa0f23ae8157b 100644 (file)
@@ -61,32 +61,6 @@ class EmailReminderPlugin extends Plugin
         return true;
     }
 
-    /**
-     * Load related modules when needed
-     *
-     * @param string $cls Name of the class to be loaded
-     *
-     * @return boolean hook value; true means continue processing, false
-     *         means stop.
-     */
-    function onAutoload($cls) {
-        $base = dirname(__FILE__);
-        $lower = strtolower($cls);
-
-        $files = array("$base/classes/$cls.php",
-            "$base/lib/$lower.php");
-        if (substr($lower, -6) == 'action') {
-            $files[] = "$base/actions/" . substr($lower, 0, -6) . ".php";
-        }
-        foreach ($files as $file) {
-            if (file_exists($file)) {
-                include_once $file;
-                return false;
-            }
-        }
-        return true;
-    }
-
     /**
      * Register our queue handlers
      *
@@ -114,43 +88,53 @@ class EmailReminderPlugin extends Plugin
     }
 
     /**
+     * Send a reminder and record doing so
      *
-     * @param type $object
-     * @param type $subject
-     * @param type $day
+     * @param string $type      type of reminder
+     * @param mixed  $object    Confirm_address or Invitation object
+     * @param string $subject   subjct of the email reminder
+     * @param int    $day       number of days
      */
     static function sendReminder($type, $object, $subject, $day)
     {
-        common_debug("QQQQQ sendReminder() enter ... ", __FILE__);
-
-        $title = "{$type}-{$day}";
-
-        common_debug("QQQQ title = {$title}", __FILE__);
+        // XXX: -1 is a for the special one-time reminder (maybe 30) would be
+        // better?  Like >= 30 days?
+        if ($day == -1) {
+            $title = "{$type}-onetime";
+        } else {
+            $title = "{$type}-{$day}";
+        }
 
         // Record the fact that we sent a reminder
         if (self::sendReminderEmail($type, $object, $subject, $title)) {
-            common_debug("Recording reminder record for {$object->address}", __FILE__);
             try {
                 Email_reminder::recordReminder($type, $object, $day);
+                common_log(
+                    LOG_INFO,
+                    "Sent {$type} reminder to {$object->address}.",
+                    __FILE__
+                );
             } catch (Exception $e) {
                 // oh noez
                 common_log(LOG_ERR, $e->getMessage(), __FILE__);
             }
         }
 
-        common_debug("QQQQQ sendReminder() exit ... ", __FILE__);
-
         return true;
     }
 
     /**
+     * Send a real live email reminder
      *
-     * @param type $object
-     * @param type $subject
-     * @param type $title
-     * @return type
+     * @todo This would probably be better as two or more sep functions
+     *
+     * @param string $type      type of reminder
+     * @param mixed  $object    Confirm_address or Invitation object
+     * @param string $subject   subjct of the email reminder
+     * @param string $title     title of the email reminder
+     * @return boolean true if the email subsystem doesn't explode
      */
-    static function sendReminderEmail($type, $object, $subject, $title=null) {
+    static function sendReminderEmail($type, $object, $subject, $title = null) {
 
         $sitename   = common_config('site', 'name');
         $recipients = array($object->address);
@@ -158,7 +142,7 @@ class EmailReminderPlugin extends Plugin
         $inviterurl = null;
 
         if ($type == UserInviteReminderHandler::INVITE_REMINDER) {
-            $user = User::staticGet($object->user_id);
+            $user = User::getKV($object->user_id);
             if (!empty($user)) {
                 $profile    = $user->getProfile();
                 $inviter    = $profile->getBestName();
@@ -177,14 +161,15 @@ class EmailReminderPlugin extends Plugin
 
         $template = DocFile::forTitle($title, DocFile::mailPaths());
 
-        $body = $template->toHTML(
-            array(
-                'confirmurl' => $confirmUrl,
-                'inviter'    => $inviter,
-                'inviterurl' => $inviterUrl
-                // @todo private invitation message
-            )
-        );
+        $blankfillers = array('confirmurl' => $confirmUrl);
+
+        if ($type == UserInviteReminderHandler::INVITE_REMINDER) {
+            $blankfillers['inviter'] = $inviter;
+            $blankfillers['inviterurl'] = $inviterUrl;
+            // @todo private invitation message?
+        }
+
+        $body = $template->toHTML($blankfillers);
 
         return mail_send($recipients, $headers, $body);
     }
@@ -194,11 +179,11 @@ class EmailReminderPlugin extends Plugin
      * @param type $versions
      * @return type
      */
-    function onPluginVersion(&$versions)
+    function onPluginVersion(array &$versions)
     {
         $versions[] = array(
             'name'           => 'EmailReminder',
-            'version'        => STATUSNET_VERSION,
+            'version'        => GNUSOCIAL_VERSION,
             'author'         => 'Zach Copley',
             'homepage'       => 'http://status.net/wiki/Plugin:EmailReminder',
             // TRANS: Plugin description.
@@ -206,4 +191,5 @@ class EmailReminderPlugin extends Plugin
         );
         return true;
     }
+
 }