/** * Helper function to avoid repetition for subscription and unsubscription. * @param string $subscribeNode The name of the element describing a * subscribe or unsubscribe request, e.g. 'subscribe' or 'unsubscribe'. * @param array $urls The URLs to subscribe/unsubscribe. * @param bool $digest Whether to set the Superfeedr 'digest' attribute to * true on the subscription tags. */ private function subscribeOrUnsubscribe($subscribeNode, array $urls, $digest) { $this->xmpp->connectAndStartSession($this->timeout); $jid = $this->xmpp->user . '@' . $this->xmpp->server; $id = $this->xmpp->getId(); // Build up the IQ request $dom = new \DOMDocument(); $iq = $dom->createElement('iq'); $iq->setAttribute('type', 'set'); $iq->setAttribute('to', $this->recipient); $iq->setAttribute('from', $jid); $iq->setAttribute('id', $id); $iq = $dom->appendChild($iq); // Create the top-level payload tag $pubsub = $dom->createElement('pubsub'); $pubsub->setAttribute('xmlns', $this->pubSubXmlns); $pubsub->setAttribute('xmlns:superfeedr', $this->superfeedrXmlns); $pubsub = $iq->appendChild($pubsub); // Add subscription requests foreach ($urls as $url) { $subscribe = $dom->createElement($subscribeNode); $subscribe->setAttribute('node', $url); $subscribe->setAttribute('jid', $jid); if ($digest) { $subscribe->setAttribute('superfeedr:digest', 'true'); } $pubsub->appendChild($subscribe); } $xml = $dom->saveXML($iq); // Send and wait for a response $this->xmpp->addIdHandler($id, 'handleResponse', $this); $this->xmpp->send($xml); $this->xmpp->processUntil('handle_subscription', $this->timeout); return $this->isSuccessful(); }