+ /**
+ * Called when generating Atom XML ActivityStreams output from an
+ * ActivityObject belonging to this plugin. Gives the plugin
+ * a chance to add custom output.
+ *
+ * Note that you can only add output of additional XML elements,
+ * not change existing stuff here.
+ *
+ * If output is already handled by the base Activity classes,
+ * you can leave this base implementation as a no-op.
+ *
+ * @param ActivityObject $obj
+ * @param XMLOutputter $out to add elements at end of object
+ */
+ function activityObjectOutputAtom(ActivityObject $obj, XMLOutputter $out)
+ {
+ if (isset($obj->pollQuestion)) {
+ /**
+ * <poll:poll xmlns:poll="http://apinamespace.org/activitystreams/object/poll">
+ * <poll:question>Who wants a poll question?</poll:question>
+ * <poll:option>Option one</poll:option>
+ * <poll:option>Option two</poll:option>
+ * <poll:option>Option three</poll:option>
+ * </poll:poll>
+ */
+ $data = array('xmlns:poll' => self::POLL_OBJECT);
+ $out->elementStart('poll:poll', $data);
+ $out->element('poll:question', array(), $obj->pollQuestion);
+ foreach ($obj->pollOptions as $opt) {
+ $out->element('poll:option', array(), $opt);
+ }
+ $out->elementEnd('poll:poll');
+ }
+ if (isset($obj->pollSelection)) {
+ /**
+ * <poll:response xmlns:poll="http://apinamespace.org/activitystreams/object/poll">
+ * poll="http://..../poll/...."
+ * selection="3" />
+ */
+ $data = array('xmlns:poll' => self::POLL_OBJECT,
+ 'poll' => $obj->pollUri,
+ 'selection' => $obj->pollSelection);
+ $out->element('poll:response', $data, '');
+ }
+ }
+
+ /**
+ * Called when generating JSON ActivityStreams output from an
+ * ActivityObject belonging to this plugin. Gives the plugin
+ * a chance to add custom output.
+ *
+ * Modify the array contents to your heart's content, and it'll
+ * all get serialized out as JSON.
+ *
+ * If output is already handled by the base Activity classes,
+ * you can leave this base implementation as a no-op.
+ *
+ * @param ActivityObject $obj
+ * @param array &$out JSON-targeted array which can be modified
+ */
+ public function activityObjectOutputJson(ActivityObject $obj, array &$out)
+ {
+ common_log(LOG_DEBUG, 'QQQ: ' . var_export($obj, true));
+ if (isset($obj->pollQuestion)) {
+ /**
+ * "poll": {
+ * "question": "Who wants a poll question?",
+ * "options": [
+ * "Option 1",
+ * "Option 2",
+ * "Option 3"
+ * ]
+ * }
+ */
+ $data = array('question' => $obj->pollQuestion,
+ 'options' => array());
+ foreach ($obj->pollOptions as $opt) {
+ $data['options'][] = $opt;
+ }
+ $out['poll'] = $data;
+ }
+ if (isset($obj->pollSelection)) {
+ /**
+ * "pollResponse": {
+ * "poll": "http://..../poll/....",
+ * "selection": 3
+ * }
+ */
+ $data = array('poll' => $obj->pollUri,
+ 'selection' => $obj->pollSelection);
+ $out['pollResponse'] = $data;
+ }
+ }
+
+