/** */ protected function _init() { global $injector, $notification, $page_output; $this->_assertCategory('Ingo_Rule_System_Whitelist', _("Whitelist")); $ingo_storage = $injector->getInstance('Ingo_Factory_Storage')->create(); $whitelist = $ingo_storage->getSystemRule('Ingo_Rule_System_Whitelist'); /* Token checking & perform requested actions. */ switch ($this->_checkToken(array('rule_update'))) { case 'rule_update': try { $whitelist->addresses = $this->vars->whitelist; $ingo_storage->updateRule($whitelist); $notification->push(_("Changes saved."), 'horde.success'); $injector->getInstance('Ingo_Factory_Script')->activateAll(); } catch (Ingo_Exception $e) { $notification->push($e); } break; } /* Prepare the view. */ $view = new Horde_View(array('templatePath' => INGO_TEMPLATES . '/basic/whitelist')); $view->addHelper('Horde_Core_View_Helper_Help'); $view->addHelper('Horde_Core_View_Helper_Label'); $view->addHelper('Text'); $view->disabled = $whitelist->disable; $view->formurl = $this->_addToken(self::url()); $view->whitelist = implode("\n", $whitelist->addresses); $page_output->addScriptFile('whitelist.js'); $page_output->addInlineJsVars(array('IngoWhitelist.filtersurl' => strval(Ingo_Basic_Filters::url()->setRaw(true)))); $this->title = _("Whitelist Edit"); $this->output = $view->render('whitelist'); }
/** */ protected function _init() { global $injector, $notification; /* Redirect if forward is not available. */ $this->_assertCategory(Ingo_Storage::ACTION_FORWARD, _("Forward")); if ($this->vars->submitbutton == _("Return to Rules List")) { Ingo_Basic_Filters::url()->redirect(); } /* Get the forward object and rule. */ $ingo_storage = $injector->getInstance('Ingo_Factory_Storage')->create(); $forward = $ingo_storage->retrieve(Ingo_Storage::ACTION_FORWARD); $filters = $ingo_storage->retrieve(Ingo_Storage::ACTION_FILTERS); $fwd_id = $filters->findRuleId(Ingo_Storage::ACTION_FORWARD); $fwd_rule = $filters->getRule($fwd_id); /* Build form. */ $form = new Ingo_Form_Forward($this->vars); /* Perform requested actions. Ingo_Form_Forward does token checking * for us. */ if ($form->validate($this->vars)) { $forward->setForwardAddresses($this->vars->addresses); $forward->setForwardKeep($this->vars->keep_copy == 'on'); try { $ingo_storage->store($forward); $notification->push(_("Changes saved."), 'horde.success'); if ($this->vars->submitbutton == _("Save and Enable")) { $filters->ruleEnable($fwd_id); $ingo_storage->store($filters); $notification->push(_("Rule Enabled"), 'horde.success'); $fwd_rule['disable'] = false; } elseif ($this->vars->submitbutton == _("Save and Disable")) { $filters->ruleDisable($fwd_id); $ingo_storage->store($filters); $notification->push(_("Rule Disabled"), 'horde.success'); $fwd_rule['disable'] = true; } Ingo_Script_Util::update(); } catch (Ingo_Exception $e) { $notification->push($e); } } /* Add buttons depending on the above actions. */ $form->setCustomButtons($fwd_rule['disable']); /* Set default values. */ if (!$form->isSubmitted()) { $this->vars->keep_copy = $forward->getForwardKeep(); $this->vars->addresses = implode("\n", $forward->getForwardAddresses()); } /* Set form title. */ $form_title = _("Forward"); if (!empty($fwd_rule['disable'])) { $form_title .= ' [<span class="horde-form-error">' . _("Disabled") . '</span>]'; } $form_title .= ' ' . Horde_Help::link('ingo', 'forward'); $form->setTitle($form_title); $this->header = _("Forwards Edit"); Horde::startBuffer(); $form->renderActive(new Horde_Form_Renderer(array('encode_title' => false, 'varrenderer_driver' => array('ingo', 'ingo'))), $this->vars, self::url(), 'post'); $this->output = Horde::endBuffer(); }
/** */ public function links() { global $prefs, $registry; $pushed = $registry->pushApp('ingo'); $links = array('newEmailFilter' => strval(Ingo_Basic_Rule::url()) . '&field[0]=From&match[0]=is&value[0]=|email|', 'showFilters' => strval(Ingo_Basic_Filters::url()), 'showFiltersMbox' => strval(Ingo_Basic_Filters::url(array('mbox_search' => '|mailbox|')))); if (!$prefs->isLocked('blacklist')) { $links['showBlacklist'] = strval(Ingo_Basic_Blacklist::url()); } if (!$prefs->isLocked('whitelist')) { $links['showWhitelist'] = strval(Ingo_Basic_Whitelist::url()); } if (!$prefs->isLocked('vacation')) { $links['showVacation'] = strval(Ingo_Basic_Vacation::url()); } if ($pushed) { $registry->popApp(); } return $links; }
/** */ protected function _init() { global $injector, $notification; $this->_assertCategory(Ingo_Storage::ACTION_SPAM, _("Spam filtering")); /* Get the spam object and rule. */ $ingo_storage = $injector->getInstance('Ingo_Factory_Storage')->create(); $spam = $ingo_storage->retrieve(Ingo_Storage::ACTION_SPAM); $filters = $ingo_storage->retrieve(Ingo_Storage::ACTION_FILTERS); $spam_id = $filters->findRuleId(Ingo_Storage::ACTION_SPAM); $spam_rule = $filters->getRule($spam_id); if ($this->vars->submitbutton == _("Return to Rules List")) { Ingo_Basic_Filters::url()->redirect(); } /* Build form. */ $form = new Ingo_Form_Spam($this->vars); $renderer = new Horde_Form_Renderer(array('encode_title' => false, 'varrenderer_driver' => array('ingo', 'ingo'))); /* Perform requested actions. Ingo_Form_Spam does token checking for * us .*/ if ($form->validate($this->vars)) { $success = false; try { $spam->setSpamFolder($this->validateMbox('folder')); $success = true; } catch (Horde_Exception $e) { $notification->push($e); } $spam->setSpamLevel($this->vars->level); try { $ingo_storage->store($spam); $notification->push(_("Changes saved."), 'horde.success'); if ($this->vars->submitbutton == _("Save and Enable")) { $filters->ruleEnable($spam_id); $ingo_storage->store($filters); $notification->push(_("Rule Enabled"), 'horde.success'); $spam_rule['disable'] = false; } elseif ($this->vars->submitbutton == _("Save and Disable")) { $filters->ruleDisable($spam_id); $ingo_storage->store($filters); $notification->push(_("Rule Disabled"), 'horde.success'); $spam_rule['disable'] = true; } Ingo_Script_Util::update(); } catch (Ingo_Exception $e) { $notification->push($e); } } /* Add buttons depending on the above actions. */ $form->setCustomButtons($spam_rule['disable']); /* Set default values. */ $form->folder_var->type->setFolder($spam->getSpamFolder()); if (!$form->isSubmitted()) { $this->vars->level = $spam->getSpamLevel(); $this->vars->folder = $spam->getSpamFolder(); $this->vars->actionID = ''; } /* Set form title. */ $form_title = _("Spam Filtering"); if (!empty($spam_rule['disable'])) { $form_title .= ' [<span class="horde-form-error">' . _("Disabled") . '</span>]'; } $form_title .= ' ' . Horde_Help::link('ingo', 'spam'); $form->setTitle($form_title); $this->header = _("Spam Filtering"); Horde::startBuffer(); $form->renderActive($renderer, $this->vars, self::url(), 'post'); $this->output = Horde::endBuffer(); }
/** */ protected function _init() { global $conf, $injector, $notification, $page_output; $ingo_storage = $injector->getInstance('Ingo_Factory_Storage')->create(); switch ($ingo_storage->maxRules()) { case Ingo_Storage::MAX_NONE: Horde::permissionDeniedError('ingo', 'allow_rules', _("You are not allowed to create or edit custom rules.")); Ingo_Basic_Filters::url()->redirect(); case Ingo_Storage::MAX_OVER: Horde::permissionDeniedError('ingo', 'max_rules', sprintf(_("You are not allowed to create more than %d rules."), $ingo_storage->max_rules)); Ingo_Basic_Filters::url()->redirect(); } if (!Ingo::hasSharePermission(Horde_Perms::EDIT)) { $notification->push(_("You do not have permission to edit filter rules."), 'horde.error'); Ingo_Basic_Filters::url()->redirect(); } /* Load the Ingo_Script:: driver. */ $ingo_script_factory = $injector->getInstance('Ingo_Factory_Script'); $ingo_script = $ingo_script_factory->create(Ingo::RULE_FILTER); /* Redirect if no rules are available. */ $availActions = $ingo_script->availableActions(); if (empty($availActions)) { $notification->push(_("Individual rules are not supported in the current filtering driver."), 'horde.error'); Ingo_Basic_Filters::url()->redirect(); } /* This provides the $ingo_fields array. */ $config = new Horde_Registry_LoadConfig('ingo', 'fields.php', 'ingo_fields'); $ingo_fields = $config->config['ingo_fields']; /* Token checking. */ $actionID = $this->_checkToken(array('rule_save', 'rule_delete')); /* Update the current rules before performing any action. */ switch ($this->vars->action) { case 'Ingo_Rule_User_Discard': case 'Ingo_Rule_User_FlagOnly': case 'Ingo_Rule_User_Keep': case 'Ingo_Rule_User_Move': case 'Ingo_Rule_User_MoveKeep': case 'Ingo_Rule_User_Notify': case 'Ingo_Rule_User_Redirect': case 'Ingo_Rule_User_RedirectKeep': case 'Ingo_Rule_User_Reject': $rule = new $this->vars->action(); $rule->combine = $this->vars->combine; $rule->name = $this->vars->name; $rule->stop = $this->vars->stop; $rule->uid = $this->vars->edit; break; default: $rule = isset($this->vars->edit) ? $ingo_storage->getRuleByUid($this->vars->edit) : new Ingo_Rule_User(); break; } if (!$rule) { $notification->push(_("Filter not found."), 'horde.error'); Ingo_Basic_Filters::url()->redirect(); } if ($ingo_script->hasFeature('case_sensitive')) { $casesensitive = $this->vars->case; } foreach (array_filter(isset($this->vars->field) ? $this->vars->field : array()) as $key => $val) { $condition = array(); $f_label = null; if ($val == Ingo::USER_HEADER) { $condition['field'] = empty($this->vars->userheader[$key]) ? '' : $this->vars->userheader[$key]; $condition['type'] = Ingo_Rule_User::TEST_HEADER; } elseif (!isset($ingo_fields[$val])) { $condition['field'] = $val; $condition['type'] = Ingo_Rule_User::TEST_HEADER; } else { $condition['field'] = $val; $f_label = $ingo_fields[$val]['label']; $condition['type'] = $ingo_fields[$val]['type']; } $condition['match'] = isset($this->vars->match[$key]) ? $this->vars->match[$key] : ''; if ($actionID == 'rule_save' && empty($this->vars->value[$key]) && !in_array($condition['match'], array('exists', 'not exist'))) { $notification->push(sprintf(_("You cannot create empty conditions. Please fill in a value for \"%s\"."), is_null($f_label) ? $condition['field'] : $f_label), 'horde.error'); $actionID = null; } $condition['value'] = isset($this->vars->value[$key]) ? $this->vars->value[$key] : ''; if (isset($casesensitive)) { $condition['case'] = isset($casesensitive[$key]) ? $casesensitive[$key] : ''; } $tmp = $rule->conditions; $tmp[] = $condition; $rule->conditions = $tmp; } if ($this->vars->action) { switch ($rule->type) { case Ingo_Rule_User::TYPE_MAILBOX: switch ($actionID) { case 'rule_save': try { $rule->value = $this->validateMbox('actionvalue'); } catch (Ingo_Exception $e) { $notification->push($e, 'horde.error'); $actionID = null; } break; default: $rule->value = $this->vars->actionvalue; if (!$this->vars->actionvalue && isset($this->vars->actionvalue_new)) { $page_output->addInlineScript(array('IngoNewFolder.setNewFolder("actionvalue", ' . Horde_Serialize::serialize($this->vars->actionvalue_new, Horde_Serialize::JSON) . ')'), true); } break; } break; default: $rule->value = $this->vars->actionvalue; break; } } $flags = empty($this->vars->flags) ? array() : $this->vars->flags; $tmp = $rule->flags; foreach ($flags as $val) { $tmp |= $val; } $rule->flags = $tmp; /* Run through action handlers. */ switch ($actionID) { case 'rule_save': if (empty($rule->conditions)) { $notification->push(_("You need to select at least one field to match."), 'horde.error'); break; } $ingo_storage->updateRule($rule); $notification->push(_("Changes saved."), 'horde.success'); try { $ingo_script_factory->activateAll(); } catch (Ingo_Exception $e) { $notification->push($e, 'horde.error'); } Ingo_Basic_Filters::url()->redirect(); case 'rule_delete': if (isset($this->vars->conditionnumber)) { $tmp = $rule->conditions; unset($tmp[intval($this->vars->conditionnumber)]); $rule->conditions = array_values($tmp); } break; } /* Add new, blank condition. */ $rule->conditions[] = array(); /* Prepare the view. */ $view = new Horde_View(array('templatePath' => INGO_TEMPLATES . '/basic/rule')); $view->addHelper('Horde_Core_View_Helper_Help'); $view->addHelper('Horde_Core_View_Helper_Image'); $view->addHelper('Horde_Core_View_Helper_Label'); $view->addHelper('FormTag'); $view->addHelper('Tag'); $view->addHelper('Text'); $view->avail_types = $ingo_script->availableTypes(); $view->edit = $this->vars->edit; $view->fields = $ingo_fields; $view->formurl = $this->_addToken(self::url()); $view->rule = $rule; $view->special = $ingo_script->specialTypes(); $view->userheader = !empty($conf['rules']['userheader']); $filter = array(); $lastcond = count($rule->conditions) - 1; /* Display the conditions. */ foreach ($rule->conditions as $cond_num => $condition) { $tmp = array('cond_num' => intval($cond_num), 'field' => isset($condition['field']) ? $condition['field'] : '', 'lastfield' => $lastcond == $cond_num); if ($view->userheader && isset($condition['type']) && $condition['type'] == Ingo_Rule_User::TEST_HEADER && !isset($ingo_fields[$tmp['field']])) { $tmp['userheader'] = $tmp['field']; } if ($tmp['lastfield']) { $filter[] = $tmp; continue; } /* Create the match listing. */ if (!isset($condition['field']) || $condition['field'] == Ingo::USER_HEADER || !isset($ingo_fields[$condition['field']]['tests'])) { $avail_tests = $ingo_script->availableTests(); } else { $avail_tests = $ingo_fields[$condition['field']]['tests']; } $tmp['matchtest'] = array(); $selected_test = empty($condition['match']) ? null : $condition['match']; foreach ($avail_tests as $test) { if (is_null($selected_test)) { $selected_test = $test; } $tmp['matchtest'][] = array('label' => $rule->getTestInfo($test)->label, 'selected' => isset($condition['match']) && $test == $condition['match'], 'value' => $test); } if (!in_array($selected_test, array('exists', 'not exist'))) { $tmp['match_value'] = isset($condition['value']) ? $condition['value'] : ''; } $testOb = $rule->getTestInfo(!empty($condition['match']) ? $condition['match'] : 'contains'); switch ($testOb->type) { case 'text': if ($ingo_script->hasFeature('case_sensitive')) { $tmp['case_sensitive'] = !empty($condition['case']); } break; } $filter[] = $tmp; } $view->filter = $filter; /* Get the action select output. */ $actions = array(); foreach ($availActions as $val) { $ob = new $val(); $actions[] = array('label' => $ob->label, 'selected' => $ob instanceof $rule, 'value' => $val); } $view->actions = $actions; /* Get the action value output. */ switch ($rule->type) { case Ingo_Rule_User::TYPE_MAILBOX: $view->actionvaluelabel = _("Select target folder"); $view->actionvalue = Ingo_Flist::select($rule->value); break; case Ingo_Rule_User::TYPE_TEXT: $view->actionvaluelabel = _("Value"); $view->actionvalue = '<input id="actionvalue" name="actionvalue" size="40" value="' . htmlspecialchars($rule->value) . '" />'; break; } $view->flags = $rule->flags && Ingo_Rule_User::FLAG_AVAILABLE && $ingo_script->hasFeature('imap_flags'); $view->stop = $ingo_script->hasFeature('stop_script'); $page_output->addScriptFile('rule.js'); $page_output->addInlineJsVars(array('IngoRule.filtersurl' => strval(Ingo_Basic_Filters::url()->setRaw(true)))); $this->header = $rule->name; $this->output = $view->render('rule'); }
/** * Return Ingo's initial page. * * @return Horde_Url URL object. */ public static function getInitialPage() { global $registry; switch ($registry->getView()) { case $registry::VIEW_SMARTMOBILE: return Horde::url('smartmobile.php'); default: if ($initial_page = $registry->get('initial_page')) { return Horde::url($registry->get('webroot') . '/' . $initial_page); } return Ingo_Basic_Filters::url(); } }
/** */ protected function _init() { global $injector, $notification; $this->_assertCategory(Ingo_Storage::ACTION_VACATION, _("Vacation")); /* Get vacation object and rules. */ $ingo_storage = $injector->getInstance('Ingo_Factory_Storage')->create(); $vacation = $ingo_storage->retrieve(Ingo_Storage::ACTION_VACATION); $filters = $ingo_storage->retrieve(Ingo_Storage::ACTION_FILTERS); $vac_id = $filters->findRuleId(Ingo_Storage::ACTION_VACATION); $vac_rule = $filters->getRule($vac_id); /* Load libraries. */ if ($this->vars->submitbutton == _("Return to Rules List")) { Ingo_Basic_Filters::url()->redirect(); } /* Build form. */ $form = new Ingo_Form_Vacation($this->vars, '', null, $injector->getInstance('Ingo_Factory_Script')->create(Ingo::RULE_VACATION)->availableCategoryFeatures(Ingo_Storage::ACTION_VACATION)); /* Perform requested actions. Ingo_Form_Vacation does token checking * for us. */ if ($form->validate($this->vars)) { $form->getInfo($this->vars, $info); $vacation->setVacationAddresses(isset($info['addresses']) ? $info['addresses'] : ''); $vacation->setVacationDays($info['days']); $vacation->setVacationExcludes($info['excludes']); $vacation->setVacationIgnorelist($info['ignorelist'] == 'on'); $vacation->setVacationReason($info['reason']); $vacation->setVacationSubject($info['subject']); $vacation->setVacationStart($info['start']); $vacation->setVacationEnd($info['end']); try { $ingo_storage->store($vacation); $notification->push(_("Changes saved."), 'horde.success'); if ($this->vars->submitbutton == _("Save and Enable")) { $filters->ruleEnable($vac_id); $ingo_storage->store($filters); $notification->push(_("Rule Enabled"), 'horde.success'); $vac_rule['disable'] = false; } elseif ($this->vars->get('submitbutton') == _("Save and Disable")) { $filters->ruleDisable($vac_id); $ingo_storage->store($filters); $notification->push(_("Rule Disabled"), 'horde.success'); $vac_rule['disable'] = true; } Ingo_Script_Util::update(); } catch (Ingo_Exception $e) { $notification->push($e); } } /* Add buttons depending on the above actions. */ $form->setCustomButtons($vac_rule['disable']); /* Make sure we have at least one address. */ if (!$vacation->getVacationAddresses()) { $identity = $injector->getInstance('Horde_Core_Factory_Identity')->create(); $addresses = implode("\n", $identity->getAll('from_addr')); /* Remove empty lines. */ $addresses = trim(preg_replace('/\\n+/', "\n", $addresses)); if (empty($addresses)) { $addresses = $GLOBALS['registry']->getAuth(); } $vacation->setVacationAddresses($addresses); } /* Set default values. */ if (!$form->isSubmitted()) { $this->vars->set('addresses', implode("\n", $vacation->getVacationAddresses())); $this->vars->set('excludes', implode("\n", $vacation->getVacationExcludes())); $this->vars->set('ignorelist', $vacation->getVacationIgnorelist()); $this->vars->set('days', $vacation->getVacationDays()); $this->vars->set('subject', $vacation->getVacationSubject()); $this->vars->set('reason', $vacation->getVacationReason()); $this->vars->set('start', $vacation->getVacationStart()); $this->vars->set('end', $vacation->getVacationEnd()); $this->vars->set('start_year', $vacation->getVacationStartYear()); $this->vars->set('start_month', $vacation->getVacationStartMonth() - 1); $this->vars->set('start_day', $vacation->getVacationStartDay() - 1); $this->vars->set('end_year', $vacation->getVacationEndYear()); $this->vars->set('end_month', $vacation->getVacationEndMonth() - 1); $this->vars->set('end_day', $vacation->getVacationEndDay() - 1); } /* Set form title. */ $form_title = _("Vacation"); if (!empty($vac_rule['disable'])) { $form_title .= ' [<span class="horde-form-error">' . _("Disabled") . '</span>]'; } $form_title .= ' ' . Horde_Help::link('ingo', 'vacation'); $form->setTitle($form_title); $this->header = _("Vacation Edit"); Horde::startBuffer(); $form->renderActive(new Horde_Form_Renderer(array('encode_title' => false, 'varrenderer_driver' => array('ingo', 'ingo'))), $this->vars, self::url(), 'post'); $this->output = Horde::endBuffer(); }
/** * Add additional items to the sidebar. * * @param Horde_View_Sidebar $sidebar The sidebar object. */ public function sidebar($sidebar) { global $injector, $session; $actions = array(); foreach ($injector->getInstance('Ingo_Factory_Script')->createAll() as $script) { $actions = array_merge($actions, $script->availableActions()); } if (!empty($actions) && !$injector->getInstance('Ingo_Factory_Storage')->create()->maxRules()) { $sidebar->addNewButton(_("New Rule"), Ingo_Basic_Rule::url()); } if ($injector->getInstance('Ingo_Shares') && count($all_rulesets = $this->_listRulesets()) > 1) { $url = Ingo_Basic_Filters::url(); $current = $session->get('ingo', 'current_share'); $sidebar->containers['rulesets'] = array('header' => array('id' => 'ingo-toggle-rules', 'label' => _("Ruleset"), 'collapsed' => false)); foreach ($all_rulesets as $id => $ruleset) { $row = array('selected' => $current == $id, 'url' => $url->add('ruleset', $id), 'label' => $ruleset->get('name'), 'type' => 'radiobox'); $sidebar->addRow($row, 'rulesets'); } } }
/** */ protected function _init() { global $injector, $notification, $page_output; $this->_assertCategory(Ingo_Storage::ACTION_BLACKLIST, _("Blacklist")); $ingo_script = $injector->getInstance('Ingo_Factory_Script')->create(Ingo::RULE_BLACKLIST); $ingo_storage = $injector->getInstance('Ingo_Factory_Storage')->create(); $flagonly = $ingo_script && in_array(Ingo_Storage::ACTION_FLAGONLY, $ingo_script->availableActions()); /* Token checking & perform requested actions. */ switch ($this->_checkToken(array('rule_update'))) { case 'rule_update': switch ($this->vars->action) { case 'delete': $folder = ''; break; case 'mark': $folder = Ingo::BLACKLIST_MARKER; break; case 'folder': $folder = $this->validateMbox('actionvalue'); break; default: $folder = null; break; } if (!$flagonly && $folder == Ingo::BLACKLIST_MARKER) { $notification->push("Not supported by this script generator.", 'horde.error'); } else { try { $blacklist = Ingo::updateListFilter($this->vars->blacklist, Ingo_Storage::ACTION_BLACKLIST); $blacklist->setBlacklistFolder($folder); $ingo_storage->store($blacklist); $notification->push(_("Changes saved."), 'horde.success'); Ingo_Script_Util::update(); } catch (Ingo_Exception $e) { $notification->push($e->getMessage(), $e->getCode()); } } break; } /* Get the blacklist object. */ if (!isset($blacklist)) { try { $blacklist = $ingo_storage->retrieve(Ingo_Storage::ACTION_BLACKLIST); } catch (Ingo_Exception $e) { $notification->push($e); $blacklist = new Ingo_Storage_Blacklist(); } } /* Create the folder listing. */ $blacklist_folder = $blacklist->getBlacklistFolder(); $folder_list = Ingo_Flist::select($blacklist_folder, 'actionvalue'); /* Get the blacklist rule. */ $bl_rule = $ingo_storage->retrieve(Ingo_Storage::ACTION_FILTERS)->findRule(Ingo_Storage::ACTION_BLACKLIST); /* Prepare the view. */ $view = new Horde_View(array('templatePath' => INGO_TEMPLATES . '/basic/blacklist')); $view->addHelper('Horde_Core_View_Helper_Help'); $view->addHelper('Horde_Core_View_Helper_Label'); $view->addHelper('FormTag'); $view->addHelper('Tag'); $view->addHelper('Text'); $view->blacklist = implode("\n", $blacklist->getBlacklist()); $view->disabled = !empty($bl_rule['disable']); $view->flagonly = $flagonly; $view->folder = $blacklist_folder; $view->folderlist = $folder_list; $view->formurl = $this->_addToken(self::url()); $page_output->addScriptFile('blacklist.js'); $page_output->addInlineJsVars(array('IngoBlacklist.filtersurl' => strval(Ingo_Basic_Filters::url()->setRaw(true)))); $this->header = _("Blacklist Edit"); $this->output = $view->render('blacklist'); }
/** * Assert category. * * @param integer $type Category type. * @param string $label Category label. */ protected function _assertCategory($type, $label) { global $notification, $session; if (!in_array($type, $session->get('ingo', 'script_categories'))) { $notification->push(sprintf(_("%s is not supported in the current filtering driver."), $label), 'horde.error'); Ingo_Basic_Filters::url()->redirect(); } }
/** * Return Ingo's initial page. * * @return Horde_Url URL object. */ public static function getInitialPage() { global $registry; switch ($registry->getView()) { case $registry::VIEW_SMARTMOBILE: return Horde::url('smartmobile.php'); default: return Ingo_Basic_Filters::url(); } }
/** */ protected function _init() { global $injector, $notification, $session; /* Redirect if script updating is not available. */ $script = $injector->getInstance('Ingo_Factory_Script'); if (!$script->hasFeature('script_file')) { Ingo_Basic_Filters::url()->redirect(); } /* Generate the script. */ $scripts = array(); foreach ($script->createAll() as $script) { $scripts = array_merge($scripts, $script->generate()); } /* Token checking. */ $actionID = $this->_checkToken(array('action_activate', 'action_deactivate')); /* Activate/deactivate script if requested. */ switch ($actionID) { case 'action_activate': case 'action_deactivate': if (!empty($scripts)) { try { Ingo_Script_Util::activate($scripts, $actionID == 'action_deactivate'); } catch (Ingo_Exception $e) { $notification->push($e); } } break; case 'show_active': $scripts = array(); foreach ($session->get('ingo', 'backend/transport', Horde_Session::TYPE_ARRAY) as $transport) { try { $backend = $injector->getInstance('Ingo_Factory_Transport')->create($transport); if (method_exists($backend, 'getScript')) { $scripts[] = $backend->getScript(); } } catch (Horde_Exception_NotFound $e) { } catch (Ingo_Exception $e) { $notification->push($e); } } break; } /* Prepare the view. */ $view = new Horde_View(array('templatePath' => INGO_TEMPLATES . '/basic/script')); $view->addHelper('Text'); if (empty($scripts)) { $view->scriptexists = false; } else { $view->scriptexists = true; foreach ($scripts as &$script) { $script['lines'] = preg_split('(\\r\\n|\\n|\\r)', trim($script['script'])); $script['width'] = strlen(count($script['lines'])); } } $view->scripturl = $this->_addToken(self::url()); $view->showactivate = $actionID != 'show_active'; if ($view->scriptexists) { $view->scripts = $scripts; } $this->header = _("Filter Script Display"); $this->output = $view->render('script'); }
/** */ protected function _init() { global $injector, $notification, $registry; $this->_assertCategory('Ingo_Rule_System_Vacation', _("Vacation")); if ($this->vars->submitbutton == _("Return to Rules List")) { Ingo_Basic_Filters::url()->redirect(); } /* Get vacation object and rules. */ $ingo_storage = $injector->getInstance('Ingo_Factory_Storage')->create(); $vacation = $ingo_storage->getSystemRule('Ingo_Rule_System_Vacation'); /* Build form. */ $form = new Ingo_Form_Vacation($this->vars, '', null, $injector->getInstance('Ingo_Factory_Script')->create(Ingo::RULE_VACATION)->availableCategoryFeatures('Ingo_Rule_System_Vacation')); /* Perform requested actions. Ingo_Form_Vacation does token checking * for us. */ if ($form->validate($this->vars)) { $form->getInfo($this->vars, $info); $vacation->addresses = isset($info['addresses']) ? $info['addresses'] : ''; $vacation->days = $info['days']; $vacation->exclude = $info['excludes']; $vacation->ignore_list = $info['ignorelist'] == 'on'; $vacation->reason = $info['reason']; $vacation->subject = $info['subject']; $vacation->start = $info['start']; $vacation->end = $info['end']; try { if ($this->vars->submitbutton == _("Save and Enable")) { $vacation->disable = false; $notify = _("Rule Enabled"); } elseif ($this->vars->get('submitbutton') == _("Save and Disable")) { $vacation->disable = true; $notify = _("Rule Disabled"); } else { $notification->push(_("Changes saved."), 'horde.success'); } $ingo_storage->updateRule($vacation); $notification->push($notify, 'horde.success'); $injector->getInstance('Ingo_Factory_Script')->activateAll(); } catch (Ingo_Exception $e) { $notification->push($e); } } /* Add buttons depending on the above actions. */ $form->setCustomButtons($vacation->disable); /* Make sure we have at least one address. */ if (!count($vacation)) { $identity = $injector->getInstance('Horde_Core_Factory_Identity')->create(); $addresses = implode("\n", $identity->getAll('from_addr')); /* Remove empty lines. */ $addresses = trim(preg_replace('/\\n+/', "\n", $addresses)); if (empty($addresses)) { $addresses = $registry->getAuth(); } $vacation->addresses = $addresses; } /* Set default values. */ if (!$form->isSubmitted()) { $this->vars->set('addresses', implode("\n", $vacation->addresses)); $this->vars->set('excludes', implode("\n", $vacation->exclude)); $this->vars->set('ignorelist', $vacation->ignore_list); $this->vars->set('days', $vacation->days); $this->vars->set('subject', $vacation->subject); $this->vars->set('reason', $vacation->reason); $this->vars->set('start', $vacation->start); $this->vars->set('end', $vacation->end); $this->vars->set('start_year', $vacation->start_year); $this->vars->set('start_month', $vacation->start_month - 1); $this->vars->set('start_day', $vacation->start_day - 1); $this->vars->set('end_year', $vacation->end_year); $this->vars->set('end_month', $vacation->end_month - 1); $this->vars->set('end_day', $vacation->end_day - 1); } /* Set form title. */ $form_title = _("Vacation"); if ($vacation->disable) { $form_title .= ' [<span class="horde-form-error">' . _("Disabled") . '</span>]'; } $form_title .= ' ' . Horde_Help::link('ingo', 'vacation'); $form->setTitle($form_title); $this->header = _("Vacation Edit"); Horde::startBuffer(); Horde_Util::pformInput(); $form->renderActive(new Horde_Form_Renderer(array('encode_title' => false, 'varrenderer_driver' => array('ingo', 'ingo'))), $this->vars, self::url(array('append_session' => -1)), 'post'); $this->output = Horde::endBuffer(); }