idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
13,700 | public static function ensureUTF8 ( $ input ) { $ encoding = mb_detect_encoding ( $ input , [ 'UTF-8' , 'ISO-8859-1' ] , true ) ; if ( 'ISO-8859-1' === $ encoding ) { return utf8_encode ( $ input ) ; } else { return $ input ; } } | This method takes an input string checks if it s not valid UTF - 8 and attempts to convert it to UTF - 8 if it s not . |
13,701 | protected function getData ( ) { if ( ! file_exists ( $ this -> locksFile ) ) { return [ ] ; } $ handle = fopen ( $ this -> locksFile , 'r' ) ; flock ( $ handle , LOCK_SH ) ; $ data = stream_get_contents ( $ handle ) ; flock ( $ handle , LOCK_UN ) ; fclose ( $ handle ) ; $ data = unserialize ( $ data ) ; if ( ! $ data ) { return [ ] ; } return $ data ; } | Loads the lockdata from the filesystem . |
13,702 | protected function putData ( array $ newData ) { $ handle = fopen ( $ this -> locksFile , 'a+' ) ; flock ( $ handle , LOCK_EX ) ; ftruncate ( $ handle , 0 ) ; rewind ( $ handle ) ; fwrite ( $ handle , serialize ( $ newData ) ) ; flock ( $ handle , LOCK_UN ) ; fclose ( $ handle ) ; } | Saves the lockdata . |
13,703 | public function getChildren ( ) { if ( $ this -> disableListing ) { throw new DAV \ Exception \ MethodNotAllowed ( 'Listing members of this collection is disabled' ) ; } $ children = [ ] ; foreach ( $ this -> principalBackend -> getPrincipalsByPrefix ( $ this -> principalPrefix ) as $ principalInfo ) { $ children [ ] = $ this -> getChildForPrincipal ( $ principalInfo ) ; } return $ children ; } | Return the list of users . |
13,704 | public function add ( $ type ) { $ this -> value [ ] = $ type ; $ this -> value = array_unique ( $ this -> value ) ; } | Adds a resourcetype value to this property . |
13,705 | protected function mail ( $ to , $ subject , $ body , array $ headers ) { mail ( $ to , $ subject , $ body , implode ( "\r\n" , $ headers ) ) ; } | This function is responsible for sending the actual email . |
13,706 | private function serializeAce ( Writer $ writer , array $ ace ) { $ writer -> startElement ( '{DAV:}ace' ) ; switch ( $ ace [ 'principal' ] ) { case '{DAV:}authenticated' : $ principal = new Principal ( Principal :: AUTHENTICATED ) ; break ; case '{DAV:}unauthenticated' : $ principal = new Principal ( Principal :: UNAUTHENTICATED ) ; break ; case '{DAV:}all' : $ principal = new Principal ( Principal :: ALL ) ; break ; default : $ principal = new Principal ( Principal :: HREF , $ ace [ 'principal' ] ) ; break ; } $ writer -> writeElement ( '{DAV:}principal' , $ principal ) ; $ writer -> startElement ( '{DAV:}grant' ) ; $ writer -> startElement ( '{DAV:}privilege' ) ; $ writer -> writeElement ( $ ace [ 'privilege' ] ) ; $ writer -> endElement ( ) ; $ writer -> endElement ( ) ; if ( ! empty ( $ ace [ 'protected' ] ) ) { $ writer -> writeElement ( '{DAV:}protected' ) ; } $ writer -> endElement ( ) ; } | Serializes a single access control entry . |
13,707 | public function getName ( ) { if ( $ this -> overrideName ) { return $ this -> overrideName ; } list ( , $ name ) = Uri \ split ( $ this -> path ) ; return $ name ; } | Returns the name of the node . |
13,708 | public function setName ( $ name ) { if ( $ this -> overrideName ) { throw new Forbidden ( 'This node cannot be renamed' ) ; } list ( $ parentPath ) = Uri \ split ( $ this -> path ) ; list ( , $ newName ) = Uri \ split ( $ name ) ; $ newPath = $ parentPath . '/' . $ newName ; rename ( $ this -> path , $ newPath ) ; $ this -> path = $ newPath ; } | Renames the node . |
13,709 | public function updateCalendar ( $ calendarId , \ Sabre \ DAV \ PropPatch $ propPatch ) { if ( ! is_array ( $ calendarId ) ) { throw new \ InvalidArgumentException ( 'The value passed to $calendarId is expected to be an array with a calendarId and an instanceId' ) ; } list ( $ calendarId , $ instanceId ) = $ calendarId ; $ supportedProperties = array_keys ( $ this -> propertyMap ) ; $ supportedProperties [ ] = '{' . CalDAV \ Plugin :: NS_CALDAV . '}schedule-calendar-transp' ; $ propPatch -> handle ( $ supportedProperties , function ( $ mutations ) use ( $ calendarId , $ instanceId ) { $ newValues = [ ] ; foreach ( $ mutations as $ propertyName => $ propertyValue ) { switch ( $ propertyName ) { case '{' . CalDAV \ Plugin :: NS_CALDAV . '}schedule-calendar-transp' : $ fieldName = 'transparent' ; $ newValues [ $ fieldName ] = 'transparent' === $ propertyValue -> getValue ( ) ; break ; default : $ fieldName = $ this -> propertyMap [ $ propertyName ] ; $ newValues [ $ fieldName ] = $ propertyValue ; break ; } } $ valuesSql = [ ] ; foreach ( $ newValues as $ fieldName => $ value ) { $ valuesSql [ ] = $ fieldName . ' = ?' ; } $ stmt = $ this -> pdo -> prepare ( 'UPDATE ' . $ this -> calendarInstancesTableName . ' SET ' . implode ( ', ' , $ valuesSql ) . ' WHERE id = ?' ) ; $ newValues [ 'id' ] = $ instanceId ; $ stmt -> execute ( array_values ( $ newValues ) ) ; $ this -> addChange ( $ calendarId , '' , 2 ) ; return true ; } ) ; } | Updates properties for a calendar . |
13,710 | public function createCalendarObject ( $ calendarId , $ objectUri , $ calendarData ) { if ( ! is_array ( $ calendarId ) ) { throw new \ InvalidArgumentException ( 'The value passed to $calendarId is expected to be an array with a calendarId and an instanceId' ) ; } list ( $ calendarId , $ instanceId ) = $ calendarId ; $ extraData = $ this -> getDenormalizedData ( $ calendarData ) ; $ stmt = $ this -> pdo -> prepare ( 'INSERT INTO ' . $ this -> calendarObjectTableName . ' (calendarid, uri, calendardata, lastmodified, etag, size, componenttype, firstoccurence, lastoccurence, uid) VALUES (?,?,?,?,?,?,?,?,?,?)' ) ; $ stmt -> execute ( [ $ calendarId , $ objectUri , $ calendarData , time ( ) , $ extraData [ 'etag' ] , $ extraData [ 'size' ] , $ extraData [ 'componentType' ] , $ extraData [ 'firstOccurence' ] , $ extraData [ 'lastOccurence' ] , $ extraData [ 'uid' ] , ] ) ; $ this -> addChange ( $ calendarId , $ objectUri , 1 ) ; return '"' . $ extraData [ 'etag' ] . '"' ; } | Creates a new calendar object . |
13,711 | protected function getDenormalizedData ( $ calendarData ) { $ vObject = VObject \ Reader :: read ( $ calendarData ) ; $ componentType = null ; $ component = null ; $ firstOccurence = null ; $ lastOccurence = null ; $ uid = null ; foreach ( $ vObject -> getComponents ( ) as $ component ) { if ( 'VTIMEZONE' !== $ component -> name ) { $ componentType = $ component -> name ; $ uid = ( string ) $ component -> UID ; break ; } } if ( ! $ componentType ) { throw new \ Sabre \ DAV \ Exception \ BadRequest ( 'Calendar objects must have a VJOURNAL, VEVENT or VTODO component' ) ; } if ( 'VEVENT' === $ componentType ) { $ firstOccurence = $ component -> DTSTART -> getDateTime ( ) -> getTimeStamp ( ) ; if ( ! isset ( $ component -> RRULE ) ) { if ( isset ( $ component -> DTEND ) ) { $ lastOccurence = $ component -> DTEND -> getDateTime ( ) -> getTimeStamp ( ) ; } elseif ( isset ( $ component -> DURATION ) ) { $ endDate = clone $ component -> DTSTART -> getDateTime ( ) ; $ endDate = $ endDate -> add ( VObject \ DateTimeParser :: parse ( $ component -> DURATION -> getValue ( ) ) ) ; $ lastOccurence = $ endDate -> getTimeStamp ( ) ; } elseif ( ! $ component -> DTSTART -> hasTime ( ) ) { $ endDate = clone $ component -> DTSTART -> getDateTime ( ) ; $ endDate = $ endDate -> modify ( '+1 day' ) ; $ lastOccurence = $ endDate -> getTimeStamp ( ) ; } else { $ lastOccurence = $ firstOccurence ; } } else { $ it = new VObject \ Recur \ EventIterator ( $ vObject , ( string ) $ component -> UID ) ; $ maxDate = new \ DateTime ( self :: MAX_DATE ) ; if ( $ it -> isInfinite ( ) ) { $ lastOccurence = $ maxDate -> getTimeStamp ( ) ; } else { $ end = $ it -> getDtEnd ( ) ; while ( $ it -> valid ( ) && $ end < $ maxDate ) { $ end = $ it -> getDtEnd ( ) ; $ it -> next ( ) ; } $ lastOccurence = $ end -> getTimeStamp ( ) ; } } if ( $ firstOccurence < 0 ) { $ firstOccurence = 0 ; } if ( $ lastOccurence < 0 ) { $ lastOccurence = 0 ; } } $ vObject -> destroy ( ) ; return [ 'etag' => md5 ( $ calendarData ) , 'size' => strlen ( $ calendarData ) , 'componentType' => $ componentType , 'firstOccurence' => $ firstOccurence , 'lastOccurence' => $ lastOccurence , 'uid' => $ uid , ] ; } | Parses some information from calendar objects used for optimized calendar - queries . |
13,712 | public function getChangesForCalendar ( $ calendarId , $ syncToken , $ syncLevel , $ limit = null ) { if ( ! is_array ( $ calendarId ) ) { throw new \ InvalidArgumentException ( 'The value passed to $calendarId is expected to be an array with a calendarId and an instanceId' ) ; } list ( $ calendarId , $ instanceId ) = $ calendarId ; $ stmt = $ this -> pdo -> prepare ( 'SELECT synctoken FROM ' . $ this -> calendarTableName . ' WHERE id = ?' ) ; $ stmt -> execute ( [ $ calendarId ] ) ; $ currentToken = $ stmt -> fetchColumn ( 0 ) ; if ( is_null ( $ currentToken ) ) { return null ; } $ result = [ 'syncToken' => $ currentToken , 'added' => [ ] , 'modified' => [ ] , 'deleted' => [ ] , ] ; if ( $ syncToken ) { $ query = 'SELECT uri, operation FROM ' . $ this -> calendarChangesTableName . ' WHERE synctoken >= ? AND synctoken < ? AND calendarid = ? ORDER BY synctoken' ; if ( $ limit > 0 ) { $ query .= ' LIMIT ' . ( int ) $ limit ; } $ stmt = $ this -> pdo -> prepare ( $ query ) ; $ stmt -> execute ( [ $ syncToken , $ currentToken , $ calendarId ] ) ; $ changes = [ ] ; while ( $ row = $ stmt -> fetch ( \ PDO :: FETCH_ASSOC ) ) { $ changes [ $ row [ 'uri' ] ] = $ row [ 'operation' ] ; } foreach ( $ changes as $ uri => $ operation ) { switch ( $ operation ) { case 1 : $ result [ 'added' ] [ ] = $ uri ; break ; case 2 : $ result [ 'modified' ] [ ] = $ uri ; break ; case 3 : $ result [ 'deleted' ] [ ] = $ uri ; break ; } } } else { $ query = 'SELECT uri FROM ' . $ this -> calendarObjectTableName . ' WHERE calendarid = ?' ; $ stmt = $ this -> pdo -> prepare ( $ query ) ; $ stmt -> execute ( [ $ calendarId ] ) ; $ result [ 'added' ] = $ stmt -> fetchAll ( \ PDO :: FETCH_COLUMN ) ; } return $ result ; } | The getChanges method returns all the changes that have happened since the specified syncToken in the specified calendar . |
13,713 | protected function addChange ( $ calendarId , $ objectUri , $ operation ) { $ stmt = $ this -> pdo -> prepare ( 'INSERT INTO ' . $ this -> calendarChangesTableName . ' (uri, synctoken, calendarid, operation) SELECT ?, synctoken, ?, ? FROM ' . $ this -> calendarTableName . ' WHERE id = ?' ) ; $ stmt -> execute ( [ $ objectUri , $ calendarId , $ operation , $ calendarId , ] ) ; $ stmt = $ this -> pdo -> prepare ( 'UPDATE ' . $ this -> calendarTableName . ' SET synctoken = synctoken + 1 WHERE id = ?' ) ; $ stmt -> execute ( [ $ calendarId , ] ) ; } | Adds a change record to the calendarchanges table . |
13,714 | public function getSubscriptionsForUser ( $ principalUri ) { $ fields = array_values ( $ this -> subscriptionPropertyMap ) ; $ fields [ ] = 'id' ; $ fields [ ] = 'uri' ; $ fields [ ] = 'source' ; $ fields [ ] = 'principaluri' ; $ fields [ ] = 'lastmodified' ; $ fields = implode ( ', ' , $ fields ) ; $ stmt = $ this -> pdo -> prepare ( 'SELECT ' . $ fields . ' FROM ' . $ this -> calendarSubscriptionsTableName . ' WHERE principaluri = ? ORDER BY calendarorder ASC' ) ; $ stmt -> execute ( [ $ principalUri ] ) ; $ subscriptions = [ ] ; while ( $ row = $ stmt -> fetch ( \ PDO :: FETCH_ASSOC ) ) { $ subscription = [ 'id' => $ row [ 'id' ] , 'uri' => $ row [ 'uri' ] , 'principaluri' => $ row [ 'principaluri' ] , 'source' => $ row [ 'source' ] , 'lastmodified' => $ row [ 'lastmodified' ] , '{' . CalDAV \ Plugin :: NS_CALDAV . '}supported-calendar-component-set' => new CalDAV \ Xml \ Property \ SupportedCalendarComponentSet ( [ 'VTODO' , 'VEVENT' ] ) , ] ; foreach ( $ this -> subscriptionPropertyMap as $ xmlName => $ dbName ) { if ( ! is_null ( $ row [ $ dbName ] ) ) { $ subscription [ $ xmlName ] = $ row [ $ dbName ] ; } } $ subscriptions [ ] = $ subscription ; } return $ subscriptions ; } | Returns a list of subscriptions for a principal . |
13,715 | public function createSubscription ( $ principalUri , $ uri , array $ properties ) { $ fieldNames = [ 'principaluri' , 'uri' , 'source' , 'lastmodified' , ] ; if ( ! isset ( $ properties [ '{http://calendarserver.org/ns/}source' ] ) ) { throw new Forbidden ( 'The {http://calendarserver.org/ns/}source property is required when creating subscriptions' ) ; } $ values = [ ':principaluri' => $ principalUri , ':uri' => $ uri , ':source' => $ properties [ '{http://calendarserver.org/ns/}source' ] -> getHref ( ) , ':lastmodified' => time ( ) , ] ; foreach ( $ this -> subscriptionPropertyMap as $ xmlName => $ dbName ) { if ( isset ( $ properties [ $ xmlName ] ) ) { $ values [ ':' . $ dbName ] = $ properties [ $ xmlName ] ; $ fieldNames [ ] = $ dbName ; } } $ stmt = $ this -> pdo -> prepare ( 'INSERT INTO ' . $ this -> calendarSubscriptionsTableName . ' (' . implode ( ', ' , $ fieldNames ) . ') VALUES (' . implode ( ', ' , array_keys ( $ values ) ) . ')' ) ; $ stmt -> execute ( $ values ) ; return $ this -> pdo -> lastInsertId ( $ this -> calendarSubscriptionsTableName . '_id_seq' ) ; } | Creates a new subscription for a principal . |
13,716 | public function updateSubscription ( $ subscriptionId , DAV \ PropPatch $ propPatch ) { $ supportedProperties = array_keys ( $ this -> subscriptionPropertyMap ) ; $ supportedProperties [ ] = '{http://calendarserver.org/ns/}source' ; $ propPatch -> handle ( $ supportedProperties , function ( $ mutations ) use ( $ subscriptionId ) { $ newValues = [ ] ; foreach ( $ mutations as $ propertyName => $ propertyValue ) { if ( '{http://calendarserver.org/ns/}source' === $ propertyName ) { $ newValues [ 'source' ] = $ propertyValue -> getHref ( ) ; } else { $ fieldName = $ this -> subscriptionPropertyMap [ $ propertyName ] ; $ newValues [ $ fieldName ] = $ propertyValue ; } } $ valuesSql = [ ] ; foreach ( $ newValues as $ fieldName => $ value ) { $ valuesSql [ ] = $ fieldName . ' = ?' ; } $ stmt = $ this -> pdo -> prepare ( 'UPDATE ' . $ this -> calendarSubscriptionsTableName . ' SET ' . implode ( ', ' , $ valuesSql ) . ', lastmodified = ? WHERE id = ?' ) ; $ newValues [ 'lastmodified' ] = time ( ) ; $ newValues [ 'id' ] = $ subscriptionId ; $ stmt -> execute ( array_values ( $ newValues ) ) ; return true ; } ) ; } | Updates a subscription . |
13,717 | public function getSchedulingObject ( $ principalUri , $ objectUri ) { $ stmt = $ this -> pdo -> prepare ( 'SELECT uri, calendardata, lastmodified, etag, size FROM ' . $ this -> schedulingObjectTableName . ' WHERE principaluri = ? AND uri = ?' ) ; $ stmt -> execute ( [ $ principalUri , $ objectUri ] ) ; $ row = $ stmt -> fetch ( \ PDO :: FETCH_ASSOC ) ; if ( ! $ row ) { return null ; } return [ 'uri' => $ row [ 'uri' ] , 'calendardata' => $ row [ 'calendardata' ] , 'lastmodified' => $ row [ 'lastmodified' ] , 'etag' => '"' . $ row [ 'etag' ] . '"' , 'size' => ( int ) $ row [ 'size' ] , ] ; } | Returns a single scheduling object . |
13,718 | public function getSchedulingObjects ( $ principalUri ) { $ stmt = $ this -> pdo -> prepare ( 'SELECT id, calendardata, uri, lastmodified, etag, size FROM ' . $ this -> schedulingObjectTableName . ' WHERE principaluri = ?' ) ; $ stmt -> execute ( [ $ principalUri ] ) ; $ result = [ ] ; foreach ( $ stmt -> fetchAll ( \ PDO :: FETCH_ASSOC ) as $ row ) { $ result [ ] = [ 'calendardata' => $ row [ 'calendardata' ] , 'uri' => $ row [ 'uri' ] , 'lastmodified' => $ row [ 'lastmodified' ] , 'etag' => '"' . $ row [ 'etag' ] . '"' , 'size' => ( int ) $ row [ 'size' ] , ] ; } return $ result ; } | Returns all scheduling objects for the inbox collection . |
13,719 | public function deleteSchedulingObject ( $ principalUri , $ objectUri ) { $ stmt = $ this -> pdo -> prepare ( 'DELETE FROM ' . $ this -> schedulingObjectTableName . ' WHERE principaluri = ? AND uri = ?' ) ; $ stmt -> execute ( [ $ principalUri , $ objectUri ] ) ; } | Deletes a scheduling object . |
13,720 | public function createSchedulingObject ( $ principalUri , $ objectUri , $ objectData ) { $ stmt = $ this -> pdo -> prepare ( 'INSERT INTO ' . $ this -> schedulingObjectTableName . ' (principaluri, calendardata, uri, lastmodified, etag, size) VALUES (?, ?, ?, ?, ?, ?)' ) ; $ stmt -> execute ( [ $ principalUri , $ objectData , $ objectUri , time ( ) , md5 ( $ objectData ) , strlen ( $ objectData ) ] ) ; } | Creates a new scheduling object . This should land in a users inbox . |
13,721 | public function updateInvites ( $ calendarId , array $ sharees ) { if ( ! is_array ( $ calendarId ) ) { throw new \ InvalidArgumentException ( 'The value passed to $calendarId is expected to be an array with a calendarId and an instanceId' ) ; } $ currentInvites = $ this -> getInvites ( $ calendarId ) ; list ( $ calendarId , $ instanceId ) = $ calendarId ; $ removeStmt = $ this -> pdo -> prepare ( 'DELETE FROM ' . $ this -> calendarInstancesTableName . ' WHERE calendarid = ? AND share_href = ? AND access IN (2,3)' ) ; $ updateStmt = $ this -> pdo -> prepare ( 'UPDATE ' . $ this -> calendarInstancesTableName . ' SET access = ?, share_displayname = ?, share_invitestatus = ? WHERE calendarid = ? AND share_href = ?' ) ; $ insertStmt = $ this -> pdo -> prepare ( 'INSERT INTO ' . $ this -> calendarInstancesTableName . ' ( calendarid, principaluri, access, displayname, uri, description, calendarorder, calendarcolor, timezone, transparent, share_href, share_displayname, share_invitestatus ) SELECT ?, ?, ?, displayname, ?, description, calendarorder, calendarcolor, timezone, 1, ?, ?, ? FROM ' . $ this -> calendarInstancesTableName . ' WHERE id = ?' ) ; foreach ( $ sharees as $ sharee ) { if ( \ Sabre \ DAV \ Sharing \ Plugin :: ACCESS_NOACCESS === $ sharee -> access ) { $ removeStmt -> execute ( [ $ calendarId , $ sharee -> href ] ) ; continue ; } if ( is_null ( $ sharee -> principal ) ) { $ sharee -> inviteStatus = \ Sabre \ DAV \ Sharing \ Plugin :: INVITE_INVALID ; } else { $ sharee -> inviteStatus = \ Sabre \ DAV \ Sharing \ Plugin :: INVITE_ACCEPTED ; } foreach ( $ currentInvites as $ oldSharee ) { if ( $ oldSharee -> href === $ sharee -> href ) { $ sharee -> properties = array_merge ( $ oldSharee -> properties , $ sharee -> properties ) ; $ updateStmt -> execute ( [ $ sharee -> access , isset ( $ sharee -> properties [ '{DAV:}displayname' ] ) ? $ sharee -> properties [ '{DAV:}displayname' ] : null , $ sharee -> inviteStatus ? : $ oldSharee -> inviteStatus , $ calendarId , $ sharee -> href , ] ) ; continue 2 ; } } $ insertStmt -> execute ( [ $ calendarId , $ sharee -> principal , $ sharee -> access , \ Sabre \ DAV \ UUIDUtil :: getUUID ( ) , $ sharee -> href , isset ( $ sharee -> properties [ '{DAV:}displayname' ] ) ? $ sharee -> properties [ '{DAV:}displayname' ] : null , $ sharee -> inviteStatus ? : \ Sabre \ DAV \ Sharing \ Plugin :: INVITE_NORESPONSE , $ instanceId , ] ) ; } } | Updates the list of shares . |
13,722 | public function getInvites ( $ calendarId ) { if ( ! is_array ( $ calendarId ) ) { throw new \ InvalidArgumentException ( 'The value passed to getInvites() is expected to be an array with a calendarId and an instanceId' ) ; } list ( $ calendarId , $ instanceId ) = $ calendarId ; $ query = <<<SQLSELECT principaluri, access, share_href, share_displayname, share_invitestatusFROM {$this->calendarInstancesTableName}WHERE calendarid = ?SQL ; $ stmt = $ this -> pdo -> prepare ( $ query ) ; $ stmt -> execute ( [ $ calendarId ] ) ; $ result = [ ] ; while ( $ row = $ stmt -> fetch ( \ PDO :: FETCH_ASSOC ) ) { $ result [ ] = new Sharee ( [ 'href' => isset ( $ row [ 'share_href' ] ) ? $ row [ 'share_href' ] : \ Sabre \ HTTP \ encodePath ( $ row [ 'principaluri' ] ) , 'access' => ( int ) $ row [ 'access' ] , 'inviteStatus' => ( int ) $ row [ 'share_invitestatus' ] , 'properties' => ! empty ( $ row [ 'share_displayname' ] ) ? [ '{DAV:}displayname' => $ row [ 'share_displayname' ] ] : [ ] , 'principal' => $ row [ 'principaluri' ] , ] ) ; } return $ result ; } | Returns the list of people whom a calendar is shared with . |
13,723 | public function propFind ( $ path , PropFind $ propFind ) { if ( ! $ propFind -> isAllProps ( ) && 0 === count ( $ propFind -> get404Properties ( ) ) ) { return ; } $ query = 'SELECT name, value, valuetype FROM ' . $ this -> tableName . ' WHERE path = ?' ; $ stmt = $ this -> pdo -> prepare ( $ query ) ; $ stmt -> execute ( [ $ path ] ) ; while ( $ row = $ stmt -> fetch ( \ PDO :: FETCH_ASSOC ) ) { if ( 'resource' === gettype ( $ row [ 'value' ] ) ) { $ row [ 'value' ] = stream_get_contents ( $ row [ 'value' ] ) ; } switch ( $ row [ 'valuetype' ] ) { case null : case self :: VT_STRING : $ propFind -> set ( $ row [ 'name' ] , $ row [ 'value' ] ) ; break ; case self :: VT_XML : $ propFind -> set ( $ row [ 'name' ] , new Complex ( $ row [ 'value' ] ) ) ; break ; case self :: VT_OBJECT : $ propFind -> set ( $ row [ 'name' ] , unserialize ( $ row [ 'value' ] ) ) ; break ; } } } | Fetches properties for a path . |
13,724 | public function propPatch ( $ path , PropPatch $ propPatch ) { $ propPatch -> handleRemaining ( function ( $ properties ) use ( $ path ) { if ( 'pgsql' === $ this -> pdo -> getAttribute ( \ PDO :: ATTR_DRIVER_NAME ) ) { $ updateSql = <<<SQLINSERT INTO {$this->tableName} (path, name, valuetype, value)VALUES (:path, :name, :valuetype, :value)ON CONFLICT (path, name)DO UPDATE SET valuetype = :valuetype, value = :valueSQL ; } else { $ updateSql = <<<SQLREPLACE INTO {$this->tableName} (path, name, valuetype, value)VALUES (:path, :name, :valuetype, :value)SQL ; } $ updateStmt = $ this -> pdo -> prepare ( $ updateSql ) ; $ deleteStmt = $ this -> pdo -> prepare ( 'DELETE FROM ' . $ this -> tableName . ' WHERE path = ? AND name = ?' ) ; foreach ( $ properties as $ name => $ value ) { if ( ! is_null ( $ value ) ) { if ( is_scalar ( $ value ) ) { $ valueType = self :: VT_STRING ; } elseif ( $ value instanceof Complex ) { $ valueType = self :: VT_XML ; $ value = $ value -> getXml ( ) ; } else { $ valueType = self :: VT_OBJECT ; $ value = serialize ( $ value ) ; } $ updateStmt -> bindParam ( 'path' , $ path , \ PDO :: PARAM_STR ) ; $ updateStmt -> bindParam ( 'name' , $ name , \ PDO :: PARAM_STR ) ; $ updateStmt -> bindParam ( 'valuetype' , $ valueType , \ PDO :: PARAM_INT ) ; $ updateStmt -> bindParam ( 'value' , $ value , \ PDO :: PARAM_LOB ) ; $ updateStmt -> execute ( ) ; } else { $ deleteStmt -> execute ( [ $ path , $ name ] ) ; } } return true ; } ) ; } | Updates properties for a path . |
13,725 | public function move ( $ source , $ destination ) { $ select = $ this -> pdo -> prepare ( 'SELECT id, path FROM ' . $ this -> tableName . ' WHERE path = ? OR path LIKE ?' ) ; $ select -> execute ( [ $ source , $ source . '/%' ] ) ; $ update = $ this -> pdo -> prepare ( 'UPDATE ' . $ this -> tableName . ' SET path = ? WHERE id = ?' ) ; while ( $ row = $ select -> fetch ( \ PDO :: FETCH_ASSOC ) ) { if ( $ row [ 'path' ] !== $ source && 0 !== strpos ( $ row [ 'path' ] , $ source . '/' ) ) { continue ; } $ trailingPart = substr ( $ row [ 'path' ] , strlen ( $ source ) + 1 ) ; $ newPath = $ destination ; if ( $ trailingPart ) { $ newPath .= '/' . $ trailingPart ; } $ update -> execute ( [ $ newPath , $ row [ 'id' ] ] ) ; } } | This method is called after a successful MOVE . |
13,726 | public function childExists ( $ name ) { if ( '.' == $ name || '..' == $ name ) { throw new DAV \ Exception \ Forbidden ( 'Permission denied to . and ..' ) ; } $ path = $ this -> path . '/' . $ name ; return file_exists ( $ path ) ; } | Checks if a child exists . |
13,727 | public function delete ( ) { foreach ( $ this -> getChildren ( ) as $ child ) { $ child -> delete ( ) ; } rmdir ( $ this -> path ) ; return true ; } | Deletes all files in this directory and then itself . |
13,728 | public function moveInto ( $ targetName , $ sourcePath , DAV \ INode $ sourceNode ) { if ( ! $ sourceNode instanceof self && ! $ sourceNode instanceof File ) { return false ; } return rename ( $ sourceNode -> path , $ this -> path . '/' . $ targetName ) ; } | Moves a node into this collection . |
13,729 | public function initialize ( DAV \ Server $ server ) { $ this -> server = $ server ; $ this -> server -> on ( 'method:GET' , [ $ this , 'httpGetEarly' ] , 90 ) ; $ this -> server -> on ( 'method:GET' , [ $ this , 'httpGet' ] , 200 ) ; $ this -> server -> on ( 'onHTMLActionsPanel' , [ $ this , 'htmlActionsPanel' ] , 200 ) ; if ( $ this -> enablePost ) { $ this -> server -> on ( 'method:POST' , [ $ this , 'httpPOST' ] ) ; } } | Initializes the plugin and subscribes to events . |
13,730 | public function httpGetEarly ( RequestInterface $ request , ResponseInterface $ response ) { $ params = $ request -> getQueryParameters ( ) ; if ( isset ( $ params [ 'sabreAction' ] ) && 'info' === $ params [ 'sabreAction' ] ) { return $ this -> httpGet ( $ request , $ response ) ; } } | This method intercepts GET requests that have ?sabreAction = info appended to the URL . |
13,731 | public function httpGet ( RequestInterface $ request , ResponseInterface $ response ) { $ getVars = $ request -> getQueryParameters ( ) ; $ response -> setHeader ( 'Content-Security-Policy' , "default-src 'none'; img-src 'self'; style-src 'self'; font-src 'self';" ) ; $ sabreAction = isset ( $ getVars [ 'sabreAction' ] ) ? $ getVars [ 'sabreAction' ] : null ; switch ( $ sabreAction ) { case 'asset' : $ this -> serveAsset ( isset ( $ getVars [ 'assetName' ] ) ? $ getVars [ 'assetName' ] : null ) ; return false ; default : case 'info' : try { $ this -> server -> tree -> getNodeForPath ( $ request -> getPath ( ) ) ; } catch ( DAV \ Exception \ NotFound $ e ) { return ; } $ response -> setStatus ( 200 ) ; $ response -> setHeader ( 'Content-Type' , 'text/html; charset=utf-8' ) ; $ response -> setBody ( $ this -> generateDirectoryIndex ( $ request -> getPath ( ) ) ) ; return false ; case 'plugins' : $ response -> setStatus ( 200 ) ; $ response -> setHeader ( 'Content-Type' , 'text/html; charset=utf-8' ) ; $ response -> setBody ( $ this -> generatePluginListing ( ) ) ; return false ; } } | This method intercepts GET requests to collections and returns the html . |
13,732 | public function httpPOST ( RequestInterface $ request , ResponseInterface $ response ) { $ contentType = $ request -> getHeader ( 'Content-Type' ) ; list ( $ contentType ) = explode ( ';' , $ contentType ) ; if ( 'application/x-www-form-urlencoded' !== $ contentType && 'multipart/form-data' !== $ contentType ) { return ; } $ postVars = $ request -> getPostData ( ) ; if ( ! isset ( $ postVars [ 'sabreAction' ] ) ) { return ; } $ uri = $ request -> getPath ( ) ; if ( $ this -> server -> emit ( 'onBrowserPostAction' , [ $ uri , $ postVars [ 'sabreAction' ] , $ postVars ] ) ) { switch ( $ postVars [ 'sabreAction' ] ) { case 'mkcol' : if ( isset ( $ postVars [ 'name' ] ) && trim ( $ postVars [ 'name' ] ) ) { list ( , $ folderName ) = Uri \ split ( trim ( $ postVars [ 'name' ] ) ) ; if ( isset ( $ postVars [ 'resourceType' ] ) ) { $ resourceType = explode ( ',' , $ postVars [ 'resourceType' ] ) ; } else { $ resourceType = [ '{DAV:}collection' ] ; } $ properties = [ ] ; foreach ( $ postVars as $ varName => $ varValue ) { if ( '{' === $ varName [ 0 ] ) { $ varName = str_replace ( '*DOT*' , '.' , $ varName ) ; $ properties [ $ varName ] = $ varValue ; } } $ mkCol = new MkCol ( $ resourceType , $ properties ) ; $ this -> server -> createCollection ( $ uri . '/' . $ folderName , $ mkCol ) ; } break ; case 'put' : if ( $ _FILES ) { $ file = current ( $ _FILES ) ; } else { break ; } list ( , $ newName ) = Uri \ split ( trim ( $ file [ 'name' ] ) ) ; if ( isset ( $ postVars [ 'name' ] ) && trim ( $ postVars [ 'name' ] ) ) { $ newName = trim ( $ postVars [ 'name' ] ) ; } list ( , $ newName ) = Uri \ split ( $ newName ) ; if ( is_uploaded_file ( $ file [ 'tmp_name' ] ) ) { $ this -> server -> createFile ( $ uri . '/' . $ newName , fopen ( $ file [ 'tmp_name' ] , 'r' ) ) ; } break ; } } $ response -> setHeader ( 'Location' , $ request -> getUrl ( ) ) ; $ response -> setStatus ( 302 ) ; return false ; } | Handles POST requests for tree operations . |
13,733 | public function generatePluginListing ( ) { $ html = $ this -> generateHeader ( 'Plugins' ) ; $ html .= '<section><h1>Plugins</h1>' ; $ html .= '<table class="propTable">' ; foreach ( $ this -> server -> getPlugins ( ) as $ plugin ) { $ info = $ plugin -> getPluginInfo ( ) ; $ html .= '<tr><th>' . $ info [ 'name' ] . '</th>' ; $ html .= '<td>' . $ info [ 'description' ] . '</td>' ; $ html .= '<td>' ; if ( isset ( $ info [ 'link' ] ) && $ info [ 'link' ] ) { $ html .= '<a href="' . $ this -> escapeHTML ( $ info [ 'link' ] ) . '"><span class="oi" data-glyph="book"></span></a>' ; } $ html .= '</td></tr>' ; } $ html .= '</table>' ; $ html .= '</section>' ; $ html .= $ this -> generateFooter ( ) ; return $ html ; } | Generates the plugins page . |
13,734 | public function htmlActionsPanel ( DAV \ INode $ node , & $ output , $ path ) { if ( ! $ node instanceof DAV \ ICollection ) { return ; } if ( 'Sabre\\DAV\\SimpleCollection' === get_class ( $ node ) ) { return ; } $ output .= <<<HTML<form method="post" action=""><h3>Create new folder</h3><input type="hidden" name="sabreAction" value="mkcol" /><label>Name:</label> <input type="text" name="name" /><br /><input type="submit" value="create" /></form><form method="post" action="" enctype="multipart/form-data"><h3>Upload file</h3><input type="hidden" name="sabreAction" value="put" /><label>Name (optional):</label> <input type="text" name="name" /><br /><label>File:</label> <input type="file" name="file" /><br /><input type="submit" value="upload" /></form>HTML ; } | This method is used to generate the actions panel output for collections . |
13,735 | protected function getLocalAssetPath ( $ assetName ) { $ assetDir = __DIR__ . '/assets/' ; $ path = $ assetDir . $ assetName ; $ path = str_replace ( '\\' , '/' , $ path ) ; if ( false !== strpos ( $ path , '/../' ) || '/..' === strrchr ( $ path , '/' ) ) { throw new DAV \ Exception \ NotFound ( 'Path does not exist, or escaping from the base path was detected' ) ; } $ realPath = realpath ( $ path ) ; if ( $ realPath && 0 === strpos ( $ realPath , realpath ( $ assetDir ) ) && file_exists ( $ path ) ) { return $ path ; } throw new DAV \ Exception \ NotFound ( 'Path does not exist, or escaping from the base path was detected' ) ; } | This method returns a local pathname to an asset . |
13,736 | protected function serveAsset ( $ assetName ) { $ assetPath = $ this -> getLocalAssetPath ( $ assetName ) ; $ mime = 'application/octet-stream' ; $ map = [ 'ico' => 'image/vnd.microsoft.icon' , 'png' => 'image/png' , 'css' => 'text/css' , ] ; $ ext = substr ( $ assetName , strrpos ( $ assetName , '.' ) + 1 ) ; if ( isset ( $ map [ $ ext ] ) ) { $ mime = $ map [ $ ext ] ; } $ this -> server -> httpResponse -> setHeader ( 'Content-Type' , $ mime ) ; $ this -> server -> httpResponse -> setHeader ( 'Content-Length' , filesize ( $ assetPath ) ) ; $ this -> server -> httpResponse -> setHeader ( 'Cache-Control' , 'public, max-age=1209600' ) ; $ this -> server -> httpResponse -> setStatus ( 200 ) ; $ this -> server -> httpResponse -> setBody ( fopen ( $ assetPath , 'r' ) ) ; } | This method reads an asset from disk and generates a full http response . |
13,737 | private function mapResourceType ( array $ resourceTypes , $ node ) { if ( ! $ resourceTypes ) { if ( $ node instanceof DAV \ IFile ) { return [ 'string' => 'File' , 'icon' => 'file' , ] ; } else { return [ 'string' => 'Unknown' , 'icon' => 'cog' , ] ; } } $ types = [ '{http://calendarserver.org/ns/}calendar-proxy-write' => [ 'string' => 'Proxy-Write' , 'icon' => 'people' , ] , '{http://calendarserver.org/ns/}calendar-proxy-read' => [ 'string' => 'Proxy-Read' , 'icon' => 'people' , ] , '{urn:ietf:params:xml:ns:caldav}schedule-outbox' => [ 'string' => 'Outbox' , 'icon' => 'inbox' , ] , '{urn:ietf:params:xml:ns:caldav}schedule-inbox' => [ 'string' => 'Inbox' , 'icon' => 'inbox' , ] , '{urn:ietf:params:xml:ns:caldav}calendar' => [ 'string' => 'Calendar' , 'icon' => 'calendar' , ] , '{http://calendarserver.org/ns/}shared-owner' => [ 'string' => 'Shared' , 'icon' => 'calendar' , ] , '{http://calendarserver.org/ns/}subscribed' => [ 'string' => 'Subscription' , 'icon' => 'calendar' , ] , '{urn:ietf:params:xml:ns:carddav}directory' => [ 'string' => 'Directory' , 'icon' => 'globe' , ] , '{urn:ietf:params:xml:ns:carddav}addressbook' => [ 'string' => 'Address book' , 'icon' => 'book' , ] , '{DAV:}principal' => [ 'string' => 'Principal' , 'icon' => 'person' , ] , '{DAV:}collection' => [ 'string' => 'Collection' , 'icon' => 'folder' , ] , ] ; $ info = [ 'string' => [ ] , 'icon' => 'cog' , ] ; foreach ( $ resourceTypes as $ k => $ resourceType ) { if ( isset ( $ types [ $ resourceType ] ) ) { $ info [ 'string' ] [ ] = $ types [ $ resourceType ] [ 'string' ] ; } else { $ info [ 'string' ] [ ] = $ resourceType ; } } foreach ( $ types as $ key => $ resourceInfo ) { if ( in_array ( $ key , $ resourceTypes ) ) { $ info [ 'icon' ] = $ resourceInfo [ 'icon' ] ; break ; } } $ info [ 'string' ] = implode ( ', ' , $ info [ 'string' ] ) ; return $ info ; } | Maps a resource type to a human - readable string and icon . |
13,738 | public function loadFile ( $ filename ) { foreach ( file ( $ filename , FILE_IGNORE_NEW_LINES ) as $ line ) { if ( 2 !== substr_count ( $ line , ':' ) ) { throw new DAV \ Exception ( 'Malformed htdigest file. Every line should contain 2 colons' ) ; } list ( $ username , $ realm , $ A1 ) = explode ( ':' , $ line ) ; if ( ! preg_match ( '/^[a-zA-Z0-9]{32}$/' , $ A1 ) ) { throw new DAV \ Exception ( 'Malformed htdigest file. Invalid md5 hash' ) ; } $ this -> users [ $ realm . ':' . $ username ] = $ A1 ; } } | Loads an htdigest - formatted file . This method can be called multiple times if more than 1 file is used . |
13,739 | public function getDigestHash ( $ realm , $ username ) { return isset ( $ this -> users [ $ realm . ':' . $ username ] ) ? $ this -> users [ $ realm . ':' . $ username ] : false ; } | Returns a users information . |
13,740 | public function getAlternateUriSet ( ) { $ uris = [ ] ; if ( isset ( $ this -> principalProperties [ '{DAV:}alternate-URI-set' ] ) ) { $ uris = $ this -> principalProperties [ '{DAV:}alternate-URI-set' ] ; } if ( isset ( $ this -> principalProperties [ '{http://sabredav.org/ns}email-address' ] ) ) { $ uris [ ] = 'mailto:' . $ this -> principalProperties [ '{http://sabredav.org/ns}email-address' ] ; } return array_unique ( $ uris ) ; } | Returns a list of alternative urls for a principal . |
13,741 | public function getName ( ) { $ uri = $ this -> principalProperties [ 'uri' ] ; list ( , $ name ) = Uri \ split ( $ uri ) ; return $ name ; } | Returns this principals name . |
13,742 | public function getProperties ( $ requestedProperties ) { $ newProperties = [ ] ; foreach ( $ requestedProperties as $ propName ) { if ( isset ( $ this -> principalProperties [ $ propName ] ) ) { $ newProperties [ $ propName ] = $ this -> principalProperties [ $ propName ] ; } } return $ newProperties ; } | Returns a list of properties . |
13,743 | public function propFindEarly ( DAV \ PropFind $ propFind , DAV \ INode $ node ) { if ( $ node instanceof ISharedCalendar ) { $ propFind -> handle ( '{' . Plugin :: NS_CALENDARSERVER . '}invite' , function ( ) use ( $ node ) { return new Xml \ Property \ Invite ( $ node -> getInvites ( ) ) ; } ) ; } } | This event is triggered when properties are requested for a certain node . |
13,744 | public function propPatch ( $ path , DAV \ PropPatch $ propPatch ) { $ node = $ this -> server -> tree -> getNodeForPath ( $ path ) ; if ( ! $ node instanceof ISharedCalendar ) { return ; } if ( \ Sabre \ DAV \ Sharing \ Plugin :: ACCESS_SHAREDOWNER === $ node -> getShareAccess ( ) || \ Sabre \ DAV \ Sharing \ Plugin :: ACCESS_NOTSHARED === $ node -> getShareAccess ( ) ) { $ propPatch -> handle ( '{DAV:}resourcetype' , function ( $ value ) use ( $ node ) { if ( $ value -> is ( '{' . Plugin :: NS_CALENDARSERVER . '}shared-owner' ) ) { return false ; } $ shares = $ node -> getInvites ( ) ; foreach ( $ shares as $ share ) { $ share -> access = DAV \ Sharing \ Plugin :: ACCESS_NOACCESS ; } $ node -> updateInvites ( $ shares ) ; return true ; } ) ; } } | This method is trigged when a user attempts to update a node s properties . |
13,745 | public function httpGet ( RequestInterface $ request , ResponseInterface $ response ) { $ queryParams = $ request -> getQueryParameters ( ) ; if ( ! array_key_exists ( 'export' , $ queryParams ) ) { return ; } $ path = $ request -> getPath ( ) ; $ node = $ this -> server -> getProperties ( $ path , [ '{DAV:}resourcetype' , '{DAV:}displayname' , '{http://sabredav.org/ns}sync-token' , '{DAV:}sync-token' , '{http://apple.com/ns/ical/}calendar-color' , ] ) ; if ( ! isset ( $ node [ '{DAV:}resourcetype' ] ) || ! $ node [ '{DAV:}resourcetype' ] -> is ( '{' . Plugin :: NS_CALDAV . '}calendar' ) ) { return ; } $ this -> server -> transactionType = 'get-calendar-export' ; $ properties = $ node ; $ start = null ; $ end = null ; $ expand = false ; $ componentType = false ; if ( isset ( $ queryParams [ 'start' ] ) ) { if ( ! ctype_digit ( $ queryParams [ 'start' ] ) ) { throw new BadRequest ( 'The start= parameter must contain a unix timestamp' ) ; } $ start = DateTime :: createFromFormat ( 'U' , $ queryParams [ 'start' ] ) ; } if ( isset ( $ queryParams [ 'end' ] ) ) { if ( ! ctype_digit ( $ queryParams [ 'end' ] ) ) { throw new BadRequest ( 'The end= parameter must contain a unix timestamp' ) ; } $ end = DateTime :: createFromFormat ( 'U' , $ queryParams [ 'end' ] ) ; } if ( isset ( $ queryParams [ 'expand' ] ) && ( bool ) $ queryParams [ 'expand' ] ) { if ( ! $ start || ! $ end ) { throw new BadRequest ( 'If you\'d like to expand recurrences, you must specify both a start= and end= parameter.' ) ; } $ expand = true ; $ componentType = 'VEVENT' ; } if ( isset ( $ queryParams [ 'componentType' ] ) ) { if ( ! in_array ( $ queryParams [ 'componentType' ] , [ 'VEVENT' , 'VTODO' , 'VJOURNAL' ] ) ) { throw new BadRequest ( 'You are not allowed to search for components of type: ' . $ queryParams [ 'componentType' ] . ' here' ) ; } $ componentType = $ queryParams [ 'componentType' ] ; } $ format = \ Sabre \ HTTP \ negotiateContentType ( $ request -> getHeader ( 'Accept' ) , [ 'text/calendar' , 'application/calendar+json' , ] ) ; if ( isset ( $ queryParams [ 'accept' ] ) ) { if ( 'application/calendar+json' === $ queryParams [ 'accept' ] || 'jcal' === $ queryParams [ 'accept' ] ) { $ format = 'application/calendar+json' ; } } if ( ! $ format ) { $ format = 'text/calendar' ; } $ this -> generateResponse ( $ path , $ start , $ end , $ expand , $ componentType , $ format , $ properties , $ response ) ; return false ; } | Intercepts GET requests on calendar urls ending with ?export . |
13,746 | public function mergeObjects ( array $ properties , array $ inputObjects ) { $ calendar = new VObject \ Component \ VCalendar ( ) ; $ calendar -> VERSION = '2.0' ; if ( DAV \ Server :: $ exposeVersion ) { $ calendar -> PRODID = '-//SabreDAV//SabreDAV ' . DAV \ Version :: VERSION . '//EN' ; } else { $ calendar -> PRODID = '-//SabreDAV//SabreDAV//EN' ; } if ( isset ( $ properties [ '{DAV:}displayname' ] ) ) { $ calendar -> { 'X-WR-CALNAME' } = $ properties [ '{DAV:}displayname' ] ; } if ( isset ( $ properties [ '{http://apple.com/ns/ical/}calendar-color' ] ) ) { $ calendar -> { 'X-APPLE-CALENDAR-COLOR' } = $ properties [ '{http://apple.com/ns/ical/}calendar-color' ] ; } $ collectedTimezones = [ ] ; $ timezones = [ ] ; $ objects = [ ] ; foreach ( $ inputObjects as $ href => $ inputObject ) { $ nodeComp = VObject \ Reader :: read ( $ inputObject ) ; foreach ( $ nodeComp -> children ( ) as $ child ) { switch ( $ child -> name ) { case 'VEVENT' : case 'VTODO' : case 'VJOURNAL' : $ objects [ ] = clone $ child ; break ; case 'VTIMEZONE' : if ( in_array ( ( string ) $ child -> TZID , $ collectedTimezones ) ) { break ; } $ timezones [ ] = clone $ child ; $ collectedTimezones [ ] = $ child -> TZID ; break ; } } $ nodeComp -> destroy ( ) ; unset ( $ nodeComp ) ; } foreach ( $ timezones as $ tz ) { $ calendar -> add ( $ tz ) ; } foreach ( $ objects as $ obj ) { $ calendar -> add ( $ obj ) ; } return $ calendar ; } | Merges all calendar objects and builds one big iCalendar blob . |
13,747 | public function getNodeForPath ( $ path ) { $ path = trim ( $ path , '/' ) ; if ( isset ( $ this -> cache [ $ path ] ) ) { return $ this -> cache [ $ path ] ; } if ( ! strlen ( $ path ) ) { return $ this -> rootNode ; } list ( $ parentName , $ baseName ) = Uri \ split ( $ path ) ; if ( '' === $ parentName ) { $ node = $ this -> rootNode -> getChild ( $ baseName ) ; } else { $ parent = $ this -> getNodeForPath ( $ parentName ) ; if ( ! ( $ parent instanceof ICollection ) ) { throw new Exception \ NotFound ( 'Could not find node at path: ' . $ path ) ; } $ node = $ parent -> getChild ( $ baseName ) ; } $ this -> cache [ $ path ] = $ node ; return $ node ; } | Returns the INode object for the requested path . |
13,748 | public function nodeExists ( $ path ) { try { if ( '' === $ path ) { return true ; } list ( $ parent , $ base ) = Uri \ split ( $ path ) ; $ parentNode = $ this -> getNodeForPath ( $ parent ) ; if ( ! $ parentNode instanceof ICollection ) { return false ; } return $ parentNode -> childExists ( $ base ) ; } catch ( Exception \ NotFound $ e ) { return false ; } } | This function allows you to check if a node exists . |
13,749 | public function copy ( $ sourcePath , $ destinationPath ) { $ sourceNode = $ this -> getNodeForPath ( $ sourcePath ) ; list ( $ destinationDir , $ destinationName ) = Uri \ split ( $ destinationPath ) ; $ destinationParent = $ this -> getNodeForPath ( $ destinationDir ) ; if ( ! $ destinationParent instanceof ICopyTarget || ! $ destinationParent -> copyInto ( $ destinationName , $ sourcePath , $ sourceNode ) ) { $ this -> copyNode ( $ sourceNode , $ destinationParent , $ destinationName ) ; } $ this -> markDirty ( $ destinationDir ) ; } | Copies a file from path to another . |
13,750 | public function move ( $ sourcePath , $ destinationPath ) { list ( $ sourceDir ) = Uri \ split ( $ sourcePath ) ; list ( $ destinationDir , $ destinationName ) = Uri \ split ( $ destinationPath ) ; if ( $ sourceDir === $ destinationDir ) { $ sourceNode = $ this -> getNodeForPath ( $ sourcePath ) ; $ sourceNode -> setName ( $ destinationName ) ; } else { $ newParentNode = $ this -> getNodeForPath ( $ destinationDir ) ; $ moveSuccess = false ; if ( $ newParentNode instanceof IMoveTarget ) { $ sourceNode = $ this -> getNodeForPath ( $ sourcePath ) ; $ moveSuccess = $ newParentNode -> moveInto ( $ destinationName , $ sourcePath , $ sourceNode ) ; } if ( ! $ moveSuccess ) { $ this -> copy ( $ sourcePath , $ destinationPath ) ; $ this -> getNodeForPath ( $ sourcePath ) -> delete ( ) ; } } $ this -> markDirty ( $ sourceDir ) ; $ this -> markDirty ( $ destinationDir ) ; } | Moves a file from one location to another . |
13,751 | public function delete ( $ path ) { $ node = $ this -> getNodeForPath ( $ path ) ; $ node -> delete ( ) ; list ( $ parent ) = Uri \ split ( $ path ) ; $ this -> markDirty ( $ parent ) ; } | Deletes a node from the tree . |
13,752 | public function getChildren ( $ path ) { $ node = $ this -> getNodeForPath ( $ path ) ; $ basePath = trim ( $ path , '/' ) ; if ( '' !== $ basePath ) { $ basePath .= '/' ; } foreach ( $ node -> getChildren ( ) as $ child ) { $ this -> cache [ $ basePath . $ child -> getName ( ) ] = $ child ; yield $ child ; } } | Returns a list of childnodes for a given path . |
13,753 | public function markDirty ( $ path ) { $ path = trim ( $ path , '/' ) ; foreach ( $ this -> cache as $ nodePath => $ node ) { if ( '' === $ path || $ nodePath == $ path || 0 === strpos ( $ nodePath , $ path . '/' ) ) { unset ( $ this -> cache [ $ nodePath ] ) ; } } } | This method is called with every tree update . |
13,754 | public function getMultipleNodes ( $ paths ) { $ parents = [ ] ; foreach ( $ paths as $ path ) { list ( $ parent , $ node ) = Uri \ split ( $ path ) ; if ( ! isset ( $ parents [ $ parent ] ) ) { $ parents [ $ parent ] = [ $ node ] ; } else { $ parents [ $ parent ] [ ] = $ node ; } } $ result = [ ] ; foreach ( $ parents as $ parent => $ children ) { $ parentNode = $ this -> getNodeForPath ( $ parent ) ; if ( $ parentNode instanceof IMultiGet ) { foreach ( $ parentNode -> getMultipleChildren ( $ children ) as $ childNode ) { $ fullPath = $ parent . '/' . $ childNode -> getName ( ) ; $ result [ $ fullPath ] = $ childNode ; $ this -> cache [ $ fullPath ] = $ childNode ; } } else { foreach ( $ children as $ child ) { $ fullPath = $ parent . '/' . $ child ; $ result [ $ fullPath ] = $ this -> getNodeForPath ( $ fullPath ) ; } } } return $ result ; } | This method tells the tree system to pre - fetch and cache a list of children of a single parent . |
13,755 | public function put ( $ data ) { file_put_contents ( $ this -> path , $ data ) ; clearstatcache ( true , $ this -> path ) ; return $ this -> getETag ( ) ; } | Updates the data . |
13,756 | public function patch ( $ data , $ rangeType , $ offset = null ) { switch ( $ rangeType ) { case 1 : $ f = fopen ( $ this -> path , 'a' ) ; break ; case 2 : $ f = fopen ( $ this -> path , 'c' ) ; fseek ( $ f , $ offset ) ; break ; case 3 : $ f = fopen ( $ this -> path , 'c' ) ; fseek ( $ f , $ offset , SEEK_END ) ; break ; } if ( is_string ( $ data ) ) { fwrite ( $ f , $ data ) ; } else { stream_copy_to_stream ( $ data , $ f ) ; } fclose ( $ f ) ; clearstatcache ( true , $ this -> path ) ; return $ this -> getETag ( ) ; } | Updates the file based on a range specification . |
13,757 | public function getCalendarHomeForPrincipal ( $ principalUrl ) { $ parts = explode ( '/' , trim ( $ principalUrl , '/' ) ) ; if ( 2 !== count ( $ parts ) ) { return ; } if ( 'principals' !== $ parts [ 0 ] ) { return ; } return self :: CALENDAR_ROOT . '/' . $ parts [ 1 ] ; } | Returns the path to a principal s calendar home . |
13,758 | public function report ( $ reportName , $ report , $ path ) { switch ( $ reportName ) { case '{' . self :: NS_CALDAV . '}calendar-multiget' : $ this -> server -> transactionType = 'report-calendar-multiget' ; $ this -> calendarMultiGetReport ( $ report ) ; return false ; case '{' . self :: NS_CALDAV . '}calendar-query' : $ this -> server -> transactionType = 'report-calendar-query' ; $ this -> calendarQueryReport ( $ report ) ; return false ; case '{' . self :: NS_CALDAV . '}free-busy-query' : $ this -> server -> transactionType = 'report-free-busy-query' ; $ this -> freeBusyQueryReport ( $ report ) ; return false ; } } | This functions handles REPORT requests specific to CalDAV . |
13,759 | public function httpMkCalendar ( RequestInterface $ request , ResponseInterface $ response ) { $ body = $ request -> getBodyAsString ( ) ; $ path = $ request -> getPath ( ) ; $ properties = [ ] ; if ( $ body ) { try { $ mkcalendar = $ this -> server -> xml -> expect ( '{urn:ietf:params:xml:ns:caldav}mkcalendar' , $ body ) ; } catch ( \ Sabre \ Xml \ ParseException $ e ) { throw new BadRequest ( $ e -> getMessage ( ) , 0 , $ e ) ; } $ properties = $ mkcalendar -> getProperties ( ) ; } if ( isset ( $ properties [ '{DAV:}resourcetype' ] ) ) { $ resourceType = $ properties [ '{DAV:}resourcetype' ] -> getValue ( ) ; } else { $ resourceType = [ '{DAV:}collection' , '{urn:ietf:params:xml:ns:caldav}calendar' ] ; } $ this -> server -> createCollection ( $ path , new MkCol ( $ resourceType , $ properties ) ) ; $ response -> setStatus ( 201 ) ; $ response -> setHeader ( 'Content-Length' , 0 ) ; return false ; } | This function handles the MKCALENDAR HTTP method which creates a new calendar . |
13,760 | public function calendarMultiGetReport ( $ report ) { $ needsJson = 'application/calendar+json' === $ report -> contentType ; $ timeZones = [ ] ; $ propertyList = [ ] ; $ paths = array_map ( [ $ this -> server , 'calculateUri' ] , $ report -> hrefs ) ; foreach ( $ this -> server -> getPropertiesForMultiplePaths ( $ paths , $ report -> properties ) as $ uri => $ objProps ) { if ( ( $ needsJson || $ report -> expand ) && isset ( $ objProps [ 200 ] [ '{' . self :: NS_CALDAV . '}calendar-data' ] ) ) { $ vObject = VObject \ Reader :: read ( $ objProps [ 200 ] [ '{' . self :: NS_CALDAV . '}calendar-data' ] ) ; if ( $ report -> expand ) { list ( $ calendarPath ) = Uri \ split ( $ uri ) ; if ( ! isset ( $ timeZones [ $ calendarPath ] ) ) { $ tzProp = '{' . self :: NS_CALDAV . '}calendar-timezone' ; $ tzResult = $ this -> server -> getProperties ( $ calendarPath , [ $ tzProp ] ) ; if ( isset ( $ tzResult [ $ tzProp ] ) ) { $ vtimezoneObj = VObject \ Reader :: read ( $ tzResult [ $ tzProp ] ) ; $ timeZone = $ vtimezoneObj -> VTIMEZONE -> getTimeZone ( ) ; } else { $ timeZone = new DateTimeZone ( 'UTC' ) ; } $ timeZones [ $ calendarPath ] = $ timeZone ; } $ vObject = $ vObject -> expand ( $ report -> expand [ 'start' ] , $ report -> expand [ 'end' ] , $ timeZones [ $ calendarPath ] ) ; } if ( $ needsJson ) { $ objProps [ 200 ] [ '{' . self :: NS_CALDAV . '}calendar-data' ] = json_encode ( $ vObject -> jsonSerialize ( ) ) ; } else { $ objProps [ 200 ] [ '{' . self :: NS_CALDAV . '}calendar-data' ] = $ vObject -> serialize ( ) ; } $ vObject -> destroy ( ) ; } $ propertyList [ ] = $ objProps ; } $ prefer = $ this -> server -> getHTTPPrefer ( ) ; $ this -> server -> httpResponse -> setStatus ( 207 ) ; $ this -> server -> httpResponse -> setHeader ( 'Content-Type' , 'application/xml; charset=utf-8' ) ; $ this -> server -> httpResponse -> setHeader ( 'Vary' , 'Brief,Prefer' ) ; $ this -> server -> httpResponse -> setBody ( $ this -> server -> generateMultiStatus ( $ propertyList , 'minimal' === $ prefer [ 'return' ] ) ) ; } | This function handles the calendar - multiget REPORT . |
13,761 | public function getSupportedPrivilegeSet ( INode $ node , array & $ supportedPrivilegeSet ) { if ( $ node instanceof ICalendar ) { $ supportedPrivilegeSet [ '{DAV:}read' ] [ 'aggregates' ] [ '{' . self :: NS_CALDAV . '}read-free-busy' ] = [ 'abstract' => false , 'aggregates' => [ ] , ] ; } } | This method is triggered whenever a subsystem reqeuests the privileges that are supported on a particular node . |
13,762 | public function htmlActionsPanel ( DAV \ INode $ node , & $ output ) { if ( ! $ node instanceof CalendarHome ) { return ; } $ output .= '<tr><td colspan="2"><form method="post" action=""> <h3>Create new calendar</h3> <input type="hidden" name="sabreAction" value="mkcol" /> <input type="hidden" name="resourceType" value="{DAV:}collection,{' . self :: NS_CALDAV . '}calendar" /> <label>Name (uri):</label> <input type="text" name="name" /><br /> <label>Display name:</label> <input type="text" name="{DAV:}displayname" /><br /> <input type="submit" value="create" /> </form> </td></tr>' ; return false ; } | This method is used to generate HTML output for the DAV \ Browser \ Plugin . This allows us to generate an interface users can use to create new calendars . |
13,763 | public function validate ( VObject \ Component \ VCalendar $ vObject , array $ filters ) { if ( $ vObject -> name !== $ filters [ 'name' ] ) { return false ; } return $ this -> validateCompFilters ( $ vObject , $ filters [ 'comp-filters' ] ) && $ this -> validatePropFilters ( $ vObject , $ filters [ 'prop-filters' ] ) ; } | Verify if a list of filters applies to the calendar data object . |
13,764 | protected function validateCompFilters ( VObject \ Component $ parent , array $ filters ) { foreach ( $ filters as $ filter ) { $ isDefined = isset ( $ parent -> { $ filter [ 'name' ] } ) ; if ( $ filter [ 'is-not-defined' ] ) { if ( $ isDefined ) { return false ; } else { continue ; } } if ( ! $ isDefined ) { return false ; } if ( $ filter [ 'time-range' ] ) { foreach ( $ parent -> { $ filter [ 'name' ] } as $ subComponent ) { if ( $ this -> validateTimeRange ( $ subComponent , $ filter [ 'time-range' ] [ 'start' ] , $ filter [ 'time-range' ] [ 'end' ] ) ) { continue 2 ; } } return false ; } if ( ! $ filter [ 'comp-filters' ] && ! $ filter [ 'prop-filters' ] ) { continue ; } foreach ( $ parent -> { $ filter [ 'name' ] } as $ subComponent ) { if ( $ this -> validateCompFilters ( $ subComponent , $ filter [ 'comp-filters' ] ) && $ this -> validatePropFilters ( $ subComponent , $ filter [ 'prop-filters' ] ) ) { continue 2 ; } } return false ; } return true ; } | This method checks the validity of comp - filters . |
13,765 | protected function validateParamFilters ( VObject \ Property $ parent , array $ filters ) { foreach ( $ filters as $ filter ) { $ isDefined = isset ( $ parent [ $ filter [ 'name' ] ] ) ; if ( $ filter [ 'is-not-defined' ] ) { if ( $ isDefined ) { return false ; } else { continue ; } } if ( ! $ isDefined ) { return false ; } if ( ! $ filter [ 'text-match' ] ) { continue ; } foreach ( $ parent [ $ filter [ 'name' ] ] -> getParts ( ) as $ paramPart ) { if ( $ this -> validateTextMatch ( $ paramPart , $ filter [ 'text-match' ] ) ) { continue 2 ; } } return false ; } return true ; } | This method checks the validity of param - filters . |
13,766 | protected function validateTextMatch ( $ check , array $ textMatch ) { if ( $ check instanceof VObject \ Node ) { $ check = $ check -> getValue ( ) ; } $ isMatching = \ Sabre \ DAV \ StringUtil :: textMatch ( $ check , $ textMatch [ 'value' ] , $ textMatch [ 'collation' ] ) ; return $ textMatch [ 'negate-condition' ] xor $ isMatching ; } | This method checks the validity of a text - match . |
13,767 | protected function validateTimeRange ( VObject \ Node $ component , $ start , $ end ) { if ( is_null ( $ start ) ) { $ start = new DateTime ( '1900-01-01' ) ; } if ( is_null ( $ end ) ) { $ end = new DateTime ( '3000-01-01' ) ; } switch ( $ component -> name ) { case 'VEVENT' : case 'VTODO' : case 'VJOURNAL' : return $ component -> isInTimeRange ( $ start , $ end ) ; case 'VALARM' : if ( 'VEVENT' === $ component -> parent -> name && $ component -> parent -> RRULE ) { $ it = new VObject \ Recur \ EventIterator ( $ component -> parent -> parent , ( string ) $ component -> parent -> UID ) ; while ( $ it -> valid ( ) ) { $ expandedEvent = $ it -> getEventObject ( ) ; $ firstAlarm = null ; if ( null !== $ expandedEvent -> VALARM ) { foreach ( $ expandedEvent -> VALARM as $ expandedAlarm ) { $ effectiveTrigger = $ expandedAlarm -> getEffectiveTriggerTime ( ) ; if ( $ expandedAlarm -> isInTimeRange ( $ start , $ end ) ) { return true ; } if ( 'DATE-TIME' === ( string ) $ expandedAlarm -> TRIGGER [ 'VALUE' ] ) { } else { if ( ! $ firstAlarm || $ effectiveTrigger < $ firstAlarm ) { $ firstAlarm = $ effectiveTrigger ; } } } } if ( is_null ( $ firstAlarm ) ) { return false ; } if ( $ firstAlarm > $ end ) { return false ; } $ it -> next ( ) ; } return false ; } else { return $ component -> isInTimeRange ( $ start , $ end ) ; } case 'VFREEBUSY' : throw new \ Sabre \ DAV \ Exception \ NotImplemented ( 'time-range filters are currently not supported on ' . $ component -> name . ' components' ) ; case 'COMPLETED' : case 'CREATED' : case 'DTEND' : case 'DTSTAMP' : case 'DTSTART' : case 'DUE' : case 'LAST-MODIFIED' : return $ start <= $ component -> getDateTime ( ) && $ end >= $ component -> getDateTime ( ) ; default : throw new \ Sabre \ DAV \ Exception \ BadRequest ( 'You cannot create a time-range filter on a ' . $ component -> name . ' component' ) ; } } | Validates if a component matches the given time range . |
13,768 | public function propFind ( PropFind $ propFind , INode $ node ) { $ propFind -> handle ( '{DAV:}getcontenttype' , function ( ) use ( $ propFind ) { list ( , $ fileName ) = Uri \ split ( $ propFind -> getPath ( ) ) ; return $ this -> getContentType ( $ fileName ) ; } ) ; } | Our PROPFIND handler . |
13,769 | protected function getContentType ( $ fileName ) { $ extension = strtolower ( substr ( $ fileName , strrpos ( $ fileName , '.' ) + 1 ) ) ; if ( isset ( $ this -> extensionMap [ $ extension ] ) ) { return $ this -> extensionMap [ $ extension ] ; } return 'application/octet-stream' ; } | Simple method to return the contenttype . |
13,770 | public function getDigestHash ( $ realm , $ username ) { $ stmt = $ this -> pdo -> prepare ( 'SELECT digesta1 FROM ' . $ this -> tableName . ' WHERE username = ?' ) ; $ stmt -> execute ( [ $ username ] ) ; return $ stmt -> fetchColumn ( ) ? : null ; } | Returns the digest hash for a user . |
13,771 | public function handleRemaining ( callable $ callback ) { $ properties = $ this -> getRemainingMutations ( ) ; if ( ! $ properties ) { return ; } foreach ( $ properties as $ propertyName ) { $ this -> result [ $ propertyName ] = 202 ; $ this -> propertyUpdateCallbacks [ ] = [ $ properties , $ callback , ] ; } } | Call this function if you wish to handle _all_ properties that haven t been handled by anything else yet . Note that you effectively claim with this that you promise to process _all_ properties that are coming in . |
13,772 | public function setResultCode ( $ properties , $ resultCode ) { foreach ( ( array ) $ properties as $ propertyName ) { $ this -> result [ $ propertyName ] = $ resultCode ; } if ( $ resultCode >= 400 ) { $ this -> failed = true ; } } | Sets the result code for one or more properties . |
13,773 | public function getRemainingMutations ( ) { $ remaining = [ ] ; foreach ( $ this -> mutations as $ propertyName => $ propValue ) { if ( ! isset ( $ this -> result [ $ propertyName ] ) ) { $ remaining [ ] = $ propertyName ; } } return $ remaining ; } | Returns the list of properties that don t have a result code yet . |
13,774 | public function commit ( ) { foreach ( $ this -> mutations as $ propertyName => $ value ) { if ( ! isset ( $ this -> result [ $ propertyName ] ) ) { $ this -> failed = true ; $ this -> result [ $ propertyName ] = 403 ; } } foreach ( $ this -> propertyUpdateCallbacks as $ callbackInfo ) { if ( $ this -> failed ) { break ; } if ( is_string ( $ callbackInfo [ 0 ] ) ) { $ this -> doCallbackSingleProp ( $ callbackInfo [ 0 ] , $ callbackInfo [ 1 ] ) ; } else { $ this -> doCallbackMultiProp ( $ callbackInfo [ 0 ] , $ callbackInfo [ 1 ] ) ; } } if ( $ this -> failed ) { foreach ( $ this -> result as $ propertyName => $ status ) { if ( 202 === $ status ) { $ this -> result [ $ propertyName ] = 424 ; } } } return ! $ this -> failed ; } | Performs the actual update and calls all callbacks . |
13,775 | private function doCallBackSingleProp ( $ propertyName , callable $ callback ) { $ result = $ callback ( $ this -> mutations [ $ propertyName ] ) ; if ( is_bool ( $ result ) ) { if ( $ result ) { if ( is_null ( $ this -> mutations [ $ propertyName ] ) ) { $ result = 204 ; } else { $ result = 200 ; } } else { $ result = 403 ; } } if ( ! is_int ( $ result ) ) { throw new UnexpectedValueException ( 'A callback sent to handle() did not return an int or a bool' ) ; } $ this -> result [ $ propertyName ] = $ result ; if ( $ result >= 400 ) { $ this -> failed = true ; } } | Executes a property callback with the single - property syntax . |
13,776 | private function doCallBackMultiProp ( array $ propertyList , callable $ callback ) { $ argument = [ ] ; foreach ( $ propertyList as $ propertyName ) { $ argument [ $ propertyName ] = $ this -> mutations [ $ propertyName ] ; } $ result = $ callback ( $ argument ) ; if ( is_array ( $ result ) ) { foreach ( $ propertyList as $ propertyName ) { if ( ! isset ( $ result [ $ propertyName ] ) ) { $ resultCode = 500 ; } else { $ resultCode = $ result [ $ propertyName ] ; } if ( $ resultCode >= 400 ) { $ this -> failed = true ; } $ this -> result [ $ propertyName ] = $ resultCode ; } } elseif ( true === $ result ) { foreach ( $ argument as $ propertyName => $ propertyValue ) { $ this -> result [ $ propertyName ] = is_null ( $ propertyValue ) ? 204 : 200 ; } } elseif ( false === $ result ) { $ this -> failed = true ; foreach ( $ propertyList as $ propertyName ) { $ this -> result [ $ propertyName ] = 403 ; } } else { throw new UnexpectedValueException ( 'A callback sent to handle() did not return an array or a bool' ) ; } } | Executes a property callback with the multi - property syntax . |
13,777 | public function xmlName ( $ element ) { list ( $ ns , $ localName ) = XmlService :: parseClarkNotation ( $ element ) ; if ( isset ( $ this -> namespaceMap [ $ ns ] ) ) { $ propName = $ this -> namespaceMap [ $ ns ] . ':' . $ localName ; } else { $ propName = $ element ; } return '<span title="' . $ this -> h ( $ element ) . '">' . $ this -> h ( $ propName ) . '</span>' ; } | This method takes an xml element in clark - notation and turns it into a shortened version with a prefix if it was a known namespace . |
13,778 | private function serializePriv ( Writer $ writer , $ privName , $ privilege ) { $ writer -> startElement ( '{DAV:}supported-privilege' ) ; $ writer -> startElement ( '{DAV:}privilege' ) ; $ writer -> writeElement ( $ privName ) ; $ writer -> endElement ( ) ; if ( ! empty ( $ privilege [ 'abstract' ] ) ) { $ writer -> writeElement ( '{DAV:}abstract' ) ; } if ( ! empty ( $ privilege [ 'description' ] ) ) { $ writer -> writeElement ( '{DAV:}description' , $ privilege [ 'description' ] ) ; } if ( isset ( $ privilege [ 'aggregates' ] ) ) { foreach ( $ privilege [ 'aggregates' ] as $ subPrivName => $ subPrivilege ) { $ this -> serializePriv ( $ writer , $ subPrivName , $ subPrivilege ) ; } } $ writer -> endElement ( ) ; } | Serializes a property . |
13,779 | public function get ( ) { if ( ! isset ( $ this -> cardData [ 'carddata' ] ) ) { $ this -> cardData = $ this -> carddavBackend -> getCard ( $ this -> addressBookInfo [ 'id' ] , $ this -> cardData [ 'uri' ] ) ; } return $ this -> cardData [ 'carddata' ] ; } | Returns the VCard - formatted object . |
13,780 | public function put ( $ cardData ) { if ( is_resource ( $ cardData ) ) { $ cardData = stream_get_contents ( $ cardData ) ; } $ cardData = DAV \ StringUtil :: ensureUTF8 ( $ cardData ) ; $ etag = $ this -> carddavBackend -> updateCard ( $ this -> addressBookInfo [ 'id' ] , $ this -> cardData [ 'uri' ] , $ cardData ) ; $ this -> cardData [ 'carddata' ] = $ cardData ; $ this -> cardData [ 'etag' ] = $ etag ; return $ etag ; } | Updates the VCard - formatted object . |
13,781 | public function getETag ( ) { if ( isset ( $ this -> cardData [ 'etag' ] ) ) { return $ this -> cardData [ 'etag' ] ; } else { $ data = $ this -> get ( ) ; if ( is_string ( $ data ) ) { return '"' . md5 ( $ data ) . '"' ; } else { return null ; } } } | Returns an ETag for this object . |
13,782 | public function beforeMethod ( RequestInterface $ request , ResponseInterface $ response ) { if ( $ this -> currentPrincipal ) { return ; } $ authResult = $ this -> check ( $ request , $ response ) ; if ( $ authResult [ 0 ] ) { $ this -> currentPrincipal = $ authResult [ 1 ] ; $ this -> loginFailedReasons = null ; return ; } $ this -> currentPrincipal = null ; $ this -> loginFailedReasons = $ authResult [ 1 ] ; if ( $ this -> autoRequireLogin ) { $ this -> challenge ( $ request , $ response ) ; throw new NotAuthenticated ( implode ( ', ' , $ authResult [ 1 ] ) ) ; } } | This method is called before any HTTP method and forces users to be authenticated . |
13,783 | public function check ( RequestInterface $ request , ResponseInterface $ response ) { if ( ! $ this -> backends ) { throw new \ Sabre \ DAV \ Exception ( 'No authentication backends were configured on this server.' ) ; } $ reasons = [ ] ; foreach ( $ this -> backends as $ backend ) { $ result = $ backend -> check ( $ request , $ response ) ; if ( ! is_array ( $ result ) || 2 !== count ( $ result ) || ! is_bool ( $ result [ 0 ] ) || ! is_string ( $ result [ 1 ] ) ) { throw new \ Sabre \ DAV \ Exception ( 'The authentication backend did not return a correct value from the check() method.' ) ; } if ( $ result [ 0 ] ) { $ this -> currentPrincipal = $ result [ 1 ] ; return [ true , $ result [ 1 ] ] ; } $ reasons [ ] = $ result [ 1 ] ; } return [ false , $ reasons ] ; } | Checks authentication credentials and logs the user in if possible . |
13,784 | public function challenge ( RequestInterface $ request , ResponseInterface $ response ) { foreach ( $ this -> backends as $ backend ) { $ backend -> challenge ( $ request , $ response ) ; } } | This method sends authentication challenges to the user . |
13,785 | public function getChild ( $ name ) { foreach ( $ this -> getChildren ( ) as $ child ) { if ( $ name == $ child -> getName ( ) ) { return $ child ; } } throw new DAV \ Exception \ NotFound ( 'Addressbook with name \'' . $ name . '\' could not be found' ) ; } | Returns a single addressbook by name . |
13,786 | public function getChildren ( ) { $ addressbooks = $ this -> carddavBackend -> getAddressBooksForUser ( $ this -> principalUri ) ; $ objs = [ ] ; foreach ( $ addressbooks as $ addressbook ) { $ objs [ ] = new AddressBook ( $ this -> carddavBackend , $ addressbook ) ; } return $ objs ; } | Returns a list of addressbooks . |
13,787 | public function httpGet ( RequestInterface $ request , ResponseInterface $ response ) { $ path = $ request -> getPath ( ) ; try { $ node = $ this -> server -> tree -> getNodeForPath ( $ path ) ; } catch ( DAV \ Exception \ NotFound $ e ) { return ; } if ( ! $ node instanceof INode ) { return ; } $ writer = $ this -> server -> xml -> getWriter ( ) ; $ writer -> contextUri = $ this -> server -> getBaseUri ( ) ; $ writer -> openMemory ( ) ; $ writer -> startDocument ( '1.0' , 'UTF-8' ) ; $ writer -> startElement ( '{http://calendarserver.org/ns/}notification' ) ; $ node -> getNotificationType ( ) -> xmlSerializeFull ( $ writer ) ; $ writer -> endElement ( ) ; $ response -> setHeader ( 'Content-Type' , 'application/xml' ) ; $ response -> setHeader ( 'ETag' , $ node -> getETag ( ) ) ; $ response -> setStatus ( 200 ) ; $ response -> setBody ( $ writer -> outputMemory ( ) ) ; return false ; } | This event is triggered before the usual GET request handler . |
13,788 | public function propFindEarly ( DAV \ PropFind $ propFind , DAV \ INode $ node ) { $ ns = '{' . self :: NS_CARDDAV . '}' ; if ( $ node instanceof IAddressBook ) { $ propFind -> handle ( $ ns . 'max-resource-size' , $ this -> maxResourceSize ) ; $ propFind -> handle ( $ ns . 'supported-address-data' , function ( ) { return new Xml \ Property \ SupportedAddressData ( ) ; } ) ; $ propFind -> handle ( $ ns . 'supported-collation-set' , function ( ) { return new Xml \ Property \ SupportedCollationSet ( ) ; } ) ; } if ( $ node instanceof DAVACL \ IPrincipal ) { $ path = $ propFind -> getPath ( ) ; $ propFind -> handle ( '{' . self :: NS_CARDDAV . '}addressbook-home-set' , function ( ) use ( $ path ) { return new LocalHref ( $ this -> getAddressBookHomeForPrincipal ( $ path ) . '/' ) ; } ) ; if ( $ this -> directories ) { $ propFind -> handle ( '{' . self :: NS_CARDDAV . '}directory-gateway' , function ( ) { return new LocalHref ( $ this -> directories ) ; } ) ; } } if ( $ node instanceof ICard ) { $ propFind -> handle ( '{' . self :: NS_CARDDAV . '}address-data' , function ( ) use ( $ node ) { $ val = $ node -> get ( ) ; if ( is_resource ( $ val ) ) { $ val = stream_get_contents ( $ val ) ; } return $ val ; } ) ; } } | Adds all CardDAV - specific properties . |
13,789 | public function report ( $ reportName , $ dom , $ path ) { switch ( $ reportName ) { case '{' . self :: NS_CARDDAV . '}addressbook-multiget' : $ this -> server -> transactionType = 'report-addressbook-multiget' ; $ this -> addressbookMultiGetReport ( $ dom ) ; return false ; case '{' . self :: NS_CARDDAV . '}addressbook-query' : $ this -> server -> transactionType = 'report-addressbook-query' ; $ this -> addressBookQueryReport ( $ dom ) ; return false ; default : return ; } } | This functions handles REPORT requests specific to CardDAV . |
13,790 | protected function getAddressbookHomeForPrincipal ( $ principal ) { list ( , $ principalId ) = Uri \ split ( $ principal ) ; return self :: ADDRESSBOOK_ROOT . '/' . $ principalId ; } | Returns the addressbook home for a given principal . |
13,791 | public function addressbookMultiGetReport ( $ report ) { $ contentType = $ report -> contentType ; $ version = $ report -> version ; if ( $ version ) { $ contentType .= '; version=' . $ version ; } $ vcardType = $ this -> negotiateVCard ( $ contentType ) ; $ propertyList = [ ] ; $ paths = array_map ( [ $ this -> server , 'calculateUri' ] , $ report -> hrefs ) ; foreach ( $ this -> server -> getPropertiesForMultiplePaths ( $ paths , $ report -> properties ) as $ props ) { if ( isset ( $ props [ '200' ] [ '{' . self :: NS_CARDDAV . '}address-data' ] ) ) { $ props [ '200' ] [ '{' . self :: NS_CARDDAV . '}address-data' ] = $ this -> convertVCard ( $ props [ 200 ] [ '{' . self :: NS_CARDDAV . '}address-data' ] , $ vcardType ) ; } $ propertyList [ ] = $ props ; } $ prefer = $ this -> server -> getHTTPPrefer ( ) ; $ this -> server -> httpResponse -> setStatus ( 207 ) ; $ this -> server -> httpResponse -> setHeader ( 'Content-Type' , 'application/xml; charset=utf-8' ) ; $ this -> server -> httpResponse -> setHeader ( 'Vary' , 'Brief,Prefer' ) ; $ this -> server -> httpResponse -> setBody ( $ this -> server -> generateMultiStatus ( $ propertyList , 'minimal' === $ prefer [ 'return' ] ) ) ; } | This function handles the addressbook - multiget REPORT . |
13,792 | protected function addressbookQueryReport ( $ report ) { $ depth = $ this -> server -> getHTTPDepth ( 0 ) ; if ( 0 == $ depth ) { $ candidateNodes = [ $ this -> server -> tree -> getNodeForPath ( $ this -> server -> getRequestUri ( ) ) , ] ; if ( ! $ candidateNodes [ 0 ] instanceof ICard ) { throw new ReportNotSupported ( 'The addressbook-query report is not supported on this url with Depth: 0' ) ; } } else { $ candidateNodes = $ this -> server -> tree -> getChildren ( $ this -> server -> getRequestUri ( ) ) ; } $ contentType = $ report -> contentType ; if ( $ report -> version ) { $ contentType .= '; version=' . $ report -> version ; } $ vcardType = $ this -> negotiateVCard ( $ contentType ) ; $ validNodes = [ ] ; foreach ( $ candidateNodes as $ node ) { if ( ! $ node instanceof ICard ) { continue ; } $ blob = $ node -> get ( ) ; if ( is_resource ( $ blob ) ) { $ blob = stream_get_contents ( $ blob ) ; } if ( ! $ this -> validateFilters ( $ blob , $ report -> filters , $ report -> test ) ) { continue ; } $ validNodes [ ] = $ node ; if ( $ report -> limit && $ report -> limit <= count ( $ validNodes ) ) { break ; } } $ result = [ ] ; foreach ( $ validNodes as $ validNode ) { if ( 0 == $ depth ) { $ href = $ this -> server -> getRequestUri ( ) ; } else { $ href = $ this -> server -> getRequestUri ( ) . '/' . $ validNode -> getName ( ) ; } list ( $ props ) = $ this -> server -> getPropertiesForPath ( $ href , $ report -> properties , 0 ) ; if ( isset ( $ props [ 200 ] [ '{' . self :: NS_CARDDAV . '}address-data' ] ) ) { $ props [ 200 ] [ '{' . self :: NS_CARDDAV . '}address-data' ] = $ this -> convertVCard ( $ props [ 200 ] [ '{' . self :: NS_CARDDAV . '}address-data' ] , $ vcardType , $ report -> addressDataProperties ) ; } $ result [ ] = $ props ; } $ prefer = $ this -> server -> getHTTPPrefer ( ) ; $ this -> server -> httpResponse -> setStatus ( 207 ) ; $ this -> server -> httpResponse -> setHeader ( 'Content-Type' , 'application/xml; charset=utf-8' ) ; $ this -> server -> httpResponse -> setHeader ( 'Vary' , 'Brief,Prefer' ) ; $ this -> server -> httpResponse -> setBody ( $ this -> server -> generateMultiStatus ( $ result , 'minimal' === $ prefer [ 'return' ] ) ) ; } | This function handles the addressbook - query REPORT . |
13,793 | public function validateFilters ( $ vcardData , array $ filters , $ test ) { if ( ! $ filters ) { return true ; } $ vcard = VObject \ Reader :: read ( $ vcardData ) ; foreach ( $ filters as $ filter ) { $ isDefined = isset ( $ vcard -> { $ filter [ 'name' ] } ) ; if ( $ filter [ 'is-not-defined' ] ) { if ( $ isDefined ) { $ success = false ; } else { $ success = true ; } } elseif ( ( ! $ filter [ 'param-filters' ] && ! $ filter [ 'text-matches' ] ) || ! $ isDefined ) { $ success = $ isDefined ; } else { $ vProperties = $ vcard -> select ( $ filter [ 'name' ] ) ; $ results = [ ] ; if ( $ filter [ 'param-filters' ] ) { $ results [ ] = $ this -> validateParamFilters ( $ vProperties , $ filter [ 'param-filters' ] , $ filter [ 'test' ] ) ; } if ( $ filter [ 'text-matches' ] ) { $ texts = [ ] ; foreach ( $ vProperties as $ vProperty ) { $ texts [ ] = $ vProperty -> getValue ( ) ; } $ results [ ] = $ this -> validateTextMatches ( $ texts , $ filter [ 'text-matches' ] , $ filter [ 'test' ] ) ; } if ( 1 === count ( $ results ) ) { $ success = $ results [ 0 ] ; } else { if ( 'anyof' === $ filter [ 'test' ] ) { $ success = $ results [ 0 ] || $ results [ 1 ] ; } else { $ success = $ results [ 0 ] && $ results [ 1 ] ; } } } if ( 'anyof' === $ test && $ success ) { $ vcard -> destroy ( ) ; return true ; } if ( 'allof' === $ test && ! $ success ) { $ vcard -> destroy ( ) ; return false ; } } $ vcard -> destroy ( ) ; return 'allof' === $ test ; } | Validates if a vcard makes it throught a list of filters . |
13,794 | protected function validateParamFilters ( array $ vProperties , array $ filters , $ test ) { foreach ( $ filters as $ filter ) { $ isDefined = false ; foreach ( $ vProperties as $ vProperty ) { $ isDefined = isset ( $ vProperty [ $ filter [ 'name' ] ] ) ; if ( $ isDefined ) { break ; } } if ( $ filter [ 'is-not-defined' ] ) { if ( $ isDefined ) { $ success = false ; } else { $ success = true ; } } elseif ( ! $ filter [ 'text-match' ] || ! $ isDefined ) { $ success = $ isDefined ; } else { $ success = false ; foreach ( $ vProperties as $ vProperty ) { $ success = DAV \ StringUtil :: textMatch ( $ vProperty [ $ filter [ 'name' ] ] -> getValue ( ) , $ filter [ 'text-match' ] [ 'value' ] , $ filter [ 'text-match' ] [ 'collation' ] , $ filter [ 'text-match' ] [ 'match-type' ] ) ; if ( $ success ) { break ; } } if ( $ filter [ 'text-match' ] [ 'negate-condition' ] ) { $ success = ! $ success ; } } if ( 'anyof' === $ test && $ success ) { return true ; } if ( 'allof' === $ test && ! $ success ) { return false ; } } return 'allof' === $ test ; } | Validates if a param - filter can be applied to a specific property . |
13,795 | protected function validateTextMatches ( array $ texts , array $ filters , $ test ) { foreach ( $ filters as $ filter ) { $ success = false ; foreach ( $ texts as $ haystack ) { $ success = DAV \ StringUtil :: textMatch ( $ haystack , $ filter [ 'value' ] , $ filter [ 'collation' ] , $ filter [ 'match-type' ] ) ; if ( $ success ) { break ; } } if ( $ filter [ 'negate-condition' ] ) { $ success = ! $ success ; } if ( $ success && 'anyof' === $ test ) { return true ; } if ( ! $ success && 'allof' == $ test ) { return false ; } } return 'allof' === $ test ; } | Validates if a text - filter can be applied to a specific property . |
13,796 | public function propFindLate ( DAV \ PropFind $ propFind , DAV \ INode $ node ) { if ( false === strpos ( ( string ) $ this -> server -> httpRequest -> getHeader ( 'User-Agent' ) , 'Thunderbird' ) ) { return ; } $ contentType = $ propFind -> get ( '{DAV:}getcontenttype' ) ; list ( $ part ) = explode ( ';' , $ contentType ) ; if ( 'text/x-vcard' === $ part || 'text/vcard' === $ part ) { $ propFind -> set ( '{DAV:}getcontenttype' , 'text/x-vcard' ) ; } } | This event is triggered when fetching properties . |
13,797 | public function htmlActionsPanel ( DAV \ INode $ node , & $ output ) { if ( ! $ node instanceof AddressBookHome ) { return ; } $ output .= '<tr><td colspan="2"><form method="post" action=""> <h3>Create new address book</h3> <input type="hidden" name="sabreAction" value="mkcol" /> <input type="hidden" name="resourceType" value="{DAV:}collection,{' . self :: NS_CARDDAV . '}addressbook" /> <label>Name (uri):</label> <input type="text" name="name" /><br /> <label>Display name:</label> <input type="text" name="{DAV:}displayname" /><br /> <input type="submit" value="create" /> </form> </td></tr>' ; return false ; } | This method is used to generate HTML output for the Sabre \ DAV \ Browser \ Plugin . This allows us to generate an interface users can use to create new addressbooks . |
13,798 | protected function negotiateVCard ( $ input , & $ mimeType = null ) { $ result = HTTP \ negotiateContentType ( $ input , [ 'text/x-vcard' , 'text/vcard' , 'text/vcard; version=4.0' , 'text/vcard; version=3.0' , 'application/vcard+json' , ] ) ; $ mimeType = $ result ; switch ( $ result ) { default : case 'text/x-vcard' : case 'text/vcard' : case 'text/vcard; version=3.0' : $ mimeType = 'text/vcard' ; return 'vcard3' ; case 'text/vcard; version=4.0' : return 'vcard4' ; case 'application/vcard+json' : return 'jcard' ; } } | This helper function performs the content - type negotiation for vcards . |
13,799 | protected function convertVCard ( $ data , $ target , array $ propertiesFilter = null ) { if ( is_resource ( $ data ) ) { $ data = stream_get_contents ( $ data ) ; } $ input = VObject \ Reader :: read ( $ data ) ; if ( ! empty ( $ propertiesFilter ) ) { $ propertiesFilter = array_merge ( [ 'UID' , 'VERSION' , 'FN' ] , $ propertiesFilter ) ; $ keys = array_unique ( array_map ( function ( $ child ) { return $ child -> name ; } , $ input -> children ( ) ) ) ; $ keys = array_diff ( $ keys , $ propertiesFilter ) ; foreach ( $ keys as $ key ) { unset ( $ input -> $ key ) ; } $ data = $ input -> serialize ( ) ; } $ output = null ; try { switch ( $ target ) { default : case 'vcard3' : if ( VObject \ Document :: VCARD30 === $ input -> getDocumentType ( ) ) { return $ data ; } $ output = $ input -> convert ( VObject \ Document :: VCARD30 ) ; return $ output -> serialize ( ) ; case 'vcard4' : if ( VObject \ Document :: VCARD40 === $ input -> getDocumentType ( ) ) { return $ data ; } $ output = $ input -> convert ( VObject \ Document :: VCARD40 ) ; return $ output -> serialize ( ) ; case 'jcard' : $ output = $ input -> convert ( VObject \ Document :: VCARD40 ) ; return json_encode ( $ output ) ; } } finally { $ input -> destroy ( ) ; if ( ! is_null ( $ output ) ) { $ output -> destroy ( ) ; } } } | Converts a vcard blob to a different version or jcard . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.