* @copyright 2002-2009 Alexandros Vellis
* @package plugins
* @subpackage avelsieve
*/
/**
* Root class for SIEVE actions.
*
* Each class that extends this class describes a SIEVE action and can contain
* the following variables:
*
* num Number of action
* capability Required capability(ies), if any
* text Textual description
* helptxt Explanation text
* options Array of Options and their default values
*
* It can also contain these functions:
*
* options_html() Returns the HTML printout of the action's options
*/
class avelsieve_action {
/*
* @var boolean Flag to enable use of images and visual enhancements.
*/
var $useimages = true;
/**
* @var boolean Translate generated email messages?
*/
var $translate_return_msgs = false;
/**
* @var int Level of Javascript support
*/
var $js = 0;
/**
* Initialize variables that we get from the configuration of avelsieve and
* the environment of Squirrelmail.
*
* @return void
*/
function init() {
global $translate_return_msgs, $useimages, $javascript_on, $plugins;
if(isset($translate_return_msgs)) {
$this->translate_return_msgs = $translate_return_msgs;
}
if(isset($useimages)) {
$this->useimages = $useimages;
}
if($javascript_on) {
$this->js++;
if(in_array('javascript_libs', $plugins)) {
$this->js++;
}
}
}
/**
* Initialize other properties based on the ones defined from child classes.
* @return void
*/
function avelsieve_action(&$s, $rule) {
$this->rule = $rule;
$this->s = $s;
if ($this->useimages && isset($this->image_src)) {
$this->text = ' '.
'' . $this->text . '';
}
}
/**
* Check if this action is valid in the current server capabilities
* ($this->capabilities array).
* @return boolean
*/
function is_action_valid() {
if(isset($this->capability) && !empty($this->capability)) {
if(!$this->s->capability_exists($this->capability)) {
return false;
}
}
return true;
}
/**
* Return All HTML Code that describes this action.
*
* @return string
*/
function action_html() {
/* Radio button */
$out = $this->action_radio();
$identifier = ($this->num ? 'action_'.$this->num : $this->name);
/* Main text */
$out .= '';
if(isset($this->helptxt)) {
$out .= ' is_selected() ? ' style="display:inline"' :
($this->js ? ' style="display:none"': '') ) .
'> – '.$this->helptxt.'';
}
/* Options */
if(isset($this->options) and sizeof($this->options) > 0) {
$optval = array();
foreach($this->options as $opt=>$defaultval) {
if(is_array($opt)) {
/* Two - level options, e.g. notify */
foreach($opt as $opt2=>$defaultval2) {
if(isset($this->rule[$opt][$opt2])) {
$optval[$opt][$opt2] = $this->rule[$opt][$opt2];
} else {
$optval[$opt][$opt2] = $defaultval2;
}
}
} else {
/* Flat-level options schema */
if(isset($this->rule[$opt])) {
$optval[$opt] = $this->rule[$opt];
} else {
$optval[$opt] = $defaultval;
}
}
}
if($this->num) {
/* Radio Button */
$out .= '
'; if(method_exists($this, 'options_html')) { $out .= $this->options_html($optval); } else { $out .= $this->options_html_generic($optval); } $out .= ''; $out .= '