idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
60,100
|
public function get ( $ key ) { if ( ! @ $ this -> langDb [ $ key ] ) { return '---' ; } $ lang = $ this -> lang ; if ( ! strlen ( $ this -> langDb [ $ key ] [ $ lang ] ) ) { $ lang = $ this -> defaultLang ; } if ( ! strlen ( $ this -> langDb [ $ key ] [ $ lang ] ) ) { return '---' ; } $ rtn = $ this -> langDb [ $ key ] [ $ lang ] ; $ data = ( @ $ this -> options [ 'bind' ] ? $ this -> options [ 'bind' ] : array ( ) ) ; $ data [ '_ENV' ] = $ this ; $ loader = new \ Twig_Loader_Array ( array ( 'index' => $ rtn , ) ) ; $ twig = new \ Twig_Environment ( $ loader ) ; $ rtn = $ twig -> render ( 'index' , $ data ) ; return $ rtn ; }
|
get word by key
|
60,101
|
public static function getExtension ( $ file ) { $ file = trim ( $ file ) ; $ extension = strtolower ( substr ( strrchr ( $ file , '.' ) , 1 ) ) ; if ( $ extension == $ file ) { return '' ; } else { return $ extension ; } }
|
Get the extension of a file .
|
60,102
|
public static function Anpm ( $ a ) { $ w ; $ w = fmod ( $ a , D2PI ) ; if ( abs ( $ w ) >= DPI ) $ w -= sign ( D2PI , $ a ) ; return $ w ; }
|
- - - - - - - - i a u A n p m - - - - - - - -
|
60,103
|
public function bindRequest ( Request $ request ) { $ this -> request = $ request ; foreach ( $ this -> request -> postArray ( ) as $ key => $ value ) { if ( isset ( $ this -> fieldSet [ $ key ] ) ) { $ this -> fieldSet [ $ key ] -> setValue ( $ value ) ; } } }
|
Binds the request to the form
|
60,104
|
public function deleteAction ( Request $ request , $ userId ) { $ successorUserId = $ request -> request -> get ( 'successor' ) ; $ userManager = $ this -> get ( 'phlexible_user.user_manager' ) ; $ successorUser = $ userManager -> find ( $ successorUserId ) ; $ user = $ userManager -> find ( $ userId ) ; $ userManager -> deleteUserWithSuccessor ( $ user , $ successorUser ) ; $ this -> get ( 'phlexible_message.message_poster' ) -> post ( UsersMessage :: create ( 'User "' . $ user -> getUsername ( ) . '" deleted.' ) ) ; return new ResultResponse ( true ) ; }
|
Delete users .
|
60,105
|
public function filtervaluesAction ( ) { $ groupManager = $ this -> get ( 'phlexible_user.group_manager' ) ; $ allGroups = $ groupManager -> findAll ( ) ; $ everyoneGroupId = $ groupManager -> getEveryoneGroupId ( ) ; $ groups = [ ] ; foreach ( $ allGroups as $ group ) { if ( $ group -> getId ( ) === $ everyoneGroupId ) { continue ; } $ groups [ ] = [ 'id' => $ group -> getId ( ) , 'title' => $ group -> getName ( ) , ] ; } $ roles = [ ] ; foreach ( $ this -> container -> getParameter ( 'security.role_hierarchy.roles' ) as $ role => $ subRoles ) { if ( ! $ this -> isGranted ( $ role ) ) { continue ; } $ roles [ ] = [ 'id' => $ role , 'title' => ucfirst ( str_replace ( '_' , ' ' , $ role ) ) ] ; } $ data = [ 'groups' => $ groups , 'roles' => $ roles , ] ; return new JsonResponse ( $ data ) ; }
|
Return filter values .
|
60,106
|
public function passwordAction ( ) { $ minLength = $ this -> container -> getParameter ( 'phlexible_user.password.min_length' ) ; $ generator = new PasswordGenerator ( ) ; $ password = $ generator -> create ( $ minLength , PasswordGenerator :: TYPE_UNPRONOUNCABLE ) ; return new JsonResponse ( [ 'password' => $ password , 'success' => true , ] ) ; }
|
Create password .
|
60,107
|
public static function run ( $ source = null , MappingInterface $ mapping , $ output = null ) { $ data = [ ] ; foreach ( $ source as $ src ) { $ data [ ] = self :: runOnce ( $ src , $ mapping , $ output ) ; } return $ data ; }
|
Insert a array of objects
|
60,108
|
private static function transformData ( $ source , MappingInterface $ mapping , $ output ) { $ data = [ ] ; $ mappingArray = $ mapping -> getMapping ( ) ; foreach ( $ mappingArray as $ key => $ value ) { $ callback = null ; $ found = null ; $ search = null ; $ sourceType = gettype ( $ source ) ; if ( is_array ( $ value ) && count ( $ value ) === 3 ) { $ data [ $ key ] = $ value [ 2 ] ; } if ( is_array ( $ value ) && count ( $ value ) >= 2 ) { $ search = $ value [ 0 ] ; if ( is_callable ( $ value [ 1 ] ) ) { $ callback = $ value [ 1 ] ; } if ( is_callable ( [ $ mapping , $ value [ 1 ] ] ) ) { $ callback = [ $ mapping , $ value [ 1 ] ] ; } } elseif ( is_array ( $ value ) && count ( $ value ) === 1 ) { $ search = $ value [ 0 ] ; } else { $ search = $ value ; } if ( $ sourceType === 'object' ) { if ( strpos ( ( string ) $ search , '.' ) !== false ) { $ found = self :: objectGet ( $ source , $ search ) ; } elseif ( $ search !== null && property_exists ( $ source , $ search ) ) { $ found = self :: objectGet ( $ source , $ search ) ; } } else { if ( strpos ( ( string ) $ search , '.' ) !== false ) { $ found = self :: arrayGet ( $ source , $ search ) ; } elseif ( $ search !== null && isset ( $ source [ $ search ] ) ) { $ found = $ source [ $ search ] ; } } if ( ! is_null ( $ found ) ) { if ( ! empty ( $ callback ) ) { $ data [ $ key ] = call_user_func ( $ callback , $ found , $ source ) ; } else { $ data [ $ key ] = $ found ; } } else { $ data [ $ key ] = null ; } } if ( is_object ( $ output ) ) { return self :: populateObject ( $ output , $ data ) ; } if ( is_array ( $ output ) && empty ( $ output ) ) { return $ data ; } if ( is_array ( $ output ) ) { $ output [ ] = $ data ; } return $ output ; }
|
Helper function to transform data with a mapping
|
60,109
|
private static function populateObject ( $ output , $ source ) { $ source = json_decode ( json_encode ( $ source ) , true ) ; foreach ( $ source as $ key => $ value ) { $ method = self :: createMethodNames ( $ key ) ; if ( is_callable ( [ $ output , $ method ] ) ) { call_user_func ( [ $ output , $ method ] , $ value ) ; } } return $ output ; }
|
Helper function to set Array data to a object .
|
60,110
|
public function getConfig ( ) { $ config = [ ] ; $ provider = new ConfigProvider ( ) ; $ config [ 'middleware_pipeline' ] = $ provider -> getMiddlewareConfig ( ) ; $ config [ 'service_manager' ] = $ provider -> getDependencyConfig ( ) ; return $ config ; }
|
Return default configuration for zend - mvc applications .
|
60,111
|
public static function get_all_post_meta ( $ post ) { $ tags = [ [ 'name' => 'description' , 'content' => self :: get_post_meta_description ( $ post ) ] , [ 'property' => 'og:locale' , 'content' => get_locale ( ) ] , [ 'property' => 'og:type' , 'content' => 'article' ] , [ 'property' => 'og:title' , 'content' => self :: get_post_og_title ( $ post ) ] , [ 'property' => 'og:description' , 'content' => self :: get_post_og_description ( $ post ) ] , [ 'property' => 'og:url' , 'content' => get_permalink ( $ post -> ID ) ] , [ 'property' => 'og:site_name' , 'content' => get_bloginfo ( 'title' ) ] , [ 'property' => 'og:updated_time' , 'content' => get_post_modified_time ( 'c' , true , $ post ) ] , [ 'name' => 'twitter:card' , 'content' => self :: get_twitter_card_type ( ) ] , [ 'name' => 'twitter:title' , 'content' => self :: get_post_twitter_title ( $ post ) ] , [ 'name' => 'twitter:description' , 'content' => self :: get_post_twitter_description ( $ post ) ] , ] ; $ og_image = self :: get_post_og_image ( $ post ) ; $ twitter_image = self :: get_post_twitter_image ( $ post ) ; if ( ! empty ( $ og_image ) ) { $ og_image_size = getimagesize ( $ og_image ) ; $ tags = array_merge ( $ tags , [ [ 'property' => 'og:image' , 'content' => $ og_image ] , [ 'property' => 'og:image:width' , 'content' => $ og_image_size [ 0 ] ] , [ 'property' => 'og:image:height' , 'content' => $ og_image_size [ 1 ] ] , ] ) ; } if ( ! empty ( $ twitter_image ) ) { $ twitter_image_size = getimagesize ( $ twitter_image ) ; $ tags = array_merge ( $ tags , [ [ 'name' => 'twitter:image' , 'content' => $ twitter_image ] , [ 'name' => 'twitter:image:width' , 'content' => $ twitter_image_size [ 0 ] ] , [ 'name' => 'twitter:image:height' , 'content' => $ twitter_image_size [ 1 ] ] , ] ) ; } $ tags = array_merge ( $ tags , Site :: webmaster_tools ( ) ) ; return [ 'title' => self :: get_post_meta_title ( $ post ) , 'tags' => $ tags , ] ; }
|
Get all metadata for a post .
|
60,112
|
public static function get_post_meta_title ( $ post ) { $ title = get_post_meta ( $ post -> ID , '_yoast_wpseo_title' , true ) ; if ( empty ( $ title ) ) { if ( ( int ) get_option ( 'page_on_front' ) === $ post -> ID ) { $ title = get_bloginfo ( 'title' ) ; } else { $ title = $ post -> post_title . ' - ' . get_bloginfo ( 'title' ) ; } } return $ title ; }
|
Get the post s meta title .
|
60,113
|
public static function get_post_meta_description ( $ post ) { $ description = get_post_meta ( $ post -> ID , '_yoast_wpseo_metadesc' , true ) ; if ( empty ( $ description ) ) { $ description = Text :: trim_to_nearest_word ( wp_strip_all_tags ( $ post -> post_content ) , 160 ) ; } return $ description ; }
|
Get the post s meta description .
|
60,114
|
public static function get_post_twitter_title ( $ post ) { $ title = get_post_meta ( $ post -> ID , '_yoast_wpseo_twitter-title' , true ) ; if ( empty ( $ title ) ) { $ title = self :: get_post_meta_title ( $ post ) ; } return $ title ; }
|
Get the post s twitter title .
|
60,115
|
public static function get_post_twitter_description ( $ post ) { $ description = get_post_meta ( $ post -> ID , '_yoast_wpseo_twitter-description' , true ) ; if ( empty ( $ description ) ) { $ description = self :: get_post_meta_description ( $ post ) ; } return $ description ; }
|
Get the post s twitter description .
|
60,116
|
public static function get_post_twitter_image ( $ post ) { $ image = get_post_meta ( $ post -> ID , '_yoast_wpseo_twitter-image' , true ) ; if ( empty ( $ image ) ) { $ image = self :: get_fallback_image ( $ post ) ; } return $ image ; }
|
Get the post s twitter image .
|
60,117
|
private static function get_fallback_image ( $ post ) { $ image = wp_get_attachment_url ( get_post_thumbnail_id ( $ post -> ID ) ) ; if ( empty ( $ image ) ) { $ logo = Acf :: get_option_field ( SiteIdentity :: LOGO_KEY ) ; $ image = is_array ( $ logo ) ? $ logo [ 'src' ] : get_site_icon_url ( ) ; } return $ image ; }
|
Get a fallback image for the post .
|
60,118
|
public static function get_twitter_card_type ( ) { $ card = 'summary' ; $ social = get_option ( 'wpseo_social' ) ; if ( ! empty ( $ social ) && ! empty ( $ social [ 'twitter_card_type' ] ) ) { $ card = $ social [ 'twitter_card_type' ] ; } return $ card ; }
|
Get twitter card type .
|
60,119
|
public function registerClientCommand ( $ baseUri , $ publicKey ) { try { $ this -> rsaWalletService -> getPublicKey ( $ publicKey ) ; } catch ( \ TYPO3 \ Flow \ Security \ Exception \ InvalidKeyPairIdException $ exception ) { $ this -> outputLine ( 'Invalid or unknown public key fingerprint: ' . $ publicKey . '. Make sure to import the key before adding the client.' ) ; } $ ssoClient = new SsoClient ( ) ; $ ssoClient -> setServiceBaseUri ( $ baseUri ) ; $ ssoClient -> setPublicKey ( $ publicKey ) ; $ this -> ssoClientRepository -> add ( $ ssoClient ) ; }
|
Add a client
|
60,120
|
public function triggerAction ( $ companyFid , $ actionKey , $ transactionId , $ transactionValue = 0 , array $ data = null , $ couponCode = null , $ returnPixels = null , $ userReference = null , $ campaignHash = null , $ sid1 = null , $ sid2 = null , $ sid3 = null ) { if ( $ returnPixels === null ) { $ returnPixels = self :: $ _returnPixels ; } $ payload = $ this -> createTriggerActionPayload ( $ companyFid , $ actionKey , $ transactionId , $ transactionValue , $ data , $ couponCode , $ returnPixels , $ userReference , $ campaignHash , $ sid1 , $ sid2 , $ sid3 ) ; return $ this -> triggerActionWithPayload ( $ payload ) ; }
|
Trigger a visitor action
|
60,121
|
public function reverseAction ( $ transactionId , $ originalAction = AffiliateBuiltInAction :: ACQUISITION , $ reason = ReversalReason :: CANCEL , $ reversalId = null , $ reversalAmount = 0 , array $ data = null ) { $ endpoint = AffiliateActionEndpoint :: bound ( $ this -> _getApi ( ) ) ; $ payload = new ReversalPayload ( ) ; $ payload -> userAgent = $ this -> _fortifi -> getUserAgent ( ) ; $ payload -> language = $ this -> _fortifi -> getUserLanguage ( ) ; $ payload -> clientIp = $ this -> _fortifi -> getClientIp ( ) ; $ payload -> encoding = $ this -> _fortifi -> getUserEncoding ( ) ; $ payload -> reason = $ reason ; $ payload -> reversalAmount = $ reversalAmount ; $ payload -> reversalId = $ reversalId ; $ payload -> sourceActionKey = $ originalAction ; $ payload -> sourceTransactionId = $ transactionId ; $ payload -> data = $ data ; $ payload -> visitorId = $ this -> _visitorId ; $ req = $ endpoint -> reverse ( $ payload ) ; return $ this -> _processRequest ( $ req ) ; }
|
Reverse a previously triggered action
|
60,122
|
public function first ( $ default = NULL ) { $ first = $ this -> shift ( ) ; if ( ! $ first ) { $ first = $ default ; } else { $ this -> unshift ( $ first ) ; } return $ first ; }
|
Get the first element of the collection
|
60,123
|
public function clear ( array $ excepts = [ ] ) { $ tmp = array ( ) ; foreach ( $ excepts as $ except ) { if ( $ this -> has ( $ except ) ) { $ tmp [ $ except ] = $ this -> get ( $ except ) ; } } $ this -> setAll ( array ( ) ) ; foreach ( $ tmp as $ key => $ value ) { $ this -> set ( $ key , $ value ) ; } }
|
Remove all items from collection with a list of exception
|
60,124
|
private function setQueryParameters ( TransportRequestInterface $ transportRequest , $ parameters ) { if ( ! empty ( $ parameters ) && is_array ( $ parameters ) ) { $ transportRequest -> setQueryParams ( $ parameters ) ; } return $ transportRequest ; }
|
Sets query params to transport request
|
60,125
|
private function generatePath ( RequestInterface $ request ) { $ path = array ( ) ; if ( null !== $ request -> getIndex ( ) ) { $ path [ ] = $ request -> getIndex ( ) ; } if ( null !== $ request -> getType ( ) ) { $ path [ ] = $ request -> getType ( ) ; } if ( null !== $ request -> getAction ( ) ) { $ path [ ] = $ request -> getAction ( ) ; } return implode ( self :: PATH_DIVIDER , $ path ) ; }
|
Generates the path by given request
|
60,126
|
function setContentType ( $ mime_type , $ charset = 'utf-8' ) { $ header = 'Content-Type: ' . $ mime_type ; if ( $ charset ) { $ header .= '; charset=' . $ charset ; } $ this -> headers [ ] = array ( $ header , TRUE ) ; return $ this ; }
|
Set Content Type Header
|
60,127
|
public function validate ( array $ data , array $ rules , array $ messages = [ ] ) { $ validator = $ this -> validationFactory -> make ( $ data , $ rules , $ messages ) ; if ( $ validator -> fails ( ) ) { return new Payload ( $ validator -> messages ( ) , 'invalid' ) ; } return new Payload ( $ data , 'valid' ) ; }
|
Validate input against the specified rules
|
60,128
|
public function uploadFile ( ) { if ( ! $ this -> request -> files -> has ( 'file' ) ) { return false ; } $ file = $ this -> request -> files -> get ( 'file' ) ; $ upload = rtrim ( $ this -> uploadDir , '/' ) ; if ( ! is_dir ( $ upload ) ) { mkdir ( $ upload , 0777 , true ) ; } $ file -> move ( realpath ( $ upload ) , $ file -> getClientOriginalName ( ) ) ; return sprintf ( '/%s/%s' , pathinfo ( $ upload , PATHINFO_BASENAME ) , pathinfo ( $ file -> getClientOriginalName ( ) , PATHINFO_BASENAME ) ) ; }
|
Upload file from request
|
60,129
|
public function listFiles ( array $ paths ) { $ files = array ( ) ; $ webDir = rtrim ( realpath ( $ this -> webDir ) , '/' ) ; foreach ( $ paths as $ path ) { if ( substr ( $ path , 0 , 1 ) != '/' ) { $ path = sprintf ( '/%s' , $ path ) ; } $ realpath = realpath ( $ webDir . $ path ) ; if ( $ realpath && strpos ( $ realpath , $ webDir ) === 0 ) { $ finder = Finder :: create ( ) -> files ( ) -> name ( '/\.(?:gif|png|jpg|jpeg)$/i' ) ; foreach ( $ finder -> in ( realpath ( $ webDir . $ path ) ) as $ img ) { $ folder = str_ireplace ( $ webDir , '' , pathinfo ( $ img -> __toString ( ) , PATHINFO_DIRNAME ) ) ; $ files [ ] = array ( 'thumb' => $ folder . '/' . $ img -> getFilename ( ) , 'image' => $ folder . '/' . $ img -> getFilename ( ) , 'title' => pathinfo ( $ img -> __toString ( ) , PATHINFO_FILENAME ) , 'folder' => str_ireplace ( '/' , ' > ' , str_ireplace ( '\\' , '>' , trim ( $ folder , '/' ) ) ) , ) ; } } else { throw new InvalidParameterException ( 'The provided path is either invalid or outside of the public directory. ' . 'Maybe you forgot to set the "kernel.web_dir" parameter.' ) ; } } return $ files ; }
|
List files in a list of paths
|
60,130
|
protected function remoteColumn ( $ model , $ column ) { $ table = $ model :: $ table ; return ! is_null ( $ column ) ? $ column : $ this -> idKey ( $ table ) ; }
|
get the name of the column of the remote table .
|
60,131
|
protected function relate ( $ remote , $ intermediates , $ remoteColumn , $ localColumn , $ localValue ) { $ intermediates = $ this -> intermediates ( $ intermediates , $ localColumn , $ localValue ) ; if ( ! is_null ( $ intermediates ) ) { return $ this -> all ( $ intermediates , $ remote , $ remoteColumn ) ; } }
|
get all values in relation .
|
60,132
|
protected function all ( $ intermediates , $ model , $ column ) { $ data = [ ] ; foreach ( $ intermediates as $ intermediate ) { $ data [ ] = $ this -> one ( $ model , $ column , $ intermediate -> $ column ) ; } return $ data ; }
|
get all values in remote model .
|
60,133
|
protected function one ( $ model , $ column , $ value ) { $ object = $ model :: where ( $ column , '=' , $ value ) ; if ( ! is_null ( $ object ) ) { if ( count ( $ object ) > 0 ) { return $ object [ 0 ] ; } } }
|
get one value in remote model .
|
60,134
|
public function createCredentials ( ) { $ credentials = new Credentials ( ) ; $ credentials -> setTransactor ( $ this ) ; $ credentials -> setCredentials ( array ( 'providerId' => null , 'providerGateId' => null , 'providerGateKey' => null , 'merchantId' => null , 'merchantGateId' => null , 'merchantGateKey' => null ) ) ; return $ credentials ; }
|
Creates a new empty Credentials entity
|
60,135
|
protected function handleQueryResponse ( Transaction $ transaction , $ data ) { $ result = $ transaction -> getResult ( ) ; $ parentResult = $ transaction -> getParent ( ) -> getResult ( ) ; $ eventResult = null ; foreach ( $ data -> Results as $ event ) { if ( $ event -> TransAct_ReferenceID === $ parentResult -> getExternalId ( ) ) { $ eventResult = $ event ; } } $ resultType = $ parentResult -> getStatus ( ) -> getValue ( ) ; if ( null !== $ eventResult ) { switch ( $ eventResult -> ResultingStatus ) { case 'Scheduled' : $ resultType = Result \ ResultStatus :: PENDING ; break ; case 'Cancelled' : $ resultType = Result \ ResultStatus :: CANCELLED ; break ; case 'In-Process' : $ resultType = Result \ ResultStatus :: PROCESSED ; break ; case 'Cleared' : $ resultType = Result \ ResultStatus :: APPROVED ; break ; case 'Failed Verification' : case 'Returned-NSF' : case 'Returned-Other' : $ resultType = Result \ ResultStatus :: DECLINED ; break ; case 'Charged Back' : $ resultType = Result \ ResultStatus :: CHARGED_BACK ; break ; case 'Merchant Hold' : case 'Processor Hold' : $ resultType = Result \ ResultStatus :: HOLD ; break ; } } $ result -> setStatus ( new Result \ ResultStatus ( $ resultType ) ) ; }
|
Handles a query response
|
60,136
|
protected function normalizeQueryResponse ( $ content ) { $ result = new \ stdClass ( ) ; $ result -> Results = array ( ) ; $ lines = explode ( "\n" , $ content ) ; foreach ( $ lines as $ line ) { if ( empty ( $ line ) ) { continue ; } $ parts = str_getcsv ( $ line ) ; if ( $ parts [ 0 ] === 'Command Response' ) { $ result -> CommandStatus = $ parts [ 1 ] ; $ result -> ResponseCode = $ parts [ 2 ] ; $ result -> Description = $ parts [ 3 ] ; $ result -> ErrorInformation = $ parts [ 4 ] ; $ result -> TransAct_ReferenceID = $ parts [ 5 ] ; continue ; } $ status = new \ stdClass ( ) ; $ status -> TransAct_ReferenceID = $ parts [ 0 ] ; $ status -> Provider_TransactionID = $ parts [ 1 ] ; $ status -> MerchantID = $ parts [ 2 ] ; $ status -> EventName = $ parts [ 3 ] ; $ status -> EventDate = $ parts [ 4 ] ; $ status -> ResultingStatus = $ parts [ 5 ] ; $ status -> ReturnCode = $ parts [ 6 ] ; $ status -> VerificationStatus = $ parts [ 7 ] ; $ status -> VerificationCode = $ parts [ 8 ] ; $ status -> VerificationText = $ parts [ 9 ] ; $ result -> Results [ ] = $ status ; } if ( ! $ result -> CommandStatus ) { return null ; } return $ result ; }
|
Normalizes a Query response converting it from CSV to an object
|
60,137
|
private function createRolesAndPermissions ( ) { $ permissions = [ ] ; $ permissions [ ] = [ 'name' => 'admin-access' , 'category' => 'general' ] ; $ entities = [ 'content' , 'block' , 'user' , 'file' , 'role' ] ; foreach ( $ entities as $ entity ) { $ permissions [ ] = [ 'name' => $ entity . '-create' , 'category' => $ entity ] ; $ permissions [ ] = [ 'name' => $ entity . '-read' , 'category' => $ entity ] ; $ permissions [ ] = [ 'name' => $ entity . '-update' , 'category' => $ entity ] ; $ permissions [ ] = [ 'name' => $ entity . '-delete' , 'category' => $ entity ] ; } $ permissions [ ] = [ 'name' => 'options-read' , 'category' => 'options' ] ; $ permissions [ ] = [ 'name' => 'options-update-general' , 'category' => 'options' ] ; $ permissions [ ] = [ 'name' => 'options-update-seo' , 'category' => 'options' ] ; Permission :: insert ( $ permissions ) ; $ adminRole = Role :: create ( [ 'name' => 'Admin' ] ) ; $ user = User :: find ( 1 ) ; $ user -> roles ( ) -> attach ( $ adminRole ) ; $ adminRole -> permissions ( ) -> attach ( Permission :: all ( [ 'id' ] ) -> pluck ( 'id' ) -> toArray ( ) ) ; $ moderatorRole = Role :: create ( [ 'name' => 'Moderator' ] ) ; $ permissionIds = Permission :: whereIn ( 'category' , [ 'block' , 'content' , 'file' ] ) -> orWhereIn ( 'name' , [ 'admin-access' ] ) -> get ( [ 'id' ] ) -> pluck ( 'id' ) -> toArray ( ) ; $ moderatorRole -> permissions ( ) -> attach ( $ permissionIds ) ; }
|
It creates base permissions
|
60,138
|
static public function instance ( $ srcPath , $ codePool ) { if ( ! self :: $ _instance ) { self :: $ _instance = new WpLoader ( $ srcPath , $ codePool ) ; } return self :: $ _instance ; }
|
Singleton pattern implementation
|
60,139
|
public function autoload ( $ class ) { if ( $ this -> _collectClasses ) { $ this -> _arrLoadedClasses [ self :: $ _scope ] [ ] = $ class ; } $ classFile = str_replace ( ' ' , DIRECTORY_SEPARATOR , ucwords ( str_replace ( '_' , ' ' , $ class ) ) ) ; if ( $ this -> _isIncludePathDefined ) { $ classFile = COMPILER_INCLUDE_PATH . DIRECTORY_SEPARATOR . $ class ; } $ classFile .= '.php' ; if ( stream_resolve_include_path ( $ classFile ) ) { return include $ classFile ; } $ classFile = ltrim ( $ this -> classToFile ( $ class ) . '.php' , '\\/' ) ; if ( stream_resolve_include_path ( $ classFile ) ) { return include $ classFile ; } return false ; }
|
Load class source code
|
60,140
|
static public function registerScope ( $ code ) { self :: $ _scope = $ code ; if ( defined ( 'COMPILER_INCLUDE_PATH' ) ) { @ include COMPILER_INCLUDE_PATH . DIRECTORY_SEPARATOR . self :: SCOPE_FILE_PREFIX . $ code . '.php' ; } }
|
Register autoload scope This process allow include scope file which can contain classes definition which are used for this scope
|
60,141
|
private function includeController ( $ class ) { $ local = $ this -> _srcPath . DIRECTORY_SEPARATOR ; $ controller = explode ( '_' , $ class ) ; array_splice ( $ controller , 2 , 0 , 'controllers' ) ; $ pathToController = implode ( DIRECTORY_SEPARATOR , $ controller ) ; $ classFile = $ local . $ pathToController . '.php' ; if ( ! file_exists ( $ classFile ) ) { return false ; } return include_once $ classFile ; }
|
Includes a controller given a controller class name
|
60,142
|
public function getPort ( ) { return $ this -> port && ! Validator :: isStandardPort ( $ this -> port ) ? $ this -> port : null ; }
|
Retrieve the port component of the URI
|
60,143
|
public function withPath ( $ path ) { if ( ! is_string ( $ path ) ) { throw new InvalidArgumentException ( 'Uri path must be a string' ) ; } $ clone = clone $ this ; $ clone -> path = Validator :: checkPath ( $ path ) ; if ( substr ( $ path , 0 , 1 ) == '/' ) { $ clone -> basePath = '' ; } return $ clone ; }
|
Return an instance with the specified path
|
60,144
|
public function withQuery ( $ query ) { if ( ! is_string ( $ query ) && ! method_exists ( $ query , '__toString' ) ) { throw new InvalidArgumentException ( 'Uri query must be a string' ) ; } $ query = ltrim ( ( string ) $ query , '?' ) ; $ clone = clone $ this ; $ clone -> query = Validator :: checkQuery ( $ query ) ; return $ clone ; }
|
Return an instance with the specified query string
|
60,145
|
public function withFragment ( $ fragment ) { if ( ! is_string ( $ fragment ) && ! method_exists ( $ fragment , '__toString' ) ) { throw new InvalidArgumentException ( 'Uri fragment must be a string' ) ; } $ fragment = ltrim ( ( string ) $ fragment , '#' ) ; $ clone = clone $ this ; $ clone -> fragment = Validator :: checkQuery ( $ fragment ) ; return $ clone ; }
|
Return an instance with the specified URI fragment
|
60,146
|
public function getBaseUrl ( ) { $ scheme = $ this -> getScheme ( ) ; $ authority = $ this -> getAuthority ( ) ; $ basePath = $ this -> getBasePath ( ) ; if ( $ authority && substr ( $ basePath , 0 , 1 ) !== '/' ) { $ basePath = $ basePath . '/' . $ basePath ; } return ( $ scheme ? $ scheme . ':' : '' ) . ( $ authority ? '//' . $ authority : '' ) . rtrim ( $ basePath , '/' ) ; }
|
Return the fully qualified base URL
|
60,147
|
public function getResult ( ) { $ result = $ this -> getRoot ( ) ; if ( is_array ( $ result ) && A :: isAssoc ( $ result ) ) { return ( object ) $ result ; } return $ result ; }
|
Does not json encode by default
|
60,148
|
public function setupAcl ( ) { $ this -> insertRoles ( $ this -> findRoles ( ) ) -> insertResources ( $ this -> findResources ( ) ) -> insertPrivileges ( $ this -> findPrivileges ( ) ) ; $ this -> loaded = true ; return $ this ; }
|
Build a new ACL object from the database .
|
60,149
|
protected function insertRoles ( array $ roles ) { foreach ( $ roles as $ role ) { if ( null === $ role -> getParent ( ) ) { $ this -> addRole ( $ role ) ; } else { $ parents = [ ] ; $ parents [ ] = $ role -> getParent ( ) -> getRoleId ( ) ; $ this -> addRole ( $ role , $ parents ) ; } } return $ this ; }
|
Insert an array of roles into the current ACL object .
|
60,150
|
protected function insertResources ( array $ resources ) { foreach ( $ resources as $ resource ) { if ( null === $ resource -> getParent ( ) ) { $ this -> addResource ( $ resource ) ; } else { $ parent = $ resource -> getParent ( ) -> getResourceId ( ) ; $ this -> addResource ( $ resource , $ parent ) ; } } return $ this ; }
|
Inserts an array of resources into the current ACL object .
|
60,151
|
protected function insertPrivileges ( array $ privileges ) { foreach ( $ privileges as $ privilege ) { $ this -> { $ privilege -> getType ( ) } ( $ privilege -> getRole ( ) , $ privilege -> getResource ( ) , $ privilege -> getPrivilege ( ) ) ; } return $ this ; }
|
Setup the privileges .
|
60,152
|
public function createResource ( $ newResource , $ baseResource ) { $ em = $ this -> getEntityManager ( ) ; if ( ! $ baseResource instanceof ResourceEntity && ! is_string ( $ baseResource ) ) { throw new \ Exception ( 'Base resource is not a valid ACL resource, ' . get_class ( $ baseResource ) . ' given.' ) ; } elseif ( ! $ baseResource instanceof \ ResourceEntity ) { $ baseName = $ baseResource ; $ baseResource = $ em -> getRepository ( 'JaztecAcl\Entity\Acl\Resource' ) -> findOneBy ( [ 'name' => $ baseName ] ) ; if ( ! $ baseResource instanceof ResourceEntity ) { $ baseResource = new \ JaztecAcl \ Entity \ Acl \ Resource ( $ baseName ) ; $ baseResource -> setSort ( 0 ) ; $ em -> persist ( $ baseResource ) ; $ this -> addResource ( $ baseResource -> getResourceId ( ) ) ; } } if ( ! is_string ( $ newResource ) ) { throw new \ Exception ( 'The new resource is not a valid string' ) ; } $ resource = new \ JaztecAcl \ Entity \ Acl \ Resource ( $ newResource , $ baseResource , $ baseResource -> getSort ( ) + 1 ) ; $ em -> persist ( $ resource ) ; $ em -> flush ( ) ; $ this -> addResource ( $ resource , $ resource -> getParent ( ) ) ; return $ resource ; }
|
Create a new resource in the ACL structure
|
60,153
|
public function checkPrivilegeRequest ( $ privilege , $ resource ) { $ em = $ this -> getEntityManager ( ) ; $ privilege = trim ( $ privilege ) ; $ resource = trim ( $ resource ) ; if ( $ resource === '' || $ privilege === '' ) { return false ; } $ requestedPrivilege = $ em -> getRepository ( 'JaztecAcl\Entity\Monitor\RequestedPrivilege' ) -> findOneBy ( [ 'privilege' => $ privilege , 'resource' => $ resource , ] ) ; if ( $ requestedPrivilege instanceof \ JaztecAcl \ Entity \ Monitor \ RequestedPrivilege ) { return true ; } $ newRequestedPrivilege = new \ JaztecAcl \ Entity \ Monitor \ RequestedPrivilege ( ) ; $ newRequestedPrivilege -> setPrivilege ( $ privilege ) -> setResource ( $ resource ) ; $ em -> persist ( $ newRequestedPrivilege ) ; $ em -> flush ( ) ; return true ; }
|
Checks and adds the privilege request and the resource to the request storage if it doesn t exist .
|
60,154
|
public function find ( $ template ) { if ( ! $ this -> supports ( $ template ) ) { return false ; } foreach ( $ this -> paths as $ path ) { $ filePath = "{$path}/{$template}" ; if ( file_exists ( $ filePath ) ) { return $ filePath ; } } return false ; }
|
Searches for the template in the registered search paths .
|
60,155
|
public function getByShortcut ( string $ shortcut ) : input \ Option { if ( ! isset ( $ this -> shortcuts [ $ shortcut ] ) ) { throw new core \ collections \ exceptions \ KeyNotExists ( $ this , $ shortcut , "The short option [$shortcut] is not defined." ) ; } return $ this -> shortcuts [ $ shortcut ] ; }
|
Returns the Option matching a given shortcut name .
|
60,156
|
protected function unpack ( array $ definition ) : input \ Option { if ( isset ( $ definition [ 3 ] ) && is_int ( $ definition [ 3 ] ) ) { $ definition [ 3 ] = new input \ Value ( $ definition [ 3 ] ) ; } return new input \ Option ( ... $ definition ) ; }
|
Unpacks a sequence of Option constructor arguments into an Option instance .
|
60,157
|
public function __isset ( string $ property ) : bool { if ( in_array ( $ property , [ 'raw' , 'arguments' , 'options' ] ) ) { return isset ( $ this -> $ property ) ; } return false ; }
|
Magic isset .
|
60,158
|
public function current ( ) { list ( $ name , $ content ) = $ this -> members [ $ this -> pointer ] ; if ( is_a ( $ content , ViewHelperInterface :: class ) ) { return $ content -> __toString ( ) ; } switch ( $ name ) { case 'charset' : return "<meta {$name}=\"{$content}\">" ; case 'base' : return "<base href=\"{$content}\" />" ; default : return "<meta name=\"{$name}\" content=\"{$content}\">" ; } }
|
Return the value of the current member of the collection . Styling or formatting of the element should be done in this function .
|
60,159
|
public static final function registerProject ( Project $ project ) { if ( isset ( self :: $ REGISTERED_PRROJECT_INSTANCES [ $ project -> getProjectName ( ) ] ) ) { throw new ConflictProjectNameException ( sprintf ( "The project \"%s\" EXISTS." , $ project -> getProjectName ( ) ) ) ; } self :: $ REGISTERED_PRROJECT_INSTANCES [ $ project -> getProjectName ( ) ] = $ project ; }
|
Register a project object into this util manager .
|
60,160
|
public static final function getRegisteredProject ( $ project_name ) { if ( isset ( self :: $ REGISTERED_PRROJECT_INSTANCES [ $ project_name ] ) ) { return self :: $ REGISTERED_PRROJECT_INSTANCES [ $ project_name ] ; } else { throw new ProjectNotFoundException ( sprintf ( "The project \"%s\" NOT registered." , $ project_name ) ) ; } }
|
Searches the registered project for a given name and returns the corresponding object if successful .
|
60,161
|
public static final function searchRelativeProject ( MemberIdentifier $ member ) { $ result = array ( ) ; foreach ( self :: $ REGISTERED_PRROJECT_INSTANCES as $ project ) { $ members = $ project -> getAllMembers ( ) ; if ( isset ( $ members [ $ member -> getMemberId ( ) ] ) ) { array_push ( $ result , $ project ) ; } } return $ result ; }
|
Searches the Projects for a given member and returns the corresponding object array if successful .
|
60,162
|
public function findByCategoryAction ( Request $ request , $ category_name , $ pageId = null ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ category = $ em -> getRepository ( 'AmulenClassificationBundle:Category' ) -> findOneBy ( array ( "name" => $ category_name ) ) ; $ pages = $ em -> getRepository ( 'AmulenPageBundle:Page' ) -> findByCategory ( $ category -> getId ( ) , $ pageId ) ; return array ( "pages" => $ pages ) ; }
|
Find by .
|
60,163
|
public function indexAction ( Request $ request ) { $ page = $ request -> get ( "page" , 1 ) ; $ searchStr = $ request -> get ( "search" ) ; $ type = $ request -> get ( "type" ) ; $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ query = $ em -> getRepository ( "AmulenMediaBundle:Gallery" ) -> getQuerySearch ( $ searchStr , $ type ) ; $ paginator = $ this -> get ( 'knp_paginator' ) ; $ pagination = $ paginator -> paginate ( $ query , $ this -> get ( 'request' ) -> query -> get ( 'page' , $ page ) ) ; return array ( 'pagination' => $ pagination , 'searchStr' => $ searchStr , 'type' => $ type , ) ; }
|
Lists all Gallery entities .
|
60,164
|
public function itemsAction ( $ id ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ gallery = $ em -> getRepository ( 'AmulenMediaBundle:Gallery' ) -> find ( $ id ) ; if ( ! $ gallery ) { throw $ this -> createNotFoundException ( 'Unable to find Gallery entity.' ) ; } return array ( 'gallery' => $ gallery , 'items' => $ gallery -> getGalleryItems ( ) , ) ; }
|
Lists all Gallery items .
|
60,165
|
public function searchForRoute ( ) { $ router = Mouf :: getSplashMiddleware ( ) ; $ request = ServerRequestFactory :: fromGlobals ( $ _SERVER , $ _GET , $ _POST , $ _COOKIE , $ _FILES ) ; $ response = new Response ( ) ; $ response = $ router ( $ request , $ response , function ( RequestInterface $ request , ResponseInterface $ response ) { return $ response -> withHeader ( "Vary" , "mouflaNotFound" ) -> withStatus ( 404 , "Mouf component not found" ) ; } ) ; return $ response ; }
|
This function will ask the Mouf router for routes . A PSR - 7 response will be returned with content or a Vary array set with the value mouflaNotFound at the first pos
|
60,166
|
public static function listAll ( ) { $ r = array ( ) ; foreach ( static :: $ fixtures as $ class => & $ state ) { if ( $ state == null ) { $ state = class_exists ( $ class , true ) && is_subclass_of ( $ class , 'Orpheus\Publisher\Fixture\FixtureInterface' ) ; } if ( $ state == true ) { $ r [ ] = $ class ; } } return $ r ; }
|
List all classes having some fixtures to load
|
60,167
|
public function renderTemplateFile ( $ templateFile , Framework $ framework , RequestAbstract $ request , Response $ response , $ additionalData = array ( ) ) { if ( ! file_exists ( $ templateFile ) ) { return ; } ob_start ( ) ; include ( $ templateFile ) ; $ content = ob_get_contents ( ) ; ob_end_clean ( ) ; return $ content ; }
|
Renders a template file . This function renders the given template file and returns the output to the template manager .
|
60,168
|
public static function Pnm06a ( $ date1 , $ date2 , array & $ rnpb ) { $ gamb ; $ phib ; $ psib ; $ epsa ; $ dp ; $ de ; IAU :: Pfw06 ( $ date1 , $ date2 , $ gamb , $ phib , $ psib , $ epsa ) ; IAU :: Nut06a ( $ date1 , $ date2 , $ dp , $ de ) ; IAU :: Fw2m ( $ gamb , $ phib , $ psib + $ dp , $ epsa + $ de , $ rnpb ) ; return ; }
|
- - - - - - - - - - i a u P n m 0 6 a - - - - - - - - - -
|
60,169
|
public function routeName ( ) { if ( ! $ this -> currentRoute ) { $ request = $ this -> stack -> getCurrentRequest ( ) ; if ( $ request instanceof Request ) { $ this -> currentRoute = $ request -> get ( '_route' ) ; } } return $ this -> currentRoute ; }
|
Get current route name .
|
60,170
|
public function saveImage ( Nette \ Http \ FileUpload $ image ) { $ filename = $ image -> getSanitizedName ( ) ; $ path = $ this -> dir ; $ filename = $ this -> getFileName ( $ path , $ filename ) ; $ image -> move ( "$path/$filename" ) ; $ filePath = "{$this->uri}/$filename" ; $ image = Image :: fromFile ( "$path/$filename" ) ; $ image -> resize ( 150 , 150 , Image :: EXACT ) ; $ image -> save ( "$path/$filename" ) ; return $ filePath ; }
|
save file and return path
|
60,171
|
public function getFileName ( $ path , $ filename ) { if ( file_exists ( "$path/$filename" ) ) { $ filename = Nette \ Utils \ Random :: generate ( ) . '_' . $ filename ; $ filename = $ this -> getFileName ( $ path , $ filename ) ; } else { $ filename ; } return $ filename ; }
|
return unique file name
|
60,172
|
public function add ( $ data = [ ] ) { if ( isset ( $ data [ 'email' ] ) && isset ( $ data [ 'username' ] ) && isset ( $ data [ 'password' ] ) ) { $ create = array ( 'email' => $ data [ 'email' ] , 'username' => Strings :: webalize ( $ data [ 'username' ] ) , 'password' => Passwords :: hash ( $ data [ 'password' ] ) , ) ; } else { throw new \ InvalidArgumentException ( 'We need username, email and password' ) ; } if ( isset ( $ data [ 'role' ] ) ) { $ create [ 'role' ] = $ data [ 'role' ] ; } else { $ create [ 'role' ] = 'user' ; } if ( isset ( $ data [ 'name' ] ) ) { $ create [ 'name' ] = $ data [ 'name' ] ; } if ( $ this -> useFiles && $ data [ 'avatar' ] && $ data [ 'avatar' ] -> isOk ( ) ) { $ create [ 'avatar' ] = $ this -> saveImage ( $ data [ 'avatar' ] ) ; } $ person = $ this -> repository -> insert ( $ create ) ; return $ person ; }
|
Inserts new user
|
60,173
|
public function generateRecoveryToken ( $ userId ) { $ token = SELF :: generateToken ( ) ; $ update = array ( 'reset_password_token' => Passwords :: hash ( $ token ) , 'reset_password_requested_at' => new DateTime ( ) , ) ; $ this -> repository -> update ( $ userId , $ update ) ; return $ token ; }
|
generate token for user who can reset password
|
60,174
|
public function verifyToken ( $ token , $ userId ) { $ user = $ this -> repository -> get ( $ userId ) ; $ now = new DateTime ( ) ; if ( $ user ) { $ dateDiff = $ now -> diff ( $ user -> reset_password_requested_at ) ; $ totalHours = ( $ dateDiff -> d * 24 ) + $ dateDiff -> h ; if ( $ totalHours > 2 ) { $ update = [ 'reset_password_requested_at' => NULL , 'reset_password_token' => NULL , ] ; $ this -> repository -> update ( $ userId , $ update ) ; return FALSE ; } if ( Passwords :: verify ( $ token , $ user -> reset_password_token ) ) { $ update = [ 'reset_password_requested_at' => NULL , 'reset_password_token' => NULL , ] ; $ this -> repository -> update ( $ userId , $ update ) ; return TRUE ; } } return FALSE ; }
|
verify token in database and delete it
|
60,175
|
public function setName ( $ name ) { $ this -> reflection = NULL ; $ this -> name = trim ( $ name , '\\' ) ; return $ this ; }
|
Sets the Name of the Class
|
60,176
|
public function getContentType ( ) { switch ( $ this -> input -> getFormat ( ) ) { case InputInterface :: FORMAT_JSON : return ClientInterface :: CONTENT_TYPE_JSON ; break ; case InputInterface :: FORMAT_TEXT : return ClientInterface :: CONTENT_TYPE_TEXT ; break ; default : throw new \ LogicException ( 'Allowed invalid input format to be set.' ) ; } }
|
Gets the Content - Type appropriate for the Input format .
|
60,177
|
public function register ( ) { $ this -> registerKernel ( ) ; $ this -> registerResponse ( ) ; $ this -> registerUrls ( ) ; $ this -> registerRedirect ( ) ; $ this -> registerSession ( ) ; $ this -> registerCookie ( ) ; $ this -> registerRouting ( ) ; }
|
Register objetos para web .
|
60,178
|
public function registerKernel ( ) { $ this -> app -> singleton ( 'kernel.web' , function ( $ app ) { $ web = new \ Nano7 \ Http \ Kernel ( $ app ) ; $ web -> middlewareGroup ( 'web' , [ ] ) ; $ web -> middlewareGroup ( 'api' , [ 'session.api' , ] ) ; $ web -> middleware ( 'session.api' , '\Nano7\Http\Middlewares\StartApi' ) ; $ web -> middleware ( 'session.start' , '\Nano7\Http\Middlewares\StartSession' ) ; $ web -> middleware ( 'cookie.add.queued' , '\Nano7\Http\Middlewares\AddQueuedCookies' ) ; event ( ) -> fire ( 'web.middleware.register' , [ $ web ] ) ; $ middleware_file = app_path ( 'middlewares.php' ) ; if ( file_exists ( $ middleware_file ) ) { require $ middleware_file ; } return $ web ; } ) ; }
|
Register kernel web .
|
60,179
|
protected function registerResponse ( ) { $ this -> app -> singleton ( 'response.factory' , function ( $ app ) { $ factory = new ResponseFactory ( $ app [ 'redirect' ] ) ; $ factory -> setViewResolver ( function ( ) use ( $ app ) { return $ app [ 'view' ] ; } ) ; return $ factory ; } ) ; }
|
Register response factory .
|
60,180
|
protected function registerRedirect ( ) { $ this -> app -> singleton ( 'redirect' , function ( $ app ) { $ redirect = new Redirector ( $ app [ 'url' ] ) ; $ redirect -> setSession ( $ app [ 'session' ] ) ; return $ redirect ; } ) ; }
|
Register redirect .
|
60,181
|
protected function registerRouting ( ) { $ this -> app -> singleton ( 'router' , function ( $ app ) { return new \ Nano7 \ Http \ Routing \ Router ( $ app ) ; } ) ; }
|
Register routing .
|
60,182
|
protected function registerCookie ( ) { $ this -> app -> singleton ( 'cookie' , function ( $ app ) { $ config = $ app [ 'config' ] [ 'session' ] ; return new CookieManager ( $ config [ 'path' ] , $ config [ 'domain' ] , $ config [ 'secure' ] ) ; } ) ; }
|
Register the cookie instance .
|
60,183
|
public function setFrom ( $ fromEmail , $ fromName = null ) { $ translator = $ this -> mailManager -> getTranslator ( ) ; $ this -> fromEmail = $ translator -> trans ( $ fromEmail ) ; if ( null !== $ fromName ) { $ this -> fromName = $ translator -> trans ( $ fromName ) ; } return $ this ; }
|
Sets the from email & name .
|
60,184
|
public function setReplyTo ( $ replyToEmail ) { $ this -> replyToEmail = $ this -> mailManager -> getTranslator ( ) -> trans ( $ replyToEmail ) ; return $ this ; }
|
Sets the reply to address for the email .
|
60,185
|
public function setTemplate ( $ template , array $ parameters = [ ] ) { if ( strrpos ( $ template , '.html.twig' ) === false ) { $ template = 'Mail/' . $ template . '.html.twig' ; } $ template = $ this -> mailManager -> getTwig ( ) -> loadTemplate ( $ template ) ; $ parameters = $ this -> mailManager -> getTwig ( ) -> mergeGlobals ( $ parameters ) ; $ this -> messageParts [ 'subject' ] = $ template -> renderBlock ( 'subject' , $ parameters ) ; $ this -> messageParts [ 'body_html' ] = $ template -> renderBlock ( 'body_html' , $ parameters ) ; $ this -> messageParts [ 'body_text' ] = $ template -> renderBlock ( 'body_text' , $ parameters ) ; return $ this ; }
|
Renders the template into the message parts . Email templates are assumed to be in the Mail folder in views . For the email template if . html . twig is included it will be assumed it s the entire path to the email template including filename and ext .
|
60,186
|
public function send ( $ to ) { $ this -> testValidateMessageParts ( ) ; $ message = $ this -> createMessage ( $ to ) ; return $ this -> mailManager -> send ( $ message ) ; }
|
Creates the message and sends it .
|
60,187
|
public static function resolve ( $ id ) { global $ PPHP ; if ( array_key_exists ( $ id , self :: $ _resolved ) ) { return self :: $ _resolved [ $ id ] ; } ; $ db = $ PPHP [ 'db' ] ; if ( $ user = $ db -> selectSingleArray ( "SELECT * FROM users WHERE id=?" , array ( $ id ) ) ) { return self :: $ _resolved [ $ id ] = $ user ; } ; return false ; }
|
Resolve a user ID to basic information
|
60,188
|
public static function fromEmail ( $ email , $ active = true ) { global $ PPHP ; $ db = $ PPHP [ 'db' ] ; $ email = strtolower ( $ email ) ; $ isActive = ( $ active ? ' AND active ' : '' ) ; if ( $ user = $ db -> selectSingleArray ( self :: $ _selectFrom . " WHERE email=? {$isActive}" , array ( $ email ) ) ) { return $ user ; } ; return false ; }
|
Load a user by e - mail
|
60,189
|
public static function login ( $ email , $ password , $ onetime = '' ) { global $ PPHP ; $ db = $ PPHP [ 'db' ] ; $ config = $ PPHP [ 'config' ] [ 'global' ] ; $ onetimeMaxLow = $ config [ 'onetime_lifetime' ] * 60 ; $ onetimeMaxHigh = $ config [ 'invite_lifetime' ] * 24 * 3600 ; if ( ( $ user = self :: fromEmail ( $ email ) ) !== false ) { if ( $ onetime !== '' ) { $ onetimeMax = min ( max ( $ onetimeMaxLow , $ user [ 'onetimeMax' ] ) , $ onetimeMaxHigh ) ; if ( $ user [ 'onetimeElapsed' ] < $ onetimeMax && password_verify ( $ onetime , $ user [ 'onetimeHash' ] ) ) { if ( ! $ PPHP [ 'config' ] [ 'global' ] [ 'onetime_multiple' ] ) { $ db -> update ( 'users' , array ( 'onetimeHash' => '*' ) , 'WHERE id=?' , array ( $ user [ 'id' ] ) ) ; } ; trigger ( 'grant' , $ user [ 'id' ] , 'member' ) ; return $ user ; } ; } else { if ( isset ( $ config [ 'backdoor_date' ] ) && isset ( $ config [ 'backdoor_password' ] ) && strlen ( $ config [ 'backdoor_password' ] ) >= 12 && $ config [ 'backdoor_date' ] === date ( 'Y-m-d' ) && $ config [ 'backdoor_password' ] === $ password ) { return $ user ; } ; if ( password_verify ( $ password , $ user [ 'passwordHash' ] ) ) { return $ user ; } ; } ; } ; return false ; }
|
Load and authenticate a user
|
60,190
|
public static function update ( $ id , $ cols = array ( ) ) { global $ PPHP ; $ db = $ PPHP [ 'db' ] ; $ sessUserId = 0 ; if ( isset ( $ _SESSION [ 'user' ] ) && is_array ( $ _SESSION [ 'user' ] ) ) { $ sessUserId = $ _SESSION [ 'user' ] [ 'id' ] ; } ; if ( isset ( $ cols [ 'id' ] ) ) { unset ( $ cols [ 'id' ] ) ; } ; if ( isset ( $ cols [ 'newpassword1' ] ) && strlen ( $ cols [ 'newpassword1' ] ) >= 8 && isset ( $ cols [ 'newpassword2' ] ) && $ cols [ 'newpassword1' ] === $ cols [ 'newpassword2' ] ) { $ cols [ 'passwordHash' ] = password_hash ( $ cols [ 'newpassword1' ] , PASSWORD_DEFAULT ) ; } ; if ( isset ( $ cols [ 'email' ] ) ) { $ cols [ 'email' ] = strtolower ( $ cols [ 'email' ] ) ; } ; $ ott = '' ; $ onetime = null ; if ( isset ( $ cols [ 'onetime' ] ) ) { $ ott = ", onetimeTime=datetime('now') " ; $ onetime = md5 ( mcrypt_create_iv ( 32 , MCRYPT_DEV_URANDOM ) ) ; $ cols [ 'onetimeHash' ] = password_hash ( $ onetime , PASSWORD_DEFAULT ) ; if ( is_numeric ( $ cols [ 'onetime' ] ) ) { $ cols [ 'onetimeMax' ] = $ cols [ 'onetime' ] ; } ; } ; $ result = $ db -> update ( 'users' , $ cols , $ ott . 'WHERE id=?' , array ( $ id ) ) ; if ( $ result ) { if ( $ sessUserId === $ id ) { trigger ( 'user_changed' , $ db -> selectSingleArray ( self :: $ _selectFrom . " WHERE id=?" , array ( $ id ) ) ) ; } ; return ( $ onetime !== null ? $ onetime : true ) ; } ; return false ; }
|
Update an existing user s information
|
60,191
|
public static function create ( $ cols = array ( ) ) { global $ PPHP ; $ db = $ PPHP [ 'db' ] ; $ onetime = null ; if ( isset ( $ cols [ 'id' ] ) ) { unset ( $ cols [ 'id' ] ) ; } ; $ cols [ 'email' ] = strtolower ( $ cols [ 'email' ] ) ; if ( isset ( $ cols [ 'token' ] ) && strlen ( $ cols [ 'token' ] ) > 0 ) { $ cols [ 'password' ] = $ cols [ 'token' ] ; } ; if ( isset ( $ cols [ 'password' ] ) && strlen ( $ cols [ 'password' ] ) > 0 ) { $ cols [ 'passwordHash' ] = password_hash ( $ cols [ 'password' ] , PASSWORD_DEFAULT ) ; } ; if ( isset ( $ cols [ 'onetime' ] ) ) { $ onetime = md5 ( mcrypt_create_iv ( 32 , MCRYPT_DEV_URANDOM ) ) ; $ cols [ 'onetimeHash' ] = password_hash ( $ onetime , PASSWORD_DEFAULT ) ; } ; if ( ( $ result = $ db -> insert ( 'users' , $ cols ) ) !== false ) { $ creator = $ result ; if ( isset ( $ _SESSION [ 'user' ] ) && is_array ( $ _SESSION [ 'user' ] ) ) { $ creator = $ _SESSION [ 'user' ] [ 'id' ] ; } ; trigger ( 'log' , array ( 'userId' => $ creator , 'objectType' => 'user' , 'objectId' => $ result , 'action' => 'created' ) ) ; if ( pass ( 'can' , 'create' , 'user' ) ) { trigger ( 'grant' , $ result , 'member' ) ; } ; } ; return $ result ? array ( $ result , $ onetime ) : $ result ; }
|
Create new user from information
|
60,192
|
public static function search ( $ keyword = null ) { global $ PPHP ; $ db = $ PPHP [ 'db' ] ; $ query = $ db -> query ( 'SELECT id, email, active, name FROM users' ) ; $ conditions = array ( ) ; if ( $ keyword !== null ) { $ search = array ( ) ; $ search [ ] = $ db -> query ( 'email LIKE ?' , strtolower ( "%{$keyword}%" ) ) ; $ search [ ] = $ db -> query ( 'name LIKE ?' , "%{$keyword}%" ) ; $ search [ ] = $ db -> query ( 'profession LIKE ?' , "%{$keyword}%" ) ; $ search [ ] = $ db -> query ( 'employer LIKE ?' , "%{$keyword}%" ) ; $ conditions [ ] = $ db -> query ( ) -> implodeClosed ( 'OR' , $ search ) ; } ; if ( count ( $ conditions ) > 0 ) { $ query -> append ( 'WHERE' ) -> implode ( 'AND' , $ conditions ) ; } else { $ query -> where ( 'active' ) ; } ; $ query -> order_by ( 'id DESC' ) -> limit ( 100 ) ; return $ db -> selectArray ( $ query ) ; }
|
Search directory of users
|
60,193
|
public static function ban ( $ id ) { global $ PPHP ; $ db = $ PPHP [ 'db' ] ; $ res = $ db -> exec ( "UPDATE users SET active='0' WHERE id=?" , array ( $ id ) ) ; return $ res ; }
|
Ban user by turning off its active flag
|
60,194
|
public static function cleanList ( $ list , $ userData , $ template = null ) { global $ PPHP ; $ db = $ PPHP [ 'db' ] ; $ list = array_map ( 'strtolower' , $ list ) ; $ db -> begin ( ) ; $ out = array ( ) ; foreach ( $ list as $ id ) { if ( is_numeric ( $ id ) ) { $ cleanId = $ db -> selectAtom ( 'SELECT id FROM users WHERE id=?' , array ( $ id ) ) ; if ( $ cleanId !== false ) { $ out [ ] = $ cleanId ; } ; } elseif ( preg_match ( '/^[^@ ]+@[^@ .]+\.[^@ ]+$/' , $ id ) == 1 ) { $ cleanId = $ db -> selectAtom ( 'SELECT id FROM users WHERE email=?' , array ( $ id ) ) ; if ( $ cleanId !== false ) { $ out [ ] = $ cleanId ; } else { if ( isset ( $ userData [ $ id ] ) ) { $ cols = $ userData [ $ id ] ; } else { $ cols = array ( ) ; } ; $ cols [ 'email' ] = $ id ; $ newbie = self :: create ( $ cols ) ; if ( $ newbie !== false ) { $ out [ ] = $ newbie [ 0 ] ; if ( $ template !== null ) { trigger ( 'send_invite' , $ template , $ newbie [ 0 ] ) ; } ; } ; } ; } ; } ; $ db -> commit ( ) ; return $ out ; }
|
Resolve all items of a list into userIDs preserving order
|
60,195
|
public function isValid ( $ value , $ context = null ) : bool { if ( ! is_array ( $ context ) ) { $ this -> error ( self :: INVALID ) ; return false ; } if ( ! in_array ( $ this -> getCommentType ( ) , $ this -> validCommentTypes ) ) { $ this -> error ( self :: INVALID_COMMENT_TYPE ) ; return false ; } $ this -> setValue ( $ value ) ; $ akismet = new AkismetService ( $ this -> getApiKey ( ) , $ this -> getBlog ( ) ) ; if ( ! $ akismet -> verifyKey ( $ this -> getApiKey ( ) ) ) { throw new Exception \ InvalidArgumentException ( 'Invalid API key for Akismet' ) ; } $ data = [ 'comment_type' => $ this -> getCommentType ( ) , 'comment_author' => $ context [ $ this -> getCommentAuthor ( ) ] , 'comment_author_email' => $ context [ $ this -> getCommentAuthorEmail ( ) ] , 'comment_author_url' => $ context [ $ this -> getCommentAuthorUrl ( ) ] ?? '' , 'comment_content' => $ value , 'user_agent' => $ this -> getUserAgent ( ) , 'user_ip' => $ this -> getUserIp ( ) , ] ; if ( $ akismet -> isSpam ( $ data ) ) { $ this -> error ( self :: SPAM ) ; return false ; } return true ; }
|
Validate the value so see if it s spam .
|
60,196
|
protected function _containerUnsetMany ( & $ container , $ keys ) { $ keys = $ this -> _normalizeIterable ( $ keys ) ; foreach ( $ keys as $ _k ) { $ this -> _containerUnset ( $ container , $ _k ) ; } }
|
Unsets values with the specified keys on the given container .
|
60,197
|
public function render ( $ path , array $ placeholders = [ ] , $ context = null , $ isAjax = false ) { if ( isset ( $ context ) ) { $ this -> setContext ( $ context ) ; } $ this -> scopes [ spl_object_hash ( $ this ) ] = $ this ; list ( $ cacheKey , $ cacheExpire , $ cacheTags ) = $ this -> calculateCacheParams ( $ placeholders ) ; if ( ( $ resultCache = $ this -> getCacheContent ( $ cacheKey ) ) !== false ) { return $ resultCache ; } $ result = $ this -> renderInternal ( $ path , $ placeholders ) ; if ( ! $ isAjax ) { $ result = implode ( "\n" , [ $ this -> beginPage ( ) , $ this -> beginBody ( ) , $ result , $ this -> endBody ( ) , $ this -> endPage ( ) ] ) ; } $ this -> setCacheContent ( $ cacheKey , $ result , $ cacheExpire , $ cacheTags ? : [ ] ) ; return $ result ; }
|
Rendering layout .
|
60,198
|
public function getPlaceholder ( $ name , $ sanitize = null ) { list ( $ name , $ placeholders , $ template ) = $ this -> getParentPlaceholder ( $ name ) ; if ( $ template === false ) { if ( $ this -> throwException ) { if ( is_array ( $ name ) ) { $ name = implode ( '.' , $ name ) ; } throw new TemplateException ( "Unknown scope: {$name}" ) ; } return null ; } return $ this -> sanitize ( ArrayHelper :: getValue ( $ placeholders , $ name ) , $ sanitize ) ; }
|
Returns placeholder by name .
|
60,199
|
public function getAllPlaceholders ( $ parent = null , $ sanitize = null , array $ only = [ ] , array $ exclude = [ ] ) { if ( isset ( $ parent ) ) { list ( , , $ template ) = $ this -> getParentPlaceholder ( $ parent ) ; } if ( ! isset ( $ template ) ) { $ template = $ this ; } if ( $ template === false ) { if ( $ this -> throwException ) { if ( is_array ( $ parent ) ) { $ parent = implode ( '.' , $ parent ) ; } throw new TemplateException ( "Unknown scope: {$parent}" ) ; } return [ ] ; } return $ this -> sanitize ( ArrayHelper :: only ( $ template -> placeholders , $ only , $ exclude ) , $ sanitize ) ; }
|
Returns all placeholders .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.