idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
3,200
|
private function dynamicFormCheck ( ) { if ( $ this -> field -> hasDynamicForms ( ) ) { $ this -> dynamicFormParentName = $ this -> field -> getName ( ) ; $ value = $ this -> field -> getValue ( ) ; $ forms = $ this -> field -> getDynamicForms ( ) ; $ this -> includeDynamicFormJavascript = true ; foreach ( $ forms as $ dynamicTriggerValue => $ form ) { $ this -> dynamicFormVisible = ( $ value == $ dynamicTriggerValue ) ; $ dynamicFields = $ form -> getFields ( ) ; $ this -> processFields ( $ dynamicFields , $ dynamicTriggerValue ) ; } unset ( $ this -> dynamicFormParentName ) ; } }
|
Checks current field being processed for dynamic sub forms
|
3,201
|
protected function prepareArrays ( array $ items = [ ] ) { $ items = array_map ( function ( $ item ) { return trim ( $ item ) ; } , $ items ) ; return array_filter ( $ items , function ( $ item ) { return ! empty ( $ item ) ; } ) ; }
|
Prepare arrays before accepting
|
3,202
|
public function parseWidget ( $ widget ) { if ( ! isset ( $ _SESSION [ 'FILES' ] [ $ this -> field -> getColName ( ) ] ) ) { return false ; } $ ext = pathinfo ( $ _SESSION [ 'FILES' ] [ $ this -> field -> getColName ( ) ] [ 'name' ] , PATHINFO_EXTENSION ) ; $ name = $ this -> field -> uploadPath . '/' . $ this -> item -> get ( 'id' ) . '_' . $ this -> field -> getColName ( ) . '.' . $ ext ; if ( move_uploaded_file ( $ _SESSION [ 'FILES' ] [ $ this -> field -> getColName ( ) ] [ 'tmp_name' ] , TL_ROOT . '/' . $ name ) ) { $ dbafsFile = \ Dbafs :: addResource ( $ name ) ; unset ( $ _SESSION [ 'FILES' ] [ $ this -> field -> getColName ( ) ] ) ; return $ dbafsFile -> uuid ; } return false ; }
|
Parses the widget and returns either the uuid of the file or false if moving the file failed
|
3,203
|
public function boot ( ) { $ this -> bootBlade ( ) ; $ this -> bootDatatable ( ) ; $ this -> bootModal ( ) ; $ this -> bootMail ( ) ; $ this -> bootValidator ( ) ; $ this -> publish ( ) ; }
|
Boot principale du service
|
3,204
|
public function bootValidator ( ) { \ Validator :: extend ( 'not_exists' , function ( $ attribute , $ value , $ parameters ) { $ row = \ DB :: table ( $ parameters [ 0 ] ) -> where ( $ parameters [ 1 ] , '=' , $ value ) -> first ( ) ; return empty ( $ row ) ; } ) ; }
|
Ajoute de nouveau validateur
|
3,205
|
public function bootMail ( ) { Response :: macro ( 'mail' , function ( $ view , $ data = [ ] , $ from = [ ] , $ to = [ ] , $ subject = '' , $ attach = [ ] ) { if ( $ from instanceof Mail \ Message ) { \ Mail :: send ( $ view , $ data , function ( Mail \ Message $ message ) use ( $ from , $ attach ) { $ swift = $ from -> getSwiftMessage ( ) ; $ message -> subject ( $ swift -> getSubject ( ) ) ; $ message -> from ( $ swift -> getFrom ( ) ) ; $ message -> to ( $ swift -> getTo ( ) ) ; if ( ! empty ( $ swift -> getSender ( ) ) ) { $ message -> sender ( $ swift -> getSender ( ) ) ; } if ( ! empty ( $ swift -> getCc ( ) ) ) { $ message -> cc ( $ swift -> getCc ( ) ) ; } if ( ! empty ( $ swift -> getBcc ( ) ) ) { $ message -> bcc ( $ swift -> getBcc ( ) ) ; } if ( ! empty ( $ swift -> getReplyTo ( ) ) ) { $ message -> replyTo ( $ swift -> getReplyTo ( ) ) ; } if ( ! empty ( $ swift -> getPriority ( ) ) ) { $ message -> priority ( $ swift -> getPriority ( ) ) ; } if ( ! empty ( $ swift -> getChildren ( ) ) ) { foreach ( $ swift -> getChildren ( ) as $ child ) { $ message -> attachData ( $ child -> getBody ( ) , $ child -> getHeaders ( ) -> get ( 'content-type' ) -> getParameter ( 'name' ) ) ; } } } ) ; } else { \ Mail :: send ( $ view , $ data , function ( Mail \ Message $ message ) use ( $ from , $ to , $ subject , $ attach ) { $ message -> from ( ... $ from ) -> subject ( $ subject ) ; foreach ( $ to as $ mail ) { $ message -> to ( ... $ mail ) ; } foreach ( $ attach as $ file ) { $ message -> attach ( $ file ) ; } } ) ; } } ) ; }
|
Permet d utiliser la reponse pour envoyer un mail
|
3,206
|
public function interceptMethodCall ( ProceedingJoinPointInterface $ jointPoint ) { if ( $ this -> breaker -> isAvailable ( $ this -> serviceName ) ) { try { $ result = $ jointPoint -> proceed ( ) ; $ this -> breaker -> reportSuccess ( $ this -> serviceName ) ; return $ result ; } catch ( Exception $ e ) { if ( $ this -> isServiceFailureException ( $ e ) ) { $ this -> breaker -> reportFailure ( $ this -> serviceName ) ; } else { $ this -> breaker -> reportSuccess ( $ this -> serviceName ) ; } throw $ e ; } } else { throw $ this -> throwOnFailure ; } }
|
In this implementation we ask CircuitBreaker implementation if it is safe to proceed with the service call .
|
3,207
|
public function getColumn ( string $ name ) : AbstractColumnDefinition { if ( ! $ this -> offsetExists ( $ name ) ) { throw new Exception \ UnexistentColumnException ( "Column '$name' does not exists in metadata" ) ; } return $ this -> offsetGet ( $ name ) ; }
|
Return specific column metadata .
|
3,208
|
public function parse ( $ selector ) { if ( '/' === $ selector ) { return array ( ) ; } if ( '/' !== substr ( $ selector , 0 , 1 ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Path "%s" must be absolute' , $ selector ) ) ; } $ selector = substr ( $ selector , 1 ) ; $ segments = array ( ) ; $ elements = explode ( '/' , $ selector ) ; foreach ( $ elements as $ index => $ element ) { if ( $ this -> processWildcard ( $ element ) ) { $ flags = self :: T_PATTERN ; } else { $ flags = self :: T_STATIC ; } if ( $ index === ( count ( $ elements ) - 1 ) ) { $ flags = $ flags | self :: T_LAST ; } $ segments [ ] = array ( $ element , $ flags ) ; } return $ segments ; }
|
Parse the given selector .
|
3,209
|
public function makeAuthenticatedApiRequest ( $ resource , array $ params = array ( ) , $ method = 'GET' ) { $ this -> assertHasActiveUser ( ) ; $ params [ 'oauth_token' ] = $ this -> token ; return $ this -> makeApiRequest ( $ resource , $ params , $ method ) ; }
|
make an authenticated request to the api
|
3,210
|
public function makeApiRequest ( $ resource , array $ params = array ( ) , $ method = 'GET' ) { $ uri = $ this -> requestUri . '/' . ltrim ( $ resource , '/' ) ; if ( $ this -> hasValidToken ( ) ) { $ params [ 'oauth_token' ] = $ this -> token ; } else { $ params [ 'client_id' ] = $ this -> clientId ; $ params [ 'client_secret' ] = $ this -> clientSecret ; } $ params [ 'v' ] = $ this -> dateVerified -> format ( 'Ymd' ) ; switch ( $ method ) { case 'GET' : $ response = json_decode ( $ this -> httpClient -> get ( $ uri , $ params ) ) ; break ; case 'POST' : $ response = json_decode ( $ this -> httpClient -> post ( $ uri , $ params ) ) ; break ; default : throw new \ RuntimeException ( 'Currently only HTTP methods "GET" and "POST" are supported.' ) ; } if ( isset ( $ response -> meta ) ) { if ( isset ( $ response -> meta -> code ) && $ response -> meta -> code != 200 ) { } if ( isset ( $ response -> meta -> notifications ) && is_array ( $ response -> meta -> notifications ) && count ( $ response -> meta -> notifications ) ) { } } return $ response -> response ; }
|
make a generic request to the api
|
3,211
|
protected function getCssContent ( ) { $ styleString = "" ; if ( class_exists ( "\\DOMDocument" ) ) { $ doc = new \ DOMDocument ( ) ; $ doc -> loadHTMLFile ( $ this -> getFilename ( ) ) ; foreach ( $ doc -> getElementsByTagName ( 'style' ) as $ styleNode ) { $ styleString .= $ styleNode -> nodeValue . "\r\n" ; } } else { throw new \ RuntimeException ( "Required extension 'dom' seems to be missing." ) ; } return $ styleString ; }
|
Gets the CSS content from the HTML source .
|
3,212
|
public function retrieveItemPrices ( $ itemsData , $ currency , $ locale ) { $ items = [ ] ; $ previousItem = null ; foreach ( $ itemsData as $ itemData ) { $ useProductsPrice = false ; if ( isset ( $ itemData [ 'useProductsPrice' ] ) && $ itemData [ 'useProductsPrice' ] == true ) { $ useProductsPrice = $ itemData [ 'useProductsPrice' ] ; } $ itemData = $ this -> setDefaultData ( $ itemData ) ; $ itemData = $ this -> unsetUneccesaryData ( $ itemData ) ; $ item = $ this -> getItemManager ( ) -> save ( $ itemData , $ locale , null , null , null , null , $ previousItem ) ; $ item -> setUseProductsPrice ( $ useProductsPrice ) ; $ itemPrice = $ this -> itemPriceCalculator -> calculateItemNetPrice ( $ item , $ currency , $ useProductsPrice , $ this -> isItemGrossPrice ( $ itemData ) ) ; $ itemTotalNetPrice = $ this -> itemPriceCalculator -> calculateItemTotalNetPrice ( $ item , $ currency , $ useProductsPrice , $ this -> isItemGrossPrice ( $ itemData ) ) ; $ item -> setPrice ( $ itemPrice ) ; $ item -> setTotalNetPrice ( $ itemTotalNetPrice ) ; if ( Item :: TYPE_ADDON !== $ item -> getType ( ) ) { $ previousItem = $ item -> getEntity ( ) ; } $ items [ ] = $ item ; } return [ 'items' => $ items , ] ; }
|
Calculates total prices of all items given in data array .
|
3,213
|
public function getMetadataForClass ( $ className ) { if ( ! class_exists ( $ className ) ) { throw new \ Exception ( "Class $className does not exist!" ) ; } if ( isset ( $ this -> loadedMetadatas [ $ className ] ) ) { return $ this -> loadedMetadatas [ $ className ] ; } return $ this -> loadedMetadatas [ $ className ] = $ this -> loadMetadataForClass ( $ className , $ this -> annotationReader ) ; }
|
Allow to get class metadata for specified class
|
3,214
|
protected function setValue ( $ value ) { if ( is_string ( $ value ) ) { $ value = trim ( $ value ) ; if ( $ value !== "" ) { $ this -> value = $ value ; } else { throw new \ InvalidArgumentException ( "Invalid value for argument 'value' given." ) ; } } else { throw new \ InvalidArgumentException ( "Invalid type '" . gettype ( $ value ) . "' for argument 'value' given. String expected." ) ; } return $ this ; }
|
Sets the value for the charset rule .
|
3,215
|
public function start ( $ environment = null , $ configLocation = null ) { $ config = $ this -> loadConfig ( $ environment , $ configLocation ) ; $ this -> loadErrorHandler ( $ config , $ environment ) ; $ instantiator = $ this -> loadContainer ( $ config , $ environment ) ; $ middleware = $ instantiator ( Middleware \ Middleware :: class ) ; $ response = $ middleware -> execute ( ) ; $ middleware -> emit ( $ response ) ; }
|
The starting point for any Weave App .
|
3,216
|
protected static function encodePart ( & $ input ) { $ codePoints = & static :: codePoints ( $ input ) ; $ n = static :: INITIAL_N ; $ bias = static :: INITIAL_BIAS ; $ delta = 0 ; $ h = $ b = count ( $ codePoints [ 'basic' ] ) ; $ output = static :: getString ( $ codePoints [ 'basic' ] ) ; if ( $ input === $ output ) { return $ output ; } if ( $ b > 0 ) { $ output .= static :: DELIMITER ; } $ codePoints [ 'nonBasic' ] = array_unique ( $ codePoints [ 'nonBasic' ] ) ; sort ( $ codePoints [ 'nonBasic' ] ) ; $ i = 0 ; $ length = $ codePoints [ 'length' ] ; while ( $ h < $ length ) { $ m = $ codePoints [ 'nonBasic' ] [ $ i ++ ] ; $ delta = $ delta + ( $ m - $ n ) * ( $ h + 1 ) ; $ n = $ m ; foreach ( $ codePoints [ 'all' ] as $ c ) { if ( $ c < $ n || $ c < static :: INITIAL_N ) { $ delta ++ ; } if ( $ c === $ n ) { $ q = $ delta ; for ( $ k = static :: BASE ; ; $ k += static :: BASE ) { $ t = static :: calculateThreshold ( $ k , $ bias ) ; if ( $ q < $ t ) { break ; } $ code = $ t + ( ( $ q - $ t ) % ( static :: BASE - $ t ) ) ; $ output .= static :: $ encodeTable [ $ code ] ; $ q = ( $ q - $ t ) / ( static :: BASE - $ t ) ; } $ output .= static :: $ encodeTable [ $ q ] ; $ bias = static :: adapt ( $ delta , $ h + 1 , ( $ h === $ b ) ) ; $ delta = 0 ; $ h ++ ; } } $ delta ++ ; $ n ++ ; } return static :: PREFIX . $ output ; }
|
Encode a part of a domain name such as tld to its Punycode version
|
3,217
|
public function blockOne ( $ host ) { return $ this -> exists ( $ host ) ? $ this -> updateOne ( $ host ) : $ this -> addOne ( $ host ) ; }
|
Add a host to a blacklist collection .
|
3,218
|
public function allowOne ( $ host ) { return $ this -> exists ( $ host ) ? $ this -> updateOne ( $ host , false ) : $ this -> addOne ( $ host , false ) ; }
|
Add a host to a whitelist collection .
|
3,219
|
private function addOne ( $ host , $ blocked = true ) { $ spammer = Spammer :: make ( $ host , $ blocked ) ; return $ this -> put ( $ spammer -> host ( ) , $ spammer ) ; }
|
Add a host to the collection .
|
3,220
|
public function whereHostIn ( array $ hosts , $ strict = false ) { $ values = $ this -> getArrayableItems ( $ hosts ) ; return $ this -> filter ( function ( Spammer $ spammer ) use ( $ values , $ strict ) { return in_array ( $ spammer -> host ( ) , $ values , $ strict ) ; } ) ; }
|
Filter the spammer by the given hosts .
|
3,221
|
public function updatePermissions ( Request $ request , Role $ role ) { $ this -> authorize ( 'manage_permissions' , Role :: class ) ; $ permissions = Permission :: all ( ) ; foreach ( $ permissions as $ permission ) { if ( array_key_exists ( $ permission -> id , $ request -> all ( ) ) ) { $ role -> addPermission ( $ permission ) ; } else { $ role -> deletePermission ( $ permission ) ; } } return redirect ( ) -> route ( 'laralum::roles.index' ) -> with ( 'success' , __ ( 'laralum_roles::general.role_permissions_updated' , [ 'id' => $ role -> id ] ) ) ; }
|
Update the role permissions .
|
3,222
|
public function contactUs ( Request $ request ) { $ this -> validate ( $ request , [ 'full_name' => 'required' , 'email' => 'required' , 'subject' => 'required' , 'message' => 'required' ] ) ; Mail :: send ( 'page::emails.contact-info' , [ 'data' => $ request -> all ( ) ] , function ( Message $ message ) use ( $ request ) { $ message -> from ( config ( "mail.username" ) , ': Contact request' ) ; $ message -> to ( $ this -> config ( "mail.username" ) , 'CTSFLA' ) -> subject ( 'Contact request' ) ; } ) ; return back ( ) -> with ( 'success' , config ( 'pagekit.contact_us_response' , 'Your message has been sent. Thank you!' ) ) ; }
|
Process the contact form name .
|
3,223
|
protected function writeLog ( $ message ) { $ fileName = 'app/logs/mail/error.log' ; $ log = sprintf ( "[%s]: %s\n" , date_format ( new \ DateTime ( ) , 'Y-m-d H:i:s' ) , $ message ) ; file_put_contents ( $ fileName , $ log , FILE_APPEND ) ; }
|
Writes a new line to mail error log
|
3,224
|
protected function author_traversal ( $ field , $ post ) { $ parts = explode ( '.' , $ field ) ; $ author = get_user_by ( 'id' , $ post -> post_author ) ; $ parts = explode ( '.' , $ field ) ; $ author = get_user_by ( 'id' , $ post -> post_author ) ; if ( is_object ( $ author ) && isset ( $ parts [ 1 ] ) && 'posts_url' == $ parts [ 1 ] ) { $ link = get_author_posts_url ( $ author -> ID ) ; return $ link ; } if ( is_object ( $ author ) && isset ( $ parts [ 1 ] ) && isset ( $ author -> $ parts [ 1 ] ) ) { return $ author -> $ parts [ 1 ] ; } }
|
Handle author . field traversals
|
3,225
|
public function filter_post ( $ in_params ) { $ params = explode ( ':' , $ in_params ) ; if ( isset ( $ params [ 1 ] ) ) { $ post = get_post ( $ params [ 0 ] ) ; $ field = $ params [ 1 ] ; } else { global $ post ; $ field = $ params [ 0 ] ; } return $ this -> get_post_value ( $ field , $ in_params , $ post ) ; }
|
Filters a post magic tag
|
3,226
|
public function filter_get_var ( $ params ) { if ( isset ( $ _GET [ $ params ] ) ) { return wp_slash ( $ _GET [ $ params ] ) ; } elseif ( ! empty ( $ _SERVER [ 'HTTP_REFERER' ] ) ) { return $ this -> filter_get_referr_var ( $ params ) ; } return $ params ; }
|
Filters a GET magic tag
|
3,227
|
private function filter_get_referr_var ( $ params ) { $ referer = parse_url ( $ _SERVER [ 'HTTP_REFERER' ] ) ; if ( ! empty ( $ referer [ 'query' ] ) ) { parse_str ( $ referer [ 'query' ] , $ get_vars ) ; if ( isset ( $ get_vars [ $ params ] ) ) { return wp_slash ( $ get_vars [ $ params ] ) ; } } return $ params ; }
|
Filters a GET from a referrer
|
3,228
|
public function filter_user ( $ params ) { if ( ! is_user_logged_in ( ) ) { return $ params ; } $ user = get_userdata ( get_current_user_id ( ) ) ; if ( isset ( $ user -> data -> { $ params } ) ) { $ params = $ user -> data -> { $ params } ; } $ is_meta = get_user_meta ( $ user -> ID , $ params , true ) ; if ( ! empty ( $ is_meta ) ) { $ params = implode ( ', ' , ( array ) $ is_meta ) ; } return $ params ; }
|
Filters a user magic tag
|
3,229
|
public function filter_ip ( ) { $ ip = $ _SERVER [ 'REMOTE_ADDR' ] ; if ( ! empty ( $ _SERVER [ 'HTTP_CLIENT_IP' ] ) ) { $ ip = $ _SERVER [ 'HTTP_CLIENT_IP' ] ; } elseif ( ! empty ( $ _SERVER [ 'HTTP_X_FORWARDED_FOR' ] ) ) { $ ip = $ _SERVER [ 'HTTP_X_FORWARDED_FOR' ] ; } return $ ip ; }
|
Filters a ip magic tag
|
3,230
|
private function maybe_do_post_thumbnail ( $ field , $ post ) { if ( 'post_thumbnail' == $ field || false !== strpos ( $ field , 'post_thumbnail.' ) ) { $ size = 'thumbnail' ; if ( false !== ( $ pos = strpos ( $ field , '.' ) ) ) { $ size = substr ( $ field , $ pos + 1 ) ; } $ id = get_post_thumbnail_id ( $ post -> ID ) ; if ( 0 < absint ( $ id ) ) { $ img = wp_get_attachment_image_src ( $ id , $ size ) ; if ( is_array ( $ img ) ) { return $ img [ 0 ] ; } } return 0 ; } return false ; }
|
If field is post_thumbnail return image source URL
|
3,231
|
private function maybe_do_featured ( $ field , $ post ) { if ( 'post_featured' == $ field ) { $ id = get_post_thumbnail_id ( $ post -> ID ) ; if ( 0 < absint ( $ id ) ) { return wp_get_attachment_image ( $ id , 'large' ) ; } return '' ; } }
|
Handle post_featured tags
|
3,232
|
public function send ( Message $ mail ) { $ mails = array ( ) ; if ( $ this -> sessionSection -> offsetExists ( 'sentMessages' ) ) { $ mails = $ this -> sessionSection -> sentMessages ; } if ( count ( $ mails ) === $ this -> limit ) { array_pop ( $ mails ) ; } $ reflectionMethod = $ mail -> getReflection ( ) -> getMethod ( 'build' ) ; $ reflectionMethod -> setAccessible ( TRUE ) ; $ builtMail = $ reflectionMethod -> invoke ( $ mail ) ; array_unshift ( $ mails , $ builtMail ) ; $ this -> sessionSection -> sentMessages = $ mails ; }
|
Sends given message via this mailer
|
3,233
|
public function removeNotReplacedChar ( $ notReplaced ) { if ( empty ( $ notReplaced ) ) { throw new \ Exception ( 'Not replaced character cannot be null.' ) ; } if ( is_array ( $ notReplaced ) ) { foreach ( $ notReplaced as $ n ) { $ this -> removeNotReplacedChar ( $ n ) ; } } else { if ( ! in_array ( $ notReplaced , $ this -> getNotReplacedChars ( ) ) ) { throw new \ Exception ( "Not replaced character '$notReplaced' is not in array." ) ; } $ newArray = array ( ) ; foreach ( $ this -> _notReplacedChars as $ n ) { if ( $ n != $ notReplaced ) { $ newArray [ ] = $ n ; } $ this -> _notReplacedChars = $ newArray ; } } return $ this ; }
|
Remove not replaced character
|
3,234
|
public function addWordDelimiter ( $ delimiter ) { if ( in_array ( $ delimiter , $ this -> getWordDelimiters ( ) ) ) { throw new \ Exception ( "Word delimiter '$delimiter' is already there." ) ; } if ( empty ( $ delimiter ) ) { throw new \ Exception ( 'Word delimiter cannot be null.' ) ; } if ( is_array ( $ delimiter ) ) { $ this -> _wordDelimiters = array_merge ( $ this -> getWordDelimiters ( ) , $ delimiter ) ; } else { $ this -> _wordDelimiters [ ] = $ delimiter ; } return $ this ; }
|
Add word delimiter
|
3,235
|
public function ActiveCollabDatabaseStructureBehaviourPositionInterfaceImplementation ( ) { $ this -> registerEventHandler ( 'on_before_save' , function ( ) { if ( ! $ this -> getPosition ( ) ) { $ table_name = $ this -> connection -> escapeTableName ( $ this -> getTableName ( ) ) ; $ conditions = $ this -> getPositionContextConditions ( ) ; if ( $ this -> getPositionMode ( ) == PositionInterface :: POSITION_MODE_HEAD ) { $ this -> setPosition ( 1 ) ; if ( $ ids = $ this -> connection -> executeFirstColumn ( "SELECT `id` FROM $table_name $conditions" ) ) { $ this -> connection -> execute ( "UPDATE $table_name SET `position` = `position` + 1 $conditions" ) ; } } else { $ this -> setPosition ( $ this -> connection -> executeFirstCell ( "SELECT MAX(`position`) FROM $table_name $conditions" ) + 1 ) ; } } } ) ; }
|
Say hello to the parent class .
|
3,236
|
private function getPositionContextConditions ( ) { $ pattern = $ this -> pool -> getTypeProperty ( get_class ( $ this ) , 'position_context_conditions_pattern' , function ( ) { $ conditions = [ ] ; foreach ( $ this -> getPositionContext ( ) as $ field_name ) { $ conditions [ ] = $ this -> connection -> escapeFieldName ( $ field_name ) . ' = ?' ; } return count ( $ conditions ) ? implode ( ' AND ' , $ conditions ) : '' ; } ) ; if ( $ pattern ) { $ to_prepare = [ $ pattern ] ; foreach ( $ this -> getPositionContext ( ) as $ field_name ) { $ to_prepare [ ] = $ this -> getFieldValue ( $ field_name ) ; } return 'WHERE ' . call_user_func_array ( [ & $ this -> connection , 'prepare' ] , $ to_prepare ) ; } return '' ; }
|
Return position context conditions .
|
3,237
|
public function next ( ) { $ this -> position ++ ; $ this -> generator -> next ( ) ; $ this -> currentData = $ this -> generator -> current ( ) ; }
|
Moves forward to next element .
|
3,238
|
public function removeStatus ( ApiItemInterface $ item , $ status , $ flush = false ) { $ currentBitmaskStatus = $ item -> getBitmaskStatus ( ) ; if ( $ currentBitmaskStatus && $ currentBitmaskStatus & $ status ) { $ item -> setBitmaskStatus ( $ currentBitmaskStatus & ~ $ status ) ; } if ( $ flush === true ) { $ this -> em -> flush ( ) ; } }
|
Converts status of an item
|
3,239
|
public function findByIdAndLocale ( $ id , $ locale ) { $ item = $ this -> itemRepository -> findByIdAndLocale ( $ id , $ locale ) ; if ( $ item ) { return $ this -> itemFactory -> createApiEntity ( $ item , $ locale ) ; } else { return null ; } }
|
Finds an item by id and locale
|
3,240
|
protected function setItemByProductData ( $ productData , ApiItemInterface $ item , $ locale ) { $ productId = $ this -> getProductId ( $ productData ) ; $ product = $ this -> productRepository -> find ( $ productId ) ; if ( ! $ product ) { throw new ProductNotFoundException ( self :: $ productEntityName , $ productId ) ; } $ item -> setProduct ( $ product ) ; $ translation = $ product -> getTranslation ( $ locale ) ; if ( is_null ( $ translation ) ) { if ( count ( $ product -> getTranslations ( ) ) > 0 ) { $ translation = $ product -> getTranslations ( ) [ 0 ] ; } else { throw new ProductException ( 'Product ' . $ product -> getId ( ) . ' has no translations!' ) ; } } $ this -> setItemSupplier ( $ item , $ product ) ; $ item -> setName ( $ translation -> getName ( ) ) ; $ item -> setDescription ( $ translation -> getLongDescription ( ) ) ; $ item -> setNumber ( $ product -> getNumber ( ) ) ; if ( $ product -> getOrderUnit ( ) ) { $ item -> setQuantityUnit ( $ product -> getOrderUnit ( ) -> getTranslation ( $ locale ) -> getName ( ) ) ; } $ item -> setTax ( 0 ) ; return $ product ; }
|
Sets item based on given product data
|
3,241
|
protected function setItemSupplier ( $ item , $ product ) { if ( $ product -> getSupplier ( ) ) { $ item -> setSupplier ( $ product -> getSupplier ( ) ) ; $ item -> setSupplierName ( $ product -> getSupplier ( ) -> getName ( ) ) ; } else { $ item -> setSupplier ( null ) ; $ item -> setSupplierName ( '' ) ; } }
|
Set supplier of an item
|
3,242
|
private function updatePrices ( ApiItemInterface $ item , $ data ) { $ currency = null ; if ( $ item -> getUseProductsPrice ( ) === false ) { $ item -> setPrice ( $ this -> getProperty ( $ data , 'price' , $ item -> getPrice ( ) ) ) ; } $ price = $ this -> itemPriceCalculator -> calculate ( $ item , $ currency , $ item -> getUseProductsPrice ( ) ) ; $ item -> setTotalNetPrice ( $ price ) ; $ itemPrice = $ this -> itemPriceCalculator -> getItemPrice ( $ item , $ currency , $ item -> getUseProductsPrice ( ) ) ; $ item -> setPrice ( $ itemPrice ) ; }
|
Function updates item prices its product data
|
3,243
|
public function process ( \ ECL \ SymbolTable $ table ) { $ results = [ ] ; for ( $ i = 0 ; $ i < count ( $ this -> commands ) ; ++ $ i ) { $ command = $ this -> commands [ $ i ] ; $ curr_result = $ command -> process ( $ table ) ; $ table [ \ ECL \ SymbolTable :: DEFAULT_SYMBOL ] = $ curr_result ; if ( $ i + 1 >= count ( $ this -> commands ) && ! ( $ command instanceof \ ECL \ Command \ Store ) ) { $ results [ ] = $ curr_result ; } } unset ( $ table [ \ ECL \ SymbolTable :: DEFAULT_SYMBOL ] ) ; return $ results ; }
|
Process the list of Commands .
|
3,244
|
public function getRouteCollectionForRequest ( Request $ request ) { $ collection = new RouteCollection ( ) ; $ path = $ this -> getNormalizedPath ( $ request ) ; $ resource = $ this -> repository -> findOneBy ( [ 'path' => $ path ] ) ; if ( $ resource ) { $ route = $ this -> createRoute ( $ resource ) ; $ collection -> add ( self :: DYNAMIC_PREFIX . $ resource -> getId ( ) , $ route ) ; } return $ collection ; }
|
Returns route collection for current request
|
3,245
|
public function getRouteByName ( $ identifier ) { $ id = str_replace ( self :: DYNAMIC_PREFIX , '' , $ identifier ) ; $ resource = $ this -> repository -> find ( $ id ) ; if ( $ resource instanceof Route ) { return $ this -> createRoute ( $ resource ) ; } return null ; }
|
Returns route by its identifier
|
3,246
|
private function getNormalizedPath ( Request $ request ) { $ path = ltrim ( $ request -> getPathInfo ( ) , '/' ) ; $ paths = explode ( self :: PATH_PARAMS_SEPARATOR , $ path ) ; return current ( $ paths ) ; }
|
Returns normalized path used in resource query
|
3,247
|
public function linkUrlsAndEscapeHtml ( $ text ) { if ( strpos ( $ text , '.' ) === false ) { return $ this -> escapeHtml ( $ text ) ; } $ html = '' ; $ position = 0 ; $ match = array ( ) ; while ( preg_match ( $ this -> buildRegex ( ) , $ text , $ match , PREG_OFFSET_CAPTURE , $ position ) ) { list ( $ url , $ urlPosition ) = $ match [ 0 ] ; $ html .= $ this -> escapeHtml ( substr ( $ text , $ position , $ urlPosition - $ position ) ) ; $ scheme = $ match [ 1 ] [ 0 ] ; $ username = $ match [ 2 ] [ 0 ] ; $ password = $ match [ 3 ] [ 0 ] ; $ domain = $ match [ 4 ] [ 0 ] ; $ afterDomain = $ match [ 5 ] [ 0 ] ; $ port = $ match [ 6 ] [ 0 ] ; $ path = $ match [ 7 ] [ 0 ] ; $ tld = strtolower ( strrchr ( $ domain , '.' ) ) ; $ validTlds = $ this -> validTlds ; if ( preg_match ( '{^\.[0-9]{1,3}$}' , $ tld ) || isset ( $ validTlds [ $ tld ] ) ) { if ( ! $ scheme && $ password ) { $ html .= $ this -> escapeHtml ( $ username ) ; $ position = $ urlPosition + strlen ( $ username ) ; continue ; } if ( ! $ scheme && $ username && ! $ password && ! $ afterDomain ) { $ emailLinkCreator = $ this -> emailLinkCreator ; $ html .= $ emailLinkCreator ( $ url , $ url ) ; } else { $ completeUrl = $ scheme ? $ url : "http://$url" ; $ linkText = "$domain$port$path" ; $ htmlLinkCreator = $ this -> htmlLinkCreator ; $ html .= $ htmlLinkCreator ( $ completeUrl , $ linkText ) ; } } else { $ html .= $ this -> escapeHtml ( $ url ) ; } $ position = $ urlPosition + strlen ( $ url ) ; } $ html .= $ this -> escapeHtml ( substr ( $ text , $ position ) ) ; return $ html ; }
|
Transforms plain text into valid HTML escaping special characters and turning URLs into links .
|
3,248
|
private function exportOrder ( Order $ order , int $ foundOrder ) { $ logger = $ this -> getLogger ( ) ; try { $ eventDispatcher = $ this -> getEventDispatcher ( ) ; $ filesystem = $ this -> getFilesystem ( ) ; $ event = $ eventDispatcher -> dispatch ( EventStore :: PRE_ORDER_EXPORT , new PrepareOrderExportEvent ( $ filesystem , $ order ) ) ; $ logger -> debug ( 'Try to write the order export.' , [ 'file' => $ file = $ this -> getOrderNameGenerator ( ) -> getOrderName ( $ order ) , 'number' => $ foundOrder ] + ( $ exportData = $ event -> getExportData ( ) ) ) ; $ written = ( $ isStopped = $ event -> isPropagationStopped ( ) ) ? false : $ filesystem -> put ( $ file , $ this -> getView ( ) -> render ( $ this -> getFileTemplate ( ) , $ exportData ) ) ; if ( ! $ written ) { $ logger -> error ( 'Failed to write order export file.' , [ 'file' => $ file , 'number' => $ foundOrder , 'isStopped' => $ isStopped ] + $ exportData ) ; $ eventDispatcher -> dispatch ( EventStore :: POST_ORDER_EXPORT_FAIL , new FailedOrderExportEvent ( $ filesystem , $ order ) ) ; } else { $ logger -> info ( 'Wrote order export file.' , [ 'file' => $ file , 'number' => $ foundOrder ] + $ exportData ) ; $ eventDispatcher -> dispatch ( EventStore :: POST_ORDER_EXPORT , new FinishOrderExportEvent ( $ file , $ filesystem , $ order ) ) ; } } catch ( SkippableException $ exc ) { $ logger -> warning ( 'Exception while writing the order export file.' , [ 'exception' => $ exc , 'order' => $ order ] ) ; $ eventDispatcher -> dispatch ( EventStore :: POST_ORDER_EXPORT_FAIL , ( new FailedOrderExportEvent ( $ filesystem , $ order ) ) -> setException ( $ exc ) ) ; } }
|
Exports the given order .
|
3,249
|
public function exportOrders ( OrderVisitor $ orderVisitor , ProgressBar $ bar ) : bool { $ logger = $ this -> getLogger ( ) ; $ bar -> start ( $ count = count ( $ orderVisitor ) ) ; $ logger -> debug ( 'Started the order export.' , [ 'count' => $ count ] ) ; foreach ( $ orderVisitor ( ) as $ num => $ order ) { set_time_limit ( 0 ) ; $ this -> exportOrder ( $ order , $ num ) ; $ bar -> advance ( ) ; } $ logger -> debug ( 'Finished the order export.' , [ 'count' => $ count ] ) ; $ bar -> finish ( ) ; return true ; }
|
Exports the given orders .
|
3,250
|
public function createRepositoryTransformer ( string $ alias ) : DataTransformerInterface { if ( ! $ this -> collection -> has ( $ alias ) ) { throw new MissingFormDataTransformerException ( $ alias ) ; } $ serviceId = $ this -> collection -> get ( $ alias ) ; return $ this -> get ( $ serviceId ) ; }
|
Creates and returns a new instance of form data transformer
|
3,251
|
public function embed ( ? string $ url = null , ? string $ id = null ) : ? string { $ hasMultiple = function ( string $ url , string $ pattern ) : bool { return false !== strpos ( $ url , $ pattern ) ; } ; if ( isset ( $ url , $ id ) ) { $ ripple = new static ( $ url ) ; if ( null !== $ ripple -> provider ) { $ class = static :: PROVIDERS [ $ provider = $ ripple -> provider ] ; $ embed = $ class :: embed ( $ id , $ hasMultiple ( $ url , $ class :: MULTIPLE_PATTERN ) ) ; } } if ( '' !== $ this -> content ) { $ class = static :: PROVIDERS [ $ provider = $ this -> provider ] ; $ embed = $ class :: embed ( $ class :: id ( $ this -> content ) , $ hasMultiple ( $ this -> url , $ class :: MULTIPLE_PATTERN ) ) ; } if ( ! isset ( $ embed , $ provider ) ) { return null ; } if ( isset ( $ this -> embedParams [ $ provider ] ) ) { return $ embed . $ this -> embedParams [ $ provider ] ; } return $ embed ; }
|
Returns HTML embed of the track .
|
3,252
|
public function validateTokenHash ( $ tokenHash ) { $ tokenData = $ this -> tokenCache -> get ( $ tokenHash ) ; if ( $ tokenData === false ) { $ this -> logger -> log ( sprintf ( 'Validation of token hash %s failed' , $ tokenHash ) , LOG_INFO ) ; return null ; } $ preset = $ this -> getPreset ( $ tokenData [ 'presetName' ] ) ; if ( ! ( isset ( $ preset [ 'preserveToken' ] ) && $ preset [ 'preserveToken' ] ) ) { $ this -> tokenCache -> remove ( $ tokenHash ) ; } $ this -> logger -> log ( sprintf ( 'Validated token hash %s for identifier %s' , $ tokenHash , $ tokenData [ 'identifier' ] ) , LOG_INFO ) ; return new Token ( $ tokenHash , $ tokenData [ 'identifier' ] , $ this -> getPreset ( $ tokenData [ 'presetName' ] ) , $ tokenData [ 'meta' ] ) ; }
|
This checks if a given hash is known and still valid before returning the associated Token .
|
3,253
|
public function invalidateToken ( Token $ token ) { $ this -> tokenCache -> remove ( $ token -> getHash ( ) ) ; $ this -> logger -> log ( sprintf ( 'Deleted token %s.' , $ token -> getIdentifier ( ) ) , LOG_INFO ) ; }
|
Removes the given token from the token cache .
|
3,254
|
public function devMode ( $ args ) { if ( empty ( $ args [ 0 ] ) ) { $ mode = \ Disco \ manage \ Manager :: devMode ( ) ; echo 'DEV_MODE : ' . ( ( $ mode ) ? 'true' : 'false' ) . PHP_EOL ; exit ; } else if ( $ args [ 0 ] != 'true' && $ args [ 0 ] != 'false' ) { echo 'Mode takes one of two values: true | false' . PHP_EOL . 'Please supply a correct value' . PHP_EOL ; exit ; } \ Disco \ manage \ Manager :: devMode ( ( $ args [ 0 ] == 'true' ) ? true : false ) ; echo 'DEV_MODE now set to: ' . $ args [ 0 ] . PHP_EOL ; }
|
Get the current dev mode optionally setting it .
|
3,255
|
public function dbRestore ( $ args ) { $ path = '/app/db/' ; if ( isset ( $ args [ 0 ] ) ) { $ path = $ args [ 0 ] ; } $ path = \ App :: path ( ) . '/' . trim ( $ path , '/' ) . '/' ; $ fileName = \ App :: config ( 'DB_DB' ) ; if ( isset ( $ args [ 1 ] ) ) { $ fileName = $ args [ 1 ] ; } $ fileName = $ path . $ fileName . '.sql' ; if ( ! is_file ( $ fileName ) ) { echo "Backup `{$fileName}` does not exist, exiting." . PHP_EOL ; exit ; } $ e = "mysql -u %1\$s -p'%2\$s' -h %3\$s %4\$s < %5\$s;" ; $ e = sprintf ( $ e , \ App :: config ( 'DB_USER' ) , \ App :: config ( 'DB_PASSWORD' ) , \ App :: config ( 'DB_HOST' ) , \ App :: config ( 'DB_DB' ) , $ fileName ) ; $ error = exec ( $ e ) ; if ( ! $ error ) { echo 'DB `' . \ App :: config ( 'DB_DB' ) . "` successfully restored from `{$fileName}`" ; } else { echo 'Unable to restore! : ' . $ error ; } echo PHP_EOL ; }
|
Restore the DB from a backup .
|
3,256
|
public function create ( $ args ) { if ( $ args [ 0 ] == 'model' ) { if ( ! isset ( $ args [ 1 ] ) ) { echo 'You must specify a table to build the model from' . PHP_EOL ; exit ; } $ table = $ args [ 1 ] ; $ templatePath = isset ( $ args [ 2 ] ) ? $ args [ 2 ] : 'app/config/model.format' ; $ outputPath = isset ( $ args [ 3 ] ) ? $ args [ 3 ] : 'app/model' ; if ( $ table == 'all' ) { $ result = $ this -> getDBSchema ( ) ; while ( $ row = $ result -> fetch ( ) ) { $ model = \ Disco \ manage \ Manager :: buildModel ( $ row [ 'table_name' ] ) ; \ Disco \ manage \ Manager :: writeModel ( $ row [ 'table_name' ] , $ model , $ templatePath , $ outputPath ) ; } } else { $ model = \ Disco \ manage \ Manager :: buildModel ( $ table ) ; \ Disco \ manage \ Manager :: writeModel ( $ table , $ model , $ templatePath , $ outputPath ) ; } } else if ( $ args [ 0 ] == 'record' ) { if ( ! isset ( $ args [ 1 ] ) ) { echo 'You must specify a table to build the record from' . PHP_EOL ; exit ; } $ table = $ args [ 1 ] ; $ templatePath = isset ( $ args [ 2 ] ) ? $ args [ 2 ] : 'app/config/record.format' ; $ outputPath = isset ( $ args [ 3 ] ) ? $ args [ 3 ] : 'app/record' ; if ( $ table == 'all' ) { $ result = $ this -> getDBSchema ( ) ; while ( $ row = $ result -> fetch ( ) ) { $ record = \ Disco \ manage \ Manager :: buildRecord ( $ row [ 'table_name' ] ) ; \ Disco \ manage \ Manager :: writeRecord ( $ row [ 'table_name' ] , $ record , $ templatePath , $ outputPath ) ; } } else { $ record = \ Disco \ manage \ Manager :: buildRecord ( $ table ) ; \ Disco \ manage \ Manager :: writeRecord ( $ table , $ record , $ templatePath , $ outputPath ) ; } } }
|
Create a model or a record . Use the special keyword all in place of a table name to generate records or models for all tables .
|
3,257
|
public static function consoleQuestion ( $ question , $ options ) { @ ob_flush ( ) ; $ orgQuestion = $ question ; $ opts = '' ; foreach ( $ options as $ value => $ statement ) { $ opts .= "'{$value}') echo '{$value}'; break;;" ; $ question .= PHP_EOL . "($value) - {$statement}" ; } $ question .= PHP_EOL . 'Your answer? : ' ; exec ( " while true; do read -p '{$question}' answer case \$answer in {$opts} *) echo ''; break;; esac done " , $ answer ) ; if ( ! array_key_exists ( $ answer [ 0 ] , $ options ) ) { echo PHP_EOL . 'Please enter a valid option and try again!' . PHP_EOL . PHP_EOL ; return self :: consoleQuestion ( $ orgQuestion , $ options ) ; } return $ answer [ 0 ] ; }
|
Prompt the user at the console with a question and the valid options that serve as an answer to that question .
|
3,258
|
public function consolePrompt ( $ question , $ cannotBeBlank = false ) { @ ob_flush ( ) ; exec ( "read -p '{$question} ' answer; echo \$answer;" , $ answer ) ; if ( ! $ answer [ 0 ] && $ cannotBeBlank === true ) { echo PHP_EOL . 'Answer cannot be blank! Try again...' . PHP_EOL . PHP_EOL ; return self :: consolePrompt ( $ question , $ cannotBeBlank ) ; } return $ answer [ 0 ] ; }
|
Prompt the user at the console to enter a free form text response to a question .
|
3,259
|
public function getOutputParam ( $ key ) { if ( isset ( $ this -> _output_params [ $ key ] ) ) { return $ this -> _output_params [ $ key ] ; } return null ; }
|
Get an output parameter .
|
3,260
|
public function validate ( ) { $ retval = false ; $ params = array ( 'output_type' => $ this -> _output_type ) ; foreach ( $ this -> _output_params as $ key => $ val ) { $ params [ self :: OUTPUT_PARAMS_PREFIX . $ key ] = $ val ; } try { $ retval = $ this -> _user -> post ( 'push/validate' , $ params ) ; } catch ( DataSift_Exception_APIError $ e ) { throw new DataSift_Exception_InvalidData ( $ e -> getMessage ( ) ) ; } }
|
Validate the output type and parameters with the DataSift API .
|
3,261
|
protected function subscribe ( $ hash_type , $ hash , $ name ) { $ retval = false ; $ params = array ( 'name' => $ name , $ hash_type => $ hash , 'output_type' => $ this -> _output_type , ) ; foreach ( $ this -> _output_params as $ key => $ val ) { $ params [ self :: OUTPUT_PARAMS_PREFIX . $ key ] = $ val ; } if ( strlen ( $ this -> getInitialStatus ( ) ) > 0 ) { $ params [ 'initial_status' ] = getInitialStatus ( ) ; } return new DataSift_Push_Subscription ( $ this -> _user , $ this -> _user -> post ( 'push/create' , $ params ) ) ; }
|
Subscribe this endpoint to a stream hash or historic playback ID . Note that this will activate the subscription if the initial status is set to active .
|
3,262
|
public function activate ( Composer $ composer , IOInterface $ ioc ) { $ installer = new Installer ( $ ioc , $ composer ) ; $ manager = $ composer -> getInstallationManager ( ) ; $ manager -> addInstaller ( $ installer ) ; }
|
Activates plugin and registers installer .
|
3,263
|
public function hasPermission ( $ permission ) { $ permission = ! is_string ( $ permission ) ? : Permission :: where ( [ 'slug' => $ permission ] ) -> first ( ) ; if ( config ( 'laralum.superadmin_bypass_haspermission' ) ) { return true ; } if ( $ permission ) { foreach ( $ this -> roles as $ role ) { if ( $ role -> hasPermission ( $ permission ) ) { return true ; } } } return false ; }
|
Returns true if the role has a permission .
|
3,264
|
public function postProcess ( Request $ request , Response $ response ) { if ( empty ( $ this -> allowedOriginHosts ) || ! $ request -> hasHeader ( 'HTTP_ORIGIN' ) ) { return ; } $ originHost = $ request -> readHeader ( 'HTTP_ORIGIN' ) -> unsecure ( ) ; foreach ( $ this -> allowedOriginHosts as $ allowedOriginHost ) { if ( preg_match ( '~' . $ allowedOriginHost . '~' , $ originHost ) === 1 ) { $ response -> addHeader ( 'Access-Control-Allow-Origin' , $ originHost ) ; } } }
|
does the postprocessing stuff
|
3,265
|
public function checkProperty ( & $ property ) { if ( is_string ( $ property ) ) { $ property = Placeholder :: replaceStringsAndComments ( $ property ) ; $ property = Placeholder :: removeCommentPlaceholders ( $ property , true ) ; $ property = Placeholder :: replaceStringPlaceholders ( $ property , true ) ; return true ; } else { throw new \ InvalidArgumentException ( "Invalid type '" . gettype ( $ property ) . "' for argument 'property' given." ) ; } }
|
Sets the declaration property .
|
3,266
|
public function checkValue ( & $ value ) { if ( is_string ( $ value ) ) { $ value = Placeholder :: replaceStringsAndComments ( $ value ) ; $ value = Placeholder :: removeCommentPlaceholders ( $ value , true ) ; $ value = Placeholder :: replaceStringPlaceholders ( $ value , true ) ; $ value = trim ( $ value ) ; if ( $ value !== '' ) { return true ; } else { $ this -> setIsValid ( false ) ; } } else { throw new \ InvalidArgumentException ( "Invalid type '" . gettype ( $ value ) . "' for argument 'value' given." ) ; } }
|
Checks the declaration value .
|
3,267
|
public function handle ( Client $ client , $ index , $ type , $ alias = null ) { $ alias = $ alias ? : $ index ; $ entries = $ this -> registry -> get ( $ alias , $ type ) ; $ this -> dispatchHandlingStartedEvent ( $ entries ) ; foreach ( $ entries as $ entry ) { $ this -> dispatchProvidingStartedEvent ( $ entry ) ; $ entry -> getProvider ( ) -> run ( $ client , $ index , $ entry -> getType ( ) , $ this -> dispatcher ) ; $ this -> dispatchProvidingFinishedEvent ( $ entry ) ; } }
|
Handle provide command
|
3,268
|
private function isUserTokenAuthenticated ( ) { try { $ token = $ this -> TokenUser -> getTokenInterface ( ) -> get ( ) ; $ this -> TokenUser -> validate ( $ token ) ; } catch ( Exception $ exception ) { return $ exception ; } return true ; }
|
Validates an authentication token if provided otherwise returns an exception that can be re - thrown later .
|
3,269
|
public function getFields ( ) { return [ ( new IntegerField ( $ this -> getName ( ) ) ) -> unsigned ( true ) -> size ( $ this -> getSize ( ) ) -> required ( $ this -> isRequired ( ) ) ] ; }
|
Return fields that this field is composed of .
|
3,270
|
public function toQuery ( ) : array { $ array = [ ] ; foreach ( get_object_vars ( $ this ) as $ name => $ value ) { if ( null === $ value ) { continue ; } if ( is_array ( $ value ) ) { if ( count ( $ value ) ) { foreach ( $ value as $ v ) { $ array [ ] = [ 'name' => $ name . '[]' , 'contents' => $ v ] ; } } } else { $ array [ ] = [ 'name' => $ name , 'contents' => $ value ] ; } } return $ array ; }
|
Convert tye object to query string .
|
3,271
|
public function getId ( $ format = 'bytes' ) { return static :: isUuid ( ) && $ format != false ? uuid ( $ format , $ this -> id ) : $ this -> id ; }
|
Getter for ID
|
3,272
|
public function getModel ( $ reload = false ) { if ( ! isset ( $ this -> model ) || $ reload ) { $ class = static :: $ modelClass ; $ this -> model = $ class :: findOrFail ( $ this -> getId ( ) ) ; } return $ this -> model ; }
|
return the main model
|
3,273
|
static public function exists ( $ id ) { try { $ class = static :: $ modelClass ; $ class :: findOrFail ( static :: isUuid ( ) ? uuid ( 'bytes' , $ id ) : $ id ) ; return true ; } catch ( \ Exception $ e ) { return false ; } }
|
return true id user exist
|
3,274
|
protected function getOAuthToken ( ) { if ( $ this -> client_id and $ this -> client_secret ) { $ response = $ this -> httpQuery ( 'POST' , 'https://orcid.org/oauth/token' , [ 'Accept' => 'application/json' , 'Content-Type' => 'application/x-www-form-urlencoded' ] , http_build_query ( [ 'client_id' => $ this -> client_id , 'client_secret' => $ this -> client_secret , 'scope' => '/read-public' , 'grant_type' => 'client_credentials' , ] ) ) ; if ( $ response ) { return $ response -> { 'access_token' } ; } } }
|
Get an OAuth access token
|
3,275
|
protected function getProfile ( $ id ) { $ token = $ this -> getOAuthToken ( ) ; if ( ! $ token ) return ; $ response = $ this -> httpQuery ( 'GET' , "https://pub.orcid.org/v1.2/$id/orcid-bio/" , [ 'Authorization' => "Bearer $token" , 'Accept' => 'application/json' , ] ) ; if ( $ response ) { return $ response -> { 'orcid-profile' } ; } }
|
get an indentified profile by ORCID ID
|
3,276
|
protected function searchProfiles ( $ query ) { $ token = $ this -> getOAuthToken ( ) ; if ( ! $ token ) return ; $ response = Unirest \ Request :: get ( "https://pub.orcid.org/v1.2/search/orcid-bio/" , [ 'Authorization' => "Bearer $token" , 'Content-Type' => 'application/orcid+json' ] , [ 'q' => luceneQuery ( 'text' , $ query ) ] ) ; if ( $ response -> code == 200 ) { return $ response -> body -> { 'orcid-search-results' } ; } }
|
search for an ORCID profile
|
3,277
|
public function getList ( array $ options = array ( ) ) { $ uri = $ this -> buildListResourceUri ( $ this -> listId ) ; $ response = $ this -> makeApiRequest ( $ uri , $ options ) ; return $ response -> list ; }
|
Get a List .
|
3,278
|
function resolve ( $ url = '' , Array $ query_string_vars = [ ] ) { if ( $ this -> done && empty ( $ this -> error ) ) { return $ this -> query_vars ; } $ this -> parseUrl ( $ url , $ query_string_vars ) ; $ rewrite = ( array ) $ this -> resolver -> getRewrite ( ) ; if ( ! empty ( $ rewrite ) ) { list ( $ matches , $ query ) = $ this -> parseRewriteRules ( $ rewrite ) ; $ this -> setMatchedQuery ( $ matches , $ query ) ; $ this -> maybeAdmin ( ) ; } return $ this -> resolveVars ( ) ; }
|
Resolve an url to an array of WP_Query arguments for main query .
|
3,279
|
private function parseUrl ( $ url = '' , Array $ query_string_vars = [ ] ) { parse_str ( parse_url ( $ url , PHP_URL_QUERY ) , $ this -> query_string ) ; $ request_uri = trim ( parse_url ( $ url , PHP_URL_PATH ) , '/' ) ; $ this -> request = trim ( preg_replace ( '#^/*index\.php#' , '' , $ request_uri ) , '/' ) ; if ( ! empty ( $ query_string_vars ) ) { $ this -> query_string = array_merge ( $ this -> query_string , $ query_string_vars ) ; } }
|
Parse the url to be resolved taking only relative part and stripping out query vars .
|
3,280
|
private function parseRewriteRules ( Array $ rewrite ) { $ this -> error = '404' ; $ request_match = $ this -> request ; if ( empty ( $ request_match ) && isset ( $ rewrite [ '$' ] ) ) { $ this -> matched_rule = '$' ; $ matches = [ '' ] ; $ query = $ rewrite [ '$' ] ; } else { foreach ( ( array ) $ rewrite as $ match => $ query ) { $ matches = $ this -> parseRewriteRule ( $ match , $ query ) ; if ( ! is_null ( $ this -> matched_rule ) ) { return [ $ matches , $ query ] ; } } } return [ $ matches , $ query ] ; }
|
Loop throught registered rewrite rule and check them against the url to resolve .
|
3,281
|
private function setMatchedQuery ( $ matches = [ ] , $ query = '' ) { if ( ! is_null ( $ this -> matched_rule ) ) { $ mathed = \ WP_MatchesMapRegex :: apply ( preg_replace ( "!^.+\?!" , '' , $ query ) , $ matches ) ; $ this -> matched_query = addslashes ( $ mathed ) ; parse_str ( $ this -> matched_query , $ this -> perma_q_vars ) ; if ( '404' === $ this -> error ) $ this -> error = NULL ; } }
|
When a rute matches save matched query string and matched query array .
|
3,282
|
private function maybeAdmin ( ) { if ( empty ( $ this -> request ) || strpos ( $ this -> request , 'wp-admin/' ) !== FALSE ) { $ this -> error = NULL ; if ( ! is_null ( $ this -> perma_q_vars ) && strpos ( $ this -> request , 'wp-admin/' ) !== FALSE ) { $ this -> perma_q_vars = NULL ; } } }
|
Check if the url is for admin in that case unset all the frontend query variables
|
3,283
|
private function resolveVars ( ) { $ this -> setCptQueryVars ( ) ; $ wp = $ this -> resolver -> getWp ( ) ; $ public_query_vars = ( array ) apply_filters ( 'query_vars' , $ wp -> public_query_vars ) ; $ extra_query_vars = ( array ) $ this -> resolver -> getExtraQueryVars ( ) ; $ this -> parseQueryVars ( $ public_query_vars , $ extra_query_vars ) ; $ this -> parseTaxQueryVars ( ) ; $ this -> parseCptQueryVars ( ) ; $ this -> parsePrivateQueryVars ( $ extra_query_vars , $ wp -> private_query_vars ) ; if ( ! is_null ( $ this -> error ) ) { return $ this -> getError ( ) ; } $ this -> query_vars = apply_filters ( 'request' , $ this -> query_vars ) ; $ this -> done = TRUE ; return $ this -> query_vars ; }
|
Setup the query variables if a rewrite rule matched or if some variables are passed as query string . Strips out not registered query variables and perform the request filter before saving and return found query vars .
|
3,284
|
private function setCptQueryVars ( ) { foreach ( get_post_types ( [ ] , 'objects' ) as $ post_type => $ t ) { if ( $ t -> query_var ) $ this -> post_type_query_vars [ $ t -> query_var ] = $ post_type ; } }
|
Store all the query rewrite slugs for all registered post types
|
3,285
|
private function parseQueryVar ( $ wpvar = '' ) { if ( ! is_array ( $ this -> query_vars [ $ wpvar ] ) ) { $ this -> query_vars [ $ wpvar ] = ( string ) $ this -> query_vars [ $ wpvar ] ; } else { foreach ( $ this -> query_vars [ $ wpvar ] as $ vkey => $ v ) { if ( ! is_object ( $ v ) ) { $ this -> query_vars [ $ wpvar ] [ $ vkey ] = ( string ) $ v ; } } } if ( isset ( $ this -> post_type_query_vars [ $ wpvar ] ) ) { $ this -> query_vars [ 'post_type' ] = $ this -> post_type_query_vars [ $ wpvar ] ; $ this -> query_vars [ 'name' ] = $ this -> query_vars [ $ wpvar ] ; } }
|
Parse a query variable flattening it if is an array or an object also set post_type and name query var if a slug of a registered post type is present among query vars
|
3,286
|
private function parseTaxQueryVars ( ) { foreach ( get_taxonomies ( [ ] , 'objects' ) as $ t ) { if ( $ t -> query_var && isset ( $ this -> query_vars [ $ t -> query_var ] ) ) { $ encoded = str_replace ( ' ' , '+' , $ this -> query_vars [ $ t -> query_var ] ) ; $ this -> query_vars [ $ t -> query_var ] = $ encoded ; } } }
|
Convert spacet to + in the query variables for custom taxonomies
|
3,287
|
private function parseCptQueryVars ( ) { if ( isset ( $ this -> query_vars [ 'post_type' ] ) ) { $ queryable = get_post_types ( [ 'publicly_queryable' => TRUE ] ) ; if ( ! is_array ( $ this -> query_vars [ 'post_type' ] ) && ! in_array ( $ this -> query_vars [ 'post_type' ] , $ queryable , TRUE ) ) { unset ( $ this -> query_vars [ 'post_type' ] ) ; } elseif ( is_array ( $ this -> query_vars [ 'post_type' ] ) ) { $ allowed = array_intersect ( $ this -> query_vars [ 'post_type' ] , $ queryable ) ; $ this -> query_vars [ 'post_type' ] = $ allowed ; } } }
|
Remove from query variables any non publicly queriable post type rewrite slug
|
3,288
|
private function parsePrivateQueryVars ( Array $ extra = [ ] , Array $ private = [ ] ) { if ( ! empty ( $ extra ) ) { foreach ( $ private as $ var ) { if ( isset ( $ extra [ $ var ] ) ) { $ this -> query_vars [ $ var ] = $ extra [ $ var ] ; } } } }
|
Look in extra query variables passed to resolver and compare to WP object private variables if some variables are found they are added to query variables to be returned
|
3,289
|
public function getFileSystem ( ) { if ( empty ( $ this -> fileSystem ) ) { $ this -> fileSystem = \ Drupal :: service ( 'file_system' ) ; } return $ this -> fileSystem ; }
|
Gets the file system .
|
3,290
|
public function recaptcha ( $ response , $ ipClient = null ) { if ( $ this -> getOptions ( ) -> getGRecaptchaKey ( ) ) { $ client = new \ Zend \ Http \ Client ( $ this -> getOptions ( ) -> getGRecaptchaUrl ( ) ) ; $ client -> setParameterPost ( array ( 'secret' => $ this -> getOptions ( ) -> getGRecaptchaKey ( ) , 'response' => $ response , 'remoteip' => $ ipClient , ) ) ; $ client -> setMethod ( \ Zend \ Http \ Request :: METHOD_POST ) ; $ result = $ client -> send ( ) ; if ( $ result ) { $ jsonResult = \ Zend \ Json \ Json :: decode ( $ result -> getBody ( ) ) ; if ( $ jsonResult -> success ) { return true ; } } } return false ; }
|
This method calls Google ReCaptcha .
|
3,291
|
protected function checkSetUserFrontendLogin ( ) { if ( FE_USER_LOGGED_IN ) { $ this -> import ( 'FrontendUser' , 'User' ) ; if ( $ this -> arrCategoryValues [ 'banner_protected' ] == 1 && $ this -> arrCategoryValues [ 'banner_group' ] > 0 ) { if ( $ this -> User -> isMemberOf ( $ this -> arrCategoryValues [ 'banner_group' ] ) === false ) { $ this -> statusBannerFrontendGroupView = false ; return false ; } } } return true ; }
|
Check if FE User loggen in and banner category is protected
|
3,292
|
protected function setRandomBlockerId ( $ BannerID = 0 ) { if ( $ BannerID == 0 ) { return ; } $ this -> statusRandomBlocker = true ; $ this -> setSession ( 'RandomBlocker' . $ this -> module_id , array ( $ BannerID => time ( ) ) ) ; return ; }
|
Random Blocker Set Banner - ID
|
3,293
|
protected function getRandomBlockerId ( ) { $ this -> getSession ( 'RandomBlocker' . $ this -> module_id ) ; if ( count ( $ this -> _session ) ) { $ key = key ( $ this -> _session ) ; $ value = current ( $ this -> _session ) ; unset ( $ value ) ; reset ( $ this -> _session ) ; return $ key ; } return 0 ; }
|
Random Blocker Get Banner - ID
|
3,294
|
protected function setFirstViewBlockerId ( $ banner_categorie = 0 ) { if ( $ banner_categorie == 0 ) { return ; } $ this -> statusFirstViewBlocker = true ; $ this -> setSession ( 'FirstViewBlocker' . $ this -> module_id , array ( $ banner_categorie => time ( ) ) ) ; return ; }
|
First View Blocker Set Banner Categorie - ID and timestamp
|
3,295
|
protected function removeOldFirstViewBlockerId ( $ key , $ tstmap ) { $ FirstViewBlockTime = time ( ) - 60 * 5 ; if ( $ tstmap > $ FirstViewBlockTime ) { return true ; } else { \ Session :: getInstance ( ) -> remove ( $ key ) ; } return false ; }
|
First View Blocker Remove old Banner Categorie - ID
|
3,296
|
protected function getSetFirstView ( ) { if ( $ this -> banner_firstview != 1 ) { return false ; } $ this -> BannerReferrer = new \ Banner \ BannerReferrer ( ) ; $ this -> BannerReferrer -> checkReferrer ( ) ; $ ReferrerDNS = $ this -> BannerReferrer -> getReferrerDNS ( ) ; if ( $ ReferrerDNS === 'o' ) { $ this -> statusBannerFirstView = false ; return false ; } if ( $ this -> getFirstViewBlockerId ( ) === false ) { $ this -> setFirstViewBlockerId ( $ this -> banner_categories ) ; $ this -> statusBannerFirstView = true ; return true ; } else { $ this -> statusBannerFirstView = false ; return false ; } }
|
Get FirstViewBanner status and set cat id as blocker
|
3,297
|
protected function setStatViewUpdateBlockerId ( $ banner_id = 0 ) { if ( $ banner_id == 0 ) { return ; } $ this -> setSession ( 'StatViewUpdateBlocker' . $ this -> module_id , array ( $ banner_id => time ( ) ) , true ) ; return ; }
|
StatViewUpdate Blocker Set Banner ID and timestamp
|
3,298
|
protected function removeStatViewUpdateBlockerId ( $ banner_id , $ tstmap ) { $ BannerBlockTime = time ( ) - 60 * 5 ; if ( isset ( $ GLOBALS [ 'TL_CONFIG' ] [ 'mod_banner_block_time' ] ) && intval ( $ GLOBALS [ 'TL_CONFIG' ] [ 'mod_banner_block_time' ] ) > 0 ) { $ BannerBlockTime = time ( ) - 60 * 1 * intval ( $ GLOBALS [ 'TL_CONFIG' ] [ 'mod_banner_block_time' ] ) ; } if ( $ tstmap > $ BannerBlockTime ) { return true ; } else { unset ( $ this -> _session [ $ banner_id ] ) ; if ( count ( $ this -> _session ) == 0 ) { \ Session :: getInstance ( ) -> remove ( 'StatViewUpdateBlocker' . $ this -> module_id ) ; } else { $ this -> setSession ( 'StatViewUpdateBlocker' . $ this -> module_id , $ this -> _session , false ) ; } } return false ; }
|
StatViewUpdate Blocker Remove old Banner ID
|
3,299
|
public function get ( $ id , $ invalidBehavior = self :: EXCEPTION_ON_INVALID_REFERENCE ) { if ( $ this -> isSilverStripeServiceRequest ( $ id ) ) { return $ this -> getSilverStripeService ( $ id ) ; } else { return parent :: get ( $ id , $ invalidBehavior ) ; } }
|
Use SilverStripe s Dependency Injection system if the service is namespaced silverstripe
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.