idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
26,400 | protected function getLinks ( $ route , array $ parameters = array ( ) ) { $ links = array ( ) ; if ( $ route != null ) { $ baseParams = $ _GET ; unset ( $ baseParams [ "page" ] ) ; $ parameters = array_merge ( $ parameters , $ baseParams ) ; $ links [ 'first' ] [ 'href' ] = $ this -> generateUrl ( $ route , array_merge ( $ parameters , array ( 'page' => 1 ) ) ) ; $ links [ 'self' ] [ 'href' ] = $ this -> generateUrl ( $ route , array_merge ( $ parameters , array ( 'page' => $ this -> getCurrentPage ( ) ) ) ) ; $ links [ 'last' ] [ 'href' ] = $ this -> generateUrl ( $ route , array_merge ( $ parameters , array ( 'page' => $ this -> getNbPages ( ) ) ) ) ; if ( $ this -> hasPreviousPage ( ) ) { $ links [ 'previous' ] [ 'href' ] = $ this -> generateUrl ( $ route , array_merge ( $ parameters , array ( 'page' => $ this -> getPreviousPage ( ) ) ) ) ; } if ( $ this -> hasNextPage ( ) ) { $ links [ 'next' ] [ 'href' ] = $ this -> generateUrl ( $ route , array_merge ( $ parameters , array ( 'page' => $ this -> getNextPage ( ) ) ) ) ; } } return $ links ; } | Genera los links de navegacion entre una y otra pagina |
26,401 | function setRequest ( \ Symfony \ Component \ HttpFoundation \ Request $ request ) { $ this -> request = $ request ; if ( self :: FORMAT_ARRAY_DATA_TABLES == $ this -> defaultFormat ) { $ start = ( int ) $ request -> get ( "start" , 0 ) ; $ length = ( int ) $ request -> get ( "length" , 10 ) ; $ this -> draw = $ request -> get ( "draw" , $ this -> draw ) + 1 ; if ( $ start > 0 ) { $ page = ( int ) ( $ start / $ length ) ; $ page = $ page + 1 ; } else { $ page = 1 ; } if ( ! is_int ( $ length ) ) { $ length = 10 ; } if ( ! is_int ( $ page ) ) { $ page = 1 ; } $ this -> setMaxPerPage ( $ length ) ; $ this -> setCurrentPage ( $ page ) ; } else if ( self :: FORMAT_ARRAY_STANDARD == $ this -> defaultFormat ) { $ page = ( int ) $ request -> get ( "page" , 1 ) ; $ maxPerPage = ( int ) $ request -> get ( "maxPerPage" , 10 ) ; $ this -> setMaxPerPage ( $ maxPerPage ) ; $ totalPages = $ this -> getNbPages ( ) ; if ( $ page > $ this -> getNbPages ( ) ) { $ page = $ totalPages ; } $ this -> setCurrentPage ( $ page ) ; } } | Establece el request actual para calculos en los formaters |
26,402 | public static function allocate ( $ filename = null , $ extension = ".rnd" , $ folder = null ) { if ( $ filename === null ) { $ filename = sha1 ( time ( ) . "_" . microtime ( true ) ) ; } if ( $ folder ) { $ ffolder = new Filesystem ( $ folder ) ; if ( ! $ ffolder -> exists ( ) ) { $ ffolder -> mkdir ( ) ; } } $ file = new Filesystem ( $ folder . '/' . $ filename . $ extension ) ; return $ file ; } | Solicita un nuevo archivo con ese nombre y extension si no se indica un nombre se genera uno de forma aleatoria . |
26,403 | public function getFilesystemFolder ( ) { $ config = Bootstrap :: getSingleton ( ) -> getConfig ( ) ; if ( isset ( $ config [ 'app' ] [ 'filesystem' ] ) ) { return Bootstrap :: getSingleton ( ) -> getDirectory ( ) . '/' . $ config [ 'app' ] [ 'filesystem' ] ; } return Bootstrap :: getSingleton ( ) -> getDirectory ( ) . '/filesystem' ; } | Obtiene la ruta al directorio donde se almacenan los archivos |
26,404 | public function url ( $ expires = null ) { $ this -> setPublic ( $ expires ) ; return get_protocol ( ) . $ _SERVER [ 'HTTP_HOST' ] . '/_raw/' . $ this -> file ; } | Obtiene una url accesible por el navegador |
26,405 | protected function _writePHPStorm ( $ map , $ className ) { $ fileName = $ this -> _root . DIRECTORY_SEPARATOR . self :: FILE_PHPSTORM ; if ( is_dir ( $ fileName ) ) { $ fileName .= DIRECTORY_SEPARATOR . 'pimple.meta.php' ; } $ list = array ( ) ; foreach ( $ map as $ data ) { if ( $ data [ 'type' ] === 'class' ) { $ list [ ] = " '{$data['name']}' instanceof {$data['value']}," ; } } $ tmpl = array ( '<?php' , '/**' , ' * ProcessWire PhpStorm Meta' , ' *' , ' * This file is not a CODE, it makes no sense and won\'t run or validate' , ' * Its AST serves PhpStorm IDE as DATA source to make advanced type inference decisions.' , ' * ' , ' * @see https://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Advanced+Metadata' , ' */' , '' , 'namespace PHPSTORM_META {' , '' , ' $STATIC_METHOD_TYPES = [' , ' new \\' . $ className . ' => [' , ' \'\' == \'@\',' , implode ( "\n" , $ list ) , ' ],' , ' ];' , '' , '}' , '' , ) ; $ content = implode ( "\n" , $ tmpl ) ; $ this -> _updateFile ( $ fileName , $ content ) ; return $ fileName ; } | Dump mapping to phpstorm meta file |
26,406 | protected function _updateFile ( $ fileName , $ content ) { $ oldContent = null ; if ( file_exists ( $ fileName ) ) { $ oldContent = file_get_contents ( $ fileName ) ; } if ( $ content !== $ oldContent ) { file_put_contents ( $ fileName , $ content ) ; } return $ fileName ; } | Update file Prevent file lastModified time change |
26,407 | public function forwardMessage ( $ toChatId , bool $ disableNotification = false ) : void { $ m = $ this -> bot -> forwardMessage ( ) ; $ m -> setChatId ( $ toChatId ) ; $ m -> setFromChatId ( $ this -> message -> getChat ( ) -> getId ( ) ) ; $ m -> setMessageId ( $ this -> message -> getMessageId ( ) ) ; $ m -> setDisableNotification ( $ disableNotification ) ; $ m -> send ( ) ; } | Forward the message that triggered this command . |
26,408 | public function load ( ) { $ data = array ( ) ; if ( $ this -> storageAdapter -> has ( $ this -> key ) ) { $ target = $ this -> serializer -> unserialize ( $ this -> storageAdapter -> get ( $ this -> key ) ) ; if ( $ target !== null ) { $ data = $ target ; } } return $ data ; } | Loads data from a storage |
26,409 | public function save ( array $ data ) { $ seriaziledData = $ this -> serializer -> serialize ( $ data ) ; $ this -> storageAdapter -> set ( $ this -> key , $ seriaziledData , $ this -> ttl ) ; return true ; } | Saves data into a storage |
26,410 | public function clear ( ) { if ( $ this -> storageAdapter -> has ( $ this -> key ) ) { $ this -> storageAdapter -> remove ( $ this -> key ) ; } } | Clears data from a storage |
26,411 | public static function build ( $ host , $ username = null , $ password = null , $ timeout = 90 , $ port = 21 , $ ssl = false ) { $ connector = new Connector ( $ host , $ timeout , $ port , $ ssl ) ; if ( ! $ connector -> connect ( ) ) { throw new RuntimeException ( 'Cannot connect to remote FTP server' ) ; } if ( $ username !== null && $ password !== null ) { if ( ! $ connector -> login ( $ username , $ password ) ) { throw new LogicException ( 'Invalid combination of username and password provided' ) ; } } return new FtpManager ( $ connector ) ; } | Builds FTP Manager |
26,412 | protected function isColumn ( ResolvedBlockTypeInterface $ type ) { if ( 'table_column' === $ type -> getBlockPrefix ( ) ) { return true ; } if ( null !== $ type -> getParent ( ) ) { return $ this -> isColumn ( $ type -> getParent ( ) ) ; } return false ; } | Check if the child is a column . |
26,413 | public function checkSecurity ( $ rol , $ parameters = null ) { if ( $ rol === null ) { throw $ this -> createAccessDeniedHttpException ( $ this -> trans ( $ this -> genericMessage ) ) ; } $ roles = $ rol ; if ( ! is_array ( $ rol ) ) { $ roles = array ( $ rol ) ; } $ valid = $ this -> getSecurityContext ( ) -> isGranted ( $ roles , $ parameters ) ; foreach ( $ roles as $ rol ) { if ( ! $ valid ) { throw $ this -> createAccessDeniedHttpException ( $ this -> buildMessage ( $ rol ) ) ; } $ methodValidMap = $ this -> getMethodValidMap ( ) ; if ( isset ( $ methodValidMap [ $ rol ] ) ) { $ method = $ methodValidMap [ $ rol ] ; $ valid = call_user_func_array ( array ( $ this , $ method ) , array ( $ rol , $ parameters ) ) ; } } } | Evalua que el usuario tenga acceso a la seccion especifica ademas se valida con un segundo metodo |
26,414 | private function buildMessage ( $ rol , $ prefix = '403' ) { return $ this -> trans ( sprintf ( '%s.%s.%s' , $ this -> prefixMessage , $ prefix , strtolower ( $ rol ) ) ) ; } | Genera el mensaje de error |
26,415 | protected function setFlash ( $ type , $ message , $ parameters = array ( ) , $ domain = 'flashes' ) { return $ this -> container -> get ( 'session' ) -> getBag ( 'flashes' ) -> add ( $ type , $ message ) ; } | Envia un mensaje flash |
26,416 | final public function build ( ) { return new ImageManager ( $ this -> getPath ( ) , $ this -> getRootDir ( ) , $ this -> getRootUrl ( ) , $ this -> getConfig ( ) ) ; } | Builds image manager s instance |
26,417 | public function getPageNumbers ( array $ pages , $ current ) { $ result = array ( ) ; $ amount = count ( $ pages ) ; $ start = 3 ; if ( $ amount > $ start ) { $ min = max ( $ current - 2 , 2 ) ; $ max = min ( $ current + 2 , $ amount - 1 ) ; $ result [ ] = 1 ; if ( $ min > 2 ) { $ result [ ] = '...' ; } for ( $ i = $ min ; $ i < $ max + 1 ; $ i ++ ) { $ result [ ] = $ i ; } if ( $ max < $ amount - 1 ) { $ result [ ] = '...' ; } $ result [ ] = $ amount ; return $ result ; } else { return range ( 1 , $ start ) ; } } | Returns filtered array via this style adapter |
26,418 | public function build ( $ controller , $ action , array $ options ) { $ class = Ns :: normalize ( $ controller ) ; if ( class_exists ( $ class ) ) { $ module = Ns :: extractVendorNs ( $ controller ) ; $ controller = new $ class ( $ this -> serviceLocator , $ module , $ options ) ; if ( method_exists ( $ controller , 'initialize' ) ) { $ controller -> initialize ( $ action ) ; if ( $ controller -> isHalted ( ) ) { throw new DomainException ( 'Controller halted its execution due to route options mismatch' ) ; } return $ controller ; } else { throw new RuntimeException ( 'A base controller must be inherited' ) ; } } else { trigger_error ( sprintf ( 'Controller does not exist : "%s" or it does not match PSR-0' , $ class ) , E_USER_ERROR ) ; } } | Builds a controller instance |
26,419 | private function getRoutesFromIndex ( & $ routes , & $ routesIndex , & $ requestMethod , & $ requestPathParts , $ requestPathIndex = 0 ) { if ( ! empty ( $ requestPathParts [ $ requestPathIndex ] ) ) { $ requestPathPart = $ requestPathParts [ $ requestPathIndex ] ; if ( array_key_exists ( $ requestPathPart , $ routesIndex ) ) { $ this -> getRoutesFromIndex ( $ routes , $ routesIndex [ $ requestPathPart ] , $ requestMethod , $ requestPathParts , $ requestPathIndex + 1 ) ; } if ( array_key_exists ( self :: ROUTE_PARAMETER_WILDCARD , $ routesIndex ) ) { $ this -> getRoutesFromIndex ( $ routes , $ routesIndex [ self :: ROUTE_PARAMETER_WILDCARD ] , $ requestMethod , $ requestPathParts , $ requestPathIndex + 1 ) ; } } else if ( array_key_exists ( self :: ROUTE_ACTIONS_KEY , $ routesIndex ) ) { $ testRoutes = & $ routesIndex [ self :: ROUTE_ACTIONS_KEY ] ; if ( array_key_exists ( $ requestMethod , $ testRoutes ) ) { $ this -> getRoutesFromIndexActions ( $ routes , $ testRoutes [ $ requestMethod ] , $ requestMethod , $ requestPathParts ) ; } if ( array_key_exists ( self :: ROUTE_GENERIC_METHOD , $ testRoutes ) ) { $ this -> getRoutesFromIndexActions ( $ routes , $ testRoutes [ self :: ROUTE_GENERIC_METHOD ] , $ requestMethod , $ requestPathParts ) ; } } if ( array_key_exists ( self :: ROUTE_GENERIC_ACTIONS_KEY , $ routesIndex ) ) { $ testRoutes = & $ routesIndex [ self :: ROUTE_GENERIC_ACTIONS_KEY ] ; if ( array_key_exists ( $ requestMethod , $ testRoutes ) ) { $ this -> getRoutesFromIndexActions ( $ routes , $ testRoutes [ $ requestMethod ] , $ requestMethod , $ requestPathParts ) ; } if ( array_key_exists ( self :: ROUTE_GENERIC_METHOD , $ testRoutes ) ) { $ this -> getRoutesFromIndexActions ( $ routes , $ testRoutes [ self :: ROUTE_GENERIC_METHOD ] , $ requestMethod , $ requestPathParts ) ; } } } | Obtiene una ruta desde un indice de rutas |
26,420 | private function getRoutesFromIndexActions ( & $ routes , array & $ routeActions , & $ requestMethod , array & $ requestPathParts ) { foreach ( $ routeActions as $ routeData ) { $ routePath = $ routeData [ 0 ] ; $ routeAction = $ routeData [ 1 ] ; $ routeParameters = [ ] ; if ( strpos ( $ routePath , self :: ROUTE_PARAMETER_PREFIX ) !== false || strpos ( $ routePath , self :: ROUTE_GENERIC_PATH ) !== false ) { $ routePathParts = explode ( self :: ROUTE_PATH_SEPARATOR , trim ( $ routePath , self :: ROUTE_PATH_SEPARATOR ) ) ; ; for ( $ i = 0 ; $ i < sizeof ( $ routePathParts ) ; $ i ++ ) { $ routePathPart = $ routePathParts [ $ i ] ; if ( $ routePathPart == self :: ROUTE_GENERIC_PATH ) { $ path = array_slice ( $ requestPathParts , $ i ) ; $ routeParameters [ self :: ROUTE_PATH_PARAMETER_NAME ] = $ path ; break ; } else if ( $ routePathPart [ 0 ] == self :: ROUTE_PARAMETER_PREFIX ) { $ parameterName = substr ( $ routePathPart , 1 ) ; $ parameterValue = $ requestPathParts [ $ i ] ; $ routeParameters [ $ parameterName ] = $ parameterValue ; } } } if ( $ routeAction instanceof RouteGenerator ) { $ route = $ routeAction -> generateRoute ( $ requestMethod , isset ( $ path ) ? $ path : $ requestPathParts ) ; if ( $ route ) { $ routes [ ] = $ route ; } } else { $ routes [ ] = new Route ( $ routeAction , $ routeParameters ) ; } } } | Obtiene rutas desde las acciones del metodo |
26,421 | protected function getRealValues ( array $ values , $ value = null ) { $ value = $ this -> getCallableValue ( $ value ) ; foreach ( $ values as & $ val ) { if ( \ is_object ( $ val ) && \ is_callable ( $ value ) ) { $ val = \ call_user_func ( $ value , $ val ) ; } } return $ values ; } | Get the choice names of values . |
26,422 | public function listTasklists ( array $ queryParameters = [ ] ) : array { $ parameters = [ 'maxResults' => 100 , ] ; $ parameters = array_merge ( $ parameters , $ queryParameters ) ; return $ this -> taskService -> tasklists -> listTasklists ( $ parameters ) -> getItems ( ) ; } | Get all task lists |
26,423 | public function listTasks ( string $ taskListId , Carbon $ dueMin = null , array $ queryParameters = [ ] ) : array { $ parameters = [ 'showCompleted' => false , 'showDeleted' => true , 'showHidden' => true , ] ; if ( is_null ( $ dueMin ) ) { $ dueMin = Carbon :: now ( ) -> startOfDay ( ) ; } $ parameters [ 'dueMin' ] = $ dueMin -> format ( DateTime :: RFC3339 ) ; $ parameters = array_merge ( $ parameters , $ queryParameters ) ; return $ this -> taskService -> tasks -> listTasks ( $ taskListId , $ parameters ) -> getItems ( ) ; } | Get task from specified list |
26,424 | public function getTask ( string $ taskId ) : Google_Service_Tasks { return $ this -> service -> tasks -> get ( $ this -> tasklist , $ taskId ) ; } | Get a single task . |
26,425 | public function insertTask ( $ task ) : Google_Service_Tasks { if ( $ task instanceof Tasks ) { $ task = $ task -> googleTasks ; } return $ this -> service -> tasks -> insert ( $ this -> tasklist , $ task ) ; } | Insert a task . |
26,426 | public function deleteTask ( $ taskId ) { if ( $ taskId instanceof Tasks ) { $ taskId = $ taskId -> id ; } $ this -> service -> tasks -> delete ( $ this -> tasklist , $ taskId ) ; } | Delete a task |
26,427 | public function getFiles ( $ name = null ) { if ( $ name !== null ) { if ( ! array_key_exists ( $ name , $ this -> files ) ) { throw new RuntimeException ( sprintf ( 'Attempted to access non-existing field %s' , $ name ) ) ; } return $ this -> hydrateAll ( $ this -> files [ $ name ] ) ; } else { return $ this -> hydrateAll ( $ this -> files ) ; } } | Return all files . Optionally filtered by named input |
26,428 | private function hydrateAll ( array $ files ) { foreach ( $ files as $ name => $ file ) { if ( ! is_array ( $ file ) ) { continue ; } foreach ( $ file as $ key => $ value ) { if ( is_array ( $ value ) ) { $ files [ $ name ] = call_user_func ( array ( $ this , __FUNCTION__ ) , $ files [ $ name ] ) ; } else { $ files [ $ name ] = $ this -> hydrate ( $ file ) ; } } } return $ files ; } | Recursively hydrate array entires skipping empty files |
26,429 | private function hydrate ( array $ file ) { $ entity = new FileEntity ( ) ; $ entity -> setType ( $ file [ 'type' ] ) -> setName ( $ file [ 'name' ] ) -> setTmpName ( $ file [ 'tmp_name' ] ) -> setSize ( $ file [ 'size' ] ) -> setError ( $ file [ 'error' ] ) ; return $ entity ; } | Hydrates a single file |
26,430 | private function removeBrokenFiles ( array $ files ) { if ( isset ( $ files [ 'error' ] ) ) { return $ files [ 'error' ] == 4 ? array ( ) : $ files ; } foreach ( $ files as $ key => $ value ) { $ files [ $ key ] = call_user_func ( array ( $ this , __FUNCTION__ ) , $ value ) ; } return array_filter ( $ files ) ; } | Remove broken ones from target array A broken file is empty one |
26,431 | private static function handleRequestNotFound ( ) { $ response = get_response ( ) ; $ response -> clear ( ) ; $ response -> statusCode ( Response :: HTTP_NOT_FOUND ) ; $ notFoundRoutes = self :: $ notFoundRoutes -> getRoutes ( ) ; if ( ! empty ( $ notFoundRoutes ) ) { foreach ( $ notFoundRoutes as $ notFoundRoute ) { $ routeResult = self :: executeAction ( $ notFoundRoute -> getAction ( ) , array_merge ( $ _REQUEST , $ notFoundRoute -> getParameters ( ) ) ) ; if ( isset ( $ routeResult ) ) { $ response -> content ( $ routeResult ) ; } } $ response -> send ( ) ; } else { handle_error_code ( Response :: HTTP_NOT_FOUND ) ; } } | Procesa una ruta no encontrada |
26,432 | public static function build ( array $ config ) { $ input = new Input ( ) ; $ input -> setQuery ( $ _GET ) -> setPost ( $ _POST ) -> setCookie ( $ _COOKIE ) -> setFiles ( $ _FILES ) -> setServer ( $ _SERVER ) -> setEnv ( $ _ENV ) -> setRequest ( $ _REQUEST ) ; return new Kernel ( $ input , $ config ) ; } | Builds prepared application instance |
26,433 | public function build ( $ dir , $ quality , array $ options = array ( ) ) { if ( isset ( $ options [ 'quality' ] ) ) { $ quality = $ options [ 'quality' ] ; } return new Thumb ( $ dir , $ options [ 'dimensions' ] , $ quality ) ; } | Builds thumb uploader |
26,434 | public function store ( $ module , $ name , $ value ) { $ this -> initializeOnDemand ( ) ; if ( ! $ this -> has ( $ module , $ name ) ) { if ( $ this -> configMapper -> insert ( $ module , $ name , $ value ) ) { $ this -> arrayConfig -> add ( $ module , $ name , $ value ) ; return true ; } } else { if ( $ this -> configMapper -> update ( $ module , $ name , $ value ) ) { $ this -> arrayConfig -> update ( $ module , $ name , $ value ) ; return true ; } } return false ; } | Stores configuration s entry |
26,435 | public function storeModule ( $ module , array $ vars ) { foreach ( $ vars as $ key => $ value ) { if ( ! $ this -> store ( $ module , $ key , $ value ) ) { return false ; } } return true ; } | Stores a collection for a module |
26,436 | public function get ( $ module , $ name , $ default = false ) { $ this -> initializeOnDemand ( ) ; return $ this -> arrayConfig -> get ( $ module , $ name , $ default ) ; } | Returns configuration entry from the cache |
26,437 | public function has ( $ module , $ name ) { $ this -> initializeOnDemand ( ) ; return $ this -> arrayConfig -> has ( $ module , $ name ) ; } | Checks configuration s entry exists in a module |
26,438 | public function removeAll ( ) { $ this -> initializeOnDemand ( ) ; if ( $ this -> configMapper -> truncate ( ) ) { $ this -> arrayConfig -> clear ( ) ; return true ; } else { return false ; } } | Removes all configuration |
26,439 | public function remove ( $ module , $ name ) { $ this -> initializeOnDemand ( ) ; if ( $ this -> exists ( $ module , $ name ) && $ this -> configMapper -> delete ( $ module , $ name ) ) { $ this -> arrayConfig -> remove ( $ module , $ name ) ; return true ; } else { return false ; } } | Removes a configuration s name and value by associated module |
26,440 | public function removeAllByModule ( $ module ) { $ this -> initializeOnDemand ( ) ; if ( $ this -> arrayConfig -> hasModule ( $ module ) && $ this -> configMapper -> deleteAllByModule ( $ module ) ) { $ this -> arrayConfig -> removeAllByModule ( $ module ) ; return true ; } else { return false ; } } | Removes all configuration data by associated module |
26,441 | private function isDirtyFile ( $ path , $ git ) { if ( ! \ is_file ( $ path ) ) { return false ; } $ status = ( array ) $ git -> status ( ) -> short ( ) -> getIndexStatus ( ) ; $ relPath = ( string ) \ substr ( $ path , ( \ strlen ( $ git -> getRepositoryPath ( ) ) + 1 ) ) ; if ( isset ( $ status [ $ relPath ] ) && $ status [ $ relPath ] ) { return true ; } return false ; } | Check if the current file path is a file and if so if it has staged modifications . |
26,442 | private function getAuthorListFrom ( ) { $ filePath = $ this -> getFilePathCollection ( $ this -> currentPath ) ; $ authors = [ ] ; foreach ( ( array ) $ filePath [ 'commits' ] as $ commit ) { if ( $ this -> isMergeCommit ( $ commit ) || isset ( $ authors [ \ md5 ( $ commit [ 'name' ] ) ] ) ) { continue ; } $ authors [ \ md5 ( $ commit [ 'name' ] ) ] = $ commit ; } if ( isset ( $ filePath [ 'pathHistory' ] ) ) { foreach ( ( array ) $ filePath [ 'pathHistory' ] as $ pathHistory ) { foreach ( ( array ) $ pathHistory [ 'commits' ] as $ commitHistory ) { if ( $ this -> isMergeCommit ( $ commitHistory ) || isset ( $ authors [ \ md5 ( $ commitHistory [ 'name' ] ) ] ) ) { continue ; } $ authors [ \ md5 ( $ commitHistory [ 'name' ] ) ] = $ commitHistory ; } } } return $ authors ; } | Retrieve the author list from the given path via calling git . |
26,443 | public function collectFilesWithCommits ( GitRepository $ git ) { $ lastCommitId = $ git -> show ( ) -> format ( '%H' ) -> execute ( '--quiet' ) ; $ cacheId = \ md5 ( __FUNCTION__ . $ lastCommitId ) ; if ( $ this -> cachePool -> has ( $ cacheId ) ) { $ fromCache = $ this -> cachePool -> get ( $ cacheId ) ; $ this -> commitCollection = $ fromCache [ 'commitCollection' ] ; $ this -> filePathMapping = $ fromCache [ 'filePathMapping' ] ; $ this -> filePathCollection = $ fromCache [ 'filePathCollection' ] ; return ; } $ commitCollection = [ ] ; $ filePathMapping = [ ] ; $ filePathCollection = [ ] ; $ this -> prepareCommitCollection ( $ git , $ this -> fetchAllCommits ( $ git , $ lastCommitId ) , $ commitCollection , $ filePathMapping , $ filePathCollection ) ; $ this -> cachePool -> set ( $ cacheId , [ 'commitCollection' => $ commitCollection , 'filePathMapping' => $ filePathMapping , 'filePathCollection' => $ filePathCollection ] ) ; $ this -> commitCollection = $ commitCollection ; $ this -> filePathMapping = $ filePathMapping ; $ this -> filePathCollection = $ filePathCollection ; } | Collect all files with their commits . |
26,444 | private function prepareCommitCollection ( GitRepository $ git , array $ logList , array & $ commitCollection , array & $ filePathMapping , array & $ filePathCollection ) { foreach ( $ logList as $ log ) { $ currentCacheId = \ md5 ( __FUNCTION__ . $ log [ 'commit' ] ) ; if ( $ this -> cachePool -> has ( $ currentCacheId ) ) { $ fromCurrentCache = $ this -> cachePool -> get ( $ currentCacheId ) ; $ commitCollection = \ array_merge ( $ filePathMapping , $ fromCurrentCache [ 'commitCollection' ] ) ; $ filePathMapping = \ array_merge ( $ filePathMapping , $ fromCurrentCache [ 'filePathMapping' ] ) ; $ filePathCollection = \ array_merge ( $ filePathCollection , $ fromCurrentCache [ 'filePathCollection' ] ) ; break ; } $ matches = $ this -> matchFileInformation ( $ this -> fetchNameStatusFromCommit ( $ log [ 'commit' ] , $ git ) ) ; if ( ! \ count ( $ matches ) ) { continue ; } $ changeCollection = [ ] ; foreach ( $ matches as $ match ) { $ changeCollection [ ] = \ array_filter ( \ array_filter ( $ match ) , 'is_string' , ARRAY_FILTER_USE_KEY ) ; } $ this -> prepareChangeCollection ( $ log , $ changeCollection , $ commitCollection , $ filePathMapping , $ filePathCollection ) ; } } | Prepare the collection of commits from the git log . |
26,445 | private function prepareChangeCollection ( array $ commit , array $ changeCollection , array & $ commitCollection , array & $ filePathMapping , array & $ filePathCollection ) { foreach ( $ changeCollection as $ change ) { if ( ! isset ( $ commit [ 'containedPath' ] ) ) { $ commit [ 'containedPath' ] = [ ] ; } if ( ! isset ( $ commit [ 'information' ] ) ) { $ commit [ 'information' ] = [ ] ; } if ( isset ( $ change [ 'criteria' ] ) ) { $ changeToHash = \ md5 ( $ change [ 'to' ] ) ; $ changeFromHash = \ md5 ( $ change [ 'from' ] ) ; $ commit [ 'containedPath' ] [ $ changeToHash ] = $ change [ 'to' ] ; $ commit [ 'information' ] [ $ changeToHash ] = $ change ; $ filePathMapping [ $ changeToHash ] = $ change [ 'to' ] ; $ filePathMapping [ $ changeFromHash ] = $ change [ 'from' ] ; $ filePathCollection [ $ changeToHash ] [ 'commits' ] [ $ commit [ 'commit' ] ] = $ commit ; $ filePathCollection [ $ changeFromHash ] [ 'commits' ] [ $ commit [ 'commit' ] ] = $ commit ; $ commitCollection [ $ commit [ 'commit' ] ] = $ commit ; continue ; } $ fileHash = \ md5 ( $ change [ 'file' ] ) ; $ commit [ 'containedPath' ] [ $ fileHash ] = $ change [ 'file' ] ; $ commit [ 'information' ] [ $ fileHash ] = $ change ; $ filePathMapping [ $ fileHash ] = $ change [ 'file' ] ; $ filePathCollection [ $ fileHash ] [ 'commits' ] [ $ commit [ 'commit' ] ] = $ commit ; $ commitCollection [ $ commit [ 'commit' ] ] = $ commit ; } } | Prepare the collection for commit file path mapping and the file path . |
26,446 | private function getFilePathCollection ( $ path ) { $ key = \ array_flip ( $ this -> filePathMapping ) [ $ path ] ; return $ this -> filePathCollection [ $ key ] ; } | Get the data to the file path collection . |
26,447 | private function setFilePathCollection ( $ path , array $ data ) { $ key = \ array_flip ( $ this -> filePathMapping ) [ $ path ] ; $ this -> filePathCollection [ $ key ] = $ data ; } | Set the data to the file path collection . |
26,448 | private function countMergeCommits ( array $ commitList ) { $ count = 0 ; foreach ( $ commitList as $ filePathCommit ) { if ( ! $ this -> isMergeCommit ( $ filePathCommit ) ) { continue ; } $ count ++ ; } return $ count ; } | Count merge commits from the commit list . |
26,449 | private function buildFileHistory ( GitRepository $ git ) { $ filePath = $ this -> getFilePathCollection ( $ this -> currentPath ) ; if ( \ count ( ( array ) $ filePath [ 'commits' ] ) === $ this -> countMergeCommits ( $ filePath [ 'commits' ] ) ) { $ commit = $ filePath [ 'commits' ] [ \ array_reverse ( \ array_keys ( $ filePath [ 'commits' ] ) ) [ 0 ] ] ; if ( $ this -> isMergeCommit ( $ commit ) ) { $ parents = \ explode ( ' ' , $ commit [ 'parent' ] ) ; $ arguments = [ $ git -> getConfig ( ) -> getGitExecutablePath ( ) , 'diff' , $ commit [ 'commit' ] , $ parents [ 1 ] , '--diff-filter=R' , '--name-status' , '--format=' , '-M' ] ; $ matches = $ this -> matchFileInformation ( $ this -> runCustomGit ( $ arguments , $ git ) ) ; foreach ( $ matches as $ match ) { if ( ! \ in_array ( $ this -> currentPath , $ match ) ) { continue ; } $ this -> currentPath = $ match [ 'to' ] ; $ filePath = $ this -> getFilePathCollection ( $ this -> currentPath ) ; break ; } } } $ fileHistory = $ this -> fetchFileHistory ( $ this -> currentPath , $ git ) ; if ( ! \ count ( $ fileHistory ) ) { return ; } foreach ( $ fileHistory as $ pathHistory ) { $ filePath [ 'pathHistory' ] [ \ md5 ( $ pathHistory ) ] = $ this -> getFilePathCollection ( $ pathHistory ) ; } $ this -> setFilePathCollection ( $ this -> currentPath , $ filePath ) ; } | Build the file history . |
26,450 | private function getFileContent ( $ search , GitRepository $ git ) { $ cacheId = \ md5 ( __FUNCTION__ . $ search ) ; if ( ! $ this -> cachePool -> has ( $ cacheId ) ) { $ fileContent = $ git -> show ( ) -> execute ( $ search ) ; $ this -> cachePool -> set ( $ cacheId , $ fileContent ) ; return $ fileContent ; } return $ this -> cachePool -> get ( $ cacheId ) ; } | Get the file content . |
26,451 | private function fetchNameStatusFromCommit ( $ commitId , GitRepository $ git ) { $ arguments = [ $ git -> getConfig ( ) -> getGitExecutablePath ( ) , 'show' , $ commitId , '-M' , '--name-status' , '--format=' ] ; return $ this -> runCustomGit ( $ arguments , $ git ) ; } | Fetch the file names with status from the commit . |
26,452 | private function fetchCurrentCommit ( GitRepository $ git ) { return \ json_decode ( \ sprintf ( '[%s]' , $ git -> show ( ) -> format ( $ this -> logFormat ( ) ) -> execute ( '--quiet' ) ) , true ) ; } | Fetch the current commit . |
26,453 | private function fetchAllCommits ( GitRepository $ git ) { $ currentCommit = $ this -> fetchCurrentCommit ( $ git ) ; $ cacheId = \ md5 ( __FUNCTION__ . \ serialize ( $ currentCommit ) ) ; if ( ! $ this -> cachePool -> has ( $ cacheId ) ) { $ logList = \ json_decode ( \ sprintf ( '[%s]' , \ trim ( $ git -> log ( ) -> simplifyMerges ( ) -> format ( $ this -> logFormat ( ) . ',' ) -> execute ( ) , ',' ) ) , true ) ; $ this -> cachePool -> set ( $ cacheId , $ logList ) ; return $ logList ; } return $ this -> cachePool -> get ( $ cacheId ) ; } | Fetch the git log with simplify merges . |
26,454 | private function fetchFileHistory ( $ path , GitRepository $ git ) { $ fileHistory = [ ] ; foreach ( $ this -> fetchCommitCollectionByPath ( $ path , $ git ) as $ logItem ) { if ( \ count ( $ fileHistory ) && ! \ in_array ( $ logItem [ 'to' ] , $ fileHistory ) ) { continue ; } if ( ( $ logItem [ 'to' ] !== $ path ) && ! \ count ( $ fileHistory ) ) { continue ; } $ this -> executeFollowDetection ( $ logItem , $ fileHistory , $ git ) ; } return $ fileHistory ; } | Fetch the history for the file . |
26,455 | private function fetchCommitCollectionByPath ( $ path , GitRepository $ git ) { $ log = $ git -> log ( ) -> follow ( ) -> revisionRange ( '--name-status' ) -> revisionRange ( '--format=%H' ) -> execute ( $ path ) ; \ preg_match_all ( "/^(?'commit'.*)\n+(?'criteria'[RC])(?'index'[\d]{3})\t(?'from'.+)\t(?'to'.+)\n/m" , $ log , $ matches , PREG_SET_ORDER ) ; if ( ! \ count ( $ matches ) ) { return [ ] ; } $ logCollection = [ ] ; foreach ( ( array ) $ matches as $ match ) { $ logCollection [ ] = \ array_filter ( $ match , 'is_string' , ARRAY_FILTER_USE_KEY ) ; } return $ logCollection ; } | Fetch the commit collection by the file path . |
26,456 | private function executeFollowDetection ( array $ logItem , array & $ fileHistory , GitRepository $ git ) { $ currentCommit = $ this -> commitCollection [ $ logItem [ 'commit' ] ] ; if ( ( $ logItem [ 'index' ] <= 70 ) && \ in_array ( $ logItem [ 'criteria' ] , [ 'R' , 'C' ] ) ) { if ( isset ( $ currentCommit [ 'information' ] [ \ md5 ( $ logItem [ 'to' ] ) ] ) ) { $ pathInformation = $ currentCommit [ 'information' ] [ \ md5 ( $ logItem [ 'to' ] ) ] ; if ( isset ( $ pathInformation [ 'status' ] ) && ( $ pathInformation [ 'status' ] === 'A' ) ) { return ; } } } $ this -> renamingDetection ( $ logItem , $ currentCommit , $ fileHistory , $ git ) ; $ this -> copyDetection ( $ logItem , $ fileHistory , $ git ) ; } | Execute the file follow detection . |
26,457 | private function renamingDetection ( array $ logItem , array $ currentCommit , array & $ fileHistory , GitRepository $ git ) { if ( $ logItem [ 'criteria' ] !== 'R' ) { return ; } if ( ( int ) $ logItem [ 'index' ] >= 75 ) { $ fileHistory [ \ md5 ( $ logItem [ 'from' ] ) ] = $ logItem [ 'from' ] ; return ; } $ fromFileContent = $ this -> getFileContent ( $ currentCommit [ 'parent' ] . ':' . $ logItem [ 'from' ] , $ git ) ; $ toFileContent = $ this -> getFileContent ( $ logItem [ 'commit' ] . ':' . $ logItem [ 'to' ] , $ git ) ; $ tempFrom = $ this -> createTempFile ( $ logItem [ 'commit' ] . ':' . $ logItem [ 'from' ] , $ fromFileContent ) ; $ tempTo = $ this -> createTempFile ( $ logItem [ 'commit' ] . ':' . $ logItem [ 'to' ] , $ toFileContent ) ; $ detector = new Detector ( new DefaultStrategy ( ) ) ; $ result = $ detector -> copyPasteDetection ( [ $ tempFrom , $ tempTo ] , 2 , 7 ) ; if ( ! $ result -> count ( ) ) { return ; } $ fileHistory [ \ md5 ( $ logItem [ 'from' ] ) ] = $ logItem [ 'from' ] ; } | Detected file follow by the renaming criteria . |
26,458 | private function copyDetection ( array $ logItem , array & $ fileHistory , GitRepository $ git ) { if ( $ logItem [ 'criteria' ] !== 'C' ) { return ; } $ fromLastCommit = $ this -> commitCollection [ $ logItem [ 'commit' ] ] [ 'parent' ] ; $ fromFileContent = $ this -> getFileContent ( $ fromLastCommit . ':' . $ logItem [ 'from' ] , $ git ) ; $ fromFileContentLength = \ strlen ( $ fromFileContent ) ; $ toFileContent = $ this -> getFileContent ( $ logItem [ 'commit' ] . ':' . $ logItem [ 'to' ] , $ git ) ; $ toFileContentLength = \ strlen ( $ toFileContent ) ; if ( $ fromFileContentLength === $ toFileContentLength ) { $ fileHistory [ \ md5 ( $ logItem [ 'from' ] ) ] = $ logItem [ 'from' ] ; return ; } $ tempFrom = $ this -> createTempFile ( $ logItem [ 'commit' ] . ':' . $ logItem [ 'from' ] , $ fromFileContent ) ; $ tempTo = $ this -> createTempFile ( $ logItem [ 'commit' ] . ':' . $ logItem [ 'to' ] , $ toFileContent ) ; $ detector = new Detector ( new DefaultStrategy ( ) ) ; $ result = $ detector -> copyPasteDetection ( [ $ tempFrom , $ tempTo ] , 5 , 35 ) ; if ( ! $ result -> count ( ) ) { return ; } $ fileHistory [ \ md5 ( $ logItem [ 'from' ] ) ] = $ logItem [ 'from' ] ; } | Detected file follow by the copy criteria . |
26,459 | private function createTempFile ( $ name , $ content ) { $ tempDir = \ sys_get_temp_dir ( ) ; $ fileName = \ md5 ( $ name ) ; $ filePath = $ tempDir . DIRECTORY_SEPARATOR . 'phpcq-author-validation' . DIRECTORY_SEPARATOR . $ fileName ; if ( \ file_exists ( $ filePath ) ) { return $ filePath ; } if ( ! \ file_exists ( \ dirname ( $ filePath ) ) && ! \ mkdir ( $ concurrentDirectory = \ dirname ( $ filePath ) ) && ! is_dir ( $ concurrentDirectory ) ) { throw new \ RuntimeException ( sprintf ( 'Directory "%s" was not created' , $ concurrentDirectory ) ) ; } $ file = \ fopen ( $ filePath , 'wb' ) ; \ fwrite ( $ file , $ content ) ; return $ filePath ; } | Create a temporary file . |
26,460 | private function removeTempDirectory ( ) { $ tempDir = \ sys_get_temp_dir ( ) ; $ directoryPath = $ tempDir . DIRECTORY_SEPARATOR . 'phpcq-author-validation' ; if ( ! \ file_exists ( $ directoryPath ) ) { return ; } $ directory = \ opendir ( $ directoryPath ) ; while ( ( $ file = \ readdir ( $ directory ) ) !== false ) { if ( \ in_array ( $ file , [ '.' , '..' ] ) ) { continue ; } \ unlink ( $ directoryPath . DIRECTORY_SEPARATOR . $ file ) ; } \ rmdir ( $ directoryPath ) ; } | Remove the temporary directory . |
26,461 | public function save ( ) { $ this -> load ( ) ; if ( $ this -> isChanged ( ) ) { @ chmod ( $ this -> path , 0777 ) ; return file_put_contents ( $ this -> path , $ this -> fileType -> render ( $ this -> config ) ) ; } else { return true ; } } | Saves the content to the disk |
26,462 | public function store ( $ key , $ value ) { $ this -> load ( ) ; $ this -> config [ $ key ] = $ value ; return true ; } | Writes configuration pair |
26,463 | public function storeMany ( array $ pair ) { foreach ( $ pair as $ key => $ value ) { $ this -> set ( $ key , $ value ) ; } return true ; } | Sets a collection |
26,464 | public function get ( $ key , $ default = false ) { $ this -> load ( ) ; if ( $ this -> has ( $ key ) ) { return $ this -> config [ $ key ] ; } else { return $ default ; } } | Reads a value by a given key |
26,465 | public function remove ( $ key ) { $ this -> load ( ) ; if ( $ this -> exists ( $ key ) ) { unset ( $ this -> config [ $ key ] ) ; return true ; } else { throw new RuntimeException ( sprintf ( 'Attempted to read non-existing key "%s"' , $ key ) ) ; } } | Deletes configuration value by its associated key |
26,466 | private function load ( ) { if ( $ this -> loaded === false ) { if ( $ this -> autoCreate === true ) { if ( ! is_file ( $ this -> path ) ) { $ this -> touch ( ) ; } } $ array = $ this -> fileType -> fetch ( $ this -> path ) ; if ( is_array ( $ array ) ) { $ this -> hash = $ this -> serializer -> buildHash ( $ array ) ; $ this -> config = $ array ; $ this -> loaded = true ; return true ; } else { throw new LogicException ( sprintf ( 'Required file should return an array and only, not "%s"' , gettype ( $ array ) ) ) ; } } return true ; } | Loads configuration into memory on demand |
26,467 | public function get ( $ service ) { if ( $ this -> has ( $ service ) ) { return $ this -> container [ $ service ] ; } else { throw new RuntimeException ( sprintf ( 'Attempted to grab non-existing service "%s"' , $ service ) ) ; } } | Returns service s instance by its name |
26,468 | public function registerArray ( array $ instances ) { foreach ( $ instances as $ name => $ instance ) { $ this -> register ( $ name , $ instance ) ; } return $ this ; } | Registers a collection of service instances |
26,469 | public function register ( $ name , $ instance ) { if ( ! is_string ( $ name ) ) { throw new InvalidArgumentException ( sprintf ( 'Argument #1 $name must be a string, received "%s"' , gettype ( $ name ) ) ) ; } $ this -> container [ $ name ] = $ instance ; return $ this ; } | Registers a new service |
26,470 | public function has ( $ service ) { if ( ! is_string ( $ service ) ) { throw new InvalidArgumentException ( sprintf ( 'Service name must be a string, received "%s"' , gettype ( $ service ) ) ) ; } return isset ( $ this -> container [ $ service ] ) ; } | Check whether service has been registered |
26,471 | public function remove ( $ service ) { if ( $ this -> has ( $ service ) ) { unset ( $ this -> container [ $ service ] ) ; return true ; } else { trigger_error ( sprintf ( 'Attempted to un-register non-existing service "%s"' , $ service ) ) ; return false ; } } | Removes a registered service |
26,472 | public static function get_pure_post_content ( ) { $ post = get_post ( ) ; if ( ! $ post || ! isset ( $ post -> post_content ) ) { return ; } if ( post_password_required ( $ post ) ) { return ; } $ extended = get_extended ( $ post -> post_content ) ; $ content = $ extended [ 'main' ] ; return $ content ; } | Return pure post content |
26,473 | public static function pure_trim_excerpt ( ) { $ raw_excerpt = '' ; $ text = static :: get_pure_post_content ( ) ; $ text = strip_shortcodes ( $ text ) ; $ text = str_replace ( ']]>' , ']]>' , $ text ) ; $ excerpt_length = apply_filters ( 'excerpt_length' , 55 ) ; $ excerpt_more = apply_filters ( 'excerpt_more' , ' […]' ) ; $ text = wp_trim_words ( $ text , $ excerpt_length , $ excerpt_more ) ; return apply_filters ( 'wp_trim_excerpt' , $ text , $ raw_excerpt ) ; } | Return pure trim excerpt |
26,474 | public static function get_page_templates ( ) { static $ wrappers = [ ] ; if ( $ wrappers ) { return $ wrappers ; } $ page_templates = new Model \ Page_Templates ( ) ; $ wrappers = $ page_templates -> get ( ) ; return $ wrappers ; } | Returns array of page templates for layout selector in customizer |
26,475 | public function last ( ) { if ( $ this -> count ( ) ) { $ models = $ this -> getModels ( ) ; return $ models [ $ this -> count ( ) - 1 ] ; } return null ; } | Obtiene el ultimo modelo de la lista |
26,476 | public function json ( $ fields = array ( ) , $ recursive = true ) { $ list = array ( ) ; foreach ( $ this -> getModels ( ) as $ model ) { $ list [ ] = $ model -> json ( $ fields , $ recursive ) ; } return $ list ; } | Genera una array lista para usar con json_encode |
26,477 | public function order ( $ field , $ desc = false ) { if ( count ( $ this -> models ) > 0 ) { $ instance = $ this -> reflection -> newInstance ( ) ; $ string = $ instance -> isString ( $ field ) ; usort ( $ this -> models , function ( $ a , $ b ) use ( $ field , $ string ) { if ( $ string ) { return strcmp ( $ a [ $ field ] , $ b [ $ field ] ) ; } return $ a [ $ field ] - $ b [ $ field ] ; } ) ; if ( $ desc ) { $ this -> models = array_reverse ( $ this -> models ) ; } } return $ this ; } | Ordena de menor a mayor en funcion del campo indicado |
26,478 | public static function send ( Bookboon $ bookboon , array $ variables = [ ] , string $ rootSegmentId = '' ) : BookboonResponse { $ url = $ rootSegmentId == '' ? '/questions' : '/questions/' . $ rootSegmentId ; $ bResponse = $ bookboon -> rawRequest ( $ url , $ variables , ClientInterface :: HTTP_POST ) ; return $ bResponse ; } | Post Questions . |
26,479 | public function getThumbnail ( int $ size = 210 , bool $ ssl = false ) { $ thumbs = [ ] ; foreach ( $ this -> safeGet ( 'thumbnail' ) as $ thumb ) { $ thumbs [ $ thumb [ 'width' ] ] = $ thumb [ '_link' ] ; } $ sizes = array_keys ( $ thumbs ) ; while ( true ) { $ thumbSize = array_shift ( $ sizes ) ; if ( ( int ) $ size <= ( int ) $ thumbSize || count ( $ sizes ) === 0 ) { return $ thumbs [ $ thumbSize ] ; } } } | Returns closes thumbnail size to input default 210px . |
26,480 | public function authenticate ( $ login , $ password ) { if ( ! isset ( $ this -> server [ 'PHP_AUTH_USER' ] ) ) { $ this -> forbid ( ) ; return false ; } else { if ( ( $ this -> server [ 'PHP_AUTH_USER' ] == $ login ) && ( $ this -> server [ 'PHP_AUTH_PW' ] == $ password ) ) { return true ; } else { $ this -> forbid ( ) ; return false ; } } } | Performs HTTP - digest authentication |
26,481 | public function setStatusCode ( $ code ) { $ this -> headerBag -> setStatusCode ( $ code ) ; $ this -> statusCode = $ code ; return $ this ; } | Prepared and appends HTTP status message to the queue by associated code |
26,482 | public function enableCache ( $ timestamp , $ ttl ) { $ handler = new HttpCache ( $ this -> headerBag ) ; $ handler -> configure ( $ timestamp , $ ttl ) ; return $ this ; } | Enables internal HTTP cache mechanism |
26,483 | public function setContentType ( $ type ) { $ this -> headerBag -> appendPair ( 'Content-Type' , sprintf ( '%s;charset=%s' , $ type , $ this -> charset ) ) ; return $ this ; } | Generates and appends to the queue Content - Type header |
26,484 | public function getBlockTemplate ( int $ reserveSize , string $ address ) : JsonResponse { $ params = [ 'reserve_size' => $ reserveSize , 'wallet_address' => $ address , ] ; return $ this -> rpcPost ( 'getblocktemplate' , $ params ) ; } | Returns block template with an empty hole for nonce . |
26,485 | public static function TweetHandler ( $ arguments ) { if ( ! isset ( $ arguments [ 'id' ] ) ) { return null ; } if ( substr ( $ arguments [ 'id' ] , 0 , 4 ) === 'http' ) { list ( $ unneeded , $ id ) = explode ( '/status/' , $ arguments [ 'id' ] ) ; } else { $ id = $ arguments [ 'id' ] ; } $ data = json_decode ( file_get_contents ( 'https://api.twitter.com/1/statuses/oembed.json?id=' . $ id . '&omit_script=true&lang=en' ) , 1 ) ; return $ data [ 'html' ] ; } | The following three functions are global once enabled! |
26,486 | public function isSamePrimaryResource ( Uri $ uri ) { if ( ! $ this -> isAbsolute ( ) || ! $ uri -> isAbsolute ( ) ) { throw new \ LogicException ( 'Cannot compare URIs: both must be absolute' ) ; } return $ this -> primaryIdentifier === $ uri -> getPrimaryResourceIdentifier ( ) ; } | Returns whether two URIs share the same primary resource identifier i . e . whether they point to the same document . |
26,487 | protected function normalizeOptions ( array $ options , array $ value ) { return $ options [ 'select2' ] [ 'enabled' ] ? array_merge ( $ value , [ 'error_bubbling' => false , 'multiple' => false , 'select2' => array_merge ( $ options [ 'select2' ] , [ 'tags' => $ options [ 'allow_add' ] , ] ) , ] ) : $ value ; } | Normalise the options for selector . |
26,488 | public function getUniqueName ( ) { $ key = 'uniq' ; if ( ! isset ( $ this -> container [ $ key ] ) ) { $ extension = $ this -> getExtension ( ) ; if ( $ extension ) { $ name = sprintf ( '%s.%s' , uniqid ( ) , $ extension ) ; } else { $ name = uniqid ( ) ; } $ this -> container [ $ key ] = $ name ; } return $ this -> container [ $ key ] ; } | Returns unique name for uploaded file |
26,489 | public function updateCMSFields ( FieldList $ fields ) { $ owner = $ this -> owner ; $ fields -> removeByName ( array ( 'News' , 'NewsID' , 'SortOrder' ) ) ; $ fields -> addFieldsToTab ( 'Root.Main' , array ( TextField :: create ( 'Title' , $ owner -> fieldLabel ( 'Title' ) ) , HtmlEditorField :: create ( 'Description' , $ owner -> fieldLabel ( 'Description' ) ) , UploadField :: create ( 'Image' , $ owner -> fieldLabel ( 'Image' ) ) , ) ) ; } | Setup the CMSFields |
26,490 | public function setPutFromRequest ( ) { if ( $ this -> _put === null ) { if ( $ _SERVER [ 'REQUEST_METHOD' ] == 'PUT' ) { $ this -> _put = file_get_contents ( "php://input" ) ; } } else { $ this -> _put = '' ; } } | get the string sent as put |
26,491 | public function redirectForTrailingSlash ( ) { $ config = \ Nf \ Registry :: get ( 'config' ) ; $ redirectionUrl = false ; $ requestParams = '' ; $ requestPage = '/' . $ this -> _uri ; if ( $ requestPage != '/' && mb_strpos ( $ requestPage , '/?' ) !== 0 ) { if ( mb_strpos ( $ requestPage , '?' ) !== false ) { $ requestParams = mb_substr ( $ requestPage , mb_strpos ( $ requestPage , '?' ) , mb_strlen ( $ requestPage ) - mb_strpos ( $ requestPage , '?' ) ) ; $ requestPage = mb_substr ( $ requestPage , 0 , mb_strpos ( $ requestPage , '?' ) ) ; } if ( isset ( $ config -> trailingSlash -> needed ) && $ config -> trailingSlash -> needed == true ) { if ( mb_substr ( $ requestPage , - 1 , 1 ) != '/' ) { $ redirectionUrl = 'http://' . $ _SERVER [ 'HTTP_HOST' ] . $ requestPage . '/' . $ requestParams ; } } else { if ( mb_substr ( $ requestPage , - 1 , 1 ) == '/' ) { $ redirectionUrl = 'http://' . $ _SERVER [ 'HTTP_HOST' ] . rtrim ( $ requestPage , '/' ) . $ requestParams ; } } if ( $ redirectionUrl !== false ) { $ response = new \ Nf \ Front \ Response \ Http ( ) ; $ response -> redirect ( $ redirectionUrl , 301 ) ; $ response -> sendHeaders ( ) ; return true ; } } return false ; } | handle the redirection according to the trailing slash configuration |
26,492 | public static function isChildPost ( $ postOrPostId = null ) { $ post = self :: getPost ( $ postOrPostId ) ; if ( empty ( $ post ) ) { return false ; } return $ post -> post_parent > 0 ; } | Checks if the given post is a child . |
26,493 | public static function getNextParentPost ( $ inSameTerm = false , $ excludedTerms = '' , $ taxonomy = 'category' ) { add_filter ( 'get_next_post_where' , [ __CLASS__ , 'addParentPostToAdjacentSql' ] ) ; return get_adjacent_post ( $ inSameTerm , $ excludedTerms , false , $ taxonomy ) ; } | Get the next adjacent parent post . |
26,494 | public static function getPreviousParentPost ( $ inSameTerm = false , $ excludedTerms = '' , $ taxonomy = 'category' ) { add_filter ( 'get_previous_post_where' , [ __CLASS__ , 'addParentPostToAdjacentSql' ] ) ; return get_adjacent_post ( $ inSameTerm , $ excludedTerms , true , $ taxonomy ) ; } | Get the previous adjacent parent post . |
26,495 | public static function extractPostId ( $ postOrPostId = null ) { if ( is_object ( $ postOrPostId ) ) { return property_exists ( $ postOrPostId , 'ID' ) ? ( int ) $ postOrPostId -> ID : null ; } if ( $ postOrPostId > 0 ) { return ( int ) $ postOrPostId ; } return get_the_ID ( ) ; } | Get the post ID from the given post or post ID . If none is passed in then it grabs the current ID . |
26,496 | public function createRandomized ( $ minDistance = - 0.005 , $ maxDistance = 0.005 ) { $ newCoordinates = Geo :: calculateNewCoordinates ( $ this -> latitude , $ this -> longitude , Random :: randomFloat ( $ minDistance , $ maxDistance ) , rand ( 0 , 360 ) ) ; $ newAltitude = $ this -> altitude + round ( Random :: randomFloat ( - 2 , 2 ) , 2 ) ; $ newAccuracy = mt_rand ( 3 , 10 ) ; return new self ( $ newCoordinates [ 0 ] , $ newCoordinates [ 1 ] , $ newAltitude , $ newAccuracy ) ; } | Creates a randomized version of this approximate position |
26,497 | protected static function extractChoiceLoader ( $ form ) { $ form = static :: getForm ( $ form ) ; $ choiceLoader = $ form -> getAttribute ( 'choice_loader' , $ form -> getOption ( 'choice_loader' ) ) ; return $ choiceLoader ; } | Extracts the ajax choice loader . |
26,498 | protected static function extractAjaxFormatter ( $ form ) { $ form = static :: getForm ( $ form ) ; $ formatter = $ form -> getAttribute ( 'select2' , $ form -> getOption ( 'select2' ) ) ; $ formatter = $ formatter [ 'ajax_formatter' ] ; if ( ! $ formatter instanceof AjaxChoiceListFormatterInterface ) { throw new UnexpectedTypeException ( $ formatter , 'Fxp\Component\FormExtensions\Form\ChoiceList\Formatter\AjaxChoiceListFormatterInterface' ) ; } return $ formatter ; } | Extracts the ajax formatter . |
26,499 | public static function camelize ( $ string , $ delimiter = ' ' ) : string { $ stringParts = explode ( $ delimiter , $ string ) ; $ camelized = array_map ( 'ucwords' , $ stringParts ) ; return implode ( $ delimiter , $ camelized ) ; } | Turns every first letter in every word in the string into a camel cased letter |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.