idx int64 0 60.3k | question stringlengths 92 4.62k | target stringlengths 7 635 |
|---|---|---|
22,700 | public static function sortArrayByArray ( array $ array , array $ orderArray ) { $ ordered = array ( ) ; foreach ( $ orderArray as $ key ) { if ( array_key_exists ( $ key , $ array ) ) { $ ordered [ $ key ] = $ array [ $ key ] ; unset ( $ array [ $ key ] ) ; } } return $ ordered + $ array ; } | Sort a multidimensional array by another array of ordered keys |
22,701 | public static function sortArrayByKey ( $ array , $ array_key , $ direction = SORT_DESC , $ sort_flags = SORT_REGULAR ) { $ output = [ ] ; if ( ! is_array ( $ array ) || ! $ array ) { return $ output ; } foreach ( $ array as $ key => $ row ) { $ output [ $ key ] = $ row [ $ array_key ] ; } array_multisort ( $ output , ... | Sort an array by a key value in the array |
22,702 | public static function getPagePathFromToken ( $ path , PageInterface $ page = null ) { $ path_parts = pathinfo ( $ path ) ; $ grav = Grav :: instance ( ) ; $ basename = '' ; if ( isset ( $ path_parts [ 'extension' ] ) ) { $ basename = '/' . $ path_parts [ 'basename' ] ; $ path = rtrim ( $ path_parts [ 'dirname' ] , ':'... | Get s path based on a token |
22,703 | public static function parseSize ( $ size ) { $ unit = preg_replace ( '/[^bkmgtpezy]/i' , '' , $ size ) ; $ size = preg_replace ( '/[^0-9\.]/' , '' , $ size ) ; if ( $ unit ) { $ size = $ size * pow ( 1024 , stripos ( 'bkmgtpezy' , $ unit [ 0 ] ) ) ; } return ( int ) abs ( round ( $ size ) ) ; } | Parse a readable file size and return a value in bytes |
22,704 | public static function multibyteParseUrl ( $ url ) { $ enc_url = preg_replace_callback ( '%[^:/@?&=#]+%usD' , function ( $ matches ) { return urlencode ( $ matches [ 0 ] ) ; } , $ url ) ; $ parts = parse_url ( $ enc_url ) ; if ( $ parts === false ) { throw new \ InvalidArgumentException ( 'Malformed URL: ' . $ url ) ; ... | Multibyte - safe Parse URL function |
22,705 | public static function processMarkdown ( $ string , $ block = true ) { $ page = Grav :: instance ( ) [ 'page' ] ?? null ; $ defaults = Grav :: instance ( ) [ 'config' ] -> get ( 'system.pages.markdown' ) ; if ( $ defaults [ 'extra' ] ) { $ parsedown = new ParsedownExtra ( $ page , $ defaults ) ; } else { $ parsedown = ... | Process a string as markdown |
22,706 | public static function getSubnet ( $ ip , $ prefix = 64 ) { if ( ! filter_var ( $ ip , FILTER_VALIDATE_IP ) ) { throw new \ InvalidArgumentException ( 'Invalid IP: ' . $ ip ) ; } $ ip = inet_pton ( $ ip ) ; $ len = 8 * strlen ( $ ip ) ; if ( $ prefix > $ len ) $ prefix = $ len ; $ mask = str_repeat ( 'f' , $ prefix >> ... | Find the subnet of an ip with CIDR prefix size |
22,707 | public function blueprints ( ) { if ( ! $ this -> blueprints ) { $ this -> blueprints = new Blueprint ; } elseif ( \ is_callable ( $ this -> blueprints ) ) { $ blueprints = $ this -> blueprints ; $ this -> blueprints = $ blueprints ( ) ; } return $ this -> blueprints ; } | Return blueprints . |
22,708 | public function init ( ) { if ( $ this -> initialized ) { return $ this ; } $ this -> grav = Grav :: instance ( ) ; $ this -> config = $ this -> grav [ 'config' ] ; $ this -> enabled = ( bool ) $ this -> config -> get ( 'system.debugger.enabled' ) ; if ( $ this -> enabled ( ) ) { $ this -> initialized = true ; $ plugin... | Initialize the debugger |
22,709 | public function addAssets ( ) { if ( $ this -> enabled ( ) ) { $ page = $ this -> grav [ 'page' ] ; if ( $ page -> templateFormat ( ) !== 'html' ) { return $ this ; } $ assets = $ this -> grav [ 'assets' ] ; $ assets -> add ( 'jquery' , 101 ) ; $ this -> renderer = $ this -> debugbar -> getJavascriptRenderer ( ) ; $ th... | Add the debugger assets to the Grav Assets |
22,710 | public function render ( ) { if ( $ this -> enabled ( ) ) { $ page = $ this -> grav [ 'page' ] ; if ( ! $ this -> renderer || $ page -> templateFormat ( ) !== 'html' ) { return $ this ; } $ this -> addDeprecations ( ) ; echo $ this -> renderer -> render ( ) ; } return $ this ; } | Displays the debug bar |
22,711 | public function getData ( ) { if ( ! $ this -> enabled ( ) ) { return null ; } $ this -> addDeprecations ( ) ; $ this -> timers = [ ] ; return $ this -> debugbar -> getData ( ) ; } | Returns collected debugger data . |
22,712 | public function startTimer ( $ name , $ description = null ) { if ( strpos ( $ name , '_' ) === 0 || $ this -> enabled ( ) ) { $ this -> debugbar [ 'time' ] -> startMeasure ( $ name , $ description ) ; $ this -> timers [ ] = $ name ; } return $ this ; } | Start a timer with an associated name and description |
22,713 | public function stopTimer ( $ name ) { if ( \ in_array ( $ name , $ this -> timers , true ) && ( strpos ( $ name , '_' ) === 0 || $ this -> enabled ( ) ) ) { $ this -> debugbar [ 'time' ] -> stopMeasure ( $ name ) ; } return $ this ; } | Stop the named timer |
22,714 | public function addMessage ( $ message , $ label = 'info' , $ isString = true ) { if ( $ this -> enabled ( ) ) { $ this -> debugbar [ 'messages' ] -> addMessage ( $ message , $ label , $ isString ) ; } return $ this ; } | Dump variables into the Messages tab of the Debug Bar |
22,715 | public function addException ( \ Exception $ e ) { if ( $ this -> initialized && $ this -> enabled ( ) ) { $ this -> debugbar [ 'exceptions' ] -> addException ( $ e ) ; } return $ this ; } | Dump exception into the Messages tab of the Debug Bar |
22,716 | public function delete ( $ username ) : bool { $ user = $ this -> load ( $ username ) ; $ exists = $ user -> exists ( ) ; if ( $ exists ) { $ user -> delete ( ) ; } return $ exists ; } | Delete user account . |
22,717 | public static function groupNames ( ) { $ groups = [ ] ; foreach ( static :: groups ( ) as $ groupname => $ group ) { $ groups [ $ groupname ] = $ group [ 'readableName' ] ?? $ groupname ; } return $ groups ; } | Get the groups list |
22,718 | public static function load ( $ groupname ) { $ groups = self :: groups ( ) ; $ content = $ groups [ $ groupname ] ?? [ ] ; $ content += [ 'groupname' => $ groupname ] ; $ blueprints = new Blueprints ( ) ; $ blueprint = $ blueprints -> get ( 'user/group' ) ; return new Group ( $ content , $ blueprint ) ; } | Get a group by name |
22,719 | public function save ( ) { $ grav = Grav :: instance ( ) ; $ config = $ grav [ 'config' ] ; $ blueprints = new Blueprints ( ) ; $ blueprint = $ blueprints -> get ( 'user/group' ) ; $ config -> set ( "groups.{$this->get('groupname')}" , [ ] ) ; $ fields = $ blueprint -> fields ( ) ; foreach ( $ fields as $ field ) { if ... | Save a group |
22,720 | public static function remove ( $ groupname ) { $ grav = Grav :: instance ( ) ; $ config = $ grav [ 'config' ] ; $ blueprints = new Blueprints ( ) ; $ blueprint = $ blueprints -> get ( 'user/group' ) ; $ type = 'groups' ; $ groups = $ config -> get ( $ type ) ; unset ( $ groups [ $ groupname ] ) ; $ config -> set ( $ t... | Remove a group |
22,721 | public function renderCss ( $ assets , $ group , $ attributes = [ ] ) { $ inline_group = false ; if ( array_key_exists ( 'loading' , $ attributes ) && $ attributes [ 'loading' ] === 'inline' ) { $ inline_group = true ; unset ( $ attributes [ 'loading' ] ) ; } $ this -> attributes = array_merge ( [ 'type' => 'text/css' ... | Minify and concatenate CSS |
22,722 | public function renderJs ( $ assets , $ group , $ attributes = [ ] ) { $ inline_group = false ; if ( array_key_exists ( 'loading' , $ attributes ) && $ attributes [ 'loading' ] === 'inline' ) { $ inline_group = true ; unset ( $ attributes [ 'loading' ] ) ; } $ this -> attributes = $ attributes ; $ json_assets = json_en... | Minify and concatenate JS files . |
22,723 | public function getMediaUri ( ) { $ folder = $ this -> getMediaFolder ( ) ; if ( strpos ( $ folder , '://' ) ) { return $ folder ; } $ locator = Grav :: instance ( ) [ 'locator' ] ; $ user = $ locator -> findResource ( 'user://' ) ; if ( strpos ( $ folder , $ user ) === 0 ) { return 'user://' . substr ( $ folder , \ st... | Get URI ot the associated media . Method will return null if path isn t URI . |
22,724 | public function getMedia ( ) { if ( $ this -> media === null ) { $ cache = $ this -> getMediaCache ( ) ; $ cacheKey = md5 ( 'media' . $ this -> getCacheKey ( ) ) ; if ( ! $ media = $ cache -> get ( $ cacheKey ) ) { $ media = new Media ( $ this -> getMediaFolder ( ) , $ this -> getMediaOrder ( ) ) ; $ cache -> set ( $ c... | Gets the associated media collection . |
22,725 | protected function setMedia ( MediaCollectionInterface $ media ) { $ cache = $ this -> getMediaCache ( ) ; $ cacheKey = md5 ( 'media' . $ this -> getCacheKey ( ) ) ; $ cache -> set ( $ cacheKey , $ media ) ; $ this -> media = $ media ; return $ this ; } | Sets the associated media collection . |
22,726 | protected function clearMediaCache ( ) { $ cache = $ this -> getMediaCache ( ) ; $ cacheKey = md5 ( 'media' . $ this -> getCacheKey ( ) ) ; $ cache -> delete ( $ cacheKey ) ; $ this -> media = null ; } | Clear media cache . |
22,727 | public function modified ( ) { $ path = $ this -> get ( 'filepath' ) ; if ( ! file_exists ( $ path ) ) { return null ; } return filemtime ( $ path ) ? : null ; } | Get file modification time for the medium . |
22,728 | public function addMetaFile ( $ filepath ) { $ this -> metadata = ( array ) CompiledYamlFile :: instance ( $ filepath ) -> content ( ) ; $ this -> merge ( $ this -> metadata ) ; } | Add meta file for the medium . |
22,729 | public function addAlternative ( $ ratio , Medium $ alternative ) { if ( ! is_numeric ( $ ratio ) || $ ratio === 0 ) { return ; } $ alternative -> set ( 'ratio' , $ ratio ) ; $ width = $ alternative -> get ( 'width' ) ; $ this -> alternatives [ $ width ] = $ alternative ; } | Add alternative Medium to this Medium . |
22,730 | public function relativePath ( $ reset = true ) { $ output = preg_replace ( '|^' . preg_quote ( GRAV_ROOT , '|' ) . '|' , '' , $ this -> get ( 'filepath' ) ) ; $ locator = Grav :: instance ( ) [ 'locator' ] ; if ( $ locator -> isStream ( $ output ) ) { $ output = $ locator -> findResource ( $ output , false ) ; } if ( ... | Return the relative path to file |
22,731 | public function url ( $ reset = true ) { $ output = preg_replace ( '|^' . preg_quote ( GRAV_ROOT , '|' ) . '|' , '' , $ this -> get ( 'filepath' ) ) ; $ locator = Grav :: instance ( ) [ 'locator' ] ; if ( $ locator -> isStream ( $ output ) ) { $ output = $ locator -> findResource ( $ output , false ) ; } if ( $ reset )... | Return URL to file . |
22,732 | public function urlQuerystring ( $ url ) { $ querystring = $ this -> querystring ( ) ; if ( isset ( $ this -> timestamp ) && ! Utils :: contains ( $ querystring , $ this -> timestamp ) ) { $ querystring = empty ( $ querystring ) ? ( '?' . $ this -> timestamp ) : ( $ querystring . '&' . $ this -> timestamp ) ; } return ... | Get the URL with full querystring |
22,733 | protected function textParsedownElement ( array $ attributes , $ reset = true ) { $ text = empty ( $ attributes [ 'title' ] ) ? empty ( $ attributes [ 'alt' ] ) ? $ this -> get ( 'filename' ) : $ attributes [ 'alt' ] : $ attributes [ 'title' ] ; $ element = [ 'name' => 'p' , 'attributes' => $ attributes , 'text' => $ t... | Parsedown element for text display mode |
22,734 | public function display ( $ mode = 'source' ) { if ( $ this -> mode === $ mode ) { return $ this ; } $ this -> mode = $ mode ; return $ mode === 'thumbnail' ? ( $ this -> getThumbnail ( ) ? $ this -> getThumbnail ( ) -> reset ( ) : null ) : $ this -> reset ( ) ; } | Switch display mode . |
22,735 | public function thumbnailExists ( $ type = 'page' ) { $ thumbs = $ this -> get ( 'thumbnails' ) ; if ( isset ( $ thumbs [ $ type ] ) ) { return true ; } return false ; } | Helper method to determine if this media item has a thumbnail or not |
22,736 | public function thumbnail ( $ type = 'auto' ) { if ( $ type !== 'auto' && ! \ in_array ( $ type , $ this -> thumbnailTypes , true ) ) { return $ this ; } if ( $ this -> thumbnailType !== $ type ) { $ this -> _thumbnail = null ; } $ this -> thumbnailType = $ type ; return $ this ; } | Switch thumbnail . |
22,737 | protected function getThumbnail ( ) { if ( ! $ this -> _thumbnail ) { $ types = $ this -> thumbnailTypes ; if ( $ this -> thumbnailType !== 'auto' ) { array_unshift ( $ types , $ this -> thumbnailType ) ; } foreach ( $ types as $ type ) { $ thumb = $ this -> get ( 'thumbnails.' . $ type , false ) ; if ( $ thumb ) { $ t... | Get the thumbnail Medium object |
22,738 | public function listFiles ( array $ paths , $ pattern = '|\.yaml$|' , $ levels = - 1 ) { $ list = [ ] ; foreach ( $ paths as $ folder ) { $ list = array_merge_recursive ( $ list , $ this -> detectAll ( $ folder , $ pattern , $ levels ) ) ; } return $ list ; } | Return all paths for all the files with a timestamp . |
22,739 | public function locateFile ( array $ paths , $ name , $ ext = '.yaml' ) { $ filename = preg_replace ( '|[.\/]+|' , '/' , $ name ) . $ ext ; $ list = [ ] ; foreach ( $ paths as $ folder ) { $ path = trim ( Folder :: getRelativePath ( $ folder ) , '/' ) ; if ( is_file ( "{$folder}/{$filename}" ) ) { $ modified = filemtim... | Return all existing locations for a single file with a timestamp . |
22,740 | protected function detectRecursive ( $ folder , $ pattern , $ levels ) { $ path = trim ( Folder :: getRelativePath ( $ folder ) , '/' ) ; if ( is_dir ( $ folder ) ) { $ options = [ 'levels' => $ levels , 'compare' => 'Filename' , 'pattern' => $ pattern , 'filters' => [ 'pre-key' => $ this -> base , 'key' => $ pattern ,... | Detects all directories with a configuration file and returns them with last modification time . |
22,741 | protected function detectInFolder ( $ folder , $ lookup = null ) { $ folder = rtrim ( $ folder , '/' ) ; $ path = trim ( Folder :: getRelativePath ( $ folder ) , '/' ) ; $ base = $ path === $ folder ? '' : ( $ path ? substr ( $ folder , 0 , - strlen ( $ path ) ) : $ folder . '/' ) ; $ list = [ ] ; if ( is_dir ( $ folde... | Detects all directories with the lookup file and returns them with last modification time . |
22,742 | public function resize ( $ width = null , $ height = null ) { $ this -> styleAttributes [ 'width' ] = $ width . 'px' ; $ this -> styleAttributes [ 'height' ] = $ height . 'px' ; return $ this ; } | Resize media by setting attributes |
22,743 | public function addCallable ( string $ name , callable $ callable ) : self { $ this -> container [ $ name ] = $ callable ; array_unshift ( $ this -> middleware , $ name ) ; return $ this ; } | Add callable initializing Middleware that will be executed as soon as possible . |
22,744 | public function addMiddleware ( string $ name , MiddlewareInterface $ middleware ) : self { $ this -> container [ $ name ] = $ middleware ; array_unshift ( $ this -> middleware , $ name ) ; return $ this ; } | Add Middleware that will be executed as soon as possible . |
22,745 | protected function init ( $ page , $ defaults ) { $ grav = Grav :: instance ( ) ; $ this -> page = $ page ; $ this -> BlockTypes [ '{' ] [ ] = 'TwigTag' ; $ this -> special_chars = [ '>' => 'gt' , '<' => 'lt' , '"' => 'quot' ] ; if ( $ defaults === null ) { $ defaults = ( array ) Grav :: instance ( ) [ 'config' ] -> ge... | Initialization function to setup key variables needed by the MarkdownGravLinkTrait |
22,746 | public function addBlockType ( $ type , $ tag , $ continuable = false , $ completable = false , $ index = null ) { $ block = & $ this -> unmarkedBlockTypes ; if ( $ type ) { if ( ! isset ( $ this -> BlockTypes [ $ type ] ) ) { $ this -> BlockTypes [ $ type ] = [ ] ; } $ block = & $ this -> BlockTypes [ $ type ] ; } if ... | Be able to define a new Block type or override an existing one |
22,747 | public function addInlineType ( $ type , $ tag , $ index = null ) { if ( null === $ index || ! isset ( $ this -> InlineTypes [ $ type ] ) ) { $ this -> InlineTypes [ $ type ] [ ] = $ tag ; } else { array_splice ( $ this -> InlineTypes [ $ type ] , $ index , 0 , [ $ tag ] ) ; } if ( strpos ( $ this -> inlineMarkerList ,... | Be able to define a new Inline type or override an existing one |
22,748 | protected function isBlockContinuable ( $ Type ) { $ continuable = \ in_array ( $ Type , $ this -> continuable_blocks ) || method_exists ( $ this , 'block' . $ Type . 'Continue' ) ; return $ continuable ; } | Overrides the default behavior to allow for plugin - provided blocks to be continuable |
22,749 | protected function isBlockCompletable ( $ Type ) { $ completable = \ in_array ( $ Type , $ this -> completable_blocks ) || method_exists ( $ this , 'block' . $ Type . 'Complete' ) ; return $ completable ; } | Overrides the default behavior to allow for plugin - provided blocks to be completable |
22,750 | public function askConfirmationIfMajorVersionUpdated ( $ package ) { $ helper = $ this -> getHelper ( 'question' ) ; $ package_name = $ package -> name ; $ new_version = $ package -> available ? : $ this -> gpm -> getLatestVersionOfPackage ( $ package -> slug ) ; $ old_version = $ package -> version ; $ major_version_c... | If the package is updated from an older major release show warning and ask confirmation |
22,751 | private function processDemo ( $ package ) { $ demo_dir = $ this -> destination . DS . $ package -> install_path . DS . '_demo' ; if ( file_exists ( $ demo_dir ) ) { $ this -> demo_processing [ ] = $ package ; } } | Add package to the queue to process the demo content if demo content exists |
22,752 | private function installDemoContent ( $ package ) { $ demo_dir = $ this -> destination . DS . $ package -> install_path . DS . '_demo' ; if ( file_exists ( $ demo_dir ) ) { $ dest_dir = $ this -> destination . DS . 'user' ; $ pages_dir = $ dest_dir . DS . 'pages' ; $ this -> output -> writeln ( "<white>Attention: </whi... | Prompt to install the demo content of a package |
22,753 | public function path ( $ reset = true ) { $ output = $ this -> saveImage ( ) ; if ( $ reset ) { $ this -> reset ( ) ; } return $ output ; } | Return PATH to image . |
22,754 | public function url ( $ reset = true ) { $ locator = Grav :: instance ( ) [ 'locator' ] ; $ image_path = $ locator -> findResource ( 'cache://images' , true ) ; $ image_dir = $ locator -> findResource ( 'cache://images' , false ) ; $ saved_image_path = $ this -> saveImage ( ) ; $ output = preg_replace ( '|^' . preg_quo... | Return URL to image . |
22,755 | public function srcset ( $ reset = true ) { if ( empty ( $ this -> alternatives ) ) { if ( $ reset ) { $ this -> reset ( ) ; } return '' ; } $ srcset = [ ] ; foreach ( $ this -> alternatives as $ ratio => $ medium ) { $ srcset [ ] = $ medium -> url ( $ reset ) . ' ' . $ medium -> get ( 'width' ) . 'w' ; } $ srcset [ ] ... | Return srcset string for this Medium and its alternatives . |
22,756 | public function setImagePrettyName ( $ name ) { $ this -> set ( 'prettyname' , $ name ) ; if ( $ this -> image ) { $ this -> image -> setPrettyName ( $ name ) ; } } | Allows the ability to override the Inmage s Pretty name stored in cache |
22,757 | public function derivatives ( $ min_width , $ max_width = 2500 , $ step = 200 ) { if ( ! empty ( $ this -> alternatives ) ) { $ max = max ( array_keys ( $ this -> alternatives ) ) ; $ base = $ this -> alternatives [ $ max ] ; } else { $ base = $ this ; } $ widths = [ ] ; if ( func_num_args ( ) === 1 ) { foreach ( ( arr... | Generate alternative image widths using either an array of integers or a min width a max width and a step parameter to fill out the necessary widths . Existing image alternatives won t be overwritten . |
22,758 | public function reset ( ) { parent :: reset ( ) ; if ( $ this -> image ) { $ this -> image ( ) ; $ this -> medium_querystring = [ ] ; $ this -> filter ( ) ; $ this -> clearAlternatives ( ) ; } $ this -> format = 'guess' ; $ this -> quality = $ this -> default_quality ; $ this -> debug_watermarked = false ; return $ thi... | Reset image . |
22,759 | public function quality ( $ quality = null ) { if ( $ quality ) { if ( ! $ this -> image ) { $ this -> image ( ) ; } $ this -> quality = $ quality ; return $ this ; } return $ this -> quality ; } | Sets or gets the quality of the image |
22,760 | public function format ( $ format ) { if ( ! $ this -> image ) { $ this -> image ( ) ; } $ this -> format = $ format ; return $ this ; } | Sets image output format . |
22,761 | public function sizes ( $ sizes = null ) { if ( $ sizes ) { $ this -> sizes = $ sizes ; return $ this ; } return empty ( $ this -> sizes ) ? '100vw' : $ this -> sizes ; } | Set or get sizes parameter for srcset media action |
22,762 | protected function image ( ) { $ locator = Grav :: instance ( ) [ 'locator' ] ; $ file = $ this -> get ( 'filepath' ) ; $ cacheDir = $ locator -> findResource ( 'cache://images' , true ) ? : $ locator -> findResource ( 'cache://images' , true , true ) ; unset ( $ this -> image ) ; $ this -> image = ImageFile :: open ( ... | Gets medium image resets image manipulation operations . |
22,763 | protected function saveImage ( ) { if ( ! $ this -> image ) { return parent :: path ( false ) ; } $ this -> filter ( ) ; if ( isset ( $ this -> result ) ) { return $ this -> result ; } if ( ! $ this -> debug_watermarked && $ this -> get ( 'debug' ) ) { $ ratio = $ this -> get ( 'ratio' ) ; if ( ! $ ratio ) { $ ratio = ... | Save the image with cache . |
22,764 | public function filter ( $ filter = 'image.filters.default' ) { $ filters = ( array ) $ this -> get ( $ filter , [ ] ) ; foreach ( $ filters as $ params ) { $ params = ( array ) $ params ; $ method = array_shift ( $ params ) ; $ this -> __call ( $ method , $ params ) ; } } | Filter image by using user defined filter parameters . |
22,765 | public function higherQualityAlternative ( ) { if ( $ this -> alternatives ) { $ max = reset ( $ this -> alternatives ) ; foreach ( $ this -> alternatives as $ alternative ) { if ( $ alternative -> quality ( ) > $ max -> quality ( ) ) { $ max = $ alternative ; } } return $ max ; } return $ this ; } | Return the image higher quality version |
22,766 | public function loadLocalConfig ( ) { $ home_folder = getenv ( 'HOME' ) ? : getenv ( 'HOMEDRIVE' ) . getenv ( 'HOMEPATH' ) ; $ local_config_file = $ home_folder . '/.grav/config' ; if ( file_exists ( $ local_config_file ) ) { $ file = YamlFile :: instance ( $ local_config_file ) ; $ this -> local_config = $ file -> con... | Load the local config file |
22,767 | public static function validate ( $ value , array $ field ) { if ( ! isset ( $ field [ 'type' ] ) ) { $ field [ 'type' ] = 'text' ; } $ type = $ validate [ 'type' ] ?? $ field [ 'type' ] ; $ validate = ( array ) ( $ field [ 'validate' ] ?? null ) ; $ required = $ validate [ 'required' ] ?? false ; if ( $ required !== t... | Validate value against a blueprint field definition . |
22,768 | public static function filter ( $ value , array $ field ) { $ validate = ( array ) ( $ field [ 'filter' ] ?? $ field [ 'validate' ] ?? null ) ; if ( ( $ value === null || $ value === '' ) && empty ( $ validate [ 'required' ] ) ) { return null ; } if ( ! isset ( $ field [ 'type' ] ) ) { $ field [ 'type' ] = 'text' ; } $... | Filter value against a blueprint field definition . |
22,769 | private function packageExists ( $ slug , $ package ) { $ path = Grav :: instance ( ) [ 'locator' ] -> findResource ( $ package -> package_type . '://' . $ slug ) ; Installer :: isValidDestination ( $ path ) ; return Installer :: lastErrorCode ( ) ; } | Check if package exists |
22,770 | public function objectTail ( $ filepath , $ lines = 1 , $ desc = true ) { $ data = $ this -> tail ( $ filepath , $ lines ) ; $ tailed_log = explode ( PHP_EOL , $ data ) ; $ line_objects = [ ] ; foreach ( $ tailed_log as $ line ) { $ line_objects [ ] = $ this -> parse ( $ line ) ; } return $ desc ? $ line_objects : arra... | Get the objects of a tailed file |
22,771 | public function tail ( $ filepath , $ lines = 1 ) { $ f = @ fopen ( $ filepath , "rb" ) ; if ( $ f === false ) return false ; else $ buffer = ( $ lines < 2 ? 64 : ( $ lines < 10 ? 512 : 4096 ) ) ; fseek ( $ f , - 1 , SEEK_END ) ; if ( fread ( $ f , 1 ) != "\n" ) $ lines -= 1 ; $ output = '' ; $ chunk = '' ; while ( fte... | Optimized way to get just the last few entries of a log file |
22,772 | public function parse ( $ line ) { if ( ! is_string ( $ line ) || strlen ( $ line ) === 0 ) { return array ( ) ; } preg_match ( $ this -> pattern , $ line , $ data ) ; if ( ! isset ( $ data [ 'date' ] ) ) { return array ( ) ; } preg_match ( '/(.*)- Trace:(.*)/' , $ data [ 'message' ] , $ matches ) ; if ( is_array ( $ m... | Parse a monolog row into array bits |
22,773 | public static function parseTrace ( $ trace , $ rows = 10 ) { $ lines = array_filter ( preg_split ( '/#\d*/m' , $ trace ) ) ; return array_slice ( $ lines , 0 , $ rows ) ; } | Parse text of trace into an array of lines |
22,774 | private function gitclone ( ) { $ this -> output -> writeln ( '' ) ; $ this -> output -> writeln ( '<green>Cloning Bits</green>' ) ; $ this -> output -> writeln ( '============' ) ; $ this -> output -> writeln ( '' ) ; foreach ( $ this -> config [ 'git' ] as $ repo => $ data ) { $ this -> destination = rtrim ( $ this -... | Clones from Git |
22,775 | public static function underscorize ( $ word ) { $ regex1 = preg_replace ( '/([A-Z]+)([A-Z][a-z])/' , '\1_\2' , $ word ) ; $ regex2 = preg_replace ( '/([a-zd])([A-Z])/' , '\1_\2' , $ regex1 ) ; $ regex3 = preg_replace ( '/[^A-Z^a-z^0-9]+/' , '_' , $ regex2 ) ; return strtolower ( $ regex3 ) ; } | Converts a word into_it_s_underscored_version |
22,776 | public static function hyphenize ( $ word ) { $ regex1 = preg_replace ( '/([A-Z]+)([A-Z][a-z])/' , '\1-\2' , $ word ) ; $ regex2 = preg_replace ( '/([a-z])([A-Z])/' , '\1-\2' , $ regex1 ) ; $ regex3 = preg_replace ( '/([0-9])([A-Z])/' , '\1-\2' , $ regex2 ) ; $ regex4 = preg_replace ( '/[^A-Z^a-z^0-9]+/' , '-' , $ rege... | Converts a word into - it - s - hyphenated - version |
22,777 | public static function ordinalize ( $ number ) { static :: init ( ) ; if ( \ in_array ( $ number % 100 , range ( 11 , 13 ) , true ) ) { return $ number . static :: $ ordinals [ 'default' ] ; } switch ( $ number % 10 ) { case 1 : return $ number . static :: $ ordinals [ 'first' ] ; case 2 : return $ number . static :: $... | Converts number to its ordinal English form . |
22,778 | public static function monthize ( $ days ) { $ now = new \ DateTime ( ) ; $ end = new \ DateTime ( ) ; $ duration = new \ DateInterval ( "P{$days}D" ) ; $ diff = $ end -> add ( $ duration ) -> diff ( $ now ) ; if ( $ diff -> y > 0 ) { $ diff -> m += 12 * $ diff -> y ; } return $ diff -> m ; } | Converts a number of days to a number of months |
22,779 | public function nth ( $ key ) { $ items = array_keys ( $ this -> items ) ; return isset ( $ items [ $ key ] ) ? $ this -> offsetGet ( $ items [ $ key ] ) : false ; } | Return nth item . |
22,780 | public function random ( $ num = 1 ) { $ count = \ count ( $ this -> items ) ; if ( $ num > $ count ) { $ num = $ count ; } $ this -> items = array_intersect_key ( $ this -> items , array_flip ( ( array ) array_rand ( $ this -> items , $ num ) ) ) ; return $ this ; } | Pick one or more random entries . |
22,781 | public function append ( $ items ) { if ( $ items instanceof static ) { $ items = $ items -> toArray ( ) ; } $ this -> items = array_merge ( $ this -> items , ( array ) $ items ) ; return $ this ; } | Append new elements to the list . |
22,782 | public function filter ( callable $ callback = null ) { foreach ( $ this -> items as $ key => $ value ) { if ( ( ! $ callback && ! ( bool ) $ value ) || ( $ callback && ! $ callback ( $ value , $ key ) ) ) { unset ( $ this -> items [ $ key ] ) ; } } return $ this ; } | Filter elements from the list |
22,783 | public function sort ( callable $ callback = null , $ desc = false ) { if ( ! $ callback || ! \ is_callable ( $ callback ) ) { return $ this ; } $ items = $ this -> items ; uasort ( $ items , $ callback ) ; return ! $ desc ? $ items : array_reverse ( $ items , true ) ; } | Sorts elements from the list and returns a copy of the list in the proper order |
22,784 | public function authenticate ( string $ password ) : bool { $ hash = $ this -> get ( 'hashed_password' ) ; $ isHashed = null !== $ hash ; if ( ! $ isHashed ) { $ hash = Grav :: instance ( ) [ 'config' ] -> get ( 'system.security.default_hash' ) ; } $ result = Authentication :: verify ( $ password , $ hash ) && $ isHash... | Authenticate user . |
22,785 | public function authorize ( string $ action , string $ scope = null ) : bool { if ( ! $ this -> get ( 'authenticated' ) ) { return false ; } if ( $ this -> get ( 'state' , 'enabled' ) !== 'enabled' ) { return false ; } if ( null !== $ scope ) { $ action = $ scope . '.' . $ action ; } $ config = Grav :: instance ( ) [ '... | Checks user authorization to the action . |
22,786 | public function getAvatarImage ( ) : ? ImageMedium { $ avatars = $ this -> get ( 'avatar' ) ; if ( \ is_array ( $ avatars ) && $ avatars ) { $ avatar = array_shift ( $ avatars ) ; $ media = $ this -> getMedia ( ) ; $ name = $ avatar [ 'name' ] ?? null ; $ image = $ name ? $ media [ $ name ] : null ; if ( $ image instan... | Return media object for the User s avatar . |
22,787 | public function getAvatarUrl ( ) : string { $ avatar = $ this -> getAvatarImage ( ) ; if ( $ avatar ) { return $ avatar -> url ( ) ; } $ avatar = $ this -> get ( 'avatar' ) ; if ( \ is_string ( $ avatar ) ) { return $ avatar ; } $ provider = $ this -> get ( 'provider' ) ; $ provider_options = $ this -> get ( $ provider... | Return the User s avatar URL |
22,788 | public static function truncateWords ( $ html , $ limit = 0 , $ ellipsis = '' ) { if ( $ limit <= 0 ) { return $ html ; } $ doc = self :: htmlToDomDocument ( $ html ) ; $ container = $ doc -> getElementsByTagName ( 'div' ) -> item ( 0 ) ; $ container = $ container -> parentNode -> removeChild ( $ container ) ; $ words ... | Safely truncates HTML by a given number of words . |
22,789 | public static function truncateLetters ( $ html , $ limit = 0 , $ ellipsis = '' ) { if ( $ limit <= 0 ) { return $ html ; } $ doc = self :: htmlToDomDocument ( $ html ) ; $ container = $ doc -> getElementsByTagName ( 'div' ) -> item ( 0 ) ; $ container = $ container -> parentNode -> removeChild ( $ container ) ; $ lett... | Safely truncates HTML by a given number of letters . |
22,790 | public static function htmlToDomDocument ( $ html ) { if ( ! $ html ) { $ html = '' ; } $ html = mb_convert_encoding ( $ html , 'HTML-ENTITIES' , 'UTF-8' ) ; libxml_use_internal_errors ( true ) ; $ dom = new DOMDocument ( ) ; $ dom -> encoding = 'UTF-8' ; $ dom -> loadHTML ( "<div>$html</div>" ) ; return $ dom ; } | Builds a DOMDocument object from a string containing HTML . |
22,791 | private static function removeProceedingNodes ( $ domNode , $ topNode ) { $ nextNode = $ domNode -> nextSibling ; if ( $ nextNode !== null ) { self :: removeProceedingNodes ( $ nextNode , $ topNode ) ; $ domNode -> parentNode -> removeChild ( $ nextNode ) ; } else { $ curNode = $ domNode -> parentNode ; while ( $ curNo... | Removes all nodes after the current node . |
22,792 | private static function getCleanedHTML ( DOMDocument $ doc , $ container ) { while ( $ doc -> firstChild ) { $ doc -> removeChild ( $ doc -> firstChild ) ; } while ( $ container -> firstChild ) { $ doc -> appendChild ( $ container -> firstChild ) ; } $ html = trim ( $ doc -> saveHTML ( ) ) ; return $ html ; } | Clean extra code |
22,793 | private static function insertEllipsis ( $ domNode , $ ellipsis ) { $ avoid = array ( 'a' , 'strong' , 'em' , 'h1' , 'h2' , 'h3' , 'h4' , 'h5' ) ; if ( $ domNode -> parentNode -> parentNode !== null && in_array ( $ domNode -> parentNode -> nodeName , $ avoid , true ) ) { $ textNode = new DOMText ( $ ellipsis ) ; if ( $... | Inserts an ellipsis |
22,794 | public static function fromFile ( $ file , array $ params = [ ] ) { if ( ! file_exists ( $ file ) ) { return null ; } $ parts = pathinfo ( $ file ) ; $ path = $ parts [ 'dirname' ] ; $ filename = $ parts [ 'basename' ] ; $ ext = $ parts [ 'extension' ] ; $ basename = $ parts [ 'filename' ] ; $ config = Grav :: instance... | Create Medium from a file |
22,795 | public static function fromUploadedFile ( FormFlashFile $ uploadedFile , array $ params = [ ] ) { $ parts = pathinfo ( $ uploadedFile -> getClientFilename ( ) ) ; $ filename = $ parts [ 'basename' ] ; $ ext = $ parts [ 'extension' ] ; $ basename = $ parts [ 'filename' ] ; $ file = $ uploadedFile -> getTmpFile ( ) ; $ p... | Create Medium from an uploaded file |
22,796 | public static function fromArray ( array $ items = [ ] , Blueprint $ blueprint = null ) { $ type = $ items [ 'type' ] ?? null ; switch ( $ type ) { case 'image' : return new ImageMedium ( $ items , $ blueprint ) ; case 'thumbnail' : return new ThumbnailImageMedium ( $ items , $ blueprint ) ; case 'animated' : case 'vec... | Create Medium from array of parameters |
22,797 | public static function scaledFromMedium ( $ medium , $ from , $ to ) { if ( ! $ medium instanceof ImageMedium ) { return $ medium ; } if ( $ to > $ from ) { return $ medium ; } $ ratio = $ to / $ from ; $ width = $ medium -> get ( 'width' ) * $ ratio ; $ height = $ medium -> get ( 'height' ) * $ ratio ; $ prev_basename... | Create a new ImageMedium by scaling another ImageMedium object . |
22,798 | public function init ( ) { $ default = $ this -> config -> get ( 'system.languages.default_lang' ) ; if ( isset ( $ default ) && $ this -> validate ( $ default ) ) { $ this -> default = $ default ; } else { $ this -> default = reset ( $ this -> languages ) ; } $ this -> page_extensions = null ; if ( empty ( $ this -> l... | Initialize the default and enabled languages |
22,799 | public function getAvailable ( ) { $ languagesArray = $ this -> languages ; $ languagesArray = array_map ( function ( $ value ) { return preg_quote ( $ value ) ; } , $ languagesArray ) ; sort ( $ languagesArray ) ; return implode ( '|' , array_reverse ( $ languagesArray ) ) ; } | Gets a pipe - separated string of available languages |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.