Overview

Packages

  • Horde
  • None

Classes

  • Horde_Ajax_Application
  • Horde_Api
  • Horde_Block_Account
  • Horde_Block_Account_Base
  • Horde_Block_Account_Finger
  • Horde_Block_Account_Ldap
  • Horde_Block_Account_Localhost
  • Horde_Block_Cloud
  • Horde_Block_FbStream
  • Horde_Block_Feed
  • Horde_Block_Fortune
  • Horde_Block_Google
  • Horde_Block_Iframe
  • Horde_Block_Metar
  • Horde_Block_Moon
  • Horde_Block_Sunrise
  • Horde_Block_Time
  • Horde_Block_TwitterTimeline
  • Horde_Block_Vatid
  • Horde_Block_Weather
  • Horde_LoginTasks_SystemTask_GarbageCollection
  • Horde_LoginTasks_SystemTask_Upgrade
  • Horde_LoginTasks_Task_AdminCheck
  • Horde_LoginTasks_Task_LastLogin
  • Horde_LoginTasks_Task_TosAgreement
  • Horde_Prefs_Ui
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Block for displaying the current user's Facebook stream, with the ability to
  4:  * filter it using the same Facebook filters available on facebook.com.  Also
  5:  * provides ability to update the current user's status.
  6:  *
  7:  * Copyright 2009-2012 Horde LLC (http://www.horde.org/)
  8:  *
  9:  * @author  Michael J. Rubinsky <mrubinsk@horde.org>
 10:  * @package Horde
 11:  */
 12: class Horde_Block_FbStream extends Horde_Core_Block
 13: {
 14:     /**
 15:      * @var Horde_Service_Facebook
 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:      * The content to go in this block.
 85:      *
 86:      * @return string   The content.
 87:      */
 88:     protected function _content()
 89:     {
 90:         $instance = hash('md5', mt_rand());
 91:         $endpoint = Horde::url('services/facebook/', true);
 92:         $html = '';
 93: 
 94:         /* Init facebook driver, exit early if no prefs exist */
 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:         /* Add the client javascript / initialize it */
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:         /* Build the UI */
123:         $html .= '<div style="padding: 8px 8px 0 8px">';
124: 
125:         /* Build the Notification Section */
126:         if (!empty($this->_params['notifications'])) {
127:             $html .= '<div class="fbinfobox" id="' . $instance . '_fbnotifications"></div>';
128:         }
129: 
130:         /* User's current status and input box to change it. */
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>'; // Close the fbgreybox node that wraps the status
166: 
167: 
168:        // Build the stream feed.
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>'; // fbbody end
173: 
174:         return $html;
175:     }
176: 
177: }
178: 
API documentation generated by ApiGen