idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
18,200
protected function buildUpsert ( $ table , array $ row , $ options = [ ] ) { unset ( $ options [ Db :: OPTION_UPSERT ] ) ; $ sql = $ this -> buildInsert ( $ table , $ row , $ options ) ; $ updates = [ ] ; foreach ( $ row as $ key => $ value ) { $ updates [ ] = $ this -> escape ( $ key ) . ' = values(' . $ this -> escape ( $ key ) . ')' ; } $ sql .= "\non duplicate key update " . implode ( ', ' , $ updates ) ; return $ sql ; }
Build an upsert statement .
18,201
protected function indexDefString ( $ table , array $ def ) { $ indexName = $ this -> escape ( $ this -> buildIndexName ( $ table , $ def ) ) ; if ( empty ( $ def [ 'columns' ] ) ) { throw new \ DomainException ( "The `$table`.$indexName index has no columns." , 500 ) ; } switch ( self :: val ( 'type' , $ def , Db :: INDEX_IX ) ) { case Db :: INDEX_IX : return "index $indexName " . $ this -> bracketList ( $ def [ 'columns' ] , '`' ) ; case Db :: INDEX_UNIQUE : return "unique $indexName " . $ this -> bracketList ( $ def [ 'columns' ] , '`' ) ; case Db :: INDEX_PK : return "primary key " . $ this -> bracketList ( $ def [ 'columns' ] , '`' ) ; } return null ; }
Return the SDL string that defines an index .
18,202
protected function forceType ( $ value , $ type ) { $ type = strtolower ( $ type ) ; if ( $ type === 'null' ) { return null ; } elseif ( $ type === 'boolean' ) { return filter_var ( $ value , FILTER_VALIDATE_BOOLEAN ) ; } elseif ( in_array ( $ type , [ 'int' , 'integer' , 'tinyint' , 'smallint' , 'mediumint' , 'bigint' , 'unsigned big int' , 'int2' , 'int8' , 'boolean' ] ) ) { return filter_var ( $ value , FILTER_VALIDATE_INT ) ; } elseif ( in_array ( $ type , [ 'real' , 'double' , 'double precision' , 'float' , 'numeric' , 'number' , 'decimal(10,5)' ] ) ) { return filter_var ( $ value , FILTER_VALIDATE_FLOAT ) ; } else { return ( string ) $ value ; } }
Force a value into the appropriate php type based on its SQL type .
18,203
private function argValue ( $ value ) { if ( is_bool ( $ value ) ) { return ( int ) $ value ; } elseif ( $ value instanceof \ DateTimeInterface ) { return $ value -> format ( self :: MYSQL_DATE_FORMAT ) ; } else { return $ value ; } }
Convert a value into something usable as a PDO parameter .
18,204
public function detectChangedPermalink ( ) { if ( $ this -> permalinkBefore === $ this -> permalinkAfter && ! $ this -> trashed ) { return false ; } if ( $ this -> trashed ) { App :: $ externalDetector -> lookForBrokenLinks ( 'internal' , str_replace ( '__trashed' , '' , $ this -> permalinkBefore ) ) ; return true ; } global $ wpdb ; $ wpdb -> query ( $ wpdb -> prepare ( "UPDATE $wpdb->posts SET post_content = REPLACE(post_content, %s, %s) WHERE post_content LIKE %s" , $ this -> permalinkBefore , $ this -> permalinkAfter , '%' . $ wpdb -> esc_like ( $ this -> permalinkBefore ) . '%' ) ) ; $ this -> permalinksUpdated += $ wpdb -> rows_affected ; if ( $ this -> permalinksUpdated > 0 ) { add_notice ( sprintf ( '%d links to this post was updated to use the new permalink.' , $ this -> permalinksUpdated ) ) ; } return true ; }
Detect and repair
18,205
public function absolute ( $ root = null ) { Argument :: i ( ) -> test ( 1 , 'string' , 'null' ) ; if ( is_dir ( $ this -> data ) || is_file ( $ this -> data ) ) { return $ this ; } if ( is_null ( $ root ) ) { $ root = $ _SERVER [ 'DOCUMENT_ROOT' ] ; } $ absolute = $ this -> format ( $ this -> format ( $ root ) . $ this -> data ) ; if ( is_dir ( $ absolute ) || is_file ( $ absolute ) ) { $ this -> data = $ absolute ; return $ this ; } Exception :: i ( ) -> setMessage ( self :: ERROR_FULL_PATH_NOT_FOUND ) -> addVariable ( $ this -> data ) -> addVariable ( $ absolute ) -> trigger ( ) ; }
Attempts to get the full absolute path as described on the server . The path given must exist .
18,206
public function append ( $ path ) { $ argument = Argument :: i ( ) -> test ( 1 , 'string' ) ; $ paths = func_get_args ( ) ; foreach ( $ paths as $ i => $ path ) { $ argument -> test ( $ i + 1 , $ path , 'string' ) ; $ this -> data .= $ this -> format ( $ path ) ; } return $ this ; }
Adds a path to the existing one
18,207
public function prepend ( $ path ) { $ error = Argument :: i ( ) -> test ( 1 , 'string' ) ; $ paths = func_get_args ( ) ; foreach ( $ paths as $ i => $ path ) { $ error -> test ( $ i + 1 , $ path , 'string' ) ; $ this -> data = $ this -> format ( $ path ) . $ this -> data ; } return $ this ; }
Adds a path before the existing one
18,208
public function pop ( ) { $ pathArray = $ this -> getArray ( ) ; $ path = array_pop ( $ pathArray ) ; $ this -> data = implode ( '/' , $ pathArray ) ; return $ path ; }
Remove the last path
18,209
public function replace ( $ path ) { Argument :: i ( ) -> test ( 1 , 'string' ) ; $ pathArray = $ this -> getArray ( ) ; array_pop ( $ pathArray ) ; $ pathArray [ ] = $ path ; $ this -> data = implode ( '/' , $ pathArray ) ; return $ this ; }
Replaces the last path with this one
18,210
protected function format ( $ path ) { $ path = str_replace ( '\\' , '/' , $ path ) ; $ path = str_replace ( '//' , '/' , $ path ) ; if ( substr ( $ path , - 1 , 1 ) == '/' ) { $ path = substr ( $ path , 0 , - 1 ) ; } if ( substr ( $ path , 0 , 1 ) != '/' && ! preg_match ( "/^[A-Za-z]+\:/" , $ path ) ) { $ path = '/' . $ path ; } return $ path ; }
Formats the path 1 . Must start with forward slash 2 . Must not end with forward slash 3 . Must not have double forward slashes
18,211
public function set_campus ( $ campus ) { $ campus = ! is_array ( $ campus ) ? array ( $ campus ) : $ campus ; $ this -> _campus = array ( ) ; foreach ( $ campus as $ c ) { $ c = strtolower ( $ c ) ; if ( ! in_array ( $ c , array ( 'canterbury' , 'medway' ) ) ) { throw new \ Exception ( "Invalid campus: '{$campus}'." ) ; } $ this -> _campus [ ] = $ c ; } }
Set the campus we want lists from . Defaults to all lists .
18,212
public function get_item ( $ url ) { $ raw = $ this -> curl ( $ url . '.json' ) ; $ json = json_decode ( $ raw , true ) ; if ( ! $ json ) { return null ; } return new Item ( $ this , $ url , $ json ) ; }
Returns a list item given a URL .
18,213
public function get_list ( $ id , $ campus = 'current' ) { if ( $ campus == 'current' ) { $ campus = $ this -> _campus ; } if ( is_array ( $ campus ) ) { throw new \ Exception ( "Campus cannot be an array!" ) ; } $ url = self :: CANTERBURY_URL ; if ( $ campus == 'medway' ) { $ url = self :: MEDWAY_URL ; } $ raw = $ this -> curl ( $ url . '/sections/' . $ id . '.json' ) ; $ parser = new Parser ( $ this , $ url , $ raw ) ; return $ parser -> get_list ( $ id ) ; }
Returns a list given an ID .
18,214
public function postIndex ( ) { $ oInput = Factory :: service ( 'Input' ) ; $ oHttpCodes = Factory :: service ( 'HttpCodes' ) ; $ oAuthModel = Factory :: model ( 'Auth' , 'nails/module-auth' ) ; $ oAccessTokenModel = Factory :: model ( 'UserAccessToken' , 'nails/module-auth' ) ; $ sIdentifier = $ oInput -> post ( 'identifier' ) ; $ sPassword = $ oInput -> post ( 'password' ) ; $ sScope = $ oInput -> post ( 'scope' ) ; $ sLabel = $ oInput -> post ( 'label' ) ; $ bIsValid = $ oAuthModel -> verifyCredentials ( $ sIdentifier , $ sPassword ) ; if ( ! $ bIsValid ) { throw new ApiException ( 'Invalid login credentials' , $ oHttpCodes :: STATUS_UNAUTHORIZED ) ; } $ oUserModel = Factory :: model ( 'User' , 'nails/module-auth' ) ; $ oUserPasswordModel = Factory :: model ( 'UserPassword' , 'nails/module-auth' ) ; $ oUser = $ oUserModel -> getByIdentifier ( $ sIdentifier ) ; $ bIsSuspended = $ oUser -> is_suspended ; $ bPwIsTemp = $ oUser -> temp_pw ; $ bPwIsExpired = $ oUserPasswordModel -> isExpired ( $ oUser -> id ) ; if ( $ bIsSuspended ) { throw new ApiException ( 'User account is suspended' , $ oHttpCodes :: STATUS_UNAUTHORIZED ) ; } elseif ( $ bPwIsTemp ) { throw new ApiException ( 'Password is temporary' , $ oHttpCodes :: STATUS_UNAUTHORIZED ) ; } elseif ( $ bPwIsExpired ) { throw new ApiException ( 'Password has expired' , $ oHttpCodes :: STATUS_UNAUTHORIZED ) ; } $ oToken = $ oAccessTokenModel -> create ( [ 'user_id' => $ oUser -> id , 'label' => $ sLabel , 'scope' => $ sScope , ] ) ; if ( ! $ oToken ) { throw new ApiException ( 'Failed to generate access token. ' . $ oAccessTokenModel -> lastError ( ) , $ oHttpCodes :: STATUS_INTERNAL_SERVER_ERROR ) ; } return Factory :: factory ( 'ApiResponse' , 'nails/module-api' ) -> setData ( [ 'token' => $ oToken -> token , 'expires' => $ oToken -> expires , ] ) ; }
Retrieves an access token for a user
18,215
public function postRevoke ( ) { $ oHttpCodes = Factory :: service ( 'HttpCodes' ) ; $ oAccessTokenModel = Factory :: model ( 'UserAccessToken' , 'nails/module-auth' ) ; if ( ! isLoggedIn ( ) ) { throw new ApiException ( 'You must be logged in' , $ oHttpCodes :: STATUS_UNAUTHORIZED ) ; } $ oInput = Factory :: service ( 'Input' ) ; $ sAccessToken = $ oInput -> post ( 'access_token' ) ; if ( empty ( $ sAccessToken ) ) { throw new ApiException ( 'An access token to revoke must be provided' , $ oHttpCodes :: STATUS_BAD_REQUEST ) ; } if ( ! $ oAccessTokenModel -> revoke ( activeUser ( 'id' ) , $ sAccessToken ) ) { throw new ApiException ( 'Failed to revoke access token. ' . $ oAccessTokenModel -> lastError ( ) , $ oHttpCodes :: STATUS_INTERNAL_SERVER_ERROR ) ; } return Factory :: factory ( 'ApiResponse' , 'nails/module-api' ) ; }
Revoke an access token for the authenticated user
18,216
public function init ( ) { $ oInput = Factory :: service ( 'Input' ) ; $ iTestingAsUser = $ oInput -> header ( Testing :: TEST_HEADER_USER_NAME ) ; if ( Environment :: not ( Environment :: ENV_PROD ) && $ iTestingAsUser ) { $ oUser = $ this -> getById ( $ iTestingAsUser ) ; if ( empty ( $ oUser ) ) { set_status_header ( 500 ) ; ErrorHandler :: halt ( 'Not a valid user ID' ) ; } $ this -> setLoginData ( $ oUser -> id ) ; } else { $ this -> refreshSession ( ) ; if ( ! $ this -> isLoggedIn ( ) ) { $ this -> loginRememberedUser ( ) ; } } }
Initialise the generic user model
18,217
protected function loginRememberedUser ( ) { $ oConfig = Factory :: service ( 'Config' ) ; $ oConfig -> load ( 'auth/auth' ) ; if ( ! $ oConfig -> item ( 'authEnableRememberMe' ) ) { return false ; } $ remember = get_cookie ( $ this -> sRememberCookie ) ; if ( $ remember ) { $ remember = explode ( '|' , $ remember ) ; $ email = isset ( $ remember [ 0 ] ) ? $ remember [ 0 ] : null ; $ code = isset ( $ remember [ 1 ] ) ? $ remember [ 1 ] : null ; if ( $ email && $ code ) { $ user = $ this -> getByEmail ( $ email ) ; if ( $ user && $ code === $ user -> remember_code ) { $ this -> setLoginData ( $ user -> id ) ; $ this -> me = $ user -> id ; } } } return true ; }
Log in a previously logged in user
18,218
public function activeUser ( $ sKeys = '' , $ sDelimiter = ' ' ) { if ( ! $ this -> isLoggedIn ( ) ) { return false ; } if ( empty ( $ sKeys ) ) { return $ this -> activeUser ; } if ( strpos ( $ sKeys , ',' ) === false ) { $ val = isset ( $ this -> activeUser -> { trim ( $ sKeys ) } ) ? $ this -> activeUser -> { trim ( $ sKeys ) } : null ; } else { $ aKeys = explode ( ',' , $ sKeys ) ; $ aKeys = array_filter ( $ aKeys ) ; $ aOut = [ ] ; foreach ( $ aKeys as $ sKey ) { if ( isset ( $ this -> activeUser -> { trim ( $ sKey ) } ) ) { $ aOut [ ] = $ this -> activeUser -> { trim ( $ sKey ) } ; } } if ( empty ( $ aOut ) ) { $ val = null ; } else { $ val = implode ( $ sDelimiter , $ aOut ) ; } } return $ val ; }
Fetches a value from the active user s session data
18,219
public function setActiveUser ( $ oUser ) { $ this -> activeUser = $ oUser ; $ oDateTimeService = Factory :: service ( 'DateTime' ) ; $ sFormatDate = $ this -> activeUser ( 'pref_date_format' ) ; $ sFormatDate = $ sFormatDate ? $ sFormatDate : $ oDateTimeService -> getDateFormatDefaultSlug ( ) ; $ sFormatTime = $ this -> activeUser ( 'pref_time_format' ) ; $ sFormatTime = $ sFormatTime ? $ sFormatTime : $ oDateTimeService -> getTimeFormatDefaultSlug ( ) ; $ oDateTimeService -> setFormats ( $ sFormatDate , $ sFormatTime ) ; }
Set the active user
18,220
public function setLoginData ( $ mIdEmail , $ bSetSessionData = true ) { if ( is_numeric ( $ mIdEmail ) ) { $ oUser = $ this -> getById ( $ mIdEmail ) ; $ sError = 'Invalid User ID.' ; } elseif ( is_string ( $ mIdEmail ) ) { Factory :: helper ( 'email' ) ; if ( valid_email ( $ mIdEmail ) ) { $ oUser = $ this -> getByEmail ( $ mIdEmail ) ; $ sError = 'Invalid User email.' ; } else { $ this -> setError ( 'Invalid User email.' ) ; return false ; } } else { $ this -> setError ( 'Invalid user ID or email.' ) ; return false ; } if ( ! $ oUser ) { $ this -> setError ( $ sError ) ; return false ; } elseif ( $ oUser -> is_suspended ) { $ this -> setError ( 'User is suspended.' ) ; return false ; } else { $ this -> bIsLoggedIn = true ; if ( $ bSetSessionData ) { $ oSession = Factory :: service ( 'Session' , 'nails/module-auth' ) ; $ oSession -> setUserData ( [ 'id' => $ oUser -> id , 'email' => $ oUser -> email , 'group_id' => $ oUser -> group_id , ] ) ; } $ this -> setActiveUser ( $ oUser ) ; return true ; } }
Set the user s login data
18,221
public function clearLoginData ( ) { $ oSession = Factory :: service ( 'Session' , 'nails/module-auth' ) ; $ oSession -> unsetUserData ( 'id' ) ; $ oSession -> unsetUserData ( 'email' ) ; $ oSession -> unsetUserData ( 'group_id' ) ; $ this -> bIsLoggedIn = false ; $ this -> clearActiveUser ( ) ; $ this -> clearRememberCookie ( ) ; }
Clears the login data for a user
18,222
public function bIsRemembered ( ) { if ( ! is_null ( $ this -> bIsRemembered ) ) { return $ this -> bIsRemembered ; } $ cookie = get_cookie ( $ this -> sRememberCookie ) ; $ cookie = explode ( '|' , $ cookie ) ; $ this -> bIsRemembered = count ( $ cookie ) == 2 ? true : false ; return $ this -> bIsRemembered ; }
Determines whether the active user is to be remembered
18,223
public function setAdminRecoveryData ( $ loggingInAs , $ returnTo = '' ) { $ oSession = Factory :: service ( 'Session' , 'nails/module-auth' ) ; $ oInput = Factory :: service ( 'Input' ) ; $ existingRecoveryData = $ oSession -> getUserData ( $ this -> sAdminRecoveryField ) ; if ( empty ( $ existingRecoveryData ) ) { $ existingRecoveryData = [ ] ; } $ adminRecoveryData = new \ stdClass ( ) ; $ adminRecoveryData -> oldUserId = activeUser ( 'id' ) ; $ adminRecoveryData -> newUserId = $ loggingInAs ; $ adminRecoveryData -> hash = md5 ( activeUser ( 'password' ) ) ; $ adminRecoveryData -> name = activeUser ( 'first_name,last_name' ) ; $ adminRecoveryData -> email = activeUser ( 'email' ) ; $ adminRecoveryData -> returnTo = empty ( $ returnTo ) ? $ oInput -> server ( 'REQUEST_URI' ) : $ returnTo ; $ adminRecoveryData -> loginUrl = 'auth/override/login_as/' ; $ adminRecoveryData -> loginUrl .= md5 ( $ adminRecoveryData -> oldUserId ) . '/' . $ adminRecoveryData -> hash ; $ adminRecoveryData -> loginUrl .= '?returningAdmin=1' ; $ adminRecoveryData -> loginUrl = site_url ( $ adminRecoveryData -> loginUrl ) ; $ existingRecoveryData [ ] = $ adminRecoveryData ; $ oSession -> setUserData ( $ this -> sAdminRecoveryField , $ existingRecoveryData ) ; }
Adds to the admin recovery array allowing suers to login as other users multiple times and come back
18,224
public function getAdminRecoveryData ( ) { $ oSession = Factory :: service ( 'Session' , 'nails/module-auth' ) ; $ existingRecoveryData = $ oSession -> getUserData ( $ this -> sAdminRecoveryField ) ; if ( empty ( $ existingRecoveryData ) ) { return [ ] ; } else { return end ( $ existingRecoveryData ) ; } }
Returns the recovery data at the bottom of the stack i . e the most recently added
18,225
public function unsetAdminRecoveryData ( ) { $ oSession = Factory :: service ( 'Session' , 'nails/module-auth' ) ; $ aExistingRecoveryData = $ oSession -> getUserData ( $ this -> sAdminRecoveryField ) ; if ( empty ( $ aExistingRecoveryData ) ) { $ aExistingRecoveryData = [ ] ; } else { array_pop ( $ aExistingRecoveryData ) ; } $ oSession -> setUserData ( $ this -> sAdminRecoveryField , $ aExistingRecoveryData ) ; }
Removes the most recently added recovery data from the stack
18,226
public function hasPermission ( $ sSearch , $ mUser = null ) { if ( is_numeric ( $ mUser ) ) { $ oUser = $ this -> getById ( $ mUser ) ; if ( isset ( $ oUser -> acl ) ) { $ aAcl = $ oUser -> acl ; unset ( $ oUser ) ; } else { return false ; } } elseif ( isset ( $ mUser -> acl ) ) { $ aAcl = $ mUser -> acl ; } else { $ aAcl = ( array ) $ this -> activeUser ( 'acl' ) ; } $ oInput = Factory :: service ( 'Input' ) ; if ( in_array ( 'admin:superuser' , $ aAcl ) || $ oInput :: isCli ( ) ) { return true ; } $ bHasPermission = false ; $ sSearch = strtolower ( preg_replace ( '/:\*/' , ':.*' , $ sSearch ) ) ; foreach ( $ aAcl as $ sPermission ) { $ sPattern = '/^' . $ sSearch . '$/' ; $ bMatch = preg_match ( $ sPattern , $ sPermission ) ; if ( $ bMatch ) { $ bHasPermission = true ; break ; } } return $ bHasPermission ; }
Determines whether the specified user has a certain ACL permission
18,227
protected function getUserColumns ( $ sPrefix = '' , $ aCols = [ ] ) { if ( $ this -> aUserColumns === null ) { $ oDb = Factory :: service ( 'Database' ) ; $ aResult = $ oDb -> query ( 'DESCRIBE `' . $ this -> table . '`' ) -> result ( ) ; $ this -> aUserColumns = [ ] ; foreach ( $ aResult as $ oResult ) { $ this -> aUserColumns [ ] = $ oResult -> Field ; } } $ aCols = array_merge ( $ aCols , $ this -> aUserColumns ) ; return $ this -> prepareDbColumns ( $ sPrefix , $ aCols ) ; }
Defines the list of columns in the user table
18,228
protected function getMetaColumns ( $ sPrefix = '' , $ aCols = [ ] ) { if ( $ this -> aMetaColumns === null ) { $ oDb = Factory :: service ( 'Database' ) ; $ aResult = $ oDb -> query ( 'DESCRIBE `' . $ this -> tableMeta . '`' ) -> result ( ) ; $ this -> aMetaColumns = [ ] ; foreach ( $ aResult as $ oResult ) { if ( $ oResult -> Field !== 'user_id' ) { $ this -> aMetaColumns [ ] = $ oResult -> Field ; } } } $ aCols = array_merge ( $ aCols , $ this -> aMetaColumns ) ; return $ this -> prepareDbColumns ( $ sPrefix , $ aCols ) ; }
Defines the list of columns in the meta table
18,229
protected function prepareDbColumns ( $ sPrefix = '' , $ aCols = [ ] ) { $ aCols = array_unique ( $ aCols ) ; $ aCols = array_filter ( $ aCols ) ; if ( $ sPrefix ) { foreach ( $ aCols as $ key => & $ value ) { $ value = $ sPrefix . '.' . $ value ; } } return $ aCols ; }
Filter out duplicates and prefix column names if necessary
18,230
public function getByIdentifier ( $ identifier ) { switch ( APP_NATIVE_LOGIN_USING ) { case 'EMAIL' : $ user = $ this -> getByEmail ( $ identifier ) ; break ; case 'USERNAME' : $ user = $ this -> getByUsername ( $ identifier ) ; break ; default : Factory :: helper ( 'email' ) ; if ( valid_email ( $ identifier ) ) { $ user = $ this -> getByEmail ( $ identifier ) ; } else { $ user = $ this -> getByUsername ( $ identifier ) ; } break ; } return $ user ; }
Look up a user by their identifier
18,231
public function getByEmail ( $ email ) { if ( ! is_string ( $ email ) ) { return false ; } $ oDb = Factory :: service ( 'Database' ) ; $ oDb -> select ( 'user_id' ) ; $ oDb -> where ( 'email' , trim ( $ email ) ) ; $ user = $ oDb -> get ( $ this -> tableEmail ) -> row ( ) ; return $ user ? $ this -> getById ( $ user -> user_id ) : false ; }
Get a user by their email address
18,232
public function getByUsername ( $ username ) { if ( ! is_string ( $ username ) ) { return false ; } $ data = [ 'where' => [ [ 'column' => $ this -> tableAlias . '.username' , 'value' => $ username , ] , ] , ] ; $ user = $ this -> getAll ( null , null , $ data ) ; return empty ( $ user ) ? false : $ user [ 0 ] ; }
Get a user by their username
18,233
public function getByHashes ( $ md5Id , $ md5Pw ) { if ( empty ( $ md5Id ) || empty ( $ md5Pw ) ) { return false ; } $ data = [ 'where' => [ [ 'column' => $ this -> tableAlias . '.id_md5' , 'value' => $ md5Id , ] , [ 'column' => $ this -> tableAlias . '.password_md5' , 'value' => $ md5Pw , ] , ] , ] ; $ user = $ this -> getAll ( null , null , $ data ) ; return empty ( $ user ) ? false : $ user [ 0 ] ; }
Get a specific user by a MD5 hash of their ID and password
18,234
public function getByReferral ( $ referralCode ) { if ( ! is_string ( $ referralCode ) ) { return false ; } $ data = [ 'where' => [ [ 'column' => $ this -> tableAlias . '.referral' , 'value' => $ referralCode , ] , ] , ] ; $ user = $ this -> getAll ( null , null , $ data ) ; return empty ( $ user ) ? false : $ user [ 0 ] ; }
Get a user by their referral code
18,235
public function getEmailsForUser ( $ id ) { $ oDb = Factory :: service ( 'Database' ) ; $ oDb -> where ( 'user_id' , $ id ) ; $ oDb -> order_by ( 'date_added' ) ; $ oDb -> order_by ( 'email' , 'ASC' ) ; return $ oDb -> get ( $ this -> tableEmail ) -> result ( ) ; }
Get all the email addresses which are registered to a particular user ID
18,236
public function setCacheUser ( $ iUserId , $ aData = [ ] ) { $ this -> unsetCacheUser ( $ iUserId ) ; $ oUser = $ this -> getById ( $ iUserId ) ; if ( empty ( $ oUser ) ) { return false ; } $ this -> setCache ( $ this -> prepareCacheKey ( $ this -> tableIdColumn , $ oUser -> id , $ aData ) , $ oUser ) ; return true ; }
Saves a user object to the persistent cache
18,237
public function emailAddSendVerify ( $ email_id , $ iUserId = null ) { $ oDb = Factory :: service ( 'Database' ) ; $ oDb -> select ( [ $ this -> tableEmailAlias . '.id' , $ this -> tableEmailAlias . '.code' , $ this -> tableEmailAlias . '.is_verified' , $ this -> tableEmailAlias . '.user_id' , $ this -> tableAlias . '.group_id' , ] ) ; if ( is_numeric ( $ email_id ) ) { $ oDb -> where ( $ this -> tableEmailAlias . '.id' , $ email_id ) ; } else { $ oDb -> where ( $ this -> tableEmailAlias . '.email' , $ email_id ) ; } if ( ! empty ( $ iUserId ) ) { $ oDb -> where ( $ this -> tableEmailAlias . '.user_id' , $ iUserId ) ; } $ oDb -> join ( $ this -> table . ' ' . $ this -> tableAlias , $ this -> tableAlias . '.id = ' . $ this -> tableEmailAlias . '.user_id' ) ; $ oEmailRow = $ oDb -> get ( $ this -> tableEmail . ' ' . $ this -> tableEmailAlias ) -> row ( ) ; if ( ! $ oEmailRow ) { $ this -> setError ( 'Invalid Email.' ) ; return false ; } if ( $ oEmailRow -> is_verified ) { $ this -> setError ( 'Email is already verified.' ) ; return false ; } $ oEmailer = Factory :: service ( 'Emailer' , 'nails/module-email' ) ; $ oEmail = new \ stdClass ( ) ; $ oEmail -> type = 'verify_email_' . $ oEmailRow -> group_id ; $ oEmail -> to_id = $ oEmailRow -> user_id ; $ oEmail -> data = new \ stdClass ( ) ; $ oEmail -> data -> verifyUrl = site_url ( 'email/verify/' . $ oEmailRow -> user_id . '/' . $ oEmailRow -> code ) ; if ( ! $ oEmailer -> send ( $ oEmail , true ) ) { $ oEmail -> type = 'verify_email' ; if ( ! $ oEmailer -> send ( $ oEmail , true ) ) { $ this -> setError ( 'The verification email failed to send.' ) ; return false ; } } return true ; }
Send or resend the verify email for a particular email address
18,238
public function emailMakePrimary ( $ mIdEmail , $ iUserId = null ) { $ oDb = Factory :: service ( 'Database' ) ; $ oDb -> select ( 'id,user_id,email' ) ; if ( is_numeric ( $ mIdEmail ) ) { $ oDb -> where ( 'id' , $ mIdEmail ) ; } else { $ oDb -> where ( 'email' , $ mIdEmail ) ; } if ( ! is_null ( $ iUserId ) ) { $ oDb -> where ( 'user_id' , $ iUserId ) ; } $ oEmail = $ oDb -> get ( $ this -> tableEmail ) -> row ( ) ; if ( empty ( $ oEmail ) ) { return false ; } $ oDb -> trans_begin ( ) ; try { $ oDb -> set ( 'is_primary' , false ) ; $ oDb -> where ( 'user_id' , $ oEmail -> user_id ) ; $ oDb -> update ( $ this -> tableEmail ) ; $ oDb -> set ( 'is_primary' , true ) ; $ oDb -> where ( 'id' , $ oEmail -> id ) ; $ oDb -> update ( $ this -> tableEmail ) ; $ this -> unsetCacheUser ( $ oEmail -> user_id ) ; if ( $ oEmail -> user_id == $ this -> activeUser ( 'id' ) ) { $ oDate = Factory :: factory ( 'DateTime' ) ; $ this -> activeUser -> last_update = $ oDate -> format ( 'Y-m-d H:i:s' ) ; } $ oDb -> trans_commit ( ) ; return true ; } catch ( \ Exception $ e ) { $ this -> setError ( 'Failed to set primary email. ' . $ e -> getMessage ( ) ) ; $ oDb -> trans_rollback ( ) ; return false ; } }
Sets an email address as the primary email address for that user .
18,239
public function incrementFailedLogin ( $ iUserId , $ expires = 300 ) { $ oDate = Factory :: factory ( 'DateTime' ) ; $ oDate -> add ( new \ DateInterval ( 'PT' . $ expires . 'S' ) ) ; $ oDb = Factory :: service ( 'Database' ) ; $ oDb -> set ( 'failed_login_count' , '`failed_login_count`+1' , false ) ; $ oDb -> set ( 'failed_login_expires' , $ oDate -> format ( 'Y-m-d H:i:s' ) ) ; return $ this -> update ( $ iUserId ) ; }
Increment the user s failed logins
18,240
public function resetFailedLogin ( $ iUserId ) { $ oDb = Factory :: service ( 'Database' ) ; $ oDb -> set ( 'failed_login_count' , 0 ) ; $ oDb -> set ( 'failed_login_expires' , 'null' , false ) ; return $ this -> update ( $ iUserId ) ; }
Reset a user s failed login
18,241
public function setRememberCookie ( $ iId = null , $ sPassword = null , $ sEmail = null ) { $ oConfig = Factory :: service ( 'Config' ) ; $ oConfig -> load ( 'auth/auth' ) ; if ( ! $ oConfig -> item ( 'authEnableRememberMe' ) ) { return false ; } if ( empty ( $ iId ) || empty ( $ sPassword ) || empty ( $ sEmail ) ) { if ( ! activeUser ( 'id' ) || ! activeUser ( 'password' ) || ! activeUser ( 'email' ) ) { return false ; } else { $ iId = $ this -> activeUser ( 'id' ) ; $ sPassword = $ this -> activeUser ( 'password' ) ; $ sEmail = $ this -> activeUser ( 'email' ) ; } } $ oEncrypt = Factory :: service ( 'Encrypt' ) ; $ sSalt = $ oEncrypt -> encode ( sha1 ( $ iId . $ sPassword . $ sEmail . APP_PRIVATE_KEY . time ( ) ) ) ; $ oDb = Factory :: service ( 'Database' ) ; $ oDb -> set ( 'remember_code' , $ sSalt ) ; $ oDb -> where ( 'id' , $ iId ) ; $ oDb -> update ( $ this -> table ) ; set_cookie ( [ 'name' => $ this -> sRememberCookie , 'value' => $ sEmail . '|' . $ sSalt , 'expire' => 1209600 , ] ) ; $ this -> bIsRemembered = true ; return true ; }
Set the user s rememberMe cookie nom nom nom
18,242
protected function refreshSession ( ) { $ oSession = Factory :: service ( 'Session' , 'nails/module-auth' ) ; if ( $ this -> wasAdmin ( ) ) { $ recoveryData = $ this -> getAdminRecoveryData ( ) ; if ( ! empty ( $ recoveryData -> newUserId ) ) { $ me = $ recoveryData -> newUserId ; } else { $ me = $ oSession -> getUserData ( 'id' ) ; } } else { $ me = $ oSession -> getUserData ( 'id' ) ; } if ( ! $ me ) { $ me = $ this -> me ; if ( ! $ me ) { return false ; } } $ me = $ this -> getById ( $ me ) ; if ( ! $ me || ! empty ( $ me -> is_suspended ) ) { $ this -> clearRememberCookie ( ) ; $ this -> clearActiveUser ( ) ; $ this -> clearLoginData ( ) ; $ this -> bIsLoggedIn = false ; return false ; } $ this -> setActiveUser ( $ me ) ; $ this -> bIsLoggedIn = true ; $ oDb = Factory :: service ( 'Database' ) ; $ oInput = Factory :: service ( 'Input' ) ; $ oDb -> set ( 'last_seen' , 'NOW()' , false ) ; $ oDb -> set ( 'last_ip' , $ oInput -> ipAddress ( ) ) ; $ oDb -> where ( 'id' , $ me -> id ) ; $ oDb -> update ( $ this -> table ) ; return true ; }
Refresh the user s session from the database
18,243
protected function generateReferral ( ) { Factory :: helper ( 'string' ) ; $ oDb = Factory :: service ( 'Database' ) ; $ sReferral = '' ; while ( 1 > 0 ) { $ sReferral = random_string ( 'alnum' , 8 ) ; $ oQuery = $ oDb -> get_where ( $ this -> table , [ 'referral' => $ sReferral ] ) ; if ( $ oQuery -> num_rows ( ) == 0 ) { break ; } } return $ sReferral ; }
Generates a valid referral code
18,244
public function isValidUsername ( $ username , $ checkDb = false , $ ignoreUserId = null ) { $ invalidChars = '/[^a-zA-Z0-9\-_\.]/' ; $ minLength = 2 ; $ containsInvalidChars = preg_match ( $ invalidChars , $ username ) ; if ( $ containsInvalidChars ) { $ msg = 'Username can only contain alpha numeric characters, underscores, periods and dashes (no spaces).' ; $ this -> setError ( $ msg ) ; return false ; } if ( strlen ( $ username ) < $ minLength ) { $ this -> setError ( 'Usernames must be at least ' . $ minLength . ' characters long.' ) ; return false ; } if ( $ checkDb ) { $ oDb = Factory :: service ( 'Database' ) ; $ oDb -> where ( 'username' , $ username ) ; if ( ! empty ( $ ignoreUserId ) ) { $ oDb -> where ( 'id !=' , $ ignoreUserId ) ; } if ( $ oDb -> count_all_results ( $ this -> table ) ) { $ this -> setError ( 'Username is already in use.' ) ; return false ; } } return true ; }
Checks whether a username is valid
18,245
public function describeFields ( $ sTable = null ) { $ aFields = parent :: describeFields ( $ sTable ) ; $ aMetaFields = parent :: describeFields ( $ this -> tableMeta ) ; unset ( $ aMetaFields [ 'user_id' ] ) ; return array_merge ( $ aFields , $ aMetaFields ) ; }
Describes the fields for this model
18,246
public function dayOfWeekLocal ( string $ locale = null ) : int { $ calendar = $ this -> createCalendar ( $ locale ) ; return $ calendar -> get ( \ IntlCalendar :: FIELD_DOW_LOCAL ) ; }
Returns the day of the week for the specified locale .
18,247
public function attachmentTypes ( ) { $ attachableObjects = $ this -> attachableObjects ( ) ; $ out = [ ] ; if ( ! $ attachableObjects ) { return $ out ; } $ i = 0 ; foreach ( $ attachableObjects as $ attType => $ attMeta ) { $ i ++ ; $ label = $ attMeta [ 'label' ] ; $ out [ ] = [ 'id' => ( isset ( $ attMeta [ 'att_id' ] ) ? $ attMeta [ 'att_id' ] : null ) , 'ident' => $ this -> createIdent ( $ attType ) , 'skipForm' => $ attMeta [ 'skipForm' ] , 'formIdent' => $ attMeta [ 'formIdent' ] , 'quickFormIdent' => $ attMeta [ 'quickFormIdent' ] , 'hasFaIcon' => ! ! $ attMeta [ 'faIcon' ] , 'faIcon' => $ attMeta [ 'faIcon' ] , 'label' => $ label , 'val' => $ attType , 'locked' => $ attMeta [ 'locked' ] , 'active' => ( $ i == 1 ) ] ; } return $ out ; }
Retrieve the attachment types with their collections .
18,248
public function attachments ( ) { $ attachableObjects = $ this -> attachableObjects ( ) ; $ attachments = $ this -> obj ( ) -> getAttachments ( [ 'group' => $ this -> group ( ) ] ) ; foreach ( $ attachments as $ attachment ) { $ GLOBALS [ 'widget_template' ] = ( string ) $ attachment -> rawPreview ( ) ; if ( isset ( $ attachableObjects [ $ attachment -> objType ( ) ] ) ) { $ attachment -> attachmentType = $ attachableObjects [ $ attachment -> objType ( ) ] ; } else { continue ; } yield $ attachment ; $ GLOBALS [ 'widget_template' ] = '' ; } }
Attachment by groups .
18,249
public function setData ( array $ data ) { $ this -> isMergingData = true ; $ data = array_merge ( $ _GET , $ data ) ; parent :: setData ( $ data ) ; $ data = $ this -> mergePresets ( $ data ) ; parent :: setData ( $ data ) ; $ this -> isMergingData = false ; if ( $ this -> lang ( ) ) { $ this -> translator ( ) -> setLocale ( $ this -> lang ( ) ) ; } return $ this ; }
Set the widget s data .
18,250
public function setAttachmentOptions ( array $ settings ) { $ this -> attachmentOptions = array_merge ( $ this -> defaultAttachmentOptions ( ) , $ this -> parseAttachmentOptions ( $ settings ) ) ; return $ this ; }
Set the attachment widget settings .
18,251
public function setGroup ( $ group ) { if ( ! is_string ( $ group ) && $ group !== null ) { throw new InvalidArgumentException ( sprintf ( 'Attachment group must be string, received %s' , is_object ( $ group ) ? get_class ( $ group ) : gettype ( $ group ) ) ) ; } $ this -> group = $ group ; return $ this ; }
Set the widget s attachment grouping .
18,252
public function attachmentOptions ( ) { if ( $ this -> attachmentOptions === null ) { $ this -> attachmentOptions = $ this -> defaultAttachmentOptions ( ) ; } return $ this -> attachmentOptions ; }
Retrieve the attachment options .
18,253
public function widgetOptions ( ) { $ options = [ 'obj_type' => $ this -> obj ( ) -> objType ( ) , 'obj_id' => $ this -> obj ( ) -> id ( ) , 'group' => $ this -> group ( ) , 'attachment_options' => $ this -> attachmentOptions ( ) , 'attachable_objects' => $ this -> attachableObjects ( ) , 'title' => $ this -> title ( ) , 'lang' => $ this -> translator ( ) -> getLocale ( ) ] ; return json_encode ( $ options , true ) ; }
Retrieve the current widget s options as a JSON object .
18,254
public function equals ( Money $ money ) { if ( ! $ money instanceof MultiCurrencyMoney ) { return false ; } return $ money -> currency == $ this -> currency && $ money -> getAmount ( ) == $ this -> getAmount ( ) ; }
Tests if two objects are of equal value .
18,255
public function reduce ( BankInterface $ bank = null , $ toCurrency = null ) { if ( null === $ bank ) { $ bank = static :: getBank ( ) ; } if ( ! $ bank instanceof MultiCurrencyBankInterface ) { throw new \ InvalidArgumentException ( 'The supplied bank must implement MultiCurrencyBankInterface' ) ; } $ rate = $ bank -> getRate ( $ this -> currency , $ toCurrency ) ; $ rounder = $ bank -> getRounder ( ) ; $ amount = bcmul ( $ this -> getAmount ( ) , $ rate , $ rounder -> getPrecision ( ) + 1 ) ; return $ bank -> createMoney ( $ rounder -> round ( $ amount , $ toCurrency ) , $ toCurrency ) ; }
Reduces the value of this object to the supplied currency .
18,256
public function build ( array $ strings ) { $ strings = array_unique ( $ strings ) ; sort ( $ strings ) ; if ( $ this -> isEmpty ( $ strings ) ) { return '' ; } $ strings = $ this -> splitStrings ( $ strings ) ; $ strings = $ this -> meta -> replaceMeta ( $ strings ) ; $ strings = $ this -> runner -> run ( $ strings ) ; return $ this -> serializer -> serializeStrings ( $ strings ) ; }
Build and return a regular expression that matches all of the given strings
18,257
public function render ( $ view = null , $ layout = null ) { $ this -> set ( 'priorities' , [ '1' => sprintf ( '1 - %s' , __d ( 'me_cms' , 'Very low' ) ) , '2' => sprintf ( '2 - %s' , __d ( 'me_cms' , 'Low' ) ) , '3' => sprintf ( '3 - %s' , __d ( 'me_cms' , 'Normal' ) ) , '4' => sprintf ( '4 - %s' , __d ( 'me_cms' , 'High' ) ) , '5' => sprintf ( '5 - %s' , __d ( 'me_cms' , 'Very high' ) ) ] ) ; return parent :: render ( $ view , $ layout ) ; }
Renders view for given template file and layout
18,258
public function updateAddress ( array $ data , $ user ) { $ this -> getEventManager ( ) -> trigger ( 'updateInfo.pre' , $ this , array ( 'user' => $ user , 'data' => $ data ) ) ; $ form = $ this -> getServiceManager ( ) -> get ( 'playgrounduser_address_form' ) ; $ form -> bind ( $ user ) ; $ form -> setData ( $ data ) ; $ filter = $ user -> getInputFilter ( ) ; $ filter -> remove ( 'password' ) ; $ filter -> remove ( 'passwordVerify' ) ; $ filter -> remove ( 'dob' ) ; $ form -> setInputFilter ( $ filter ) ; if ( $ form -> isValid ( ) ) { $ user = $ this -> getUserMapper ( ) -> update ( $ user ) ; $ this -> getEventManager ( ) -> trigger ( 'updateInfo.post' , $ this , array ( 'user' => $ user , 'data' => $ data ) ) ; if ( $ user ) { return $ user ; } } return false ; }
Update user address informations
18,259
public function getCSV ( $ array ) { ob_start ( ) ; $ out = fopen ( 'php://output' , 'w' ) ; fputcsv ( $ out , array_keys ( $ array [ 0 ] ) , ";" ) ; array_shift ( $ array ) ; foreach ( $ array as $ line ) { fputcsv ( $ out , $ line , ";" ) ; } fclose ( $ out ) ; return ob_get_clean ( ) ; }
getCSV creates lines of CSV and returns it .
18,260
public function getProviderService ( ) { if ( $ this -> providerService == null ) { $ this -> setProviderService ( $ this -> getServiceManager ( ) -> get ( 'playgrounduser_provider_service' ) ) ; } return $ this -> providerService ; }
retourne le service provider
18,261
public function addEnableCommentsField ( ) { Cache :: clear ( false , '_cake_model_' ) ; foreach ( [ 'Pages' , 'Posts' ] as $ table ) { $ Table = $ this -> loadModel ( 'MeCms.' . $ table ) ; if ( ! $ Table -> getSchema ( ) -> hasColumn ( 'enable_comments' ) ) { $ Table -> getConnection ( ) -> execute ( sprintf ( 'ALTER TABLE `%s` ADD `enable_comments` BOOLEAN NOT NULL DEFAULT TRUE AFTER `preview`' , $ Table -> getTable ( ) ) ) ; } } }
Adds the enable_comments field to Pages and Posts tables
18,262
public function alterTagColumnSize ( ) { $ Tags = $ this -> loadModel ( 'MeCms.Tags' ) ; if ( $ Tags -> getSchema ( ) -> getColumn ( 'tag' ) [ 'length' ] < 255 ) { $ Tags -> getConnection ( ) -> execute ( 'ALTER TABLE tags MODIFY tag varchar(255) NOT NULL' ) ; } }
Alter the length of the tag column of the tags table
18,263
public function execute ( Arguments $ args , ConsoleIo $ io ) { $ this -> addEnableCommentsField ( ) ; $ this -> alterTagColumnSize ( ) ; $ this -> deleteOldDirectories ( ) ; return null ; }
Performs some updates to the database or files needed for versioning
18,264
public static function getSchemaVersion ( $ xml ) { $ doiXML = new \ DOMDocument ( ) ; $ doiXML -> loadXML ( $ xml ) ; $ resources = $ doiXML -> getElementsByTagName ( 'resource' ) ; $ theSchema = 'unknown' ; if ( $ resources -> length > 0 ) { if ( isset ( $ resources -> item ( 0 ) -> attributes -> item ( 0 ) -> name ) ) { $ theSchema = substr ( $ resources -> item ( 0 ) -> attributes -> item ( 0 ) -> nodeValue , strpos ( $ resources -> item ( 0 ) -> attributes -> item ( 0 ) -> nodeValue , "/meta/kernel" ) + 5 ) ; } } return $ theSchema ; }
determines datacite xml schema version xsd
18,265
public static function replaceDOIValue ( $ doiValue , $ xml ) { $ doiXML = new \ DOMDocument ( ) ; $ doiXML -> loadXML ( $ xml ) ; $ currentIdentifier = $ doiXML -> getElementsByTagName ( 'identifier' ) ; for ( $ i = 0 ; $ i < $ currentIdentifier -> length ; $ i ++ ) { $ doiXML -> getElementsByTagName ( 'resource' ) -> item ( 0 ) -> removeChild ( $ currentIdentifier -> item ( $ i ) ) ; } $ newIdentifier = $ doiXML -> createElement ( 'identifier' , $ doiValue ) ; $ newIdentifier -> setAttribute ( 'identifierType' , "DOI" ) ; $ doiXML -> getElementsByTagName ( 'resource' ) -> item ( 0 ) -> insertBefore ( $ newIdentifier , $ doiXML -> getElementsByTagName ( 'resource' ) -> item ( 0 ) -> firstChild ) ; return $ doiXML -> saveXML ( ) ; }
Replaces the DOI Identifier value in the provided XML
18,266
public static function getDOIValue ( $ xml ) { $ doiXML = new \ DOMDocument ( ) ; $ doiXML -> loadXML ( $ xml ) ; $ currentIdentifier = $ doiXML -> getElementsByTagName ( 'identifier' ) ; return $ currentIdentifier -> item ( 0 ) -> nodeValue ; }
Gets the DOI Identifier value in the provided XML
18,267
public function showUsers ( ) { $ userMapper = ( $ this -> container -> dataMapper ) ( 'UserMapper' ) ; $ users = $ userMapper -> find ( ) ; return $ this -> render ( 'users.html' , $ users ) ; }
Show All Users
18,268
public function versions ( ) { $ Plugin = new BasePlugin ; $ plugins [ 'me_cms' ] = trim ( file_get_contents ( $ Plugin -> path ( 'MeCms' , 'version' ) ) ) ; foreach ( $ Plugin -> all ( [ 'exclude' => 'MeCms' ] ) as $ plugin ) { $ file = $ Plugin -> path ( $ plugin , 'version' , true ) ; $ plugins [ 'others' ] [ $ plugin ] = __d ( 'me_cms' , 'n.a.' ) ; if ( $ file ) { $ plugins [ 'others' ] [ $ plugin ] = trim ( file_get_contents ( $ file ) ) ; } } return $ plugins ; }
Returns the version number for each plugin
18,269
protected function _isWriteable ( $ paths ) { foreach ( ( array ) $ paths as $ path ) { $ result [ $ path ] = is_writable_resursive ( $ path ) ; } return $ result ; }
Checks if each path is writeable
18,270
public function setForm ( $ formOrContainer ) { if ( ! $ formOrContainer instanceof FormInterface && ! $ formOrContainer instanceof Container ) { throw new \ InvalidArgumentException ( 'Parameter must be either of type "\Zend\Form\FormInterface" or "\Core\Form\Container"' ) ; } $ this -> form = $ formOrContainer ; $ this -> generateCheckboxes ( ) ; return $ this ; }
Sets the target form or form container .
18,271
protected function prepareCheckboxes ( array $ boxes , $ prefix ) { foreach ( $ boxes as $ box ) { if ( is_array ( $ box ) ) { $ this -> prepareCheckboxes ( $ box , $ prefix ) ; } else { $ box -> setName ( $ prefix . $ box -> getName ( ) ) ; } } }
Prepares the checkboxes prior to the rendering .
18,272
protected function createCheckbox ( $ name , $ options ) { $ box = new Checkbox ( $ name , $ options ) ; $ box -> setAttribute ( 'checked' , true ) -> setAttribute ( 'id' , preg_replace ( array ( '~\[~' , '~\]~' , '~--+~' , '~-$~' ) , array ( '-' , '' , '-' , '' ) , $ name ) ) ; return $ box ; }
Creates a toggle checkbox .
18,273
protected function buildLinks ( $ links , array $ linksOptions = [ ] ) { return array_map ( function ( $ link ) use ( $ linksOptions ) { return $ this -> Html -> link ( $ link [ 0 ] , $ link [ 1 ] , $ linksOptions ) ; } , $ links ) ; }
Internal method to build links converting them from array to html
18,274
protected function getMenuMethods ( $ plugin ) { $ methods = get_child_methods ( sprintf ( '\%s\View\Helper\MenuHelper' , $ plugin ) ) ; return $ methods ? array_values ( preg_grep ( '/^(?!_).+$/' , $ methods ) ) : [ ] ; }
Internal method to get all menu methods names from a plugin
18,275
public function generate ( $ plugin ) { $ methods = $ this -> getMenuMethods ( $ plugin ) ; if ( empty ( $ methods ) ) { return [ ] ; } $ className = sprintf ( '%s.Menu' , $ plugin ) ; $ helper = $ this -> _View -> loadHelper ( $ className , compact ( 'className' ) ) ; $ menus = [ ] ; foreach ( $ methods as $ method ) { list ( $ links , $ title , $ titleOptions ) = call_user_func ( [ $ helper , $ method ] ) ; if ( empty ( $ links ) || empty ( $ title ) ) { continue ; } $ menus [ sprintf ( '%s.%s' , $ plugin , $ method ) ] = compact ( 'links' , 'title' , 'titleOptions' ) ; } return $ menus ; }
Generates all menus for a plugin
18,276
public function renderAsCollapse ( $ plugin ) { return implode ( PHP_EOL , array_map ( function ( $ menu ) { $ collapseName = 'collapse-' . strtolower ( Text :: slug ( $ menu [ 'title' ] ) ) ; $ titleOptions = optionsParser ( $ menu [ 'titleOptions' ] , [ 'aria-controls' => $ collapseName , 'aria-expanded' => 'false' , 'class' => 'collapsed' , 'data-toggle' => 'collapse' , ] ) ; $ mainLink = $ this -> Html -> link ( $ menu [ 'title' ] , '#' . $ collapseName , $ titleOptions -> toArray ( ) ) ; $ links = $ this -> Html -> div ( 'collapse' , $ this -> buildLinks ( $ menu [ 'links' ] ) , [ 'id' => $ collapseName ] ) ; return $ this -> Html -> div ( 'card' , $ mainLink . PHP_EOL . $ links ) ; } , $ this -> generate ( $ plugin ) ) ) ; }
Renders a menu as collapse
18,277
public function renderAsDropdown ( $ plugin , array $ titleOptions = [ ] ) { return array_map ( function ( $ menu ) use ( $ titleOptions ) { $ titleOptions = optionsParser ( $ menu [ 'titleOptions' ] , $ titleOptions ) ; $ links = $ this -> buildLinks ( $ menu [ 'links' ] , [ 'class' => 'dropdown-item' ] ) ; return $ this -> Dropdown -> menu ( $ menu [ 'title' ] , $ links , $ titleOptions -> toArray ( ) ) ; } , $ this -> generate ( $ plugin ) ) ; }
Renders a menu as dropdown
18,278
protected function buildElementsByBlock ( $ elements ) { if ( empty ( $ elements ) ) { return $ elements ; } $ output = [ ] ; foreach ( $ elements as $ element ) { $ output [ $ element -> block_key ] [ ] = $ element ; } return $ output ; }
Build Page Elements by Block
18,279
protected function buildPageSettings ( $ settings ) { if ( empty ( $ settings ) ) { return $ settings ; } $ output = [ ] ; foreach ( $ settings as $ setting ) { $ output [ $ setting -> setting_key ] = $ setting -> setting_value ; } return $ output ; }
Build Page Settings
18,280
public function setFrom ( $ address , $ name = null ) : EmailInterface { $ this -> mailer -> setFrom ( $ address , $ name , false ) ; return $ this ; }
Set From Address
18,281
public function setTo ( $ address , $ name = null ) : EmailInterface { $ this -> mailer -> addAddress ( $ address , $ name ) ; return $ this ; }
Set Recipient To Address
18,282
public function mergeSettings ( array $ savedSettings , array $ definedSettings ) { $ pageSetting = isset ( $ savedSettings [ 0 ] -> category ) ? false : true ; $ settingIndex = array_combine ( array_column ( $ savedSettings , 'setting_key' ) , array_keys ( $ savedSettings ) ) ; foreach ( $ definedSettings as $ defKey => $ setting ) { if ( isset ( $ settingIndex [ $ setting -> key ] ) ) { $ definedSettings [ $ defKey ] -> id = $ savedSettings [ $ settingIndex [ $ setting -> key ] ] -> id ; $ definedSettings [ $ defKey ] -> setting_value = $ savedSettings [ $ settingIndex [ $ setting -> key ] ] -> setting_value ; $ definedSettings [ $ defKey ] -> created_by = $ savedSettings [ $ settingIndex [ $ setting -> key ] ] -> created_by ; $ definedSettings [ $ defKey ] -> created_date = $ savedSettings [ $ settingIndex [ $ setting -> key ] ] -> created_date ; $ definedSettings [ $ defKey ] -> updated_by = $ savedSettings [ $ settingIndex [ $ setting -> key ] ] -> updated_by ; $ definedSettings [ $ defKey ] -> updated_date = $ savedSettings [ $ settingIndex [ $ setting -> key ] ] -> updated_date ; unset ( $ savedSettings [ $ settingIndex [ $ setting -> key ] ] ) ; } else { $ definedSettings [ $ defKey ] -> setting_value = $ definedSettings [ $ defKey ] -> value ; } $ definedSettings [ $ defKey ] -> setting_key = $ setting -> key ; $ definedSettings [ $ defKey ] -> input_type = $ definedSettings [ $ defKey ] -> inputType ; if ( $ definedSettings [ $ defKey ] -> inputType === 'select' ) { $ definedSettings [ $ defKey ] -> options = array_column ( $ definedSettings [ $ defKey ] -> options , 'name' , 'value' ) ; } $ definedSettings [ $ defKey ] -> category = 'custom' ; unset ( $ definedSettings [ $ defKey ] -> key ) ; unset ( $ definedSettings [ $ defKey ] -> value ) ; unset ( $ definedSettings [ $ defKey ] -> inputType ) ; } array_walk ( $ savedSettings , function ( & $ row ) use ( $ pageSetting ) { if ( $ pageSetting || ( isset ( $ row -> category ) && $ row -> category === 'custom' ) ) { $ row -> orphaned = true ; } } ) ; return array_merge ( $ savedSettings , $ definedSettings ) ; }
Merge Saved Settings with Defined Settings
18,283
public function getPageTemplates ( string $ templateType = null ) { $ toolbox = $ this -> container -> toolbox ; $ json = $ this -> container -> json ; if ( $ templateType !== null && ! in_array ( $ templateType , [ 'page' , 'collection' ] ) ) { throw new Exception ( "PitonCMS Unexpected $templateType paramter. Expecting 'page' or 'collection'" ) ; } $ jsonPath = ROOT_DIR . "structure/definitions/pages/" ; $ templates = [ ] ; foreach ( $ toolbox -> getDirectoryFiles ( $ jsonPath ) as $ row ) { if ( null === $ definition = $ json -> getJson ( $ jsonPath . $ row [ 'filename' ] , 'page' ) ) { $ this -> setAlert ( 'danger' , 'Page JSON Definition Error' , $ json -> getErrorMessages ( ) ) ; break ; } if ( $ templateType !== null && $ definition -> templateType !== $ templateType ) { continue ; } $ templates [ ] = [ 'filename' => $ row [ 'filename' ] , 'name' => $ definition -> templateName , 'description' => $ definition -> templateDescription ] ; } return $ templates ; }
Get Page or Collection Templates
18,284
public function getThemes ( ) { $ json = $ this -> container -> json ; if ( null === $ definition = $ json -> getJson ( ROOT_DIR . 'structure/definitions/themes.json' , 'themes' ) ) { throw new Exception ( 'PitonCMS: Get themes exception: ' . implode ( $ json -> getErrorMessages ( ) , ',' ) ) ; } return array_column ( $ definition -> themes , 'name' , 'value' ) ; }
Get Array of Themes
18,285
public function getAlert ( $ context , $ key = null ) { $ session = $ this -> container -> sessionHandler ; $ alert = ( isset ( $ context [ 'alert' ] ) ) ? $ context [ 'alert' ] : $ session -> getFlashData ( 'alert' ) ; if ( $ key === null ) { return $ alert ; } if ( isset ( $ alert [ $ key ] ) ) { if ( $ key === 'message' ) { return '<ul><li>' . implode ( '</li><li>' , $ alert [ 'message' ] ) . '</ul>' ; } return $ alert [ $ key ] ; } return null ; }
Get Alert Messages
18,286
public function getCollections ( ) { if ( $ this -> collections ) { return $ this -> collections ; } $ collectionMapper = ( $ this -> container -> dataMapper ) ( 'CollectionMapper' ) ; return $ this -> collections = $ collectionMapper -> find ( ) ; }
Get Collection Options
18,287
public function getGalleries ( ) { if ( $ this -> galleries ) { return $ this -> galleries ; } $ mediaCategoryMapper = ( $ this -> container -> dataMapper ) ( 'MediaCategoryMapper' ) ; return $ this -> galleries = $ mediaCategoryMapper -> findCategories ( ) ; }
Get Gallery Options
18,288
public function getUnreadMessageCount ( ) { $ messageMapper = ( $ this -> container -> dataMapper ) ( 'MessageMapper' ) ; $ count = $ messageMapper -> findUnreadCount ( ) ; return ( $ count === 0 ) ? null : $ count ; }
Get Unread Message Count
18,289
protected function loadOverrides ( ) { if ( $ this -> overrides === null ) { $ this -> overrides = [ ] ; if ( $ this -> overrideFile !== null ) { $ this -> overrides = Craft :: $ app -> getConfig ( ) -> getConfigFromFile ( $ this -> overrideFile ) ; } } }
Load override cache configurations
18,290
public function contactUsMail ( $ data ) { key_exists_or_fail ( [ 'email' , 'first_name' , 'last_name' , 'message' ] , $ data ) ; $ this -> viewBuilder ( ) -> setTemplate ( 'MeCms.Systems/contact_us' ) ; $ this -> setSender ( $ data [ 'email' ] , sprintf ( '%s %s' , $ data [ 'first_name' ] , $ data [ 'last_name' ] ) ) -> setReplyTo ( $ data [ 'email' ] , sprintf ( '%s %s' , $ data [ 'first_name' ] , $ data [ 'last_name' ] ) ) -> setTo ( getConfigOrFail ( 'email.webmaster' ) ) -> setSubject ( __d ( 'me_cms' , 'Email from {0}' , getConfigOrFail ( 'main.title' ) ) ) -> setViewVars ( [ 'email' => $ data [ 'email' ] , 'firstName' => $ data [ 'first_name' ] , 'lastName' => $ data [ 'last_name' ] , 'message' => $ data [ 'message' ] , ] ) ; }
Email for the contact us form .
18,291
public function showCollections ( ) { $ collectionMapper = ( $ this -> container -> dataMapper ) ( 'CollectionMapper' ) ; $ pageMapper = ( $ this -> container -> dataMapper ) ( 'PageMapper' ) ; $ collectionPages = $ pageMapper -> findCollectionPages ( ) ; foreach ( $ collectionPages as $ col ) { if ( ! isset ( $ data [ 'collectionPages' ] [ $ col -> collection_id ] ) ) { $ data [ 'collectionPages' ] [ $ col -> collection_id ] [ 'collection_id' ] = $ col -> collection_id ; $ data [ 'collectionPages' ] [ $ col -> collection_id ] [ 'collection_title' ] = $ col -> collection_title ; $ data [ 'collectionPages' ] [ $ col -> collection_id ] [ 'collection_slug' ] = $ col -> collection_slug ; } $ data [ 'collectionPages' ] [ $ col -> collection_id ] [ 'pages' ] [ ] = $ col ; } $ data [ 'templates' ] = $ this -> getPageTemplates ( 'collection' ) ; $ data [ 'collections' ] = $ collectionMapper -> find ( ) ; $ templateArray = array_column ( $ data [ 'templates' ] , 'filename' ) ; array_walk ( $ data [ 'collections' ] , function ( & $ collect ) use ( $ data , $ templateArray ) { $ key = array_search ( $ collect -> definition , $ templateArray ) ; $ collect -> templateName = $ data [ 'templates' ] [ $ key ] [ 'name' ] ; $ collect -> templateDescription = $ data [ 'templates' ] [ $ key ] [ 'description' ] ; } ) ; return $ this -> render ( 'collections.html' , $ data ) ; }
Show Collections and Collection Pages
18,292
public function editCollection ( $ args ) { $ collectionMapper = ( $ this -> container -> dataMapper ) ( 'CollectionMapper' ) ; $ json = $ this -> container -> json ; $ toolbox = $ this -> container -> toolbox ; if ( isset ( $ args [ 'id' ] ) && is_numeric ( $ args [ 'id' ] ) ) { $ collection = $ collectionMapper -> findById ( $ args [ 'id' ] ) ; } else { $ definionParam = $ this -> request -> getQueryParam ( 'definition' ) ; if ( null === $ definionParam || 1 !== preg_match ( '/^[a-zA-Z0-9]+\.json$/' , $ definionParam ) ) { throw new Exception ( "PitonCMS: Invalid query parameter for 'definition': $definionParam" ) ; } $ collection = $ collectionMapper -> make ( ) ; $ collection -> definition = $ definionParam ; } return $ this -> render ( 'editCollection.html' , $ collection ) ; }
Edit Collection Group
18,293
public function confirmDeleteCollection ( $ args ) { $ collectionMapper = ( $ this -> container -> dataMapper ) ( 'CollectionMapper' ) ; $ pageMapper = ( $ this -> container -> dataMapper ) ( 'PageMapper' ) ; $ data = $ collectionMapper -> findById ( $ args [ 'id' ] ) ; $ data -> pages = $ pageMapper -> findCollectionPagesById ( $ args [ 'id' ] , false ) ; return $ this -> render ( 'confirmDeleteCollection.html' , $ data ) ; }
Confirm Delete Collection
18,294
public function call ( string $ service , ... $ params ) { return Container :: getInstance ( ) -> make ( ServiceCaller :: class ) -> call ( $ service , ... $ params ) ; }
Call a service .
18,295
protected function beforeRun ( array $ strings ) { $ this -> isOptional = ( isset ( $ strings [ 0 ] ) && $ strings [ 0 ] === [ ] ) ; if ( $ this -> isOptional ) { array_shift ( $ strings ) ; } return $ strings ; }
Prepare the list of strings before the pass is run
18,296
protected function isSingleCharStringList ( array $ strings ) { foreach ( $ strings as $ string ) { if ( ! $ this -> isSingleCharString ( $ string ) ) { return false ; } } return true ; }
Test whether given list of strings contains nothing but single - char strings
18,297
public function logout ( ) { $ authService = $ this -> getServiceManager ( ) -> get ( 'zfcuser_auth_service' ) ; $ user = $ authService -> getIdentity ( ) ; $ cookie = explode ( "\n" , $ this -> getRememberMeService ( ) -> getCookie ( ) ) ; if ( $ cookie [ 0 ] !== '' && $ user !== null ) { $ this -> getRememberMeService ( ) -> removeSerie ( $ user -> getId ( ) , $ cookie [ 1 ] ) ; $ this -> getRememberMeService ( ) -> removeCookie ( ) ; } }
Hack to use getStorage to clear cookie on logout
18,298
public function middleware ( $ middleware ) { $ key = Configure :: read ( 'Security.cookieKey' , md5 ( Configure :: read ( 'Security.salt' ) ) ) ; return $ middleware -> add ( new EncryptedCookieMiddleware ( [ 'login' ] , $ key ) ) ; }
Adds middleware for the plugin
18,299
protected function setVendorLinks ( ) { $ links = array_unique ( array_merge ( Configure :: read ( 'VENDOR_LINKS' , [ ] ) , [ 'npm-asset' . DS . 'js-cookie' . DS . 'src' => 'js-cookie' , 'sunhater' . DS . 'kcfinder' => 'kcfinder' , 'enyo' . DS . 'dropzone' . DS . 'dist' => 'dropzone' , ] ) ) ; return Configure :: write ( 'VENDOR_LINKS' , $ links ) ? $ links : false ; }
Sets symbolic links for vendor assets to be created