summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorBrion Vibber <brion@status.net>2010-11-12 12:28:44 -0800
committerBrion Vibber <brion@status.net>2010-11-12 12:28:44 -0800
commit5d12ec0532fa9bcc71644186f6ff80f2b527703c (patch)
tree5a62c9af56efa0cdf47a06bf0fe26c8efbf8f7b7 /classes
parentfdf3a23da7769586a818ca2219ec6bc1b46587de (diff)
parentcb124fe831a3c77dfca89590ebb8d691685bb573 (diff)
Merge branch 'oembed-thumbnails' into 0.9.x
Diffstat (limited to 'classes')
-rw-r--r--classes/File.php26
-rw-r--r--classes/File_oembed.php6
-rw-r--r--classes/File_thumbnail.php30
3 files changed, 50 insertions, 12 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..a5540ecfe 100644
--- a/classes/File_oembed.php
+++ b/classes/File_oembed.php
@@ -58,11 +58,11 @@ class File_oembed extends Memcached_DataObject
return array(false, false, false);
}
- function _getOembed($url, $maxwidth = 500, $maxheight = 400) {
+ function _getOembed($url) {
require_once INSTALLDIR.'/extlib/Services/oEmbed.php';
$parameters = array(
- 'maxwidth'=>$maxwidth,
- 'maxheight'=>$maxheight,
+ 'maxwidth' => common_config('attachments', 'thumb_width'),
+ 'maxheight' => common_config('attachments', 'thumb_height'),
);
try{
$oEmbed = new Services_oEmbed($url);
diff --git a/classes/File_thumbnail.php b/classes/File_thumbnail.php
index edae8ac21..d371b9e8a 100644
--- a/classes/File_thumbnail.php
+++ b/classes/File_thumbnail.php
@@ -48,12 +48,34 @@ 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) {
+ self::saveThumbnail($file_id,
+ $data->thumbnail_url,
+ $data->thumbnail_width,
+ $data->thumbnail_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();
}
}