idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
43,900 | protected function outputParagraphStart ( $ maxPos ) { if ( $ this -> context [ 'inParagraph' ] || ! ( $ this -> context [ 'flags' ] & self :: RULE_CREATE_PARAGRAPHS ) ) { return ; } $ this -> outputWhitespace ( $ maxPos ) ; if ( $ this -> pos < $ this -> textLen ) { $ this -> output .= '<p>' ; $ this -> context [ 'inParagraph' ] = true ; } } | Start a paragraph between current position and given position if applicable |
43,901 | protected function outputVerbatim ( Tag $ tag ) { $ flags = $ this -> context [ 'flags' ] ; $ this -> context [ 'flags' ] = $ tag -> getFlags ( ) ; $ this -> outputText ( $ this -> currentTag -> getPos ( ) + $ this -> currentTag -> getLen ( ) , 0 , false ) ; $ this -> context [ 'flags' ] = $ flags ; } | Output the content of a verbatim tag |
43,902 | protected function outputWhitespace ( $ maxPos ) { if ( $ maxPos > $ this -> pos ) { $ spn = strspn ( $ this -> text , self :: WHITESPACE , $ this -> pos , $ maxPos - $ this -> pos ) ; if ( $ spn ) { $ this -> output .= substr ( $ this -> text , $ this -> pos , $ spn ) ; $ this -> pos += $ spn ; } } } | Skip as much whitespace after current position as possible |
43,903 | public function enablePlugin ( $ pluginName ) { if ( isset ( $ this -> pluginsConfig [ $ pluginName ] ) ) { $ this -> pluginsConfig [ $ pluginName ] [ 'isDisabled' ] = false ; } } | Enable a plugin |
43,904 | protected function executePluginParser ( $ pluginName ) { $ pluginConfig = $ this -> pluginsConfig [ $ pluginName ] ; if ( isset ( $ pluginConfig [ 'quickMatch' ] ) && strpos ( $ this -> text , $ pluginConfig [ 'quickMatch' ] ) === false ) { return ; } $ matches = [ ] ; if ( isset ( $ pluginConfig [ 'regexp' ] ) ) { $ matches = $ this -> getMatches ( $ pluginConfig [ 'regexp' ] , $ pluginConfig [ 'regexpLimit' ] ) ; if ( empty ( $ matches ) ) { return ; } } call_user_func ( $ this -> getPluginParser ( $ pluginName ) , $ this -> text , $ matches ) ; } | Execute given plugin |
43,905 | protected function executePluginParsers ( ) { foreach ( $ this -> pluginsConfig as $ pluginName => $ pluginConfig ) { if ( empty ( $ pluginConfig [ 'isDisabled' ] ) ) { $ this -> executePluginParser ( $ pluginName ) ; } } } | Execute all the plugins |
43,906 | protected function getMatches ( $ regexp , $ limit ) { $ cnt = preg_match_all ( $ regexp , $ this -> text , $ matches , PREG_SET_ORDER | PREG_OFFSET_CAPTURE ) ; if ( $ cnt > $ limit ) { $ matches = array_slice ( $ matches , 0 , $ limit ) ; } return $ matches ; } | Execute given regexp and returns as many matches as given limit |
43,907 | protected function getPluginParser ( $ pluginName ) { if ( ! isset ( $ this -> pluginParsers [ $ pluginName ] ) ) { $ pluginConfig = $ this -> pluginsConfig [ $ pluginName ] ; $ className = ( isset ( $ pluginConfig [ 'className' ] ) ) ? $ pluginConfig [ 'className' ] : 's9e\\TextFormatter\\Plugins\\' . $ pluginName . '\\Parser' ; $ this -> pluginParsers [ $ pluginName ] = [ new $ className ( $ this , $ pluginConfig ) , 'parse' ] ; } return $ this -> pluginParsers [ $ pluginName ] ; } | Get the cached callback for given plugin s parser |
43,908 | public function registerParser ( $ pluginName , $ parser , $ regexp = null , $ limit = PHP_INT_MAX ) { if ( ! is_callable ( $ parser ) ) { throw new InvalidArgumentException ( 'Argument 1 passed to ' . __METHOD__ . ' must be a valid callback' ) ; } if ( ! isset ( $ this -> pluginsConfig [ $ pluginName ] ) ) { $ this -> pluginsConfig [ $ pluginName ] = [ ] ; } if ( isset ( $ regexp ) ) { $ this -> pluginsConfig [ $ pluginName ] [ 'regexp' ] = $ regexp ; $ this -> pluginsConfig [ $ pluginName ] [ 'regexpLimit' ] = $ limit ; } $ this -> pluginParsers [ $ pluginName ] = $ parser ; } | Register a parser |
43,909 | protected function closeAncestor ( Tag $ tag ) { if ( ! empty ( $ this -> openTags ) ) { $ tagName = $ tag -> getName ( ) ; $ tagConfig = $ this -> tagsConfig [ $ tagName ] ; if ( ! empty ( $ tagConfig [ 'rules' ] [ 'closeAncestor' ] ) ) { $ i = count ( $ this -> openTags ) ; while ( -- $ i >= 0 ) { $ ancestor = $ this -> openTags [ $ i ] ; $ ancestorName = $ ancestor -> getName ( ) ; if ( isset ( $ tagConfig [ 'rules' ] [ 'closeAncestor' ] [ $ ancestorName ] ) ) { ++ $ this -> currentFixingCost ; $ this -> tagStack [ ] = $ tag ; $ this -> addMagicEndTag ( $ ancestor , $ tag -> getPos ( ) , $ tag -> getSortPriority ( ) - 1 ) ; return true ; } } } } return false ; } | Apply closeAncestor rules associated with given tag |
43,910 | protected function createChild ( Tag $ tag ) { $ tagConfig = $ this -> tagsConfig [ $ tag -> getName ( ) ] ; if ( isset ( $ tagConfig [ 'rules' ] [ 'createChild' ] ) ) { $ priority = - 1000 ; $ tagPos = $ this -> pos + strspn ( $ this -> text , " \n\r\t" , $ this -> pos ) ; foreach ( $ tagConfig [ 'rules' ] [ 'createChild' ] as $ tagName ) { $ this -> addStartTag ( $ tagName , $ tagPos , 0 , ++ $ priority ) ; } } } | Apply the createChild rules associated with given tag |
43,911 | protected function fosterParent ( Tag $ tag ) { if ( ! empty ( $ this -> openTags ) ) { $ tagName = $ tag -> getName ( ) ; $ tagConfig = $ this -> tagsConfig [ $ tagName ] ; if ( ! empty ( $ tagConfig [ 'rules' ] [ 'fosterParent' ] ) ) { $ parent = end ( $ this -> openTags ) ; $ parentName = $ parent -> getName ( ) ; if ( isset ( $ tagConfig [ 'rules' ] [ 'fosterParent' ] [ $ parentName ] ) ) { if ( $ parentName !== $ tagName && $ this -> currentFixingCost < $ this -> maxFixingCost ) { $ this -> addFosterTag ( $ tag , $ parent ) ; } $ this -> tagStack [ ] = $ tag ; $ this -> addMagicEndTag ( $ parent , $ tag -> getPos ( ) , $ tag -> getSortPriority ( ) - 1 ) ; $ this -> currentFixingCost += 4 ; return true ; } } } return false ; } | Apply fosterParent rules associated with given tag |
43,912 | protected function requireAncestor ( Tag $ tag ) { $ tagName = $ tag -> getName ( ) ; $ tagConfig = $ this -> tagsConfig [ $ tagName ] ; if ( isset ( $ tagConfig [ 'rules' ] [ 'requireAncestor' ] ) ) { foreach ( $ tagConfig [ 'rules' ] [ 'requireAncestor' ] as $ ancestorName ) { if ( ! empty ( $ this -> cntOpen [ $ ancestorName ] ) ) { return false ; } } $ this -> logger -> err ( 'Tag requires an ancestor' , [ 'requireAncestor' => implode ( ',' , $ tagConfig [ 'rules' ] [ 'requireAncestor' ] ) , 'tag' => $ tag ] ) ; return true ; } return false ; } | Apply requireAncestor rules associated with given tag |
43,913 | protected function addFosterTag ( Tag $ tag , Tag $ fosterTag ) { list ( $ childPos , $ childPrio ) = $ this -> getMagicStartCoords ( $ tag -> getPos ( ) + $ tag -> getLen ( ) ) ; $ childTag = $ this -> addCopyTag ( $ fosterTag , $ childPos , 0 , $ childPrio ) ; $ tag -> cascadeInvalidationTo ( $ childTag ) ; } | Create and add a copy of a tag as a child of a given tag |
43,914 | protected function addMagicEndTag ( Tag $ startTag , $ tagPos , $ prio = 0 ) { $ tagName = $ startTag -> getName ( ) ; if ( ( $ this -> currentTag -> getFlags ( ) | $ startTag -> getFlags ( ) ) & self :: RULE_IGNORE_WHITESPACE ) { $ tagPos = $ this -> getMagicEndPos ( $ tagPos ) ; } $ endTag = $ this -> addEndTag ( $ tagName , $ tagPos , 0 , $ prio ) ; $ endTag -> pairWith ( $ startTag ) ; return $ endTag ; } | Create and add an end tag for given start tag at given position |
43,915 | protected function getMagicEndPos ( $ tagPos ) { while ( $ tagPos > $ this -> pos && strpos ( self :: WHITESPACE , $ this -> text [ $ tagPos - 1 ] ) !== false ) { -- $ tagPos ; } return $ tagPos ; } | Compute the position of a magic end tag adjusted for whitespace |
43,916 | protected function getMagicStartCoords ( $ tagPos ) { if ( empty ( $ this -> tagStack ) ) { $ nextPos = $ this -> textLen + 1 ; $ nextPrio = 0 ; } else { $ nextTag = end ( $ this -> tagStack ) ; $ nextPos = $ nextTag -> getPos ( ) ; $ nextPrio = $ nextTag -> getSortPriority ( ) ; } while ( $ tagPos < $ nextPos && strpos ( self :: WHITESPACE , $ this -> text [ $ tagPos ] ) !== false ) { ++ $ tagPos ; } $ prio = ( $ tagPos === $ nextPos ) ? $ nextPrio - 1 : 0 ; return [ $ tagPos , $ prio ] ; } | Compute the position and priority of a magic start tag adjusted for whitespace |
43,917 | protected function isFollowedByClosingTag ( Tag $ tag ) { return ( empty ( $ this -> tagStack ) ) ? false : end ( $ this -> tagStack ) -> canClose ( $ tag ) ; } | Test whether given start tag is immediately followed by a closing tag |
43,918 | protected function processTags ( ) { if ( empty ( $ this -> tagStack ) ) { return ; } foreach ( array_keys ( $ this -> tagsConfig ) as $ tagName ) { $ this -> cntOpen [ $ tagName ] = 0 ; $ this -> cntTotal [ $ tagName ] = 0 ; } do { while ( ! empty ( $ this -> tagStack ) ) { if ( ! $ this -> tagStackIsSorted ) { $ this -> sortTags ( ) ; } $ this -> currentTag = array_pop ( $ this -> tagStack ) ; $ this -> processCurrentTag ( ) ; } foreach ( $ this -> openTags as $ startTag ) { $ this -> addMagicEndTag ( $ startTag , $ this -> textLen ) ; } } while ( ! empty ( $ this -> tagStack ) ) ; } | Process all tags in the stack |
43,919 | protected function processCurrentTag ( ) { if ( ( $ this -> context [ 'flags' ] & self :: RULE_IGNORE_TAGS ) && ! $ this -> currentTag -> canClose ( end ( $ this -> openTags ) ) && ! $ this -> currentTag -> isSystemTag ( ) ) { $ this -> currentTag -> invalidate ( ) ; } $ tagPos = $ this -> currentTag -> getPos ( ) ; $ tagLen = $ this -> currentTag -> getLen ( ) ; if ( $ this -> pos > $ tagPos && ! $ this -> currentTag -> isInvalid ( ) ) { $ startTag = $ this -> currentTag -> getStartTag ( ) ; if ( $ startTag && in_array ( $ startTag , $ this -> openTags , true ) ) { $ this -> addEndTag ( $ startTag -> getName ( ) , $ this -> pos , max ( 0 , $ tagPos + $ tagLen - $ this -> pos ) ) -> pairWith ( $ startTag ) ; return ; } if ( $ this -> currentTag -> isIgnoreTag ( ) ) { $ ignoreLen = $ tagPos + $ tagLen - $ this -> pos ; if ( $ ignoreLen > 0 ) { $ this -> addIgnoreTag ( $ this -> pos , $ ignoreLen ) ; return ; } } $ this -> currentTag -> invalidate ( ) ; } if ( $ this -> currentTag -> isInvalid ( ) ) { return ; } if ( $ this -> currentTag -> isIgnoreTag ( ) ) { $ this -> outputIgnoreTag ( $ this -> currentTag ) ; } elseif ( $ this -> currentTag -> isBrTag ( ) ) { if ( ! ( $ this -> context [ 'flags' ] & self :: RULE_PREVENT_BR ) ) { $ this -> outputBrTag ( $ this -> currentTag ) ; } } elseif ( $ this -> currentTag -> isParagraphBreak ( ) ) { $ this -> outputText ( $ this -> currentTag -> getPos ( ) , 0 , true ) ; } elseif ( $ this -> currentTag -> isVerbatim ( ) ) { $ this -> outputVerbatim ( $ this -> currentTag ) ; } elseif ( $ this -> currentTag -> isStartTag ( ) ) { $ this -> processStartTag ( $ this -> currentTag ) ; } else { $ this -> processEndTag ( $ this -> currentTag ) ; } } | Process current tag |
43,920 | protected function popContext ( ) { $ tag = array_pop ( $ this -> openTags ) ; -- $ this -> cntOpen [ $ tag -> getName ( ) ] ; $ this -> context = $ this -> context [ 'parentContext' ] ; } | Update counters and replace current context with its parent context |
43,921 | protected function pushContext ( Tag $ tag ) { $ tagName = $ tag -> getName ( ) ; $ tagFlags = $ tag -> getFlags ( ) ; $ tagConfig = $ this -> tagsConfig [ $ tagName ] ; ++ $ this -> cntTotal [ $ tagName ] ; if ( $ tag -> isSelfClosingTag ( ) ) { return ; } $ allowed = [ ] ; if ( $ tagFlags & self :: RULE_IS_TRANSPARENT ) { foreach ( $ this -> context [ 'allowed' ] as $ k => $ v ) { $ allowed [ ] = $ tagConfig [ 'allowed' ] [ $ k ] & $ v ; } } else { foreach ( $ this -> context [ 'allowed' ] as $ k => $ v ) { $ allowed [ ] = $ tagConfig [ 'allowed' ] [ $ k ] & ( ( $ v & 0xFF00 ) | ( $ v >> 8 ) ) ; } } $ flags = $ tagFlags | ( $ this -> context [ 'flags' ] & self :: RULES_INHERITANCE ) ; if ( $ flags & self :: RULE_DISABLE_AUTO_BR ) { $ flags &= ~ self :: RULE_ENABLE_AUTO_BR ; } ++ $ this -> cntOpen [ $ tagName ] ; $ this -> openTags [ ] = $ tag ; $ this -> context = [ 'allowed' => $ allowed , 'flags' => $ flags , 'inParagraph' => false , 'parentContext' => $ this -> context ] ; } | Update counters and replace current context with a new context based on given tag |
43,922 | protected function tagIsAllowed ( $ tagName ) { $ n = $ this -> tagsConfig [ $ tagName ] [ 'bitNumber' ] ; return ( bool ) ( $ this -> context [ 'allowed' ] [ $ n >> 3 ] & ( 1 << ( $ n & 7 ) ) ) ; } | Return whether given tag is allowed in current context |
43,923 | public function addStartTag ( $ name , $ pos , $ len , $ prio = 0 ) { return $ this -> addTag ( Tag :: START_TAG , $ name , $ pos , $ len , $ prio ) ; } | Add a start tag |
43,924 | public function addEndTag ( $ name , $ pos , $ len , $ prio = 0 ) { return $ this -> addTag ( Tag :: END_TAG , $ name , $ pos , $ len , $ prio ) ; } | Add an end tag |
43,925 | public function addSelfClosingTag ( $ name , $ pos , $ len , $ prio = 0 ) { return $ this -> addTag ( Tag :: SELF_CLOSING_TAG , $ name , $ pos , $ len , $ prio ) ; } | Add a self - closing tag |
43,926 | public function addIgnoreTag ( $ pos , $ len , $ prio = 0 ) { return $ this -> addTag ( Tag :: SELF_CLOSING_TAG , 'i' , $ pos , min ( $ len , $ this -> textLen - $ pos ) , $ prio ) ; } | Add an ignore tag |
43,927 | public function addCopyTag ( Tag $ tag , $ pos , $ len , $ prio = null ) { if ( ! isset ( $ prio ) ) { $ prio = $ tag -> getSortPriority ( ) ; } $ copy = $ this -> addTag ( $ tag -> getType ( ) , $ tag -> getName ( ) , $ pos , $ len , $ prio ) ; $ copy -> setAttributes ( $ tag -> getAttributes ( ) ) ; return $ copy ; } | Add a copy of given tag at given position and length |
43,928 | protected function isInvalidTextSpan ( $ pos , $ len ) { return ( $ len < 0 || $ pos < 0 || $ pos + $ len > $ this -> textLen || preg_match ( '([\\x80-\\xBF])' , substr ( $ this -> text , $ pos , 1 ) . substr ( $ this -> text , $ pos + $ len , 1 ) ) ) ; } | Test whether given text span is outside text boundaries or an invalid UTF sequence |
43,929 | protected function insertTag ( Tag $ tag ) { if ( ! $ this -> tagStackIsSorted ) { $ this -> tagStack [ ] = $ tag ; } else { $ i = count ( $ this -> tagStack ) ; while ( $ i > 0 && self :: compareTags ( $ this -> tagStack [ $ i - 1 ] , $ tag ) > 0 ) { $ this -> tagStack [ $ i ] = $ this -> tagStack [ $ i - 1 ] ; -- $ i ; } $ this -> tagStack [ $ i ] = $ tag ; } } | Insert given tag in the tag stack |
43,930 | public function addTagPair ( $ name , $ startPos , $ startLen , $ endPos , $ endLen , $ prio = 0 ) { $ endTag = $ this -> addEndTag ( $ name , $ endPos , $ endLen , - $ prio ) ; $ startTag = $ this -> addStartTag ( $ name , $ startPos , $ startLen , $ prio ) ; $ startTag -> pairWith ( $ endTag ) ; return $ startTag ; } | Add a pair of tags |
43,931 | public function addVerbatim ( $ pos , $ len , $ prio = 0 ) { return $ this -> addTag ( Tag :: SELF_CLOSING_TAG , 'v' , $ pos , $ len , $ prio ) ; } | Add a tag that represents a verbatim copy of the original text |
43,932 | public static function normalize ( $ name ) { $ name = ( string ) $ name ; if ( ! static :: isValid ( $ name ) ) { throw new InvalidArgumentException ( "Invalid parameter name '" . $ name . "'" ) ; } return $ name ; } | Normalize a template parameter name |
43,933 | public function encode ( $ value ) { $ type = gettype ( $ value ) ; if ( ! isset ( $ this -> typeEncoders [ $ type ] ) ) { throw new RuntimeException ( 'Cannot encode ' . $ type . ' value' ) ; } return $ this -> typeEncoders [ $ type ] ( $ value ) ; } | Encode a value into JavaScript |
43,934 | protected function encodeAssociativeArray ( array $ array , $ preserveNames = false ) { ksort ( $ array ) ; $ src = '{' ; $ sep = '' ; foreach ( $ array as $ k => $ v ) { $ src .= $ sep . $ this -> encodePropertyName ( "$k" , $ preserveNames ) . ':' . $ this -> encode ( $ v ) ; $ sep = ',' ; } $ src .= '}' ; return $ src ; } | Encode an associative array to JavaScript |
43,935 | protected function encodeConfigValue ( ConfigValue $ configValue ) { return ( $ configValue -> isDeduplicated ( ) ) ? $ configValue -> getVarName ( ) : $ this -> encode ( $ configValue -> getValue ( ) ) ; } | Encode a ConfigValue instance into JavaScript |
43,936 | protected function encodeObject ( $ object ) { foreach ( $ this -> objectEncoders as $ className => $ callback ) { if ( $ object instanceof $ className ) { return $ callback ( $ object ) ; } } throw new RuntimeException ( 'Cannot encode instance of ' . get_class ( $ object ) ) ; } | Encode an object into JavaScript |
43,937 | protected function encodePropertyName ( $ name , $ preserveNames ) { return ( $ preserveNames || ! $ this -> isLegalProp ( $ name ) ) ? json_encode ( $ name ) : $ name ; } | Encode an object property name into JavaScript |
43,938 | protected function isLegalProp ( $ name ) { $ reserved = [ 'abstract' , 'boolean' , 'break' , 'byte' , 'case' , 'catch' , 'char' , 'class' , 'const' , 'continue' , 'debugger' , 'default' , 'delete' , 'do' , 'double' , 'else' , 'enum' , 'export' , 'extends' , 'false' , 'final' , 'finally' , 'float' , 'for' , 'function' , 'goto' , 'if' , 'implements' , 'import' , 'in' , 'instanceof' , 'int' , 'interface' , 'let' , 'long' , 'native' , 'new' , 'null' , 'package' , 'private' , 'protected' , 'public' , 'return' , 'short' , 'static' , 'super' , 'switch' , 'synchronized' , 'this' , 'throw' , 'throws' , 'transient' , 'true' , 'try' , 'typeof' , 'var' , 'void' , 'volatile' , 'while' , 'with' ] ; if ( in_array ( $ name , $ reserved , true ) ) { return false ; } return ( bool ) preg_match ( '#^(?![0-9])[$_\\pL][$_\\pL\\pNl]+$#Du' , $ name ) ; } | Test whether a string can be used as a property name unquoted |
43,939 | public function setRegexp ( $ regexp ) { if ( is_string ( $ regexp ) ) { $ regexp = new Regexp ( $ regexp ) ; } $ this -> vars [ 'regexp' ] = $ regexp ; $ this -> resetSafeness ( ) ; $ this -> evaluateSafeness ( ) ; } | Set this filter s regexp |
43,940 | protected function evaluateSafenessAsURL ( ) { $ regexpInfo = RegexpParser :: parse ( $ this -> vars [ 'regexp' ] ) ; $ captureStart = '(?>\\((?:\\?:)?)*' ; $ regexp = '#^\\^' . $ captureStart . '(?!data|\\w*script)[a-z0-9]+\\??:#i' ; if ( preg_match ( $ regexp , $ regexpInfo [ 'regexp' ] ) && strpos ( $ regexpInfo [ 'modifiers' ] , 'm' ) === false ) { $ this -> markAsSafeAsURL ( ) ; return ; } $ regexp = RegexpParser :: getAllowedCharacterRegexp ( $ this -> vars [ 'regexp' ] ) ; foreach ( ContextSafeness :: getDisallowedCharactersAsURL ( ) as $ char ) { if ( preg_match ( $ regexp , $ char ) ) { return ; } } $ this -> markAsSafeAsURL ( ) ; } | Mark whether this filter makes a value safe to be used as a URL |
43,941 | public function normalize ( DOMElement $ template ) { $ this -> ownerDocument = $ template -> ownerDocument ; $ this -> xpath = new DOMXPath ( $ this -> ownerDocument ) ; foreach ( $ this -> getNodes ( ) as $ node ) { $ this -> normalizeNode ( $ node ) ; } $ this -> reset ( ) ; } | Apply this normalization rule to given template |
43,942 | protected function createElement ( $ nodeName , $ textContent = '' ) { $ methodName = 'createElement' ; $ args = [ $ nodeName ] ; if ( $ textContent !== '' ) { $ args [ ] = htmlspecialchars ( $ textContent , ENT_NOQUOTES , 'UTF-8' ) ; } $ prefix = strstr ( $ nodeName , ':' , true ) ; if ( $ prefix > '' ) { $ methodName .= 'NS' ; array_unshift ( $ args , $ this -> ownerDocument -> lookupNamespaceURI ( $ prefix ) ) ; } return call_user_func_array ( [ $ this -> ownerDocument , $ methodName ] , $ args ) ; } | Create an element in current template |
43,943 | protected function isXsl ( DOMNode $ node , $ localName = null ) { return ( $ node -> namespaceURI === self :: XMLNS_XSL && ( ! isset ( $ localName ) || $ localName === $ node -> localName ) ) ; } | Test whether given node is an XSL element |
43,944 | protected function normalizeNode ( DOMNode $ node ) { if ( ! $ node -> parentNode ) { return ; } if ( $ node instanceof DOMElement ) { $ this -> normalizeElement ( $ node ) ; } elseif ( $ node instanceof DOMAttr ) { $ this -> normalizeAttribute ( $ node ) ; } } | Normalize given node |
43,945 | protected function xpath ( $ query , DOMNode $ node = null ) { $ query = str_replace ( '$XSL' , '"' . self :: XMLNS_XSL . '"' , $ query ) ; return iterator_to_array ( $ this -> xpath -> query ( $ query , $ node ) ) ; } | Evaluate given XPath expression |
43,946 | protected function replaceElement ( DOMElement $ element ) { $ elName = $ this -> lowercase ( $ element -> localName ) ; if ( $ elName === $ element -> localName ) { return ; } $ newElement = ( is_null ( $ element -> namespaceURI ) ) ? $ this -> ownerDocument -> createElement ( $ elName ) : $ this -> ownerDocument -> createElementNS ( $ element -> namespaceURI , $ elName ) ; while ( $ element -> firstChild ) { $ newElement -> appendChild ( $ element -> removeChild ( $ element -> firstChild ) ) ; } foreach ( $ element -> attributes as $ attribute ) { $ newElement -> setAttributeNS ( $ attribute -> namespaceURI , $ attribute -> nodeName , $ attribute -> value ) ; } $ element -> parentNode -> replaceChild ( $ newElement , $ element ) ; } | Normalize and replace a non - XSL element if applicable |
43,947 | public function convertEq ( $ expr1 , $ operator , $ expr2 ) { $ operator = $ operator [ 0 ] . '=' ; if ( $ this -> runner -> getType ( $ expr1 ) === 'String' && $ this -> runner -> getType ( $ expr2 ) === 'String' ) { $ operator .= '=' ; } return $ this -> convertComparison ( $ expr1 , $ operator , $ expr2 ) ; } | Convert an equality test |
43,948 | protected function convertComparison ( $ expr1 , $ operator , $ expr2 ) { return $ this -> convert ( $ expr1 ) . $ operator . $ this -> convert ( $ expr2 ) ; } | Convert a comparison |
43,949 | protected function convertOperation ( $ expr1 , $ operator , $ expr2 ) { $ expr1 = $ this -> convert ( $ expr1 ) ; $ expr2 = $ this -> convert ( $ expr2 ) ; if ( $ operator === '-' && $ expr2 [ 0 ] === '-' ) { $ operator .= ' ' ; } return $ expr1 . $ operator . $ expr2 ; } | Convert an operation |
43,950 | protected function at ( DOMNode $ root , $ query = null ) { if ( $ root -> nodeType === XML_TEXT_NODE ) { $ this -> out .= htmlspecialchars ( $ root -> textContent , 0 ) ; } else { $ nodes = ( isset ( $ query ) ) ? $ this -> xpath -> query ( $ query , $ root ) : $ root -> childNodes ; foreach ( $ nodes as $ node ) { $ this -> renderNode ( $ node ) ; } } } | Render the content of given node |
43,951 | protected function canQuickRender ( $ xml ) { return ( $ this -> enableQuickRenderer && ! preg_match ( $ this -> quickRenderingTest , $ xml ) && substr ( $ xml , - 4 ) === '</r>' ) ; } | Test whether given XML can be rendered with the Quick renderer |
43,952 | protected function getParamAsXPath ( $ paramName ) { return ( isset ( $ this -> params [ $ paramName ] ) ) ? XPath :: export ( $ this -> params [ $ paramName ] ) : "''" ; } | Return a parameter s value as an XPath expression |
43,953 | protected function matchAttributes ( $ xml ) { if ( strpos ( $ xml , '="' ) === false ) { return [ ] ; } preg_match_all ( '(([^ =]++)="([^"]*))S' , substr ( $ xml , 0 , strpos ( $ xml , '>' ) ) , $ m ) ; return array_combine ( $ m [ 1 ] , $ m [ 2 ] ) ; } | Capture and return the attributes of an XML element |
43,954 | protected function renderQuick ( $ xml ) { $ this -> attributes = [ ] ; $ xml = $ this -> decodeSMP ( $ xml ) ; $ html = preg_replace_callback ( $ this -> quickRegexp , [ $ this , 'renderQuickCallback' ] , preg_replace ( '(<[eis]>[^<]*</[eis]>)' , '' , substr ( $ xml , 1 + strpos ( $ xml , '>' ) , - 4 ) ) ) ; return str_replace ( '<br/>' , '<br>' , $ html ) ; } | Render an intermediate representation using the Quick renderer |
43,955 | protected function renderQuickCallback ( array $ m ) { if ( isset ( $ m [ 3 ] ) ) { return $ this -> renderQuickSelfClosingTag ( $ m ) ; } if ( isset ( $ m [ 2 ] ) ) { $ id = $ m [ 2 ] ; } else { $ id = $ m [ 1 ] ; $ this -> checkTagPairContent ( $ id , $ m [ 0 ] ) ; } if ( isset ( $ this -> static [ $ id ] ) ) { return $ this -> static [ $ id ] ; } if ( isset ( $ this -> dynamic [ $ id ] ) ) { return preg_replace ( $ this -> dynamic [ $ id ] [ 0 ] , $ this -> dynamic [ $ id ] [ 1 ] , $ m [ 0 ] , 1 ) ; } return $ this -> renderQuickTemplate ( $ id , $ m [ 0 ] ) ; } | Render a string matched by the Quick renderer |
43,956 | protected function renderQuickSelfClosingTag ( array $ m ) { unset ( $ m [ 3 ] ) ; $ m [ 0 ] = substr ( $ m [ 0 ] , 0 , - 2 ) . '>' ; $ html = $ this -> renderQuickCallback ( $ m ) ; $ m [ 0 ] = '</' . $ m [ 2 ] . '>' ; $ m [ 2 ] = '/' . $ m [ 2 ] ; $ html .= $ this -> renderQuickCallback ( $ m ) ; return $ html ; } | Render a self - closing tag using the Quick renderer |
43,957 | protected function getRegexp ( ) { $ anchor = RegexpBuilder :: fromList ( $ this -> configurator -> urlConfig -> getAllowedSchemes ( ) ) . '://' ; if ( $ this -> matchWww ) { $ anchor = '(?:' . $ anchor . '|www\\.)' ; } $ regexp = '#\\b' . $ anchor . '\\S(?>[^\\s()\\[\\]' . '\\x{FF01}-\\x{FF0F}\\x{FF1A}-\\x{FF20}\\x{FF3B}-\\x{FF40}\\x{FF5B}-\\x{FF65}' . ']|\\([^\\s()]*\\)|\\[\\w*\\])++#Siu' ; return $ regexp ; } | Return the regexp used to match URLs |
43,958 | protected function castConfigValue ( $ name , $ value ) { foreach ( $ this -> configTypes as list ( $ nameRegexp , $ valueRegexp , $ methodName ) ) { if ( preg_match ( $ nameRegexp , $ name ) && preg_match ( $ valueRegexp , $ value ) ) { return $ this -> $ methodName ( $ value ) ; } } return $ value ; } | Cast given config value to the appropriate type |
43,959 | protected function convertValueTypes ( array $ config ) { foreach ( $ config as $ k => $ v ) { if ( is_array ( $ v ) ) { $ config [ $ k ] = $ this -> convertValueTypes ( $ v ) ; } else { $ config [ $ k ] = $ this -> castConfigValue ( $ k , $ v ) ; } } return $ config ; } | Convert known config values to the appropriate type |
43,960 | protected function flattenConfig ( array $ config ) { foreach ( $ config as $ k => $ v ) { if ( is_array ( $ v ) && count ( $ v ) === 1 ) { $ config [ $ k ] = end ( $ v ) ; } } return $ config ; } | Replace arrays that contain a single element with the element itself |
43,961 | protected function getConfigFromXmlFile ( $ filepath ) { $ dom = new DOMDocument ; $ dom -> loadXML ( file_get_contents ( $ filepath ) , LIBXML_NOCDATA ) ; return $ this -> getElementConfig ( $ dom -> documentElement ) ; } | Extract a site s config from its XML file |
43,962 | protected function getElementConfig ( DOMElement $ element ) { $ config = [ ] ; foreach ( $ element -> attributes as $ attribute ) { $ config [ $ attribute -> name ] [ ] = $ attribute -> value ; } foreach ( $ element -> childNodes as $ childNode ) { if ( $ childNode instanceof DOMElement ) { $ config [ $ childNode -> nodeName ] [ ] = $ this -> getValueFromElement ( $ childNode ) ; } } return $ this -> flattenConfig ( $ this -> convertValueTypes ( $ config ) ) ; } | Extract a site s config from its XML representation |
43,963 | protected function getValueFromElement ( DOMElement $ element ) { return ( ! $ element -> attributes -> length && $ element -> childNodes -> length === 1 && $ element -> firstChild -> nodeType === XML_TEXT_NODE ) ? $ element -> nodeValue : $ this -> getElementConfig ( $ element ) ; } | Extract a value from given element |
43,964 | public static function get ( $ funcName ) { if ( isset ( self :: $ cache [ $ funcName ] ) ) { return self :: $ cache [ $ funcName ] ; } if ( preg_match ( '(^[a-z_0-9]+$)D' , $ funcName ) ) { $ filepath = __DIR__ . '/functions/' . $ funcName . '.js' ; if ( file_exists ( $ filepath ) ) { return file_get_contents ( $ filepath ) ; } } throw new InvalidArgumentException ( "Unknown function '" . $ funcName . "'" ) ; } | Return a function s source from the cache or the filesystem |
43,965 | public function add ( $ attrName , $ regexp ) { $ attrName = AttributeName :: normalize ( $ attrName ) ; $ k = serialize ( [ $ attrName , $ regexp ] ) ; $ this -> items [ $ k ] = new AttributePreprocessor ( $ regexp ) ; return $ this -> items [ $ k ] ; } | Add an attribute preprocessor |
43,966 | public function merge ( $ attributePreprocessors ) { $ error = false ; if ( $ attributePreprocessors instanceof AttributePreprocessorCollection ) { foreach ( $ attributePreprocessors as $ attrName => $ attributePreprocessor ) { $ this -> add ( $ attrName , $ attributePreprocessor -> getRegexp ( ) ) ; } } elseif ( is_array ( $ attributePreprocessors ) ) { foreach ( $ attributePreprocessors as $ values ) { if ( ! is_array ( $ values ) ) { $ error = true ; break ; } list ( $ attrName , $ value ) = $ values ; if ( $ value instanceof AttributePreprocessor ) { $ value = $ value -> getRegexp ( ) ; } $ this -> add ( $ attrName , $ value ) ; } } else { $ error = true ; } if ( $ error ) { throw new InvalidArgumentException ( 'merge() expects an instance of AttributePreprocessorCollection or a 2D array where each element is a [attribute name, regexp] pair' ) ; } } | Merge a set of attribute preprocessors into this collection |
43,967 | protected function appendElement ( DOMElement $ parentNode , $ name , $ value = '' ) { return $ parentNode -> appendChild ( $ parentNode -> ownerDocument -> createElement ( $ name , $ value ) ) ; } | Create and append an element to given node in the IR |
43,968 | protected function evaluate ( $ expr , DOMNode $ node = null ) { return ( isset ( $ node ) ) ? $ this -> xpath -> evaluate ( $ expr , $ node ) : $ this -> xpath -> evaluate ( $ expr ) ; } | Evaluate an XPath expression and return its result |
43,969 | protected function evaluateExpression ( $ expr ) { $ original = $ expr ; foreach ( $ this -> getOptimizationPasses ( ) as $ regexp => $ methodName ) { $ regexp = str_replace ( ' ' , '\\s*' , $ regexp ) ; $ expr = preg_replace_callback ( $ regexp , [ $ this , $ methodName ] , $ expr ) ; } return ( $ expr === $ original ) ? $ expr : $ this -> evaluateExpression ( trim ( $ expr ) ) ; } | Evaluate given expression and return the result |
43,970 | protected function normalizeAttribute ( DOMAttr $ attribute ) { AVTHelper :: replace ( $ attribute , function ( $ token ) { if ( $ token [ 0 ] === 'expression' ) { $ token [ 1 ] = $ this -> evaluateExpression ( $ token [ 1 ] ) ; } return $ token ; } ) ; } | Replace constant expressions in given AVT |
43,971 | protected function getCachedFilepath ( array $ vars ) { if ( ! isset ( $ this -> cacheDir ) ) { return null ; } $ filepath = $ this -> cacheDir . '/http.' . $ this -> getCacheKey ( $ vars ) ; if ( extension_loaded ( 'zlib' ) ) { $ filepath = 'compress.zlib://' . $ filepath . '.gz' ; } return $ filepath ; } | Generate and return a filepath that matches given vars |
43,972 | protected function getClient ( ) { $ this -> client -> timeout = $ this -> timeout ; $ this -> client -> sslVerifyPeer = $ this -> sslVerifyPeer ; return $ this -> client ; } | Return cached client configured with this client s options |
43,973 | protected function load ( ) { if ( ! isset ( $ this -> proc ) ) { $ xsl = $ this -> loadXML ( $ this -> stylesheet ) ; $ this -> proc = new XSLTProcessor ; $ this -> proc -> importStylesheet ( $ xsl ) ; } } | Create an XSLTProcessor and load the stylesheet |
43,974 | public function addCustom ( $ usage , $ template , array $ options = [ ] ) { $ config = $ this -> bbcodeMonkey -> create ( $ usage , $ template ) ; if ( isset ( $ options [ 'tagName' ] ) ) { $ config [ 'bbcode' ] -> tagName = $ options [ 'tagName' ] ; } if ( isset ( $ options [ 'rules' ] ) ) { $ config [ 'tag' ] -> rules -> merge ( $ options [ 'rules' ] ) ; } return $ this -> addFromConfig ( $ config ) ; } | Add a BBCode using their human - readable representation |
43,975 | public function addFromRepository ( $ name , $ repository = 'default' , array $ vars = [ ] ) { if ( ! ( $ repository instanceof Repository ) ) { if ( ! $ this -> repositories -> exists ( $ repository ) ) { throw new InvalidArgumentException ( "Repository '" . $ repository . "' does not exist" ) ; } $ repository = $ this -> repositories -> get ( $ repository ) ; } return $ this -> addFromConfig ( $ repository -> get ( $ name , $ vars ) ) ; } | Add a BBCode from a repository |
43,976 | protected function addFromConfig ( array $ config ) { $ bbcodeName = $ config [ 'bbcodeName' ] ; $ bbcode = $ config [ 'bbcode' ] ; $ tag = $ config [ 'tag' ] ; if ( ! isset ( $ bbcode -> tagName ) ) { $ bbcode -> tagName = $ bbcodeName ; } $ this -> configurator -> templateNormalizer -> normalizeTag ( $ tag ) ; $ this -> configurator -> templateChecker -> checkTag ( $ tag ) ; $ this -> collection -> add ( $ bbcodeName , $ bbcode ) ; $ this -> configurator -> tags -> add ( $ bbcode -> tagName , $ tag ) ; return $ bbcode ; } | Add a BBCode and its tag based on the return config from BBCodeMonkey |
43,977 | public function minify ( $ src ) { $ options = ( $ this -> options ) ? ' ' . $ this -> options : '' ; if ( $ this -> excludeDefaultExterns && $ this -> compilationLevel === 'ADVANCED_OPTIMIZATIONS' ) { $ options .= ' --externs ' . __DIR__ . '/../externs.application.js --env=CUSTOM' ; } $ crc = crc32 ( $ src ) ; $ inFile = sys_get_temp_dir ( ) . '/' . $ crc . '.js' ; $ outFile = sys_get_temp_dir ( ) . '/' . $ crc . '.min.js' ; file_put_contents ( $ inFile , $ src ) ; $ cmd = $ this -> command . ' --compilation_level ' . escapeshellarg ( $ this -> compilationLevel ) . $ options . ' --js ' . escapeshellarg ( $ inFile ) . ' --js_output_file ' . escapeshellarg ( $ outFile ) ; exec ( $ cmd . ' 2>&1' , $ output , $ return ) ; unlink ( $ inFile ) ; if ( file_exists ( $ outFile ) ) { $ src = trim ( file_get_contents ( $ outFile ) ) ; unlink ( $ outFile ) ; } if ( ! empty ( $ return ) ) { throw new RuntimeException ( 'An error occured during minification: ' . implode ( "\n" , $ output ) ) ; } return $ src ; } | Compile given JavaScript source via the Closure Compiler application |
43,978 | public static function fromList ( array $ words , array $ options = [ ] ) { $ options += [ 'delimiter' => '/' , 'caseInsensitive' => false , 'specialChars' => [ ] , 'unicode' => true ] ; if ( $ options [ 'caseInsensitive' ] ) { foreach ( $ words as & $ word ) { $ word = strtr ( $ word , 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' , 'abcdefghijklmnopqrstuvwxyz' ) ; } unset ( $ word ) ; } $ builder = new Builder ( [ 'delimiter' => $ options [ 'delimiter' ] , 'meta' => $ options [ 'specialChars' ] , 'input' => $ options [ 'unicode' ] ? 'Utf8' : 'Bytes' , 'output' => $ options [ 'unicode' ] ? 'Utf8' : 'Bytes' ] ) ; return $ builder -> build ( $ words ) ; } | Create a regexp pattern that matches a list of words |
43,979 | public static function getDefaultFilter ( $ filterName ) { $ filterName = ucfirst ( strtolower ( $ filterName ) ) ; $ className = 's9e\\TextFormatter\\Configurator\\Items\\AttributeFilters\\' . $ filterName . 'Filter' ; if ( ! class_exists ( $ className ) ) { throw new InvalidArgumentException ( "Unknown attribute filter '" . $ filterName . "'" ) ; } return new $ className ; } | Get an instance of the default filter for given name |
43,980 | public function normalizeKey ( $ key ) { if ( preg_match ( '/^#[a-z_0-9]+$/Di' , $ key ) ) { return strtolower ( $ key ) ; } if ( is_string ( $ key ) && is_callable ( $ key ) ) { return $ key ; } throw new InvalidArgumentException ( "Invalid filter name '" . $ key . "'" ) ; } | Normalize the name of an attribute filter |
43,981 | public function normalizeValue ( $ value ) { if ( $ value instanceof AttributeFilter ) { return $ value ; } if ( is_callable ( $ value ) ) { return new AttributeFilter ( $ value ) ; } throw new InvalidArgumentException ( 'Argument 1 passed to ' . __METHOD__ . ' must be a valid callback or an instance of s9e\\TextFormatter\\Configurator\\Items\\AttributeFilter' ) ; } | Normalize a value to an instance of AttributeFilter |
43,982 | public function getRegexp ( ) { $ hosts = [ ] ; foreach ( $ this -> items as $ host ) { $ hosts [ ] = $ this -> normalizeHostmask ( $ host ) ; } $ regexp = RegexpBuilder :: fromList ( $ hosts , [ 'specialChars' => [ '*' => '.*' , '^' => '^' , '$' => '$' ] ] ) ; return '/' . $ regexp . '/DSis' ; } | Return a regexp that matches the list of hostnames |
43,983 | protected function normalizeHostmask ( $ host ) { if ( preg_match ( '#[\\x80-\xff]#' , $ host ) && function_exists ( 'idn_to_ascii' ) ) { $ variant = ( defined ( 'INTL_IDNA_VARIANT_UTS46' ) ) ? INTL_IDNA_VARIANT_UTS46 : 0 ; $ host = idn_to_ascii ( $ host , 0 , $ variant ) ; } if ( substr ( $ host , 0 , 1 ) === '*' ) { $ host = ltrim ( $ host , '*' ) ; } else { $ host = '^' . $ host ; } if ( substr ( $ host , - 1 ) === '*' ) { $ host = rtrim ( $ host , '*' ) ; } else { $ host .= '$' ; } return $ host ; } | Normalize a hostmask to a regular expression |
43,984 | public static function getVariables ( $ expr ) { $ expr = preg_replace ( '/(["\']).*?\\1/s' , '$1$1' , $ expr ) ; preg_match_all ( '/\\$(\\w+)/' , $ expr , $ matches ) ; $ varNames = array_unique ( $ matches [ 1 ] ) ; sort ( $ varNames ) ; return $ varNames ; } | Return the list of variables used in a given XPath expression |
43,985 | public static function isExpressionNumeric ( $ expr ) { $ expr = strrev ( preg_replace ( '(\\((?!\\s*(?!vid(?!\\w))\\w))' , ' ' , strrev ( $ expr ) ) ) ; $ expr = str_replace ( ')' , ' ' , $ expr ) ; if ( preg_match ( '(^\\s*([$@][-\\w]++|-?\\.\\d++|-?\\d++(?:\\.\\d++)?)(?>\\s*(?>[-+*]|div)\\s*(?1))++\\s*$)' , $ expr ) ) { return true ; } return false ; } | Determine whether given XPath expression definitely evaluates to a number |
43,986 | public static function minify ( $ expr ) { $ old = $ expr ; $ strings = [ ] ; $ expr = preg_replace_callback ( '/"[^"]*"|\'[^\']*\'/' , function ( $ m ) use ( & $ strings ) { $ uniqid = '(' . sha1 ( uniqid ( ) ) . ')' ; $ strings [ $ uniqid ] = $ m [ 0 ] ; return $ uniqid ; } , trim ( $ expr ) ) ; if ( preg_match ( '/[\'"]/' , $ expr ) ) { throw new RuntimeException ( "Cannot parse XPath expression '" . $ old . "'" ) ; } $ expr = preg_replace ( '/\\s+/' , ' ' , $ expr ) ; $ expr = preg_replace ( '/([-a-z_0-9]) ([^-a-z_0-9])/i' , '$1$2' , $ expr ) ; $ expr = preg_replace ( '/([^-a-z_0-9]) ([-a-z_0-9])/i' , '$1$2' , $ expr ) ; $ expr = preg_replace ( '/(?!- -)([^-a-z_0-9]) ([^-a-z_0-9])/i' , '$1$2' , $ expr ) ; $ expr = preg_replace ( '/ - ([a-z_0-9])/i' , ' -$1' , $ expr ) ; $ expr = preg_replace ( '/((?:^|[ \\(])\\d+) div ?/' , '$1div' , $ expr ) ; $ expr = preg_replace ( '/([^-a-z_0-9]div) (?=[$0-9@])/' , '$1' , $ expr ) ; $ expr = strtr ( $ expr , $ strings ) ; return $ expr ; } | Remove extraneous space in a given XPath expression |
43,987 | public static function parseEqualityExpr ( $ expr ) { $ eq = '(?<equality>' . '(?<key>@[-\\w]+|\\$\\w+|\\.)' . '(?<operator>\\s*=\\s*)' . '(?:' . '(?<literal>(?<string>"[^"]*"|\'[^\']*\')|0|[1-9][0-9]*)' . '|' . '(?<concat>concat\\(\\s*(?&string)\\s*(?:,\\s*(?&string)\\s*)+\\))' . ')' . '|' . '(?:(?<literal>(?&literal))|(?<concat>(?&concat)))(?&operator)(?<key>(?&key))' . ')' ; $ regexp = '(^(?J)\\s*' . $ eq . '\\s*(?:or\\s*(?&equality)\\s*)*$)' ; if ( ! preg_match ( $ regexp , $ expr ) ) { return false ; } preg_match_all ( "((?J)$eq)" , $ expr , $ matches , PREG_SET_ORDER ) ; $ map = [ ] ; foreach ( $ matches as $ m ) { $ key = $ m [ 'key' ] ; $ value = ( ! empty ( $ m [ 'concat' ] ) ) ? self :: evaluateConcat ( $ m [ 'concat' ] ) : self :: evaluateLiteral ( $ m [ 'literal' ] ) ; $ map [ $ key ] [ ] = $ value ; } return $ map ; } | Parse an XPath expression that is composed entirely of equality tests between a variable part and a constant part |
43,988 | public static function normalizeName ( $ bbcodeName ) { if ( $ bbcodeName === '*' ) { return '*' ; } if ( ! TagName :: isValid ( $ bbcodeName ) ) { throw new InvalidArgumentException ( "Invalid BBCode name '" . $ bbcodeName . "'" ) ; } return TagName :: normalize ( $ bbcodeName ) ; } | Normalize the name of a BBCode |
43,989 | public function optimize ( $ php ) { $ this -> reset ( $ php ) ; $ this -> optimizeTokens ( ) ; if ( $ this -> changed ) { $ php = $ this -> serialize ( ) ; } unset ( $ this -> tokens ) ; return $ php ; } | Optimize the control structures of a script |
43,990 | protected function reset ( $ php ) { $ this -> tokens = token_get_all ( '<?php ' . $ php ) ; $ this -> i = 0 ; $ this -> cnt = count ( $ this -> tokens ) ; $ this -> changed = false ; } | Reset the internal state of this optimizer |
43,991 | protected function serialize ( ) { unset ( $ this -> tokens [ 0 ] ) ; $ php = '' ; foreach ( $ this -> tokens as $ token ) { $ php .= ( is_string ( $ token ) ) ? $ token : $ token [ 1 ] ; } return $ php ; } | Serialize the tokens back to source |
43,992 | protected function skipToString ( $ str ) { while ( ++ $ this -> i < $ this -> cnt && $ this -> tokens [ $ this -> i ] !== $ str ) ; } | Move the internal cursor until it reaches given string |
43,993 | protected function skipWhitespace ( ) { while ( ++ $ this -> i < $ this -> cnt && $ this -> tokens [ $ this -> i ] [ 0 ] === T_WHITESPACE ) ; } | Skip all whitespace |
43,994 | protected function unindentBlock ( $ start , $ end ) { $ this -> i = $ start ; do { if ( $ this -> tokens [ $ this -> i ] [ 0 ] === T_WHITESPACE || $ this -> tokens [ $ this -> i ] [ 0 ] === T_DOC_COMMENT ) { $ this -> tokens [ $ this -> i ] [ 1 ] = preg_replace ( "/^\t/m" , '' , $ this -> tokens [ $ this -> i ] [ 1 ] ) ; } } while ( ++ $ this -> i <= $ end ) ; } | Remove one tab of indentation off a range of PHP tokens |
43,995 | protected function replaceAVT ( DOMAttr $ attribute ) { AVTHelper :: replace ( $ attribute , function ( $ token ) { if ( $ token [ 0 ] === 'expression' ) { $ token [ 1 ] = XPathHelper :: minify ( $ token [ 1 ] ) ; } return $ token ; } ) ; } | Minify XPath expressions in given attribute |
43,996 | protected function captureAttributes ( Tag $ tag , $ elName , $ str ) { preg_match_all ( '/[a-z][-a-z0-9]*(?>\\s*=\\s*(?>"[^"]*"|\'[^\']*\'|[^\\s"\'=<>`]+))?/i' , $ str , $ attrMatches ) ; foreach ( $ attrMatches [ 0 ] as $ attrMatch ) { $ pos = strpos ( $ attrMatch , '=' ) ; if ( $ pos === false ) { $ pos = strlen ( $ attrMatch ) ; $ attrMatch .= '=' . strtolower ( $ attrMatch ) ; } $ attrName = strtolower ( trim ( substr ( $ attrMatch , 0 , $ pos ) ) ) ; $ attrValue = trim ( substr ( $ attrMatch , 1 + $ pos ) ) ; if ( isset ( $ this -> config [ 'aliases' ] [ $ elName ] [ $ attrName ] ) ) { $ attrName = $ this -> config [ 'aliases' ] [ $ elName ] [ $ attrName ] ; } if ( $ attrValue [ 0 ] === '"' || $ attrValue [ 0 ] === "'" ) { $ attrValue = substr ( $ attrValue , 1 , - 1 ) ; } $ tag -> setAttribute ( $ attrName , html_entity_decode ( $ attrValue , ENT_QUOTES , 'UTF-8' ) ) ; } } | Capture all attributes in given string |
43,997 | public static function closesParent ( DOMElement $ child , DOMElement $ parent ) { $ parentName = $ parent -> nodeName ; $ childName = $ child -> nodeName ; return ! empty ( self :: $ htmlElements [ $ childName ] [ 'cp' ] ) && in_array ( $ parentName , self :: $ htmlElements [ $ childName ] [ 'cp' ] , true ) ; } | Test whether given child element closes given parent element |
43,998 | protected static function evaluate ( $ query , DOMElement $ element ) { $ xpath = new DOMXPath ( $ element -> ownerDocument ) ; return $ xpath -> evaluate ( 'boolean(' . $ query . ')' , $ element ) ; } | Evaluate an XPath query using given element as context node |
43,999 | protected static function getBitfield ( DOMElement $ element , $ name ) { $ props = self :: getProperties ( $ element ) ; $ bitfield = self :: toBin ( $ props [ $ name ] ) ; foreach ( array_keys ( array_filter ( str_split ( $ bitfield , 1 ) ) ) as $ bitNumber ) { $ conditionName = $ name . $ bitNumber ; if ( isset ( $ props [ $ conditionName ] ) && ! self :: evaluate ( $ props [ $ conditionName ] , $ element ) ) { $ bitfield [ $ bitNumber ] = '0' ; } } return self :: toRaw ( $ bitfield ) ; } | Get the bitfield value for a given element |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.