original = $this->settings = get_option("{$this->config["label"]}-options");
// Check to see if there was a change to the number of widgets and update.
if ($_POST["{$this->config["label"]}-submit"] != "") {
$this->settings["number"] = strip_tags(stripslashes($_POST["{$this->config["label"]}-count"]));
}
// Check to see if the number of widgets is within range.
if ($this->settings["number"] < 1) $this->settings["number"] = 1;
if ($this->settings["number"] > $this->config["number"]) $this->settings["number"] = $this->config["number"];
for ($i = 1; $i <= $this->settings["number"]; $i++) {
if ($this->settings[$i]["defaults_set"] != true) $setdefaults = $this->settings[$i]["defaults_set"] = true;
if (count($this->config["settings"]) >= 1 && is_array($this->config["settings"]))
foreach ($this->config["settings"] as $item) {
if (is_array($item)) {
$label = "{$this->config["label"]}-$i-{$item["name"]}";
$value = $this->settings[$i]["{$item["name"]}"];
$default = $item["default-value"];
if ($setdefaults) $this->settings[$i]["{$item["name"]}"] = $default;
if ($_POST["{$this->config["label"]}-$i-submitted"]) {
$this->settings[$i]["{$item["name"]}"] = strip_tags(stripslashes($_POST[$label]));
// Call the validator if one is set. The validator function should return True is all is good else I will set the value to the default.
if (method_exists($this,$item["validator"])) {
if(!call_user_func(array($this,$item["validator"]),$this->settings[$i]["{$item["name"]}"])) $this->settings[$i]["{$item["name"]}"] = $item["default-value"];;
} elseif (function_exists($item["validator"])) {
if(!call_user_func($item["validator"],$this->settings[$i]["{$item["name"]}"])) $this->settings[$i]["{$item["name"]}"] = $item["default-value"];
}
}
}
}
}
// Save the options if they have chaanged.
if ($this->original != $this->settings) $this->save_settings();
// Look for and execute a function called additional_filters;
if (method_exists($this,"additional_filters")) call_user_func(array($this,"additional_filters"));
}
function save_settings() {
add_option("{$this->config["label"]}-options",'',"{$this->config["title"]}",'yes');
update_option("{$this->config["label"]}-options", $this->settings);
}
// The setting interface
function widget_control($i = 1) {
foreach ($this->config["settings"] as $item) {
if (is_array($item)) {
$label = "{$this->config["label"]}-$i-{$item["name"]}";
$value = $this->settings[$i]["{$item["name"]}"];
$description = $item["description"];
$type = $item["type"];
echo "
";
switch ($type){
case "text" :
echo "";
break;
case "checkbox" :
echo "";
break;
case "select" :
// First check that the option-list is an array and set the options to that if it is.
// Else I presume its a call to a function that outputs and array so try and execute it.
if (is_array($item["option-list"])) {
$optionlist = $item["option-list"];
} elseif (method_exists($this,$item["option-list"])) {
$optionlist = call_user_func(array($this,$item["option-list"]));
}
// Check that the previous section outputted an array and that the array has content.
if (!is_array($optionlist) && !count($optionlist) >= 1) {
echo "Error: missing or corrupt option-list array. ";
break;
}
echo "";
break;
}
echo "
get_settings();
// Add a widget and controller for the number stated.
for ($i = 1; $i <= $this->settings['number']; $i++) {
if ($this->config['number'] == 1) {
$name = array("{$this->config["title"]}", "widgets", $i);
} else {
$name = array("{$this->config["title"]} %s", "widgets", $i);
}
register_sidebar_widget($name, array($this,'widget_output'), "{$this->config["label"]}",$this->settings[$i]);
if (count($this->config["settings"]) >= 1) register_widget_control($name, array($this,'widget_control'),310,(count($this->config["settings"])*40)+10,$i);
}
// Add the interface to choose how many widgets you want available.
if ($this->config["number"] > 1) add_action('sidebar_admin_page', array($this,'page'));
}
}?>