shortening links in notices from XMPP
This patch enables shortening of links, that where send from XMPP. The problem was, that in util.php common_current_user() is not finding the user account from which is posted, so the service to shorten is not known, so no shortening at all... This patch cleans up the xmppdaemon a little bit and hard codes ur1.ca as shortening service _if_ the user is not set. Ugly but working.
This commit is contained in:
parent
4277a6818c
commit
7196410bb0
20
lib/util.php
20
lib/util.php
@ -519,11 +519,16 @@ function common_shorten_links($text)
|
|||||||
|
|
||||||
function common_shorten_link($url, $reverse = false)
|
function common_shorten_link($url, $reverse = false)
|
||||||
{
|
{
|
||||||
|
|
||||||
static $url_cache = array();
|
static $url_cache = array();
|
||||||
if ($reverse) return isset($url_cache[$url]) ? $url_cache[$url] : $url;
|
if ($reverse) return isset($url_cache[$url]) ? $url_cache[$url] : $url;
|
||||||
|
|
||||||
$user = common_current_user();
|
$user = common_current_user();
|
||||||
|
if (!isset($user)) {
|
||||||
|
// common current user does not find a user when called from the XMPP daemon
|
||||||
|
// therefore we'll set one here fix, so that XMPP given URLs may be shortened
|
||||||
|
$user->urlshorteningservice = 'ur1.ca';
|
||||||
|
}
|
||||||
$curlh = curl_init();
|
$curlh = curl_init();
|
||||||
curl_setopt($curlh, CURLOPT_CONNECTTIMEOUT, 20); // # seconds to wait
|
curl_setopt($curlh, CURLOPT_CONNECTTIMEOUT, 20); // # seconds to wait
|
||||||
curl_setopt($curlh, CURLOPT_USERAGENT, 'Laconica');
|
curl_setopt($curlh, CURLOPT_USERAGENT, 'Laconica');
|
||||||
@ -1321,16 +1326,3 @@ function common_compatible_license($from, $to)
|
|||||||
// XXX: better compatibility check needed here!
|
// XXX: better compatibility check needed here!
|
||||||
return ($from == $to);
|
return ($from == $to);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* returns a quoted table name, if required according to config
|
|
||||||
*/
|
|
||||||
function common_database_tablename($tablename)
|
|
||||||
{
|
|
||||||
|
|
||||||
if(common_config('db','quote_identifiers')) {
|
|
||||||
$tablename = '"'. $tablename .'"';
|
|
||||||
}
|
|
||||||
//table prefixes could be added here later
|
|
||||||
return $tablename;
|
|
||||||
}
|
|
@ -152,11 +152,6 @@ class XMPPDaemon extends Daemon
|
|||||||
$body = preg_replace('/d[\ ]*('. $to .')[\ ]*/', '', $pl['body']);
|
$body = preg_replace('/d[\ ]*('. $to .')[\ ]*/', '', $pl['body']);
|
||||||
$this->add_direct($user, $body, $to, $from);
|
$this->add_direct($user, $body, $to, $from);
|
||||||
} else {
|
} else {
|
||||||
$len = mb_strlen($pl['body']);
|
|
||||||
if($len > 140) {
|
|
||||||
$this->from_site($from, 'Message too long - maximum is 140 characters, you sent ' . $len);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$this->add_notice($user, $pl);
|
$this->add_notice($user, $pl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,15 +250,13 @@ class XMPPDaemon extends Daemon
|
|||||||
function add_notice(&$user, &$pl)
|
function add_notice(&$user, &$pl)
|
||||||
{
|
{
|
||||||
$body = trim($pl['body']);
|
$body = trim($pl['body']);
|
||||||
$content_shortened = common_shorten_link($body);
|
$content_shortened = common_shorten_links($body);
|
||||||
if (mb_strlen($content_shortened) > 140) {
|
if (mb_strlen($content_shortened) > 140) {
|
||||||
$content = trim(mb_substr($body, 0, 140));
|
$from = jabber_normalize_jid($pl['from']);
|
||||||
$content_shortened = common_shorten_link($content);
|
$this->from_site($from, "Message too long - maximum is 140 characters, you sent ".mb_strlen($content_shortened));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else {
|
$notice = Notice::saveNew($user->id, $content_shortened, 'xmpp');
|
||||||
$content = $body;
|
|
||||||
}
|
|
||||||
$notice = Notice::saveNew($user->id, $content, 'xmpp');
|
|
||||||
if (is_string($notice)) {
|
if (is_string($notice)) {
|
||||||
$this->log(LOG_ERR, $notice);
|
$this->log(LOG_ERR, $notice);
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user