* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
-
-require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
-require_once INSTALLDIR.'/classes/File_redirection.php';
-require_once INSTALLDIR.'/classes/File_oembed.php';
-require_once INSTALLDIR.'/classes/File_thumbnail.php';
-require_once INSTALLDIR.'/classes/File_to_post.php';
-//require_once INSTALLDIR.'/classes/File_redirection.php';
+if (!defined('GNUSOCIAL')) { exit(1); }
/**
* Table Definition for file
$x = File::getKV('url', $given_url);
- if (empty($x)) {
+ if (!$x instanceof File) {
$x = new File;
$x->url = $given_url;
if (!empty($redir_data['protected'])) $x->protected = $redir_data['protected'];
public function saveOembed(array $redir_data, $given_url)
{
if (isset($redir_data['type'])
- && (('text/html' === substr($redir_data['type'], 0, 9) || 'application/xhtml+xml' === substr($redir_data['type'], 0, 21)))
- && ($oembed_data = File_oembed::_getOembed($given_url))) {
+ && (('text/html' === substr($redir_data['type'], 0, 9)
+ || 'application/xhtml+xml' === substr($redir_data['type'], 0, 21)))) {
+ try {
+ $oembed_data = File_oembed::_getOembed($given_url);
+ } catch (Exception $e) {
+ return false;
+ }
$fo = File_oembed::getKV('file_id', $this->id);
- if (empty($fo)) {
+ if ($fo instanceof File_oembed) {
+ common_log(LOG_WARNING, "Strangely, a File_oembed object exists for new file $file_id", __FILE__);
+ } else {
File_oembed::saveNew($oembed_data, $this->id);
return true;
- } else {
- common_log(LOG_WARNING, "Strangely, a File_oembed object exists for new file $file_id", __FILE__);
}
}
return false;
function saveNew($data, $file_id) {
$file_oembed = new File_oembed;
$file_oembed->file_id = $file_id;
+ if (!isset($data->version)) {
+ common_debug('DEBUGGING oEmbed: data->version undefined in variable $data: '.var_export($data, true));
+ }
$file_oembed->version = $data->version;
$file_oembed->type = $data->type;
if (!empty($data->provider_name)) $file_oembed->provider = $data->provider_name;
$given_url = File_redirection::_canonUrl($file_oembed->url);
if (! empty($given_url)){
$file = File::getKV('url', $given_url);
- if (empty($file)) {
+ if ($file instanceof File) {
+ $file_oembed->mimetype = $file->mimetype;
+ } else {
$file_redir = File_redirection::getKV('url', $given_url);
if (empty($file_redir)) {
$redir_data = File_redirection::where($given_url);
} else {
$file_id = $file_redir->file_id;
}
- } else {
- $file_oembed->mimetype=$file->mimetype;
}
}
}
$file_oembed->insert();
if (!empty($data->thumbnail_url) || ($data->type == 'photo')) {
$ft = File_thumbnail::getKV('file_id', $file_id);
- if (!empty($ft)) {
+ if ($ft instanceof File_thumbnail) {
common_log(LOG_WARNING, "Strangely, a File_thumbnail object exists for new file $file_id",
__FILE__);
} else {
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
-
-require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
-require_once INSTALLDIR.'/classes/File.php';
-require_once INSTALLDIR.'/classes/File_oembed.php';
+if (!defined('GNUSOCIAL')) { exit(1); }
/**
* Table Definition for file_redirection
$short_url = (string)$short_url;
// store it
$file = File::getKV('url', $long_url);
- if (empty($file)) {
+ if ($file instanceof File) {
+ $file_id = $file->id;
+ } else {
// Check if the target URL is itself a redirect...
$redir_data = File_redirection::where($long_url);
if (is_array($redir_data)) {
}
$file_id = $file->id;
}
- } else {
- $file_id = $file->id;
}
$file_redir = File_redirection::getKV('url', $short_url);
- if (empty($file_redir)) {
+ if (!$file_redir instanceof File_redirection) {
$file_redir = new File_redirection;
$file_redir->url = $short_url;
$file_redir->file_id = $file_id;