]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/newnotice.php
Add basic support for Georgian (ka)
[quix0rs-gnu-social.git] / actions / newnotice.php
index 2aa354870b2813a87d5fe829100ef3a3951fcb4b..ea832cf4e1300ec0ce75424c40f9f4e8530e1164 100644 (file)
@@ -131,6 +131,8 @@ class NewnoticeAction extends Action
         $user = common_current_user();
         assert($user); // XXX: maybe an error instead...
         $content = $this->trimmed('status_textarea');
+        $options = array();
+        Event::handle('StartSaveNewNoticeWeb', array($this, $user, &$content, &$options));
 
         if (!$content) {
             $this->clientError(_('No content!'));
@@ -157,52 +159,65 @@ class NewnoticeAction extends Action
                                        Notice::maxContent()));
         }
 
-        $replyto = $this->trimmed('inreplyto');
-        #If an ID of 0 is wrongly passed here, it will cause a database error,
-        #so override it...
-        if ($replyto == 0) {
-            $replyto = 'false';
+        $replyto = intval($this->trimmed('inreplyto'));
+        if ($replyto) {
+            $options['reply_to'] = $replyto;
         }
 
-        $uploads = array();
-        foreach($_FILES as $name => $value) {
-            if(substr($name, 0, 6) == "attach") {
-                $upload = MediaFile::fromUpload($name);
-                if (isset($upload)) {
-                    $content_shortened .= ' ' . $upload->shortUrl();
-                }
+        $upload = null;
+        $upload = MediaFile::fromUpload('attach');
+
+        if (isset($upload)) {
+
+            if (Event::handle('StartSaveNewNoticeAppendAttachment', array($this, $upload, &$content_shortened, &$options))) {
+                $content_shortened .= ' ' . $upload->shortUrl();
             }
-        }
-        if (Notice::contentTooLong($content_shortened)) {
-            foreach($uploads as $upload) {
+            Event::handle('EndSaveNewNoticeAppendAttachment', array($this, $upload, &$content_shortened, &$options));
+
+            if (Notice::contentTooLong($content_shortened)) {
                 $upload->delete();
+                $this->clientError(
+                    sprintf(
+                        _('Max notice size is %d chars, including attachment URL.'),
+                          Notice::maxContent()
+                    )
+                );
             }
-            $this->clientError(
-                sprintf(
-                    _('Max notice size is %d chars, including attachment URL.'),
-                      Notice::maxContent()
-                )
-            );
         }
 
-        $options = array('reply_to' => ($replyto == 'false') ? null : $replyto);
-
-        if ($user->shareLocation() && $this->arg('notice_data-geo')) {
-
-            $locOptions = Notice::locationOptions($this->trimmed('lat'),
-                                                  $this->trimmed('lon'),
-                                                  $this->trimmed('location_id'),
-                                                  $this->trimmed('location_ns'),
-                                                  $user->getProfile());
+        if ($user->shareLocation()) {
+            // use browser data if checked; otherwise profile data
+            if ($this->arg('notice_data-geo')) {
+                $locOptions = Notice::locationOptions($this->trimmed('lat'),
+                                                      $this->trimmed('lon'),
+                                                      $this->trimmed('location_id'),
+                                                      $this->trimmed('location_ns'),
+                                                      $user->getProfile());
+            } else {
+                $locOptions = Notice::locationOptions(null,
+                                                      null,
+                                                      null,
+                                                      null,
+                                                      $user->getProfile());
+            }
 
             $options = array_merge($options, $locOptions);
         }
 
-        $notice = Notice::saveNew($user->id, $content_shortened, 'web', $options);
+        $author_id = $user->id;
+        $text      = $content_shortened;
+
+        if (Event::handle('StartNoticeSaveWeb', array($this, &$author_id, &$text, &$options))) {
+
+            $notice = Notice::saveNew($user->id, $content_shortened, 'web', $options);
+
+            if (isset($upload)) {
+                $upload->attachToNotice($notice);
+            }
 
-        foreach($uploads as $upload) {
-            $upload->attachToNotice($notice);
+            Event::handle('EndNoticeSaveWeb', array($this, $notice));
         }
+        Event::handle('EndSaveNewNoticeWeb', array($this, $user, &$content_shortened, &$options));
 
         if ($this->boolean('ajax')) {
             header('Content-Type: text/xml;charset=utf-8');