| 1 |
<?php // $Id: mlm.inc,v 1.8 2009/03/18 22:11:38 vauxia Exp $ |
<?php // $Id: mlm.inc,v 1.9 2009/08/10 01:09:32 vauxia Exp $ |
| 2 |
|
|
| 3 |
class mlm { |
class mlm { |
|
// The name of this class/backend. |
|
|
var $name = NULL; |
|
|
|
|
| 4 |
// The supported list types ( announcement, discussion, etc. ). |
// The supported list types ( announcement, discussion, etc. ). |
| 5 |
var $supported_types = array(); |
var $supported_types = array(); |
| 6 |
|
|
| 10 |
// The node id that is acting as this list's container. |
// The node id that is acting as this list's container. |
| 11 |
var $nid = 0; |
var $nid = 0; |
| 12 |
|
|
| 13 |
|
// The title of this list. |
| 14 |
|
var $title = NULL; |
| 15 |
|
|
| 16 |
// The mailing list backend. |
// The mailing list backend. |
| 17 |
var $backend = NULL; |
var $backend = NULL; |
| 18 |
|
|
| 23 |
var $incoming_address = ''; |
var $incoming_address = ''; |
| 24 |
|
|
| 25 |
// An array of settings/options. |
// An array of settings/options. |
| 26 |
var $settings = array(); |
// var $settings = array(); |
|
|
|
|
// The title of this list. |
|
|
var $title = NULL; |
|
|
|
|
|
function __construct($row = NULL) { |
|
|
if ($row) { |
|
|
$row = (object) $row; |
|
|
if ($row->lid) $this->lid = $row->lid; |
|
|
if ($row->nid) $this->nid = $row->nid; |
|
|
$this->list_type = $row->list_type; |
|
|
$this->incoming_address = $row->incoming_address; |
|
|
$this->title = $row->title; |
|
| 27 |
|
|
| 28 |
// Load settings from database and set them in "$this->settings" |
function __construct($values = NULL) { |
| 29 |
$res = db_query("SELECT * FROM {mlm_setting} WHERE lid = %d", $this->lid); |
$current = (array) $this; |
| 30 |
while ($row = db_fetch_object($res)) { |
if ($values) { |
| 31 |
if (!$value = @unserialize($row->value)) $value = $row->value; |
foreach ($values as $name => $val) { |
| 32 |
$this->settings[$row->name] = $value; |
if ($name == 'settings' && !empty($val)) { |
| 33 |
|
$this->__construct(unserialize($val)); |
| 34 |
|
} |
| 35 |
|
elseif (array_key_exists($name, $current) && !is_null($val)) { |
| 36 |
|
$func = 'set_'. $name; |
| 37 |
|
if (method_exists($this, $func)) { |
| 38 |
|
$this->$func($val); |
| 39 |
|
} |
| 40 |
|
else { |
| 41 |
|
$this->$name = $val; |
| 42 |
|
} |
| 43 |
|
unset($current[$name]); |
| 44 |
|
} |
| 45 |
|
} |
| 46 |
|
} |
| 47 |
|
// Set defaults if possible. |
| 48 |
|
foreach ($current as $name => $val) { |
| 49 |
|
$func = 'set_'. $name; |
| 50 |
|
if (method_exists($this, $func)) { |
| 51 |
|
$this->$func($this->$name); |
| 52 |
} |
} |
| 53 |
} |
} |
| 54 |
} |
} |
| 63 |
} |
} |
| 64 |
} |
} |
| 65 |
|
|
| 66 |
|
function set_backend() { |
| 67 |
|
if (!isset($this->backend)) $this->backend = get_class($this); |
| 68 |
|
} |
| 69 |
|
|
| 70 |
|
function backend() { |
| 71 |
|
$this->set_backend(); |
| 72 |
|
return $this->backend; |
| 73 |
|
} |
| 74 |
|
|
| 75 |
|
function set_title($val = NULL) { |
| 76 |
|
$this->title = check_plain($val); |
| 77 |
|
} |
| 78 |
|
|
| 79 |
|
function title() { |
| 80 |
|
return check_plain($this->title); |
| 81 |
|
} |
| 82 |
|
|
| 83 |
|
function set_list_type($val = NULL) { |
| 84 |
|
if (in_array($val, $this->supported_types())) { |
| 85 |
|
$this->list_type = $val; |
| 86 |
|
} |
| 87 |
|
} |
| 88 |
|
|
| 89 |
|
function list_type() { |
| 90 |
|
return check_plain($this->list_type); |
| 91 |
|
} |
| 92 |
|
|
| 93 |
|
function set_incoming_address($val = NULL) { |
| 94 |
|
if (valid_email_address($val)) { |
| 95 |
|
$this->incoming_address = filter_xss($val); |
| 96 |
|
} |
| 97 |
|
} |
| 98 |
|
|
| 99 |
|
function incoming_address() { |
| 100 |
|
return filter_xss($this->incoming_address); |
| 101 |
|
} |
| 102 |
|
|
| 103 |
function supported_types() { |
function supported_types() { |
| 104 |
$types = array(); |
$types = array(); |
| 105 |
foreach ($this->supported_types as $type) { |
foreach ($this->supported_types as $type) { |
| 108 |
return $types; |
return $types; |
| 109 |
} |
} |
| 110 |
|
|
| 111 |
function title() { |
function set_description($text = NULL) { |
| 112 |
return $this->title; |
$this->description = filter_xss($text); |
| 113 |
} |
} |
| 114 |
|
|
| 115 |
function description() { |
function description() { |
| 119 |
} |
} |
| 120 |
} |
} |
| 121 |
|
|
| 122 |
|
function set_settings($settings = array()) { |
| 123 |
|
// Load settings from database and set them in "$this->settings" |
| 124 |
|
if (!$this->settings) { |
| 125 |
|
$res = db_query("SELECT * FROM {mlm_setting} WHERE lid = %d", $this->lid); |
| 126 |
|
while ($row = db_fetch_object($res)) { |
| 127 |
|
if (!$value = @unserialize($row->value)) $value = $row->value; |
| 128 |
|
$this->settings[$row->name] = $value; |
| 129 |
|
} |
| 130 |
|
} |
| 131 |
|
if ($settings) { |
| 132 |
|
foreach ($settings as $name => $val) { |
| 133 |
|
$this->settings[check_plain($name)] = filter_xss($value); |
| 134 |
|
} |
| 135 |
|
} |
| 136 |
|
} |
| 137 |
|
|
| 138 |
function path() { |
function path() { |
| 139 |
if ($this->nid) { |
if ($this->nid) { |
| 140 |
return 'node/'. $this->nid; |
return 'node/'. $this->nid; |
| 260 |
} |
} |
| 261 |
} |
} |
| 262 |
|
|
| 263 |
function _edit_form($form = array()) { |
function _edit_form(&$form_state) { |
| 264 |
$edit_form = array(); |
$form = array(); |
| 265 |
$edit_form['lid'] = array('#type' => 'value', '#value' => $this->lid); |
$form['lid'] = array('#type' => 'value', '#value' => $this->lid); |
| 266 |
|
$form['backend'] = array('#type' => 'value', '#value' => $this->backend()); |
| 267 |
|
|
| 268 |
if ($node = $form['#node']) { |
if ($node = $form['#node']) { |
| 269 |
$edit_form['nid'] = array('#type' => 'value', '#value' => $node->nid); |
$form['nid'] = array('#type' => 'value', '#value' => $node->nid); |
| 270 |
} |
} |
| 271 |
|
|
| 272 |
// TODO |
// TODO |
| 273 |
$types = $this->supported_types(); |
$types = $this->supported_types(); |
| 274 |
$edit_form['list_type'] = array( |
$form['list_type'] = array( |
| 275 |
'#type' => 'select', |
'#type' => 'select', |
| 276 |
'#title' => t('List type'), |
'#title' => t('List type'), |
| 277 |
'#options' => $types, |
'#options' => $types, |
| 278 |
'#default_value' => $this->list_type ? $this->list_type : current($types) , |
'#default_value' => $this->list_type ? $this->list_type : current($types) , |
| 279 |
'#access' => count($types) > 1, |
'#access' => count($types) > 1, |
| 280 |
); |
); |
| 281 |
$edit_form['incoming_address'] = array('#type' => 'value', '#value' => ''); |
$form['incoming_address'] = array('#type' => 'value', '#value' => ''); |
| 282 |
|
|
| 283 |
// Call the API's edit_form function to add additional fields. |
// Call the API's edit_form function to add additional fields. |
| 284 |
if (method_exists($this, 'edit_form')) { |
if (method_exists($this, 'edit_form')) { |
| 285 |
$edit_form = array_merge($edit_form, $this->edit_form($form)); |
$form = array_merge($edit_form, $this->edit_form($form)); |
| 286 |
} |
} |
| 287 |
|
|
| 288 |
return $edit_form; |
return $form; |
| 289 |
} |
} |
| 290 |
|
|
| 291 |
//function edit_form(&$form) { |
//function edit_form(&$form) { |