idx int64 0 60.3k | question stringlengths 92 4.62k | target stringlengths 7 635 |
|---|---|---|
59,400 | public function clearFeatureData ( $ feature ) { $ feature = $ this -> get ( $ feature ) ; if ( $ feature ) { $ feature -> setData ( array ( ) ) ; $ this -> save ( $ feature ) ; } } | Clear all feature data |
59,401 | public function after ( $ content ) { $ content = self :: create ( $ content ) ; $ newnodes = array ( ) ; foreach ( $ this as $ i => $ node ) { $ refnode = $ node -> nextSibling ; foreach ( $ content as $ newnode ) { $ newnode = static :: importNewnode ( $ newnode , $ node , $ i ) ; if ( $ refnode === null ) { $ node -... | Insert content specified by the parameter after each element in the set of matched elements . |
59,402 | public function append ( $ content ) { $ content = self :: create ( $ content ) ; $ newnodes = array ( ) ; foreach ( $ this as $ i => $ node ) { foreach ( $ content as $ newnode ) { $ newnode = static :: importNewnode ( $ newnode , $ node , $ i ) ; $ node -> appendChild ( $ newnode ) ; $ newnodes [ ] = $ newnode ; } } ... | Insert HTML content as child nodes of each element after existing children |
59,403 | public function setAttribute ( $ name , $ value ) { foreach ( $ this as $ node ) { if ( $ node instanceof \ DOMElement ) { $ node -> setAttribute ( $ name , $ value ) ; } } return $ this ; } | Sets an attribute on each element |
59,404 | public function before ( $ content ) { $ content = self :: create ( $ content ) ; $ newnodes = array ( ) ; foreach ( $ this as $ i => $ node ) { foreach ( $ content as $ newnode ) { if ( $ node !== $ newnode ) { $ newnode = static :: importNewnode ( $ newnode , $ node , $ i ) ; $ node -> parentNode -> insertBefore ( $ ... | Insert content specified by the parameter before each element in the set of matched elements . |
59,405 | public function css ( $ key , $ value = null ) { if ( null === $ value ) { return $ this -> getStyle ( $ key ) ; } else { return $ this -> setStyle ( $ key , $ value ) ; } } | Get one CSS style property of the first element or set it for all elements in the list |
59,406 | public function getStyle ( $ key ) { $ styles = Helpers :: cssStringToArray ( $ this -> getAttribute ( 'style' ) ) ; return ( isset ( $ styles [ $ key ] ) ? $ styles [ $ key ] : null ) ; } | get one CSS style property of the first element |
59,407 | public function setStyle ( $ key , $ value ) { foreach ( $ this as $ node ) { if ( $ node instanceof \ DOMElement ) { $ styles = Helpers :: cssStringToArray ( $ node -> getAttribute ( 'style' ) ) ; if ( $ value != '' ) { $ styles [ $ key ] = $ value ; } elseif ( isset ( $ styles [ $ key ] ) ) { unset ( $ styles [ $ key... | set one CSS style property for all elements in the list |
59,408 | public function setInnerHtml ( $ content ) { $ content = self :: create ( $ content ) ; foreach ( $ this as $ node ) { $ node -> nodeValue = '' ; foreach ( $ content as $ newnode ) { $ newnode = static :: importNewnode ( $ newnode , $ node ) ; $ node -> appendChild ( $ newnode ) ; } } return $ this ; } | Set the HTML contents of each element |
59,409 | public function insertAfter ( $ element ) { $ e = self :: create ( $ element ) ; $ newnodes = array ( ) ; foreach ( $ e as $ i => $ node ) { $ refnode = $ node -> nextSibling ; foreach ( $ this as $ newnode ) { $ newnode = static :: importNewnode ( $ newnode , $ node , $ i ) ; if ( $ refnode === null ) { $ node -> pare... | Insert every element in the set of matched elements after the target . |
59,410 | public function insertBefore ( $ element ) { $ e = self :: create ( $ element ) ; $ newnodes = array ( ) ; foreach ( $ e as $ i => $ node ) { foreach ( $ this as $ newnode ) { $ newnode = static :: importNewnode ( $ newnode , $ node , $ i ) ; if ( $ newnode !== $ node ) { $ node -> parentNode -> insertBefore ( $ newnod... | Insert every element in the set of matched elements before the target . |
59,411 | public function prepend ( $ content ) { $ content = self :: create ( $ content ) ; $ newnodes = array ( ) ; foreach ( $ this as $ i => $ node ) { $ refnode = $ node -> firstChild ; foreach ( $ content as $ newnode ) { $ newnode = static :: importNewnode ( $ newnode , $ node , $ i ) ; if ( $ refnode === null ) { $ node ... | Insert content specified by the parameter to the beginning of each element in the set of matched elements . |
59,412 | public function remove ( ) { foreach ( $ this as $ node ) { if ( $ node -> parentNode instanceof \ DOMElement ) { $ node -> parentNode -> removeChild ( $ node ) ; } } $ this -> clear ( ) ; } | Remove the set of matched elements from the DOM . |
59,413 | public function removeAttribute ( $ name ) { foreach ( $ this as $ node ) { if ( $ node instanceof \ DOMElement ) { if ( $ node -> hasAttribute ( $ name ) ) { $ node -> removeAttribute ( $ name ) ; } } } return $ this ; } | Remove an attribute from each element in the set of matched elements . |
59,414 | public function removeClass ( $ name ) { foreach ( $ this as $ node ) { if ( $ node instanceof \ DOMElement ) { $ classes = preg_split ( '/\s+/s' , $ node -> getAttribute ( 'class' ) ) ; $ count = count ( $ classes ) ; for ( $ i = 0 ; $ i < $ count ; $ i ++ ) { if ( $ classes [ $ i ] == $ name ) { unset ( $ classes [ $... | Remove a class from each element in the list |
59,415 | public function replaceAll ( $ element ) { $ e = self :: create ( $ element ) ; $ newnodes = array ( ) ; foreach ( $ e as $ i => $ node ) { $ parent = $ node -> parentNode ; $ refnode = $ node -> nextSibling ; foreach ( $ this as $ j => $ newnode ) { $ newnode = static :: importNewnode ( $ newnode , $ node , $ i ) ; if... | Replace each target element with the set of matched elements . |
59,416 | public function unwrap ( ) { $ parents = array ( ) ; foreach ( $ this as $ i => $ node ) { $ parents [ ] = $ node -> parentNode ; } self :: create ( $ parents ) -> unwrapInner ( ) ; return $ this ; } | Remove the parents of the set of matched elements from the DOM leaving the matched elements in their place . |
59,417 | public function unwrapInner ( ) { foreach ( $ this as $ i => $ node ) { if ( ! $ node -> parentNode instanceof \ DOMElement ) { throw new \ InvalidArgumentException ( 'DOMElement does not have a parent DOMElement node.' ) ; } $ children = iterator_to_array ( $ node -> childNodes ) ; foreach ( $ children as $ child ) { ... | Remove the matched elements but promote the children to take their place . |
59,418 | public function wrapAll ( $ content ) { $ content = self :: create ( $ content ) ; $ parent = $ this -> getNode ( 0 ) -> parentNode ; foreach ( $ this as $ i => $ node ) { if ( $ node -> parentNode !== $ parent ) { throw new \ LogicException ( 'Nodes to be wrapped with wrapAll() must all have the same parent' ) ; } } $... | Wrap an HTML structure around all elements in the set of matched elements . |
59,419 | public function wrapInner ( $ content ) { foreach ( $ this as $ i => $ node ) { self :: create ( $ node -> childNodes ) -> wrapAll ( $ content ) ; } return $ this ; } | Wrap an HTML structure around the content of each element in the set of matched elements . |
59,420 | public function saveHTML ( ) { if ( $ this -> isHtmlDocument ( ) ) { return $ this -> getDOMDocument ( ) -> saveHTML ( ) ; } else { $ doc = new \ DOMDocument ( '1.0' , 'UTF-8' ) ; $ root = $ doc -> appendChild ( $ doc -> createElement ( '_root' ) ) ; foreach ( $ this as $ node ) { $ root -> appendChild ( $ doc -> impor... | Get the HTML code fragment of all elements and their contents . |
59,421 | public function getDOMDocument ( ) { $ node = $ this -> getNode ( 0 ) ; $ r = null ; if ( $ node instanceof \ DOMElement && $ node -> ownerDocument instanceof \ DOMDocument ) { $ r = $ node -> ownerDocument ; } return $ r ; } | get ownerDocument of the first element |
59,422 | public function setTitle ( $ title ) { $ t = $ this -> dom -> getElementsByTagName ( 'title' ) -> item ( 0 ) ; if ( $ t == null ) { $ t = $ this -> dom -> createElement ( 'title' ) ; $ this -> getHeadNode ( ) -> appendChild ( $ t ) ; } $ t -> nodeValue = htmlspecialchars ( $ title ) ; } | Sets the page title of the HTML document |
59,423 | public function getTitle ( ) { $ t = $ this -> dom -> getElementsByTagName ( 'title' ) -> item ( 0 ) ; if ( $ t == null ) { return null ; } else { return $ t -> nodeValue ; } } | Get the page title of the HTML document |
59,424 | public function setMeta ( $ name , $ content ) { $ c = $ this -> filterXPath ( 'descendant-or-self::meta[@name = \'' . $ name . '\']' ) ; if ( count ( $ c ) == 0 ) { $ node = $ this -> dom -> createElement ( 'meta' ) ; $ node -> setAttribute ( 'name' , $ name ) ; $ this -> getHeadNode ( ) -> appendChild ( $ node ) ; $ ... | Set a META tag with specified name and content attributes |
59,425 | public function getMeta ( $ name ) { $ node = $ this -> filterXPath ( 'descendant-or-self::meta[@name = \'' . $ name . '\']' ) -> getNode ( 0 ) ; if ( $ node instanceof \ DOMElement ) { return $ node -> getAttribute ( 'content' ) ; } else { return null ; } } | Get the content attribute of a meta tag with the specified name attribute |
59,426 | public function getBaseHref ( ) { $ node = $ this -> filterXPath ( 'descendant-or-self::base' ) -> getNode ( 0 ) ; if ( $ node instanceof \ DOMElement ) { return $ node -> getAttribute ( 'href' ) ; } else { return null ; } } | Get the href attribute from the base tag null if not present in document |
59,427 | public function getHeadNode ( ) { $ head = $ this -> dom -> getElementsByTagName ( 'head' ) -> item ( 0 ) ; if ( $ head == null ) { $ head = $ this -> dom -> createElement ( 'head' ) ; $ head = $ this -> dom -> documentElement -> insertBefore ( $ head , $ this -> getBodyNode ( ) ) ; } return $ head ; } | Get the document s HEAD section as DOMElement |
59,428 | public function getBodyNode ( ) { $ body = $ this -> dom -> getElementsByTagName ( 'body' ) -> item ( 0 ) ; if ( $ body == null ) { $ body = $ this -> dom -> createElement ( 'body' ) ; $ body = $ this -> dom -> documentElement -> appendChild ( $ body ) ; } return $ body ; } | Get the document s body as DOMElement |
59,429 | public function minify ( array $ options = array ( ) ) { if ( ! class_exists ( 'Wa72\\HtmlPrettymin\\PrettyMin' ) ) { throw new \ Exception ( 'Function minify needs composer package wa72/html-pretty-min' ) ; } $ pm = new PrettyMin ( $ options ) ; $ pm -> load ( $ this -> dom ) -> minify ( ) ; return $ this ; } | minify the HTML document |
59,430 | public static function cssStringToArray ( $ css ) { $ statements = explode ( ';' , preg_replace ( '/\s+/s' , ' ' , $ css ) ) ; $ styles = array ( ) ; foreach ( $ statements as $ statement ) { $ statement = trim ( $ statement ) ; if ( '' === $ statement ) { continue ; } $ p = strpos ( $ statement , ':' ) ; if ( $ p <= 0... | Convert CSS string to array |
59,431 | public static function getBodyNodeFromHtmlFragment ( $ html , $ charset = 'UTF-8' ) { $ html = '<html><body>' . $ html . '</body></html>' ; $ current = libxml_use_internal_errors ( true ) ; $ disableEntities = libxml_disable_entity_loader ( true ) ; $ d = new \ DOMDocument ( '1.0' , $ charset ) ; $ d -> validateOnParse... | Helper function for getting a body element from an HTML fragment |
59,432 | private function prefixWithDateIfFound ( AbstractFile $ file , string $ outputPath ) : string { if ( $ file -> getDate ( ) === null ) { return $ outputPath ; } return str_replace ( [ ':year' , ':month' , ':day' ] , [ $ file -> getDateInFormat ( 'Y' ) , $ file -> getDateInFormat ( 'm' ) , $ file -> getDateInFormat ( 'd'... | Only if the date is part of file name |
59,433 | private function updateScore ( Element $ node , float $ addToScore ) : void { $ currentScore = ( float ) $ node -> attr ( 'gravityScore' ) ; $ node -> attr ( 'gravityScore' , ( string ) ( $ currentScore + $ addToScore ) ) ; } | Adds a score to the gravityScore Attribute we put on divs we ll get the current score then add the score we re passing in to the current |
59,434 | private function updateNodeCount ( Element $ node , int $ addToCount ) : void { $ currentScore = ( int ) $ node -> attr ( 'gravityNodes' ) ; $ node -> attr ( 'gravityNodes' , ( string ) ( $ currentScore + $ addToCount ) ) ; } | Stores how many decent nodes are under a parent node |
59,435 | private function getVideos ( ) : array { $ videos = [ ] ; $ topNode = $ this -> article ( ) -> getTopNode ( ) ; if ( $ topNode instanceof Element && $ topNode -> parent ( ) instanceof Element ) { $ nodes = $ topNode -> parent ( ) -> find ( 'embed, object, iframe, video' ) ; foreach ( $ nodes as $ node ) { if ( $ node -... | Pulls out videos we like |
59,436 | private function getLinks ( ) : array { $ goodLinks = [ ] ; $ parentNode = $ this -> article ( ) -> getTopNode ( ) -> parent ( ) ; if ( $ parentNode instanceof Element ) { $ candidates = $ parentNode -> find ( 'a[href]' ) ; foreach ( $ candidates as $ el ) { if ( $ el -> attr ( 'href' ) != '#' && trim ( $ el -> attr ( ... | Pulls out links we like |
59,437 | public function getTopNode ( ) : ? Element { $ nodes = $ this -> getTopNodeCandidatesByContents ( $ this -> article ( ) ) ; $ nodeCandidates = [ ] ; $ i = 0 ; foreach ( $ nodes as $ node ) { if ( $ this -> isOkToBoost ( $ node ) ) { $ upscore = $ this -> getTopNodeCandidateScore ( $ node , $ i , count ( $ nodes ) ) ; $... | We re going to start looking for where the clusters of paragraphs are . We ll score a cluster based on the number of stopwords and the number of consecutive paragraphs together which should form the cluster of text that this node is around also store on how high up the paragraphs are comments are usually at the bottom ... |
59,438 | private function isOkToBoost ( Element $ node ) : bool { $ stepsAway = 0 ; $ minimumStopWordCount = 5 ; $ maxStepsAwayFromNode = 3 ; $ siblings = $ node -> precedingAll ( function ( $ node ) { return $ node instanceof Element ; } ) ; foreach ( $ siblings as $ sibling ) { if ( $ sibling -> is ( 'p, strong' ) ) { if ( $ ... | A lot of times the first paragraph might be the caption under an image so we ll want to make sure if we re going to boost a parent node that it should be connected to other paragraphs at least for the first n paragraphs so we ll want to make sure that the next sibling is a paragraph and has at least some substantial we... |
59,439 | private function getDateFromSchemaOrg ( ) : ? \ DateTime { $ dt = null ; $ nodes = $ this -> article ( ) -> getRawDoc ( ) -> find ( '*[itemprop="datePublished"]' ) ; foreach ( $ nodes as $ node ) { try { if ( $ node -> hasAttribute ( 'datetime' ) ) { $ dt = new \ DateTime ( $ node -> getAttribute ( 'datetime' ) ) ; bre... | Check for and determine dates from Schema . org s datePublished property . |
59,440 | private function getDateFromDublinCore ( ) : ? \ DateTime { $ dt = null ; $ nodes = $ this -> article ( ) -> getRawDoc ( ) -> find ( '*[name="dc.date"], *[name="dc.date.issued"], *[name="DC.date.issued"]' ) ; foreach ( $ nodes as $ node ) { try { if ( $ node -> hasAttribute ( 'content' ) ) { $ dt = new \ DateTime ( $ n... | Check for and determine dates based on Dublin Core standards . |
59,441 | private function getDateFromOpenGraph ( ) : ? \ DateTime { $ dt = null ; $ og_data = $ this -> article ( ) -> getOpenGraph ( ) ; try { if ( isset ( $ og_data [ 'published_time' ] ) ) { $ dt = new \ DateTime ( $ og_data [ 'published_time' ] ) ; } if ( is_null ( $ dt ) && isset ( $ og_data [ 'pubdate' ] ) ) { $ dt = new ... | Check for and determine dates based on OpenGraph standards . |
59,442 | private function getDateFromParsely ( ) : ? \ DateTime { $ dt = null ; $ nodes = $ this -> article ( ) -> getRawDoc ( ) -> find ( 'script[type="application/ld+json"]' ) ; foreach ( $ nodes as $ node ) { try { $ json = json_decode ( $ node -> text ( ) ) ; if ( isset ( $ json -> dateCreated ) ) { $ date = is_array ( $ js... | Check for and determine dates based on Parsely metadata . |
59,443 | public static function storeImagesToLocalFile ( $ imageSrcs , bool $ returnAll , Configuration $ config ) : array { $ localImages = self :: handleEntity ( $ imageSrcs , $ returnAll , $ config ) ; if ( empty ( $ localImages ) ) { return [ ] ; } $ locallyStoredImages = [ ] ; foreach ( $ localImages as $ localImage ) { if... | Writes an image src http string to disk as a temporary file and returns the LocallyStoredImage object that has the info you should need on the image |
59,444 | private function isHighLinkDensity ( Element $ node , float $ limit = 1.0 ) : bool { $ links = $ node -> find ( 'a, [onclick]' ) ; if ( $ links -> count ( ) == 0 ) { return false ; } $ words = preg_split ( '@[\s]+@iu' , $ node -> text ( ) , - 1 , PREG_SPLIT_NO_EMPTY ) ; if ( ! is_array ( $ words ) || empty ( $ words ) ... | Checks the density of links within a node is there not much text and most of it contains linky shit? if so it s no good |
59,445 | private function getFormattedText ( ) : string { $ this -> removeNodesWithNegativeScores ( $ this -> article ( ) -> getTopNode ( ) ) ; $ this -> convertLinksToText ( $ this -> article ( ) -> getTopNode ( ) ) ; $ this -> replaceTagsWithText ( $ this -> article ( ) -> getTopNode ( ) ) ; $ this -> removeParagraphsWithFewW... | Removes all unnecessary elements and formats the selected text nodes |
59,446 | private function convertToText ( Element $ topNode ) : string { if ( empty ( $ topNode ) ) { return '' ; } $ list = [ ] ; foreach ( $ topNode -> contents ( ) as $ child ) { $ list [ ] = trim ( $ child -> text ( ) ) ; } return implode ( "\n\n" , $ list ) ; } | Takes an element and turns the P tags into \ n \ n |
59,447 | private function cleanupHtml ( ) : string { $ topNode = $ this -> article ( ) -> getTopNode ( ) ; if ( empty ( $ topNode ) ) { return '' ; } $ this -> removeParagraphsWithFewWords ( $ topNode ) ; $ html = $ this -> convertToHtml ( $ topNode ) ; return str_replace ( [ '<p></p>' , '<p> </p>' ] , '' , $ html ) ; } | Scrape the node content and return the html |
59,448 | private function convertLinksToText ( Element $ topNode ) : self { if ( ! empty ( $ topNode ) ) { $ links = $ topNode -> find ( 'a' ) ; foreach ( $ links as $ item ) { $ images = $ item -> find ( 'img' ) ; if ( $ images -> count ( ) == 0 ) { $ item -> replaceWith ( new Text ( Helper :: textNormalise ( $ item -> text ( ... | cleans up and converts any nodes that should be considered text into text |
59,449 | private function removeNodesWithNegativeScores ( Element $ topNode ) : self { if ( ! empty ( $ topNode ) ) { $ gravityItems = $ topNode -> find ( '*[gravityScore]' ) ; foreach ( $ gravityItems as $ item ) { $ score = ( int ) $ item -> attr ( 'gravityScore' ) ; if ( $ score < 1 ) { $ item -> remove ( ) ; } } } return $ ... | if there are elements inside our top node that have a negative gravity score let s give em the boot |
59,450 | private function removeParagraphsWithFewWords ( Element $ topNode ) : self { if ( ! empty ( $ topNode ) ) { $ nodes = $ topNode -> find ( 'p' ) ; foreach ( $ nodes as $ node ) { $ stopWords = $ this -> config ( ) -> getStopWords ( ) -> getStopwordCount ( $ node -> text ( ) ) ; if ( mb_strlen ( Helper :: textNormalise (... | remove paragraphs that have less than x number of words would indicate that it s some sort of link |
59,451 | private function postExtractionCleanup ( ) : self { $ this -> addSiblings ( $ this -> article ( ) -> getTopNode ( ) ) ; foreach ( $ this -> article ( ) -> getTopNode ( ) -> contents ( ) as $ node ) { if ( $ node -> is ( self :: $ CLEANUP_IGNORE_SELECTOR ) ) { if ( $ this -> isHighLinkDensity ( $ node ) || $ this -> isT... | Remove any divs that looks like non - content clusters of links or paras with no gusto |
59,452 | private function getSiblingContent ( Element $ currentSibling , float $ baselineScoreForSiblingParagraphs ) : array { $ text = trim ( $ currentSibling -> text ( ) ) ; if ( $ currentSibling -> is ( 'p, strong' ) && ! empty ( $ text ) ) { return [ $ currentSibling ] ; } $ results = [ ] ; $ nodes = $ currentSibling -> fin... | Adds any siblings that may have a decent score to this node |
59,453 | private function getBaselineScoreForSiblings ( Element $ topNode ) : float { $ base = 100000 ; $ numberOfParagraphs = 0 ; $ scoreOfParagraphs = 0 ; $ nodesToCheck = $ topNode -> find ( 'p, strong' ) ; foreach ( $ nodesToCheck as $ node ) { $ nodeText = $ node -> text ( ) ; $ wordStats = $ this -> config ( ) -> getStopW... | we could have long articles that have tons of paragraphs so if we tried to calculate the base score against the total text score of those paragraphs it would be unfair . So we need to normalize the score based on the average scoring of the paragraphs within the top node . For example if our total score of 10 paragraphs... |
59,454 | private function scoreLocalImages ( $ locallyStoredImages ) : array { $ results = [ ] ; $ i = 1 ; $ initialArea = 0 ; $ locallyStoredImages = array_slice ( $ locallyStoredImages , 0 , 30 ) ; foreach ( $ locallyStoredImages as $ locallyStoredImage ) { $ sequenceScore = 1 / $ i ; $ area = $ locallyStoredImage -> getWidth... | Set image score and on locally downloaded images |
59,455 | private function filterBadNames ( NodeList $ images ) : array { $ goodImages = [ ] ; foreach ( $ images as $ image ) { if ( $ this -> isOkImageFileName ( $ image ) ) { $ goodImages [ ] = $ image ; } else { $ image -> remove ( ) ; } } return $ goodImages ; } | takes a list of image elements and filters out the ones with bad names |
59,456 | private function isOkImageFileName ( Element $ imageNode ) : bool { $ imgSrc = $ imageNode -> attr ( 'src' ) ; if ( empty ( $ imgSrc ) ) { return false ; } $ regex = '@' . implode ( '|' , $ this -> badFileNames ) . '@i' ; if ( preg_match ( $ regex , $ imgSrc ) ) { return false ; } return true ; } | will check the image src against a list of bad image files we know of like buttons etc ... |
59,457 | private function checkForKnownElements ( ) : ? Image { if ( ! $ this -> article ( ) -> getRawDoc ( ) ) { return null ; } $ knownImgDomNames = self :: $ KNOWN_IMG_DOM_NAMES ; $ domain = $ this -> getCleanDomain ( ) ; $ customSiteMapping = $ this -> customSiteMapping ( ) ; if ( isset ( $ customSiteMapping [ $ domain ] ) ... | In here we check for known image contains from sites we ve checked out like yahoo techcrunch etc ... that have known places to look for good images . |
59,458 | public function run ( Article $ article ) : self { $ this -> document ( $ article -> getDoc ( ) ) ; $ this -> removeXPath ( '//comment()' ) ; $ this -> replace ( 'em, strong, b, i, strike, del, ins' , function ( $ node ) { return ! $ node -> find ( 'img' ) -> count ( ) ; } ) ; $ this -> replace ( 'span[class~=dropcap],... | Clean the contents of the supplied article document |
59,459 | private function remove ( string $ selector , callable $ callback = null ) : self { $ nodes = $ this -> document ( ) -> find ( $ selector ) ; foreach ( $ nodes as $ node ) { if ( is_null ( $ callback ) || $ callback ( $ node ) ) { $ node -> remove ( ) ; } } return $ this ; } | Remove via CSS selectors |
59,460 | private function removeXPath ( string $ expression , callable $ callback = null ) : self { $ nodes = $ this -> document ( ) -> findXPath ( $ expression ) ; foreach ( $ nodes as $ node ) { if ( is_null ( $ callback ) || $ callback ( $ node ) ) { $ node -> remove ( ) ; } } return $ this ; } | Remove using via XPath expressions |
59,461 | private function replace ( string $ selector , callable $ callback = null ) : self { $ nodes = $ this -> document ( ) -> find ( $ selector ) ; foreach ( $ nodes as $ node ) { if ( is_null ( $ callback ) || $ callback ( $ node ) ) { $ node -> replaceWith ( new Text ( ( string ) $ node -> text ( ) ) ) ; } } return $ this... | Replace node with its textual contents via CSS selectors |
59,462 | private function removeBadTags ( ) : self { $ lists = [ "[%s^='%s']" => $ this -> startsWithNodes , "[%s*='%s']" => $ this -> searchNodes , "[%s$='%s']" => $ this -> endsWithNodes , "[%s='%s']" => $ this -> equalsNodes , ] ; $ attrs = [ 'id' , 'class' , 'name' , ] ; $ exceptions = array_map ( function ( $ value ) { ret... | Remove unwanted junk elements based on pre - defined CSS selectors |
59,463 | private function getOpenGraph ( ) : array { $ results = array ( ) ; $ nodes = $ this -> article ( ) -> getDoc ( ) -> find ( 'meta[property^="og:"]' ) ; foreach ( $ nodes as $ node ) { $ property = explode ( ':' , $ node -> attr ( 'property' ) ) ; array_shift ( $ property ) ; $ results [ implode ( ':' , $ property ) ] =... | Retrieve all OpenGraph meta data |
59,464 | private function cleanTitle ( string $ title ) : string { $ openGraph = $ this -> article ( ) -> getOpenGraph ( ) ; if ( isset ( $ openGraph [ 'site_name' ] ) && $ openGraph [ 'site_name' ] != $ title ) { $ title = str_replace ( $ openGraph [ 'site_name' ] , '' , $ title ) ; } if ( $ this -> article ( ) -> getDomain ( ... | Clean title text |
59,465 | private function getTitle ( ) : string { $ openGraph = $ this -> article ( ) -> getOpenGraph ( ) ; if ( isset ( $ openGraph [ 'title' ] ) ) { return $ this -> cleanTitle ( $ openGraph [ 'title' ] ) ; } $ nodes = $ this -> getNodesByLowercasePropertyValue ( $ this -> article ( ) -> getDoc ( ) , 'meta' , 'name' , 'headli... | Get article title |
59,466 | private function getMetaLanguage ( ) : string { $ lang = '' ; $ el = $ this -> article ( ) -> getDoc ( ) -> find ( 'html[lang]' ) ; if ( $ el -> count ( ) ) { $ lang = $ el -> first ( ) -> attr ( 'lang' ) ; } if ( empty ( $ lang ) ) { $ selectors = [ 'html > head > meta[http-equiv=content-language]' , 'html > head > me... | If the article has meta language set in the source use that |
59,467 | private function getMetaDescription ( ) : string { $ desc = $ this -> getMetaContent ( $ this -> article ( ) -> getDoc ( ) , 'name' , 'description' ) ; if ( empty ( $ desc ) ) { $ desc = $ this -> getMetaContent ( $ this -> article ( ) -> getDoc ( ) , 'property' , 'og:description' ) ; } if ( empty ( $ desc ) ) { $ desc... | If the article has meta description set in the source use that |
59,468 | private function getCanonicalLink ( ) : ? string { $ nodes = $ this -> getNodesByLowercasePropertyValue ( $ this -> article ( ) -> getDoc ( ) , 'link' , 'rel' , 'canonical' ) ; if ( $ nodes -> count ( ) ) { return trim ( $ nodes -> first ( ) -> attr ( 'href' ) ) ; } $ nodes = $ this -> getNodesByLowercasePropertyValue ... | If the article has meta canonical link set in the url |
59,469 | protected function setHandler ( ServerRequestInterface $ request , $ handler ) : ServerRequestInterface { return $ request -> withAttribute ( $ this -> attribute , $ handler ) ; } | Set the handler reference on the request . |
59,470 | public function create ( $ bare = null ) { mkdir ( $ this -> getPath ( ) ) ; $ command = 'init' ; if ( $ bare ) { $ command .= ' --bare' ; } $ this -> getClient ( ) -> run ( $ this , $ command ) ; return $ this ; } | Create a new git repository . |
59,471 | public function getConfig ( $ key ) { $ key = $ this -> getClient ( ) -> run ( $ this , 'config ' . $ key ) ; return trim ( $ key ) ; } | Get a git configuration variable . |
59,472 | public function addStatistics ( $ statistics ) { if ( ! is_array ( $ statistics ) ) { $ statistics = array ( $ statistics ) ; } foreach ( $ statistics as $ statistic ) { $ reflect = new \ ReflectionClass ( $ statistic ) ; $ this -> statistics [ strtolower ( $ reflect -> getShortName ( ) ) ] = $ statistic ; } } | Add statistic aggregator . |
59,473 | public function getStatistics ( ) { if ( false === $ this -> getCommitsHaveBeenParsed ( ) ) { $ this -> getCommits ( ) ; } foreach ( $ this -> statistics as $ statistic ) { $ statistic -> sortCommits ( ) ; } return $ this -> statistics ; } | Get statistic aggregators . |
59,474 | public function add ( $ files = '.' ) { if ( is_array ( $ files ) ) { $ files = implode ( ' ' , array_map ( 'escapeshellarg' , $ files ) ) ; } else { $ files = escapeshellarg ( $ files ) ; } $ this -> getClient ( ) -> run ( $ this , "add $files" ) ; return $ this ; } | Add untracked files . |
59,475 | public function push ( $ repository = null , $ refspec = null ) { $ command = 'push' ; if ( $ repository ) { $ command .= " $repository" ; } if ( $ refspec ) { $ command .= " $refspec" ; } $ this -> getClient ( ) -> run ( $ this , $ command ) ; return $ this ; } | Update remote references . |
59,476 | public function getBranches ( ) { static $ cache = array ( ) ; if ( array_key_exists ( $ this -> path , $ cache ) ) { return $ cache [ $ this -> path ] ; } $ branches = $ this -> getClient ( ) -> run ( $ this , 'branch' ) ; $ branches = explode ( "\n" , $ branches ) ; $ branches = array_filter ( preg_replace ( '/[\*\s]... | Show a list of the repository branches . |
59,477 | public function getCurrentBranch ( ) { $ branches = $ this -> getClient ( ) -> run ( $ this , 'branch' ) ; $ branches = explode ( "\n" , $ branches ) ; foreach ( $ branches as $ branch ) { if ( '*' === $ branch [ 0 ] ) { if ( preg_match ( '/(detached|no branch)/' , $ branch ) ) { return null ; } return substr ( $ branc... | Return the current repository branch . |
59,478 | public function hasBranch ( $ branch ) { $ branches = $ this -> getBranches ( ) ; $ status = in_array ( $ branch , $ branches ) ; return $ status ; } | Check if a specified branch exists . |
59,479 | public function createTag ( $ tag , $ message = null ) { $ command = 'tag' ; if ( $ message ) { $ command .= " -a -m '$message'" ; } $ command .= " $tag" ; $ this -> getClient ( ) -> run ( $ this , $ command ) ; } | Create a new repository tag . |
59,480 | public function getTags ( ) { static $ cache = array ( ) ; if ( array_key_exists ( $ this -> path , $ cache ) ) { return $ cache [ $ this -> path ] ; } $ tags = $ this -> getClient ( ) -> run ( $ this , 'tag' ) ; $ tags = explode ( "\n" , $ tags ) ; array_pop ( $ tags ) ; if ( empty ( $ tags [ 0 ] ) ) { return $ cache ... | Show a list of the repository tags . |
59,481 | public function getTotalCommits ( $ file = null ) { if ( defined ( 'PHP_WINDOWS_VERSION_BUILD' ) ) { $ command = "rev-list --count --all $file" ; } else { $ command = "rev-list --all $file | wc -l" ; } $ commits = $ this -> getClient ( ) -> run ( $ this , $ command ) ; return trim ( $ commits ) ; } | Show the amount of commits on the repository . |
59,482 | public function getCommits ( $ file = null ) { $ command = 'log --pretty=format:"<item><hash>%H</hash><short_hash>%h</short_hash><tree>%T</tree><parents>%P</parents><author>%an</author><author_email>%ae</author_email><date>%at</date><commiter>%cn</commiter><commiter_email>%ce</commiter_email><commiter_date>%ct</commite... | Show the repository commit log . |
59,483 | public function getCommit ( $ commitHash ) { if ( version_compare ( $ this -> getClient ( ) -> getVersion ( ) , '1.8.4' , '>=' ) ) { $ logs = $ this -> getClient ( ) -> run ( $ this , "show --ignore-blank-lines -w -b --pretty=format:\"<item><hash>%H</hash><short_hash>%h</short_hash><tree>%T</tree><parents>%P</parents><... | Show the data from a specific commit . |
59,484 | public function readDiffLogs ( array $ logs ) { $ diffs = array ( ) ; $ lineNumOld = 0 ; $ lineNumNew = 0 ; foreach ( $ logs as $ log ) { if ( 'diff' === substr ( $ log , 0 , 4 ) ) { if ( isset ( $ diff ) ) { $ diffs [ ] = $ diff ; } $ diff = new Diff ( ) ; if ( preg_match ( '/^diff --[\S]+ a\/?(.+) b\/?/' , $ log , $ ... | Read diff logs and generate a collection of diffs . |
59,485 | public function getHead ( $ default = null ) { $ file = '' ; if ( file_exists ( $ this -> getPath ( ) . '/.git/HEAD' ) ) { $ file = file_get_contents ( $ this -> getPath ( ) . '/.git/HEAD' ) ; } elseif ( file_exists ( $ this -> getPath ( ) . '/HEAD' ) ) { $ file = file_get_contents ( $ this -> getPath ( ) . '/HEAD' ) ;... | Get the current HEAD . |
59,486 | public function getBranchTree ( $ branch ) { $ hash = $ this -> getClient ( ) -> run ( $ this , "log --pretty=\"%T\" --max-count=1 $branch" ) ; $ hash = trim ( $ hash , "\r\n " ) ; return $ hash ? : false ; } | Extract the tree hash for a given branch or tree reference . |
59,487 | public function getBlame ( $ file ) { $ blame = array ( ) ; $ logs = $ this -> getClient ( ) -> run ( $ this , "blame -s $file" ) ; $ logs = explode ( "\n" , $ logs ) ; $ i = 0 ; $ previousCommit = '' ; foreach ( $ logs as $ log ) { if ( '' == $ log ) { continue ; } preg_match_all ( "/([a-zA-Z0-9^]{8})\s+.*?([0-9]+)\)(... | Blames the provided file and parses the output . |
59,488 | public function getPrettyFormat ( $ command ) { $ output = $ this -> getClient ( ) -> run ( $ this , $ command ) ; $ format = new PrettyFormat ( ) ; return $ format -> parse ( $ output ) ; } | Get and parse the output of a git command with a XML - based pretty format . |
59,489 | public function createRepository ( $ path , $ bare = null ) { if ( file_exists ( $ path . '/.git/HEAD' ) && ! file_exists ( $ path . '/HEAD' ) ) { throw new \ RuntimeException ( 'A GIT repository already exists at ' . $ path ) ; } $ repository = new Repository ( $ path , $ this ) ; return $ repository -> create ( $ bar... | Creates a new repository on the specified path . |
59,490 | public function getRepository ( $ path ) { if ( ! file_exists ( $ path ) || ! file_exists ( $ path . '/.git/HEAD' ) && ! file_exists ( $ path . '/HEAD' ) ) { throw new \ RuntimeException ( 'There is no GIT repository at ' . $ path ) ; } return new Repository ( $ path , $ this ) ; } | Opens a repository at the specified path . |
59,491 | public function fileGetContents ( $ file ) { $ client = new Client ( ) ; $ response = $ client -> createRequest ( ) -> setMethod ( 'get' ) -> setUrl ( $ file ) -> addHeaders ( [ 'user-agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36' ] ) -> s... | Read file contents |
59,492 | public function runJob ( $ jobName ) { $ progress = $ this -> getProgressBar ( ) ; $ progress -> setMessage ( 'Scanning ' . $ jobName ) ; $ scanner = $ this -> scanners [ $ jobName ] ; foreach ( $ this -> fileLists [ $ jobName ] as $ filePath ) { $ scanner -> scan ( $ filePath ) ; $ progress -> advance ( ) ; } if ( $ p... | Run a single job . |
59,493 | public function merge ( $ data ) { foreach ( $ data as $ key => $ value ) { $ this -> set ( $ key , $ value ) ; } } | Merge this configuration with an associative array . |
59,494 | public static function getPrimitives ( ) { return [ Type :: TYPE_NULL => 'null' , Type :: TYPE_BOOLEAN => 'bool' , Type :: TYPE_LONG => 'int' , Type :: TYPE_DOUBLE => 'float' , Type :: TYPE_STRING => 'string' , Type :: TYPE_OBJECT => 'object' , Type :: TYPE_ARRAY => 'array' , Type :: TYPE_CALLABLE => 'callable' , ] ; } | Get the primitives |
59,495 | public function askQuestion ( InteractiveQuestion $ question , $ position = null , InputInterface $ input = null ) { $ text = ( $ position !== null ? $ position . ') ' : null ) . $ question -> getFormatedText ( ) ; if ( $ this -> dialogHelper instanceof QuestionHelper ) { if ( ! $ input ) { throw new \ InvalidArgumentE... | QuestionHelper does about the same as we do here . |
59,496 | public function getCommandOptions ( ) { $ consoleOptions = array ( ) ; foreach ( $ this -> requests as $ name => $ request ) { if ( $ request -> isAvailableAsCommandOption ( ) ) { $ consoleOptions [ $ name ] = $ request -> convertToCommandOption ( ) ; } } return $ consoleOptions ; } | Return a set of command request converted from the Base Request |
59,497 | public function isValid ( $ tag ) { if ( strlen ( $ this -> tagPrefix ) > 0 && strpos ( $ tag , $ this -> tagPrefix ) !== 0 ) { return false ; } return preg_match ( '/^' . $ this -> regex . '$/' , substr ( $ tag , strlen ( $ this -> tagPrefix ) ) ) == 1 ; } | Check if a tag is valid |
59,498 | public function filtrateList ( $ tags ) { $ validTags = array ( ) ; foreach ( $ tags as $ tag ) { if ( $ this -> isValid ( $ tag ) ) { $ validTags [ ] = $ tag ; } } return $ validTags ; } | Remove all invalid tags from a list |
59,499 | protected function interact ( InputInterface $ input , OutputInterface $ output ) { parent :: interact ( $ input , $ output ) ; if ( Context :: get ( 'information-collector' ) -> hasMissingInformation ( ) ) { $ questions = Context :: get ( 'information-collector' ) -> getInteractiveQuestions ( ) ; $ this -> getOutput (... | Executed only when we are in interactive mode |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.