Slight cleanup in typing and syntax of File and File_* classes
This commit is contained in:
parent
729c6eef36
commit
73fe8a81b7
@ -17,14 +17,7 @@
|
||||
* 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
|
||||
@ -88,7 +81,7 @@ class File extends Managed_DataObject
|
||||
|
||||
$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'];
|
||||
@ -116,16 +109,21 @@ class File extends Managed_DataObject
|
||||
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;
|
||||
|
@ -98,6 +98,9 @@ class File_oembed extends Managed_DataObject
|
||||
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;
|
||||
@ -114,7 +117,9 @@ class File_oembed extends Managed_DataObject
|
||||
$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);
|
||||
@ -122,15 +127,13 @@ class File_oembed extends Managed_DataObject
|
||||
} 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 {
|
||||
|
@ -17,11 +17,7 @@
|
||||
* 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
|
||||
@ -251,7 +247,9 @@ class File_redirection extends Managed_DataObject
|
||||
$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)) {
|
||||
@ -275,11 +273,9 @@ class File_redirection extends Managed_DataObject
|
||||
}
|
||||
$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;
|
||||
|
Loading…
Reference in New Issue
Block a user