]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/newnotice.php
db stuff for URLs: redirections, oembed, etc.
[quix0rs-gnu-social.git] / actions / newnotice.php
index cbd04c58b226c0a609c44996f7048bcf28f7abcd..8b03abc62cef3603bccb4a43b8c1c5fe262db0b6 100644 (file)
@@ -166,6 +166,8 @@ class NewnoticeAction extends Action
             return;
         }
 
+        $this->saveUrls($notice);
+
         common_broadcast_notice($notice);
 
         if ($this->boolean('ajax')) {
@@ -191,6 +193,37 @@ class NewnoticeAction extends Action
         }
     }
 
+    /** save all urls in the notice to the db
+     *
+     * follow redirects and save all available file information
+     * (mimetype, date, size, oembed, etc.)
+     *
+     * @param class $notice Notice to pull URLs from
+     *
+     * @return void
+     */
+    function saveUrls($notice) {
+        common_debug("Saving all URLs");
+        common_replace_urls_callback($notice->content, array($this, 'saveUrl'), $notice->id);
+    }
+
+    function saveUrl($data) {
+        list($url, $notice_id) = $data;
+        common_debug("Saving $url for $notice_id");
+        $file = File::staticGet('url', $url);
+        if (empty($file)) {
+            common_debug('unknown file/url');
+            $file = new File;
+            $file->url = $url;
+            $file->insert();
+        }
+        common_debug('File: ' . print_r($file, true));
+        $f2p = new File_to_post;
+        $f2p->file_id = $file->id;
+        $f2p->post_id = $notice_id;
+        $f2p->insert();
+    }
+
     /**
      * Show an Ajax-y error message
      *