Update PollPlugin Atom input

This commit is contained in:
Brion Vibber 2011-03-11 12:41:11 -08:00
parent a9d589dbdc
commit e1136bacae

View File

@ -203,26 +203,22 @@ class PollPlugin extends MicroAppPlugin
$pollElements = $activity->entry->getElementsByTagNameNS(self::POLL_OBJECT, 'poll'); $pollElements = $activity->entry->getElementsByTagNameNS(self::POLL_OBJECT, 'poll');
$responseElements = $activity->entry->getElementsByTagNameNS(self::POLL_OBJECT, 'response'); $responseElements = $activity->entry->getElementsByTagNameNS(self::POLL_OBJECT, 'response');
if ($pollElements->length) { if ($pollElements->length) {
$data = $pollElements->item(0); $question = '';
$question = $data->getAttribute('question');
$opts = array(); $opts = array();
foreach ($data->attributes as $node) {
$name = $node->nodeName; $data = $pollElements->item(0);
if (substr($name, 0, 6) == 'option') { foreach ($data->getElementsByTagNameNS(self::POLL_OBJECT, 'question') as $node) {
$n = intval(substr($name, 6)); $question = $node->textValue; // ?
if ($n > 0) {
$opts[$n - 1] = $node->nodeValue;
} }
foreach ($data->getElementsByTagNameNS(self::POLL_OBJECT, 'option') as $node) {
$opts[] = $node->textValue;
} }
}
common_log(LOG_DEBUG, "YYY question: $question");
common_log(LOG_DEBUG, "YYY opts: " . var_export($opts, true));
try { try {
$notice = Poll::saveNew($profile, $question, $opts, $options); $notice = Poll::saveNew($profile, $question, $opts, $options);
common_log(LOG_DEBUG, "YYY ok: " . $notice->id); common_log(LOG_DEBUG, "Saved Poll from ActivityStream data ok: notice id " . $notice->id);
return $notice; return $notice;
} catch (Exception $e) { } catch (Exception $e) {
common_log(LOG_DEBUG, "YYY fail: " . $e->getMessage()); common_log(LOG_DEBUG, "Poll save from ActivityStream data failed: " . $e->getMessage());
} }
} else if ($responseElements->length) { } else if ($responseElements->length) {
$data = $responseElements->item(0); $data = $responseElements->item(0);
@ -240,10 +236,10 @@ class PollPlugin extends MicroAppPlugin
} }
try { try {
$notice = Poll_response::saveNew($profile, $poll, $selection, $options); $notice = Poll_response::saveNew($profile, $poll, $selection, $options);
common_log(LOG_DEBUG, "YYY response ok: " . $notice->id); common_log(LOG_DEBUG, "Saved Poll_response ok, notice id: " . $notice->id);
return $notice; return $notice;
} catch (Exception $e) { } catch (Exception $e) {
common_log(LOG_DEBUG, "YYY response fail: " . $e->getMessage()); common_log(LOG_DEBUG, "Poll response save fail: " . $e->getMessage());
} }
} else { } else {
common_log(LOG_DEBUG, "YYY no poll data"); common_log(LOG_DEBUG, "YYY no poll data");