3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2008, 2009, StatusNet, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
22 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
23 require_once INSTALLDIR.'/classes/File_redirection.php';
26 * Table Definition for file_oembed
29 class File_oembed extends Memcached_DataObject
32 /* the code below is auto generated do not remove the above tag */
34 public $__table = 'file_oembed'; // table name
35 public $file_id; // int(4) primary_key not_null
36 public $version; // varchar(20)
37 public $type; // varchar(20)
38 public $mimetype; // varchar(50)
39 public $provider; // varchar(50)
40 public $provider_url; // varchar(255)
41 public $width; // int(4)
42 public $height; // int(4)
43 public $html; // text()
44 public $title; // varchar(255)
45 public $author_name; // varchar(50)
46 public $author_url; // varchar(255)
47 public $url; // varchar(255)
48 public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
51 function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('File_oembed',$k,$v); }
53 /* the code above is auto generated do not remove the tag below */
56 function sequenceKey()
58 return array(false, false, false);
61 function _getOembed($url, $maxwidth = 500, $maxheight = 400) {
62 require_once INSTALLDIR.'/extlib/Services/oEmbed.php';
64 'maxwidth'=>$maxwidth,
65 'maxheight'=>$maxheight,
68 $oEmbed = new Services_oEmbed($url);
69 $object = $oEmbed->getObject($parameters);
73 $oEmbed = new Services_oEmbed($url, array(
74 Services_oEmbed::OPTION_API => common_config('oohembed', 'endpoint')
76 $object = $oEmbed->getObject($parameters);
78 }catch(Exception $ex){
85 * Save embedding info for a new file.
87 * @param object $data Services_oEmbed_Object_*
90 function saveNew($data, $file_id) {
91 $file_oembed = new File_oembed;
92 $file_oembed->file_id = $file_id;
93 $file_oembed->version = $data->version;
94 $file_oembed->type = $data->type;
95 if (!empty($data->provider_name)) $file_oembed->provider = $data->provider_name;
96 if (!empty($data->provider)) $file_oembed->provider = $data->provider;
97 if (!empty($data->provide_url)) $file_oembed->provider_url = $data->provider_url;
98 if (!empty($data->width)) $file_oembed->width = intval($data->width);
99 if (!empty($data->height)) $file_oembed->height = intval($data->height);
100 if (!empty($data->html)) $file_oembed->html = $data->html;
101 if (!empty($data->title)) $file_oembed->title = $data->title;
102 if (!empty($data->author_name)) $file_oembed->author_name = $data->author_name;
103 if (!empty($data->author_url)) $file_oembed->author_url = $data->author_url;
104 if (!empty($data->url)){
105 $file_oembed->url = $data->url;
106 $given_url = File_redirection::_canonUrl($file_oembed->url);
107 if (! empty($given_url)){
108 $file = File::staticGet('url', $given_url);
110 $file_redir = File_redirection::staticGet('url', $given_url);
111 if (empty($file_redir)) {
112 $redir_data = File_redirection::where($given_url);
113 $file_oembed->mimetype = $redir_data['type'];
115 $file_id = $file_redir->file_id;
118 $file_oembed->mimetype=$file->mimetype;
122 $file_oembed->insert();
123 if (!empty($data->thumbnail_url)) {
124 $ft = File_thumbnail::staticGet('file_id', $file_id);
126 common_log(LOG_WARNING, "Strangely, a File_thumbnail object exists for new file $file_id",
129 File_thumbnail::saveNew($data, $file_id);