forked from GNUsocial/gnu-social
db stuff for URLs: redirections, oembed, etc.
This commit is contained in:
parent
8fc8eaa1b6
commit
d010d811ba
@ -166,6 +166,8 @@ class NewnoticeAction extends Action
|
||||
return;
|
||||
}
|
||||
|
||||
$this->saveUrls($notice);
|
||||
|
||||
common_broadcast_notice($notice);
|
||||
|
||||
if ($this->boolean('ajax')) {
|
||||
@ -191,6 +193,37 @@ class NewnoticeAction extends Action
|
||||
}
|
||||
}
|
||||
|
||||
/** save all urls in the notice to the db
|
||||
*
|
||||
* follow redirects and save all available file information
|
||||
* (mimetype, date, size, oembed, etc.)
|
||||
*
|
||||
* @param class $notice Notice to pull URLs from
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function saveUrls($notice) {
|
||||
common_debug("Saving all URLs");
|
||||
common_replace_urls_callback($notice->content, array($this, 'saveUrl'), $notice->id);
|
||||
}
|
||||
|
||||
function saveUrl($data) {
|
||||
list($url, $notice_id) = $data;
|
||||
common_debug("Saving $url for $notice_id");
|
||||
$file = File::staticGet('url', $url);
|
||||
if (empty($file)) {
|
||||
common_debug('unknown file/url');
|
||||
$file = new File;
|
||||
$file->url = $url;
|
||||
$file->insert();
|
||||
}
|
||||
common_debug('File: ' . print_r($file, true));
|
||||
$f2p = new File_to_post;
|
||||
$f2p->file_id = $file->id;
|
||||
$f2p->post_id = $notice_id;
|
||||
$f2p->insert();
|
||||
}
|
||||
|
||||
/**
|
||||
* Show an Ajax-y error message
|
||||
*
|
||||
|
47
classes/File.php
Normal file
47
classes/File.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/*
|
||||
* Laconica - a distributed open-source microblogging tool
|
||||
* Copyright (C) 2008, Controlez-Vous, Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
if (!defined('LACONICA')) { exit(1); }
|
||||
|
||||
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
|
||||
|
||||
/**
|
||||
* Table Definition for file
|
||||
*/
|
||||
|
||||
class File extends Memcached_DataObject
|
||||
{
|
||||
###START_AUTOCODE
|
||||
/* the code below is auto generated do not remove the above tag */
|
||||
|
||||
public $__table = 'file'; // table name
|
||||
public $id; // int(11) not_null primary_key group_by
|
||||
public $url; // varchar(255) unique_key
|
||||
public $mimetype; // varchar(50)
|
||||
public $size; // int(11) group_by
|
||||
public $title; // varchar(255)
|
||||
public $date; // int(11) group_by
|
||||
public $protected; // int(1) group_by
|
||||
|
||||
/* Static get */
|
||||
function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('File',$k,$v); }
|
||||
|
||||
/* the code above is auto generated do not remove the tag below */
|
||||
###END_AUTOCODE
|
||||
}
|
53
classes/File_oembed.php
Normal file
53
classes/File_oembed.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/*
|
||||
* Laconica - a distributed open-source microblogging tool
|
||||
* Copyright (C) 2008, Controlez-Vous, Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
if (!defined('LACONICA')) { exit(1); }
|
||||
|
||||
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
|
||||
|
||||
/**
|
||||
* Table Definition for file_oembed
|
||||
*/
|
||||
|
||||
class File_oembed extends Memcached_DataObject
|
||||
{
|
||||
###START_AUTOCODE
|
||||
/* the code below is auto generated do not remove the above tag */
|
||||
|
||||
public $__table = 'file_oembed'; // table name
|
||||
public $id; // int(11) not_null primary_key group_by
|
||||
public $file_id; // int(11) unique_key group_by
|
||||
public $version; // varchar(20)
|
||||
public $type; // varchar(20)
|
||||
public $provider; // varchar(50)
|
||||
public $provider_url; // varchar(255)
|
||||
public $width; // int(11) group_by
|
||||
public $height; // int(11) group_by
|
||||
public $html; // blob(65535) blob
|
||||
public $title; // varchar(255)
|
||||
public $author_name; // varchar(50)
|
||||
public $author_url; // varchar(255)
|
||||
public $url; // varchar(255)
|
||||
|
||||
/* Static get */
|
||||
function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('File_oembed',$k,$v); }
|
||||
|
||||
/* the code above is auto generated do not remove the tag below */
|
||||
###END_AUTOCODE
|
||||
}
|
45
classes/File_redirection.php
Normal file
45
classes/File_redirection.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/*
|
||||
* Laconica - a distributed open-source microblogging tool
|
||||
* Copyright (C) 2008, Controlez-Vous, Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
if (!defined('LACONICA')) { exit(1); }
|
||||
|
||||
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
|
||||
|
||||
/**
|
||||
* Table Definition for file_redirection
|
||||
*/
|
||||
|
||||
class File_redirection extends Memcached_DataObject
|
||||
{
|
||||
###START_AUTOCODE
|
||||
/* the code below is auto generated do not remove the above tag */
|
||||
|
||||
public $__table = 'file_redirection'; // table name
|
||||
public $id; // int(11) not_null primary_key group_by
|
||||
public $url; // varchar(255) unique_key
|
||||
public $file_id; // int(11) group_by
|
||||
public $redirections; // int(11) group_by
|
||||
public $httpcode; // int(11) group_by
|
||||
|
||||
/* Static get */
|
||||
function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('File_redirection',$k,$v); }
|
||||
|
||||
/* the code above is auto generated do not remove the tag below */
|
||||
###END_AUTOCODE
|
||||
}
|
45
classes/File_thumbnail.php
Normal file
45
classes/File_thumbnail.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/*
|
||||
* Laconica - a distributed open-source microblogging tool
|
||||
* Copyright (C) 2008, Controlez-Vous, Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
if (!defined('LACONICA')) { exit(1); }
|
||||
|
||||
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
|
||||
|
||||
/**
|
||||
* Table Definition for file_thumbnail
|
||||
*/
|
||||
|
||||
class File_thumbnail extends Memcached_DataObject
|
||||
{
|
||||
###START_AUTOCODE
|
||||
/* the code below is auto generated do not remove the above tag */
|
||||
|
||||
public $__table = 'file_thumbnail'; // table name
|
||||
public $id; // int(11) not_null primary_key group_by
|
||||
public $file_id; // int(11) unique_key group_by
|
||||
public $url; // varchar(255) unique_key
|
||||
public $width; // int(11) group_by
|
||||
public $height; // int(11) group_by
|
||||
|
||||
/* Static get */
|
||||
function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('File_thumbnail',$k,$v); }
|
||||
|
||||
/* the code above is auto generated do not remove the tag below */
|
||||
###END_AUTOCODE
|
||||
}
|
43
classes/File_to_post.php
Normal file
43
classes/File_to_post.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/*
|
||||
* Laconica - a distributed open-source microblogging tool
|
||||
* Copyright (C) 2008, Controlez-Vous, Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
if (!defined('LACONICA')) { exit(1); }
|
||||
|
||||
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
|
||||
|
||||
/**
|
||||
* Table Definition for file_to_post
|
||||
*/
|
||||
|
||||
class File_to_post extends Memcached_DataObject
|
||||
{
|
||||
###START_AUTOCODE
|
||||
/* the code below is auto generated do not remove the above tag */
|
||||
|
||||
public $__table = 'file_to_post'; // table name
|
||||
public $id; // int(11) not_null primary_key group_by
|
||||
public $file_id; // int(11) multiple_key group_by
|
||||
public $post_id; // int(11) group_by
|
||||
|
||||
/* Static get */
|
||||
function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('File_to_post',$k,$v); }
|
||||
|
||||
/* the code above is auto generated do not remove the tag below */
|
||||
###END_AUTOCODE
|
||||
}
|
123
classes/laconica.ini
Executable file → Normal file
123
classes/laconica.ini
Executable file → Normal file
@ -1,4 +1,67 @@
|
||||
|
||||
[file]
|
||||
id = 129
|
||||
url = 2
|
||||
mimetype = 2
|
||||
size = 1
|
||||
title = 2
|
||||
date = 1
|
||||
protected = 17
|
||||
|
||||
[file__keys]
|
||||
id = K
|
||||
url = U
|
||||
|
||||
[file_oembed]
|
||||
id = 129
|
||||
file_id = 1
|
||||
version = 2
|
||||
type = 2
|
||||
provider = 2
|
||||
provider_url = 2
|
||||
width = 1
|
||||
height = 1
|
||||
html = 66
|
||||
title = 2
|
||||
author_name = 2
|
||||
author_url = 2
|
||||
url = 2
|
||||
|
||||
[file_oembed__keys]
|
||||
id = K
|
||||
file_id = U
|
||||
|
||||
[file_redirection]
|
||||
id = 129
|
||||
url = 2
|
||||
file_id = 1
|
||||
redirections = 1
|
||||
httpcode = 1
|
||||
|
||||
[file_redirection__keys]
|
||||
id = K
|
||||
url = U
|
||||
|
||||
[file_thumbnail]
|
||||
id = 129
|
||||
file_id = 1
|
||||
url = 2
|
||||
width = 1
|
||||
height = 1
|
||||
|
||||
[file_thumbnail__keys]
|
||||
id = K
|
||||
file_id = U
|
||||
url = U
|
||||
|
||||
[file_to_post]
|
||||
id = 129
|
||||
file_id = 1
|
||||
post_id = 1
|
||||
|
||||
[file_to_post__keys]
|
||||
id = K
|
||||
|
||||
[avatar]
|
||||
profile_id = 129
|
||||
original = 17
|
||||
@ -393,3 +456,63 @@ modified = 384
|
||||
[user_openid__keys]
|
||||
canonical = K
|
||||
display = U
|
||||
|
||||
[file]
|
||||
id = 129
|
||||
url = 2
|
||||
mimetype = 2
|
||||
size = 1
|
||||
title = 2
|
||||
date = 1
|
||||
protected = 1
|
||||
|
||||
[file__keys]
|
||||
id = N
|
||||
|
||||
[file_oembed]
|
||||
id = 129
|
||||
file_id = 129
|
||||
version = 2
|
||||
type = 2
|
||||
provider = 2
|
||||
provider_url = 2
|
||||
width = 1
|
||||
height = 1
|
||||
html = 34
|
||||
title = 2
|
||||
author_name = 2
|
||||
author_url = 2
|
||||
url = 2
|
||||
|
||||
[file_oembed__keys]
|
||||
id = N
|
||||
|
||||
[file_redirection]
|
||||
id = 129
|
||||
url = 2
|
||||
file_id = 129
|
||||
redirections = 1
|
||||
httpcode = 1
|
||||
|
||||
[file_redirection__keys]
|
||||
id = N
|
||||
|
||||
[file_thumbnail]
|
||||
id = 129
|
||||
file_id = 129
|
||||
url = 2
|
||||
width = 1
|
||||
height = 1
|
||||
|
||||
[file_thumbnail__keys]
|
||||
id = N
|
||||
|
||||
[file_to_post]
|
||||
id = 129
|
||||
file_id = 129
|
||||
post_id = 129
|
||||
|
||||
[file_to_post__keys]
|
||||
id = N
|
||||
|
||||
|
||||
|
@ -41,3 +41,74 @@ subscribed = profile:id
|
||||
[fave]
|
||||
notice_id = notice:id
|
||||
user_id = user:id
|
||||
|
||||
[file_oembed]
|
||||
file_id = file:id
|
||||
|
||||
[file_redirection]
|
||||
file_id = file:id
|
||||
|
||||
[file_thumbnail]
|
||||
file_id = file:id
|
||||
|
||||
[file_to_post]
|
||||
file_id = file:id
|
||||
post_id = post:id
|
||||
|
||||
[avatar]
|
||||
profile_id = profile:id
|
||||
|
||||
[user]
|
||||
id = profile:id
|
||||
carrier = sms_carrier:id
|
||||
|
||||
[remote_profile]
|
||||
id = profile:id
|
||||
|
||||
[notice]
|
||||
profile_id = profile:id
|
||||
reply_to = notice:id
|
||||
|
||||
[reply]
|
||||
notice_id = notice:id
|
||||
profile_id = profile:id
|
||||
|
||||
[token]
|
||||
consumer_key = consumer:consumer_key
|
||||
|
||||
[nonce]
|
||||
consumer_key,token = token:consumer_key,token
|
||||
|
||||
[user_openid]
|
||||
user_id = user:id
|
||||
|
||||
[confirm_address]
|
||||
user_id = user:id
|
||||
|
||||
[remember_me]
|
||||
user_id = user:id
|
||||
|
||||
[queue_item]
|
||||
notice_id = notice:id
|
||||
|
||||
[subscription]
|
||||
subscriber = profile:id
|
||||
subscribed = profile:id
|
||||
|
||||
[fave]
|
||||
notice_id = notice:id
|
||||
user_id = user:id
|
||||
|
||||
[file_oembed]
|
||||
file_id = file:id
|
||||
|
||||
[file_redirection]
|
||||
file_id = file:id
|
||||
|
||||
[file_thumbnail]
|
||||
file_id = file:id
|
||||
|
||||
[file_to_post]
|
||||
file_id = file:id
|
||||
post_id = post:id
|
||||
|
||||
|
@ -395,7 +395,7 @@ function common_render_text($text)
|
||||
return $r;
|
||||
}
|
||||
|
||||
function common_replace_urls_callback($text, $callback) {
|
||||
function common_replace_urls_callback($text, $callback, $notice_id = null) {
|
||||
// Start off with a regex
|
||||
$regex = '#'.
|
||||
'(?:'.
|
||||
@ -466,7 +466,11 @@ function common_replace_urls_callback($text, $callback) {
|
||||
$url = (mb_strpos($orig_url, htmlspecialchars($url)) === FALSE) ? $url:htmlspecialchars($url);
|
||||
|
||||
// Call user specified func
|
||||
$modified_url = call_user_func($callback, $url);
|
||||
if (isset($notice_id)) {
|
||||
$modified_url = call_user_func($callback, array($url, $notice_id));
|
||||
} else {
|
||||
$modified_url = call_user_func($callback, $url);
|
||||
}
|
||||
|
||||
// Replace it!
|
||||
$start = mb_strpos($text, $url, $offset);
|
||||
|
Loading…
Reference in New Issue
Block a user