From d9e8dabaf4c5b38712a3e3ce97b45c5effee4bad Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Wed, 26 Aug 2009 14:53:52 -0400 Subject: Save the mimetype for oEmbed linked url --- classes/File_oembed.php | 21 ++++++++++++++++++++- classes/laconica.ini | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'classes') diff --git a/classes/File_oembed.php b/classes/File_oembed.php index bbf112729..94de8e117 100644 --- a/classes/File_oembed.php +++ b/classes/File_oembed.php @@ -20,6 +20,7 @@ if (!defined('LACONICA')) { exit(1); } require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; +require_once INSTALLDIR.'/classes/File_redirection.php'; /** * Table Definition for file_oembed @@ -34,6 +35,7 @@ class File_oembed extends Memcached_DataObject public $file_id; // int(4) primary_key not_null public $version; // varchar(20) public $type; // varchar(20) + public $mimetype; // varchar(50) public $provider; // varchar(50) public $provider_url; // varchar(255) public $width; // int(4) @@ -93,7 +95,24 @@ class File_oembed extends Memcached_DataObject if (!empty($data->title)) $file_oembed->title = $data->title; if (!empty($data->author_name)) $file_oembed->author_name = $data->author_name; if (!empty($data->author_url)) $file_oembed->author_url = $data->author_url; - if (!empty($data->url)) $file_oembed->url = $data->url; + if (!empty($data->url)){ + $file_oembed->url = $data->url; + $given_url = File_redirection::_canonUrl($file_oembed->url); + if (! empty($given_url)){ + $file = File::staticGet('url', $given_url); + if (empty($file)) { + $file_redir = File_redirection::staticGet('url', $given_url); + if (empty($file_redir)) { + $redir_data = File_redirection::where($given_url); + $file_oembed->mimetype = $redir_data['type']; + } else { + $file_id = $file_redir->file_id; + } + } else { + $file_oembed->mimetype=$file->mimetype; + } + } + } $file_oembed->insert(); if (!empty($data->thumbnail_url)) { File_thumbnail::saveNew($data, $file_id); diff --git a/classes/laconica.ini b/classes/laconica.ini index 7edeeebe4..f58c30f54 100755 --- a/classes/laconica.ini +++ b/classes/laconica.ini @@ -98,6 +98,7 @@ id = N file_id = 129 version = 2 type = 2 +mimetype = 2 provider = 2 provider_url = 2 width = 1 -- cgit v1.2.3-54-g00ecf From 6d60d74093005992701418edda5be4422e46262f Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Wed, 26 Aug 2009 15:40:51 -0400 Subject: Display linked oembed resources as enclosures if they are of non-html mime types --- classes/File.php | 50 +++++++++++++++++++++++++++++++++++++++++--------- classes/Notice.php | 9 +++++---- lib/rssaction.php | 23 ++++++++++++----------- lib/twitterapi.php | 9 +++++---- 4 files changed, 63 insertions(+), 28 deletions(-) (limited to 'classes') diff --git a/classes/File.php b/classes/File.php index b2c510340..1c64b4d33 100644 --- a/classes/File.php +++ b/classes/File.php @@ -195,17 +195,49 @@ class File extends Memcached_DataObject return 'http://'.$server.$path.$filename; } - function isEnclosure(){ + function getEnclosure(){ + $enclosure = (object) array(); + $enclosure->title=$this->title; + $enclosure->url=$this->url; + $enclosure->title=$this->title; + $enclosure->date=$this->date; + $enclosure->modified=$this->modified; + $enclosure->size=$this->size; + $enclosure->mimetype=$this->mimetype; + if(isset($this->filename)){ - return true; - } - $notEnclosureMimeTypes = array('text/html','application/xhtml+xml'); - $mimetype = strtolower($this->mimetype); - $semicolon = strpos($mimetype,';'); - if($semicolon){ - $mimetype = substr($mimetype,0,$semicolon); + return $enclosure; + }else{ + $notEnclosureMimeTypes = array('text/html','application/xhtml+xml'); + $mimetype = strtolower($this->mimetype); + $semicolon = strpos($mimetype,';'); + if($semicolon){ + $mimetype = substr($mimetype,0,$semicolon); + } + if(in_array($mimetype,$notEnclosureMimeTypes)){ + $ombed = File_oembed::staticGet('file_id',$this->id); + if($oembed){ + $mimetype = strtolower($ombed->mimetype); + $semicolon = strpos($mimetype,';'); + if($semicolon){ + $mimetype = substr($mimetype,0,$semicolon); + } + if(in_array($mimetype,$notEnclosureMimeTypes)){ + return false; + }else{ + if($ombed->mimetype) $enclosure->mimetype=$ombed->mimetype; + if($ombed->url) $enclosure->url=$ombed->url; + if($ombed->title) $enclosure->title=$ombed->title; + if($ombed->modified) $enclosure->modified=$ombed->modified; + unset($ombed->size); + } + }else{ + return $enclosure; + } + }else{ + return $enclosure; + } } - return(! in_array($mimetype,$notEnclosureMimeTypes)); } } diff --git a/classes/Notice.php b/classes/Notice.php index 48d4a0940..c4f163c31 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -1199,10 +1199,11 @@ class Notice extends Memcached_DataObject $attachments = $this->attachments(); if($attachments){ foreach($attachments as $attachment){ - if ($attachment->isEnclosure()) { - $attributes = array('rel'=>'enclosure','href'=>$attachment->url,'type'=>$attachment->mimetype,'length'=>$attachment->size); - if($attachment->title){ - $attributes['title']=$attachment->title; + $enclosure=$attachment->getEnclosure(); + if ($enclosure) { + $attributes = array('rel'=>'enclosure','href'=>$enclosure->url,'type'=>$enclosure->mimetype,'length'=>$enclosure->size); + if($enclosure->title){ + $attributes['title']=$enclosure->title; } $xs->element('link', $attributes, null); } diff --git a/lib/rssaction.php b/lib/rssaction.php index 0aca96566..7e317010d 100644 --- a/lib/rssaction.php +++ b/lib/rssaction.php @@ -258,26 +258,27 @@ class Rss10Action extends Action $attachments = $notice->attachments(); if($attachments){ foreach($attachments as $attachment){ - if ($attachment->isEnclosure()) { + $enclosure=$attachment->getEnclosure(); + if ($enclosure) { // DO NOT move xmlns declaration to root element. Making it // the default namespace here improves compatibility with // real-world feed readers. $attribs = array( - 'rdf:resource' => $attachment->url, - 'url' => $attachment->url, + 'rdf:resource' => $enclosure->url, + 'url' => $enclosure->url, 'xmlns' => 'http://purl.oclc.org/net/rss_2.0/enc#' ); - if ($attachment->title) { - $attribs['dc:title'] = $attachment->title; + if ($enclosure->title) { + $attribs['dc:title'] = $enclosure->title; } - if ($attachment->modified) { - $attribs['dc:date'] = common_date_w3dtf($attachment->modified); + if ($enclosure->modified) { + $attribs['dc:date'] = common_date_w3dtf($enclosure->modified); } - if ($attachment->size) { - $attribs['length'] = $attachment->size; + if ($enclosure->size) { + $attribs['length'] = $enclosure->size; } - if ($attachment->mimetype) { - $attribs['type'] = $attachment->mimetype; + if ($enclosure->mimetype) { + $attribs['type'] = $enclosure->mimetype; } $this->element('enclosure', $attribs); } diff --git a/lib/twitterapi.php b/lib/twitterapi.php index 583007208..e0087e689 100644 --- a/lib/twitterapi.php +++ b/lib/twitterapi.php @@ -274,11 +274,12 @@ class TwitterapiAction extends Action $enclosures = array(); foreach ($attachments as $attachment) { - if ($attachment->isEnclosure()) { + $enclosure_o=$attachment->getEnclosure(); + if ($enclosure_o) { $enclosure = array(); - $enclosure['url'] = $attachment->url; - $enclosure['mimetype'] = $attachment->mimetype; - $enclosure['size'] = $attachment->size; + $enclosure['url'] = $enclosure_o->url; + $enclosure['mimetype'] = $enclosure_o->mimetype; + $enclosure['size'] = $enclosure_o->size; $enclosures[] = $enclosure; } } -- cgit v1.2.3-54-g00ecf From 504c42aa7d4ff5cccd722bceb3231a5a8f46a27b Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Wed, 26 Aug 2009 21:51:54 -0400 Subject: Fix some stupid bugs, such as a mispelling of oembed --- classes/File.php | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'classes') diff --git a/classes/File.php b/classes/File.php index 1c64b4d33..58fe91237 100644 --- a/classes/File.php +++ b/classes/File.php @@ -204,10 +204,8 @@ class File extends Memcached_DataObject $enclosure->modified=$this->modified; $enclosure->size=$this->size; $enclosure->mimetype=$this->mimetype; - - if(isset($this->filename)){ - return $enclosure; - }else{ + + if(! isset($this->filename)){ $notEnclosureMimeTypes = array('text/html','application/xhtml+xml'); $mimetype = strtolower($this->mimetype); $semicolon = strpos($mimetype,';'); @@ -215,9 +213,9 @@ class File extends Memcached_DataObject $mimetype = substr($mimetype,0,$semicolon); } if(in_array($mimetype,$notEnclosureMimeTypes)){ - $ombed = File_oembed::staticGet('file_id',$this->id); + $oembed = File_oembed::staticGet('file_id',$this->id); if($oembed){ - $mimetype = strtolower($ombed->mimetype); + $mimetype = strtolower($oembed->mimetype); $semicolon = strpos($mimetype,';'); if($semicolon){ $mimetype = substr($mimetype,0,$semicolon); @@ -225,19 +223,16 @@ class File extends Memcached_DataObject if(in_array($mimetype,$notEnclosureMimeTypes)){ return false; }else{ - if($ombed->mimetype) $enclosure->mimetype=$ombed->mimetype; - if($ombed->url) $enclosure->url=$ombed->url; - if($ombed->title) $enclosure->title=$ombed->title; - if($ombed->modified) $enclosure->modified=$ombed->modified; - unset($ombed->size); + 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 $enclosure; } - }else{ - return $enclosure; } } + return $enclosure; } } -- cgit v1.2.3-54-g00ecf