idx int64 0 60.3k | question stringlengths 92 4.62k | target stringlengths 7 635 |
|---|---|---|
22,600 | public function group ( $ property , $ separator = null ) { $ list = [ ] ; foreach ( $ this -> getIterator ( ) as $ element ) { $ list [ ( string ) $ element -> getNestedProperty ( $ property , null , $ separator ) ] [ ] = $ element ; } return $ list ; } | Group items in the collection by a field . |
22,601 | public function getInstallable ( $ list_type_installed = [ 'plugins' => true , 'themes' => true ] ) { $ items = [ 'total' => 0 ] ; foreach ( $ list_type_installed as $ type => $ type_installed ) { if ( $ type_installed === false ) { continue ; } $ methodInstallableType = 'getInstalled' . ucfirst ( $ type ) ; $ to_insta... | Returns the Locally installable packages |
22,602 | public function getInstalledPackage ( $ slug ) { if ( isset ( $ this -> installed [ 'plugins' ] [ $ slug ] ) ) { return $ this -> installed [ 'plugins' ] [ $ slug ] ; } if ( isset ( $ this -> installed [ 'themes' ] [ $ slug ] ) ) { return $ this -> installed [ 'themes' ] [ $ slug ] ; } return null ; } | Return the instance of a specific Package |
22,603 | public function countUpdates ( ) { $ count = 0 ; $ count += count ( $ this -> getUpdatablePlugins ( ) ) ; $ count += count ( $ this -> getUpdatableThemes ( ) ) ; return $ count ; } | Returns the amount of updates available |
22,604 | public function getUpdatable ( $ list_type_update = [ 'plugins' => true , 'themes' => true ] ) { $ items = [ 'total' => 0 ] ; foreach ( $ list_type_update as $ type => $ type_updatable ) { if ( $ type_updatable === false ) { continue ; } $ methodUpdatableType = 'getUpdatable' . ucfirst ( $ type ) ; $ to_update = $ this... | Returns an array of Plugins and Themes that can be updated . Plugins and Themes are extended with the available property that relies to the remote version |
22,605 | public function getUpdatableThemes ( ) { $ items = [ ] ; $ repository = $ this -> repository [ 'themes' ] ; if ( isset ( $ this -> cache [ __METHOD__ ] ) ) { return $ this -> cache [ __METHOD__ ] ; } foreach ( $ this -> installed [ 'themes' ] as $ slug => $ plugin ) { if ( ! isset ( $ repository [ $ slug ] ) || $ plugi... | Returns an array of Themes that can be updated . The Themes are extended with the available property that relies to the remote version |
22,606 | public function findPackage ( $ search , $ ignore_exception = false ) { $ search = strtolower ( $ search ) ; $ found = $ this -> getRepositoryTheme ( $ search ) ; if ( $ found ) { return $ found ; } $ found = $ this -> getRepositoryPlugin ( $ search ) ; if ( $ found ) { return $ found ; } $ themes = $ this -> getReposi... | Searches for a Package in the repository |
22,607 | public static function downloadPackage ( $ package_file , $ tmp ) { $ package = parse_url ( $ package_file ) ; $ filename = basename ( $ package [ 'path' ] ) ; if ( Grav :: instance ( ) [ 'config' ] -> get ( 'system.gpm.official_gpm_only' ) && $ package [ 'host' ] !== 'getgrav.org' ) { throw new \ RuntimeException ( "O... | Download the zip package via the URL |
22,608 | public static function copyPackage ( $ package_file , $ tmp ) { $ package_file = realpath ( $ package_file ) ; if ( file_exists ( $ package_file ) ) { $ filename = basename ( $ package_file ) ; Folder :: create ( $ tmp ) ; copy ( realpath ( $ package_file ) , $ tmp . DS . $ filename ) ; return $ tmp . DS . $ filename ;... | Copy the local zip package to tmp |
22,609 | public static function getPackageType ( $ source ) { $ plugin_regex = '/^class\\s{1,}[a-zA-Z0-9]{1,}\\s{1,}extends.+Plugin/m' ; $ theme_regex = '/^class\\s{1,}[a-zA-Z0-9]{1,}\\s{1,}extends.+Theme/m' ; if ( file_exists ( $ source . 'system/defines.php' ) && file_exists ( $ source . 'system/config/system.yaml' ) ) { retu... | Try to guess the package type from the source files |
22,610 | public static function getPackageName ( $ source ) { $ ignore_yaml_files = [ 'blueprints' , 'languages' ] ; foreach ( glob ( $ source . '*.yaml' ) as $ filename ) { $ name = strtolower ( basename ( $ filename , '.yaml' ) ) ; if ( in_array ( $ name , $ ignore_yaml_files ) ) { continue ; } return $ name ; } return false ... | Try to guess the package name from the source files |
22,611 | public static function getInstallPath ( $ type , $ name ) { $ locator = Grav :: instance ( ) [ 'locator' ] ; if ( $ type === 'theme' ) { $ install_path = $ locator -> findResource ( 'themes://' , false ) . DS . $ name ; } else { $ install_path = $ locator -> findResource ( 'plugins://' , false ) . DS . $ name ; } retur... | Get the install path for a name and a particular type of package |
22,612 | public function findPackages ( $ searches = [ ] ) { $ packages = [ 'total' => 0 , 'not_found' => [ ] ] ; $ inflector = new Inflector ( ) ; foreach ( $ searches as $ search ) { $ repository = '' ; if ( is_object ( $ search ) ) { $ search = ( array ) $ search ; $ key = key ( $ search ) ; $ repository = $ search [ $ key ]... | Searches for a list of Packages in the repository |
22,613 | public function getPackagesThatDependOnPackage ( $ slug ) { $ plugins = $ this -> getInstalledPlugins ( ) ; $ themes = $ this -> getInstalledThemes ( ) ; $ packages = array_merge ( $ plugins -> toArray ( ) , $ themes -> toArray ( ) ) ; $ dependent_packages = [ ] ; foreach ( $ packages as $ package_name => $ package ) {... | Return the list of packages that have the passed one as dependency |
22,614 | public function getVersionOfDependencyRequiredByPackage ( $ package_slug , $ dependency_slug ) { $ dependencies = $ this -> getInstalledPackage ( $ package_slug ) -> dependencies ; foreach ( $ dependencies as $ dependency ) { if ( isset ( $ dependency [ $ dependency_slug ] ) ) { return $ dependency [ $ dependency_slug ... | Get the required version of a dependency of a package |
22,615 | public function checkPackagesCanBeInstalled ( $ packages_names_list ) { foreach ( $ packages_names_list as $ package_name ) { $ this -> checkNoOtherPackageNeedsThisDependencyInALowerVersion ( $ package_name , $ this -> getLatestVersionOfPackage ( $ package_name ) , $ packages_names_list ) ; } } | Check the passed packages list can be updated |
22,616 | private function calculateMergedDependenciesOfPackage ( $ packageName , $ dependencies ) { $ packageData = $ this -> findPackage ( $ packageName ) ; if ( isset ( $ packageData -> dependencies ) ) { foreach ( $ packageData -> dependencies as $ dependency ) { $ current_package_name = $ dependency [ 'name' ] ; if ( isset ... | Calculates and merges the dependencies of a package |
22,617 | public function calculateMergedDependenciesOfPackages ( $ packages ) { $ dependencies = [ ] ; foreach ( $ packages as $ package ) { $ dependencies = $ this -> calculateMergedDependenciesOfPackage ( $ package , $ dependencies ) ; } return $ dependencies ; } | Calculates and merges the dependencies of the passed packages |
22,618 | public function checkNextSignificantReleasesAreCompatible ( $ version1 , $ version2 ) { $ version1array = explode ( '.' , $ version1 ) ; $ version2array = explode ( '.' , $ version2 ) ; if ( \ count ( $ version1array ) > \ count ( $ version2array ) ) { list ( $ version1array , $ version2array ) = [ $ version2array , $ ... | Check if two releases are compatible by next significant release |
22,619 | public function fieldNameFilter ( $ str ) { $ path = explode ( '.' , rtrim ( $ str , '.' ) ) ; return array_shift ( $ path ) . ( $ path ? '[' . implode ( '][' , $ path ) . ']' : '' ) ; } | Filters field name by changing dot notation into array notation . |
22,620 | public function safeEmailFilter ( $ str ) { $ email = '' ; for ( $ i = 0 , $ len = strlen ( $ str ) ; $ i < $ len ; $ i ++ ) { $ j = random_int ( 0 , 1 ) ; $ email .= $ j === 0 ? '&#' . ord ( $ str [ $ i ] ) . ';' : $ str [ $ i ] ; } return str_replace ( '@' , '@' , $ email ) ; } | Protects email address . |
22,621 | public function randomizeFilter ( $ original , $ offset = 0 ) { if ( ! \ is_array ( $ original ) ) { return $ original ; } if ( $ original instanceof \ Traversable ) { $ original = iterator_to_array ( $ original , false ) ; } $ sorted = [ ] ; $ random = array_slice ( $ original , $ offset ) ; shuffle ( $ random ) ; $ s... | Returns array in a random order . |
22,622 | public function modulusFilter ( $ number , $ divider , $ items = null ) { if ( \ is_string ( $ number ) ) { $ number = strlen ( $ number ) ; } $ remainder = $ number % $ divider ; if ( \ is_array ( $ items ) ) { return $ items [ $ remainder ] ?? $ items [ 0 ] ; } return $ remainder ; } | Returns the modulus of an integer |
22,623 | public function sortByKeyFilter ( $ input , $ filter , $ direction = SORT_ASC , $ sort_flags = SORT_REGULAR ) { return Utils :: sortArrayByKey ( $ input , $ filter , $ direction , $ sort_flags ) ; } | Sorts a collection by key |
22,624 | public function containsFilter ( $ haystack , $ needle ) { if ( empty ( $ needle ) ) { return $ haystack ; } return ( strpos ( $ haystack , ( string ) $ needle ) !== false ) ; } | determine if a string contains another |
22,625 | public function xssFunc ( $ data ) { if ( ! \ is_array ( $ data ) ) { return Security :: detectXss ( $ data ) ; } $ results = Security :: detectXssFromArray ( $ data ) ; $ results_parts = array_map ( function ( $ value , $ key ) { return $ key . ': \'' . $ value . '\'' ; } , array_values ( $ results ) , array_keys ( $ ... | Allow quick check of a string for XSS Vulnerabilities |
22,626 | public function gistFunc ( $ id , $ file = false ) { $ url = 'https://gist.github.com/' . $ id . '.js' ; if ( $ file ) { $ url .= '?file=' . $ file ; } return '<script src="' . $ url . '"></script>' ; } | Output a Gist |
22,627 | public function arrayKeyValueFunc ( $ key , $ val , $ current_array = null ) { if ( empty ( $ current_array ) ) { return array ( $ key => $ val ) ; } $ current_array [ $ key ] = $ val ; return $ current_array ; } | Workaround for twig associative array initialization Returns a key = > val array |
22,628 | public function jsonDecodeFilter ( $ str , $ assoc = false , $ depth = 512 , $ options = 0 ) { return json_decode ( html_entity_decode ( $ str ) , $ assoc , $ depth , $ options ) ; } | Decodes string from JSON . |
22,629 | public function regexReplace ( $ subject , $ pattern , $ replace , $ limit = - 1 ) { return preg_replace ( $ pattern , $ replace , $ subject , $ limit ) ; } | Twig wrapper for PHP s preg_replace method |
22,630 | public function exifFunc ( $ image , $ raw = false ) { if ( isset ( $ this -> grav [ 'exif' ] ) ) { $ locator = $ this -> grav [ 'locator' ] ; if ( $ locator -> isStream ( $ image ) ) { $ image = $ locator -> findResource ( $ image ) ; } $ exif_reader = $ this -> grav [ 'exif' ] -> getReader ( ) ; if ( $ image & file_e... | Get s the Exif data for a file |
22,631 | public function readFileFunc ( $ filepath ) { $ locator = $ this -> grav [ 'locator' ] ; if ( $ locator -> isStream ( $ filepath ) ) { $ filepath = $ locator -> findResource ( $ filepath ) ; } if ( $ filepath && file_exists ( $ filepath ) ) { return file_get_contents ( $ filepath ) ; } return false ; } | Simple function to read a file based on a filepath and output it |
22,632 | public function mediaDirFunc ( $ media_dir ) { $ locator = $ this -> grav [ 'locator' ] ; if ( $ locator -> isStream ( $ media_dir ) ) { $ media_dir = $ locator -> findResource ( $ media_dir ) ; } if ( $ media_dir && file_exists ( $ media_dir ) ) { return new Media ( $ media_dir ) ; } return null ; } | Process a folder as Media and return a media object |
22,633 | public function niceNumberFunc ( $ n ) { if ( ! \ is_float ( $ n ) && ! \ is_int ( $ n ) ) { if ( ! \ is_string ( $ n ) || $ n === '' ) { return false ; } $ list = array_filter ( preg_split ( "/\D+/" , str_replace ( ',' , '' , $ n ) ) ) ; $ n = reset ( $ list ) ; if ( ! \ is_numeric ( $ n ) ) { return false ; } $ n = (... | Returns a nicer more readable number |
22,634 | public function themeVarFunc ( $ var , $ default = null ) { $ header = $ this -> grav [ 'page' ] -> header ( ) ; $ header_classes = $ header -> { $ var } ?? null ; return $ header_classes ? : $ this -> config -> get ( 'theme.' . $ var , $ default ) ; } | Get a theme variable |
22,635 | public function bodyClassFunc ( $ classes ) { $ header = $ this -> grav [ 'page' ] -> header ( ) ; $ body_classes = $ header -> body_classes ?? '' ; foreach ( ( array ) $ classes as $ class ) { if ( ! empty ( $ body_classes ) && Utils :: contains ( $ body_classes , $ class ) ) { continue ; } $ val = $ this -> config ->... | takes an array of classes and if they are not set on body_classes look to see if they are set in theme config |
22,636 | public function pageHeaderVarFunc ( $ var , $ pages = null ) { if ( $ pages === null ) { $ pages = $ this -> grav [ 'page' ] ; } if ( ! \ is_array ( $ pages ) ) { $ pages = [ $ pages ] ; } foreach ( $ pages as $ page ) { if ( \ is_string ( $ page ) ) { $ page = $ this -> grav [ 'pages' ] -> find ( $ page ) ; } if ( $ p... | Look for a page header variable in an array of pages working its way through until a value is found |
22,637 | public function getChangelog ( $ diff = null ) { if ( ! $ diff ) { return $ this -> data [ 'changelog' ] ; } $ diffLog = [ ] ; foreach ( ( array ) $ this -> data [ 'changelog' ] as $ version => $ changelog ) { preg_match ( "/[\w\-\.]+/" , $ version , $ cleanVersion ) ; if ( ! $ cleanVersion || version_compare ( $ diff ... | Returns the changelog list for each version of Grav |
22,638 | public function isDue ( \ DateTime $ date = null ) { if ( ! $ this -> executionTime ) { $ this -> at ( '* * * * *' ) ; } $ date = $ date ?? $ this -> creationTime ; return $ this -> executionTime -> isDue ( $ date ) ; } | Check if the Job is due to run . It accepts as input a DateTime used to check if the job is due . Defaults to job creation time . It also default the execution time if not previously defined . |
22,639 | public function isOverlapping ( ) { return $ this -> lockFile && file_exists ( $ this -> lockFile ) && call_user_func ( $ this -> whenOverlapping , filemtime ( $ this -> lockFile ) ) === false ; } | Check if the Job is overlapping . |
22,640 | public function onlyOne ( $ tempDir = null , callable $ whenOverlapping = null ) { if ( $ tempDir === null || ! is_dir ( $ tempDir ) ) { $ tempDir = $ this -> tempDir ; } $ this -> lockFile = implode ( '/' , [ trim ( $ tempDir ) , trim ( $ this -> id ) . '.lock' , ] ) ; if ( $ whenOverlapping ) { $ this -> whenOverlapp... | This will prevent the Job from overlapping . It prevents another instance of the same Job of being executed if the previous is still running . The job id is used as a filename for the lock file . |
22,641 | public function finalize ( ) { $ process = $ this -> process ; if ( $ process ) { $ process -> wait ( ) ; if ( $ process -> isSuccessful ( ) ) { $ this -> successful = true ; $ this -> output = $ process -> getOutput ( ) ; } else { $ this -> successful = false ; $ this -> output = $ process -> getErrorOutput ( ) ; } $ ... | Finish up processing the job |
22,642 | private function postRun ( ) { if ( count ( $ this -> outputTo ) > 0 ) { foreach ( $ this -> outputTo as $ file ) { $ output_mode = $ this -> outputMode === 'append' ? FILE_APPEND | LOCK_EX : LOCK_EX ; file_put_contents ( $ file , $ this -> output , $ output_mode ) ; } } $ this -> emailOutput ( ) ; if ( is_callable ( $... | Things to run after job has run |
22,643 | public function then ( callable $ fn , $ runInBackground = false ) { $ this -> after = $ fn ; if ( $ runInBackground === false ) { $ this -> inForeground ( ) ; } return $ this ; } | Set a function to be called after job execution . By default this will force the job to run in foreground because the output is injected as a parameter of this function but it could be avoided by passing true as a second parameter . The job will run in background if it meets all the other criteria . |
22,644 | public function join ( $ name , $ value , $ separator = null ) { $ separator = $ separator ?? '.' ; $ old = $ this -> get ( $ name , null , $ separator ) ; if ( $ old !== null ) { if ( ! \ is_array ( $ old ) ) { throw new \ RuntimeException ( 'Value ' . $ old ) ; } if ( \ is_object ( $ value ) ) { $ value = ( array ) $... | Join nested values together by using blueprints . |
22,645 | public function monthly ( $ month = '*' , $ day = 1 , $ hour = 0 , $ minute = 0 ) { if ( \ is_string ( $ hour ) ) { $ parts = explode ( ':' , $ hour ) ; $ hour = $ parts [ 0 ] ; $ minute = $ parts [ 1 ] ?? '0' ; } $ c = $ this -> validateCronSequence ( $ minute , $ hour , $ day , $ month ) ; return $ this -> at ( "{$c[... | Set the execution time to once a month . |
22,646 | public function getIndex ( array $ keys = null , string $ keyField = null ) : FlexIndexInterface { $ index = clone $ this -> loadIndex ( ) ; $ index = $ index -> withKeyField ( $ keyField ) ; if ( null !== $ keys ) { $ index = $ index -> select ( $ keys ) ; } return $ index -> getIndex ( ) ; } | Get the full collection of all stored objects . |
22,647 | public function getObject ( $ key , string $ keyField = null ) : ? FlexObjectInterface { return $ this -> getIndex ( null , $ keyField ) -> get ( $ key ) ; } | Returns an object if it exists . |
22,648 | public static function processImageHtml ( $ html , PageInterface $ page ) { $ excerpt = static :: getExcerptFromHtml ( $ html , 'img' ) ; $ original_src = $ excerpt [ 'element' ] [ 'attributes' ] [ 'src' ] ; $ excerpt [ 'element' ] [ 'attributes' ] [ 'href' ] = $ original_src ; $ excerpt = static :: processLinkExcerpt ... | Process Grav image media URL from HTML tag |
22,649 | public static function getExcerptFromHtml ( $ html , $ tag ) { $ doc = new \ DOMDocument ( ) ; $ doc -> loadHTML ( $ html ) ; $ images = $ doc -> getElementsByTagName ( $ tag ) ; $ excerpt = null ; foreach ( $ images as $ image ) { $ attributes = [ ] ; foreach ( $ image -> attributes as $ name => $ value ) { $ attribut... | Get an Excerpt array from a chunk of HTML |
22,650 | public static function getHtmlFromExcerpt ( $ excerpt ) { $ element = $ excerpt [ 'element' ] ; $ html = '<' . $ element [ 'name' ] ; if ( isset ( $ element [ 'attributes' ] ) ) { foreach ( $ element [ 'attributes' ] as $ name => $ value ) { if ( $ value === null ) { continue ; } $ html .= ' ' . $ name . '="' . $ value... | Rebuild HTML tag from an excerpt array |
22,651 | public static function processLinkExcerpt ( $ excerpt , PageInterface $ page , $ type = 'link' ) { $ url = htmlspecialchars_decode ( rawurldecode ( $ excerpt [ 'element' ] [ 'attributes' ] [ 'href' ] ) ) ; $ url_parts = static :: parseUrl ( $ url ) ; if ( isset ( $ url_parts [ 'query' ] ) ) { $ actions = array_reduce (... | Process a Link excerpt |
22,652 | public static function processImageExcerpt ( array $ excerpt , PageInterface $ page ) { $ url = htmlspecialchars_decode ( urldecode ( $ excerpt [ 'element' ] [ 'attributes' ] [ 'src' ] ) ) ; $ url_parts = static :: parseUrl ( $ url ) ; $ media = null ; $ filename = null ; if ( ! empty ( $ url_parts [ 'stream' ] ) ) { $... | Process an image excerpt |
22,653 | public static function processMediaActions ( $ medium , $ url ) { if ( ! is_array ( $ url ) ) { $ url_parts = parse_url ( $ url ) ; } else { $ url_parts = $ url ; } $ actions = [ ] ; if ( isset ( $ url_parts [ 'query' ] ) ) { $ actions = array_reduce ( explode ( '&' , $ url_parts [ 'query' ] ) , function ( $ carry , $ ... | Process media actions |
22,654 | public static function getSubscribedEvents ( ) { $ methods = get_class_methods ( get_called_class ( ) ) ; $ list = [ ] ; foreach ( $ methods as $ method ) { if ( strpos ( $ method , 'on' ) === 0 ) { $ list [ $ method ] = [ $ method , 0 ] ; } } return $ list ; } | By default assign all methods as listeners using the default priority . |
22,655 | protected function isPluginActiveAdmin ( $ plugin_route ) { $ should_run = false ; $ uri = $ this -> grav [ 'uri' ] ; if ( strpos ( $ uri -> path ( ) , $ this -> config -> get ( 'plugins.admin.route' ) . '/' . $ plugin_route ) === false ) { $ should_run = false ; } elseif ( isset ( $ uri -> paths ( ) [ 1 ] ) && $ uri -... | Determine if this route is in Admin and active for the plugin |
22,656 | protected function mergeConfig ( PageInterface $ page , $ deep = false , $ params = [ ] , $ type = 'plugins' ) { $ class_name = $ this -> name ; $ class_name_merged = $ class_name . '.merged' ; $ defaults = $ this -> config -> get ( $ type . '.' . $ class_name , [ ] ) ; $ page_header = $ page -> header ( ) ; $ header =... | Merge global and page configurations . |
22,657 | private function mergeArrays ( $ deep , $ array1 , $ array2 ) { if ( $ deep === 'merge' ) { return Utils :: arrayMergeRecursiveUnique ( $ array1 , $ array2 ) ; } if ( $ deep === true ) { return array_replace_recursive ( $ array1 , $ array2 ) ; } return array_merge ( $ array1 , $ array2 ) ; } | Merge arrays based on deepness |
22,658 | protected function loadBlueprint ( ) { if ( ! $ this -> blueprint ) { $ grav = Grav :: instance ( ) ; $ plugins = $ grav [ 'plugins' ] ; $ this -> blueprint = $ plugins -> get ( $ this -> name ) -> blueprints ( ) ; } } | Load blueprints . |
22,659 | public static function filterUserInfo ( $ info ) { if ( ! \ is_string ( $ info ) ) { throw new \ InvalidArgumentException ( 'Uri user info must be a string' ) ; } return preg_replace_callback ( '/(?:[^a-zA-Z0-9_\-\.~!\$&\'\(\)\*\+,;=]+|%(?![A-Fa-f0-9]{2}))/u' , function ( $ match ) { return rawurlencode ( $ match [ 0 ]... | Filters the user info string . |
22,660 | public function html ( $ title = null , $ alt = null , $ class = null , $ id = null , $ reset = true ) { $ element = $ this -> parsedownElement ( $ title , $ alt , $ class , $ id , $ reset ) ; if ( ! $ this -> parsedown ) { $ this -> parsedown = new Parsedown ( null , null ) ; } return $ this -> parsedown -> elementToH... | Return HTML markup from the medium . |
22,661 | public function preload ( $ status = null ) { if ( $ status ) { $ this -> attributes [ 'preload' ] = $ status ; } else { unset ( $ this -> attributes [ 'preload' ] ) ; } return $ this ; } | Allows ability to set the preload option |
22,662 | public function playsinline ( $ status = false ) { if ( $ status ) { $ this -> attributes [ 'playsinline' ] = true ; } else { unset ( $ this -> attributes [ 'playsinline' ] ) ; } return $ this ; } | Allows to set the playsinline attribute |
22,663 | public function getDefaults ( ) { $ this -> initInternals ( ) ; if ( null === $ this -> defaults ) { $ this -> defaults = $ this -> blueprintSchema -> getDefaults ( ) ; } return $ this -> defaults ; } | Get nested structure containing default values defined in the blueprints . |
22,664 | public function processForm ( array $ data , array $ toggles = [ ] ) { $ this -> initInternals ( ) ; return $ this -> blueprintSchema -> processForm ( $ data , $ toggles ) ; } | Process data coming from a form . |
22,665 | protected function initInternals ( ) { if ( null === $ this -> blueprintSchema ) { $ types = Grav :: instance ( ) [ 'plugins' ] -> formFieldTypes ; $ this -> blueprintSchema = new BlueprintSchema ; if ( $ types ) { $ this -> blueprintSchema -> setTypes ( $ types ) ; } $ this -> blueprintSchema -> embed ( '' , $ this ->... | Initialize validator . |
22,666 | public static function create ( $ password ) : string { if ( ! $ password ) { throw new \ RuntimeException ( 'Password hashing failed: no password provided.' ) ; } $ hash = password_hash ( $ password , PASSWORD_DEFAULT ) ; if ( ! $ hash ) { throw new \ RuntimeException ( 'Password hashing failed: internal error.' ) ; }... | Create password hash from plaintext password . |
22,667 | public static function verify ( $ password , $ hash ) : int { if ( ! $ password || ! $ hash || ! password_verify ( $ password , $ hash ) ) { return 0 ; } return password_needs_rehash ( $ hash , PASSWORD_DEFAULT ) ? 2 : 1 ; } | Verifies that a password matches a hash . |
22,668 | protected function orderMedia ( $ media ) { if ( null === $ this -> media_order ) { $ page = Grav :: instance ( ) [ 'pages' ] -> get ( $ this -> getPath ( ) ) ; if ( $ page && isset ( $ page -> header ( ) -> media_order ) ) { $ this -> media_order = array_map ( 'trim' , explode ( ',' , $ page -> header ( ) -> media_ord... | Order the media based on the page s media_order |
22,669 | protected function getFileParts ( $ filename ) { if ( preg_match ( '/(.*)@(\d+)x\.(.*)$/' , $ filename , $ matches ) ) { $ name = $ matches [ 1 ] ; $ extension = $ matches [ 3 ] ; $ extra = ( int ) $ matches [ 2 ] ; $ type = 'alternative' ; if ( $ extra === 1 ) { $ type = 'base' ; $ extra = null ; } } else { $ filePart... | Get filename extension and meta part . |
22,670 | public function name ( $ name = null ) { if ( ! $ this -> name ) { $ this -> name = $ name ? : md5 ( json_encode ( array_keys ( $ this -> files ) ) ) ; } return $ this ; } | Get filename for the compiled PHP file . |
22,671 | public function checksum ( ) { if ( null === $ this -> checksum ) { $ this -> checksum = md5 ( json_encode ( $ this -> files ) . $ this -> version ) ; } return $ this -> checksum ; } | Returns checksum from the configuration files . |
22,672 | protected function loadFiles ( ) { $ this -> createObject ( ) ; $ list = array_reverse ( $ this -> files ) ; foreach ( $ list as $ files ) { foreach ( $ files as $ name => $ item ) { $ this -> loadFile ( $ name , $ this -> path . $ item [ 'file' ] ) ; } } $ this -> finalizeObject ( ) ; return true ; } | Load and join all configuration files . |
22,673 | protected function loadCompiledFile ( $ filename ) { if ( ! file_exists ( $ filename ) ) { return false ; } $ cache = include $ filename ; if ( ! \ is_array ( $ cache ) || ! isset ( $ cache [ 'checksum' ] , $ cache [ 'data' ] , $ cache [ '@class' ] ) || $ cache [ '@class' ] !== \ get_class ( $ this ) ) { return false ;... | Load compiled file . |
22,674 | protected function saveCompiledFile ( $ filename ) { $ file = PhpFile :: instance ( $ filename ) ; try { $ file -> lock ( false ) ; } catch ( \ Exception $ e ) { } if ( $ file -> locked ( ) === false ) { return ; } $ cache = [ '@class' => \ get_class ( $ this ) , 'timestamp' => time ( ) , 'checksum' => $ this -> checks... | Save compiled file . |
22,675 | private static function pluginFolderPaths ( $ plugins , $ folder_path ) { $ paths = [ ] ; foreach ( $ plugins as $ path ) { $ iterator = new \ DirectoryIterator ( $ path ) ; foreach ( $ iterator as $ directory ) { if ( ! $ directory -> isDir ( ) || $ directory -> isDot ( ) ) { continue ; } $ lang_path = $ directory -> ... | Find specific paths in plugins |
22,676 | protected function gatherLinks ( array $ assets , $ css = true ) { $ buffer = '' ; foreach ( $ assets as $ id => $ asset ) { $ local = true ; $ link = $ asset -> getAsset ( ) ; $ relative_path = $ link ; if ( static :: isRemoteLink ( $ link ) ) { $ local = false ; if ( 0 === strpos ( $ link , '//' ) ) { $ link = 'http:... | Download and concatenate the content of several links . |
22,677 | public function getValue ( string $ name ) { $ value = $ this -> data ? $ this -> data [ $ name ] : null ; return $ value ?? $ this -> getObject ( ) -> value ( $ name ) ; } | Get a value from the form . |
22,678 | protected function filterData ( \ ArrayAccess $ data ) : void { if ( $ data instanceof Data ) { $ data -> filter ( true , true ) ; } } | Filter validated data . |
22,679 | protected function writeCacheFile ( $ file , $ content ) { if ( empty ( $ file ) ) { return ; } if ( ! isset ( self :: $ umask ) ) { self :: $ umask = Grav :: instance ( ) [ 'config' ] -> get ( 'system.twig.umask_fix' , false ) ; } if ( self :: $ umask ) { $ dir = dirname ( $ file ) ; if ( ! is_dir ( $ dir ) ) { $ old ... | This exists so template cache files use the same group between apache and cli |
22,680 | public static function url ( $ input , $ domain = false ) { if ( ! trim ( ( string ) $ input ) ) { $ input = '/' ; } if ( Grav :: instance ( ) [ 'config' ] -> get ( 'system.absolute_urls' , false ) ) { $ domain = true ; } if ( Grav :: instance ( ) [ 'uri' ] -> isExternal ( $ input ) ) { return $ input ; } $ uri = Grav ... | Simple helper method to make getting a Grav URL easier |
22,681 | public static function substrToString ( $ haystack , $ needle , $ case_sensitive = true ) { $ compare_func = $ case_sensitive ? 'mb_strpos' : 'mb_stripos' ; if ( static :: contains ( $ haystack , $ needle , $ case_sensitive ) ) { return mb_substr ( $ haystack , 0 , $ compare_func ( $ haystack , $ needle , $ case_sensit... | Returns the substring of a string up to a specified needle . if not found return the whole haystack |
22,682 | public static function replaceFirstOccurrence ( $ search , $ replace , $ subject ) { if ( ! $ search ) { return $ subject ; } $ pos = mb_strpos ( $ subject , $ search ) ; if ( $ pos !== false ) { $ subject = static :: mb_substr_replace ( $ subject , $ replace , $ pos , mb_strlen ( $ search ) ) ; } return $ subject ; } | Utility method to replace only the first occurrence in a string |
22,683 | public static function replaceLastOccurrence ( $ search , $ replace , $ subject ) { $ pos = strrpos ( $ subject , $ search ) ; if ( $ pos !== false ) { $ subject = static :: mb_substr_replace ( $ subject , $ replace , $ pos , mb_strlen ( $ search ) ) ; } return $ subject ; } | Utility method to replace only the last occurrence in a string |
22,684 | public static function mb_substr_replace ( $ original , $ replacement , $ position , $ length ) { $ startString = mb_substr ( $ original , 0 , $ position , "UTF-8" ) ; $ endString = mb_substr ( $ original , $ position + $ length , mb_strlen ( $ original ) , "UTF-8" ) ; return $ startString . $ replacement . $ endString... | Multibyte compatible substr_replace |
22,685 | public static function arrayMergeRecursiveUnique ( $ array1 , $ array2 ) { if ( empty ( $ array1 ) ) { return $ array2 ; } foreach ( $ array2 as $ key => $ value ) { if ( is_array ( $ value ) && isset ( $ array1 [ $ key ] ) && is_array ( $ array1 [ $ key ] ) ) { $ value = static :: arrayMergeRecursiveUnique ( $ array1 ... | Recursive Merge with uniqueness |
22,686 | public static function arrayCombine ( $ arr1 , $ arr2 ) { $ count = min ( count ( $ arr1 ) , count ( $ arr2 ) ) ; return array_combine ( array_slice ( $ arr1 , 0 , $ count ) , array_slice ( $ arr2 , 0 , $ count ) ) ; } | Array combine but supports different array lengths |
22,687 | public static function dateFormats ( ) { $ now = new \ DateTime ( ) ; $ date_formats = [ 'd-m-Y H:i' => 'd-m-Y H:i (e.g. ' . $ now -> format ( 'd-m-Y H:i' ) . ')' , 'Y-m-d H:i' => 'Y-m-d H:i (e.g. ' . $ now -> format ( 'Y-m-d H:i' ) . ')' , 'm/d/Y h:i a' => 'm/d/Y h:i a (e.g. ' . $ now -> format ( 'm/d/Y h:i a' ) . ')'... | Return the Grav date formats allowed |
22,688 | public static function truncate ( $ string , $ limit = 150 , $ up_to_break = false , $ break = ' ' , $ pad = '…' ) { if ( mb_strlen ( $ string ) <= $ limit ) { return $ string ; } if ( $ up_to_break && false !== ( $ breakpoint = mb_strpos ( $ string , $ break , $ limit ) ) ) { if ( $ breakpoint < mb_strlen ( $ s... | Truncate text by number of characters but can cut off words . |
22,689 | public static function getMimeTypes ( array $ extensions ) { $ mimetypes = [ ] ; foreach ( $ extensions as $ extension ) { $ mimetype = static :: getMimeByExtension ( $ extension , false ) ; if ( $ mimetype && ! in_array ( $ mimetype , $ mimetypes ) ) { $ mimetypes [ ] = $ mimetype ; } } return $ mimetypes ; } | Get all the mimetypes for an array of extensions |
22,690 | public static function getExtensions ( array $ mimetypes ) { $ extensions = [ ] ; foreach ( $ mimetypes as $ mimetype ) { $ extension = static :: getExtensionByMime ( $ mimetype , false ) ; if ( $ extension && ! \ in_array ( $ extension , $ extensions , true ) ) { $ extensions [ ] = $ extension ; } } return $ extension... | Get all the extensions for an array of mimetypes |
22,691 | public static function getMimeByLocalFile ( $ filename , $ default = 'application/octet-stream' ) { $ type = false ; if ( ! stream_is_local ( $ filename ) || ! file_exists ( $ filename ) ) { return false ; } if ( \ extension_loaded ( 'fileinfo' ) ) { $ finfo = finfo_open ( FILEINFO_SYMLINK | FILEINFO_MIME_TYPE ) ; $ ty... | Return the mimetype based on existing local file |
22,692 | public static function normalizePath ( $ path ) { $ locator = Grav :: instance ( ) [ 'locator' ] ; if ( $ locator -> isStream ( $ path ) ) { $ path = $ locator -> findResource ( $ path ) ; } $ root = '' ; preg_match ( self :: ROOTURL_REGEX , $ path , $ matches ) ; if ( $ matches ) { $ root = $ matches [ 1 ] ; $ path = ... | Normalize path by processing relative . and .. syntax and merging path |
22,693 | public static function timezones ( ) { $ timezones = \ DateTimeZone :: listIdentifiers ( \ DateTimeZone :: ALL ) ; $ offsets = [ ] ; $ testDate = new \ DateTime ( ) ; foreach ( $ timezones as $ zone ) { $ tz = new \ DateTimeZone ( $ zone ) ; $ offsets [ $ zone ] = $ tz -> getOffset ( $ testDate ) ; } asort ( $ offsets ... | Get the formatted timezones list |
22,694 | public static function arrayFlattenDotNotation ( $ array , $ prepend = '' ) { $ results = array ( ) ; foreach ( $ array as $ key => $ value ) { if ( is_array ( $ value ) ) { $ results = array_merge ( $ results , static :: arrayFlattenDotNotation ( $ value , $ prepend . $ key . '.' ) ) ; } else { $ results [ $ prepend .... | Flatten a multi - dimensional associative array into dot notation |
22,695 | public static function arrayUnflattenDotNotation ( $ array , $ separator = '.' ) { $ newArray = [ ] ; foreach ( $ array as $ key => $ value ) { $ dots = explode ( $ separator , $ key ) ; if ( \ count ( $ dots ) > 1 ) { $ last = & $ newArray [ $ dots [ 0 ] ] ; foreach ( $ dots as $ k => $ dot ) { if ( $ k === 0 ) { cont... | Opposite of flatten convert flat dot notation array to multi dimensional array |
22,696 | public static function pathPrefixedByLangCode ( $ string ) { if ( strlen ( $ string ) <= 3 ) { return false ; } $ languages_enabled = Grav :: instance ( ) [ 'config' ] -> get ( 'system.languages.supported' , [ ] ) ; $ parts = explode ( '/' , trim ( $ string , '/' ) ) ; if ( count ( $ parts ) > 0 && in_array ( $ parts [... | Checks if the passed path contains the language code prefix |
22,697 | public static function date2timestamp ( $ date , $ format = null ) { $ config = Grav :: instance ( ) [ 'config' ] ; $ dateformat = $ format ? : $ config -> get ( 'system.pages.dateformat.default' ) ; if ( $ dateformat ) { $ datetime = \ DateTime :: createFromFormat ( $ dateformat , $ date ) ; } else { $ datetime = new ... | Get the timestamp of a date |
22,698 | public static function getNonce ( $ action , $ previousTick = false ) { if ( isset ( static :: $ nonces [ $ action ] [ $ previousTick ] ) ) { return static :: $ nonces [ $ action ] [ $ previousTick ] ; } $ nonce = md5 ( self :: generateNonceString ( $ action , $ previousTick ) ) ; static :: $ nonces [ $ action ] [ $ pr... | Creates a hashed nonce tied to the passed action . Tied to the current user and time . The nonce for a given action is the same for 12 hours . |
22,699 | public static function verifyNonce ( $ nonce , $ action ) { if ( is_array ( $ nonce ) ) { $ nonce = array_shift ( $ nonce ) ; } if ( $ nonce === self :: getNonce ( $ action ) ) { return true ; } $ previousTick = true ; return $ nonce === self :: getNonce ( $ action , $ previousTick ) ; } | Verify the passed nonce for the give action |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.