idx
int64 0
60.3k
| question
stringlengths 101
6.21k
| target
stringlengths 7
803
|
|---|---|---|
59,200
|
public function compare ( DocumentationEntity $ other ) { $ v1 = $ this -> getVersion ( ) ; $ v2 = $ other -> getVersion ( ) ; $ dots = substr_count ( $ v1 , '.' ) - substr_count ( $ v2 , '.' ) ; while ( $ dots > 0 ) { $ dots -- ; $ v2 .= '.99999' ; } while ( $ dots < 0 ) { $ dots ++ ; $ v1 .= '.99999' ; } return version_compare ( $ v1 , $ v2 ) ; }
|
Returns an integer value based on if a given version is the latest version . Will return - 1 for if the version is older 0 if versions are the same and 1 if the version is greater than .
|
59,201
|
protected function _initWeight ( Zend_Search_Lucene_Interface $ reader ) { if ( $ this -> _weight !== null ) { return $ this -> _weight ; } $ this -> createWeight ( $ reader ) ; $ sum = $ this -> _weight -> sumOfSquaredWeights ( ) ; $ queryNorm = $ reader -> getSimilarity ( ) -> queryNorm ( $ sum ) ; $ this -> _weight -> normalize ( $ queryNorm ) ; }
|
Constructs an initializes a Weight for a _top - level_query_ .
|
59,202
|
protected function getUserImage ( array $ response , AccessToken $ token ) { $ guid = $ token -> getResourceOwnerId ( ) ; $ url = 'https://social.yahooapis.com/v1/user/' . $ guid . '/profile/image/' . $ this -> imageSize . '?format=json' ; $ request = $ this -> getAuthenticatedRequest ( 'get' , $ url , $ token ) ; $ response = $ this -> getResponse ( $ request ) ; return $ response ; }
|
Get user image from provider
|
59,203
|
protected function getUserImageUrl ( array $ response , AccessToken $ token ) { $ image = $ this -> getUserImage ( $ response , $ token ) ; if ( isset ( $ image [ 'image' ] [ 'imageUrl' ] ) ) { return $ image [ 'image' ] [ 'imageUrl' ] ; } return null ; }
|
Get user image url from provider if available
|
59,204
|
public function withSpecialMark ( $ mark , string $ name = 'default' ) : self { $ this -> special_marks [ $ name ] = $ mark ; return $ this ; }
|
Mark this object
|
59,205
|
protected function makeResult ( $ response , $ method ) { if ( $ method != 'HEAD' && isset ( $ response -> headers -> { 'content-length' } ) && strlen ( $ response -> body ) != $ response -> headers -> { 'content-length' } ) { throw new SagException ( 'Unexpected end of packet.' ) ; } if ( $ method == 'HEAD' ) { if ( $ response -> status >= 400 ) { throw new SagCouchException ( 'HTTP/CouchDB error without message body' , $ response -> headers -> _HTTP -> status ) ; } return $ response ; } if ( ! empty ( $ response -> headers -> { 'content-type' } ) && $ response -> headers -> { 'content-type' } == 'application/json' ) { $ json = json_decode ( $ response -> body ) ; if ( isset ( $ json ) ) { if ( ! empty ( $ json -> error ) ) { throw new SagCouchException ( "{$json->error} ({$json->reason})" , $ response -> headers -> _HTTP -> status ) ; } if ( $ this -> decodeResp ) { $ response -> body = $ json ; } } } return $ response ; }
|
Used by the concrete HTTP adapters this abstracts out the generic task of turning strings from the net into response objects .
|
59,206
|
public function setRWTimeout ( $ seconds , $ microseconds ) { if ( ! is_int ( $ microseconds ) || $ microseconds < 0 ) { throw new SagException ( 'setRWTimeout() expects $microseconds to be an integer >= 0.' ) ; } if ( ! is_int ( $ seconds ) || ( ( ! $ microseconds && $ seconds < 1 ) || ( $ microseconds && $ seconds < 0 ) ) ) { throw new SagException ( 'setRWTimeout() expects $seconds to be a positive integer.' ) ; } $ this -> socketRWTimeoutSeconds = $ seconds ; $ this -> socketRWTimeoutMicroseconds = $ microseconds ; }
|
Set how long we should wait for an HTTP request to be executed .
|
59,207
|
public function setTimeoutsFromArray ( $ arr ) { if ( ! is_array ( $ arr ) ) { throw SagException ( 'Expected an array and got something else.' ) ; } if ( is_int ( $ arr [ 'open' ] ) ) { $ this -> setOpenTimeout ( $ arr [ 'open' ] ) ; } if ( is_int ( $ arr [ 'rwSeconds' ] ) ) { if ( is_int ( $ arr [ 'rwMicroseconds' ] ) ) { $ this -> setRWTimeout ( $ arr [ 'rwSeconds' ] , $ arr [ 'rwMicroseconds' ] ) ; } else { $ this -> setRWTimeout ( $ arr [ 'rwSeconds' ] ) ; } } }
|
A utility function that sets the different timeout values based on an associative array .
|
59,208
|
private function makeFollowAdapter ( $ parts ) { if ( empty ( $ parts [ 'host' ] ) || ( $ parts [ 'host' ] == $ this -> host && $ parts [ 'port' ] == $ this -> port && $ parts [ 'scheme' ] == $ this -> proto ) ) { return $ this ; } if ( empty ( $ parts [ 'port' ] ) ) { $ parts [ 'port' ] = ( $ parts [ 'scheme' ] == 'https' ) ? 443 : 5984 ; } $ adapter = new SagCURLHTTPAdapter ( $ parts [ 'host' ] , $ parts [ 'port' ] ) ; $ adapter -> useSSL ( $ parts [ 'scheme' ] == 'https' ) ; $ adapter -> setTimeoutsFromArray ( $ this -> getTimeouts ( ) ) ; return $ adapter ; }
|
Used when we need to create a new adapter to follow a redirect because cURL can t .
|
59,209
|
public function multiple ( ) : self { $ unique_array = array_unique ( $ this -> getArrayCopy ( ) ) ; return new ArrayMap ( array_diff_assoc ( $ this -> getArrayCopy ( ) , $ unique_array ) ) ; }
|
Get duplicate values in an array
|
59,210
|
public function put ( $ element ) { $ nodeId = count ( $ this -> _heap ) ; $ parentId = ( $ nodeId - 1 ) >> 1 ; while ( $ nodeId != 0 && $ this -> _less ( $ element , $ this -> _heap [ $ parentId ] ) ) { $ this -> _heap [ $ nodeId ] = $ this -> _heap [ $ parentId ] ; $ nodeId = $ parentId ; $ parentId = ( $ nodeId - 1 ) >> 1 ; } $ this -> _heap [ $ nodeId ] = $ element ; }
|
Add element to the queue
|
59,211
|
public function pop ( ) { if ( count ( $ this -> _heap ) == 0 ) { return null ; } $ top = $ this -> _heap [ 0 ] ; $ lastId = count ( $ this -> _heap ) - 1 ; $ nodeId = 0 ; $ childId = 1 ; if ( $ lastId > 2 && $ this -> _less ( $ this -> _heap [ 2 ] , $ this -> _heap [ 1 ] ) ) { $ childId = 2 ; } while ( $ childId < $ lastId && $ this -> _less ( $ this -> _heap [ $ childId ] , $ this -> _heap [ $ lastId ] ) ) { $ this -> _heap [ $ nodeId ] = $ this -> _heap [ $ childId ] ; $ nodeId = $ childId ; $ childId = ( $ nodeId << 1 ) + 1 ; if ( ( $ childId + 1 ) < $ lastId && $ this -> _less ( $ this -> _heap [ $ childId + 1 ] , $ this -> _heap [ $ childId ] ) ) { $ childId ++ ; } } $ this -> _heap [ $ nodeId ] = $ this -> _heap [ $ lastId ] ; unset ( $ this -> _heap [ $ lastId ] ) ; return $ top ; }
|
Removes and return least element of the queue
|
59,212
|
public function VersionWarning ( ) { $ page = $ this -> owner -> getPage ( ) ; if ( ! $ page ) { return false ; } $ entity = $ page -> getEntity ( ) ; if ( ! $ entity ) { return false ; } $ versions = $ this -> owner -> getManifest ( ) -> getAllVersionsOfEntity ( $ entity ) ; if ( $ entity -> getIsStable ( ) ) { return false ; } $ stable = $ this -> owner -> getManifest ( ) -> getStableVersion ( $ entity ) ; $ compare = $ entity -> compare ( $ stable ) ; if ( $ entity -> getVersion ( ) == 'master' || $ compare > 0 ) { return $ this -> owner -> customise ( new ArrayData ( array ( 'FutureRelease' => true , 'StableVersion' => DBField :: create_field ( 'HTMLText' , $ stable -> getVersion ( ) ) ) ) ) ; } else { return $ this -> owner -> customise ( new ArrayData ( array ( 'OutdatedRelease' => true , 'StableVersion' => DBField :: create_field ( 'HTMLText' , $ stable -> getVersion ( ) ) ) ) ) ; } return false ; }
|
Check to see if the currently accessed version is out of date or perhaps a future version rather than the stable edition .
|
59,213
|
public function nextTerm ( ) { while ( ( $ termStream = $ this -> _termsStreamQueue -> pop ( ) ) !== null ) { if ( $ this -> _termsStreamQueue -> top ( ) === null || $ this -> _termsStreamQueue -> top ( ) -> currentTerm ( ) -> key ( ) != $ termStream -> currentTerm ( ) -> key ( ) ) { $ this -> _lastTerm = $ termStream -> currentTerm ( ) ; if ( $ termStream -> nextTerm ( ) !== null ) { $ this -> _termsStreamQueue -> put ( $ termStream ) ; } return $ this -> _lastTerm ; } if ( $ termStream -> nextTerm ( ) !== null ) { $ this -> _termsStreamQueue -> put ( $ termStream ) ; } } $ this -> _lastTerm = null ; return null ; }
|
Scans term streams and returns next term
|
59,214
|
public function addField ( Zend_Search_Lucene_Field $ field ) { if ( ! isset ( $ this -> _fields [ $ field -> name ] ) ) { $ fieldNumber = count ( $ this -> _fields ) ; $ this -> _fields [ $ field -> name ] = new Zend_Search_Lucene_Index_FieldInfo ( $ field -> name , $ field -> isIndexed , $ fieldNumber , $ field -> storeTermVector ) ; return $ fieldNumber ; } else { $ this -> _fields [ $ field -> name ] -> isIndexed |= $ field -> isIndexed ; $ this -> _fields [ $ field -> name ] -> storeTermVector |= $ field -> storeTermVector ; return $ this -> _fields [ $ field -> name ] -> number ; } }
|
Add field to the segment
|
59,215
|
public function addFieldInfo ( Zend_Search_Lucene_Index_FieldInfo $ fieldInfo ) { if ( ! isset ( $ this -> _fields [ $ fieldInfo -> name ] ) ) { $ fieldNumber = count ( $ this -> _fields ) ; $ this -> _fields [ $ fieldInfo -> name ] = new Zend_Search_Lucene_Index_FieldInfo ( $ fieldInfo -> name , $ fieldInfo -> isIndexed , $ fieldNumber , $ fieldInfo -> storeTermVector ) ; return $ fieldNumber ; } else { $ this -> _fields [ $ fieldInfo -> name ] -> isIndexed |= $ fieldInfo -> isIndexed ; $ this -> _fields [ $ fieldInfo -> name ] -> storeTermVector |= $ fieldInfo -> storeTermVector ; return $ this -> _fields [ $ fieldInfo -> name ] -> number ; } }
|
Add fieldInfo to the segment
|
59,216
|
public function addStoredFields ( $ storedFields ) { if ( ! isset ( $ this -> _fdxFile ) ) { $ this -> _fdxFile = $ this -> _directory -> createFile ( $ this -> _name . '.fdx' ) ; $ this -> _fdtFile = $ this -> _directory -> createFile ( $ this -> _name . '.fdt' ) ; $ this -> _files [ ] = $ this -> _name . '.fdx' ; $ this -> _files [ ] = $ this -> _name . '.fdt' ; } $ this -> _fdxFile -> writeLong ( $ this -> _fdtFile -> tell ( ) ) ; $ this -> _fdtFile -> writeVInt ( count ( $ storedFields ) ) ; foreach ( $ storedFields as $ field ) { $ this -> _fdtFile -> writeVInt ( $ this -> _fields [ $ field -> name ] -> number ) ; $ fieldBits = ( $ field -> isTokenized ? 0x01 : 0x00 ) | ( $ field -> isBinary ? 0x02 : 0x00 ) | 0x00 ; $ this -> _fdtFile -> writeByte ( $ fieldBits ) ; if ( $ field -> isBinary ) { $ this -> _fdtFile -> writeVInt ( strlen ( $ field -> value ) ) ; $ this -> _fdtFile -> writeBytes ( $ field -> value ) ; } else { $ this -> _fdtFile -> writeString ( $ field -> getUtf8Value ( ) ) ; } } $ this -> _docCount ++ ; }
|
Add stored fields information
|
59,217
|
public function initializeDictionaryFiles ( ) { $ this -> _tisFile = $ this -> _directory -> createFile ( $ this -> _name . '.tis' ) ; $ this -> _tisFile -> writeInt ( ( int ) 0xFFFFFFFD ) ; $ this -> _tisFile -> writeLong ( 0 ) ; $ this -> _tisFile -> writeInt ( self :: $ indexInterval ) ; $ this -> _tisFile -> writeInt ( self :: $ skipInterval ) ; $ this -> _tisFile -> writeInt ( self :: $ maxSkipLevels ) ; $ this -> _tiiFile = $ this -> _directory -> createFile ( $ this -> _name . '.tii' ) ; $ this -> _tiiFile -> writeInt ( ( int ) 0xFFFFFFFD ) ; $ this -> _tiiFile -> writeLong ( 0 ) ; $ this -> _tiiFile -> writeInt ( self :: $ indexInterval ) ; $ this -> _tiiFile -> writeInt ( self :: $ skipInterval ) ; $ this -> _tiiFile -> writeInt ( self :: $ maxSkipLevels ) ; $ this -> _tiiFile -> writeVInt ( 0 ) ; $ this -> _tiiFile -> writeString ( '' ) ; $ this -> _tiiFile -> writeInt ( ( int ) 0xFFFFFFFF ) ; $ this -> _tiiFile -> writeByte ( ( int ) 0x0F ) ; $ this -> _tiiFile -> writeVInt ( 0 ) ; $ this -> _tiiFile -> writeVInt ( 0 ) ; $ this -> _tiiFile -> writeVInt ( 0 ) ; $ this -> _tiiFile -> writeVInt ( 24 ) ; $ this -> _frqFile = $ this -> _directory -> createFile ( $ this -> _name . '.frq' ) ; $ this -> _prxFile = $ this -> _directory -> createFile ( $ this -> _name . '.prx' ) ; $ this -> _files [ ] = $ this -> _name . '.tis' ; $ this -> _files [ ] = $ this -> _name . '.tii' ; $ this -> _files [ ] = $ this -> _name . '.frq' ; $ this -> _files [ ] = $ this -> _name . '.prx' ; $ this -> _prevTerm = null ; $ this -> _prevTermInfo = null ; $ this -> _prevIndexTerm = null ; $ this -> _prevIndexTermInfo = null ; $ this -> _lastIndexPosition = 24 ; $ this -> _termCount = 0 ; }
|
Create dicrionary frequency and positions files and write necessary headers
|
59,218
|
protected function _dumpTermDictEntry ( Zend_Search_Lucene_Storage_File $ dicFile , & $ prevTerm , Zend_Search_Lucene_Index_Term $ term , & $ prevTermInfo , Zend_Search_Lucene_Index_TermInfo $ termInfo ) { if ( isset ( $ prevTerm ) && $ prevTerm -> field == $ term -> field ) { $ matchedBytes = 0 ; $ maxBytes = min ( strlen ( $ prevTerm -> text ) , strlen ( $ term -> text ) ) ; while ( $ matchedBytes < $ maxBytes && $ prevTerm -> text [ $ matchedBytes ] == $ term -> text [ $ matchedBytes ] ) { $ matchedBytes ++ ; } $ prefixBytes = 0 ; $ prefixChars = 0 ; while ( $ prefixBytes < $ matchedBytes ) { $ charBytes = 1 ; if ( ( ord ( $ term -> text [ $ prefixBytes ] ) & 0xC0 ) == 0xC0 ) { $ charBytes ++ ; if ( ord ( $ term -> text [ $ prefixBytes ] ) & 0x20 ) { $ charBytes ++ ; if ( ord ( $ term -> text [ $ prefixBytes ] ) & 0x10 ) { $ charBytes ++ ; } } } if ( $ prefixBytes + $ charBytes > $ matchedBytes ) { break ; } $ prefixChars ++ ; $ prefixBytes += $ charBytes ; } $ dicFile -> writeVInt ( $ prefixChars ) ; $ dicFile -> writeString ( substr ( $ term -> text , $ prefixBytes ) ) ; } else { $ dicFile -> writeVInt ( 0 ) ; $ dicFile -> writeString ( $ term -> text ) ; } $ dicFile -> writeVInt ( $ term -> field ) ; $ dicFile -> writeVInt ( $ termInfo -> docFreq ) ; $ prevTerm = $ term ; if ( ! isset ( $ prevTermInfo ) ) { $ dicFile -> writeVInt ( $ termInfo -> freqPointer ) ; $ dicFile -> writeVInt ( $ termInfo -> proxPointer ) ; } else { $ dicFile -> writeVInt ( $ termInfo -> freqPointer - $ prevTermInfo -> freqPointer ) ; $ dicFile -> writeVInt ( $ termInfo -> proxPointer - $ prevTermInfo -> proxPointer ) ; } if ( $ termInfo -> skipOffset != 0 ) { $ dicFile -> writeVInt ( $ termInfo -> skipOffset ) ; } $ prevTermInfo = $ termInfo ; }
|
Dump Term Dictionary segment file entry . Used to write entry to . tis or . tii files
|
59,219
|
protected function _generateCFS ( ) { $ cfsFile = $ this -> _directory -> createFile ( $ this -> _name . '.cfs' ) ; $ cfsFile -> writeVInt ( count ( $ this -> _files ) ) ; $ dataOffsetPointers = array ( ) ; foreach ( $ this -> _files as $ fileName ) { $ dataOffsetPointers [ $ fileName ] = $ cfsFile -> tell ( ) ; $ cfsFile -> writeLong ( 0 ) ; $ cfsFile -> writeString ( $ fileName ) ; } foreach ( $ this -> _files as $ fileName ) { $ dataOffset = $ cfsFile -> tell ( ) ; $ cfsFile -> seek ( $ dataOffsetPointers [ $ fileName ] ) ; $ cfsFile -> writeLong ( $ dataOffset ) ; $ cfsFile -> seek ( $ dataOffset ) ; $ dataFile = $ this -> _directory -> getFileObject ( $ fileName ) ; $ byteCount = $ this -> _directory -> fileLength ( $ fileName ) ; while ( $ byteCount > 0 ) { $ data = $ dataFile -> readBytes ( min ( $ byteCount , 131072 ) ) ; $ byteCount -= strlen ( $ data ) ; $ cfsFile -> writeBytes ( $ data ) ; } $ this -> _directory -> deleteFile ( $ fileName ) ; } }
|
Generate compound index file
|
59,220
|
public function getDocument ( ) { if ( ! $ this -> _document instanceof Zend_Search_Lucene_Document ) { $ this -> _document = $ this -> _index -> getDocument ( $ this -> id ) ; } return $ this -> _document ; }
|
Return the document object for this hit
|
59,221
|
protected function withBulk ( array $ data = [ ] ) { if ( ! $ this -> isArray ( $ data ) ) { return ; } foreach ( $ data [ 'data' ] as $ index => $ element ) { $ row = $ this -> data -> addChild ( 'row' ) ; $ row -> addAttribute ( 'no' , ++ $ index ) ; foreach ( $ element as $ key => $ value ) { $ child = $ row -> addChild ( 'FL' , $ value ) ; $ child -> addAttribute ( 'val' , $ key ) ; } } }
|
One or more elements in data array .
|
59,222
|
protected function withoutBulk ( array $ data = [ ] ) { if ( $ this -> isArray ( $ data ) ) { return ; } $ row = $ this -> data -> addChild ( 'row' ) ; $ row -> addAttribute ( 'no' , 1 ) ; foreach ( $ data [ 'data' ] as $ key => $ value ) { $ child = $ row -> addChild ( 'FL' , $ value ) ; $ child -> addAttribute ( 'val' , $ key ) ; } }
|
Only one element in data array . For BC .
|
59,223
|
public function setHTTPAdapter ( $ type = null ) { if ( ! $ type ) { $ type = extension_loaded ( "curl" ) ? self :: $ HTTP_CURL : self :: $ HTTP_NATIVE_SOCKETS ; } if ( $ type === $ this -> httpAdapterType ) { return true ; } $ prevDecode = null ; $ prevTimeouts = null ; if ( $ this -> httpAdapter ) { $ prevDecode = $ this -> httpAdapter -> decodeResp ; $ prevTimeouts = $ this -> httpAdapter -> getTimeouts ( ) ; } switch ( $ type ) { case self :: $ HTTP_NATIVE_SOCKETS : $ this -> httpAdapter = new SagNativeHTTPAdapter ( $ this -> host , $ this -> port ) ; break ; case self :: $ HTTP_CURL : $ this -> httpAdapter = new SagCURLHTTPAdapter ( $ this -> host , $ this -> port ) ; break ; default : throw SagException ( "Invalid Sag HTTP adapter specified: $type" ) ; } if ( is_bool ( $ prevDecode ) ) { $ this -> httpAdapter -> decodeResp = $ prevDecode ; } if ( is_array ( $ prevTimeouts ) ) { $ this -> httpAdapter -> setTimeoutsFromArray ( $ prevTimeouts ) ; } $ this -> httpAdapterType = $ type ; return $ this ; }
|
Set which HTTP library you want to use for communicating with CouchDB .
|
59,224
|
public function get ( $ url ) { if ( ! $ this -> db ) { throw new SagException ( 'No database specified' ) ; } if ( strpos ( $ url , '/' ) !== 0 ) { $ url = "/$url" ; } $ url = "/{$this->db}$url" ; if ( $ this -> staleDefault ) { $ url = self :: setURLParameter ( $ url , 'stale' , 'ok' ) ; } $ response = null ; if ( $ this -> cache ) { $ prevResponse = $ this -> cache -> get ( $ url ) ; if ( $ prevResponse ) { $ response = $ this -> procPacket ( 'GET' , $ url , null , array ( 'If-None-Match' => $ prevResponse -> headers -> etag ) ) ; if ( $ response -> headers -> _HTTP -> status == 304 ) { $ response -> fromCache = true ; return $ prevResponse ; } $ this -> cache -> remove ( $ url ) ; } unset ( $ prevResponse ) ; } if ( ! $ response ) { $ response = $ this -> procPacket ( 'GET' , $ url ) ; } if ( $ this -> cache ) { $ this -> cache -> set ( $ url , $ response ) ; } return $ response ; }
|
Performs an HTTP GET operation for the supplied URL . The database name you provided is automatically prepended to the URL so you only need to give the portion of the URL that comes after the database name .
|
59,225
|
public function head ( $ url ) { if ( ! $ this -> db ) { throw new SagException ( 'No database specified' ) ; } if ( strpos ( $ url , '/' ) !== 0 ) { $ url = "/$url" ; } if ( $ this -> staleDefault ) { $ url = self :: setURLParameter ( $ url , 'stale' , 'ok' ) ; } return $ this -> procPacket ( 'HEAD' , "/{$this->db}$url" ) ; }
|
Performs an HTTP HEAD operation for the supplied document . This operation does not try to read from a provided cache and does not cache its results .
|
59,226
|
public function delete ( $ id , $ rev ) { if ( ! $ this -> db ) { throw new SagException ( 'No database specified' ) ; } if ( ! is_string ( $ id ) || ! is_string ( $ rev ) || empty ( $ id ) || empty ( $ rev ) ) { throw new SagException ( 'delete() expects two strings.' ) ; } $ url = "/{$this->db}/$id" ; if ( $ this -> cache ) { $ this -> cache -> remove ( $ url ) ; } return $ this -> procPacket ( 'DELETE' , $ url . '?rev=' . urlencode ( $ rev ) ) ; }
|
DELETE s the specified document .
|
59,227
|
public function put ( $ id , $ data ) { if ( ! $ this -> db ) { throw new SagException ( 'No database specified' ) ; } if ( ! is_string ( $ id ) ) { throw new SagException ( 'put() expected a string for the doc id.' ) ; } if ( ! isset ( $ data ) || ( ! is_object ( $ data ) && ! is_string ( $ data ) && ! is_array ( $ data ) ) ) { throw new SagException ( 'put() needs an object for data - are you trying to use delete()?' ) ; } $ toSend = ( is_string ( $ data ) ) ? $ data : json_encode ( $ data ) ; $ id = urlencode ( $ id ) ; $ url = "/{$this->db}/$id" ; $ response = $ this -> procPacket ( 'PUT' , $ url , $ toSend ) ; unset ( $ toSend ) ; if ( $ this -> cache && $ response -> body -> ok ) { if ( is_string ( $ data ) ) { $ data = json_decode ( $ data ) ; } $ data -> _rev = $ response -> body -> rev ; $ toCache = clone $ response ; $ toCache -> body = $ data ; $ this -> cache -> set ( $ url , $ toCache ) ; unset ( $ toCache ) ; } return $ response ; }
|
PUT s the data to the document .
|
59,228
|
public function post ( $ data , $ path = null ) { if ( ! $ this -> db ) { throw new SagException ( 'No database specified' ) ; } if ( ! isset ( $ data ) || ( ! is_string ( $ data ) && ! is_object ( $ data ) && ! is_array ( $ data ) ) ) { throw new SagException ( 'post() needs an object for data.' ) ; } if ( ! is_string ( $ data ) ) { $ data = json_encode ( $ data ) ; } if ( is_string ( $ path ) && ! empty ( $ path ) ) { if ( $ path [ 0 ] === '/' ) { $ path = '/' . urlencode ( substr ( $ path , 1 ) ) ; } else { $ path = '/' . urlencode ( $ path ) ; } } else if ( isset ( $ path ) ) { throw new SagException ( 'post() needs a string for a path.' ) ; } return $ this -> procPacket ( 'POST' , "/{$this->db}{$path}" , $ data ) ; }
|
POST s the provided document . When using a SagCache the created document and response are not cached .
|
59,229
|
public function bulk ( $ docs , $ allOrNothing = false ) { if ( ! $ this -> db ) { throw new SagException ( 'No database specified' ) ; } if ( ! is_array ( $ docs ) ) { throw new SagException ( 'bulk() expects an array for its first argument' ) ; } if ( ! is_bool ( $ allOrNothing ) ) { throw new SagException ( 'bulk() expects a boolean for its second argument' ) ; } $ data = new stdClass ( ) ; if ( $ allOrNothing ) { $ data -> all_or_nothing = $ allOrNothing ; } $ data -> docs = $ docs ; return $ this -> procPacket ( "POST" , "/{$this->db}/_bulk_docs" , json_encode ( $ data ) ) ; }
|
Bulk pushes documents to the database .
|
59,230
|
public function copy ( $ srcID , $ dstID , $ dstRev = null ) { if ( ! $ this -> db ) { throw new SagException ( 'No database specified' ) ; } if ( empty ( $ srcID ) || ! is_string ( $ srcID ) ) { throw new SagException ( 'copy() got an invalid source ID' ) ; } if ( empty ( $ dstID ) || ! is_string ( $ dstID ) ) { throw new SagException ( 'copy() got an invalid destination ID' ) ; } if ( $ dstRev != null && ( empty ( $ dstRev ) || ! is_string ( $ dstRev ) ) ) { throw new SagException ( 'copy() got an invalid source revision' ) ; } $ headers = array ( "Destination" => "$dstID" . ( ( $ dstRev ) ? "?rev=$dstRev" : "" ) ) ; $ srcID = urlencode ( $ srcID ) ; $ response = $ this -> procPacket ( 'COPY' , "/{$this->db}/$srcID" , null , $ headers ) ; return $ response ; }
|
COPY s the document .
|
59,231
|
public function getAllDocs ( $ incDocs = false , $ limit = null , $ startKey = null , $ endKey = null , $ keys = null , $ descending = false , $ skip = 0 ) { if ( ! $ this -> db ) { throw new SagException ( 'No database specified.' ) ; } $ qry = array ( ) ; if ( $ incDocs !== false ) { if ( ! is_bool ( $ incDocs ) ) { throw new SagException ( 'getAllDocs() expected a boolean for include_docs.' ) ; } $ qry [ ] = "include_docs=true" ; } if ( isset ( $ startKey ) ) { if ( ! is_string ( $ startKey ) ) { throw new SagException ( 'getAllDocs() expected a string for startkey.' ) ; } $ qry [ ] = 'startkey=' . urlencode ( $ startKey ) ; } if ( isset ( $ endKey ) ) { if ( ! is_string ( $ endKey ) ) { throw new SagException ( 'getAllDocs() expected a string for endkey.' ) ; } $ qry [ ] = 'endkey=' . urlencode ( $ endKey ) ; } if ( isset ( $ limit ) ) { if ( ! is_int ( $ limit ) || $ limit < 0 ) { throw new SagException ( 'getAllDocs() expected a positive integeter for limit.' ) ; } $ qry [ ] = 'limit=' . urlencode ( $ limit ) ; } if ( $ descending !== false ) { if ( ! is_bool ( $ descending ) ) { throw new SagException ( 'getAllDocs() expected a boolean for descending.' ) ; } $ qry [ ] = "descending=true" ; } if ( isset ( $ skip ) ) { if ( ! is_int ( $ skip ) || $ skip < 0 ) { throw new SagException ( 'getAllDocs() expected a non-negative integer for skip' ) ; } $ qry [ ] = 'skip=' . urlencode ( $ skip ) ; } $ qry = '?' . implode ( '&' , $ qry ) ; if ( isset ( $ keys ) ) { if ( ! is_array ( $ keys ) ) { throw new SagException ( 'getAllDocs() expected an array for the keys.' ) ; } $ data = new stdClass ( ) ; $ data -> keys = $ keys ; return $ this -> procPacket ( 'POST' , "/{$this->db}/_all_docs$qry" , json_encode ( $ data ) ) ; } return $ this -> procPacket ( 'GET' , "/{$this->db}/_all_docs$qry" ) ; }
|
Gets all the documents in the database with _all_docs . Its results will not be cached by SagCache .
|
59,232
|
public function replicate ( $ src , $ target , $ continuous = false , $ createTarget = null , $ filter = null , $ filterQueryParams = null ) { if ( empty ( $ src ) || ! is_string ( $ src ) ) { throw new SagException ( 'replicate() is missing a source to replicate from.' ) ; } if ( empty ( $ target ) || ! is_string ( $ target ) ) { throw new SagException ( 'replicate() is missing a target to replicate to.' ) ; } if ( ! is_bool ( $ continuous ) ) { throw new SagException ( 'replicate() expected a boolean for its third argument.' ) ; } if ( isset ( $ createTarget ) && ! is_bool ( $ createTarget ) ) { throw new SagException ( 'createTarget needs to be a boolean.' ) ; } if ( isset ( $ filter ) ) { if ( ! is_string ( $ filter ) ) { throw new SagException ( 'filter must be the name of a design doc\'s filter function: ddoc/filter' ) ; } if ( isset ( $ filterQueryParams ) && ! is_object ( $ filterQueryParams ) && ! is_array ( $ filterQueryParams ) ) { throw new SagException ( 'filterQueryParams needs to be an object or an array' ) ; } } $ data = new stdClass ( ) ; $ data -> source = $ src ; $ data -> target = $ target ; if ( $ continuous ) { $ data -> continuous = true ; } if ( $ createTarget ) { $ data -> create_target = true ; } if ( $ filter ) { $ data -> filter = $ filter ; if ( $ filterQueryParams ) { $ data -> query_params = $ filterQueryParams ; } } return $ this -> procPacket ( 'POST' , '/_replicate' , json_encode ( $ data ) ) ; }
|
Starts a replication job between two databases independently of which database you set with Sag .
|
59,233
|
private function procPacket ( $ method , $ url , $ data = null , $ headers = array ( ) ) { if ( $ data && ! is_string ( $ data ) ) { throw new SagException ( 'Unexpected data format. Please report this bug.' ) ; } if ( $ this -> pathPrefix && is_string ( $ this -> pathPrefix ) ) { $ url = $ this -> pathPrefix . $ url ; } $ headers [ 'Expect' ] = isset ( $ headers [ 'Expect' ] ) ? $ headers [ 'Expect' ] : null ; if ( ! $ headers [ 'Expect' ] ) { $ headers [ 'Expect' ] = ( isset ( $ headers [ 'expect' ] ) && $ headers [ 'expect' ] ) ? $ headers [ 'expect' ] : ' ' ; } if ( strtolower ( $ headers [ 'Expect' ] ) === '100-continue' ) { throw new SagException ( 'Sag does not support HTTP/1.1\'s Continue.' ) ; } $ headers [ "Host" ] = "{$this->host}:{$this->port}" ; $ headers [ "User-Agent" ] = "Sag/%VERSION%" ; $ headers [ 'Accept' ] = 'application/json' ; if ( $ this -> authType == Sag :: $ AUTH_BASIC && ( isset ( $ this -> user ) || isset ( $ this -> pass ) ) ) { $ headers [ "Authorization" ] = 'Basic ' . base64_encode ( "{$this->user}:{$this->pass}" ) ; } elseif ( $ this -> authType == Sag :: $ AUTH_COOKIE && isset ( $ this -> authSession ) ) { $ headers [ 'Cookie' ] = array ( 'AuthSession' => $ this -> authSession ) ; $ headers [ 'X-CouchDB-WWW-Authenticate' ] = 'Cookie' ; } if ( is_array ( $ this -> globalCookies ) && sizeof ( $ this -> globalCookies ) ) { if ( $ headers [ 'Cookie' ] ) { $ headers [ 'Cookie' ] = array_merge ( $ headers [ 'Cookie' ] , $ this -> globalCookies ) ; } else { $ headers [ 'Cookie' ] = $ this -> globalCookies ; } } if ( ! empty ( $ headers [ 'Cookie' ] ) ) { $ buff = '' ; foreach ( $ headers [ 'Cookie' ] as $ k => $ v ) { $ buff = ( ( $ buff ) ? ' ' : '' ) . "$k=$v;" ; } $ headers [ 'Cookie' ] = $ buff ; unset ( $ buff ) ; } if ( ! isset ( $ headers [ 'Content-Type' ] ) ) { $ headers [ 'Content-Type' ] = 'application/json' ; } if ( $ data ) { $ headers [ 'Content-Length' ] = strlen ( $ data ) ; } return $ this -> httpAdapter -> procPacket ( $ method , $ url , $ data , $ headers ) ; }
|
The main driver - does all the socket and protocol work .
|
59,234
|
protected function extractMetaData ( ZipArchive $ package ) { $ coreProperties = array ( ) ; $ relations = simplexml_load_string ( $ package -> getFromName ( "_rels/.rels" ) ) ; foreach ( $ relations -> Relationship as $ rel ) { if ( $ rel [ "Type" ] == Zend_Search_Lucene_Document_OpenXml :: SCHEMA_COREPROPERTIES ) { $ contents = simplexml_load_string ( $ package -> getFromName ( dirname ( $ rel [ "Target" ] ) . "/" . basename ( $ rel [ "Target" ] ) ) ) ; foreach ( $ contents -> children ( Zend_Search_Lucene_Document_OpenXml :: SCHEMA_DUBLINCORE ) as $ child ) { $ coreProperties [ $ child -> getName ( ) ] = ( string ) $ child ; } foreach ( $ contents -> children ( Zend_Search_Lucene_Document_OpenXml :: SCHEMA_COREPROPERTIES ) as $ child ) { $ coreProperties [ $ child -> getName ( ) ] = ( string ) $ child ; } foreach ( $ contents -> children ( Zend_Search_Lucene_Document_OpenXml :: SCHEMA_DUBLINCORETERMS ) as $ child ) { $ coreProperties [ $ child -> getName ( ) ] = ( string ) $ child ; } } } return $ coreProperties ; }
|
Extract metadata from document
|
59,235
|
protected function encodeMessage ( $ msg ) { $ encodings = array ( 9 => '	' , 10 => '
' , 13 => '
' , 32 => ' ' , 34 => '"' , 39 => ''' , ) ; $ ret = array ( ) ; for ( $ j = 0 ; $ j < strlen ( $ msg ) ; $ j ++ ) { $ str = $ msg [ $ j ] ; $ asci = ord ( $ str ) ; if ( isset ( $ encodings [ $ asci ] ) ) { $ ret [ ] = $ encodings [ $ asci ] ; } elseif ( $ asci >= 128 || $ asci < 32 || in_array ( $ str , array ( '*' , '#' , '%' , '<' , '>' , '+' ) ) ) { $ ret [ ] = strtoupper ( '%' . sprintf ( "%02s" , dechex ( $ asci ) ) ) ; } else { $ ret [ ] = $ str ; } } return implode ( '' , $ ret ) ; }
|
Encodes the message according to doc
|
59,236
|
protected function buildGetCreditPayload ( ) { $ xml = new \ SimpleXMLElement ( '<?xml version="1.0" encoding="ISO-8859-1"?>' . '<!DOCTYPE REQUESTCREDIT SYSTEM "http://127.0.0.1:80/psms/dtd/requestcredit.dtd">' . '<REQUESTCREDIT></REQUESTCREDIT>' ) ; $ xml -> addAttribute ( 'USERNAME' , $ this -> username ) ; $ xml -> addAttribute ( 'PASSWORD' , $ this -> password ) ; return $ xml -> asXml ( ) ; }
|
Constructs valid XML for sending SMS - CR credit request service
|
59,237
|
protected function buildGetStatusPayload ( $ messageId ) { $ xml = new \ SimpleXMLElement ( '<?xml version="1.0" encoding="ISO-8859-1"?>' . '<!DOCTYPE STATUSREQUEST SYSTEM "http://127.0.0.1:80/psms/dtd/requeststatusv12.dtd">' . '<STATUSREQUEST VER="1.2"></STATUSREQUEST>' ) ; $ user = $ xml -> addChild ( 'USER' ) ; $ user -> addAttribute ( 'USERNAME' , $ this -> username ) ; $ user -> addAttribute ( 'PASSWORD' , $ this -> password ) ; $ guid = $ xml -> addChild ( 'GUID' ) ; $ guid -> addAttribute ( 'GUID' , $ messageId ) ; return $ xml -> asXml ( ) ; }
|
Constructs valid XML for sending SMS - SR request service
|
59,238
|
protected function buildSendSmsPayload ( array $ data = array ( ) ) { $ xml = new \ SimpleXMLElement ( '<?xml version="1.0" encoding="ISO-8859-1"?>' . '<!DOCTYPE MESSAGE SYSTEM "http://127.0.0.1:80/psms/dtd/messagev12.dtd">' . '<MESSAGE VER="1.2"></MESSAGE>' ) ; $ user = $ xml -> addChild ( 'USER' ) ; foreach ( array ( 'USERNAME' , 'PASSWORD' ) as $ key ) { if ( ! isset ( $ data [ $ key ] ) ) { continue ; } $ user -> addAttribute ( $ key , $ data [ $ key ] ) ; } $ sms = $ xml -> addChild ( 'SMS' ) ; foreach ( array ( 'UDH' , 'CODING' , 'PROPERTY' , 'ID' , 'TEXT' , 'DLR' , 'VALIDITY' , 'SEND_ON' ) as $ key ) { if ( ! isset ( $ data [ $ key ] ) ) { continue ; } if ( 'TEXT' === $ key ) { $ sms -> addAttribute ( $ key , $ this -> encodeMessage ( $ data [ $ key ] ) ) ; } else { $ sms -> addAttribute ( $ key , $ data [ $ key ] ) ; } } $ address = $ sms -> addChild ( 'ADDRESS' ) ; foreach ( array ( 'FROM' , 'TO' , 'SEQ' , 'TAG' ) as $ k ) { if ( isset ( $ data [ $ k ] ) ) { $ address -> addAttribute ( $ k , $ data [ $ k ] ) ; } } return $ xml -> asXml ( ) ; }
|
Constructs valid XML for sending SMS - MT message
|
59,239
|
public static function binary ( $ name , $ value ) { return new self ( $ name , $ value , '' , true , false , false , true ) ; }
|
Constructs a Binary String valued Field that is not tokenized nor indexed but is stored in the index for return with hits .
|
59,240
|
public static function text ( $ name , $ value , $ encoding = '' ) { return new self ( $ name , $ value , $ encoding , true , true , true ) ; }
|
Constructs a String - valued Field that is tokenized and indexed and is stored in the index for return with hits . Useful for short text fields like title or subject . Term vector will not be stored for this field .
|
59,241
|
public static function unStored ( $ name , $ value , $ encoding = '' ) { return new self ( $ name , $ value , $ encoding , false , true , true ) ; }
|
Constructs a String - valued Field that is tokenized and indexed but that is not stored in the index .
|
59,242
|
public function getUtf8Value ( ) { if ( strcasecmp ( $ this -> encoding , 'utf8' ) == 0 || strcasecmp ( $ this -> encoding , 'utf-8' ) == 0 ) { return $ this -> value ; } else { return ( PHP_OS != 'AIX' ) ? iconv ( $ this -> encoding , 'UTF-8' , $ this -> value ) : iconv ( 'ISO8859-1' , 'UTF-8' , $ this -> value ) ; } }
|
Get field value in UTF - 8 encoding
|
59,243
|
private static function _floatToByte ( $ f ) { if ( $ f <= 0.0 ) { return 0 ; } $ lowIndex = 0 ; $ highIndex = 255 ; while ( $ highIndex >= $ lowIndex ) { $ mid = ( $ highIndex + $ lowIndex ) >> 1 ; $ delta = $ f - self :: $ _normTable [ $ mid ] ; if ( $ delta < 0 ) { $ highIndex = $ mid - 1 ; } elseif ( $ delta > 0 ) { $ lowIndex = $ mid + 1 ; } else { return $ mid ; } } if ( $ highIndex != 255 && $ f - self :: $ _normTable [ $ highIndex ] > self :: $ _normTable [ $ highIndex + 1 ] - $ f ) { return $ highIndex + 1 ; } else { return $ highIndex ; } }
|
Float to byte conversion
|
59,244
|
public function idf ( $ input , Zend_Search_Lucene_Interface $ reader ) { if ( ! is_array ( $ input ) ) { return $ this -> idfFreq ( $ reader -> docFreq ( $ input ) , $ reader -> count ( ) ) ; } else { $ idf = 0.0 ; foreach ( $ input as $ term ) { $ idf += $ this -> idfFreq ( $ reader -> docFreq ( $ term ) , $ reader -> count ( ) ) ; } return $ idf ; } }
|
Computes a score factor for a simple term or a phrase .
|
59,245
|
private function _parseRichText ( $ is = null ) { $ value = array ( ) ; if ( isset ( $ is -> t ) ) { $ value [ ] = ( string ) $ is -> t ; } else { foreach ( $ is -> r as $ run ) { $ value [ ] = ( string ) $ run -> t ; } } return implode ( '' , $ value ) ; }
|
Parse rich text XML
|
59,246
|
private function _loadDelFile ( ) { if ( $ this -> _delGen == - 1 ) { return null ; } else if ( $ this -> _delGen == 0 ) { return $ this -> _loadPre21DelFile ( ) ; } else { return $ this -> _load21DelFile ( ) ; } }
|
Load detetions file
|
59,247
|
private function _loadPre21DelFile ( ) { require_once 'Zend/Search/Lucene/Exception.php' ; try { $ delFile = $ this -> _directory -> getFileObject ( $ this -> _name . '.del' ) ; $ byteCount = $ delFile -> readInt ( ) ; $ byteCount = ceil ( $ byteCount / 8 ) ; $ bitCount = $ delFile -> readInt ( ) ; if ( $ bitCount == 0 ) { $ delBytes = '' ; } else { $ delBytes = $ delFile -> readBytes ( $ byteCount ) ; } if ( extension_loaded ( 'bitset' ) ) { return $ delBytes ; } else { $ deletions = array ( ) ; for ( $ count = 0 ; $ count < $ byteCount ; $ count ++ ) { $ byte = ord ( $ delBytes [ $ count ] ) ; for ( $ bit = 0 ; $ bit < 8 ; $ bit ++ ) { if ( $ byte & ( 1 << $ bit ) ) { $ deletions [ $ count * 8 + $ bit ] = 1 ; } } } return $ deletions ; } } catch ( Zend_Search_Lucene_Exception $ e ) { if ( strpos ( $ e -> getMessage ( ) , 'is not readable' ) === false ) { throw new Zend_Search_Lucene_Exception ( $ e -> getMessage ( ) , $ e -> getCode ( ) , $ e ) ; } $ this -> _delGen = - 1 ; return null ; } }
|
Load pre - 2 . 1 detetions file
|
59,248
|
private function _load21DelFile ( ) { $ delFile = $ this -> _directory -> getFileObject ( $ this -> _name . '_' . base_convert ( $ this -> _delGen , 10 , 36 ) . '.del' ) ; $ format = $ delFile -> readInt ( ) ; if ( $ format == ( int ) 0xFFFFFFFF ) { if ( extension_loaded ( 'bitset' ) ) { $ deletions = bitset_empty ( ) ; } else { $ deletions = array ( ) ; } $ byteCount = $ delFile -> readInt ( ) ; $ bitCount = $ delFile -> readInt ( ) ; $ delFileSize = $ this -> _directory -> fileLength ( $ this -> _name . '_' . base_convert ( $ this -> _delGen , 10 , 36 ) . '.del' ) ; $ byteNum = 0 ; do { $ dgap = $ delFile -> readVInt ( ) ; $ nonZeroByte = $ delFile -> readByte ( ) ; $ byteNum += $ dgap ; if ( extension_loaded ( 'bitset' ) ) { for ( $ bit = 0 ; $ bit < 8 ; $ bit ++ ) { if ( $ nonZeroByte & ( 1 << $ bit ) ) { bitset_incl ( $ deletions , $ byteNum * 8 + $ bit ) ; } } return $ deletions ; } else { for ( $ bit = 0 ; $ bit < 8 ; $ bit ++ ) { if ( $ nonZeroByte & ( 1 << $ bit ) ) { $ deletions [ $ byteNum * 8 + $ bit ] = 1 ; } } return ( count ( $ deletions ) > 0 ) ? $ deletions : null ; } } while ( $ delFile -> tell ( ) < $ delFileSize ) ; } else { $ byteCount = ceil ( $ format / 8 ) ; $ bitCount = $ delFile -> readInt ( ) ; if ( $ bitCount == 0 ) { $ delBytes = '' ; } else { $ delBytes = $ delFile -> readBytes ( $ byteCount ) ; } if ( extension_loaded ( 'bitset' ) ) { return $ delBytes ; } else { $ deletions = array ( ) ; for ( $ count = 0 ; $ count < $ byteCount ; $ count ++ ) { $ byte = ord ( $ delBytes [ $ count ] ) ; for ( $ bit = 0 ; $ bit < 8 ; $ bit ++ ) { if ( $ byte & ( 1 << $ bit ) ) { $ deletions [ $ count * 8 + $ bit ] = 1 ; } } } return ( count ( $ deletions ) > 0 ) ? $ deletions : null ; } } }
|
Load 2 . 1 + format detetions file
|
59,249
|
public function openCompoundFile ( $ extension , $ shareHandler = true ) { if ( ( $ extension == '.fdx' || $ extension == '.fdt' ) && $ this -> _usesSharedDocStore ) { $ fdxFName = $ this -> _sharedDocStoreOptions [ 'segment' ] . '.fdx' ; $ fdtFName = $ this -> _sharedDocStoreOptions [ 'segment' ] . '.fdt' ; if ( ! $ this -> _sharedDocStoreOptions [ 'isCompound' ] ) { $ fdxFile = $ this -> _directory -> getFileObject ( $ fdxFName , $ shareHandler ) ; $ fdxFile -> seek ( $ this -> _sharedDocStoreOptions [ 'offset' ] * 8 , SEEK_CUR ) ; if ( $ extension == '.fdx' ) { return $ fdxFile ; } else { $ fdtStartOffset = $ fdxFile -> readLong ( ) ; $ fdtFile = $ this -> _directory -> getFileObject ( $ fdtFName , $ shareHandler ) ; $ fdtFile -> seek ( $ fdtStartOffset , SEEK_CUR ) ; return $ fdtFile ; } } if ( ! isset ( $ this -> _sharedDocStoreOptions [ 'files' ] [ $ fdxFName ] ) ) { require_once 'Zend/Search/Lucene/Exception.php' ; throw new Zend_Search_Lucene_Exception ( 'Shared doc storage segment compound file doesn\'t contain ' . $ fdxFName . ' file.' ) ; } if ( ! isset ( $ this -> _sharedDocStoreOptions [ 'files' ] [ $ fdtFName ] ) ) { require_once 'Zend/Search/Lucene/Exception.php' ; throw new Zend_Search_Lucene_Exception ( 'Shared doc storage segment compound file doesn\'t contain ' . $ fdtFName . ' file.' ) ; } $ cfxFile = $ this -> _directory -> getFileObject ( $ this -> _sharedDocStoreOptions [ 'segment' ] . '.cfx' , $ shareHandler ) ; $ cfxFile -> seek ( $ this -> _sharedDocStoreOptions [ 'files' ] [ $ fdxFName ] ) ; $ cfxFile -> seek ( $ this -> _sharedDocStoreOptions [ 'offset' ] * 8 , SEEK_CUR ) ; if ( $ extension == '.fdx' ) { return $ cfxFile ; } else { $ fdtStartOffset = $ cfxFile -> readLong ( ) ; $ cfxFile -> seek ( $ this -> _sharedDocStoreOptions [ 'files' ] [ $ fdtFName ] ) ; $ cfxFile -> seek ( $ fdtStartOffset , SEEK_CUR ) ; return $ fdtFile ; } } $ filename = $ this -> _name . $ extension ; if ( ! $ this -> _isCompound ) { return $ this -> _directory -> getFileObject ( $ filename , $ shareHandler ) ; } if ( ! isset ( $ this -> _segFiles [ $ filename ] ) ) { require_once 'Zend/Search/Lucene/Exception.php' ; throw new Zend_Search_Lucene_Exception ( 'Segment compound file doesn\'t contain ' . $ filename . ' file.' ) ; } $ file = $ this -> _directory -> getFileObject ( $ this -> _name . '.cfs' , $ shareHandler ) ; $ file -> seek ( $ this -> _segFiles [ $ filename ] ) ; return $ file ; }
|
Opens index file stoted within compound index file
|
59,250
|
public function compoundFileLength ( $ extension ) { if ( ( $ extension == '.fdx' || $ extension == '.fdt' ) && $ this -> _usesSharedDocStore ) { $ filename = $ this -> _sharedDocStoreOptions [ 'segment' ] . $ extension ; if ( ! $ this -> _sharedDocStoreOptions [ 'isCompound' ] ) { return $ this -> _directory -> fileLength ( $ filename ) ; } if ( ! isset ( $ this -> _sharedDocStoreOptions [ 'fileSizes' ] [ $ filename ] ) ) { require_once 'Zend/Search/Lucene/Exception.php' ; throw new Zend_Search_Lucene_Exception ( 'Shared doc store compound file doesn\'t contain ' . $ filename . ' file.' ) ; } return $ this -> _sharedDocStoreOptions [ 'fileSizes' ] [ $ filename ] ; } $ filename = $ this -> _name . $ extension ; if ( $ this -> _directory -> fileExists ( $ filename ) ) { return $ this -> _directory -> fileLength ( $ filename ) ; } if ( ! isset ( $ this -> _segFileSizes [ $ filename ] ) ) { require_once 'Zend/Search/Lucene/Exception.php' ; throw new Zend_Search_Lucene_Exception ( 'Index compound file doesn\'t contain ' . $ filename . ' file.' ) ; } return $ this -> _segFileSizes [ $ filename ] ; }
|
Get compound file length
|
59,251
|
public function getFieldNum ( $ fieldName ) { foreach ( $ this -> _fields as $ field ) { if ( $ field -> name == $ fieldName ) { return $ field -> number ; } } return - 1 ; }
|
Returns field index or - 1 if field is not found
|
59,252
|
private function _deletedCount ( ) { if ( $ this -> _deleted === null ) { return 0 ; } if ( extension_loaded ( 'bitset' ) ) { return count ( bitset_to_array ( $ this -> _deleted ) ) ; } else { return count ( $ this -> _deleted ) ; } }
|
Returns number of deleted documents .
|
59,253
|
private function _getFieldPosition ( $ fieldNum ) { return isset ( $ this -> _fieldsDicPositions [ $ fieldNum ] ) ? $ this -> _fieldsDicPositions [ $ fieldNum ] : $ fieldNum ; }
|
Get field position in a fields dictionary
|
59,254
|
private function _loadDictionaryIndex ( ) { if ( $ this -> _directory -> fileExists ( $ this -> _name . '.sti' ) ) { $ stiFile = $ this -> _directory -> getFileObject ( $ this -> _name . '.sti' ) ; $ stiFileData = $ stiFile -> readBytes ( $ this -> _directory -> fileLength ( $ this -> _name . '.sti' ) ) ; if ( ( $ unserializedData = @ unserialize ( $ stiFileData ) ) !== false ) { list ( $ this -> _termDictionary , $ this -> _termDictionaryInfos ) = $ unserializedData ; return ; } } $ tiiFile = $ this -> openCompoundFile ( '.tii' ) ; $ tiiFileData = $ tiiFile -> readBytes ( $ this -> compoundFileLength ( '.tii' ) ) ; require_once 'Zend/Search/Lucene/Index/DictionaryLoader.php' ; list ( $ this -> _termDictionary , $ this -> _termDictionaryInfos ) = Zend_Search_Lucene_Index_DictionaryLoader :: load ( $ tiiFileData ) ; $ stiFileData = serialize ( array ( $ this -> _termDictionary , $ this -> _termDictionaryInfos ) ) ; $ stiFile = $ this -> _directory -> createFile ( $ this -> _name . '.sti' ) ; $ stiFile -> writeBytes ( $ stiFileData ) ; }
|
Load terms dictionary index
|
59,255
|
private function _loadNorm ( $ fieldNum ) { if ( $ this -> _hasSingleNormFile ) { $ normfFile = $ this -> openCompoundFile ( '.nrm' ) ; $ header = $ normfFile -> readBytes ( 3 ) ; $ headerFormatVersion = $ normfFile -> readByte ( ) ; if ( $ header != 'NRM' || $ headerFormatVersion != ( int ) 0xFF ) { require_once 'Zend/Search/Lucene/Exception.php' ; throw new Zend_Search_Lucene_Exception ( 'Wrong norms file format.' ) ; } foreach ( $ this -> _fields as $ fNum => $ fieldInfo ) { if ( $ fieldInfo -> isIndexed ) { $ this -> _norms [ $ fNum ] = $ normfFile -> readBytes ( $ this -> _docCount ) ; } } } else { $ fFile = $ this -> openCompoundFile ( '.f' . $ fieldNum ) ; $ this -> _norms [ $ fieldNum ] = $ fFile -> readBytes ( $ this -> _docCount ) ; } }
|
Load normalizatin factors from an index file
|
59,256
|
public function norm ( $ id , $ fieldName ) { $ fieldNum = $ this -> getFieldNum ( $ fieldName ) ; if ( ! ( $ this -> _fields [ $ fieldNum ] -> isIndexed ) ) { return null ; } if ( ! isset ( $ this -> _norms [ $ fieldNum ] ) ) { $ this -> _loadNorm ( $ fieldNum ) ; } return Zend_Search_Lucene_Search_Similarity :: decodeNorm ( ord ( $ this -> _norms [ $ fieldNum ] [ $ id ] ) ) ; }
|
Returns normalization factor for specified documents
|
59,257
|
public function normVector ( $ fieldName ) { $ fieldNum = $ this -> getFieldNum ( $ fieldName ) ; if ( $ fieldNum == - 1 || ! ( $ this -> _fields [ $ fieldNum ] -> isIndexed ) ) { $ similarity = Zend_Search_Lucene_Search_Similarity :: getDefault ( ) ; return str_repeat ( chr ( $ similarity -> encodeNorm ( $ similarity -> lengthNorm ( $ fieldName , 0 ) ) ) , $ this -> _docCount ) ; } if ( ! isset ( $ this -> _norms [ $ fieldNum ] ) ) { $ this -> _loadNorm ( $ fieldNum ) ; } return $ this -> _norms [ $ fieldNum ] ; }
|
Returns norm vector encoded in a byte string
|
59,258
|
public function writeChanges ( ) { $ latestDelGen = $ this -> _detectLatestDelGen ( ) ; if ( ! $ this -> _deletedDirty ) { if ( $ latestDelGen == $ this -> _delGen ) { return ; } else if ( $ latestDelGen > $ this -> _delGen ) { $ this -> _delGen = $ latestDelGen ; $ this -> _deleted = $ this -> _loadDelFile ( ) ; return ; } else { require_once 'Zend/Search/Lucene/Exception.php' ; throw new Zend_Search_Lucene_Exception ( 'Delete file processing workflow is corrupted for the segment \'' . $ this -> _name . '\'.' ) ; } } if ( $ latestDelGen > $ this -> _delGen ) { $ this -> _delGen = $ latestDelGen ; $ latestDelete = $ this -> _loadDelFile ( ) ; if ( extension_loaded ( 'bitset' ) ) { $ this -> _deleted = bitset_union ( $ this -> _deleted , $ latestDelete ) ; } else { $ this -> _deleted += $ latestDelete ; } } if ( extension_loaded ( 'bitset' ) ) { $ delBytes = $ this -> _deleted ; $ bitCount = count ( bitset_to_array ( $ delBytes ) ) ; } else { $ byteCount = floor ( $ this -> _docCount / 8 ) + 1 ; $ delBytes = str_repeat ( chr ( 0 ) , $ byteCount ) ; for ( $ count = 0 ; $ count < $ byteCount ; $ count ++ ) { $ byte = 0 ; for ( $ bit = 0 ; $ bit < 8 ; $ bit ++ ) { if ( isset ( $ this -> _deleted [ $ count * 8 + $ bit ] ) ) { $ byte |= ( 1 << $ bit ) ; } } $ delBytes [ $ count ] = chr ( $ byte ) ; } $ bitCount = count ( $ this -> _deleted ) ; } if ( $ this -> _delGen == - 1 ) { $ this -> _delGen = 1 ; } else { $ this -> _delGen ++ ; } $ delFile = $ this -> _directory -> createFile ( $ this -> _name . '_' . base_convert ( $ this -> _delGen , 10 , 36 ) . '.del' ) ; $ delFile -> writeInt ( $ this -> _docCount ) ; $ delFile -> writeInt ( $ bitCount ) ; $ delFile -> writeBytes ( $ delBytes ) ; $ this -> _deletedDirty = false ; }
|
Write changes if it s necessary .
|
59,259
|
public function lock ( Request $ request ) { $ cacheKey = $ this -> getCacheKey ( $ request ) ; if ( isset ( $ this -> locks [ $ cacheKey ] ) ) { return false ; } $ this -> locks [ $ cacheKey ] = $ this -> lockFactory -> createLock ( $ cacheKey ) ; return $ this -> locks [ $ cacheKey ] -> acquire ( ) ; }
|
Locks the cache for a given Request .
|
59,260
|
public function isLocked ( Request $ request ) { $ cacheKey = $ this -> getCacheKey ( $ request ) ; if ( ! isset ( $ this -> locks [ $ cacheKey ] ) ) { return false ; } return $ this -> locks [ $ cacheKey ] -> isAcquired ( ) ; }
|
Returns whether or not a lock exists .
|
59,261
|
public function cleanup ( ) { try { foreach ( $ this -> locks as $ lock ) { $ lock -> release ( ) ; } } catch ( LockReleasingException $ e ) { } finally { $ this -> locks = [ ] ; } }
|
Release all locks .
|
59,262
|
public function invalidateTags ( array $ tags ) { if ( ! $ this -> cache instanceof TagAwareAdapterInterface ) { throw new \ RuntimeException ( 'Cannot invalidate tags on a cache implementation that does not implement the TagAwareAdapterInterface.' ) ; } try { return $ this -> cache -> invalidateTags ( $ tags ) ; } catch ( InvalidArgumentException $ e ) { return false ; } }
|
The tags are set from the header configured in cache_tags_header .
|
59,263
|
private function autoPruneExpiredEntries ( ) { if ( 0 === $ this -> options [ 'prune_threshold' ] ) { return ; } $ item = $ this -> cache -> getItem ( self :: COUNTER_KEY ) ; $ counter = ( int ) $ item -> get ( ) ; if ( $ counter > $ this -> options [ 'prune_threshold' ] ) { $ this -> prune ( ) ; $ counter = 0 ; } else { ++ $ counter ; } $ item -> set ( $ counter ) ; $ this -> cache -> saveDeferred ( $ item ) ; }
|
Increases a counter every time an item is stored to the cache and then prunes expired cache entries if a configurable threshold is reached . This only happens during write operations so cache retrieval is not slowed down .
|
59,264
|
private function restoreResponse ( array $ cacheData ) { $ body = null ; if ( isset ( $ cacheData [ 'headers' ] [ 'x-content-digest' ] [ 0 ] ) ) { $ item = $ this -> cache -> getItem ( $ cacheData [ 'headers' ] [ 'x-content-digest' ] [ 0 ] ) ; if ( $ item -> isHit ( ) ) { $ body = $ item -> get ( ) ; } } return new Response ( $ body , $ cacheData [ 'status' ] , $ cacheData [ 'headers' ] ) ; }
|
Restores a Response from the cached data .
|
59,265
|
public function debug ( ) { $ query = $ this -> pdo -> prepare ( <<<SQLSELECT *FROM robotstxt__cache1WHERE base = :base;SQL ) ; $ query -> bindValue ( 'base' , $ this -> base , \ PDO :: PARAM_STR ) ; $ query -> execute ( ) ; return $ query -> rowCount ( ) > 0 ? $ query -> fetch ( \ PDO :: FETCH_ASSOC ) : [ ] ; }
|
Debug - Get raw data
|
59,266
|
private function markAsActive ( $ workerID = 0 ) { if ( $ workerID == 0 ) { $ query = $ this -> pdo -> prepare ( <<<SQLUPDATE robotstxt__cache1SET worker = NULLWHERE base = :base AND worker = 0;SQL ) ; $ query -> bindValue ( 'base' , $ this -> base , \ PDO :: PARAM_STR ) ; return $ query -> execute ( ) ; } return true ; }
|
Mark robots . txt as active
|
59,267
|
public function refresh ( ) { $ client = new UriClient ( $ this -> base , $ this -> curlOptions , $ this -> byteLimit ) ; $ effective = $ client -> getEffectiveUri ( ) ; if ( $ effective == $ this -> base ) { $ effective = null ; } $ statusCode = $ client -> getStatusCode ( ) ; $ nextUpdate = $ client -> nextUpdate ( ) ; if ( strpos ( $ this -> base , 'http' ) === 0 && ( $ statusCode === null || ( $ statusCode >= 500 && $ statusCode < 600 ) ) && $ this -> displacePush ( $ nextUpdate ) ) { return $ client ; } $ validUntil = $ client -> validUntil ( ) ; $ content = $ client -> render ( ) -> compressed ( self :: RENDER_LINE_SEPARATOR ) ; $ query = $ this -> pdo -> prepare ( <<<SQLINSERT INTO robotstxt__cache1 (base, content, statusCode, validUntil, nextUpdate, effective)VALUES (:base, :content, :statusCode, :validUntil, :nextUpdate, :effective)ON DUPLICATE KEY UPDATE content = :content, statusCode = :statusCode, validUntil = :validUntil, nextUpdate = :nextUpdate, effective = :effective, worker = 0;SQL ) ; $ query -> bindValue ( 'base' , $ this -> base , \ PDO :: PARAM_STR ) ; $ query -> bindValue ( 'content' , $ content , \ PDO :: PARAM_STR ) ; $ query -> bindValue ( 'statusCode' , $ statusCode , \ PDO :: PARAM_INT | \ PDO :: PARAM_NULL ) ; $ query -> bindValue ( 'validUntil' , $ validUntil , \ PDO :: PARAM_INT ) ; $ query -> bindValue ( 'nextUpdate' , $ nextUpdate , \ PDO :: PARAM_INT ) ; $ query -> bindValue ( 'effective' , $ effective , \ PDO :: PARAM_STR | \ PDO :: PARAM_NULL ) ; $ query -> execute ( ) ; return $ client ; }
|
Update the robots . txt
|
59,268
|
private function displacePush ( $ nextUpdate ) { $ query = $ this -> pdo -> prepare ( <<<SQLSELECT validUntil, UNIX_TIMESTAMP()FROM robotstxt__cache1WHERE base = :base;SQL ) ; $ query -> bindValue ( 'base' , $ this -> base , \ PDO :: PARAM_STR ) ; $ query -> execute ( ) ; if ( $ query -> rowCount ( ) > 0 ) { $ row = $ query -> fetch ( \ PDO :: FETCH_ASSOC ) ; $ this -> clockSyncCheck ( $ row [ 'UNIX_TIMESTAMP()' ] , self :: OUT_OF_SYNC_TIME_LIMIT ) ; if ( $ row [ 'validUntil' ] > $ row [ 'UNIX_TIMESTAMP()' ] ) { $ nextUpdate = min ( $ row [ 'validUntil' ] , $ nextUpdate ) ; $ query = $ this -> pdo -> prepare ( <<<SQLUPDATE robotstxt__cache1SET nextUpdate = :nextUpdate, worker = 0WHERE base = :base;SQL ) ; $ query -> bindValue ( 'base' , $ this -> base , \ PDO :: PARAM_STR ) ; $ query -> bindValue ( 'nextUpdate' , $ nextUpdate , \ PDO :: PARAM_INT ) ; return $ query -> execute ( ) ; } } return false ; }
|
Displace push timestamp
|
59,269
|
public function updateCache ( ) { if ( $ this -> updateAttempted ) { return ; } $ this -> updateAttempted = true ; $ this -> metadata = $ this -> downloadMetadata ( ) ; if ( $ this -> metadata === null ) { return ; } $ expires = time ( ) + 24 * 60 * 60 ; if ( $ this -> metadata -> validUntil !== null && $ this -> metadata -> validUntil < $ expires ) { $ expires = $ this -> metadata -> validUntil ; } $ metadataSerialized = serialize ( $ this -> metadata ) ; $ this -> aggregator -> addCacheItem ( $ this -> cacheId , $ metadataSerialized , $ expires , $ this -> cacheTag ) ; }
|
Attempt to update our cache file .
|
59,270
|
public function getMetadata ( ) { if ( $ this -> metadata !== null ) { return $ this -> metadata ; } if ( ! $ this -> aggregator -> isCacheValid ( $ this -> cacheId , $ this -> cacheTag ) ) { $ this -> updateCache ( ) ; if ( $ this -> metadata !== null ) { return $ this -> metadata ; } } $ cacheFile = $ this -> aggregator -> getCacheFile ( $ this -> cacheId ) ; if ( is_null ( $ cacheFile ) || ! file_exists ( $ cacheFile ) ) { Logger :: error ( $ this -> logLoc . 'No cached metadata available.' ) ; return null ; } Logger :: debug ( $ this -> logLoc . 'Using cached metadata from ' . var_export ( $ cacheFile , true ) ) ; $ metadata = file_get_contents ( $ cacheFile ) ; if ( $ metadata !== false ) { $ this -> metadata = unserialize ( $ metadata ) ; return $ this -> metadata ; } return null ; }
|
Retrieve the metadata file .
|
59,271
|
public function setError ( $ code , $ node , $ message = '' ) { $ this -> errorCode = $ code ; $ this -> errorNode = $ node ; $ this -> errorMessage = $ message ; }
|
Sets error .
|
59,272
|
protected function setup_storage ( ) { $ storage = $ this -> get_option ( 'storage' ) ; if ( 'option' === $ storage ) { $ storage = Option_Storage :: get_instance ( ) ; } elseif ( 'thememod' === $ storage ) { $ storage = Theme_Mod_Storage :: get_instance ( ) ; } elseif ( is_string ( $ storage ) && is_subclass_of ( $ storage , Storage :: class ) ) { $ storage = new $ storage ; } elseif ( is_callable ( $ storage ) ) { $ storage = $ storage ( $ this ) ; } if ( $ storage instanceof Storage ) { $ this -> set_storage ( $ storage ) ; } }
|
Setup the field storage .
|
59,273
|
protected function setup_data ( ) { if ( ! $ storage = $ this -> get_storage ( ) ) { return ; } $ _hash = spl_object_hash ( $ storage ) ; if ( $ storage instanceof Deferred_Storage && ! isset ( static :: $ storages_was_read [ $ _hash ] ) ) { $ storage -> read ( ) ; static :: $ storages_was_read [ $ _hash ] = true ; } $ this -> set_value ( $ storage -> get ( $ this -> get_map_key ( ) ) ) ; }
|
Setup field data from the storage .
|
59,274
|
public function get_value ( ) { if ( $ this -> group && null === $ this -> value ) { return $ this -> value = $ this -> get_value_in_group ( ) ; } return $ this -> value ; }
|
Gets the field value .
|
59,275
|
protected function get_value_in_group ( ) { $ id = $ this -> get_id ( ) ; $ data = $ this -> group -> get_value ( ) ; return is_array ( $ data ) && isset ( $ data [ $ this -> group -> index ] [ $ id ] ) ? $ data [ $ this -> group -> index ] [ $ id ] : null ; }
|
Returns current value in group .
|
59,276
|
public function get_sanitization_value ( $ value ) { if ( $ this -> is_repeatable ( ) && is_callable ( $ sanitizer = $ this -> get_option ( 'sanitization_cb' ) ) ) { $ sanitized = is_array ( $ value ) ? array_map ( $ sanitizer , $ value ) : [ ] ; return Utils :: filter_blank ( $ sanitized ) ; } return $ this -> sanitization_cb ( $ value ) ; }
|
Perform the sanitization a given value .
|
59,277
|
private function getExtension ( UploadedFile $ file ) : ? string { $ originalName = $ file -> getClientOriginalName ( ) ; if ( $ extension = pathinfo ( $ originalName , PATHINFO_EXTENSION ) ) { return strtolower ( $ extension ) ; } if ( $ extension = $ file -> guessExtension ( ) ) { return strtolower ( $ extension ) ; } return null ; }
|
Guess the extension of the given file .
|
59,278
|
public function save_file ( Request $ request ) { $ filepath = $ request -> input ( 'filepath' ) ; $ filedata = $ request -> input ( 'filedata' ) ; $ data = file_put_contents ( base_path ( $ filepath ) , $ filedata ) ; return response ( ) -> json ( [ 'success' => true ] ) ; }
|
Save file content
|
59,279
|
public function register ( ) { $ builder = $ this -> get_builder ( ) ; foreach ( $ this -> get_builder_config ( ) as $ key => $ value ) { $ builder -> set_option ( $ key , $ value ) ; } ( new Loader ( $ builder ) ) -> fire ( ) ; }
|
Register the box .
|
59,280
|
public function get_builder_config ( ) { $ vars = Arr :: except ( get_object_vars ( $ this ) , [ 'sections' , 'containers' , 'properties' , 'builder' , '_form' ] ) ; return array_merge ( $ vars , $ this -> properties ) ; }
|
Returns the form builder config .
|
59,281
|
public function get_property ( $ key ) { return isset ( $ this -> properties [ $ key ] ) ? $ this -> properties [ $ key ] : null ; }
|
Get box property .
|
59,282
|
private function getInlineValue ( $ header , $ part , $ delimiter = ";" ) { foreach ( array_map ( 'trim' , explode ( $ delimiter , $ header ) ) as $ string ) { if ( stripos ( $ string , $ part . '=' ) === 0 ) { return trim ( explode ( '=' , $ string , 2 ) [ 1 ] ) ; } } return false ; }
|
Get inline header variable value
|
59,283
|
private function buildCleanParam ( $ array ) { $ result = [ ] ; foreach ( $ array as $ param => $ paths ) { foreach ( $ paths as $ path ) { $ result [ ] = self :: DIRECTIVE_CLEAN_PARAM . ':' . $ param . ' ' . $ path ; } } return $ result ; }
|
Clean - param
|
59,284
|
private function buildUserAgent ( $ array ) { $ result = [ ] ; foreach ( $ array as $ userAgent => $ rules ) { $ rules = $ this -> arrayMergeRecursiveEx ( self :: TEMPLATE_SUB , $ rules ) ; $ result = array_merge ( $ result , [ self :: DIRECTIVE_USER_AGENT . ':' . $ userAgent ] , $ this -> buildString ( $ rules [ self :: DIRECTIVE_ROBOT_VERSION ] , self :: DIRECTIVE_ROBOT_VERSION ) , $ this -> buildVisitTime ( $ rules [ self :: DIRECTIVE_VISIT_TIME ] ) , $ this -> buildArray ( $ rules [ self :: DIRECTIVE_NO_INDEX ] , self :: DIRECTIVE_NO_INDEX ) , $ this -> buildArray ( $ rules [ self :: DIRECTIVE_DISALLOW ] , self :: DIRECTIVE_DISALLOW ) , $ this -> buildArray ( $ rules [ self :: DIRECTIVE_ALLOW ] , self :: DIRECTIVE_ALLOW ) , $ this -> buildString ( $ rules [ self :: DIRECTIVE_CRAWL_DELAY ] , self :: DIRECTIVE_CRAWL_DELAY ) , $ this -> buildString ( $ rules [ self :: DIRECTIVE_CACHE_DELAY ] , self :: DIRECTIVE_CACHE_DELAY ) , $ this -> buildRequestRate ( $ rules [ self :: DIRECTIVE_REQUEST_RATE ] ) , $ this -> buildArray ( $ rules [ self :: DIRECTIVE_COMMENT ] , self :: DIRECTIVE_COMMENT ) ) ; } return $ result ; }
|
User - agent
|
59,285
|
private function buildVisitTime ( $ array ) { $ result = [ ] ; foreach ( $ array as $ pair ) { $ result [ ] = self :: DIRECTIVE_VISIT_TIME . ':' . $ pair [ 'from' ] . '-' . $ pair [ 'to' ] ; } return $ result ; }
|
Visit - time
|
59,286
|
private function buildRequestRate ( $ array ) { $ result = [ ] ; foreach ( $ array as $ pair ) { $ string = self :: DIRECTIVE_REQUEST_RATE . ':' . $ pair [ 'ratio' ] ; if ( isset ( $ pair [ 'from' ] ) && isset ( $ pair [ 'to' ] ) ) { $ string .= ' ' . $ pair [ 'from' ] . '-' . $ pair [ 'to' ] ; } $ result [ ] = $ string ; } return $ result ; }
|
Request - rate
|
59,287
|
public function cron ( $ timeLimit = self :: CRON_EXEC_TIME , $ workerID = self :: WORKER_ID ) { $ start = microtime ( true ) ; $ workerID = $ this -> setWorkerID ( $ workerID ) ; $ log = [ ] ; $ lastCount = - 1 ; while ( count ( $ log ) > $ lastCount && ( empty ( $ timeLimit ) || $ timeLimit > ( microtime ( true ) - $ start ) ) ) { $ lastCount = count ( $ log ) ; $ query = $ this -> pdo -> prepare ( <<<SQLUPDATE robotstxt__cache1SET worker = :workerIDWHERE worker IS NULL AND nextUpdate <= UNIX_TIMESTAMP()ORDER BY nextUpdate ASCLIMIT 1;SQL ) ; $ query -> bindValue ( 'workerID' , $ workerID , \ PDO :: PARAM_INT ) ; $ query -> execute ( ) ; $ query = $ this -> pdo -> prepare ( <<<SQLSELECT baseFROM robotstxt__cache1WHERE worker = :workerIDORDER BY nextUpdate DESCLIMIT 10;SQL ) ; $ query -> bindValue ( 'workerID' , $ workerID , \ PDO :: PARAM_INT ) ; $ query -> execute ( ) ; while ( $ baseUri = $ query -> fetch ( \ PDO :: FETCH_COLUMN ) ) { if ( ( new Base ( $ this -> pdo , $ baseUri , $ this -> curlOptions , $ this -> byteLimit ) ) -> refresh ( ) ) { $ log [ ( string ) microtime ( true ) ] = $ baseUri ; } } } return $ log ; }
|
Process the update queue
|
59,288
|
public function clean ( $ delay = self :: CLEAN_DELAY ) { $ delay += self :: CACHE_TIME ; $ query = $ this -> pdo -> prepare ( <<<SQLDELETE FROM robotstxt__cache1WHERE nextUpdate < (UNIX_TIMESTAMP() - :delay);SQL ) ; $ query -> bindValue ( 'delay' , $ delay , \ PDO :: PARAM_INT ) ; return $ query -> execute ( ) ; }
|
Clean the cache table
|
59,289
|
protected function _prepareLayout ( ) { $ this -> buttonList -> remove ( 'save' ) ; $ this -> buttonList -> remove ( 'delete' ) ; $ this -> buttonList -> remove ( 'reset' ) ; $ this -> buttonList -> add ( 'send' , [ 'label' => __ ( 'Send mail ...' ) , 'onclick' => "setLocation('{$this->getUrl('*/*/send', ['id' => $this->_mail->getId()] )}')" , 'class' => 'task' ] ) ; $ this -> buttonList -> add ( 'send_post' , [ 'label' => __ ( 'Resend mail' ) , 'onclick' => "setLocation('{$this->getUrl('*/*/sendPost', [ 'id' => $this->_mail->getId() ])}')" , 'class' => 'task' ] ) ; return parent :: _prepareLayout ( ) ; }
|
Prepare the layout .
|
59,290
|
public function getTimeSleepUntil ( ) { if ( $ this -> delay == 0 ) { return 0 ; } $ query = $ this -> pdo -> prepare ( <<<SQLSELECT delayUntil, UNIX_TIMESTAMP()FROM robotstxt__delay0WHERE base = :base AND userAgent = :userAgent;SQL ) ; $ query -> bindValue ( 'base' , $ this -> base , \ PDO :: PARAM_STR ) ; $ query -> bindValue ( 'userAgent' , $ this -> userAgent , \ PDO :: PARAM_STR ) ; $ query -> execute ( ) ; $ this -> increment ( ) ; if ( $ query -> rowCount ( ) > 0 ) { $ row = $ query -> fetch ( \ PDO :: FETCH_ASSOC ) ; $ this -> clockSyncCheck ( $ row [ 'UNIX_TIMESTAMP()' ] , self :: OUT_OF_SYNC_TIME_LIMIT ) ; return $ row [ 'delayUntil' ] / 1000000 ; } return 0 ; }
|
Timestamp with milliseconds
|
59,291
|
private function increment ( ) { $ query = $ this -> pdo -> prepare ( <<<SQLINSERT INTO robotstxt__delay0 (base, userAgent, delayUntil, lastDelay)VALUES (:base, :userAgent, (UNIX_TIMESTAMP(CURTIME(6)) + :delay) * 1000000, :delay * 1000000)ON DUPLICATE KEY UPDATE delayUntil = GREATEST((UNIX_TIMESTAMP(CURTIME(6)) + :delay) * 1000000, delayUntil + (:delay * 1000000)), lastDelay = :delay * 1000000;SQL ) ; $ query -> bindValue ( 'base' , $ this -> base , \ PDO :: PARAM_STR ) ; $ query -> bindValue ( 'userAgent' , $ this -> userAgent , \ PDO :: PARAM_STR ) ; $ query -> bindValue ( 'delay' , $ this -> delay , \ PDO :: PARAM_INT ) ; return $ query -> execute ( ) ; }
|
Set new delayUntil timestamp
|
59,292
|
public function execute ( $ cronjobId ) { $ cronjob = $ this -> cronjobTable -> get ( $ cronjobId ) ; if ( empty ( $ cronjob ) ) { throw new StatusCode \ NotFoundException ( 'Could not find cronjob' ) ; } if ( $ cronjob [ 'status' ] == Table \ Cronjob :: STATUS_DELETED ) { throw new StatusCode \ GoneException ( 'Cronjob was deleted' ) ; } $ exitCode = null ; try { $ this -> executorService -> execute ( $ cronjob [ 'action' ] , 'GET' , null , null , null , null ) ; $ exitCode = Table \ Cronjob :: CODE_SUCCESS ; } catch ( \ Throwable $ e ) { $ this -> errorTable -> create ( [ 'cronjob_id' => $ cronjob [ 'id' ] , 'message' => $ e -> getMessage ( ) , 'trace' => $ e -> getTraceAsString ( ) , 'file' => $ e -> getFile ( ) , 'line' => $ e -> getLine ( ) , ] ) ; $ exitCode = Table \ Cronjob :: CODE_ERROR ; } $ record = [ 'id' => $ cronjob [ 'id' ] , 'execute_date' => new \ DateTime ( ) , 'exit_code' => $ exitCode , ] ; $ this -> cronjobTable -> update ( $ record ) ; }
|
Executes a specific cronjob
|
59,293
|
private function writeCronFile ( ) { if ( empty ( $ this -> cronFile ) ) { return false ; } if ( ! is_file ( $ this -> cronFile ) ) { return false ; } if ( ! is_writable ( $ this -> cronFile ) ) { return false ; } return file_put_contents ( $ this -> cronFile , $ this -> generateCron ( ) ) ; }
|
Writes the cron file
|
59,294
|
public function pay ( $ points , ContextInterface $ context ) { $ this -> userTable -> payPoints ( $ context -> getUser ( ) -> getId ( ) , $ points ) ; $ this -> usageTable -> create ( [ 'route_id' => $ context -> getRouteId ( ) , 'user_id' => $ context -> getUser ( ) -> getId ( ) , 'app_id' => $ context -> getApp ( ) -> getId ( ) , 'points' => $ points , 'insert_date' => new \ DateTime ( ) , ] ) ; $ userContext = UserContext :: newContext ( $ context -> getUser ( ) -> getId ( ) , $ context -> getApp ( ) -> getId ( ) ) ; $ this -> eventDispatcher -> dispatch ( PlanEvents :: PAY , new PayedEvent ( $ points , $ userContext ) ) ; }
|
Method which is called in case a user visits a route which cost a specific amount of points . This method decreases the points from the user account
|
59,295
|
public function credit ( $ points , UserContext $ context ) { $ this -> userTable -> creditPoints ( $ context -> getUserId ( ) , $ points ) ; $ this -> eventDispatcher -> dispatch ( PlanEvents :: CREDIT , new CreditedEvent ( $ points , $ context ) ) ; }
|
Method which is called in case the user has bought new points . It adds the points to the user account
|
59,296
|
public function getMessage ( ) { if ( ! empty ( parent :: getMessage ( ) ) ) { return parent :: getMessage ( ) ; } return $ this -> _storage -> loadMessage ( $ this ) ; }
|
Every mailing is associated to a real message
|
59,297
|
public function getAttachments ( ) { if ( ! empty ( parent :: getAttachments ( ) ) ) { return parent :: getAttachments ( ) ; } $ attachments = $ this -> _storage -> getAttachments ( $ this ) ; $ this -> setAttachments ( $ attachments ) ; return $ attachments ; }
|
A mail can have zero to n associated attachments . An Attachment is a meta description to get information and access to binary data
|
59,298
|
public function getTags ( ) { $ value = $ this -> getData ( 'tags' ) ; if ( ! empty ( $ decoded = json_decode ( $ value , true ) ) ) { return $ decoded ; } return [ ] ; }
|
Get tags used for mail Tags are stored as json string in database
|
59,299
|
public function updateWithTransport ( $ transport ) { $ this -> setSubject ( $ transport -> getMessage ( ) -> getSubject ( ) ) -> setMessage ( $ transport -> getMessage ( ) ) -> setRecipients ( $ transport -> getMessage ( ) -> getRecipients ( ) ) -> setId ( null ) ; return $ this ; }
|
Update mail data with information created while transport init
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.