Add $config['attachments']['process_links'] to allow disabling processing of mentioned URL links for attachment info (oEmbed lookups) and dereferencing of redirects that we didn't have shortened ourselves.
This option may be useful for intranet sites that don't have direct access to the internet, as they may be unable to successfully fetch those resources.
This commit is contained in:
parent
589aee587f
commit
197b56778a
@ -139,6 +139,7 @@ class File_redirection extends Memcached_DataObject
|
|||||||
* reached.
|
* reached.
|
||||||
*
|
*
|
||||||
* @param string $in_url
|
* @param string $in_url
|
||||||
|
* @param boolean $discover true to attempt dereferencing the redirect if we don't know it already
|
||||||
* @return mixed one of:
|
* @return mixed one of:
|
||||||
* string - target URL, if this is a direct link or a known redirect
|
* string - target URL, if this is a direct link or a known redirect
|
||||||
* array - redirect info if this is an *unknown* redirect:
|
* array - redirect info if this is an *unknown* redirect:
|
||||||
@ -150,7 +151,7 @@ class File_redirection extends Memcached_DataObject
|
|||||||
* size (optional): byte size from Content-Length header
|
* size (optional): byte size from Content-Length header
|
||||||
* time (optional): timestamp from Last-Modified header
|
* time (optional): timestamp from Last-Modified header
|
||||||
*/
|
*/
|
||||||
public function where($in_url) {
|
public function where($in_url, $discover=true) {
|
||||||
// let's see if we know this...
|
// let's see if we know this...
|
||||||
$a = File::staticGet('url', $in_url);
|
$a = File::staticGet('url', $in_url);
|
||||||
|
|
||||||
@ -166,8 +167,13 @@ class File_redirection extends Memcached_DataObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($discover) {
|
||||||
$ret = File_redirection::lookupWhere($in_url);
|
$ret = File_redirection::lookupWhere($in_url);
|
||||||
return $ret;
|
return $ret;
|
||||||
|
} else {
|
||||||
|
// No manual dereferencing; leave the unknown URL as is.
|
||||||
|
return $in_url;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -476,8 +476,10 @@ class Notice extends Memcached_DataObject
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function saveUrls() {
|
function saveUrls() {
|
||||||
|
if (common_config('attachments', 'process_links')) {
|
||||||
common_replace_urls_callback($this->content, array($this, 'saveUrl'), $this->id);
|
common_replace_urls_callback($this->content, array($this, 'saveUrl'), $this->id);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save the given URLs as related links/attachments to the db
|
* Save the given URLs as related links/attachments to the db
|
||||||
@ -489,11 +491,13 @@ class Notice extends Memcached_DataObject
|
|||||||
*/
|
*/
|
||||||
function saveKnownUrls($urls)
|
function saveKnownUrls($urls)
|
||||||
{
|
{
|
||||||
|
if (common_config('attachments', 'process_links')) {
|
||||||
// @fixme validation?
|
// @fixme validation?
|
||||||
foreach (array_unique($urls) as $url) {
|
foreach (array_unique($urls) as $url) {
|
||||||
File::processNew($url, $this->id);
|
File::processNew($url, $this->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private callback
|
* @private callback
|
||||||
|
@ -253,6 +253,7 @@ $default =
|
|||||||
'show_thumbs' => true, // show thumbnails in notice lists for uploaded images, and photos and videos linked remotely that provide oEmbed info
|
'show_thumbs' => true, // show thumbnails in notice lists for uploaded images, and photos and videos linked remotely that provide oEmbed info
|
||||||
'thumb_width' => 100,
|
'thumb_width' => 100,
|
||||||
'thumb_height' => 75,
|
'thumb_height' => 75,
|
||||||
|
'process_links' => true, // check linked resources for embeddable photos and videos; this will hit referenced external web sites when processing new messages.
|
||||||
),
|
),
|
||||||
'application' =>
|
'application' =>
|
||||||
array('desclimit' => null),
|
array('desclimit' => null),
|
||||||
|
@ -848,7 +848,7 @@ function common_linkify($url) {
|
|||||||
|
|
||||||
$canon = File_redirection::_canonUrl($url);
|
$canon = File_redirection::_canonUrl($url);
|
||||||
|
|
||||||
$longurl_data = File_redirection::where($canon);
|
$longurl_data = File_redirection::where($canon, common_config('attachments', 'process_links'));
|
||||||
if (is_array($longurl_data)) {
|
if (is_array($longurl_data)) {
|
||||||
$longurl = $longurl_data['url'];
|
$longurl = $longurl_data['url'];
|
||||||
} elseif (is_string($longurl_data)) {
|
} elseif (is_string($longurl_data)) {
|
||||||
@ -872,9 +872,11 @@ function common_linkify($url) {
|
|||||||
$f = File::staticGet('url', $longurl);
|
$f = File::staticGet('url', $longurl);
|
||||||
|
|
||||||
if (empty($f)) {
|
if (empty($f)) {
|
||||||
|
if (common_config('attachments', 'process_links')) {
|
||||||
// XXX: this writes to the database. :<
|
// XXX: this writes to the database. :<
|
||||||
$f = File::processNew($longurl);
|
$f = File::processNew($longurl);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($f)) {
|
if (!empty($f)) {
|
||||||
if ($f->getEnclosure()) {
|
if ($f->getEnclosure()) {
|
||||||
|
@ -50,7 +50,7 @@ class LinkPreviewPlugin extends Plugin
|
|||||||
function onEndShowScripts($action)
|
function onEndShowScripts($action)
|
||||||
{
|
{
|
||||||
$user = common_current_user();
|
$user = common_current_user();
|
||||||
if ($user) {
|
if ($user && common_config('attachments', 'process_links')) {
|
||||||
$action->script('plugins/LinkPreview/linkpreview.js');
|
$action->script('plugins/LinkPreview/linkpreview.js');
|
||||||
$data = json_encode(array(
|
$data = json_encode(array(
|
||||||
'api' => common_local_url('oembedproxy'),
|
'api' => common_local_url('oembedproxy'),
|
||||||
|
@ -659,10 +659,12 @@ class TwitterImport
|
|||||||
*/
|
*/
|
||||||
function saveStatusAttachments($notice, $status)
|
function saveStatusAttachments($notice, $status)
|
||||||
{
|
{
|
||||||
|
if (common_config('attachments', 'process_links')) {
|
||||||
if (!empty($status->entities) && !empty($status->entities->urls)) {
|
if (!empty($status->entities) && !empty($status->entities->urls)) {
|
||||||
foreach ($status->entities->urls as $url) {
|
foreach ($status->entities->urls as $url) {
|
||||||
File::processNew($url->url, $notice->id);
|
File::processNew($url->url, $notice->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user