Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

improved setOption() function and now parses results

  • Loading branch information...
commit 817cf45c48147c9d1f3b1367bc06f415850ab76d 1 parent 28956b5
@hm2k hm2k authored
Showing with 37 additions and 20 deletions.
  1. +37 −20 Services/Mailman.php
View
57 Services/Mailman.php
@@ -428,7 +428,7 @@ public function setDigest($email,$digest = 1)
}
/**
- * Set options
+ * Set an option
*
* @param string $email Valid email address of a member
*
@@ -436,7 +436,7 @@ public function setDigest($email,$digest = 1)
*
* @param string $value A value for the given option
*
- * @return string Returns unparsed HTML
+ * @return string Returns resulting value, if successful.
*
* @throws {@link Services_Mailman_Exception}
*/
@@ -449,69 +449,86 @@ public function setOption($email, $option, $value)
);
}
$path = '/options/' . $this->list . '/' . $email;
- $query = array( 'options-submit' => 'Submit+My+Changes',
- 'adminpw' => $this->adminPW);
- $options = array( 'new-address',
- 'fullname',
- 'newpw',
- 'disablemail',
- 'digest','mime',
- 'dontreceive',
- 'ackposts',
- 'remind',
- 'conceal',
- 'rcvtopic',
- 'nodupes');
+ $query = array('password' => $this->adminPW);
if ($option == 'new-address') {
$query['new-address'] = $value;
$query['confirm-address'] = $value;
+ $query['change-of-address'] = 'Change+My+Address+and+Name';
+ $xp="//input[@name='$option']/@value";
}
elseif ($option == 'fullname') {
$query['fullname'] = $value;
+ $query['change-of-address'] = 'Change+My+Address+and+Name';
+ $xp="//input[@name='$option']/@value";
}
elseif ($option == 'newpw') {
$query['newpw'] = $value;
$query['confpw'] = $value;
+ $query['changepw'] = 'Change+My+Password';
+ $xp="//input[@name='$option']/@value";
}
elseif ($option == 'disablemail') {
$query['disablemail'] = $value;
+ $query['options-submit'] = 'Submit+My+Changes';
+ $xp="//input[@name='$option' and @checked='checked']/@value";
}
elseif ($option == 'digest') {
$query['digest'] = $value;
+ $query['options-submit'] = 'Submit+My+Changes';
+ $xp="//input[@name='$option' and @checked='checked']/@value";
}
elseif ($option == 'mime') {
$query['mime'] = $value;
+ $query['options-submit'] = 'Submit+My+Changes';
+ $xp="//input[@name='$option' and @checked='checked']/@value";
}
elseif ($option == 'dontreceive') {
$query['dontreceive'] = $value;
+ $query['options-submit'] = 'Submit+My+Changes';
+ $xp="//input[@name='$option' and @checked='checked']/@value";
}
elseif ($option == 'ackposts') {
$query['ackposts'] = $value;
+ $query['options-submit'] = 'Submit+My+Changes';
+ $xp="//input[@name='$option' and @checked='checked']/@value";
}
elseif ($option == 'remind') {
$query['remind'] = $value;
+ $query['options-submit'] = 'Submit+My+Changes';
+ $xp="//input[@name='$option' and @checked='checked']/@value";
}
elseif ($option == 'conceal') {
$query['conceal'] = $value;
+ $query['options-submit'] = 'Submit+My+Changes';
+ $xp="//input[@name='$option' and @checked='checked']/@value";
}
elseif ($option == 'rcvtopic') {
$query['rcvtopic'] = $value;
+ $query['options-submit'] = 'Submit+My+Changes';
+ $xp="//input[@name='$option' and @checked='checked']/@value";
}
elseif ($option == 'nodupes') {
$query['nodupes'] = $value;
+ $query['options-submit'] = 'Submit+My+Changes';
+ $xp="//input[@name='$option' and @checked='checked']/@value";
}
else {
throw new Services_Mailman_Exception('Invalid option.');
}
-
$query = http_build_query($query, '', '&');
$url = dirname($this->adminURL) . $path . '?' . $query;
$html = $this->fetch($url);
- if (!$html) {
- throw new Services_Mailman_Exception('Unable to fetch HTML.');
+ libxml_use_internal_errors(true);
+ $doc = new DOMDocument();
+ $doc->preserveWhiteSpace = false;
+ $doc->loadHTML($html);
+ $xpath = new DOMXPath($doc);
+ $query = $xpath->query($xp);
+ libxml_clear_errors();
+ if ($query->item(0)) {
+ return $query->item(0)->nodeValue;
}
- //TODO:parse html
- return $html;
+ throw new Services_Mailman_Exception('Failed to parse HTML.');
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.