summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
Diffstat (limited to 'classes')
-rw-r--r--classes/File_redirection.php9
-rw-r--r--classes/Message.php9
-rw-r--r--classes/Notice.php14
-rw-r--r--classes/User.php19
4 files changed, 41 insertions, 10 deletions
diff --git a/classes/File_redirection.php b/classes/File_redirection.php
index 4ee43026b..53c15bf8b 100644
--- a/classes/File_redirection.php
+++ b/classes/File_redirection.php
@@ -187,13 +187,14 @@ class File_redirection extends Memcached_DataObject
* 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) {
+ function makeShort($long_url, $user=null) {
$canon = File_redirection::_canonUrl($long_url);
- $short_url = File_redirection::_userMakeShort($canon);
+ $short_url = File_redirection::_userMakeShort($canon, $user);
// Did we get one? Is it shorter?
if (!empty($short_url) && mb_strlen($short_url) < mb_strlen($long_url)) {
@@ -203,8 +204,8 @@ class File_redirection extends Memcached_DataObject
}
}
- function _userMakeShort($long_url) {
- $short_url = common_shorten_url($long_url);
+ function _userMakeShort($long_url, User $user=null) {
+ $short_url = common_shorten_url($long_url, $user);
if (!empty($short_url) && $short_url != $long_url) {
$short_url = (string)$short_url;
// store it
diff --git a/classes/Message.php b/classes/Message.php
index 353dc01f9..c4508187b 100644
--- a/classes/Message.php
+++ b/classes/Message.php
@@ -45,11 +45,18 @@ class Message extends Memcached_DataObject
throw new ClientException(_('You are banned from sending direct messages.'));
}
+ $user = User::staticGet('id', $sender->id);
+
$msg = new Message();
$msg->from_profile = $from;
$msg->to_profile = $to;
- $msg->content = common_shorten_links($content);
+ if ($user) {
+ // Use the sender's URL shortening options.
+ $msg->content = $user->shortenLinks($content);
+ } else {
+ $msg->content = common_shorten_links($content);
+ }
$msg->rendered = common_render_text($content);
$msg->created = common_sql_now();
$msg->source = $source;
diff --git a/classes/Notice.php b/classes/Notice.php
index dd9438f16..4169f1a1c 100644
--- a/classes/Notice.php
+++ b/classes/Notice.php
@@ -256,9 +256,14 @@ class Notice extends Memcached_DataObject
$is_local = Notice::LOCAL_PUBLIC;
}
- $profile = Profile::staticGet($profile_id);
-
- $final = common_shorten_links($content);
+ $profile = Profile::staticGet('id', $profile_id);
+ $user = User::staticGet('id', $profile_id);
+ if ($user) {
+ // Use the local user's shortening preferences, if applicable.
+ $final = $user->shortenLinks($content);
+ } else {
+ $final = common_shorten_links($content);
+ }
if (Notice::contentTooLong($final)) {
// TRANS: Client exception thrown if a notice contains too many characters.
@@ -502,8 +507,7 @@ class Notice extends Memcached_DataObject
/**
* @private callback
*/
- function saveUrl($data) {
- list($url, $notice_id) = $data;
+ function saveUrl($url, $notice_id) {
File::processNew($url, $notice_id);
}
diff --git a/classes/User.php b/classes/User.php
index 92180a9fb..041c64c38 100644
--- a/classes/User.php
+++ b/classes/User.php
@@ -927,4 +927,23 @@ class User extends Memcached_DataObject
throw new ServerException(_('Single-user mode code called when not enabled.'));
}
}
+
+ /**
+ * Find and shorten links in the given text using this user's URL shortening
+ * settings.
+ *
+ * By default, links will be left untouched if the text is shorter than the
+ * configured maximum notice length. Pass true for the $always parameter
+ * to force all links to be shortened regardless.
+ *
+ * Side effects: may save file and file_redirection records for referenced URLs.
+ *
+ * @param string $text
+ * @param boolean $always
+ * @return string
+ */
+ public function shortenLinks($text, $always=false)
+ {
+ return common_shorten_links($text, $always, $this);
+ }
}