From: Duck (Jakob Munih) Date: Tue, 28 Apr 2009 17:52:17 +0000 (+0200) Subject: update FB code X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=b69f39fa876522642fe4b26efc9e856e7398bb14;p=horde.git update FB code --- diff --git a/folks/lib/Friends/facebook.php b/folks/lib/Friends/facebook.php index 85a834237..f004294d1 100644 --- a/folks/lib/Friends/facebook.php +++ b/folks/lib/Friends/facebook.php @@ -1,8 +1,6 @@ _loadFB) { + return $this->_fb); } - $context = array('http_client' => new Horde_Http_Client(), - 'http_request' => new Horde_Controller_Request_Http()); - $facebook = new Horde_Service_Facebook($conf['facebook']['key'], - $conf['facebook']['secret'], - $context); - - $session = unserialize($prefs->getValue('facebook')); - $facebook->auth->setUser($session['uid'], $session['sid'], 0); - - $fql = 'SELECT uid, name FROM user WHERE uid IN (' - . 'SELECT uid2 FROM friend WHERE uid1=' . $session['uid'] . ')'; - - $results = $facebook->fql->run($fql); - $friends = array(); - foreach ($results as $result) { - $friends[$result['uid']] = $result['uid']; + try { + $friends = $this->_fb->friends->get(null, $this->_uid); + } catch (Horde_Service_Facebook_Exception $e) { + return PEAR::raiseError($e->getMessage()); } return $friends; @@ -55,6 +46,50 @@ class Folks_Friends_facebook extends Folks_Friends { */ public function getGroups() { - return array('whitelist' => _("Friends")); + if (!$this->_loadFB) { + return $this->_fb); + } + + try { + $groups = $this->_fb->friends->getLists(); + } catch (Horde_Service_Facebook_Exception $e) { + return PEAR::raiseError($e->getMessage()); + } + + return $groups; + } + + + /** + * Load FB content + */ + private function _loadFB() + { + if ($this->_fb) { + return true; + } + + if (!$conf['facebook']['enabled']) { + $this->_fb = PEAR::raiseError(_("No Facebook integration exists.")); + return false; + } + + // Check FB user config + $fbp = unserialize($prefs->getValue('facebook')); + if (!$fbp || empty($fbp['uid'])) { + $this->_fb = PEAR::raiseError(_("User has no link.")); + return false; + } + + $context = array('http_client' => new Horde_Http_Client(), + 'http_request' => new Horde_Controller_Request_Http()); + + $this->_fb = new Horde_Service_Facebook($conf['facebook']['key'], + $conf['facebook']['secret'], + $context); + + $this->_fb->auth->setUser($fbp['uid'], $fbp['sid'], 0); + + return true; } } \ No newline at end of file diff --git a/folks/lib/Notification/facebook.php b/folks/lib/Notification/facebook.php index bdd669792..2a9a4bd55 100644 --- a/folks/lib/Notification/facebook.php +++ b/folks/lib/Notification/facebook.php @@ -72,7 +72,7 @@ class Folks_Notification_facebook extends Folks_Notification { } try { - $message = '' . $subject . ': ' . $body; + $message = $this->_formatBody($subject, $body); $result = $this->_fb->notifications->send(array($this->_fbp['uid']), $message, 'user_to_user'); } catch (Horde_Service_Facebook_Exception $e) { return PEAR::raiseError($e->getMessage(), $e->getCode()); @@ -104,7 +104,7 @@ class Folks_Notification_facebook extends Folks_Notification { } try { - $message = '' . $subject . ': ' . $body; + $message = $this->_formatBody($subject, $body); $result = $this->_fb->notifications->send($friends, $message, 'user_to_user'); } catch (Horde_Service_Facebook_Exception $e) { return PEAR::raiseError($e->getMessage(), $e->getCode()); @@ -146,4 +146,20 @@ class Folks_Notification_facebook extends Folks_Notification { return true; } + + /** + * Format notification content + * + * @param string $subject Subject of message + * @param string $body Body of message + * + * @return string Formatted message + */ + private function _formatBody($subject, $body) + { + require_once 'Horde/Text/Filter.php'; + + return '' . $subject . ': ' + . Text_Filter::filter($body, 'text2html', array('parselevel' => TEXT_HTML_MICRO_LINKURL)); + } }