idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
29,300
public function addPermission ( $ action ) { if ( $ this -> hasPermission ( $ action ) === false ) { $ this -> setPermissions ( $ this -> getPermissions ( ) + $ this -> getKey ( $ action ) ) ; } return $ this ; }
Adds an action to the bitmask property when generating a new permissions code .
29,301
public function removePermission ( $ action ) { if ( $ this -> grant ( $ this -> getPermissions ( ) , $ action ) === true ) { $ this -> setPermissions ( $ this -> getPermissions ( ) - $ this -> getKey ( $ action ) ) ; } return $ this ; }
Removes an action to the bitmask property when generating a new permissions code .
29,302
protected function grant ( $ permissions , $ action ) { $ key = $ this -> getKey ( $ action ) ; $ grant = ( ( $ permissions & $ key ) == $ key ) ; return $ grant ; }
Checks if the provided action is allowed when using the provided permissions code .
29,303
private function setMenuTitle ( $ menuTitle , $ menuSlug = false ) { $ this -> menuTitle = $ menuTitle ; $ this -> menuSlug = ( $ menuSlug !== false ? sanitize_title ( $ menuSlug ) : sanitize_title ( $ menuTitle ) ) ; $ this -> fieldPrefix = "__wex_{$this->menuSlug}_" ; $ this -> pageTitle = $ menuTitle ; return $ this ; }
Sets menu title menu slug and page title . Page title is concatenated with the translatable string settings
29,304
function Render ( $ name , $ value = '' ) { $ baseUrl = $ this -> baseUrl ; $ grantResult = $ this -> guard -> Grant ( Action :: UseIt ( ) , $ this ) ; $ disabled = ( ( string ) $ grantResult != ( string ) GrantResult :: Allowed ( ) ) ; $ _SESSION [ 'KCFINDER' ] [ 'disabled' ] = $ disabled ; $ _SESSION [ 'KCFINDER' ] [ 'uploadURL' ] = $ this -> uploadUrl ; $ _SESSION [ 'KCFINDER' ] [ 'uploadDir' ] = $ this -> uploadDir ; $ oCKeditor = new \ CKEditor ( ) ; $ oCKeditor -> basePath = IO \ Path :: Combine ( $ baseUrl , 'ckeditor/' ) ; $ oCKeditor -> config [ 'skin' ] = 'v2' ; $ oCKeditor -> config [ 'filebrowserBrowseUrl' ] = IO \ Path :: Combine ( $ baseUrl , 'kcfinder/browse.php?type=files' ) ; $ oCKeditor -> config [ 'filebrowserImageBrowseUrl' ] = IO \ Path :: Combine ( $ baseUrl , 'kcfinder/browse.php?type=images' ) ; $ oCKeditor -> config [ 'filebrowserFlashBrowseUrl' ] = IO \ Path :: Combine ( $ baseUrl , 'kcfinder/browse.php?type=flash' ) ; $ oCKeditor -> config [ 'filebrowserUploadUrl' ] = IO \ Path :: Combine ( $ baseUrl , 'kcfinder/upload.php?type=files' ) ; $ oCKeditor -> config [ 'filebrowserImageUploadUrl' ] = IO \ Path :: Combine ( $ baseUrl , 'kcfinder/upload.php?type=images' ) ; $ oCKeditor -> config [ 'filebrowserFlashUploadUrl' ] = IO \ Path :: Combine ( $ baseUrl , 'kcfinder/upload.php?type=flash' ) ; foreach ( $ this -> config as $ key => $ val ) { $ oCKeditor -> config [ $ key ] = $ val ; } ob_start ( ) ; echo '<div class="phine-cke">' ; $ oCKeditor -> editor ( $ name , $ value ) ; echo '</div>' ; return ob_get_clean ( ) ; }
Renders the rich text editor .
29,305
public function setImageType ( $ image_type ) { if ( in_array ( $ image_type , $ this -> image_types_available ) ) { $ this -> image_type = $ image_type ; } return $ this ; }
Set image type for rendering .
29,306
public function get ( $ format = 'png' ) { $ this -> create ( ) ; if ( $ format == 'jpg' ) { $ format = 'jpeg' ; } if ( ! in_array ( $ format , $ this -> image_types_available ) ) { $ format = $ this -> image_type ; } if ( ! function_exists ( 'image' . $ format ) ) { throw new Exception ( 'QRCode: function image' . $ format . ' does not exists.' ) ; } ob_start ( ) ; $ success = call_user_func ( 'image' . $ format , $ this -> image ) ; if ( $ success === false ) { throw new Exception ( 'QRCode: function image' . $ format . ' failed.' ) ; } $ content = ob_get_clean ( ) ; return $ content ; }
Create QR Code and return its raw content .
29,307
public function redirectTo ( $ target , $ headerCode = 301 , $ withOrigin = false ) { if ( ! ( $ this -> request instanceof WebRequest ) ) { return ; } if ( ! preg_match ( '/http(s?)\:\/\//' , $ target ) ) { $ target = $ this -> request -> getFullRoute ( $ target ) ; } if ( $ withOrigin ) { $ target = $ this -> addOriginToTargetUrl ( $ target ) ; } header ( "Location: " . $ target , true , $ headerCode ) ; }
Set the Location header to redirect a request
29,308
public function sendHeader ( $ message , $ code = null ) { if ( ! ( $ this -> request instanceof WebRequest ) ) { return ; } if ( $ code !== null ) { header ( $ message , true , $ code ) ; } else { header ( $ message ) ; } }
Sends a header
29,309
public function sendHttpStatus ( $ code , $ resetOutput = false ) { if ( ! ( $ this -> request instanceof WebRequest ) ) { return ; } $ codes = array ( 100 => 'Continue' , 101 => 'Switching Protocols' , 102 => 'Processing' , 200 => 'OK' , 201 => 'Created' , 202 => 'Accepted' , 203 => 'Non-Authoritative Information' , 204 => 'No Content' , 205 => 'Reset Content' , 206 => 'Partial Content' , 207 => 'Multi-Status' , 300 => 'Multiple Choices' , 301 => 'Moved Permanently' , 302 => 'Found' , 303 => 'See Other' , 304 => 'Not Modified' , 305 => 'Use Proxy' , 306 => 'Switch Proxy' , 307 => 'Temporary Redirect' , 400 => 'Bad Request' , 401 => 'Unauthorized' , 402 => 'Payment Required' , 403 => 'Forbidden' , 404 => 'Not Found' , 405 => 'Method Not Allowed' , 406 => 'Not Acceptable' , 407 => 'Proxy Authentication Required' , 408 => 'Request Timeout' , 409 => 'Conflict' , 410 => 'Gone' , 411 => 'Length Required' , 412 => 'Precondition Failed' , 413 => 'Request Entity Too Large' , 414 => 'Request-URI Too Long' , 415 => 'Unsupported Media Type' , 416 => 'Requested Range Not Satisfiable' , 417 => 'Expectation Failed' , 418 => 'I\'m a teapot' , 422 => 'Unprocessable Entity' , 423 => 'Locked' , 424 => 'Failed Dependency' , 425 => 'Unordered Collection' , 426 => 'Upgrade Required' , 449 => 'Retry With' , 450 => 'Blocked by Windows Parental Controls' , 500 => 'Internal Server Error' , 501 => 'Not Implemented' , 502 => 'Bad Gateway' , 503 => 'Service Unavailable' , 504 => 'Gateway Timeout' , 505 => 'HTTP Version Not Supported' , 506 => 'Variant Also Negotiates' , 507 => 'Insufficient Storage' , 509 => 'Bandwidth Limit Exceeded' , 510 => 'Not Extended' ) ; if ( ! isset ( $ codes [ $ code ] ) ) { return false ; } $ message = $ this -> request -> getProtocol ( ) . ' ' . $ code . ' ' . $ codes [ $ code ] ; header ( $ message , true , $ code ) ; if ( $ resetOutput ) { $ this -> setOutput ( $ message ) ; } }
Sends the status code for the give code
29,310
protected function addOriginToTargetUrl ( $ target ) { $ origin = $ this -> request -> getFullRoute ( ) ; $ additionalQuery = '_origin=' . base64_encode ( $ origin ) ; $ parts = parse_url ( $ target ) ; if ( $ parts === false ) { return $ target ; } if ( ! isset ( $ parts [ 'query' ] ) ) { $ parts [ 'query' ] = '' ; } else if ( $ parts [ 'query' ] !== '' ) { $ parts [ 'query' ] .= '&' ; } $ parts [ 'query' ] .= $ additionalQuery ; return $ this -> buildUrl ( $ parts ) ; }
Adds the origin and returns the given target url with the origin query parameter .
29,311
protected static function Asc ( DBInterfaces \ IDatabaseConnection $ connection , Selectable $ selectable ) { return new self ( $ connection , $ selectable , self :: $ asc ) ; }
Am ascending order of the selectable
29,312
protected static function Desc ( DBInterfaces \ IDatabaseConnection $ connection , Selectable $ selectable ) { return new self ( $ connection , $ selectable , self :: $ desc ) ; }
A descending order of the selectable
29,313
public function generateSlots ( $ dir , $ themeName , $ templateName , array $ slots ) { $ themeBasename = str_replace ( 'Bundle' , '' , $ themeName ) ; $ extensionAlias = Container :: underscore ( $ themeBasename ) ; $ parameters = array ( 'theme_name' => $ extensionAlias , 'template_name' => $ templateName , "slots" => $ slots , ) ; $ slotFile = $ templateName . '.xml' ; $ this -> setSkeletonDirs ( $ this -> themeSkeletonDir ) ; $ this -> renderFile ( 'slots.xml' , $ dir . '/' . $ slotFile , $ parameters ) ; $ message = '' ; foreach ( $ slots as $ slotName => $ slot ) { if ( array_key_exists ( 'errors' , $ slot ) ) { foreach ( $ slot [ 'errors' ] as $ error ) { $ message .= sprintf ( '<error>The argument %s assigned to the %s slot is not recognized</error>' , $ error , $ slotName ) ; } } } $ message .= sprintf ( 'The template\'s slots <info>%s</info> has been generated into <info>%s</info>' , $ slotFile , $ dir ) ; return $ message ; }
Generates the slot file
29,314
public static function all ( ) { $ result = [ ] ; foreach ( self :: getConstants ( ) as $ k => $ v ) { if ( static :: isValid ( $ v ) ) { $ object = new static ( $ v ) ; $ result [ $ object -> getValue ( ) ] = $ object ; } } return $ result ; }
Returns array of all Enum instances index by their values .
29,315
public function loadOids ( $ file ) { if ( ! file_exists ( $ file ) ) { throw $ this -> createException ( 'OIDs cache file not found' ) ; } if ( $ this -> oidTypeNames ) { return $ this ; } if ( ! $ this -> host || ! $ this -> dbName ) { throw $ this -> createException ( 'You must set host name and dbName first' ) ; } $ oids = include $ file ; if ( isset ( $ oids [ $ this -> host ] [ $ this -> dbName ] ) ) { $ this -> oidTypeNames = $ oids [ $ this -> host ] [ $ this -> dbName ] ; } return $ this ; }
Load precached oids from file
29,316
public function saveOids ( $ file , $ overwrite = false ) { $ this -> connect ( ) ; $ overwrite = file_exists ( $ file ) ? $ overwrite : true ; $ result = pg_query ( $ this -> pgConn , 'select oid, typname from pg_type' ) ; if ( $ result === false ) { throw $ this -> createException ( ) ; } $ this -> oidTypeNames = [ ] ; while ( $ row = pg_fetch_array ( $ result , null , PGSQL_ASSOC ) ) { $ this -> oidTypeNames [ $ row [ 'oid' ] ] = $ row [ 'typname' ] ; } if ( $ overwrite ) { $ resultOids = [ $ this -> host => [ $ this -> dbName => $ this -> oidTypeNames ] ] ; } else { $ resultOids = include $ file ; if ( isset ( $ resultOids [ $ this -> host ] [ $ this -> dbName ] ) ) { $ resultOids [ $ this -> host ] [ $ this -> dbName ] = $ this -> oidTypeNames ; } } $ content = <<<'PHP'<?php//This file is automatically generated. Do not edit it.returnPHP ; $ content .= ' ' . var_export ( $ resultOids , true ) . ';' ; file_put_contents ( $ file , $ content ) ; }
Precache oids into the file
29,317
private function dbBeginTransaction ( ) { if ( $ this -> pendingConnection ) { $ this -> connect ( ) ; } $ this -> pendingTransactionBegin [ $ this -> transLevel ] = false ; if ( $ this -> dbTransLevel == 0 ) { $ res = pg_query ( $ this -> pgConn , 'begin' ) ; } else { $ res = pg_query ( $ this -> pgConn , 'savepoint level' . $ this -> dbTransLevel . 'begin' ) ; } if ( $ res === false ) { $ this -> cleanAfterCommit ( ) ; throw $ this -> createException ( ) ; } $ this -> dbTransLevel ++ ; return $ res ; }
Begin transaction on the db side
29,318
private function dbRollback ( ) { $ res = null ; if ( ! $ this -> isInDbTransaction ( ) ) { return $ res ; } $ this -> dbTransLevel -- ; if ( $ this -> dbTransLevel == 0 ) { $ res = pg_query ( $ this -> pgConn , 'rollback' ) ; } elseif ( $ this -> dbTransLevel > 0 ) { $ res = pg_query ( $ this -> pgConn , 'rollback to level' . $ this -> dbTransLevel . 'begin' ) ; } if ( $ res === false ) { throw $ this -> createException ( ) ; } return $ res ; }
Rollback transaction on the db side
29,319
public function execOne ( ) { $ args = func_get_args ( ) ; if ( count ( $ args ) > 1 ) { $ template = array_shift ( $ args ) ; $ this -> currentQuery = vsprintf ( $ template , $ args ) ; } elseif ( count ( $ args ) == 1 ) { $ this -> currentQuery = $ args [ 0 ] ; } else { return null ; } $ res = $ this -> dbExec ( ) ; $ rows = $ res -> count ( ) ; if ( $ rows > 1 ) { throw $ this -> createException ( 'Return set contains more than one row' ) ; } elseif ( $ rows == 0 ) { return null ; } return $ res -> current ( ) ; }
Execute single row query
29,320
private function afterCommit ( ) { if ( ! $ this -> isInTransaction ( ) ) { return ; } if ( ! $ this -> transLevelRolledBack [ $ this -> transLevel ] ) { if ( $ this -> transLevel == 1 ) { foreach ( $ this -> commitCallbacks as $ callback ) { $ callback ( ) ; } $ this -> cleanAfterCommit ( ) ; } } }
Run callbacks on commit
29,321
public static function toArray ( array $ arr , $ level = 0 ) { foreach ( $ arr as $ k => $ v ) { $ arr [ $ k ] = ( is_array ( $ v ) ? self :: toArray ( $ v , 1 ) : '"' . addcslashes ( $ v , '"\\' ) . '"' ) ; } if ( $ level === 0 ) { return "'" . pg_escape_string ( "{" . join ( ',' , $ arr ) . "}" ) . "'" ; } else { return pg_escape_string ( "{" . join ( ',' , $ arr ) . "}" ) ; } }
Convert php array to pg array
29,322
public static function toHStore ( $ array ) { $ hstore = [ ] ; if ( empty ( $ array ) || ! is_array ( $ array ) ) { return "''" ; } foreach ( $ array as $ paramID => $ paramValue ) { if ( is_array ( $ paramValue ) ) { $ hstore [ ] = sprintf ( "hstore('%s', %s)" , self :: quote ( $ paramID ) , '(' . self :: toHStore ( $ paramValue ) . ')::text' ) . PHP_EOL ; } else { $ hstore [ ] = sprintf ( "hstore('%s', '%s')" , self :: quote ( $ paramID ) , self :: quote ( $ paramValue ) ) ; } } return implode ( ' || ' , $ hstore ) ; }
Convert multilevel php array to hstore
29,323
protected function setUserInfo ( $ user , $ password = null ) { $ this -> userInfo = $ user . ( ( null !== $ password ) ? ( ':' . $ password ) : '' ) ; }
Setter for userInfo .
29,324
public function run ( $ data , $ id = null ) { $ result = true ; $ this -> hr ( ) ; $ this -> out ( __d ( 'cake_ldap' , 'CakePHP Queue Recovery task.' ) ) ; $ queueLength = $ this -> ExtendQueuedTask -> getLengthQueue ( 'RecoveryEmployee' ) ; if ( $ queueLength > 0 ) { $ this -> out ( __d ( 'cake_ldap' , 'Found recovery task in queue: %d. Skipped.' , $ queueLength ) ) ; return true ; } set_time_limit ( RECOVER_TREE_EMPLOYEE_TIME_LIMIT ) ; $ this -> QueuedTask -> updateProgress ( $ id , 0 ) ; if ( $ this -> SubordinateDb -> verify ( ) === true ) { $ this -> QueuedTask -> markJobFailed ( $ id , __d ( 'cake_ldap' , 'The recovery tree of employees is not required' ) ) ; return true ; } $ this -> QueuedTask -> updateProgress ( $ id , 0.33 ) ; if ( ! $ this -> SubordinateDb -> recoverEmployeeTree ( false ) ) { $ result = false ; $ this -> QueuedTask -> markJobFailed ( $ id , __d ( 'cake_ldap' , 'Error on recovery tree of employee.' ) ) ; } $ this -> QueuedTask -> updateProgress ( $ id , 0.66 ) ; if ( $ result && ! $ this -> SubordinateDb -> syncInformation ( null , $ id ) ) { $ this -> QueuedTask -> markJobFailed ( $ id , __d ( 'cake_ldap' , 'Error on synchronizing the employee tree with LDAP server.' ) ) ; } $ this -> QueuedTask -> updateProgress ( $ id , 1 ) ; return true ; }
Main function . Used for recovery tree of employee .
29,325
public function parse ( InlineParserContext $ inlineContext ) { $ cursor = $ inlineContext -> getCursor ( ) ; $ previousChar = $ cursor -> peek ( - 1 ) ; if ( $ previousChar !== null && $ previousChar !== ' ' ) { return false ; } $ previousState = $ cursor -> saveState ( ) ; $ cursor -> advance ( ) ; $ handle = $ cursor -> match ( '/^[A-Za-z0-9_]{1,15}(?!\w)/' ) ; if ( empty ( $ handle ) ) { $ cursor -> restoreState ( $ previousState ) ; return false ; } $ profileUrl = "https://twitter.com/{$handle}" ; $ inlineContext -> getContainer ( ) -> appendChild ( new Link ( $ profileUrl , '@' . $ handle ) ) ; return true ; }
Parse a line and determine if it contains a handle .
29,326
public function format ( $ format = null ) { $ format ? : $ format = $ this -> format ; return strtr ( $ format , $ this -> getFormattedReplacements ( ) ) ; }
Format the output timey
29,327
public function diff ( Time $ time , $ absolute = true ) { $ diff = $ this -> getSeconds ( ) - $ time -> getSeconds ( ) ; return new self ( 0 , 0 , $ absolute ? abs ( $ diff ) : $ diff ) ; }
Get a new instance of WallaceMaxters \ Timer \ Time of diff with another Time
29,328
public function getMembers ( ) { $ time = [ ] ; $ seconds = abs ( $ this -> getSeconds ( ) ) ; $ time [ 'hours' ] = floor ( $ seconds / 3600 ) ; $ time [ 'minutes' ] = floor ( ( $ seconds - ( $ time [ 'hours' ] * 3600 ) ) / 60 ) ; $ time [ 'seconds' ] = floor ( $ seconds % 60 ) ; $ time [ 'total_minutes' ] = ( $ time [ 'hours' ] * 60 ) + $ time [ 'minutes' ] ; return $ time ; }
Get members of time in an array
29,329
protected function getFormattedReplacements ( ) { $ time = $ this -> getMembers ( ) ; $ negative = $ this -> isNegative ( ) ; return [ self :: HOUR_FORMAT => sprintf ( '%02d' , $ time [ 'hours' ] ) , self :: MINUTE_FORMAT => sprintf ( '%02d' , $ time [ 'minutes' ] ) , self :: SECOND_FORMAT => sprintf ( '%02d' , $ time [ 'seconds' ] ) , self :: TOTAL_MINUTES_FORMAT => sprintf ( '%02d' , $ time [ 'total_minutes' ] ) , self :: SIGN_ANY => $ negative ? '-' : '+' , self :: SIGN_NEGATIVE => $ negative ? '-' : '' , ] ; }
Gets replacements for the format method
29,330
public static function getSecondsFromInterval ( DateInterval $ interval ) { $ map = [ 31536000 , 2592000 , 86400 , 3600 , 60 , 1 ] ; $ parts = explode ( '.' , $ interval -> format ( '%y.%m.%d.%h.%i.%s' ) ) ; $ value = 0 ; foreach ( $ parts as $ key => $ val ) { $ value += $ val * $ map [ $ key ] ; } return $ value ; }
Returns the seconds of an DateInterval recalculating years months etc .
29,331
public function getDataAction ( ) { $ request = $ this -> getRequest ( ) ; $ dataCount = 0 ; $ dataFilteredCount = 0 ; $ tableData = array ( ) ; $ draw = 0 ; if ( $ request -> isPost ( ) ) { $ post = get_object_vars ( $ request -> getPost ( ) ) ; $ columns = array_keys ( $ this -> tool ( ) -> getColumns ( ) ) ; $ draw = ( int ) $ post [ 'draw' ] ; $ selColOrder = $ columns [ ( int ) $ post [ 'order' ] [ 0 ] [ 'column' ] ] ; $ orderDirection = isset ( $ post [ 'order' ] [ '0' ] [ 'dir' ] ) ? strtoupper ( $ post [ 'order' ] [ '0' ] [ 'dir' ] ) : 'ASC' ; $ searchValue = isset ( $ post [ 'search' ] [ 'value' ] ) ? $ post [ 'search' ] [ 'value' ] : null ; $ searchableCols = $ this -> tool ( ) -> getSearchableColumns ( ) ; $ start = ( int ) $ post [ 'start' ] ; $ length = ( int ) $ post [ 'length' ] ; $ data = $ this -> themeTable ( ) -> getData ( $ searchValue , $ searchableCols , $ selColOrder , $ orderDirection , $ start , $ length ) -> toArray ( ) ; $ dataCount = $ this -> themeTable ( ) -> getTotalData ( ) ; $ dataFilteredCount = $ this -> themeTable ( ) -> getTotalFiltered ( ) ; $ tableData = $ data ; for ( $ ctr = 0 ; $ ctr < count ( $ tableData ) ; $ ctr ++ ) { foreach ( $ tableData [ $ ctr ] as $ vKey => $ vValue ) { $ tableData [ $ ctr ] [ $ vKey ] = $ this -> tool ( ) -> limitedText ( $ vValue , 80 ) ; } $ tableData [ $ ctr ] [ 'DT_RowId' ] = $ tableData [ $ ctr ] [ 'pros_theme_id' ] ; } } $ response = [ 'draw' => $ draw , 'data' => $ tableData , 'recordsFiltered' => $ dataFilteredCount , 'recordsTotal' => $ dataCount ] ; return new JsonModel ( $ response ) ; }
Returns the theme items for the data table
29,332
public function write ( $ string ) { if ( ! $ this -> isWritable ( ) ) { throw new \ RuntimeException ( 'Stream is not writable' ) ; } if ( ! $ this -> eof ( ) ) { $ tempStream = $ this -> createStream ( ) ; stream_copy_to_stream ( $ this -> stream , $ tempStream ) ; fseek ( $ tempStream , 0 ) ; $ this -> seek ( $ this -> cursor ) ; } $ retval = fwrite ( $ this -> stream , $ string ) ; if ( $ retval === false ) { throw new \ RuntimeException ( 'Write failed (fwrite returned false)' ) ; } $ this -> flen += $ retval ; $ this -> cursor += $ retval ; if ( isset ( $ tempStream ) ) { stream_copy_to_stream ( $ tempStream , $ this -> stream ) ; fclose ( $ tempStream ) ; $ this -> seek ( $ this -> cursor ) ; } return $ retval ; }
Write data to the stream via an insert .
29,333
public function load ( $ objectId ) { Splash :: log ( ) -> trace ( ) ; $ entity = $ this -> repository -> find ( $ objectId ) ; if ( ! $ entity ) { return Splash :: log ( ) -> errTrace ( static :: $ NAME . ' : Unable to load ' . $ objectId ) ; } return $ entity ; }
Load Request Object
29,334
public function update ( $ needed ) { if ( $ needed ) { $ this -> entityManager -> flush ( $ this -> object ) ; } return $ this -> getObjectIdentifier ( ) ; }
Update Request Object
29,335
public static function match ( $ phone = '' ) { if ( ! \ is_string ( $ phone ) ) { if ( \ is_numeric ( $ phone ) ) { $ phone = ( string ) $ phone ; } else { return false ; } } phone :: sanitize_phone ( $ phone ) ; if ( false === $ phone ) { return false ; } $ test = array ( $ phone ) ; $ tmp = \ ltrim ( $ phone , '0' ) ; if ( 0 === \ strpos ( $ tmp , \ strval ( static :: PREFIX ) ) ) { $ test [ ] = \ substr ( $ tmp , \ strlen ( static :: PREFIX ) ) ; } foreach ( $ test as $ t ) { foreach ( static :: PATTERNS as $ p ) { if ( \ preg_match ( "/^($p)$/" , $ t ) ) { $ types = static :: types ( $ t ) ; if ( ! \ count ( $ types ) ) { continue ; } $ out = phone :: TEMPLATE ; $ out [ 'country' ] = static :: CODE ; $ out [ 'prefix' ] = static :: PREFIX ; $ out [ 'region' ] = static :: REGION ; $ out [ 'types' ] = $ types ; $ out [ 'number' ] = '+' . static :: PREFIX . ' ' . static :: format ( $ t ) ; return $ out ; } } } return false ; }
Validate a Number
29,336
protected static function format ( string $ phone = '' ) { foreach ( static :: FORMATS as $ k => $ v ) { if ( \ preg_match ( "/^($k)$/" , $ phone ) ) { return \ preg_replace ( "/^$k$/" , $ v , $ phone ) ; } } return $ phone ; }
Apply formatting rules .
29,337
public function saveProspectsDatas ( $ datas , $ prosId = null ) { $ prospectsTable = $ this -> getServiceLocator ( ) -> get ( 'MelisProspects' ) ; try { $ datas [ 'pros_theme' ] = ! empty ( $ datas [ 'pros_theme' ] ) ? $ datas [ 'pros_theme' ] : null ; $ prosId = $ prospectsTable -> save ( $ datas , $ prosId ) ; } catch ( \ Exception $ e ) { echo $ e -> getMessage ( ) ; } return $ prosId ; }
Save a prospect in the database
29,338
public function getProspectsDataByDate ( $ type = 'daily' , $ date ) { $ prospectsTable = $ this -> getServiceLocator ( ) -> get ( 'MelisProspects' ) ; $ dataProspects = $ prospectsTable -> getProspectsOrderByDate ( 'DESC' ) ; $ nb = 0 ; if ( ! empty ( $ dataProspects ) ) { $ res = $ dataProspects -> toArray ( ) ; if ( ! empty ( $ res ) ) { switch ( $ type ) { case 'daily' : for ( $ i = 0 ; $ i < count ( $ res ) ; $ i ++ ) { if ( $ date == date ( 'Y-m-d' , strtotime ( $ res [ $ i ] [ 'pros_contact_date' ] ) ) ) { $ nb ++ ; } } break ; case 'monthly' : for ( $ i = 0 ; $ i < count ( $ res ) ; $ i ++ ) { if ( date ( 'Y-m' , strtotime ( $ date ) ) == date ( 'Y-m' , strtotime ( $ res [ $ i ] [ 'pros_contact_date' ] ) ) ) { $ nb ++ ; } } break ; case 'yearly' : for ( $ i = 0 ; $ i < count ( $ res ) ; $ i ++ ) { if ( date ( 'Y' , strtotime ( $ date ) ) == date ( 'Y' , strtotime ( $ res [ $ i ] [ 'pros_contact_date' ] ) ) ) { $ nb ++ ; } } break ; default : break ; } } } return $ nb ; }
This method will get Prospect Data
29,339
public function getWidgetProspects ( $ identifier ) { $ results = null ; $ prospectTable = $ this -> getServiceLocator ( ) -> get ( 'MelisProspects' ) ; switch ( $ identifier ) { case 'curMonth' : $ results = $ prospectTable -> getCurrentMonth ( ) -> count ( ) ; break ; case 'avgMonth' : $ minDate = $ prospectTable -> getProspectsOrderByDate ( 'ASC' ) -> current ( ) ; $ maxDate = $ prospectTable -> getProspectsOrderByDate ( 'DESC' ) -> current ( ) ; $ minDate = ( $ minDate ) ? strtotime ( $ minDate -> pros_contact_date ) : 0 ; $ maxDate = ( $ maxDate ) ? strtotime ( $ maxDate -> pros_contact_date ) : 0 ; $ days = ceil ( abs ( $ minDate - time ( ) ) / 86400 ) ; $ months = intval ( $ days / 30 ) ; $ results = $ prospectTable -> getAvgMonth ( $ months ) -> current ( ) ; break ; default : break ; } return $ results ; }
This method retrieves the data used for the list widget
29,340
public function addMouseClick ( $ code , $ controlIds = array ( ) , $ priority = 5 , $ inline = false ) { $ mouseClick = new MouseClick ( ) ; $ mouseClick -> setCode ( $ code ) -> setControlIds ( $ controlIds ) -> setPriority ( $ priority ) -> setInline ( $ inline ) ; $ this -> builder -> addEvent ( $ mouseClick ) ; return $ this ; }
Adds a MouseClick event to the ManiaScript .
29,341
public function addMouseOver ( $ code , $ controlIds = array ( ) , $ priority = 5 , $ inline = false ) { $ mouseOver = new MouseOver ( ) ; $ mouseOver -> setCode ( $ code ) -> setControlIds ( $ controlIds ) -> setPriority ( $ priority ) -> setInline ( $ inline ) ; $ this -> builder -> addEvent ( $ mouseOver ) ; return $ this ; }
Adds a MouseOver event to the ManiaScript .
29,342
public function addMouseOut ( $ code , $ controlIds = array ( ) , $ priority = 5 , $ inline = false ) { $ mouseOut = new MouseOut ( ) ; $ mouseOut -> setCode ( $ code ) -> setControlIds ( $ controlIds ) -> setPriority ( $ priority ) -> setInline ( $ inline ) ; $ this -> builder -> addEvent ( $ mouseOut ) ; return $ this ; }
Adds a MouseOut event to the ManiaScript .
29,343
public function addEntrySubmit ( $ code , $ controlIds = array ( ) , $ priority = 5 , $ inline = false ) { $ entrySubmit = new EntrySubmit ( ) ; $ entrySubmit -> setCode ( $ code ) -> setControlIds ( $ controlIds ) -> setPriority ( $ priority ) -> setInline ( $ inline ) ; $ this -> builder -> addEvent ( $ entrySubmit ) ; return $ this ; }
Adds a EntrySubmit event to the ManiaScript .
29,344
public function addKeyPress ( $ code , $ keyCodes = array ( ) , $ priority = 5 , $ inline = false ) { $ keyPress = new KeyPress ( ) ; $ keyPress -> setCode ( $ code ) -> setKeyCodes ( $ keyCodes ) -> setPriority ( $ priority ) -> setInline ( $ inline ) ; $ this -> builder -> addEvent ( $ keyPress ) ; return $ this ; }
Adds a KeyPress event to the ManiaScript .
29,345
public function addMenuNavigation ( $ code , $ actions = array ( ) , $ priority = 5 , $ inline = false ) { $ menuNavigation = new MenuNavigation ( ) ; $ menuNavigation -> setCode ( $ code ) -> setActions ( $ actions ) -> setPriority ( $ priority ) -> setInline ( $ inline ) ; $ this -> builder -> addEvent ( $ menuNavigation ) ; return $ this ; }
Adds a MenuNavigation event to the ManiaScript .
29,346
public function addLoad ( $ code , $ priority = 5 , $ inline = false ) { $ load = new Load ( ) ; $ load -> setCode ( $ code ) -> setPriority ( $ priority ) -> setInline ( $ inline ) ; $ this -> builder -> addEvent ( $ load ) ; return $ this ; }
Adds a Load pseudo event to the ManiaScript .
29,347
public function addFirstLoop ( $ code , $ priority = 5 , $ inline = false ) { $ firstLoop = new FirstLoop ( ) ; $ firstLoop -> setCode ( $ code ) -> setPriority ( $ priority ) -> setInline ( $ inline ) ; $ this -> builder -> addEvent ( $ firstLoop ) ; return $ this ; }
Adds a FirstLoop pseudo event to the ManiaScript .
29,348
public function addLoop ( $ code , $ priority = 5 , $ inline = false ) { $ loop = new Loop ( ) ; $ loop -> setCode ( $ code ) -> setPriority ( $ priority ) -> setInline ( $ inline ) ; $ this -> builder -> addEvent ( $ loop ) ; return $ this ; }
Adds a Loop pseudo event to the ManiaScript .
29,349
public function addCustomEvent ( $ name , $ code , $ priority = 5 , $ inline = false ) { $ custom = new Custom ( ) ; $ custom -> setName ( $ name ) -> setCode ( $ code ) -> setPriority ( $ priority ) -> setInline ( $ inline ) ; $ this -> builder -> addEvent ( $ custom ) ; return $ this ; }
Adds a custom event to the ManiaScript .
29,350
public function addTimer ( $ name , $ code , $ priority = 5 , $ inline = false ) { $ timer = new Timer ( ) ; $ timer -> setName ( $ name ) -> setCode ( $ code ) -> setPriority ( $ priority ) -> setInline ( $ inline ) ; $ this -> builder -> addEvent ( $ timer ) ; return $ this ; }
Adds a timer handler to the ManiaScript .
29,351
public function getAddTimerCode ( $ name , $ delay , $ replaceExisting = false ) { return $ this -> builder -> getAddTimerCode ( $ name , $ delay , $ replaceExisting ) ; }
Returns the ManiaScript code to add a new timer .
29,352
protected function convertDatabaseException ( \ Exception $ e ) { if ( $ e instanceof DatabaseException ) { return $ e ; } $ cause = $ e ; if ( ! $ cause instanceof \ PDOException ) { while ( NULL !== ( $ cause = $ cause -> getPrevious ( ) ) ) { if ( $ cause instanceof \ PDOException ) { break ; } } } if ( $ cause instanceof \ PDOException ) { switch ( $ this -> driverName ) { case DB :: DRIVER_MYSQL : return $ this -> convertMySqlException ( $ cause , $ e ) ; case DB :: DRIVER_POSTGRESQL : return $ this -> convertPostgresException ( $ cause , $ e ) ; case DB :: DRIVER_SQLITE : return $ this -> convertSqliteException ( $ cause , $ e ) ; } } return new DatabaseException ( $ e -> getMessage ( ) , 0 , $ e ) ; }
Converts the given exception into a DB API exception .
29,353
public static function transliterate ( $ text , $ separator = '-' ) { $ text = strip_tags ( $ text ) ; $ text = GedmoUrlizer :: transliterate ( $ text , $ separator ) ; return $ text ; }
Uses transliteration tables to convert any kind of utf8 character
29,354
public static function run ( ) { $ smConfig = include dirname ( __DIR__ ) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'module.config.php' ; $ serviceManager = new ServiceManager ( new ServiceManagerConfig ( $ smConfig [ 'service_manager' ] ) ) ; try { $ discovery = $ serviceManager -> get ( 'MelisDbDeployDiscoveryService' ) ; $ discovery -> processing ( ) ; } catch ( ConfigFileNotFoundException $ exception ) { return ; } }
Trigger the processing of discovery patch and deploy sql migration
29,355
protected function checkFilePath ( $ filePath ) { $ filePath = rtrim ( $ filePath , '/\\' ) ; if ( ! is_dir ( $ filePath ) ) { mkdir ( $ filePath , 0755 , true ) ; } if ( ! is_writable ( $ filePath ) ) { throw new \ RuntimeException ( sprintf ( 'The base cache path `%s` is not writable.' , $ filePath ) ) ; } return true ; }
Check that the file path is a directory and writable .
29,356
public function load ( ObjectManager $ manager ) { $ loader = new Loader ( ) ; $ loader -> addFile ( __DIR__ . '/../../Resources/config/data/Metas.yml' ) ; $ loader -> load ( $ manager , null , $ this ) ; }
Load fixtures files
29,357
public static function arrayToXLS ( Array $ data , String $ file = 'excel.xls' ) { $ file = Base :: suffix ( $ file , '.xls' ) ; header ( "Content-Disposition: attachment; filename=\"$file\"" ) ; header ( "Content-Type: application/vnd.ms-excel;" ) ; header ( "Pragma: no-cache" ) ; header ( "Expires: 0" ) ; $ output = fopen ( "php://output" , 'w' ) ; foreach ( $ data as $ column ) { fputcsv ( $ output , $ column , "\t" ) ; } fclose ( $ output ) ; }
Array to XLS
29,358
public static function CSVToArray ( String $ file ) : Array { $ file = Base :: suffix ( $ file , '.csv' ) ; if ( ! is_file ( $ file ) ) { throw new Exception \ FileNotFoundException ( NULL , $ file ) ; } $ row = 1 ; $ rows = [ ] ; if ( ( $ resource = fopen ( $ file , "r" ) ) !== false ) { while ( ( $ data = fgetcsv ( $ resource , 1000 , "," ) ) !== false ) { $ num = count ( $ data ) ; $ row ++ ; for ( $ c = 0 ; $ c < $ num ; $ c ++ ) { $ rows [ ] = explode ( ';' , $ data [ $ c ] ) ; } } fclose ( $ resource ) ; } return $ rows ; }
CSV to Array
29,359
protected function getAccessTokenOptions ( array $ params ) { $ params += [ 'scope' => implode ( $ this -> getScopeSeparator ( ) , $ this -> getDefaultScopes ( ) ) , ] ; $ options = parent :: getAccessTokenOptions ( $ params ) ; $ options [ 'headers' ] [ 'Authorization' ] = sprintf ( 'Basic %s' , base64_encode ( sprintf ( '%s:%s' , $ this -> clientId , $ this -> lif ) ) ) ; return $ options ; }
Builds request options used for requesting an access token including the client authentication header
29,360
static public function rUrl ( $ url ) { $ module = null ; if ( strpos ( $ url , 'http' ) !== 0 && ( $ pos = strpos ( $ url , ':' ) ) !== false ) { $ module = trim ( substr ( $ url , 0 , $ pos ) , '/' ) ; $ url = trim ( substr ( $ url , $ pos + 1 ) , '/' ) ; } if ( strpos ( $ url , 'http' ) === 0 ) { $ url = str_replace ( static :: url ( $ module . ':' ) , '' , $ url ) ; } return trim ( $ url , '/' ) ; }
get relative url
29,361
static public function uploadUrl ( $ path ) { if ( strpos ( $ path , 'images' ) === 0 ) { return Config :: getRootUrl ( $ path ) ; } return Config :: getUploadFileUrl ( $ path ) ; }
get upload url
29,362
private function registerRoutes ( $ controller , $ controllerService , $ reflectionClass ) { $ methods = $ reflectionClass -> getMethods ( ) ; foreach ( $ methods as $ reflectionMethod ) { $ route = $ this -> reader -> getMethodAnnotation ( $ reflectionMethod , 'Singular\Annotation\Route' ) ; $ beforeFilters = $ this -> reader -> getMethodAnnotation ( $ reflectionMethod , 'Singular\Annotation\Before' ) ; $ afterFilters = $ this -> reader -> getMethodAnnotation ( $ reflectionMethod , 'Singular\Annotation\After' ) ; if ( $ route ) { $ this -> registerBasicRoute ( $ route , $ controller , $ controllerService , $ reflectionClass , $ reflectionMethod , $ beforeFilters , $ afterFilters ) ; } } }
Registra rotas definidas no controlador .
29,363
private function registerBasicRoute ( $ annotation , $ controller , $ controllerService , $ reflectionClass , $ reflectionMethod , $ beforeFilters , $ afterFilters ) { $ app = $ this -> app ; if ( $ annotation -> method != null || ! empty ( $ annotation -> methods ) ) { $ routeMethods = $ annotation -> method == null ? $ annotation -> methods : array ( $ annotation -> method ) ; if ( $ annotation -> pattern ) { $ container = $ app ; $ ctr = $ container -> match ( $ annotation -> pattern , $ controllerService . ':' . $ reflectionMethod -> getName ( ) ) -> method ( implode ( '|' , $ routeMethods ) ) ; } else { $ ctr = $ controller -> match ( $ this -> getRoutePattern ( $ reflectionMethod ) , $ controllerService . ':' . $ reflectionMethod -> getName ( ) ) -> method ( implode ( '|' , $ routeMethods ) ) ; } if ( $ annotation -> name != null ) { $ ctr -> bind ( $ annotation -> name ) ; } else { $ ctr -> bind ( $ controllerService . '.' . strtolower ( $ reflectionMethod -> getName ( ) ) ) ; } if ( ! empty ( $ beforeFilters ) ) { foreach ( $ beforeFilters -> methods as $ method ) { $ this -> registerFilter ( $ method , 'before' , $ ctr , $ controllerService , $ reflectionClass ) ; } } if ( ! empty ( $ afterFilters ) ) { foreach ( $ afterFilters -> methods as $ method ) { $ this -> registerFilter ( $ method , 'after' , $ ctr , $ controllerService , $ reflectionClass ) ; } } $ this -> registerVariableHandlers ( $ ctr , $ controllerService , $ reflectionMethod ) ; } else { throw Exception :: routeMethodNotDefinedError ( sprintf ( "O metodo '%s' do controlador '%s' foi anotado como rota mas nao possui um metodo (post,get,etc) definido" , $ reflectionMethod -> getName ( ) , $ reflectionClass -> getName ( ) ) ) ; } }
Mapeia uma rota convencional em um controlador .
29,364
public function addRetry ( ) { $ retries = $ this -> activity [ 'retries' ] ; array_unshift ( $ retries , Carbon :: now ( ) -> toDateTimeString ( ) ) ; $ this -> activity = array_merge ( $ this -> activity , [ 'retries' => $ retries ] ) ; }
Add an entry to settings - > retries
29,365
public function scopeForUserContext ( $ query , Context $ context ) { if ( $ context -> hasRole ( 'Coach' ) ) { return $ query -> whereHas ( 'member' , function ( $ query ) use ( $ context ) { $ query -> where ( 'team_id' , $ context -> team_id ) ; } ) ; } return $ query -> where ( 'inviter_id' , $ context -> id ) ; }
Scope a query to only include MemberInvitations for a specified Team .
29,366
public static function getEnum ( ) { $ enumClass = get_called_class ( ) ; if ( ! isset ( self :: $ ConstantsCache [ $ enumClass ] ) ) { $ reflect = new \ ReflectionClass ( $ enumClass ) ; self :: $ ConstantsCache [ $ enumClass ] = $ reflect -> getConstants ( ) ; } return self :: $ ConstantsCache [ $ enumClass ] ; }
Get all constants of called class .
29,367
public static function isValidName ( $ name , $ strict = false ) { $ constants = self :: getEnum ( ) ; if ( $ strict ) { return array_key_exists ( $ name , $ constants ) ; } $ keys = array_map ( 'strtolower' , array_keys ( $ constants ) ) ; return in_array ( strtolower ( $ name ) , $ keys , true ) ; }
Checks whether a constant is valid .
29,368
public function query ( $ sql ) { $ this -> connect ( ) ; $ this -> statement = null ; if ( ! ( $ this -> result = $ this -> connection -> query ( $ sql ) ) ) { $ this -> showError ( ) ; } return $ this -> result ; }
Execute the SQL query and create a result resource or display the SQL error .
29,369
public static function create ( $ className , $ arguments = null , $ constructor = null , $ reflection = null ) { if ( ! $ reflection ) { $ reflection = new ReflectionClass ( $ className ) ; } if ( $ arguments ) { if ( ! is_array ( $ arguments ) ) { $ arguments = [ $ arguments ] ; } return $ reflection -> newInstanceArgs ( $ arguments ) ; } else { return $ reflection -> newInstance ( ) ; } }
This method is intend to create instances of multi - instance - classes . You can pass optional arguments to the factory for creating instance and passing arguments to it . You can pass an optional already existing reflection instance of the class if one exist to speed up instantiation . If you don t use an autoloader the you must include the file containing the class right before you call this method .
29,370
static public function dump ( $ data , $ line = true ) { if ( is_string ( $ data ) ) { $ data = json_decode ( str_replace ( [ "\r\n" ] , "" , $ data ) , true ) ; } if ( is_array ( $ data ) ) { $ isPureArray = false ; $ keys = array_keys ( $ data ) ; foreach ( $ keys as $ k ) { if ( ! is_numeric ( $ k ) ) { $ isPureArray = false ; break ; } } $ line = $ line ? PHP_EOL : '' ; $ str = "" ; $ s_data = [ ] ; foreach ( $ data as $ name => $ value ) { if ( is_scalar ( $ value ) ) { $ s_data [ ] = ( ! $ isPureArray ? '"' . $ name . '": ' : '' ) . ( is_string ( $ value ) ? '"' . $ value . '"' : $ value ) ; } else { $ s_data [ ] = ( ! $ isPureArray ? '"' . $ name . '": ' : '' ) . static :: dump ( $ value , $ line ) ; } } $ str .= implode ( ',' . $ line , $ s_data ) ; $ str = $ isPureArray ? '[' . $ line . $ str . $ line . ']' : '{' . $ line . $ str . $ line . '}' ; return $ str ; } return $ data ; }
dump pretty json
29,371
protected function addAttachmentBody ( array $ body ) { foreach ( $ this -> attachments as $ attachment ) { list ( $ name , $ data , $ mime ) = $ attachment ; $ mime = $ mime ? $ mime : MimeType :: getMimeType ( $ name ) ; $ data = base64_encode ( $ data ) ; $ count = ceil ( strlen ( $ data ) / 998 ) ; $ body [ ] = '--' . $ this -> boundary [ 1 ] ; $ body [ ] = 'Content-type: ' . $ mime . '; name="' . $ name . '"' ; $ body [ ] = 'Content-disposition: attachment; filename="' . $ name . '"' ; $ body [ ] = 'Content-transfer-encoding: base64' ; $ body [ ] = null ; for ( $ i = 0 ; $ i < $ count ; $ i ++ ) { $ body [ ] = substr ( $ data , ( $ i * 998 ) , 998 ) ; } $ body [ ] = null ; $ body [ ] = null ; } $ body [ ] = '--' . $ this -> boundary [ 1 ] . '--' ; return $ body ; }
Adds the attachment string body for plain text emails
29,372
protected function getHeaders ( array $ customHeaders = array ( ) ) { $ timestamp = $ this -> getTimestamp ( ) ; $ subject = trim ( $ this -> subject ) ; $ subject = str_replace ( array ( "\n" , "\r" ) , '' , $ subject ) ; $ to = $ cc = $ bcc = array ( ) ; foreach ( $ this -> to as $ email => $ name ) { $ to [ ] = trim ( $ name . ' <' . $ email . '>' ) ; } foreach ( $ this -> cc as $ email => $ name ) { $ cc [ ] = trim ( $ name . ' <' . $ email . '>' ) ; } foreach ( $ this -> bcc as $ email => $ name ) { $ bcc [ ] = trim ( $ name . ' <' . $ email . '>' ) ; } list ( $ account , $ suffix ) = explode ( '@' , $ this -> username ) ; $ headers = array ( 'Date' => $ timestamp , 'Subject' => $ subject , 'From' => '<' . $ this -> username . '>' , 'To' => implode ( ', ' , $ to ) ) ; if ( ! empty ( $ cc ) ) { $ headers [ 'Cc' ] = implode ( ', ' , $ cc ) ; } if ( ! empty ( $ bcc ) ) { $ headers [ 'Bcc' ] = implode ( ', ' , $ bcc ) ; } $ headers [ 'Message-ID' ] = '<' . md5 ( uniqid ( time ( ) ) ) . '.wslimphp@' . $ suffix . '>' ; $ headers [ 'Thread-Topic' ] = $ this -> subject ; $ headers [ 'Reply-To' ] = '<' . $ this -> username . '>' ; foreach ( $ customHeaders as $ key => $ value ) { $ key = explode ( '-' , $ key ) ; $ key = implode ( '-' , array_map ( function ( $ value ) { return ucfirst ( strtolower ( $ value ) ) ; } , $ key ) ) ; $ headers [ $ key ] = $ value ; } return $ headers ; }
Returns the header information
29,373
private function isUtf8 ( $ string ) { $ encoding = mb_detect_encoding ( $ string ) ; if ( $ encoding == 'UTF-8' ) { return true ; } $ regex = array ( '[\xC2-\xDF][\x80-\xBF]' , '\xE0[\xA0-\xBF][\x80-\xBF]' , '[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}' , '\xED[\x80-\x9F][\x80-\xBF]' , '\xF0[\x90-\xBF][\x80-\xBF]{2}' , '[\xF1-\xF3][\x80-\xBF]{3}' , '\xF4[\x80-\x8F][\x80-\xBF]{2}' ) ; $ count = ceil ( strlen ( $ string ) / 5000 ) ; for ( $ i = 0 ; $ i < $ count ; $ i ++ ) { if ( preg_match ( '%(?:' . implode ( '|' , $ regex ) . ')+%xs' , substr ( $ string , ( $ i * 5000 ) , 5000 ) ) ) { return false ; } } return true ; }
Returns true if there s UTF encodeing
29,374
private function quotedPrintableEncode ( $ input , $ line_max = 250 ) { $ hex = array ( '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , 'A' , 'B' , 'C' , 'D' , 'E' , 'F' ) ; $ lines = preg_split ( "/(?:\r\n|\r|\n)/" , $ input ) ; $ linebreak = "=0D=0A=\r\n" ; $ line_max = $ line_max - strlen ( $ linebreak ) ; $ escape = "=" ; $ output = "" ; $ cur_conv_line = "" ; $ length = 0 ; $ whitespace_pos = 0 ; $ addtl_chars = 0 ; for ( $ j = 0 ; $ j < count ( $ lines ) ; $ j ++ ) { $ line = $ lines [ $ j ] ; $ linlen = strlen ( $ line ) ; for ( $ i = 0 ; $ i < $ linlen ; $ i ++ ) { $ c = substr ( $ line , $ i , 1 ) ; $ dec = ord ( $ c ) ; $ length ++ ; if ( $ dec == 32 ) { if ( ( $ i == ( $ linlen - 1 ) ) ) { $ c = "=20" ; $ length += 2 ; } $ addtl_chars = 0 ; $ whitespace_pos = $ i ; } else if ( ( $ dec == 61 ) || ( $ dec < 32 ) || ( $ dec > 126 ) ) { $ h2 = floor ( $ dec / 16 ) ; $ h1 = floor ( $ dec % 16 ) ; $ c = $ escape . $ hex [ "$h2" ] . $ hex [ "$h1" ] ; $ length += 2 ; $ addtl_chars += 2 ; } if ( $ length >= $ line_max ) { $ cur_conv_line .= $ c ; $ whitesp_diff = $ i - $ whitespace_pos + $ addtl_chars ; if ( ( $ i + $ addtl_chars ) > $ whitesp_diff ) { $ output .= substr ( $ cur_conv_line , 0 , ( strlen ( $ cur_conv_line ) - $ whitesp_diff ) ) . $ linebreak ; $ i = $ i - $ whitesp_diff + $ addtl_chars ; } else { $ output .= $ cur_conv_line . $ linebreak ; } $ cur_conv_line = "" ; $ length = 0 ; $ whitespace_pos = 0 ; } else { $ cur_conv_line .= $ c ; } } $ length = 0 ; $ whitespace_pos = 0 ; $ output .= $ cur_conv_line ; $ cur_conv_line = "" ; if ( $ j <= count ( $ lines ) - 1 ) { $ output .= $ linebreak ; } } return trim ( $ output ) ; }
Returns a printable encode version of the body
29,375
protected function start ( $ interface = self :: INTERFACE_LOCALHOST , $ port = self :: DEFAULT_PORT , $ documentRoot = self :: DEFAULT_DOCUMENT_ROOT , $ router = self :: DEFAULT_ROOTER ) { $ command = sprintf ( 'php -S %s:%s -t %s%s 2>&1' , $ interface , $ port , $ documentRoot , $ router ) ; $ descriptorspec = array ( 0 => array ( 'pipe' , 'r' ) , 1 => array ( 'pipe' , 'w' ) , 2 => array ( 'pipe' , 'w' , 'a' ) , ) ; $ this -> server = proc_open ( $ command , $ descriptorspec , $ this -> pipes , $ documentRoot ) ; if ( $ this -> isRunning ( $ this -> server ) === false ) { $ this -> showError ( 'Failed to start test web server!' ) ; } else { $ status = proc_get_status ( $ this -> server ) ; echo $ this -> colorize ( 'Server running ' , '%g' ) . sprintf ( '[PID: %s] ' , $ status [ 'pid' ] ) . $ this -> colorize ( sprintf ( '%s:%s %s %s' , $ interface , $ port , $ documentRoot , $ router ) . ' ' , '%y' ) . PHP_EOL ; echo 'Press Ctrl + C to stop ...' . PHP_EOL ; while ( $ this -> isRunning ( $ this -> server ) !== false ) { echo $ this -> fetchStreams ( $ this -> pipes ) ; } } }
Starts PHP s internal webserver and give us some control of it .
29,376
protected function fetchStreams ( array $ pipes ) { $ output = $ this -> colorize ( stream_get_contents ( $ pipes [ 2 ] ) , '%r' ) ; $ output .= $ this -> colorize ( stream_get_contents ( $ pipes [ 1 ] ) , '%g' ) ; return $ output ; }
Fetch the streams new input .
29,377
public function getEasterDate ( ) { $ easter = new \ DateTime ( $ this -> getYear ( ) . '-03-21' ) ; $ days = easter_days ( $ this -> getYear ( ) ) ; return $ easter -> add ( new DateInterval ( 'P' . $ days . 'D' ) ) ; }
Returns the easter date for the current year
29,378
protected function init ( ) { if ( empty ( $ this -> errorCodeMatrix ) ) { $ typeMatrix = Doozr_Form_Service_Validator_Generic :: getValidationTypeMatrix ( ) ; foreach ( $ typeMatrix as $ type => $ order ) { $ this -> errorCodeMatrix [ $ type ] = ( $ order + 1 ) ; } } return $ this ; }
Initializes the validation matrix .
29,379
protected function getErrorMessage ( $ errorCode ) { if ( ! isset ( $ this -> errorMessageMatrix [ $ errorCode ] ) ) { $ this -> errorMessageMatrix [ $ errorCode ] = 'ERROR_MSG_UNKNOWN' ; } if ( $ this -> info ) { if ( is_string ( $ this -> info ) ) { $ this -> errorMessageMatrix [ $ errorCode ] .= ' ' . $ this -> info ; } elseif ( count ( $ this -> info ) != 1 || $ this -> info [ 0 ] != null ) { foreach ( $ this -> info as $ info ) { $ info = serialize ( $ info ) ; $ this -> errorMessageMatrix [ $ errorCode ] .= ' ' . $ info ; } } } return $ this -> errorMessageMatrix [ $ errorCode ] ; }
Returns error - message by error - code .
29,380
public function addColumn ( $ table , $ name , $ type ) { return $ this -> handler -> addColumn ( $ table , $ name , $ type ) ; }
Adds a new column to a database table .
29,381
public function withGroup ( $ group ) { $ group = str_replace ( '\\' , '/' , $ group ) ; if ( ! isset ( static :: $ instances [ $ group ] ) ) { $ instance = new static ( $ this -> options ) ; $ instance -> setGroup ( $ group ) ; static :: $ instances [ $ group ] = $ instance ; } return static :: $ instances [ $ group ] ; }
with specified group return new object
29,382
public static final function instance ( self $ instance = null ) { if ( ! self :: $ _instance ) { self :: $ _instance = ! is_null ( $ instance ) ? $ instance : new static ( 2 ) ; } return self :: $ _instance ; }
The instance used by the static logging methods .
29,383
final private function protectMethod ( ) { if ( ! ( App :: environment ( 'testing' ) || ( $ this -> callerService instanceof Service ) || ( self :: $ callerServiceForNext instanceof Service ) ) ) { throw new \ Exception ( 'You must use an Subbly\Api\Service\Service to save a Model' ) ; } $ this -> callerService = null ; }
Protect the model methods .
29,384
public function getData ( ) { if ( $ this -> data ) { return $ this -> data ; } if ( ! $ this -> url ) { throw new AVException ( "Cannot retrieve data for unsaved AVFile." ) ; } $ this -> data = $ this -> download ( ) ; return $ this -> data ; }
Return the data for the file downloading it if not already present .
29,385
public function delete ( ) { if ( ! $ this -> url ) { throw new AVException ( "Cannot delete file that has not been saved." ) ; } $ headers = AVClient :: _getRequestHeaders ( null , true ) ; $ url = AVClient :: HOST_NAME . '/files/' . $ this -> getName ( ) ; $ rest = curl_init ( ) ; curl_setopt ( $ rest , CURLOPT_URL , $ url ) ; curl_setopt ( $ rest , CURLOPT_CUSTOMREQUEST , "DELETE" ) ; curl_setopt ( $ rest , CURLOPT_RETURNTRANSFER , 1 ) ; curl_setopt ( $ rest , CURLOPT_HTTPHEADER , $ headers ) ; $ response = curl_exec ( $ rest ) ; $ contentType = curl_getinfo ( $ rest , CURLINFO_CONTENT_TYPE ) ; if ( curl_errno ( $ rest ) ) { throw new AVException ( curl_error ( $ rest ) , curl_errno ( $ rest ) ) ; } curl_close ( $ rest ) ; }
Send a REST request to delete the AVFile
29,386
public static function _createFromServer ( $ name , $ url ) { $ file = new AVFile ( ) ; $ file -> name = $ name ; $ file -> url = $ url ; return $ file ; }
Internal method used when constructing a Avos File from Avos .
29,387
public function save ( ) { if ( ! $ this -> url ) { $ response = $ this -> upload ( ) ; $ this -> url = $ response [ 'url' ] ; $ this -> name = $ response [ 'name' ] ; } return true ; }
Uploads the file contents to Avos if not saved .
29,388
public function findMain ( bool $ onlyVisible = false ) : ICollection { $ result = ( $ onlyVisible ? $ this -> findVisible ( ) : $ this -> findAll ( ) ) -> findBy ( [ 'parent' => null ] ) ; return $ result ; }
Vrati hlavni stranky
29,389
public function findMenu ( string $ locale ) : ICollection { return $ this -> findMain ( true ) -> findBy ( [ 'this->views->id' => PagesViewsMapper :: MENU , 'this->locale->name' => $ locale ] ) ; }
Vrati stranky v menu
29,390
public function findFooter ( string $ locale ) : ICollection { return $ this -> findMain ( true ) -> findBy ( [ 'this->views->id' => PagesViewsMapper :: FOOTER , 'this->locale->name' => $ locale ] ) ; }
Vrati stranky v paticce
29,391
protected static function sendCookieForm ( $ message = '' ) { ?> <!DOCTYPE HTML><html lang="en-US"> <head><meta charset="UTF-8"> <?php echo self :: getAllJs ( ) ; ?> <style type="text/css"> * {font-family:Candara,Arial,Tahoma,georgia,serif; font-size: 0.99em;} legend { margin-top: 10px; } .form-horizontal .control-label { float: left; width: 40px; padding-right: 20px; } body .form-horizontal .form-group { margin-left: 0; margin-right: 0; } .form-horizontal .controls { margin-left: 50px; } .form-horizontal input[type="text"], .form-horizontal input[type="password"] { width: 260px; } .alert { font-size: 13px; margin-top: 10px; } .alert i { margin-right: 12px; } i { padding-right: 5px; } .relative { position: relative; } .absolute { left: 137px; position: absolute; top: -34px; } </style> <script type="text/javascript"> $(function () { var form = $('form'); $('button').click(function () { var val = $(this).data('val'); form .find('.val') .val(val) .attr('name',val) .end() .submit(); }) }); </script> </head><body> <fieldset style="width: 300px; margin: auto;"> <legend>Logowanie:</legend> <form method="post" class="form-horizontal"> <div class="form-group"> <label for=" <?php echo self :: PL ; ?> " class="control-label">login:</label> <div> <input type="text" name=" <?php echo self :: PL ; ?> " class="form-control" required="required"/> </div> </div> <div class="form-group"> <label for=" <?php echo self :: PP ; ?> " class="control-label">hasło:</label> <div> <input type="password" name=" <?php echo self :: PP ; ?> " class="form-control" required="required"/> </div> </div> <input type="hidden" class="val" /> <div class="form-horizontal"> <div class="control-group"> <label class="control-label"></label> <div> <button type="submit" class="btn btn-primary" data-val="login" value="_basicauth_redirect" name="_basicauth_redirect"> <i class="glyphicon glyphicon-ok"></i> zaloguj </button> </div> </div> <?php if ( ! empty ( $ message ) ) { ?> <div class="alert alert-warning"><i class="glyphicon glyphicon-info-sign"></i> <?php echo $ message ; ?> </div> <?php } ?> </div> </form> <div class="relative"> <?php if ( ! empty ( $ _COOKIE [ static :: $ CN ] ) ) { ?> <button type="submit" class="btn btn-danger absolute" data-val="logout"> <i class="glyphicon glyphicon-remove"></i> usuń ciastko </button> <?php } ?> </div> </fieldset> </body></html> <?php die ( ) ; }
Taka metoda templatka
29,392
public function update ( ) { if ( ! Input :: has ( 'settings' ) ) { return $ this -> jsonErrorResponse ( '"settings" is required.' ) ; } $ settings = Subbly :: api ( 'subbly.setting' ) ; $ user = $ settings -> updateMany ( Input :: get ( 'settings' ) ) ; return $ this -> jsonResponse ( array ( 'settings' => $ settings -> all ( ) , ) , array ( 'status' => array ( 'code' => 200 , 'message' => 'Settings updated' , ) , ) ) ; }
Update a Setting .
29,393
public function setMetatags ( array $ metatags ) { if ( array_key_exists ( 'title' , $ metatags ) ) $ this -> metaTitle = $ metatags [ 'title' ] ; if ( array_key_exists ( 'description' , $ metatags ) ) $ this -> metaDescription = $ metatags [ 'description' ] ; if ( array_key_exists ( 'keywords' , $ metatags ) ) $ this -> metaKeywords = $ metatags [ 'keywords' ] ; return $ this ; }
Sets the page metatags
29,394
protected function mergeAssets ( $ method , $ assetType , $ type ) { $ assetsCollection = $ this -> getTemplate ( ) -> $ method ( ) ; if ( null !== $ assetsCollection ) { $ assetsCollection = clone ( $ assetsCollection ) ; $ blocks = $ this -> pageBlocks -> getBlocks ( ) ; foreach ( $ blocks as $ slotBlocks ) { foreach ( $ slotBlocks as $ block ) { $ key = ucfirst ( $ type ) . ucfirst ( $ assetType ) ; $ key = substr ( $ key , 0 , - 1 ) ; if ( array_key_exists ( $ key , $ block ) ) { $ assetsCollection -> addRange ( explode ( ',' , $ block [ $ key ] ) ) ; } } } return $ assetsCollection ; } }
Merges the assets for the given method
29,395
protected function __data ( ) { $ people = [ ] ; $ people [ ] = 'John Do' ; $ people [ ] = 'Jane Do' ; $ people [ ] = 'Foo Bar' ; $ people [ ] = 'Bar Baz' ; $ data = [ 'title' => 'Doozr\'s bootstrap environment' , 'year' => date ( 'Y' ) , 'people' => $ people , ] ; $ this -> setData ( $ data ) ; return true ; }
Magic & generic data delivery .
29,396
public function aroundTranslateTypeName ( \ Magento \ Framework \ Reflection \ TypeProcessor $ subject , \ Closure $ proceed , $ class ) { try { $ result = $ proceed ( $ class ) ; } catch ( \ InvalidArgumentException $ e ) { if ( preg_match ( '/\\\\?(Praxigento)\\\\([A-Za-z0-9]*)\\\\(.*)/' , $ class , $ matches ) ) { $ moduleNamespace = 'Praxigento' ; $ moduleName = $ matches [ 2 ] ; $ typeNameParts = explode ( '\\' , $ matches [ 3 ] ) ; $ result = ucfirst ( $ moduleNamespace . $ moduleName . implode ( '' , $ typeNameParts ) ) ; } elseif ( preg_match ( '/\\\\?(Flancer32)\\\\([A-Za-z0-9]*)\\\\(.*)/' , $ class , $ matches ) ) { $ moduleNamespace = 'Flancer32' ; $ moduleName = $ matches [ 2 ] ; $ typeNameParts = explode ( '\\' , $ matches [ 3 ] ) ; $ result = ucfirst ( $ moduleNamespace . $ moduleName . implode ( '' , $ typeNameParts ) ) ; } else { throw $ e ; } } return $ result ; }
Add \ Praxigento \ ... namespace to available set to process classes as web service enabled .
29,397
public static function removeEmptyDirsToPath ( $ dir , $ path ) { $ dir = rtrim ( $ dir , DIRECTORY_SEPARATOR ) ; $ path = rtrim ( $ path , DIRECTORY_SEPARATOR ) ; while ( $ dir != $ path ) { if ( ! static :: removeDirIfEmpty ( $ dir ) ) { break ; } $ dir = pathinfo ( $ dir , PATHINFO_DIRNAME ) ; } }
Remove empty directory up to path
29,398
public static function rename ( $ source , $ target , $ mode = 0770 ) { $ dir = dirname ( $ target ) ; if ( ! file_exists ( $ dir ) ) { static :: mkDir ( $ dir , true , $ mode ) ; } return rename ( $ source , $ target ) ; }
Move method but it will create directory if doesn t eist
29,399
public static function toggleFlagGetState ( $ file , $ id ) { static :: checkFile ( $ file , $ toWrite = true ) ; $ content = file_get_contents ( $ file ) ; $ id = preg_quote ( $ id , '#' ) ; preg_match ( "#/\*$id\*/!!([0|1])#" , $ content , $ match ) ; if ( isset ( $ match [ '1' ] ) ) { return ! ! intval ( $ match [ '1' ] ) ; } return null ; }
Return state of flag