idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
11,000
|
public function debug_decode ( $ json , $ assoc = false , $ depth = 512 , $ options = 0 ) { $ test = json_decode ( $ json , $ assoc , $ depth , $ options ) ; if ( ! empty ( $ test ) ) $ json = $ test ; $ data = $ this -> errorMessage ( json_last_error ( ) , $ json ) ; return json_encode ( $ data , JSON_PRETTY_PRINT ) ; }
|
Debugger to test json decode
|
11,001
|
public function fixControlChar ( $ string ) { for ( $ i = 0 ; $ i <= 9 ; ++ $ i ) { $ string = str_replace ( chr ( $ i ) , "" , $ string ) ; } for ( $ i = 11 ; $ i <= 12 ; ++ $ i ) { $ string = str_replace ( chr ( $ i ) , "" , $ string ) ; } for ( $ i = 14 ; $ i <= 31 ; ++ $ i ) { $ string = str_replace ( chr ( $ i ) , "" , $ string ) ; } $ string = str_replace ( chr ( 127 ) , "" , $ string ) ; if ( 0 === strpos ( bin2hex ( $ string ) , 'efbbbf' ) ) { $ string = substr ( $ string , 3 ) ; } $ string = preg_replace ( "/[\r\n]+/" , "\\n" , $ string ) ; return $ string ; }
|
Most common fixed hidden control char in json string which made json decode fails .
|
11,002
|
public function modifyJsonStringInArray ( $ data , $ jsonfield , $ setnewfield = "" ) { if ( is_array ( $ data ) ) { if ( count ( $ data ) == count ( $ data , COUNT_RECURSIVE ) ) { foreach ( $ data as $ value ) { if ( ! empty ( $ setnewfield ) ) { if ( is_array ( $ jsonfield ) ) { for ( $ i = 0 ; $ i < count ( $ jsonfield ) ; $ i ++ ) { if ( isset ( $ data [ $ jsonfield [ $ i ] ] ) ) { $ data [ $ setnewfield [ $ i ] ] = json_decode ( $ data [ $ jsonfield [ $ i ] ] ) ; } } } else { if ( isset ( $ data [ $ jsonfield ] ) ) { $ data [ $ setnewfield ] = json_decode ( $ data [ $ jsonfield ] ) ; } } } else { if ( is_array ( $ jsonfield ) ) { for ( $ i = 0 ; $ i < count ( $ jsonfield ) ; $ i ++ ) { if ( isset ( $ data [ $ jsonfield [ $ i ] ] ) ) { if ( is_string ( $ data [ $ jsonfield [ $ i ] ] ) ) { $ decode = json_decode ( $ data [ $ jsonfield [ $ i ] ] ) ; if ( ! empty ( $ decode ) ) $ data [ $ jsonfield [ $ i ] ] = $ decode ; } } } } else { if ( isset ( $ data [ $ jsonfield ] ) ) { $ decode = json_decode ( $ data [ $ jsonfield ] ) ; if ( ! empty ( $ decode ) ) $ data [ $ jsonfield ] = $ decode ; } } } } } else { foreach ( $ data as $ key => $ value ) { $ data [ $ key ] = $ this -> modifyJsonStringInArray ( $ data [ $ key ] , $ jsonfield , $ setnewfield ) ; } } } return $ data ; }
|
Modify json data string in some field array to be nice json data structure
|
11,003
|
public function minify ( $ json ) { $ tokenizer = "/\"|(\/\*)|(\*\/)|(\/\/)|\n|\r/" ; $ in_string = false ; $ in_multiline_comment = false ; $ in_singleline_comment = false ; $ tmp ; $ tmp2 ; $ new_str = array ( ) ; $ ns = 0 ; $ from = 0 ; $ lc ; $ rc ; $ lastIndex = 0 ; while ( preg_match ( $ tokenizer , $ json , $ tmp , PREG_OFFSET_CAPTURE , $ lastIndex ) ) { $ tmp = $ tmp [ 0 ] ; $ lastIndex = $ tmp [ 1 ] + strlen ( $ tmp [ 0 ] ) ; $ lc = substr ( $ json , 0 , $ lastIndex - strlen ( $ tmp [ 0 ] ) ) ; $ rc = substr ( $ json , $ lastIndex ) ; if ( ! $ in_multiline_comment && ! $ in_singleline_comment ) { $ tmp2 = substr ( $ lc , $ from ) ; if ( ! $ in_string ) { $ tmp2 = preg_replace ( "/(\n|\r|\s)*/" , "" , $ tmp2 ) ; } $ new_str [ ] = $ tmp2 ; } $ from = $ lastIndex ; if ( $ tmp [ 0 ] == "\"" && ! $ in_multiline_comment && ! $ in_singleline_comment ) { preg_match ( "/(\\\\)*$/" , $ lc , $ tmp2 ) ; if ( ! $ in_string || ! $ tmp2 || ( strlen ( $ tmp2 [ 0 ] ) % 2 ) == 0 ) { $ in_string = ! $ in_string ; } $ from -- ; $ rc = substr ( $ json , $ from ) ; } else if ( $ tmp [ 0 ] == "/*" && ! $ in_string && ! $ in_multiline_comment && ! $ in_singleline_comment ) { $ in_multiline_comment = true ; } else if ( $ tmp [ 0 ] == "*/" && ! $ in_string && $ in_multiline_comment && ! $ in_singleline_comment ) { $ in_multiline_comment = false ; } else if ( $ tmp [ 0 ] == "//" && ! $ in_string && ! $ in_multiline_comment && ! $ in_singleline_comment ) { $ in_singleline_comment = true ; } else if ( ( $ tmp [ 0 ] == "\n" || $ tmp [ 0 ] == "\r" ) && ! $ in_string && ! $ in_multiline_comment && $ in_singleline_comment ) { $ in_singleline_comment = false ; } else if ( ! $ in_multiline_comment && ! $ in_singleline_comment && ! ( preg_match ( "/\n|\r|\s/" , $ tmp [ 0 ] ) ) ) { $ new_str [ ] = $ tmp [ 0 ] ; } } $ new_str [ ] = $ rc ; return implode ( "" , $ new_str ) ; }
|
Minify the json string
|
11,004
|
public function renderPageSummary ( ) { $ content = parent :: renderPageSummary ( ) ; if ( $ this -> showCustomPageSummary ) { if ( ! $ content ) { $ content = "<tfoot></tfoot>" ; } if ( $ this -> beforeSummary ) { foreach ( $ this -> beforeSummary as & $ row ) { if ( ! isset ( $ row [ 'options' ] ) ) { $ row [ 'options' ] = $ this -> pageSummaryRowOptions ; } } } if ( $ this -> afterSummary ) { foreach ( $ this -> afterSummary as & $ row ) { if ( ! isset ( $ row [ 'options' ] ) ) { $ row [ 'options' ] = $ this -> pageSummaryRowOptions ; } } } return strtr ( $ content , [ '<tfoot>' => "<tfoot>\n" . parent :: generateRows ( $ this -> beforeSummary ) , '</tfoot>' => parent :: generateRows ( $ this -> afterSummary ) . "\n</tfoot>" , ] ) ; } return $ content ; }
|
Custom renders the table page summary .
|
11,005
|
public function multi ( string $ name = null , string $ mail = null , string $ ip = null ) { return $ this -> makeRequest ( 'multi' , compact ( 'name' , 'mail' , 'ip' ) ) ; }
|
Test matches all parameters at once .
|
11,006
|
public function getContent ( ) { $ content = "" ; $ maxLen = 0 ; foreach ( $ this -> logs as $ log ) if ( $ log [ 0 ] ) { $ name = $ log [ 0 ] -> getFeature ( ) -> getName ( ) ; $ maxLen = strlen ( $ name ) > $ maxLen ? strlen ( $ name ) : $ maxLen ; } foreach ( $ this -> logs as $ log ) $ content .= sprintf ( "%-{$maxLen}s | $log[1]\n" , $ log [ 0 ] ? $ log [ 0 ] -> getFeature ( ) -> getName ( ) : "" ) ; return new TextFileContent ( $ content ) ; }
|
Returns the log file s content . Tabular output is generated .
|
11,007
|
public function render_screen ( ) { $ this -> register_batches ( ) ; ?> <div class="wrap"> <h2> <?php $ this -> _e ( 'Do Batch Actions' ) ?> </h2> <?php if ( $ this -> batches ) : ?> <form id="batch-form" method="post" action=" <?= admin_url ( 'admin-ajax.php' ) ?> "> <input type="hidden" name="action" value="wpametu_batch"> <?php wp_nonce_field ( 'wpametu_batch' ) ?> <input type="hidden" name="page_num" id="page_num" value="1" /> <ol class="batch-container"> <?php $ counter = 0 ; foreach ( $ this -> batches as $ batch_class ) : $ counter ++ ; $ batch = $ batch_class :: get_instance ( ) ; $ option = $ this -> option ; if ( isset ( $ option [ $ batch_class ] ) ) { $ last = $ option [ $ batch_class ] ; } else { $ last = false ; } ?> <li> <input type="radio" id="batch- <?= $ counter ?> " name="batch_class" value=" <?= esc_attr ( get_class ( $ batch ) ) ?> " /> <label for="batch- <?= $ counter ?> "> <span class="dashicons dashicons-yes"></span> <strong> <?= esc_html ( $ batch -> title ) ?> </strong><small>ver <?= esc_html ( $ batch -> version ) ?> </small> <span class="description"> <?= nl2br ( esc_html ( $ batch -> description ) ) ?> </span> <?php if ( false === $ last ) : ?> <span class="executed not-yet"> <?php $ this -> _e ( 'Never executed' ) ?> </span> <?php else : ?> <span class="executed"> <?= date_i18n ( get_option ( 'date_format' ) . ' ' . get_option ( 'time_format' ) , $ last ) ?> </span> <?php endif ; ?> </label> </li> <?php endforeach ; ?> </ol> <?php submit_button ( $ this -> __ ( 'Execute' ) ) ?> <div class="loader"> <div><span class="dashicons dashicons-update"></span></div> </div> </form> <div id="batch-result"> <h3><span class="dashicons dashicons-media-code"></span> <?php $ this -> _e ( 'Console' ) ?> </h3> <div class="console"> </div> </div> <?php else : ?> <div class="error"><p> <?php $ this -> _e ( 'There is no classes.' ) ?> </p></div> <?php endif ; ?> </div> <?php }
|
Render Admin screen
|
11,008
|
protected function register_batches ( ) { static $ batch_registered = false ; if ( ! $ batch_registered ) { $ auto_loader = AutoLoader :: get_instance ( ) ; $ root = $ auto_loader -> namespace_root ; $ namespace = $ auto_loader -> namespace ; if ( $ namespace && $ root && is_dir ( $ root . '/Batches' ) ) { foreach ( scandir ( $ root . '/Batches' ) as $ file ) { if ( preg_match ( '/\.php$/' , $ file ) ) { $ class_name = $ namespace . '\\Batches\\' . str_replace ( '.php' , '' , $ file ) ; if ( class_exists ( $ class_name ) && $ this -> is_sub_class_of ( $ class_name , Batch :: class ) ) { $ this -> batches [ ] = $ class_name ; } } } } $ batch_registered = true ; } }
|
Register Batch classes
|
11,009
|
public function request ( array $ curl_options ) { $ curl = $ this -> _init ( $ curl_options ) ; $ response = $ this -> _execute ( $ curl ) ; if ( $ response === FALSE ) { $ this -> _handle_error ( $ curl ) ; return FALSE ; } $ this -> _close ( $ curl ) ; return $ response ; }
|
Perform a cURL request
|
11,010
|
protected function _init ( array $ curl_options ) { $ options = array ( CURLOPT_SSL_VERIFYPEER => FALSE , CURLOPT_SSL_VERIFYHOST => FALSE , CURLOPT_RETURNTRANSFER => TRUE , CURLOPT_FOLLOWLOCATION => TRUE , CURLOPT_MAXREDIRS => 10 ) ; $ options += $ curl_options ; $ curl = curl_init ( ) ; curl_setopt_array ( $ curl , $ options ) ; return $ curl ; }
|
Initializes a cURL resource and set options
|
11,011
|
protected function _handle_error ( $ curl ) { $ code = curl_errno ( $ curl ) ; $ error = curl_error ( $ curl ) ; $ this -> _close ( $ curl ) ; throw new Exception_Source ( 'Fetching :source_name data failed: :error (:code)' , 'remote' , array ( ':error' => $ error , ':code' => $ code ) ) ; }
|
Handle cURL errors
|
11,012
|
public static function getValues ( $ name , $ index = 'code' ) { if ( $ property_id = self :: getId ( $ name ) ) { $ a = [ ] ; foreach ( Lookup :: find ( ) -> select ( [ 'position' , 'name' ] ) -> where ( [ 'property_id' => $ property_id ] ) -> orderBy ( $ index ) -> all ( ) as $ item ) $ a [ $ item -> $ index ] = $ item -> name ; return $ a ; } else return null ; }
|
Get all property values as array with Code or Position as index .
|
11,013
|
private function set_cron_event ( ) { $ interval = $ this -> get_interval ( ) ; if ( $ interval > 0 ) { if ( ! wp_next_scheduled ( $ this -> get_hook_name ( ) ) ) { if ( $ this -> is_running_cron_process ( ) ) { return ; } wp_schedule_single_event ( time ( ) + $ interval , $ this -> get_hook_name ( ) ) ; } } }
|
set cron event
|
11,014
|
public function isValid ( $ value , array $ context = null ) { $ context = ( array ) $ context ; if ( ! array_key_exists ( $ this -> identity , $ context ) || empty ( $ context [ $ this -> identity ] ) ) { return false ; } if ( ! array_key_exists ( $ this -> credential , $ context ) || empty ( $ context [ $ this -> credential ] ) ) { return false ; } $ authAdapter = $ this -> auth -> getAdapter ( ) ; $ authAdapter -> setIdentity ( $ context [ $ this -> identity ] ) ; $ authAdapter -> setCredential ( $ context [ $ this -> credential ] ) ; $ result = $ this -> authResult = $ this -> auth -> authenticate ( ) ; if ( ! $ result -> isValid ( ) ) { $ this -> error ( $ result -> getCode ( ) ) ; return false ; } return true ; }
|
Test if authentication is valid
|
11,015
|
protected function fires ( ) { $ className = isset ( $ this -> notification -> classname ) ? snake_case ( class_basename ( $ this -> notification -> classname ) ) : false ; if ( ! $ className ) { return [ ] ; } $ before = event ( 'notifications:' . $ className . '.render.before' ) ; $ after = event ( 'notifications:' . $ className . '.render.after' ) ; return [ 'before' => ! empty ( $ before ) ? current ( $ before ) : '' , 'after' => ! empty ( $ after ) ? current ( $ after ) : '' ] ; }
|
fires events for notification template
|
11,016
|
public function save ( array $ options = array ( ) ) { $ fired = $ this -> fires ( ) ; $ content = count ( $ fired ) ? str_replace ( [ $ fired [ 'before' ] , $ fired [ 'after' ] ] , '' , $ this -> content ) : $ this -> content ; $ this -> setAttribute ( 'content' , $ content ) ; $ this -> attributes [ 'content' ] = $ content ; parent :: save ( $ options ) ; }
|
saves notification content without data from fired events
|
11,017
|
public function get ( $ key , $ defaultValue = null ) { $ keys = explode ( '.' , $ key ) ; $ config = $ this -> _arr ; foreach ( $ keys as $ value ) { if ( is_array ( $ config ) ) { if ( array_key_exists ( $ value , $ config ) ) { $ config = $ config [ $ value ] ; } else { return $ defaultValue ; } } else { return $ defaultValue ; } } return $ config ; }
|
Gets config value based on key .
|
11,018
|
public function set ( $ key , $ value ) { $ keys = explode ( '.' , $ key ) ; $ config = & $ this -> _arr ; foreach ( $ keys as $ val ) { $ config = & $ config [ $ val ] ; } $ config = $ value ; }
|
Sets config value based on key .
|
11,019
|
public function remove ( $ key ) { $ keys = explode ( '.' , $ key ) ; $ cKeys = count ( $ keys ) ; $ config = & $ this -> _arr ; for ( $ i = 0 ; $ i < $ cKeys ; ++ $ i ) { if ( $ i === ( $ cKeys - 1 ) ) { unset ( $ config [ $ keys [ $ i ] ] ) ; } elseif ( is_array ( $ config ) ) { if ( array_key_exists ( $ keys [ $ i ] , $ config ) ) { $ config = & $ config [ $ keys [ $ i ] ] ; } else { return ; } } } }
|
Removes config value based on key .
|
11,020
|
public function has ( $ key ) { $ keys = explode ( '.' , $ key ) ; $ cKeys = count ( $ keys ) ; $ config = $ this -> _arr ; for ( $ i = 0 ; $ i < $ cKeys ; ++ $ i ) { if ( is_array ( $ config ) ) { if ( array_key_exists ( $ keys [ $ i ] , $ config ) ) { $ config = $ config [ $ keys [ $ i ] ] ; } else { return false ; } } else { return false ; } } return true ; }
|
Checks whether config has a certain key .
|
11,021
|
public function add_fonts ( array $ fonts ) { if ( ! \ defined ( 'BBN_LIB_PATH' ) ) { die ( 'You must define BBN_LIB_PATH!' ) ; } if ( ! is_dir ( BBN_LIB_PATH . 'mpdf/mpdf/ttfonts/' ) ) { die ( "You don't have the mpdf/mpdf/ttfonts directory." ) ; } foreach ( $ fonts as $ f => $ fs ) { foreach ( $ fs as $ i => $ v ) { if ( ! empty ( $ v ) ) { if ( ! is_file ( BBN_LIB_PATH . 'mpdf/mpdf/ttfonts/' . basename ( $ v ) ) ) { \ bbn \ file \ dir :: copy ( $ v , BBN_LIB_PATH . 'mpdf/mpdf/ttfonts/' . basename ( $ v ) ) ; } $ fs [ $ i ] = basename ( $ v ) ; if ( $ i === 'R' ) { array_push ( $ this -> pdf -> available_unifonts , $ f ) ; } else { array_push ( $ this -> pdf -> available_unifonts , $ f . $ i ) ; } } else { unset ( $ fs [ $ i ] ) ; } } $ this -> pdf -> fontdata [ $ f ] = $ fs ; } $ this -> pdf -> default_available_fonts = $ this -> pdf -> available_unifonts ; }
|
Adds custom fonts
|
11,022
|
static public function confirmAspectMockConfigured ( ) { $ httpDouble = test :: double ( 'SimpleSAML\Utils\HTTP' , [ 'getAcceptLanguage' => [ 'some-lang' ] ] ) ; if ( [ 'some-lang' ] !== \ SimpleSAML \ Utils \ HTTP :: getAcceptLanguage ( ) ) { throw new \ Exception ( "Aspect mock does not seem to be configured" ) ; } return $ httpDouble ; }
|
Checks that AspectMock is configured and can override HTTP Util methods
|
11,023
|
private function setupConnection ( ) { $ requiredMode = $ this -> options -> quoteIdentifier ; if ( $ requiredMode == ezcDbMssqlOptions :: QUOTES_GUESS ) { $ result = parent :: query ( "SELECT sessionproperty('QUOTED_IDENTIFIER')" ) ; $ rows = $ result -> fetchAll ( ) ; $ mode = ( int ) $ rows [ 0 ] [ 0 ] ; if ( $ mode == 0 ) { $ this -> identifierQuoteChars = array ( 'start' => '[' , 'end' => ']' ) ; } else { $ this -> identifierQuoteChars = array ( 'start' => '"' , 'end' => '"' ) ; } } else if ( $ requiredMode == ezcDbMssqlOptions :: QUOTES_COMPLIANT ) { parent :: exec ( 'SET QUOTED_IDENTIFIER ON' ) ; $ this -> identifierQuoteChars = array ( 'start' => '"' , 'end' => '"' ) ; } else if ( $ requiredMode == ezcDbMssqlOptions :: QUOTES_LEGACY ) { parent :: exec ( 'SET QUOTED_IDENTIFIER OFF' ) ; $ this -> identifierQuoteChars = array ( 'start' => '[' , 'end' => ']' ) ; } }
|
Sets up opened connection according to options .
|
11,024
|
protected function rebuildClassPathCache ( $ path , $ cacheFile ) { if ( $ cacheFile !== false ) { $ tmp = $ this -> classPath ; $ this -> classPath = array ( ) ; } $ list = glob ( rtrim ( $ path , DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR . '*' ) ; if ( is_array ( $ list ) ) { foreach ( $ list as $ f ) { if ( is_dir ( $ f ) ) { $ this -> rebuildClassPathCache ( $ f , false ) ; } else { $ this -> classPath [ str_replace ( array ( 'function.' , 'block.' , 'modifier.' , 'outputfilter.' , 'filter.' , 'prefilter.' , 'postfilter.' , 'pre.' , 'post.' , 'output.' , 'shared.' , 'helper.' ) , '' , basename ( $ f , '.php' ) ) ] = $ f ; } } } if ( $ cacheFile !== false ) { if ( ! file_put_contents ( $ cacheFile , serialize ( $ this -> classPath ) ) ) { throw new Dwoo_Exception ( 'Could not write into ' . $ cacheFile . ', either because the folder is not there (create it) or because of the chmod configuration (please ensure this directory is writable by php), alternatively you can change the directory used with $dwoo->setCompileDir() or provide a custom loader object with $dwoo->setLoader()' ) ; } $ this -> classPath += $ tmp ; } }
|
rebuilds class paths scans the given directory recursively and saves all paths in the given file
|
11,025
|
public function loadPlugin ( $ class , $ forceRehash = true ) { if ( ! isset ( $ this -> classPath [ $ class ] ) || ! ( include $ this -> classPath [ $ class ] ) ) { if ( $ forceRehash ) { $ this -> rebuildClassPathCache ( $ this -> corePluginDir , $ this -> cacheDir . 'classpath.cache.d' . Dwoo :: RELEASE_TAG . '.php' ) ; foreach ( $ this -> paths as $ path => $ file ) { $ this -> rebuildClassPathCache ( $ path , $ file ) ; } if ( isset ( $ this -> classPath [ $ class ] ) ) { include $ this -> classPath [ $ class ] ; } else { throw new Dwoo_Exception ( 'Plugin <em>' . $ class . '</em> can not be found, maybe you forgot to bind it if it\'s a custom plugin ?' , E_USER_NOTICE ) ; } } else { throw new Dwoo_Exception ( 'Plugin <em>' . $ class . '</em> can not be found, maybe you forgot to bind it if it\'s a custom plugin ?' , E_USER_NOTICE ) ; } } }
|
loads a plugin file
|
11,026
|
public static function render ( $ source , $ rules = array ( ) , $ directory = null ) { if ( ! $ directory ) $ directory = getcwd ( ) ; return self :: fromSpecification ( fphp \ Specification \ TemplateSpecification :: fromArrayAndSettings ( array ( "source" => $ source , "rules" => $ rules ) , fphp \ Settings :: inDirectory ( $ directory ) ) ) -> getContent ( ) -> getSummary ( ) ; }
|
A quick way to directly render a template file with some replacement rules .
|
11,027
|
public function getContent ( ) { $ content = file_get_contents ( $ this -> fileSource ) ; foreach ( $ this -> rules as $ rule ) $ content = $ rule -> apply ( $ content ) ; return new TextFileContent ( $ content ) ; }
|
Returns the template file s content . The content consists of the file content with every rule applied .
|
11,028
|
public function listAction ( ) { $ this -> performAccessChecks ( ) ; $ crons = $ this -> cronService -> getCrons ( ) ; return $ this -> render ( 'SmileEzUICronBundle:cron:tab/crons/list.html.twig' , [ 'datas' => $ crons ] ) ; }
|
List crons definition
|
11,029
|
public function editAction ( Request $ request , $ type , $ alias ) { $ this -> performAccessChecks ( ) ; $ value = $ request -> get ( 'value' ) ; $ response = new Response ( ) ; try { $ this -> cronService -> updateCron ( $ alias , $ type , $ value ) ; $ response -> setStatusCode ( 200 , $ this -> translator -> trans ( 'cron.edit.done' , [ '%type%' => $ type , '%alias%' => $ alias ] , 'smileezcron' ) ) ; } catch ( NotFoundException $ e ) { $ response -> setStatusCode ( 500 , $ e -> getMessage ( ) ) ; } catch ( InvalidArgumentException $ e ) { $ response -> setStatusCode ( 500 , $ e -> getMessage ( ) ) ; } return $ response ; }
|
Edition cron definition
|
11,030
|
public function detect ( ) { foreach ( $ this -> detectors as $ detector ) { $ locales = ( array ) $ this -> getInstance ( $ detector ) -> detect ( ) ; foreach ( $ locales as $ locale ) { if ( $ this -> isSupportedLocale ( $ locale ) ) { return $ locale ; } } } return false ; }
|
Detect any supported locale and return the first match .
|
11,031
|
public function tables ( ) { $ schema = $ this -> db -> connection ( ) -> getDoctrineConnection ( ) -> getSchemaManager ( ) ; $ tables = $ schema -> listTableNames ( ) ; foreach ( $ tables as $ table ) { $ columns = $ this -> describer -> describe ( $ table ) ; yield compact ( 'table' , 'columns' ) ; } }
|
Return a description for each table .
|
11,032
|
public function flush ( ) { if ( $ this -> recordSize === 0 ) { return ; } $ str = '' ; foreach ( $ this -> records as $ record ) { $ str .= $ this -> recordFormat ( $ record ) ; } $ this -> clear ( ) ; $ this -> write ( $ str ) ; }
|
flush data to file .
|
11,033
|
public function getLogPath ( ) { if ( ! $ this -> basePath ) { throw new \ InvalidArgumentException ( 'The property basePath is required.' ) ; } return $ this -> getBasePath ( ) . '/' . ( $ this -> subFolder ? $ this -> subFolder . '/' : '' ) ; }
|
get log path
|
11,034
|
private function saveIncident ( $ report_xml ) { if ( ! empty ( $ report_xml ) && $ report_xml = simplexml_load_string ( $ report_xml ) ) { $ this -> feedName = 'default' ; if ( $ this -> isKnownFeed ( ) && $ this -> isEnabledFeed ( ) ) { $ report_raw = json_decode ( json_encode ( $ report_xml ) , true ) ; $ report = $ this -> applyFilters ( $ report_raw [ 'Source' ] ) ; if ( $ this -> hasRequiredFields ( $ report ) === true ) { $ incident = new Incident ( ) ; $ incident -> source = config ( "{$this->configBase}.parser.name" ) ; $ incident -> source_id = false ; $ incident -> ip = $ report [ 'IP_Address' ] ; $ incident -> domain = false ; $ incident -> class = config ( "{$this->configBase}.feeds.{$this->feedName}.class" ) ; $ incident -> type = config ( "{$this->configBase}.feeds.{$this->feedName}.type" ) ; $ incident -> timestamp = strtotime ( $ report [ 'TimeStamp' ] ) ; $ incident -> information = json_encode ( $ report_raw ) ; $ this -> incidents [ ] = $ incident ; } } } }
|
Uses the XML to create incidents
|
11,035
|
private function setPayload ( array $ parameters ) : void { $ this -> payload = [ ] ; foreach ( $ parameters as $ parameter => $ value ) { $ this -> setPayloadParameter ( $ parameter , $ value ) ; } }
|
Set payload .
|
11,036
|
public function getAuthType ( ) { if ( isset ( $ this -> auth [ 'username' ] ) && isset ( $ this -> auth [ 'password' ] ) ) { return self :: HTTP_PASSWORD ; } if ( isset ( $ this -> auth [ 'client_id' ] ) && isset ( $ this -> auth [ 'client_secret' ] ) ) { return self :: URL_SECRET ; } if ( isset ( $ this -> auth [ 'access_token' ] ) ) { return self :: URL_TOKEN ; } return - 1 ; }
|
Calculating the Authentication Type
|
11,037
|
public function httpPassword ( Event $ event ) { $ event [ 'request' ] -> setHeader ( 'Authorization' , sprintf ( 'Basic %s' , base64_encode ( $ this -> auth [ 'username' ] . ':' . $ this -> auth [ 'password' ] ) ) ) ; }
|
Basic Authorization with username and password
|
11,038
|
public function urlSecret ( Event $ event ) { $ query = $ event [ 'request' ] -> getQuery ( ) ; $ query -> set ( 'client_id' , $ this -> auth [ 'client_id' ] ) ; $ query -> set ( 'client_secret' , $ this -> auth [ 'client_secret' ] ) ; }
|
OAUTH2 Authorization with client secret
|
11,039
|
public function offsetSet ( $ offset , $ value ) { if ( is_null ( $ offset ) ) { throw new \ Exception ( 'Must supply key to modify arguments in an AssociativeArray.' ) ; } else { $ this -> _args [ $ offset ] = $ value ; } }
|
Override the offsetSet function to modify values of the wrapped array . Key is enforced .
|
11,040
|
public function Elements ( ) { $ fcvdo = new \ Nblum \ FlexibleContent \ FlexibleContentVersionedDataObject ( ) ; $ defaultStage = $ fcvdo -> getDefaultStage ( ) ; if ( isset ( $ _GET [ 'stage' ] ) && $ defaultStage == $ _GET [ 'stage' ] && \ Permission :: check ( 'CMS_ACCESS' ) ) { $ stage = $ defaultStage ; } else { $ stage = \ Nblum \ FlexibleContent \ FlexibleContentVersionedDataObject :: get_live_stage ( ) ; } $ results = \ Nblum \ FlexibleContent \ FlexibleContentVersionedDataObject :: get_by_stage ( \ ContentElement :: class , $ stage , [ 'Active' => '1' , 'ParentID' => $ this -> getField ( 'ID' ) ] , [ 'Sort' => 'ASC' ] ) ; return $ results ; }
|
creates List of all rows with content
|
11,041
|
public static function convert ( $ value , $ to , $ from ) { if ( $ from instanceof Measure === false || $ to instanceof Measure === false ) { throw new Exception ( '`from` or `to` parameter is not a Measure' ) ; } if ( $ from -> type !== $ to -> type ) { throw new Exception ( 'Measures have different types' ) ; } if ( $ from -> id == $ to -> id ) { return $ value ; } $ converterClass = isset ( static :: $ converters [ $ to -> type ] ) === true ? static :: $ converters [ $ to -> type ] : 'DevGroup\Measure\converters\DefaultMeasureTypeConverter' ; return $ converterClass :: convert ( $ value , $ to , $ from ) ; }
|
Convert a value from one measure to another
|
11,042
|
public static function format ( $ value , $ to , $ from = null ) { if ( $ to instanceof Measure === false ) { throw new Exception ( 'Unknown object' ) ; } if ( $ from instanceof Measure ) { $ value = static :: convert ( $ value , $ to , $ from ) ; } $ formatter = $ to -> use_custom_formatter == true ? $ to -> formatter : \ Yii :: $ app -> formatter ; return strtr ( $ to -> format , [ '#' => $ formatter -> asDecimal ( $ value ) , '$' => static :: t ( $ to -> unit ) , ] ) ; }
|
Format a value by rule as a string
|
11,043
|
public static function parseString ( $ source , $ matchRules ) { foreach ( ( array ) $ matchRules as $ matchRule ) { if ( is_callable ( $ matchRule ) === true ) { return call_user_func ( $ matchRule , $ source ) ; } else { if ( preg_match ( $ matchRule , $ source , $ matches ) === 1 ) { $ value = $ matches [ 'integral' ] ; if ( isset ( $ matches [ 'fractional' ] ) ) { $ value .= '.' . $ matches [ 'fractional' ] ; } return ( double ) $ value ; } } } return false ; }
|
Parse string by regexp or closure .
|
11,044
|
private function addHeadersSection ( ezcMailHeadersHolder $ headers ) { $ result = "" ; foreach ( $ headers -> getCaseSensitiveArray ( ) as $ header => $ value ) { $ result .= $ header . ": " . $ value . ezcMailTools :: lineBreak ( ) ; } return $ result ; }
|
Returns the generated text for a section of the delivery - status part .
|
11,045
|
public function createRecipient ( ) { $ result = count ( $ this -> recipients ) ; $ this -> recipients [ $ result ] = new ezcMailHeadersHolder ( ) ; return $ result ; }
|
Adds a new recipient to this delivery - status message and returns the index of the last added recipient .
|
11,046
|
public function validate ( $ cache ) { $ original = $ cache ; if ( is_callable ( $ cache ) ) { $ failed = false ; try { $ cache = $ cache ( $ this -> container ) ; } catch ( \ Exception $ e ) { $ failed = true ; $ this -> container [ 'log' ] -> warning ( 'Unable to connect to the cache backend.' ) ; } if ( ! $ failed && $ cache instanceof CacheContract ) { return $ original ; } } else { $ this -> container [ 'log' ] -> warning ( 'A cache must be configured as a closure. See the documentation for more information.' ) ; } return function ( $ app ) { return new NullCache ( ) ; } ; }
|
Validate a cache to ensure it implements the Cache Contract and that we are able to connect to the cache backend .
|
11,047
|
public function injectResponse ( ViewEvent $ e ) { $ renderer = $ e -> getRenderer ( ) ; if ( $ renderer !== $ this -> renderer ) { return ; } $ result = $ e -> getResult ( ) ; $ response = $ e -> getResponse ( ) ; $ response -> setContent ( $ result ) ; $ headers = $ response -> getHeaders ( ) ; $ headers -> addHeaderLine ( 'content-type' , 'text/xml' ) ; }
|
Inject the response with the feed payload and appropriate Content - Type header
|
11,048
|
public function getPdf ( $ id = '' ) { $ id = $ id ? : $ this -> attributes [ $ this -> primary_column ] ; return $ this -> request ( 'GET' , sprintf ( '%s/%s' , $ this -> getUrl ( ) , $ id ) , array ( ) , "" , "pdf" ) ; }
|
Retrieves a PDF file of an invoice
|
11,049
|
public function generateFiles ( $ class , $ target ) { $ files = array ( ) ; $ includes = "" ; $ registers = "" ; foreach ( $ this -> aspects as $ aspect ) { $ files [ ] = $ aspect -> getStoredFile ( ) ; $ includes .= "require_once __DIR__ . '/" . str_replace ( "'" , "\'" , $ aspect -> getRelativeFileTarget ( $ target ) ) . "';\n" ; $ registers .= ' $container->registerAspect(new ' . $ aspect -> getClassName ( ) . "());\n" ; } $ files [ ] = fphp \ File \ TemplateFile :: fromSpecification ( fphp \ Specification \ TemplateSpecification :: fromArrayAndSettings ( array ( "source" => "AspectKernel.php.template" , "target" => $ target , "rules" => array ( array ( "assign" => "class" , "to" => $ class ) , array ( "assign" => "includes" , "to" => trim ( $ includes ) ) , array ( "assign" => "registers" , "to" => trim ( $ registers ) ) ) ) , fphp \ Settings :: inDirectory ( __DIR__ ) ) ) ; return $ files ; }
|
Generates the aspect kernel s files . This includes all aspect files and the aspect kernel itself .
|
11,050
|
public function build ( $ name , Collection $ fields = null ) { $ path = $ this -> getClassFilePath ( $ name ) ; $ tableName = source_table_name ( $ name ) ; $ contents = view ( '_hierarchy::entities.model' , [ 'tableName' => $ tableName , 'name' => $ this -> getClassName ( $ name ) , 'fields' => $ this -> makeFields ( $ fields ) , 'searchableFields' => $ this -> makeSearchableFields ( $ fields , $ tableName ) , 'mutatables' => $ this -> makeMutatableFields ( $ fields ) ] ) -> render ( ) ; $ this -> write ( $ path , $ contents ) ; }
|
Builds a source model
|
11,051
|
protected function makeSearchableFields ( Collection $ fields = null , $ tableName ) { if ( is_null ( $ fields ) ) { return '' ; } $ searchables = [ ] ; foreach ( $ fields as $ field ) { if ( intval ( $ field -> search_priority ) > 0 ) { $ searchables [ ] = "'{$tableName}.{$field->name}' => {$field->search_priority}" ; } } return implode ( "," , $ searchables ) ; }
|
Makes searchable fields
|
11,052
|
protected function makeMutatableFields ( Collection $ fields = null ) { if ( is_null ( $ fields ) ) { return '' ; } $ mutatables = [ ] ; foreach ( $ fields as $ field ) { if ( in_array ( $ field -> type , [ 'document' , 'gallery' , 'markdown' , 'node' , 'node_collection' ] ) ) { $ mutatables [ ] = "'{$field->name}' => '{$field->type}'" ; } } return implode ( "," , $ mutatables ) ; }
|
Makes mutatable fields
|
11,053
|
public function run ( ) : bool { if ( $ this -> startup ) { $ this -> logger -> debug ( 'Calling startup callback' ) ; call_user_func ( $ this -> startup , $ this ) ; } $ actions = implode ( ', ' , array_keys ( $ this -> callbacks ) ) ; $ this -> logger -> info ( "Component running with callbacks for $actions" ) ; $ this -> executor -> execute ( $ this -> apiFactory , $ this -> input , $ this -> callbacks , $ this -> error ) ; if ( $ this -> shutdown ) { $ this -> logger -> debug ( 'Calling shutdown callback' ) ; call_user_func ( $ this -> shutdown , $ this ) ; } return true ; }
|
Run the SDK .
|
11,054
|
public function getFileData ( $ file = null , $ offset = null ) { if ( null === $ file ) $ file = & $ this -> file ; if ( null === $ offset ) $ offset = $ this -> file_offset ; $ this -> IO = fopen ( $ file , 'r' ) ; fseek ( $ this -> IO , $ offset ) ; try { $ this -> raw = stream_get_contents ( $ this -> IO ) ; } catch ( \ Exception $ e ) { $ this -> raw = '' ; trigger_error ( $ e -> getMessage ( ) , $ this -> e_level ) ; } return $ this -> raw ; }
|
read file from offset
|
11,055
|
static function get ( $ post_id ) { global $ db ; $ sql = "SELECT * FROM " . POSTS_TABLE . " WHERE post_id=" . intval ( $ post_id ) ; $ result = $ db -> sql_query ( $ sql ) ; $ post_data = $ db -> sql_fetchrow ( $ result ) ; $ db -> sql_freeresult ( $ result ) ; if ( ! $ post_data ) { return false ; } return post :: from_array ( $ post_data ) ; }
|
static method loads the post with a given post_id from database . returns false if the post does not exist
|
11,056
|
function get_topic ( $ all_posts = false ) { if ( ! $ this -> _topic ) { if ( $ this -> post_id ) { $ this -> _topic = topic :: get ( $ this -> topic_id , $ all_posts ) ; if ( $ all_posts ) { for ( $ i = 0 ; $ i < sizeof ( $ this -> _topic -> posts ) ; $ i ++ ) { if ( $ this -> _topic -> posts [ $ i ] -> post_id == $ this -> post_id ) { $ this -> _topic -> posts [ $ i ] = & $ this ; break ; } } } else { $ this -> _topic -> posts [ ] = & $ this ; } } else { $ this -> _topic = topic :: from_post ( $ this ) ; } } return $ this -> _topic ; }
|
loads and returns the topic for this post
|
11,057
|
function add ( $ type , $ id , $ field , $ amount = 1 ) { $ this -> init ( $ type , $ id ) ; if ( ! isset ( $ this -> data [ $ type ] [ $ id ] [ 'add' ] [ $ field ] ) ) { $ this -> data [ $ type ] [ $ id ] [ 'add' ] [ $ field ] = 0 ; } $ this -> data [ $ type ] [ $ id ] [ 'add' ] [ $ field ] += $ amount ; }
|
increments or decrements a field .
|
11,058
|
private function open_pdo_connection ( ) { try { $ this -> connection = in_array ( $ this -> dbtype , [ 'sqlite3' , 'pgsql' ] ) ? new \ PDO ( $ this -> connection_string ) : new \ PDO ( $ this -> connection_string , $ this -> dbuser , $ this -> dbpass ) ; self :: $ logger -> debug ( sprintf ( "SQL: connection opened: '%s'." , json_encode ( $ this -> verified_params ) ) ) ; } catch ( \ PDOException $ e ) { self :: $ logger -> error ( sprintf ( "SQL: connection failed: '%s'." , json_encode ( $ this -> verified_params ) ) ) ; throw new SQLError ( SQLError :: CONNECTION_ERROR , $ this -> dbtype . " connection error." ) ; } $ this -> connection -> setAttribute ( \ PDO :: ATTR_ERRMODE , \ PDO :: ERRMODE_EXCEPTION ) ; if ( $ this -> dbtype == 'sqlite3' ) $ this -> connection -> exec ( "PRAGMA foreign_keys=ON" ) ; }
|
Open PDO connection .
|
11,059
|
private function format_connection_string ( ) { if ( ! in_array ( $ this -> dbtype , [ 'sqlite3' , 'mysql' , 'pgsql' ] ) ) { $ this -> verified_params = null ; self :: $ logger -> error ( sprintf ( "SQL: database not supported: '%s'." , $ this -> dbtype ) ) ; throw new SQLError ( SQLError :: DBTYPE_ERROR , $ this -> dbtype . " not supported." ) ; } if ( $ this -> dbtype == 'sqlite3' ) return $ this -> connection_string = 'sqlite:' . $ this -> dbname ; if ( ! $ this -> dbuser ) { $ this -> verified_params = null ; self :: $ logger -> error ( "SQL: param not supplied: 'dbuser'." ) ; throw new SQLError ( SQLError :: CONNECTION_ARGS_ERROR , "'dbuser' not supplied." ) ; } $ cstr = sprintf ( "%s:dbname=%s" , $ this -> dbtype , $ this -> dbname ) ; if ( $ this -> dbhost ) { $ cstr .= sprintf ( ';host=%s' , $ this -> dbhost ) ; if ( $ this -> dbport ) $ cstr .= sprintf ( ';port=%s' , $ this -> dbport ) ; } if ( $ this -> dbtype == 'mysql' ) return $ this -> connection_string = $ cstr ; $ cstr .= sprintf ( ";user=%s" , $ this -> dbuser ) ; if ( $ this -> dbpass ) $ cstr .= sprintf ( ";password=%s" , $ this -> dbpass ) ; return $ this -> connection_string = $ cstr ; }
|
Verify and format connection string .
|
11,060
|
final public function time ( ) { if ( $ this -> dbtype == 'pgsql' ) return $ this -> query ( "SELECT EXTRACT('epoch' from CURRENT_TIMESTAMP) AS now" ) [ 'now' ] ; if ( $ this -> dbtype == 'mysql' ) return $ this -> query ( "SELECT UNIX_TIMESTAMP() AS now" ) [ 'now' ] ; return $ this -> query ( "SELECT strftime('%s', CURRENT_TIMESTAMP) AS now" ) [ 'now' ] ; }
|
Get Unix timestamp from database server .
|
11,061
|
private function stmt_fragment_datetime ( $ delta ) { $ sign = $ delta >= 0 ? '+' : '-' ; $ delta = abs ( $ delta ) ; $ date = '' ; switch ( $ this -> dbtype ) { case 'sqlite3' : $ date = "(datetime('now', '%s%s second'))" ; break ; case 'pgsql' : $ date = ( "(" . "now() at time zone 'utc' %s " . "interval '%s second'" . ")::timestamp(0)" ) ; break ; case 'mysql' : $ date = ( "(date_add(utc_timestamp(), interval %s%s second))" ) ; break ; } return sprintf ( $ date , $ sign , $ delta ) ; }
|
SQL datetime fragment .
|
11,062
|
public function stmt_fragment ( $ part , $ args = [ ] ) { $ type = $ this -> dbtype ; if ( $ part == 'engine' ) { if ( $ type == 'mysql' ) return "ENGINE=InnoDB" ; return '' ; } if ( $ part == "index" ) { if ( $ type == 'pgsql' ) return 'SERIAL PRIMARY KEY' ; if ( $ type == 'mysql' ) return 'INTEGER PRIMARY KEY AUTO_INCREMENT' ; return 'INTEGER PRIMARY KEY AUTOINCREMENT' ; } if ( $ part == 'datetime' ) { $ delta = 0 ; if ( $ args && isset ( $ args [ 'delta' ] ) ) $ delta = ( int ) $ args [ 'delta' ] ; return $ this -> stmt_fragment_datetime ( $ delta ) ; } return "" ; }
|
SQL statement fragment .
|
11,063
|
public function table_exists ( $ table ) { if ( ! preg_match ( '!^[0-9a-z_]+$!i' , $ table ) ) return false ; self :: $ logger -> deactivate ( ) ; try { $ this -> query ( sprintf ( "SELECT 1 FROM %s LIMIT 1" , $ table ) ) ; self :: $ logger -> activate ( ) ; return true ; } catch ( SQLError $ e ) { self :: $ logger -> activate ( ) ; return false ; } }
|
Check if a table or view exists .
|
11,064
|
private function prepare_statement ( $ stmt , $ args = [ ] ) { if ( ! $ this -> connection ) { self :: $ logger -> error ( sprintf ( "SQL: connection failed: '%s'." , json_encode ( $ this -> verified_params ) ) ) ; throw new SQLError ( SQLError :: CONNECTION_ERROR , $ this -> dbtype . " connection error." ) ; } $ conn = $ this -> connection ; try { $ pstmt = $ conn -> prepare ( $ stmt ) ; } catch ( \ PDOException $ e ) { self :: $ logger -> error ( sprintf ( "SQL: execution failed: %s <- '%s': %s." , $ stmt , json_encode ( $ args ) , $ e -> getMessage ( ) ) ) ; throw new SQLError ( SQLError :: EXECUTION_ERROR , sprintf ( "Execution error: %s." , $ e -> getMessage ( ) ) , $ stmt , $ args ) ; } try { $ pstmt -> execute ( array_values ( $ args ) ) ; } catch ( \ PDOException $ e ) { self :: $ logger -> error ( sprintf ( "SQL: execution failed: %s <- '%s': %s." , $ stmt , json_encode ( $ args ) , $ e -> getMessage ( ) ) ) ; throw new SQLError ( SQLError :: EXECUTION_ERROR , sprintf ( "Execution error: %s." , $ e -> getMessage ( ) ) , $ stmt , $ args ) ; } return $ pstmt ; }
|
Prepare and execute statement .
|
11,065
|
final public function query_raw ( $ stmt , $ args = [ ] ) { $ pstmt = $ this -> prepare_statement ( $ stmt , $ args ) ; self :: $ logger -> info ( sprintf ( "SQL: query raw ok: %s." , $ stmt ) ) ; return $ pstmt ; }
|
Execute raw query .
|
11,066
|
final public function insert ( $ table , $ args = [ ] , $ pk = null ) { $ keys = $ vals = [ ] ; $ keys = array_keys ( $ args ) ; $ vals = array_fill ( 0 , count ( $ args ) , '?' ) ; $ columns = implode ( ',' , $ keys ) ; $ placeholders = implode ( ',' , $ vals ) ; $ stmt = "INSERT INTO $table ($columns) VALUES ($placeholders)" ; if ( $ this -> dbtype == 'pgsql' ) $ stmt .= " RETURNING " . ( $ pk ? $ pk : '*' ) ; $ pstmt = $ this -> prepare_statement ( $ stmt , $ args ) ; if ( $ this -> dbtype == 'pgsql' ) { $ last = $ pstmt -> fetch ( \ PDO :: FETCH_ASSOC ) ; $ ret = $ pk ? $ last [ $ pk ] : $ last ; } else { $ ret = $ this -> connection -> lastInsertId ( ) ; } self :: $ logger -> info ( sprintf ( "SQL: insert ok: %s <- '%s'." , $ stmt , json_encode ( $ args ) ) ) ; return $ ret ; }
|
Insert statement .
|
11,067
|
public function registerStandardObjects ( ) { $ this -> extensionMap = new ExtensionMap ( ) ; $ this -> extensions = $ this -> extensionMap -> getRegisteredExtensionNames ( ) ; $ this -> finder -> files ( ) ; }
|
Registers the extension map and sets the finder to look for files
|
11,068
|
public function filterByExtension ( ) { $ filter = function ( \ SplFileInfo $ file ) { return in_array ( $ file -> getExtension ( ) , $ this -> extensions ) ; } ; $ this -> filter ( $ filter ) ; }
|
Filters file results by their extension
|
11,069
|
public function fetch ( ) { $ this -> filterByExtension ( ) ; $ results = Array ( ) ; foreach ( $ this -> finder as $ file ) { $ config = new ConfigFile ( $ this -> fs , $ this -> fileInfo , $ this -> extracter ) ; $ config -> load ( $ file -> getRealPath ( ) ) ; $ results [ ] = $ config ; } $ this -> finder = new Finder ( ) ; return new CollectionResults ( $ results ) ; }
|
Fetches results of current instance of the finder
|
11,070
|
public function setDirectory ( $ directory ) { $ this -> directory = $ directory ; $ this -> finder -> in ( $ directory ) ; return $ this ; }
|
Sets the directory value
|
11,071
|
protected function _update ( & $ Schema , $ table = null ) { $ db = ConnectionManager :: getDataSource ( $ this -> Schema -> connection ) ; $ this -> out ( __d ( 'cake_console' , 'Comparing Database to Schema...' ) ) ; $ options = array ( ) ; $ this -> params [ 'force' ] = false ; if ( isset ( $ this -> params [ 'force' ] ) ) { $ options [ 'models' ] = false ; } $ Old = $ this -> Schema -> read ( $ options ) ; $ compare = $ this -> Schema -> compare ( $ Old , $ Schema ) ; $ contents = array ( ) ; if ( ! empty ( $ compare [ 'media' ] ) ) { unset ( $ compare [ 'media' ] ) ; } if ( empty ( $ table ) ) { foreach ( $ compare as $ table => $ changes ) { if ( isset ( $ compare [ $ table ] [ 'create' ] ) ) { $ contents [ $ table ] = $ db -> createSchema ( $ Schema , $ table ) ; } else { $ contents [ $ table ] = $ db -> alterSchema ( array ( $ table => $ compare [ $ table ] ) , $ table ) ; } } } elseif ( isset ( $ compare [ $ table ] ) ) { if ( isset ( $ compare [ $ table ] [ 'create' ] ) ) { $ contents [ $ table ] = $ db -> createSchema ( $ Schema , $ table ) ; } else { $ contents [ $ table ] = $ db -> alterSchema ( array ( $ table => $ compare [ $ table ] ) , $ table ) ; } } if ( empty ( $ contents ) ) { $ this -> out ( __d ( 'cake_console' , 'Schema is up to date.' ) ) ; return false ; } $ this -> out ( "\n" . __d ( 'cake_console' , 'The following statements will run.' ) ) ; $ this -> out ( array_map ( 'trim' , $ contents ) ) ; if ( ! empty ( $ this -> params [ 'yes' ] ) || $ this -> in ( __d ( 'cake_console' , 'Are you sure you want to alter the tables?' ) , array ( 'y' , 'n' ) , 'n' ) === 'y' ) { $ this -> out ( ) ; $ this -> out ( __d ( 'cake_console' , 'Updating Database...' ) ) ; $ this -> _run ( $ contents , 'update' , $ Schema ) ; } $ this -> out ( __d ( 'cake_console' , 'End update.' ) ) ; }
|
Update database with Schema object Should be called via the run method
|
11,072
|
public function createPidfile ( $ appName , $ path = '/var/run' ) { if ( ! $ this -> control ) { $ this -> createControl ( ) ; } return new Pidfile ( $ this -> control , strtolower ( $ appName ) , $ path ) ; }
|
Create Pid file for process
|
11,073
|
protected function replaces ( PackageInterface $ source , PackageInterface $ target ) { foreach ( $ source -> getReplaces ( ) as $ link ) { if ( $ link -> getTarget ( ) === $ target -> getName ( ) ) { return true ; } } return false ; }
|
Checks if source replaces a package with the same name as target .
|
11,074
|
final public static function className ( string $ fullName = null ) : string { $ fullName = $ fullName ? : self :: fullName ( ) ; $ fullName = str_replace ( '\\' , '/' , $ fullName ) ; return basename ( $ fullName ) ; }
|
get called class name
|
11,075
|
public static function resolve ( $ name , $ callable ) { $ invokable = Resolver :: of ( $ callable ) ; $ annotations = $ invokable -> annotations ( ) ; $ annotations [ 'method' ] = $ invokable ; return new Logic ( $ name , $ annotations ) ; }
|
Resolve logic from callable
|
11,076
|
public function bitXor ( $ value1 , $ value2 ) { $ value1 = $ this -> getIdentifier ( $ value1 ) ; $ value2 = $ this -> getIdentifier ( $ value2 ) ; return "( {$value1} + {$value2} - bitand( {$value1}, {$value2} ) * 2 )" ; }
|
Returns the SQL that performs the bitwise XOR on two values .
|
11,077
|
public function unixTimestamp ( $ column ) { $ column = $ this -> getIdentifier ( $ column ) ; if ( $ column != 'NOW()' ) { $ column = "CAST( {$column} AS TIMESTAMP )" ; } $ date1 = "CAST( SYS_EXTRACT_UTC( {$column} ) AS DATE )" ; $ date2 = "TO_DATE( '19700101000000', 'YYYYMMDDHH24MISS' )" ; return " ROUND( ( {$date1} - {$date2} ) / ( 1 / 86400 ) ) " ; }
|
Returns the SQL that converts a timestamp value to a unix timestamp .
|
11,078
|
public function dateSub ( $ column , $ expr , $ type ) { $ type = $ this -> intervalMap [ $ type ] ; $ column = $ this -> getIdentifier ( $ column ) ; if ( $ column != 'NOW()' ) { $ column = "CAST( {$column} AS TIMESTAMP )" ; } return " {$column} - INTERVAL '{$expr}' {$type} " ; }
|
Returns the SQL that subtracts an interval from a timestamp value .
|
11,079
|
public function dateAdd ( $ column , $ expr , $ type ) { $ type = $ this -> intervalMap [ $ type ] ; $ column = $ this -> getIdentifier ( $ column ) ; if ( $ column != 'NOW()' ) { $ column = "CAST( {$column} AS TIMESTAMP )" ; } return " {$column} + INTERVAL '{$expr}' {$type} " ; }
|
Returns the SQL that adds an interval to a timestamp value .
|
11,080
|
public function in ( $ column ) { $ args = func_get_args ( ) ; if ( count ( $ args ) < 2 ) { throw new ezcQueryVariableParameterException ( 'in' , count ( $ args ) , 2 ) ; } if ( is_array ( $ args [ 1 ] ) && count ( $ args [ 1 ] ) == 0 ) { throw new ezcQueryInvalidParameterException ( 'in' , 2 , 'empty array' , 'non-empty array' ) ; } $ values = ezcQuerySelect :: arrayFlatten ( array_slice ( $ args , 1 ) ) ; $ values = $ this -> getIdentifiers ( $ values ) ; $ column = $ this -> getIdentifier ( $ column ) ; if ( count ( $ values ) == 0 ) { throw new ezcQueryVariableParameterException ( 'in' , count ( $ args ) , 2 ) ; } if ( $ this -> quoteValues ) { foreach ( $ values as $ key => $ value ) { switch ( true ) { case is_int ( $ value ) : case is_float ( $ value ) : case $ value instanceof ezcQuerySubSelect : $ values [ $ key ] = ( string ) $ value ; break ; default : $ values [ $ key ] = $ this -> db -> quote ( $ value ) ; } } } if ( count ( $ values ) <= 1000 ) { return "{$column} IN ( " . join ( ', ' , $ values ) . ' )' ; } else { $ expression = '( ' ; do { $ bunch = array_slice ( $ values , 0 , 1000 ) ; $ values = array_slice ( $ values , 1000 ) ; $ expression .= "{$column} IN ( " . join ( ', ' , $ bunch ) . ' ) OR ' ; } while ( count ( $ values ) > 1000 ) ; $ expression .= "{$column} IN ( " . join ( ', ' , $ values ) . ' ) )' ; return $ expression ; } }
|
Returns the SQL to check if a value is one in a set of given values .
|
11,081
|
protected function mergeComposerJsonFiles ( string $ composer_file , \ stdClass $ original_composer , \ stdClass $ new_composer , callable $ callback = NULL ) { $ new_composer = $ this -> mergeComposerObjects ( $ original_composer , $ new_composer , $ callback ) ; $ composer_content = file_get_contents ( $ composer_file ) ; $ replace_composer = json_decode ( $ composer_content ) ; $ changes = $ this -> calculateRequirementChanges ( $ replace_composer , $ new_composer ) ; if ( file_put_contents ( $ composer_file , json_encode ( $ new_composer , JSON_PRETTY_PRINT ) ) !== FALSE ) { return $ changes ; } }
|
Merges the original composer file with a new composer file .
|
11,082
|
protected function mergeComposerObjects ( \ stdClass $ original_composer , \ stdClass $ new_composer , callable $ callback = NULL ) { foreach ( $ original_composer as $ key => $ values ) { $ is_array = is_array ( $ values ) ; $ values = ( array ) $ values ; if ( isset ( $ new_composer -> { $ key } ) ) { $ value = ( array ) $ new_composer -> { $ key } ; $ values = array_merge ( $ value , $ values ) ; } $ new_composer -> { $ key } = $ is_array ? $ values : ( object ) $ values ; } if ( $ callback ) { call_user_func ( $ callback , $ new_composer ) ; } return $ new_composer ; }
|
Merges two composer objects into one .
|
11,083
|
protected function calculateRequirementChanges ( $ replace_composer , $ new_composer ) { $ changes = [ 'install' => [ ] , 'update' => [ ] , 'remove' => [ ] , ] ; foreach ( [ 'require' , 'require-dev' ] as $ key ) { $ old_requirements = ! empty ( $ replace_composer -> { $ key } ) ? $ replace_composer -> { $ key } : [ ] ; $ new_requirements = ! empty ( $ new_composer -> { $ key } ) ? $ new_composer -> { $ key } : [ ] ; foreach ( $ new_requirements as $ requirement => $ version ) { if ( empty ( $ old_requirements -> { $ requirement } ) ) { $ changes [ 'install' ] [ $ requirement ] = $ version ; } if ( ( ! empty ( $ old_requirements -> { $ requirement } ) && Comparator :: greaterThan ( $ version , $ old_requirements -> { $ requirement } ) ) ) { $ changes [ 'update' ] [ $ requirement ] = $ version ; } } foreach ( $ old_requirements as $ requirement => $ version ) { if ( empty ( $ new_requirements -> { $ requirement } ) ) { $ changes [ 'remove' ] [ ] = $ requirement ; } } } return $ changes ; }
|
Calculated requirements that need to be removed from the system .
|
11,084
|
public function toXhtml ( \ DOMDocument $ document , \ DOMElement $ root ) { $ content = '' ; $ caption = '' ; foreach ( $ this -> node -> nodes as $ node ) { $ content .= $ node -> token -> content ; } $ matches = array ( ) ; if ( preg_match ( '/([^<]*)<?([^>]*)>?/' , $ content , $ matches ) ) { if ( isset ( $ matches [ 2 ] ) && $ matches [ 2 ] ) { $ content = $ matches [ 2 ] ; $ caption = trim ( $ matches [ 1 ] ) ; } } if ( ! $ caption && $ this -> visitor ) { $ toc = $ this -> visitor -> getTableOfContents ( ) ; $ caption = isset ( $ toc [ $ content ] ) ? $ toc [ $ content ] -> getName ( ) : '' ; } if ( ! $ caption ) { $ caption = str_replace ( array ( '-' , '_' ) , ' ' , ucfirst ( ltrim ( substr ( htmlspecialchars ( $ content ) , strrpos ( $ content , '/' ) ) , '\\/' ) ) ) ; } $ link = $ document -> createElement ( 'a' , $ caption ) ; $ root -> appendChild ( $ link ) ; $ link -> setAttribute ( 'href' , str_replace ( '\\' , '/' , $ content ) . '.html' ) ; }
|
Transform text role to HTML .
|
11,085
|
public function _getParams ( $ key = - 1 ) { if ( $ key >= 0 ) { if ( isset ( self :: $ params [ $ key ] ) ) { return self :: $ params [ $ key ] ; } else { return NULL ; } } else { return self :: $ params ; } }
|
get Route Paramenters
|
11,086
|
public function setParams ( $ key , $ value = '' ) { if ( is_array ( $ key ) ) { self :: $ RealParams = $ key ; } else { self :: $ RealParams [ $ key ] = $ value ; } }
|
Set route paramters
|
11,087
|
public function isPut ( ) { if ( isset ( $ _SERVER [ 'REQUEST_METHOD' ] ) ) { if ( $ _SERVER [ 'REQUEST_METHOD' ] == 'PUT' || ( isset ( $ _POST [ '_METHOD' ] ) && $ _POST [ '_METHOD' ] == 'PUT' ) ) { parse_str ( file_get_contents ( "php://input" ) , $ vars ) ; if ( isset ( $ vars [ '_METHOD' ] ) ) { unset ( $ vars [ '_METHOD' ] ) ; } $ GLOBALS [ '_PUT' ] = $ _PUT = $ vars ; return TRUE ; } else { return FALSE ; } } else { return FALSE ; } }
|
Check request of Put method
|
11,088
|
public function isDelete ( ) { if ( isset ( $ _SERVER [ 'REQUEST_METHOD' ] ) ) { if ( $ _SERVER [ 'REQUEST_METHOD' ] == 'DELETE' || ( isset ( $ _POST [ '_METHOD' ] ) && $ _POST [ '_METHOD' ] == 'DELETE' ) ) { parse_str ( file_get_contents ( "php://input" ) , $ vars ) ; if ( isset ( $ vars [ '_METHOD' ] ) ) { unset ( $ vars [ '_METHOD' ] ) ; } $ GLOBALS [ '_DELETE' ] = $ _DELETE = $ vars ; return TRUE ; } else { return FALSE ; } } else { return FALSE ; } }
|
Check request of delete method
|
11,089
|
public function isPatch ( ) { if ( isset ( $ _SERVER [ 'REQUEST_METHOD' ] ) ) { if ( $ _SERVER [ 'REQUEST_METHOD' ] == 'PATCH' || ( isset ( $ _POST [ '_METHOD' ] ) && $ _POST [ '_METHOD' ] == 'PATCH' ) ) { parse_str ( file_get_contents ( "php://input" ) , $ vars ) ; if ( isset ( $ vars [ '_METHOD' ] ) ) { unset ( $ vars [ '_METHOD' ] ) ; } $ GLOBALS [ '_PATCH' ] = $ _PATCH = $ vars ; return TRUE ; } else { return FALSE ; } } else { return FALSE ; } }
|
Check request of Patch method
|
11,090
|
public function isOptions ( ) { if ( isset ( $ _SERVER [ 'REQUEST_METHOD' ] ) ) { if ( $ _SERVER [ 'REQUEST_METHOD' ] == 'OPTIONS' || ( isset ( $ _POST [ '_METHOD' ] ) && $ _POST [ '_METHOD' ] == 'OPTIONS' ) ) { parse_str ( file_get_contents ( "php://input" ) , $ vars ) ; if ( isset ( $ vars [ '_METHOD' ] ) ) { unset ( $ vars [ '_METHOD' ] ) ; } $ GLOBALS [ '_OPTIONS' ] = $ _OPTIONS = $ vars ; return TRUE ; } else { return FALSE ; } } else { return FALSE ; } }
|
Check request of Options method
|
11,091
|
public function transform ( $ block ) { $ block = $ this -> entityToArray ( Block :: class , $ block ) ; return [ 'id' => $ this -> setNullableValue ( $ block [ 'id' ] ) , 'type' => $ block [ 'type' ] , 'region' => $ block [ 'region' ] , 'filter' => $ block [ 'filter' ] , 'options' => $ block [ 'options' ] , 'theme' => $ block [ 'theme' ] , 'weight' => ( int ) $ block [ 'weight' ] , 'isActive' => ( bool ) $ block [ 'is_active' ] , 'isCacheable' => ( bool ) $ block [ 'is_cacheable' ] , 'createdAt' => $ block [ 'created_at' ] , 'updatedAt' => $ block [ 'updated_at' ] ] ; }
|
Transforms block entity
|
11,092
|
public function add_js ( $ js ) { $ current = $ this -> dwoo_data -> js_files ; $ current [ ] = $ js ; $ this -> dwoo_data -> js_files = $ current ; }
|
Add Javascript files to template
|
11,093
|
public function add_css ( $ css ) { $ current = $ this -> dwoo_data -> css_files ; $ current [ ] = $ css ; $ this -> dwoo_data -> css_files = $ current ; }
|
Add Css stylesheets to template
|
11,094
|
public function display ( $ sTemplate , $ return = FALSE ) { $ CI = get_instance ( ) ; $ CI -> benchmark -> mark ( 'dwoo_parse_start' ) ; if ( ! file_exists ( $ this -> template_dir . $ sTemplate ) ) { $ message = sprintf ( 'Template file \'%s\' not found.' , $ sTemplate ) ; show_error ( $ message ) ; log_message ( 'error' , $ message ) ; } $ tpl = new Dwoo_Template_File ( $ this -> template_dir . $ sTemplate ) ; $ template = $ this -> get ( $ tpl , $ this -> dwoo_data ) ; $ CI -> benchmark -> mark ( 'dwoo_parse_end' ) ; if ( $ return == FALSE ) { $ CI -> output -> final_output = $ template ; } else { return $ template ; } }
|
Display or return the compiled template Since we assign the results to the standard CI output module you can also use the helper from CI in your templates!!
|
11,095
|
private function initialize ( ) { $ CI = get_instance ( ) ; $ CI -> config -> load ( 'dwootemplate' , TRUE ) ; $ config = $ CI -> config -> item ( 'dwootemplate' ) ; foreach ( $ config as $ key => $ val ) { $ this -> $ key = $ val ; } }
|
Assign the dwootemplate config items to the instance
|
11,096
|
public function getModelAdminSearchContext ( ) { return SearchContext :: create ( get_class ( $ this -> getOwner ( ) ) , $ this -> getOwner ( ) -> scaffoldSearchFields ( ) , $ this -> getOwner ( ) -> defaultSearchFilters ( ) ) ; }
|
Get a custom search context for model admin plus
|
11,097
|
public function combine ( $ another ) { if ( is_a ( $ another , DC_DataHolder :: getKlass ( ) ) ) { if ( empty ( $ this -> identifier ) ) { debug_message ( "DC_DataHolder::identifier should not be empty!!" ) ; $ this -> identifier = $ another -> identifier ; } elseif ( strcmp ( substr ( $ this -> identifier , - strlen ( $ another -> identifier ) ) , $ another -> identifier ) !== 0 ) { debug_var_dump ( 'comparison' , strcmp ( substr ( $ this -> identifier , - strlen ( $ another -> identifier ) ) , $ another -> identifier ) ) ; error_log ( "found a different identifier for this element " . $ this -> identifier . " != " . $ another -> identifier ) ; return ; } $ this -> addElement ( 'contributor' , $ another ) ; $ this -> addElement ( 'coverage' , $ another ) ; $ this -> addElement ( 'creator' , $ another ) ; $ this -> addElement ( 'date_' , $ another ) ; $ this -> addElement ( 'description' , $ another ) ; $ this -> addElement ( 'format_' , $ another ) ; $ this -> addElement ( 'language' , $ another ) ; $ this -> addElement ( 'publisher' , $ another ) ; $ this -> addElement ( 'relation' , $ another ) ; $ this -> addElement ( 'rights' , $ another ) ; $ this -> addElement ( 'source' , $ another ) ; $ this -> addElement ( 'subject' , $ another ) ; $ this -> addElement ( 'title' , $ another ) ; $ this -> addElement ( 'type_' , $ another ) ; } }
|
Combines this object with another DC_DataHolder object
|
11,098
|
private function generateThumbs ( $ episode , $ cache_asset ) { $ uri = $ this -> asset_helper -> getAbsoluteUrl ( $ episode -> getVideo ( ) ) ; $ path = $ this -> asset_helper -> getPath ( $ cache_asset , true ) ; $ cmd = sprintf ( "ffmpeg -i %s -s %sx%s -vf fps=1/%s %s 2>&1" , $ uri , $ this -> sprite_width , $ this -> sprite_height , $ this -> sprite_interval , $ path ) ; $ fp = popen ( $ cmd , "r" ) ; while ( ! feof ( $ fp ) ) { $ chunk = fread ( $ fp , 1024 ) ; if ( ! $ episode -> getDuration ( ) ) { preg_match ( "/Duration: (.*?), start:/" , $ chunk , $ matches ) ; if ( array_key_exists ( 1 , $ matches ) ) { list ( $ hours , $ minutes , $ seconds ) = explode ( ":" , $ matches [ 1 ] ) ; $ episode -> setDuration ( ( ( $ hours * 3600 ) + ( $ minutes * 60 ) + $ seconds ) ) ; } } flush ( ) ; } fclose ( $ fp ) ; }
|
takes episode and creates thumbnails in given width and height
|
11,099
|
public function removeBehaviour ( BehaviourAbstract $ behaviour ) { foreach ( $ this -> behaviours as $ key => $ thisBehaviour ) { if ( $ behaviour == $ thisBehaviour ) { unset ( $ this -> behaviours [ $ key ] ) ; } } }
|
Removes a behaviour from the collection
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.