Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
improved setOption() function and now parses results
  • Loading branch information
hm2k committed Jan 30, 2012
1 parent 28956b5 commit 817cf45
Showing 1 changed file with 37 additions and 20 deletions.
57 changes: 37 additions & 20 deletions Services/Mailman.php
Expand Up @@ -428,15 +428,15 @@ public function setDigest($email,$digest = 1)
} }


/** /**
* Set options * Set an option
* *
* @param string $email Valid email address of a member * @param string $email Valid email address of a member
* *
* @param string $option A valid option * @param string $option A valid option
* *
* @param string $value A value for the given option * @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} * @throws {@link Services_Mailman_Exception}
*/ */
Expand All @@ -449,69 +449,86 @@ public function setOption($email, $option, $value)
); );
} }
$path = '/options/' . $this->list . '/' . $email; $path = '/options/' . $this->list . '/' . $email;
$query = array( 'options-submit' => 'Submit+My+Changes', $query = array('password' => $this->adminPW);
'adminpw' => $this->adminPW);
$options = array( 'new-address',
'fullname',
'newpw',
'disablemail',
'digest','mime',
'dontreceive',
'ackposts',
'remind',
'conceal',
'rcvtopic',
'nodupes');
if ($option == 'new-address') { if ($option == 'new-address') {
$query['new-address'] = $value; $query['new-address'] = $value;
$query['confirm-address'] = $value; $query['confirm-address'] = $value;
$query['change-of-address'] = 'Change+My+Address+and+Name';
$xp="//input[@name='$option']/@value";
} }
elseif ($option == 'fullname') { elseif ($option == 'fullname') {
$query['fullname'] = $value; $query['fullname'] = $value;
$query['change-of-address'] = 'Change+My+Address+and+Name';
$xp="//input[@name='$option']/@value";
} }
elseif ($option == 'newpw') { elseif ($option == 'newpw') {
$query['newpw'] = $value; $query['newpw'] = $value;
$query['confpw'] = $value; $query['confpw'] = $value;
$query['changepw'] = 'Change+My+Password';
$xp="//input[@name='$option']/@value";
} }
elseif ($option == 'disablemail') { elseif ($option == 'disablemail') {
$query['disablemail'] = $value; $query['disablemail'] = $value;
$query['options-submit'] = 'Submit+My+Changes';
$xp="//input[@name='$option' and @checked='checked']/@value";
} }
elseif ($option == 'digest') { elseif ($option == 'digest') {
$query['digest'] = $value; $query['digest'] = $value;
$query['options-submit'] = 'Submit+My+Changes';
$xp="//input[@name='$option' and @checked='checked']/@value";
} }
elseif ($option == 'mime') { elseif ($option == 'mime') {
$query['mime'] = $value; $query['mime'] = $value;
$query['options-submit'] = 'Submit+My+Changes';
$xp="//input[@name='$option' and @checked='checked']/@value";
} }
elseif ($option == 'dontreceive') { elseif ($option == 'dontreceive') {
$query['dontreceive'] = $value; $query['dontreceive'] = $value;
$query['options-submit'] = 'Submit+My+Changes';
$xp="//input[@name='$option' and @checked='checked']/@value";
} }
elseif ($option == 'ackposts') { elseif ($option == 'ackposts') {
$query['ackposts'] = $value; $query['ackposts'] = $value;
$query['options-submit'] = 'Submit+My+Changes';
$xp="//input[@name='$option' and @checked='checked']/@value";
} }
elseif ($option == 'remind') { elseif ($option == 'remind') {
$query['remind'] = $value; $query['remind'] = $value;
$query['options-submit'] = 'Submit+My+Changes';
$xp="//input[@name='$option' and @checked='checked']/@value";
} }
elseif ($option == 'conceal') { elseif ($option == 'conceal') {
$query['conceal'] = $value; $query['conceal'] = $value;
$query['options-submit'] = 'Submit+My+Changes';
$xp="//input[@name='$option' and @checked='checked']/@value";
} }
elseif ($option == 'rcvtopic') { elseif ($option == 'rcvtopic') {
$query['rcvtopic'] = $value; $query['rcvtopic'] = $value;
$query['options-submit'] = 'Submit+My+Changes';
$xp="//input[@name='$option' and @checked='checked']/@value";
} }
elseif ($option == 'nodupes') { elseif ($option == 'nodupes') {
$query['nodupes'] = $value; $query['nodupes'] = $value;
$query['options-submit'] = 'Submit+My+Changes';
$xp="//input[@name='$option' and @checked='checked']/@value";
} }
else { else {
throw new Services_Mailman_Exception('Invalid option.'); throw new Services_Mailman_Exception('Invalid option.');
} }

$query = http_build_query($query, '', '&'); $query = http_build_query($query, '', '&');
$url = dirname($this->adminURL) . $path . '?' . $query; $url = dirname($this->adminURL) . $path . '?' . $query;
$html = $this->fetch($url); $html = $this->fetch($url);
if (!$html) { libxml_use_internal_errors(true);
throw new Services_Mailman_Exception('Unable to fetch HTML.'); $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 throw new Services_Mailman_Exception('Failed to parse HTML.');
return $html;
} }


/** /**
Expand Down

0 comments on commit 817cf45

Please sign in to comment.