summaryrefslogtreecommitdiff
path: root/classes/Notice.php
diff options
context:
space:
mode:
authorEvan Prodromou <evan@controlyourself.ca>2009-03-12 11:56:23 -0400
committerEvan Prodromou <evan@controlyourself.ca>2009-03-12 11:56:23 -0400
commitb3a0eea3b66e95becb6c4595ed71c7fe71ed6437 (patch)
tree76666150701f03205bfff77e7d034dfa724f8764 /classes/Notice.php
parent399669b1fb955d2d8c18098a7b551184d534a94c (diff)
parente185c0395a6cd250ccd7c8e385c54830be73f937 (diff)
Merge branch '0.7.x' into 0.8.x
Conflicts: classes/Notice.php lib/action.php lib/router.php lib/twitter.php
Diffstat (limited to 'classes/Notice.php')
-rw-r--r--classes/Notice.php50
1 files changed, 44 insertions, 6 deletions
diff --git a/classes/Notice.php b/classes/Notice.php
index 9b5194a5c..adeed2796 100644
--- a/classes/Notice.php
+++ b/classes/Notice.php
@@ -122,6 +122,8 @@ class Notice extends Memcached_DataObject
$profile = Profile::staticGet($profile_id);
+ $final = common_shorten_links($content);
+
if (!$profile) {
common_log(LOG_ERR, 'Problem saving notice. Unknown user.');
return _('Problem saving notice. Unknown user.');
@@ -132,7 +134,12 @@ class Notice extends Memcached_DataObject
return _('Too many notices too fast; take a breather and post again in a few minutes.');
}
- $banned = common_config('profile', 'banned');
+ if (common_config('site', 'dupelimit') > 0 && !Notice::checkDupes($profile_id, $final)) {
+ common_log(LOG_WARNING, 'Dupe posting by profile #' . $profile_id . '; throttled.');
+ return _('Too many duplicate messages too quickly; take a breather and post again in a few minutes.');
+ }
+
+ $banned = common_config('profile', 'banned');
if ( in_array($profile_id, $banned) || in_array($profile->nickname, $banned)) {
common_log(LOG_WARNING, "Attempted post from banned user: $profile->nickname (user id = $profile_id).");
@@ -156,11 +163,12 @@ class Notice extends Memcached_DataObject
$notice->query('BEGIN');
- $notice->created = common_sql_now();
- $notice->content = common_shorten_links($content);
- $notice->rendered = common_render_content($notice->content, $notice);
- $notice->source = $source;
- $notice->uri = $uri;
+ $notice->reply_to = $reply_to;
+ $notice->created = common_sql_now();
+ $notice->content = $final;
+ $notice->rendered = common_render_content($final, $notice);
+ $notice->source = $source;
+ $notice->uri = $uri;
if (!empty($reply_to)) {
$reply_notice = Notice::staticGet('id', $reply_to);
@@ -212,6 +220,36 @@ class Notice extends Memcached_DataObject
return $notice;
}
+ static function checkDupes($profile_id, $content) {
+ $profile = Profile::staticGet($profile_id);
+ if (!$profile) {
+ return false;
+ }
+ $notice = $profile->getNotices(0, NOTICE_CACHE_WINDOW);
+ if ($notice) {
+ $last = 0;
+ while ($notice->fetch()) {
+ if (time() - strtotime($notice->created) >= common_config('site', 'dupelimit')) {
+ return true;
+ } else if ($notice->content == $content) {
+ return false;
+ }
+ }
+ }
+ # If we get here, oldest item in cache window is not
+ # old enough for dupe limit; do direct check against DB
+ $notice = new Notice();
+ $notice->profile_id = $profile_id;
+ $notice->content = $content;
+ if (common_config('db','type') == 'pgsql')
+ $notice->whereAdd('extract(epoch from now() - created) < ' . common_config('site', 'dupelimit'));
+ else
+ $notice->whereAdd('now() - created < ' . common_config('site', 'dupelimit'));
+
+ $cnt = $notice->count();
+ return ($cnt == 0);
+ }
+
static function checkEditThrottle($profile_id) {
$profile = Profile::staticGet($profile_id);
if (!$profile) {