idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
18,300
protected function setWritableDirs ( ) { $ dirs = array_unique ( array_filter ( array_merge ( Configure :: read ( 'WRITABLE_DIRS' , [ ] ) , [ getConfig ( 'Assets.target' ) , getConfigOrFail ( 'DatabaseBackup.target' ) , getConfigOrFail ( 'Thumber.target' ) , BANNERS , LOGIN_RECORDS , PHOTOS , USER_PICTURES , ] ) ) ) ; return Configure :: write ( 'WRITABLE_DIRS' , $ dirs ) ? $ dirs : false ; }
Sets directories to be created and must be writable
18,301
public function changePassword ( ) { $ user = $ this -> Users -> get ( $ this -> Auth -> user ( 'id' ) ) ; if ( $ this -> request -> is ( [ 'patch' , 'post' , 'put' ] ) ) { $ user = $ this -> Users -> patchEntity ( $ user , $ this -> request -> getData ( ) ) ; if ( $ this -> Users -> save ( $ user ) ) { $ this -> getMailer ( 'MeCms.User' ) -> send ( 'changePassword' , [ $ user ] ) ; $ this -> Flash -> success ( I18N_OPERATION_OK ) ; return $ this -> redirect ( [ '_name' => 'dashboard' ] ) ; } $ this -> Flash -> error ( I18N_OPERATION_NOT_OK ) ; } $ this -> set ( compact ( 'user' ) ) ; }
Changes the user s password
18,302
public function changePicture ( ) { $ id = $ this -> Auth -> user ( 'id' ) ; if ( $ this -> request -> getData ( 'file' ) ) { foreach ( ( ( new Folder ( USER_PICTURES ) ) -> find ( $ id . '\..+' ) ) as $ filename ) { @ unlink ( USER_PICTURES . $ filename ) ; } $ filename = sprintf ( '%s.%s' , $ id , pathinfo ( $ this -> request -> getData ( 'file' ) [ 'tmp_name' ] , PATHINFO_EXTENSION ) ) ; $ uploaded = $ this -> Uploader -> set ( $ this -> request -> getData ( 'file' ) ) -> mimetype ( 'image' ) -> save ( USER_PICTURES , $ filename ) ; if ( ! $ uploaded ) { return $ this -> setUploadError ( $ this -> Uploader -> getError ( ) ) ; } $ this -> Auth -> setUser ( array_merge ( $ this -> Auth -> user ( ) , [ 'picture' => $ uploaded ] ) ) ; ( new ThumbManager ) -> clear ( $ uploaded ) ; } }
Changes the user s picture
18,303
public function lastLogin ( ) { if ( ! getConfig ( 'users.login_log' ) ) { $ this -> Flash -> error ( I18N_DISABLED ) ; return $ this -> redirect ( [ '_name' => 'dashboard' ] ) ; } $ this -> set ( 'loginLog' , $ this -> LoginRecorder -> setConfig ( 'user' , $ this -> Auth -> user ( 'id' ) ) -> read ( ) ) ; }
Displays the login log
18,304
public function setStyles ( OutputInterface $ oOutput ) : void { $ oWarningStyle = new OutputFormatterStyle ( 'white' , 'yellow' ) ; $ oOutput -> getFormatter ( ) -> setStyle ( 'warning' , $ oWarningStyle ) ; }
Adds additional styles to the output
18,305
protected function confirm ( $ sQuestion , $ bDefault ) { $ sQuestion = is_array ( $ sQuestion ) ? implode ( "\n" , $ sQuestion ) : $ sQuestion ; $ oHelper = $ this -> getHelper ( 'question' ) ; $ sDefault = ( bool ) $ bDefault ? 'Y' : 'N' ; $ oQuestion = new ConfirmationQuestion ( $ sQuestion . ' [' . $ sDefault . ']: ' , $ bDefault ) ; return $ oHelper -> ask ( $ this -> oInput , $ this -> oOutput , $ oQuestion ) ; }
Confirms something with the user
18,306
protected function ask ( $ mQuestion , $ sDefault ) { $ mQuestion = is_array ( $ mQuestion ) ? implode ( "\n" , $ mQuestion ) : $ mQuestion ; $ oHelper = $ this -> getHelper ( 'question' ) ; $ oQuestion = new Question ( $ mQuestion . ' [' . $ sDefault . ']: ' , $ sDefault ) ; return $ oHelper -> ask ( $ this -> oInput , $ this -> oOutput , $ oQuestion ) ; }
Asks the user for some input
18,307
protected function outputBlock ( array $ aLines , string $ sType ) : void { $ aLengths = array_map ( 'strlen' , $ aLines ) ; $ iMaxLength = max ( $ aLengths ) ; $ this -> oOutput -> writeln ( '<' . $ sType . '> ' . str_pad ( '' , $ iMaxLength , ' ' ) . ' </' . $ sType . '>' ) ; foreach ( $ aLines as $ sLine ) { $ this -> oOutput -> writeln ( '<' . $ sType . '> ' . str_pad ( $ sLine , $ iMaxLength , ' ' ) . ' </' . $ sType . '>' ) ; } $ this -> oOutput -> writeln ( '<' . $ sType . '> ' . str_pad ( '' , $ iMaxLength , ' ' ) . ' </' . $ sType . '>' ) ; }
Renders an coloured block
18,308
protected function callCommand ( $ sCommand , array $ aArguments = [ ] , $ bInteractive = true , $ bSilent = false ) { $ oCmd = $ this -> getApplication ( ) -> find ( $ sCommand ) ; $ aArguments = array_merge ( [ 'command' => $ sCommand ] , $ aArguments ) ; $ oCmdInput = new ArrayInput ( $ aArguments ) ; $ oCmdInput -> setInteractive ( $ bInteractive ) ; if ( $ bSilent ) { $ oCmdOutput = new NullOutput ( ) ; } else { $ oCmdOutput = $ this -> oOutput ; } return $ oCmd -> run ( $ oCmdInput , $ oCmdOutput ) ; }
Call another command within the app
18,309
public function getProviders ( $ status = null ) { if ( $ status == 'ENABLED' ) { return $ this -> aProviders [ 'enabled' ] ; } elseif ( $ status == 'DISABLED' ) { return $ this -> aProviders [ 'disabled' ] ; } else { return $ this -> aProviders [ 'all' ] ; } }
Returns a list of providers optionally filtered by availability
18,310
public function getProvider ( $ provider ) { if ( isset ( $ this -> aProviders [ 'all' ] [ strtolower ( $ provider ) ] ) ) { return $ this -> aProviders [ 'all' ] [ strtolower ( $ provider ) ] ; } else { return false ; } }
Returns the details of a particular provider
18,311
protected function getProviderClass ( $ sProvider ) { $ aProviders = $ this -> getProviders ( ) ; return isset ( $ aProviders [ strtolower ( $ sProvider ) ] [ 'class' ] ) ? $ aProviders [ strtolower ( $ sProvider ) ] [ 'class' ] : null ; }
Returns the correct casing for a provider
18,312
public function authenticate ( $ sProvider , $ mParams = null ) { try { $ sProvider = $ this -> getProviderClass ( $ sProvider ) ; return $ this -> oHybridAuth -> authenticate ( $ sProvider , $ mParams ) ; } catch ( \ Exception $ e ) { $ this -> setError ( 'Provider Error: ' . $ e -> getMessage ( ) ) ; return false ; } }
Authenticates a user using Hybrid Auth s authenticate method
18,313
public function getUserProfile ( $ provider ) { $ oAdapter = $ this -> authenticate ( $ provider ) ; try { return $ oAdapter -> getUserProfile ( ) ; } catch ( \ Exception $ e ) { $ this -> setError ( 'Provider Error: ' . $ e -> getMessage ( ) ) ; return false ; } }
Returns the user s profile for a particular provider .
18,314
public function getUserByProviderId ( $ provider , $ identifier ) { $ this -> oDb -> select ( 'user_id' ) ; $ this -> oDb -> where ( 'provider' , $ provider ) ; $ this -> oDb -> where ( 'identifier' , $ identifier ) ; $ oUser = $ this -> oDb -> get ( NAILS_DB_PREFIX . 'user_social' ) -> row ( ) ; if ( empty ( $ oUser ) ) { return false ; } return $ this -> oUserModel -> getById ( $ oUser -> user_id ) ; }
Fetches a local user profile via a provider and provider ID
18,315
public function restoreSession ( $ user_id = null ) { if ( empty ( $ user_id ) ) { $ user_id = activeUser ( 'id' ) ; } if ( empty ( $ user_id ) ) { $ this -> setError ( 'Must specify which user ID\'s session to restore.' ) ; return false ; } $ oUser = $ this -> oUserModel -> getById ( $ user_id ) ; if ( ! $ oUser ) { $ this -> setError ( 'Invalid User ID' ) ; return false ; } $ this -> oHybridAuth -> logoutAllProviders ( ) ; $ this -> oDb -> where ( 'user_id' , $ oUser -> id ) ; $ aSessions = $ this -> oDb -> get ( NAILS_DB_PREFIX . 'user_social' ) -> result ( ) ; $ aRestore = [ ] ; foreach ( $ aSessions as $ oSession ) { $ oSession -> session_data = unserialize ( $ oSession -> session_data ) ; $ aRestore = array_merge ( $ aRestore , $ oSession -> session_data ) ; } return $ this -> oHybridAuth -> restoreSessionData ( serialize ( $ aRestore ) ) ; }
Restores a user s social session
18,316
public function api ( $ sProvider , $ call = '' ) { if ( ! $ this -> isConnectedWith ( $ sProvider ) ) { $ this -> setError ( 'Not connected with provider "' . $ sProvider . '"' ) ; return false ; } try { $ sProvider = $ this -> getProviderClass ( $ sProvider ) ; $ oProvider = $ this -> oHybridAuth -> getAdapter ( $ sProvider ) ; return $ oProvider -> api ( ) -> api ( $ call ) ; } catch ( \ Exception $ e ) { $ this -> setError ( 'Provider Error: ' . $ e -> getMessage ( ) ) ; return false ; } }
Abstraction to a provider s API
18,317
public function cacheModuleConfig ( $ return = false ) { $ modules = $ this -> getModulesFromDb ( ) ; $ arrayModule = array ( ) ; foreach ( $ modules as $ module ) { if ( ! in_array ( $ module -> folder , $ arrayModule ) ) $ arrayModule [ ] = $ module -> folder ; } if ( $ return == false ) { $ filePath = Yii :: getPathOfAlias ( 'application.config' ) ; $ fileHandle = fopen ( $ filePath . '/cache_module.php' , 'w' ) ; fwrite ( $ fileHandle , implode ( "\n" , $ arrayModule ) ) ; fclose ( $ fileHandle ) ; } else return $ arrayModule ; }
Cache modul dari database ke bentuk file . Untuk mengurangi query pada saat install ke database .
18,318
public function getModuleConfig ( $ module ) { Yii :: import ( 'mustangostang.spyc.Spyc' ) ; define ( 'DS' , DIRECTORY_SEPARATOR ) ; $ configPath = Yii :: getPathOfAlias ( 'application.vendor.ommu.' . $ module ) . DS . $ module . '.yaml' ; if ( file_exists ( $ configPath ) ) return Spyc :: YAMLLoad ( $ configPath ) ; else return null ; }
Get module config from yaml file
18,319
public function deleteModuleDatabase ( $ module ) { $ config = $ this -> getModuleConfig ( $ module ) ; $ tableName = $ config [ 'db_table_name' ] ; if ( $ config && $ tableName ) { foreach ( $ tableName as $ val ) { Yii :: app ( ) -> db -> createCommand ( "DROP TABLE {$val}" ) -> execute ( ) ; } } else return false ; }
Delete Module Database
18,320
public function deleteModuleDb ( $ module ) { if ( $ module != null ) { $ model = OmmuPlugins :: model ( ) -> findByAttributes ( array ( 'folder' => $ module ) ) ; if ( $ model != null ) $ model -> delete ( ) ; else return true ; } else return true ; }
Delete Module from Plugin Database
18,321
public function setModules ( ) { $ moduleVendorPath = Yii :: getPathOfAlias ( 'application.vendor.ommu' ) ; $ installedModule = $ this -> getModulesFromDir ( ) ; $ cacheModule = file ( Yii :: getPathOfAlias ( 'application.config' ) . '/cache_module.php' ) ; $ toBeInstalled = array ( ) ; $ caches = array ( ) ; foreach ( $ cacheModule as $ val ) { $ caches [ ] = trim ( $ val ) ; } if ( ! $ installedModule ) $ installedModule = array ( ) ; foreach ( $ caches as $ cache ) { if ( ! in_array ( $ cache , array_map ( "trim" , $ installedModule ) ) ) $ this -> deleteModuleDb ( $ cache ) ; } $ moduleDb = $ this -> cacheModuleConfig ( true ) ; foreach ( $ installedModule as $ module ) { $ module = trim ( $ module ) ; if ( ! in_array ( $ module , array_map ( "trim" , $ moduleDb ) ) ) { $ config = $ this -> getModuleConfig ( $ module ) ; $ moduleFile = join ( '/' , array ( $ moduleVendorPath , $ module , ucfirst ( $ module ) . 'Module.php' ) ) ; if ( $ config && file_exists ( $ moduleFile ) && $ module == $ config [ 'folder_name' ] ) { $ model = new OmmuPlugins ; $ model -> folder = $ module ; $ model -> name = $ config [ 'name' ] ; $ model -> desc = $ config [ 'description' ] ; if ( $ config [ 'model' ] ) $ model -> model = $ config [ 'model' ] ; $ model -> save ( ) ; } } } $ this -> generateModules ( ) ; }
Install modul ke database
18,322
public function fill ( $ payload ) { $ payload = $ this -> determineTypeAndMessage ( $ payload ) ; $ payload = $ this -> fillBlanks ( $ payload ) ; return $ payload ; }
Helper method to assist with filling out the values in the payload
18,323
public function fillBlanks ( $ payload ) { $ fields = [ 'doi' , 'url' , 'message' , 'verbosemessage' , 'responsecode' , 'app_id' ] ; foreach ( $ fields as $ field ) { if ( ! array_key_exists ( $ field , $ payload ) ) { $ payload [ $ field ] = "" ; } } return $ payload ; }
Make sure that all fields are filled out
18,324
public function setData ( array $ data ) { if ( isset ( $ data [ 'attachables' ] ) ) { $ this -> setAttachables ( $ data [ 'attachables' ] ) ; } if ( isset ( $ data [ 'groups' ] ) ) { $ this -> setGroups ( $ data [ 'groups' ] ) ; } if ( isset ( $ data [ 'widgets' ] ) ) { $ this -> setWidgets ( $ data [ 'widgets' ] ) ; } unset ( $ data [ 'attachables' ] , $ data [ 'groups' ] , $ data [ 'widgets' ] ) ; return parent :: setData ( $ data ) ; }
Set attachments settings in a specific order .
18,325
public function setAttachables ( array $ attachables ) { foreach ( $ attachables as $ attType => $ attStruct ) { if ( ! is_array ( $ attStruct ) ) { throw new InvalidArgumentException ( sprintf ( 'The attachment structure for "%s" must be an array' , $ attType ) ) ; } if ( isset ( $ attStruct [ 'attachment_type' ] ) ) { $ attType = $ attStruct [ 'attachment_type' ] ; } else { $ attStruct [ 'attachment_type' ] = $ attType ; } if ( ! is_string ( $ attType ) ) { throw new InvalidArgumentException ( 'The attachment type must be a string' ) ; } $ this -> attachables [ $ attType ] = $ attStruct ; } return $ this ; }
Set attachment types .
18,326
public function setGroups ( array $ groups ) { foreach ( $ groups as $ groupIdent => $ groupStruct ) { if ( ! is_array ( $ groupStruct ) ) { throw new InvalidArgumentException ( sprintf ( 'The attachment group "%s" must be an array of attachable objects' , $ groupIdent ) ) ; } if ( isset ( $ groupStruct [ 'ident' ] ) ) { $ groupIdent = $ groupStruct [ 'ident' ] ; unset ( $ groupStruct [ 'ident' ] ) ; } if ( ! is_string ( $ groupIdent ) ) { throw new InvalidArgumentException ( 'The attachment group identifier must be a string' ) ; } if ( isset ( $ groupStruct [ 'attachable_objects' ] ) ) { $ groupStruct = $ groupStruct [ 'attachable_objects' ] ; } elseif ( isset ( $ groupStruct [ 'attachables' ] ) ) { $ groupStruct = $ groupStruct [ 'attachables' ] ; } $ this -> groups [ $ groupIdent ] = $ groupStruct ; } return $ this ; }
Set attachment type groups .
18,327
public function setWidgets ( array $ widgets ) { foreach ( $ widgets as $ widgetIdent => $ widgetStruct ) { if ( ! is_array ( $ widgetStruct ) ) { throw new InvalidArgumentException ( sprintf ( 'The attachment widget "%s" must be an array of widget settings' , $ widgetIdent ) ) ; } if ( isset ( $ widgetStruct [ 'ident' ] ) ) { $ widgetIdent = $ widgetStruct [ 'ident' ] ; unset ( $ widgetStruct [ 'ident' ] ) ; } if ( ! is_string ( $ widgetIdent ) ) { throw new InvalidArgumentException ( 'The attachment widget identifier must be a string' ) ; } $ this -> widgets [ $ widgetIdent ] = $ widgetStruct ; } return $ this ; }
Set attachment widget structures .
18,328
protected function getPrefixLength ( array $ strings ) { $ len = 1 ; $ cnt = count ( $ strings [ 0 ] ) ; while ( $ len < $ cnt && $ this -> stringsMatch ( $ strings , $ len ) ) { ++ $ len ; } return $ len ; }
Get the number of leading elements common to all given strings
18,329
protected function getStringsByPrefix ( array $ strings ) { $ byPrefix = [ ] ; foreach ( $ strings as $ string ) { $ byPrefix [ $ string [ 0 ] ] [ ] = $ string ; } return $ byPrefix ; }
Return given strings grouped by their first element
18,330
protected function mergeStrings ( array $ strings ) { $ len = $ this -> getPrefixLength ( $ strings ) ; $ newString = array_slice ( $ strings [ 0 ] , 0 , $ len ) ; foreach ( $ strings as $ string ) { $ newString [ $ len ] [ ] = array_slice ( $ string , $ len ) ; } return $ newString ; }
Merge given strings into a new single string
18,331
protected function stringsMatch ( array $ strings , $ pos ) { $ value = $ strings [ 0 ] [ $ pos ] ; foreach ( $ strings as $ string ) { if ( ! isset ( $ string [ $ pos ] ) || $ string [ $ pos ] !== $ value ) { return false ; } } return true ; }
Test whether all given strings elements match at given position
18,332
public function find ( $ type = 'all' , $ options = [ ] ) { $ next = $ this -> getNextToBePublished ( ) ; if ( $ next && time ( ) >= $ next ) { Cache :: clear ( false , $ this -> getCacheName ( ) ) ; $ this -> setNextToBePublished ( ) ; } return parent :: find ( $ type , $ options ) ; }
Creates a new Query for this repository and applies some defaults based on the type of search that was selected
18,333
public function setNextToBePublished ( ) { $ next = $ this -> find ( ) -> where ( [ sprintf ( '%s.active' , $ this -> getAlias ( ) ) => true , sprintf ( '%s.created >' , $ this -> getAlias ( ) ) => new Time , ] ) -> order ( [ sprintf ( '%s.created' , $ this -> getAlias ( ) ) => 'ASC' ] ) -> extract ( 'created' ) -> first ( ) ; $ next = empty ( $ next ) ? false : $ next -> toUnixString ( ) ; Cache :: write ( 'next_to_be_published' , $ next , $ this -> getCacheName ( ) ) ; return $ next ; }
Sets to cache the timestamp of the next record to be published . This value can be used to check if the cache is valid
18,334
protected static function ensureTypes ( ) { if ( self :: $ doneScanning && count ( self :: $ types ) > 0 ) { return ; } foreach ( self :: types ( ) as $ t ) { } }
A wee bit hacky but this ensures that when ever has or get is called before types all types are detected and available for has and get .
18,335
public function add ( ) { $ group = $ this -> UsersGroups -> newEntity ( ) ; if ( $ this -> request -> is ( 'post' ) ) { $ group = $ this -> UsersGroups -> patchEntity ( $ group , $ this -> request -> getData ( ) ) ; if ( $ this -> UsersGroups -> save ( $ group ) ) { $ this -> Flash -> success ( I18N_OPERATION_OK ) ; return $ this -> redirect ( [ 'action' => 'index' ] ) ; } $ this -> Flash -> error ( I18N_OPERATION_NOT_OK ) ; } $ this -> set ( compact ( 'group' ) ) ; }
Adds users group
18,336
public function edit ( $ id = null ) { $ group = $ this -> UsersGroups -> get ( $ id ) ; if ( $ this -> request -> is ( [ 'patch' , 'post' , 'put' ] ) ) { $ group = $ this -> UsersGroups -> patchEntity ( $ group , $ this -> request -> getData ( ) ) ; if ( $ this -> UsersGroups -> save ( $ group ) ) { $ this -> Flash -> success ( I18N_OPERATION_OK ) ; return $ this -> redirect ( [ 'action' => 'index' ] ) ; } $ this -> Flash -> error ( I18N_OPERATION_NOT_OK ) ; } $ this -> set ( compact ( 'group' ) ) ; }
Edits users group
18,337
public function delete ( $ id = null ) { $ this -> request -> allowMethod ( [ 'post' , 'delete' ] ) ; $ group = $ this -> UsersGroups -> get ( $ id ) ; if ( $ id > 3 && ! $ group -> user_count ) { $ this -> UsersGroups -> deleteOrFail ( $ group ) ; $ this -> Flash -> success ( I18N_OPERATION_OK ) ; } else { $ this -> Flash -> alert ( $ id <= 3 ? __d ( 'me_cms' , 'You cannot delete this users group' ) : I18N_BEFORE_DELETE ) ; } return $ this -> redirect ( [ 'action' => 'index' ] ) ; }
Deletes users group
18,338
public function getFormData ( ) { $ data = Client :: perform ( 'get-class-values' , [ 'class' => 'client,ticket_settings' ] ) ; $ this -> ticket_emails = $ data [ 'ticket_emails' ] ; $ this -> send_message_text = $ data [ 'send_message_text' ] ; $ this -> new_messages_first = $ data [ 'new_messages_first' ] ; }
Get form data from API .
18,339
public static function getPages ( $ publish = null , $ array = true ) { $ criteria = new CDbCriteria ; if ( $ publish != null ) $ criteria -> compare ( 't.publish' , $ publish ) ; $ model = self :: model ( ) -> findAll ( $ criteria ) ; if ( $ array == true ) { $ items = array ( ) ; if ( $ model != null ) { foreach ( $ model as $ key => $ val ) { $ items [ $ val -> page_id ] = $ val -> name ; } return $ items ; } else return false ; } else return $ model ; }
getPages 0 = unpublish 1 = publish
18,340
public static function getParentMenu ( $ publish = null , $ parent = null , $ type = null ) { $ criteria = new CDbCriteria ; if ( $ publish != null ) $ criteria -> compare ( 't.publish' , $ publish ) ; if ( $ parent != null ) $ criteria -> compare ( 't.parent_id' , $ parent ) ; $ model = self :: model ( ) -> findAll ( $ criteria ) ; if ( $ type == null ) { $ items = array ( ) ; if ( $ model != null ) { foreach ( $ model as $ key => $ val ) { $ items [ $ val -> id ] = $ val -> title -> message ; } return $ items ; } else { return false ; } } else return $ model ; }
getParentMenu 0 = unpublish 1 = publish
18,341
public function getResponse ( $ question , $ params = array ( ) ) { $ params = $ this -> cleanParamsAndPrintPrompt ( $ question , $ params ) ; $ response = str_replace ( array ( "\n" , "\r" ) , array ( "" , "" ) , $ this -> input ( ) ) ; return $ this -> validateResponse ( $ response , $ question , $ params ) ; }
A function for getting answers to questions from users interractively . This function takes the question and an optional array of parameters . The question is a regular string and the array provides extra information about the question being asked .
18,342
public function resetOutputLevel ( ) { if ( count ( $ this -> outputLevelStack ) > 0 ) { $ this -> setOutputLevel ( reset ( $ this -> outputLevelStack ) ) ; $ this -> outputLevelStack = array ( ) ; } }
Resets the output level stack . This method clears all items off the output level stack leaving only the current output level .
18,343
private function getStream ( $ type ) { if ( ! isset ( $ this -> streams [ $ type ] ) ) { $ this -> streams [ $ type ] = fopen ( $ this -> streamUrls [ $ type ] , $ type == 'input' ? 'r' : 'w' ) ; } return $ this -> streams [ $ type ] ; }
Returns a stream resource for a given stream type . If the stream has not been opened this method opens the stream before returning the asociated resource . This ensures that there is only one resource handle to any stream at any given time .
18,344
public function ajaxauthenticateAction ( ) { if ( $ this -> zfcUserAuthentication ( ) -> getAuthService ( ) -> hasIdentity ( ) ) { return true ; } $ adapter = $ this -> zfcUserAuthentication ( ) -> getAuthAdapter ( ) ; $ adapter -> prepareForAuthentication ( $ this -> getRequest ( ) ) ; $ auth = $ this -> zfcUserAuthentication ( ) -> getAuthService ( ) -> authenticate ( $ adapter ) ; if ( ! $ auth -> isValid ( ) ) { $ adapter -> resetAdapters ( ) ; return false ; } $ user = $ this -> zfcUserAuthentication ( ) -> getIdentity ( ) ; if ( $ user -> getState ( ) && $ user -> getState ( ) === 2 ) { $ this -> getUserService ( ) -> getUserMapper ( ) -> activate ( $ user ) ; } $ this -> getEventManager ( ) -> trigger ( 'login.post' , $ this , array ( 'user' => $ user ) ) ; return true ; }
Ajax authentication action
18,345
public function emailExistsAction ( ) { $ email = $ this -> getEvent ( ) -> getRouteMatch ( ) -> getParam ( 'email' ) ; $ request = $ this -> getRequest ( ) ; $ response = $ this -> getResponse ( ) ; $ user = $ this -> getUserService ( ) -> getUserMapper ( ) -> findByEmail ( $ email ) ; if ( empty ( $ user ) ) { $ result = [ 'result' => false ] ; } else { $ result = [ 'result' => true ] ; } $ response -> setContent ( \ Zend \ Json \ Json :: encode ( $ result ) ) ; return $ response ; }
You can search for a user based on the email
18,346
public function autoCompleteUserAction ( ) { $ field = $ this -> getEvent ( ) -> getRouteMatch ( ) -> getParam ( 'field' ) ; $ value = $ this -> getEvent ( ) -> getRouteMatch ( ) -> getParam ( 'value' ) ; $ request = $ this -> getRequest ( ) ; $ response = $ this -> getResponse ( ) ; $ result = $ this -> getUserService ( ) -> autoCompleteUser ( $ field , $ value ) ; $ response -> setContent ( \ Zend \ Json \ Json :: encode ( $ result ) ) ; return $ response ; }
You can search for a user based on any user field
18,347
public function getPrizeCategoryForm ( ) { if ( ! $ this -> prizeCategoryForm ) { $ this -> setPrizeCategoryForm ( $ this -> getServiceLocator ( ) -> get ( 'playgroundgame_prizecategoryuser_form' ) ) ; } return $ this -> prizeCategoryForm ; }
Get prizeCategoryForm .
18,348
public function getBlockAccountForm ( ) { if ( ! $ this -> blockAccountForm ) { $ this -> setBlockAccountForm ( $ this -> getServiceLocator ( ) -> get ( 'playgrounduser_blockaccount_form' ) ) ; } return $ this -> blockAccountForm ; }
Get blockAccountForm .
18,349
public function getNewsletterForm ( ) { if ( ! $ this -> newsletterForm ) { $ this -> setNewsletterForm ( $ this -> getServiceLocator ( ) -> get ( 'playgrounduser_newsletter_form' ) ) ; } return $ this -> newsletterForm ; }
Get newsletterForm .
18,350
public function getAddressForm ( ) { if ( ! $ this -> addressForm ) { $ this -> setAddressForm ( $ this -> getServiceLocator ( ) -> get ( 'playgrounduser_address_form' ) ) ; } return $ this -> addressForm ; }
Get addressForm .
18,351
public function getProviderService ( ) { if ( $ this -> providerService == null ) { $ this -> setProviderService ( $ this -> getServiceLocator ( ) -> get ( 'playgrounduser_provider_service' ) ) ; } return $ this -> providerService ; }
retourne le service social
18,352
public function getHybridAuth ( ) { if ( ! $ this -> hybridAuth ) { $ this -> hybridAuth = $ this -> getServiceLocator ( ) -> get ( 'HybridAuth' ) ; } return $ this -> hybridAuth ; }
Get the Hybrid_Auth object
18,353
public function getDefaultTheme ( $ type = 'public' ) { $ theme = OmmuThemes :: model ( ) -> find ( array ( 'select' => 'folder' , 'condition' => 'group_page = :group AND default_theme = :default' , 'params' => array ( ':group' => $ type , ':default' => '1' , ) , ) ) ; if ( $ theme !== null ) return $ theme -> folder ; else return null ; }
Get default theme from database
18,354
public static function getRulePos ( $ rules ) { $ result = 1 ; $ before = array ( ) ; $ after = array ( ) ; foreach ( $ rules as $ key => $ val ) { if ( $ key == '<module:\w+>/<controller:\w+>/<action:\w+>' ) break ; $ result ++ ; } $ i = 1 ; foreach ( $ rules as $ key => $ val ) { if ( $ i < $ result ) $ before [ $ key ] = $ val ; elseif ( $ i >= $ pos ) $ after [ $ key ] = $ val ; $ i ++ ; } return array ( 'after' => $ after , 'before' => $ before ) ; }
Split rules into two part
18,355
public function serializeStrings ( array $ strings ) { $ info = $ this -> analyzeStrings ( $ strings ) ; $ alternations = array_map ( [ $ this , 'serializeString' ] , $ info [ 'strings' ] ) ; if ( ! empty ( $ info [ 'chars' ] ) ) { array_unshift ( $ alternations , $ this -> serializeCharacterClass ( $ info [ 'chars' ] ) ) ; } $ expr = implode ( '|' , $ alternations ) ; if ( $ this -> needsParentheses ( $ info ) ) { $ expr = '(?:' . $ expr . ')' ; } return $ expr . $ info [ 'quantifier' ] ; }
Serialize given strings into a regular expression
18,356
protected function analyzeStrings ( array $ strings ) { $ info = [ 'alternationsCount' => 0 , 'quantifier' => '' ] ; if ( $ strings [ 0 ] === [ ] ) { $ info [ 'quantifier' ] = '?' ; unset ( $ strings [ 0 ] ) ; } $ chars = $ this -> getChars ( $ strings ) ; if ( count ( $ chars ) > 1 ) { ++ $ info [ 'alternationsCount' ] ; $ info [ 'chars' ] = array_values ( $ chars ) ; $ strings = array_diff_key ( $ strings , $ chars ) ; } $ info [ 'strings' ] = array_values ( $ strings ) ; $ info [ 'alternationsCount' ] += count ( $ strings ) ; return $ info ; }
Analyze given strings to determine how to serialize them
18,357
protected function getChars ( array $ strings ) { $ chars = [ ] ; foreach ( $ strings as $ k => $ string ) { if ( $ this -> isChar ( $ string ) ) { $ chars [ $ k ] = $ string [ 0 ] ; } } return $ chars ; }
Return the portion of strings that are composed of a single character
18,358
protected function getRanges ( array $ values ) { $ i = 0 ; $ cnt = count ( $ values ) ; $ start = $ values [ 0 ] ; $ end = $ start ; $ ranges = [ ] ; while ( ++ $ i < $ cnt ) { if ( $ values [ $ i ] === $ end + 1 ) { ++ $ end ; } else { $ ranges [ ] = [ $ start , $ end ] ; $ start = $ end = $ values [ $ i ] ; } } $ ranges [ ] = [ $ start , $ end ] ; return $ ranges ; }
Get the list of ranges that cover all given values
18,359
protected function serializeCharacterClass ( array $ values ) { $ expr = '[' ; foreach ( $ this -> getRanges ( $ values ) as list ( $ start , $ end ) ) { $ expr .= $ this -> serializeCharacterClassUnit ( $ start ) ; if ( $ end > $ start ) { if ( $ end > $ start + 1 ) { $ expr .= '-' ; } $ expr .= $ this -> serializeCharacterClassUnit ( $ end ) ; } } $ expr .= ']' ; return $ expr ; }
Serialize a given list of values into a character class
18,360
protected function serializeElement ( $ element ) { return ( is_array ( $ element ) ) ? $ this -> serializeStrings ( $ element ) : $ this -> serializeLiteral ( $ element ) ; }
Serialize an element from a string
18,361
protected function serializeValue ( $ value , $ escapeMethod ) { return ( $ value < 0 ) ? $ this -> meta -> getExpression ( $ value ) : $ this -> escaper -> $ escapeMethod ( $ this -> output -> output ( $ value ) ) ; }
Serialize a given value
18,362
public static function mb_ucfirst ( $ str , $ encoding = 'UTF-8' ) { $ length = mb_strlen ( $ str , $ encoding ) ; $ firstChar = mb_substr ( $ str , 0 , 1 , $ encoding ) ; $ then = mb_substr ( $ str , 1 , $ length - 1 , $ encoding ) ; return mb_strtoupper ( $ firstChar , $ encoding ) . $ then ; }
This function is missing in PHP for now .
18,363
public static function getPlugin ( $ actived = null , $ keypath = null , $ array = true ) { $ criteria = new CDbCriteria ; if ( $ actived != null ) $ criteria -> compare ( 'actived' , $ actived ) ; $ criteria -> addNotInCondition ( 'orders' , array ( 0 ) ) ; if ( $ actived == null || $ actived == 0 ) $ criteria -> order = 'folder ASC' ; else $ criteria -> order = 'orders ASC' ; $ model = self :: model ( ) -> findAll ( $ criteria ) ; if ( $ array == true ) { $ items = array ( ) ; if ( $ model != null ) { foreach ( $ model as $ key => $ val ) { if ( $ keypath == null || $ keypath == 'id' ) $ items [ $ val -> plugin_id ] = $ val -> name ; else $ items [ $ val -> folder ] = $ val -> name ; } return $ items ; } else return false ; } else return $ model ; }
getPlugin 0 = unpublish 1 = publish
18,364
public function times ( $ multiplier ) { return new self ( $ this -> getAugend ( ) -> times ( $ multiplier ) , $ this -> getAddend ( ) -> times ( $ multiplier ) ) ; }
Multiplies all items of this sum by the multiplier .
18,365
private function get_dataset ( $ index , $ apiindex ) { if ( isset ( $ this -> data [ $ index ] ) ) { return $ this -> data [ $ index ] ; } $ data = array ( ) ; foreach ( $ this -> raw as $ k => $ v ) { $ pos = strpos ( $ k , $ apiindex ) ; if ( $ pos !== 0 ) { continue ; } $ data [ ] = substr ( $ k , strlen ( $ apiindex ) ) ; } $ this -> data [ $ index ] = $ data ; return $ data ; }
Shorthand method .
18,366
public function get_lists ( $ timeperiod ) { $ lists = array ( ) ; foreach ( $ this -> get_all_lists ( ) as $ list ) { $ object = $ this -> get_list ( $ list ) ; if ( $ object -> get_time_period ( ) == $ timeperiod ) { $ lists [ ] = $ list ; } } return $ lists ; }
Grabs lists for a specific time period .
18,367
public function get_list ( $ id ) { foreach ( array ( self :: INDEX_LISTS , self :: INDEX_LIST ) as $ k ) { $ key = $ this -> baseurl . '/' . $ k . $ id ; if ( isset ( $ this -> raw [ $ key ] ) ) { return new ReadingList ( $ this -> api , $ this -> baseurl , $ id , $ this -> raw [ $ key ] ) ; } } return null ; }
Returns a list object for a specific list .
18,368
public function get_category ( $ url ) { if ( isset ( $ this -> raw [ $ url ] ) ) { return new Category ( $ this -> api , $ this -> baseurl , $ url , $ this -> raw [ $ url ] ) ; } return null ; }
So this is a category . Return a sensible object .
18,369
public static function firstLine ( string $ comment ) : string { $ docLines = \ preg_split ( '~\R~u' , $ comment ) ; if ( isset ( $ docLines [ 1 ] ) ) { return \ trim ( $ docLines [ 1 ] , "/\t *" ) ; } return '' ; }
Returns the first line of docBlock .
18,370
public static function description ( string $ comment ) : string { $ comment = \ str_replace ( "\r" , '' , \ trim ( \ preg_replace ( '/^\s*\**( |\t)?/m' , '' , trim ( $ comment , '/' ) ) ) ) ; if ( \ preg_match ( '/^\s*@\w+/m' , $ comment , $ matches , \ PREG_OFFSET_CAPTURE ) ) { $ comment = \ trim ( \ substr ( $ comment , 0 , $ matches [ 0 ] [ 1 ] ) ) ; } return $ comment ; }
Returns full description from the doc - block . If have multi line text will return multi line .
18,371
public function sendHeader ( string $ name , ? string $ value ) : void { if ( headers_sent ( $ file , $ line ) ) { throw new HttpException ( sprintf ( "Cannot use '%s()', headers already sent in %s:%s" , __method__ , $ file , $ line ) ) ; } if ( $ value === null ) { $ this -> removeHeader ( $ name ) ; header_remove ( $ name ) ; } else { $ this -> setHeader ( $ name , $ value ) ; header ( sprintf ( '%s: %s' , $ name , $ value ) ) ; } }
Send header .
18,372
public function sendCookie ( string $ name , ? string $ value , int $ expire = 0 , string $ path = '/' , string $ domain = '' , bool $ secure = false , bool $ httpOnly = false ) : void { if ( ! preg_match ( '~^[a-z0-9_\-\.]+$~i' , $ name ) ) { throw new HttpException ( "Invalid cookie name '{$name}' given" ) ; } $ value = ( string ) $ value ; if ( $ expire < 0 ) { $ value = '' ; } setcookie ( $ name , $ value , $ expire , $ path , $ domain , $ secure , $ httpOnly ) ; }
Send cookie .
18,373
public function sendCookies ( ) : void { foreach ( ( array ) $ this -> cookies as $ cookie ) { $ this -> sendCookie ( $ cookie [ 'name' ] , $ cookie [ 'value' ] , $ cookie [ 'expire' ] , $ cookie [ 'path' ] , $ cookie [ 'domain' ] , $ cookie [ 'secure' ] , $ cookie [ 'httpOnly' ] ) ; } }
Send cookies .
18,374
private function alterTableMigrate ( array $ alterDef , array $ options = [ ] ) { $ table = $ alterDef [ 'name' ] ; $ currentDef = $ this -> fetchTableDef ( $ table ) ; if ( ! self :: val ( Db :: OPTION_DROP , $ options ) ) { $ tableDef = $ this -> mergeTableDefs ( $ currentDef , $ alterDef ) ; } else { $ tableDef = $ alterDef [ 'def' ] ; } foreach ( self :: val ( 'indexes' , $ currentDef , [ ] ) as $ indexDef ) { if ( self :: val ( 'type' , $ indexDef , Db :: INDEX_IX ) === Db :: INDEX_IX ) { $ this -> dropIndex ( $ indexDef [ 'name' ] ) ; } } $ tmpTable = $ table . '_' . time ( ) ; $ this -> renameTable ( $ table , $ tmpTable ) ; $ this -> createTableDb ( $ tableDef , $ options ) ; $ columns = array_keys ( array_intersect_key ( $ tableDef [ 'columns' ] , $ currentDef [ 'columns' ] ) ) ; $ sql = 'insert into ' . $ this -> prefixTable ( $ table ) . "\n" . $ this -> bracketList ( $ columns , '`' ) . "\n" . $ this -> buildSelect ( $ tmpTable , [ ] , [ 'columns' => $ columns ] ) ; $ this -> queryDefine ( $ sql ) ; $ this -> dropTable ( $ tmpTable ) ; }
Alter a table by creating a new table and copying the old table s data to it .
18,375
protected function fetchColumnDefsDb ( string $ table ) { $ cdefs = $ this -> query ( 'pragma table_info(' . $ this -> prefixTable ( $ table , false ) . ')' ) -> fetchAll ( PDO :: FETCH_ASSOC ) ; if ( empty ( $ cdefs ) ) { return null ; } $ columns = [ ] ; $ pk = [ ] ; foreach ( $ cdefs as $ cdef ) { $ column = Db :: typeDef ( $ cdef [ 'type' ] ) ; if ( $ column === null ) { throw new \ Exception ( "Unknown type '$columnType'." , 500 ) ; } $ column [ 'allowNull' ] = ! filter_var ( $ cdef [ 'notnull' ] , FILTER_VALIDATE_BOOLEAN ) ; if ( $ cdef [ 'pk' ] ) { $ pk [ ] = $ cdef [ 'name' ] ; if ( strcasecmp ( $ cdef [ 'type' ] , 'integer' ) === 0 ) { $ column [ 'autoIncrement' ] = true ; } else { $ column [ 'primary' ] = true ; } } if ( $ cdef [ 'dflt_value' ] !== null ) { $ column [ 'default' ] = $ this -> forceType ( $ cdef [ 'dflt_value' ] , $ column [ 'type' ] ) ; } $ columns [ $ cdef [ 'name' ] ] = $ column ; } return $ columns ; }
Get the columns for a table ..
18,376
protected function fetchIndexesDb ( $ table = '' ) { $ indexes = [ ] ; $ indexInfos = $ this -> query ( 'pragma index_list(' . $ this -> prefixTable ( $ table ) . ')' ) -> fetchAll ( PDO :: FETCH_ASSOC ) ; foreach ( $ indexInfos as $ row ) { $ indexName = $ row [ 'name' ] ; if ( $ row [ 'unique' ] ) { $ type = Db :: INDEX_UNIQUE ; } else { $ type = Db :: INDEX_IX ; } $ columns = $ this -> query ( 'pragma index_info(' . $ this -> quote ( $ indexName ) . ')' ) -> fetchAll ( PDO :: FETCH_ASSOC ) ; $ index = [ 'name' => $ indexName , 'columns' => array_column ( $ columns , 'name' ) , 'type' => $ type ] ; $ indexes [ ] = $ index ; } return $ indexes ; }
Get the indexes for a table .
18,377
private function getPKValue ( $ table , array $ row , $ quick = false ) { if ( $ quick && isset ( $ row [ $ table . 'ID' ] ) ) { return [ $ table . 'ID' => $ row [ $ table . 'ID' ] ] ; } $ tdef = $ this -> fetchTableDef ( $ table ) ; $ cols = [ ] ; foreach ( $ tdef [ 'columns' ] as $ name => $ cdef ) { if ( empty ( $ cdef [ 'primary' ] ) ) { break ; } if ( ! array_key_exists ( $ name , $ row ) ) { return null ; } $ cols [ $ name ] = $ row [ $ name ] ; } return $ cols ; }
Get the primary or secondary keys from the given rows .
18,378
protected function fetchTableNamesDb ( ) { $ tables = $ this -> get ( new Identifier ( 'sqlite_master' ) , [ 'type' => 'table' , 'name' => [ Db :: OP_LIKE => $ this -> escapeLike ( $ this -> getPx ( ) ) . '%' ] ] , [ 'columns' => [ 'name' ] ] ) -> fetchAll ( PDO :: FETCH_COLUMN ) ; $ tables = array_filter ( $ tables , function ( $ name ) { return substr ( $ name , 0 , 7 ) !== 'sqlite_' ; } ) ; return $ tables ; }
Get the all of table names in the database .
18,379
public function forbidden ( ServerRequestInterface $ request , ResponseInterface $ response ) { $ contentType = $ this -> determineContentType ( $ request ) ; switch ( $ contentType ) { case 'application/json' : $ output = $ this -> renderJsonErrorMessage ( ) ; break ; case 'text/html' : $ output = $ this -> renderHtmlErrorMessage ( ) ; break ; default : throw new Exception ( 'Cannot render unknown content type ' . $ contentType ) ; } return $ response -> withStatus ( 403 ) -> withHeader ( 'Content-type' , $ contentType ) -> write ( $ output ) ; }
Forbidden HTTP 403 Response
18,380
public function request ( $ url , $ content = false , $ customRequest = false ) { $ request_parts = explode ( '/' , $ url ) ; $ request = $ request_parts [ 3 ] ; $ ch = curl_init ( ) ; curl_setopt ( $ ch , CURLOPT_URL , $ url ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , true ) ; if ( strpos ( $ url , 'test' ) ) { curl_setopt ( $ ch , CURLOPT_USERPWD , $ this -> username . ":" . $ this -> testPassword ) ; } else { curl_setopt ( $ ch , CURLOPT_USERPWD , $ this -> username . ":" . $ this -> password ) ; } curl_setopt ( $ ch , CURLOPT_HTTPHEADER , array ( "Content-Type:application/xml;charset=UTF-8" ) ) ; if ( $ content && ! $ customRequest ) { curl_setopt ( $ ch , CURLOPT_POST , 1 ) ; curl_setopt ( $ ch , CURLOPT_POSTFIELDS , $ content ) ; } if ( $ customRequest ) { curl_setopt ( $ ch , CURLOPT_CUSTOMREQUEST , $ customRequest ) ; } $ output = curl_exec ( $ ch ) ; $ outputINFO = curl_getinfo ( $ ch ) ; $ this -> log ( [ "httpcode" => $ outputINFO [ 'http_code' ] , "url" => $ url , "endpoint" => $ request , "output" => $ output ] ) ; if ( $ outputINFO [ 'http_code' ] >= 400 || curl_errno ( $ ch ) ) { $ this -> log ( curl_error ( $ ch ) , "error" ) ; $ this -> log ( $ output , "error" ) ; } else { $ this -> log ( ".datacite." . $ request . ".response:" . $ output ) ; } curl_close ( $ ch ) ; return $ output ; }
Do an actual request to the specified URL
18,381
protected function filterEligibleKeys ( array $ eligibleKeys ) { $ filteredKeys = [ ] ; foreach ( $ eligibleKeys as $ k => $ keys ) { if ( count ( $ keys ) > 1 ) { $ filteredKeys [ ] = $ keys ; } } return $ filteredKeys ; }
Filter the list of eligible keys and keep those that have at least two matches
18,382
protected function getEligibleKeys ( array $ strings ) { $ eligibleKeys = [ ] ; foreach ( $ strings as $ k => $ string ) { if ( ! is_array ( $ string [ 0 ] ) && isset ( $ string [ 1 ] ) ) { $ suffix = serialize ( array_slice ( $ string , 1 ) ) ; $ eligibleKeys [ $ suffix ] [ ] = $ k ; } } return $ this -> filterEligibleKeys ( $ eligibleKeys ) ; }
Get a list of keys of strings eligible to be merged together grouped by suffix
18,383
public function get_time_period ( ) { $ period = $ this -> data [ Parser :: INDEX_LISTS_TIME_PERIOD ] [ 0 ] [ 'value' ] ; return substr ( $ period , strpos ( $ period , Parser :: INDEX_TIME_PERIOD ) + strlen ( Parser :: INDEX_TIME_PERIOD ) ) ; }
Which time period is this list in?
18,384
public function get_items ( ) { if ( ! isset ( $ this -> data [ Parser :: INDEX_CHILDREN_SPEC ] ) ) { return array ( ) ; } $ items = array ( ) ; foreach ( $ this -> data [ Parser :: INDEX_CHILDREN_SPEC ] as $ k => $ data ) { $ items [ ] = $ this -> api -> get_item ( $ data [ 'value' ] ) ; } return $ items ; }
Items in the list .
18,385
public function get_item_count ( ) { $ data = $ this -> data ; $ count = 0 ; if ( isset ( $ data [ Parser :: INDEX_LISTS_LIST_ITEMS ] ) ) { foreach ( $ data [ Parser :: INDEX_LISTS_LIST_ITEMS ] as $ things ) { if ( preg_match ( '#/items/#' , $ things [ 'value' ] ) ) { $ count ++ ; } } } return $ count ; }
Counts the number of items in a list .
18,386
public function get_categories ( ) { $ data = $ this -> data ; if ( empty ( $ data [ Parser :: INDEX_PARENT_SPEC ] ) ) { return array ( ) ; } $ categories = array ( ) ; foreach ( $ data [ Parser :: INDEX_PARENT_SPEC ] as $ category ) { $ categories [ ] = $ this -> api -> get_category ( $ category [ 'value' ] ) ; } return $ categories ; }
Returns a list s categories .
18,387
public function get_last_updated ( $ asstring = false ) { $ data = $ this -> data ; $ time = null ; if ( isset ( $ data [ Parser :: INDEX_LISTS_LIST_UPDATED ] ) ) { $ time = $ data [ Parser :: INDEX_LISTS_LIST_UPDATED ] [ 0 ] [ 'value' ] ; $ time = strtotime ( $ time ) ; } if ( $ asstring && $ time ) { return $ this -> contextual_time ( $ time ) ; } return $ time ; }
Get the time a list was last updated .
18,388
protected function emailFromArray ( array $ arr ) { if ( isset ( $ arr [ 'address' ] ) ) { $ arr [ 'email' ] = $ arr [ 'address' ] ; unset ( $ arr [ 'address' ] ) ; } if ( ! isset ( $ arr [ 'email' ] ) ) { throw new InvalidArgumentException ( 'The array must contain at least the "address" key.' ) ; } $ email = strval ( filter_var ( $ arr [ 'email' ] , FILTER_SANITIZE_EMAIL ) ) ; if ( ! isset ( $ arr [ 'name' ] ) || $ arr [ 'name' ] === '' ) { return $ email ; } $ name = str_replace ( '"' , '' , filter_var ( $ arr [ 'name' ] , FILTER_SANITIZE_STRING ) ) ; return sprintf ( '"%s" <%s>' , $ name , $ email ) ; }
Convert an email address array to a RFC - 822 string notation .
18,389
public function add ( ) { $ position = $ this -> BannersPositions -> newEntity ( ) ; if ( $ this -> request -> is ( 'post' ) ) { $ position = $ this -> BannersPositions -> patchEntity ( $ position , $ this -> request -> getData ( ) ) ; if ( $ this -> BannersPositions -> save ( $ position ) ) { $ this -> Flash -> success ( I18N_OPERATION_OK ) ; return $ this -> redirect ( [ 'action' => 'index' ] ) ; } $ this -> Flash -> error ( I18N_OPERATION_NOT_OK ) ; } $ this -> set ( compact ( 'position' ) ) ; }
Adds banners position
18,390
public function edit ( $ id = null ) { $ position = $ this -> BannersPositions -> get ( $ id ) ; if ( $ this -> request -> is ( [ 'patch' , 'post' , 'put' ] ) ) { $ position = $ this -> BannersPositions -> patchEntity ( $ position , $ this -> request -> getData ( ) ) ; if ( $ this -> BannersPositions -> save ( $ position ) ) { $ this -> Flash -> success ( I18N_OPERATION_OK ) ; return $ this -> redirect ( [ 'action' => 'index' ] ) ; } $ this -> Flash -> error ( I18N_OPERATION_NOT_OK ) ; } $ this -> set ( compact ( 'position' ) ) ; }
Edits banners position
18,391
public function delete ( $ id = null ) { $ this -> request -> allowMethod ( [ 'post' , 'delete' ] ) ; $ position = $ this -> BannersPositions -> get ( $ id ) ; if ( ! $ position -> banner_count ) { $ this -> BannersPositions -> deleteOrFail ( $ position ) ; $ this -> Flash -> success ( I18N_OPERATION_OK ) ; } else { $ this -> Flash -> alert ( I18N_BEFORE_DELETE ) ; } return $ this -> redirect ( [ 'action' => 'index' ] ) ; }
Deletes banners position
18,392
protected function getTranslations ( $ domain ) { if ( ! isset ( $ this -> files [ $ domain ] ) ) { if ( ! isset ( $ this -> sources [ $ domain ] ) ) { $ msg = sprintf ( 'No translation directory for domain "%1$s" available' , $ domain ) ; throw new \ Aimeos \ MW \ Translation \ Exception ( $ msg ) ; } $ locations = array_reverse ( $ this -> getTranslationFileLocations ( $ this -> sources [ $ domain ] , $ this -> getLocale ( ) ) ) ; foreach ( $ locations as $ location ) { $ this -> files [ $ domain ] [ $ location ] = new \ Aimeos \ MW \ Translation \ File \ Mo ( $ location ) ; } } return ( isset ( $ this -> files [ $ domain ] ) ? $ this -> files [ $ domain ] : [ ] ) ; }
Returns the MO file objects which contain the translations .
18,393
protected function syncRelatedFields ( IdProperty $ newProp , PropertyField $ newField , IdProperty $ oldProp , PropertyField $ oldField ) { unset ( $ newProp , $ oldProp , $ oldField ) ; $ cli = $ this -> climate ( ) ; if ( ! $ this -> quiet ( ) ) { $ cli -> br ( ) ; $ cli -> comment ( 'Syncing new IDs to pivot table.' ) ; } $ pivot = $ this -> pivotModel ( ) ; $ attach = $ this -> targetModel ( ) ; $ pivotSource = $ pivot -> source ( ) ; $ pivotTable = $ pivotSource -> table ( ) ; $ attachSource = $ attach -> source ( ) ; $ attachTable = $ attachSource -> table ( ) ; $ db = $ attachSource -> db ( ) ; $ binds = [ '%pivotTable' => $ pivotTable , '%objectType' => 'object_type' , '%objectId' => 'object_id' , '%targetId' => 'attachment_id' , '%targetTable' => $ attachTable , '%targetType' => 'type' , '%newKey' => $ newField -> ident ( ) , '%oldKey' => $ attach -> key ( ) , ] ; $ sql = 'UPDATE `%pivotTable` AS p JOIN `%targetTable` AS a ON p.`%targetId` = a.`%oldKey` SET p.`%targetId` = a.`%newKey`;' ; $ db -> query ( strtr ( $ sql , $ binds ) ) ; $ sql = 'UPDATE `%pivotTable` AS p JOIN `%targetTable` AS a ON p.`%objectId` = a.`%oldKey` AND p.`%objectType` = a.`%targetType` SET p.`%objectId` = a.`%newKey`;' ; $ db -> query ( strtr ( $ sql , $ binds ) ) ; return $ this ; }
Sync the new primary keys to pivot table .
18,394
public function targetModel ( ) { if ( ! isset ( $ this -> targetModel ) ) { $ this -> targetModel = $ this -> modelFactory ( ) -> get ( Attachment :: class ) ; } return $ this -> targetModel ; }
Retrieve the model to alter .
18,395
public function pivotModel ( ) { if ( ! isset ( $ this -> pivotModel ) ) { $ this -> pivotModel = $ this -> modelFactory ( ) -> get ( Join :: class ) ; } return $ this -> pivotModel ; }
Retrieve the attachment association model .
18,396
public final function getCookie ( string $ name , ? string $ valueDefault = null ) : ? string { return $ this -> cookies [ $ name ] ?? $ valueDefault ; }
Get cookie .
18,397
public function removeCookie ( string $ name , bool $ defer = false ) : self { if ( $ this -> type == self :: TYPE_REQUEST ) { throw new HttpException ( 'You cannot modify request cookies' ) ; } unset ( $ this -> cookies [ $ name ] ) ; if ( ! $ defer ) { $ this -> sendCookie ( $ name , null , 0 ) ; } return $ this ; }
Remove cookie .
18,398
protected function loginWithCookie ( ) { $ username = $ this -> request -> getCookie ( 'login.username' ) ; $ password = $ this -> request -> getCookie ( 'login.password' ) ; if ( ! $ username || ! $ password ) { return ; } $ this -> request = $ this -> request -> withParsedBody ( compact ( 'username' , 'password' ) ) ; $ user = $ this -> Auth -> identify ( ) ; if ( ! $ user || ! $ user [ 'active' ] || $ user [ 'banned' ] ) { return $ this -> buildLogout ( ) ; } $ this -> Auth -> setUser ( $ user ) ; $ this -> LoginRecorder -> setConfig ( 'user' , $ user [ 'id' ] ) -> write ( ) ; return $ this -> redirect ( $ this -> Auth -> redirectUrl ( ) ) ; }
Internal method to login with cookie
18,399
protected function buildLogout ( ) { $ cookies = $ this -> request -> getCookieCollection ( ) -> remove ( 'login' ) -> remove ( 'sidebar-lastmenu' ) ; $ this -> request = $ this -> request -> withCookieCollection ( $ cookies ) ; $ this -> request -> getSession ( ) -> delete ( 'KCFINDER' ) ; return $ this -> redirect ( $ this -> Auth -> logout ( ) ) ; }
Internal method to logout