Ansel_Ajax_Application_Handler::uploadNotification PHP Method

uploadNotification() public method

public uploadNotification ( )
    public function uploadNotification()
    {
        global $conf, $injector, $prefs, $registry;
        $gallery = $injector->getInstance('Ansel_Storage')->getGallery($this->vars->g);
        switch ($this->vars->s) {
            case 'twitter':
                $url = Ansel::getUrlFor('view', array('view' => 'Gallery', 'gallery' => $gallery->id), true);
                if (!empty($conf['urlshortener'])) {
                    try {
                        $url = $injector->getInstance('Horde_Service_UrlShortener')->shorten($url->setRaw(true));
                    } catch (Horde_Service_UrlShortener_Exception $e) {
                        Horde::log($e, 'ERR');
                        header('HTTP/1.1 500');
                    }
                }
                $text = sprintf(_("New images uploaded to %s. %s"), $gallery->get('name'), $url);
                $token = unserialize($prefs->getValue('twitter'));
                if (empty($token['key']) && empty($token['secret'])) {
                    $pref_link = $registry->getServiceLink('prefs', 'horde')->add('group', 'twitter')->link();
                    throw new Ansel_Exception(sprintf(_("You have not properly connected your Twitter account with Horde. You should check your Twitter settings in your %s."), $pref_link . _("preferences") . '</a>'));
                }
                $twitter = $injector->getInstance('Horde_Service_Twitter');
                $auth_token = new Horde_Oauth_Token($token['key'], $token['secret']);
                $twitter->auth->setToken($auth_token);
                try {
                    return $twitter->statuses->update($text);
                } catch (Horde_Service_Twitter_Exception $e) {
                    Horde::log($e, 'ERR');
                    header('HTTP/1.1 500');
                }
        }
    }