3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, Controlez-Vous, 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('LACONICA')) { exit(1); }
22 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
25 * Table Definition for file_oembed
28 class File_oembed extends Memcached_DataObject
31 /* the code below is auto generated do not remove the above tag */
33 public $__table = 'file_oembed'; // table name
34 public $id; // int(11) not_null primary_key group_by
35 public $file_id; // int(11) unique_key group_by
36 public $version; // varchar(20)
37 public $type; // varchar(20)
38 public $provider; // varchar(50)
39 public $provider_url; // varchar(255)
40 public $width; // int(11) group_by
41 public $height; // int(11) group_by
42 public $html; // blob(65535) blob
43 public $title; // varchar(255)
44 public $author_name; // varchar(50)
45 public $author_url; // varchar(255)
46 public $url; // varchar(255)
49 function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('File_oembed',$k,$v); }
51 /* the code above is auto generated do not remove the tag below */
55 function _getOembed($url, $maxwidth = 500, $maxheight = 400, $format = 'json') {
56 $cmd = 'http://oohembed.com/oohembed/?url=' . urlencode($url);
57 if (is_int($maxwidth)) $cmd .= "&maxwidth=$maxwidth";
58 if (is_int($maxheight)) $cmd .= "&maxheight=$maxheight";
59 if (is_string($format)) $cmd .= "&format=$format";
60 $oe = @file_get_contents($cmd);
61 if (false === $oe) return false;
62 return array($format => (('json' === $format) ? json_decode($oe, true) : $oe));
65 function saveNew($data, $file_id) {
66 $file_oembed = new File_oembed;
67 $file_oembed->file_id = $file_id;
68 $file_oembed->version = $data['version'];
69 $file_oembed->type = $data['type'];
70 if (!empty($data['provider_name'])) $file_oembed->provider = $data['provider_name'];
71 if (!isset($file_oembed->provider) && !empty($data['provide'])) $file_oembed->provider = $data['provider'];
72 if (!empty($data['provide_url'])) $file_oembed->provider_url = $data['provider_url'];
73 if (!empty($data['width'])) $file_oembed->width = intval($data['width']);
74 if (!empty($data['height'])) $file_oembed->height = intval($data['height']);
75 if (!empty($data['html'])) $file_oembed->html = $data['html'];
76 if (!empty($data['title'])) $file_oembed->title = $data['title'];
77 if (!empty($data['author_name'])) $file_oembed->author_name = $data['author_name'];
78 if (!empty($data['author_url'])) $file_oembed->author_url = $data['author_url'];
79 if (!empty($data['url'])) $file_oembed->url = $data['url'];
80 $file_oembed->insert();
81 if (!empty($data['thumbnail_url'])) {
82 File_thumbnail::saveNew($data, $file_id);