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'));
     }
 }
Example #2
0
/**
 * Shorten a URL with the current user's configured shortening service,
 * or ur1.ca if configured, or not at all if no shortening is set up.
 *
 * @param string  $long_url original URL
 * @param User $user to specify a particular user's options
 * @param boolean $force    Force shortening (used when notice is too long)
 * @return string may return the original URL if shortening failed
 *
 * @fixme provide a way to specify a particular shortener
 */
function common_shorten_url($long_url, User $user = null, $force = false)
{
    $long_url = trim($long_url);
    $user = common_current_user();
    $maxUrlLength = User_urlshortener_prefs::maxUrlLength($user);
    // $force forces shortening even if it's not strictly needed
    // I doubt URL shortening is ever 'strictly' needed. - ESP
    if (mb_strlen($long_url) < $maxUrlLength && !$force) {
        return $long_url;
    }
    $shortenerName = User_urlshortener_prefs::urlShorteningService($user);
    if (Event::handle('StartShortenUrl', array($long_url, $shortenerName, &$shortenedUrl))) {
        if ($shortenerName == 'internal') {
            $f = File::processNew($long_url);
            if (empty($f)) {
                return $long_url;
            } else {
                $shortenedUrl = common_local_url('redirecturl', array('id' => $f->id));
                return $shortenedUrl;
            }
        } else {
            return $long_url;
        }
    } else {
        //URL was shortened, so return the result
        return trim($shortenedUrl);
    }
}
Example #3
0
 /**
  * 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');
 }