From e1136bacaec721c08b830f52e80069f89b7a45e2 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 11 Mar 2011 12:41:11 -0800 Subject: [PATCH] Update PollPlugin Atom input --- plugins/Poll/PollPlugin.php | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/plugins/Poll/PollPlugin.php b/plugins/Poll/PollPlugin.php index 78357457a6..490f39005f 100644 --- a/plugins/Poll/PollPlugin.php +++ b/plugins/Poll/PollPlugin.php @@ -203,26 +203,22 @@ class PollPlugin extends MicroAppPlugin $pollElements = $activity->entry->getElementsByTagNameNS(self::POLL_OBJECT, 'poll'); $responseElements = $activity->entry->getElementsByTagNameNS(self::POLL_OBJECT, 'response'); if ($pollElements->length) { - $data = $pollElements->item(0); - $question = $data->getAttribute('question'); + $question = ''; $opts = array(); - foreach ($data->attributes as $node) { - $name = $node->nodeName; - if (substr($name, 0, 6) == 'option') { - $n = intval(substr($name, 6)); - if ($n > 0) { - $opts[$n - 1] = $node->nodeValue; - } - } + + $data = $pollElements->item(0); + foreach ($data->getElementsByTagNameNS(self::POLL_OBJECT, 'question') as $node) { + $question = $node->textValue; // ? + } + 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 { $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; } 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) { $data = $responseElements->item(0); @@ -240,10 +236,10 @@ class PollPlugin extends MicroAppPlugin } try { $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; } catch (Exception $e) { - common_log(LOG_DEBUG, "YYY response fail: " . $e->getMessage()); + common_log(LOG_DEBUG, "Poll response save fail: " . $e->getMessage()); } } else { common_log(LOG_DEBUG, "YYY no poll data"); -- 2.39.5