* @package Horde */ class Horde_Block_FbStream extends Horde_Core_Block { /** * @var Horde_Service_Facebook */ protected $_facebook; /** * Cache the uid/sid * * @var string */ protected $_fbp = array(); /** */ public function __construct($app, $params = array()) { try { $this->_facebook = $GLOBALS['injector'] ->getInstance('Horde_Service_Facebook'); } catch (Horde_Exception $e) { $this->enabled = false; return; } parent::__construct($app, $params); $this->_name = _("My Facebook Stream"); $this->_fbp = unserialize($GLOBALS['prefs']->getValue('facebook')); } /** */ protected function _params() { $filters = array(); if (!empty($this->_fbp['sid'])) { try { $stream_filters = $this->_facebook->streams->getFilters($this->_fbp['uid']); foreach ($stream_filters as $filter) { $filters[$filter['filter_key']] = $filter['name']; } } catch (Horde_Service_Facebook_Exception $e) { } } return array( 'filter' => array( 'type' => 'enum', 'name' => _("Filter"), 'default' => 'nf', 'values' => $filters ), 'count' => array( 'type' => 'int', 'name' => _("Maximum number of entries to display"), 'default' => '20' ), 'height' => array( 'name' => _("Height of stream content (width automatically adjusts to block)"), 'type' => 'int', 'default' => 250 ), ); } /** */ protected function _title() { return Horde::externalUrl('http://facebook.com', true) . $this->getName() . ''; } /** * The content to go in this block. * * @return string The content. */ protected function _content() { global $page_output; $instance = hash('md5', mt_rand()); $endpoint = Horde::url('services/facebook/', true); $html = ''; // Init facebook driver, exit early if no prefs exist $facebook = $this->_facebook; if (!($facebook->auth->getSessionKey())) { return sprintf( _("You are not connected to your Facebook account. You should check your Facebook settings in your %s."), $GLOBALS['registry']->getServiceLink('prefs', 'horde')->add('group', 'facebook')->link() . _("preferences") . '' ); } // Add the client javascript / initialize it $page_output->addThemeStylesheet('facebook.css'); $page_output->addScriptFile('facebookclient.js'); $script = <<_params['filter']}', 'count': '{$this->_params['count']}' }); EOT; $page_output->addInlineScript($script); // Start building the block UI. $html .= '
'; try { $html .= Horde_Themes_Image::tag( 'loading.gif', array( 'attr' => array( 'id' => $instance. '_loading', 'style' => 'display:none;' ) ) ); } catch (Horde_Service_Facebook_Exception $e) { $prefs = $GLOBALS['registry']->getServiceLink('prefs'); $html .= sprintf(_("There was an error making the request: %s"), $e->getMessage()); $html .= sprintf(_("You can also check your Facebook settings in your %s."), $prefs->add('group', 'facebook')->link() . _("preferences") . ''); return $html; } $html .= '
'; // Close the node that wraps the status // Build the stream feed. $html .= '

'; $html .= '
'; $html .= ''; return $html; } }