idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
43,800 | protected function checkObjects ( ) { foreach ( $ this -> getElements ( 'object' ) as $ object ) { $ this -> checkDynamicParams ( $ object ) ; $ params = $ this -> getObjectParams ( $ object ) ; foreach ( $ params as $ param ) { $ this -> checkSetting ( $ param , $ param -> getAttribute ( 'value' ) ) ; } if ( empty ( $ params ) ) { $ this -> checkSetting ( $ object , $ this -> defaultSetting ) ; } } } | Check object elements in given template |
43,801 | protected function checkSetting ( DOMNode $ node , $ setting ) { if ( ! isset ( $ this -> settings [ strtolower ( $ setting ) ] ) ) { if ( preg_match ( '/(?<!\\{)\\{(?:\\{\\{)*(?!\\{)/' , $ setting ) ) { throw new UnsafeTemplateException ( 'Cannot assess ' . $ this -> settingName . " setting '" . $ setting . "'" , $ node ) ; } throw new UnsafeTemplateException ( 'Unknown ' . $ this -> settingName . " value '" . $ setting . "'" , $ node ) ; } $ value = $ this -> settings [ strtolower ( $ setting ) ] ; $ maxValue = $ this -> settings [ strtolower ( $ this -> maxSetting ) ] ; if ( $ value > $ maxValue ) { throw new UnsafeTemplateException ( $ this -> settingName . " setting '" . $ setting . "' exceeds restricted value '" . $ this -> maxSetting . "'" , $ node ) ; } } | Test whether given setting is allowed |
43,802 | protected function getElements ( $ tagName ) { $ nodes = [ ] ; foreach ( $ this -> template -> ownerDocument -> getElementsByTagName ( $ tagName ) as $ node ) { if ( ! $ this -> onlyIfDynamic || $ this -> isDynamic ( $ node ) ) { $ nodes [ ] = $ node ; } } return $ nodes ; } | Get all elements the restriction applies to |
43,803 | protected function getObjectParams ( DOMElement $ object ) { $ params = [ ] ; $ settingName = strtolower ( $ this -> settingName ) ; foreach ( $ object -> getElementsByTagName ( 'param' ) as $ param ) { $ paramName = strtolower ( $ param -> getAttribute ( 'name' ) ) ; if ( $ paramName === $ settingName && $ param -> parentNode -> isSameNode ( $ object ) ) { $ params [ ] = $ param ; } } return $ params ; } | Get all param elements attached to given object |
43,804 | public function get ( $ src ) { try { return ( isset ( $ this -> cacheDir ) ) ? $ this -> getFromCache ( $ src ) : $ this -> minify ( $ src ) ; } catch ( Exception $ e ) { if ( ! $ this -> keepGoing ) { throw $ e ; } } return $ src ; } | Minify given JavaScript source and cache the result if applicable |
43,805 | protected function getFromCache ( $ src ) { $ differentiator = $ this -> getCacheDifferentiator ( ) ; $ key = sha1 ( serialize ( [ get_class ( $ this ) , $ differentiator , $ src ] ) ) ; $ cacheFile = $ this -> cacheDir . '/minifier.' . $ key . '.js' ; if ( ! file_exists ( $ cacheFile ) ) { file_put_contents ( $ cacheFile , $ this -> minify ( $ src ) ) ; } return file_get_contents ( $ cacheFile ) ; } | Get the minified source from cache or minify and cache the result |
43,806 | public function getHelper ( ) { $ config = $ this -> asConfig ( ) ; if ( isset ( $ config ) ) { $ config = ConfigHelper :: filterConfig ( $ config , 'PHP' ) ; } else { $ config = [ 'attrName' => $ this -> attrName , 'regexp' => '/(?!)/' , 'tagName' => $ this -> tagName ] ; } return new Helper ( $ config ) ; } | Return an instance of s9e \ TextFormatter \ Plugins \ Censor \ Helper |
43,807 | protected function getWordsRegexp ( array $ words ) { $ expr = RegexpBuilder :: fromList ( $ words , $ this -> regexpOptions ) ; $ regexp = new Regexp ( '/(?<![\\pL\\pN])' . $ expr . '(?![\\pL\\pN])/Siu' ) ; $ expr = str_replace ( '[\\pL\\pN]' , '[^\\s!-\\/:-?]' , $ expr ) ; $ expr = str_replace ( '(?>' , '(?:' , $ expr ) ; $ regexp -> setJS ( '/(?:^|\\W)' . $ expr . '(?!\\w)/gi' ) ; return $ regexp ; } | Generate a regexp that matches the given list of words |
43,808 | public static function getBitfields ( TagCollection $ tags , Ruleset $ rootRules ) { $ rules = [ '*root*' => iterator_to_array ( $ rootRules ) ] ; foreach ( $ tags as $ tagName => $ tag ) { $ rules [ $ tagName ] = iterator_to_array ( $ tag -> rules ) ; } $ matrix = self :: unrollRules ( $ rules ) ; self :: pruneMatrix ( $ matrix ) ; $ groupedTags = [ ] ; foreach ( array_keys ( $ matrix ) as $ tagName ) { if ( $ tagName === '*root*' ) { continue ; } $ k = '' ; foreach ( $ matrix as $ tagMatrix ) { $ k .= $ tagMatrix [ 'allowedChildren' ] [ $ tagName ] ; $ k .= $ tagMatrix [ 'allowedDescendants' ] [ $ tagName ] ; } $ groupedTags [ $ k ] [ ] = $ tagName ; } $ bitTag = [ ] ; $ bitNumber = 0 ; $ tagsConfig = [ ] ; foreach ( $ groupedTags as $ tagNames ) { foreach ( $ tagNames as $ tagName ) { $ tagsConfig [ $ tagName ] [ 'bitNumber' ] = $ bitNumber ; $ bitTag [ $ bitNumber ] = $ tagName ; } ++ $ bitNumber ; } foreach ( $ matrix as $ tagName => $ tagMatrix ) { $ allowedChildren = '' ; $ allowedDescendants = '' ; foreach ( $ bitTag as $ targetName ) { $ allowedChildren .= $ tagMatrix [ 'allowedChildren' ] [ $ targetName ] ; $ allowedDescendants .= $ tagMatrix [ 'allowedDescendants' ] [ $ targetName ] ; } $ tagsConfig [ $ tagName ] [ 'allowed' ] = self :: pack ( $ allowedChildren , $ allowedDescendants ) ; } $ return = [ 'root' => $ tagsConfig [ '*root*' ] , 'tags' => $ tagsConfig ] ; unset ( $ return [ 'tags' ] [ '*root*' ] ) ; return $ return ; } | Generate the allowedChildren and allowedDescendants bitfields for every tag and for the root context |
43,809 | protected static function initMatrix ( array $ rules ) { $ matrix = [ ] ; $ tagNames = array_keys ( $ rules ) ; foreach ( $ rules as $ tagName => $ tagRules ) { $ matrix [ $ tagName ] [ 'allowedChildren' ] = array_fill_keys ( $ tagNames , 0 ) ; $ matrix [ $ tagName ] [ 'allowedDescendants' ] = array_fill_keys ( $ tagNames , 0 ) ; } return $ matrix ; } | Initialize a matrix of settings |
43,810 | protected static function applyTargetedRule ( array & $ matrix , $ rules , $ ruleName , $ key , $ value ) { foreach ( $ rules as $ tagName => $ tagRules ) { if ( ! isset ( $ tagRules [ $ ruleName ] ) ) { continue ; } foreach ( $ tagRules [ $ ruleName ] as $ targetName ) { $ matrix [ $ tagName ] [ $ key ] [ $ targetName ] = $ value ; } } } | Apply given rule from each applicable tag |
43,811 | protected static function pruneMatrix ( array & $ matrix ) { $ usableTags = [ '*root*' => 1 ] ; $ parentTags = $ usableTags ; do { $ nextTags = [ ] ; foreach ( array_keys ( $ parentTags ) as $ tagName ) { $ nextTags += array_filter ( $ matrix [ $ tagName ] [ 'allowedChildren' ] ) ; } $ parentTags = array_diff_key ( $ nextTags , $ usableTags ) ; $ parentTags = array_intersect_key ( $ parentTags , $ matrix ) ; $ usableTags += $ parentTags ; } while ( ! empty ( $ parentTags ) ) ; $ matrix = array_intersect_key ( $ matrix , $ usableTags ) ; unset ( $ usableTags [ '*root*' ] ) ; foreach ( $ matrix as $ tagName => & $ tagMatrix ) { $ tagMatrix [ 'allowedChildren' ] = array_intersect_key ( $ tagMatrix [ 'allowedChildren' ] , $ usableTags ) ; $ tagMatrix [ 'allowedDescendants' ] = array_intersect_key ( $ tagMatrix [ 'allowedDescendants' ] , $ usableTags ) ; } unset ( $ tagMatrix ) ; } | Remove unusable tags from the matrix |
43,812 | protected static function pack ( $ allowedChildren , $ allowedDescendants ) { $ allowedChildren = str_split ( $ allowedChildren , 8 ) ; $ allowedDescendants = str_split ( $ allowedDescendants , 8 ) ; $ allowed = [ ] ; foreach ( array_keys ( $ allowedChildren ) as $ k ) { $ allowed [ ] = bindec ( sprintf ( '%1$08s%2$08s' , strrev ( $ allowedDescendants [ $ k ] ) , strrev ( $ allowedChildren [ $ k ] ) ) ) ; } return $ allowed ; } | Convert a binary representation such as 101011 to an array of integer |
43,813 | public function serialize ( DOMElement $ ir ) { $ this -> xpath = new DOMXPath ( $ ir -> ownerDocument ) ; $ this -> isVoid = [ ] ; foreach ( $ this -> xpath -> query ( '//element' ) as $ element ) { $ this -> isVoid [ $ element -> getAttribute ( 'id' ) ] = $ element -> getAttribute ( 'void' ) ; } return $ this -> serializeChildren ( $ ir ) ; } | Serialize the internal representation of a template into PHP |
43,814 | protected function convertAttributeValueTemplate ( $ attrValue ) { $ phpExpressions = [ ] ; foreach ( AVTHelper :: parse ( $ attrValue ) as $ token ) { if ( $ token [ 0 ] === 'literal' ) { $ phpExpressions [ ] = var_export ( $ token [ 1 ] , true ) ; } else { $ phpExpressions [ ] = $ this -> convertXPath ( $ token [ 1 ] ) ; } } return implode ( '.' , $ phpExpressions ) ; } | Convert an attribute value template into PHP |
43,815 | protected function escapeLiteral ( $ text , $ context ) { if ( $ context === 'raw' ) { return $ text ; } $ escapeMode = ( $ context === 'attribute' ) ? ENT_COMPAT : ENT_NOQUOTES ; return htmlspecialchars ( $ text , $ escapeMode ) ; } | Escape given literal |
43,816 | protected function escapePHPOutput ( $ php , $ context ) { if ( $ context === 'raw' ) { return $ php ; } $ escapeMode = ( $ context === 'attribute' ) ? ENT_COMPAT : ENT_NOQUOTES ; return 'htmlspecialchars(' . $ php . ',' . $ escapeMode . ')' ; } | Escape the output of given PHP expression |
43,817 | protected function serializeChildren ( DOMElement $ ir ) { $ php = '' ; foreach ( $ ir -> childNodes as $ node ) { if ( $ node instanceof DOMElement ) { $ methodName = 'serialize' . ucfirst ( $ node -> localName ) ; $ php .= $ this -> $ methodName ( $ node ) ; } } return $ php ; } | Serialize all the children of given node into PHP |
43,818 | public static function replaceTokens ( $ template , $ regexp , $ fn ) { $ dom = TemplateLoader :: load ( $ template ) ; $ xpath = new DOMXPath ( $ dom ) ; foreach ( $ xpath -> query ( '//@*' ) as $ attribute ) { self :: replaceTokensInAttribute ( $ attribute , $ regexp , $ fn ) ; } foreach ( $ xpath -> query ( '//text()' ) as $ node ) { self :: replaceTokensInText ( $ node , $ regexp , $ fn ) ; } return TemplateLoader :: save ( $ dom ) ; } | Replace parts of a template that match given regexp |
43,819 | protected static function createReplacementNode ( DOMDocument $ dom , array $ replacement ) { if ( $ replacement [ 0 ] === 'expression' ) { $ newNode = $ dom -> createElementNS ( self :: XMLNS_XSL , 'xsl:value-of' ) ; $ newNode -> setAttribute ( 'select' , $ replacement [ 1 ] ) ; } elseif ( $ replacement [ 0 ] === 'passthrough' ) { $ newNode = $ dom -> createElementNS ( self :: XMLNS_XSL , 'xsl:apply-templates' ) ; if ( isset ( $ replacement [ 1 ] ) ) { $ newNode -> setAttribute ( 'select' , $ replacement [ 1 ] ) ; } } else { $ newNode = $ dom -> createTextNode ( $ replacement [ 1 ] ) ; } return $ newNode ; } | Create a node that implements given replacement strategy |
43,820 | protected static function replaceTokensInAttribute ( DOMAttr $ attribute , $ regexp , $ fn ) { $ attrValue = preg_replace_callback ( $ regexp , function ( $ m ) use ( $ fn , $ attribute ) { $ replacement = $ fn ( $ m , $ attribute ) ; if ( $ replacement [ 0 ] === 'expression' || $ replacement [ 0 ] === 'passthrough' ) { $ replacement [ ] = '.' ; return '{' . $ replacement [ 1 ] . '}' ; } else { return $ replacement [ 1 ] ; } } , $ attribute -> value ) ; $ attribute -> value = htmlspecialchars ( $ attrValue , ENT_COMPAT , 'UTF-8' ) ; } | Replace parts of an attribute that match given regexp |
43,821 | protected static function replaceTokensInText ( DOMText $ node , $ regexp , $ fn ) { $ parentNode = $ node -> parentNode ; $ dom = $ node -> ownerDocument ; preg_match_all ( $ regexp , $ node -> textContent , $ matches , PREG_SET_ORDER | PREG_OFFSET_CAPTURE ) ; $ lastPos = 0 ; foreach ( $ matches as $ m ) { $ pos = $ m [ 0 ] [ 1 ] ; $ text = substr ( $ node -> textContent , $ lastPos , $ pos - $ lastPos ) ; $ parentNode -> insertBefore ( $ dom -> createTextNode ( $ text ) , $ node ) ; $ lastPos = $ pos + strlen ( $ m [ 0 ] [ 0 ] ) ; $ replacement = $ fn ( array_column ( $ m , 0 ) , $ node ) ; $ newNode = self :: createReplacementNode ( $ dom , $ replacement ) ; $ parentNode -> insertBefore ( $ newNode , $ node ) ; } $ text = substr ( $ node -> textContent , $ lastPos ) ; $ parentNode -> insertBefore ( $ dom -> createTextNode ( $ text ) , $ node ) ; $ parentNode -> removeChild ( $ node ) ; } | Replace parts of a text node that match given regexp |
43,822 | public function minify ( $ src ) { $ body = $ this -> generateRequestBody ( $ src ) ; $ response = $ this -> query ( $ body ) ; if ( $ response === false ) { throw new RuntimeException ( 'Could not contact the Closure Compiler service' ) ; } return $ this -> decodeResponse ( $ response ) ; } | Compile given JavaScript source via the Closure Compiler Service |
43,823 | protected function decodeResponse ( $ response ) { $ response = json_decode ( $ response , true ) ; if ( is_null ( $ response ) ) { throw new RuntimeException ( 'Closure Compiler service returned invalid JSON: ' . json_last_error_msg ( ) ) ; } if ( isset ( $ response [ 'serverErrors' ] [ 0 ] ) ) { $ error = $ response [ 'serverErrors' ] [ 0 ] ; throw new RuntimeException ( 'Server error ' . $ error [ 'code' ] . ': ' . $ error [ 'error' ] ) ; } if ( isset ( $ response [ 'errors' ] [ 0 ] ) ) { $ error = $ response [ 'errors' ] [ 0 ] ; throw new RuntimeException ( 'Compilation error: ' . $ error [ 'error' ] ) ; } return $ response [ 'compiledCode' ] ; } | Decode the response returned by the Closure Compiler service |
43,824 | protected function generateRequestBody ( $ src ) { $ params = [ 'compilation_level' => $ this -> compilationLevel , 'js_code' => $ src , 'output_format' => 'json' , 'output_info' => 'compiled_code' ] ; if ( $ this -> excludeDefaultExterns && $ this -> compilationLevel === 'ADVANCED_OPTIMIZATIONS' ) { $ params [ 'exclude_default_externs' ] = 'true' ; $ params [ 'js_externs' ] = $ this -> externs ; } $ body = http_build_query ( $ params ) . '&output_info=errors' ; return $ body ; } | Generate the request body for given code |
43,825 | public function isSafeInJS ( ) { $ safeCallbacks = [ 'urlencode' , 'strtotime' , 'rawurlencode' ] ; if ( in_array ( $ this -> callback , $ safeCallbacks , true ) ) { return true ; } return $ this -> isSafe ( 'InJS' ) ; } | Return whether this filter makes a value safe to be used in JavaScript |
43,826 | public static function filter ( $ attrValue , array $ urlConfig , Logger $ logger = null ) { $ p = self :: parseUrl ( trim ( $ attrValue ) ) ; $ error = self :: validateUrl ( $ urlConfig , $ p ) ; if ( ! empty ( $ error ) ) { if ( isset ( $ logger ) ) { $ p [ 'attrValue' ] = $ attrValue ; $ logger -> err ( $ error , $ p ) ; } return false ; } return self :: rebuildUrl ( $ p ) ; } | Filter a URL |
43,827 | protected static function parseUrl ( $ url ) { $ regexp = '(^(?:([a-z][-+.\\w]*):)?(?://(?:([^:/?#]*)(?::([^/?#]*)?)?@)?(?:(\\[[a-f\\d:]+\\]|[^:/?#]+)(?::(\\d*))?)?(?![^/?#]))?([^?#]*)(\\?[^#]*)?(#.*)?$)Di' ; preg_match ( $ regexp , $ url , $ m ) ; $ parts = [ ] ; $ tokens = [ 'scheme' , 'user' , 'pass' , 'host' , 'port' , 'path' , 'query' , 'fragment' ] ; foreach ( $ tokens as $ i => $ name ) { $ parts [ $ name ] = ( isset ( $ m [ $ i + 1 ] ) ) ? $ m [ $ i + 1 ] : '' ; } $ parts [ 'scheme' ] = strtolower ( $ parts [ 'scheme' ] ) ; $ parts [ 'host' ] = rtrim ( preg_replace ( "/\xE3\x80\x82|\xEF(?:\xBC\x8E|\xBD\xA1)/s" , '.' , $ parts [ 'host' ] ) , '.' ) ; if ( preg_match ( '#[^[:ascii:]]#' , $ parts [ 'host' ] ) && function_exists ( 'idn_to_ascii' ) ) { $ variant = ( defined ( 'INTL_IDNA_VARIANT_UTS46' ) ) ? INTL_IDNA_VARIANT_UTS46 : 0 ; $ parts [ 'host' ] = idn_to_ascii ( $ parts [ 'host' ] , 0 , $ variant ) ; } return $ parts ; } | Parse a URL and return its components |
43,828 | protected static function rebuildUrl ( array $ p ) { $ url = '' ; if ( $ p [ 'scheme' ] !== '' ) { $ url .= $ p [ 'scheme' ] . ':' ; } if ( $ p [ 'host' ] !== '' ) { $ url .= '//' ; if ( $ p [ 'user' ] !== '' ) { $ url .= rawurlencode ( urldecode ( $ p [ 'user' ] ) ) ; if ( $ p [ 'pass' ] !== '' ) { $ url .= ':' . rawurlencode ( urldecode ( $ p [ 'pass' ] ) ) ; } $ url .= '@' ; } $ url .= $ p [ 'host' ] ; if ( $ p [ 'port' ] !== '' ) { $ url .= ':' . $ p [ 'port' ] ; } } elseif ( $ p [ 'scheme' ] === 'file' ) { $ url .= '//' ; } $ path = $ p [ 'path' ] . $ p [ 'query' ] . $ p [ 'fragment' ] ; $ path = preg_replace_callback ( '/%.?[a-f]/' , function ( $ m ) { return strtoupper ( $ m [ 0 ] ) ; } , $ path ) ; $ url .= self :: sanitizeUrl ( $ path ) ; if ( ! $ p [ 'scheme' ] ) { $ url = preg_replace ( '#^([^/]*):#' , '$1%3A' , $ url ) ; } return $ url ; } | Rebuild a parsed URL |
43,829 | protected static function validateUrl ( array $ urlConfig , array $ p ) { if ( $ p [ 'scheme' ] !== '' && ! preg_match ( $ urlConfig [ 'allowedSchemes' ] , $ p [ 'scheme' ] ) ) { return 'URL scheme is not allowed' ; } if ( $ p [ 'host' ] !== '' ) { $ regexp = '/^(?!-)[-a-z0-9]{0,62}[a-z0-9](?:\\.(?!-)[-a-z0-9]{0,62}[a-z0-9])*$/i' ; if ( ! preg_match ( $ regexp , $ p [ 'host' ] ) ) { if ( ! NetworkFilter :: filterIpv4 ( $ p [ 'host' ] ) && ! NetworkFilter :: filterIpv6 ( preg_replace ( '/^\\[(.*)\\]$/' , '$1' , $ p [ 'host' ] ) ) ) { return 'URL host is invalid' ; } } if ( ( isset ( $ urlConfig [ 'disallowedHosts' ] ) && preg_match ( $ urlConfig [ 'disallowedHosts' ] , $ p [ 'host' ] ) ) || ( isset ( $ urlConfig [ 'restrictedHosts' ] ) && ! preg_match ( $ urlConfig [ 'restrictedHosts' ] , $ p [ 'host' ] ) ) ) { return 'URL host is not allowed' ; } } elseif ( preg_match ( '(^(?:(?:f|ht)tps?)$)' , $ p [ 'scheme' ] ) ) { return 'Missing host' ; } } | Validate a parsed URL |
43,830 | public function render ( $ xml ) { if ( substr ( $ xml , 0 , 3 ) === '<t>' && substr ( $ xml , - 4 ) === '</t>' ) { return $ this -> renderPlainText ( $ xml ) ; } else { return $ this -> renderRichText ( preg_replace ( '(<[eis]>[^<]*</[eis]>)' , '' , $ xml ) ) ; } } | Render an intermediate representation |
43,831 | protected function renderPlainText ( $ xml ) { $ html = substr ( $ xml , 3 , - 4 ) ; $ html = str_replace ( '<br/>' , '<br>' , $ html ) ; $ html = $ this -> decodeSMP ( $ html ) ; return $ html ; } | Render an intermediate representation of plain text |
43,832 | public function setParameters ( array $ params ) { foreach ( $ params as $ paramName => $ paramValue ) { $ this -> setParameter ( $ paramName , $ paramValue ) ; } } | Set the values of several parameters from the stylesheet |
43,833 | protected function checkUnsupported ( $ xml ) { if ( strpos ( $ xml , '<!' ) !== false ) { throw new InvalidArgumentException ( 'DTDs, CDATA nodes and comments are not allowed' ) ; } if ( strpos ( $ xml , '<?' ) !== false ) { throw new InvalidArgumentException ( 'Processing instructions are not allowed' ) ; } } | Test for the presence of unsupported XML and throw an exception if found |
43,834 | protected static function export ( array $ arr ) { $ exportKeys = ( array_keys ( $ arr ) !== range ( 0 , count ( $ arr ) - 1 ) ) ; ksort ( $ arr ) ; $ entries = [ ] ; foreach ( $ arr as $ k => $ v ) { $ entries [ ] = ( ( $ exportKeys ) ? var_export ( $ k , true ) . '=>' : '' ) . ( ( is_array ( $ v ) ) ? self :: export ( $ v ) : var_export ( $ v , true ) ) ; } return '[' . implode ( ',' , $ entries ) . ']' ; } | Export an array as PHP |
43,835 | public static function getRenderingStrategy ( $ php ) { $ renderings = self :: getStringRenderings ( $ php ) ; foreach ( self :: getQuickRendering ( $ php ) as $ i => $ phpRendering ) { if ( ! isset ( $ renderings [ $ i ] ) || strpos ( $ phpRendering , '$this->attributes[]' ) !== false ) { $ renderings [ $ i ] = [ 'php' , $ phpRendering ] ; } } return $ renderings ; } | Compute the rendering strategy for a compiled template |
43,836 | protected static function convertPHP ( & $ head , & $ tail , $ passthrough ) { $ saveAttributes = ( bool ) preg_match ( '(\\$node->(?:get|has)Attribute)' , $ tail ) ; preg_match_all ( "(\\\$node->getAttribute\\('([^']+)'\\))" , preg_replace_callback ( '(if\\(\\$node->hasAttribute\\(([^\\)]+)[^}]+)' , function ( $ m ) { return str_replace ( '$node->getAttribute(' . $ m [ 1 ] . ')' , '' , $ m [ 0 ] ) ; } , $ head . $ tail ) , $ matches ) ; $ attrNames = array_unique ( $ matches [ 1 ] ) ; self :: replacePHP ( $ head ) ; self :: replacePHP ( $ tail ) ; if ( ! $ passthrough && strpos ( $ head , '$node->textContent' ) !== false ) { $ head = '$textContent=$this->getQuickTextContent($xml);' . str_replace ( '$node->textContent' , '$textContent' , $ head ) ; } if ( ! empty ( $ attrNames ) ) { ksort ( $ attrNames ) ; $ head = "\$attributes+=['" . implode ( "'=>null,'" , $ attrNames ) . "'=>null];" . $ head ; } if ( $ saveAttributes ) { $ head .= '$this->attributes[]=$attributes;' ; $ tail = '$attributes=array_pop($this->attributes);' . $ tail ; } } | Convert the two sides of a compiled template to quick rendering |
43,837 | protected static function replacePHP ( & $ php ) { $ getAttribute = "\\\$node->getAttribute\\(('[^']+')\\)" ; $ string = "'(?:[^\\\\']|\\\\.)*+'" ; $ replacements = [ '$this->out' => '$html' , '(htmlspecialchars\\(' . $ getAttribute . ',' . ENT_NOQUOTES . '\\))' => "str_replace('"','\"',\$attributes[\$1])" , '(htmlspecialchars\\((' . $ getAttribute . '(?:\\.' . $ getAttribute . ')*),' . ENT_COMPAT . '\\))' => function ( $ m ) use ( $ getAttribute ) { return preg_replace ( '(' . $ getAttribute . ')' , '$attributes[$1]' , $ m [ 1 ] ) ; } , '(htmlspecialchars\\(strtr\\(' . $ getAttribute . ",('[^\"&\\\\';<>aglmopqtu]+'),('[^\"&\\\\'<>]+')\\)," . ENT_COMPAT . '\\))' => 'strtr($attributes[$1],$2,$3)' , '(' . $ getAttribute . '(!?=+)' . $ getAttribute . ')' => '$attributes[$1]$2$attributes[$3]' , '(' . $ getAttribute . '===(' . $ string . '))s' => function ( $ m ) { return '$attributes[' . $ m [ 1 ] . ']===' . htmlspecialchars ( $ m [ 2 ] , ENT_COMPAT ) ; } , '((' . $ string . ')===' . $ getAttribute . ')s' => function ( $ m ) { return htmlspecialchars ( $ m [ 1 ] , ENT_COMPAT ) . '===$attributes[' . $ m [ 2 ] . ']' ; } , '(strpos\\(' . $ getAttribute . ',(' . $ string . ')\\)([!=]==(?:0|false)))s' => function ( $ m ) { return 'strpos($attributes[' . $ m [ 1 ] . "]," . htmlspecialchars ( $ m [ 2 ] , ENT_COMPAT ) . ')' . $ m [ 3 ] ; } , '(strpos\\((' . $ string . '),' . $ getAttribute . '\\)([!=]==(?:0|false)))s' => function ( $ m ) { return 'strpos(' . htmlspecialchars ( $ m [ 1 ] , ENT_COMPAT ) . ',$attributes[' . $ m [ 2 ] . '])' . $ m [ 3 ] ; } , '(' . $ getAttribute . '(?=(?:==|[-+*])\\d+))' => '$attributes[$1]' , '(\\b(\\d+(?:==|[-+*]))' . $ getAttribute . ')' => '$1$attributes[$2]' , '(empty\\(' . $ getAttribute . '\\))' => 'empty($attributes[$1])' , "(\\\$node->hasAttribute\\(('[^']+')\\))" => 'isset($attributes[$1])' , 'if($node->attributes->length)' => 'if($this->hasNonNullValues($attributes))' , '(' . $ getAttribute . ')' => 'htmlspecialchars_decode($attributes[$1])' ] ; foreach ( $ replacements as $ match => $ replace ) { if ( $ replace instanceof Closure ) { $ php = preg_replace_callback ( $ match , $ replace , $ php ) ; } elseif ( $ match [ 0 ] === '(' ) { $ php = preg_replace ( $ match , $ replace , $ php ) ; } else { $ php = str_replace ( $ match , $ replace , $ php ) ; } } } | Replace the PHP code used in a compiled template to be used by the Quick renderer |
43,838 | protected static function buildPHP ( array $ branches ) { $ return = [ '' , '' ] ; foreach ( $ branches as $ branch ) { $ return [ 0 ] .= $ branch [ 'statement' ] . '{' . $ branch [ 'head' ] ; $ return [ 1 ] .= $ branch [ 'statement' ] . '{' ; if ( $ branch [ 'branches' ] ) { list ( $ head , $ tail ) = self :: buildPHP ( $ branch [ 'branches' ] ) ; $ return [ 0 ] .= $ head ; $ return [ 1 ] .= $ tail ; } $ return [ 0 ] .= '}' ; $ return [ 1 ] .= $ branch [ 'tail' ] . '}' ; } return $ return ; } | Build the source for the two sides of a templates based on the structure extracted from its original source |
43,839 | protected static function getBranchesPassthrough ( array $ branches ) { $ values = [ ] ; foreach ( $ branches as $ branch ) { $ values [ ] = $ branch [ 'passthrough' ] ; } if ( $ branch [ 'statement' ] !== 'else' ) { $ values [ ] = 0 ; } return array_unique ( $ values ) ; } | Get the unique values for the passthrough key of given branches |
43,840 | protected static function getStringRenderings ( $ php ) { $ chunks = explode ( '$this->at($node);' , $ php ) ; if ( count ( $ chunks ) > 2 ) { return [ ] ; } $ renderings = [ ] ; foreach ( $ chunks as $ k => $ chunk ) { $ rendering = self :: getStaticRendering ( $ chunk ) ; if ( $ rendering !== false ) { $ renderings [ $ k ] = [ 'static' , $ rendering ] ; } elseif ( $ k === 0 ) { $ rendering = self :: getDynamicRendering ( $ chunk ) ; if ( $ rendering !== false ) { $ renderings [ $ k ] = [ 'dynamic' , $ rendering ] ; } } } return $ renderings ; } | Get string rendering strategies for given chunks |
43,841 | protected static function replacePlaceholder ( & $ str , $ uniqid , $ index ) { $ str = preg_replace_callback ( '(' . preg_quote ( $ uniqid ) . '(.))' , function ( $ m ) use ( $ index ) { if ( is_numeric ( $ m [ 1 ] ) ) { return '${' . $ index . '}' . $ m [ 1 ] ; } else { return '$' . $ index . $ m [ 1 ] ; } } , $ str ) ; } | Replace all instances of a uniqid with a PCRE replacement in a string |
43,842 | public static function filter ( $ attrValue , array $ map ) { foreach ( $ map as $ pair ) { if ( preg_match ( $ pair [ 0 ] , $ attrValue ) ) { return $ pair [ 1 ] ; } } return $ attrValue ; } | Filter a mapped value |
43,843 | public function addParameterByName ( $ paramName ) { if ( array_key_exists ( $ paramName , $ this -> params ) ) { throw new InvalidArgumentException ( "Parameter '" . $ paramName . "' already exists" ) ; } $ this -> params [ $ paramName ] = null ; return $ this ; } | Add a parameter by name |
43,844 | protected function autoloadJS ( ) { if ( ! is_string ( $ this -> callback ) ) { return ; } try { $ this -> js = FunctionProvider :: get ( $ this -> callback ) ; } catch ( InvalidArgumentException $ e ) { } } | Try to load the JavaScript source for this callback |
43,845 | protected function normalizeCallback ( $ callback ) { if ( is_array ( $ callback ) && is_string ( $ callback [ 0 ] ) ) { $ callback = $ callback [ 0 ] . '::' . $ callback [ 1 ] ; } if ( is_string ( $ callback ) ) { $ callback = ltrim ( $ callback , '\\' ) ; } return $ callback ; } | Normalize a callback s representation |
43,846 | protected function optimizeLooseMap ( array $ map ) { foreach ( $ map as $ k => $ v ) { if ( $ k === $ v ) { unset ( $ map [ $ k ] ) ; } } return $ map ; } | Optimize a non - strict map by removing values that are identical to their key |
43,847 | public function get ( $ name , array $ vars = [ ] ) { $ name = BBCode :: normalizeName ( $ name ) ; $ node = $ this -> xpath -> query ( '//bbcode[@name="' . $ name . '"]' ) -> item ( 0 ) ; if ( ! ( $ node instanceof DOMElement ) ) { throw new RuntimeException ( "Could not find '" . $ name . "' in repository" ) ; } $ node = $ node -> cloneNode ( true ) ; $ this -> replaceVars ( $ node , $ vars ) ; $ usage = $ this -> xpath -> evaluate ( 'string(usage)' , $ node ) ; $ template = $ this -> xpath -> evaluate ( 'string(template)' , $ node ) ; $ config = $ this -> bbcodeMonkey -> create ( $ usage , $ template ) ; if ( $ node -> hasAttribute ( 'tagName' ) ) { $ config [ 'bbcode' ] -> tagName = $ node -> getAttribute ( 'tagName' ) ; } $ this -> addRules ( $ node , $ config [ 'tag' ] ) ; return $ config ; } | Get a BBCode and its associated tag from this repository |
43,848 | protected function addRules ( DOMElement $ node , Tag $ tag ) { foreach ( $ this -> xpath -> query ( 'rules/*' , $ node ) as $ ruleNode ) { $ methodName = $ ruleNode -> nodeName ; $ args = [ ] ; if ( $ ruleNode -> textContent ) { $ args [ ] = $ ruleNode -> textContent ; } call_user_func_array ( [ $ tag -> rules , $ methodName ] , $ args ) ; } } | Add rules to given tag based on given definition |
43,849 | protected function loadRepository ( $ filepath ) { if ( ! file_exists ( $ filepath ) ) { throw $ this -> createRepositoryException ( $ filepath ) ; } $ dom = new DOMDocument ; $ dom -> preserveWhiteSpace = false ; if ( ! $ dom -> loadXML ( file_get_contents ( $ filepath ) , LIBXML_NOERROR ) ) { throw $ this -> createRepositoryException ( $ filepath ) ; } return $ dom ; } | Load a repository file into a DOMDocument |
43,850 | protected function replaceVars ( DOMElement $ node , array $ vars ) { foreach ( $ this -> xpath -> query ( './/var' , $ node ) as $ varNode ) { $ varName = $ varNode -> getAttribute ( 'name' ) ; if ( isset ( $ vars [ $ varName ] ) ) { $ varNode -> parentNode -> replaceChild ( $ this -> dom -> createTextNode ( $ vars [ $ varName ] ) , $ varNode ) ; } } } | Replace var elements in given definition |
43,851 | public function enablePass ( $ passName ) { foreach ( array_keys ( $ this -> disabledPasses , $ passName , true ) as $ k ) { unset ( $ this -> disabledPasses [ $ k ] ) ; } } | Enable a given pass |
43,852 | protected function adjustEndingPositions ( ) { if ( $ this -> closeEm && $ this -> closeStrong ) { if ( $ this -> emPos < $ this -> strongPos ) { $ this -> emEndPos += 2 ; } else { ++ $ this -> strongEndPos ; } } } | Adjust the ending position of current EM and STRONG spans |
43,853 | protected function adjustStartingPositions ( ) { if ( isset ( $ this -> emPos ) && $ this -> emPos === $ this -> strongPos ) { if ( $ this -> closeEm ) { $ this -> emPos += 2 ; } else { ++ $ this -> strongPos ; } } } | Adjust the starting position of current EM and STRONG spans |
43,854 | protected function closeSpans ( ) { if ( $ this -> closeEm ) { -- $ this -> remaining ; $ this -> parser -> addTagPair ( 'EM' , $ this -> emPos , 1 , $ this -> emEndPos , 1 ) ; $ this -> emPos = null ; } if ( $ this -> closeStrong ) { $ this -> remaining -= 2 ; $ this -> parser -> addTagPair ( 'STRONG' , $ this -> strongPos , 2 , $ this -> strongEndPos , 2 ) ; $ this -> strongPos = null ; } } | End current valid EM and STRONG spans |
43,855 | protected function parseEmphasisByCharacter ( $ character , $ regexp ) { $ pos = $ this -> text -> indexOf ( $ character ) ; if ( $ pos === false ) { return ; } foreach ( $ this -> getEmphasisByBlock ( $ regexp , $ pos ) as $ block ) { $ this -> processEmphasisBlock ( $ block ) ; } } | Parse emphasis and strong applied using given character |
43,856 | protected function getEmphasisByBlock ( $ regexp , $ pos ) { $ block = [ ] ; $ blocks = [ ] ; $ breakPos = $ this -> text -> indexOf ( "\x17" , $ pos ) ; preg_match_all ( $ regexp , $ this -> text , $ matches , PREG_OFFSET_CAPTURE , $ pos ) ; foreach ( $ matches [ 0 ] as $ m ) { $ matchPos = $ m [ 1 ] ; $ matchLen = strlen ( $ m [ 0 ] ) ; if ( $ matchPos > $ breakPos ) { $ blocks [ ] = $ block ; $ block = [ ] ; $ breakPos = $ this -> text -> indexOf ( "\x17" , $ matchPos ) ; } if ( ! $ this -> ignoreEmphasis ( $ matchPos , $ matchLen ) ) { $ block [ ] = [ $ matchPos , $ matchLen ] ; } } $ blocks [ ] = $ block ; return $ blocks ; } | Get emphasis markup split by block |
43,857 | protected function ignoreEmphasis ( $ matchPos , $ matchLen ) { return ( $ this -> text -> charAt ( $ matchPos ) === '_' && $ matchLen === 1 && $ this -> text -> isSurroundedByAlnum ( $ matchPos , $ matchLen ) ) ; } | Test whether emphasis should be ignored at the given position in the text |
43,858 | protected function openSpans ( $ pos ) { if ( $ this -> remaining & 1 ) { $ this -> emPos = $ pos - $ this -> remaining ; } if ( $ this -> remaining & 2 ) { $ this -> strongPos = $ pos - $ this -> remaining ; } } | Open EM and STRONG spans whose content starts at given position |
43,859 | protected function processEmphasisBlock ( array $ block ) { $ this -> emPos = null ; $ this -> strongPos = null ; foreach ( $ block as list ( $ matchPos , $ matchLen ) ) { $ this -> processEmphasisMatch ( $ matchPos , $ matchLen ) ; } } | Process a list of emphasis markup strings |
43,860 | protected function processEmphasisMatch ( $ matchPos , $ matchLen ) { $ canOpen = ! $ this -> text -> isBeforeWhitespace ( $ matchPos + $ matchLen - 1 ) ; $ canClose = ! $ this -> text -> isAfterWhitespace ( $ matchPos ) ; $ closeLen = ( $ canClose ) ? min ( $ matchLen , 3 ) : 0 ; $ this -> closeEm = ( $ closeLen & 1 ) && isset ( $ this -> emPos ) ; $ this -> closeStrong = ( $ closeLen & 2 ) && isset ( $ this -> strongPos ) ; $ this -> emEndPos = $ matchPos ; $ this -> strongEndPos = $ matchPos ; $ this -> remaining = $ matchLen ; $ this -> adjustStartingPositions ( ) ; $ this -> adjustEndingPositions ( ) ; $ this -> closeSpans ( ) ; $ this -> remaining = ( $ canOpen ) ? min ( $ this -> remaining , 3 ) : 0 ; $ this -> openSpans ( $ matchPos + $ matchLen ) ; } | Process an emphasis mark |
43,861 | protected function normalizeScrape ( $ value ) { if ( ! empty ( $ value ) && ! isset ( $ value [ 0 ] ) ) { $ value = [ $ value ] ; } foreach ( $ value as & $ scrape ) { $ scrape += [ 'extract' => [ ] , 'match' => '//' ] ; $ scrape [ 'extract' ] = $ this -> normalizeRegexp ( $ scrape [ 'extract' ] ) ; $ scrape [ 'match' ] = $ this -> normalizeRegexp ( $ scrape [ 'match' ] ) ; } unset ( $ scrape ) ; return $ value ; } | Normalize the scrape value |
43,862 | public function setNestingLimit ( $ limit ) { $ limit = ( int ) $ limit ; if ( $ limit < 1 ) { throw new InvalidArgumentException ( 'nestingLimit must be a number greater than 0' ) ; } $ this -> nestingLimit = $ limit ; } | Set this tag s nestingLimit |
43,863 | public function setTagLimit ( $ limit ) { $ limit = ( int ) $ limit ; if ( $ limit < 1 ) { throw new InvalidArgumentException ( 'tagLimit must be a number greater than 0' ) ; } $ this -> tagLimit = $ limit ; } | Set this tag s tagLimit |
43,864 | public function setTemplate ( $ template ) { if ( ! ( $ template instanceof Template ) ) { $ template = new Template ( $ template ) ; } $ this -> template = $ template ; } | Set the template associated with this tag |
43,865 | public function normalizeTag ( Tag $ tag ) { if ( isset ( $ tag -> template ) && ! $ tag -> template -> isNormalized ( ) ) { $ tag -> template -> normalize ( $ this ) ; } } | Normalize a tag s template |
43,866 | public function normalizeTemplate ( $ template ) { $ dom = TemplateLoader :: load ( $ template ) ; $ i = 0 ; do { $ old = $ template ; foreach ( $ this -> collection as $ k => $ normalization ) { $ normalization -> normalize ( $ dom -> documentElement ) ; } $ template = TemplateLoader :: save ( $ dom ) ; } while ( ++ $ i < $ this -> maxIterations && $ template !== $ old ) ; return $ template ; } | Normalize a template |
43,867 | protected function adoptChildren ( DOMElement $ branch ) { while ( $ branch -> firstChild -> firstChild ) { $ branch -> appendChild ( $ branch -> firstChild -> removeChild ( $ branch -> firstChild -> firstChild ) ) ; } $ branch -> removeChild ( $ branch -> firstChild ) ; } | Adopt the children of given element s only child |
43,868 | protected function parseInlineImages ( ) { preg_match_all ( '/!\\[(?:[^\\x17[\\]]|\\[[^\\x17[\\]]*\\])*\\]\\(( *(?:[^\\x17\\s()]|\\([^\\x17\\s()]*\\))*(?=[ )]) *(?:"[^\\x17]*?"|\'[^\\x17]*?\'|\\([^\\x17)]*\\))? *)\\)/' , $ this -> text , $ matches , PREG_OFFSET_CAPTURE | PREG_SET_ORDER ) ; foreach ( $ matches as $ m ) { $ linkInfo = $ m [ 1 ] [ 0 ] ; $ startPos = $ m [ 0 ] [ 1 ] ; $ endLen = 3 + strlen ( $ linkInfo ) ; $ endPos = $ startPos + strlen ( $ m [ 0 ] [ 0 ] ) - $ endLen ; $ alt = substr ( $ m [ 0 ] [ 0 ] , 2 , strlen ( $ m [ 0 ] [ 0 ] ) - $ endLen - 2 ) ; $ this -> addImageTag ( $ startPos , $ endPos , $ endLen , $ linkInfo , $ alt ) ; } } | Parse inline images markup |
43,869 | protected function parseReferenceImages ( ) { preg_match_all ( '/!\\[((?:[^\\x17[\\]]|\\[[^\\x17[\\]]*\\])*)\\](?: ?\\[([^\\x17[\\]]+)\\])?/' , $ this -> text , $ matches , PREG_OFFSET_CAPTURE | PREG_SET_ORDER ) ; foreach ( $ matches as $ m ) { $ startPos = $ m [ 0 ] [ 1 ] ; $ endPos = $ startPos + 2 + strlen ( $ m [ 1 ] [ 0 ] ) ; $ endLen = 1 ; $ alt = $ m [ 1 ] [ 0 ] ; $ id = $ alt ; if ( isset ( $ m [ 2 ] [ 0 ] , $ this -> text -> linkReferences [ $ m [ 2 ] [ 0 ] ] ) ) { $ endLen = strlen ( $ m [ 0 ] [ 0 ] ) - strlen ( $ alt ) - 2 ; $ id = $ m [ 2 ] [ 0 ] ; } elseif ( ! isset ( $ this -> text -> linkReferences [ $ id ] ) ) { continue ; } $ this -> addImageTag ( $ startPos , $ endPos , $ endLen , $ this -> text -> linkReferences [ $ id ] , $ alt ) ; } } | Parse reference images markup |
43,870 | protected function uninlineDynamicAttribute ( DOMAttr $ attribute ) { $ xslAttribute = $ this -> createElement ( 'xsl:attribute' ) ; foreach ( AVTHelper :: parse ( $ attribute -> value ) as list ( $ type , $ content ) ) { if ( $ type === 'expression' ) { $ childNode = $ this -> createElement ( 'xsl:value-of' ) ; $ childNode -> setAttribute ( 'select' , $ content ) ; } else { $ childNode = $ this -> createText ( $ content ) ; } $ xslAttribute -> appendChild ( $ childNode ) ; } return $ xslAttribute ; } | Uninline an AVT - style attribute |
43,871 | public static function filterRange ( $ attrValue , $ min , $ max , Logger $ logger = null ) { $ attrValue = filter_var ( $ attrValue , FILTER_VALIDATE_INT ) ; if ( $ attrValue === false ) { return false ; } if ( $ attrValue < $ min ) { if ( isset ( $ logger ) ) { $ logger -> warn ( 'Value outside of range, adjusted up to min value' , [ 'attrValue' => $ attrValue , 'min' => $ min , 'max' => $ max ] ) ; } return $ min ; } if ( $ attrValue > $ max ) { if ( isset ( $ logger ) ) { $ logger -> warn ( 'Value outside of range, adjusted down to max value' , [ 'attrValue' => $ attrValue , 'min' => $ min , 'max' => $ max ] ) ; } return $ max ; } return $ attrValue ; } | Filter a range value |
43,872 | protected function getHandle ( ) { if ( ! isset ( self :: $ handle ) ) { self :: $ handle = $ this -> getNewHandle ( ) ; } curl_setopt ( self :: $ handle , CURLOPT_SSL_VERIFYPEER , $ this -> sslVerifyPeer ) ; curl_setopt ( self :: $ handle , CURLOPT_TIMEOUT , $ this -> timeout ) ; return self :: $ handle ; } | Return a globally cached cURL handle configured for current instance |
43,873 | protected function getNewHandle ( ) { $ handle = curl_init ( ) ; curl_setopt ( $ handle , CURLOPT_ENCODING , '' ) ; curl_setopt ( $ handle , CURLOPT_FAILONERROR , true ) ; curl_setopt ( $ handle , CURLOPT_FOLLOWLOCATION , true ) ; curl_setopt ( $ handle , CURLOPT_RETURNTRANSFER , true ) ; return $ handle ; } | Create and return a new cURL handle |
43,874 | protected function parseShortForm ( $ pos ) { preg_match_all ( $ this -> shortRegexp , $ this -> text , $ matches , PREG_OFFSET_CAPTURE , $ pos ) ; foreach ( $ matches [ 0 ] as list ( $ match , $ matchPos ) ) { $ matchLen = strlen ( $ match ) ; $ startPos = $ matchPos ; $ endLen = ( substr ( $ match , - 1 ) === $ this -> syntaxChar ) ? 1 : 0 ; $ endPos = $ matchPos + $ matchLen - $ endLen ; $ this -> parser -> addTagPair ( $ this -> tagName , $ startPos , 1 , $ endPos , $ endLen ) ; } } | Parse the short form x^x and x^x^ |
43,875 | protected function addLine ( $ line ) { $ ignoreLen = 0 ; if ( ! isset ( $ this -> table ) ) { $ this -> table = [ ] ; preg_match ( '/^ */' , $ line , $ m ) ; $ ignoreLen = strlen ( $ m [ 0 ] ) ; $ line = substr ( $ line , $ ignoreLen ) ; } $ line = preg_replace ( '/^( *)\\|/' , '$1 ' , $ line ) ; $ line = preg_replace ( '/\\|( *)$/' , ' $1' , $ line ) ; $ this -> table [ 'rows' ] [ ] = [ 'line' => $ line , 'pos' => $ this -> pos + $ ignoreLen ] ; } | Add current line to a table |
43,876 | protected function addTableBody ( ) { $ i = 1 ; $ cnt = count ( $ this -> table [ 'rows' ] ) ; while ( ++ $ i < $ cnt ) { $ this -> addTableRow ( 'TD' , $ this -> table [ 'rows' ] [ $ i ] ) ; } $ this -> createBodyTags ( $ this -> table [ 'rows' ] [ 2 ] [ 'pos' ] , $ this -> pos ) ; } | Process current table s body |
43,877 | protected function addTableCell ( $ tagName , $ align , $ text ) { $ startPos = $ this -> pos ; $ endPos = $ startPos + strlen ( $ text ) ; $ this -> pos = $ endPos ; preg_match ( '/^( *).*?( *)$/' , $ text , $ m ) ; if ( $ m [ 1 ] ) { $ ignoreLen = strlen ( $ m [ 1 ] ) ; $ this -> createIgnoreTag ( $ startPos , $ ignoreLen ) ; $ startPos += $ ignoreLen ; } if ( $ m [ 2 ] ) { $ ignoreLen = strlen ( $ m [ 2 ] ) ; $ this -> createIgnoreTag ( $ endPos - $ ignoreLen , $ ignoreLen ) ; $ endPos -= $ ignoreLen ; } $ this -> createCellTags ( $ tagName , $ startPos , $ endPos , $ align ) ; } | Add a cell s tags for current table at current position |
43,878 | protected function addTableHead ( ) { $ this -> addTableRow ( 'TH' , $ this -> table [ 'rows' ] [ 0 ] ) ; $ this -> createHeadTags ( $ this -> table [ 'rows' ] [ 0 ] [ 'pos' ] , $ this -> pos ) ; } | Process current table s head |
43,879 | protected function addTableRow ( $ tagName , $ row ) { $ this -> pos = $ row [ 'pos' ] ; foreach ( explode ( '|' , $ row [ 'line' ] ) as $ i => $ str ) { if ( $ i > 0 ) { $ this -> createIgnoreTag ( $ this -> pos , 1 ) ; ++ $ this -> pos ; } $ align = ( empty ( $ this -> table [ 'cols' ] [ $ i ] ) ) ? '' : $ this -> table [ 'cols' ] [ $ i ] ; $ this -> addTableCell ( $ tagName , $ align , $ str ) ; } $ this -> createRowTags ( $ row [ 'pos' ] , $ this -> pos ) ; } | Process given table row |
43,880 | protected function captureTables ( ) { unset ( $ this -> table ) ; $ this -> tables = [ ] ; $ this -> pos = 0 ; foreach ( explode ( "\n" , $ this -> text ) as $ line ) { if ( strpos ( $ line , '|' ) === false ) { $ this -> endTable ( ) ; } else { $ this -> addLine ( $ line ) ; } $ this -> pos += 1 + strlen ( $ line ) ; } $ this -> endTable ( ) ; } | Capture all pipe tables in current text |
43,881 | protected function createCellTags ( $ tagName , $ startPos , $ endPos , $ align ) { if ( $ startPos === $ endPos ) { $ tag = $ this -> parser -> addSelfClosingTag ( $ tagName , $ startPos , 0 , - 101 ) ; } else { $ tag = $ this -> parser -> addTagPair ( $ tagName , $ startPos , 0 , $ endPos , 0 , - 101 ) ; } if ( $ align ) { $ tag -> setAttribute ( 'align' , $ align ) ; } } | Create a pair of TD or TH tags for given text span |
43,882 | protected function createIgnoreTag ( $ pos , $ len ) { $ this -> tableTag -> cascadeInvalidationTo ( $ this -> parser -> addIgnoreTag ( $ pos , $ len , 1000 ) ) ; } | Create an ignore tag for given text span |
43,883 | protected function createTableTags ( $ startPos , $ endPos ) { $ this -> tableTag = $ this -> parser -> addTagPair ( 'TABLE' , $ startPos , 0 , $ endPos , 0 , - 104 ) ; } | Create a pair of TABLE tags for given text span |
43,884 | protected function endTable ( ) { if ( $ this -> hasValidTable ( ) ) { $ this -> table [ 'cols' ] = $ this -> parseColumnAlignments ( $ this -> table [ 'rows' ] [ 1 ] [ 'line' ] ) ; $ this -> tables [ ] = $ this -> table ; } unset ( $ this -> table ) ; } | End current buffered table |
43,885 | protected function hasValidTable ( ) { return ( isset ( $ this -> table ) && count ( $ this -> table [ 'rows' ] ) > 2 && $ this -> isValidSeparator ( $ this -> table [ 'rows' ] [ 1 ] [ 'line' ] ) ) ; } | Test whether a valid table is currently buffered |
43,886 | protected function overwriteEscapes ( ) { if ( strpos ( $ this -> text , '\\|' ) !== false ) { $ this -> text = preg_replace ( '/\\\\[\\\\|]/' , '..' , $ this -> text ) ; } } | Overwrite escape sequences in current text |
43,887 | protected function overwriteMarkdown ( ) { if ( strpos ( $ this -> text , '`' ) !== false ) { $ this -> text = preg_replace_callback ( '/`[^`]*`/' , [ $ this , 'overwriteInlineCodeCallback' ] , $ this -> text ) ; } if ( strpos ( $ this -> text , '>' ) !== false ) { $ this -> text = preg_replace_callback ( '/^(?:> ?)+/m' , [ $ this , 'overwriteBlockquoteCallback' ] , $ this -> text ) ; } } | Overwrite Markdown - style markup in current text |
43,888 | protected function parseColumnAlignments ( $ line ) { $ align = [ 0b00 => '' , 0b01 => 'right' , 0b10 => 'left' , 0b11 => 'center' ] ; $ cols = [ ] ; preg_match_all ( '/(:?)-+(:?)/' , $ line , $ matches , PREG_SET_ORDER ) ; foreach ( $ matches as $ m ) { $ key = ( ! empty ( $ m [ 1 ] ) ? 2 : 0 ) + ( ! empty ( $ m [ 2 ] ) ? 1 : 0 ) ; $ cols [ ] = $ align [ $ key ] ; } return $ cols ; } | Parse and return column alignments in given separator line |
43,889 | protected function processCurrentTable ( ) { $ firstRow = $ this -> table [ 'rows' ] [ 0 ] ; $ lastRow = end ( $ this -> table [ 'rows' ] ) ; $ this -> createTableTags ( $ firstRow [ 'pos' ] , $ lastRow [ 'pos' ] + strlen ( $ lastRow [ 'line' ] ) ) ; $ this -> addTableHead ( ) ; $ this -> createSeparatorTag ( $ this -> table [ 'rows' ] [ 1 ] ) ; $ this -> addTableBody ( ) ; } | Process current table declaration |
43,890 | protected function processTables ( ) { foreach ( $ this -> tables as $ table ) { $ this -> table = $ table ; $ this -> processCurrentTable ( ) ; } } | Process all the captured tables |
43,891 | protected function getAliasesConfig ( ) { $ config = [ ] ; $ custom = $ this -> getCustomAliases ( ) ; if ( ! empty ( $ custom ) ) { $ regexp = '/' . RegexpBuilder :: fromList ( $ custom ) . '/' ; $ config [ 'customRegexp' ] = new Regexp ( $ regexp , true ) ; $ quickMatch = ConfigHelper :: generateQuickMatchFromList ( $ custom ) ; if ( $ quickMatch !== false ) { $ config [ 'customQuickMatch' ] = $ quickMatch ; } } return $ config ; } | Generate the config options related to aliases |
43,892 | public static function filter ( $ attrValue ) { if ( preg_match ( '/^(?=\\d)(?:(\\d+)h)?(?:(\\d+)m)?(?:(\\d+)s)?$/D' , $ attrValue , $ m ) ) { $ m += [ 0 , 0 , 0 , 0 ] ; return intval ( $ m [ 1 ] ) * 3600 + intval ( $ m [ 2 ] ) * 60 + intval ( $ m [ 3 ] ) ; } return NumericFilter :: filterUint ( $ attrValue ) ; } | Filter a timestamp value |
43,893 | protected function reset ( $ text ) { if ( ! preg_match ( '//u' , $ text ) ) { throw new InvalidArgumentException ( 'Invalid UTF-8 input' ) ; } $ text = preg_replace ( '/\\r\\n?/' , "\n" , $ text ) ; $ text = preg_replace ( '/[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F]+/S' , '' , $ text ) ; $ this -> logger -> clear ( ) ; $ this -> cntOpen = [ ] ; $ this -> cntTotal = [ ] ; $ this -> currentFixingCost = 0 ; $ this -> currentTag = null ; $ this -> isRich = false ; $ this -> namespaces = [ ] ; $ this -> openTags = [ ] ; $ this -> output = '' ; $ this -> pos = 0 ; $ this -> tagStack = [ ] ; $ this -> tagStackIsSorted = false ; $ this -> text = $ text ; $ this -> textLen = strlen ( $ text ) ; $ this -> wsPos = 0 ; $ this -> context = $ this -> rootContext ; $ this -> context [ 'inParagraph' ] = false ; ++ $ this -> uid ; } | Reset the parser for a new parsing |
43,894 | protected function setTagOption ( $ tagName , $ optionName , $ optionValue ) { if ( isset ( $ this -> tagsConfig [ $ tagName ] ) ) { $ tagConfig = $ this -> tagsConfig [ $ tagName ] ; unset ( $ this -> tagsConfig [ $ tagName ] ) ; $ tagConfig [ $ optionName ] = $ optionValue ; $ this -> tagsConfig [ $ tagName ] = $ tagConfig ; } } | Set a tag s option |
43,895 | public function parse ( $ text ) { $ this -> reset ( $ text ) ; $ uid = $ this -> uid ; $ this -> executePluginParsers ( ) ; $ this -> processTags ( ) ; $ this -> finalizeOutput ( ) ; if ( $ this -> uid !== $ uid ) { throw new RuntimeException ( 'The parser has been reset during execution' ) ; } if ( $ this -> currentFixingCost > $ this -> maxFixingCost ) { $ this -> logger -> warn ( 'Fixing cost limit exceeded' ) ; } return $ this -> output ; } | Parse a text |
43,896 | protected function finalizeOutput ( ) { $ this -> outputText ( $ this -> textLen , 0 , true ) ; do { $ this -> output = preg_replace ( '(<([^ />]++)[^>]*></\\1>)' , '' , $ this -> output , - 1 , $ cnt ) ; } while ( $ cnt > 0 ) ; if ( strpos ( $ this -> output , '</i><i>' ) !== false ) { $ this -> output = str_replace ( '</i><i>' , '' , $ this -> output ) ; } $ this -> output = preg_replace ( '([\\x00-\\x08\\x0B-\\x1F])' , '' , $ this -> output ) ; $ this -> output = Utils :: encodeUnicodeSupplementaryCharacters ( $ this -> output ) ; $ tagName = ( $ this -> isRich ) ? 'r' : 't' ; $ tmp = '<' . $ tagName ; foreach ( array_keys ( $ this -> namespaces ) as $ prefix ) { $ tmp .= ' xmlns:' . $ prefix . '="urn:s9e:TextFormatter:' . $ prefix . '"' ; } $ this -> output = $ tmp . '>' . $ this -> output . '</' . $ tagName . '>' ; } | Finalize the output by appending the rest of the unprocessed text and create the root node |
43,897 | protected function outputTag ( Tag $ tag ) { $ this -> isRich = true ; $ tagName = $ tag -> getName ( ) ; $ tagPos = $ tag -> getPos ( ) ; $ tagLen = $ tag -> getLen ( ) ; $ tagFlags = $ tag -> getFlags ( ) ; if ( $ tagFlags & self :: RULE_IGNORE_WHITESPACE ) { $ skipBefore = 1 ; $ skipAfter = ( $ tag -> isEndTag ( ) ) ? 2 : 1 ; } else { $ skipBefore = $ skipAfter = 0 ; } $ closeParagraph = false ; if ( $ tag -> isStartTag ( ) ) { if ( $ tagFlags & self :: RULE_BREAK_PARAGRAPH ) { $ closeParagraph = true ; } } else { $ closeParagraph = true ; } $ this -> outputText ( $ tagPos , $ skipBefore , $ closeParagraph ) ; $ tagText = ( $ tagLen ) ? htmlspecialchars ( substr ( $ this -> text , $ tagPos , $ tagLen ) , ENT_NOQUOTES , 'UTF-8' ) : '' ; if ( $ tag -> isStartTag ( ) ) { if ( ! ( $ tagFlags & self :: RULE_BREAK_PARAGRAPH ) ) { $ this -> outputParagraphStart ( $ tagPos ) ; } $ colonPos = strpos ( $ tagName , ':' ) ; if ( $ colonPos ) { $ this -> namespaces [ substr ( $ tagName , 0 , $ colonPos ) ] = 0 ; } $ this -> output .= '<' . $ tagName ; $ attributes = $ tag -> getAttributes ( ) ; ksort ( $ attributes ) ; foreach ( $ attributes as $ attrName => $ attrValue ) { $ this -> output .= ' ' . $ attrName . '="' . str_replace ( "\n" , ' ' , htmlspecialchars ( $ attrValue , ENT_COMPAT , 'UTF-8' ) ) . '"' ; } if ( $ tag -> isSelfClosingTag ( ) ) { if ( $ tagLen ) { $ this -> output .= '>' . $ tagText . '</' . $ tagName . '>' ; } else { $ this -> output .= '/>' ; } } elseif ( $ tagLen ) { $ this -> output .= '><s>' . $ tagText . '</s>' ; } else { $ this -> output .= '>' ; } } else { if ( $ tagLen ) { $ this -> output .= '<e>' . $ tagText . '</e>' ; } $ this -> output .= '</' . $ tagName . '>' ; } $ this -> pos = $ tagPos + $ tagLen ; $ this -> wsPos = $ this -> pos ; while ( $ skipAfter && $ this -> wsPos < $ this -> textLen && $ this -> text [ $ this -> wsPos ] === "\n" ) { -- $ skipAfter ; ++ $ this -> wsPos ; } } | Append a tag to the output |
43,898 | protected function outputBrTag ( Tag $ tag ) { $ this -> outputText ( $ tag -> getPos ( ) , 0 , false ) ; $ this -> output .= '<br/>' ; } | Output a linebreak tag |
43,899 | protected function outputIgnoreTag ( Tag $ tag ) { $ tagPos = $ tag -> getPos ( ) ; $ tagLen = $ tag -> getLen ( ) ; $ ignoreText = substr ( $ this -> text , $ tagPos , $ tagLen ) ; $ this -> outputText ( $ tagPos , 0 , false ) ; $ this -> output .= '<i>' . htmlspecialchars ( $ ignoreText , ENT_NOQUOTES , 'UTF-8' ) . '</i>' ; $ this -> isRich = true ; $ this -> pos = $ tagPos + $ tagLen ; } | Output an ignore tag |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.