]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Add events for filtering and logging new notices
authorEvan Prodromou <evan@controlyourself.ca>
Fri, 13 Feb 2009 15:52:26 +0000 (10:52 -0500)
committerEvan Prodromou <evan@controlyourself.ca>
Fri, 13 Feb 2009 15:52:26 +0000 (10:52 -0500)
EVENTS.txt
actions/newnotice.php
classes/Notice.php

index 16ca9ea06662f75598997fbef528f38816283673..af0bee587c1be7dc32eaa514ceac66848b494765 100644 (file)
@@ -30,7 +30,7 @@ EndShowLaconicaStyles: End showing Laconica Style links;  good place to add hand
 StartShowUAStyles: Showing custom UA Style links
 - $action: the current action
 
-EndShowUAStyles: End showing custom UA Style links; good place to add user-agent (e.g., filter, -webkit, -moz) specific styles 
+EndShowUAStyles: End showing custom UA Style links; good place to add user-agent (e.g., filter, -webkit, -moz) specific styles
 - $action: the current action
 
 StartShowScripts: Showing JavaScript links
@@ -76,3 +76,9 @@ StartShowContentBlock: Showing before the content container
 EndShowContentBlock: Showing after the content container
 - $action: the current action
 
+StartNoticeSave: before inserting a notice (good place for content filters)
+- $notice: notice being saved (no ID or URI)
+
+EndNoticeSave: after inserting a notice and related code
+- $notice: notice that was saved (with ID and URI)
+
index 5e7691f33d1cae68442b8b18b4c643eb3deca24b..9face9644356a0a08375f3dfdeee1dda5d7a7059 100644 (file)
@@ -98,7 +98,12 @@ class NewnoticeAction extends Action
                 return;
             }
 
-            $this->saveNewNotice();
+            try {
+                $this->saveNewNotice();
+            } catch (Exception $e) {
+                $this->showForm($e->getMessage());
+                return;
+            }
         } else {
             $this->showForm();
         }
@@ -123,15 +128,13 @@ class NewnoticeAction extends Action
         $content = $this->trimmed('status_textarea');
 
         if (!$content) {
-            $this->showForm(_('No content!'));
-            return;
+            $this->clientError(_('No content!'));
         } else {
             $content_shortened = common_shorten_links($content);
 
             if (mb_strlen($content_shortened) > 140) {
-                $this->showForm(_('That\'s too long. '.
-                                  'Max notice size is 140 chars.'));
-                return;
+                $this->clientError(_('That\'s too long. '.
+                                     'Max notice size is 140 chars.'));
             }
         }
 
@@ -154,7 +157,7 @@ class NewnoticeAction extends Action
                                   ($replyto == 'false') ? null : $replyto);
 
         if (is_string($notice)) {
-            $this->showForm($notice);
+            $this->clientError($notice);
             return;
         }
 
index 32998836862043f1ca74a9602f478a9328440774..6db59c96ef5775b9b82d4a66311c9e8413592e90 100644 (file)
@@ -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