X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=classes%2FFile_redirection.php;h=74e89db5f27f712be050d12607fe95609b0aabb0;hb=8b32ac85d8cbfe1be03836af461d80fddd54fc6c;hp=4ee43026b72cc44dc6efd6d8a02d18a3a30d778c;hpb=834acaaa794254dfb9dc7e57dab498001d975d11;p=quix0rs-gnu-social.git diff --git a/classes/File_redirection.php b/classes/File_redirection.php index 4ee43026b7..74e89db5f2 100644 --- a/classes/File_redirection.php +++ b/classes/File_redirection.php @@ -23,8 +23,6 @@ require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; require_once INSTALLDIR.'/classes/File.php'; require_once INSTALLDIR.'/classes/File_oembed.php'; -define('USER_AGENT', 'StatusNet user agent / file probe'); - /** * Table Definition for file_redirection */ @@ -176,6 +174,35 @@ class File_redirection extends Memcached_DataObject } } + /** + * Shorten a URL with the current user's configured shortening + * options, if applicable. + * + * If it cannot be shortened or the "short" URL is longer than the + * original, the original is returned. + * + * If the referenced item has not been seen before, embedding data + * may be saved. + * + * @param string $long_url + * @param User $user whose shortening options to use; defaults to the current web session user + * @return string + */ + function makeShort($long_url, $user=null) + { + $canon = File_redirection::_canonUrl($long_url); + + $short_url = File_redirection::_userMakeShort($canon, $user); + + // Did we get one? Is it shorter? + + if (!empty($short_url)) { + return $short_url; + } else { + return $long_url; + } + } + /** * Shorten a URL with the current user's configured shortening * options, if applicable. @@ -189,22 +216,23 @@ class File_redirection extends Memcached_DataObject * @param string $long_url * @return string */ - function makeShort($long_url) { + function forceShort($long_url, $user) + { $canon = File_redirection::_canonUrl($long_url); - $short_url = File_redirection::_userMakeShort($canon); + $short_url = File_redirection::_userMakeShort($canon, $user, true); // Did we get one? Is it shorter? - if (!empty($short_url) && mb_strlen($short_url) < mb_strlen($long_url)) { + if (!empty($short_url)) { return $short_url; } else { return $long_url; } } - function _userMakeShort($long_url) { - $short_url = common_shorten_url($long_url); + function _userMakeShort($long_url, User $user=null, $force = false) { + $short_url = common_shorten_url($long_url, $user, $force); if (!empty($short_url) && $short_url != $long_url) { $short_url = (string)$short_url; // store it