Overview

Packages

  • Horde
    • Icalendar
      • UnitTests
  • Ingo
    • UnitTests
  • None

Classes

  • Ingo_Application
  • Ingo_Block_Overview
  • Ingo_Script_Imap_Mock
  • Ingo_Test_Notification
  • ScriptTester
  • ScriptTester_all
  • ScriptTester_imap
  • ScriptTester_sieve
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Ingo application API.
  4:  *
  5:  * This file defines Horde's core API interface. Other core Horde libraries
  6:  * can interact with Ingo through this API.
  7:  *
  8:  * Copyright 2010-2012 Horde LLC (http://www.horde.org/)
  9:  *
 10:  * See the enclosed file LICENSE for license information (ASL).  If you
 11:  * did not receive this file, see http://www.horde.org/licenses/apache.
 12:  *
 13:  * @package Ingo
 14:  */
 15: 
 16: /* Determine the base directories. */
 17: if (!defined('INGO_BASE')) {
 18:     define('INGO_BASE', dirname(__FILE__) . '/..');
 19: }
 20: 
 21: if (!defined('HORDE_BASE')) {
 22:     /* If Horde does not live directly under the app directory, the HORDE_BASE
 23:      * constant should be defined in config/horde.local.php. */
 24:     if (file_exists(INGO_BASE . '/config/horde.local.php')) {
 25:         include INGO_BASE . '/config/horde.local.php';
 26:     } else {
 27:         define('HORDE_BASE', INGO_BASE . '/..');
 28:     }
 29: }
 30: 
 31: /* Load the Horde Framework core (needed to autoload
 32:  * Horde_Registry_Application::). */
 33: require_once HORDE_BASE . '/lib/core.php';
 34: 
 35: /**
 36:  * Ingo application API.
 37:  *
 38:  */
 39: class Ingo_Application extends Horde_Registry_Application
 40: {
 41:     /**
 42:      */
 43:     public $version = 'H4 (2.0.11-git)';
 44: 
 45:     /**
 46:      * Global variables defined:
 47:      *   $all_rulesets - TODO
 48:      *   $ingo_shares - TODO
 49:      *   $ingo_storage - TODO
 50:      */
 51:     protected function _init()
 52:     {
 53:         // Load the Ingo_Storage driver.
 54:         $GLOBALS['ingo_storage'] = Ingo_Storage::factory();
 55: 
 56:         // Create the ingo session.
 57:         Ingo::createSession();
 58: 
 59:         // Create shares if necessary.
 60:         $transport = Ingo::getTransport();
 61:         if ($transport->supportShares()) {
 62:             $GLOBALS['ingo_shares'] = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create();
 63:             $GLOBALS['all_rulesets'] = Ingo::listRulesets();
 64: 
 65:             /* If personal share doesn't exist then create it. */
 66:             $signature = $GLOBALS['session']->get('ingo', 'backend/id') . ':' . $GLOBALS['registry']->getAuth();
 67:             if (!$GLOBALS['ingo_shares']->exists($signature)) {
 68:                 $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create();
 69:                 $name = $identity->getValue('fullname');
 70:                 if (trim($name) == '') {
 71:                     $name = $GLOBALS['registry']->getAuth('original');
 72:                 }
 73:                 $share = $GLOBALS['ingo_shares']->newShare($GLOBALS['registry']->getAuth(), $signature, $name);
 74:                 $GLOBALS['ingo_shares']->addShare($share);
 75:                 $GLOBALS['all_rulesets'][$signature] = $share;
 76:             }
 77: 
 78:             /* Select current share. */
 79:             $GLOBALS['session']->set('ingo', 'current_share', Horde_Util::getFormData('ruleset', $GLOBALS['session']->get('ingo', 'current_share')));
 80:             if (!$GLOBALS['session']->get('ingo', 'current_share') ||
 81:                 empty($GLOBALS['all_rulesets'][$GLOBALS['session']->get('ingo', 'current_share')]) ||
 82:                 !$GLOBALS['all_rulesets'][$GLOBALS['session']->get('ingo', 'current_share')]->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::READ)) {
 83:                 $GLOBALS['session']->set('ingo', 'current_share', $signature);
 84:             }
 85:         } else {
 86:             $GLOBALS['ingo_shares'] = null;
 87:         }
 88:     }
 89: 
 90:     /**
 91:      */
 92:     public function perms()
 93:     {
 94:         return array(
 95:             'allow_rules' => array(
 96:                 'title' => _("Allow Rules"),
 97:                 'type' => 'boolean'
 98:             ),
 99:             'max_rules' => array(
100:                 'title' => _("Maximum Number of Rules"),
101:                 'type' => 'int'
102:             )
103:         );
104:     }
105: 
106:     /**
107:      */
108:     public function menu($menu)
109:     {
110:         try {
111:             $menu->add(Horde::url('filters.php'), _("Filter _Rules"), 'ingo.png', null, null, null, basename($_SERVER['PHP_SELF']) == 'index.php' ? 'current' : null);
112:             $menu->add(Horde::url($GLOBALS['injector']->getInstance('Horde_Registry')->link('mail/showWhitelist')), _("_Whitelist"), 'whitelist.png');
113:             $menu->add(Horde::url($GLOBALS['injector']->getInstance('Horde_Registry')->link('mail/showBlacklist')), _("_Blacklist"), 'blacklist.png');
114:         } catch (Horde_Exception $e) {
115:             Horde::logMessage($e->getMessage(), 'ERR');
116:         }
117: 
118:         $s_categories = $GLOBALS['session']->get('ingo', 'script_categories');
119: 
120:         if (in_array(Ingo_Storage::ACTION_VACATION, $s_categories)) {
121:             $menu->add(Horde::url('vacation.php'), _("_Vacation"), 'vacation.png');
122:         }
123: 
124:         if (in_array(Ingo_Storage::ACTION_FORWARD, $s_categories)) {
125:             $menu->add(Horde::url('forward.php'), _("_Forward"), 'forward.png');
126:         }
127: 
128:         if (in_array(Ingo_Storage::ACTION_SPAM, $s_categories)) {
129:             $menu->add(Horde::url('spam.php'), _("S_pam"), 'spam.png');
130:         }
131: 
132:         if ($GLOBALS['session']->get('ingo', 'script_generate') &&
133:             (!$GLOBALS['prefs']->isLocked('auto_update') ||
134:              !$GLOBALS['prefs']->getValue('auto_update'))) {
135:             $menu->add(Horde::url('script.php'), _("_Script"), 'script.png');
136:         }
137: 
138:         if (!empty($GLOBALS['ingo_shares']) && empty($GLOBALS['conf']['share']['no_sharing'])) {
139:             $menu->add('#', _("_Permissions"), 'perms.png', null, '', Horde::popupJs(Horde::url($GLOBALS['registry']->get('webroot', 'horde') . '/services/shares/edit.php', true), array('params' => array('app' => 'ingo', 'share' => $GLOBALS['session']->get('ingo', 'backend/id') . ':' . $GLOBALS['registry']->getAuth()), 'urlencode' => true)) . 'return false;');
140:         }
141:     }
142: 
143:     /**
144:      */
145:     public function hasPermission($permission, $allowed, $opts = array())
146:     {
147:         if (is_array($allowed)) {
148:             switch ($permission) {
149:             case 'allow_rules':
150:                 $allowed = (bool)count(array_filter($allowed));
151:                 break;
152: 
153:             case 'max_rules':
154:                 $allowed = max($allowed);
155:                 break;
156:             }
157:         }
158:         return $allowed;
159:     }
160: 
161:     /**
162:      */
163:     public function removeUserData($user)
164:     {
165:         /* Remove all filters/rules owned by the user. */
166:         try {
167:             $GLOBALS['ingo_storage']->removeUserData($user);
168:         } catch (Ingo_Exception $e) {
169:             Horde::logMessage($e, 'ERR');
170:             throw $e;
171:         }
172: 
173:         /* Now remove all shares owned by the user. */
174:         if (!empty($GLOBALS['ingo_shares'])) {
175:             /* Get the user's default share. */
176:             try {
177:                 $share = $GLOBALS['ingo_shares']->getShare($user);
178:                 $GLOBALS['ingo_shares']->removeShare($share);
179:             } catch (Horde_Share_Exception $e) {
180:                 Horde::logMessage($e, 'ERR');
181:                 throw new Ingo_Exception($e);
182:             }
183: 
184:             /* Get a list of all shares this user has perms to and remove the
185:              * perms. */
186:             try {
187:                 $shares = $GLOBALS['ingo_shares']->listShares($user);
188:                 foreach ($shares as $share) {
189:                     $share->removeUser($user);
190:                 }
191:             } catch (Horde_Share_Exception $e) {
192:                 Horde::logMessage($e, 'ERR');
193:             }
194: 
195:             /* Get a list of all shares this user owns and has perms to delete
196:              * and remove them. */
197:             try {
198:                 $shares = $GLOBALS['ingo_shares']->listShares($user, array('perm' => Horde_Perms::DELETE,
199:                                                                            'attributes' => $user));
200:             } catch (Horde_Share_Exception $e) {
201:                 Horde::logMessage($e, 'ERR');
202:                 throw new Ingo_Exception($e);
203:             }
204: 
205:             foreach ($shares as $share) {
206:                 $GLOBALS['ingo_shares']->removeShare($share);
207:             }
208:         }
209:     }
210: 
211:     /**
212:      */
213:     public function prefsInit($ui)
214:     {
215:         if (!$GLOBALS['session']->get('ingo', 'script_generate')) {
216:             $ui->suppressGroups[] = 'script';
217:         }
218:     }
219: }
220: 
API documentation generated by ApiGen