idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
57,900
|
private function parseResponseHeaders ( $ raw_response_headers ) { $ response_header_array = explode ( "\r\n\r\n" , $ raw_response_headers ) ; $ response_header = '' ; for ( $ i = count ( $ response_header_array ) - 1 ; $ i >= 0 ; $ i -- ) { if ( stripos ( $ response_header_array [ $ i ] , 'HTTP/' ) === 0 ) { $ response_header = $ response_header_array [ $ i ] ; break ; } } $ response_headers = new CaseInsensitiveArray ( ) ; list ( $ first_line , $ headers ) = $ this -> parseHeaders ( $ response_header ) ; $ response_headers [ 'Status-Line' ] = $ first_line ; foreach ( $ headers as $ key => $ value ) { $ response_headers [ $ key ] = $ value ; } return $ response_headers ; }
|
Parse Response Headers
|
57,901
|
public static function array_flatten_multidim ( $ array , $ prefix = false ) { $ return = array ( ) ; if ( is_array ( $ array ) || is_object ( $ array ) ) { if ( empty ( $ array ) ) { $ return [ $ prefix ] = '' ; } else { foreach ( $ array as $ key => $ value ) { if ( is_scalar ( $ value ) ) { if ( $ prefix ) { $ return [ $ prefix . '[' . $ key . ']' ] = $ value ; } else { $ return [ $ key ] = $ value ; } } else { if ( $ value instanceof \ CURLFile ) { $ return [ $ key ] = $ value ; } else { $ return = array_merge ( $ return , self :: array_flatten_multidim ( $ value , $ prefix ? $ prefix . '[' . $ key . ']' : $ key ) ) ; } } } } } elseif ( $ array === null ) { $ return [ $ prefix ] = $ array ; } return $ return ; }
|
Array Flatten Multidim
|
57,902
|
public function buildCommand ( ) { $ command = $ this -> getCommand ( ) ; $ output = $ this -> output !== null ? $ this -> output : $ this -> getDefaultOutput ( ) ; return $ command . ' > ' . $ output . ' 2>&1' ; }
|
build the exec command
|
57,903
|
public function isDue ( ) { $ date = Carbon :: now ( ) ; if ( $ this -> timezone ) { $ date -> setTimezone ( $ this -> timezone ) ; } $ response = CronExpression :: factory ( $ this -> getPatternString ( ) ) -> isDue ( $ date -> toDateTimeString ( ) ) ; return $ response && $ this -> resolveWhen ( ) ; }
|
check the event for call
|
57,904
|
private function runClosureTask ( ) { if ( $ this -> before !== null ) { $ this -> resolveBeforeCallbacks ( ) ; } call_user_func ( $ this -> command ) ; if ( $ this -> after !== null ) { $ this -> resolveAfterCallbacks ( ) ; } }
|
run the closure
|
57,905
|
private function runExecTask ( ) { chdir ( $ this -> resolveBasePath ( ) ) ; $ process = new Process ( $ this -> getCommand ( ) ) ; $ process -> run ( ) ; }
|
run the exec task
|
57,906
|
protected static function handleUniqueColumns ( ) { $ class = get_called_class ( ) ; if ( self :: testClassForUniqueId ( $ class ) == true ) { $ class :: creating ( function ( $ object ) use ( $ class ) { $ object -> { $ object -> primaryKey } = $ class :: findExistingReferences ( $ class , $ object -> primaryKey ) ; } ) ; } if ( isset ( $ class :: $ uniqueStringColumns ) && count ( $ class :: $ uniqueStringColumns ) > 0 ) { foreach ( $ class :: $ uniqueStringColumns as $ field ) { $ class :: creating ( function ( $ object ) use ( $ class , $ field ) { $ object -> { $ field } = $ class :: findExistingReferences ( $ class , $ field ) ; } ) ; } } }
|
Make sure that any unique column is given a unique string .
|
57,907
|
public function uploadFile ( ) { if ( ! isset ( Yii :: app ( ) -> params [ 'ciims_plugins' ] [ 'upload' ] ) ) { Yii :: import ( 'cii.utilities.CiiFileUploader' ) ; $ className = 'CiiFileUploader' ; } else $ className = Yii :: app ( ) -> params [ 'ciims_plugins' ] [ 'upload' ] [ 'class' ] ; $ config = isset ( Yii :: app ( ) -> params [ 'ciims_plugins' ] [ 'upload' ] [ 'options' ] ) ? Yii :: app ( ) -> params [ 'ciims_plugins' ] [ 'upload' ] [ 'options' ] : array ( ) ; $ class = new $ className ( $ config ) ; $ this -> _result = $ class -> upload ( ) ; $ this -> _response = $ this -> _handleResourceUpload ( $ this -> _result [ 'url' ] ) ; return $ this -> _response ; }
|
Handles all uploads
|
57,908
|
private function _handleResourceUpload ( $ value ) { if ( Cii :: get ( $ this -> _result , 'success' , false ) == true ) { $ meta = ContentMetadata :: model ( ) -> findbyAttributes ( array ( 'content_id' => $ this -> _id , 'key' => $ this -> _result [ 'filename' ] ) ) ; if ( $ meta == NULL ) $ meta = new ContentMetadata ; $ meta -> content_id = $ this -> _id ; $ meta -> key = $ this -> _result [ 'filename' ] ; $ meta -> value = $ value ; if ( $ meta -> save ( ) ) { if ( $ this -> _promote ) $ this -> _promote ( $ this -> _result [ 'filename' ] ) ; $ this -> _result [ 'filepath' ] = $ value ; return htmlspecialchars ( CJSON :: encode ( $ this -> _result ) , ENT_NOQUOTES ) ; } else throw new CHttpException ( 400 , Yii :: t ( 'ciims.misc' , 'Unable to save uploaded image.' ) ) ; } else throw new CHttpException ( 400 , $ this -> _result [ 'error' ] ) ; }
|
Generic function to handle all resource uploads
|
57,909
|
private function _promote ( $ key = NULL ) { $ promotedKey = 'blog-image' ; if ( $ this -> _id == NULL || $ key == NULL ) return false ; $ model = ContentMetadata :: model ( ) -> findByAttributes ( array ( 'content_id' => $ this -> _id , 'key' => $ key ) ) ; if ( $ model -> key == $ promotedKey ) return true ; $ model2 = ContentMetadata :: model ( ) -> findByAttributes ( array ( 'content_id' => $ this -> _id , 'key' => $ promotedKey ) ) ; if ( $ model2 === NULL ) { $ model2 = new ContentMetadata ; $ model2 -> content_id = $ this -> _id ; $ model2 -> key = $ promotedKey ; } $ model2 -> value = $ model -> value ; if ( ! $ model2 -> save ( ) ) return false ; return true ; }
|
Promotes an image to blog - image
|
57,910
|
public function login ( $ provider , Request $ request ) { $ user = $ this -> authenticateUser -> authenticate ( $ provider , $ request -> has ( 'code' ) ) ; auth ( ) -> login ( $ user , true ) ; return redirect ( ) -> intended ( route ( 'core::home' ) ) ; }
|
log a user using socialite
|
57,911
|
public function setupUser ( Event $ event , $ user ) { $ UsersGroups = TableRegistry :: get ( 'Wasabi/Core.UsersGroups' ) ; $ user [ 'group_id' ] = $ UsersGroups -> getGroupIds ( $ user [ 'id' ] ) ; $ user [ 'password_hashed' ] = $ UsersGroups -> Users -> get ( $ user [ 'id' ] , [ 'fields' => [ 'password' ] ] ) -> get ( 'password' ) ; return $ user ; }
|
Setup the group ids and set the password of the logged in users to store it in the session . Reset failed login attempts .
|
57,912
|
public function onFailedLogin ( Event $ event , $ clientIp , $ loginField , $ loginFieldValue ) { $ recognitionTime = Wasabi :: setting ( 'Core.Auth.failed_login_recognition_time' ) ; $ maxLoginAttempts = Wasabi :: setting ( 'Core.Auth.max_login_attempts' ) ; $ past = ( new \ DateTime ( ) ) -> modify ( '-' . $ recognitionTime . ' minutes' ) ; $ LoginLogs = TableRegistry :: get ( 'Wasabi/Core.LoginLogs' ) ; $ loginLog = $ LoginLogs -> newEntity ( [ 'client_ip' => $ clientIp , 'login_field' => $ loginField , 'login_field_value' => $ loginFieldValue , 'success' => false ] ) ; $ failedLogins = $ LoginLogs -> find ( ) -> where ( [ 'client_ip' => $ clientIp , 'success' => false ] ) -> andWhere ( function ( QueryExpression $ exp ) use ( $ past ) { return $ exp -> gt ( 'created' , $ past -> format ( 'Y-m-d H:i:s' ) ) ; } ) -> count ( ) ; if ( ( $ failedLogins + 1 ) >= $ maxLoginAttempts ) { $ loginLog -> set ( 'blocked' , true ) ; } $ LoginLogs -> save ( $ loginLog ) ; }
|
On a failed login attempt increase the failed login attempt of the corresponding user and update the last failed login attempt datetime .
|
57,913
|
public function actionCreate ( ) { $ form = new DomainForm ( ) ; if ( $ form -> load ( Yii :: $ app -> request -> post ( ) ) && $ form -> validate ( ) ) { try { $ model = $ this -> service -> create ( $ form ) ; return $ this -> redirect ( [ 'view' , 'id' => $ model -> id ] ) ; } catch ( \ DomainException $ e ) { Yii :: $ app -> errorHandler -> logException ( $ e ) ; Yii :: $ app -> session -> setFlash ( 'error' , $ e -> getMessage ( ) ) ; } } return $ this -> render ( 'create' , [ 'model' => $ form , ] ) ; }
|
Creates a new Domain model . If creation is successful the browser will be redirected to the view page .
|
57,914
|
public function beforeUpdate ( ) { $ this -> owner -> setAttribute ( $ this -> imageAttribute , $ this -> owner -> getOldAttribute ( $ this -> imageAttribute ) ) ; }
|
Before update action
|
57,915
|
public function getImagePath ( ) { if ( $ this -> imagePath === null ) { $ this -> imagePath = '/images/' . strtolower ( ( new \ ReflectionClass ( $ this -> owner ) ) -> getShortName ( ) ) ; } return $ this -> imagePath ; }
|
Get image path
|
57,916
|
public function getImageAbsolutePath ( ) { if ( $ this -> _imageAbsolutePath === null ) { $ this -> _imageAbsolutePath = Yii :: getAlias ( '@webroot' ) . '/' . ( defined ( 'IS_BACKEND' ) ? '../' : '' ) . ltrim ( $ this -> getImagePath ( ) , '/' ) ; if ( ! file_exists ( $ this -> _imageAbsolutePath ) ) { yii \ helpers \ FileHelper :: createDirectory ( $ this -> _imageAbsolutePath ) ; } } return $ this -> _imageAbsolutePath ; }
|
Get absolute team image path in filesystem
|
57,917
|
public function hasImage ( ) { $ image = $ this -> owner -> getAttribute ( $ this -> imageAttribute ) ; return ! empty ( $ image ) && $ image != $ this -> imageDefault ; }
|
Check team image
|
57,918
|
public function getImageUrl ( ) { return ! $ this -> hasImage ( ) ? $ this -> getImageDefaultUrl ( ) : $ this -> _imageUrl ( $ this -> owner -> getAttribute ( $ this -> imageAttribute ) ) ; }
|
Get team image URL
|
57,919
|
public function imageChangeByUpload ( ) { $ formName = $ this -> owner -> formName ( ) ; if ( ! empty ( $ _POST [ $ formName ] [ $ this -> imageAttribute ] ) && $ _POST [ $ formName ] [ $ this -> imageAttribute ] == 'empty' ) { $ this -> imageReset ( ) ; } else { if ( ! empty ( $ _FILES [ $ formName ] [ 'tmp_name' ] [ $ this -> imageAttribute ] ) ) { $ this -> imageChange ( [ $ _FILES [ $ formName ] [ 'name' ] [ $ this -> imageAttribute ] => $ _FILES [ $ formName ] [ 'tmp_name' ] [ $ this -> imageAttribute ] ] ) ; } } }
|
Change image by uploaded file
|
57,920
|
public function imageReset ( ) { $ this -> imageRemoveFile ( ) ; $ this -> owner -> setAttribute ( $ this -> imageAttribute , null ) ; $ this -> owner -> updateAttributes ( [ $ this -> imageAttribute ] ) ; }
|
Reset image to default
|
57,921
|
protected function read ( $ namespace , $ group , $ locale , $ item ) { $ this -> load ( $ namespace , $ group , $ locale ) ; $ data = Arr :: get ( $ this -> loaded [ $ namespace ] [ $ group ] [ $ locale ] , $ item ) ; return $ data ; }
|
Retrieve a data out the loaded array .
|
57,922
|
protected function handleDoubleQuotedString ( File $ phpcsFile , $ stackPointer , $ workingString ) { $ stringTokens = token_get_all ( '<?php ' . $ workingString ) ; foreach ( $ stringTokens as $ token ) { if ( is_array ( $ token ) && $ token [ 0 ] === T_VARIABLE ) { $ error = 'Variable "%s" not allowed in double quoted string; use concatenation and single quotes instead' ; $ data = [ $ token [ 1 ] ] ; $ phpcsFile -> addError ( $ error , $ stackPointer , 'Prduction.DisallowDoubleQuoteUsage.ContainsVar' , $ data ) ; } } }
|
This method adds errors if double quoted strings contain variables .
|
57,923
|
protected function handleSpecialChars ( File $ phpcsFile , $ stackPointer , $ workingString ) { foreach ( $ this -> specialChars as $ testChar ) { if ( strpos ( $ workingString , $ testChar ) !== false ) { $ error = 'Please use constants (LF, CR, CRLF, ...) using concatenation instead of "%s" in double quotes' ; $ errorMsg = sprintf ( $ error , $ testChar ) ; $ phpcsFile -> addError ( $ errorMsg , $ stackPointer , 'Prduction.DisallowDoubleQuoteUsage.ContainsVar' ) ; } } }
|
This method adds errors if double quoted strings contain control characters like \ n .
|
57,924
|
public function getNextDefinition ( input \ parameter \ values \ Arguments $ values ) : ? input \ Argument { $ nextIndex = $ values -> count ( ) ; $ items = array_values ( $ this -> items ) ; if ( isset ( $ items [ $ nextIndex ] ) ) { return $ items [ $ nextIndex ] ; } if ( isset ( $ items [ $ nextIndex - 1 ] ) && $ items [ $ nextIndex - 1 ] -> getValue ( ) instanceof input \ values \ Multiple ) { return $ items [ $ nextIndex - 1 ] ; } return null ; }
|
Returns the next Input Argument Definition for the given Input Argument values collection unless the collection already exceeds the number of defined Arguments .
|
57,925
|
public function add ( core \ interfaces \ Named $ argument ) : core \ collections \ interfaces \ NamedObjectSet { if ( $ this -> hasMultiparam ) { throw new \ LogicException ( "Cannot define additional arguments after an Argument [name: " . end ( $ this -> items ) -> getName ( ) . "] which accepts multiple values." ) ; } if ( ! $ argument instanceof input \ Argument ) { throw new \ InvalidArgumentException ( 'Expected an instance of [' . input \ Argument :: class . '], got [' . diagnostics \ Debug :: getTypeName ( $ argument ) . '] instead.' ) ; } $ name = $ argument -> getName ( ) ; $ value = $ argument -> getValue ( ) ; if ( isset ( $ this -> items [ $ name ] ) ) { throw new \ LogicException ( "An Argument with this name [$name] has already been defined." ) ; } if ( $ value -> is ( input \ Value :: REQUIRED ) ) { if ( $ this -> hasOptional ) { throw new \ LogicException ( "Cannot add a required Argument after an optional one." ) ; } ++ $ this -> required ; } else { $ this -> hasOptional = true ; } if ( $ value instanceof input \ values \ Multiple ) { $ this -> hasMultiparam = true ; } $ this -> items [ $ name ] = $ argument ; return $ this ; }
|
Adds a Input Argument Definition to this collection .
|
57,926
|
protected function unpack ( array $ definition ) : input \ Argument { if ( isset ( $ definition [ 2 ] ) && is_int ( $ definition [ 2 ] ) ) { $ definition [ 2 ] = new input \ Value ( $ definition [ 2 ] ) ; } return new input \ Argument ( ... $ definition ) ; }
|
Unpacks a sequence of Argument constructor arguments into an Argument instance .
|
57,927
|
protected function guardAgainstNull ( $ data , $ dataName = 'Argument' , $ exceptionClass = 'Zend\Stdlib\Exception\InvalidArgumentException' ) { if ( null === $ data ) { $ message = sprintf ( '%s cannot be null' , $ dataName ) ; throw new $ exceptionClass ( $ message ) ; } }
|
Verify that the data is not null
|
57,928
|
protected function send ( array $ args = [ ] ) { $ this -> log -> debug ( 'send()ing command' , $ args ) ; $ response = RespUtils :: deserialize ( $ this -> stream -> write ( RespUtils :: serialize ( $ args ) ) ) ; $ this -> log -> debug ( 'response' , [ $ response ] ) ; return $ response ; }
|
Send request and retrieve response to the connected disque node .
|
57,929
|
protected function mapJobs ( array $ list ) { return array_map ( function ( $ element ) { return Job :: create ( [ 'queue' => $ element [ 0 ] , 'id' => $ element [ 1 ] , 'body' => isset ( $ element [ 2 ] ) ? $ element [ 2 ] : '' , ] ) ; } , $ list ) ; }
|
Map Disque s job responses to Job objects .
|
57,930
|
public function getOGTypeMapping ( $ name , $ subname = null ) { if ( $ types = $ this -> owner -> config ( ) -> open_graph_types ) { if ( isset ( $ types [ $ name ] ) ) { if ( is_array ( $ types [ $ name ] ) && $ subname ) { return $ types [ $ name ] [ $ subname ] ; } if ( ! is_array ( $ types [ $ name ] ) ) { return $ types [ $ name ] ; } } } }
|
Answers the open graph type for the mapping with the given name and optional sub - name .
|
57,931
|
public function getOGTypeNamespace ( ) { if ( $ type = $ this -> owner -> OGType ) { return ( strpos ( $ type , '.' ) !== false ) ? explode ( '.' , $ type ) [ 0 ] : $ type ; } }
|
Answers the open graph type namespace for the page .
|
57,932
|
public function getOGImage ( ) { $ config = $ this -> getSiteConfig ( ) ; if ( ( $ image = $ this -> owner -> MetaImage ) && $ image -> exists ( ) ) { return $ image -> AbsoluteURL ; } if ( $ config -> AppIconLargeID && $ config -> AppIconLarge ( ) -> exists ( ) ) { return $ config -> AppIconLarge ( ) -> AbsoluteURL ; } }
|
Answers the image for the open graph tag .
|
57,933
|
public function MetaTags ( & $ tags ) { if ( ! preg_match ( '/[\n]$/' , $ tags ) ) { $ tags .= "\n" ; } foreach ( $ this -> owner -> config ( ) -> open_graph_metadata as $ tag => $ property ) { $ this -> addMetaTag ( $ tags , "og:{$tag}" , $ this -> owner -> $ property ) ; } }
|
Appends the additional open graph tags to the provided meta tags .
|
57,934
|
protected function addMetaTag ( & $ tags , $ property = null , $ content = null ) { if ( is_array ( $ content ) ) { foreach ( $ content as $ value ) { $ this -> addMetaTag ( $ tags , $ property , $ value ) ; } } else { if ( $ content ) { $ tags .= $ this -> getMetaTag ( $ property , $ content ) ; } } }
|
Appends a meta tag with the given property name and content value to the provided tags variable .
|
57,935
|
protected function getMetaTag ( $ property = null , $ content = null ) { return sprintf ( "<meta property=\"%s\" content=\"%s\" />\n" , Convert :: raw2att ( $ property ) , Convert :: raw2att ( $ content ) ) ; }
|
Answers a meta tag with the given property name and content value .
|
57,936
|
protected function getNamespaceURI ( $ prefix ) { $ namespaces = $ this -> owner -> config ( ) -> open_graph_namespaces ; if ( isset ( $ namespaces [ $ prefix ] ) ) { return $ namespaces [ $ prefix ] ; } }
|
Answers the namespace URI for the specified prefix .
|
57,937
|
public function push ( $ socketMessage ) { $ message = json_decode ( $ socketMessage , true ) ; if ( $ message [ 'channel' ] === 'global' ) { if ( ! empty ( $ this -> subscribedChannels ) ) { return ; } foreach ( $ this -> subscribedChannels as $ channel ) { $ channel -> broadcast ( $ message ) ; } return ; } if ( ! array_key_exists ( $ message [ 'channel' ] , $ this -> subscribedChannels ) ) { return ; } $ channel = $ this -> subscribedChannels [ $ message [ 'channel' ] ] ; $ channel -> broadcast ( $ message ) ; }
|
Push socket messages to subscribers of individual channels . Broadcasting to all subscribers is possible via the global channel .
|
57,938
|
public function insert ( $ name , $ value , $ priority = 0 ) { if ( ! isset ( $ this -> items [ $ name ] ) ) { $ this -> count ++ ; } $ this -> sorted = false ; $ this -> items [ $ name ] = [ 'data' => $ value , 'priority' => ( int ) $ priority , 'serial' => $ this -> serial ++ , ] ; }
|
Insert a new item .
|
57,939
|
public function remove ( $ name ) { if ( isset ( $ this -> items [ $ name ] ) ) { $ this -> count -- ; } unset ( $ this -> items [ $ name ] ) ; }
|
Remove a item .
|
57,940
|
public function clear ( ) { $ this -> items = [ ] ; $ this -> serial = 0 ; $ this -> count = 0 ; $ this -> sorted = false ; }
|
Remove all items .
|
57,941
|
protected function sort ( ) { if ( ! $ this -> sorted ) { uasort ( $ this -> items , [ $ this , 'compare' ] ) ; $ this -> sorted = true ; } }
|
Sort all items .
|
57,942
|
protected function compare ( array $ item1 , array $ item2 ) { return ( $ item1 [ 'priority' ] === $ item2 [ 'priority' ] ) ? ( $ item1 [ 'serial' ] > $ item2 [ 'serial' ] ? - 1 : 1 ) * $ this -> isLIFO : ( $ item1 [ 'priority' ] > $ item2 [ 'priority' ] ? - 1 : 1 ) ; }
|
Compare the priority of two items .
|
57,943
|
public function toArray ( $ flag = self :: EXTR_DATA ) { $ this -> sort ( ) ; if ( $ flag == self :: EXTR_BOTH ) { return $ this -> items ; } return array_map ( function ( $ item ) use ( $ flag ) { return ( $ flag == PriorityList :: EXTR_PRIORITY ) ? $ item [ 'priority' ] : $ item [ 'data' ] ; } , $ this -> items ) ; }
|
Return list as array
|
57,944
|
protected function imageUpload ( $ field , UploadedFile $ file ) { if ( UPLOAD_ERR_OK == $ file -> getError ( ) ) { $ asserts = $ this -> getAsserts ( ) [ $ field ] ; foreach ( $ asserts as $ assert ) { if ( $ assert instanceof Image ) { $ path = $ file -> getPathname ( ) ; $ pathWithExtension = $ path . '.' . $ file -> guessExtension ( ) ; rename ( $ path , $ pathWithExtension ) ; try { $ this -> resize ( $ pathWithExtension , $ assert -> maxWidth , $ assert -> maxHeight ) ; } catch ( ImageWorkshopException $ e ) { } rename ( $ pathWithExtension , $ path ) ; } } } }
|
File upload callback Resizes the image according to validation constraints
|
57,945
|
public function addAttribute ( $ key , $ value , $ type = Attribute :: T_DEFAULT ) { $ this -> attributes [ ] = new Attribute ( $ key , $ value , $ type ) ; return $ this ; }
|
Append an attributes to match
|
57,946
|
public function addPseudo ( $ name , $ argument = false ) { $ this -> pseudos [ ] = new Pseudo ( $ name , $ argument ) ; return $ this ; }
|
Append an pseudo class to match
|
57,947
|
public function add ( $ type = false , $ identification = false , $ tagName = false , $ classes = false , $ pseudos = false ) { return $ this -> selector = new self ( $ this , $ type , $ identification , $ tagName , $ classes , $ pseudos ) ; }
|
Creates an sets the child selector
|
57,948
|
public function convert ( $ dotnetFormat ) { $ stringLiterals = [ ] ; $ callback = function ( $ matches ) use ( & $ stringLiterals ) { $ stringLiterals [ ] = reset ( $ matches ) ; return '%s' ; } ; $ dotnetFormatPlaceholders = preg_replace_callback ( $ this -> getPatternStringLiteralsDotNet ( ) , $ callback , $ dotnetFormat ) ; $ callback = function ( $ matches ) use ( $ dotnetFormat ) { $ specifier = reset ( $ matches ) ; if ( ! isset ( $ this -> dotnetToPhp [ $ specifier ] ) ) { throw new UnsupportedFormatException ( $ dotnetFormat , $ specifier ) ; } return $ this -> dotnetToPhp [ $ specifier ] ; } ; $ phpFormatPlaceholders = preg_replace_callback ( $ this -> getPatternSpecifiersDotnet ( ) , $ callback , $ dotnetFormatPlaceholders ) ; $ callback = function ( $ value ) { if ( $ value == '\\' ) { return $ value ; } if ( preg_match ( '/^["\'].+["\']$/' , $ value ) ) { return $ value ; } $ value = stripslashes ( $ value ) ; return $ value ; } ; $ stringLiterals = array_map ( $ callback , $ stringLiterals ) ; $ stringLiterals = str_replace ( [ '"' , '\'' ] , '' , $ stringLiterals ) ; $ callback = function ( $ matches ) { $ match = reset ( $ matches ) ; return '\\' . $ match ; } ; $ stringLiterals = preg_replace_callback ( $ this -> getPatternSpecifiersPhp ( ) , $ callback , $ stringLiterals ) ; return vsprintf ( $ phpFormatPlaceholders , $ stringLiterals ) ; }
|
Convert a . NET custom date format string to it s PHP equivalent .
|
57,949
|
public function encode ( $ value ) { $ encryptedValue = $ this -> getEncryptor ( ) -> encrypt ( $ value ) ; $ encodedValue = base64_encode ( $ encryptedValue ) ; return $ encodedValue ; }
|
Encrypt and encode a value .
|
57,950
|
public function decode ( $ encodedValue ) { $ encryptedValue = base64_decode ( $ encodedValue ) ; $ value = $ this -> getEncryptor ( ) -> decrypt ( $ encryptedValue ) ; return $ value ; }
|
Decode and decrypt a value .
|
57,951
|
protected function setEnvironmentVariable ( $ name , $ value ) { $ name = strtoupper ( $ name ) ; $ result = putenv ( "$name=$value" ) ; if ( $ result === false ) { throw new Exception \ RuntimeException ( sprintf ( 'Failed to set environment variable "%s"' , $ name ) ) ; } }
|
Set environment variable .
|
57,952
|
public function getParent ( int $ level = 1 ) : self { $ tree = PathTree :: make ( $ this -> path ) -> getInversedPathTree ( ) ; if ( $ level > count ( $ tree ) - 1 ) { throw OverFlowRootDirException :: make ( ) ; } return $ tree [ $ level ] ; }
|
Devuelve el directorio padre del nivel indicado
|
57,953
|
public function addClass ( $ class ) { $ this -> setVariable ( self :: VIEW_MODEL_CLASS , $ this -> addValue ( $ this -> getVariable ( self :: VIEW_MODEL_CLASS ) , $ class ) ) ; }
|
Adds a css class name .
|
57,954
|
public function setAttributes ( $ attributes ) { $ this -> setVariable ( self :: ATTRIBUTES , "" ) ; foreach ( $ attributes as $ name => $ value ) { $ this -> addAttribute ( $ name , $ value ) ; } }
|
Sets an array of attributes .
|
57,955
|
public function html ( PhpRenderer $ renderer = null ) { $ view = new View ( ) ; $ view -> setResponse ( new Response ( ) ) ; $ resolver = new TemplateMapResolver ( ) ; if ( $ renderer === null ) { $ renderer = new PhpRenderer ( ) ; $ resolver -> add ( $ this -> getTemplate ( ) , $ this -> getDefaultTemplatePath ( $ this -> getTemplate ( ) ) ) ; $ renderer -> setResolver ( $ resolver ) ; } else { $ renderer -> resolver ( ) -> attach ( $ resolver ) ; } $ view -> getEventManager ( ) -> attach ( new PhpRendererStrategy ( $ renderer ) ) ; $ view -> render ( $ this ) ; return $ view -> getResponse ( ) -> getContent ( ) ; }
|
Returns this view model as rendered html string .
|
57,956
|
protected function extractValueFromAssignmentString ( $ assignment ) { if ( ! $ assignment ) { return null ; } $ assignmentArray = explode ( "=" , $ assignment ) ; return isset ( $ assignmentArray [ 1 ] ) ? $ assignmentArray [ 1 ] : null ; }
|
Returns the value after the equality sign .
|
57,957
|
protected function assembleAssignmentString ( $ name , $ value , $ quote = '"' ) { if ( $ quote === '"' ) { return $ name . '="' . $ value . '"' ; } else if ( $ quote === "'" ) { return $ name . "='" . $ value . "'" ; } else if ( $ quote === false ) { return $ name . "=" . $ value ; } }
|
Returns a assignment string like a = b .
|
57,958
|
protected function buildHeaders ( \ Zend_Controller_Response_Abstract $ response , array $ headers ) { foreach ( $ headers as $ header => $ value ) { if ( ! in_array ( $ header , $ this -> defaultHeaders ) ) { $ response -> setHeader ( $ header , $ value ) ; } } return $ this ; }
|
Method build response headers
|
57,959
|
protected function disableViewAndLayout ( ) { $ layoout = \ Zend_Layout :: getMvcInstance ( ) ; if ( null !== $ layoout ) { $ layoout -> disableLayout ( ) ; } $ view = \ Zend_Controller_Action_HelperBroker :: getStaticHelper ( 'viewRenderer' ) ; if ( null !== $ view ) { $ view -> setNoRender ( true ) ; } return $ this ; }
|
Method disable default html view and layout
|
57,960
|
public function run ( ServerRequestInterface $ request = null ) : void { if ( null === $ request ) { $ request = $ this -> getContainer ( ) -> get ( ServerRequestFactoryInterface :: class ) -> createServerRequestFromArray ( $ _SERVER ) ; } try { $ this -> response = $ this -> handleRequest ( $ request ) ; } catch ( \ Throwable $ e ) { if ( $ this -> config -> getParam ( 'env' ) != 'prod' ) { throw $ e ; } $ this -> exceptionHandler -> report ( $ e ) ; $ this -> response = $ this -> exceptionHandler -> throwableToResponse ( $ e ) ; } $ this -> sendResponse ( $ this -> response ) ; $ this -> terminate ( ) ; }
|
Application entry point . Takes the request as param or if it is not provided one is created from the globals and runs it throught the whole app stack . The response is then sent to the browser and the app business is finished .
|
57,961
|
private function handleRequest ( ServerRequestInterface $ request ) : ResponseInterface { $ this -> eventDispatcher -> dispatch ( new EventBeforeAppHandlingRequest ( $ request ) ) ; $ routerMatch = $ this -> matchRoute ( $ request ) ; $ stack = $ this -> getFullMiddlewareStack ( $ request , $ routerMatch ) ; $ this -> eventDispatcher -> dispatch ( new EventBeforeAppMiddlewareFullStackDispatching ( $ stack ) ) ; $ this -> middlewareDispatcher -> init ( $ stack ) ; $ response = $ this -> middlewareDispatcher -> process ( $ request ) ; $ this -> eventDispatcher -> dispatch ( new EventAfterAppMiddlewareFullStackDispatching ( $ response ) ) ; $ this -> eventDispatcher -> dispatch ( new EventAfterAppHandlingRequest ( $ response ) ) ; return $ response ; }
|
Passes the response through the whole application stack .
|
57,962
|
private function matchRoute ( ServerRequestInterface $ request ) : RouterMatch { $ this -> eventDispatcher -> dispatch ( new EventBeforeAppMatchingRoute ( $ request ) ) ; try { $ routerMatch = $ this -> router -> match ( $ request ) ; } catch ( \ Throwable $ e ) { $ statusCode = 404 ; $ message = "$statusCode: Router could not match request path {$request->getUri()->getPath()}" ; throw new HttpException ( $ statusCode , $ message , null , $ e ) ; } $ this -> eventDispatcher -> dispatch ( new EventAfterAppMatchingRoute ( $ request , $ routerMatch ) ) ; return $ routerMatch ; }
|
Matches the request to a route .
|
57,963
|
public function init ( ) { if ( version_compare ( $ GLOBALS [ 'wp_version' ] , self :: MIN_WP_VER , '<' ) ) { Compat :: loadNotices ( ) ; } add_action ( 'after_setup_theme' , [ $ this -> theme , 'addThemeSupports' ] ) ; add_action ( 'widgets_init' , [ $ this -> theme , 'registerWidgets' ] ) ; add_action ( 'wp_enqueue_scripts' , [ $ this -> assets , 'loadSiteScripts' ] ) ; add_action ( 'wp_enqueue_scripts' , [ $ this -> assets , 'loadSiteStyles' ] ) ; add_action ( 'admin_enqueue_scripts' , [ $ this -> assets , 'loadAdminScripts' ] ) ; add_action ( 'admin_enqueue_scripts' , [ $ this -> assets , 'loadAdminStyles' ] ) ; add_action ( 'login_enqueue_scripts' , [ $ this -> assets , 'loadLoginScripts' ] ) ; add_action ( 'login_enqueue_scripts' , [ $ this -> assets , 'loadLoginStyles' ] ) ; add_action ( 'wp_head' , [ $ this -> viewMeta , 'render' ] , 1 ) ; add_action ( 'customize_register' , [ $ this -> customizer , 'register' ] ) ; add_action ( 'customize_preview_init' , [ $ this -> assets , 'loadCustomizeScript' ] ) ; }
|
Initializes the framework
|
57,964
|
public function loginAction ( Request $ request ) { $ oauth = $ this -> get ( 'campaignchain.security.authentication.client.oauth.authentication' ) ; $ oauth -> authenticate ( self :: RESOURCE_OWNER , $ this -> applicationInfo , true ) ; $ wizard = $ this -> get ( 'campaignchain.core.channel.wizard' ) ; $ wizard -> set ( 'profile' , $ oauth -> getProfile ( ) ) ; $ wizard -> set ( 'linkedin_user_id' , $ oauth -> getProfile ( ) -> identifier ) ; $ tokens [ $ oauth -> getProfile ( ) -> identifier ] = $ oauth -> getToken ( ) ; $ wizard -> set ( 'tokens' , $ tokens ) ; return $ this -> render ( 'CampaignChainChannelLinkedInBundle:Create:closePopUp.html.twig' ) ; }
|
Perform the login into LinkedIn
|
57,965
|
public function editAction ( ) { if ( method_exists ( $ this , 'getEditForm' ) ) { $ form = $ this -> getEditForm ( ) ; } else { $ form = $ this -> getForm ( ) ; } $ id = $ this -> getEvent ( ) -> getRouteMatch ( ) -> getParam ( 'id' , 0 ) ; $ form -> add ( [ 'type' => 'Zend\Form\Element\Hidden' , 'name' => 'id' , 'attributes' => [ 'id' => 'id' , 'value' => $ id , ] , 'filters' => [ [ 'name' => 'Int' , ] , ] , 'validators' => [ [ 'name' => 'Digits' , ] , ] , ] ) ; $ em = $ this -> getEntityManager ( ) ; $ objRepository = $ em -> getRepository ( $ this -> getEntityClass ( ) ) ; $ entity = $ objRepository -> find ( $ id ) ; $ form -> bind ( $ entity ) ; $ redirectUrl = $ this -> url ( ) -> fromRoute ( $ this -> getActionRoute ( ) , [ ] , true ) ; $ prg = $ this -> fileprg ( $ form , $ redirectUrl , true ) ; if ( $ prg instanceof Response ) { return $ prg ; } elseif ( $ prg === false ) { $ this -> getEventManager ( ) -> trigger ( 'getForm' , $ this , [ 'form' => $ form , 'entityClass' => $ this -> getEntityClass ( ) , 'id' => $ id , 'entity' => $ entity , ] ) ; return [ 'entityForm' => $ form , 'entity' => $ entity , ] ; } $ this -> getEventManager ( ) -> trigger ( 'getForm' , $ this , [ 'form' => $ form , 'entityClass' => $ this -> getEntityClass ( ) , 'id' => $ id , 'entity' => $ entity , ] ) ; $ savedEntity = $ this -> getEntityService ( ) -> save ( $ form , $ entity ) ; if ( ! $ savedEntity ) { return [ 'entityForm' => $ form , 'entity' => $ entity , ] ; } $ this -> flashMessenger ( ) -> addSuccessMessage ( $ this -> getServiceLocator ( ) -> get ( 'translator' ) -> translate ( $ this -> successEditMessage ) ) ; return $ this -> redirect ( ) -> toRoute ( $ this -> getActionRoute ( 'list' ) , [ ] , true ) ; }
|
Altera uma entidade
|
57,966
|
public function safeAttributes ( ) { $ t = Yii :: createObject ( $ this -> getTranslationModelClassName ( ) ) ; return ArrayHelper :: merge ( parent :: safeAttributes ( ) , $ t -> safeAttributes ( ) ) ; }
|
Override safe attributes to include translation attributes
|
57,967
|
public function triggerEvent ( $ event , Payload $ payload ) { if ( $ payload -> state ( ) === null ) { $ this -> updatePayload ( $ this -> process -> initialState ( ) , $ payload ) ; } $ state = $ this -> process -> state ( $ payload -> state ( ) ) ; $ nextStateName = $ state -> triggerEvent ( $ event , $ payload ) ; if ( $ nextStateName === null ) { return ; } $ state = $ this -> process -> state ( $ nextStateName ) ; $ this -> updatePayload ( $ state , $ payload ) ; $ this -> handleOnStateWasSet ( $ state , $ payload ) ; }
|
Trigger event for subject identified by identifier Restore subject from handler by its identifier then triggers event and saves subject Return run history
|
57,968
|
private function handleOnStateWasSet ( State $ state , Payload $ payload ) { while ( $ state -> hasEvent ( self :: ON_STATE_WAS_SET ) ) { $ newState = $ state -> triggerEvent ( self :: ON_STATE_WAS_SET , $ payload ) ; if ( $ newState === null ) { break ; } $ state = $ this -> process -> state ( $ newState ) ; $ this -> updatePayload ( $ state , $ payload ) ; } }
|
Handles onStateWasSet event Returns true if there was state change
|
57,969
|
public function hasErrors ( $ key = NULL ) { if ( $ key ) { return isset ( $ this [ $ key ] ) ; } else { if ( count ( $ this ) ) { return true ; } else { return false ; } } }
|
Does the handler have an error for the given key ?
|
57,970
|
public function getMethods ( $ path ) { if ( $ this -> methods -> has ( $ path ) ) { return $ this -> methods -> get ( $ path ) -> toArray ( ) ; } return [ ] ; }
|
Returns methods for a given path
|
57,971
|
public function setDate ( $ year , $ month = 1 , $ day = 1 ) { switch ( gettype ( $ year ) ) { case 'object' : $ year = ( array ) $ year ; case 'array' : $ arrIn = array_change_key_case ( $ year ) ; $ year = $ this -> format ( 'Y' ) ; $ month = $ this -> format ( 'n' ) ; $ day = $ this -> format ( 'j' ) ; foreach ( $ arrIn as $ k => $ v ) { switch ( substr ( $ k , 0 , 3 ) ) { case 'yea' : $ year = $ v ; break ; case 'mon' : $ month = $ v ; break ; case 'day' : $ day = $ v ; break ; } } break ; } parent :: setDate ( ( int ) $ year , ( int ) $ month , ( int ) $ day ) ; return $ this ; }
|
Adds the ability to pass in an arrayor object with key names of variable length but a minimum of 3 characters upper or lower case . Requires one object one associative array or 3 integer parameters .
|
57,972
|
public function setTime ( $ hour , $ minute = 0 , $ second = 0 , $ mcs = 0 ) { switch ( gettype ( $ hour ) ) { case 'object' : $ hour = ( array ) $ hour ; case 'array' : $ arrIn = array_change_key_case ( $ hour ) ; $ hour = $ this -> format ( 'G' ) ; $ minute = $ this -> format ( 'i' ) ; $ second = $ this -> format ( 's' ) ; $ mcs = $ this -> format ( 'u' ) ; foreach ( $ arrIn as $ k => $ v ) { switch ( substr ( $ k , 0 , 3 ) ) { case 'hou' : $ hour = $ v ; break ; case 'min' : $ minute = $ v ; break ; case 'sec' : $ second = $ v ; break ; case 'mcs' : $ mcs = $ v ; break ; case 'fra' : $ mcs = $ v * 1000000 ; break ; } } } parent :: setTime ( ( int ) $ hour , ( int ) $ minute , ( int ) $ second , ( int ) $ mcs ) ; return $ this ; }
|
Adds the ability to pass in an array with key names of variable length but a minimum of 3 characters upper or lower case . Requires one object one associative array or 4 integer parameters .
|
57,973
|
protected function _writeStream ( $ buffer ) { $ fd = $ this -> socket_ ; $ total = TStringFuncFactory :: create ( ) -> strlen ( $ buffer ) ; if ( $ total <= 0 ) { return ; } $ failed = FALSE ; $ sent = 0 ; while ( ! $ failed && $ sent < $ total ) { if ( ! is_resource ( $ fd ) ) { $ failed = TRUE ; } try { $ written = @ fwrite ( $ fd , $ buffer , self :: MAX_BYTES_PER_WRITE ) ; if ( $ written > 0 ) { $ sent += $ written ; $ buffer = substr ( $ buffer , $ written ) ; } else if ( $ written === FALSE ) { if ( $ this -> debug_ ) { error_log ( "Write failed." ) ; } $ failed = TRUE ; } else if ( $ written === 0 ) { if ( $ this -> debug_ ) { error_log ( "Zero bytes written to socket. sent=$sent total=$total" ) ; } $ failed = TRUE ; } else { if ( $ this -> debug_ ) { error_log ( "Unexpected fwrite return value '$written'" ) ; } $ failed = TRUE ; } if ( $ this -> debug_ ) { error_log ( "Written = $written bytes. Sent $sent of $total." ) ; } } catch ( Exception $ e ) { if ( $ this -> debug_ ) { error_log ( $ e ) ; } $ failed = TRUE ; } } if ( $ failed ) { $ this -> _closeSocket ( ) ; } }
|
Helper to write the given buffer to the persistent socket .
|
57,974
|
protected function _readStream ( ) { if ( ! $ this -> debug_ ) { error_log ( 'Intended as a debug-only function' ) ; return ; } if ( ! is_resource ( $ this -> socket_ ) ) { error_log ( "Invalid socket handle" ) ; return ; } $ buffer = "" ; $ start = microtime ( TRUE ) ; while ( ! feof ( $ this -> socket_ ) ) { $ meta = stream_get_meta_data ( $ this -> socket_ ) ; error_log ( "socket status (" . sprintf ( "%.2f" , microtime ( TRUE ) - $ start ) . "s): " . json_encode ( $ meta ) ) ; $ read = fread ( $ this -> socket_ , 8192 ) ; if ( strlen ( $ read ) == 0 ) { usleep ( 1e5 ) ; } $ buffer .= $ read ; } $ end = microtime ( TRUE ) ; error_log ( "Read took: " . ( $ end - $ start ) . " seconds." ) ; $ meta = stream_get_meta_data ( $ this -> socket_ ) ; $ headers = array ( ) ; foreach ( explode ( "\n" , $ buffer ) as $ line ) { $ pair = explode ( ":" , $ line ) ; if ( count ( $ pair ) == 2 ) { $ key = $ pair [ 0 ] ; $ value = $ pair [ 1 ] ; $ headers [ $ key ] = $ value ; } } error_log ( "Response headers: " . json_encode ( $ headers ) ) ; }
|
Intended for debugging purposes only . The response is ignored in normal production circumstances as not to block the calling process .
|
57,975
|
protected function _ensureSocketCreated ( ) { if ( is_resource ( $ this -> socket_ ) ) { return TRUE ; } $ sockaddr = $ this -> scheme_ . '://' . $ this -> host_ ; $ port = $ this -> port_ ; $ timeout = self :: DEFAULT_CONNECT_TIMEOUT_SECS ; for ( $ retry = 0 ; $ retry < self :: MAX_SOCKET_OPEN_RETRIES ; $ retry ++ ) { try { $ fd = @ pfsockopen ( $ sockaddr , $ port , $ errno , $ errstr , $ timeout ) ; if ( $ errno == 0 && is_resource ( $ fd ) ) { stream_set_blocking ( $ fd , 0 ) ; stream_set_timeout ( $ fd , 0 , self :: DEFAULT_STREAM_TIMEOUT_MICROS ) ; $ this -> socket_ = $ fd ; break ; } } catch ( Exception $ e ) { } } return is_resource ( $ this -> socket_ ) ; }
|
Create the persistent socket connection if necessary . Otherwise do nothing .
|
57,976
|
protected function _closeSocket ( ) { if ( $ this -> debug_ ) { error_log ( "Closing socket." ) ; } $ fd = $ this -> socket_ ; if ( is_resource ( $ fd ) ) { $ this -> socket_ = null ; @ fclose ( $ fd ) ; } }
|
Close the persistent connection . Note this does not necessarily close the socket itself as it is persisted but the handle this process has to it .
|
57,977
|
public function updateRewrite ( string $ postType , $ args ) { global $ wp_post_types , $ wp_rewrite ; $ pageForPostType = get_option ( 'page_for_' . $ postType ) ; if ( ! $ pageForPostType ) { return ; } $ postStatus = get_post_status ( $ pageForPostType ) ; if ( ! in_array ( $ postStatus , array ( 'publish' , 'private' ) ) ) { return ; } $ args -> rewrite = ( array ) $ args -> rewrite ; $ oldRewrite = isset ( $ args -> rewrite [ 'slug' ] ) ? $ args -> rewrite [ 'slug' ] : $ postType ; \ WpPageForPostType \ Settings :: $ originalSlugs [ $ postType ] = $ oldRewrite ; $ newSlug = $ this -> getPageSlug ( $ pageForPostType ) ; $ args -> rewrite = wp_parse_args ( array ( 'slug' => $ newSlug ) , $ args -> rewrite ) ; $ args -> has_archive = $ newSlug ; $ this -> rebuildRewriteRules ( $ postType , $ args , $ oldRewrite ) ; $ wp_post_types [ $ postType ] = $ args ; }
|
Updates the rewrite rules for the posttype
|
57,978
|
public function rebuildRewriteRules ( $ postType , $ args ) { global $ wp_post_types , $ wp_rewrite ; if ( ! is_admin ( ) && empty ( get_option ( 'permalink_structure' ) ) ) { return ; } if ( $ args -> has_archive ) { $ archiveSlug = $ args -> has_archive === true ? $ args -> rewrite [ 'slug' ] : $ args -> has_archive ; if ( $ args -> rewrite [ 'with_front' ] ) { $ archiveSlug = substr ( $ wp_rewrite -> front , 1 ) . $ archiveSlug ; } else { $ archiveSlug = $ wp_rewrite -> root . $ archiveSlug ; } add_rewrite_rule ( "{$archiveSlug}/?$" , "index.php?post_type=$postType" , 'top' ) ; if ( $ args -> rewrite [ 'feeds' ] && $ wp_rewrite -> feeds ) { $ feeds = '(' . trim ( implode ( '|' , $ wp_rewrite -> feeds ) ) . ')' ; add_rewrite_rule ( "{$archiveSlug}/feed/$feeds/?$" , "index.php?post_type=$postType" . '&feed=$matches[1]' , 'top' ) ; add_rewrite_rule ( "{$archiveSlug}/$feeds/?$" , "index.php?post_type=$postType" . '&feed=$matches[1]' , 'top' ) ; } if ( $ args -> rewrite [ 'pages' ] ) { add_rewrite_rule ( "{$archiveSlug}/{$wp_rewrite->pagination_base}/([0-9]{1,})/?$" , "index.php?post_type=$postType" . '&paged=$matches[1]' , 'top' ) ; } } $ permastructArgs = $ args -> rewrite ; $ permastructArgs [ 'feed' ] = $ permastructArgs [ 'feeds' ] ; if ( isset ( $ args -> rewrite [ 'permastruct' ] ) ) { $ permastruct = str_replace ( $ oldRewrite , $ slug , $ args -> rewrite [ 'permastruct' ] ) ; } else { $ permastruct = "{$args->rewrite['slug']}/%$postType%" ; } add_permastruct ( $ postType , $ permastruct , $ permastructArgs ) ; return true ; }
|
Rebuild rewrite rules
|
57,979
|
public function orderBy ( $ col = 'id' , $ type = 'asc' ) { try { if ( ! is_null ( $ this -> query ) ) { $ this -> query .= ' ORDER BY ' . $ col . ' ' . $ type ; return $ this ; } } catch ( \ Exception $ exception ) { var_dump ( $ exception -> getMessage ( ) ) ; } }
|
Order by statement
|
57,980
|
public function orWhereLike ( $ column , $ value ) { try { if ( ! is_null ( $ this -> query ) ) { $ this -> query .= ' OR ' . $ column . ' LIKE "' . $ value . '"' ; return $ this ; } } catch ( \ Exception $ exception ) { var_dump ( $ exception -> getMessage ( ) ) ; } }
|
Or where like statement
|
57,981
|
public function groupWhere ( $ callback ) { $ origQuery = $ this -> query ; $ this -> query = '' ; $ qb = $ callback ( $ this ) ; $ query = $ qb -> query . ')' ; $ query = preg_replace ( '/AND /' , 'AND (' , $ query , 1 ) ; $ this -> query = $ origQuery . $ query ; }
|
Group where statement
|
57,982
|
public function getInfoAction ( $ actorId , $ id ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ entity = $ em -> getRepository ( 'EcommerceBundle:Address' ) -> findOneById ( $ id ) ; $ addressResponse = new stdClass ( ) ; $ addressResponse -> id = $ entity -> getId ( ) ; $ addressResponse -> address = $ entity -> getAddress ( ) ; $ addressResponse -> dni = $ entity -> getDni ( ) ; $ addressResponse -> city = $ entity -> getCity ( ) ; $ addressResponse -> state = $ entity -> getState ( ) -> getId ( ) ; $ addressResponse -> country = $ entity -> getCountry ( ) -> getId ( ) ; $ addressResponse -> phone = $ entity -> getPhone ( ) ; $ addressResponse -> phone2 = $ entity -> getPhone2 ( ) ; $ addressResponse -> postalCode = $ entity -> getPostalCode ( ) ; $ addressResponse -> preferredSchedule = $ entity -> getPreferredSchedule ( ) ; return new JsonResponse ( $ addressResponse ) ; }
|
Returns a list of Address entities in JSON format .
|
57,983
|
public function & createTitle ( $ text = '' , $ autoadd = true ) { $ title = new PanelTitle ( ) ; if ( ! empty ( $ text ) ) { $ title -> setTitle ( $ text ) ; } if ( $ autoadd ) { $ this -> title = $ title ; } return $ title ; }
|
Creates a PanelTitle object adds it by default as title to use in the heading and returns a reference to it
|
57,984
|
public static function format ( $ date = false , $ format = 'Y-m-d H:i:s' ) { if ( $ date ) { $ DateTime = new DateTime ( $ date ) ; return $ DateTime -> format ( $ format ) ; } return false ; }
|
Get date in given format .
|
57,985
|
public static function isDate ( $ date = false , $ format = 'Y-m-d H:i:s' ) { if ( $ date ) { $ DateTime = DateTime :: createFromFormat ( $ format , $ date ) ; return $ DateTime && $ DateTime -> format ( $ format ) == $ date ; } return false ; }
|
Check if date is valid .
|
57,986
|
public static function Auto ( $ Mixed ) { $ Formatter = C ( 'Garden.InputFormatter' ) ; if ( ! method_exists ( 'Gdn_Format' , $ Formatter ) ) return $ Mixed ; return Gdn_Format :: $ Formatter ( $ Mixed ) ; }
|
Takes a mixed variable filters unsafe things renders BBCode and returns it .
|
57,987
|
public static function Clean ( $ Mixed ) { if ( ! is_string ( $ Mixed ) ) return self :: To ( $ Mixed , 'Clean' ) ; $ Mixed = strtr ( $ Mixed , self :: $ _CleanChars ) ; $ Mixed = preg_replace ( '/[^A-Za-z0-9 ]/' , '' , urldecode ( $ Mixed ) ) ; $ Mixed = preg_replace ( '/ +/' , '-' , trim ( $ Mixed ) ) ; return strtolower ( $ Mixed ) ; }
|
Convert certain unicode characters into their ascii equivalents .
|
57,988
|
public static function DateFull ( $ Timestamp , $ Format = '' ) { if ( $ Timestamp === NULL ) return T ( 'Null Date' , '-' ) ; if ( ! is_numeric ( $ Timestamp ) ) { $ Timestamp = self :: ToTimestamp ( $ Timestamp ) ; } if ( ! $ Timestamp ) $ Timestamp = time ( ) ; $ GmTimestamp = $ Timestamp ; $ Now = time ( ) ; $ Session = Gdn :: Session ( ) ; if ( $ Session -> UserID > 0 ) { $ SecondsOffset = ( $ Session -> User -> HourOffset * 3600 ) ; $ Timestamp += $ SecondsOffset ; $ Now += $ SecondsOffset ; } $ Html = FALSE ; if ( strcasecmp ( $ Format , 'html' ) == 0 ) { $ Format = '' ; $ Html = TRUE ; } $ FullFormat = T ( 'Date.DefaultDateTimeFormat' , '%c' ) ; $ Result = strftime ( $ FullFormat , $ Timestamp ) ; if ( $ Html ) { $ Result = Wrap ( $ Result , 'time' , array ( 'title' => strftime ( $ FullFormat , $ Timestamp ) , 'datetime' => gmdate ( 'c' , $ GmTimestamp ) ) ) ; } return $ Result ; }
|
Formats a MySql datetime or a unix timestamp for display in the system .
|
57,989
|
public static function Display ( $ Mixed ) { if ( ! is_string ( $ Mixed ) ) return self :: To ( $ Mixed , 'Display' ) ; else { $ Mixed = htmlspecialchars ( $ Mixed , ENT_QUOTES , C ( 'Garden.Charset' , '' ) ) ; $ Mixed = str_replace ( array ( """ , "&" ) , array ( '"' , '&' ) , $ Mixed ) ; $ Mixed = self :: Mentions ( $ Mixed ) ; $ Mixed = self :: Links ( $ Mixed ) ; return $ Mixed ; } }
|
Takes a mixed variable formats it for display on the screen and returns it .
|
57,990
|
public static function Email ( $ Email ) { $ Max = max ( 3 , floor ( strlen ( $ Email ) / 2 ) ) ; $ Chunks = str_split ( $ Email , mt_rand ( 3 , $ Max ) ) ; $ Chunks = array_map ( 'htmlentities' , $ Chunks ) ; $ St = mt_rand ( 0 , 1 ) ; $ End = count ( $ Chunks ) - mt_rand ( 1 , 4 ) ; $ Result = '' ; foreach ( $ Chunks as $ i => $ Chunk ) { if ( $ i >= $ St && $ i <= $ End ) { $ Result .= '<span style="display:inline;display:none">' . str_rot13 ( $ Chunk ) . '</span>' ; } $ Result .= '<span style="display:none;display:inline">' . $ Chunk . '</span>' ; } return '<span class="Email">' . $ Result . '</span>' ; }
|
Formats an email address in a non - scrapable format .
|
57,991
|
public static function Form ( $ Mixed ) { if ( ! is_string ( $ Mixed ) ) return self :: To ( $ Mixed , 'Form' ) ; else { if ( C ( 'Garden.Format.ReplaceNewlines' , TRUE ) ) return nl2br ( htmlspecialchars ( $ Mixed , ENT_QUOTES , C ( 'Garden.Charset' , '' ) ) ) ; else return htmlspecialchars ( $ Mixed , ENT_QUOTES , C ( 'Garden.Charset' , '' ) ) ; } }
|
Takes a mixed variable formats it for display in a form and returns it .
|
57,992
|
public static function Html ( $ Mixed ) { if ( ! is_string ( $ Mixed ) ) { return self :: To ( $ Mixed , 'Html' ) ; } else { $ IsHtml = strpos ( $ Mixed , '<' ) !== FALSE || ( bool ) preg_match ( '/&#?[a-z0-9]{1,10};/i' , $ Mixed ) ; if ( $ IsHtml ) { $ Formatter = Gdn :: Factory ( 'HtmlFormatter' ) ; if ( is_null ( $ Formatter ) ) { return self :: Display ( $ Mixed ) ; } $ Mixed = preg_replace ( array ( '/<code([^>]*)>(.+?)<\/code>/sei' ) , array ( '\'<code\'.RemoveQuoteSlashes(\'\1\').\'>\'.htmlspecialchars(RemoveQuoteSlashes(\'\2\')).\'</code>\'' ) , $ Mixed ) ; $ Mixed = $ Formatter -> Format ( $ Mixed ) ; $ Mixed = Gdn_Format :: Links ( $ Mixed ) ; $ Mixed = Gdn_Format :: Mentions ( $ Mixed ) ; if ( C ( 'Garden.Format.ReplaceNewlines' , TRUE ) ) { $ Mixed = preg_replace ( "/(\015\012)|(\015)|(\012)/" , "<br />" , $ Mixed ) ; $ Mixed = FixNl2Br ( $ Mixed ) ; } $ Result = $ Mixed ; } else { $ Result = htmlspecialchars ( $ Mixed , ENT_NOQUOTES , 'UTF-8' ) ; $ Result = Gdn_Format :: Mentions ( $ Result ) ; $ Result = Gdn_Format :: Links ( $ Result ) ; if ( C ( 'Garden.Format.ReplaceNewlines' , TRUE ) ) { $ Result = preg_replace ( "/(\015\012)|(\015)|(\012)/" , "<br />" , $ Result ) ; $ Result = FixNl2Br ( $ Result ) ; } } return $ Result ; } }
|
Takes a mixed variable filters unsafe html and returns it .
|
57,993
|
public static function Image ( $ Body ) { if ( is_string ( $ Body ) ) { $ Image = @ unserialize ( $ Body ) ; if ( ! $ Image ) return Gdn_Format :: Html ( $ Body ) ; } $ Url = GetValue ( 'Image' , $ Image ) ; $ Caption = Gdn_Format :: PlainText ( GetValue ( 'Caption' , $ Image ) ) ; return '<div class="ImageWrap">' . '<div class="Image">' . Img ( $ Url , array ( 'alt' => $ Caption , 'title' => $ Caption ) ) . '</div>' . '<div class="Caption">' . $ Caption . '</div>' . '</div>' ; }
|
Format a serialized string of image properties as html .
|
57,994
|
public static function PlainText ( $ Body , $ Format = 'Html' ) { $ Result = Gdn_Format :: To ( $ Body , $ Format ) ; if ( $ Format != 'Text' ) { $ Result = str_replace ( array ( "\n" , "\r" ) , ' ' , $ Result ) ; $ Result = preg_replace ( '`<br\s*/?>`' , "\n" , $ Result ) ; $ Result = str_replace ( '<li>' , '* ' , $ Result ) ; $ Result = preg_replace ( '`</(?:li|ol|ul)>`' , "\n" , $ Result ) ; $ Allblocks = '(?:div|table|dl|pre|blockquote|address|p|h[1-6]|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)' ; $ Result = preg_replace ( '`</' . $ Allblocks . '>`' , "\n\n" , $ Result ) ; $ Result = strip_tags ( $ Result ) ; } $ Result = trim ( html_entity_decode ( $ Result , ENT_QUOTES , 'UTF-8' ) ) ; return $ Result ; }
|
Format a string as plain text .
|
57,995
|
public static function Links ( $ Mixed ) { if ( ! is_string ( $ Mixed ) ) return self :: To ( $ Mixed , 'Links' ) ; else { $ Regex = "`(?:(</?)([!a-z]+))|(/?\s*>)|((?:https?|ftp)://[\@a-z0-9\x21\x23-\x27\x2a-\x2e\x3a\x3b\/;\x3f-\x7a\x7e\x3d]+)`i" ; self :: LinksCallback ( NULL ) ; $ Mixed = preg_replace_callback ( $ Regex , array ( 'Gdn_Format' , 'LinksCallback' ) , $ Mixed ) ; return $ Mixed ; } }
|
Formats the anchor tags around the links in text .
|
57,996
|
protected static function ListCallback ( $ Matches ) { $ Content = explode ( "[*]" , $ Matches [ 1 ] ) ; $ Result = '' ; foreach ( $ Content as $ Item ) { if ( trim ( $ Item ) != '' ) $ Result .= '<li>' . $ Item . '</li>' ; } $ Result = '<ul>' . $ Result . '</ul>' ; return $ Result ; }
|
Formats BBCode list items .
|
57,997
|
public static function GetEmbedSize ( ) { $ Sizes = array ( 'tiny' => array ( 400 , 225 ) , 'small' => array ( 560 , 340 ) , 'normal' => array ( 640 , 385 ) , 'big' => array ( 853 , 505 ) , 'huge' => array ( 1280 , 745 ) ) ; $ Size = Gdn :: Config ( 'Garden.Format.EmbedSize' , 'normal' ) ; if ( ! isset ( $ Sizes [ $ Size ] ) ) { if ( strpos ( $ Size , 'x' ) ) { list ( $ Width , $ Height ) = explode ( 'x' , $ Size ) ; $ Width = intval ( $ Width ) ; $ Height = intval ( $ Height ) ; if ( $ Width < 30 or $ Height < 30 ) { $ Size = 'normal' ; } } else { $ Size = 'normal' ; } } if ( isset ( $ Sizes [ $ Size ] ) ) { list ( $ Width , $ Height ) = $ Sizes [ $ Size ] ; } return array ( $ Width , $ Height ) ; }
|
Returns embedded video width and height based on configuration .
|
57,998
|
public static function Markdown ( $ Mixed ) { if ( ! is_string ( $ Mixed ) ) { return self :: To ( $ Mixed , 'Markdown' ) ; } else { $ Formatter = Gdn :: Factory ( 'HtmlFormatter' ) ; if ( is_null ( $ Formatter ) ) { return Gdn_Format :: Display ( $ Mixed ) ; } else { require_once ( PATH_LIBRARY . '/vendors/markdown/markdown.php' ) ; $ Mixed = Markdown ( $ Mixed ) ; $ Mixed = $ Formatter -> Format ( $ Mixed ) ; $ Mixed = Gdn_Format :: Links ( $ Mixed ) ; $ Mixed = Gdn_Format :: Mentions ( $ Mixed ) ; return $ Mixed ; } } }
|
Format a string using Markdown syntax . Also purifies the output html .
|
57,999
|
public static function Serialize ( $ Mixed ) { if ( is_array ( $ Mixed ) || is_object ( $ Mixed ) || ( is_string ( $ Mixed ) && ( substr_compare ( 'a:' , $ Mixed , 0 , 2 ) === 0 || substr_compare ( 'O:' , $ Mixed , 0 , 2 ) === 0 || substr_compare ( 'arr:' , $ Mixed , 0 , 4 ) === 0 || substr_compare ( 'obj:' , $ Mixed , 0 , 4 ) === 0 ) ) ) { $ Result = serialize ( $ Mixed ) ; } else { $ Result = $ Mixed ; } return $ Result ; }
|
Takes any variable and serializes it .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.