Overview

Packages

  • None
  • Sam

Classes

  • Sam
  • Sam_Driver_Amavisd_Sql
  • Sam_Driver_Base
  • Sam_Driver_Spamd_Base
  • Sam_Driver_Spamd_Ftp
  • Sam_Driver_Spamd_Ldap
  • Sam_Driver_Spamd_Sql
  • Sam_Exception
  • Sam_Factory_Driver
  • Sam_Form_Blacklist
  • Sam_Form_List
  • Sam_Form_Options
  • Sam_Form_Whitelist
  • Overview
  • Package
  • Class
  • Tree
 1: <?php
 2: /**
 3:  * Form Class for SpamAssassin Options Management.
 4:  *
 5:  * Copyright 2003-2012 Horde LLC (http://www.horde.org/)
 6:  *
 7:  * See the enclosed file COPYING for license information (GPL). If you
 8:  * did not receive this file, see http://www.horde.org/licenses/gpl.
 9:  *
10:  * @author  Max Kalika <max@horde.org>
11:  * @package Sam
12:  */
13: class Sam_Form_Options extends Horde_Form
14: {
15:     public function __construct($vars)
16:     {
17:         parent::__construct($vars, _("Spam Options"));
18:         $this->setButtons(_("Save"), true);
19: 
20:         try {
21:             $sam_driver = $GLOBALS['injector']->getInstance('Sam_Driver');
22:         } catch (Sam_Exception $e) {
23:             return;
24:         }
25: 
26:         foreach (Sam::getAttributes() as $key => $attribute) {
27:             if (!Sam::infoAttribute($attribute['type']) &&
28:                 !$sam_driver->hasCapability($key)) {
29:                 continue;
30:             }
31:             $var = $this->addVariable($attribute['label'],
32:                                       $key, $attribute['type'],
33:                                       !empty($attribute['required']),
34:                                       !empty($attribute['readonly']),
35:                                       isset($attribute['description'])
36:                                           ? $attribute['description']
37:                                           : null,
38:                                       isset($attribute['params'])
39:                                           ? $attribute['params']
40:                                           : array());
41: 
42:             $var->setHelp($key);
43:             if (isset($attribute['default'])) {
44:                 $var->setDefault($attribute['default']);
45:             }
46: 
47:             if ($vars->exists($key)) {
48:                 continue;
49:             }
50: 
51:             if (isset($attribute['basepref'])) {
52:                 /* If basepref is set, key is one of multiple multiple possible
53:                  * entries for basepref.  Get all basepref entries from
54:                  * backend. */
55:                 $value = $sam_driver->getListOption($attribute['basepref']);
56: 
57:                 /* Split entries into individual elements */
58:                 $elements = preg_split('/\n/', $value, -1, PREG_SPLIT_NO_EMPTY);
59: 
60:                 foreach ($elements as $element) {
61:                     /* Split element into subtype and data e.g. 'Subject' and
62:                      * '***SPAM***' */
63:                     $pref = explode(' ', $element);
64: 
65:                     /* Find right subtype entry for this key */
66:                     if (isset($pref[0]) && $pref[0] == $attribute['subtype']) {
67:                         if (isset($pref[1])) {
68:                             /* Set value for key to just the data */
69:                             $vars->set($key, $pref[1]);
70:                         } else {
71:                             $vars->set($key, '');
72:                         }
73:                         break;
74:                     }
75:                 }
76:             } else {
77:                 $value = $sam_driver->getOption($key);
78:                 if (!is_null($value)) {
79:                     if ($attribute['type'] == 'boolean') {
80:                         $boolean = $sam_driver->optionToBoolean($value);
81:                         $vars->set($key, $boolean);
82:                     } else {
83:                         $vars->set($key, $value);
84:                     }
85:                 }
86:             }
87:         }
88: 
89:         if ($sam_driver->hasCapability('global_defaults') &&
90:             $GLOBALS['registry']->isAdmin()) {
91:             $this->addVariable('', '', 'spacer', false);
92:             $var = $this->addVariable(_("Make Settings Global"),
93:                                       'global_defaults', 'boolean', false);
94:             $var->setHelp('global_defaults');
95:         }
96:     }
97: }
98: 
API documentation generated by ApiGen