1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11: class Ansel_Ajax_Imple_UploadNotification extends Horde_Core_Ajax_Imple
12: {
13: public function attach()
14: {
15:
16: }
17:
18: public function getUrl()
19: {
20: return $this->_getUrl('UploadNotification', 'ansel');
21: }
22:
23: public function handle($args, $post)
24: {
25: $gallery = $GLOBALS['injector']
26: ->getInstance('Ansel_Storage')
27: ->getGallery($post['g']);
28:
29: switch ($post['s']) {
30: case 'twitter':
31: $url = Ansel::getUrlFor(
32: 'view',
33: array('view' => 'Gallery', 'gallery' => $gallery->id),
34: true);
35: if (!empty($GLOBALS['conf']['urlshortener'])) {
36: try {
37: $url = $GLOBALS['injector']
38: ->getInstance('Horde_Service_UrlShortener')
39: ->shorten($url->setRaw(true));
40: } catch (Horde_Service_UrlShortener_Exception $e) {
41: Horde::logMessage($e, 'ERR');
42: header('HTTP/1.1 500');
43: }
44: }
45: $text = sprintf(_("New images uploaded to %s. %s"), $gallery->get('name'), $url);
46: $twitter = $this->_getTwitterObject();
47:
48: try {
49: return $twitter->statuses->update($text);
50: } catch (Horde_Service_Twitter_Exception $e) {
51: Horde::logMessage($e, 'ERR');
52: header('HTTP/1.1 500');
53: }
54: }
55: }
56:
57: protected function ()
58: {
59: $token = unserialize($GLOBALS['prefs']->getValue('twitter'));
60: if (empty($token['key']) && empty($token['secret'])) {
61: $pref_link = Horde::getServiceLink('prefs', 'horde')->add('group', 'twitter')->link();
62: throw new Horde_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>'));
63: }
64:
65: $twitter = $GLOBALS['injector']->getInstance('Horde_Service_Twitter');
66: $auth_token = new Horde_Oauth_Token($token['key'], $token['secret']);
67: $twitter->auth->setToken($auth_token);
68:
69: return $twitter;
70: }
71:
72: }
73: