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:  * @package Horde
  4:  */
  5: class Horde_Block_Feed extends Horde_Core_Block
  6: {
  7:     /**
  8:      */
  9:     private $_feed = null;
 10: 
 11:     /**
 12:      */
 13:     public function __construct($app, $params = array())
 14:     {
 15:         parent::__construct($app, $params);
 16: 
 17:         $this->enabled = class_exists('Horde_Feed');
 18:         $this->_name = _("Syndicated Feed");
 19:     }
 20: 
 21:     /**
 22:      */
 23:     protected function _params()
 24:     {
 25:         return array(
 26:             'uri' => array(
 27:                 'type' => 'text',
 28:                 'name' => _("Feed Address")
 29:             ),
 30:             'limit' => array(
 31:                 'name' => _("Number of articles to display"),
 32:                 'type' => 'int',
 33:                 'default' => 10
 34:             ),
 35:             'interval' => array(
 36:                 'name' => _("How many seconds before we check for new articles?"),
 37:                 'type' => 'int',
 38:                 'default' => 86400
 39:             ),
 40:             'details' => array(
 41:                 'name' => _("Show extra detail?"),
 42:                 'type' => 'boolean',
 43:                 'default' => 20
 44:             )
 45:         );
 46:     }
 47: 
 48:     /**
 49:      */
 50:     protected function _title()
 51:     {
 52:         $this->_read();
 53: 
 54:         return ($this->_feed instanceof Horde_Feed_Base)
 55:             ? $this->_feed->title()
 56:             : _("Feed");
 57:     }
 58: 
 59:     /**
 60:      */
 61:     protected function _content()
 62:     {
 63:         $this->_read();
 64: 
 65:         if ($this->_feed instanceof Horde_Feed_Base) {
 66:             $html = '';
 67:             $count = 0;
 68:             foreach ($this->_feed as $entry) {
 69:                 if (++$count > $this->_params['limit']) {
 70:                     break;
 71:                 }
 72:                 $html .= '<a href="' . $entry->link. '"';
 73:                 if (empty($this->_params['details'])) {
 74:                     $html .= ' title="' . htmlspecialchars(strip_tags($entry->description())) . '"';
 75:                 }
 76:                 $html .= '>' . htmlspecialchars($entry->title) . '</a>';
 77:                 if (!empty($this->_params['details'])) {
 78:                     $html .= '<br />' .  htmlspecialchars(strip_tags($entry->description())). "<br />\n";
 79:                 }
 80:                 $html .= '<br />';
 81:             }
 82:             return $html;
 83:         }
 84: 
 85:         return is_string($this->_feed)
 86:             ? $this->_feed
 87:             : '';
 88:     }
 89: 
 90:     /**
 91:      */
 92:     private function _read()
 93:     {
 94:         if (empty($this->_params['uri'])) {
 95:             return;
 96:         }
 97: 
 98:         $key = md5($this->_params['uri']);
 99:         $cache = $GLOBALS['injector']->getInstance('Horde_Cache');
100:         $feed = $cache->get($key, $this->_params['interval']);
101:         if (!empty($feed)) {
102:             $this->_feed = unserialize($feed);
103:         }
104: 
105:         try {
106:             $client = $GLOBALS['injector']
107:               ->getInstance('Horde_Core_Factory_HttpClient')
108:               ->create();
109:             $feed = Horde_Feed::readUri($this->_params['uri'], $client);
110:             $cache->set($key, serialize($feed));
111:             $this->_feed = $feed;
112:         } catch (Exception $e) {
113:             $this->_feed = $e->getMessage();
114:         }
115:     }
116: 
117: }
118: 
API documentation generated by ApiGen