]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/File_oembed.php
bbf112729b008519877b594c61c5c86dc2d9e4f7
[quix0rs-gnu-social.git] / classes / File_oembed.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, 2009, Control Yourself, Inc.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 if (!defined('LACONICA')) { exit(1); }
21
22 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
23
24 /**
25  * Table Definition for file_oembed
26  */
27
28 class File_oembed extends Memcached_DataObject
29 {
30     ###START_AUTOCODE
31     /* the code below is auto generated do not remove the above tag */
32
33     public $__table = 'file_oembed';                     // table name
34     public $file_id;                         // int(4)  primary_key not_null
35     public $version;                         // varchar(20)
36     public $type;                            // varchar(20)
37     public $provider;                        // varchar(50)
38     public $provider_url;                    // varchar(255)
39     public $width;                           // int(4)
40     public $height;                          // int(4)
41     public $html;                            // text()
42     public $title;                           // varchar(255)
43     public $author_name;                     // varchar(50)
44     public $author_url;                      // varchar(255)
45     public $url;                             // varchar(255)
46     public $modified;                        // timestamp()   not_null default_CURRENT_TIMESTAMP
47
48     /* Static get */
49     function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('File_oembed',$k,$v); }
50
51     /* the code above is auto generated do not remove the tag below */
52     ###END_AUTOCODE
53
54     function sequenceKey()
55     {
56         return array(false, false, false);
57     }
58
59     function _getOembed($url, $maxwidth = 500, $maxheight = 400) {
60         require_once INSTALLDIR.'/extlib/Services/oEmbed.php';
61         $parameters = array(
62             'maxwidth'=>$maxwidth,
63             'maxheight'=>$maxheight,
64         );
65         try{
66             $oEmbed = new Services_oEmbed($url);
67             $object = $oEmbed->getObject($parameters);
68             return $object;
69         }catch(Exception $e){
70             try{
71                 $oEmbed = new Services_oEmbed($url, array(
72                     Services_oEmbed::OPTION_API => common_config('oohembed', 'endpoint')
73                 ));
74                 $object = $oEmbed->getObject($parameters);
75                 return $object;
76             }catch(Exception $ex){
77                 return false;
78             }
79         }
80     }
81
82     function saveNew($data, $file_id) {
83         $file_oembed = new File_oembed;
84         $file_oembed->file_id = $file_id;
85         $file_oembed->version = $data->version;
86         $file_oembed->type = $data->type;
87         if (!empty($data->provider_name)) $file_oembed->provider = $data->provider_name;
88         if (!empty($data->provider)) $file_oembed->provider = $data->provider;
89         if (!empty($data->provide_url)) $file_oembed->provider_url = $data->provider_url;
90         if (!empty($data->width)) $file_oembed->width = intval($data->width);
91         if (!empty($data->height)) $file_oembed->height = intval($data->height);
92         if (!empty($data->html)) $file_oembed->html = $data->html;
93         if (!empty($data->title)) $file_oembed->title = $data->title;
94         if (!empty($data->author_name)) $file_oembed->author_name = $data->author_name;
95         if (!empty($data->author_url)) $file_oembed->author_url = $data->author_url;
96         if (!empty($data->url)) $file_oembed->url = $data->url;
97         $file_oembed->insert();
98         if (!empty($data->thumbnail_url)) {
99             File_thumbnail::saveNew($data, $file_id);
100         }
101     }
102 }
103