function onEndShowScripts($action) { if (common_logged_in()) { $user = common_current_user(); $action->inlineScript('var maxNoticeLength = ' . User_urlshortener_prefs::maxNoticeLength($user)); $action->inlineScript('var maxUrlLength = ' . User_urlshortener_prefs::maxUrlLength($user)); $action->script($this->path('shorten.js')); } }
/** * Find and shorten links in a given chunk of text if it's longer than the * configured notice content limit (or unconditionally). * * Side effects: may save file and file_redirection records for referenced URLs. * * Pass the $user option or call $user->shortenLinks($text) to ensure the proper * user's options are used; otherwise the current web session user's setitngs * will be used or ur1.ca if there is no active web login. * * @param string $text * @param boolean $always (optional) * @param User $user (optional) * * @return string */ function common_shorten_links($text, $always = false, User $user = null) { $user = common_current_user(); $maxLength = User_urlshortener_prefs::maxNoticeLength($user); if ($always || mb_strlen($text) > $maxLength) { return common_replace_urls_callback($text, array('File_redirection', 'forceShort'), $user); } else { return common_replace_urls_callback($text, array('File_redirection', 'makeShort'), $user); } }
/** * Content area of the page * * Shows a form for uploading an avatar. * * @return void */ function showContent() { $user = common_current_user(); $this->elementStart('form', array('method' => 'post', 'id' => 'form_settings_other', 'class' => 'form_settings', 'action' => common_local_url('urlsettings'))); $this->elementStart('fieldset'); $this->hidden('token', common_session_token()); $this->elementStart('ul', 'form_data'); $shorteners = array(); Event::handle('GetUrlShorteners', array(&$shorteners)); $services = array(); foreach ($shorteners as $name => $value) { $services[$name] = $name; if ($value['freeService']) { // TRANS: Used as a suffix for free URL shorteners in a dropdown list in the tab "Other" of a // TRANS: user's profile settings. This message has one space at the beginning. Use your // TRANS: language's word separator here if it has one (most likely a single space). $services[$name] .= _(' (free service)'); } } // Include default values // TRANS: Default value for URL shortening settings. $services['none'] = _('[none]'); // TRANS: Default value for URL shortening settings. $services['internal'] = _('[internal]'); if ($services) { asort($services); $this->elementStart('li'); // TRANS: Label for dropdown with URL shortener services. $this->dropdown('urlshorteningservice', _('Shorten URLs with'), $services, _('Automatic shortening service to use.'), false, $user->urlshorteningservice); $this->elementEnd('li'); } $this->elementStart('li'); $this->input('maxurllength', _('URL longer than'), !is_null($this->arg('maxurllength')) ? $this->arg('maxurllength') : User_urlshortener_prefs::maxUrlLength($user), _('URLs longer than this will be shortened, -1 means never shorten because a URL is long.')); $this->elementEnd('li'); $this->elementStart('li'); $this->input('maxnoticelength', _('Text longer than'), !is_null($this->arg('maxnoticelength')) ? $this->arg('maxnoticelength') : User_urlshortener_prefs::maxNoticeLength($user), _('URLs in notices longer than this will always be shortened, -1 means only shorten if the full post exceeds maximum length.')); $this->elementEnd('li'); $this->elementEnd('ul'); // TRANS: Button text for saving "Other settings" in profile. $this->submit('save', _m('BUTTON', 'Save')); $this->elementEnd('fieldset'); $this->elementEnd('form'); }