From 4ad5d55ecf65fb1c9f58211b37f8f111e9ca0c7b Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 13 Feb 2009 10:52:26 -0500 Subject: Add events for filtering and logging new notices --- classes/Notice.php | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'classes/Notice.php') diff --git a/classes/Notice.php b/classes/Notice.php index 329988368..6db59c96e 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -154,32 +154,37 @@ class Notice extends Memcached_DataObject $notice->source = $source; $notice->uri = $uri; - $id = $notice->insert(); + if (Event::handle('StartNoticeSave', array(&$notice))) { - if (!$id) { - common_log_db_error($notice, 'INSERT', __FILE__); - return _('Problem saving notice.'); - } - - # Update the URI after the notice is in the database - if (!$uri) { - $orig = clone($notice); - $notice->uri = common_notice_uri($notice); + $id = $notice->insert(); - if (!$notice->update($orig)) { - common_log_db_error($notice, 'UPDATE', __FILE__); + if (!$id) { + common_log_db_error($notice, 'INSERT', __FILE__); return _('Problem saving notice.'); } - } - # XXX: do we need to change this for remote users? + # Update the URI after the notice is in the database + if (!$uri) { + $orig = clone($notice); + $notice->uri = common_notice_uri($notice); + + if (!$notice->update($orig)) { + common_log_db_error($notice, 'UPDATE', __FILE__); + return _('Problem saving notice.'); + } + } + + # XXX: do we need to change this for remote users? - $notice->saveReplies(); - $notice->saveTags(); - $notice->saveGroups(); + $notice->saveReplies(); + $notice->saveTags(); + $notice->saveGroups(); - $notice->addToInboxes(); - $notice->query('COMMIT'); + $notice->addToInboxes(); + $notice->query('COMMIT'); + + Event::handle('EndNoticeSave', array($notice)); + } # Clear the cache for subscribed users, so they'll update at next request # XXX: someone clever could prepend instead of clearing the cache -- cgit v1.2.3-54-g00ecf From da2348fbbe27facf4cfbf3fad800b3ccf98b4136 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 14 Feb 2009 21:55:25 -0500 Subject: Optionally ignore some notice sources for public page We optionally ignore some notice sources from the public page. Typically these are automatic notice sources like twitterfeed that don't usually represent the community on the site very well. --- classes/Notice.php | 4 +++- config.php.sample | 8 ++++++++ lib/common.php | 3 ++- 3 files changed, 13 insertions(+), 2 deletions(-) (limited to 'classes/Notice.php') diff --git a/classes/Notice.php b/classes/Notice.php index 6db59c96e..b8cd2bd7f 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -136,10 +136,12 @@ class Notice extends Memcached_DataObject $notice->profile_id = $profile_id; $blacklist = common_config('public', 'blacklist'); + $autosource = common_config('public', 'autosource'); # Blacklisted are non-false, but not 1, either - if ($blacklist && in_array($profile_id, $blacklist)) { + if (($blacklist && in_array($profile_id, $blacklist)) || + ($source && $autosource && in_array($source, $autosource))) { $notice->is_local = -1; } else { $notice->is_local = $is_local; diff --git a/config.php.sample b/config.php.sample index a2c5801f4..3fa898e1b 100644 --- a/config.php.sample +++ b/config.php.sample @@ -107,6 +107,14 @@ $config['sphinx']['port'] = 3312; #$config['public']['blacklist'][] = 123; #$config['public']['blacklist'][] = 2307; +#Mark certain notice sources as automatic and thus not +#appropriate for public feed +#$config['public]['autosource'][] = 'twitterfeed'; +#$config['public]['autosource'][] = 'rssdent'; +#$config['public]['autosource'][] = 'Ping.Fm'; +#$config['public]['autosource'][] = 'HelloTxt'; +#$config['public]['autosource'][] = 'Updating.Me'; + #Do notice broadcasts offline #If you use this, you must run the six offline daemons in the #background. See the README for details. diff --git a/lib/common.php b/lib/common.php index 7bfd14c42..4fc749ca0 100644 --- a/lib/common.php +++ b/lib/common.php @@ -106,7 +106,8 @@ $config = array('server' => null), 'public' => array('localonly' => true, - 'blacklist' => array()), + 'blacklist' => array(), + 'autosource' => array()), 'theme' => array('server' => null), 'throttle' => -- cgit v1.2.3-54-g00ecf From ca90d790aa9d93a4e88602330f91d4703c29b75d Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 16 Feb 2009 18:02:31 -0500 Subject: Automatically add a tag for every group messages If you post to a group !foo, it's automatically listed as being tagged "foo". This is to keep users from having to do !foo #foo in all their messages. --- classes/Notice.php | 40 +++++++++++++++++++++++++++------------- classes/Notice_tag.php | 13 +++++++++---- 2 files changed, 36 insertions(+), 17 deletions(-) (limited to 'classes/Notice.php') diff --git a/classes/Notice.php b/classes/Notice.php index b8cd2bd7f..8e08ad503 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -94,23 +94,28 @@ class Notice extends Memcached_DataObject /* Add them to the database */ foreach(array_unique($match[1]) as $hashtag) { /* elide characters we don't want in the tag */ - $hashtag = common_canonical_tag($hashtag); - - $tag = DB_DataObject::factory('Notice_tag'); - $tag->notice_id = $this->id; - $tag->tag = $hashtag; - $tag->created = $this->created; - $id = $tag->insert(); - if (!$id) { - $last_error = PEAR::getStaticProperty('DB_DataObject','lastError'); - common_log(LOG_ERR, 'DB error inserting hashtag: ' . $last_error->message); - common_server_error(sprintf(_('DB error inserting hashtag: %s'), $last_error->message)); - return; - } + $this->saveTag($hashtag); } return true; } + function saveTag($hashtag) + { + $hashtag = common_canonical_tag($hashtag); + + $tag = new Notice_tag(); + $tag->notice_id = $this->id; + $tag->tag = $hashtag; + $tag->created = $this->created; + $id = $tag->insert(); + + if (!$id) { + throw new ServerException(sprintf(_('DB error inserting hashtag: %s'), + $last_error->message)); + return; + } + } + static function saveNew($profile_id, $content, $source=null, $is_local=1, $reply_to=null, $uri=null) { $profile = Profile::staticGet($profile_id); @@ -621,6 +626,15 @@ class Notice extends Memcached_DataObject continue; } + // we automatically add a tag for every group name, too + + $tag = Notice_tag::pkeyGet(array('tag' => common_canonical_tag($nickname), + 'notice_id' => $this->id)); + + if (is_null($tag)) { + $this->saveTag($nickname); + } + if ($profile->isMember($group)) { $gi = new Group_inbox(); diff --git a/classes/Notice_tag.php b/classes/Notice_tag.php index 94f9296d6..0365973f5 100644 --- a/classes/Notice_tag.php +++ b/classes/Notice_tag.php @@ -19,7 +19,7 @@ require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; -class Notice_tag extends Memcached_DataObject +class Notice_tag extends Memcached_DataObject { ###START_AUTOCODE /* the code below is auto generated do not remove the above tag */ @@ -35,9 +35,9 @@ class Notice_tag extends Memcached_DataObject /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE - + static function getStream($tag, $offset=0, $limit=20) { - $qry = + $qry = 'SELECT notice.* ' . 'FROM notice JOIN notice_tag ON notice.id = notice_tag.notice_id ' . 'WHERE notice_tag.tag = "%s" '; @@ -46,7 +46,7 @@ class Notice_tag extends Memcached_DataObject 'notice_tag:notice_stream:' . common_keyize($tag), $offset, $limit); } - + function blowCache() { $cache = common_memcache(); @@ -54,4 +54,9 @@ class Notice_tag extends Memcached_DataObject $cache->delete(common_cache_key('notice_tag:notice_stream:' . $this->tag)); } } + + function &pkeyGet($kv) + { + return Memcached_DataObject::pkeyGet('Notice_tag', $kv); + } } -- cgit v1.2.3-54-g00ecf From 175c4665cc33c07bbbc42bbf96dd07cf90ba7bbb Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 16 Feb 2009 18:26:15 -0500 Subject: send mail when @-replies are received --- classes/Notice.php | 32 +++++++++++++++++++++----------- lib/mail.php | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 11 deletions(-) (limited to 'classes/Notice.php') diff --git a/classes/Notice.php b/classes/Notice.php index 8e08ad503..570d76f61 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -34,22 +34,23 @@ class Notice extends Memcached_DataObject ###START_AUTOCODE /* the code below is auto generated do not remove the above tag */ - public $__table = 'notice'; // table name - public $id; // int(4) primary_key not_null - public $profile_id; // int(4) not_null + public $__table = 'notice'; // table name + public $id; // int(4) primary_key not_null + public $profile_id; // int(4) not_null public $uri; // varchar(255) unique_key public $content; // varchar(140) - public $rendered; // text() + public $rendered; // text() public $url; // varchar(255) - public $created; // datetime() not_null - public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP - public $reply_to; // int(4) - public $is_local; // tinyint(1) - public $source; // varchar(32) + public $created; // datetime() not_null + public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP + public $reply_to; // int(4) + public $is_local; // tinyint(1) + public $source; // varchar(32) /* Static get */ - function staticGet($k,$v=null) - { return Memcached_DataObject::staticGet('Notice',$k,$v); } + function staticGet($k,$v=NULL) { + return Memcached_DataObject::staticGet('Notice',$k,$v); + } /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE @@ -746,10 +747,19 @@ class Notice extends Memcached_DataObject if (!$id) { common_log_db_error($reply, 'INSERT', __FILE__); return; + } else { + $replied[$recipient->id] = 1; } } } } } + + foreach (array_keys($replied) as $recipient) { + $user = User::staticGet('id', $recipient); + if ($user) { + mail_attn_notify($user, $notice); + } + } } } diff --git a/lib/mail.php b/lib/mail.php index a1faefc80..9fa86de5c 100644 --- a/lib/mail.php +++ b/lib/mail.php @@ -573,3 +573,53 @@ function mail_notify_fave($other, $user, $notice) common_init_locale(); mail_to_user($other, $subject, $body); } + +/** + * notify a user that they have received an "attn:" message AKA "@-reply" + * + * @param User $user The user who recevied the notice + * @param Notice $notice The notice that was sent + * + * @return void + */ + +function mail_notify_attn($user, $notice) +{ + if (!$user->email || !$user->emailnotifyattn) { + return; + } + + $sender = $notice->getProfile(); + + $bestname = $sender->getBestName(); + + common_init_locale($user->language); + + $subject = sprintf(_('%s sent a notice to your attention'), $bestname); + + $body = sprintf(_("%1\$s just sent a notice to your attention (an '@-reply') on %2\$s.\n\n". + "The notice is here:\n\n". + "\t%3\$s\n\n" . + "It reads:\n\n". + "\t%4\$s\n\n" . + "You can reply back here:\n\n". + "\t%5\$s\n\n" . + "The list of all @-replies for you here:\n\n" . + "%6\$s\n\n" . + "Faithfully yours,\n" . + "%2\$s\n\n" . + "P.S. You can turn off these email notifications here: %7\$s\n"), + $bestname, + common_config('site', 'name'), + common_local_url('shownotice', + array('notice' => $notice->id)), + $notice->content, + common_local_url('newnotice', + array('replyto' => $sender->nickname)), + common_local_url('replies', + array('nickname' => $user->nickname)), + common_local_url('emailsettings')); + + common_init_locale(); + mail_to_user($user, $subject, $body); +} -- cgit v1.2.3-54-g00ecf From 419960fd19c21007958973af5151a84e00b164f8 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 16 Feb 2009 18:45:59 -0500 Subject: wrong name for attn function --- classes/Notice.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'classes/Notice.php') diff --git a/classes/Notice.php b/classes/Notice.php index 570d76f61..8300667fa 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -758,7 +758,7 @@ class Notice extends Memcached_DataObject foreach (array_keys($replied) as $recipient) { $user = User::staticGet('id', $recipient); if ($user) { - mail_attn_notify($user, $notice); + mail_notify_attn($user, $this); } } } -- cgit v1.2.3-54-g00ecf