/** * test xml generation for IPhone * * birthday must have 12 hours added */ public function testAppendXmlData() { $imp = new DOMImplementation(); $dtd = $imp->createDocumentType('AirSync', "-//AIRSYNC//DTD AirSync//EN", "http://www.microsoft.com/"); $testDoc = $imp->createDocument('uri:AirSync', 'Sync', $dtd); $testDoc->formatOutput = true; $testDoc->encoding = 'utf-8'; $appData = $testDoc->documentElement->appendChild($testDoc->createElementNS('uri:AirSync', 'ApplicationData')); $email = new Syncroton_Model_FileReference(array('contentType' => 'text/plain', 'data' => 'Lars')); $email->appendXML($appData, $this->_testDevice); #echo $testDoc->saveXML(); $xpath = new DomXPath($testDoc); $xpath->registerNamespace('AirSync', 'uri:AirSync'); $xpath->registerNamespace('AirSyncBase', 'uri:AirSyncBase'); $xpath->registerNamespace('Email', 'uri:Email'); $xpath->registerNamespace('Email2', 'uri:Email2'); $nodes = $xpath->query('//AirSync:Sync/AirSync:ApplicationData/AirSyncBase:ContentType'); $this->assertEquals(1, $nodes->length, $testDoc->saveXML()); $this->assertEquals('text/plain', $nodes->item(0)->nodeValue, $testDoc->saveXML()); $nodes = $xpath->query('//AirSync:Sync/AirSync:ApplicationData/ItemOperations:Data'); $this->assertEquals(1, $nodes->length, $testDoc->saveXML()); $this->assertEquals('TGFycw==', $nodes->item(0)->nodeValue, $testDoc->saveXML()); // try to encode XML until we have wbxml tests $outputStream = fopen("php://temp", 'r+'); $encoder = new Syncroton_Wbxml_Encoder($outputStream, 'UTF-8', 3); $encoder->encode($testDoc); }
public function testExpandProperty() { $list = Tinebase_Group::getInstance()->getGroupById(Tinebase_Core::getUser()->accountPrimaryGroup); $body = '<?xml version="1.0" encoding="UTF-8"?> <A:expand-property xmlns:A="DAV:"> <A:property name="expanded-group-member-set" namespace="http://calendarserver.org/ns/"> <A:property name="last-name" namespace="http://calendarserver.org/ns/"/> <A:property name="principal-URL" namespace="DAV:"/> <A:property name="calendar-user-type" namespace="urn:ietf:params:xml:ns:caldav"/> <A:property name="calendar-user-address-set" namespace="urn:ietf:params:xml:ns:caldav"/> <A:property name="first-name" namespace="http://calendarserver.org/ns/"/> <A:property name="record-type" namespace="http://calendarserver.org/ns/"/> <A:property name="displayname" namespace="DAV:"/> </A:property> </A:expand-property>'; $request = new Sabre\HTTP\Request(array('REQUEST_METHOD' => 'REPORT', 'REQUEST_URI' => '/principals/groups/' . $list->list_id . '/')); $request->setBody($body); $this->server->httpRequest = $request; $this->server->exec(); $responseDoc = new DOMDocument(); $responseDoc->loadXML($this->response->body); #$responseDoc->formatOutput = true; echo $responseDoc->saveXML(); $xpath = new DomXPath($responseDoc); $xpath->registerNamespace('cal', 'urn:ietf:params:xml:ns:caldav'); $xpath->registerNamespace('cs', 'http://calendarserver.org/ns/'); $nodes = $xpath->query('///cs:expanded-group-member-set/d:response/d:href[text()="/principals/groups/' . $list->list_id . '/"]'); $this->assertEquals(1, $nodes->length, 'group itself (not shown by client) is missing'); $nodes = $xpath->query('///cs:expanded-group-member-set/d:response/d:href[text()="/principals/intelligroups/' . $list->list_id . '/"]'); $this->assertEquals(1, $nodes->length, 'intelligroup (to keep group itself) is missing'); $nodes = $xpath->query('///cs:expanded-group-member-set/d:response/d:href[text()="/principals/users/' . Tinebase_Core::getUser()->contact_id . '/"]'); $this->assertEquals(1, $nodes->length, 'user is missing'); }
/** * test testGetProperties method */ public function testGetProperties() { $body = '<?xml version="1.0" encoding="utf-8"?> <propfind xmlns="DAV:"> <prop> <default-alarm-vevent-date xmlns="urn:ietf:params:xml:ns:caldav"/> <default-alarm-vevent-datetime xmlns="urn:ietf:params:xml:ns:caldav"/> <default-alarm-vtodo-date xmlns="urn:ietf:params:xml:ns:caldav"/> <default-alarm-vtodo-datetime xmlns="urn:ietf:params:xml:ns:caldav"/> </prop> </propfind>'; $request = new Sabre\HTTP\Request(array('REQUEST_METHOD' => 'PROPFIND', 'REQUEST_URI' => '/calendars/' . Tinebase_Core::getUser()->contact_id, 'HTTP_DEPTH' => '0')); $request->setBody($body); $this->server->httpRequest = $request; $this->server->exec(); //var_dump($this->response->body); $this->assertEquals('HTTP/1.1 207 Multi-Status', $this->response->status); $responseDoc = new DOMDocument(); $responseDoc->loadXML($this->response->body); //$responseDoc->formatOutput = true; echo $responseDoc->saveXML(); $xpath = new DomXPath($responseDoc); $xpath->registerNamespace('cal', 'urn:ietf:params:xml:ns:caldav'); $nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/cal:default-alarm-vevent-datetime'); $this->assertEquals(1, $nodes->length, $responseDoc->saveXML()); $this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML()); $nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/cal:default-alarm-vevent-date'); $this->assertEquals(1, $nodes->length, $responseDoc->saveXML()); $this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML()); $nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/cal:default-alarm-vtodo-datetime'); $this->assertEquals(1, $nodes->length, $responseDoc->saveXML()); $this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML()); $nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/cal:default-alarm-vtodo-date'); $this->assertEquals(1, $nodes->length, $responseDoc->saveXML()); $this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML()); }
/** * test xml generation for IPhone */ public function testSearch() { $doc = new DOMDocument(); $doc->loadXML('<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/"> <Search xmlns="uri:Search"> <Store> <Name>GAL</Name> <Query>Lars</Query> <Options> <Range>0-3</Range> <RebuildResults/> <DeepTraversal/> </Options> </Store> </Search> '); $search = new Syncroton_Command_Search($doc, $this->_device, null); $search->handle(); $responseDoc = $search->getResponse(); #$responseDoc->formatOutput = true; echo $responseDoc->saveXML(); $xpath = new DomXPath($responseDoc); $xpath->registerNamespace('Search', 'uri:Search'); $nodes = $xpath->query('//Search:Search/Search:Status'); $this->assertEquals(1, $nodes->length, $responseDoc->saveXML()); $this->assertEquals(Syncroton_Command_Search::STATUS_SUCCESS, $nodes->item(0)->nodeValue, $responseDoc->saveXML()); $nodes = $xpath->query('//Search:Search/Search:Response/Search:Store/Search:Total'); $this->assertEquals(1, $nodes->length, $responseDoc->saveXML()); $this->assertEquals(5, $nodes->item(0)->nodeValue, $responseDoc->saveXML()); $nodes = $xpath->query('//Search:Search/Search:Response/Search:Store/Search:Result'); $this->assertEquals(4, $nodes->length, $responseDoc->saveXML()); #$this->assertEquals(Syncroton_Command_Search::STATUS_SUCCESS, $nodes->item(0)->nodeValue, $responseDoc->saveXML()); }
public function ovfImport($url, $xpath = false) { $this->url = $url; $dom = new DomDocument(); $loaded = $dom->load($url); if (!$loaded) { return $loaded; } $xpath = new DomXPath($dom); // register the namespace $xpath->registerNamespace('envl', 'http://schemas.dmtf.org/ovf/envelope/1'); $vs_nodes = $xpath->query('//envl:VirtualSystem'); // selects all name element $refs_nodes = $xpath->query('//envl:References'); // selects all name element $disk_nodes = $xpath->query('//envl:DiskSection'); // selects all name element $refs_nodes_0 = $refs_nodes->item(0); $disk_nodes_0 = $disk_nodes->item(0); $vs_nodes_0 = $vs_nodes->item(0); if ($refs_nodes_0 && $disk_nodes_0 && $vs_nodes_0) { $this->buildReferences($refs_nodes_0); $this->buildDiskSection($disk_nodes_0); $this->buildVirtualSystem($vs_nodes_0); return true; } else { return false; } }
/** * test processing of meeting reponse */ public function testMeetingResponse() { $doc = new DOMDocument(); $doc->loadXML('<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/"> <MeetingResponse xmlns="uri:MeetingResponse" xmlns:Search="uri:Search"> <Request> <UserResponse>2</UserResponse> <CollectionId>17</CollectionId> <RequestId>f0c79775b6b44be446f91187e24566aa1c5d06ab</RequestId> </Request> <Request> <UserResponse>2</UserResponse> <Search:LongId>1129::64c542b3b4bf624630a1fbbc30d2375a3729b734</Search:LongId> </Request> </MeetingResponse> '); $meetingResponse = new Syncroton_Command_MeetingResponse($doc, $this->_device, null); $meetingResponse->handle(); $responseDoc = $meetingResponse->getResponse(); #$responseDoc->formatOutput = true; echo $responseDoc->saveXML(); $xpath = new DomXPath($responseDoc); $xpath->registerNamespace('MeetingResponse', 'uri:MeetingResponse'); $nodes = $xpath->query('//MeetingResponse:MeetingResponse/MeetingResponse:Result'); $this->assertEquals(2, $nodes->length, $responseDoc->saveXML()); #$nodes = $xpath->query('//Search:Search/Search:Response/Search:Store/Search:Total'); #$this->assertEquals(1, $nodes->length, $responseDoc->saveXML()); #$this->assertEquals(5, $nodes->item(0)->nodeValue, $responseDoc->saveXML()); #$nodes = $xpath->query('//Search:Search/Search:Response/Search:Store/Search:Result'); #$this->assertEquals(4, $nodes->length, $responseDoc->saveXML()); #$this->assertEquals(Syncroton_Command_Search::STATUS_SUCCESS, $nodes->item(0)->nodeValue, $responseDoc->saveXML()); }
/** * test testGetProperties method */ public function testGetProperties() { $body = '<?xml version="1.0" encoding="utf-8"?> <propfind xmlns="DAV:"> <prop> <getlastmodified xmlns="DAV:"/> <getcontentlength xmlns="DAV:"/> <resourcetype xmlns="DAV:"/> <getetag xmlns="DAV:"/> <id xmlns="http://owncloud.org/ns"/> </prop> </propfind>'; $request = new Sabre\HTTP\Request(array('REQUEST_METHOD' => 'PROPFIND', 'REQUEST_URI' => '/remote.php/webdav/' . Tinebase_Core::getUser()->accountDisplayName, 'HTTP_DEPTH' => '0')); $request->setBody($body); $this->server->httpRequest = $request; $this->server->exec(); //var_dump($this->response->body); $this->assertEquals('HTTP/1.1 207 Multi-Status', $this->response->status); $responseDoc = new DOMDocument(); $responseDoc->loadXML($this->response->body); //$responseDoc->formatOutput = true; echo $responseDoc->saveXML(); $xpath = new DomXPath($responseDoc); $xpath->registerNamespace('owncloud', 'http://owncloud.org/ns'); $nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/owncloud:id'); $this->assertEquals(1, $nodes->length, $responseDoc->saveXML()); $this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML()); }
/** * process the incoming data */ public function handle() { $xpath = new DomXPath($this->requestBody); $xpath->registerNamespace('2006', 'http://schemas.microsoft.com/exchange/autodiscover/mobilesync/requestschema/2006'); $nodes = $xpath->query('//2006:Autodiscover/2006:Request/2006:EMailAddress'); if ($nodes->length === 0) { throw new Syncroton_Exception(); } $this->emailAddress = $nodes->item(0)->nodeValue; }
public function testGetProperties() { $body = '<?xml version="1.0" encoding="UTF-8"?> <A:propfind xmlns:A="DAV:"> <A:prop> <B:dropbox-home-URL xmlns:B="http://calendarserver.org/ns/"/> </A:prop> </A:propfind>'; $request = new Sabre\HTTP\Request(array('REQUEST_METHOD' => 'PROPFIND', 'REQUEST_URI' => '/' . Tinebase_WebDav_PrincipalBackend::PREFIX_USERS . '/' . Tinebase_Core::getUser()->contact_id)); $request->setBody($body); $this->server->httpRequest = $request; $this->server->exec(); $responseDoc = new DOMDocument(); $responseDoc->loadXML($this->response->body); //$responseDoc->formatOutput = true; echo $responseDoc->saveXML(); $xpath = new DomXPath($responseDoc); $xpath->registerNamespace('cal', 'urn:ietf:params:xml:ns:caldav'); $xpath->registerNamespace('cs', 'http://calendarserver.org/ns/'); $nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/cs:dropbox-home-URL/d:href'); $dropboxUrl = $nodes->item(0)->nodeValue; $this->assertTrue(!!strstr($dropboxUrl, 'dropbox'), $dropboxUrl); }
/** * validate xml generation for all devices except IPhone */ public function testAppendXmlPalm() { $imp = new DOMImplementation(); $dtd = $imp->createDocumentType('AirSync', "-//AIRSYNC//DTD AirSync//EN", "http://www.microsoft.com/"); $testDoc = $imp->createDocument('uri:AirSync', 'Sync', $dtd); $testDoc->formatOutput = true; $testDoc->encoding = 'utf-8'; $testDoc->documentElement->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:Contacts', 'uri:Contacts'); $testNode = $testDoc->documentElement->appendChild($testDoc->createElementNS('uri:AirSync', 'ApplicationData')); $device = $this->_deviceBackend->create(Syncope_Backend_DeviceTests::getTestDevice(Syncope_Model_Device::TYPE_WEBOS)); $dataController = Syncope_Data_Factory::factory(Syncope_Data_Factory::CLASS_CONTACTS, $device, new DateTime(null, new DateTimeZone('UTC'))); $dataController->appendXML($testNode, array('collectionId' => 'addressbookFolderId'), 'contact1'); #echo $testDoc->saveXML(); $xpath = new DomXPath($testDoc); $xpath->registerNamespace('AirSync', 'uri:AirSync'); $xpath->registerNamespace('Contacts', 'uri:Contacts'); $nodes = $xpath->query('//AirSync:Sync/AirSync:ApplicationData/Contacts:FirstName'); $this->assertEquals(1, $nodes->length, $testDoc->saveXML()); $this->assertEquals('Lars', $nodes->item(0)->nodeValue, $testDoc->saveXML()); // offset birthday 12 hours + user TZ and namespace === uri:Contacts #$this->assertEquals(Tinebase_Translation::getCountryNameByRegionCode('DE'), @$testDoc->getElementsByTagNameNS('uri:Contacts', 'BusinessCountry')->item(0)->nodeValue, $testDoc->saveXML()); #$this->assertEquals('1975-01-02T16:00:00.000Z', @$testDoc->getElementsByTagNameNS('uri:Contacts', 'Birthday')->item(0)->nodeValue, $testDoc->saveXML()); }
static function loadXml($xml, $nsPrefix = 'd') { $dom = new \DOMDocument(); @$dom->loadXML($xml); $xpath = new \DomXPath($dom); $rootNamespace = $dom->lookupNamespaceUri($dom->namespaceURI); if ($rootNamespace) { if ($dom->documentElement->getAttribute('xmlns:d')) { Debug::toss('Namespace prefix "' . $nsPrefix . '" taken'); } $xpath->registerNamespace($nsPrefix, $rootNamespace); $nsPrefix .= ':'; } else { $nsPrefix = ''; } return array($dom, $xpath, $nsPrefix); }
/** * test xml generation for IPhone */ public function testSetDeviceInformation() { // delete folder created above $doc = new DOMDocument(); $doc->loadXML('<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/"> <Settings xmlns="uri:Settings"><DeviceInformation><Set><Model>iPhone</Model><IMEI>086465r87697</IMEI></Set></DeviceInformation></Settings>'); $folderDelete = new Syncroton_Command_Settings($doc, $this->_device, null); $folderDelete->handle(); $responseDoc = $folderDelete->getResponse(); #$responseDoc->formatOutput = true; echo $responseDoc->saveXML(); $xpath = new DomXPath($responseDoc); $xpath->registerNamespace('Settings', 'uri:Settings'); $nodes = $xpath->query('//Settings:Settings/Settings:Status'); $this->assertEquals(1, $nodes->length, $responseDoc->saveXML()); $this->assertEquals(Syncroton_Command_Settings::STATUS_SUCCESS, $nodes->item(0)->nodeValue, $responseDoc->saveXML()); $updatedDevice = Syncroton_Registry::getDeviceBackend()->get($this->_device->id); $this->assertEquals('086465r87697', $updatedDevice->imei); }
/** * test xml generation for IPhone */ public function testDeleteFolder() { // do initial sync first $doc = new DOMDocument(); $doc->loadXML('<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/"> <FolderSync xmlns="uri:FolderHierarchy"><SyncKey>0</SyncKey></FolderSync>'); $folderSync = new Syncope_Command_FolderSync($doc, $this->_device, null); $folderSync->handle(); $responseDoc = $folderSync->getResponse(); $doc = new DOMDocument(); $doc->loadXML('<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/"> <FolderCreate xmlns="uri:FolderHierarchy"><SyncKey>1</SyncKey><ParentId/><DisplayName>Test Folder</DisplayName><Type>14</Type></FolderCreate>'); $folderCreate = new Syncope_Command_FolderCreate($doc, $this->_device, null); $folderCreate->handle(); $responseDoc = $folderCreate->getResponse(); #$responseDoc->formatOutput = true; echo $responseDoc->saveXML(); $xpath = new DomXPath($responseDoc); $xpath->registerNamespace('FolderHierarchy', 'uri:FolderHierarchy'); $nodes = $xpath->query('//FolderHierarchy:FolderCreate/FolderHierarchy:ServerId'); $newFolderId = $nodes->item(0)->nodeValue; // delete folder created above $doc = new DOMDocument(); $doc->loadXML('<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/"> <FolderDelete xmlns="uri:FolderHierarchy"><SyncKey>2</SyncKey><ServerId>' . $newFolderId . '</ServerId></FolderDelete>'); $folderDelete = new Syncope_Command_FolderDelete($doc, $this->_device, null); $folderDelete->handle(); $responseDoc = $folderDelete->getResponse(); #$responseDoc->formatOutput = true; echo $responseDoc->saveXML(); $xpath = new DomXPath($responseDoc); $xpath->registerNamespace('FolderHierarchy', 'uri:FolderHierarchy'); $nodes = $xpath->query('//FolderHierarchy:FolderDelete/FolderHierarchy:Status'); $this->assertEquals(1, $nodes->length, $responseDoc->saveXML()); $this->assertEquals(Syncope_Command_FolderSync::STATUS_SUCCESS, $nodes->item(0)->nodeValue, $responseDoc->saveXML()); $nodes = $xpath->query('//FolderHierarchy:FolderDelete/FolderHierarchy:SyncKey'); $this->assertEquals(1, $nodes->length, $responseDoc->saveXML()); $this->assertEquals(3, $nodes->item(0)->nodeValue, $responseDoc->saveXML()); $this->assertArrayNotHasKey($newFolderId, Syncope_Data_Contacts::$folders); }
/** * test xml generation for IPhone * * birthday must have 12 hours added */ public function testAppendXmlData() { $imp = new DOMImplementation(); $dtd = $imp->createDocumentType('AirSync', "-//AIRSYNC//DTD AirSync//EN", "http://www.microsoft.com/"); $testDoc = $imp->createDocument('uri:Provision', 'Provision', $dtd); $testDoc->formatOutput = true; $testDoc->encoding = 'utf-8'; $provDoc = $testDoc->documentElement->appendChild($testDoc->createElementNS('uri:Provision', 'EASProvisionDoc')); $provData = new Syncroton_Model_Policy(array('id' => 'skdjhfkjsfd', 'devicePasswordEnabled' => 1)); $provData->appendXML($provDoc, $this->_testDevice); #echo $testDoc->saveXML(); $xpath = new DomXPath($testDoc); $xpath->registerNamespace('Provision', 'uri:Provision'); $nodes = $xpath->query('//Provision:Provision/Provision:EASProvisionDoc/Provision:DevicePasswordEnabled'); $this->assertEquals(1, $nodes->length, $testDoc->saveXML()); $this->assertEquals('1', $nodes->item(0)->nodeValue, $testDoc->saveXML()); // try to encode XML until we have wbxml tests $outputStream = fopen("php://temp", 'r+'); $encoder = new Syncroton_Wbxml_Encoder($outputStream, 'UTF-8', 3); $encoder->encode($testDoc); }
/** * test testGetProperties method */ public function testGetProperties() { $body = '<?xml version="1.0" encoding="utf-8"?> <A:calendarserver-principal-search xmlns:A="http://calendarserver.org/ns/" context="attendee"> <A:search-token>Administrators</A:search-token> <A:limit> <A:nresults>50</A:nresults> </A:limit> <B:prop xmlns:B="DAV:"> <C:calendar-user-address-set xmlns:C="urn:ietf:params:xml:ns:caldav"/> <C:calendar-user-type xmlns:C="urn:ietf:params:xml:ns:caldav"/> <A:record-type/> <A:first-name/> <A:last-name/> </B:prop> </A:calendarserver-principal-search>'; $request = new Sabre\HTTP\Request(array('REQUEST_METHOD' => 'REPORT', 'REQUEST_URI' => '/principals')); $request->setBody($body); $this->server->httpRequest = $request; $this->server->exec(); //var_dump($this->response->body); $this->assertEquals('HTTP/1.1 207 Multi-Status', $this->response->status); $responseDoc = new DOMDocument(); $responseDoc->loadXML($this->response->body); #$responseDoc->formatOutput = true; echo $responseDoc->saveXML(); $xpath = new DomXPath($responseDoc); $xpath->registerNamespace('cal', 'urn:ietf:params:xml:ns:caldav'); $nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/cal:calendar-user-address-set'); $this->assertEquals(1, $nodes->length, $responseDoc->saveXML()); $this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML()); $nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/cal:calendar-user-type'); $this->assertEquals(1, $nodes->length, $responseDoc->saveXML()); $this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML()); #$nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/cal:default-alarm-vtodo-datetime'); #$this->assertEquals(1, $nodes->length, $responseDoc->saveXML()); #$this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML()); #$nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/cal:default-alarm-vtodo-date'); #$this->assertEquals(1, $nodes->length, $responseDoc->saveXML()); #$this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML()); }
function poco_last_updated($profile, $force = false) { $gcontacts = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($profile))); if ($gcontacts[0]["created"] == "0000-00-00 00:00:00") { q("UPDATE `gcontact` SET `created` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc(normalise_link($profile))); } if ($gcontacts[0]["server_url"] != "") { $server_url = $gcontacts[0]["server_url"]; } else { $server_url = poco_detect_server($profile); } if ($server_url != "") { if (!poco_check_server($server_url, $gcontacts[0]["network"], $force)) { if ($force) { q("UPDATE `gcontact` SET `last_failure` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc(normalise_link($profile))); } return false; } q("UPDATE `gcontact` SET `server_url` = '%s' WHERE `nurl` = '%s'", dbesc($server_url), dbesc(normalise_link($profile))); } if (in_array($gcontacts[0]["network"], array("", NETWORK_FEED))) { $server = q("SELECT `network` FROM `gserver` WHERE `nurl` = '%s' AND `network` != ''", dbesc(normalise_link($server_url))); if ($server) { q("UPDATE `gcontact` SET `network` = '%s' WHERE `nurl` = '%s'", dbesc($server[0]["network"]), dbesc(normalise_link($profile))); } else { return; } } // noscrape is really fast so we don't cache the call. if ($gcontacts[0]["server_url"] != "" and $gcontacts[0]["nick"] != "") { // Use noscrape if possible $server = q("SELECT `noscrape` FROM `gserver` WHERE `nurl` = '%s' AND `noscrape` != ''", dbesc(normalise_link($gcontacts[0]["server_url"]))); if ($server) { $noscraperet = z_fetch_url($server[0]["noscrape"] . "/" . $gcontacts[0]["nick"]); if ($noscraperet["success"] and $noscraperet["body"] != "") { $noscrape = json_decode($noscraperet["body"], true); if ($noscrape["fn"] != "" and $noscrape["fn"] != $gcontacts[0]["name"]) { q("UPDATE `gcontact` SET `name` = '%s' WHERE `nurl` = '%s'", dbesc($noscrape["fn"]), dbesc(normalise_link($profile))); } if ($noscrape["photo"] != "" and $noscrape["photo"] != $gcontacts[0]["photo"]) { q("UPDATE `gcontact` SET `photo` = '%s' WHERE `nurl` = '%s'", dbesc($noscrape["photo"]), dbesc(normalise_link($profile))); } if ($noscrape["updated"] != "" and $noscrape["updated"] != $gcontacts[0]["updated"]) { q("UPDATE `gcontact` SET `updated` = '%s' WHERE `nurl` = '%s'", dbesc($noscrape["updated"]), dbesc(normalise_link($profile))); } if ($noscrape["gender"] != "" and $noscrape["gender"] != $gcontacts[0]["gender"]) { q("UPDATE `gcontact` SET `gender` = '%s' WHERE `nurl` = '%s'", dbesc($noscrape["gender"]), dbesc(normalise_link($profile))); } if ($noscrape["pdesc"] != "" and $noscrape["pdesc"] != $gcontacts[0]["about"]) { q("UPDATE `gcontact` SET `about` = '%s' WHERE `nurl` = '%s'", dbesc($noscrape["pdesc"]), dbesc(normalise_link($profile))); } if ($noscrape["about"] != "" and $noscrape["about"] != $gcontacts[0]["about"]) { q("UPDATE `gcontact` SET `about` = '%s' WHERE `nurl` = '%s'", dbesc($noscrape["about"]), dbesc(normalise_link($profile))); } if (isset($noscrape["comm"]) and $noscrape["comm"] != $gcontacts[0]["community"]) { q("UPDATE `gcontact` SET `community` = %d WHERE `nurl` = '%s'", intval($noscrape["comm"]), dbesc(normalise_link($profile))); } if (isset($noscrape["tags"])) { $keywords = implode(" ", $noscrape["tags"]); } else { $keywords = ""; } if ($keywords != "" and $keywords != $gcontacts[0]["keywords"]) { q("UPDATE `gcontact` SET `keywords` = '%s' WHERE `nurl` = '%s'", dbesc($keywords), dbesc(normalise_link($profile))); } $location = $noscrape["locality"]; if ($noscrape["region"] != "") { if ($location != "") { $location .= ", "; } $location .= $noscrape["region"]; } if ($noscrape["country-name"] != "") { if ($location != "") { $location .= ", "; } $location .= $noscrape["country-name"]; } if ($location != "" and $location != $gcontacts[0]["location"]) { q("UPDATE `gcontact` SET `location` = '%s' WHERE `nurl` = '%s'", dbesc($location), dbesc(normalise_link($profile))); } // If we got data from noscrape then mark the contact as reachable if (is_array($noscrape) and count($noscrape)) { q("UPDATE `gcontact` SET `last_contact` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc(normalise_link($profile))); } return $noscrape["updated"]; } } } // If we only can poll the feed, then we only do this once a while if (!$force and !poco_do_update($gcontacts[0]["created"], $gcontacts[0]["updated"], $gcontacts[0]["last_failure"], $gcontacts[0]["last_contact"])) { return $gcontacts[0]["updated"]; } $data = probe_url($profile); // Is the profile link the alternate OStatus link notation? (http://domain.tld/user/4711) // Then check the other link and delete this one if ($data["network"] == NETWORK_OSTATUS and poco_alternate_ostatus_url($profile) and normalise_link($profile) == normalise_link($data["alias"]) and normalise_link($profile) != normalise_link($data["url"])) { // Delete the old entry q("DELETE FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($profile))); q("DELETE FROM `glink` WHERE `gcid` = %d", intval($gcontacts[0]["id"])); poco_check($data["url"], $data["name"], $data["network"], $data["photo"], $gcontacts[0]["about"], $gcontacts[0]["location"], $gcontacts[0]["gender"], $gcontacts[0]["keywords"], $data["addr"], $gcontacts[0]["updated"], $gcontacts[0]["generation"]); poco_last_updated($data["url"], $force); return false; } if ($data["poll"] == "" or $data["network"] == NETWORK_FEED) { q("UPDATE `gcontact` SET `last_failure` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc(normalise_link($profile))); return false; } if ($data["name"] != "" and $data["name"] != $gcontacts[0]["name"]) { q("UPDATE `gcontact` SET `name` = '%s' WHERE `nurl` = '%s'", dbesc($data["name"]), dbesc(normalise_link($profile))); } if ($data["nick"] != "" and $data["nick"] != $gcontacts[0]["nick"]) { q("UPDATE `gcontact` SET `nick` = '%s' WHERE `nurl` = '%s'", dbesc($data["nick"]), dbesc(normalise_link($profile))); } if ($data["addr"] != "" and $data["addr"] != $gcontacts[0]["connect"]) { q("UPDATE `gcontact` SET `connect` = '%s' WHERE `nurl` = '%s'", dbesc($data["addr"]), dbesc(normalise_link($profile))); } if ($data["photo"] != "" and $data["photo"] != $gcontacts[0]["photo"]) { q("UPDATE `gcontact` SET `photo` = '%s' WHERE `nurl` = '%s'", dbesc($data["photo"]), dbesc(normalise_link($profile))); } if ($data["baseurl"] != "" and $data["baseurl"] != $gcontacts[0]["server_url"]) { q("UPDATE `gcontact` SET `server_url` = '%s' WHERE `nurl` = '%s'", dbesc($data["baseurl"]), dbesc(normalise_link($profile))); } $feedret = z_fetch_url($data["poll"]); if (!$feedret["success"]) { q("UPDATE `gcontact` SET `last_failure` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc(normalise_link($profile))); return false; } $doc = new DOMDocument(); @$doc->loadXML($feedret["body"]); $xpath = new DomXPath($doc); $xpath->registerNamespace('atom', "http://www.w3.org/2005/Atom"); $entries = $xpath->query('/atom:feed/atom:entry'); $last_updated = ""; foreach ($entries as $entry) { $published = $xpath->query('atom:published/text()', $entry)->item(0)->nodeValue; $updated = $xpath->query('atom:updated/text()', $entry)->item(0)->nodeValue; if ($last_updated < $published) { $last_updated = $published; } if ($last_updated < $updated) { $last_updated = $updated; } } // Maybe there aren't any entries. Then check if it is a valid feed if ($last_updated == "") { if ($xpath->query('/atom:feed')->length > 0) { $last_updated = "0000-00-00 00:00:00"; } } q("UPDATE `gcontact` SET `updated` = '%s', `last_contact` = '%s' WHERE `nurl` = '%s'", dbesc($last_updated), dbesc(datetime_convert()), dbesc(normalise_link($profile))); if ($gcontacts[0]["generation"] == 0) { q("UPDATE `gcontact` SET `generation` = 9 WHERE `nurl` = '%s'", dbesc(normalise_link($profile))); } return $last_updated; }
public function fillInDom($dom, $formName, $formId, $values) { $xpath = new DomXPath($dom); if ($dom->documentElement && $dom->documentElement->namespaceURI) { $xpath->registerNamespace('xhtml', $dom->documentElement->namespaceURI); $ns = 'xhtml:'; } else { $ns = ''; } // find our form if ($formName) { $xpath_query = '//' . $ns . 'form[@name="' . $formName . '"]'; } elseif ($formId) { $xpath_query = '//' . $ns . 'form[@id="' . $formId . '"]'; } else { $xpath_query = '//' . $ns . 'form'; } $form = $xpath->query($xpath_query)->item(0); if (!$form) { if (!$formName && !$formId) { throw new sfException('No form found in this page'); } else { throw new sfException(sprintf('The form "%s" cannot be found', $formName ? $formName : $formId)); } } $query = 'descendant::' . $ns . 'input[@name and (not(@type)'; foreach ($this->types as $type) { $query .= ' or @type="' . $type . '"'; } $query .= ')] | descendant::' . $ns . 'textarea[@name] | descendant::' . $ns . 'select[@name]'; foreach ($xpath->query($query, $form) as $element) { $name = (string) $element->getAttribute('name'); $value = (string) $element->getAttribute('value'); $type = (string) $element->getAttribute('type'); // skip fields if (!$this->hasValue($values, $name) || in_array($name, $this->skipFields)) { continue; } if ($element->nodeName == 'input') { if ($type == 'checkbox' || $type == 'radio') { // checkbox and radio $element->removeAttribute('checked'); if (is_array($this->getValue($values, $name)) && ($this->hasValue($values, $name) || !$element->hasAttribute('value'))) { if (in_array($value, $this->getValue($values, $name))) { $element->setAttribute('checked', 'checked'); } } else { if ($this->hasValue($values, $name) && ($this->getValue($values, $name) == $value || !$element->hasAttribute('value'))) { $element->setAttribute('checked', 'checked'); } } } else { // text input $element->removeAttribute('value'); $element->setAttribute('value', $this->escapeValue($this->getValue($values, $name, true), $name)); } } else { if ($element->nodeName == 'textarea') { $el = $element->cloneNode(false); $el->appendChild($dom->createTextNode($this->escapeValue($this->getValue($values, $name, true), $name))); $element->parentNode->replaceChild($el, $element); } else { if ($element->nodeName == 'select') { // if the name contains [] it is part of an array that needs to be shifted $value = $this->getValue($values, $name, strpos($name, '[]') !== false); $multiple = $element->hasAttribute('multiple'); foreach ($xpath->query('descendant::' . $ns . 'option', $element) as $option) { $option->removeAttribute('selected'); if ($multiple && is_array($value)) { if (in_array($option->getAttribute('value'), $value)) { $option->setAttribute('selected', 'selected'); } } else { if ($value == $option->getAttribute('value')) { $option->setAttribute('selected', 'selected'); } } } } } } } return $dom; }
/** * @internal */ static function doXQueryFromNode($xmlnode, $xquery) { // Perform an XQUERY on a NODE // Register the 4 CMIS namespaces //THis may be a hopeless HACK! //TODO: Review if (!$xmlnode instanceof DOMDocument) { $xdoc = new DOMDocument(); $xnode = $xdoc->importNode($xmlnode, true); $xdoc->appendChild($xnode); $xpath = new DomXPath($xdoc); } else { $xpath = new DomXPath($xmlnode); } foreach (CMISRepositoryWrapper::$namespaces as $nspre => $nsuri) { $xpath->registerNamespace($nspre, $nsuri); } return $xpath->query($xquery); }
static function doXQueryFromNode($xmlnode, $xquery) { // Perform an XQUERY on a NODE // Register the 4 CMIS namespaces $xpath = new DomXPath($xmlnode); foreach (CMISRepositoryWrapper::$namespaces as $nspre => $nsuri) { $xpath->registerNamespace($nspre, $nsuri); } return $xpath->query($xquery); }
function selectMedia($size) { $x = new DomXPath($this->dom); $x->registerNamespace('media', Dase_Atom::$ns['media']); $x->registerNamespace('atom', Dase_Atom::$ns['atom']); $elem = $x->query("media:content/media:category[. = '{$size}']", $this->root)->item(0)->parentNode; if ($elem) { return $elem->getAttribute('url'); } }
public function testSyncWithNoChanges() { $serverId = $this->testSyncOfContacts(); $doc = new DOMDocument(); $doc->loadXML('<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/"> <Sync xmlns="uri:AirSync" xmlns:AirSyncBase="uri:AirSyncBase"><Collections> <Collection> <Class>Contacts</Class><SyncKey>3</SyncKey><CollectionId>addressbookFolderId</CollectionId><DeletesAsMoves/><GetChanges/><WindowSize>100</WindowSize> <Options><AirSyncBase:BodyPreference><AirSyncBase:Type>1</AirSyncBase:Type><AirSyncBase:TruncationSize>5120</AirSyncBase:TruncationSize></AirSyncBase:BodyPreference><Conflict>1</Conflict></Options> </Collection> </Collections></Sync>'); $sync = new Syncope_Command_Sync($doc, $this->_device, $this->_device->policykey); $sync->handle(); $syncDoc = $sync->getResponse(); #$syncDoc->formatOutput = true; echo $syncDoc->saveXML(); $xpath = new DomXPath($syncDoc); $xpath->registerNamespace('AirSync', 'uri:AirSync'); $nodes = $xpath->query('//AirSync:Sync/AirSync:Collections/AirSync:Collection/AirSync:SyncKey'); $this->assertEquals(1, $nodes->length, $syncDoc->saveXML()); $this->assertEquals(3, $nodes->item(0)->nodeValue, $syncDoc->saveXML()); $nodes = $xpath->query('//AirSync:Sync/AirSync:Collections/AirSync:Collection/AirSync:Status'); $this->assertEquals(1, $nodes->length, $syncDoc->saveXML()); $this->assertEquals(Syncope_Command_Sync::STATUS_SUCCESS, $nodes->item(0)->nodeValue, $syncDoc->saveXML()); }
function ostatus_import($xml, $importer, &$contact, &$hub) { $a = get_app(); logger("Import OStatus message", LOGGER_DEBUG); if ($xml == "") { return; } $doc = new DOMDocument(); @$doc->loadXML($xml); $xpath = new DomXPath($doc); $xpath->registerNamespace('atom', "http://www.w3.org/2005/Atom"); $xpath->registerNamespace('thr', "http://purl.org/syndication/thread/1.0"); $xpath->registerNamespace('georss', "http://www.georss.org/georss"); $xpath->registerNamespace('activity', "http://activitystrea.ms/spec/1.0/"); $xpath->registerNamespace('media', "http://purl.org/syndication/atommedia"); $xpath->registerNamespace('poco', "http://portablecontacts.net/spec/1.0"); $xpath->registerNamespace('ostatus', "http://ostatus.org/schema/1.0"); $xpath->registerNamespace('statusnet', "http://status.net/schema/api/1/"); $gub = ""; $hub_attributes = $xpath->query("/atom:feed/atom:link[@rel='hub']")->item(0)->attributes; if (is_object($hub_attributes)) { foreach ($hub_attributes as $hub_attribute) { if ($hub_attribute->name == "href") { $hub = $hub_attribute->textContent; logger("Found hub " . $hub, LOGGER_DEBUG); } } } $header = array(); $header["uid"] = $importer["uid"]; $header["network"] = NETWORK_OSTATUS; $header["type"] = "remote"; $header["wall"] = 0; $header["origin"] = 0; $header["gravity"] = GRAVITY_PARENT; // it could either be a received post or a post we fetched by ourselves // depending on that, the first node is different $first_child = $doc->firstChild->tagName; if ($first_child == "feed") { $entries = $xpath->query('/atom:feed/atom:entry'); } else { $entries = $xpath->query('/atom:entry'); } $conversation = ""; $conversationlist = array(); $item_id = 0; // Reverse the order of the entries $entrylist = array(); foreach ($entries as $entry) { $entrylist[] = $entry; } foreach (array_reverse($entrylist) as $entry) { $mention = false; // fetch the author if ($first_child == "feed") { $author = ostatus_fetchauthor($xpath, $doc->firstChild, $importer, $contact); } else { $author = ostatus_fetchauthor($xpath, $entry, $importer, $contact); } $item = array_merge($header, $author); // Now get the item $item["uri"] = $xpath->query('atom:id/text()', $entry)->item(0)->nodeValue; $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s'", intval($importer["uid"]), dbesc($item["uri"])); if ($r) { logger("Item with uri " . $item["uri"] . " for user " . $importer["uid"] . " already existed under id " . $r[0]["id"], LOGGER_DEBUG); continue; } $item["body"] = add_page_info_to_body(html2bbcode($xpath->query('atom:content/text()', $entry)->item(0)->nodeValue)); $item["object-type"] = $xpath->query('activity:object-type/text()', $entry)->item(0)->nodeValue; if ($item["object-type"] == ACTIVITY_OBJ_BOOKMARK or $item["object-type"] == ACTIVITY_OBJ_EVENT) { $item["title"] = $xpath->query('atom:title/text()', $entry)->item(0)->nodeValue; $item["body"] = $xpath->query('atom:summary/text()', $entry)->item(0)->nodeValue; } elseif ($item["object-type"] == ACTIVITY_OBJ_QUESTION) { $item["title"] = $xpath->query('atom:title/text()', $entry)->item(0)->nodeValue; } $item["object"] = $xml; $item["verb"] = $xpath->query('activity:verb/text()', $entry)->item(0)->nodeValue; // To-Do: // Delete a message if ($item["verb"] == "qvitter-delete-notice") { // ignore "Delete" messages (by now) continue; } if ($item["verb"] == ACTIVITY_JOIN) { // ignore "Join" messages continue; } if ($item["verb"] == ACTIVITY_FOLLOW) { // ignore "Follow" messages continue; } if ($item["verb"] == ACTIVITY_FAVORITE) { // ignore "Favorite" messages continue; } $item["created"] = $xpath->query('atom:published/text()', $entry)->item(0)->nodeValue; $item["edited"] = $xpath->query('atom:updated/text()', $entry)->item(0)->nodeValue; $conversation = $xpath->query('ostatus:conversation/text()', $entry)->item(0)->nodeValue; $related = ""; $inreplyto = $xpath->query('thr:in-reply-to', $entry); if (is_object($inreplyto->item(0))) { foreach ($inreplyto->item(0)->attributes as $attributes) { if ($attributes->name == "ref") { $item["parent-uri"] = $attributes->textContent; } if ($attributes->name == "href") { $related = $attributes->textContent; } } } $georsspoint = $xpath->query('georss:point', $entry); if ($georsspoint) { $item["coord"] = $georsspoint->item(0)->nodeValue; } // To-Do // $item["location"] = $categories = $xpath->query('atom:category', $entry); if ($categories) { foreach ($categories as $category) { foreach ($category->attributes as $attributes) { if ($attributes->name == "term") { $term = $attributes->textContent; if (strlen($item["tag"])) { $item["tag"] .= ','; } $item["tag"] .= "#[url=" . $a->get_baseurl() . "/search?tag=" . $term . "]" . $term . "[/url]"; } } } } $self = ""; $enclosure = ""; $links = $xpath->query('atom:link', $entry); if ($links) { $rel = ""; $href = ""; $type = ""; $length = "0"; $title = ""; foreach ($links as $link) { foreach ($link->attributes as $attributes) { if ($attributes->name == "href") { $href = $attributes->textContent; } if ($attributes->name == "rel") { $rel = $attributes->textContent; } if ($attributes->name == "type") { $type = $attributes->textContent; } if ($attributes->name == "length") { $length = $attributes->textContent; } if ($attributes->name == "title") { $title = $attributes->textContent; } } if ($rel != "" and $href != "") { switch ($rel) { case "alternate": $item["plink"] = $href; if ($item["object-type"] == ACTIVITY_OBJ_QUESTION or $item["object-type"] == ACTIVITY_OBJ_EVENT) { $item["body"] .= add_page_info($href); } break; case "ostatus:conversation": $conversation = $href; break; case "enclosure": $enclosure = $href; if (strlen($item["attach"])) { $item["attach"] .= ','; } $item["attach"] .= '[attach]href="' . $href . '" length="' . $length . '" type="' . $type . '" title="' . $title . '"[/attach]'; break; case "related": if ($item["object-type"] != ACTIVITY_OBJ_BOOKMARK) { if (!isset($item["parent-uri"])) { $item["parent-uri"] = $href; } if ($related == "") { $related = $href; } } else { $item["body"] .= add_page_info($href); } break; case "self": $self = $href; break; case "mentioned": // Notification check if ($importer["nurl"] == normalise_link($href)) { $mention = true; } break; } } } } $local_id = ""; $repeat_of = ""; $notice_info = $xpath->query('statusnet:notice_info', $entry); if ($notice_info and $notice_info->length > 0) { foreach ($notice_info->item(0)->attributes as $attributes) { if ($attributes->name == "source") { $item["app"] = strip_tags($attributes->textContent); } if ($attributes->name == "local_id") { $local_id = $attributes->textContent; } if ($attributes->name == "repeat_of") { $repeat_of = $attributes->textContent; } } } // Is it a repeated post? if ($repeat_of != "") { $activityobjects = $xpath->query('activity:object', $entry)->item(0); if (is_object($activityobjects)) { $orig_uri = $xpath->query("activity:object/atom:id", $activityobjects)->item(0)->nodeValue; if (!isset($orig_uri)) { $orig_uri = $xpath->query('atom:id/text()', $activityobjects)->item(0)->nodeValue; } $orig_links = $xpath->query("activity:object/atom:link[@rel='alternate']", $activityobjects); if ($orig_links and $orig_links->length > 0) { foreach ($orig_links->item(0)->attributes as $attributes) { if ($attributes->name == "href") { $orig_link = $attributes->textContent; } } } if (!isset($orig_link)) { $orig_link = $xpath->query("atom:link[@rel='alternate']", $activityobjects)->item(0)->nodeValue; } if (!isset($orig_link)) { $orig_link = ostatus_convert_href($orig_uri); } $orig_body = $xpath->query('activity:object/atom:content/text()', $activityobjects)->item(0)->nodeValue; if (!isset($orig_body)) { $orig_body = $xpath->query('atom:content/text()', $activityobjects)->item(0)->nodeValue; } $orig_created = $xpath->query('atom:published/text()', $activityobjects)->item(0)->nodeValue; $orig_contact = $contact; $orig_author = ostatus_fetchauthor($xpath, $activityobjects, $importer, $orig_contact); //if (!intval(get_config('system','wall-to-wall_share'))) { // $prefix = share_header($orig_author['author-name'], $orig_author['author-link'], $orig_author['author-avatar'], "", $orig_created, $orig_link); // $item["body"] = $prefix.add_page_info_to_body(html2bbcode($orig_body))."[/share]"; //} else { $item["author-name"] = $orig_author["author-name"]; $item["author-link"] = $orig_author["author-link"]; $item["author-avatar"] = $orig_author["author-avatar"]; $item["body"] = add_page_info_to_body(html2bbcode($orig_body)); $item["created"] = $orig_created; $item["uri"] = $orig_uri; $item["plink"] = $orig_link; //} $item["verb"] = $xpath->query('activity:verb/text()', $activityobjects)->item(0)->nodeValue; $item["object-type"] = $xpath->query('activity:object/activity:object-type/text()', $activityobjects)->item(0)->nodeValue; if (!isset($item["object-type"])) { $item["object-type"] = $xpath->query('activity:object-type/text()', $activityobjects)->item(0)->nodeValue; } } } //if ($enclosure != "") // $item["body"] .= add_page_info($enclosure); if (isset($item["parent-uri"])) { $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s'", intval($importer["uid"]), dbesc($item["parent-uri"])); if (!$r and $related != "") { $reply_path = str_replace("/notice/", "/api/statuses/show/", $related) . ".atom"; if ($reply_path != $related) { logger("Fetching related items for user " . $importer["uid"] . " from " . $reply_path, LOGGER_DEBUG); $reply_xml = fetch_url($reply_path); $reply_contact = $contact; ostatus_import($reply_xml, $importer, $reply_contact, $reply_hub); // After the import try to fetch the parent item again $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s'", intval($importer["uid"]), dbesc($item["parent-uri"])); } } if ($r) { $item["type"] = 'remote-comment'; $item["gravity"] = GRAVITY_COMMENT; } } else { $item["parent-uri"] = $item["uri"]; } $item_id = ostatus_completion($conversation, $importer["uid"], $item); if (!$item_id) { logger("Error storing item", LOGGER_DEBUG); continue; } logger("Item was stored with id " . $item_id, LOGGER_DEBUG); $item["id"] = $item_id; if ($mention) { $u = q("SELECT `notify-flags`, `language`, `username`, `email` FROM user WHERE uid = %d LIMIT 1", intval($item['uid'])); $r = q("SELECT `parent` FROM `item` WHERE `id` = %d", intval($item_id)); notification(array('type' => NOTIFY_TAGSELF, 'notify_flags' => $u[0]["notify-flags"], 'language' => $u[0]["language"], 'to_name' => $u[0]["username"], 'to_email' => $u[0]["email"], 'uid' => $item["uid"], 'item' => $item, 'link' => $a->get_baseurl() . '/display/' . urlencode(get_item_guid($item_id)), 'source_name' => $item["author-name"], 'source_link' => $item["author-link"], 'source_photo' => $item["author-avatar"], 'verb' => ACTIVITY_TAG, 'otype' => 'item', 'parent' => $r[0]["parent"])); } } }
/** * test deleting existing folder */ public function testDeleteNonExsistingFolder() { // delete folder created above $doc = new DOMDocument(); $doc->loadXML('<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/"> <FolderDelete xmlns="uri:FolderHierarchy"> <SyncKey>2</SyncKey> <ServerId>invalidFolderId</ServerId> </FolderDelete>'); $folderDelete = new Syncroton_Command_FolderDelete($doc, $this->_device, null); $folderDelete->handle(); $responseDoc = $folderDelete->getResponse(); #$responseDoc->formatOutput = true; echo $responseDoc->saveXML(); $xpath = new DomXPath($responseDoc); $xpath->registerNamespace('FolderHierarchy', 'uri:FolderHierarchy'); $nodes = $xpath->query('//FolderHierarchy:FolderDelete/FolderHierarchy:Status'); $this->assertEquals(1, $nodes->length, $responseDoc->saveXML()); $this->assertEquals(Syncroton_Command_FolderSync::STATUS_FOLDER_NOT_FOUND, $nodes->item(0)->nodeValue, $responseDoc->saveXML()); }
/** */ public function testFileReference() { // do initial sync first $doc = new DOMDocument(); $doc->loadXML('<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/"> <FolderSync xmlns="uri:ItemOperations"><SyncKey>0</SyncKey></FolderSync>'); $folderSync = new Syncope_Command_FolderSync($doc, $this->_device, null); $folderSync->handle(); $responseDoc = $folderSync->getResponse(); $doc = new DOMDocument(); $doc->loadXML('<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/"> <ItemOperations xmlns="uri:ItemOperations" xmlns:AirSync="uri:AirSync" xmlns:AirSyncBase="uri:AirSyncBase"> <Fetch><Store>Mailbox</Store><AirSyncBase:FileReference>email1-10</AirSyncBase:FileReference></Fetch> </ItemOperations>'); $itemOperations = new Syncope_Command_ItemOperations($doc, $this->_device, null); $itemOperations->handle(); $responseDoc = $itemOperations->getResponse(); #$responseDoc->formatOutput = true; echo $responseDoc->saveXML(); $xpath = new DomXPath($responseDoc); $xpath->registerNamespace('ItemOperations', 'uri:ItemOperations'); $xpath->registerNamespace('Email', 'uri:Email'); $nodes = $xpath->query('//ItemOperations:ItemOperations/ItemOperations:Status'); $this->assertEquals(1, $nodes->length, $responseDoc->saveXML()); $this->assertEquals(Syncope_Command_ItemOperations::STATUS_SUCCESS, $nodes->item(0)->nodeValue, $responseDoc->saveXML()); $nodes = $xpath->query('//ItemOperations:ItemOperations/ItemOperations:Response/ItemOperations:Fetch/ItemOperations:Status'); $this->assertEquals(1, $nodes->length, $responseDoc->saveXML()); $this->assertEquals(Syncope_Command_ItemOperations::STATUS_SUCCESS, $nodes->item(0)->nodeValue, $responseDoc->saveXML()); $nodes = $xpath->query('//ItemOperations:ItemOperations/ItemOperations:Response/ItemOperations:Fetch/ItemOperations:Properties/AirSyncBase:ContentType'); $this->assertEquals(1, $nodes->length, $responseDoc->saveXML()); $this->assertEquals('text/plain', $nodes->item(0)->nodeValue, $responseDoc->saveXML()); }
/** * test xml generation for IPhone */ public function testGetFoldersSyncKey0() { $doc = new DOMDocument(); $doc->loadXML('<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/"> <FolderSync xmlns="uri:FolderHierarchy"><SyncKey>0</SyncKey></FolderSync>'); $folderSync = new Syncope_Command_FolderSync($doc, $this->_device, $this->_device->policykey); $folderSync->handle(); $responseDoc = $folderSync->getResponse(); #$responseDoc->formatOutput = true; echo $responseDoc->saveXML(); $xpath = new DomXPath($responseDoc); $xpath->registerNamespace('FolderHierarchy', 'uri:FolderHierarchy'); $nodes = $xpath->query('//FolderHierarchy:FolderSync/FolderHierarchy:Status'); $this->assertEquals(1, $nodes->length, $responseDoc->saveXML()); $this->assertEquals(Syncope_Command_FolderSync::STATUS_SUCCESS, $nodes->item(0)->nodeValue, $responseDoc->saveXML()); $nodes = $xpath->query('//FolderHierarchy:FolderSync/FolderHierarchy:SyncKey'); $this->assertEquals(1, $nodes->length, $responseDoc->saveXML()); $this->assertEquals(1, $nodes->item(0)->nodeValue, $responseDoc->saveXML()); $nodes = $xpath->query('//FolderHierarchy:FolderSync/FolderHierarchy:Changes/FolderHierarchy:Add'); $this->assertGreaterThanOrEqual(1, $nodes->length, $responseDoc->saveXML()); }
* To change this template use File | Settings | File Templates. */ include "../library/Corto/XmlToArray.php"; if ($xml = $_POST['msg']) { $xml = stripslashes($xml); $element = Corto_XmlToArray::xml2array($xml); print "<pre>"; print_r($element); $signatureValue = base64_decode($element['ds:Signature']['ds:SignatureValue']['__v']); $digestValue = $element['ds:Signature']['ds:SignedInfo']['ds:Reference'][0]['ds:DigestValue']['__v']; $certificate = $element['ds:Signature']['ds:KeyInfo']['ds:X509Data']['ds:X509Certificate']['__v']; $publicKey = "-----BEGIN CERTIFICATE-----\n" . chunk_split($certificate, 64) . "-----END CERTIFICATE-----"; #print_r($publicKey); $document = DOMDocument::loadXML($xml); $xp = new DomXPath($document); $xp->registerNamespace('ds', 'http://www.w3.org/2000/09/xmldsig#'); $id = $element['_ID']; $signedElement = $xp->query("//*[@ID = '{$id}']")->item(0); $signature = $xp->query(".//ds:Signature", $signedElement)->item(0); $signedInfo = $xp->query(".//ds:SignedInfo", $signature)->item(0)->C14N(true, false); $signature->parentNode->removeChild($signature); $canonicalXml = $signedElement->C14N(true, false); print_r(htmlspecialchars($xml)); print "\n"; print_r(htmlspecialchars($canonicalXml)); print "\n\n"; $newdigest = base64_encode(sha1($canonicalXml, true)); $digestMatches = $newdigest == $digestValue; if (!$digestMatches) { print "Digest didn't match ... {$newdigest} != {$digestValue}\n"; } else {
/** * This function returns a domXPath object with all the current namespaces * already registered. * * @param DOMDocument $document * The processing Dom Document. * * @return DomXPath * The object */ protected function getXpath($document) { $xpath = new DomXPath($document); foreach ($this->namespaces as $alias => $uri) { $xpath->registerNamespace($alias, $uri); } return $xpath; }
/** * test xml generation for IPhone * * birthday must have 12 hours added */ public function testAppendXmlData() { $imp = new DOMImplementation(); $dtd = $imp->createDocumentType('AirSync', "-//AIRSYNC//DTD AirSync//EN", "http://www.microsoft.com/"); $testDoc = $imp->createDocument('uri:AirSync', 'Sync', $dtd); $testDoc->formatOutput = true; $testDoc->encoding = 'utf-8'; $appData = $testDoc->documentElement->appendChild($testDoc->createElementNS('uri:AirSync', 'ApplicationData')); $xml = new SimpleXMLElement($this->_testXMLInput); $event = new Syncroton_Model_Task($xml->Collections->Collection->Commands->Change->ApplicationData); $event->appendXML($appData, $this->_testDevice); #echo $testDoc->saveXML(); $xpath = new DomXPath($testDoc); $xpath->registerNamespace('AirSync', 'uri:AirSync'); $xpath->registerNamespace('Tasks', 'uri:Tasks'); $nodes = $xpath->query('//AirSync:Sync/AirSync:ApplicationData/Tasks:Subject'); $this->assertEquals(1, $nodes->length, $testDoc->saveXML()); $this->assertEquals('Testaufgabe auf mfe', $nodes->item(0)->nodeValue, $testDoc->saveXML()); $nodes = $xpath->query('//AirSync:Sync/AirSync:ApplicationData/Tasks:Complete'); $this->assertEquals(1, $nodes->length, $testDoc->saveXML()); $this->assertEquals('0', $nodes->item(0)->nodeValue, $testDoc->saveXML()); $nodes = $xpath->query('//AirSync:Sync/AirSync:ApplicationData/Tasks:DueDate'); $this->assertEquals(1, $nodes->length, $testDoc->saveXML()); $this->assertEquals('2010-11-28T23:59:00.000Z', $nodes->item(0)->nodeValue, $testDoc->saveXML()); $nodes = $xpath->query('//AirSync:Sync/AirSync:ApplicationData/Tasks:Recurrence/Tasks:Type'); $this->assertEquals(1, $nodes->length, $testDoc->saveXML()); $this->assertEquals(Syncroton_Model_TaskRecurrence::TYPE_WEEKLY, $nodes->item(0)->nodeValue, $testDoc->saveXML()); // try to encode XML until we have wbxml tests $outputStream = fopen("php://temp", 'r+'); $encoder = new Syncroton_Wbxml_Encoder($outputStream, 'UTF-8', 3); $encoder->encode($testDoc); }
private function _initXpath() { if ($this->xpath_obj) { return $this->xpath_obj; } else { if ('DOMDocument' != get_class($this->dom)) { $c = get_class($this->dom); throw new Dase_Atom_Exception("xpath must be performed on DOMDocument, not {$c}"); } $x = new DomXPath($this->dom); foreach (Dase_Atom::$ns as $k => $v) { $x->registerNamespace($k, $v); } $this->xpath_obj = $x; return $this->xpath_obj; } }
/** * merge a partial XML document with the XML document from the previous request * * @param DOMDocument|null $requestBody * @return SimpleXMLElement */ protected function _mergeSyncRequest($requestBody, Syncroton_Model_Device $device) { $lastSyncCollection = array(); if (!empty($device->lastsynccollection)) { $lastSyncCollection = json_decode($device->lastsynccollection, true); if (!empty($lastSyncCollection['lastXML'])) { $lastXML = new DOMDocument(); $lastXML->loadXML($lastSyncCollection['lastXML']); } } if (!$requestBody instanceof DOMDocument && isset($lastXML) && $lastXML instanceof DOMDocument) { $requestBody = $lastXML; } elseif (!$requestBody instanceof DOMDocument) { throw new Syncroton_Exception_UnexpectedValue('no xml body found'); } if ($requestBody->getElementsByTagName('Partial')->length > 0) { $partialBody = clone $requestBody; $requestBody = $lastXML; $xpath = new DomXPath($requestBody); $xpath->registerNamespace('AirSync', 'uri:AirSync'); foreach ($partialBody->documentElement->childNodes as $child) { if (!$child instanceof DOMElement) { continue; } if ($child->tagName == 'Partial') { continue; } if ($child->tagName == 'Collections') { foreach ($child->getElementsByTagName('Collection') as $updatedCollection) { $collectionId = $updatedCollection->getElementsByTagName('CollectionId')->item(0)->nodeValue; $existingCollections = $xpath->query("//AirSync:Sync/AirSync:Collections/AirSync:Collection[AirSync:CollectionId='{$collectionId}']"); if ($existingCollections->length > 0) { $existingCollection = $existingCollections->item(0); foreach ($updatedCollection->childNodes as $updatedCollectionChild) { if (!$updatedCollectionChild instanceof DOMElement) { continue; } $duplicateChild = $existingCollection->getElementsByTagName($updatedCollectionChild->tagName); if ($duplicateChild->length > 0) { $existingCollection->replaceChild($requestBody->importNode($updatedCollectionChild, TRUE), $duplicateChild->item(0)); } else { $existingCollection->appendChild($requestBody->importNode($updatedCollectionChild, TRUE)); } } } else { $importedCollection = $requestBody->importNode($updatedCollection, TRUE); } } } else { $duplicateChild = $xpath->query("//AirSync:Sync/AirSync:{$child->tagName}"); if ($duplicateChild->length > 0) { $requestBody->documentElement->replaceChild($requestBody->importNode($child, TRUE), $duplicateChild->item(0)); } else { $requestBody->documentElement->appendChild($requestBody->importNode($child, TRUE)); } } } } $lastSyncCollection['lastXML'] = $this->_cleanUpXML($requestBody)->saveXML(); $device->lastsynccollection = json_encode($lastSyncCollection); return $requestBody; }