summaryrefslogtreecommitdiff
path: root/actions
diff options
context:
space:
mode:
authorRobin Millette <millette@controlyourself.ca>2009-05-11 13:45:00 -0400
committerRobin Millette <millette@controlyourself.ca>2009-05-11 13:45:00 -0400
commitd010d811ba812ccc8fbb1a49fcba7a30226ea779 (patch)
tree0d3c9d910ce1dacbeaa684701b3976f1cb004481 /actions
parent8fc8eaa1b6199d74f0e17197650c6316b4594203 (diff)
db stuff for URLs: redirections, oembed, etc.
Diffstat (limited to 'actions')
-rw-r--r--actions/newnotice.php33
1 files changed, 33 insertions, 0 deletions
diff --git a/actions/newnotice.php b/actions/newnotice.php
index cbd04c58b..8b03abc62 100644
--- a/actions/newnotice.php
+++ b/actions/newnotice.php
@@ -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
*