Overview

Packages

  • Jonah
  • None

Classes

  • Jonah
  • Jonah_Api
  • Jonah_Block_Latest
  • Jonah_Driver
  • Jonah_Driver_Sql
  • Jonah_Exception
  • Jonah_Factory_Driver
  • Jonah_Form_Feed
  • Jonah_Form_Story
  • Jonah_Test
  • Jonah_View_ChannelDelete
  • Jonah_View_ChannelEdit
  • Jonah_View_ChannelList
  • Jonah_View_StoryDelete
  • Jonah_View_StoryEdit
  • Jonah_View_StoryList
  • Jonah_View_StoryPdf
  • Jonah_View_StoryView
  • Jonah_View_TagSearchList
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Jonah Base Class.
  4:  *
  5:  * Copyright 2002-2012 Horde LLC (http://www.horde.org/)
  6:  *
  7:  * See the enclosed file LICENSE for license information (BSD). If you did not
  8:  * did not receive this file, see http://cvs.horde.org/co.php/jonah/LICENSE.
  9:  *
 10:  * @author  Chuck Hagenbuch <chuck@horde.org>
 11:  * @author  Eric Rechlin <eric@hpcalc.org>
 12:  *
 13:  * @package Jonah
 14:  */
 15: class Jonah
 16: {
 17:     /**
 18:      * Internal Jonah channel.
 19:      */
 20:     const INTERNAL_CHANNEL = 0;
 21: 
 22:     /**
 23:      * Composite channel.
 24:      */
 25:     const COMPOSITE_CHANNEL = 3;
 26: 
 27:     /**
 28:      */
 29:     const ORDER_PUBLISHED = 0;
 30:     const ORDER_READ = 1;
 31:     const ORDER_COMMENTS = 2;
 32: 
 33:     /**
 34:      * Obtain the list of stories from the passed in URI.
 35:      *
 36:      * @deprecated Will be removed when external channels are removed.
 37:      *
 38:      * @param string $url  The url to get the list of the channel's stories.
 39:      */
 40:     static public function readURL($url)
 41:     {
 42:         global $conf;
 43: 
 44:         $http = $GLOBALS['injector']
 45:           ->getInstance('Horde_Core_Factory_HttpClient')
 46:           ->create();
 47: 
 48:         try {
 49:             $response = $http->get($url);
 50:         } catch (Horde_Http_Exception $e) {
 51:             throw new Jonah_Exception(sprintf(_("Could not open %s: %s"), $url, $e->getMessage()));
 52:         }
 53:         if ($response->code <> '200') {
 54:             throw new Jonah_Exception(sprintf(_("Could not open %s: %s"), $url, $response->code));
 55:         }
 56:         $result = array('body' => $response->getBody());
 57:         $content_type = $response->getHeader('Content-Type');
 58:         if (preg_match('/.*;\s?charset="?([^"]*)/', $content_type, $match)) {
 59:             $result['charset'] = $match[1];
 60:         } elseif (preg_match('/<\?xml[^>]+encoding=["\']?([^"\'\s?]+)[^?].*?>/i', $result['body'], $match)) {
 61:             $result['charset'] = $match[1];
 62:         }
 63: 
 64:         return $result;
 65:     }
 66: 
 67:     /**
 68:      * @deprecated Remove when external channels moved to hippo.
 69:      */
 70:     static public function getChannelTypeLabel($type)
 71:     {
 72:         switch ($type) {
 73:         case Jonah::INTERNAL_CHANNEL:
 74:             return _("Local Feed");
 75:         }
 76:     }
 77: 
 78:     /**
 79:      *
 80:      *
 81:      * @param string $filter       The type of channel
 82:      * @param integer $permission  Horde_Perms:: constant
 83:      * @param mixed $in            ??
 84:      *
 85:      * @return mixed  An array of results or a single boolean?
 86:      */
 87:     static public function checkPermissions($filter, $permission = Horde_Perms::READ, $in = null)
 88:     {
 89:         if ($GLOBALS['registry']->isAdmin(array('permission' => 'jonah:admin', 'permlevel' =>  $permission))) {
 90:             if (empty($in)) {
 91:                 // Calls with no $in parameter are checking whether this user
 92:                 // has permission.  Since this user is an admin, they always
 93:                 // have permission.  If the $in parameter is an empty array,
 94:                 // the method is expected to return an array too.
 95:                 return is_array($in) ? array() : true;
 96:             } else {
 97:                 return $in;
 98:             }
 99:         }
100: 
101:         $perms = $GLOBALS['injector']->getInstance('Horde_Perms');
102: 
103:         $out = array();
104: 
105:         switch ($filter) {
106:         case 'internal_channels':
107:             if (empty($in) || !$perms->exists('jonah:news:' . $filter . ':' . $in)) {
108:                 return $perms->hasPermission('jonah:news:' . $filter, $GLOBALS['registry']->getAuth(), $permission);
109:             } elseif (!is_array($in)) {
110:                 return $perms->hasPermission('jonah:news:' . $filter . ':' . $in, $GLOBALS['registry']->getAuth(), $permission);
111:             } else {
112:                 foreach ($in as $key => $val) {
113:                     if ($perms->hasPermission('jonah:news:' . $filter . ':' . $val, $GLOBALS['registry']->getAuth(), $permission)) {
114:                         $out[$key] = $val;
115:                     }
116:                 }
117:             }
118:             break;
119: 
120:         case 'channels':
121:             foreach ($in as $key => $val) {
122:                 $perm_name = Jonah::typeToPermName($val['channel_type']);
123:                 if ($perms->hasPermission('jonah:news:' . $perm_name,  $GLOBALS['registry']->getAuth(), $permission) ||
124:                     $perms->hasPermission('jonah:news:' . $perm_name . ':' . $val['channel_id'], $GLOBALS['registry']->getAuth(), $permission)) {
125:                     $out[$key] = $in[$key];
126:                 }
127:             }
128:             break;
129: 
130:         default:
131:             return $perms->hasPermission($filter, $GLOBALS['registry']->getAuth(), Horde_Perms::EDIT);
132:         }
133: 
134:         return $out;
135:     }
136: 
137:     /**
138:      * @deprecated Remove when external channels removed.
139:      *
140:      * @param string $type  The Jonah::* constant for the channel type.
141:      *
142:      * @return string  The string representation of the channel type.
143:      */
144:     static public function typeToPermName($type)
145:     {
146:         if ($type == Jonah::INTERNAL_CHANNEL) {
147:             return 'internal_channels';
148:         }
149:     }
150: 
151:     /**
152:      * Returns an array of configured body types from Jonah's $conf array.
153:      *
154:      * @return array  An array of body types.
155:      */
156:     static public function getBodyTypes()
157:     {
158:         static $types = array();
159:         if (!empty($types)) {
160:             return $types;
161:         }
162: 
163:         if (in_array('richtext', $GLOBALS['conf']['news']['story_types'])) {
164:             $types['richtext'] = _("Rich Text");
165:         }
166: 
167:         /* Other than checking if text is enabled, it is inserted by default if
168:          * no other body type has been enabled in the config. */
169:         if (in_array('text', $GLOBALS['conf']['news']['story_types']) ||
170:             empty($types)) {
171:             $types['text'] = _("Text");
172:         }
173: 
174:         return $types;
175:     }
176: 
177:     /**
178:      * Tries to figure out a default body type. Used when none has been
179:      * specified and a types is needed to fall back on to.
180:      *
181:      * @return string  A default type.
182:      */
183:     static public function getDefaultBodyType()
184:     {
185:         $types = Jonah::getBodyTypes();
186:         if (isset($types['text'])) {
187:             return 'text';
188:         } elseif (isset($types['richtext'])) {
189:             return 'richtext';
190:         }
191:         /* The two most common body types have not been found, so just return
192:          * the first one that is in the array. */
193:         return array_shift(array_keys($types));
194:     }
195: 
196:     /**
197:      * Returns the available channel types based on what was set in the
198:      * configuration.
199:      *
200:      * @return array  The available news channel types.
201:      */
202:     static public function getAvailableTypes()
203:     {
204:         $types = array();
205: 
206:         if (empty($GLOBALS['conf']['news']['enable'])) {
207:             return $types;
208:         }
209:         if (in_array('internal', $GLOBALS['conf']['news']['enable'])) {
210:             $types[Jonah::INTERNAL_CHANNEL] = _("Local Feed");
211:         }
212:         if (in_array('composite', $GLOBALS['conf']['news']['enable'])) {
213:             $types[Jonah::COMPOSITE_CHANNEL] = _("Composite Feed");
214:         }
215: 
216:         return $types;
217:     }
218: 
219: }
API documentation generated by ApiGen