idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
1,800
|
public static function fromFloat ( $ float , $ tolerance = null ) { if ( $ float instanceof FloatType ) { $ float = $ float ( ) ; } if ( $ float == 0.0 ) { return new RationalType ( new IntType ( 0 ) , new IntType ( 1 ) ) ; } if ( $ tolerance instanceof FloatType ) { $ tolerance = $ tolerance ( ) ; } elseif ( is_null ( $ tolerance ) ) { $ tolerance = self :: $ defaultTolerance ; } $ negative = ( $ float < 0 ) ; if ( $ negative ) { $ float = abs ( $ float ) ; } $ num1 = 1 ; $ num2 = 0 ; $ den1 = 0 ; $ den2 = 1 ; $ oneOver = 1 / $ float ; do { $ oneOver = 1 / $ oneOver ; $ floor = floor ( $ oneOver ) ; $ aux = $ num1 ; $ num1 = $ floor * $ num1 + $ num2 ; $ num2 = $ aux ; $ aux = $ den1 ; $ den1 = $ floor * $ den1 + $ den2 ; $ den2 = $ aux ; $ oneOver = $ oneOver - $ floor ; } while ( abs ( $ float - $ num1 / $ den1 ) > $ float * $ tolerance ) ; if ( $ negative ) { $ num1 *= - 1 ; } return self :: createCorrectRational ( $ num1 , $ den1 ) ; }
|
Create a rational number from a float or FloatType Use Continued Fractions method of determining the rational number
|
1,801
|
protected static function createCorrectRational ( $ num , $ den ) { if ( self :: getRequiredType ( ) == self :: TYPE_GMP ) { return new GMPRationalType ( new GMPIntType ( $ num ) , new GMPIntType ( $ den ) ) ; } return new RationalType ( new IntType ( $ num ) , new IntType ( $ den ) ) ; }
|
Create and return the correct number type rational
|
1,802
|
private static function createFromNumericNumerator ( $ numerator , $ denominator ) { if ( is_null ( $ denominator ) ) { return self :: createCorrectRational ( $ numerator , 1 ) ; } if ( is_numeric ( $ denominator ) ) { return self :: createCorrectRational ( $ numerator , $ denominator ) ; } if ( $ denominator instanceof IntType ) { return self :: createCorrectRational ( $ numerator , $ denominator ( ) ) ; } self :: throwCreateException ( $ numerator , $ denominator ) ; }
|
Create where numerator is known to be numeric
|
1,803
|
private static function throwCreateException ( $ numerator , $ denominator ) { $ typeN = gettype ( $ numerator ) ; $ typeD = gettype ( $ denominator ) ; throw new InvalidTypeException ( "{$typeN}:{$typeD} for Rational type construction" ) ; }
|
Throw a create exception
|
1,804
|
public static function getWorkingDaysCount ( $ beginDate , $ endDate , $ nonWorkingDays = [ ] ) { $ workdays = 0 ; if ( ! is_null ( $ beginDate ) && ! is_null ( $ endDate ) ) { if ( $ beginDate > $ endDate ) { $ temp = $ beginDate ; $ beginDate = $ endDate ; $ endDate = $ temp ; } $ oneDayInterval = new DateInterval ( 'P1D' ) ; $ date = clone $ beginDate ; while ( self :: compareDateWithoutTime ( $ date , $ endDate ) <= 0 ) { $ weekday = $ date -> format ( 'N' ) ; if ( ! in_array ( $ weekday , $ nonWorkingDays ) ) { $ workdays ++ ; } $ date -> add ( $ oneDayInterval ) ; } } return $ workdays ; }
|
Count working days between the two given dates . The comparison includes both begin and end dates .
|
1,805
|
public static function getAverageTimeForArrayOfDateTimes ( $ array ) { if ( ! is_array ( $ array ) ) { return false ; } $ averageTime = null ; $ averageSecondsFromDateBeginSum = 0 ; $ processedItemsCounter = 0 ; foreach ( $ array as $ datetime ) { if ( ! is_object ( $ datetime ) || ! ( $ datetime instanceof \ DateTime ) ) { continue ; } $ hours = ( int ) $ datetime -> format ( 'H' ) ; $ minutes = ( int ) $ datetime -> format ( 'i' ) ; $ seconds = ( int ) $ datetime -> format ( 's' ) ; $ averageSecondsFromDateBeginSum += $ hours * 3600 + $ minutes * 60 + $ seconds ; $ processedItemsCounter += 1 ; } $ averageTime = gmdate ( 'H:i:s' , intval ( $ averageSecondsFromDateBeginSum / $ processedItemsCounter ) % 86400 ) ; return $ averageTime ; }
|
Method find the average time for given array of datetime objects it ignores any non DateTIme values in the given array
|
1,806
|
public function limit ( $ limit , $ skip = null ) { $ this -> pipeline [ '$limit' ] = $ limit ; if ( ! empty ( $ skip ) ) { $ this -> pipeline [ '$skip' ] = $ skip ; } return $ this ; }
|
Set the result limit and offset .
|
1,807
|
public function getResult ( ) { $ result = $ this -> mongo -> aggregate ( $ this -> getCollectionName ( ) , $ this -> getPipeline ( ) ) ; return $ result -> toArray ( ) ; }
|
This method does your query lookup and returns the result in form of an array . In case if there are no records to return false is returned .
|
1,808
|
public function sortByTimestamp ( $ direction ) { if ( $ this -> id != '$ts' ) { throw new AnalyticsDbException ( 'In order to sort by timestamp, you need to first group by timestamp.' ) ; } $ direction = ( int ) $ direction ; $ this -> pipeline [ '$sort' ] = [ '_id' => $ direction ] ; return $ this ; }
|
Sorts the result by timestamp .
|
1,809
|
public function sortByEntityName ( $ direction ) { if ( $ this -> id != '$entity' ) { throw new AnalyticsDbException ( 'In order to sort by entity name, you need to first group by entity name.' ) ; } $ direction = ( int ) $ direction ; $ this -> pipeline [ '$sort' ] = [ '_id' => $ direction ] ; return $ this ; }
|
Sorts the result by entity name .
|
1,810
|
public function sortByRef ( $ direction ) { if ( $ this -> id != '$ref' ) { throw new AnalyticsDbException ( 'In order to sort by ref, you need to first group by ref.' ) ; } $ direction = ( int ) $ direction ; $ this -> pipeline [ '$sort' ] = [ '_id' => $ direction ] ; return $ this ; }
|
Sorts the result by referrer value .
|
1,811
|
public function getPipeline ( ) { $ pipeline = [ ] ; foreach ( $ this -> pipeline as $ k => $ v ) { $ pipeline [ ] = [ $ k => $ v ] ; } return $ pipeline ; }
|
Returns the pipeline array .
|
1,812
|
public function config ( $ key , $ value = null ) { if ( is_array ( $ key ) ) { foreach ( $ key as $ id => $ val ) { $ this -> config ( $ id , $ val ) ; } } else { if ( ! is_null ( $ value ) ) { return $ this -> bind ( $ key , $ value ) ; } if ( $ this -> bound ( $ key ) ) { return $ this -> make ( $ key ) ; } else { $ default = $ this -> get_default_config ( ) ; return isset ( $ default [ $ key ] ) ? $ default [ $ key ] : null ; } } }
|
Get or set configuration values .
|
1,813
|
protected function get_engine_config ( ) { $ config = $ this -> prepare_engine_config ( ) ; $ locations = $ config [ 'locations' ] ; unset ( $ config [ 'locations' ] ) ; $ locations = array_filter ( ( array ) $ locations , function ( $ location ) { return file_exists ( $ location ) ; } ) ; return [ $ locations , $ config ] ; }
|
Get engine config .
|
1,814
|
protected function prepare_config ( $ arr ) { $ result = [ ] ; if ( ! is_array ( $ arr ) ) { return $ result ; } $ arr = array_merge ( $ this -> get_default_config ( ) , $ arr ) ; foreach ( $ arr as $ key => $ value ) { $ res = $ this -> config ( $ key ) ; $ result [ $ key ] = is_null ( $ res ) ? $ value : $ res ; } return apply_filters ( 'digster/config' , $ result ) ; }
|
Prepare the template engines real configuration .
|
1,815
|
public function finish ( Lexer $ lexer ) { if ( is_array ( $ this -> exitPattern ) ) { foreach ( $ this -> exitPattern as $ exitPattern ) { $ lexer -> addExitPattern ( $ exitPattern , $ this -> name ) ; } } else { $ lexer -> addExitPattern ( $ this -> exitPattern , $ this -> name ) ; } return $ this ; }
|
Finish rule after connecting
|
1,816
|
protected function handleEndState ( $ content , $ position , TokenList $ tokenList ) { if ( ! empty ( $ content ) ) { $ tokenList -> addToken ( $ this -> name , $ position ) -> set ( 'content' , $ content ) ; } }
|
Handle lexers end state
|
1,817
|
public static function valid ( $ key , $ cipher ) { $ keyLength = mb_strlen ( $ key , '8bit' ) ; if ( static :: SUPPORTED_CIPHER_32_LENGTH === $ keyLength && $ cipher === static :: SUPPORTED_CIPHER_32 ) { return true ; } if ( static :: SUPPORTED_CIPHER_16_LENGTH == $ keyLength && $ cipher === static :: SUPPORTED_CIPHER_16 ) { return true ; } return false ; }
|
Check if the given key and cipher have valid length and name .
|
1,818
|
public static function generateEncryptionKey ( $ cipher ) { if ( $ cipher === static :: SUPPORTED_CIPHER_32 ) { return random_bytes ( static :: SUPPORTED_CIPHER_32_LENGTH ) ; } if ( $ cipher === static :: SUPPORTED_CIPHER_16 ) { return random_bytes ( static :: SUPPORTED_CIPHER_16_LENGTH ) ; } }
|
Generate encryption key .
|
1,819
|
public function encrypt ( $ value ) { $ iv = random_bytes ( openssl_cipher_iv_length ( $ this -> cipher ) ) ; $ value = \ openssl_encrypt ( $ value , $ this -> cipher , $ this -> key , 0 , $ iv ) ; $ hash_mac = $ this -> mac ( $ iv = base64_encode ( $ iv ) , $ value ) ; if ( ! $ value ) { throw new Exception ( 'Unable to encrypt given value' ) ; } $ encrypted = json_encode ( compact ( 'iv' , 'value' , 'hash_mac' ) ) ; if ( json_last_error ( ) !== JSON_ERROR_NONE ) { throw new Exception ( 'Unable to encrypt given value.' ) ; } return base64_encode ( $ encrypted ) ; }
|
Encrypt the value .
|
1,820
|
public function decrypt ( $ data ) { $ data = json_decode ( base64_decode ( $ data ) , true ) ; $ iv = base64_decode ( $ data [ 'iv' ] ) ; if ( ! $ this -> isEncryptedDataValid ( $ data ) ) { throw new Exception ( 'The given encrypted data is invalid.' ) ; } if ( ! $ this -> isMacValid ( $ data , 16 ) ) { throw new Exception ( 'The hash is invalid.' ) ; } $ decrypted = \ openssl_decrypt ( $ data [ 'value' ] , $ this -> cipher , $ this -> key , 0 , $ iv ) ; if ( $ decrypted === false ) { throw new Exception ( 'Data could not be decrypted.' ) ; } return $ decrypted ; }
|
Decrypt the given data and return plain text .
|
1,821
|
protected function isMacValid ( $ data , $ bytes ) { $ calculated = hash_hmac ( 'sha384' , $ this -> mac ( $ data [ 'iv' ] , $ data [ 'value' ] ) , $ bytes , true ) ; return hash_equals ( hash_hmac ( 'sha384' , $ data [ 'hash_mac' ] , $ bytes , true ) , $ calculated ) ; }
|
Determine if hash is valid .
|
1,822
|
public function get ( ) { if ( $ this -> isInteger ( ) ) { return $ this -> value [ 'num' ] -> get ( ) ; } $ num = intval ( gmp_strval ( $ this -> value [ 'num' ] -> gmp ( ) ) ) ; $ den = intval ( gmp_strval ( $ this -> value [ 'den' ] -> gmp ( ) ) ) ; return $ num / $ den ; }
|
Get the value of the object typed properly as a PHP Native type
|
1,823
|
private function getMatchingIndex ( array $ matchingList , PreferenceInterface $ pref ) { $ index = - 1 ; foreach ( $ matchingList as $ key => $ match ) { if ( $ match -> getVariant ( ) === $ pref -> getVariant ( ) ) { $ index = $ key ; } } return $ index ; }
|
Returns the first index containing a matching variant or - 1 if not present .
|
1,824
|
public function execute ( $ path ) { $ parts = ( ! is_array ( $ path ) ) ? explode ( '.' , $ path ) : $ path ; $ source = $ this -> subject ; foreach ( $ parts as $ index => $ part ) { $ source = $ this -> resolve ( $ part , $ source ) ; } return $ source ; }
|
Execute the data search using the path provided
|
1,825
|
public function resolve ( $ part , $ source ) { if ( is_array ( $ source ) ) { $ source = $ this -> handleArray ( $ part , $ source ) ; } elseif ( is_object ( $ source ) ) { $ source = $ this -> handleObject ( $ part , $ source ) ; } return $ source ; }
|
Using the path part given locate the data on the current source
|
1,826
|
public function handleArray ( $ path , $ subject ) { $ set = [ ] ; foreach ( $ subject as $ subj ) { $ result = $ this -> resolve ( $ path , $ subj ) ; if ( is_array ( $ result ) ) { $ set = array_merge ( $ set , $ result ) ; } else { $ set = $ result ; } } return $ set ; }
|
Handle the location of the value when the source is an array
|
1,827
|
public function loadTranslations ( $ locale , $ package = 'default' ) { $ package = $ package ? : 'default' ; if ( empty ( static :: $ translations [ $ locale ] ) ) { $ fileName = $ locale . DIRECTORY_SEPARATOR . $ package . '.json' ; $ filePath = $ this -> getBaseDirectory ( ) . DIRECTORY_SEPARATOR . $ fileName ; if ( is_file ( $ filePath ) ) { $ fileContents = file_get_contents ( $ filePath ) ; static :: $ translations [ $ locale ] = json_decode ( $ fileContents , true ) ; } else { throw new FileNotFoundException ( $ fileName ) ; } } }
|
Load translations from file .
|
1,828
|
public function is ( $ flag ) { if ( ! isset ( $ this -> _detectors [ $ flag ] ) ) { return $ flag === $ this -> format ( ) ; } $ detector = $ this -> _detectors [ $ flag ] ; if ( is_callable ( $ detector ) ) { return $ detector ( $ this ) ; } if ( ! is_array ( $ detector ) ) { throw new Exception ( "Invalid `'{$flag}'` detector definition." ) ; } $ key = key ( $ detector ) ; $ check = current ( $ detector ) ; $ value = $ this -> attr ( $ key ) ; if ( is_array ( $ check ) ) { return ! ! preg_match ( '~' . join ( '|' , $ check ) . '~i' , $ value ) ; } if ( preg_match ( '~^(?P<char>\~|/|@|#).*?(?P=char)$~' , $ check ) ) { return ! ! preg_match ( $ check , $ value ) ; } return $ check === $ value ; }
|
Provides a simple syntax for making assertions about the properties of a request .
|
1,829
|
public function locale ( $ locale = null ) { if ( $ locale ) { $ this -> _locale = $ locale ; } if ( $ this -> _locale ) { return $ this -> _locale ; } if ( isset ( $ this -> _params [ 'locale' ] ) ) { return $ this -> _params [ 'locale' ] ; } }
|
Sets or returns the current locale string .
|
1,830
|
public static function ingoing ( $ config = [ ] ) { $ config [ 'env' ] = isset ( $ config [ 'env' ] ) ? $ config [ 'env' ] : $ _SERVER ; if ( ! isset ( $ config [ 'env' ] [ 'REQUEST_URI' ] ) ) { throw new NetException ( "Missing `'REQUEST_URI'` environment variable, unable to create the main request." ) ; } if ( ! isset ( $ config [ 'env' ] [ 'SCRIPT_NAME' ] ) ) { throw new NetException ( "Missing `'SCRIPT_NAME'` environment variable, unable to create the main request." ) ; } return new static ( $ config + [ 'body' => new Part ( [ 'filename' => 'php://input' , 'mode' => 'r' ] ) , 'query' => isset ( $ _GET ) ? $ _GET : [ ] , 'cookies' => $ _COOKIE ] ) ; }
|
Creates a request extracted from CGI globals .
|
1,831
|
private function setDefaultManipulationInformation ( ) { $ this -> add_base_dn = $ this -> basedn_array [ 0 ] ; $ this -> add_dn = $ this -> dn ; $ this -> add_pw = $ this -> password ; $ this -> modify_method = "self" ; $ this -> modify_base_dn = $ this -> add_base_dn ; $ this -> modify_dn = $ this -> add_dn ; $ this -> modify_pw = $ this -> add_pw ; }
|
Sets the base DN and credentials for add and modify operations based on the search base DN and credentials . This is done to provide sensible defaults in case the specific setter methods are not invoked .
|
1,832
|
public function connect ( $ username = "" , $ password = "" ) { if ( ! extension_loaded ( 'ldap' ) ) { throw new LdapExtensionNotLoadedException ( ) ; } $ params = array ( 'hostname' => $ this -> host , 'base_dn' => $ this -> basedn , 'options' => [ ConnectionInterface :: OPT_PROTOCOL_VERSION => $ this -> version , ] , ) ; if ( ! empty ( $ this -> overlay_dn ) ) { $ params [ 'base_dn' ] = $ this -> overlay_dn ; } $ this -> ldap = new Manager ( $ params , new Driver ( ) ) ; try { $ this -> ldap -> connect ( ) ; if ( ! empty ( $ username ) ) { foreach ( $ this -> basedn_array as $ basedn ) { try { $ selectedUsername = $ this -> search_username . "=" . $ username ; if ( ! empty ( $ basedn ) ) { $ selectedUsername .= "," . $ basedn ; } $ selectedPassword = "" ; if ( empty ( $ password ) ) { if ( $ this -> allowNoPass ) { $ selectedUsername = $ this -> dn ; $ selectedPassword = $ this -> password ; } } else { $ selectedPassword = $ password ; } if ( ! empty ( $ this -> overlay_dn ) ) { $ selectedUsername .= "," . $ this -> overlay_dn ; } $ this -> bind ( $ selectedUsername , $ selectedPassword ) ; return true ; } catch ( BindException $ e ) { } } } else { $ dn = $ this -> dn ; if ( ! empty ( $ this -> overlay_dn ) ) { $ dn .= "," . $ this -> overlay_dn ; } $ this -> bind ( $ dn , $ this -> password ) ; } return true ; } catch ( BindException $ be ) { return false ; } catch ( Exception $ e ) { throw $ e ; } return false ; }
|
Connects and binds to the LDAP server . An optional username and password can be supplied to override the default credentials . Returns whether the connection and binding was successful .
|
1,833
|
public function connectByDN ( $ dn , $ password = "" ) { if ( ! extension_loaded ( 'ldap' ) ) { throw new LdapExtensionNotLoadedException ( ) ; } $ params = array ( 'hostname' => $ this -> host , 'base_dn' => $ this -> basedn , 'options' => [ ConnectionInterface :: OPT_PROTOCOL_VERSION => $ this -> version , ] , ) ; if ( ! empty ( $ this -> overlay_dn ) ) { $ params [ 'base_dn' ] = $ this -> overlay_dn ; } $ this -> ldap = new Manager ( $ params , new Driver ( ) ) ; try { $ this -> ldap -> connect ( ) ; if ( empty ( $ password ) ) { if ( $ this -> allowNoPass ) { $ dn = $ this -> dn ; if ( ! empty ( $ this -> overlay_dn ) ) { $ dn .= "," . $ this -> overlay_dn ; } $ password = $ this -> password ; } } $ this -> bind ( $ dn , $ password ) ; return true ; } catch ( BindException $ be ) { return false ; } catch ( Exception $ e ) { throw $ e ; } return false ; }
|
Connects and binds to the LDAP server based on the provided DN and an optional password . Returns whether the connection and binding were successful .
|
1,834
|
public function getAttributeFromResults ( $ results , $ attr_name ) { foreach ( $ results as $ node ) { if ( $ attr_name == "dn" ) { return $ node -> getDn ( ) ; } foreach ( $ node -> getAttributes ( ) as $ attribute ) { if ( strtolower ( $ attribute -> getName ( ) ) == strtolower ( $ attr_name ) ) { return $ attribute -> getValues ( ) [ 0 ] ; } } } return null ; }
|
Returns the value of the specified attribute from the result set . Returns null if the attribute could not be found .
|
1,835
|
public function searchByAuth ( $ value ) { $ numArgs = substr_count ( $ this -> search_auth_query , "%s" ) ; $ args = array_fill ( 0 , $ numArgs , $ value ) ; $ searchStr = vsprintf ( $ this -> search_auth_query , $ args ) ; $ results = null ; foreach ( $ this -> basedn_array as $ basedn ) { if ( ! empty ( $ this -> overlay_dn ) ) { if ( ! empty ( $ basedn ) ) { $ basedn .= ',' . $ this -> overlay_dn ; } else { $ basedn = $ this -> overlay_dn ; } } $ results = $ this -> ldap -> search ( $ basedn , $ searchStr ) ; if ( $ this -> isValidResult ( $ results ) ) { return $ results ; } } return $ results ; }
|
Queries LDAP for the record with the specified value for attributes matching what could commonly be used for authentication . For the purposes of this method uid mail and mailLocalAddress are searched by default unless their values have been overridden .
|
1,836
|
public function searchByEmail ( $ email ) { $ results = $ this -> ldap -> search ( $ this -> basedn , $ this -> search_mail . '=' . $ email ) ; return $ results ; }
|
Queries LDAP for the record with the specified email .
|
1,837
|
public function searchByEmailArray ( $ email ) { $ results = $ this -> ldap -> search ( $ this -> basedn , $ this -> search_mail_array . '=' . $ email ) ; return $ results ; }
|
Queries LDAP for the record with the specified mailLocalAddress .
|
1,838
|
public function searchByQuery ( $ query ) { $ results = $ this -> ldap -> search ( $ this -> basedn , $ query ) ; return $ results ; }
|
Queries LDAP for the records using the specified query .
|
1,839
|
public function searchByUid ( $ uid ) { $ results = $ this -> ldap -> search ( $ this -> basedn , $ this -> search_username . '=' . $ uid ) ; return $ results ; }
|
Queries LDAP for the record with the specified uid .
|
1,840
|
public function addObject ( $ identifier , $ attributes ) { $ this -> bind ( $ this -> add_dn , $ this -> add_pw ) ; $ node = new Node ( ) ; if ( strpos ( $ identifier , ',' ) !== FALSE ) { $ dn = $ identifier ; } else { $ dn = $ this -> search_username . '=' . $ identifier . ',' . $ this -> add_base_dn ; } $ node -> setDn ( $ dn ) ; try { $ this -> ldap -> getNode ( $ dn ) ; return false ; } catch ( NodeNotFoundException $ e ) { foreach ( $ attributes as $ key => $ value ) { $ node -> get ( $ key , true ) -> add ( $ value ) ; } $ this -> ldap -> save ( $ node ) ; return true ; } }
|
Adds an object into the add subtree using the specified identifier and an associative array of attributes . Returns a boolean describing whether the operation was successful . Throws an exception if the bind fails .
|
1,841
|
public function modifyObject ( $ identifier , $ attributes ) { if ( $ this -> modify_method != "self" ) { $ this -> bind ( $ this -> modify_dn , $ this -> modify_pw ) ; } if ( strpos ( $ identifier , ',' ) !== FALSE ) { $ dn = $ identifier ; } else { $ dn = $ this -> search_username . '=' . $ identifier . ',' . $ this -> modify_base_dn ; } try { $ node = $ this -> ldap -> getNode ( $ dn ) ; foreach ( $ attributes as $ key => $ value ) { if ( $ node -> has ( $ key ) ) { $ node -> get ( $ key ) -> set ( $ value ) ; } else { $ node -> get ( $ key , true ) -> add ( $ value ) ; } } $ this -> ldap -> save ( $ node ) ; return true ; } catch ( NodeNotFoundException $ e ) { return false ; } }
|
Modifies an object in the modify subtree using the specified identifier and an associative array of attributes . Returns a boolean describing whether the operation was successful . Throws an exception if the bind fails .
|
1,842
|
public function setAddBaseDN ( $ add_base_dn ) { if ( ! empty ( $ add_base_dn ) ) { $ this -> add_base_dn = $ add_base_dn ; } else { $ this -> add_base_dn = $ this -> basedn ; } }
|
Sets the base DN for add operations in a subtree .
|
1,843
|
public function setAddDN ( $ add_dn ) { if ( ! empty ( $ add_dn ) ) { $ this -> add_dn = $ add_dn ; } else { $ this -> add_dn = $ this -> dn ; } }
|
Sets the admin DN for add operations in a subtree . If the parameter is left empty the search admin DN will be used instead .
|
1,844
|
public function setAddPassword ( $ add_pw ) { if ( ! empty ( $ add_pw ) ) { $ this -> add_pw = $ add_pw ; } else { $ this -> add_pw = $ this -> password ; } }
|
Sets the admin password for add operations in a subtree . If the parameter is left empty the search admin password will be used instead .
|
1,845
|
public function setModifyBaseDN ( $ modify_base_dn ) { if ( ! empty ( $ modify_base_dn ) ) { $ this -> modify_base_dn = $ modify_base_dn ; } else { $ this -> modify_base_dn = $ this -> add_base_dn ; } }
|
Sets the base DN for modify operations in a subtree . If the parameter is left empty the add base DN will be used instead .
|
1,846
|
public function setModifyDN ( $ modify_dn ) { if ( ! empty ( $ modify_dn ) ) { $ this -> modify_dn = $ modify_dn ; } else { $ this -> modify_dn = $ this -> add_dn ; } }
|
Sets the admin DN for modify operations in a subtree . If the parameter is left empty the add admin DN will be used instead .
|
1,847
|
public function setModifyPassword ( $ modify_pw ) { if ( ! empty ( $ modify_pw ) ) { $ this -> modify_pw = $ modify_pw ; } else { $ this -> modify_pw = $ this -> add_pw ; } }
|
Sets the admin password for modify operations in a subtree . If the parameter is left empty the add admin password will be used instead .
|
1,848
|
protected function loadConfigFromFiles ( string ... $ configFiles ) { foreach ( $ configFiles as $ configFile ) { $ this -> config -> merge ( require $ configFile ) ; } }
|
Merges config params from service provider with the global configuration .
|
1,849
|
protected function provideCommands ( string ... $ commandClasses ) { $ commandCollector = $ this -> container -> get ( CommandCollection :: class ) ; foreach ( $ commandClasses as $ commandClass ) { $ commandCollector -> add ( $ commandClass ) ; } }
|
Registers commands exposed by service provider .
|
1,850
|
function post ( $ resource , $ payload = array ( ) , $ headers = array ( ) ) { $ result = $ this -> client -> post ( $ this -> build_url ( $ resource ) , [ 'headers' => array_merge ( [ 'Content-Type' => $ this -> getContentType ( ) , 'Authorization' => $ this -> getBearer ( ) , 'Content-Length' => ( ! count ( $ payload ) ) ? 0 : strlen ( json_encode ( $ payload ) ) , ] , $ headers ) , 'body' => json_encode ( $ payload ) ] ) ; return $ result ; }
|
Build and make a POST request .
|
1,851
|
function delete ( $ resource , $ headers = array ( ) ) { $ result = $ this -> client -> delete ( $ this -> build_url ( $ resource ) , [ 'headers' => array_merge ( [ 'Authorization' => $ this -> getBearer ( ) ] , $ headers ) ] ) ; return $ result ; }
|
Build and make a DELETE request .
|
1,852
|
public function request ( $ method , $ url , $ params = array ( ) , $ vars = array ( ) ) { $ this -> request = curl_init ( ) ; $ this -> setRequestMethod ( $ method ) ; $ this -> setOptions ( $ url , $ method , $ params , $ vars ) ; $ data = curl_exec ( $ this -> request ) ; if ( $ data === false ) { throw new \ Exception ( 'Curl Error: ' . curl_error ( $ this -> request ) ) ; } $ response = new HttpResponse ( $ data ) ; curl_close ( $ this -> request ) ; return $ response ; }
|
Executes a request
|
1,853
|
protected function setRequestMethod ( $ method ) { switch ( strtoupper ( $ method ) ) { case 'HEAD' : curl_setopt ( $ this -> request , CURLOPT_NOBODY , true ) ; break ; case 'GET' : curl_setopt ( $ this -> request , CURLOPT_CUSTOMREQUEST , 'GET' ) ; break ; case 'POST' : curl_setopt ( $ this -> request , CURLOPT_POST , true ) ; break ; default : curl_setopt ( $ this -> request , CURLOPT_CUSTOMREQUEST , $ method ) ; } }
|
Set the associated CURL options for a request method
|
1,854
|
protected function setOptions ( $ url , $ method , $ params , $ vars ) { if ( ! empty ( $ params ) ) { $ url = $ url . "?" . http_build_query ( $ params ) ; } curl_setopt ( $ this -> request , CURLOPT_URL , $ url ) ; curl_setopt ( $ this -> request , CURLOPT_HEADER , true ) ; curl_setopt ( $ this -> request , CURLOPT_RETURNTRANSFER , true ) ; curl_setopt ( $ this -> request , CURLOPT_FOLLOWLOCATION , true ) ; if ( in_array ( $ method , array ( 'POST' , 'PUT' ) ) || ( $ method == 'GET' && ! empty ( $ vars ) ) ) { $ this -> setJSONPayload ( $ vars ) ; } $ headers = array ( ) ; foreach ( $ this -> headers as $ key => $ value ) { $ headers [ ] = $ key . ':' . $ value ; } curl_setopt ( $ this -> request , CURLOPT_HTTPHEADER , $ headers ) ; }
|
Set the CURL options
|
1,855
|
protected function setJSONPayload ( $ vars ) { $ this -> headers [ 'Content-Type' ] = 'application/json' ; $ this -> headers [ 'Content-Length' ] = 0 ; $ this -> headers [ 'Expect' ] = '' ; if ( ! empty ( $ vars ) ) { $ data = json_encode ( $ vars ) ; $ this -> headers [ 'Content-Length' ] = strlen ( $ data ) ; curl_setopt ( $ this -> request , CURLOPT_POSTFIELDS , $ data ) ; } }
|
Set the JSON payload
|
1,856
|
public function format ( $ data ) { if ( ! $ data -> hasProperty ( 'meta' ) ) { return $ data ; } foreach ( $ data -> getProperty ( 'meta' ) as $ meta ) { $ regex = false ; if ( ! $ this -> metaKeyExists ( $ meta ) && ! ( $ regex = $ this -> metaKeyIsRegex ( $ meta ) ) ) { continue ; } if ( $ regex ) { $ property = $ this -> getRegexProperty ( $ regex , $ regex [ 'value' ] ) ; } else { $ property = $ this -> metaFields [ $ meta [ 'meta_key' ] ] ; } $ value = $ this -> getUnserializedValue ( $ meta ) ; $ data -> setProperty ( $ property , $ value ) ; } $ data -> unsetProperty ( 'meta' ) ; return $ data ; }
|
Format the meta fields from the given data .
|
1,857
|
protected function metaKeyIsRegex ( $ meta ) { if ( ! isset ( $ meta [ 'meta_key' ] ) ) { return false ; } return $ this -> pregMatchArray ( $ meta [ 'meta_key' ] , $ this -> regex ) ; }
|
Meta key is regex?
|
1,858
|
protected function getUnserializedValue ( $ meta ) { $ value = $ meta [ 'meta_value' ] ; if ( $ unserializedValue = @ unserialize ( $ value ) ) { $ value = $ unserializedValue ; } return $ value ; }
|
Get unserialized value .
|
1,859
|
private function processConfig ( ) { $ processor = new Processor ( ) ; $ coreConfig = Yaml :: parse ( file_get_contents ( __DIR__ . '/Resources/core_filters.yml' ) ) ; $ configs = array ( $ this -> config , $ coreConfig ) ; $ configuration = new StereoConfiguration ( ) ; $ processedConfiguration = $ processor -> processConfiguration ( $ configuration , $ configs ) ; foreach ( $ processedConfiguration [ 'core_filters' ] as $ filterClass ) { $ this -> mixer -> addFilter ( $ filterClass ) ; } foreach ( $ processedConfiguration [ 'custom_filters' ] as $ customFilterClass ) { $ this -> mixer -> addFilter ( $ customFilterClass ) ; } foreach ( $ processedConfiguration [ 'tapes' ] as $ name => $ settings ) { $ tape = new Tape ( $ name ) ; foreach ( $ settings [ 'filters' ] as $ k => $ args ) { $ filter = $ this -> mixer -> createFilter ( $ k , $ args ) ; $ tape -> addFilter ( $ filter ) ; } $ this -> addTape ( $ tape ) ; } }
|
Process configuration for registering tapes and filters .
|
1,860
|
public function dump ( ) { foreach ( $ this -> tapes as $ tape ) { if ( $ tape -> hasResponses ( ) ) { $ fileName = 'record_' . $ tape -> getName ( ) . '.json' ; $ content = $ this -> formatter -> encodeResponsesCollection ( $ tape -> getResponses ( ) ) ; $ this -> writer -> write ( $ fileName , $ content ) ; } } }
|
Dumps the tapes on disk .
|
1,861
|
public function getTapeContent ( $ name ) { $ tape = $ this -> getTape ( $ name ) ; if ( $ tape -> hasResponses ( ) ) { $ content = $ this -> formatter -> encodeResponsesCollection ( $ tape -> getResponses ( ) ) ; return $ content ; } return ; }
|
Returns the content of a specific tape without writing it to disk .
|
1,862
|
protected function buildTabsArray ( $ availableGroups , $ attachedGroups ) { $ addGroupItems = [ ] ; $ tabs = [ ] ; foreach ( $ availableGroups as $ id => $ name ) { if ( ! in_array ( $ id , $ attachedGroups ) ) { $ addGroupItems [ $ id ] = $ name ; } $ isAttached = in_array ( $ id , $ attachedGroups ) ; if ( $ isAttached ) { $ content = '' ; $ properties = Property :: find ( ) -> from ( Property :: tableName ( ) . ' p' ) -> innerJoin ( PropertyPropertyGroup :: tableName ( ) . ' ppg' , 'p.id = ppg.property_id' ) -> where ( [ 'ppg.property_group_id' => $ id ] ) -> all ( ) ; foreach ( $ properties as $ property ) { $ content .= $ property -> handler ( ) -> renderProperty ( $ this -> model , $ property , AbstractPropertyHandler :: BACKEND_EDIT , $ this -> form ) ; } $ tabs [ ] = [ 'label' => Html :: encode ( $ name ) . ' ' . Html :: button ( new Icon ( 'close' ) , [ 'class' => 'btn btn-danger btn-xs' , 'data-group-id' => $ id , 'data-action' => 'delete-property-group' , ] ) , 'content' => $ content . Html :: hiddenInput ( 'propertyGroupIds[]' , $ id , [ 'class' => 'property-group-ids' , ] ) , ] ; } } $ tabs [ ] = [ 'label' => Select2 :: widget ( [ 'data' => $ addGroupItems , 'name' => 'plus-group' , 'options' => [ 'placeholder' => Module :: t ( 'widget' , '(+) Add group' ) , 'style' => [ 'min-width' => '100px' ] ] , 'pluginOptions' => [ 'allowClear' => true ] , ] ) , 'url' => '#' , ] ; return $ tabs ; }
|
Build array for tabs .
|
1,863
|
public function packageExists ( $ namespace , $ package ) { $ folder = $ this -> vendorFolder . $ namespace ; $ folderExists = file_exists ( $ folder ) ; if ( ! $ folderExists ) { return false ; } $ packageFolder = $ folder . '/' . $ package ; $ packageFolderExists = file_exists ( $ packageFolder ) ; return $ packageFolderExists ; }
|
Determine if a composer package exists .
|
1,864
|
public function onBeforeSend ( Event $ event ) { $ request = $ event [ 'request' ] ; list ( $ newUrl , $ port ) = $ this -> proxify ( $ request -> getUrl ( ) , $ this -> bucketKey , $ this -> gatewayHost ) ; $ request -> setUrl ( $ newUrl ) ; if ( $ port ) { $ request -> setHeader ( 'Runscope-Request-Port' , $ port ) ; } if ( $ this -> authToken ) { $ request -> setHeader ( 'Runscope-Bucket-Auth' , $ this -> authToken ) ; } }
|
Event triggered right before sending a request
|
1,865
|
public function add_action ( $ hook , $ component , $ callback , $ priority = 10 , $ accepted_args = 1 ) { $ this -> actions = $ this -> add ( $ this -> actions , $ hook , $ component , $ callback , $ priority , $ accepted_args ) ; }
|
Add a new action to the collection to be registered with WordPress .
|
1,866
|
public function add_filter ( $ hook , $ component , $ callback , $ priority = 10 , $ accepted_args = 1 ) { $ this -> filters = $ this -> add ( $ this -> filters , $ hook , $ component , $ callback , $ priority , $ accepted_args ) ; }
|
Add a new filter to the collection to be registered with WordPress .
|
1,867
|
public function run ( ) { foreach ( $ this -> filters as $ hook ) { add_filter ( $ hook [ 'hook' ] , array ( $ hook [ 'component' ] , $ hook [ 'callback' ] ) , $ hook [ 'priority' ] , $ hook [ 'accepted_args' ] ) ; } foreach ( $ this -> actions as $ hook ) { add_action ( $ hook [ 'hook' ] , array ( $ hook [ 'component' ] , $ hook [ 'callback' ] ) , $ hook [ 'priority' ] , $ hook [ 'accepted_args' ] ) ; } }
|
Register the filters and actions with WordPress .
|
1,868
|
public function getTranslations ( $ language , $ instance , $ parent_instance = false ) { $ sql = <<<TRANSLATIONS SELECT id, message, comment, SUBSTRING_INDEX(GROUP_CONCAT(destination_instance ORDER BY language_depth DESC, instance_depth DESC SEPARATOR '##-##'),'##-##',1) as destination_instance, SUBSTRING_INDEX(GROUP_CONCAT(language ORDER BY language_depth DESC, instance_depth DESC SEPARATOR '##-##'),'##-##',1) as language, SUBSTRING_INDEX(GROUP_CONCAT(translation ORDER BY language_depth DESC, instance_depth DESC SEPARATOR '##-##'),'##-##',1) as translation, SUBSTRING_INDEX(GROUP_CONCAT(author ORDER BY language_depth DESC, instance_depth DESC SEPARATOR '##-##'),'##-##',1) as author, SUBSTRING_INDEX(GROUP_CONCAT(modified ORDER BY language_depth DESC, instance_depth DESC SEPARATOR '##-##'),'##-##',1) as modified, SUBSTRING_INDEX(GROUP_CONCAT(is_base_lang ORDER BY language_depth DESC, instance_depth DESC SEPARATOR '##-##'),'##-##',1) as is_base_lang FROM ( SELECT m.id, m.message, m.comment, m.instance AS message_instance, t.instance AS translation_instance, i.instance AS destination_instance, ip.instance AS instance_parent, ( SELECT COUNT(ip_x.instance) as depth FROM i18n_instances i_x JOIN i18n_instances ip_x ON i_x.lft BETWEEN ip_x.lft AND ip_x.rgt WHERE i_x.instance = t.instance GROUP BY i_x.instance ) as instance_depth, t.lang as origin_language, l.lang as language, ( SELECT COUNT(lp_x.lang) as depth FROM i18n_languages l_x JOIN i18n_languages lp_x ON l_x.lft BETWEEN lp_x.lft AND lp_x.rgt WHERE l_x.lang = lp.lang GROUP BY l_x.lang ) as language_depth, t.translation AS translation, t.author AS author, t.modified AS modified, IF(t.lang = l.lang, 1, 0) as is_base_lang FROM i18n_messages m LEFT JOIN i18n_languages l ON l.lang = ? LEFT JOIN i18n_languages lp ON l.lft BETWEEN lp.lft AND lp.rgt LEFT JOIN i18n_translations t ON m.id = t.id_message AND t.lang = lp.lang LEFT JOIN i18n_instances i ON i.instance = ? LEFT JOIN i18n_instances ip ON i.lft BETWEEN ip.lft AND ip.rgt WHERE t.instance = ip.instance ORDER BY IF(t.id_message IS NULL,0,1), LOWER(CONVERT(m.message USING utf8)), m.id, t.lang = l.lang DESC ) tbl GROUP BY id;TRANSLATIONS ; return $ this -> GetArray ( $ sql , array ( $ language , $ instance , 'tag' => 'Get all translations for current language' ) ) ; }
|
Returns the translations list for a given langauge .
|
1,869
|
public function getStats ( $ instance , $ parent_instance ) { $ parent_instance_sql = '' ; $ parent_instance_sub_sql = 'm.instance = ? OR t.instance = ?' ; if ( $ parent_instance ) { $ parent_instance_sql = ' OR instance IS NULL ' ; $ parent_instance_sub_sql = '( m.instance = ? OR m.instance IS NULL ) AND ( t.instance = ? OR t.instance IS NULL )' ; } $ sql = <<<TRANSLATIONSSELECT l.english_name, l.lang, lc.local_name AS name, @lang := l.lang AS lang, @translated := (SELECT COUNT(*) FROM i18n_translations WHERE ( instance = ? $parent_instance_sql ) AND lang = @lang AND translation != '' AND translation IS NOT NULL ) AS total_translated, @total := (SELECT COUNT(DISTINCT(m.id)) FROM i18n_messages m LEFT JOIN i18n_translations t ON m.id=t.id_message AND t.lang = @lang WHERE $parent_instance_sub_sql ) AS total, ROUND( ( @translated / @total) * 100, 2 ) AS percent, ( @total - @translated ) AS missingFROM i18n_languages l LEFT JOIN i18n_language_codes lc ON l.lang = lc.l10nORDER BY percent DESC, english_name ASCTRANSLATIONS ; return $ this -> GetArray ( $ sql , array ( 'tag' => 'Get current stats' , $ instance , $ instance , $ instance , $ instance , $ instance ) ) ; }
|
Get stats of translations .
|
1,870
|
public function addMessage ( $ message , $ instance = null ) { $ sql = <<<SQLINSERT INTO i18n_messagesSET message = ?, instance = ?SQL ; return $ this -> Execute ( $ sql , array ( 'tag' => 'Add message' , $ message , $ instance ) ) ; }
|
Add message in database .
|
1,871
|
protected function buildMessage ( array $ allowedMethods ) : string { $ ending = 'Allowed method is: %s' ; if ( count ( $ allowedMethods ) > 1 ) { $ ending = 'Allowed methods are: %s' ; } return sprintf ( 'Method is not allowed. ' . $ ending , implode ( ', ' , $ allowedMethods ) ) ; }
|
Builds error message
|
1,872
|
public function accepts ( ) { $ accepts = $ this -> hasHeader ( 'Accept' ) ? $ this -> getHeader ( 'Accept' ) : [ 'text/html' ] ; foreach ( $ accepts as $ i => $ value ) { list ( $ mime , $ q ) = preg_split ( '/;\s*q\s*=\s*/' , $ value , 2 ) + [ $ value , 1.0 ] ; $ stars = substr_count ( $ mime , '*' ) ; $ score = $ stars ? ( 0.03 - $ stars * 0.01 ) : $ q ; $ score = $ score * 100000 + strlen ( $ mime ) ; $ preferences [ $ score ] [ strtolower ( trim ( $ mime ) ) ] = ( float ) $ q ; } krsort ( $ preferences ) ; $ preferences = call_user_func_array ( 'array_merge' , $ preferences ) ; return $ preferences ; }
|
Return information about the mime of content that the client is requesting .
|
1,873
|
public function url ( ) { $ scheme = $ this -> scheme ( ) ; $ scheme = $ scheme ? $ scheme . '://' : '//' ; $ query = $ this -> query ( ) ? '?' . http_build_query ( $ this -> query ( ) ) : '' ; $ fragment = $ this -> fragment ( ) ? '#' . $ this -> fragment ( ) : '' ; return $ scheme . $ this -> host ( ) . $ this -> path ( ) . $ query . $ fragment ; }
|
Returns the message URI .
|
1,874
|
public function credential ( ) { if ( ! $ username = $ this -> username ( ) ) { return '' ; } $ credentials = $ username ; if ( $ password = $ this -> password ( ) ) { $ credentials .= ':' . $ password ; } return $ credentials ; }
|
Returns the credential .
|
1,875
|
public function requestTarget ( ) { if ( $ this -> method ( ) === 'CONNECT' || $ this -> mode ( ) === 'authority' ) { $ credential = $ this -> credential ( ) ; return ( $ credential ? $ credential . '@' : '' ) . $ this -> host ( ) ; } if ( $ this -> mode ( ) === 'absolute' ) { return $ this -> url ( ) ; } if ( $ this -> mode ( ) === 'asterisk' ) { return '*' ; } $ query = $ this -> query ( ) ? '?' . http_build_query ( $ this -> query ( ) ) : '' ; $ fragment = $ this -> fragment ( ) ; return $ this -> path ( ) . $ query . ( $ fragment ? '#' . $ fragment : '' ) ; }
|
Returns the request target present in the status line .
|
1,876
|
public function auth ( $ auth = true ) { $ headers = $ this -> headers ( ) ; if ( $ auth === false ) { unset ( $ headers [ 'Authorization' ] ) ; } if ( ! $ auth ) { return ; } if ( is_array ( $ auth ) && ! empty ( $ auth [ 'nonce' ] ) ) { $ data = [ 'method' => $ this -> method ( ) , 'uri' => $ this -> path ( ) ] ; $ data += $ auth ; } else { $ data = [ ] ; } $ auth = $ this -> _classes [ 'auth' ] ; $ data = $ auth :: encode ( $ this -> username ( ) , $ this -> password ( ) , $ data ) ; $ headers [ 'Authorization' ] = $ auth :: header ( $ data ) ; return $ this ; }
|
Sets the request authorization .
|
1,877
|
public function applyCookies ( $ cookies ) { $ values = [ ] ; foreach ( $ cookies as $ cookie ) { if ( $ cookie -> matches ( $ this -> url ( ) ) ) { $ values [ $ cookie -> path ( ) ] = $ cookie -> name ( ) . '=' . $ cookie -> value ( ) ; } } $ keys = array_map ( 'strlen' , array_keys ( $ values ) ) ; array_multisort ( $ keys , SORT_DESC , $ values ) ; $ headers = $ this -> headers ( ) ; if ( $ values ) { $ headers [ 'Cookie' ] = implode ( '; ' , $ values ) ; } else { unset ( $ headers [ 'Cookie' ] ) ; } return $ this ; }
|
Set the Cookie header
|
1,878
|
public function cookieValues ( ) { $ headers = $ request -> headers ( ) ; return isset ( $ headers [ 'Cookie' ] ) ? CookieValues :: toArray ( $ headers [ 'Cookie' ] -> value ( ) ) : [ ] ; }
|
Extract cookies value .
|
1,879
|
public static function create ( $ method = 'GET' , $ url = null , $ config = [ ] ) { if ( func_num_args ( ) ) { if ( ! preg_match ( '~^(?:[a-z]+:)?//~i' , $ url ) || ! $ defaults = parse_url ( $ url ) ) { throw new NetException ( "Invalid url: `'{$url}'`." ) ; } $ defaults [ 'username' ] = isset ( $ defaults [ 'user' ] ) ? $ defaults [ 'user' ] : null ; $ defaults [ 'password' ] = isset ( $ defaults [ 'pass' ] ) ? $ defaults [ 'pass' ] : null ; } $ config [ 'method' ] = strtoupper ( $ method ) ; return new static ( $ config + $ defaults ) ; }
|
Creates a request instance using an absolute URL .
|
1,880
|
public function addTo ( $ address , $ name = null ) { $ address = $ this -> _addRecipient ( 'To' , $ address , $ name ) ; $ this -> _recipients [ $ address -> email ( ) ] = $ address ; return $ this ; }
|
Add an email recipient .
|
1,881
|
public function addCc ( $ address , $ name = null ) { $ address = $ this -> _addRecipient ( 'Cc' , $ address , $ name ) ; $ this -> _recipients [ $ address -> email ( ) ] = $ address ; return $ this ; }
|
Adds carbon copy email recipient .
|
1,882
|
public function addBcc ( $ address , $ name = null ) { $ class = $ this -> _classes [ 'address' ] ; $ bcc = new $ class ( $ address , $ name ) ; $ this -> _recipients [ $ bcc -> email ( ) ] = $ bcc ; return $ this ; }
|
Adds blind carbon copy email recipient .
|
1,883
|
protected function _addRecipient ( $ type , $ address , $ name = null ) { $ classes = $ this -> _classes ; $ headers = $ this -> headers ( ) ; if ( ! isset ( $ headers [ $ type ] ) ) { $ addresses = $ classes [ 'addresses' ] ; $ headers [ $ type ] = new $ addresses ( ) ; } $ class = $ classes [ 'address' ] ; $ value = new $ class ( $ address , $ name ) ; $ headers [ $ type ] [ ] = $ value ; return $ value ; }
|
Add a recipient to a specific type section .
|
1,884
|
public function addInline ( $ path , $ name = null , $ mime = true , $ encoding = true ) { $ cid = static :: generateId ( $ this -> client ( ) ) ; $ filename = basename ( $ path ) ; $ this -> _inlines [ $ path ] = [ 'filename' => $ name ? : $ filename , 'disposition' => 'attachment' , 'mime' => $ mime , 'headers' => [ 'Content-ID: ' . $ cid ] ] ; return $ cid ; }
|
Add an embedded file .
|
1,885
|
public function addAttachment ( $ path , $ name = null , $ mime = true , $ encoding = true ) { $ cid = static :: generateId ( $ this -> client ( ) ) ; $ filename = basename ( $ path ) ; $ this -> _attachments [ $ path ] = [ 'filename' => $ name ? : $ filename , 'disposition' => 'attachment' , 'mime' => $ mime , 'headers' => [ 'Content-ID: ' . $ cid ] ] ; return $ cid ; }
|
Add an attachment .
|
1,886
|
public function html ( $ body , $ basePath = null ) { if ( ! func_num_args ( ) ) { return $ this -> _body ; } if ( $ basePath ) { $ cids = [ ] ; $ hasInline = preg_match_all ( '~ (<img[^<>]*\s src\s*=\s* |<body[^<>]*\s background\s*=\s* |<[^<>]+\s style\s*=\s* ["\'][^"\'>]+[:\s] url\( |<style[^>]*>[^<]+ [:\s] url\() (["\']?)(?![a-z]+:|[/#])([^"\'>)\s]+) |\[\[ ([\w()+./@\\~-]+) \]\] ~ix' , $ body , $ matches , PREG_OFFSET_CAPTURE | PREG_SET_ORDER ) ; if ( $ hasInline ) { foreach ( array_reverse ( $ matches ) as $ m ) { $ file = rtrim ( $ basePath , '/\\' ) . '/' . ( isset ( $ m [ 4 ] ) ? $ m [ 4 ] [ 0 ] : urldecode ( $ m [ 3 ] [ 0 ] ) ) ; if ( ! isset ( $ cids [ $ file ] ) ) { $ cids [ $ file ] = substr ( $ this -> addInline ( $ file ) , 1 , - 1 ) ; } $ body = substr_replace ( $ body , "{$m[1][0]}{$m[2][0]}cid:{$cids[$file]}" , $ m [ 0 ] [ 1 ] , strlen ( $ m [ 0 ] [ 0 ] ) ) ; } } } $ this -> body ( $ body ) ; $ this -> mime ( 'text/html' ) ; $ this -> charset ( Mime :: optimalCharset ( $ body ) ) ; $ this -> _altBody = static :: stripTags ( $ this -> _body ) ; return $ this ; }
|
Set the HTML body message with an optionnal alternative body .
|
1,887
|
public static function stripTags ( $ html , $ charset = 'UTF-8' ) { $ patterns = [ '~<(style|script|head).*</\\1>~Uis' => '' , '~<t[dh][ >]~i' => ' $0' , '~<a\s[^>]*href=(?|"([^"]+)"|\'([^\']+)\')[^>]*>(.*?)</a>~is' => '$2 <$1>' , '~[\r\n ]+~' => ' ' , '~<(/?p|/?h\d|li|br|/tr)[ >/]~i' => "\n$0" , ] ; $ text = preg_replace ( array_keys ( $ patterns ) , array_values ( $ patterns ) , $ html ) ; $ text = html_entity_decode ( strip_tags ( $ text ) , ENT_QUOTES , $ charset ) ; $ text = preg_replace ( '~[ \t]+~' , ' ' , $ text ) ; return trim ( $ text ) ; }
|
Strip HTML tags
|
1,888
|
protected function initializeProperties ( $ properties = null ) { $ this -> getPropertiesInfo ( ) ; $ initializeValueValidationEnabled = Configuration :: isInitializeValuesValidationEnabled ( ) ; foreach ( $ this -> _initialPropertiesValues as $ propertyName => $ initialization ) { $ value = null ; switch ( $ initialization [ 'type' ] ) { case 'initialize' : $ value = $ initialization [ 'value' ] ; break ; default : $ className = $ initialization [ 'value' ] ; $ value = new $ className ( ) ; break ; } if ( $ initializeValueValidationEnabled ) { $ this -> assertPropertyValue ( $ propertyName , $ value ) ; } $ this -> $ propertyName = $ value ; $ this -> updateInitializedPropertyValue ( $ propertyName , $ value ) ; } if ( $ this -> _initializationNeededArguments !== null && $ properties !== null ) { $ numberOfNeededArguments = count ( $ this -> _initializationNeededArguments ) ; MethodCallManager :: assertArgsNumber ( $ numberOfNeededArguments , $ properties ) ; for ( $ i = 0 ; $ i < $ numberOfNeededArguments ; $ i ++ ) { $ propertyName = $ this -> _initializationNeededArguments [ $ i ] ; $ argument = $ properties [ $ i ] ; $ this -> assertPropertyValue ( $ propertyName , $ argument ) ; $ this -> $ propertyName = $ argument ; $ this -> updateInitializedPropertyValue ( $ propertyName , $ argument ) ; } } }
|
Initializes the object according to its class specification and given arguments .
|
1,889
|
private function updateInitializedPropertyValue ( $ propertyName , $ value ) { if ( empty ( $ this -> _collectionsItemNames [ 'byProperty' ] [ $ propertyName ] ) ) { $ this -> updatePropertyAssociation ( $ propertyName , array ( "oldValue" => null , "newValue" => $ value ) ) ; } else { foreach ( $ value as $ newValue ) { $ this -> updatePropertyAssociation ( $ propertyName , array ( "oldValue" => null , "newValue" => $ newValue ) ) ; } } }
|
Update an initialized value .
|
1,890
|
protected function delete_vulnerabilities ( ) { $ query = new WP_Query ( [ 'fields' => 'ids' , 'no_found_rows' => true , 'post_type' => 'soter_vulnerability' , 'post_status' => 'private' , 'posts_per_page' => - 1 , 'update_post_meta_cache' => false , 'update_post_term_cache' => false , ] ) ; foreach ( $ query -> posts as $ id ) { wp_delete_post ( $ id ) ; } }
|
Deletes any lingering soter_vulnerability posts .
|
1,891
|
protected function prepare_ignored_plugins ( array $ plugins ) { if ( ! function_exists ( 'get_plugins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php' ; } $ valid_slugs = array_map ( function ( $ file ) { if ( false === strpos ( $ file , '/' ) ) { $ slug = basename ( $ file , '.php' ) ; } else { $ slug = dirname ( $ file ) ; } return $ slug ; } , array_keys ( get_plugins ( ) ) ) ; return array_values ( array_intersect ( $ valid_slugs , $ plugins ) ) ; }
|
Ensure ignored plugins setting only contains currently installed plugins .
|
1,892
|
protected function prepare_ignored_themes ( array $ themes ) { $ valid_slugs = array_values ( wp_list_pluck ( wp_get_themes ( ) , 'stylesheet' ) ) ; return array_values ( array_intersect ( $ valid_slugs , $ themes ) ) ; }
|
Ensure ignored themes setting only contains currently installed themes .
|
1,893
|
protected function upgrade_to_050 ( ) { if ( $ this -> options -> installed_version ) { return ; } $ this -> upgrade_cron ( ) ; $ this -> upgrade_options ( ) ; $ this -> upgrade_results ( ) ; $ this -> delete_vulnerabilities ( ) ; $ this -> options -> get_store ( ) -> set ( 'installed_version' , '0.5.0' ) ; }
|
Required logic for upgrading to v0 . 5 . 0 .
|
1,894
|
protected function upgrade_options ( ) { $ old_options = ( array ) $ this -> options -> get_store ( ) -> get ( 'settings' , [ ] ) ; if ( isset ( $ old_options [ 'email_address' ] ) ) { $ sanitized = sanitize_email ( $ old_options [ 'email_address' ] ) ; if ( $ sanitized ) { $ this -> options -> get_store ( ) -> set ( 'email_address' , $ old_options [ 'email_address' ] ) ; } } if ( isset ( $ old_options [ 'html_email' ] ) && $ old_options [ 'html_email' ] ) { $ this -> options -> get_store ( ) -> set ( 'email_type' , 'html' ) ; } if ( isset ( $ old_options [ 'ignored_plugins' ] ) && is_array ( $ old_options [ 'ignored_plugins' ] ) ) { $ ignored_plugins = $ this -> prepare_ignored_plugins ( $ old_options [ 'ignored_plugins' ] ) ; if ( ! empty ( $ ignored_plugins ) ) { $ this -> options -> get_store ( ) -> set ( 'ignored_plugins' , $ ignored_plugins ) ; } } if ( isset ( $ old_options [ 'ignored_themes' ] ) && is_array ( $ old_options [ 'ignored_themes' ] ) ) { $ ignored_themes = $ this -> prepare_ignored_themes ( $ old_options [ 'ignored_themes' ] ) ; if ( ! empty ( $ ignored_themes ) ) { $ this -> options -> get_store ( ) -> set ( 'ignored_themes' , $ ignored_themes ) ; } } $ this -> options -> get_store ( ) -> set ( 'email_enabled' , 'yes' ) ; $ this -> options -> get_store ( ) -> set ( 'last_scan_hash' , '' ) ; $ this -> options -> get_store ( ) -> set ( 'should_nag' , 'yes' ) ; $ this -> options -> get_store ( ) -> set ( 'slack_enabled' , 'no' ) ; $ this -> options -> get_store ( ) -> set ( 'slack_url' , '' ) ; $ this -> options -> get_store ( ) -> delete ( 'settings' ) ; }
|
Upgrade to latest options implementation .
|
1,895
|
public function create ( $ device , array $ tagNames = array ( ) ) { if ( ! empty ( $ tagNames ) ) { $ tagEndpoint = new Tags ( $ this -> client ) ; $ tags = $ tagEndpoint -> findAll ( $ tagNames ) ; if ( ! empty ( $ tags [ 'notFound' ] ) ) { foreach ( $ tags [ 'notFound' ] as $ name ) { $ tags [ 'tags' ] [ ] = $ tagEndpoint -> create ( $ name ) ; } } $ formattedTags = $ tagEndpoint -> format ( $ tags [ 'tags' ] , 'other' ) ; $ device [ 'tags' ] = $ formattedTags [ 'tags' ] ; } $ device = $ this -> makeJsonReady ( $ device ) ; return $ this -> post ( 'inventory/devices/' , $ device ) ; }
|
Create a device
|
1,896
|
public function tokenize ( string $ input ) : TokenStream { $ this -> prepare ( $ input ) ; while ( $ this -> cursor < $ this -> end ) { $ this -> currentChar = $ this -> input [ $ this -> cursor ] ; if ( preg_match ( '@' . Token :: REGEX_T_EOL . '@' , $ this -> currentChar ) ) { if ( $ this -> mode !== self :: MODE_IDENT ) { ++ $ this -> line ; $ this -> lineOffset = $ this -> cursor + 1 ; } } switch ( $ this -> mode ) { case self :: MODE_ALL : $ this -> lexAll ( ) ; break ; case self :: MODE_INSIDE_TAG : $ this -> lexInsideTag ( ) ; break ; case self :: MODE_IDENT : $ this -> lexIdent ( ) ; break ; case self :: MODE_VAR : $ this -> lexVar ( ) ; break ; case self :: MODE_STRING : $ this -> lexString ( ) ; break ; case self :: MODE_NUMBER : $ this -> lexNumber ( ) ; break ; case self :: MODE_OP : $ this -> lexOperator ( ) ; break ; } } return $ this -> stream ; }
|
Tokenizes a string into a TokenStream
|
1,897
|
private function prepare ( string $ input ) { $ this -> input = str_replace ( [ "\n\r" , "\r" ] , "\n" , $ input ) ; $ this -> stream = new TokenStream ( ) ; $ this -> cursor = 0 ; $ this -> line = 1 ; $ this -> lineOffset = 0 ; $ this -> end = strlen ( $ this -> input ) ; $ this -> lastCharPos = $ this -> end - 1 ; $ this -> currentChar = '' ; $ this -> currentValue = '' ; $ this -> modeStartChar = '' ; $ this -> modeStartPosition = 0 ; $ this -> modeStartLine = 0 ; $ this -> setMode ( self :: MODE_ALL ) ; }
|
Prepares the Lexer for tokenizing a string
|
1,898
|
private function setMode ( int $ mode ) { $ this -> mode = $ mode ; $ this -> modeStartLine = $ this -> line ; $ this -> modeStartPosition = $ this -> getCurrentLinePosition ( ) ; }
|
Sets the lexing mode
|
1,899
|
protected function addManager ( $ fileInfo , & $ mikado ) { $ manager = new Manager ( ) ; $ pathParts = pathinfo ( $ fileInfo -> getBasename ( ) ) ; $ model = $ pathParts [ 'filename' ] ; $ this -> addFormatter ( $ manager , $ model , 'MetaFormatter' ) ; $ this -> addFormatter ( $ manager , $ model , 'RemapFormatter' ) ; $ this -> addFormatter ( $ manager , $ model , 'FilterFormatter' ) ; $ mikado -> add ( $ model , $ manager ) ; }
|
Add manager to mikado .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.