idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
1,200
public function getUrl ( $ revision = null ) { if ( ! isset ( $ revision ) ) { return $ this -> info [ 'url' ] ; } if ( ( $ info = $ this -> getRevision ( $ revision ) ) === null ) { return null ; } return $ info [ 'url' ] ; }
Returns the URL of this file or of its specified revision .
1,201
public function getUser ( $ revision = null ) { if ( ! isset ( $ revision ) ) { return $ this -> info [ 'user' ] ; } if ( ( $ info = $ this -> getRevision ( $ revision ) ) === null ) { return null ; } return $ info [ 'user' ] ; }
Returns the user who uploaded this file or of its specified revision .
1,202
public function getUserId ( $ revision = null ) { if ( ! isset ( $ revision ) ) { return ( int ) $ this -> info [ 'userid' ] ; } if ( ( $ info = $ this -> getRevision ( $ revision ) ) === null ) { return - 1 ; } return ( int ) $ info [ 'userid' ] ; }
Returns the ID of the user who uploaded this file or of its specified revision .
1,203
public function getWidth ( $ revision = null ) { if ( ! isset ( $ revision ) ) { return ( int ) $ this -> info [ 'width' ] ; } if ( ( $ info = $ this -> getRevision ( $ revision ) ) === null ) { return - 1 ; } return ( int ) $ info [ 'width' ] ; }
Returns the width of this file or of its specified revision .
1,204
public function getRevision ( $ revision ) { if ( is_int ( $ revision ) ) { if ( isset ( $ this -> history [ $ revision ] ) ) { return $ this -> history [ $ revision ] ; } } else { foreach ( $ this -> history as $ history ) { if ( $ history [ 'timestamp' ] == $ revision ) { return $ history ; } } } $ this -> error = array ( ) ; $ this -> error [ 'file' ] = "Revision '$revision' was not found for this file" ; return null ; }
Returns the properties of the specified file revision .
1,205
public function getArchivename ( $ revision ) { if ( ( $ info = $ this -> getRevision ( $ revision ) ) === null ) { return null ; } if ( ! isset ( $ info [ 'archivename' ] ) ) { $ this -> error = array ( ) ; $ this -> error [ 'file' ] = 'This revision contains no archive name' ; return null ; } return $ info [ 'archivename' ] ; }
Returns the archive name of the specified file revision .
1,206
public function downloadData ( ) { $ data = $ this -> wikimate -> download ( $ this -> getUrl ( ) ) ; if ( $ data === null ) { $ this -> error = $ this -> wikimate -> getError ( ) ; } else { $ this -> error = null ; } return $ data ; }
Downloads and returns the current file s contents or null if an error occurs .
1,207
public function downloadFile ( $ path ) { if ( ( $ data = $ this -> downloadData ( ) ) === null ) { return false ; } if ( @ file_put_contents ( $ path , $ data ) === false ) { $ this -> error = array ( ) ; $ this -> error [ 'file' ] = "Unable to write file '$path'" ; return false ; } return true ; }
Downloads the current file s contents and writes it to the given path .
1,208
public function setId ( int $ objectId ) : int { if ( $ this -> objectId !== 0 ) { throw new UnexpectedValueException ( 'ObjectId property is immutable.' ) ; } $ this -> objectId = $ objectId ; $ this -> rId = $ objectId ; return $ objectId ; }
Set the id for the object .
1,209
protected static function getSetting ( array $ settings , bool $ mandatory , string $ sectionName , string $ settingName ) { if ( ! array_key_exists ( $ sectionName , $ settings ) ) { if ( $ mandatory ) { throw new RuntimeException ( "Section '%s' not found in configuration file." , $ sectionName ) ; } else { return null ; } } if ( ! array_key_exists ( $ settingName , $ settings [ $ sectionName ] ) ) { if ( $ mandatory ) { throw new RuntimeException ( "Setting '%s' not found in section '%s' configuration file." , $ settingName , $ sectionName ) ; } else { return null ; } } return $ settings [ $ sectionName ] [ $ settingName ] ; }
Returns the value of a setting .
1,210
protected function writeTwoPhases ( string $ filename , string $ data ) : void { $ write_flag = true ; if ( file_exists ( $ filename ) ) { $ old_data = file_get_contents ( $ filename ) ; if ( $ data == $ old_data ) $ write_flag = false ; } if ( $ write_flag ) { $ tmp_filename = $ filename . '.tmp' ; file_put_contents ( $ tmp_filename , $ data ) ; rename ( $ tmp_filename , $ filename ) ; $ this -> io -> text ( sprintf ( 'Wrote <fso>%s</fso>' , OutputFormatter :: escape ( $ filename ) ) ) ; } else { $ this -> io -> text ( sprintf ( 'File <fso>%s</fso> is up to date' , OutputFormatter :: escape ( $ filename ) ) ) ; } }
Writes a file in two phase to the filesystem .
1,211
private function detectNameConflicts ( ) : void { list ( $ sources_by_path , $ sources_by_method ) = $ this -> getDuplicates ( ) ; foreach ( $ sources_by_path as $ source ) { $ this -> errorFilenames [ ] = $ source [ 'path_name' ] ; } foreach ( $ sources_by_method as $ method => $ sources ) { $ tmp = [ ] ; foreach ( $ sources as $ source ) { $ tmp [ ] = $ source [ 'path_name' ] ; } $ this -> io -> error ( sprintf ( "The following source files would result wrapper methods with equal name '%s'" , $ method ) ) ; $ this -> io -> listing ( $ tmp ) ; } foreach ( $ this -> sources as $ i => $ source ) { if ( isset ( $ sources_by_path [ $ source [ 'path_name' ] ] ) ) { unset ( $ this -> sources [ $ i ] ) ; } } }
Detects stored routines that would result in duplicate wrapper method name .
1,212
private function findSourceFiles ( ) : void { $ helper = new SourceFinderHelper ( dirname ( $ this -> configFilename ) ) ; $ filenames = $ helper -> findSources ( $ this -> sourcePattern ) ; foreach ( $ filenames as $ filename ) { $ routineName = pathinfo ( $ filename , PATHINFO_FILENAME ) ; $ this -> sources [ ] = [ 'path_name' => $ filename , 'routine_name' => $ routineName , 'method_name' => $ this -> methodName ( $ routineName ) ] ; } }
Searches recursively for all source files .
1,213
private function findSourceFilesFromList ( array $ filenames ) : void { foreach ( $ filenames as $ filename ) { if ( ! file_exists ( $ filename ) ) { $ this -> io -> error ( sprintf ( "File not exists: '%s'" , $ filename ) ) ; $ this -> errorFilenames [ ] = $ filename ; } else { $ routineName = pathinfo ( $ filename , PATHINFO_FILENAME ) ; $ this -> sources [ ] = [ 'path_name' => $ filename , 'routine_name' => $ routineName , 'method_name' => $ this -> methodName ( $ routineName ) ] ; } } }
Finds all source files that actually exists from a list of file names .
1,214
private function getColumnTypes ( ) : void { $ rows = DataLayer :: getAllTableColumns ( ) ; foreach ( $ rows as $ row ) { $ key = '@' . $ row [ 'table_name' ] . '.' . $ row [ 'column_name' ] . '%type@' ; $ key = strtoupper ( $ key ) ; $ value = $ row [ 'column_type' ] ; if ( isset ( $ row [ 'character_set_name' ] ) ) $ value .= ' character set ' . $ row [ 'character_set_name' ] ; $ this -> replacePairs [ $ key ] = $ value ; } $ this -> io -> text ( sprintf ( 'Selected %d column types for substitution' , sizeof ( $ rows ) ) ) ; }
Selects schema table column names and the column type from MySQL and saves them as replace pairs .
1,215
private function getConstants ( ) : void { if ( ! isset ( $ this -> constantClassName ) ) return ; $ reflection = new \ ReflectionClass ( $ this -> constantClassName ) ; $ constants = $ reflection -> getConstants ( ) ; foreach ( $ constants as $ name => $ value ) { if ( ! is_numeric ( $ value ) ) $ value = "'" . $ value . "'" ; $ this -> replacePairs [ '@' . $ name . '@' ] = $ value ; } $ this -> io -> text ( sprintf ( 'Read %d constants for substitution from <fso>%s</fso>' , sizeof ( $ constants ) , OutputFormatter :: escape ( $ reflection -> getFileName ( ) ) ) ) ; }
Reads constants set the PHP configuration file and adds them to the replace pairs .
1,216
private function getOldStoredRoutinesInfo ( ) : void { $ this -> rdbmsOldMetadata = [ ] ; $ routines = DataLayer :: getRoutines ( ) ; foreach ( $ routines as $ routine ) { $ this -> rdbmsOldMetadata [ $ routine [ 'routine_name' ] ] = $ routine ; } }
Retrieves information about all stored routines in the current schema .
1,217
private function loadAll ( ) : void { $ this -> findSourceFiles ( ) ; $ this -> detectNameConflicts ( ) ; $ this -> getColumnTypes ( ) ; $ this -> readStoredRoutineMetadata ( ) ; $ this -> getConstants ( ) ; $ this -> getOldStoredRoutinesInfo ( ) ; $ this -> getCorrectSqlMode ( ) ; $ this -> loadStoredRoutines ( ) ; $ this -> dropObsoleteRoutines ( ) ; $ this -> removeObsoleteMetadata ( ) ; $ this -> io -> writeln ( '' ) ; $ this -> writeStoredRoutineMetadata ( ) ; }
Loads all stored routines into MySQL .
1,218
private function loadList ( array $ fileNames ) : void { $ this -> findSourceFilesFromList ( $ fileNames ) ; $ this -> detectNameConflicts ( ) ; $ this -> getColumnTypes ( ) ; $ this -> readStoredRoutineMetadata ( ) ; $ this -> getConstants ( ) ; $ this -> getOldStoredRoutinesInfo ( ) ; $ this -> getCorrectSqlMode ( ) ; $ this -> loadStoredRoutines ( ) ; $ this -> writeStoredRoutineMetadata ( ) ; }
Loads all stored routines in a list into MySQL .
1,219
private function loadStoredRoutines ( ) : void { $ this -> io -> writeln ( '' ) ; usort ( $ this -> sources , function ( $ a , $ b ) { return strcmp ( $ a [ 'routine_name' ] , $ b [ 'routine_name' ] ) ; } ) ; foreach ( $ this -> sources as $ filename ) { $ routineName = $ filename [ 'routine_name' ] ; $ helper = new RoutineLoaderHelper ( $ this -> io , $ filename [ 'path_name' ] , $ this -> phpStratumMetadata [ $ routineName ] ?? null , $ this -> replacePairs , $ this -> rdbmsOldMetadata [ $ routineName ] ?? null , $ this -> sqlMode , $ this -> characterSet , $ this -> collate ) ; try { $ this -> phpStratumMetadata [ $ routineName ] = $ helper -> loadStoredRoutine ( ) ; } catch ( RoutineLoaderException $ e ) { $ messages = [ $ e -> getMessage ( ) , sprintf ( "Failed to load file '%s'" , $ filename [ 'path_name' ] ) ] ; $ this -> io -> error ( $ messages ) ; $ this -> errorFilenames [ ] = $ filename [ 'path_name' ] ; unset ( $ this -> phpStratumMetadata [ $ routineName ] ) ; } catch ( DataLayerException $ e ) { if ( $ e -> isQueryError ( ) ) { $ this -> io -> error ( $ e -> getShortMessage ( ) ) ; $ this -> io -> text ( $ e -> getMarkedQuery ( ) ) ; } else { $ this -> io -> error ( $ e -> getMessage ( ) ) ; } } } }
Loads all stored routines .
1,220
private function logOverviewErrors ( ) : void { if ( ! empty ( $ this -> errorFilenames ) ) { $ this -> io -> warning ( 'Routines in the files below are not loaded:' ) ; $ this -> io -> listing ( $ this -> errorFilenames ) ; } }
Logs the source files that were not successfully loaded into MySQL .
1,221
private function methodName ( string $ routineName ) : ? string { if ( $ this -> nameMangler !== null ) { $ mangler = $ this -> nameMangler ; return $ mangler :: getMethodName ( $ routineName ) ; } return null ; }
Returns the method name in the wrapper for a stored routine . Returns null when name mangler is not set .
1,222
private function readStoredRoutineMetadata ( ) : void { if ( file_exists ( $ this -> phpStratumMetadataFilename ) ) { $ this -> phpStratumMetadata = ( array ) json_decode ( file_get_contents ( $ this -> phpStratumMetadataFilename ) , true ) ; if ( json_last_error ( ) != JSON_ERROR_NONE ) { throw new RuntimeException ( "Error decoding JSON: '%s'." , json_last_error_msg ( ) ) ; } } }
Reads the metadata of stored routines from the metadata file .
1,223
private function removeObsoleteMetadata ( ) : void { $ clean = [ ] ; foreach ( $ this -> sources as $ source ) { $ routine_name = $ source [ 'routine_name' ] ; if ( isset ( $ this -> phpStratumMetadata [ $ routine_name ] ) ) { $ clean [ $ routine_name ] = $ this -> phpStratumMetadata [ $ routine_name ] ; } } $ this -> phpStratumMetadata = $ clean ; }
Removes obsolete entries from the metadata of all stored routines .
1,224
private function writeStoredRoutineMetadata ( ) : void { $ json_data = json_encode ( $ this -> phpStratumMetadata , JSON_PRETTY_PRINT ) ; if ( json_last_error ( ) != JSON_ERROR_NONE ) { throw new RuntimeException ( "Error of encoding to JSON: '%s'." , json_last_error_msg ( ) ) ; } $ this -> writeTwoPhases ( $ this -> phpStratumMetadataFilename , $ json_data ) ; }
Writes the metadata of all stored routines to the metadata file .
1,225
public static function canComment ( $ hook , $ type , $ permission , $ params ) { $ entity = elgg_extract ( 'entity' , $ params ) ; if ( ! $ entity instanceof Comment ) { return $ permission ; } if ( $ entity -> getDepthToOriginalContainer ( ) >= ( int ) elgg_get_plugin_setting ( 'max_comment_depth' , 'hypeInteractions' ) ) { return false ; } }
Disallows commenting on comments once a certain depth has been reached
1,226
public static function canEditAnnotation ( $ hook , $ type , $ permission , $ params ) { $ annotation = elgg_extract ( 'annotation' , $ params ) ; $ user = elgg_extract ( 'user' , $ params ) ; if ( $ annotation instanceof ElggAnnotation && $ annotation -> name == 'likes' ) { $ ann_owner = $ annotation -> getOwnerEntity ( ) ; return ( $ ann_owner && $ ann_owner -> canEdit ( $ user -> guid ) ) ; } return $ permission ; }
Fixes editing permissions on likes
1,227
public function transform ( ) { $ object = $ this -> resource ; $ data = $ object instanceof Collection || $ object instanceof AbstractPaginator ? $ object -> map ( [ $ this , 'transformResource' ] ) -> toArray ( ) : $ this -> transformResource ( $ object ) ; if ( $ object instanceof AbstractPaginator ) { $ this -> withMeta ( array_merge ( $ this -> getExtra ( 'meta' , [ ] ) , Arr :: except ( $ object -> toArray ( ) , [ 'data' ] ) ) ) ; } $ data = array_filter ( compact ( 'data' ) + $ this -> extras ) ; ksort ( $ data ) ; return $ data ; }
Get a displayable API output for the given object .
1,228
public function toResponse ( $ status = 200 , array $ headers = [ ] , $ options = 0 ) { return new JsonResponse ( $ this -> transform ( ) , $ status , $ headers , $ options ) ; }
Get the instance as a json response object .
1,229
public static function riverMenuSetup ( $ hook , $ type , $ return , $ params ) { if ( ! elgg_is_logged_in ( ) ) { return $ return ; } $ remove = array ( 'comment' ) ; foreach ( $ return as $ key => $ item ) { if ( $ item instanceof ElggMenuItem && in_array ( $ item -> getName ( ) , $ remove ) ) { unset ( $ return [ $ key ] ) ; } } return $ return ; }
Filters river menu
1,230
public static function interactionsMenuSetup ( $ hook , $ type , $ menu , $ params ) { $ entity = elgg_extract ( 'entity' , $ params , false ) ; if ( ! elgg_instanceof ( $ entity ) ) { return $ menu ; } $ active_tab = elgg_extract ( 'active_tab' , $ params ) ; $ comments_count = $ entity -> countComments ( ) ; $ can_comment = $ entity -> canComment ( ) ; if ( $ can_comment ) { $ menu [ ] = ElggMenuItem :: factory ( array ( 'name' => 'comments' , 'text' => ( $ entity instanceof Comment ) ? elgg_echo ( 'interactions:reply:create' ) : elgg_echo ( 'interactions:comment:create' ) , 'href' => "stream/comments/$entity->guid" , 'priority' => 200 , 'data-trait' => 'comments' , 'item_class' => 'interactions-action' , ) ) ; } if ( $ can_comment || $ comments_count ) { $ menu [ ] = ElggMenuItem :: factory ( array ( 'name' => 'comments:badge' , 'text' => elgg_view ( 'framework/interactions/elements/badge' , array ( 'entity' => $ entity , 'icon' => 'comments' , 'type' => 'comments' , 'count' => $ comments_count , ) ) , 'href' => "stream/comments/$entity->guid" , 'selected' => ( $ active_tab == 'comments' ) , 'priority' => 100 , 'data-trait' => 'comments' , 'item_class' => 'interactions-tab' , ) ) ; } if ( elgg_is_active_plugin ( 'likes' ) ) { $ likes_count = $ entity -> countAnnotations ( 'likes' ) ; $ can_like = $ entity -> canAnnotate ( 0 , 'likes' ) ; $ does_like = elgg_annotation_exists ( $ entity -> guid , 'likes' ) ; if ( $ can_like ) { $ before_text = elgg_echo ( 'interactions:likes:before' ) ; $ after_text = elgg_echo ( 'interactions:likes:after' ) ; $ menu [ ] = ElggMenuItem :: factory ( array ( 'name' => 'likes' , 'text' => ( $ does_like ) ? $ after_text : $ before_text , 'href' => "action/stream/like?guid=$entity->guid" , 'is_action' => true , 'priority' => 400 , 'link_class' => 'interactions-state-toggler' , 'item_class' => 'interactions-action' , 'data-guid' => $ entity -> guid , 'data-trait' => 'likes' , 'data-state' => ( $ does_like ) ? 'after' : 'before' , ) ) ; } if ( $ can_like || $ likes_count ) { $ menu [ ] = ElggMenuItem :: factory ( array ( 'name' => 'likes:badge' , 'text' => elgg_view ( 'framework/interactions/elements/badge' , array ( 'entity' => $ entity , 'icon' => 'likes' , 'type' => 'likes' , 'count' => $ likes_count , ) ) , 'href' => "stream/likes/$entity->guid" , 'selected' => ( $ active_tab == 'likes' ) , 'data-trait' => 'likes' , 'priority' => 300 , 'item_class' => 'interactions-tab' , ) ) ; } } return $ menu ; }
Setups entity interactions menu
1,231
public static function entityMenuSetup ( $ hook , $ type , $ menu , $ params ) { $ entity = elgg_extract ( 'entity' , $ params ) ; if ( ! $ entity instanceof Comment ) { return ; } if ( $ entity -> canEdit ( ) ) { $ menu [ ] = ElggMenuItem :: factory ( array ( 'name' => 'edit' , 'text' => elgg_echo ( 'edit' ) , 'href' => "stream/edit/$entity->guid" , 'priority' => 800 , 'item_class' => 'interactions-edit' , 'data' => [ 'icon' => 'pencil' , ] ) ) ; } if ( $ entity -> canDelete ( ) ) { $ menu [ ] = ElggMenuItem :: factory ( array ( 'name' => 'delete' , 'text' => elgg_echo ( 'delete' ) , 'href' => "action/comment/delete?guid=$entity->guid" , 'is_action' => true , 'priority' => 900 , 'confirm' => true , 'item_class' => 'interactions-delete' , 'data' => [ 'icon' => 'delete' , ] ) ) ; } return $ menu ; }
Setups comment menu
1,232
protected function generateBody ( array $ params , array $ columns ) : void { $ uniqueColumns = $ this -> checkUniqueKeys ( $ columns ) ; $ limit = ( $ uniqueColumns == null ) ; $ this -> codeStore -> append ( sprintf ( 'delete from %s' , $ this -> tableName ) ) ; $ this -> codeStore -> append ( 'where' ) ; $ first = true ; foreach ( $ params as $ column ) { if ( $ first ) { $ format = sprintf ( "%%%ds %%s = p_%%s" , 1 ) ; $ this -> codeStore -> appendToLastLine ( sprintf ( $ format , '' , $ column [ 'column_name' ] , $ column [ 'column_name' ] ) ) ; } else { $ format = sprintf ( "and%%%ds %%s = p_%%s" , 3 ) ; $ this -> codeStore -> append ( sprintf ( $ format , '' , $ column [ 'column_name' ] , $ column [ 'column_name' ] ) ) ; } $ first = false ; } if ( $ limit ) { $ this -> codeStore -> append ( 'limit 0,1' ) ; } $ this -> codeStore -> append ( ';' ) ; }
Generate body part .
1,233
public static function createNewAccessToken ( int $ ttl , TokenOwnerInterface $ owner = null , Client $ client = null , $ scopes = null ) : AccessToken { return static :: createNew ( $ ttl , $ owner , $ client , $ scopes ) ; }
Create a new AccessToken
1,234
public function map ( array $ options , Banner $ banner ) { $ bannerOptions = get_object_vars ( $ banner ) ; $ validatedOptions = array ( ) ; foreach ( $ bannerOptions as $ name => $ value ) { $ validatedOptions [ $ name ] = empty ( $ options [ $ name ] ) ? $ value : $ options [ $ name ] ; } return $ validatedOptions ; }
Map additional options used by Banner object .
1,235
private function registerApiMiddleware ( ) { $ config = $ this -> app [ 'config' ] ; foreach ( $ config -> get ( 'api-helper.middleware' , [ ] ) as $ name => $ class ) { $ this -> aliasMiddleware ( $ name , $ class ) ; } ; }
Register the API route Middleware .
1,236
protected function prepareTokenResponse ( AccessToken $ accessToken , RefreshToken $ refreshToken = null , bool $ useRefreshTokenScopes = false ) : ResponseInterface { $ owner = $ accessToken -> getOwner ( ) ; $ scopes = $ useRefreshTokenScopes ? $ refreshToken -> getScopes ( ) : $ accessToken -> getScopes ( ) ; $ responseBody = [ 'access_token' => $ accessToken -> getToken ( ) , 'token_type' => 'Bearer' , 'expires_in' => $ accessToken -> getExpiresIn ( ) , 'scope' => implode ( ' ' , $ scopes ) , 'owner_id' => $ owner ? $ owner -> getTokenOwnerId ( ) : null , ] ; if ( null !== $ refreshToken ) { $ responseBody [ 'refresh_token' ] = $ refreshToken -> getToken ( ) ; } return new Response \ JsonResponse ( array_filter ( $ responseBody ) ) ; }
Prepare the actual HttpResponse for the token
1,237
protected static function parseButton ( ButtonInterface $ button , array $ args ) { $ button -> setActive ( ArrayHelper :: get ( $ args , "active" , false ) ) ; $ button -> setBlock ( ArrayHelper :: get ( $ args , "block" , false ) ) ; $ button -> setContent ( ArrayHelper :: get ( $ args , "content" ) ) ; $ button -> setDisabled ( ArrayHelper :: get ( $ args , "disabled" , false ) ) ; $ button -> setSize ( ArrayHelper :: get ( $ args , "size" ) ) ; $ button -> setTitle ( ArrayHelper :: get ( $ args , "title" ) ) ; return $ button ; }
Parses a button .
1,238
protected function getSyntaxHighlighterConfig ( ) { $ provider = $ this -> get ( SyntaxHighlighterStringsProvider :: SERVICE_NAME ) ; $ config = new SyntaxHighlighterConfig ( ) ; $ config -> setStrings ( $ provider -> getSyntaxHighlighterStrings ( ) ) ; return $ config ; }
Get the Syntax Highlighter config .
1,239
public static function setup_theme ( ) { global $ pagenow ; if ( ( is_admin ( ) && 'themes.php' == $ pagenow ) || ! self :: can_switch_themes ( ) ) { return ; } self :: check_reset ( ) ; self :: load_cookie ( ) ; if ( empty ( self :: $ theme ) ) { return ; } add_filter ( 'pre_option_template' , array ( self :: $ theme , 'get_template' ) ) ; add_filter ( 'pre_option_stylesheet' , array ( self :: $ theme , 'get_stylesheet' ) ) ; add_filter ( 'pre_option_stylesheet_root' , array ( self :: $ theme , 'get_theme_root' ) ) ; $ parent = self :: $ theme -> parent ( ) ; add_filter ( 'pre_option_template_root' , array ( empty ( $ parent ) ? self :: $ theme : $ parent , 'get_theme_root' ) ) ; add_filter ( 'pre_option_current_theme' , '__return_false' ) ; }
Loads cookie and sets up theme filters .
1,240
public static function check_reset ( ) { if ( ! empty ( filter_input ( INPUT_GET , 'tts_reset' ) ) ) { setcookie ( self :: get_cookie_name ( ) , '' , 1 ) ; nocache_headers ( ) ; wp_safe_redirect ( home_url ( ) ) ; die ; } }
Clear theme choice if reset variable is present in request .
1,241
public static function load_cookie ( ) { $ theme_name = filter_input ( INPUT_COOKIE , self :: get_cookie_name ( ) ) ; if ( ! $ theme_name ) { return ; } $ theme = wp_get_theme ( $ theme_name ) ; if ( $ theme -> exists ( ) && $ theme -> get ( 'Name' ) !== get_option ( 'current_theme' ) && $ theme -> is_allowed ( ) ) { self :: $ theme = $ theme ; } }
Sets if cookie is defined to non - default theme .
1,242
public static function get_allowed_themes ( ) { static $ themes ; if ( isset ( $ themes ) ) { return $ themes ; } $ wp_themes = wp_get_themes ( array ( 'allowed' => true ) ) ; foreach ( $ wp_themes as $ theme ) { $ themes [ $ theme -> get ( 'Name' ) ] = $ theme ; } $ themes = apply_filters ( 'tts_allowed_themes' , $ themes ) ; return $ themes ; }
Retrieves allowed themes .
1,243
public static function init ( ) { if ( self :: can_switch_themes ( ) ) { add_action ( 'admin_bar_menu' , array ( __CLASS__ , 'admin_bar_menu' ) , 90 ) ; add_action ( 'wp_ajax_tts_set_theme' , array ( __CLASS__ , 'set_theme' ) ) ; } load_plugin_textdomain ( 'toolbar-theme-switcher' , false , dirname ( dirname ( plugin_basename ( __FILE__ ) ) ) . '/lang' ) ; }
Sets up hooks that doesn t need to happen early .
1,244
public static function admin_bar_menu ( $ wp_admin_bar ) { $ themes = self :: get_allowed_themes ( ) ; $ current = empty ( self :: $ theme ) ? wp_get_theme ( ) : self :: $ theme ; unset ( $ themes [ $ current -> get ( 'Name' ) ] ) ; uksort ( $ themes , array ( __CLASS__ , 'sort_core_themes' ) ) ; $ title = apply_filters ( 'tts_root_title' , sprintf ( __ ( 'Theme: %s' , 'toolbar-theme-switcher' ) , $ current -> display ( 'Name' ) ) ) ; $ wp_admin_bar -> add_menu ( array ( 'id' => 'toolbar_theme_switcher' , 'title' => $ title , 'href' => admin_url ( 'themes.php' ) , ) ) ; $ ajax_url = admin_url ( 'admin-ajax.php' ) ; foreach ( $ themes as $ theme ) { $ href = add_query_arg ( array ( 'action' => 'tts_set_theme' , 'theme' => urlencode ( $ theme -> get_stylesheet ( ) ) , ) , $ ajax_url ) ; $ wp_admin_bar -> add_menu ( array ( 'id' => $ theme [ 'Stylesheet' ] , 'title' => $ theme -> display ( 'Name' ) , 'href' => $ href , 'parent' => 'toolbar_theme_switcher' , ) ) ; } }
Creates menu in toolbar .
1,245
public static function sort_core_themes ( $ theme_a , $ theme_b ) { static $ twenties = array ( 'Twenty Ten' , 'Twenty Eleven' , 'Twenty Twelve' , 'Twenty Thirteen' , 'Twenty Fourteen' , 'Twenty Fifteen' , 'Twenty Sixteen' , 'Twenty Seventeen' , 'Twenty Eighteen' , 'Twenty Nineteen' , 'Twenty Twenty' , ) ; if ( 0 === strpos ( $ theme_a , 'Twenty' ) && 0 === strpos ( $ theme_b , 'Twenty' ) ) { $ index_a = array_search ( $ theme_a , $ twenties , true ) ; $ index_b = array_search ( $ theme_b , $ twenties , true ) ; if ( false !== $ index_a && false !== $ index_b ) { return ( $ index_a < $ index_b ) ? - 1 : 1 ; } } return strcasecmp ( $ theme_a , $ theme_b ) ; }
Callback to sort theme array with core themes in numerical order by year .
1,246
public static function set_theme ( ) { $ stylesheet = filter_input ( INPUT_GET , 'theme' ) ; $ theme = wp_get_theme ( $ stylesheet ) ; if ( $ theme -> exists ( ) && $ theme -> is_allowed ( ) ) { setcookie ( self :: get_cookie_name ( ) , $ theme -> get_stylesheet ( ) , strtotime ( '+1 year' ) , COOKIEPATH ) ; } wp_safe_redirect ( wp_get_referer ( ) ) ; die ; }
Saves selected theme in cookie if valid .
1,247
public static function get_theme_field ( $ field_name , $ default = false ) { if ( ! empty ( self :: $ theme ) ) { return self :: $ theme -> get ( $ field_name ) ; } return $ default ; }
Returns field from theme data if cookie is set to valid theme .
1,248
public function getGrant ( string $ grantType ) : GrantInterface { if ( $ this -> hasGrant ( $ grantType ) ) { return $ this -> grants [ $ grantType ] ; } throw OAuth2Exception :: unsupportedGrantType ( sprintf ( 'Grant type "%s" is not supported by this server' , $ grantType ) ) ; }
Get the grant by its name
1,249
public function getResponseType ( string $ responseType ) : GrantInterface { if ( $ this -> hasResponseType ( $ responseType ) ) { return $ this -> responseTypes [ $ responseType ] ; } throw OAuth2Exception :: unsupportedResponseType ( sprintf ( 'Response type "%s" is not supported by this server' , $ responseType ) ) ; }
Get the response type by its name
1,250
private function createResponseFromOAuthException ( OAuth2Exception $ exception ) : ResponseInterface { $ payload = [ 'error' => $ exception -> getCode ( ) , 'error_description' => $ exception -> getMessage ( ) , ] ; return new Response \ JsonResponse ( $ payload , 400 ) ; }
Create a response from the exception using the format of the spec
1,251
private function extractClientCredentials ( ServerRequestInterface $ request ) : array { if ( $ request -> hasHeader ( 'Authorization' ) ) { $ parts = explode ( ' ' , $ request -> getHeaderLine ( 'Authorization' ) ) ; $ value = base64_decode ( end ( $ parts ) ) ; list ( $ id , $ secret ) = explode ( ':' , $ value ) ; } else { $ postParams = $ request -> getParsedBody ( ) ; $ id = $ postParams [ 'client_id' ] ?? null ; $ secret = $ postParams [ 'client_secret' ] ?? null ; } return [ $ id , $ secret ] ; }
Extract the client credentials from Authorization header or POST data
1,252
public function getDigitalOcean ( $ file = self :: DEFAULT_CREDENTIALS_FILE ) { if ( ! file_exists ( $ file ) ) { throw new \ RuntimeException ( sprintf ( 'Impossible to get credentials informations in %s' , $ file ) ) ; } $ credentials = Yaml :: parse ( $ file ) ; return new DigitalOcean ( new Credentials ( $ credentials [ 'CLIENT_ID' ] , $ credentials [ 'API_KEY' ] ) ) ; }
Returns an instance of DigitalOcean
1,253
private static function getLeadingDir ( string $ pattern ) : string { $ dir = $ pattern ; $ pos = strpos ( $ dir , '*' ) ; if ( $ pos !== false ) $ dir = substr ( $ dir , 0 , $ pos ) ; $ pos = strpos ( $ dir , '?' ) ; if ( $ pos !== false ) $ dir = substr ( $ dir , 0 , $ pos ) ; $ pos = strrpos ( $ dir , '/' ) ; if ( $ pos !== false ) { $ dir = substr ( $ dir , 0 , $ pos ) ; } else { $ dir = '.' ; } return $ dir ; }
Returns the leading directory without wild cards of a pattern .
1,254
public function findSources ( string $ sources ) : array { $ patterns = $ this -> sourcesToPatterns ( $ sources ) ; $ sources = [ ] ; foreach ( $ patterns as $ pattern ) { $ tmp = $ this -> findSourcesInPattern ( $ pattern ) ; $ sources = array_merge ( $ sources , $ tmp ) ; } $ sources = array_unique ( $ sources ) ; sort ( $ sources ) ; return $ sources ; }
Finds sources of stored routines .
1,255
private function findSourcesInPattern ( string $ pattern ) : array { $ sources = [ ] ; $ directory = new RecursiveDirectoryIterator ( self :: getLeadingDir ( $ pattern ) ) ; $ directory -> setFlags ( RecursiveDirectoryIterator :: FOLLOW_SYMLINKS ) ; $ files = new RecursiveIteratorIterator ( $ directory ) ; foreach ( $ files as $ fullPath => $ file ) { if ( $ file -> isFile ( ) && SelectorHelper :: matchPath ( $ pattern , $ fullPath ) ) { $ sources [ ] = $ fullPath ; } } return $ sources ; }
Finds sources of stored routines in a pattern .
1,256
private function readPatterns ( string $ filename ) : array { $ path = $ this -> basedir . '/' . $ filename ; $ lines = explode ( PHP_EOL , file_get_contents ( $ path ) ) ; $ patterns = [ ] ; foreach ( $ lines as $ line ) { $ line = trim ( $ line ) ; if ( $ line <> '' ) { $ patterns [ ] = $ line ; } } return $ patterns ; }
Reads a list of patterns from a file .
1,257
private function sourcesToPatterns ( string $ sources ) : array { if ( substr ( $ sources , 0 , 5 ) == 'file:' ) { $ patterns = $ this -> readPatterns ( substr ( $ sources , 5 ) ) ; } else { $ patterns = [ $ sources ] ; } return $ patterns ; }
Converts the sources parameter to a list a patterns .
1,258
protected function bootstrapButtonGroup ( $ class , $ role , array $ buttons ) { $ attributes = [ ] ; $ attributes [ "class" ] = $ class ; $ attributes [ "role" ] = $ role ; $ innerHTML = "\n" . implode ( "\n" , $ buttons ) . "\n" ; return static :: coreHTMLElement ( "div" , $ innerHTML , $ attributes ) ; }
Displays a Bootstrap button group .
1,259
public static function createNewAuthorizationCode ( int $ ttl , string $ redirectUri = null , TokenOwnerInterface $ owner = null , Client $ client = null , $ scopes = null ) : AuthorizationCode { $ token = static :: createNew ( $ ttl , $ owner , $ client , $ scopes ) ; $ token -> redirectUri = $ redirectUri ?? '' ; return $ token ; }
Create a new AuthorizationCode
1,260
public static function getCSSClassname ( $ size , $ value , $ suffix , $ min = 1 , $ max = 12 ) { if ( $ value < $ min || $ max < $ value ) { return null ; } $ sizes = [ "lg" , "md" , "sm" , "xs" ] ; $ suffixes = [ "offset" , "pull" , "push" , "" ] ; if ( false === in_array ( $ size , $ sizes ) || false === in_array ( $ suffix , $ suffixes ) ) { return null ; } if ( "" !== $ suffix ) { $ suffix .= "-" ; } return implode ( "-" , [ "col" , $ size , $ suffix . $ value ] ) ; }
Get a CSS classname .
1,261
public function getGuidFromRiverId ( $ river_id = 0 ) { $ river_id = ( int ) $ river_id ; $ guid = $ this -> id_cache -> get ( $ river_id ) ; if ( $ guid ) { return $ guid ; } $ objects = elgg_get_entities_from_metadata ( [ 'types' => RiverObject :: TYPE , 'subtypes' => [ RiverObject :: SUBTYPE , 'hjstream' ] , 'metadata_name_value_pairs' => [ 'name' => 'river_id' , 'value' => $ river_id , ] , 'limit' => 1 , 'callback' => false , ] ) ; $ guid = ( $ objects ) ? $ objects [ 0 ] -> guid : false ; if ( $ guid ) { $ this -> id_cache -> put ( $ river_id , $ guid ) ; return $ guid ; } return false ; }
Return value of the entity guid that corresponds to river_id
1,262
public static function getWikiViews ( ) { $ tableContents = [ ] ; $ tableContents [ ] = new WikiView ( "Twig-extension" , "CSS" , "button" , "Button" ) ; $ tableContents [ ] = new WikiView ( "twig-extension" , "CSS" , "code" , "Code" ) ; $ tableContents [ ] = new WikiView ( "Twig-extension" , "CSS" , "grid" , "Grid" ) ; $ tableContents [ ] = new WikiView ( "Twig-extension" , "CSS" , "image" , "Image" ) ; $ tableContents [ ] = new WikiView ( "Twig-extension" , "CSS" , "typography" , "Typography" ) ; $ tableContents [ ] = new WikiView ( "Twig-extension" , "Component" , "alert" , "Alert" ) ; $ tableContents [ ] = new WikiView ( "Twig-extension" , "Component" , "badge" , "Badge" ) ; $ tableContents [ ] = new WikiView ( "Twig-extension" , "Component" , "glyphicon" , "Glyphicon" ) ; $ tableContents [ ] = new WikiView ( "Twig-extension" , "Component" , "label" , "Label" ) ; $ tableContents [ ] = new WikiView ( "Twig-extension" , "Component" , "progress-bar" , "Progress bar" ) ; $ tableContents [ ] = new WikiView ( "Twig-extension" , "Utility" , "form-button" , "Form button" ) ; $ tableContents [ ] = new WikiView ( "Twig-extension" , "Utility" , "role-label" , "Role label" ) ; $ tableContents [ ] = new WikiView ( "Twig-extension" , "Utility" , "table-button" , "Table button" ) ; $ tableContents [ ] = new WikiView ( "Twig-extension" , "Plugin" , "font-awesome" , "Font Awesome" ) ; $ tableContents [ ] = new WikiView ( "Twig-extension" , "Plugin" , "jquery-inputmask" , "jQuery InputMask" ) ; $ tableContents [ ] = new WikiView ( "Twig-extension" , "Plugin" , "material-design-iconic-font" , "Material Design Iconic Font" ) ; $ tableContents [ ] = new WikiView ( "Twig-extension" , "Plugin" , "meteocons" , "Meteocons" ) ; foreach ( $ tableContents as $ current ) { $ current -> setBundle ( "WBWBootstrap" ) ; } return $ tableContents ; }
Get the wiki views .
1,263
public function indexAction ( $ category , $ package , $ page ) { $ wikiViews = self :: getWikiViews ( ) ; $ wikiView = WikiView :: find ( $ wikiViews , $ category , $ package , $ page ) ; if ( null === $ wikiView ) { $ wikiView = $ wikiViews [ 0 ] ; $ this -> notifyDanger ( "The requested page was not found" ) ; $ this -> notifyInfo ( "You have been redirected to homepage" ) ; } return $ this -> render ( $ wikiView -> getView ( ) , [ "wikiViews" => $ wikiViews , "wikiView" => $ wikiView , "syntaxHighlighterConfig" => $ this -> getSyntaxHighlighterConfig ( ) , "syntaxHighlighterDefaults" => $ this -> getSyntaxHighlighterDefaults ( ) , "user" => $ this -> getSampleUser ( ) , "userRoleColors" => $ this -> getSampleUserRoleColors ( ) , "userRoleTranslations" => $ this -> getSampleUserRoleTranslations ( ) , ] ) ; }
Displays a wiki page .
1,264
public function bootstrapButtonDangerFunction ( array $ args = [ ] ) { return $ this -> bootstrapButton ( ButtonFactory :: parseDangerButton ( $ args ) , ArrayHelper :: get ( $ args , "icon" ) ) ; }
Displays a Bootstrap button Danger .
1,265
public function bootstrapButtonDefaultFunction ( array $ args = [ ] ) { return $ this -> bootstrapButton ( ButtonFactory :: parseDefaultButton ( $ args ) , ArrayHelper :: get ( $ args , "icon" ) ) ; }
Displays a Bootstrap button Default .
1,266
public function bootstrapButtonInfoFunction ( array $ args = [ ] ) { return $ this -> bootstrapButton ( ButtonFactory :: parseInfoButton ( $ args ) , ArrayHelper :: get ( $ args , "icon" ) ) ; }
Displays a Bootstrap button Info .
1,267
public function bootstrapButtonLinkFilter ( $ button , $ href = self :: DEFAULT_HREF , $ target = null ) { if ( 1 === preg_match ( "/disabled=\"disabled\"/" , $ button ) ) { $ searches = [ " disabled=\"disabled\"" , "class=\"" ] ; $ replaces = [ "" , "class=\"disabled " ] ; $ button = StringHelper :: replace ( $ button , $ searches , $ replaces ) ; } $ searches = [ "<button" , "type=\"button\"" , "</button>" ] ; $ replaces = [ "<a" , "href=\"" . $ href . "\"" . ( null !== $ target ? " target=\"" . $ target . "\"" : "" ) , "</a>" ] ; return StringHelper :: replace ( $ button , $ searches , $ replaces ) ; }
Transforms a Bootstrap button into an anchor .
1,268
public function bootstrapButtonLinkFunction ( array $ args = [ ] ) { return $ this -> bootstrapButton ( ButtonFactory :: parseLinkButton ( $ args ) , ArrayHelper :: get ( $ args , "icon" ) ) ; }
Displays a Bootstrap button Link .
1,269
public function bootstrapButtonPrimaryFunction ( array $ args = [ ] ) { return $ this -> bootstrapButton ( ButtonFactory :: parsePrimaryButton ( $ args ) , ArrayHelper :: get ( $ args , "icon" ) ) ; }
Displays a Bootstrap button Primary .
1,270
public function bootstrapButtonSuccessFunction ( array $ args = [ ] ) { return $ this -> bootstrapButton ( ButtonFactory :: parseSuccessButton ( $ args ) , ArrayHelper :: get ( $ args , "icon" ) ) ; }
Displays a Bootstrap button Success .
1,271
public function bootstrapButtonWarningFunction ( array $ args = [ ] ) { return $ this -> bootstrapButton ( ButtonFactory :: parseWarningButton ( $ args ) , ArrayHelper :: get ( $ args , "icon" ) ) ; }
Displays a Bootstrap button Warning .
1,272
protected function validateTokenScopes ( array $ scopes ) { $ scopes = array_map ( function ( $ scope ) { return ( string ) $ scope ; } , $ scopes ) ; $ registeredScopes = $ this -> scopeService -> getAll ( ) ; $ registeredScopes = array_map ( function ( $ scope ) { return ( string ) $ scope ; } , $ registeredScopes ) ; $ diff = array_diff ( $ scopes , $ registeredScopes ) ; if ( count ( $ diff ) > 0 ) { throw OAuth2Exception :: invalidScope ( sprintf ( 'Some scope(s) do not exist: %s' , implode ( ', ' , $ diff ) ) ) ; } }
Validate the token scopes against the registered scope
1,273
public function save ( DomainObjectInterface & $ domainObject ) : void { if ( $ domainObject -> getId ( ) === 0 ) { $ this -> concreteInsert ( $ domainObject ) ; } $ this -> concreteUpdate ( $ domainObject ) ; }
Store the DomainObject in persistent storage . Either insert or update the store as required .
1,274
public function gc ( $ maxlifetime ) { $ this -> pdo -> queryWithParam ( 'DELETE FROM session WHERE last_update < DATE_SUB(NOW(), INTERVAL :maxlifetime SECOND)' , [ [ ':maxlifetime' , $ maxlifetime , \ PDO :: PARAM_INT ] ] ) ; return $ this -> pdo -> getLastOperationStatus ( ) ; }
Delete old sessions from storage .
1,275
public function read ( $ session_id ) { return ( string ) $ this -> pdo -> queryWithParam ( 'SELECT session_data FROM session WHERE session_id = :session_id' , [ [ ':session_id' , $ session_id , \ PDO :: PARAM_STR ] ] ) -> fetchColumn ( ) ; }
Read session data from storage .
1,276
public function bootstrapAlertDangerFunction ( array $ args = [ ] ) { return $ this -> bootstrapAlert ( ArrayHelper :: get ( $ args , "content" ) , ArrayHelper :: get ( $ args , "dismissible" ) , "alert-" . BootstrapInterface :: BOOTSTRAP_DANGER ) ; }
Displays a Bootstrap alert Danger .
1,277
public function bootstrapAlertInfoFunction ( array $ args = [ ] ) { return $ this -> bootstrapAlert ( ArrayHelper :: get ( $ args , "content" ) , ArrayHelper :: get ( $ args , "dismissible" ) , "alert-" . BootstrapInterface :: BOOTSTRAP_INFO ) ; }
Displays a Bootstrap alert Info .
1,278
public function bootstrapAlertLinkFunction ( array $ args = [ ] ) { $ attributes = [ ] ; $ attributes [ "href" ] = ArrayHelper :: get ( $ args , "href" , NavigationInterface :: NAVIGATION_HREF_DEFAULT ) ; $ innerHTML = ArrayHelper :: get ( $ args , "content" ) ; return static :: coreHTMLElement ( "a" , $ innerHTML , $ attributes ) ; }
Displays a Bootstrap alert Link .
1,279
public function bootstrapAlertSuccessFunction ( array $ args = [ ] ) { return $ this -> bootstrapAlert ( ArrayHelper :: get ( $ args , "content" ) , ArrayHelper :: get ( $ args , "dismissible" ) , "alert-" . BootstrapInterface :: BOOTSTRAP_SUCCESS ) ; }
Displays a Bootstrap alert Success .
1,280
public function bootstrapAlertWarningFunction ( array $ args = [ ] ) { return $ this -> bootstrapAlert ( ArrayHelper :: get ( $ args , "content" ) , ArrayHelper :: get ( $ args , "dismissible" ) , "alert-" . BootstrapInterface :: BOOTSTRAP_WARNING ) ; }
Displays a Bootstrap alert Warning .
1,281
private function getTopologyGroup ( string $ char ) : string { $ groups = $ this -> chars ; if ( \ strpos ( $ groups [ 0 ] , $ char ) !== false ) { return 'u' ; } if ( \ strpos ( $ groups [ 1 ] , $ char ) !== false ) { return 'l' ; } if ( \ strpos ( $ groups [ 2 ] , $ char ) !== false ) { return 'd' ; } if ( \ strpos ( $ groups [ 3 ] , $ char ) !== false ) { return 's' ; } throw new InvalidArgumentException ( 'Out of group character provided.' ) ; }
Return topology group for the given char .
1,282
private function getRandomChar ( string $ interval ) : string { $ size = \ strlen ( $ interval ) - 1 ; $ int = \ random_int ( 0 , $ size ) ; return $ interval [ $ int ] ; }
Get random char between .
1,283
public function executeLog ( string $ queries ) : int { $ n = 0 ; $ this -> multiQuery ( $ queries ) ; do { $ result = $ this -> mysqli -> store_result ( ) ; if ( $ this -> mysqli -> errno ) $ this -> mySqlError ( 'mysqli::store_result' ) ; if ( $ result ) { $ fields = $ result -> fetch_fields ( ) ; while ( ( $ row = $ result -> fetch_row ( ) ) ) { $ line = '' ; foreach ( $ row as $ i => $ field ) { if ( $ i > 0 ) $ line .= ' ' ; $ line .= str_pad ( ( string ) $ field , $ fields [ $ i ] -> max_length ) ; } echo date ( 'Y-m-d H:i:s' ) , ' ' , $ line , "\n" ; $ n ++ ; } $ result -> free ( ) ; } $ continue = $ this -> mysqli -> more_results ( ) ; if ( $ continue ) { $ tmp = $ this -> mysqli -> next_result ( ) ; if ( $ tmp === false ) $ this -> mySqlError ( 'mysqli::next_result' ) ; } } while ( $ continue ) ; return $ n ; }
Executes a query and logs the result set .
1,284
public function getRowInRowSet ( string $ columnName , $ value , array $ rowSet ) : array { if ( is_array ( $ rowSet ) ) { foreach ( $ rowSet as $ row ) { if ( ( string ) $ row [ $ columnName ] == ( string ) $ value ) { return $ row ; } } } throw new RuntimeException ( "Value '%s' for column '%s' not found in row set." , $ value , $ columnName ) ; }
Returns the first row in a row set for which a column has a specific value .
1,285
public function quoteListOfInt ( $ list , string $ delimiter , string $ enclosure , string $ escape ) : string { if ( $ list === null || $ list === false || $ list === '' || $ list === [ ] ) { return 'null' ; } $ ret = '' ; if ( is_scalar ( $ list ) ) { $ list = str_getcsv ( $ list , $ delimiter , $ enclosure , $ escape ) ; } elseif ( is_array ( $ list ) ) { ; } else { throw new RuntimeException ( "Unexpected parameter type '%s'. Array or scalar expected." , gettype ( $ list ) ) ; } foreach ( $ list as $ number ) { if ( $ list === null || $ list === false || $ list === '' ) { throw new RuntimeException ( 'Empty values are not allowed.' ) ; } if ( ! is_numeric ( $ number ) ) { throw new RuntimeException ( "Value '%s' is not a number." , ( is_scalar ( $ number ) ) ? $ number : gettype ( $ number ) ) ; } if ( $ ret ) $ ret .= ',' ; $ ret .= $ number ; } return $ this -> quoteString ( $ ret ) ; }
Returns a literal for an expression with a separated list of integers that can be safely used in SQL statements . Throws an exception if the value is a list of integers .
1,286
public function searchInRowSet ( string $ columnName , $ value , array $ rowSet ) { if ( is_array ( $ rowSet ) ) { foreach ( $ rowSet as $ key => $ row ) { if ( ( string ) $ row [ $ columnName ] === ( string ) $ value ) { return $ key ; } } } return null ; }
Returns the key of the first row in a row set for which a column has a specific value . Returns null if no row is found .
1,287
protected function sendLongData ( mysqli_stmt $ statement , int $ paramNr , ? string $ data ) : void { if ( $ data !== null ) { $ n = strlen ( $ data ) ; $ p = 0 ; while ( $ p < $ n ) { $ b = $ statement -> send_long_data ( $ paramNr , substr ( $ data , $ p , $ this -> chunkSize ) ) ; if ( ! $ b ) $ this -> mySqlError ( 'mysqli_stmt::send_long_data' ) ; $ p += $ this -> chunkSize ; } } }
Send data in blocks to the MySQL server .
1,288
private function executeTableShowFooter ( array $ columns ) : void { $ separator = '+' ; foreach ( $ columns as $ column ) { $ separator .= str_repeat ( '-' , $ column [ 'length' ] + 2 ) . '+' ; } echo $ separator , "\n" ; }
Helper method for method executeTable . Shows table footer .
1,289
private function executeTableShowHeader ( array $ columns ) : void { $ separator = '+' ; $ header = '|' ; foreach ( $ columns as $ column ) { $ separator .= str_repeat ( '-' , $ column [ 'length' ] + 2 ) . '+' ; $ spaces = ( $ column [ 'length' ] + 2 ) - mb_strlen ( ( string ) $ column [ 'header' ] ) ; $ spacesLeft = ( int ) floor ( $ spaces / 2 ) ; $ spacesRight = ( int ) ceil ( $ spaces / 2 ) ; $ fillerLeft = ( $ spacesLeft > 0 ) ? str_repeat ( ' ' , $ spacesLeft ) : '' ; $ fillerRight = ( $ spacesRight > 0 ) ? str_repeat ( ' ' , $ spacesRight ) : '' ; $ header .= $ fillerLeft . $ column [ 'header' ] . $ fillerRight . '|' ; } echo "\n" , $ separator , "\n" ; echo $ header , "\n" ; echo $ separator , "\n" ; }
Helper method for method executeTable . Shows table header .
1,290
public static function staticToStatic ( string $ sourceName , string $ targetName ) : void { $ source = file_get_contents ( $ sourceName ) ; $ sourceClass = basename ( $ sourceName , '.php' ) ; $ targetClass = basename ( $ targetName , '.php' ) ; $ source = NonStatic :: nonStatic ( $ source , $ sourceClass , $ targetClass ) ; file_put_contents ( $ targetName , $ source ) ; }
Makes non static implementation of a static class .
1,291
protected function getCookieExpirationDate ( ) { if ( ! empty ( $ this -> config [ 'expire_on_close' ] ) ) { $ expirationDate = 0 ; } else { $ expirationDate = Carbon :: now ( ) -> addMinutes ( 5 * 60 ) ; } return $ expirationDate ; }
Get the session lifetime in seconds .
1,292
public function updateAverageNote ( ) { $ commentTableName = $ this -> em -> getClassMetadata ( $ this -> commentManager -> getClass ( ) ) -> table [ 'name' ] ; $ threadTableName = $ this -> em -> getClassMetadata ( $ this -> getClass ( ) ) -> table [ 'name' ] ; $ this -> em -> getConnection ( ) -> beginTransaction ( ) ; $ this -> em -> getConnection ( ) -> query ( sprintf ( 'UPDATE %s t SET t.average_note = 0' , $ threadTableName ) ) ; $ this -> em -> getConnection ( ) -> query ( sprintf ( 'UPDATE %s t, (SELECT c.thread_id, avg(c.note) as avg_note FROM %s as c WHERE c.private <> 1 GROUP BY c.thread_id) as comments_note SET t.average_note = comments_note.avg_note WHERE t.id = comments_note.thread_id AND t.is_commentable <> 0' , $ threadTableName , $ commentTableName ) ) ; $ this -> em -> getConnection ( ) -> commit ( ) ; }
Updates the threads average note from comments notes .
1,293
private function format_trace_flags ( ) { $ flags = array ( ) ; if ( ! $ this -> already_invoked ) { $ flags [ ] = 'first_time' ; } if ( ! $ this -> is_needed ( ) ) { $ flags [ ] = 'not_needed' ; } return ( count ( $ flags ) ) ? '(' . join ( ', ' , $ flags ) . ')' : '' ; }
Format the trace flags for display .
1,294
protected function doRequest ( $ method , $ apiMethod , array $ data = [ ] ) { $ url = $ this -> config [ 'endpoint' ] . $ apiMethod ; $ data = $ this -> mergeData ( $ this -> createAuthData ( ) , $ data ) ; $ response = $ this -> getGuzzleClient ( ) -> request ( $ method , $ url , [ 'json' => $ data ] ) ; $ responseContent = \ GuzzleHttp \ json_decode ( $ response -> getBody ( ) ) ; if ( ! property_exists ( $ responseContent , 'success' ) || ! $ responseContent -> success ) { throw new InvalidRequestException ( $ method , $ url , $ data , $ response ) ; } return $ responseContent ; }
Send request to SalesManago API .
1,295
protected function createAuthData ( ) { return [ 'clientId' => $ this -> config [ 'client_id' ] , 'apiKey' => $ this -> config [ 'api_key' ] , 'requestTime' => time ( ) , 'sha' => sha1 ( $ this -> config [ 'api_key' ] . $ this -> config [ 'client_id' ] . $ this -> config [ 'api_secret' ] ) ] ; }
Returns an array of authentication data .
1,296
private function mergeData ( array $ base , array $ replacements ) { return array_filter ( array_merge ( $ base , $ replacements ) , function ( $ value ) { return $ value !== null ; } ) ; }
Merge data and removing null values .
1,297
public function set ( $ domain , $ key , $ value = null ) { $ this -> validateDomain ( $ domain ) ; if ( null !== $ value ) { $ this -> profile [ $ domain ] [ $ key ] = $ value ; } else { $ this -> profile [ $ domain ] = $ key ; } }
Set a domain configuration .
1,298
public function get ( $ domain , $ key = null ) { $ this -> validateDomain ( $ domain ) ; if ( null === $ key ) { return new Config ( $ this -> profile [ $ domain ] ) ; } if ( ! isset ( $ this -> profile [ $ domain ] [ $ key ] ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Unknown key "%s" for profile domain "%s"' , $ key , $ domain ) ) ; } return $ this -> profile [ $ domain ] [ $ key ] ; }
Get a domain configuration .
1,299
protected function getFieldNames ( Criterion $ criterion ) { $ fieldDefinitionIdentifier = $ criterion -> target ; $ fieldMap = $ this -> contentTypeHandler -> getSearchableFieldMap ( ) ; $ fieldNames = [ ] ; foreach ( $ fieldMap as $ contentTypeIdentifier => $ fieldIdentifierMap ) { if ( ! isset ( $ fieldIdentifierMap [ $ fieldDefinitionIdentifier ] ) ) { continue ; } $ fieldNames [ ] = $ this -> fieldNameGenerator -> getTypedName ( $ this -> fieldNameGenerator -> getName ( 'is_empty' , $ fieldDefinitionIdentifier , $ contentTypeIdentifier ) , new BooleanField ( ) ) ; } return $ fieldNames ; }
Return all field names for the given criterion .