1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
12: class Horde_Block_FbStream extends Horde_Core_Block
13: {
14: 15: 16:
17: private $_facebook;
18:
19: 20:
21: public function __construct($app, $params = array())
22: {
23: try {
24: $this->_facebook = $GLOBALS['injector']->getInstance('Horde_Service_Facebook');
25: } catch (Horde_Exception $e) {
26: $this->enabled = false;
27: return;
28: }
29: parent::__construct($app, $params);
30: $this->_name = _("My Facebook Stream");
31: }
32:
33: 34:
35: protected function _params()
36: {
37: $fbp = unserialize($GLOBALS['prefs']->getValue('facebook'));
38: $filters = array();
39: if (!empty($fbp['sid'])) {
40: $fql = 'SELECT filter_key, name FROM stream_filter WHERE uid="'
41: . $fbp['uid'] . '"';
42: try {
43: $stream_filters = $this->_facebook->fql->run($fql);
44: foreach ($stream_filters as $filter) {
45: $filters[$filter['filter_key']] = $filter['name'];
46: }
47: } catch (Horde_Service_Facebook_Exception $e) {
48: }
49: }
50:
51: return array(
52: 'filter' => array(
53: 'type' => 'enum',
54: 'name' => _("Filter"),
55: 'default' => 'nf',
56: 'values' => $filters
57: ),
58: 'count' => array(
59: 'type' => 'int',
60: 'name' => _("Maximum number of entries to display"),
61: 'default' => '20'
62: ),
63: 'notifications' => array(
64: 'type' => 'boolean',
65: 'name' => _("Show notifications"),
66: 'default' => true
67: ),
68: 'height' => array(
69: 'name' => _("Height of stream content (width automatically adjusts to block)"),
70: 'type' => 'int',
71: 'default' => 250
72: ),
73: );
74: }
75:
76: 77:
78: protected function _title()
79: {
80: return Horde::externalUrl('http://facebook.com', true) . $this->getName() . '</a>';
81: }
82:
83: 84: 85: 86: 87:
88: protected function _content()
89: {
90: $instance = hash('md5', mt_rand());
91: $endpoint = Horde::url('services/facebook/', true);
92: $html = '';
93:
94:
95: $facebook = $this->_facebook;
96: if (!($facebook->auth->getSessionKey())) {
97: return sprintf(_("You have not properly connected your Facebook account with Horde. You should check your Facebook settings in your %s."), Horde::getServiceLink('prefs', 'horde')->add('group', 'facebook')->link() . _("preferences") . '</a>');
98: }
99: $fbp = unserialize($GLOBALS['prefs']->getValue('facebook'));
100:
101:
102: $GLOBALS['injector']->getInstance('Horde_Themes_Css')->addThemeStylesheet('facebook.css');
103: Horde::addScriptFile('facebookclient.js');
104: $script = <<<EOT
105: var Horde = window.Horde || {};
106: Horde['{$instance}_facebook'] = new Horde_Facebook({
107: spinner: '{$instance}_loading',
108: endpoint: '{$endpoint}',
109: content: '{$instance}_fbcontent',
110: status: '{$instance}_currentStatus',
111: notifications: '{$instance}_fbnotifications',
112: getmore: '{$instance}_getmore',
113: 'input': '{$instance}_newStatus',
114: 'button': '{$instance}_button',
115: instance: '{$instance}',
116: 'filter': '{$this->_params['filter']}',
117: 'count': '{$this->_params['count']}'
118: });
119: EOT;
120: Horde::addInlineScript($script, 'dom');
121:
122:
123: $html .= '<div style="padding: 8px 8px 0 8px">';
124:
125:
126: if (!empty($this->_params['notifications'])) {
127: $html .= '<div class="fbinfobox" id="' . $instance . '_fbnotifications"></div>';
128: }
129:
130:
131: $fql = 'SELECT first_name, last_name, status, pic_square_with_logo from user where uid=' . $fbp['uid'] . ' LIMIT 1';
132: try {
133: $status = $facebook->fql->run($fql);
134: } catch (Horde_Service_Facebook_Exception $e) {
135: $html = sprintf(_("There was an error making the request: %s"), $e->getMessage());
136: $html .= sprintf(_("You can also check your Facebook settings in your %s."), Horde::getServiceLink('prefs', 'horde')->add('group', 'facebook')->link() . _("preferences") . '</a>');
137:
138: return $html;
139: }
140:
141: $status = array_pop($status);
142: if (empty($status['status']['message'])) {
143: $status['status']['message'] = _("What's on your mind?");
144: $class = 'fbemptystatus';
145: } else {
146: $class = '';
147: }
148: $html .= '<div class="fbgreybox fbboxfont">'
149: . '<img style="float:left;" src="' . $status['pic_square_with_logo'] . '" />'
150: . '<div id="' . $instance . '_currentStatus" class="' . $class . '" style="margin-left:55px;">'
151: . $status['status']['message']
152: . '</div>';
153:
154: try {
155: if ($facebook->users->hasAppPermission(Horde_Service_Facebook_Auth::EXTEND_PERMS_PUBLISHSTREAM)) {
156: $html .= '<input style="width:100%;margin-top:4px;margin-bottom:4px;" type="text" class="fbinput" id="' . $instance . '_newStatus" name="newStatus" />'
157: . '<div><a class="button" href="#" id="' . $instance . '_button">' . _("Update") . '</a></div>'
158: . Horde::img('loading.gif', '', array('id' => $instance. '_loading', 'style' => 'display:none;'));
159: }
160: } catch (Horde_Service_Facebook_Exception $e) {
161: $html .= sprintf(_("There was an error making the request: %s"), $e->getMessage());
162: $html .= sprintf(_("You can also check your Facebook settings in your %s."), Horde::link($endpoint) . _("preferences") . '</a>');
163: return $html;
164: }
165: $html .= '</div>';
166:
167:
168:
169: $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 />';
170: $html .= '<div class="hordeSmGetmore"><input type="button" id="' . $instance . '_getmore" class="button" value="' . _("Get More") . '"></div>';
171:
172: $html .= '</div>';
173:
174: return $html;
175: }
176:
177: }
178: