idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
14,900
public function downgrade ( ) { $ template = $ this -> getTemplate ( $ this -> getTemplateName ( ) ) ; $ fieldgroup = $ template -> fieldgroup ; $ fg = $ this -> wire ( 'fieldgroups' ) -> get ( $ template -> name ) ; $ minNumberToError = $ fg -> id == $ fieldgroup -> id ? 2 : 1 ; if ( $ fg -> numTemplates ( ) >= $ minNumberToError ) throw new WireException ( "Cannot delete $template->name, because it's fieldgroup is used by at least one other template." ) ; $ selector = "template=$template, include=all, check_access=0" ; $ this -> eachPageUncache ( $ selector , function ( $ p ) { $ this -> pages -> delete ( $ p , true ) ; } ) ; $ this -> templates -> delete ( $ template ) ; $ this -> fieldgroups -> delete ( $ fieldgroup ) ; }
Delete the template Does delete all pages of that template and does even delete system templates
14,901
public function loadDescendantProductGroupIDListInto ( & $ idList ) { if ( $ children = $ this -> AllChildren ( ) ) { foreach ( $ children as $ child ) { if ( in_array ( $ child -> ID , $ idList ) ) { continue ; } if ( $ child instanceof self ) { $ idList [ ] = $ child -> ID ; $ child -> loadDescendantProductGroupIDListInto ( $ idList ) ; } } } }
loadDescendantProductGroupIDListInto function .
14,902
public function modify ( $ customerId , $ username , $ name , $ company , $ address , $ city , $ state , $ country , $ zipCode , $ phoneCC , $ phone , $ lang ) { return $ this -> post ( 'modify' , [ 'customer-id' => $ customerId , 'username' => $ username , 'name' => $ name , 'company' => $ company , 'address-line-1' => $ address , 'city' => $ city , 'state' => $ state , 'country' => $ country , 'zipcode' => $ zipCode , 'phone-cc' => $ phoneCC , 'phone' => $ phone , 'lang-pref' => $ lang , ] ) ; }
Modifies the Account details of the specified Customer .
14,903
public function signup ( $ username , $ passwd , $ name , $ company , $ address , $ city , $ state , $ country , $ zipCode , $ phoneCC , $ phone , $ lang ) { return $ this -> post ( 'signup' , [ 'username' => $ username , 'passwd' => $ passwd , 'name' => $ name , 'company' => $ company , 'address-line-1' => $ address , 'city' => $ city , 'state' => $ state , 'country' => $ country , 'zipcode' => $ zipCode , 'phone-cc' => $ phoneCC , 'phone' => $ phone , 'lang-pref' => $ lang , ] ) ; }
Creates a Customer Account using the details provided .
14,904
public function setConfig ( $ config_location = NULL ) { static $ CAPTCHA_CONFIG = array ( ) ; $ path = ( NULL === $ config_location ) ? __DIR__ . DIRECTORY_SEPARATOR . 'captcha_config.php' : realpath ( $ config_location ) ; if ( false === $ path ) { throw new CaptchaException ( sprintf ( "Config File not found in: %s " , $ config_location ) ) ; } if ( $ path ) { include_once $ path ; foreach ( get_class_vars ( get_class ( $ this ) ) as $ key => $ value ) { $ config = preg_replace ( '/^[\_A-Z]/' , '\\1' , $ key ) ; if ( array_key_exists ( $ config , $ CAPTCHA_CONFIG ) ) { $ this -> $ key = $ CAPTCHA_CONFIG [ $ config ] ; } } } }
Set global reCAPTCHA options by loading an external config file these options can be set for all instances of reCAPTCHA in your app this avoid to set options private and public Keys all the time individualy within your forms that has a Captcha widget .
14,905
public function displayHTML ( $ theme_name = NULL , $ options = array ( ) ) { if ( strlen ( $ this -> _publicKey == 0 ) ) { throw new CaptchaException ( 'To use reCAPTCHA you must get a Public API key from https://www.google.com/recaptcha/admin' ) ; } $ captcha_snippet = $ this -> _theme ( $ theme_name , $ options ) ; $ captcha_snippet .= '<script type="text/javascript" src="' . $ this -> _buildServerURI ( ) . '"></script> <noscript> <iframe src="' . $ this -> _buildServerURI ( 'noscript' ) . '" height="300" width="500" frameborder="0"></iframe><br> <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea> <input type="hidden" name="recaptcha_response_field" value="manual_challenge"> </noscript>' ; return $ captcha_snippet ; }
Create embedded widget script HTML called within a form
14,906
public function isValid ( ) { if ( strtoupper ( $ _SERVER [ 'REQUEST_METHOD' ] ) !== 'POST' ) { return FALSE ; } else { $ captchaChallenge = isset ( $ _POST [ 'recaptcha_challenge_field' ] ) ? $ this -> _sanitizeField ( $ _POST [ 'recaptcha_challenge_field' ] ) : NULL ; $ captchaResponse = isset ( $ _POST [ 'recaptcha_response_field' ] ) ? $ this -> _sanitizeField ( $ _POST [ 'recaptcha_response_field' ] ) : NULL ; if ( strlen ( $ captchaChallenge ) == 0 || strlen ( $ captchaResponse ) == 0 ) { $ this -> setError ( 'incorrect-captcha-sol' ) ; return FALSE ; } $ data = array ( 'privatekey' => $ this -> _privateKey , 'remoteip' => $ this -> _remoteIp ( ) , 'challenge' => $ captchaChallenge , 'response' => $ captchaResponse ) ; $ result = $ this -> _postHttpChallenge ( $ data ) ; if ( $ result [ 'isvalid' ] === "true" ) { return TRUE ; } else { $ this -> setError ( $ result [ 'error' ] ) ; } return FALSE ; } }
Verifying reCAPTCHA User s Answer resolves response challenge return TRUE if the answer matches
14,907
protected function _postHttpChallenge ( array $ data ) { if ( strlen ( $ this -> _privateKey ) == 0 ) { throw new CaptchaException ( 'To use reCAPTCHA you must get a Private API key from https://www.google.com/recaptcha/admin' ) ; } $ responseHeader = '' ; $ result = array ( 'isvalid' => 'false' , 'error' => '' ) ; $ remote_url = parse_url ( self :: RECAPTCHA_VERIFY_SERVER ) ; $ httpQuery = http_build_query ( $ data ) ; $ requestHeader = sprintf ( self :: RECAPTCHA_HEADER , $ remote_url [ 'path' ] , $ remote_url [ 'host' ] , strlen ( $ httpQuery ) , $ httpQuery ) ; if ( function_exists ( 'fsockopen' ) ) { $ handler = @ fsockopen ( $ remote_url [ 'host' ] , 80 , $ errno , $ errstr , $ this -> timeout ) ; if ( false == ( $ handler ) ) { throw new CaptchaException ( sprintf ( 'Could not open sock to check reCAPTCHA at %s.' , self :: RECAPTCHA_VERIFY_SERVER ) ) ; } stream_set_timeout ( $ handler , $ this -> timeout ) ; fwrite ( $ handler , $ requestHeader ) ; $ remote_response = stream_get_line ( $ handler , 32 , "\n" ) ; if ( strpos ( $ remote_response , '200 OK' ) !== false ) { while ( ! feof ( $ handler ) ) { $ responseHeader .= stream_get_line ( $ handler , 356 ) ; } fclose ( $ handler ) ; $ responseHeader = str_replace ( "\r\n" , "\n" , $ responseHeader ) ; $ responseHeader = explode ( "\n\n" , $ responseHeader ) ; array_shift ( $ responseHeader ) ; $ responseHeader = explode ( "\n" , implode ( "\n\n" , $ responseHeader ) ) ; } } elseif ( extension_loaded ( 'curl' ) ) { $ ch = curl_init ( self :: RECAPTCHA_VERIFY_SERVER ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , true ) ; curl_setopt ( $ ch , CURLOPT_CONNECTTIMEOUT , $ this -> timeout ) ; curl_setopt ( $ ch , CURLOPT_USERAGENT , 'reCAPTCHA/PHP' ) ; curl_setopt ( $ ch , CURLOPT_HTTPHEADER , explode ( "\r\n" , $ requestHeader ) ) ; curl_setopt ( $ ch , CURLOPT_HEADER , false ) ; curl_setopt ( $ ch , CURLOPT_POST , true ) ; curl_setopt ( $ ch , CURLOPT_POSTFIELDS , $ httpQuery ) ; $ responseHeader = curl_exec ( $ ch ) ; curl_close ( $ ch ) ; if ( $ responseHeader !== false ) { $ responseHeader = explode ( "\n\n" , $ responseHeader ) ; $ responseHeader = explode ( "\n" , implode ( "\n\n" , $ responseHeader ) ) ; } } else { throw new CaptchaException ( sprintf ( 'Can\'t connect to the server %s. Try again.' , self :: RECAPTCHA_VERIFY_SERVER ) ) ; } $ result = ( count ( $ responseHeader ) == 2 ) ? array_combine ( array_keys ( $ result ) , $ responseHeader ) : $ result ; return $ result ; }
reCAPTCHA API Request
14,908
private function _buildServerURI ( $ path = 'challenge' ) { $ uri = ( TRUE === $ this -> _ssl ) ? 'https://' : 'http://' ; $ uri .= self :: RECAPTCHA_API_SERVER ; $ uri .= ( $ path !== 'challenge' ) ? 'noscript' : $ path ; $ uri .= '?k=' . $ this -> _publicKey ; $ uri .= ( $ this -> _error ) ? '&error=' . $ this -> _error : NULL ; $ uri .= ( isset ( $ this -> _recaptchaOptions [ 'lang' ] ) ) ? '&hl=' . $ this -> _recaptchaOptions [ 'lang' ] : '&hl=' . $ this -> clientLang ( ) ; return $ uri ; }
Build API server URI
14,909
public function getNodes ( $ content ) { $ items = array ( ) ; $ document = $ this -> createDocumentFromXML ( $ content ) ; $ nodes = $ document -> getElementsByTagName ( 'item' ) ; if ( $ nodes -> length ) { foreach ( $ nodes as $ node ) { try { $ item = $ this -> create ( $ node ) ; $ items [ ] = $ item ; } catch ( \ Exception $ e ) { throw new RuntimeException ( $ e -> getMessage ( ) ) ; } } } return $ items ; }
Retrieve a Items s array
14,910
protected static function _defineRelationships ( ) { $ className = get_called_class ( ) ; $ classes = class_parents ( $ className ) ; array_unshift ( $ classes , $ className ) ; static :: $ _classRelationships [ $ className ] = [ ] ; while ( $ class = array_pop ( $ classes ) ) { if ( ! empty ( $ class :: $ relationships ) ) { static :: $ _classRelationships [ $ className ] = array_merge ( static :: $ _classRelationships [ $ className ] , $ class :: $ relationships ) ; } if ( static :: isVersioned ( ) && ! empty ( $ class :: $ versioningRelationships ) ) { static :: $ _classRelationships [ $ className ] = array_merge ( static :: $ _classRelationships [ $ className ] , $ class :: $ versioningRelationships ) ; } } }
Called when anything relationships related is used for the first time to define relationships before _initRelationships
14,911
protected static function _initRelationships ( ) { $ className = get_called_class ( ) ; if ( ! empty ( static :: $ _classRelationships [ $ className ] ) ) { $ relationships = [ ] ; foreach ( static :: $ _classRelationships [ $ className ] as $ relationship => $ options ) { if ( is_array ( $ options ) ) { $ relationships [ $ relationship ] = static :: _initRelationship ( $ relationship , $ options ) ; } } static :: $ _classRelationships [ $ className ] = $ relationships ; } }
Called after _defineRelationships to initialize and apply defaults to the relationships property Must be idempotent as it may be applied multiple times up the inheritence chain
14,912
protected function resolveValue ( $ field ) { $ cur = & $ this -> _record ; if ( array_key_exists ( $ field , $ cur ) ) { $ cur = & $ cur [ $ field ] ; } else { return null ; } return $ cur ; }
protected instance methods
14,913
public function getComments ( $ newestFirst = true , $ limit = null , $ offset = null ) { $ query = Comment :: find ( ) -> subject ( $ this -> owner ) ; $ query -> orderNewestFirst ( $ newestFirst ) ; if ( $ limit !== null ) $ query -> limit ( $ limit ) ; if ( $ offset !== null ) $ query -> offset ( $ offset ) ; return $ query -> all ( ) ; }
Fetches comments related to the owner of this behavior
14,914
protected function getImageSizeList ( ) { $ arrSizes = \ System :: getContainer ( ) -> get ( 'contao.image.image_sizes' ) -> getAllOptions ( ) ; if ( is_array ( $ arrList = \ StringUtil :: deserialize ( $ this -> sizeList ) ) ) { $ arrSizes [ 'image_sizes' ] = array_intersect_key ( $ arrSizes [ 'image_sizes' ] , array_flip ( $ arrList ) ) ; } else { $ arrSizes [ 'image_sizes' ] = array ( ) ; } if ( $ this -> canEnterSize ) { return $ arrSizes ; } return $ arrSizes [ 'image_sizes' ] ; }
Get a list of image sizes
14,915
protected function eachPageUncache ( $ selector , callable $ callback ) { $ num = 0 ; $ id = 0 ; while ( true ) { $ p = $ this -> pages -> get ( "{$selector}, id>$id" ) ; if ( ! $ id = $ p -> id ) break ; $ callback ( $ p ) ; $ this -> pages -> uncacheAll ( $ p ) ; $ num ++ ; } return $ num ; }
Cycle over a group of pages without running into memory exhaustion
14,916
protected function insertIntoTemplate ( $ template , $ field , $ reference = null , $ after = true ) { $ template = $ this -> getTemplate ( $ template ) ; $ fieldgroup = $ template -> fieldgroup ; $ method = $ after ? 'insertAfter' : 'insertBefore' ; $ field = $ this -> getField ( $ field ) ; if ( $ reference instanceof Field ) $ reference = $ fieldgroup -> get ( $ reference -> name ) ; else if ( is_string ( $ reference ) ) $ reference = $ fieldgroup -> get ( $ reference ) ; if ( $ reference instanceof Field ) $ fieldgroup -> $ method ( $ field , $ reference ) ; else $ fieldgroup -> append ( $ field ) ; $ fieldgroup -> save ( ) ; }
Insert a field into a template optionally at a specific position .
14,917
protected function removeFromTemplate ( $ template , $ field ) { $ t = $ this -> getTemplate ( $ template ) ; $ f = $ this -> getField ( $ field ) ; $ success = $ t -> fieldgroup -> remove ( $ f ) ; $ t -> fieldgroup -> save ( ) ; return $ success ; }
Removes a field from a template . Also removes all data for that field from pages using the template .
14,918
protected function editInTemplateContext ( $ template , $ field , callable $ callback ) { $ template = $ this -> getTemplate ( $ template ) ; $ fieldgroup = $ template -> fieldgroup ; $ field = $ this -> getField ( $ field ) ; $ context = $ fieldgroup -> getField ( $ field -> name , true ) ; $ callback ( $ context , $ template ) ; $ this -> fields -> saveFieldgroupContext ( $ context , $ fieldgroup ) ; }
Edit a field in template context
14,919
public function setPickerOptions ( $ value , $ dc ) { $ db = Database :: getInstance ( ) ; switch ( $ value ) { case 'datetime' : if ( ! in_array ( $ dc -> activeRecord -> rgxp , array ( 'date' , 'time' , 'datim' ) ) ) { $ db -> prepare ( "UPDATE " . $ this -> table . " SET rgxp=? WHERE id=?" ) -> execute ( 'date' , $ dc -> activeRecord -> id ) ; } if ( $ dc -> activeRecord -> multiple ) { $ db -> prepare ( "UPDATE " . $ this -> table . " SET multiple=? WHERE id=?" ) -> execute ( '' , $ dc -> activeRecord -> id ) ; } break ; case 'color' : if ( ! in_array ( $ dc -> activeRecord -> rgxp , array ( 'alnum' , 'extnd' ) ) ) { $ db -> prepare ( "UPDATE " . $ this -> table . " SET rgxp=? WHERE id=?" ) -> execute ( '' , $ dc -> activeRecord -> id ) ; } break ; case 'link' : if ( $ dc -> activeRecord -> rgxp != 'url' ) { $ db -> prepare ( "UPDATE " . $ this -> table . " SET rgxp=? WHERE id=?" ) -> execute ( 'url' , $ dc -> activeRecord -> id ) ; } if ( $ dc -> activeRecord -> multiple ) { $ db -> prepare ( "UPDATE " . $ this -> table . " SET multiple=? WHERE id=?" ) -> execute ( '' , $ dc -> activeRecord -> id ) ; } break ; case 'unit' : if ( $ dc -> activeRecord -> maxLength > 200 ) { $ db -> prepare ( "UPDATE " . $ this -> table . " SET maxLength=? WHERE id=?" ) -> execute ( 200 , $ dc -> activeRecord -> id ) ; } if ( $ dc -> activeRecord -> multiple ) { $ db -> prepare ( "UPDATE " . $ this -> table . " SET multiple=? WHERE id=?" ) -> execute ( '' , $ dc -> activeRecord -> id ) ; } break ; } return $ value ; }
Adjust maxlength and multiple settings according to the rgxp settings
14,920
public function setMultipleOption ( $ value , $ dc ) { $ db = Database :: getInstance ( ) ; if ( $ value > 3 && $ dc -> activeRecord -> maxLength > 200 ) { $ db -> prepare ( "UPDATE " . $ this -> table . " SET maxLength=? WHERE id=?" ) -> execute ( 200 , $ dc -> activeRecord -> id ) ; } return $ value ; }
Reduce the maxLength for 4 input fields
14,921
public function setSourceOptions ( $ value , $ dc ) { $ db = Database :: getInstance ( ) ; if ( $ value == 'video' || $ value == 'audio' ) { if ( ! $ dc -> activeRecord -> multiSource ) { $ db -> prepare ( "UPDATE " . $ this -> table . " SET multiSource=? WHERE id=?" ) -> execute ( 1 , $ dc -> activeRecord -> id ) ; } if ( $ dc -> activeRecord -> sortBy != 'html5media' ) { $ db -> prepare ( "UPDATE " . $ this -> table . " SET sortBy=? WHERE id=?" ) -> execute ( 'html5media' , $ dc -> activeRecord -> id ) ; } if ( $ dc -> activeRecord -> canChangeSortBy ) { $ db -> prepare ( "UPDATE " . $ this -> table . " SET canChangeSortBy=? WHERE id=?" ) -> execute ( 0 , $ dc -> activeRecord -> id ) ; } } return $ value ; }
Adjust multiSource and sortBy according to the source type
14,922
public function getPattern ( $ dc ) { $ pattern = array ( ) ; foreach ( $ GLOBALS [ 'TL_CTP' ] as $ k => $ v ) { foreach ( $ v as $ kk => $ vv ) { if ( ! $ vv [ 'unique' ] ) { $ pattern [ $ k ] [ ] = $ kk ; } elseif ( \ PatternModel :: countByPidAndType ( $ dc -> activeRecord -> pid , $ kk ) < 1 || $ dc -> activeRecord -> type == $ kk ) { $ pattern [ $ k ] [ ] = $ kk ; } } } return $ pattern ; }
Return content pattern as array
14,923
public function saveGroups ( $ dc ) { $ db = Database :: getInstance ( ) ; if ( $ dc -> activeRecord -> type == 'protection' && ! $ dc -> activeRecord -> canChangeGroups ) { $ groups = is_array ( $ dc -> activeRecord -> groups ) ? serialize ( $ dc -> activeRecord -> groups ) : $ dc -> activeRecord -> groups ; $ db -> prepare ( "UPDATE tl_content SET groups=? WHERE type=(SELECT alias FROM tl_elements WHERE id=?)" ) -> execute ( $ groups , $ dc -> activeRecord -> pid ) ; } }
Save group settings from the pattern to the content element
14,924
public function getForms ( ) { $ arrForms = array ( ) ; $ objForms = $ this -> Database -> execute ( "SELECT id, title FROM tl_form ORDER BY title" ) ; while ( $ objForms -> next ( ) ) { $ arrForms [ $ objForms -> id ] = $ objForms -> title . ' (ID ' . $ objForms -> id . ')' ; } return $ arrForms ; }
Get forms and return them as array
14,925
public function exportTables ( $ xml , $ objArchive , $ objThemeId ) { $ tables = $ xml -> getElementsByTagName ( 'tables' ) [ 0 ] ; $ table = $ xml -> createElement ( 'table' ) ; $ table -> setAttribute ( 'name' , 'tl_elements' ) ; $ table = $ tables -> appendChild ( $ table ) ; $ this -> loadDataContainer ( 'tl_elements' ) ; $ objDcaExtractor = \ DcaExtractor :: getInstance ( 'tl_elements' ) ; $ arrOrder = $ objDcaExtractor -> getOrderFields ( ) ; $ objContentBlocks = $ this -> Database -> prepare ( "SELECT * FROM tl_elements WHERE pid=?" ) -> execute ( $ objThemeId ) ; while ( $ objContentBlocks -> next ( ) ) { $ this -> addDataRow ( $ xml , $ table , $ objContentBlocks -> row ( ) , $ arrOrder ) ; } $ objContentBlocks -> reset ( ) ; $ table = $ xml -> createElement ( 'table' ) ; $ table -> setAttribute ( 'name' , 'tl_pattern' ) ; $ table = $ tables -> appendChild ( $ table ) ; $ this -> loadDataContainer ( 'tl_pattern' ) ; $ objDcaExtractor = \ DcaExtractor :: getInstance ( 'tl_pattern' ) ; $ arrOrder = $ objDcaExtractor -> getOrderFields ( ) ; while ( $ objContentBlocks -> next ( ) ) { $ this -> addPatternData ( $ xml , $ table , $ arrOrder , $ objContentBlocks -> id ) ; } }
Export content blocks tables with template export
14,926
protected function addPatternData ( $ xml , $ table , $ arrOrder , $ intParentID ) { $ objContentPattern = $ this -> Database -> prepare ( "SELECT * FROM tl_pattern WHERE pid=?" ) -> execute ( $ intParentID ) ; while ( $ objContentPattern -> next ( ) ) { $ this -> addDataRow ( $ xml , $ table , $ objContentPattern -> row ( ) , $ arrOrder ) ; if ( in_array ( $ objContentPattern -> type , $ GLOBALS [ 'TL_CTP_SUB' ] ) ) { $ this -> addPatternData ( $ xml , $ table , $ arrOrder , $ objContentPattern -> id ) ; } } }
Add pattern recursively
14,927
public function getCombinations ( array $ sourceDataSet , $ subsetSize = null ) { if ( isset ( $ subsetSize ) ) { return $ this -> _getCombinationSubset ( $ sourceDataSet , $ subsetSize ) ; } $ masterCombinationSet = [ ] ; $ sourceDataSetLength = count ( $ sourceDataSet ) ; for ( $ i = 1 ; $ i <= $ sourceDataSetLength ; $ i ++ ) { $ combinationSubset = $ this -> _getCombinationSubset ( $ sourceDataSet , $ i ) ; $ masterCombinationSet = array_merge ( $ masterCombinationSet , $ combinationSubset ) ; } return $ masterCombinationSet ; }
Creates all the possible combinations for the source data set .
14,928
protected function _getCombinationSubset ( array $ sourceDataSet , $ subsetSize ) { if ( ! isset ( $ subsetSize ) || $ subsetSize < 0 ) { throw new \ InvalidArgumentException ( 'Subset size cannot be empty or less than 0' ) ; } $ sourceSetSize = count ( $ sourceDataSet ) ; if ( $ subsetSize >= $ sourceSetSize ) { return [ $ sourceDataSet ] ; } else if ( $ subsetSize == 1 ) { return array_chunk ( $ sourceDataSet , 1 , true ) ; } else if ( $ subsetSize == 0 ) { return [ ] ; } $ combinations = [ ] ; $ setKeys = array_keys ( $ sourceDataSet ) ; $ pointer = new Pointer ( $ sourceDataSet , $ subsetSize ) ; do { $ combinations [ ] = $ this -> _getCombination ( $ sourceDataSet , $ setKeys , $ pointer ) ; } while ( $ pointer -> advance ( ) ) ; return $ combinations ; }
Calculates all the combinations of a given subset size .
14,929
private function _getCombination ( $ sourceDataSet , $ setKeyList , Pointer $ pointer ) { $ combination = array ( ) ; $ indexPointerList = $ pointer -> getPointerList ( ) ; foreach ( $ indexPointerList as $ indexPointer ) { $ namedKey = $ setKeyList [ $ indexPointer ] ; $ combination [ $ namedKey ] = $ sourceDataSet [ $ namedKey ] ; } return $ combination ; }
Get the combination for the current pointer positions .
14,930
public function generateDCA ( $ strFieldName , $ arrFieldDCA = array ( ) , $ bolVisble = true , $ bolCallbacks = true ) { $ strVirtualField = $ this -> virtualFieldName ( $ strFieldName ) ; if ( $ bolVisble ) { $ GLOBALS [ 'TL_DCA' ] [ 'tl_content' ] [ 'palettes' ] [ $ this -> element ] .= ',' . $ strVirtualField ; } if ( $ bolCallbacks ) { $ arrFieldDCA [ 'eval' ] [ 'doNotSaveEmpty' ] = true ; $ arrFieldDCA [ 'load_callback' ] = is_array ( $ arrFieldDCA [ 'load_callback' ] ) ? $ arrFieldDCA [ 'load_callback' ] : array ( ) ; $ arrFieldDCA [ 'save_callback' ] = is_array ( $ arrFieldDCA [ 'save_callback' ] ) ? $ arrFieldDCA [ 'save_callback' ] : array ( ) ; if ( $ arrFieldDCA [ 'default' ] ) { array_unshift ( $ arrFieldDCA [ 'load_callback' ] , array ( 'tl_content_elements' , 'defaultValue' ) ) ; } array_unshift ( $ arrFieldDCA [ 'load_callback' ] , array ( 'tl_content_elements' , 'loadFieldValue' ) ) ; array_push ( $ arrFieldDCA [ 'save_callback' ] , array ( 'tl_content_elements' , 'saveFieldAndClear' ) ) ; } $ arrFieldDCA = array_merge ( $ arrFieldDCA , array ( 'id' => ( isset ( $ this -> data -> id ) ) ? $ this -> data -> id : null , 'pattern' => $ this -> pattern , 'parent' => ( isset ( $ this -> parent ) ) ? $ this -> parent : 0 , 'column' => $ strFieldName , 'data' => ( isset ( $ this -> data -> $ strFieldName ) ) ? $ this -> data -> $ strFieldName : null ) ) ; $ GLOBALS [ 'TL_DCA' ] [ 'tl_content' ] [ 'fields' ] [ $ strVirtualField ] = $ arrFieldDCA ; }
Generate the DCA for a virtual input field
14,931
protected function virtualFieldName ( $ strFieldName ) { $ strVirtualField = $ this -> pattern . '-' . $ strFieldName ; if ( $ this -> data !== null ) { $ strVirtualField .= '-' . $ this -> data -> id ; } return $ strVirtualField ; }
Generate a field alias with the right syntax
14,932
public function writeToTemplate ( $ value ) { if ( is_array ( $ this -> arrMapper ) ) { $ arrValue [ $ this -> arrMapper [ 0 ] ] = $ this -> Template -> { $ this -> arrMapper [ 0 ] } ; $ map = & $ arrValue ; foreach ( $ this -> arrMapper as $ key ) { if ( ! is_array ( $ map [ $ key ] ) ) { $ map [ $ key ] = array ( ) ; } $ map = & $ map [ $ key ] ; } $ map [ $ this -> alias ] = $ value ; $ this -> Template -> { $ this -> arrMapper [ 0 ] } = $ arrValue [ $ this -> arrMapper [ 0 ] ] ; return ; } $ this -> Template -> { $ this -> alias } = $ value ; }
Write a value to the template
14,933
public static function hasData ( $ strName ) { foreach ( $ GLOBALS [ 'TL_CTP' ] as $ v ) { foreach ( $ v as $ kk => $ vv ) { if ( $ kk == $ strName ) { return ( $ vv [ 'data' ] ) ? : false ; } } } return null ; }
Check if a pattern saves data to the database
14,934
static function encrypt ( $ pwd , $ data , $ ispwdHex = 0 ) { if ( $ ispwdHex ) $ pwd = @ pack ( 'H*' , $ pwd ) ; $ key [ ] = '' ; $ box [ ] = '' ; $ cipher = '' ; $ pwd_length = strlen ( $ pwd ) ; $ data_length = strlen ( $ data ) ; for ( $ i = 0 ; $ i < 256 ; $ i ++ ) { $ key [ $ i ] = ord ( $ pwd [ $ i % $ pwd_length ] ) ; $ box [ $ i ] = $ i ; } for ( $ j = $ i = 0 ; $ i < 256 ; $ i ++ ) { $ j = ( $ j + $ box [ $ i ] + $ key [ $ i ] ) % 256 ; $ tmp = $ box [ $ i ] ; $ box [ $ i ] = $ box [ $ j ] ; $ box [ $ j ] = $ tmp ; } for ( $ a = $ j = $ i = 0 ; $ i < $ data_length ; $ i ++ ) { $ a = ( $ a + 1 ) % 256 ; $ j = ( $ j + $ box [ $ a ] ) % 256 ; $ tmp = $ box [ $ a ] ; $ box [ $ a ] = $ box [ $ j ] ; $ box [ $ j ] = $ tmp ; $ k = $ box [ ( ( $ box [ $ a ] + $ box [ $ j ] ) % 256 ) ] ; $ cipher .= chr ( ord ( $ data [ $ i ] ) ^ $ k ) ; } return $ cipher ; }
The symmetric encryption function
14,935
public function getOrders ( $ limit = 10 ) { if ( $ Member = Security :: getCurrentUser ( ) ) { $ Orders = $ Member -> Orders ( ) -> sort ( 'TransactionDate' , 'DESC' ) ; $ list = new PaginatedList ( $ Orders , Controller :: curr ( ) -> getRequest ( ) ) ; $ list -> setPageLength ( $ limit ) ; return $ list ; } return false ; }
return all current Member s Orders .
14,936
public function subject ( $ model ) { Comment :: validateSubject ( $ model , true ) ; $ this -> modelClass ( $ model :: className ( ) ) ; $ this -> andWhere ( [ 'foreign_pk' => $ this -> createPrimaryKeyJson ( $ model ) ] ) ; return $ this ; }
Named scope to get entries for a certain model
14,937
public function addCteType ( $ arrRow ) { $ return = \ tl_content :: addCteType ( $ arrRow ) ; if ( ( $ objElement = $ objElement = \ ElementsModel :: findOneByAlias ( $ arrRow [ 'type' ] ) ) === null && ! array_key_exists ( $ arrRow [ 'type' ] , $ GLOBALS [ 'TL_DCA' ] [ 'tl_content' ] [ 'palettes' ] ) ) { $ tag = '<span style="color: #222;">' . $ GLOBALS [ 'TL_LANG' ] [ 'CTE' ] [ 'deleted' ] . '</span>' ; } else if ( $ objElement -> invisible ) { $ tag = ' <span style="color: #c6c6c6;">(' . $ GLOBALS [ 'TL_LANG' ] [ 'CTE' ] [ 'invisible' ] . ')</span>' ; } return ( $ tag ) ? substr_replace ( $ return , $ tag . '</div>' , strpos ( $ return , '</div>' ) ) : $ return ; }
Wrap the content block elements into an div block and mark content element if content block is invisible
14,938
public function addTypeHelpWizard ( $ dc ) { return ' <a href="contao/help.php?table=' . $ dc -> table . '&amp;field=' . $ dc -> field . '&amp;ptable=' . $ dc -> parentTable . '&amp;pid=' . $ dc -> activeRecord -> pid . '" title="' . \ StringUtil :: specialchars ( $ GLOBALS [ 'TL_LANG' ] [ 'MSC' ] [ 'helpWizard' ] ) . '" onclick="Backend.openModalIframe({\'width\':735,\'title\':\'' . \ StringUtil :: specialchars ( str_replace ( "'" , "\\'" , $ arrData [ 'label' ] [ 0 ] ) ) . '\',\'url\':this.href});return false">' . \ Image :: getHtml ( 'about.svg' , $ GLOBALS [ 'TL_LANG' ] [ 'MSC' ] [ 'helpWizard' ] , 'style="vertical-align:text-bottom"' ) . '</a>' ; }
Add a custom help wirzard to the type field
14,939
public function getElements ( $ dc ) { if ( $ dc -> activeRecord !== null ) { $ ptable = $ dc -> activeRecord -> ptable ; $ pid = $ dc -> activeRecord -> pid ; } else { $ ptable = \ Input :: get ( 'ptable' ) ; $ pid = \ Input :: get ( 'pid' ) ; } $ objLayout = \ LayoutModel :: findById ( \ Agoat \ CustomContentElementsBundle \ Contao \ Controller :: getLayoutId ( $ ptable , $ pid ) ) ; $ colElements = \ ElementsModel :: findPublishedByPid ( $ objLayout -> pid ) ; $ arrElements = array ( ) ; $ strGroup = 'cte' ; if ( $ colElements !== null ) { foreach ( $ colElements as $ objElement ) { if ( $ objElement -> type == 'group' ) { $ strGroup = $ objElement -> alias ; } else { $ arrElements [ $ strGroup ] [ ] = $ objElement -> alias ; } } } if ( ! \ Config :: get ( 'hideLegacyCTE' ) ) { unset ( $ GLOBALS [ 'TL_CTE' ] [ 'CTE' ] ) ; foreach ( $ GLOBALS [ 'TL_CTE' ] as $ k => $ v ) { foreach ( array_keys ( $ v ) as $ kk ) { $ arrElements [ $ k ] [ ] = $ kk ; } } } if ( $ dc -> value != '' && ! in_array ( $ dc -> value , array_reduce ( $ arrElements , 'array_merge' , array ( ) ) ) ) { if ( ( $ objLegacy = \ ElementsModel :: findOneByAlias ( $ dc -> value ) ) === null && ! array_key_exists ( $ dc -> value , $ GLOBALS [ 'TL_DCA' ] [ 'tl_content' ] [ 'palettes' ] ) ) { $ arrLegacy = array ( 'deleted' => array ( $ dc -> value ) ) ; } else if ( $ objLegacy -> invisible ) { $ arrLegacy = array ( 'invisible' => array ( $ dc -> value ) ) ; } else { $ arrLegacy = array ( 'legacy' => array ( $ dc -> value ) ) ; } $ arrElements = array_merge ( $ arrLegacy , $ arrElements ) ; } return $ arrElements ; }
Generate a content element list array
14,940
public function setDefaultType ( $ value , $ dc ) { if ( ! $ value ) { if ( $ dc -> activeRecord !== null ) { $ ptable = $ dc -> activeRecord -> ptable ; $ pid = $ dc -> activeRecord -> pid ; } else { return $ value ; } $ objLayout = \ LayoutModel :: findById ( \ Agoat \ CustomContentElementsBundle \ Contao \ Controller :: getLayoutId ( $ ptable , $ pid ) ) ; $ objDefault = \ ElementsModel :: findDefaultPublishedElementByPid ( $ objLayout -> pid ) ; if ( $ objDefault === null ) { if ( \ Config :: get ( 'hideLegacyCTE' ) ) { $ objDefault = \ ElementsModel :: findFirstPublishedElementByPid ( $ objLayout -> pid ) ; } if ( $ objDefault === null ) { $ objDefault = new \ stdClass ( ) ; $ objDefault -> alias = 'text' ; } } $ objContent = \ ContentModel :: findByPk ( $ dc -> id ) ; $ objContent -> type = $ objDefault -> alias ; $ objContent -> save ( ) ; $ this -> redirect ( \ Environment :: get ( 'request' ) ) ; } return $ value ; }
Set default value for new records
14,941
public function buildPaletteAndFields ( $ dc ) { if ( \ Input :: get ( 'act' ) != 'edit' && \ Input :: get ( 'act' ) != 'show' && ! isset ( $ _GET [ 'target' ] ) ) { return ; } $ intId = ( isset ( $ _GET [ 'target' ] ) ) ? explode ( '.' , \ Input :: get ( 'target' ) ) [ 2 ] : $ dc -> id ; $ objContent = \ ContentModel :: findByPk ( $ intId ) ; if ( $ objContent === null ) { return ; } $ objElement = \ ElementsModel :: findOneByAlias ( $ objContent -> type ) ; if ( $ objElement === null ) { return ; } $ GLOBALS [ 'TL_DCA' ] [ 'tl_content' ] [ 'palettes' ] [ $ objElement -> alias ] = '{type_legend},type' ; $ colPattern = \ PatternModel :: findVisibleByPid ( $ objElement -> id ) ; if ( $ colPattern === null ) { return ; } $ arrData = array ( ) ; $ colData = \ DataModel :: findByPid ( $ intId ) ; if ( $ colData !== null ) { foreach ( $ colData as $ objData ) { $ arrData [ $ objData -> pattern ] = $ objData ; } } foreach ( $ colPattern as $ objPattern ) { $ strClass = Agoat \ CustomContentElementsBundle \ Contao \ Pattern :: findClass ( $ objPattern -> type ) ; $ bolData = Agoat \ CustomContentElementsBundle \ Contao \ Pattern :: hasData ( $ objPattern -> type ) ; if ( ! class_exists ( $ strClass ) ) { \ System :: log ( 'Pattern element class "' . $ strClass . '" (pattern element "' . $ objPattern -> type . '") does not exist' , __METHOD__ , TL_ERROR ) ; } else { if ( $ bolData && ! isset ( $ arrData [ $ objPattern -> alias ] ) ) { $ arrData [ $ objPattern -> alias ] = new \ DataModel ( ) ; $ arrData [ $ objPattern -> alias ] -> pid = $ objContent -> id ; $ arrData [ $ objPattern -> alias ] -> pattern = $ objPattern -> alias ; $ arrData [ $ objPattern -> alias ] -> save ( ) ; } $ objPatternClass = new $ strClass ( $ objPattern ) ; $ objPatternClass -> pid = $ objContent -> id ; $ objPatternClass -> pattern = $ objPattern -> alias ; $ objPatternClass -> element = $ objElement -> alias ; $ objPatternClass -> data = $ arrData [ $ objPattern -> alias ] ; $ objPatternClass -> create ( ) ; } } }
Build the palette and field DCA for the virtual input fields
14,942
public function loadFieldValue ( $ value , $ dc ) { if ( ! empty ( $ value ) ) { return $ value ; } if ( ! empty ( $ GLOBALS [ 'TL_DCA' ] [ 'tl_content' ] [ 'fields' ] [ $ dc -> field ] [ 'data' ] ) ) { return $ GLOBALS [ 'TL_DCA' ] [ 'tl_content' ] [ 'fields' ] [ $ dc -> field ] [ 'data' ] ; } return null ; }
Load the virtual field value from the DCA
14,943
public function saveData ( & $ dc ) { foreach ( $ this -> arrModifiedData as $ field => $ value ) { $ id = $ GLOBALS [ 'TL_DCA' ] [ 'tl_content' ] [ 'fields' ] [ $ field ] [ 'id' ] ; $ pattern = $ GLOBALS [ 'TL_DCA' ] [ 'tl_content' ] [ 'fields' ] [ $ field ] [ 'pattern' ] ; $ parent = $ GLOBALS [ 'TL_DCA' ] [ 'tl_content' ] [ 'fields' ] [ $ field ] [ 'parent' ] ; $ column = $ GLOBALS [ 'TL_DCA' ] [ 'tl_content' ] [ 'fields' ] [ $ field ] [ 'column' ] ; if ( $ id !== null ) { $ objData = \ DataModel :: findByPK ( $ id ) ; } else { $ objData = \ DataModel :: findByPidAndPatternAndParent ( $ dc -> activeRecord -> id , $ pattern , $ parent ) ; } if ( $ objData === null ) { $ objData = new \ DataModel ( ) ; $ objData -> tstamp = time ( ) ; } $ objData -> pid = $ dc -> activeRecord -> id ; $ objData -> pattern = $ pattern ; $ objData -> parent = $ parent ; if ( $ objData -> $ column != $ value ) { $ dc -> blnCreateNewVersion = true ; $ objData -> $ column = $ value ; $ objData -> tstamp = time ( ) ; } $ objData -> save ( ) ; } }
Save the virtual field values into the tl_data table
14,944
public function prepareOrderValue ( $ value , $ dc ) { $ orderField = $ GLOBALS [ 'TL_DCA' ] [ 'tl_content' ] [ 'fields' ] [ $ dc -> field ] [ 'eval' ] [ 'orderField' ] ; $ orderData = \ StringUtil :: deserialize ( $ GLOBALS [ 'TL_DCA' ] [ 'tl_content' ] [ 'fields' ] [ $ orderField ] [ 'data' ] ) ; $ GLOBALS [ 'TL_DCA' ] [ 'tl_content' ] [ 'fields' ] [ $ dc -> field ] [ 'eval' ] [ $ orderField ] = ( is_array ( $ orderData ) ) ? $ orderData : array ( ) ; return $ value ; }
Prepare the virtual order field
14,945
public function saveOrderValue ( $ value , $ dc ) { $ orderField = $ GLOBALS [ 'TL_DCA' ] [ 'tl_content' ] [ 'fields' ] [ $ dc -> field ] [ 'eval' ] [ 'orderField' ] ; $ orderData = \ Input :: post ( $ orderField ) ; if ( $ orderData ) { if ( $ GLOBALS [ 'TL_DCA' ] [ 'tl_content' ] [ 'fields' ] [ $ dc -> field ] [ 'inputType' ] == 'fileTree' ) { $ this -> arrModifiedData [ $ orderField ] = array_map ( '\StringUtil::uuidToBin' , explode ( ',' , $ orderData ) ) ; } else { $ this -> arrModifiedData [ $ orderField ] = explode ( ',' , $ orderData ) ; } } else { $ this -> arrModifiedData [ $ orderField ] = NULL ; } return $ value ; }
Save the virtual order field
14,946
public function setAceCodeHighlighting ( $ value , $ dc ) { $ pattern = $ GLOBALS [ 'TL_DCA' ] [ 'tl_content' ] [ 'fields' ] [ $ dc -> field ] [ 'pattern' ] ; $ highlight = $ GLOBALS [ 'TL_DCA' ] [ 'tl_content' ] [ 'fields' ] [ $ pattern . '-highlight' ] [ 'data' ] ; if ( ! empty ( $ highlight ) ) { $ GLOBALS [ 'TL_DCA' ] [ 'tl_content' ] [ 'fields' ] [ $ dc -> field ] [ 'eval' ] [ 'rte' ] = 'ace|' . strtolower ( $ highlight ) ; } return $ value ; }
Dynamically set the ace highlight syntax
14,947
public function createDataVersion ( $ strTable , $ intPid , $ intVersion ) { $ db = Database :: getInstance ( ) ; $ objData = $ db -> prepare ( "SELECT * FROM tl_data WHERE pid=?" ) -> execute ( $ intPid ) ; if ( $ objData === null ) { return ; } $ db -> prepare ( "INSERT INTO tl_version (pid, tstamp, version, fromTable, data) VALUES (?, ?, ?, ?, ?)" ) -> execute ( $ intPid , time ( ) , $ intVersion , 'tl_data' , serialize ( $ objData -> fetchAllAssoc ( ) ) ) ; }
Save tl_data versions
14,948
public function restoreDataVersion ( $ strTable , $ intPid , $ intVersion ) { $ db = Database :: getInstance ( ) ; $ objData = $ db -> prepare ( "SELECT * FROM tl_version WHERE fromTable=? AND pid=? AND version=?" ) -> execute ( 'tl_data' , $ intPid , $ intVersion ) ; if ( $ objData -> numRows < 1 ) { return ; } $ data = \ StringUtil :: deserialize ( $ objData -> data ) ; if ( ! is_array ( $ data ) ) { return ; } $ arrFields = array_flip ( $ this -> Database -> getFieldnames ( 'tl_data' ) ) ; $ objStmt = $ db -> prepare ( "DELETE FROM tl_data WHERE pid=?" ) -> execute ( $ intPid ) ; foreach ( $ data as $ row ) { $ row = array_intersect_key ( $ row , $ arrFields ) ; foreach ( array_diff_key ( $ arrFields , $ row ) as $ k => $ v ) { $ row [ $ k ] = \ Widget :: getEmptyValueByFieldType ( $ GLOBALS [ 'TL_DCA' ] [ 'tl_data' ] [ 'fields' ] [ $ k ] [ 'sql' ] ) ; } $ db -> prepare ( "INSERT INTO tl_data %s" ) -> set ( $ row ) -> execute ( $ row [ 'id' ] ) ; } }
Restore tl_data versions
14,949
public function convertAvatar ( $ projectId , $ cropperWidth , $ cropperOffsetX , $ cropperOffsetY , $ needsCropping ) { return $ this -> apiClient -> callEndpoint ( sprintf ( '%s/%s/avatar' , self :: ENDPOINT , $ projectId ) , array ( "cropperWidth" => $ cropperWidth , "cropperOffsetX" => $ cropperOffsetX , "cropperOffsetY" => $ cropperOffsetY , "needsCropping" => $ needsCropping ) , HttpMethod :: REQUEST_POST ) ; }
Converts temporary avatar into a real avatar
14,950
public function findProperty ( $ projectId , $ propertyKey ) { return $ this -> apiClient -> callEndpoint ( sprintf ( '%s/%s/properties/%s' , self :: ENDPOINT , $ projectId , $ propertyKey ) ) ; }
Returns the value of the property with a given key from the project identified by the key or by the id . The user who retrieves the property is required to have permissions to read the project .
14,951
public function findRole ( $ projectId , $ roleId ) { return $ this -> apiClient -> callEndpoint ( sprintf ( '%s/%s/role/%s' , self :: ENDPOINT , $ projectId , $ roleId ) ) ; }
Details on a given project role .
14,952
public function updateRole ( $ projectId , $ roleId , $ user = null , $ group = null ) { $ parameters = [ ] ; if ( ( is_null ( $ user ) && is_null ( $ group ) ) || ( ! is_null ( $ user ) && ! is_null ( $ group ) ) ) { throw new EndpointParameterException ( 'User or group should be given' ) ; } elseif ( ! is_null ( $ user ) ) { $ parameters [ 'user' ] = $ user ; } else { $ parameters [ 'group' ] = $ group ; } return $ this -> apiClient -> callEndpoint ( sprintf ( '%s/%s/role/%s' , self :: ENDPOINT , $ projectId , $ roleId ) , $ parameters , null , HttpMethod :: REQUEST_PUT ) ; }
Updates a project role to contain the sent actors .
14,953
public function addRole ( $ projectId , $ roleId , $ user = null , $ group = null ) { $ parameters = [ ] ; if ( ( is_null ( $ user ) && is_null ( $ group ) ) || ( ! is_null ( $ user ) && ! is_null ( $ group ) ) ) { throw new EndpointParameterException ( 'User or group should be given' ) ; } elseif ( ! is_null ( $ user ) ) { $ parameters [ 'user' ] = $ user ; } else { $ parameters [ 'group' ] = $ group ; } return $ this -> apiClient -> callEndpoint ( sprintf ( '%s/%s/role/%s' , self :: ENDPOINT , $ projectId , $ roleId ) , $ parameters , null , HttpMethod :: REQUEST_POST ) ; }
Add an actor to a project role .
14,954
public function deleteRole ( $ projectId , $ roleId ) { return $ this -> apiClient -> callEndpoint ( sprintf ( '%s/%s/role/%s' , self :: ENDPOINT , $ projectId , $ roleId ) , array ( ) , null , HttpMethod :: REQUEST_DELETE ) ; }
Remove actors from a project role .
14,955
public function dontSeeTimeIsInSecs ( $ time , $ seconds ) { \ PHPUnit_Framework_Assert :: assertNotEquals ( $ seconds , $ this -> _GetNow ( ) -> diffInSeconds ( $ this -> _ParseDate ( $ time ) , false ) ) ; }
See time is not in a given number of seconds .
14,956
public function seeTimeWasInSecs ( $ time , $ seconds ) { \ PHPUnit_Framework_Assert :: assertEquals ( $ seconds , $ this -> _ParseDate ( $ time ) -> diffInSeconds ( $ this -> _GetNow ( ) , false ) ) ; }
See time was in a given number of seconds .
14,957
public function seeTimeIsInMins ( $ time , $ minutes ) { \ PHPUnit_Framework_Assert :: assertEquals ( $ minutes , $ this -> _GetNow ( ) -> diffInMinutes ( $ this -> _ParseDate ( $ time ) , false ) ) ; }
See time is in a given number of minutes .
14,958
public function dontSeeTimeIsInMins ( $ time , $ minutes ) { \ PHPUnit_Framework_Assert :: assertNotEquals ( $ minutes , $ this -> _GetNow ( ) -> diffInMinutes ( $ this -> _ParseDate ( $ time ) , false ) ) ; }
See time is not in a given number of minutes .
14,959
public function dontSeeTimeIsInHours ( $ time , $ hours ) { \ PHPUnit_Framework_Assert :: assertNotEquals ( $ hours , $ this -> _GetNow ( ) -> diffInHours ( $ this -> _ParseDate ( $ time ) , false ) ) ; }
See time is not in a given number of hours .
14,960
public function seeTimeWasInHours ( $ time , $ hours ) { \ PHPUnit_Framework_Assert :: assertEquals ( $ hours , $ this -> _ParseDate ( $ time ) -> diffInHours ( $ this -> _GetNow ( ) , false ) ) ; }
See time was in a given number of hours .
14,961
public function seeTimeMatches ( $ t1 , $ t2 ) { \ PHPUnit_Framework_Assert :: assertTrue ( $ this -> _ParseDate ( $ t1 ) -> eq ( $ this -> _ParseDate ( $ t2 ) ) ) ; }
See that two times match .
14,962
public function dontSeeTimeMatches ( $ t1 , $ t2 ) { \ PHPUnit_Framework_Assert :: assertTrue ( $ this -> _ParseDate ( $ t1 ) -> ne ( $ this -> _ParseDate ( $ t2 ) ) ) ; }
See that two times don t match .
14,963
private function getBotId ( ) { if ( is_null ( $ this -> botId ) ) { $ response = $ this -> http -> get ( self :: API_ENDPOINT . 'people/me' , [ ] , $ this -> getHeaders ( ) ) ; $ bot = json_decode ( $ response -> getContent ( ) ) ; $ this -> botId = $ bot -> id ; } return $ this -> botId ; }
Returns the chatbot ID .
14,964
public function parse ( ) { $ strBuffer = parent :: parse ( ) ; if ( TL_MODE == 'BE' ) { $ strBuffer = '<div class="tl_ce ' . $ this -> strTemplate . '">' . $ strBuffer . '</div>' ; } return $ strBuffer ; }
Add a wrapper in the backend
14,965
public function addImage ( $ image , $ size , $ width = 0 , $ height = 0 ) { if ( ! is_array ( $ image ) ) { return ; } if ( @ unserialize ( $ size ) === false ) { $ size = serialize ( array ( ( string ) $ width , ( string ) $ height , $ size ) ) ; } $ image [ 'size' ] = $ size ; $ image [ 'singleSRC' ] = $ image [ 'path' ] ; Pattern :: addImageToTemplate ( $ picture = new \ stdClass ( ) , $ image ) ; $ picture = $ picture -> picture ; $ picture [ 'imageUrl' ] = $ image [ 'imageUrl' ] ; $ picture [ 'caption' ] = $ image [ 'caption' ] ; $ picture [ 'id' ] = $ image [ 'id' ] ; $ picture [ 'uuid' ] = $ image [ 'uuid' ] ; $ picture [ 'name' ] = $ image [ 'name' ] ; $ picture [ 'path' ] = $ image [ 'path' ] ; $ picture [ 'extension' ] = $ image [ 'extension' ] ; return $ picture ; }
Add an image to template
14,966
public function addCSS ( $ strCSS , $ strType = 'scss' , $ bolStatic = true ) { if ( $ strCSS == '' ) { return ; } $ strType = strtoupper ( $ strType ) ; if ( ! in_array ( $ strType , array ( 'CSS' , 'SCSS' , 'LESS' ) ) ) { return ; } if ( ! $ bolStatic && $ strType == 'css' ) { $ strKey = substr ( md5 ( $ strType . $ strCSS ) , 0 , 12 ) ; $ strPath = 'assets/css/' . $ strKey . '.' . $ strType ; if ( ! file_exists ( $ strPath ) ) { $ objFile = new File ( $ strPath , true ) ; $ objFile -> write ( $ strCSS ) ; $ objFile -> close ( ) ; } $ GLOBALS [ TL_USER_CSS ] [ ] = $ strPath ; return ; } $ GLOBALS [ 'TL_CTB_' . $ strType ] .= $ strCSS ; }
Add CSS to the page
14,967
public function addJS ( $ strJS , $ bolStatic = true ) { if ( $ strJS == '' ) { return ; } if ( ! $ bolStatic ) { $ strKey = substr ( md5 ( 'js' . $ strJS ) , 0 , 12 ) ; $ strPath = 'assets/js/' . $ strKey . '.js' ; if ( ! file_exists ( $ strPath ) ) { $ objFile = new File ( $ strPath , true ) ; $ objFile -> write ( $ strCSS ) ; $ objFile -> close ( ) ; } $ GLOBALS [ TL_JAVASCRIPT ] [ ] = $ strPath ; return ; } $ GLOBALS [ 'TL_CTB_JS' ] .= $ strJS ; }
Add Javascript to the page
14,968
public function prevElement ( ) { if ( ( $ arrTypes = $ GLOBALS [ 'templateTypes' ] [ $ this -> ptable . '.' . $ this -> pid ] ) === null ) { $ objCte = \ ContentModel :: findPublishedByPidAndTable ( $ this -> pid , $ this -> ptable ) ; if ( $ objCte === null ) { return ; } $ arrTypes = $ GLOBALS [ 'templateTypes' ] [ $ this -> ptable . '.' . $ this -> pid ] = $ objCte -> fetchEach ( 'type' ) ; } return $ arrTypes [ array_keys ( $ arrTypes ) [ array_search ( $ this -> id , array_keys ( $ arrTypes ) ) - 1 ] ] ; }
Get the alias of the previous content element
14,969
public function insert ( $ name , array $ data = null ) { if ( ! array_key_exists ( $ name , TemplateLoader :: getFiles ( ) ) ) { $ objTheme = \ LayoutModel :: findById ( Controller :: getLayoutId ( $ this -> ptable , $ this -> pid ) ) -> getRelated ( 'pid' ) ; TemplateLoader :: addFile ( $ name , $ objTheme -> templates ) ; } if ( $ this instanceof \ Template ) { $ tpl = new static ( $ name ) ; } elseif ( TL_MODE == 'BE' ) { $ tpl = new BackendTemplate ( $ name ) ; } else { $ tpl = new FrontendTemplate ( $ name ) ; } if ( $ data !== null ) { $ tpl -> setData ( $ data ) ; } echo $ tpl -> parse ( ) ; }
Insert a template
14,970
public function onMessage ( Server $ server , Frame $ frame ) { $ fd = $ frame -> fd ; WebSocketContext :: setFdToCoId ( $ fd ) ; App :: trigger ( WsEvent :: ON_MESSAGE , null , $ server , $ frame ) ; $ this -> log ( "received message: {$frame->data} from fd #{$fd}, co ID #" . Coroutine :: tid ( ) , [ ] , 'debug' ) ; \ bean ( 'wsDispatcher' ) -> message ( $ server , $ frame ) ; WebSocketContext :: delFdByCoId ( ) ; RequestContext :: destroy ( ) ; }
When you receive the message
14,971
public function getTotal ( ) { return ( float ) ( $ this -> valorDocumento + $ this -> taxa + $ this -> outrosAcrescimos ) - ( $ this -> desconto + $ this -> outrasDeducoes ) ; }
Retorna a valor total do boleto .
14,972
public function index ( ArticlesDataTable $ dataTable ) { $ categories = [ ] ; $ allYesNo = [ ] ; $ statuses = [ ] ; if ( ! request ( ) -> wantsJson ( ) ) { $ categories = Category :: root ( ) -> getDescendants ( ) -> map ( function ( Category $ category ) { $ category -> title = $ category -> present ( ) -> name ; return $ category ; } ) -> pluck ( 'title' , 'id' ) ; $ categories = collect ( [ '' => '- Select Category -' ] ) -> union ( $ categories ) ; $ allYesNo = [ '' => '- Select Article Type -' , 0 => 'Article' , 1 => 'Page' , ] ; $ statuses = [ '' => '- Select Status -' , 0 => 'Unpublished' , 1 => 'Published' , ] ; } return $ dataTable -> render ( 'administrator.articles.index' , compact ( 'categories' , 'allYesNo' , 'statuses' ) ) ; }
Display list of articles .
14,973
public function create ( Article $ article ) { $ article -> published = true ; $ article -> setHighestOrderNumber ( ) ; $ tags = Article :: existingTags ( ) -> pluck ( 'name' ) ; return view ( 'administrator.articles.create' , compact ( 'article' , 'tags' ) ) ; }
Show articles form .
14,974
public function store ( ArticlesFormRequest $ request ) { $ article = new Article ; $ article -> fill ( $ request -> all ( ) ) ; $ article -> published = $ request -> get ( 'published' , false ) ; $ article -> featured = $ request -> get ( 'featured' , false ) ; $ article -> authenticated = $ request -> get ( 'authenticated' , false ) ; $ article -> is_page = $ request -> get ( 'is_page' , false ) ; $ article -> save ( ) ; $ article -> permissions ( ) -> sync ( $ request -> get ( 'permissions' , [ ] ) ) ; if ( $ request -> tags ) { $ article -> tag ( explode ( ',' , $ request -> tags ) ) ; } event ( new ArticleWasCreated ( $ article ) ) ; flash ( ) -> success ( trans ( 'cms::article.store.success' ) ) ; return redirect ( ) -> route ( 'administrator.articles.index' ) ; }
Store a newly created article .
14,975
public function edit ( Article $ article ) { $ tags = Article :: existingTags ( ) -> pluck ( 'name' ) ; $ selectedTags = implode ( ',' , $ article -> tagNames ( ) ) ; return view ( 'administrator.articles.edit' , compact ( 'article' , 'tags' , 'selectedTags' ) ) ; }
Show and edit selected article .
14,976
public function update ( Article $ article , ArticlesFormRequest $ request ) { $ article -> fill ( $ request -> all ( ) ) ; $ article -> published = $ request -> get ( 'published' , false ) ; $ article -> featured = $ request -> get ( 'featured' , false ) ; $ article -> authenticated = $ request -> get ( 'authenticated' , false ) ; $ article -> is_page = $ request -> get ( 'is_page' , false ) ; $ article -> save ( ) ; $ article -> permissions ( ) -> sync ( $ request -> get ( 'permissions' , [ ] ) ) ; if ( $ request -> tags ) { $ article -> retag ( explode ( ',' , $ request -> tags ) ) ; } event ( new ArticleWasUpdated ( $ article ) ) ; flash ( ) -> success ( trans ( 'cms::article.update.success' ) ) ; return redirect ( ) -> route ( 'administrator.articles.index' ) ; }
Update selected article .
14,977
public function listCommand ( $ host = null , $ match = null ) { $ outputByHost = function ( $ host = null ) use ( $ match ) { $ redirects = $ this -> redirectStorage -> getAll ( $ host ) ; $ this -> outputLine ( ) ; if ( $ host !== null ) { $ this -> outputLine ( '<info>==</info> <b>Redirect for %s</b>' , [ $ host ] ) ; } else { $ this -> outputLine ( '<info>==</info> <b>Redirects valid for all hosts</b>' , [ $ host ] ) ; } if ( $ match !== null ) { $ this -> outputLine ( ' <info>++</info> <b>Only showing redirects where source or target URI matches <u>%s</u></b>' , [ $ match ] ) ; sleep ( 1 ) ; } $ this -> outputLine ( ) ; foreach ( $ redirects as $ redirect ) { $ outputLine = function ( $ source , $ target , $ statusCode ) { $ this -> outputLine ( ' <comment>></comment> %s <info>=></info> %s <comment>(%d)</comment>' , [ $ source , $ target , $ statusCode ] ) ; } ; $ source = $ redirect -> getSourceUriPath ( ) ; $ target = $ redirect -> getTargetUriPath ( ) ; $ statusCode = $ redirect -> getStatusCode ( ) ; if ( $ match === null ) { $ outputLine ( $ source , $ target , $ statusCode ) ; } else { $ regexp = sprintf ( '#%s#' , $ match ) ; $ matches = preg_grep ( $ regexp , [ $ target , $ source ] ) ; if ( count ( $ matches ) > 0 ) { $ replace = "<error>$0</error>" ; $ source = preg_replace ( $ regexp , $ replace , $ source ) ; $ target = preg_replace ( $ regexp , $ replace , $ target ) ; $ outputLine ( $ source , $ target , $ statusCode ) ; } } } } ; if ( $ host !== null ) { $ outputByHost ( $ host ) ; } else { $ hosts = $ this -> redirectStorage -> getDistinctHosts ( ) ; array_map ( $ outputByHost , $ hosts ) ; } $ this -> outputLine ( ) ; }
List all redirects
14,978
public function exportCommand ( $ filename = null , $ host = null ) { if ( ! class_exists ( Writer :: class ) ) { $ this -> outputWarningForLeagueCsvPackage ( ) ; } $ writer = Writer :: createFromFileObject ( new \ SplTempFileObject ( ) ) ; if ( $ host !== null ) { $ redirects = $ this -> redirectStorage -> getAll ( $ host ) ; } else { $ redirects = new \ AppendIterator ( ) ; foreach ( $ this -> redirectStorage -> getDistinctHosts ( ) as $ host ) { $ redirects -> append ( $ this -> redirectStorage -> getAll ( $ host ) ) ; } } foreach ( $ redirects as $ redirect ) { $ writer -> insertOne ( [ $ redirect -> getSourceUriPath ( ) , $ redirect -> getTargetUriPath ( ) , $ redirect -> getStatusCode ( ) , $ redirect -> getHost ( ) ] ) ; } if ( $ filename === null ) { $ writer -> output ( ) ; } else { file_put_contents ( $ filename , ( string ) $ writer ) ; } }
Export redirects to CSV
14,979
public function removeCommand ( $ source , $ host = null ) { $ redirect = $ this -> redirectStorage -> getOneBySourceUriPathAndHost ( $ source , $ host ) ; if ( $ redirect === null ) { $ this -> outputLine ( 'There is no redirect with the source URI path "%s", maybe you forgot the --host argument ?' , [ $ source ] ) ; $ this -> quit ( 1 ) ; } $ this -> redirectStorage -> removeOneBySourceUriPathAndHost ( $ source , $ host ) ; $ this -> outputLine ( 'Removed redirect with the source URI path "%s"' , [ $ source ] ) ; }
Remove a single redirect
14,980
public function removeByHostCommand ( $ host ) { if ( $ host === 'all' ) { $ this -> redirectStorage -> removeByHost ( null ) ; $ this -> outputLine ( 'Removed redirects matching all hosts' ) ; } else { $ this -> redirectStorage -> removeByHost ( $ host ) ; $ this -> outputLine ( 'Removed all redirects for host "%s"' , [ $ host ] ) ; } }
Remove all redirects by host
14,981
public function render ( ) { $ block = $ this -> config ( 'viewBlockName' ) ; foreach ( ( array ) $ this -> config ( 'tags' ) as $ namespace => $ values ) { foreach ( $ values as $ tag => $ content ) { $ property = "$namespace:$tag" ; if ( ! is_array ( $ content ) ) { $ this -> Html -> meta ( null , null , compact ( 'property' , 'content' , 'block' ) ) ; continue ; } $ options = array_pop ( $ content ) ; $ content = array_shift ( $ content ) ; $ this -> Html -> meta ( null , null , compact ( 'property' , 'content' , 'block' ) ) ; foreach ( $ options as $ key => $ value ) { if ( ! is_array ( $ value ) ) { $ this -> Html -> meta ( null , null , [ 'property' => "$property:$key" , 'content' => $ value , 'block' => $ block ] ) ; continue ; } foreach ( $ value as $ content ) { $ this -> Html -> meta ( null , null , [ 'property' => "$property:$key" , 'content' => $ content , 'block' => $ block ] ) ; } } } } return $ this -> _View -> fetch ( $ block ) ; }
Render view block .
14,982
protected function uploadFileToCloudinary ( $ file , $ publicId ) { $ result = $ this -> uploader -> upload ( $ file -> getRealPath ( ) , [ 'public_id' => $ publicId , ] ) ; return $ result ; }
Upload a picture to Cloudinary .
14,983
public function memory ( ) { $ usedInBytes = $ this -> data [ 'memory_usage' ] [ 'used_memory' ] ; $ wastedInBytes = $ this -> data [ 'memory_usage' ] [ 'wasted_memory' ] ; $ sizeInBytes = $ usedInBytes + $ wastedInBytes + $ this -> data [ 'memory_usage' ] [ 'free_memory' ] ; return new Memory ( $ this -> bytesToMb ( $ usedInBytes ) , $ this -> bytesToMb ( $ sizeInBytes ) , $ this -> bytesToMb ( $ wastedInBytes ) ) ; }
Provides information about the memory usage .
14,984
public function scripts ( ) { $ scripts = array_map ( function ( $ scriptData ) { return new Script ( $ scriptData [ 'full_path' ] , $ this -> bytesToMb ( $ scriptData [ 'memory_consumption' ] ) , $ scriptData [ 'hits' ] , new \ DateTimeImmutable ( '@' . $ scriptData [ 'last_used_timestamp' ] ) ) ; } , $ this -> data [ 'scripts' ] ) ; return new ScriptCollection ( $ scripts , $ this -> calculateCacheSlots ( ) ) ; }
Returns data about cached scripts .
14,985
public function internedStrings ( ) : InternedStrings { $ usageInMb = $ this -> bytesToMb ( $ this -> data [ 'interned_strings_usage' ] [ 'used_memory' ] ?? 0 ) ; $ sizeInMb = $ this -> bytesToMb ( $ this -> data [ 'interned_strings_usage' ] [ 'buffer_size' ] ?? 0 ) ; $ freeInMb = $ this -> bytesToMb ( $ this -> data [ 'interned_strings_usage' ] [ 'free_memory' ] ?? 0 ) ; $ stringCount = $ this -> data [ 'interned_strings_usage' ] [ 'number_of_strings' ] ?? 0 ; return new InternedStrings ( $ usageInMb , $ sizeInMb , $ freeInMb , $ stringCount ) ; }
Returns data about interned strings .
14,986
protected function calculateCacheSlots ( ) { $ cachedScripts = $ this -> data [ 'opcache_statistics' ] [ 'num_cached_scripts' ] ; $ wasted = $ this -> data [ 'opcache_statistics' ] [ 'num_cached_keys' ] - $ cachedScripts ; return new ScriptSlots ( $ cachedScripts , $ this -> data [ 'opcache_statistics' ] [ 'max_cached_keys' ] , $ wasted ) ; }
Calculates cache slot statistics .
14,987
protected function discernIdentifier ( $ cve , $ title ) { $ identifier = $ cve ; if ( ! $ identifier || $ identifier === '~' ) { $ identifier = explode ( ':' , $ title ) ; $ identifier = array_shift ( $ identifier ) ; } $ this -> extend ( 'updateIdentifier' , $ identifier , $ cve , $ title ) ; return $ identifier ; }
Most SilverStripe issued alerts are _not_ assiged CVEs . However they have their own identifier in the form of a prefix to the title - we can use this instead of a CVE ID .
14,988
public function published ( ) { $ class = $ this -> entity -> published ? 'fa fa-check-circle-o' : 'fa fa-circle-o' ; $ state = $ this -> entity -> published ? 'Published' : 'Unpublished' ; return html ( ) -> tag ( 'i' , '' , [ "class" => $ class , "data-toggle" => "tooltip" , "data-title" => $ state ] ) ; }
Publication state .
14,989
public function author ( ) { $ author = ! empty ( $ this -> entity -> author_alias ) ? $ this -> entity -> author_alias : $ this -> entity -> createdByName ; return $ author ?? config ( 'site.author' ) ; }
Get article s author name .
14,990
public function title ( ) { $ heading = null ; if ( session ( ) -> has ( 'active_menu' ) ) { $ heading = session ( 'active_menu' ) -> param ( 'page_heading' ) ; } return $ heading ? $ heading : $ this -> entity -> title ; }
Get the article s title .
14,991
public function introText ( ) { $ body = explode ( '<hr id="system-readmore" />' , $ this -> entity -> body ) ; if ( $ body [ 0 ] === $ this -> entity -> body ) { return '' ; } return $ body [ 0 ] ; }
Get intro text .
14,992
public function image ( ) { if ( $ image = $ this -> articleImage ( ) ) { return $ image ; } if ( $ image = $ this -> introImage ( ) ) { return $ image ; } return config ( 'article.image' ) ; }
Get article intro image .
14,993
public static function setFdToCoId ( int $ fd ) { $ cid = self :: getCoroutineId ( ) ; self :: $ map [ $ cid ] = $ fd ; }
init coId to fd mapping
14,994
public static function delFdByCoId ( int $ cid = null ) : bool { $ cid = $ cid > - 1 ? $ cid : self :: getCoroutineId ( ) ; if ( isset ( self :: $ map [ $ cid ] ) ) { unset ( self :: $ map [ $ cid ] ) ; return true ; } return false ; }
delete coId to fd mapping
14,995
public function findOrFail ( $ id ) { return $ this -> cache -> rememberForever ( 'extension.' . $ id , function ( ) use ( $ id ) { return $ this -> repository -> findOrFail ( $ id ) ; } ) ; }
Find or fail an extension .
14,996
protected function bootAdministratorViewComposer ( ) { view ( ) -> composer ( 'administrator.widgets.*' , function ( View $ view ) { $ themes = $ this -> app [ 'themes' ] ; $ theme = $ themes -> current ( ) ; $ positions = $ theme -> positions ; $ data = [ ] ; foreach ( $ positions as $ position ) { $ data [ $ position ] = Str :: title ( $ position ) ; } $ view -> with ( 'widget_positions' , $ data ) ; $ view -> with ( 'theme' , $ theme ) ; $ extensions = $ this -> app [ 'extensions' ] ; $ widgets = $ extensions -> allWidgets ( ) -> filter ( function ( $ extension ) { return $ extension -> enabled ; } ) ; $ view -> with ( 'extensions' , $ widgets ) ; } ) ; view ( ) -> composer ( [ 'administrator.partials.permissions' ] , function ( View $ view ) { $ view -> with ( 'permissions' , Permission :: orderBy ( 'resource' ) -> get ( ) ) ; } ) ; }
Register administrator view composers .
14,997
public function replaceCssPaths ( array $ links ) { foreach ( $ links as $ key => $ link ) { if ( ! $ this -> isExternalStylesheet ( $ link ) ) { $ links [ $ key ] = $ this -> getUrl ( ) . $ link ; } } return $ links ; }
Replace a given set of links with the proper url if it is an external css file .
14,998
public function backup ( $ task = 'run' ) { if ( ! in_array ( $ task , [ 'run' , 'clean' ] ) ) { $ message = trans ( 'cms::utilities.backup.not_allowed' , [ 'task' => $ task ] ) . trans ( 'cms::utilities.field.executed_by' , [ 'name' => $ this -> getCurrentUserName ( ) ] ) ; $ this -> log -> info ( $ message ) ; return $ this -> notifyError ( $ message ) ; } Artisan :: call ( 'backup:' . $ task ) ; $ message = $ task == 'clean' ? trans ( 'cms::utilities.backup.cleanup_complete' ) : trans ( 'cms::utilities.backup.complete' ) ; $ this -> log -> info ( $ message . trans ( 'cms::utilities.field.executed_by' , [ 'name' => $ this -> getCurrentUserName ( ) ] ) ) ; return $ this -> notifySuccess ( $ message ) ; }
Execute back up manually .
14,999
public function cache ( ) { Artisan :: call ( 'cache:clear' ) ; $ this -> log -> info ( trans ( 'cms::utilities.cache.success' ) . trans ( 'cms::utilities.field.executed_by' , [ 'name' => $ this -> getCurrentUserName ( ) ] ) ) ; return $ this -> notifySuccess ( trans ( 'cms::utilities.cache.success' ) ) ; }
Clear cache manually .