idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
14,000
public function getParticipants ( $ tournament ) { $ response = Guzzle :: get ( "tournaments/{$tournament}/participants" ) ; $ participants = [ ] ; foreach ( $ response as $ team ) { $ participant = new Participant ( $ team -> participant ) ; $ participant -> tournament_slug = $ tournament ; $ participants [ ] = $ participant ; } return $ participants ; }
Retrieve a tournament s participant list .
14,001
public function randomizeParticipants ( $ tournament ) { $ response = Guzzle :: post ( "tournaments/{$tournament}/participants/randomize" ) ; $ participants = [ ] ; foreach ( $ response as $ team ) { $ participant = new Participant ( $ team -> participant ) ; $ participant -> tournament_slug = $ tournament ; $ participants [ ] = $ participant ; } return $ participants ; }
Randomize seeds among participants .
14,002
public function getParticipant ( $ tournament , $ participant ) { $ response = Guzzle :: get ( "tournaments/{$tournament}/participants/{$participant}" ) ; $ participant = new Participant ( $ response -> participant ) ; $ participant -> tournament_slug = $ tournament ; return $ participant ; }
Retrieve a single participant record for a tournament .
14,003
public function getMatches ( $ tournament ) { $ response = Guzzle :: get ( "tournaments/{$tournament}/matches" ) ; $ matches = [ ] ; foreach ( $ response as $ match ) { $ matchModel = new Match ( $ match -> match ) ; $ matchModel -> tournament_slug = $ tournament ; $ matches [ ] = $ matchModel ; } return $ matches ; }
Retrieve a tournament s match list .
14,004
public function getMatch ( $ tournament , $ match ) { $ response = Guzzle :: get ( "tournaments/{$tournament}/matches/{$match}" ) ; $ match = new Match ( $ response -> match ) ; $ match -> tournament_slug = $ tournament ; return $ match ; }
Retrieve a single match record for a tournament .
14,005
public static function getCurrenciesData ( $ locale ) { if ( null === self :: $ currencies ) { self :: prepareCurrencies ( $ locale ) ; } return self :: $ currencies ; }
Returns the currencies data .
14,006
public static function getDisplayCurrencies ( $ locale ) { if ( null === self :: $ currenciesNames ) { self :: prepareCurrencies ( $ locale ) ; } return self :: $ currenciesNames ; }
Returns the currencies names for a locale .
14,007
public function updateCMSFields ( FieldList $ fields ) { if ( $ this -> owner -> class != 'Folder' ) { $ set = $ this -> owner -> getTranslatableTabSet ( ) ; $ set -> removeByName ( Translatable :: default_locale ( ) ) ; foreach ( $ set -> FieldList ( ) as $ tab ) { $ fields -> addFieldToTab ( 'Root' , $ tab ) ; } } }
Update the field values for the files & images section
14,008
public static function get_extra_config ( $ class , $ extension , $ args ) { if ( ! self :: is_translatable_installed ( ) ) { if ( SapphireTest :: is_running_test ( ) ) { return null ; } user_error ( 'Translatable module is not installed but required.' , E_USER_WARNING ) ; return null ; } if ( $ args ) { self :: $ arguments [ $ class ] = $ args ; } return array ( 'db' => self :: collectDBFields ( $ class ) , 'has_one' => self :: collectHasOneRelations ( $ class ) ) ; }
Use table information and locales to dynamically build required table fields
14,009
public function updateCMSFields ( FieldList $ fields ) { parent :: updateCMSFields ( $ fields ) ; if ( ! isset ( self :: $ collectorCache [ $ this -> owner -> class ] ) ) { return ; } foreach ( self :: $ collectorCache [ $ this -> owner -> class ] as $ translatableField => $ type ) { $ fields -> removeByName ( $ translatableField ) ; } if ( Translatable :: default_locale ( ) != Translatable :: get_current_locale ( ) ) { $ transformation = TranslatableFormFieldTransformation :: create ( $ this -> owner ) ; foreach ( self :: $ collectorCache [ $ this -> owner -> class ] as $ translatableField => $ type ) { if ( strpos ( $ translatableField , Translatable :: get_current_locale ( ) ) ) { $ basename = $ this -> getBasename ( $ translatableField ) ; if ( $ field = $ this -> getLocalizedFormField ( $ basename , Translatable :: default_locale ( ) ) ) { $ fields -> replaceField ( $ basename , $ transformation -> transformFormField ( $ field ) ) ; } } } } }
Alter the CMS Fields in order to automatically present the correct ones based on current language .
14,010
public function getLocalizedFormField ( $ fieldName , $ locale ) { $ baseName = $ this -> getBasename ( $ fieldName ) ; $ fieldLabels = $ this -> owner -> fieldLabels ( ) ; $ localizedFieldName = self :: localized_field ( $ fieldName , $ locale ) ; $ fieldLabel = isset ( $ fieldLabels [ $ baseName ] ) ? $ fieldLabels [ $ baseName ] : $ baseName ; if ( ! $ this -> canTranslate ( null , $ locale ) ) { return ReadonlyField :: create ( $ localizedFieldName , $ fieldLabel ) ; } $ dbFields = array ( ) ; Config :: inst ( ) -> get ( $ this -> owner -> class , 'db' , Config :: EXCLUDE_EXTRA_SOURCES , $ dbFields ) ; $ type = isset ( $ dbFields [ $ baseName ] ) ? $ dbFields [ $ baseName ] : '' ; $ typeClean = ( ( $ p = strpos ( $ type , '(' ) ) !== false ) ? substr ( $ type , 0 , $ p ) : $ type ; switch ( strtolower ( $ typeClean ) ) { case 'varchar' : case 'htmlvarchar' : $ field = TextField :: create ( $ localizedFieldName , $ fieldLabel ) ; break ; case 'text' : $ field = TextareaField :: create ( $ localizedFieldName , $ fieldLabel ) ; break ; case 'htmltext' : default : $ field = HtmlEditorField :: create ( $ localizedFieldName , $ fieldLabel ) ; break ; } return $ field ; }
Get a form field for the given field name
14,011
public function getLocalizedRelationField ( $ fieldName , $ locale ) { $ baseName = $ this -> getBasename ( $ fieldName ) ; $ localizedFieldName = self :: localized_field ( $ fieldName , $ locale ) ; $ field = null ; if ( $ field = $ this -> getFieldForRelation ( $ fieldName ) ) { $ relationField = clone $ field ; $ relationField -> setName ( $ localizedFieldName ) ; return $ relationField ; } }
Get a form field for the given relation name
14,012
public function updateFieldLabels ( & $ labels ) { parent :: updateFieldLabels ( $ labels ) ; $ statics = self :: $ collectorCache [ $ this -> ownerBaseClass ] ; foreach ( $ statics as $ field => $ type ) { $ parts = explode ( TRANSLATABLE_COLUMN_SEPARATOR , $ field ) ; $ labels [ $ field ] = FormField :: name_to_label ( $ parts [ 0 ] ) . ' (' . $ parts [ 1 ] . ')' ; } }
Present translatable form fields in a more readable fashion
14,013
public function isLocalizedField ( $ fieldName ) { $ fields = self :: get_localized_class_fields ( $ this -> ownerBaseClass ) ; return in_array ( $ fieldName , $ fields ) ; }
Check if the given field name is a localized field
14,014
public function getLocalizedFieldName ( $ fieldName ) { if ( $ this -> isLocalizedField ( $ fieldName ) || $ this -> isLocalizedRelation ( $ fieldName ) ) { return self :: localized_field ( $ fieldName ) ; } trigger_error ( "Field '$fieldName' is not a localized field" , E_USER_ERROR ) ; }
Get the field name in the current reading locale
14,015
public function getLocalizedRelation ( $ fieldName , $ strict = true ) { $ localizedField = $ this -> getLocalizedFieldName ( $ fieldName ) ; if ( $ strict ) { return $ this -> owner -> getRelation ( $ localizedField ) ; } if ( $ value = $ this -> owner -> getRelation ( $ localizedField ) ) { return $ value ; } return $ this -> owner -> getRelation ( $ fieldName ) ; }
Get the localized object for a given relation .
14,016
public function getLocalizedValue ( $ fieldName , $ strict = true , $ parseShortCodes = false ) { $ localizedField = $ this -> getLocalizedFieldName ( $ fieldName ) ; $ strict = filter_var ( $ strict , FILTER_VALIDATE_BOOLEAN ) ; $ value = $ this -> owner -> dbObject ( $ localizedField ) ; if ( ! $ strict && ! $ value -> exists ( ) ) { $ value = $ this -> owner -> dbObject ( $ fieldName ) ; } return ( $ parseShortCodes && $ value ) ? ShortcodeParser :: get_active ( ) -> parse ( $ value -> getValue ( ) ) : $ value ; }
Get the localized value for a given field .
14,017
public function onBeforeWrite ( ) { if ( ! isset ( self :: $ localizedFields [ $ this -> ownerBaseClass ] ) ) { return ; } $ fields = self :: $ localizedFields [ $ this -> ownerBaseClass ] ; foreach ( $ fields as $ field => $ localized ) { foreach ( self :: get_target_locales ( ) as $ locale ) { $ fieldName = self :: localized_field ( $ field , $ locale ) ; if ( $ this -> owner -> isChanged ( $ fieldName , 2 ) && ! $ this -> canTranslate ( null , $ locale ) ) { throw new PermissionFailureException ( "You're not allowed to edit the locale '$locale' for this object" ) ; } } } }
On before write hook . Check if any translatable field has changed and if permissions are sufficient
14,018
public static function get_localized_class_fields ( $ class ) { $ fieldNames = null ; $ ancestry = array_reverse ( ClassInfo :: ancestry ( $ class ) ) ; foreach ( $ ancestry as $ className ) { if ( isset ( self :: $ localizedFields [ $ className ] ) ) { if ( $ fieldNames === null ) { $ fieldNames = array ( ) ; } foreach ( self :: $ localizedFields [ $ className ] as $ k => $ v ) { $ fieldNames [ ] = $ k ; } } } return array_unique ( $ fieldNames ) ; }
Get an array with all localized fields for the given class
14,019
public static function localized_field ( $ field , $ locale = null ) { if ( $ locale === null ) { $ locale = Translatable :: get_current_locale ( ) ; } if ( $ locale == Translatable :: default_locale ( ) ) { return $ field ; } return $ field . TRANSLATABLE_COLUMN_SEPARATOR . $ locale ; }
Given a field name and a locale name create a composite string that represents the field in the database .
14,020
public static function set_locales ( $ locales ) { if ( is_array ( $ locales ) ) { $ list = array ( ) ; foreach ( $ locales as $ locale ) { if ( i18n :: validate_locale ( $ locale ) ) { $ list [ ] = $ locale ; } } $ list = array_unique ( $ list ) ; Config :: inst ( ) -> update ( 'TranslatableDataObject' , 'locales' , empty ( $ list ) ? null : $ list ) ; } else { Config :: inst ( ) -> update ( 'TranslatableDataObject' , 'locales' , null ) ; } }
Explicitly set the locales that should be translated .
14,021
protected static function collectDBFields ( $ class ) { if ( isset ( self :: $ collectorCache [ $ class ] ) ) { return self :: $ collectorCache [ $ class ] ; } if ( isset ( self :: $ collectorLock [ $ class ] ) && self :: $ collectorLock [ $ class ] ) { return null ; } self :: $ collectorLock [ $ class ] = true ; $ fields = array ( ) ; Config :: inst ( ) -> get ( $ class , 'db' , Config :: EXCLUDE_EXTRA_SOURCES , $ fields ) ; $ arguments = self :: get_arguments ( $ class ) ; $ locales = self :: get_target_locales ( ) ; if ( ( $ index = array_search ( Translatable :: default_locale ( ) , $ locales ) ) !== false ) { array_splice ( $ locales , $ index , 1 ) ; } $ fieldsToTranslate = array ( ) ; if ( $ arguments ) { foreach ( $ arguments as $ field ) { if ( array_key_exists ( $ field , $ fields ) ) { $ fieldsToTranslate [ ] = $ field ; } } } else { foreach ( $ fields as $ field => $ type ) { $ typeClean = ( ( $ p = strpos ( $ type , '(' ) ) !== false ) ? substr ( $ type , 0 , $ p ) : $ type ; $ defaultFields = self :: config ( ) -> default_field_types ; if ( is_array ( $ defaultFields ) && in_array ( $ typeClean , $ defaultFields ) ) { $ fieldsToTranslate [ ] = $ field ; } } } $ additionalFields = array ( ) ; self :: $ localizedFields [ $ class ] = array ( ) ; foreach ( $ fieldsToTranslate as $ field ) { self :: $ localizedFields [ $ class ] [ $ field ] = array ( ) ; foreach ( $ locales as $ locale ) { $ localizedName = self :: localized_field ( $ field , $ locale ) ; self :: $ localizedFields [ $ class ] [ $ field ] [ ] = $ localizedName ; $ additionalFields [ $ localizedName ] = $ fields [ $ field ] ; } } self :: $ collectorCache [ $ class ] = $ additionalFields ; self :: $ collectorLock [ $ class ] = false ; return $ additionalFields ; }
Collect all additional database fields of the given class .
14,022
protected static function get_target_locales ( ) { if ( is_array ( self :: config ( ) -> locales ) ) { return ( array ) self :: config ( ) -> locales ; } else if ( is_array ( Translatable :: get_allowed_locales ( ) ) ) { return ( array ) Translatable :: get_allowed_locales ( ) ; } return array_keys ( Translatable :: get_existing_content_languages ( ) ) ; }
Get the locales that should be translated
14,023
protected static function get_arguments ( $ class ) { if ( isset ( self :: $ arguments [ $ class ] ) ) { return self :: $ arguments [ $ class ] ; } else { if ( $ staticFields = Config :: inst ( ) -> get ( $ class , 'translatable_fields' , Config :: FIRST_SET ) ) { if ( is_array ( $ staticFields ) && ! empty ( $ staticFields ) ) { return $ staticFields ; } } } return null ; }
Get the custom arguments for a given class . Either directly from how the extension was defined or lookup the translatable_fields static variable
14,024
public function setFieldForRelation ( $ fieldName , FormField $ field ) { if ( self :: isLocalizedRelation ( $ fieldName ) ) { self :: $ localizedFields [ $ this -> ownerBaseClass . '_has_one' ] [ $ fieldName ] [ 'FormField' ] = $ field ; } }
Setter for relation specific FormField . Will be cloned in scaffolding functions
14,025
public static function getDisplayCountries ( $ locale ) { if ( ! isset ( self :: $ countries [ $ locale ] ) ) { self :: $ countries [ $ locale ] = Intl :: getRegionBundle ( ) -> getCountryNames ( $ locale ) ; } return self :: $ countries [ $ locale ] ; }
Returns the country names for a locale .
14,026
public static function getDisplayLanguages ( $ locale ) { if ( ! isset ( self :: $ languages [ $ locale ] ) ) { self :: $ languages [ $ locale ] = Intl :: getLanguageBundle ( ) -> getLanguageNames ( $ locale ) ; } return self :: $ languages [ $ locale ] ; }
Returns the language names for a locale .
14,027
public static function getDisplayLocales ( $ locale ) { if ( ! isset ( self :: $ locales [ $ locale ] ) ) { self :: $ locales [ $ locale ] = Intl :: getLocaleBundle ( ) -> getLocaleNames ( $ locale ) ; } return self :: $ locales [ $ locale ] ; }
Returns the locale names for a locale .
14,028
public function exitWorkerManager ( int $ sig , array $ pid ) : void { $ this -> logger -> debug ( 'fork manager [' . $ pid [ 'pid' ] . '] exit with [' . $ sig . ']' , [ 'category' => get_class ( $ this ) , ] ) ; pcntl_waitpid ( $ pid [ 'pid' ] , $ status , WNOHANG | WUNTRACED ) ; $ this -> cleanup ( SIGTERM ) ; }
Wait for worker manager .
14,029
protected function initWorkerManager ( ) { $ pid = pcntl_fork ( ) ; $ this -> manager_pid = $ pid ; if ( - 1 === $ pid ) { throw new SpawnForkException ( 'failed to spawn fork manager' ) ; } if ( ! $ pid ) { $ manager = $ this -> factory -> buildManager ( ) ; $ manager -> process ( ) ; exit ( ) ; } }
Fork a worker manager .
14,030
protected function main ( ) : void { $ this -> logger -> info ( 'start job listener' , [ 'category' => get_class ( $ this ) , ] ) ; $ cursor_jobs = $ this -> jobs -> getCursor ( [ '$or' => [ [ 'status' => JobInterface :: STATUS_WAITING ] , [ 'status' => JobInterface :: STATUS_POSTPONED ] , ] , ] ) ; $ cursor_events = $ this -> events -> getCursor ( [ 'timestamp' => [ '$gte' => new UTCDateTime ( ) ] , 'job' => [ '$exists' => true ] , 'status' => [ '$gt' => JobInterface :: STATUS_POSTPONED ] , ] ) ; $ this -> catchSignal ( ) ; while ( $ this -> loop ( ) ) { while ( $ this -> loop ( ) ) { if ( null === $ cursor_events -> current ( ) ) { if ( $ cursor_events -> getInnerIterator ( ) -> isDead ( ) ) { $ this -> logger -> error ( 'event queue cursor is dead, is it a capped collection?' , [ 'category' => get_class ( $ this ) , ] ) ; $ this -> events -> create ( ) ; $ this -> main ( ) ; break ; } $ this -> events -> next ( $ cursor_events , function ( ) { $ this -> main ( ) ; } ) ; } $ event = $ cursor_events -> current ( ) ; $ this -> events -> next ( $ cursor_events , function ( ) { $ this -> main ( ) ; } ) ; if ( $ event === null ) { break ; } $ this -> handleEvent ( $ event ) ; } if ( null === $ cursor_jobs -> current ( ) ) { if ( $ cursor_jobs -> getInnerIterator ( ) -> isDead ( ) ) { $ this -> logger -> error ( 'job queue cursor is dead, is it a capped collection?' , [ 'category' => get_class ( $ this ) , ] ) ; $ this -> jobs -> create ( ) ; $ this -> main ( ) ; break ; } $ this -> jobs -> next ( $ cursor_jobs , function ( ) { $ this -> main ( ) ; } ) ; continue ; } $ job = $ cursor_jobs -> current ( ) ; $ this -> jobs -> next ( $ cursor_jobs , function ( ) { $ this -> main ( ) ; } ) ; $ this -> handleJob ( $ job ) ; } }
Fork handling blocking process .
14,031
public function does_it_meet_required_php_version ( $ version = PHP_VERSION ) { if ( $ this -> version_passes_requirement ( $ this -> minimum_version , $ version ) ) { return true ; } $ this -> load_version_notice ( array ( $ this , 'minimum_admin_notice' ) ) ; return false ; }
Check given PHP version against minimum required version .
14,032
public function does_it_meet_recommended_php_version ( $ version = PHP_VERSION ) { if ( $ this -> version_passes_requirement ( $ this -> recommended_version , $ version ) ) { return true ; } $ this -> load_version_notice ( array ( $ this , 'recommended_admin_notice' ) ) ; return false ; }
Check given PHP version against recommended version .
14,033
public function get_admin_notice ( $ level = 'minimum' ) { if ( 'recommended' === $ level ) { if ( ! empty ( $ this -> plugin_name ) ) { return '<p>' . $ this -> plugin_name . ' recommends a PHP version higher than ' . $ this -> recommended_version . '. Read more information about <a href="http://www.wpupdatephp.com/update/">how you can update</a>.</p>' ; } else { return '<p>This plugin recommends a PHP version higher than ' . $ this -> recommended_version . '. Read more information about <a href="http://www.wpupdatephp.com/update/">how you can update</a>.</p>' ; } } if ( ! empty ( $ this -> plugin_name ) ) { return '<p>Unfortunately, ' . $ this -> plugin_name . ' cannot run on PHP versions older than ' . $ this -> minimum_version . '. Read more information about <a href="http://www.wpupdatephp.com/update/">how you can update</a>.</p>' ; } else { return '<p>Unfortunately, this plugin cannot run on PHP versions older than ' . $ this -> minimum_version . '. Read more information about <a href="http://www.wpupdatephp.com/update/">how you can update</a>.</p>' ; } }
Return the string to be shown in the admin notice .
14,034
private static function splAutoloader ( $ class_name ) { if ( 'Treffynnon\\Navigator' === substr ( ltrim ( $ class_name , '\\' ) , 0 , 20 ) ) { $ class_path = realpath ( __DIR__ . '/..' ) . '/' . str_replace ( '\\' , DIRECTORY_SEPARATOR , $ class_name ) ; require_once $ class_path . '.php' ; } }
Convert class names into file paths for inclusion
14,035
public static function distanceFactory ( $ lat1 , $ long1 , $ lat2 , $ long2 ) { $ point1 = new L ( new C ( $ lat1 ) , new C ( $ long1 ) ) ; $ point2 = new L ( new C ( $ lat2 ) , new C ( $ long2 ) ) ; return new D ( $ point1 , $ point2 ) ; }
Get a primed instance of the distance object
14,036
public static function getDistance ( $ lat1 , $ long1 , $ lat2 , $ long2 ) { return self :: distanceFactory ( $ lat1 , $ long1 , $ lat2 , $ long2 ) -> get ( ) ; }
Get the distance in metres
14,037
public function exitWorker ( int $ sig , array $ pid ) : self { $ this -> logger -> debug ( 'worker [' . $ pid [ 'pid' ] . '] exit with [' . $ sig . ']' , [ 'category' => get_class ( $ this ) , ] ) ; pcntl_waitpid ( $ pid [ 'pid' ] , $ status , WNOHANG | WUNTRACED ) ; foreach ( $ this -> forks as $ id => $ process ) { if ( $ process === $ pid [ 'pid' ] ) { unset ( $ this -> forks [ $ id ] ) ; if ( isset ( $ this -> job_map [ $ id ] ) ) { unset ( $ this -> job_map [ $ id ] ) ; } } } $ this -> spawnMinimumWorkers ( ) ; return $ this ; }
Wait for child and terminate .
14,038
protected function spawnInitialWorkers ( ) { $ this -> logger -> debug ( 'spawn initial [' . $ this -> min_children . '] workers' , [ 'category' => get_class ( $ this ) , ] ) ; if ( self :: PM_DYNAMIC === $ this -> pm || self :: PM_STATIC === $ this -> pm ) { for ( $ i = $ this -> count ( ) ; $ i < $ this -> min_children ; ++ $ i ) { $ this -> spawnWorker ( ) ; } } }
Start initial workers .
14,039
protected function spawnMinimumWorkers ( ) { $ this -> logger -> debug ( 'verify that the minimum number [' . $ this -> min_children . '] of workers are running' , [ 'category' => get_class ( $ this ) , ] ) ; for ( $ i = $ this -> count ( ) ; $ i < $ this -> min_children ; ++ $ i ) { $ this -> spawnWorker ( ) ; } }
Start minumum number of workers .
14,040
public function getJob ( ObjectId $ id ) : Process { $ result = $ this -> db -> { $ this -> job_queue } -> findOne ( [ '_id' => $ id , ] , [ 'typeMap' => self :: TYPE_MAP , ] ) ; if ( null === $ result ) { throw new JobNotFoundException ( 'job ' . $ id . ' was not found' ) ; } return new Process ( $ result , $ this , $ this -> events ) ; }
Get job by Id .
14,041
public function cancelJob ( ObjectId $ id ) : bool { $ result = $ this -> updateJob ( $ id , JobInterface :: STATUS_CANCELED ) ; if ( 1 !== $ result -> getMatchedCount ( ) ) { throw new JobNotFoundException ( 'job ' . $ id . ' was not found' ) ; } $ this -> db -> { $ this -> event_queue } -> insertOne ( [ 'job' => $ id , 'status' => JobInterface :: STATUS_CANCELED , 'timestamp' => new UTCDateTime ( ) , ] ) ; return true ; }
Cancel job .
14,042
public function addJob ( string $ class , $ data , array $ options = [ ] ) : Process { $ document = $ this -> prepareInsert ( $ class , $ data , $ options ) ; $ result = $ this -> db -> { $ this -> job_queue } -> insertOne ( $ document ) ; $ this -> logger -> debug ( 'queue job [' . $ result -> getInsertedId ( ) . '] added to [' . $ class . ']' , [ 'category' => get_class ( $ this ) , 'params' => $ options , 'data' => $ data , ] ) ; $ this -> db -> { $ this -> event_queue } -> insertOne ( [ 'job' => $ result -> getInsertedId ( ) , 'status' => JobInterface :: STATUS_WAITING , 'timestamp' => new UTCDateTime ( ) , ] ) ; $ document = $ this -> db -> { $ this -> job_queue } -> findOne ( [ '_id' => $ result -> getInsertedId ( ) ] , [ 'typeMap' => self :: TYPE_MAP , ] ) ; $ process = new Process ( $ document , $ this , $ this -> events ) ; return $ process ; }
Add job to queue .
14,043
public function addJobOnce ( string $ class , $ data , array $ options = [ ] ) : Process { $ filter = [ 'class' => $ class , '$or' => [ [ 'status' => JobInterface :: STATUS_WAITING ] , [ 'status' => JobInterface :: STATUS_POSTPONED ] , [ 'status' => JobInterface :: STATUS_PROCESSING ] , ] , ] ; $ requested = $ options ; $ document = $ this -> prepareInsert ( $ class , $ data , $ options ) ; if ( true !== $ options [ self :: OPTION_IGNORE_DATA ] ) { $ filter = [ 'data' => $ data ] + $ filter ; } $ result = $ this -> db -> { $ this -> job_queue } -> updateOne ( $ filter , [ '$setOnInsert' => $ document ] , [ 'upsert' => true , '$isolated' => true , ] ) ; if ( $ result -> getMatchedCount ( ) > 0 ) { $ document = $ this -> db -> { $ this -> job_queue } -> findOne ( $ filter , [ 'typeMap' => self :: TYPE_MAP , ] ) ; if ( array_intersect_key ( $ document [ 'options' ] , $ requested ) !== $ requested || ( $ data !== $ document [ 'data' ] && true === $ options [ self :: OPTION_IGNORE_DATA ] ) ) { $ this -> logger -> debug ( 'job [' . $ document [ '_id' ] . '] options/data changed, reschedule new job' , [ 'category' => get_class ( $ this ) , 'data' => $ data , ] ) ; $ this -> cancelJob ( $ document [ '_id' ] ) ; return $ this -> addJobOnce ( $ class , $ data , $ options ) ; } return new Process ( $ document , $ this , $ this -> events ) ; } $ this -> logger -> debug ( 'queue job [' . $ result -> getUpsertedId ( ) . '] added to [' . $ class . ']' , [ 'category' => get_class ( $ this ) , 'params' => $ options , 'data' => $ data , ] ) ; $ this -> db -> { $ this -> event_queue } -> insertOne ( [ 'job' => $ result -> getUpsertedId ( ) , 'status' => JobInterface :: STATUS_WAITING , 'timestamp' => new UTCDateTime ( ) , ] ) ; $ document = $ this -> db -> { $ this -> job_queue } -> findOne ( [ '_id' => $ result -> getUpsertedId ( ) ] , [ 'typeMap' => self :: TYPE_MAP , ] ) ; return new Process ( $ document , $ this , $ this -> events ) ; }
Only add job if not in queue yet .
14,044
public function listen ( Closure $ callback , array $ query = [ ] ) : self { if ( 0 === count ( $ query ) ) { $ query = [ 'timestamp' => [ '$gte' => new UTCDateTime ( ) ] , ] ; } $ cursor = $ this -> events -> getCursor ( $ query ) ; while ( true ) { if ( null === $ cursor -> current ( ) ) { if ( $ cursor -> getInnerIterator ( ) -> isDead ( ) ) { $ this -> logger -> error ( 'events queue cursor is dead, is it a capped collection?' , [ 'category' => get_class ( $ this ) , ] ) ; $ this -> events -> create ( ) ; return $ this -> listen ( $ callback , $ query ) ; } $ this -> events -> next ( $ cursor , function ( ) use ( $ callback , $ query ) { return $ this -> listen ( $ callback , $ query ) ; } ) ; continue ; } $ result = $ cursor -> current ( ) ; $ this -> events -> next ( $ cursor , function ( ) use ( $ callback , $ query ) { $ this -> listen ( $ callback , $ query ) ; } ) ; $ process = new Process ( $ result , $ this , $ this -> events ) ; if ( true === $ callback ( $ process ) ) { return $ this ; } } }
Listen for events .
14,045
protected function prepareInsert ( string $ class , $ data , array & $ options = [ ] ) : array { $ defaults = [ self :: OPTION_AT => $ this -> default_at , self :: OPTION_INTERVAL => $ this -> default_interval , self :: OPTION_RETRY => $ this -> default_retry , self :: OPTION_RETRY_INTERVAL => $ this -> default_retry_interval , self :: OPTION_FORCE_SPAWN => false , self :: OPTION_TIMEOUT => $ this -> default_timeout , self :: OPTION_IGNORE_DATA => false , ] ; $ options = array_merge ( $ defaults , $ options ) ; $ options = SchedulerValidator :: validateOptions ( $ options ) ; $ document = [ 'class' => $ class , 'status' => JobInterface :: STATUS_WAITING , 'created' => new UTCDateTime ( ) , 'started' => new UTCDateTime ( ) , 'ended' => new UTCDateTime ( ) , 'worker' => new ObjectId ( ) , 'data' => $ data , ] ; if ( isset ( $ options [ self :: OPTION_ID ] ) ) { $ id = $ options [ self :: OPTION_ID ] ; unset ( $ options [ self :: OPTION_ID ] ) ; $ document [ '_id' ] = $ id ; } $ document [ 'options' ] = $ options ; return $ document ; }
Prepare insert .
14,046
public function transformFormField ( FormField $ field ) { $ newfield = $ field -> performReadOnlyTransformation ( ) ; $ fieldname = $ field -> getName ( ) ; if ( $ this -> original -> isLocalizedField ( $ fieldname ) ) { $ field -> setName ( $ this -> original -> getLocalizedFieldName ( $ fieldname ) ) ; $ value = $ this -> original -> getLocalizedValue ( $ fieldname ) ; if ( $ value instanceof DBField ) { $ field -> setValue ( $ value -> getValue ( ) ) ; } else { $ field -> setValue ( $ value ) ; } } return $ this -> baseTransform ( $ newfield , $ field , $ fieldname ) ; }
Transform a given form field into a composite field where the translation is editable and the original value is added as a read - only field .
14,047
public function start ( ) { if ( $ this -> state != 'pending' ) { throw new AlreadyStartedException ( 'Tournament is already underway.' ) ; } $ response = Guzzle :: post ( "tournaments/{$this->id}/start" ) ; return $ this -> updateModel ( $ response -> tournament ) ; }
Start a tournament opening up first round matches for score reporting .
14,048
public function finalize ( ) { if ( $ this -> state != 'awaiting_review' ) { throw new StillRunningException ( 'Tournament is still running.' ) ; } $ response = Guzzle :: post ( "tournaments/{$this->id}/finalize" ) ; return $ this -> updateModel ( $ response -> tournament ) ; }
Finalize a tournament that has had all match scores submitted rendering its results permanent .
14,049
public function update ( $ params = [ ] ) { $ response = Guzzle :: put ( "tournaments/{$this->id}" , $ params ) ; return $ this -> updateModel ( $ response -> tournament ) ; }
Update a tournament s attributes .
14,050
public function get ( D \ Calculator \ CalculatorInterface $ calculator = null , D \ Converter \ ConverterInterface $ unit_converter = null ) { if ( is_null ( $ calculator ) ) { $ calculator = new D \ Calculator \ Vincenty ; } $ distance = $ calculator -> calculate ( $ this -> point1 , $ this -> point2 ) ; if ( ! is_null ( $ unit_converter ) ) { $ distance = $ unit_converter -> convert ( $ distance ) ; } return $ distance ; }
Calculate the distance between two points . Defaults to Vincenty if no calculator is supplied . If no unit converter is supplied then the formula will return a value in metres .
14,051
protected function getPackageReplacementTokens ( PackageInterface $ package ) { $ vars = array ( '{$type}' => $ package -> getType ( ) , ) ; $ prettyName = $ package -> getPrettyName ( ) ; if ( strpos ( $ prettyName , '/' ) !== false ) { $ pieces = explode ( '/' , $ prettyName ) ; $ vars [ '{$vendor}' ] = $ pieces [ 0 ] ; $ vars [ '{$name}' ] = $ pieces [ 1 ] ; } else { $ vars [ '{$vendor}' ] = '' ; $ vars [ '{$name}' ] = $ prettyName ; } return $ vars ; }
Retrieve replacement tokens for the given package .
14,052
protected function getPluginConfiguration ( ) { if ( ! isset ( $ this -> configuration ) ) { $ extra = $ this -> composer -> getPackage ( ) -> getExtra ( ) ; $ legacy = false ; if ( isset ( $ extra [ 'custom-installer' ] ) ) { $ legacy = true ; foreach ( $ extra [ 'custom-installer' ] as $ key => $ val ) { if ( is_array ( $ val ) ) { $ legacy = false ; break ; } } } if ( $ legacy ) { $ this -> configuration = new ConfigurationAlpha1 ( $ extra ) ; } else { $ this -> configuration = new Configuration ( $ extra ) ; } } return $ this -> configuration ; }
Retrieve plugin configuration object .
14,053
public function getTaxonomyKey ( ) { $ called_class_segments = explode ( '\\' , get_called_class ( ) ) ; $ class_name = end ( $ called_class_segments ) ; return ( is_null ( $ this -> taxonomy_key ) ) ? Str :: machine ( Str :: camelToHuman ( $ class_name ) , Base :: SEPARATOR ) : $ this -> taxonomy_key ; }
Get the taxonomy key
14,054
public function getOptionID ( $ term_id = null ) { return join ( '_' , array ( $ this -> getTaxonomyKey ( ) , ( $ term_id ) ? $ term_id : $ this -> get ( self :: ID ) ) ) ; }
Get the option ID
14,055
public function renderAdminColumn ( $ column_name , $ term_id ) { $ this -> load ( $ term_id ) ; parent :: renderAdminColumn ( $ column_name , $ term_id ) ; }
Render an admin column Note param order is flipped from parent
14,056
public function getEditPermalink ( $ object_type = null ) { if ( is_null ( $ object_type ) ) { $ object_type = $ this -> get ( 'object_id' ) ; if ( ! $ object_type ) { throw new \ Exception ( 'No object_type nor object_id' ) ; } } return get_edit_term_link ( $ this -> get ( 'term_id' ) , $ this -> getTaxonomyKey ( ) , $ object_type ) ; }
Get the edit permalink
14,057
public static function getWhere ( $ args = array ( ) ) { $ instance = Term \ Factory :: create ( get_called_class ( ) ) ; $ default_args = array ( 'orderby' => $ instance -> getDefaultOrderBy ( ) , 'order' => $ instance -> getDefaultOrder ( ) , 'hide_empty' => false , ) ; $ criteria = array_merge ( $ default_args , $ args ) ; $ orderby = null ; $ order = null ; $ wordpress_sortable_fields = array ( 'id' , 'name' , 'count' , 'slug' , 'term_group' , 'none' ) ; if ( array_key_exists ( 'orderby' , $ criteria ) && ! in_array ( $ criteria [ 'orderby' ] , $ wordpress_sortable_fields ) ) { $ orderby = $ criteria [ 'orderby' ] ; $ order = ( array_key_exists ( 'order' , $ criteria ) ) ? strtoupper ( $ criteria [ 'order' ] ) : 'ASC' ; unset ( $ criteria [ 'orderby' ] ) ; unset ( $ criteria [ 'order' ] ) ; } $ criteria [ 'taxonomy' ] = $ instance -> getTaxonomyKey ( ) ; $ terms = Term \ Factory :: createMultiple ( get_terms ( $ criteria ) ) ; if ( ! Arr :: iterable ( $ terms ) ) { return $ terms ; } if ( ! $ orderby ) { return $ terms ; } $ field = $ instance -> getField ( $ orderby ) ; if ( $ field [ 'type' ] === 'number' ) { foreach ( $ terms as & $ term ) { if ( ! isset ( $ term -> $ orderby ) ) { continue ; } if ( $ term -> $ orderby === '' ) { continue ; } $ term -> $ orderby = ( float ) $ term -> $ orderby ; } } $ sort_flag = ( $ field [ 'type' ] === 'number' ) ? SORT_NUMERIC : SORT_STRING ; $ terms = Collection :: sortBy ( $ terms , $ orderby , $ sort_flag ) ; if ( strtoupper ( $ order ) === 'DESC' ) { $ terms = array_reverse ( $ terms , true ) ; } if ( $ field [ 'type' ] === 'number' ) { foreach ( $ terms as & $ term ) { if ( ! isset ( $ term -> $ orderby ) ) { continue ; } if ( $ term -> $ orderby === '' ) { continue ; } $ term -> $ orderby = ( string ) $ term -> $ orderby ; } } return $ terms ; }
Get terms with conditions
14,058
public static function getOneWhere ( $ args = array ( ) ) { $ args [ 'number' ] = 1 ; $ result = static :: getWhere ( $ args ) ; return ( count ( $ result ) ) ? current ( $ result ) : null ; }
Get one term
14,059
public static function find ( $ term_id ) { $ instance = Post \ Factory :: create ( get_called_class ( ) ) ; $ instance -> load ( $ term_id ) ; return $ instance ; }
Find a term
14,060
public static function loadAll ( ) { global $ taxonomies_infos ; $ subclasses = self :: getSubclasses ( ) ; foreach ( $ subclasses as $ class ) { $ instance = new $ class ; $ taxonomies_infos = array_merge ( $ taxonomies_infos , $ instance -> getTaxonomiesInfo ( ) ) ; self :: load ( $ class ) ; } }
Load all the posts
14,061
public static function load ( $ class ) { $ instance = new $ class ; $ post_type = $ instance -> getPostType ( ) ; if ( strlen ( $ post_type ) > 20 ) { throw new \ Exception ( 'Post Type name exceeds maximum 20 characters: ' . $ post_type ) ; } if ( ! $ post_type ) { return false ; } $ instance -> registerPostType ( ) ; add_action ( 'save_post' , array ( $ instance , 'addSaveHooks' ) ) ; if ( is_admin ( ) ) { $ is_edit_screen = ( is_array ( $ _SERVER ) && preg_match ( '/post.php\?post=[\d]{1,}/i' , $ _SERVER [ 'REQUEST_URI' ] ) && ! Arr :: iterable ( $ _POST ) ) ; $ is_edit_save = ( preg_match ( '/post.php/i' , $ _SERVER [ 'REQUEST_URI' ] ) && Arr :: iterable ( $ _POST ) ) ; $ post = null ; if ( $ is_edit_screen && array_key_exists ( 'post' , $ _GET ) ) { $ post = get_post ( $ _GET [ 'post' ] ) ; } elseif ( $ is_edit_save ) { $ post = get_post ( $ _POST [ 'post_ID' ] ) ; } if ( $ post && $ post -> post_type === $ instance -> getPostType ( ) ) { $ instance -> load ( $ post ) ; } add_action ( 'admin_menu' , array ( $ instance , 'addMetaBoxes' ) ) ; add_action ( sprintf ( 'manage_%s_posts_columns' , $ post_type ) , array ( $ instance , 'addAdminColumns' ) , 10 , 2 ) ; add_action ( sprintf ( 'manage_%s_posts_custom_column' , $ post_type ) , array ( $ instance , 'renderAdminColumn' ) , 10 , 2 ) ; add_filter ( sprintf ( 'manage_edit-%s_sortable_columns' , $ post_type ) , array ( $ instance , 'makeAdminColumnsSortable' ) ) ; add_filter ( 'request' , array ( $ instance , 'sortAdminColumns' ) ) ; add_filter ( 'posts_clauses' , array ( $ instance , 'makeAdminTaxonomyColumnsSortable' ) , 10 , 2 ) ; $ is_browsing_index = ( is_array ( $ _SERVER ) && preg_match ( '/edit.php\?post_type=' . $ post_type . '$/i' , $ _SERVER [ 'REQUEST_URI' ] ) ) ; if ( $ is_browsing_index && $ instance -> getHideTitleFromAdminColumns ( ) ) { add_action ( 'admin_init' , function ( ) { wp_register_style ( 'hide_title_column_css' , plugins_url ( 'taco/base/hide_title_column.css' ) ) ; wp_enqueue_style ( 'hide_title_column_css' ) ; } ) ; } } }
Load a post type
14,062
public static function getSubclasses ( ) { $ subclasses = array ( ) ; foreach ( get_declared_classes ( ) as $ class ) { if ( method_exists ( $ class , 'isLoadable' ) && $ class :: isLoadable ( ) === false ) { continue ; } if ( is_subclass_of ( $ class , 'Taco\Post' ) ) { $ subclasses [ ] = $ class ; } } return $ subclasses ; }
Get all subclasses
14,063
public function calculate ( N \ LatLong $ point1 , N \ LatLong $ point2 ) { $ celestialBody = $ this -> getCelestialBody ( ) ; $ deltaLat = $ point2 -> getLatitude ( ) -> get ( ) - $ point1 -> getLatitude ( ) -> get ( ) ; $ deltaLong = $ point2 -> getLongitude ( ) -> get ( ) - $ point1 -> getLongitude ( ) -> get ( ) ; $ a = sin ( $ deltaLat / 2 ) * sin ( $ deltaLat / 2 ) + cos ( $ point1 -> getLatitude ( ) -> get ( ) ) * cos ( $ point2 -> getLatitude ( ) -> get ( ) ) * sin ( $ deltaLong / 2 ) * sin ( $ deltaLong / 2 ) ; $ c = 2 * atan2 ( sqrt ( $ a ) , sqrt ( 1 - $ a ) ) ; $ d = $ celestialBody -> volumetricMeanRadius * $ c * 1000 ; return $ d ; }
Calculate the distance between two points using the Haversine formula .
14,064
public function update ( $ params = [ ] ) { $ response = Guzzle :: put ( "tournaments/{$this->tournament_slug}/participants/{$this->id}" , $ params ) ; return $ this -> updateModel ( $ response -> participant ) ; }
Update the attributes of a tournament participant .
14,065
public function transform ( $ object ) { if ( ( $ collection = $ this -> normalize ( $ object ) ) instanceof Collection ) { return $ this -> transformCollection ( $ collection ) ; } if ( $ this -> relatedCount ) { return $ this -> transformWithRelated ( $ object ) ; } if ( is_callable ( $ this -> transformationMethod ) ) { return $ this -> getAlternateTransformation ( $ object ) ; } return $ this -> getTransformation ( $ object ) ; }
Transforms the object . Called recursively when transforming a collection or a relation .
14,066
protected function normalize ( $ object ) { if ( $ object instanceof Paginator ) { return collect ( $ object -> items ( ) ) ; } elseif ( is_array ( $ object ) ) { return collect ( $ object ) ; } return $ object ; }
Normalizes the object to a collection if it is some sort of a container to multiple items .
14,067
public function transformWithRelated ( $ item ) { $ transformedItem = $ this -> getTransformation ( $ item ) ; return $ this -> transformRelated ( $ transformedItem , $ item ) ; }
Transforms the item with its related models .
14,068
public function with ( $ relation ) { $ this -> reset ( ) ; if ( func_num_args ( ) > 1 ) { return $ this -> with ( func_get_args ( ) ) ; } if ( is_array ( $ relation ) ) { $ this -> related = array_merge ( $ this -> related , $ relation ) ; } else { $ this -> related [ ] = $ relation ; } $ this -> relatedCount = count ( $ this -> related ) ; return $ this ; }
Adds a relation to the transformer .
14,069
public function setTransformation ( $ transformation ) { if ( is_callable ( $ transformation ) ) { $ this -> transformationMethod = $ transformation ; return $ this ; } $ methodName = str_replace ( 'Transformation' , '' , $ transformation ) . "Transformation" ; if ( ! method_exists ( $ this , $ methodName ) ) { throw new TransformerException ( "No such transformation as $methodName defined." ) ; } $ this -> transformationMethod = [ $ this , $ methodName ] ; return $ this ; }
Sets the current transformation .
14,070
protected function transformRelated ( $ itemTransformation , $ item ) { foreach ( $ this -> related as $ relation ) { $ relationName = explode ( '.' , $ relation , 2 ) [ 0 ] ; $ itemTransformation [ $ relationName ] = $ this -> getRelatedTransformation ( $ item , $ relation ) ; } return $ itemTransformation ; }
Transforms the related item and adds it to the transformation array .
14,071
protected function getRelatedTransformation ( $ item , $ relation ) { $ nestedRelations = explode ( '.' , $ relation , 2 ) ; $ relation = $ nestedRelations [ 0 ] ; $ result = $ item -> { $ relation } ; $ related = $ result ; $ transformer = null ; if ( ! is_object ( $ related ) ) { return $ related ; } if ( $ related instanceof Collection ) { if ( $ related -> count ( ) ) { $ result = $ result [ 0 ] ; } else { return [ ] ; } } $ transformer = $ this -> resolveTransformer ( $ result ) ; if ( ! $ transformer ) { return $ related -> toArray ( ) ; } if ( count ( $ nestedRelations ) == 2 ) { $ transformer -> with ( $ nestedRelations [ 1 ] ) ; } return $ transformer -> transform ( $ related ) ; }
Resolves the transformation for the related model .
14,072
public function calculate ( N \ LatLong $ point1 , N \ LatLong $ point2 ) { $ celestialBody = $ this -> getCelestialBody ( ) ; $ degrees = acos ( sin ( $ point1 -> getLatitude ( ) -> get ( ) ) * sin ( $ point2 -> getLatitude ( ) -> get ( ) ) + cos ( $ point1 -> getLatitude ( ) -> get ( ) ) * cos ( $ point2 -> getLatitude ( ) -> get ( ) ) * cos ( $ point2 -> getLongitude ( ) -> get ( ) - $ point1 -> getLongitude ( ) -> get ( ) ) ) ; $ d = $ degrees * $ celestialBody -> volumetricMeanRadius ; return $ d * 1000 ; }
Calculate the distance between two points using the Great Circle formula .
14,073
public static function image ( $ sEmail , $ iSize = null , $ sDefaultImage = null , $ sRating = null , $ sExtension = null , $ bForceDefault = false ) { $ gravatarImage = ( new Image ( ) ) -> setEmail ( $ sEmail ) -> setSize ( $ iSize ) -> setDefaultImage ( $ sDefaultImage , $ bForceDefault ) -> setMaxRating ( $ sRating ) -> setExtension ( $ sExtension ) ; return $ gravatarImage ; }
Return the Gravatar image based on the provided email address .
14,074
public static function images ( array $ aEmail , $ iSize = null , $ sDefaultImage = null , $ sRating = null , $ sExtension = null , $ bForceDefault = false ) { $ aImages = [ ] ; foreach ( $ aEmail as $ sEmail ) { $ gravatarImage = ( new Image ( ) ) -> setEmail ( $ sEmail ) -> setSize ( $ iSize ) -> setDefaultImage ( $ sDefaultImage , $ bForceDefault ) -> setMaxRating ( $ sRating ) -> setExtension ( $ sExtension ) ; $ aImages [ $ sEmail ] = $ gravatarImage ; } return $ aImages ; }
Return multiples Gravatar images based on the provided array of emails addresses .
14,075
public static function profiles ( array $ aEmail , $ sFormat = null ) { $ aProfils = [ ] ; foreach ( $ aEmail as $ sEmail ) { $ gravatarProfil = ( new Profile ( ) ) -> setEmail ( $ sEmail ) -> setFormat ( $ sFormat ) ; $ aProfils [ $ sEmail ] = $ gravatarProfil ; } return $ aProfils ; }
Return multiples Gravatar profiles based on the provided array of emails addresses .
14,076
public function email ( $ sEmail = null ) { if ( null === $ sEmail ) { return $ this -> getEmail ( ) ; } return $ this -> setEmail ( $ sEmail ) ; }
Get or set the address email to be used .
14,077
public static function create ( $ post , $ load_terms = true ) { if ( is_string ( $ post ) && class_exists ( $ post ) ) { return new $ post ; } $ original_post = $ post ; if ( ! is_object ( $ post ) ) { $ post = get_post ( $ post ) ; } if ( ! is_object ( $ post ) ) { throw new \ Exception ( sprintf ( 'Post %s not found in the database' , json_encode ( $ original_post ) ) ) ; } $ class = str_replace ( ' ' , '' , ucwords ( str_replace ( Base :: SEPARATOR , ' ' , $ post -> post_type ) ) ) ; if ( ! class_exists ( $ class ) ) { $ class = str_replace ( ' ' , '\\' , ucwords ( str_replace ( Base :: SEPARATOR , ' ' , $ post -> post_type ) ) ) ; } $ instance = new $ class ; $ instance -> load ( $ post , $ load_terms ) ; return $ instance ; }
Create an instance based on a WP post This basically autoloads the meta data
14,078
public static function createMultiple ( $ posts , $ load_terms = true ) { if ( ! Arr :: iterable ( $ posts ) ) { return $ posts ; } $ out = array ( ) ; foreach ( $ posts as $ k => $ post ) { if ( ! get_post_status ( $ post ) ) { continue ; } $ record = self :: create ( $ post , $ load_terms ) ; $ out [ $ k ] = $ record ; } return $ out ; }
Create multiple instances based on WP posts This basically autoloads the meta data
14,079
public function draw ( Dm_Image $ image , $ x = 0 , $ y = 0 , $ width = null , $ height = null ) { $ srcImageResource = $ image -> getImageResource ( ) ; if ( is_null ( $ width ) ) $ width = $ image -> getWidth ( ) ; if ( is_null ( $ height ) ) $ height = $ image -> getHeight ( ) ; return imagecopy ( $ this -> getImageResource ( ) , $ srcImageResource , $ x , $ y , 0 , 0 , $ width , $ height ) ; }
Copy and merge part of an image
14,080
public function saveTo ( $ path , $ type = 'png' , $ quality = null ) { if ( ! $ path ) return false ; return $ this -> outputTo ( $ path , $ type , $ quality ) ; }
The path to save the file to .
14,081
public function destroy ( ) { imagedestroy ( $ this -> _imageResource ) ; $ this -> graphics -> destroy ( ) ; $ this -> graphics = null ; $ this -> textGraphics -> destroy ( ) ; $ this -> textGraphics = null ; }
Destroy an image .
14,082
public function toDataSchemeURI ( ) { $ md5 = md5 ( microtime ( 1 ) . rand ( 10000 , 99999 ) ) ; $ filePath = $ this -> tempDirPath ( ) . DIRECTORY_SEPARATOR . "temp" . $ md5 . ".png" ; $ this -> saveTo ( $ filePath ) ; $ uri = 'data:' . mime_content_type ( $ filePath ) . ';base64,' ; $ uri .= base64_encode ( file_get_contents ( $ filePath ) ) ; unlink ( $ filePath ) ; return $ uri ; }
Return data scheme URI .
14,083
public function serve ( $ salt = '' ) { $ protocol = isset ( $ _SERVER [ 'SERVER_PROTOCOL' ] ) ? $ _SERVER [ 'SERVER_PROTOCOL' ] : 'HTTP/1.0' ; if ( $ input = $ this -> findInput ( ) ) { $ output = $ this -> cacheName ( $ salt . $ input ) ; $ etag = $ noneMatch = trim ( $ this -> getIfNoneMatchHeader ( ) , '"' ) ; if ( $ this -> needsCompile ( $ output , $ etag ) ) { try { list ( $ css , $ etag ) = $ this -> compile ( $ input , $ output ) ; $ lastModified = gmdate ( 'D, d M Y H:i:s' , filemtime ( $ output ) ) . ' GMT' ; header ( 'Last-Modified: ' . $ lastModified ) ; header ( 'Content-type: text/css' ) ; header ( 'ETag: "' . $ etag . '"' ) ; echo $ css ; } catch ( \ Exception $ e ) { if ( $ this -> showErrorsAsCSS ) { header ( 'Content-type: text/css' ) ; echo $ this -> createErrorCSS ( $ e ) ; } else { header ( $ protocol . ' 500 Internal Server Error' ) ; header ( 'Content-type: text/plain' ) ; echo 'Parse error: ' . $ e -> getMessage ( ) . "\n" ; } } return ; } header ( 'X-SCSS-Cache: true' ) ; header ( 'Content-type: text/css' ) ; header ( 'ETag: "' . $ etag . '"' ) ; if ( $ etag === $ noneMatch ) { header ( $ protocol . ' 304 Not Modified' ) ; return ; } $ modifiedSince = $ this -> getIfModifiedSinceHeader ( ) ; $ mtime = filemtime ( $ output ) ; if ( strtotime ( $ modifiedSince ) === $ mtime ) { header ( $ protocol . ' 304 Not Modified' ) ; return ; } $ lastModified = gmdate ( 'D, d M Y H:i:s' , $ mtime ) . ' GMT' ; header ( 'Last-Modified: ' . $ lastModified ) ; echo file_get_contents ( $ output ) ; return ; } header ( $ protocol . ' 404 Not Found' ) ; header ( 'Content-type: text/plain' ) ; $ v = Version :: VERSION ; echo "/* INPUT NOT FOUND scss $v */\n" ; }
Compile requested scss and serve css . Outputs HTTP response .
14,084
public function getPrefixGroupedMetaBoxes ( ) { $ fields = $ this -> getFields ( ) ; $ groups = array ( ) ; foreach ( $ fields as $ k => $ field ) { $ prefix = current ( explode ( '_' , $ k ) ) ; if ( ! array_key_exists ( $ prefix , $ groups ) ) { $ groups [ $ prefix ] = array ( ) ; } $ groups [ $ prefix ] [ ] = $ k ; } return $ groups ; }
Get meta boxes grouped by prefix
14,085
public function replaceMetaBoxGroupMatches ( $ meta_boxes ) { if ( ! Arr :: iterable ( $ meta_boxes ) ) { return $ meta_boxes ; } foreach ( $ meta_boxes as $ k => $ group ) { $ group = ( is_array ( $ group ) ) ? $ group : array ( $ group ) ; if ( array_key_exists ( 'fields' , $ group ) ) { continue ; } $ fields = $ this -> getFields ( ) ; $ new_group = array ( ) ; foreach ( $ group as $ pattern_key => $ pattern ) { if ( ! preg_match ( '/\*$/' , $ pattern ) ) { $ new_group [ ] = $ pattern ; continue ; } $ prefix = preg_replace ( '/\*$/' , '' , $ pattern ) ; $ regex = sprintf ( '/^%s/' , $ prefix ) ; foreach ( $ fields as $ field_key => $ field ) { if ( ! preg_match ( $ regex , $ field_key ) ) { continue ; } $ new_group [ ] = $ field_key ; } } $ meta_boxes [ $ k ] = $ new_group ; } return $ meta_boxes ; }
Replace any meta box group matches
14,086
public function getMetaBoxConfig ( $ config , $ key = null ) { if ( ! array_key_exists ( 'fields' , $ config ) ) { $ fields = array ( ) ; foreach ( $ config as $ field ) { if ( preg_match ( '/^\</' , $ field ) && preg_match ( '/\>$/' , $ field ) ) { $ fields [ md5 ( mt_rand ( ) ) ] = array ( 'type' => 'html' , 'label' => null , 'value' => $ field , ) ; continue ; } $ fields [ $ field ] = $ this -> getField ( $ field ) ; } $ config = array ( 'fields' => $ fields ) ; } if ( Arr :: iterable ( $ config [ 'fields' ] ) ) { $ fields = array ( ) ; foreach ( $ config [ 'fields' ] as $ k => $ v ) { if ( is_array ( $ v ) ) { $ fields [ $ k ] = $ v ; } else { $ fields [ $ v ] = $ this -> getField ( $ v ) ; } } $ config [ 'fields' ] = $ fields ; } $ config [ 'title' ] = ( array_key_exists ( 'title' , $ config ) ) ? $ config [ 'title' ] : $ this -> getMetaBoxTitle ( $ key ) ; $ config [ 'context' ] = ( array_key_exists ( 'context' , $ config ) ) ? $ config [ 'context' ] : 'normal' ; $ config [ 'priority' ] = ( array_key_exists ( 'priority' , $ config ) ) ? $ config [ 'priority' ] : 'high' ; return $ config ; }
Get a meta box config handling defaults
14,087
public function assign ( $ vals ) { if ( count ( $ vals ) === 0 ) { return 0 ; } $ n = 0 ; foreach ( $ vals as $ k => $ v ) { if ( $ this -> set ( $ k , $ v ) ) { $ n ++ ; } } return $ n ; }
Set multiple fields
14,088
public function isValid ( $ vals ) { $ fields = $ this -> getFields ( ) ; if ( ! Arr :: iterable ( $ fields ) ) { return true ; } $ result = true ; foreach ( $ fields as $ k => $ field ) { if ( $ this -> isRequired ( $ field ) ) { if ( ! array_key_exists ( $ k , $ vals ) || is_null ( $ vals [ $ k ] ) || $ vals [ $ k ] === '' || $ vals [ $ k ] === false || ( $ field [ 'type' ] === 'checkbox' && empty ( $ vals [ $ k ] ) ) ) { $ result = false ; $ this -> _messages [ $ k ] = $ this -> getFieldRequiredMessage ( $ k ) ; continue ; } } if ( array_key_exists ( 'maxlength' , $ field ) ) { if ( strlen ( $ vals [ $ k ] ) > $ field [ 'maxlength' ] ) { $ result = false ; $ this -> _messages [ $ k ] = 'Value too long' ; continue ; } } if ( ! array_key_exists ( $ k , $ vals ) ) { continue ; } if ( ! array_key_exists ( 'type' , $ field ) ) { continue ; } if ( $ field [ 'type' ] === 'select' ) { if ( ! array_key_exists ( $ vals [ $ k ] , $ field [ 'options' ] ) ) { $ result = false ; $ this -> _messages [ $ k ] = 'Invalid option' ; } continue ; } if ( $ field [ 'type' ] === 'email' ) { if ( ! filter_var ( $ vals [ $ k ] , FILTER_VALIDATE_EMAIL ) ) { $ result = false ; $ this -> _messages [ $ k ] = 'Invalid email address' ; } continue ; } if ( $ field [ 'type' ] === 'url' ) { if ( ! filter_var ( $ vals [ $ k ] , FILTER_VALIDATE_URL ) ) { $ result = false ; $ this -> _messages [ $ k ] = 'Invalid URL' ; } continue ; } if ( $ field [ 'type' ] === 'color' ) { if ( ! preg_match ( '/^#[0-9a-f]{6}$/i' , $ vals [ $ k ] ) ) { $ result = false ; $ this -> _messages [ $ k ] = 'Invalid color' ; } continue ; } } return $ result ; }
Is this a valid entry?
14,089
public function getMetaBoxTitle ( $ key = null ) { return ( $ key ) ? Str :: human ( $ key ) : sprintf ( '%s' , $ this -> getSingular ( ) ) ; }
Get the meta box title
14,090
private static function scrubAttributes ( $ field , $ type = null ) { $ invalid_keys = [ 'default' , 'description' , 'label' , 'options' , ] ; if ( $ type && $ type === 'textarea' ) { $ invalid_keys [ ] = 'value' ; } foreach ( $ invalid_keys as $ invalid_key ) { if ( array_key_exists ( $ invalid_key , $ field ) ) { unset ( $ field [ $ invalid_key ] ) ; } } return $ field ; }
Remove invalid HTML attribute keys from field definition
14,091
public function getCheckboxDisplay ( $ column_name ) { $ displays = $ this -> getCheckboxDisplays ( ) ; if ( array_key_exists ( $ column_name , $ displays ) ) { return $ displays [ $ column_name ] ; } if ( array_key_exists ( 'default' , $ displays ) ) { return $ displays [ 'default' ] ; } return array ( 'Yes' , 'No' ) ; }
Get checkbox display for a specific admin column
14,092
public function renderAdminColumn ( $ column_name , $ item_id ) { $ columns = $ this -> getAdminColumns ( ) ; if ( ! in_array ( $ column_name , $ columns ) ) { return ; } $ field = $ this -> getField ( $ column_name ) ; if ( is_array ( $ field ) ) { $ class = get_called_class ( ) ; $ entry = new $ class ; $ entry -> load ( $ item_id ) ; $ out = $ entry -> get ( $ column_name ) ; if ( isset ( $ field [ 'type' ] ) ) { switch ( $ field [ 'type' ] ) { case 'checkbox' : $ checkbox_display = $ entry -> getCheckboxDisplay ( $ column_name ) ; $ out = ( $ entry -> get ( $ column_name ) ) ? reset ( $ checkbox_display ) : end ( $ checkbox_display ) ; break ; case 'image' : $ out = Html :: image ( $ entry -> get ( $ column_name ) , $ entry -> get ( $ column_name ) , array ( 'class' => 'thumbnail' ) ) ; break ; case 'select' : $ out = array_key_exists ( $ entry -> get ( $ column_name ) , $ field [ 'options' ] ) ? $ field [ 'options' ] [ $ entry -> get ( $ column_name ) ] : null ; break ; } } if ( method_exists ( $ this , 'getHideTitleFromAdminColumns' ) && $ this -> getHideTitleFromAdminColumns ( ) && method_exists ( $ this , 'getEditPermalink' ) && array_search ( $ column_name , array_values ( $ columns ) ) === 0 ) { $ out = sprintf ( '<a href="%s">%s</a>' , $ this -> getEditPermalink ( ) , $ out ) ; } echo $ out ; return ; } if ( Arr :: iterable ( $ this -> getTaxonomies ( ) ) ) { $ taxonomy_key = $ this -> getTaxonomyKey ( $ column_name ) ; if ( $ taxonomy_key ) { echo get_the_term_list ( $ item_id , $ taxonomy_key , null , ', ' ) ; return ; } } }
Render an admin column
14,093
public function makeAdminColumnsSortable ( $ columns ) { $ admin_columns = $ this -> getAdminColumns ( ) ; if ( ! Arr :: iterable ( $ admin_columns ) ) { return $ columns ; } foreach ( $ admin_columns as $ k ) { $ columns [ $ k ] = $ k ; } return $ columns ; }
Make the admin columns sortable
14,094
public function getPlural ( ) { $ singular = $ this -> getSingular ( ) ; if ( preg_match ( '/y$/' , $ singular ) ) { return preg_replace ( '/y$/' , 'ies' , $ singular ) ; } return ( is_null ( $ this -> plural ) ) ? Str :: human ( $ singular ) . 's' : $ this -> plural ; }
Get the plural name
14,095
public function getThe ( $ key , $ convert_value = false , $ return_wrapped = true ) { if ( $ return_wrapped ) { return apply_filters ( 'the_content' , $ this -> get ( $ key , $ convert_value ) ) ; } remove_filter ( 'the_content' , 'wpautop' ) ; $ value = apply_filters ( 'the_content' , $ this -> get ( $ key , $ convert_value ) ) ; add_filter ( 'the_content' , 'wpautop' ) ; return $ value ; }
Get any value run through the_content filter
14,096
public function getLabelText ( $ field_key ) { $ field = $ this -> getField ( $ field_key ) ; if ( ! is_array ( $ field ) ) { return null ; } return ( array_key_exists ( 'label' , $ field ) ) ? $ field [ 'label' ] : Str :: human ( str_replace ( '-' , ' ' , preg_replace ( '/_id$/i' , '' , $ field_key ) ) ) ; }
Get the label text for a field
14,097
public function getRenderLabel ( $ field_key , $ required_mark = ' <span class="required">*</span>' ) { return sprintf ( '<label for="%s">%s%s</label>' , $ field_key , $ this -> getLabelText ( $ field_key ) , ( $ required_mark && $ this -> isRequired ( $ field_key ) ) ? $ required_mark : null ) ; }
Get the label HTML for a field
14,098
public function isRequired ( $ field_key ) { $ field = ( is_array ( $ field_key ) ) ? $ field_key : $ this -> getField ( $ field_key ) ; return ( is_array ( $ field ) && array_key_exists ( 'required' , $ field ) && $ field [ 'required' ] ) ; }
Is the field required?
14,099
public function parse ( $ coord ) { $ coordinate = null ; $ matches = array ( ) ; preg_match ( $ this -> input_format , $ coord , $ matches ) ; if ( count ( $ matches ) == 5 ) { $ degrees = $ matches [ 1 ] ; $ minutes = $ matches [ 2 ] * ( 1 / 60 ) ; $ seconds = $ matches [ 3 ] * ( 1 / 60 * 1 / 60 ) ; $ coordinate = '' ; if ( isset ( $ matches [ 4 ] ) ) { if ( $ matches [ 4 ] == 'S' or $ matches [ 4 ] == 'W' ) { $ coordinate = '-' ; } } $ coordinate .= $ degrees + $ minutes + $ seconds ; } if ( is_numeric ( $ coordinate ) ) { return deg2rad ( ( float ) $ coordinate ) ; } throw new E \ InvalidCoordinateFormatException ( 'The format of "' . $ coord . '" cannot be parsed' ) ; }
Used when setting a value in the Coordinate class .