Changeset 530

Show
Ignore:
Timestamp:
09/06/06 22:53:51 (2 years ago)
Author:
ben
Message:

Notifications - user comments etc - are now sent to a 'messages' database, which is primed for internal user-to-user messaging. If the emailnotifications flag is set, notifications still get emailed. TODO: 'view' interface, as part of recent activity.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • devel/lib/db/mysql.php

    r529 r530  
    361361     
    362362    if ($oldversion < 2006090600) { 
    363         execute_sql("ALTER TABLE `{$CFG->prefix}users` CHANGE `username` `username` VARCHAR(128) NOT NULL DEFAULT '' ;",false); 
     363        execute_sql("ALTER TABLE `{$CFG->prefix}users` CHANGE `username` `username` VARCHAR(128) NOT NULL DEFAULT '' ",false); 
     364    } 
     365     
     366    if ($oldversion < 2006090601) { 
     367        modify_database('',"CREATE TABLE `{$CFG->prefix}messages` (`ident` int(11) NOT NULL auto_increment, `title` text NOT NULL default '', `body` text NOT NULL default '', `from` int(11) NOT NULL, `to` int(11) NOT NULL, `posted` int(11) NOT NULL, `status` enum('read','unread') NOT NULL default 'unread', PRIMARY KEY  (`ident`), KEY `from` (`from`,`to`,`posted`)) TYPE=MyISAM;",false); 
    364368    } 
    365369     
  • devel/lib/db/mysql.sql

    r529 r530  
    501501  KEY `tagline` (`tagline`) 
    502502) ; 
     503 
     504 
     505--  
     506-- Table structure for table `messages` 
     507--  
     508 
     509CREATE TABLE `prefix_messages` ( 
     510  `ident` int(11) NOT NULL auto_increment, 
     511  `title` text NOT NULL default '', 
     512  `body` text NOT NULL default '', 
     513  `from` int(11) NOT NULL, 
     514  `to` int(11) NOT NULL, 
     515  `posted` int(11) NOT NULL, 
     516  `status` enum('read','unread') NOT NULL default 'unread', 
     517  PRIMARY KEY  (`ident`), 
     518  KEY `from` (`from`,`to`,`posted`) 
     519) TYPE=MyISAM ; 
  • devel/lib/db/postgres7.php

    r529 r530  
    323323     
    324324    if ($oldversion < 2006090600) { 
    325         execute_sql("ALTER TABLE `{$CFG->prefix}users` CHANGE `username` `username` VARCHAR(128) NOT NULL DEFAULT '' ;",false); 
     325        execute_sql("ALTER TABLE `{$CFG->prefix}users` CHANGE `username` `username` VARCHAR(128) NOT NULL DEFAULT '' ",false); 
     326    } 
     327     
     328    if ($oldversion < 2006090601) { 
     329        execute_sql("CREATE TABLE `{$CFG->prefix}messages` (`ident` SERIAL PRIMARY KEY, `title` text NOT NULL default '', `body` text NOT NULL default '', `from` int(11) NOT NULL default -1, `to` int(11) NOT NULL default -1, `posted` int(11) NOT NULL default 0, `status` enum('read','unread') NOT NULL default 'unread')",false); 
     330        execute_sql("CREATE INDEX {$CFG->prefix}messages_to_idx ON {$CFG->prefix}messages (from,to)"); 
    326331    } 
    327332     
  • devel/lib/db/postgres7.sql

    r529 r530  
    358358CREATE INDEX prefix_feeds_siteurl_idx ON prefix_feeds (siteurl); 
    359359CREATE INDEX prefix_feeds_tagline_idx ON prefix_feeds (tagline); 
     360 
     361 
     362--  
     363-- Table structure for table `messages` 
     364--  
     365 
     366CREATE TABLE `prefix_messages` ( 
     367  `ident` SERIAL PRIMARY KEY, 
     368  `title` text NOT NULL default '', 
     369  `body` text NOT NULL default '', 
     370  `from` int(11) NOT NULL default -1, 
     371  `to` int(11) NOT NULL default -1, 
     372  `posted` int(11) NOT NULL default 0, 
     373  `status` enum('read','unread') NOT NULL default 'unread', 
     374); 
     375 
     376CREATE INDEX prefix_messages_to_idx ON prefix_messages (from,to); 
  • devel/lib/userlib.php

    r503 r530  
    139139        } 
    140140    } 
     141 
     142// NOTIFICATIONS AND MESSAGING ///////////////////////////////////////////////// 
     143 
     144    // Send a message to a user 
     145     
     146    function message_user($to, $from, $title, $message) { 
     147         
     148        global $messages; 
     149         
     150        $notifications = user_flag_get("emailnotifications",$to); 
     151        if ($notifications) { 
     152            $from = new StdClass; 
     153            $from->email = $CFG->noreplyaddress; 
     154            $from->name = $CFG->sitename; 
     155            email_to_user($u,$from,$title,$message); 
     156        } 
     157         
     158        $m = new StdClass; 
     159        $m->title = $title; 
     160        $m->body = $message; 
     161        $m->from_id = $from; 
     162        $m->to_id = $to; 
     163        $m->posted = time(); 
     164        $m->status = 'unread'; 
     165        if (!insert_record('messages',$m)) { 
     166            $messages[] = gettext("Failed to send message. An unknown error occurred."); 
     167        } 
     168         
     169    } 
     170 
     171    // Send a notification to a user, both using the notifications table and 
     172    // - potentially - email, depending on a user's preferences 
     173     
     174    function notify_user($user_id, $title, $message) { 
     175         
     176        message_user($user_id, -1, $title, $message); 
     177         
     178    } 
    141179     
    142180// STATISTICS ////////////////////////////////////////////////////////////////// 
  • devel/units/communities/communities_actions.php

    r454 r530  
    5252     case "friend": 
    5353         if (!empty($friend_id) && logged_on) { 
    54              if (run("users:type:get", $friend_id) == "community") { 
     54             if (user_info("user_type",$friend_id) == "community") { 
    5555                 if ($friend = get_record('users','ident',$friend_id)) { 
    5656                     $owner = get_record('users','ident',$friend->owner); 
     
    5858                         $messages[] = sprintf(gettext("You joined %s."), stripslashes($friend->name)); 
    5959                         if (run("users:flags:get",array("emailnotifications",$owner->ident))) { 
    60                              $email_message = sprintf(gettext("%s has joined %s!\n\nTo visit this user's profile, click on the following link:\n\n\t". 
     60                             $message_body = sprintf(gettext("%s has joined %s!\n\nTo visit this user's profile, click on the following link:\n\n\t". 
    6161                                                                     "%s\n\nTo view all community members, click here:\n\n\t%s\n\nRegards,\n\nThe %s team."), 
    62                                                                      $_SESSION['name'], $friend->name, $CFG->wwwroot . run("users:id_to_name",$USER->ident) . "/", $CFG->wwwroot . "_communities/members.php?owner=" . $friend_id,$CFG->sitename); 
    63                              email_to_user($owner,null,sprintf(gettext("New %s member"), $friend->name),$email_message); 
     62                                                                     $_SESSION['name'], $friend->name, $CFG->wwwroot . user_info("username",$USER->ident) . "/", $CFG->wwwroot . "_communities/members.php?owner=" . $friend_id,$CFG->sitename); 
     63                             $title = sprintf(gettext("New %s member"), $friend->name); 
     64                             notify_user($owner->ident,$title,$message_body); 
    6465                         } 
    6566                     } else if ($friend->moderation == "yes") { 
    6667                         $messages[] = sprintf(gettext("Membership of %s needs to be approved. Your request has been added to the list."), stripslashes($friend->name)); 
    6768                         if (run("users:flags:get",array("emailnotifications",$owner->ident))) { 
    68                              $email_message = sprintf(gettext("%s has applied to join %s!\n\nTo visit this user's profile, click on the following link:\n\n\t". 
     69                             $message_body = sprintf(gettext("%s has applied to join %s!\n\nTo visit this user's profile, click on the following link:\n\n\t". 
    6970                                                                     "%s\n\nTo view all membership requests and approve or deny this user, click here:\n\n\t%s\n\nRegards,\n\nThe %s team."), 
    70                                                                      $_SESSION['name'], $friend->name, $CFG->wwwroot . run("users:id_to_name",$USER->ident) . "/", $CFG->wwwroot . "_communities/members.php?owner=" . $friend_id,$CFG->sitename); 
    71                              email_to_user($owner,null,sprintf(gettext("New %s member"), $friend->name),$email_message); 
     71                                                                     $_SESSION['name'], $friend->name, $CFG->wwwroot . user_info("username",$USER->ident) . "/", $CFG->wwwroot . "_communities/members.php?owner=" . $friend_id,$CFG->sitename); 
     72                             $title = sprintf(gettext("New %s member request"), $friend->name); 
     73                             notify_user($owner->ident,$title,$message_body); 
    7274                         } 
    7375                     } else if ($friend->moderation == "priv") { 
  • devel/units/friends/friends_actions.php

    r432 r530  
    2121                if ($friend->moderation == 'no') { 
    2222                    if (insert_record('friends',$f)) { 
    23                         if (run("users:type:get", $friend_id) == "person") { 
     23                        if (user_info("user_type",$friend_id) == "person") { 
    2424                            $messages[] = sprintf(gettext("%s was added to your friends list."),$friend->name); 
    2525                            if (run("users:flags:get",array("emailnotifications",$friend_id))) { 
    2626                                $u = get_record('users','ident',$friend_id); 
    27                                 $email_message = sprintf(gettext("%s has added you as a friend!\n\nTo visit this user's profile, click on the following link:\n\n\t". 
     27                                $message_body = sprintf(gettext("%s has added you as a friend!\n\nTo visit this user's profile, click on the following link:\n\n\t". 
    2828                                                                 "%s\n\nTo view all your friends, click here:\n\n\t%s\n\nRegards,\n\nThe %s team."), 
    29                                                                  $_SESSION['name'], $CFG->wwwroot . run("users:id_to_name",$USER->ident) . "/", $CFG->wwwroot . run("users:id_to_name",$friend_id) . "/friends/",$CFG->sitename); 
    30                                 email_to_user($u,null,sprintf(gettext("New %s friend"), $CFG->sitename),$email_message); 
     29                                                                 $_SESSION['name'], $CFG->wwwroot . user_info("username",$USER->ident) . "/", $CFG->wwwroot . user_info("username",$friend_id) . "/friends/",$CFG->sitename); 
     30                                $title = sprintf(gettext("New %s friend"), $CFG->sitename); 
     31                                notify_user($u,$title,$message_body); 
    3132                            } 
    3233                        } 
    3334                    } else { 
    34                         if (run("users:type:get", $friend_id) == "person") { 
     35                        if (user_info("user_type",$friend_id) == "person") { 
    3536                            $messages[] = sprintf(gettext("%s couldn't be added to your friends list."),$friend->name); 
    3637                        } 
     
    3839                } else if ($friend->moderation == 'yes') { 
    3940                    if (insert_record('friends_requests',$f)) { 
    40                         if (run("users:type:get", $friend_id) == "person") { 
     41                        if (user_info("user_type",$friend_id) == "person") { 
    4142                            $messages[] = sprintf(gettext("%s has elected to moderate friendship requests. Your request has been added to their moderation queue."),$friend->name); 
    4243                            if (run("users:flags:get",array("emailnotifications",$friend_id))) { 
    4344                                $u = get_record('users','ident',$friend_id); 
    44                                 $email_message = sprintf(gettext("%s has requested to add you as a friend!\n\nTo visit this user's profile, click on the following link:\n\n\t". 
     45                                $message_body = sprintf(gettext("%s has requested to add you as a friend!\n\nTo visit this user's profile, click on the following link:\n\n\t". 
    4546                                                                 "%s\n\nTo view all your friends requests and approve or deny this user, click here:\n\n\t%s\n\nRegards,\n\nThe %s team."), 
    46                                                                  $_SESSION['name'], $CFG->wwwroot . run("users:id_to_name",$USER->ident) . "/", $CFG->wwwroot . "_friends/requests.php?owner=" . $friend_id,$CFG->sitename); 
    47                                 email_to_user($u,null,sprintf(gettext("New %s friend request"), $CFG->sitename),$email_message); 
     47                                                                 $_SESSION['name'], $CFG->wwwroot . user_info("username",$USER->ident) . "/", $CFG->wwwroot . "_friends/requests.php?owner=" . $friend_id,$CFG->sitename); 
     48                                $title = sprintf(gettext("New %s friend request"), $CFG->sitename); 
     49                                notify_user($u,$title,$message_body); 
    4850                            } 
    4951                        } 
    5052                    } else { 
    51                         if (run("users:type:get", $friend_id) == "person") { 
     53                        if (user_info("user_type",$friend_id) == "person") { 
    5254                            $messages[] = sprintf(gettext("%s has elected to moderate friendship requests, but your friend request couldn't be added to their moderation queue."),$friend->name); 
    5355                        } 
    5456                    } 
    55                 } else if ($friend->moderation == 'priv'  && run("users:type:get", $friend_id) == "person") { 
     57                } else if ($friend->moderation == 'priv'  && user_info("user_type",$friend_id) == "person") { 
    5658                    $messages[] = sprintf(gettext("%s has decided not to allow any new friendship requests at this time. Your friendship request has been declined."),$friend->name); 
    5759                } 
     
    6365         if (!empty($friend) && logged_on) { 
    6466             if (delete_records('friends','owner',$USER->ident,'friend',$friend_id)) { 
    65                  if (run("users:type:get", $friend_id) == "person") { 
     67                 if (user_info("user_type",$friend_id) == "person") { 
    6668                     $messages[] = $friend->name . gettext(" was removed from your friends."); 
    6769                 } 
    6870             } else { 
    69                  if (run("users:type:get", $friend_id) == "person") { 
     71                 if (user_info("user_type",$friend_id) == "person") { 
    7072                     $messages[] = $friend->name . gettext(" couldn't be removed from your friends."); 
    7173                 } 
     
    8789                         delete_records('friends_requests','ident',$request_id); 
    8890                         $messages[] = sprintf(gettext("You approved the friendship request. %s now lists you as a friend."),stripslashes($request->name)); 
     91                         $message_body = sprintf(gettext("%s has approved your friendship request!\n\nTo visit this user's profile, click on the following link:\n\n\t". 
     92                                                          "%s\n\nTo view all your friends, click here:\n\n\t%s\n\nRegards,\n\nThe %s team."), 
     93                                                          user_info("name",$request->friend), $CFG->wwwroot . user_info("username",$request->friend) . "/", $CFG->wwwroot . user_info("username",$request->owner) . "/friends/",$CFG->sitename); 
     94                         $title = sprintf(gettext("%s friend request approved!"), $CFG->sitename); 
     95                         notify_user($request->owner,$title,$message_body); 
    8996                     } else { 
    9097                         $messages[] = gettext("An error occurred: couldn't add you as a friend"); 
     
    109116                     delete_records('friends_requests','ident',$request_id); 
    110117                     $messages[] = sprintf(gettext("You declined the friendship request. %s does not list you as a friend."),stripslashes($request->name)); 
     118                     $message_body = sprintf(gettext("%s has denied your friendship request.\n\nTo visit this user's profile, click on the following link:\n\n\t". 
     119                                                          "%s\n\nTo view all your existing friends, click here:\n\n\t%s\n\nRegards,\n\nThe %s team."), 
     120                                                          user_info("name",$request->friend), $CFG->wwwroot . user_info("username",$request->friend) . "/", $CFG->wwwroot . user_info("username",$request->owner) . "/friends/",$CFG->sitename); 
     121                         $title = sprintf(gettext("%s friend request denied"), $CFG->sitename); 
     122                         notify_user($request->owner,$title,$message_body); 
    111123                 } else { 
    112124                     $messages[] = gettext("Error: you do not have authority to modify this friendship request."); 
  • devel/units/weblogs/weblogs_actions.php

    r436 r530  
    131131                        if (run("users:flags:get",array("emailreplies",$post->owner))) { 
    132132                            if ($email = get_record('users','ident',$post->owner)) { 
    133                                 $username = $email->username; 
    134133                                $message = gettext(sprintf("You have received a comment from %s on your blog post '%s'. It reads as follows:", $comment->postedname, stripslashes($post->title))); 
    135134                                $message .= "\n\n\n" . stripslashes($comment->body) . "\n\n\n"; 
    136135                                $message .= gettext(sprintf("To reply and see other comments on this blog post, click here: %s", url . $username . "/weblog/" . $post->ident . ".html")); 
    137136                                $message = wordwrap($message); 
    138                                 $from = new StdClass; 
    139                                 $from->email = $CFG->noreplyaddress; 
    140                                 $from->name = $comment->postedname; 
    141                                 email_to_user($email,$from,stripslashes($post->title),$message); 
     137                                notify_user($post->owner,stripslashes($post->title),$message); 
    142138                            } 
    143139                        } 
  • devel/version.php

    r529 r530  
    77// whether upgrades should be performed (see lib/db/*.php) 
    88 
    9    $version = 2006090600;  // YYYYMMDD   = Elgg Date 
     9   $version = 2006090601;  // YYYYMMDD   = Elgg Date 
    1010                           //         X  = Elgg Point release (0,1,2...) 
    1111                           //          Y = Interim incrementer