forked from GNUsocial/gnu-social
common_shorten_links() can only access the web session's logged-in user, so never properly took user options into effect for posting via XMPP, API, mail, etc. Adds an optional $user parameter on common_shorten_links(), and a $user->shortenLinks() as a clearer interface for that. Tweaked some lower-level functions so $user gets passed down -- making the $notice_id param previously there for saving URLs at notice save time generalized a little. Note also ticket #2919: there's a lot of duplicate code calling the shortening, checking the length, and reporting near-identical error messages. These should be consolidated to aid in code and translation maintenance.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user