summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorEvan Prodromou <evan@status.net>2010-11-15 11:57:31 -0500
committerEvan Prodromou <evan@status.net>2010-11-15 11:57:31 -0500
commit8a21b13ee93cf46626ba9e99a4fda44587e6d1a1 (patch)
treed48111cc0c91060f237ecc268a5ee2b0c69ce029 /classes
parentc1cee3b27ffa1529009195604c5495bef4f83bc2 (diff)
parent4f323efdf7abc5452152a87241e320aca20ce486 (diff)
Merge remote branch 'gitorious/0.9.x' into 0.9.x
Diffstat (limited to 'classes')
-rw-r--r--classes/File.php26
-rw-r--r--classes/File_oembed.php28
-rw-r--r--classes/File_thumbnail.php41
3 files changed, 67 insertions, 28 deletions
diff --git a/classes/File.php b/classes/File.php
index 16e00024a..499c8d72c 100644
--- a/classes/File.php
+++ b/classes/File.php
@@ -352,22 +352,28 @@ class File extends Memcached_DataObject
$mimetype = substr($mimetype,0,$semicolon);
}
if(in_array($mimetype,$notEnclosureMimeTypes)){
+ // Never treat generic HTML links as an enclosure type!
+ // But if we have oEmbed info, we'll consider it golden.
$oembed = File_oembed::staticGet('file_id',$this->id);
- if($oembed){
+ if($oembed && in_array($oembed->type, array('photo', 'video'))){
$mimetype = strtolower($oembed->mimetype);
$semicolon = strpos($mimetype,';');
if($semicolon){
$mimetype = substr($mimetype,0,$semicolon);
}
- if(in_array($mimetype,$notEnclosureMimeTypes)){
- return false;
- }else{
+ // @fixme uncertain if this is right.
+ // we want to expose things like YouTube videos as
+ // viewable attachments, but don't expose them as
+ // downloadable enclosures.....?
+ //if (in_array($mimetype, $notEnclosureMimeTypes)) {
+ // return false;
+ //} else {
if($oembed->mimetype) $enclosure->mimetype=$oembed->mimetype;
if($oembed->url) $enclosure->url=$oembed->url;
if($oembed->title) $enclosure->title=$oembed->title;
if($oembed->modified) $enclosure->modified=$oembed->modified;
unset($oembed->size);
- }
+ //}
} else {
return false;
}
@@ -382,4 +388,14 @@ class File extends Memcached_DataObject
$enclosure = $this->getEnclosure();
return !empty($enclosure);
}
+
+ /**
+ * Get the attachment's thumbnail record, if any.
+ *
+ * @return File_thumbnail
+ */
+ function getThumbnail()
+ {
+ return File_thumbnail::staticGet('file_id', $this->id);
+ }
}
diff --git a/classes/File_oembed.php b/classes/File_oembed.php
index 4813d5dda..b7bf3a5da 100644
--- a/classes/File_oembed.php
+++ b/classes/File_oembed.php
@@ -58,26 +58,16 @@ class File_oembed extends Memcached_DataObject
return array(false, false, false);
}
- function _getOembed($url, $maxwidth = 500, $maxheight = 400) {
- require_once INSTALLDIR.'/extlib/Services/oEmbed.php';
+ function _getOembed($url) {
$parameters = array(
- 'maxwidth'=>$maxwidth,
- 'maxheight'=>$maxheight,
+ 'maxwidth' => common_config('attachments', 'thumb_width'),
+ 'maxheight' => common_config('attachments', 'thumb_height'),
);
- try{
- $oEmbed = new Services_oEmbed($url);
- $object = $oEmbed->getObject($parameters);
- return $object;
- }catch(Exception $e){
- try{
- $oEmbed = new Services_oEmbed($url, array(
- Services_oEmbed::OPTION_API => common_config('oohembed', 'endpoint')
- ));
- $object = $oEmbed->getObject($parameters);
- return $object;
- }catch(Exception $ex){
- return false;
- }
+ try {
+ return oEmbedHelper::getObject($url, $parameters);
+ } catch (Exception $e) {
+ common_log(LOG_ERR, "Error during oembed lookup for $url - " . $e->getMessage());
+ return false;
}
}
@@ -120,7 +110,7 @@ class File_oembed extends Memcached_DataObject
}
}
$file_oembed->insert();
- if (!empty($data->thumbnail_url)) {
+ if (!empty($data->thumbnail_url) || ($data->type == 'photo')) {
$ft = File_thumbnail::staticGet('file_id', $file_id);
if (!empty($ft)) {
common_log(LOG_WARNING, "Strangely, a File_thumbnail object exists for new file $file_id",
diff --git a/classes/File_thumbnail.php b/classes/File_thumbnail.php
index edae8ac21..17bac7f08 100644
--- a/classes/File_thumbnail.php
+++ b/classes/File_thumbnail.php
@@ -48,12 +48,45 @@ class File_thumbnail extends Memcached_DataObject
return array(false, false, false);
}
- function saveNew($data, $file_id) {
+ /**
+ * Save oEmbed-provided thumbnail data
+ *
+ * @param object $data
+ * @param int $file_id
+ */
+ public static function saveNew($data, $file_id) {
+ if (!empty($data->thumbnail_url)) {
+ // Non-photo types such as video will usually
+ // show us a thumbnail, though it's not required.
+ self::saveThumbnail($file_id,
+ $data->thumbnail_url,
+ $data->thumbnail_width,
+ $data->thumbnail_height);
+ } else if ($data->type == 'photo') {
+ // The inline photo URL given should also fit within
+ // our requested thumbnail size, per oEmbed spec.
+ self::saveThumbnail($file_id,
+ $data->url,
+ $data->width,
+ $data->height);
+ }
+ }
+
+ /**
+ * Save a thumbnail record for the referenced file record.
+ *
+ * @param int $file_id
+ * @param string $url
+ * @param int $width
+ * @param int $height
+ */
+ static function saveThumbnail($file_id, $url, $width, $height)
+ {
$tn = new File_thumbnail;
$tn->file_id = $file_id;
- $tn->url = $data->thumbnail_url;
- $tn->width = intval($data->thumbnail_width);
- $tn->height = intval($data->thumbnail_height);
+ $tn->url = $url;
+ $tn->width = intval($width);
+ $tn->height = intval($height);
$tn->insert();
}
}