summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Prodromou <evan@status.net>2009-08-27 20:23:31 -0700
committerEvan Prodromou <evan@status.net>2009-08-27 20:23:31 -0700
commitc0d03fc2799c7b0c57d05166b404a3d13427f497 (patch)
treef7e606d095eb3d7766d78c82a7b7217e8e7c775b
parent34ce75c71d37754fa941233c805c042a47910184 (diff)
make URL analyzer save new info on URLs0.8.1rc2
-rw-r--r--classes/File.php8
-rw-r--r--lib/util.php21
2 files changed, 18 insertions, 11 deletions
diff --git a/classes/File.php b/classes/File.php
index 0cebfc55e..f4d0a3a48 100644
--- a/classes/File.php
+++ b/classes/File.php
@@ -85,7 +85,7 @@ class File extends Memcached_DataObject
return $x;
}
- function processNew($given_url, $notice_id) {
+ function processNew($given_url, $notice_id=null) {
if (empty($given_url)) return -1; // error, no url to process
$given_url = File_redirection::_canonUrl($given_url);
if (empty($given_url)) return -1; // error, no url to process
@@ -96,7 +96,7 @@ class File extends Memcached_DataObject
$redir_data = File_redirection::where($given_url);
$redir_url = $redir_data['url'];
// TODO: max field length
- if ($redir_url === $given_url || strlen($redir_url) > 255) {
+ if ($redir_url === $given_url || strlen($redir_url) > 255) {
$x = File::saveNew($redir_data, $given_url);
$file_id = $x->id;
} else {
@@ -119,7 +119,9 @@ class File extends Memcached_DataObject
}
}
- File_to_post::processNew($file_id, $notice_id);
+ if (!empty($notice_id)) {
+ File_to_post::processNew($file_id, $notice_id);
+ }
return $x;
}
diff --git a/lib/util.php b/lib/util.php
index 070b4232c..8a56be55d 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -520,7 +520,7 @@ function common_linkify($url) {
// functions
$url = htmlspecialchars_decode($url);
- if(strpos($url, '@')!==false && strpos($url, ':')===false){
+ if(strpos($url, '@') !== false && strpos($url, ':') === false) {
//url is an email address without the mailto: protocol
return XMLStringer::estring('a', array('href' => "mailto:$url", 'rel' => 'external'), $url);
}
@@ -544,19 +544,24 @@ function common_linkify($url) {
// Check to see whether this is a known "attachment" URL.
- $localfile = File::staticGet('url', $longurl);
+ $f = File::staticGet('url', $longurl);
- if (!empty($localfile)) {
- if (isset($localfile->filename)) {
+ if (empty($f)) {
+ // XXX: this writes to the database. :<
+ $f = File::processNew($longurl);
+ }
+
+ if (!empty($f)) {
+ if (isset($f->filename)) {
$is_attachment = true;
- $attachment_id = $localfile->id;
+ $attachment_id = $f->id;
} else { // if it has OEmbed info, it's an attachment, too
- $foe = File_oembed::staticGet('file_id', $localfile->id);
+ $foe = File_oembed::staticGet('file_id', $f->id);
if (!empty($foe)) {
$is_attachment = true;
- $attachment_id = $localfile->id;
+ $attachment_id = $f->id;
- $thumb = File_thumbnail::staticGet('file_id', $localfile->id);
+ $thumb = File_thumbnail::staticGet('file_id', $f->id);
if (!empty($thumb)) {
$has_thumb = true;
}