idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
20,200
public function getAllMembers ( ) { $ this -> roadMap ; $ this -> resources ; $ result = array ( ) ; foreach ( $ this -> roadMap as $ road ) { $ result [ $ road -> getMemberId ( ) ] = $ road ; } foreach ( $ this -> resources as $ resource ) { $ result [ $ resource -> getMemberId ( ) ] = $ resource ; } return $ result ; }
Get all the Member Elements such as SourceRoad annotation and resources .
20,201
public function registerResource ( AbstractResourceFile $ resource ) { if ( ! isset ( $ this -> resources [ md5 ( $ resource -> getRealPath ( ) ) ] ) ) { $ this -> resources [ md5 ( $ resource -> getRealPath ( ) ) ] = $ resource ; } }
Register a resource to this project .
20,202
public function getResourceByFile ( File $ file ) { if ( isset ( $ this -> resources [ md5 ( $ file -> getAbsolutePath ( ) ) ] ) ) { return $ this -> resources [ md5 ( $ file -> getAbsolutePath ( ) ) ] ; } else { return null ; } }
Get the target resource via the given file object or return null if not registered .
20,203
public function getOn ( string $ name , $ default = "" ) { $ event = new RenderGetOnEvent ( $ name , $ this -> getPath ( $ name , $ default ) ) ; EventManager :: dispatch ( $ event ) ; return $ event -> getParam ( "value" ) ; }
Use RenderGetOnEvent event before return item value
20,204
public function fillChoice ( array $ keys , $ default = "" ) { foreach ( $ keys as $ key ) { if ( $ this -> isFill ( $ key ) ) { return $ this -> items [ $ key ] ; } } return $ default ; }
Get an item from the collection by keys if value not empty .
20,205
public function toArray ( ) { return array ( 'id' => $ this -> getId ( ) , 'titulo' => $ this -> getTitulo ( ) , 'imagem' => $ this -> getImagem ( ) , 'descricao' => $ this -> getDescricao ( ) , 'preco' => $ this -> getPreco ( ) ) ; }
Obtem a estrutura da entity Produto em formato array
20,206
private function getNeighbor ( Date $ slugDate , $ direction = 'next' ) { if ( strcasecmp ( $ direction , 'next' ) == 0 ) { $ activeDate = 'ActiveDate.after' ; $ orderBy = 'ActiveDate ASC' ; $ slugDate = $ slugDate -> modify ( '+1 minute' ) ; } else { $ activeDate = 'ActiveDate.before' ; $ orderBy = 'ActiveDate DESC' ; $ slugDate = $ slugDate -> modify ( '-1 minute' ) ; } $ nq = new NodeQuery ( ) ; $ this -> passthruTemplateVariable ( $ nq , 'Elements.in' ) ; $ this -> passthruTemplateVariable ( $ nq , 'OutTags.exist' ) ; $ this -> passthruTemplateVariable ( $ nq , 'Meta.select' ) ; $ this -> passthruTemplateVariable ( $ nq , 'OutTags.select' ) ; $ this -> passthruTemplateVariable ( $ nq , 'InTags.select' ) ; $ this -> setMetaWhereParams ( $ nq ) ; $ nq -> setParameter ( $ activeDate , $ slugDate ) ; $ nq -> setParameter ( 'Status.isActive' , true ) ; $ nq -> setLimit ( 1 ) ; $ nq -> isRetrieveTotalRecords ( false ) ; $ nq -> setOrderBy ( $ orderBy ) ; return $ this -> RegulatedNodeService -> findAll ( $ nq ) -> getResults ( ) ; }
gets a single neighboring item
20,207
protected function executeCommand ( $ command ) { $ process = new Process ( $ command ) ; $ process -> run ( ) ; return array ( $ process -> getExitCode ( ) , $ process -> getOutput ( ) , $ process -> getErrorOutput ( ) , ) ; }
Executes the given command via shell and returns the complete output as a string
20,208
public function onRequestError ( Event $ event ) { if ( in_array ( $ event [ 'response' ] -> getStatusCode ( ) , array ( 401 , 403 ) ) ) { $ request = $ event [ 'request' ] ; if ( $ request -> getUrl ( ) === $ request -> getClient ( ) -> getTokenUrl ( ) ) { return ; } if ( $ request -> hasHeader ( 'X-Auth-Retries' ) ) { $ headerValues = $ request -> getHeader ( 'X-Auth-Retries' ) -> toArray ( ) ; $ retriesValue = array_shift ( $ headerValues ) ; } $ retries = $ request -> hasHeader ( 'X-Auth-Retries' ) ? $ retriesValue : 1 ; if ( $ retries < 1 ) { if ( $ this -> logger ) { $ this -> logger -> addError ( 'Keystone request failed, no more retries left' ) ; } return ; } if ( $ this -> logger ) { $ this -> logger -> addDebug ( 'Token expired, fetching a new one' ) ; } $ client = $ request -> getClient ( ) ; $ this -> resetToken ( $ client ) ; $ newRequest = clone $ request ; $ newRequest -> setHeader ( 'X-Auth-Token' , $ client -> getToken ( ) -> getId ( ) ) ; $ newRequest -> setHeader ( 'X-Auth-Retries' , -- $ retries ) ; $ newResponse = $ newRequest -> send ( ) ; $ event [ 'response' ] = $ newResponse ; $ event -> stopPropagation ( ) ; } }
Listener for request errors . Handles requests with expired authentication by reauthenticating and sending the request again .
20,209
public function apply ( array $ params ) { $ tags = [ ] ; foreach ( $ params as $ key => $ value ) { $ tags [ '/{' . $ key . '}/' ] = $ value ; } return preg_replace ( array_keys ( $ tags ) , array_values ( $ tags ) , $ this -> getConfig ( 'template' ) ) ; }
Apply a data set to the template .
20,210
public function get ( $ identifier = null , $ fallback = null ) { return $ this -> arrayGet ( self :: $ _data , '_session_class._standard.' . $ this -> section . ( $ identifier !== null ? '.' . $ identifier : '' ) , $ fallback ) ; }
Retrieves session data saved with a given identifier .
20,211
public function set ( $ identifier , $ value ) { $ this -> arraySet ( self :: $ _data , '_session_class._standard.' . $ this -> section . '.' . $ identifier , $ value ) ; }
Sets session data with a given identifier .
20,212
public function getFlash ( $ identifier = null , $ fallback = null ) { $ value = $ this -> arrayGet ( self :: $ _data , '_session_class._flash.' . $ this -> section . ( $ identifier !== null ? '.' . $ identifier : '' ) , $ fallback ) ; if ( $ value !== null ) { $ this -> arrayDelete ( self :: $ _data , '_session_class._flash.' . $ this -> section . ( $ identifier !== null ? '.' . $ identifier : '' ) ) ; } return $ value ; }
Retrieves session data saved with a given identifier and removes the data from the session .
20,213
public function delete ( $ identifier = null ) { if ( $ this -> get ( $ identifier ) === null ) return ; $ this -> arrayDelete ( self :: $ _data , '_session_class._standard.' . $ this -> section . ( $ identifier !== null ? '.' . $ identifier : '' ) ) ; }
Deletes session data .
20,214
public function sessionhandler_gc ( $ maxlifetime ) { $ files = scandir ( $ this -> save_path ) ; foreach ( $ files as $ file ) { if ( $ file { 0 } === '.' ) continue ; if ( filemtime ( $ this -> save_path . $ file ) < time ( ) - $ maxlifetime ) { unlink ( $ this -> save_path . $ file ) ; } } return true ; }
Cleanup old sessions .
20,215
public function renderPaymentView ( $ viewTemplate = null ) { $ formType = $ this -> formFactory -> create ( 'paymill_view' ) ; $ this -> environment -> display ( $ viewTemplate ? : $ this -> viewTemplate , array ( 'paymill_form' => $ formType -> createView ( ) , ) ) ; }
Render paymill form view
20,216
public function renderPaymentScripts ( ) { $ this -> environment -> display ( $ this -> scriptsTemplate , array ( 'public_key' => $ this -> publicKey , 'currency' => $ this -> paymentBridgeInterface -> getCurrency ( ) , ) ) ; }
Render paymill scripts view
20,217
public function toArray ( ) { $ data = [ 'text' => $ this -> getText ( ) , ] ; if ( $ this -> getTitle ( ) ) $ data [ 'title' ] = $ this -> getTitle ( ) ; if ( $ this -> getTitle ( ) ) $ data [ 'ok_text' ] = $ this -> getOkText ( ) ; if ( $ this -> getTitle ( ) ) $ data [ 'dismiss_text' ] = $ this -> getDismissText ( ) ; return $ data ; }
Get the array representation of this confirm
20,218
public function getLocale ( ) { $ auth = $ this -> getView ( ) -> authentication ( ) ; if ( $ auth -> hasIdentity ( ) ) { $ locale = $ auth -> getIdentity ( ) -> locale ; } else { $ locale = Locale :: getDefault ( ) ; } return $ locale ; }
Get user - locale
20,219
public static function parse ( string $ data ) : self { $ separator = strpos ( $ data , "\r\n\r\n" ) ; if ( $ separator === false ) { throw new FormatException ( 'Invalid article format' ) ; } $ headers = HeaderBag :: parse ( substr ( $ data , 0 , $ separator + 2 ) ) ; $ body = substr ( $ data , $ separator + 4 ) ; return new self ( $ body , $ headers ) ; }
Parses an article from a string .
20,220
public static function format ( string $ value ) { $ value = explode ( ',' , $ value ) ; if ( ! is_array ( $ value ) ) { $ value = [ $ value ] ; } return $ value ; }
Convert header string value to array
20,221
public function handle ( $ request , HandlerInterface $ next ) { if ( $ this -> isEmpty ( ) ) { return $ request ; } if ( $ this -> shadow == false ) { $ bundle = clone $ this ; $ bundle -> store -> setIteratorMode ( SplDoublyLinkedList :: IT_MODE_FIFO | SplDoublyLinkedList :: IT_MODE_DELETE ) ; $ this -> shadow = true ; return $ next -> handle ( $ request , $ bundle ) ; } $ handler = $ this -> frontPop ( ) ; return $ handler -> handle ( $ request , $ this ) ; }
Process a request using all stored handlers .
20,222
public function reverse ( ) { $ length = count ( $ this -> store ) ; for ( $ i = 0 ; $ i < $ length ; ++ $ i ) { $ this -> store -> unshift ( $ this -> store -> pop ( ) ) ; } }
Reverse handlers .
20,223
public static function normalize ( Config $ config ) { self :: normalizeFunctions ( $ config ) ; self :: normalizeTime ( $ config ) ; self :: normalizeArrays ( $ config ) ; self :: normalizeStreams ( $ config ) ; }
Normalizes a config
20,224
public function readInteractions ( $ file ) { return array_map ( function ( array $ interaction ) { return new Interaction ( $ this -> messageHandler -> convertFromRequest ( new SimplifiedRequest ( $ interaction [ 'request' ] [ 'method' ] , $ interaction [ 'request' ] [ 'path' ] , $ this -> mapHeaders ( $ interaction [ 'request' ] [ 'headers' ] ) , $ interaction [ 'request' ] [ 'content' ] ) ) , $ this -> messageHandler -> convertFromResponse ( new SimplifiedResponse ( $ interaction [ 'request' ] [ 'path' ] , $ interaction [ 'response' ] [ 'code' ] , $ this -> mapHeaders ( $ interaction [ 'response' ] [ 'headers' ] ) , $ interaction [ 'response' ] [ 'content' ] ) ) ) ; } , $ this -> decoder -> decode ( file_get_contents ( $ file ) ) ) ; }
Read interactions l
20,225
private function setValue ( $ item ) : void { if ( is_string ( $ item ) ) { return ; } $ element = $ item -> getElement ( ) ; $ name = $ element -> name ( ) ; if ( $ element instanceof File ) { if ( array_key_exists ( $ name , $ _FILES ) ) { $ element -> setValue ( $ _FILES [ $ name ] ) ; $ element -> valueSuppliedByUser ( true ) ; } } elseif ( array_key_exists ( $ name , $ _POST ) ) { if ( $ element instanceof Radio ) { if ( $ _POST [ $ name ] == $ element -> getValue ( ) || ( is_array ( $ _POST [ $ name ] ) && in_array ( $ element -> getValue ( ) , $ _POST [ $ name ] ) ) ) { $ element -> check ( ) ; } else { $ element -> check ( false ) ; } } else { $ element -> setValue ( $ _POST [ $ name ] ) ; } $ element -> valueSuppliedByUser ( true ) ; } elseif ( $ element instanceof Radio ) { $ element -> check ( false ) ; } }
Internal helper method to set the value of whatever we are dealing with .
20,226
public function setOptions ( $ url , $ query , $ port ) { curl_setopt_array ( $ this -> handle , [ CURLOPT_URL => $ url , CURLOPT_POST => true , CURLOPT_PORT => $ port , CURLOPT_POSTFIELDS => $ query , CURLOPT_RETURNTRANSFER => true , CURLOPT_SSL_VERIFYPEER => false , CURLOPT_FRESH_CONNECT => true ] ) ; }
Sets the Curl options
20,227
public function addAccountEntry ( $ name , array $ options ) { $ this -> accountEntries [ $ name ] = $ this -> optionResolver -> resolve ( $ options ) ; }
Adds the entry to he account menu .
20,228
public function createAccountMenu ( ) { $ menu = $ this -> factory -> createItem ( 'root' ) ; uasort ( $ this -> accountEntries , function ( $ a , $ b ) { if ( $ a [ 'position' ] == $ b [ 'position' ] ) { return 0 ; } return $ a [ 'position' ] < $ b [ 'position' ] ? - 1 : 1 ; } ) ; foreach ( $ this -> accountEntries as $ name => $ options ) { $ menu -> addChild ( $ name , $ options ) ; } return $ menu ; }
Creates the account menu .
20,229
public function createUserMenu ( ) { $ menu = $ this -> factory -> createItem ( 'root' ) ; if ( $ this -> accountEnabled ) { if ( null !== $ token = $ this -> tokenStorage -> getToken ( ) ) { if ( $ this -> authorization -> isGranted ( 'IS_AUTHENTICATED_FULLY' ) || $ this -> authorization -> isGranted ( 'IS_AUTHENTICATED_REMEMBERED' ) ) { $ user = $ token -> getUser ( ) ; $ item = $ menu -> addChild ( $ user -> getEmail ( ) , [ 'uri' => '#' ] ) ; $ item -> addChild ( 'ekyna_user.account.menu.my_profile' , [ 'route' => 'fos_user_profile_show' ] ) ; if ( $ this -> authorization -> isGranted ( 'ROLE_ADMIN' ) ) { $ item -> addChild ( 'ekyna_user.account.menu.backend' , [ 'route' => 'ekyna_admin' ] ) ; } $ item -> addChild ( 'ekyna_user.account.menu.logout' , [ 'route' => 'fos_user_security_logout' ] ) ; return $ menu ; } } $ menu -> addChild ( 'ekyna_user.account.menu.login' , [ 'route' => 'fos_user_security_login' ] ) ; } return $ menu ; }
Creates the user menu .
20,230
private function initializeConfig ( ) { if ( empty ( $ this -> config [ 'url' ] ) ) { $ this -> config [ 'url' ] = static :: $ url ; } $ this -> config [ 'url' ] = rtrim ( $ this -> config [ 'url' ] , '/' ) ; if ( filter_var ( $ this -> config [ 'url' ] , FILTER_VALIDATE_URL ) === false ) { throw new InvalidConfigException ( 'You must provide a valid URL in the config.' ) ; } }
Setup the config if one hasn t been provided .
20,231
public function push ( $ event , $ channel = 'public' , array $ payload = [ ] ) { $ payload = $ this -> preparePayload ( $ payload ) ; $ this -> validateEvent ( $ event ) ; $ channels = $ this -> validateChannel ( $ channel ) ; $ url = $ this -> getURL ( ) ; $ headers = [ 'body' => [ 'private' => $ this -> privateKey , 'channels' => $ channels , 'event' => $ event , 'payload' => $ payload ] ] ; $ response = $ this -> processRequest ( $ url , $ headers ) ; return $ response ; }
Push an event to Pushman the most used command .
20,232
private function validateChannel ( $ channels = [ ] , $ returnAsArray = true ) { if ( $ returnAsArray ) { if ( is_string ( $ channels ) ) { $ channels = [ $ channels ] ; } if ( empty ( $ channels ) ) { return [ 'public' ] ; } foreach ( $ channels as $ channel ) { if ( strpos ( $ channel , ' ' ) !== false ) { throw new InvalidChannelException ( 'No spaces are allowed in channel names.' ) ; } } return json_encode ( $ channels ) ; } else { if ( empty ( $ channels ) ) { return 'public' ; } if ( strpos ( $ channels , ' ' ) !== false ) { throw new InvalidChannelException ( 'No spaces are allowed in channel names.' ) ; } return $ channels ; } }
Validate a channel or set of channels return JSON if appropriate .
20,233
private function getURL ( $ endpoint = null ) { if ( is_null ( $ endpoint ) ) { $ endpoint = $ this -> getEndpoint ( ) ; } else { $ endpoint = '/api/' . $ endpoint ; } return $ this -> config [ 'url' ] . $ endpoint ; }
Get the URL of our Pushman instance . Defaults to the live site Push command .
20,234
private function processRequest ( $ url , $ headers , $ method = 'post' ) { if ( array_key_exists ( 'body' , $ headers ) ) { $ headers [ 'body' ] = json_encode ( $ headers [ 'body' ] ) ; } if ( $ method == 'post' ) { $ response = $ this -> guzzle -> request ( 'POST' , $ url , $ headers ) ; } elseif ( $ method == 'delete' ) { $ response = $ this -> guzzle -> request ( 'DELETE' , $ url , $ headers ) ; } else { $ params = $ this -> processGetParams ( $ headers ) ; $ response = $ this -> guzzle -> request ( 'GET' , $ url . $ params ) ; } $ response = $ this -> processResponse ( $ response ) ; return $ response ; }
Process a request and return the handled response .
20,235
private function processGetParams ( $ headers ) { $ paramStrings = [ ] ; foreach ( $ headers [ 'body' ] as $ key => $ value ) { $ paramStrings [ ] = $ key . "=" . $ value ; } $ paramString = "?" ; $ paramString .= implode ( "&" , $ paramStrings ) ; return $ paramString ; }
If we are doing a GET request turn it into URL params .
20,236
private function processResponse ( Response $ response ) { $ response = $ response -> getBody ( ) -> getContents ( ) ; $ response = json_decode ( $ response , true ) ; return $ response ; }
Process a repsonse get the JSON and output the decoded values .
20,237
public function channel ( $ channel ) { $ channel = $ this -> validateChannel ( $ channel , false ) ; $ url = $ this -> getURL ( 'channel' ) ; $ headers = [ 'body' => [ 'private' => $ this -> privateKey , 'channel' => $ channel ] ] ; $ response = $ this -> processRequest ( $ url , $ headers , 'get' ) ; return $ response ; }
Get information on a single channel .
20,238
public function channels ( ) { $ url = $ this -> getURL ( 'channels' ) ; $ headers = [ 'body' => [ 'private' => $ this -> privateKey ] ] ; $ response = $ this -> processRequest ( $ url , $ headers , 'get' ) ; return $ response ; }
Get an array of channels in the site .
20,239
public function buildChannel ( $ channel , $ max = 3 , $ refreshes = 'no' ) { $ channels = $ this -> validateChannel ( $ channel ) ; $ url = $ this -> getURL ( 'channel' ) ; $ headers = [ 'body' => [ 'private' => $ this -> privateKey , 'channel' => $ channels , 'max' => $ max , 'refreshes' => $ refreshes ] ] ; $ response = $ this -> processRequest ( $ url , $ headers , 'post' ) ; return $ response ; }
Build a new channel or set of channels .
20,240
public function destroyChannel ( $ channel ) { $ channels = $ this -> validateChannel ( $ channel ) ; $ arrayOfChannels = json_decode ( $ channels , true ) ; if ( in_array ( 'public' , $ arrayOfChannels ) ) { throw new InvalidDeleteRequestException ( 'You cannot delete the public channel.' ) ; } $ url = $ this -> getURL ( 'channel' ) ; $ headers = [ 'body' => [ 'private' => $ this -> privateKey , 'channel' => $ channels ] ] ; $ response = $ this -> processRequest ( $ url , $ headers , 'delete' ) ; return $ response ; }
Destroy a channel or set of channels .
20,241
public function send ( ) { if ( $ this -> sent ( ) ) { throw new Exceptions \ HeadersAlreadySentException ( "Headers already sent" ) ; } $ this -> sent = true ; foreach ( $ this as $ header ) { $ header -> send ( ) ; } return $ this ; }
Send the headers
20,242
public function setVector ( $ vector ) { try { $ this -> blockCipher -> setSalt ( $ vector ) ; } catch ( CryptException \ InvalidArgumentException $ e ) { throw new Exception \ InvalidArgumentException ( $ e -> getMessage ( ) ) ; } $ this -> encryption [ 'vector' ] = $ vector ; return $ this ; }
Set the inizialization vector
20,243
public function setKey ( $ key ) { try { $ this -> blockCipher -> setKey ( $ key ) ; } catch ( CryptException \ InvalidArgumentException $ e ) { throw new Exception \ InvalidArgumentException ( $ e -> getMessage ( ) ) ; } $ this -> encryption [ 'key' ] = $ key ; return $ this ; }
Set the encryption key
20,244
public function setCompression ( $ compression ) { if ( is_string ( $ this -> compression ) ) { $ compression = [ 'adapter' => $ compression ] ; } $ this -> compression = $ compression ; return $ this ; }
Sets an internal compression for values to encrypt
20,245
public function toArray ( ) { $ target = $ this -> getTarget ( ) ; if ( empty ( $ target ) ) throw new \ Exception ( 'The target is not defined' ) ; $ map = [ ] ; foreach ( $ this -> services as $ service ) { $ map = array_merge ( $ map , $ service -> toArray ( ) ) ; } return $ this -> formatRespond ( $ map ) ; }
Return the service map as an associative array .
20,246
protected function formatRespond ( $ map ) { $ envelope = \ App :: make ( 'Greplab\Jsonrpcsmd\Envelope\\' . $ this -> envelope , array ( $ this ) ) ; return $ envelope -> build ( $ map ) ; }
Format the response including the map .
20,247
public function format ( FormatInterface $ format ) : string { $ template = $ format -> getTemplate ( ) ; $ replacements = $ format -> getReplacements ( ) ; return $ this -> parse ( $ template , $ replacements ) ; }
Devuelve un dumper parseado
20,248
public function decorate ( Token $ token ) : string { $ style = $ token -> style ( ) ; $ value = $ token -> value ( ) ; foreach ( $ this -> decorators as $ decorator ) { $ value = $ decorator -> decorate ( $ style , $ value ) ; } return $ value ; }
Devuelve un token parseado
20,249
public function set ( $ key , $ value = null ) { if ( ( $ default = Hash :: extract ( $ this -> _defaults , $ key ) ) !== null ) { if ( is_float ( $ default ) ) { $ value = ( float ) $ value ; } else if ( is_numeric ( $ default ) ) { $ value = ( int ) $ value ; } else if ( is_bool ( $ default ) ) { $ value = ( bool ) $ value ; } else if ( is_string ( $ default ) ) { $ value = ( string ) $ value ; } else if ( is_array ( $ default ) ) { $ value = ( array ) $ value ; } } $ this -> _data = Hash :: insert ( $ this -> _data , $ key , $ value ) ; return $ this ; }
Set a configuration by key . Autobox the value if a default exists .
20,250
private function _parseComponent ( $ components ) { $ address = new GeoAddress ( ) ; $ address -> geoCoding = $ this -> name ; if ( array_key_exists ( 'address' , $ components ) ) { $ addressData = $ components [ 'address' ] ; $ address -> addressLine1 = array_key_exists ( 'addressLine' , $ addressData ) ? $ addressData [ 'addressLine' ] : "" ; $ address -> state = array_key_exists ( 'adminDistrict' , $ addressData ) ? $ addressData [ 'adminDistrict' ] : "" ; $ address -> country = array_key_exists ( 'countryRegion' , $ addressData ) ? $ addressData [ 'countryRegion' ] : "" ; if ( array_key_exists ( 'formattedAddress' , $ addressData ) ) { $ address -> formattedAddress = $ addressData [ 'formattedAddress' ] . ', ' . $ address -> country ; } $ address -> suburb = array_key_exists ( 'locality' , $ addressData ) ? $ addressData [ 'locality' ] : "" ; $ address -> postcode = array_key_exists ( 'postalCode' , $ addressData ) ? $ addressData [ 'postalCode' ] : "" ; } if ( array_key_exists ( 'confidence' , $ components ) ) { $ address -> partial = $ components [ 'confidence' ] != 'High' ; } if ( array_key_exists ( 'point' , $ components ) ) { $ address -> latitude = strval ( $ components [ 'point' ] [ 'coordinates' ] [ 0 ] ) ; $ address -> longitude = strval ( $ components [ 'point' ] [ 'coordinates' ] [ 1 ] ) ; } return $ address ; }
This function use to parse the return components from google bing api
20,251
public function getTrace ( ) : Trace { if ( $ this -> trace !== null ) { return $ this -> trace ; } return $ this -> trace = new Trace ( $ this -> getFrames ( ) ) ; }
Returns a Trace instance representing the stack trace of the inspected Throwable .
20,252
protected function getFrames ( ) : array { $ frames = $ this -> throwable -> getTrace ( ) ; if ( ! $ this -> throwable instanceof \ ErrorException ) { array_unshift ( $ frames , diagnostics \ Debug :: throwableToArray ( $ this -> throwable ) ) ; return $ frames ; } $ fatal = false ; switch ( $ this -> throwable -> getSeverity ( ) ) { case E_ERROR : case E_CORE_ERROR : case E_COMPILE_ERROR : case E_USER_ERROR : case E_RECOVERABLE_ERROR : case E_PARSE : $ fatal = true ; break ; } if ( ! $ fatal || ! extension_loaded ( 'xdebug' ) || ! xdebug_is_enabled ( ) ) { array_shift ( $ frames ) ; return $ frames ; } $ frames = array_diff_key ( array_reverse ( xdebug_get_function_stack ( ) ) , debug_backtrace ( DEBUG_BACKTRACE_IGNORE_ARGS ) ) ; foreach ( $ frames as & $ frame ) { if ( 'dynamic' === $ frame [ 'type' ] ) { $ frame [ 'type' ] = '->' ; } elseif ( 'static' === $ frame [ 'type' ] ) { $ frame [ 'type' ] = '::' ; } if ( isset ( $ frame [ 'params' ] ) && ! isset ( $ frame [ 'args' ] ) ) { $ frame [ 'args' ] = $ frame [ 'params' ] ; unset ( $ frame [ 'params' ] ) ; } } return $ frames ; }
Returns the traced frames from the inspected Throwable ..
20,253
public static function get_all_collection_meta ( $ lead_post ) { $ title = self :: get_collection_title ( $ lead_post -> post_type ) ; $ tags = [ [ 'name' => 'description' , 'content' => Post :: get_post_meta_description ( $ lead_post ) ] , [ 'property' => 'og:locale' , 'content' => get_locale ( ) ] , [ 'property' => 'og:type' , 'content' => 'summary' ] , [ 'property' => 'og:title' , 'content' => $ title ] , [ 'property' => 'og:description' , 'content' => Post :: get_post_og_description ( $ lead_post ) ] , [ 'property' => 'og:url' , 'content' => get_permalink ( $ lead_post -> ID ) ] , [ 'property' => 'og:site_name' , 'content' => get_bloginfo ( 'title' ) ] , [ 'name' => 'twitter:card' , 'content' => 'summary' ] , [ 'name' => 'twitter:title' , 'content' => $ title ] , [ 'name' => 'twitter:description' , 'content' => Post :: get_post_twitter_description ( $ lead_post ) ] , ] ; $ tags = array_merge ( $ tags , Site :: webmaster_tools ( ) ) ; return [ 'title' => $ title , 'tags' => $ tags , ] ; }
Get all metadata for a collection .
20,254
public static function get_collection_title ( $ post_type ) { $ post_type_name = 'Blog' ; if ( 'post' !== $ post_type ) { $ type = get_post_type_object ( $ post_type ) ; $ post_type_name = $ type -> labels -> name ; } $ filter_name = sprintf ( self :: TITLE_FILTER , is_string ( $ post_type ) ? $ post_type : $ post_type_name ) ; $ collection_title = sprintf ( '%s - %s' , $ post_type_name , get_bloginfo ( 'title' ) ) ; return apply_filters ( $ filter_name , $ collection_title ) ; }
Get the title for a collection .
20,255
public static function create ( array $ attributes = [ ] ) { $ user = new static ( $ attributes ) ; $ user -> setPassword ( $ attributes [ 'password' ] ) ; $ user -> save ( ) ; return $ user ; }
Static constructor for User
20,256
protected function getPrefixes ( ) { $ prefixes = $ this -> options [ 'prefixes' ] ; if ( $ prefixes ) { return $ prefixes ; } return self :: $ standardizedPrefixes [ $ this -> getMode ( ) ] ; }
Get the predefined prefixes or use the build - in standardized lists of prefixes .
20,257
protected function getPrefixAt ( $ index ) { $ prefixes = $ this -> getPrefixes ( ) ; return isset ( $ prefixes [ $ index ] ) ? $ prefixes [ $ index ] : null ; }
Find the prefix at a specific location in the prefixes array .
20,258
public function replaceMedia ( $ postId ) { if ( empty ( $ _POST [ 'media-replacer-replace-with' ] ) || ! is_numeric ( $ _POST [ 'media-replacer-replace-with' ] ) ) { return ; } $ uploadDir = wp_upload_dir ( ) ; $ filename = $ uploadDir [ 'basedir' ] . '/' . get_post_meta ( $ postId , '_wp_attached_file' , true ) ; $ file = pathinfo ( $ filename ) ; $ replacementFile = $ uploadDir [ 'basedir' ] . '/' . get_post_meta ( $ _POST [ 'media-replacer-replace-with' ] , '_wp_attached_file' , true ) ; $ backup = $ this -> createBackup ( $ filename ) ; $ replaced = $ this -> replaceFile ( $ filename , $ replacementFile ) ; if ( $ replaced ) { unlink ( $ replacementFile ) ; } $ meta = wp_generate_attachment_metadata ( $ postId , $ filename ) ; wp_update_attachment_metadata ( $ postId , $ meta ) ; $ revisions = get_post_meta ( $ postId , self :: $ revisionMetaKey , true ) ; if ( ! $ revisions ) { $ revisions = array ( ) ; } $ revisions [ time ( ) ] = $ backup ; update_post_meta ( $ postId , self :: $ revisionMetaKey , $ revisions ) ; $ this -> removeAttachment ( $ _POST [ 'media-replacer-replace-with' ] ) ; }
Replaces the media file
20,259
public function replaceFile ( $ original , $ replacement ) { $ this -> removeThumbnails ( $ original ) ; if ( copy ( $ replacement , $ original ) ) { return $ original ; } return false ; }
Replaces a file
20,260
public function removeThumbnails ( $ filename ) { $ file = pathinfo ( $ filename ) ; $ pattern = '/' . $ file [ 'filename' ] . '-([0-9]+)x([0-9]+)\.' . $ file [ 'extension' ] . '/' ; $ remove = ( array ) glob ( $ file [ 'dirname' ] . '/*.' . $ file [ 'extension' ] ) ; $ remove = array_filter ( $ remove , function ( $ item ) use ( $ pattern ) { return preg_match ( $ pattern , $ item ) ; } ) ; array_map ( 'unlink' , $ remove ) ; return true ; }
Remove thumbnails for a image
20,261
public function createBackup ( $ originalPath ) { if ( ! file_exists ( $ originalPath ) ) { return false ; } $ pathinfo = pathinfo ( $ originalPath ) ; $ backupPrefered = $ pathinfo [ 'dirname' ] . '/' . $ pathinfo [ 'filename' ] . '.' . $ pathinfo [ 'extension' ] . '.bkp' ; $ backupFile = $ backupPrefered ; $ i = 0 ; while ( file_exists ( $ backupFile ) ) { $ i ++ ; $ backupFile = $ backupPrefered . $ i ; } if ( copy ( $ originalPath , $ backupFile ) ) { return $ backupFile ; } return false ; }
Creates a backup of a media file
20,262
public function formFields ( $ fields , $ post ) { if ( ! isset ( $ _GET [ 'post' ] ) || $ post -> post_type !== 'attachment' ) { return $ fields ; } add_thickbox ( ) ; wp_enqueue_media ( ) ; $ uploadDir = wp_upload_dir ( ) ; $ mime = mime_content_type ( $ uploadDir [ 'basedir' ] . '/' . get_post_meta ( get_the_id ( ) , '_wp_attached_file' , true ) ) ; $ html = '<button type="button" class="button-secondary button-large" data-action="media-replacer-replace" data-mime="' . $ mime . '" data-edit-link="' . get_edit_post_link ( $ post -> ID ) . '">' . __ ( 'Replace media' , 'media-replacer' ) . '</button> <input type="hidden" name="media-replacer-replace-with">' ; $ revisions = get_post_meta ( $ post -> ID , self :: $ revisionMetaKey , true ) ; if ( ! is_array ( $ revisions ) ) { $ revisions = array ( ) ; } $ revisions = array_reverse ( $ revisions , true ) ; if ( count ( $ revisions ) > 0 ) { $ html .= '<a href="#TB_inline?width=600&height=550&inlineId=media-replace-revisions-thickbox-' . $ post -> ID . '" class="thickbox button-secondary button-large" data-action="media-replacer-revisions" data-edit-link="' . get_edit_post_link ( $ post -> ID ) . '">' . __ ( 'Media revisions' , 'media-replacer' ) . '</a>' ; $ html .= '<div id="media-replace-revisions-thickbox-' . $ post -> ID . '" style="display:none;"><ul class="media-replace-revisions">' ; } foreach ( $ revisions as $ time => $ path ) { if ( ! file_exists ( $ path ) ) { continue ; } $ url = str_replace ( $ uploadDir [ 'basedir' ] , $ uploadDir [ 'baseurl' ] , $ path ) ; $ date = mysql2date ( 'Y-m-d H:i' , date ( 'Y-m-d H:i:s' , $ time ) ) ; $ html .= '<li data-restore="' . $ path . '">' ; if ( explode ( '/' , mime_content_type ( $ path ) ) [ 0 ] === 'image' ) { $ html .= '<div class="media-replace-revision-thumb" style="background-image:url(' . $ url . ')"></div>' ; } $ html .= '<time>' . $ date . '</time>' ; $ html .= '</li>' ; } if ( count ( $ revisions ) ) { $ html .= '</ul> <div class="media-replace-revision-footer"> <button type="button" class="button button-large" data-action="media-replace-close-thickbox">' . __ ( 'Cancel' ) . '</button> <button type="button" class="button button-large button-primary" data-action="media-replace-close-thickbox">' . __ ( 'Ok' ) . '</button> </div> </div><input type="hidden" name="media-replace-restore">' ; } $ fields [ 'media_replacer' ] = array ( 'label' => '' , 'input' => 'html' , 'html' => $ html ) ; return $ fields ; }
Adds replacer field to the edit attachment form
20,263
public function predictOutput ( callable $ capture , string $ content ) { ob_start ( ) ; call_user_func ( $ capture ) ; $ clearedOutput = trim ( stripControlCharacters ( stripColorCharacters ( ob_get_clean ( ) ) ) ) ; if ( $ clearedOutput !== $ content ) { throw new \ Exception ( 'The predicted output did not match the actual one.' ) ; } }
Method to check if an function or method echo output matches the expected result
20,264
public function up ( ) { $ table = $ this -> table ( 'article' ) ; $ table -> addColumn ( 'searchable' , 'boolean' , array ( 'comment' => 'Should web crawlers index this?' , 'null' => false , 'after' => 'hidden' , 'default' => 1 , ) ) -> addIndex ( array ( 'searchable' ) ) -> save ( ) ; $ this -> execute ( 'UPDATE `article` SET searchable = 0 WHERE `id` IN (1378, 1450)' ) ; }
Up Method .
20,265
public function get ( $ name ) { if ( ! array_key_exists ( $ name , $ this -> options ) ) { throw new \ InvalidArgumentException ( sprintf ( 'The option "%s" does not exist.' , $ name ) ) ; } return $ this -> options [ $ name ] ; }
Returns a option by name .
20,266
public function before ( ) { parent :: before ( ) ; if ( ! App :: $ User -> isAuth ( ) || ! App :: $ User -> identity ( ) -> role -> can ( 'global/file' ) ) throw new NativeException ( 'Permission denied' ) ; App :: $ Translate -> append ( __DIR__ . '/Translation/' . App :: $ Request -> getLanguage ( ) . '.php' ) ; }
Append translation file ; )
20,267
public function actionBrowse ( $ type ) { $ files = null ; $ relative = null ; if ( $ this -> allowedExt [ $ type ] === null || ! Any :: isArray ( $ this -> allowedExt [ $ type ] ) ) { throw new NativeException ( 'Hack attempt' ) ; } $ files = File :: listFiles ( '/upload/' . $ type , $ this -> allowedExt [ $ type ] ) ; foreach ( $ files as $ file ) { $ newName = Str :: sub ( $ file , Str :: length ( root ) + 1 ) ; $ relative [ ] = trim ( Str :: replace ( DIRECTORY_SEPARATOR , '/' , $ newName ) , '/' ) ; } return App :: $ View -> render ( 'editor/browse' , [ 'callbackName' => App :: $ Security -> strip_tags ( App :: $ Request -> query -> get ( 'CKEditor' ) ) , 'callbackId' => ( int ) App :: $ Request -> query -> get ( 'CKEditorFuncNum' ) , 'files' => $ relative , 'type' => $ type ] , __DIR__ ) ; }
Browse files from ckeditor
20,268
public function actionUpload ( $ type ) { $ loadFile = App :: $ Request -> files -> get ( 'upload' ) ; if ( $ loadFile === null || $ loadFile -> getError ( ) !== 0 ) return $ this -> errorResponse ( __ ( 'File upload failed' ) ) ; $ fileExt = '.' . $ loadFile -> guessExtension ( ) ; if ( $ this -> allowedExt [ $ type ] === null || ! Any :: isArray ( $ this -> allowedExt [ $ type ] ) ) throw new NativeException ( 'Hack attempt' ) ; if ( ! Arr :: in ( $ fileExt , $ this -> allowedExt [ $ type ] ) ) { return $ this -> errorResponse ( __ ( 'This file type is not allowed to upload' ) ) ; } $ date = Date :: convertToDatetime ( time ( ) , 'd-m-Y' ) ; $ fileNewName = App :: $ Security -> simpleHash ( $ loadFile -> getFilename ( ) . $ loadFile -> getSize ( ) ) . $ fileExt ; $ savePath = Normalize :: diskFullPath ( '/upload/' . $ type . '/' . $ date ) ; $ loadFile -> move ( $ savePath , $ fileNewName ) ; $ url = '/upload/' . $ type . '/' . $ date . '/' . $ fileNewName ; return App :: $ View -> render ( 'editor/load_success' , [ 'callbackId' => ( int ) App :: $ Request -> query -> get ( 'CKEditorFuncNum' ) , 'url' => $ url ] , __DIR__ ) ; }
Upload files from ckeditor
20,269
private function errorResponse ( $ message = null ) { if ( $ message === null ) $ message = 'Unknown error' ; return App :: $ View -> render ( 'editor/load_error' , [ 'callbackId' => ( int ) App :: $ Request -> query -> get ( 'CKEditorFuncNum' ) , 'message' => $ message ] , __DIR__ ) ; }
Return error message for ckeditor API
20,270
protected function Value ( $ fieldName , $ defaultValue ) { $ form = Form :: Current ( ) ; if ( ! $ form ) { return $ defaultValue ; } return $ form -> GetValue ( $ fieldName , $ defaultValue ) ; }
Gets the submitted value or the default value if nothing submitted
20,271
public static function factory ( $ message , $ code , $ file , $ line , \ Exception $ prev = null ) { $ exception = null ; switch ( $ code ) { case E_WARNING : case E_USER_WARNING : case E_COMPILE_WARNING : case E_CORE_WARNING : $ exception = PHPWarningException :: class ; break ; case E_NOTICE : case E_USER_NOTICE : $ exception = PHPNoticeException :: class ; break ; case E_DEPRECATED : case E_USER_DEPRECATED : $ exception = PHPDepreciatedException :: class ; break ; case E_STRICT : $ exception = PHPStrictException :: class ; break ; case E_PARSE : $ exception = PHPParseException :: class ; break ; default : $ exception = PHPErrorException :: class ; break ; } return new $ exception ( $ message , $ code , $ file , $ line , $ prev ) ; }
Returns an exception for the given code
20,272
public function portletsAction ( ) { $ securityContext = $ this -> get ( 'security.context' ) ; $ data = [ ] ; foreach ( $ this -> get ( 'phlexible_dashboard.portlets' ) -> all ( ) as $ portlet ) { if ( $ portlet -> hasRole ( ) && ! $ securityContext -> isGranted ( $ portlet -> getRole ( ) ) ) { continue ; } $ data [ ] = $ portlet -> toArray ( ) ; } return new JsonResponse ( $ data ) ; }
Return portlets .
20,273
public function saveAction ( Request $ request ) { $ portlets = $ request -> request -> get ( 'portlets' ) ; $ portlets = json_decode ( $ portlets , true ) ; if ( ! is_array ( $ portlets ) ) { return new ResultResponse ( false , 'Portlets data invalid.' ) ; } $ user = $ this -> getUser ( ) ; $ user -> setProperty ( 'portlets' , json_encode ( $ portlets ) ) ; $ this -> get ( 'phlexible_user.user_manager' ) -> updateUser ( $ user ) ; return new ResultResponse ( true , 'Portlets saved.' ) ; }
Save portlets .
20,274
protected function validate ( array $ rules , $ values = null , array $ customAttrs = [ ] ) { if ( is_null ( $ values ) ) { $ values = request ( ) -> all ( ) ; } return Validator :: validate ( $ values , $ rules , $ customAttrs ) ; }
Validar valores pela regra .
20,275
function save ( string $ file = null ) { if ( $ file == null ) { $ file = static :: $ configFile ; } $ a = null ; foreach ( $ this as $ k => $ v ) { $ a [ $ k ] = $ v ; } return file_put_contents ( $ file , json_encode ( $ a , JSON_PRETTY_PRINT ) ) ; }
Save to Json config file
20,276
function load ( string $ file = null ) { if ( $ file == null ) { $ file = static :: $ configFile ; } if ( ! file_exists ( $ file ) ) { return false ; } $ a = json_decode ( file_get_contents ( $ file ) ) ; if ( isset ( $ a -> css ) ) { $ this -> css = $ a -> css ; } if ( isset ( $ a -> js ) ) { $ this -> js = $ a -> js ; } if ( isset ( $ a -> jss ) ) { $ this -> jss = $ a -> jss ; } return true ; }
Load configuration json file
20,277
public function getNextBuildTime ( BuildInterface $ lastJob = null ) { if ( file_exists ( $ this -> file ) ) { unlink ( $ this -> file ) ; return time ( ) ; } return null ; }
Calculates the real next job runtime dependend on lastJob .
20,278
public function prepareResponse ( Response $ response ) { $ cto = $ this -> getContentTypeObject ( ) ; if ( ! empty ( $ cto ) ) { $ ctt_type = $ cto -> getContentType ( ) ; } else { $ ctt_type = $ this -> getContentType ( ) ; } $ response -> setContentType ( $ ctt_type ) ; }
Prepare the content of the response before to send it to client
20,279
public function parseContent ( $ content ) { $ cto = $ this -> getContentTypeObject ( ) ; if ( ! empty ( $ cto ) ) { return $ cto -> parseContent ( $ content ) ; } else { return $ content ; } }
Parse an input content
20,280
public function valid ( ) : bool { if ( $ this -> pointer >= 0 && $ this -> pointer < count ( $ this -> members ) ) { return true ; } return false ; }
Check if the current position of the pointer is valid
20,281
public static function inProperty ( string $ name , array $ truths = [ true , 1 , '1' ] , array $ falsehoods = [ false , 0 , '0' ] ) : ExposesDataKey { $ instance = parent :: inProperty ( $ name ) ; assert ( $ instance instanceof BooleanValue ) ; $ instance -> truths = $ truths ; $ instance -> falsehoods = $ falsehoods ; return $ instance ; }
Creates a new mapping for the boolean type object property .
20,282
public static function inPropertyWithDifferentKey ( string $ name , string $ key , array $ truths = [ true , 1 , '1' ] , array $ falsehoods = [ false , 0 , '0' ] ) : ExposesDataKey { $ instance = parent :: inPropertyWithDifferentKey ( $ name , $ key ) ; assert ( $ instance instanceof BooleanValue ) ; $ instance -> truths = $ truths ; $ instance -> falsehoods = $ falsehoods ; return $ instance ; }
Creates a new mapping for the boolean type object property using the data from a specific key .
20,283
public static function protectEmail ( $ email ) { $ chunks = explode ( '@' , $ email ) ; $ chunks [ 0 ] = substr ( $ chunks [ 0 ] , 0 , 2 ) . '****' ; return implode ( '@' , $ chunks ) ; }
Hide most of the user part of an e - mail address
20,284
public static function html2text ( $ html ) { libxml_use_internal_errors ( true ) ; $ doc = new \ DOMDocument ( ) ; $ doc -> loadHTML ( '<?xml encoding="UTF-8">' . $ html , LIBXML_NOERROR | LIBXML_NOWARNING ) ; foreach ( $ doc -> childNodes as $ item ) { if ( $ item -> nodeType == XML_PI_NODE ) { $ doc -> removeChild ( $ item ) ; break ; } ; } ; $ doc -> encoding = 'UTF-8' ; return self :: _dom2text ( $ doc ) ; }
Convert an HTML string to a plain text approximation
20,285
private function fileReader ( $ filename ) { if ( empty ( $ this -> message_path ) ) { $ this -> message_path = __DIR__ . DIRECTORY_SEPARATOR . 'messages' . DIRECTORY_SEPARATOR ; } $ message = file_get_contents ( $ this -> message_path . $ filename . '.livia' ) ; return $ message ; }
Provide a FileReader .
20,286
protected function getNotification ( $ name , $ status = FALSE ) { if ( $ status === FALSE ) { if ( $ this -> commandExists ( 'notify-send' ) ) { shell_exec ( 'notify-send "' . $ this -> getAppName ( ) . ' Tasks" "Running ' . $ name . '..." -i dialog-information' ) ; } echo "\n" ; echo "\t" , $ this -> colorize ( 'Running ' . $ name . '...' , 'info' ) ; echo "\n" ; } else { if ( $ this -> commandExists ( 'notify-send' ) ) { shell_exec ( 'notify-send "' . $ this -> getAppName ( ) . ' Tasks" "' . $ name . ' Task Completed!" -i dialog-ok' ) ; } echo "\n" ; echo "\t" , $ this -> colorize ( $ name . ' Task Completed!' , 'success' ) ; echo "\n" ; } }
Provide a NotificationManager .
20,287
public function ask ( $ question ) { echo "\n" ; echo "\t" , $ this -> colorize ( $ question , 'info' ) ; echo "\n" ; echo "\t" ; $ response = trim ( fgets ( STDIN ) ) ; return $ response ; }
Provide a AskManager .
20,288
public function confirm ( $ question , $ default = 'yes' ) { echo "\n" ; echo "\t" , $ this -> colorize ( $ question . " [$default] " , 'info' ) ; echo " " ; $ response = trim ( fgets ( STDIN ) ) ; if ( $ response == 'yes' || $ response == 'no' ) { return $ response ; } else if ( empty ( $ response ) ) { return $ default ; } else { $ this -> confirm ( $ question , $ default ) ; } }
Provide a ConfirmManager .
20,289
public static function register ( ) : bool { static :: init ( ) ; if ( ! \ array_key_exists ( static :: $ backend , static :: $ invokableClasses ) ) { throw new InvalidArgumentException ( 'Unsupported session backend: ' . static :: $ backend ) ; } $ handler = new static :: $ invokableClasses [ static :: $ backend ] ; \ session_save_path ( static :: $ savePath ) ; return \ session_set_save_handler ( $ handler , true ) ; }
Registers session handler
20,290
public function EntryController_RegisterBeforePassword_Handler ( $ Sender ) { $ ProfileFields = $ this -> GetProfileFields ( ) ; $ Sender -> RegistrationFields = array ( ) ; foreach ( $ ProfileFields as $ Name => $ Field ) { if ( GetValue ( 'OnRegister' , $ Field ) ) $ Sender -> RegistrationFields [ $ Name ] = $ Field ; } include ( $ this -> GetView ( 'registrationfields.php' ) ) ; }
Add fields to registration forms .
20,291
public function EntryController_RegisterValidation_Handler ( $ Sender ) { $ ProfileFields = $ this -> GetProfileFields ( ) ; foreach ( $ ProfileFields as $ Name => $ Field ) { if ( GetValue ( 'Required' , $ Field ) && GetValue ( 'OnRegister' , $ Field ) ) $ Sender -> UserModel -> Validation -> ApplyRule ( $ Name , 'Required' , $ Field [ 'Label' ] . " is required." ) ; } }
Required fields on registration forms .
20,292
public function ParseSpecialFields ( $ Fields = array ( ) ) { if ( ! is_array ( $ Fields ) ) return $ Fields ; foreach ( $ Fields as $ Label => $ Value ) { switch ( $ Label ) { case 'Twitter' : $ Fields [ 'Twitter' ] = Anchor ( '@' . $ Value , 'http://twitter.com/' . $ Value ) ; break ; case 'Facebook' : $ Fields [ 'Facebook' ] = Anchor ( $ Value , 'http://facebook.com/' . $ Value ) ; break ; case 'LinkedIn' : $ Fields [ 'LinkedIn' ] = Anchor ( $ Value , 'http://www.linkedin.com/in/' . $ Value ) ; break ; case 'Google' : $ Fields [ 'Google' ] = Anchor ( 'Google+' , $ Value , '' , array ( 'rel' => 'me' ) ) ; break ; case 'Website' : $ Fields [ 'Website' ] = Anchor ( $ Value , $ Value ) ; break ; case 'Real Name' : $ Fields [ 'Real Name' ] = Wrap ( htmlspecialchars ( $ Value ) , 'span' , array ( 'itemprop' => 'name' ) ) ; break ; } } return $ Fields ; }
Special manipulations .
20,293
private function GetProfileFields ( ) { $ Fields = C ( 'ProfileExtender.Fields' , array ( ) ) ; if ( ! is_array ( $ Fields ) ) $ Fields = array ( ) ; foreach ( $ Fields as $ Name => $ Field ) { if ( ! is_array ( $ Field ) || strlen ( $ Name ) < 1 ) { unset ( $ Fields [ $ Name ] ) ; } if ( ! isset ( $ Field [ 'FormType' ] ) ) $ Fields [ $ Name ] [ 'FormType' ] = 'TextBox' ; elseif ( ! array_key_exists ( $ Field [ 'FormType' ] , $ this -> FormTypes ) ) unset ( $ this -> ProfileFields [ $ Name ] ) ; } return $ Fields ; }
Get custom profile fields .
20,294
private function ProfileFields ( $ Sender ) { $ this -> ProfileFields = $ this -> GetProfileFields ( ) ; $ this -> UserFields = Gdn :: UserModel ( ) -> GetMeta ( $ Sender -> Data ( "User.UserID" ) , 'Profile.%' , 'Profile.' ) ; foreach ( $ this -> UserFields as $ Field => $ Value ) { $ Sender -> Form -> SetValue ( $ Field , $ Value ) ; } include ( $ this -> GetView ( 'profilefields.php' ) ) ; }
Display custom profile fields on form .
20,295
public function SettingsController_ProfileExtender_Create ( $ Sender ) { $ Sender -> Permission ( 'Garden.Settings.Manage' ) ; if ( ! C ( 'ProfileExtender.Fields' ) ) $ this -> Setup ( ) ; $ Data = $ this -> GetProfileFields ( ) ; $ Sender -> SetData ( 'ExtendedFields' , $ Data ) ; $ Sender -> AddSideMenu ( 'settings/profileextender' ) ; $ Sender -> SetData ( 'Title' , T ( 'Profile Fields' ) ) ; $ Sender -> Render ( 'settings' , '' , 'plugins/ProfileExtender' ) ; }
Settings page .
20,296
public function SettingsController_ProfileFieldDelete_Create ( $ Sender , $ Args ) { $ Sender -> Permission ( 'Garden.Settings.Manage' ) ; $ Sender -> SetData ( 'Title' , 'Delete Field' ) ; if ( isset ( $ Args [ 0 ] ) ) { if ( $ Sender -> Form -> IsPostBack ( ) ) { RemoveFromConfig ( 'ProfileExtender.Fields.' . $ Args [ 0 ] ) ; $ Sender -> RedirectUrl = Url ( '/settings/profileextender' ) ; } else $ Sender -> SetData ( 'Field' , $ this -> GetProfileField ( $ Args [ 0 ] ) ) ; } $ Sender -> Render ( 'delete' , '' , 'plugins/ProfileExtender' ) ; }
Delete a field .
20,297
public function UserInfoModule_OnBasicInfo_Handler ( $ Sender ) { try { $ ProfileFields = Gdn :: UserModel ( ) -> GetMeta ( $ Sender -> User -> UserID , 'Profile.%' , 'Profile.' ) ; if ( ! count ( $ ProfileFields ) && is_object ( $ Sender -> User ) && C ( 'Plugins.CustomProfileFields.SuggestedFields' , FALSE ) ) { $ ProfileFields = Gdn :: UserModel ( ) -> GetAttribute ( $ Sender -> User -> UserID , 'CustomProfileFields' , FALSE ) ; if ( $ ProfileFields ) { Gdn :: UserModel ( ) -> SetMeta ( $ Sender -> User -> UserID , $ ProfileFields , 'Profile.' ) ; Gdn :: UserModel ( ) -> SaveAttribute ( $ Sender -> User -> UserID , 'CustomProfileFields' , FALSE ) ; } } $ ProfileFields = $ this -> ParseSpecialFields ( $ ProfileFields ) ; $ AllFields = $ this -> GetProfileFields ( ) ; if ( ! is_array ( $ AllFields ) || ! is_array ( $ ProfileFields ) ) return ; $ ProfileFields = array_reverse ( $ ProfileFields ) ; foreach ( $ ProfileFields as $ Name => $ Value ) { if ( ! $ Value ) continue ; if ( ! GetValue ( 'OnProfile' , $ AllFields [ $ Name ] ) ) continue ; if ( ! in_array ( $ Name , $ this -> MagicLabels ) ) $ Value = Gdn_Format :: Links ( htmlspecialchars ( $ Value ) ) ; echo ' <dt class="ProfileExtend Profile' . Gdn_Format :: AlphaNumeric ( $ Name ) . '">' . Gdn_Format :: Text ( $ AllFields [ $ Name ] [ 'Label' ] ) . '</dt> ' ; echo ' <dd class="ProfileExtend Profile' . Gdn_Format :: AlphaNumeric ( $ Name ) . '">' . $ Value . '</dd> ' ; } } catch ( Exception $ ex ) { } }
Display custom fields on Profile .
20,298
public function UserModel_AfterSave_Handler ( $ Sender ) { $ FormPostValues = GetValue ( 'FormPostValues' , $ Sender -> EventArguments ) ; if ( is_array ( $ FormPostValues ) ) { $ UserID = GetValue ( 'UserID' , $ Sender -> EventArguments ) ; $ AllowedFields = $ this -> GetProfileFields ( ) ; $ Columns = Gdn :: SQL ( ) -> FetchColumns ( 'User' ) ; foreach ( $ FormPostValues as $ Name => $ Field ) { if ( ! array_key_exists ( $ Name , $ AllowedFields ) ) unset ( $ FormPostValues [ $ Name ] ) ; if ( in_array ( $ Name , $ Columns ) ) unset ( $ FormPostValues [ $ Name ] ) ; } if ( count ( $ FormPostValues ) ) Gdn :: UserModel ( ) -> SetMeta ( $ UserID , $ FormPostValues , 'Profile.' ) ; } }
Save custom profile fields when saving the user .
20,299
public function Setup ( ) { if ( $ Fields = C ( 'Plugins.ProfileExtender.ProfileFields' , C ( 'Plugins.CustomProfileFields.SuggestedFields' ) ) ) { $ Hidden = C ( 'Plugins.ProfileExtender.HideFields' , C ( 'Plugins.CustomProfileFields.HideFields' ) ) ; $ OnRegister = C ( 'Plugins.ProfileExtender.RegistrationFields' ) ; $ Length = C ( 'Plugins.ProfileExtender.TextMaxLength' , C ( 'Plugins.CustomProfileFields.ValueLength' ) ) ; $ Fields = array_filter ( ( array ) explode ( ',' , $ Fields ) ) ; $ Hidden = array_filter ( ( array ) explode ( ',' , $ Hidden ) ) ; $ OnRegister = array_filter ( ( array ) explode ( ',' , $ OnRegister ) ) ; $ NewData = array ( ) ; foreach ( $ Fields as $ Field ) { $ Name = $ TestSlug = preg_replace ( '`[^0-9a-zA-Z]`' , '' , $ Field ) ; $ i = 1 ; while ( array_key_exists ( $ Name , $ NewData ) || in_array ( $ Name , $ this -> ReservedNames ) ) { $ Name = $ TestSlug . $ i ++ ; } $ NewData [ $ Name ] = array ( 'Label' => $ Field , 'Length' => $ Length , 'FormType' => 'TextBox' , 'OnProfile' => ( in_array ( $ Field , $ Hidden ) ) ? 0 : 1 , 'OnRegister' => ( in_array ( $ Field , $ OnRegister ) ) ? 1 : 0 , 'OnDiscussion' => 0 , 'Required' => 0 , 'Locked' => 0 , 'Sort' => 0 ) ; } SaveToConfig ( 'ProfileExtender.Fields' , $ NewData ) ; } }
Import from CustomProfileFields or upgrade from ProfileExtender 2 . 0 .