1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
<?php
/**
* Block for displaying the current user's Facebook stream, with the ability to
* filter it using the same Facebook filters available on facebook.com. Also
* provides ability to update the current user's status.
*
* Copyright 2009-2016 Horde LLC (http://www.horde.org/)
*
* @author Michael J. Rubinsky <mrubinsk@horde.org>
* @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() . '</a>';
}
/**
* 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") . '</a>'
);
}
// Add the client javascript / initialize it
$page_output->addThemeStylesheet('facebook.css');
$page_output->addScriptFile('facebookclient.js');
$script = <<<EOT
var Horde = window.Horde || {};
Horde['{$instance}_facebook'] = new Horde_Facebook({
spinner: '{$instance}_loading',
endpoint: '{$endpoint}',
content: '{$instance}_fbcontent',
status: '{$instance}_currentStatus',
getmore: '{$instance}_getmore',
'input': '{$instance}_newStatus',
'button': '{$instance}_button',
instance: '{$instance}',
'filter': '{$this->_params['filter']}',
'count': '{$this->_params['count']}'
});
EOT;
$page_output->addInlineScript($script);
// Start building the block UI.
$html .= '<div style="padding: 8px 8px 0 8px">';
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") . '</a>');
return $html;
}
$html .= '</div>'; // Close the node that wraps the status
// Build the stream feed.
$html .= '<br /><div id="' . $instance . '_fbcontent" style="height:' . (empty($this->_params['height']) ? 300 : $this->_params['height']) . 'px;overflow-y:auto;overflow-x:hidden;"></div><br />';
$html .= '<div class="hordeSmGetmore"><input type="button" id="' . $instance . '_getmore" class="horde-default" value="' . _("Get More") . '"></div>';
$html .= '</div>';
return $html;
}
}
|