idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
56,100
public function registerFromUrl ( $ id , $ url , array $ context = [ ] ) { $ response = $ this -> parser -> getRemoteFile ( $ url , $ context ) ; if ( $ response && ( $ dom = $ this -> parser -> parseFromString ( $ response ) ) ) { $ this -> doms [ $ id ] = $ dom ; } return false ; }
Get remote file
56,101
public function addCover ( $ src , $ dest = '' , $ id = 'cover' ) { if ( file_exists ( $ src ) ) { if ( ! $ dest ) { $ dest = 'Image' . DIRECTORY_SEPARATOR . basename ( $ src ) ; } $ this -> distributor -> copy ( $ src , 'OEBPS' . DIRECTORY_SEPARATOR . $ dest ) ; $ this -> opf -> addItem ( $ dest , $ id , [ 'cover-image' ] ) ; $ this -> opf -> addMeta ( 'meta' , '' , [ 'name' => 'cover' , 'content' => $ id ] ) ; } }
Add Cover image
56,102
protected function _callQuery ( $ query ) { $ query -> contain ( $ this -> type [ 'contain' ] ) ; $ extQuery = $ this -> type [ 'query' ] ; return $ extQuery ( $ query ) ; }
Uses the query - callable from the PostType .
56,103
protected function _loadAssociations ( ) { foreach ( $ this -> Model -> associations ( ) -> getIterator ( ) as $ association => $ assocData ) { $ this -> set ( Inflector :: variable ( $ assocData -> alias ( ) ) , $ this -> Model -> { $ association } -> find ( 'list' ) -> toArray ( ) ) ; } }
Dynamically loads all associations of the model .
56,104
protected function _actionIsEnabled ( $ action ) { $ actions = $ this -> type [ 'actions' ] ; if ( array_key_exists ( $ action , $ actions ) ) { return $ actions [ $ action ] ; } return true ; }
Checks if the action is enabled .
56,105
protected function _event ( $ action , $ data = [ ] ) { $ _event = new Event ( 'Controller.PostTypes.' . $ this -> type [ 'name' ] . '.' . $ action , $ this , $ data ) ; $ this -> eventManager ( ) -> dispatch ( $ _event ) ; }
Fires an event with the PostType - prefix .
56,106
public static function formatError ( $ message , $ errorValues ) { foreach ( $ errorValues as $ token => $ value ) { $ message = preg_replace ( "/\%$token\%/" , $ value , $ message ) ; } return $ message ; }
Replaces placeholder tokens in an error message with actual values .
56,107
private function _validateIndicator ( $ indicator ) { if ( $ indicator == null ) { $ indicator = ' ' ; } elseif ( strlen ( $ indicator ) > 1 ) { $ errorMessage = File_MARC_Exception :: formatError ( File_MARC_Exception :: $ messages [ File_MARC_Exception :: ERROR_INVALID_INDICATOR ] , array ( "tag" => $ this -> getTag ( ) , "indicator" => $ indicator ) ) ; throw new File_MARC_Exception ( $ errorMessage , File_MARC_Exception :: ERROR_INVALID_INDICATOR ) ; } return $ indicator ; }
Validates an indicator field
56,108
function getIndicator ( $ ind ) { if ( $ ind == 1 ) { return ( string ) $ this -> ind1 ; } elseif ( $ ind == 2 ) { return ( string ) $ this -> ind2 ; } else { $ errorMessage = File_MARC_Exception :: formatError ( File_MARC_Exception :: $ messages [ File_MARC_Exception :: ERROR_INVALID_INDICATOR_REQUEST ] , array ( "indicator" => $ indicator ) ) ; throw new File_MARC_Exception ( $ errorMessage , File_MARC_Exception :: ERROR_INVALID_INDICATOR_REQUEST ) ; } return false ; }
Get the value of an indicator
56,109
function setIndicator ( $ ind , $ value ) { switch ( $ ind ) { case 1 : $ this -> ind1 = $ this -> _validateIndicator ( $ value ) ; break ; case 2 : $ this -> ind2 = $ this -> _validateIndicator ( $ value ) ; break ; default : $ errorMessage = File_MARC_Exception :: formatError ( File_MARC_Exception :: $ messages [ File_MARC_Exception :: ERROR_INVALID_INDICATOR_REQUEST ] , array ( "indicator" => $ ind ) ) ; throw new File_MARC_Exception ( $ errorMessage , File_MARC_Exception :: ERROR_INVALID_INDICATOR_REQUEST ) ; return false ; } return $ this -> getIndicator ( $ ind ) ; }
Set the value of an indicator
56,110
function getSubfield ( $ code = null , $ pcre = null ) { foreach ( $ this -> subfields as $ sf ) { if ( ( $ pcre && preg_match ( "/$code/" , $ sf -> getCode ( ) ) ) || ( ! $ pcre && $ code == $ sf -> getCode ( ) ) ) { return $ sf ; } } return false ; }
Returns the first subfield that matches a requested code .
56,111
function isEmpty ( ) { if ( ! $ this -> subfields ) { return true ; } foreach ( $ this -> subfields as $ subfield ) { if ( ! $ subfield -> isEmpty ( ) ) { return false ; } } return true ; }
Checks if the field is empty .
56,112
function toRaw ( ) { $ subfields = array ( ) ; foreach ( $ this -> subfields as $ subfield ) { if ( ! $ subfield -> isEmpty ( ) ) { $ subfields [ ] = $ subfield -> toRaw ( ) ; } } return ( string ) $ this -> ind1 . $ this -> ind2 . implode ( "" , $ subfields ) . File_MARC :: END_OF_FIELD ; }
Return Field in Raw MARC
56,113
function getContents ( $ joinChar = '' ) { $ contents = array ( ) ; foreach ( $ this -> subfields as $ subfield ) { $ contents [ ] = $ subfield -> getData ( ) ; } return implode ( $ joinChar , $ contents ) ; }
Return fields data content as joined string
56,114
private function _decode ( $ text ) { $ marc = new $ this -> record_class ( $ this ) ; $ marc -> setLeader ( $ text -> leader ) ; foreach ( $ text -> fields as $ field ) { foreach ( $ field as $ tag => $ values ) { if ( strpos ( $ tag , '00' ) === 0 ) { $ marc -> appendField ( new File_MARC_Control_Field ( $ tag , $ values ) ) ; } else { $ subfield_data = array ( ) ; foreach ( $ values -> subfields as $ subfield ) { foreach ( $ subfield as $ sf_code => $ sf_value ) { $ subfield_data [ ] = new File_MARC_Subfield ( $ sf_code , $ sf_value ) ; } } try { $ new_field = new File_MARC_Data_Field ( $ tag , $ subfield_data , $ values -> ind1 , $ values -> ind2 ) ; $ marc -> appendField ( $ new_field ) ; } catch ( Exception $ e ) { $ marc -> addWarning ( $ e -> getMessage ( ) ) ; } } } } return $ marc ; }
Decode a given MARC - in - JSON record
56,115
protected function printDbBuildVersion ( OutputInterface $ output ) : void { $ output -> writeln ( sprintf ( '<info>Reference Database Version</info> => %s%s' , $ this -> getApplication ( ) -> getDbVersions ( ) [ 'build.version' ] , PHP_EOL ) ) ; }
Prints the database current build version
56,116
protected function tableHelper ( OutputInterface $ output , array $ headers , array $ rows , string $ style = 'compact' ) : void { $ table = new Table ( $ output ) ; $ table -> setStyle ( $ style ) -> setHeaders ( $ headers ) -> setRows ( $ rows ) -> render ( ) ; }
Helper that convert analyser results to a console table
56,117
public function execute ( OperationInterface $ op ) { try { if ( $ op instanceof DeleteOperationInterface ) { $ response = $ this -> httpClient -> delete ( $ op -> getEndpoint ( ) , [ 'headers' => $ op -> getHeaders ( ) , ] ) ; } elseif ( $ op instanceof PostOperationInterface ) { $ response = $ this -> httpClient -> post ( $ op -> getEndpoint ( ) , [ 'headers' => $ op -> getHeaders ( ) , 'body' => $ op -> getData ( ) , ] ) ; } elseif ( $ op instanceof PatchOperationInterface ) { $ response = $ this -> httpClient -> patch ( $ op -> getEndpoint ( ) , [ 'headers' => $ op -> getHeaders ( ) , 'body' => $ op -> getData ( ) , ] ) ; } elseif ( $ op instanceof PutOperationInterface ) { $ response = $ this -> httpClient -> put ( $ op -> getEndpoint ( ) , [ 'headers' => $ op -> getHeaders ( ) , 'body' => $ op -> getData ( ) , ] ) ; } else { $ response = $ this -> httpClient -> get ( $ op -> getEndpoint ( ) ) ; } } catch ( GuzzleHttp \ Exception \ ClientException $ e ) { throw new Exception \ ClientException ( 'ClientException occurred in request to Orchestrate: ' . $ e -> getMessage ( ) , $ e -> getCode ( ) , $ e ) ; } catch ( GuzzleHttp \ Exception \ ServerException $ e ) { throw new Exception \ ServerException ( 'ServerException occurred in request to Orchestrate: ' . $ e -> getMessage ( ) , $ e -> getCode ( ) , $ e ) ; } $ refLink = null ; $ location = null ; if ( $ response -> hasHeader ( 'ETag' ) ) { $ refLink = str_replace ( '"' , '' , $ response -> getHeaderLine ( 'ETag' ) ) ; } elseif ( $ response -> hasHeader ( 'Link' ) ) { $ refLink = str_replace ( [ '<' , '>; rel="next"' ] , [ '' , '' ] , $ response -> getHeaderLine ( 'Link' ) ) ; } if ( $ response -> hasHeader ( 'Location' ) ) { $ location = $ response -> getHeaderLine ( 'Location' ) ; } $ rawValue = $ response -> getBody ( true ) ; $ value = json_decode ( $ rawValue , true ) ; return $ op -> getObjectFromResponse ( $ refLink , $ location , $ value , $ rawValue ) ; }
Execute an operaction
56,118
protected function setCookie ( $ value , array $ params ) { if ( headers_sent ( ) ) { throw new TokenStorageException ( 'Cannot store CSRF token, headers already sent' ) ; } return setcookie ( $ params [ 'name' ] , $ value , $ params [ 'expire' ] , $ params [ 'path' ] , $ params [ 'domain' ] , $ params [ 'secure' ] , $ params [ 'httpOnly' ] ) ; }
Sets the cookie that stores the secret CSRF token .
56,119
protected function _generateTableColumns ( $ model ) { $ model = TableRegistry :: get ( $ model ) ; $ columns = ConnectionManager :: get ( 'default' ) -> schemaCollection ( ) -> describe ( $ model -> table ( ) ) -> columns ( ) ; $ result = [ ] ; $ counter = 0 ; $ max = 2 ; if ( in_array ( 'id' , $ columns ) ) { $ result [ 'id' ] = [ ] ; unset ( $ columns [ 'id' ] ) ; } foreach ( $ columns as $ column ) { if ( $ counter < $ max ) { $ result [ $ column ] = [ ] ; unset ( $ columns [ $ column ] ) ; $ counter ++ ; } } if ( in_array ( 'created' , $ columns ) ) { $ result [ 'created' ] = [ ] ; } return $ result ; }
If no tablecolumns are given this method will be called to generate a list of tablecolumns .
56,120
protected function _generateFormFields ( $ model ) { $ model = TableRegistry :: get ( $ model ) ; $ columns = ConnectionManager :: get ( 'default' ) -> schemaCollection ( ) -> describe ( $ model -> table ( ) ) -> columns ( ) ; $ ignoredFields = [ 'created' , 'modified' , 'created_by' , 'modified_by' , 'password' ] ; $ result = [ ] ; foreach ( $ columns as $ column ) { if ( ! in_array ( $ column , $ ignoredFields ) ) { $ result [ $ column ] = [ ] ; } } return $ result ; }
If no formfields are given this method will be called to generate a list of formfields .
56,121
protected function _normalizeFormFields ( $ fields ) { $ _options = [ 'on' => 'both' ] ; $ _defaults = [ '_create' => $ _options ] ; $ result = [ ] ; $ result [ '_create' ] = $ _defaults [ '_create' ] ; foreach ( $ fields as $ name => $ options ) { if ( is_array ( $ options ) ) { $ result [ $ name ] = array_merge ( $ _options , $ options ) ; } else { $ result [ $ options ] = $ _options ; } } return $ result ; }
Normalizes the formfields - array .
56,122
protected function _normalizeTableColumns ( $ columns ) { $ _defaults = [ 'get' => false , 'before' => '' , 'after' => '' , ] ; $ result = [ ] ; foreach ( $ columns as $ name => $ options ) { if ( is_array ( $ options ) ) { $ _defaults [ 'get' ] = $ name ; $ result [ $ name ] = array_merge ( $ _defaults , $ options ) ; } else { $ _defaults [ 'get' ] = $ options ; $ result [ $ options ] = $ _defaults ; } } return $ result ; }
Normalizes the tablecolumns - array .
56,123
public function checkRecord ( $ marc ) { $ this -> warnings = array ( ) ; if ( ! is_a ( $ marc , 'File_MARC_Record' ) ) { $ this -> warn ( 'Must pass a File_MARC_Record object to checkRecord' ) ; } else { $ this -> checkDuplicate1xx ( $ marc ) ; $ this -> checkMissing245 ( $ marc ) ; $ this -> standardFieldChecks ( $ marc ) ; } return $ this -> warnings ; }
Check the provided MARC record and return an array of warning messages .
56,124
protected function checkDuplicate1xx ( $ marc ) { $ result = $ marc -> getFields ( '1[0-9][0-9]' , true ) ; $ count = count ( $ result ) ; if ( $ count > 1 ) { $ this -> warn ( "1XX: Only one 1XX tag is allowed, but I found $count of them." ) ; } }
Check for multiple 1xx fields .
56,125
protected function standardFieldChecks ( $ marc ) { $ fieldsSeen = array ( ) ; foreach ( $ marc -> getFields ( ) as $ current ) { $ tagNo = $ current -> getTag ( ) ; if ( $ tagNo == 880 ) { if ( $ sub6 = $ current -> getSubfield ( 6 ) ) { $ tagNo = substr ( $ sub6 -> getData ( ) , 0 , 3 ) ; $ tagrules = isset ( $ this -> rules [ $ tagNo ] ) ? $ this -> rules [ $ tagNo ] : null ; if ( isset ( $ tagrules [ 'repeatable' ] ) && $ tagrules [ 'repeatable' ] == 'NR' && isset ( $ fieldsSeen [ '880.' . $ tagNo ] ) ) { $ this -> warn ( "$tagNo: Field is not repeatable." ) ; } $ fieldsSeen [ '880.' . $ tagNo ] = isset ( $ fieldsSeen [ '880.' . $ tagNo ] ) ? $ fieldsSeen [ '880.' . $ tagNo ] + 1 : 1 ; } else { $ this -> warn ( "880: No subfield 6." ) ; $ tagRules = null ; } } else { $ tagrules = isset ( $ this -> rules [ $ tagNo ] ) ? $ this -> rules [ $ tagNo ] : null ; if ( isset ( $ tagrules [ 'repeatable' ] ) && $ tagrules [ 'repeatable' ] == 'NR' && isset ( $ fieldsSeen [ $ tagNo ] ) ) { $ this -> warn ( "$tagNo: Field is not repeatable." ) ; } $ fieldsSeen [ $ tagNo ] = isset ( $ fieldsSeen [ $ tagNo ] ) ? $ fieldsSeen [ $ tagNo ] + 1 : 1 ; } if ( intval ( ltrim ( $ tagNo , '0' ) ) >= 10 ) { if ( ! empty ( $ tagrules ) ) { $ this -> checkIndicators ( $ tagNo , $ current , $ tagrules ) ; $ this -> checkSubfields ( $ tagNo , $ current , $ tagrules ) ; } } else { if ( strstr ( $ current -> toRaw ( ) , chr ( hexdec ( '1F' ) ) ) ) { $ this -> warn ( "$tagNo: Subfields are not allowed in fields lower than 010" ) ; } } $ method = 'check' . $ tagNo ; if ( method_exists ( $ this , $ method ) ) { $ this -> $ method ( $ current ) ; } } }
Check all fields against the standard rules encoded in the class .
56,126
protected function checkIndicators ( $ tagNo , $ field , $ rules ) { for ( $ i = 1 ; $ i <= 2 ; $ i ++ ) { $ ind = $ field -> getIndicator ( $ i ) ; if ( $ ind === false || $ ind == ' ' ) { $ ind = 'b' ; } if ( ! strstr ( $ rules [ 'ind' . $ i ] [ 'values' ] , $ ind ) ) { if ( $ ind == 'b' ) { $ ind = 'blank' ; } $ this -> warn ( "$tagNo: Indicator $i must be " . $ rules [ 'ind' . $ i ] [ 'hr_values' ] . " but it's \"$ind\"" ) ; } } }
Check the indicators for the provided field .
56,127
protected function checkSubfields ( $ tagNo , $ field , $ rules ) { $ subSeen = array ( ) ; foreach ( $ field -> getSubfields ( ) as $ current ) { $ code = $ current -> getCode ( ) ; $ data = $ current -> getData ( ) ; $ subrules = isset ( $ rules [ 'sub' . $ code ] ) ? $ rules [ 'sub' . $ code ] : null ; if ( empty ( $ subrules ) ) { $ this -> warn ( "$tagNo: Subfield _$code is not allowed." ) ; } elseif ( $ subrules [ 'repeatable' ] == 'NR' && isset ( $ subSeen [ $ code ] ) ) { $ this -> warn ( "$tagNo: Subfield _$code is not repeatable." ) ; } if ( preg_match ( '/\r|\t|\n/' , $ data ) ) { $ this -> warn ( "$tagNo: Subfield _$code has an invalid control character" ) ; } $ subSeen [ $ code ] = isset ( $ subSeen [ $ code ] ) ? $ subSeen [ $ code ] ++ : 1 ; } }
Check the subfields for the provided field .
56,128
protected function parseRules ( ) { $ lines = explode ( "\n" , $ this -> getRawRules ( ) ) ; $ currentGroup = array ( ) ; foreach ( $ lines as $ currentLine ) { if ( empty ( $ currentLine ) && ! empty ( $ currentGroup ) ) { $ this -> processRuleGroup ( $ currentGroup ) ; $ currentGroup = array ( ) ; } else { $ currentGroup [ ] = preg_replace ( "/\s+/" , " " , $ currentLine ) ; } } if ( ! empty ( $ currentGroup ) ) { $ this -> processRuleGroup ( $ currentGroup ) ; } }
Support method for constructor to load MARC rules .
56,129
protected function getHumanReadableIndicatorValues ( $ rules ) { if ( $ rules == 'blank' ) { return $ rules ; } $ string = '' ; $ length = strlen ( $ rules ) ; for ( $ i = 0 ; $ i < $ length ; $ i ++ ) { $ current = substr ( $ rules , $ i , 1 ) ; if ( $ current == 'b' ) { $ current = 'blank' ; } $ string .= $ current ; if ( $ length - $ i == 2 ) { $ string .= ' or ' ; } else if ( $ length - $ i > 2 ) { $ string .= ', ' ; } } return $ string ; }
Turn a set of indicator rules into a human - readable list .
56,130
public function convertToString ( $ dom ) { $ html = $ this -> html5 -> saveHTML ( $ dom ) ; $ html = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . "\n" . $ html ; $ html = str_replace ( '<html' , '<html xmlns="http://www.w3.org/1999/xhtml"' , $ html ) ; $ html = str_replace ( '&nbsp;' , '&#160;' , $ html ) ; $ html = preg_replace ( '/srcset="[^"]*"/' , '' , $ html ) ; $ html = preg_replace ( '/<rp>[^<]*?<\/rp>/' , '' , $ html ) ; $ html = preg_replace ( '/align="(center|right|left)"/' , 'class="text-$1"' , $ html ) ; $ html = preg_replace ( '/<(meta|link|img|br|param|hr)([^>]*)?>/u' , '<$1$2 />' , $ html ) ; return $ html ; }
Get HTML5 string
56,131
public function saveDom ( \ DOMDocument $ dom , $ name ) { return $ this -> distributor -> write ( $ this -> convertToString ( $ dom ) , "OEBPS/Text/{$name}" ) ; }
Save Dom as XHTML file .
56,132
public function pullRemoteAssets ( \ DomDocument & $ dom ) { $ paths = [ ] ; foreach ( [ 'img' => 'src' , 'script' => 'src' , 'link' => 'href' ] as $ tag => $ attr ) { foreach ( $ dom -> getElementsByTagName ( $ tag ) as $ elem ) { $ url = $ elem -> getAttribute ( $ attr ) ; if ( ! preg_match ( '/^(https?:)?\/\//' , $ url ) ) { continue ; } if ( ! ( $ resource = $ this -> getRemote ( $ url ) ) ) { continue ; } list ( $ basename ) = explode ( '?' , basename ( $ url ) ) ; $ dir = Mime :: getDestinationFolder ( $ basename ) ; if ( 'Misc' === $ dir ) { if ( $ resource [ 'info' ] ) { list ( $ mime , $ type ) = explode ( '/' , $ resource [ 'info' ] [ 'content_type' ] ) ; list ( $ ext ) = explode ( ';' , $ type ) ; $ new_dir = Mime :: getDestinationFolder ( "hoge.{$ext}" ) ; if ( $ new_dir != $ dir ) { $ dir = $ new_dir ; $ basename = "{$basename}.{$ext}" ; } } } $ new_path = $ dir . '/' . $ basename ; $ elem -> setAttribute ( $ attr , '../' . $ new_path ) ; if ( $ this -> distributor -> write ( $ resource [ 'body' ] , 'OEBPS/' . $ new_path ) ) { $ paths [ ] = $ new_path ; } } } return $ paths ; }
Extract remote assets and save it
56,133
private function recursiveToc ( Toc & $ toc , $ src , array $ headers ) { foreach ( $ headers as $ id => $ header ) { $ child = $ toc -> addChild ( $ header [ 'content' ] , $ src . '#' . $ id ) ; if ( $ header [ 'children' ] ) { $ this -> recursiveToc ( $ child , $ src , $ header [ 'children' ] ) ; } } }
Recursively add toc
56,134
private function digToc ( $ id , array $ header , array & $ headers ) { $ keys = array_keys ( $ headers ) ; krsort ( $ keys ) ; $ done = false ; foreach ( $ keys as $ key ) { if ( $ headers [ $ key ] [ 'level' ] < $ header [ 'level' ] ) { if ( ! $ this -> digToc ( $ id , $ header , $ headers [ $ key ] [ 'children' ] ) ) { $ headers [ $ key ] [ 'children' ] [ $ id ] = $ header ; } return true ; } } return false ; }
Arrange toc elements
56,135
public function add_class ( \ DOMElement & $ node , $ classes ) { $ classes = ( array ) $ classes ; if ( $ node -> hasAttribute ( 'class' ) ) { $ classes = array_merge ( $ classes , explode ( ' ' , $ node -> getAttribute ( 'classs' ) ) ) ; } $ node -> setAttribute ( 'class' , implode ( ' ' , $ classes ) ) ; }
Add class to element
56,136
public function getRemote ( $ url ) { $ ch = curl_init ( $ url ) ; curl_setopt_array ( $ ch , [ CURLOPT_RETURNTRANSFER => true , CURLOPT_TIMEOUT => 5 , CURLOPT_SSL_VERIFYPEER => false , CURLOPT_FAILONERROR => true , ] ) ; $ result = curl_exec ( $ ch ) ; if ( false === $ result ) { return false ; } $ return = [ 'info' => curl_getinfo ( $ ch ) , 'body' => $ result , ] ; curl_close ( $ ch ) ; return $ return ; }
Get remote assets
56,137
public function parseFromString ( $ string ) { $ dom = $ this -> html5 -> loadHTML ( $ string ) ; if ( is_a ( $ dom , 'DOMDocument' ) ) { return $ dom ; } else { return false ; } }
Parse HTML5 and convert to Dom document
56,138
function nextRaw ( ) { if ( $ this -> type == self :: SOURCE_FILE ) { $ record = stream_get_line ( $ this -> source , File_MARC :: MAX_RECORD_LENGTH , File_MARC :: END_OF_RECORD ) ; $ record = preg_replace ( '/^[\\x0a\\x0d\\x00]+/' , "" , $ record ) ; } elseif ( $ this -> type == self :: SOURCE_STRING ) { $ record = array_shift ( $ this -> source ) ; } if ( ! $ record ) { return false ; } $ record .= File_MARC :: END_OF_RECORD ; return $ record ; }
Return the next raw MARC record
56,139
function toXMLFooter ( ) { $ this -> xmlwriter -> endElement ( ) ; $ this -> xmlwriter -> endDocument ( ) ; return $ this -> xmlwriter -> outputMemory ( ) ; }
Returns the MARCXML collection footer
56,140
public function set ( $ file , $ url , $ title , $ titles , $ tocs , $ ctime , array $ depends ) { foreach ( $ tocs as $ toc ) { foreach ( $ toc as $ child ) { $ this -> parents [ $ child ] = $ file ; if ( isset ( $ this -> entries [ $ child ] ) ) { $ this -> entries [ $ child ] [ 'parent' ] = $ file ; } } } $ this -> entries [ $ file ] = array ( 'file' => $ file , 'url' => $ url , 'title' => $ title , 'titles' => $ titles , 'tocs' => $ tocs , 'ctime' => $ ctime , 'depends' => $ depends ) ; if ( isset ( $ this -> parents [ $ file ] ) ) { $ this -> entries [ $ file ] [ 'parent' ] = $ this -> parents [ $ file ] ; } }
Sets the meta for url giving the title the modification time and the dependencies list
56,141
public function get ( $ url ) { if ( isset ( $ this -> entries [ $ url ] ) ) { return $ this -> entries [ $ url ] ; } else { return null ; } }
Gets the meta for a given document reference url
56,142
protected function render ( ) { $ this -> display ( '* Rendering documents' ) ; foreach ( $ this -> documents as $ file => & $ document ) { $ this -> display ( ' -> Rendering ' . $ file . '...' ) ; $ target = $ this -> getTargetOf ( $ file ) ; $ directory = dirname ( $ target ) ; if ( ! is_dir ( $ directory ) ) { mkdir ( $ directory , 0755 , true ) ; } file_put_contents ( $ target , $ document -> renderDocument ( ) ) ; } }
Renders all the pending documents
56,143
protected function addToParseQueue ( $ file ) { $ this -> states [ $ file ] = self :: PARSE ; if ( ! isset ( $ this -> documents [ $ file ] ) ) { $ this -> parseQueue [ $ file ] = $ file ; } }
Adding a file to the parse queue
56,144
protected function parseAll ( ) { $ this -> display ( '* Parsing files' ) ; while ( $ file = $ this -> getFileToParse ( ) ) { $ this -> display ( ' -> Parsing ' . $ file . '...' ) ; $ rst = $ this -> getRST ( $ file ) ; $ parser = new Parser ( null , $ this -> kernel ) ; $ environment = $ parser -> getEnvironment ( ) ; $ environment -> setMetas ( $ this -> metas ) ; $ environment -> setCurrentFilename ( $ file ) ; $ environment -> setCurrentDirectory ( $ this -> directory ) ; $ environment -> setTargetDirectory ( $ this -> targetDirectory ) ; $ environment -> setErrorManager ( $ this -> errorManager ) ; $ environment -> setUseRelativeUrls ( $ this -> relativeUrls ) ; foreach ( $ this -> beforeHooks as $ hook ) { $ hook ( $ parser ) ; } if ( ! file_exists ( $ rst ) ) { $ this -> errorManager -> error ( 'Can\'t parse the file ' . $ rst ) ; continue ; } $ document = $ this -> documents [ $ file ] = $ parser -> parseFile ( $ rst ) ; foreach ( $ this -> hooks as $ hook ) { $ hook ( $ document ) ; } $ this -> kernel -> postParse ( $ document ) ; $ dependencies = $ document -> getEnvironment ( ) -> getDependencies ( ) ; if ( $ dependencies ) { $ this -> display ( ' -> Scanning dependencies of ' . $ file . '...' ) ; foreach ( $ dependencies as $ dependency ) { $ this -> scan ( $ dependency ) ; } } $ this -> metas -> set ( $ file , $ this -> getUrl ( $ document ) , $ document -> getTitle ( ) , $ document -> getTitles ( ) , $ document -> getTocs ( ) , filectime ( $ rst ) , $ dependencies ) ; } }
Parses all the document that need to be parsed
56,145
public function scan ( $ file ) { if ( ! isset ( $ this -> states [ $ file ] ) ) { $ this -> display ( ' -> Scanning ' . $ file . '...' ) ; $ this -> states [ $ file ] = self :: NO_PARSE ; $ entry = $ this -> metas -> get ( $ file ) ; $ rst = $ this -> getRST ( $ file ) ; if ( ! $ entry || ! file_exists ( $ rst ) || $ entry [ 'ctime' ] < filectime ( $ rst ) ) { $ this -> addToParseQueue ( $ file ) ; } else { $ depends = $ entry [ 'depends' ] ; if ( isset ( $ entry [ 'parent' ] ) ) { $ depends [ ] = $ entry [ 'parent' ] ; } foreach ( $ depends as $ dependency ) { $ this -> scan ( $ dependency ) ; if ( $ this -> states [ $ dependency ] == self :: PARSE ) { $ this -> addToParseQueue ( $ file ) ; } } } } }
Scans a file this will check the status of the file and tell if it needs to be parsed or not
56,146
public function scanMetas ( ) { $ entries = $ this -> metas -> getAll ( ) ; foreach ( $ entries as $ file => $ infos ) { $ this -> scan ( $ file ) ; } }
Scans all the metas
56,147
protected function saveMetas ( ) { $ metas = '<?php return ' . var_export ( $ this -> metas -> getAll ( ) , true ) . ';' ; file_put_contents ( $ this -> getMetaFile ( ) , $ metas ) ; }
Saving the meta files
56,148
public function getUrl ( $ document ) { $ environment = $ document -> getEnvironment ( ) ; return $ environment -> getUrl ( ) . '.' . $ this -> kernel -> getFileExtension ( ) ; }
Gets the URL of a target file
56,149
public function doCopy ( ) { foreach ( $ this -> toCopy as $ copy ) { list ( $ source , $ destination ) = $ copy ; if ( ! $ this -> isAbsolute ( $ source ) ) { $ source = $ this -> getSourceFile ( $ source ) ; } $ destination = $ this -> getTargetFile ( $ destination ) ; if ( is_dir ( $ source ) && is_dir ( $ destination ) ) { $ destination = dirname ( $ destination ) ; } shell_exec ( 'cp -R ' . $ source . ' ' . $ destination ) ; } }
Run the copy
56,150
public function copy ( $ source , $ destination = null ) { if ( $ destination === null ) { $ destination = basename ( $ source ) ; } $ this -> toCopy [ ] = array ( $ source , $ destination ) ; return $ this ; }
Add a file to copy
56,151
public function doMkdir ( ) { foreach ( $ this -> toMkdir as $ mkdir ) { $ dir = $ this -> getTargetFile ( $ mkdir ) ; if ( ! is_dir ( $ dir ) ) { mkdir ( $ dir , 0755 , true ) ; } } }
Run the directories creation
56,152
public function disconnect ( ) { if ( ! $ this -> isConnected || $ this -> isDisconnecting ) { return new RejectedPromise ( new \ LogicException ( 'The client is not connected.' ) ) ; } $ this -> isDisconnecting = true ; $ deferred = new Deferred ( ) ; $ this -> startFlow ( new OutgoingDisconnectFlow ( $ this -> connection ) , true ) -> then ( function ( Connection $ connection ) use ( $ deferred ) { $ this -> isDisconnecting = false ; $ this -> isConnected = false ; $ this -> emit ( 'disconnect' , [ $ connection , $ this ] ) ; $ deferred -> resolve ( $ connection ) ; if ( $ this -> stream !== null ) { $ this -> stream -> close ( ) ; } } ) -> otherwise ( function ( ) use ( $ deferred ) { $ this -> isDisconnecting = false ; $ deferred -> reject ( $ this -> connection ) ; } ) ; return $ deferred -> promise ( ) ; }
Disconnects from a broker .
56,153
public function subscribe ( Subscription $ subscription ) { if ( ! $ this -> isConnected ) { return new RejectedPromise ( new \ LogicException ( 'The client is not connected.' ) ) ; } return $ this -> startFlow ( new OutgoingSubscribeFlow ( [ $ subscription ] , $ this -> identifierGenerator ) ) ; }
Subscribes to a topic filter .
56,154
public function unsubscribe ( Subscription $ subscription ) { if ( ! $ this -> isConnected ) { return new RejectedPromise ( new \ LogicException ( 'The client is not connected.' ) ) ; } return $ this -> startFlow ( new OutgoingUnsubscribeFlow ( [ $ subscription ] , $ this -> identifierGenerator ) ) ; }
Unsubscribes from a topic filter .
56,155
public function publish ( Message $ message ) { if ( ! $ this -> isConnected ) { return new RejectedPromise ( new \ LogicException ( 'The client is not connected.' ) ) ; } return $ this -> startFlow ( new OutgoingPublishFlow ( $ message , $ this -> identifierGenerator ) ) ; }
Publishes a message .
56,156
public function publishPeriodically ( $ interval , Message $ message , callable $ generator ) { if ( ! $ this -> isConnected ) { return new RejectedPromise ( new \ LogicException ( 'The client is not connected.' ) ) ; } $ deferred = new Deferred ( ) ; $ this -> timer [ ] = $ this -> loop -> addPeriodicTimer ( $ interval , function ( ) use ( $ message , $ generator , $ deferred ) { $ this -> publish ( $ message -> withPayload ( $ generator ( $ message -> getTopic ( ) ) ) ) -> then ( function ( $ value ) use ( $ deferred ) { $ deferred -> notify ( $ value ) ; } , function ( \ Exception $ e ) use ( $ deferred ) { $ deferred -> reject ( $ e ) ; } ) ; } ) ; return $ deferred -> promise ( ) ; }
Calls the given generator periodically and publishes the return value .
56,157
private function establishConnection ( $ host , $ port , $ timeout ) { $ deferred = new Deferred ( ) ; $ timer = $ this -> loop -> addTimer ( $ timeout , function ( ) use ( $ deferred , $ timeout ) { $ exception = new \ RuntimeException ( sprintf ( 'Connection timed out after %d seconds.' , $ timeout ) ) ; $ deferred -> reject ( $ exception ) ; } ) ; $ this -> connector -> connect ( $ host . ':' . $ port ) -> always ( function ( ) use ( $ timer ) { $ this -> loop -> cancelTimer ( $ timer ) ; } ) -> then ( function ( DuplexStreamInterface $ stream ) use ( $ deferred ) { $ stream -> on ( 'data' , function ( $ data ) { $ this -> handleReceive ( $ data ) ; } ) ; $ stream -> on ( 'close' , function ( ) { $ this -> handleClose ( ) ; } ) ; $ stream -> on ( 'error' , function ( \ Exception $ e ) { $ this -> handleError ( $ e ) ; } ) ; $ deferred -> resolve ( $ stream ) ; } ) -> otherwise ( function ( \ Exception $ e ) use ( $ deferred ) { $ deferred -> reject ( $ e ) ; } ) ; return $ deferred -> promise ( ) ; }
Establishes a network connection to a server .
56,158
private function registerClient ( Connection $ connection , $ timeout ) { $ deferred = new Deferred ( ) ; $ responseTimer = $ this -> loop -> addTimer ( $ timeout , function ( ) use ( $ deferred , $ timeout ) { $ exception = new \ RuntimeException ( sprintf ( 'No response after %d seconds.' , $ timeout ) ) ; $ deferred -> reject ( $ exception ) ; } ) ; $ this -> startFlow ( new OutgoingConnectFlow ( $ connection , $ this -> identifierGenerator ) , true ) -> always ( function ( ) use ( $ responseTimer ) { $ this -> loop -> cancelTimer ( $ responseTimer ) ; } ) -> then ( function ( Connection $ connection ) use ( $ deferred ) { $ this -> timer [ ] = $ this -> loop -> addPeriodicTimer ( floor ( $ connection -> getKeepAlive ( ) * 0.75 ) , function ( ) { $ this -> startFlow ( new OutgoingPingFlow ( ) ) ; } ) ; $ deferred -> resolve ( $ connection ) ; } ) -> otherwise ( function ( \ Exception $ e ) use ( $ deferred ) { $ deferred -> reject ( $ e ) ; } ) ; return $ deferred -> promise ( ) ; }
Registers a new client with the broker .
56,159
private function handleReceive ( $ data ) { if ( ! $ this -> isConnected && ! $ this -> isConnecting ) { return ; } $ flowCount = count ( $ this -> receivingFlows ) ; $ packets = $ this -> parser -> push ( $ data ) ; foreach ( $ packets as $ packet ) { $ this -> handlePacket ( $ packet ) ; } if ( $ flowCount > count ( $ this -> receivingFlows ) ) { $ this -> receivingFlows = array_values ( $ this -> receivingFlows ) ; } $ this -> handleSend ( ) ; }
Handles incoming data .
56,160
private function handlePacket ( Packet $ packet ) { switch ( $ packet -> getPacketType ( ) ) { case Packet :: TYPE_PUBLISH : $ message = new DefaultMessage ( $ packet -> getTopic ( ) , $ packet -> getPayload ( ) , $ packet -> getQosLevel ( ) , $ packet -> isRetained ( ) , $ packet -> isDuplicate ( ) ) ; $ this -> startFlow ( new IncomingPublishFlow ( $ message , $ packet -> getIdentifier ( ) ) ) ; break ; case Packet :: TYPE_CONNACK : case Packet :: TYPE_PINGRESP : case Packet :: TYPE_SUBACK : case Packet :: TYPE_UNSUBACK : case Packet :: TYPE_PUBREL : case Packet :: TYPE_PUBACK : case Packet :: TYPE_PUBREC : case Packet :: TYPE_PUBCOMP : $ flowFound = false ; foreach ( $ this -> receivingFlows as $ index => $ flow ) { if ( $ flow -> accept ( $ packet ) ) { $ flowFound = true ; unset ( $ this -> receivingFlows [ $ index ] ) ; $ this -> continueFlow ( $ flow , $ packet ) ; break ; } } if ( ! $ flowFound ) { $ this -> emitWarning ( new \ LogicException ( sprintf ( 'Received unexpected packet of type %d.' , $ packet -> getPacketType ( ) ) ) ) ; } break ; default : $ this -> emitWarning ( new \ LogicException ( sprintf ( 'Cannot handle packet of type %d.' , $ packet -> getPacketType ( ) ) ) ) ; } }
Handles an incoming packet .
56,161
private function handleSend ( ) { $ flow = null ; if ( $ this -> writtenFlow !== null ) { $ flow = $ this -> writtenFlow ; $ this -> writtenFlow = null ; } if ( count ( $ this -> sendingFlows ) > 0 ) { $ this -> writtenFlow = array_shift ( $ this -> sendingFlows ) ; $ this -> stream -> write ( $ this -> writtenFlow -> getPacket ( ) ) ; } if ( $ flow !== null ) { if ( $ flow -> isFinished ( ) ) { $ this -> loop -> nextTick ( function ( ) use ( $ flow ) { $ this -> finishFlow ( $ flow ) ; } ) ; } else { $ this -> receivingFlows [ ] = $ flow ; } } }
Handles outgoing packets .
56,162
private function handleClose ( ) { foreach ( $ this -> timer as $ timer ) { $ this -> loop -> cancelTimer ( $ timer ) ; } $ connection = $ this -> connection ; $ this -> isConnecting = false ; $ this -> isDisconnecting = false ; $ this -> isConnected = false ; $ this -> connection = null ; $ this -> stream = null ; if ( $ connection !== null ) { $ this -> emit ( 'close' , [ $ connection , $ this ] ) ; } }
Handles closing of the stream .
56,163
private function startFlow ( Flow $ flow , $ isSilent = false ) { try { $ packet = $ flow -> start ( ) ; } catch ( \ Exception $ e ) { $ this -> emitError ( $ e ) ; return new RejectedPromise ( $ e ) ; } $ deferred = new Deferred ( ) ; $ internalFlow = new ReactFlow ( $ flow , $ deferred , $ packet , $ isSilent ) ; if ( $ packet !== null ) { if ( $ this -> writtenFlow !== null ) { $ this -> sendingFlows [ ] = $ internalFlow ; } else { $ this -> stream -> write ( $ packet ) ; $ this -> writtenFlow = $ internalFlow ; $ this -> handleSend ( ) ; } } else { $ this -> loop -> nextTick ( function ( ) use ( $ internalFlow ) { $ this -> finishFlow ( $ internalFlow ) ; } ) ; } return $ deferred -> promise ( ) ; }
Starts the given flow .
56,164
private function continueFlow ( ReactFlow $ flow , Packet $ packet ) { try { $ response = $ flow -> next ( $ packet ) ; } catch ( \ Exception $ e ) { $ this -> emitError ( $ e ) ; return ; } if ( $ response !== null ) { if ( $ this -> writtenFlow !== null ) { $ this -> sendingFlows [ ] = $ flow ; } else { $ this -> stream -> write ( $ response ) ; $ this -> writtenFlow = $ flow ; $ this -> handleSend ( ) ; } } elseif ( $ flow -> isFinished ( ) ) { $ this -> loop -> nextTick ( function ( ) use ( $ flow ) { $ this -> finishFlow ( $ flow ) ; } ) ; } }
Continues the given flow .
56,165
private function finishFlow ( ReactFlow $ flow ) { if ( $ flow -> isSuccess ( ) ) { if ( ! $ flow -> isSilent ( ) ) { $ this -> emit ( $ flow -> getCode ( ) , [ $ flow -> getResult ( ) , $ this ] ) ; } $ flow -> getDeferred ( ) -> resolve ( $ flow -> getResult ( ) ) ; } else { $ result = new \ RuntimeException ( $ flow -> getErrorMessage ( ) ) ; $ this -> emitWarning ( $ result ) ; $ flow -> getDeferred ( ) -> reject ( $ result ) ; } }
Finishes the given flow .
56,166
public function elementValue ( FormRuntime $ formRuntime , RootRenderableInterface $ element ) { $ request = $ formRuntime -> getRequest ( ) ; $ validationResults = $ formRuntime -> getRequest ( ) -> getInternalArgument ( '__submittedArgumentValidationResults' ) ; if ( $ validationResults !== null && $ validationResults -> forProperty ( $ element -> getIdentifier ( ) ) -> hasErrors ( ) ) { return $ this -> getLastSubmittedFormData ( $ request , $ element -> getIdentifier ( ) ) ; } return ObjectAccess :: getPropertyPath ( $ formRuntime , $ element -> getIdentifier ( ) ) ; }
Returns the value of a given Form Element . If there are validation errors for the element the previously submitted value will be returned .
56,167
public function hasValidationErrors ( FormRuntime $ formRuntime , RootRenderableInterface $ element ) : bool { return $ this -> getValidationResult ( $ formRuntime , $ element ) -> hasErrors ( ) ; }
Whether the given Form Element has validation errors
56,168
public function validationErrors ( FormRuntime $ formRuntime , RootRenderableInterface $ element ) : array { return $ this -> getValidationResult ( $ formRuntime , $ element ) -> getErrors ( ) ; }
Returns all validation errors for a given Form Element
56,169
public function translateAndEscapeProperty ( AbstractRenderable $ element , string $ property ) : string { return $ this -> escape ( $ this -> translateProperty ( $ element , $ property ) ) ; }
Translates the property of a given Form Element and htmlspecialchar s the result
56,170
public function translateProperty ( AbstractRenderable $ element , string $ property ) : string { if ( $ property === 'label' ) { $ defaultValue = $ element -> getLabel ( ) ; if ( $ defaultValue === null ) { $ defaultValue = '' ; } } elseif ( $ element instanceof FormElementInterface ) { $ defaultValue = isset ( $ element -> getProperties ( ) [ $ property ] ) ? ( string ) $ element -> getProperties ( ) [ $ property ] : '' ; } else { $ defaultValue = '' ; } $ translationId = sprintf ( 'forms.elements.%s.%s' , $ element -> getIdentifier ( ) , $ property ) ; return $ this -> translate ( $ element , $ translationId , $ defaultValue ) ; }
Translates the property of a given Form Element
56,171
public static function getFilePickerCallback ( $ url , $ popupSettings = [ ] , $ view = null ) { $ default = [ 'title' => 'elFinder' , 'width' => 900 , 'height' => 500 , ] ; $ settings = array_merge ( $ default , $ popupSettings ) ; $ settings [ 'file' ] = Url :: to ( $ url ) ; $ encodedSettings = Json :: htmlEncode ( $ settings ) ; if ( $ view === null ) { $ view = Yii :: $ app -> view ; } HelperAsset :: register ( $ view ) ; return new JsExpression ( "alexantr.elFinder.filePickerCallback($encodedSettings)" ) ; }
Callback for TinyMCE 4 file_picker_callback
56,172
public function generate ( $ random = null ) { $ results = [ ] ; $ plaintext = $ this -> _convert ( $ random ? : $ this -> _random ( 8 ) ) ; $ part = $ try = 0 ; while ( count ( $ results ) < $ this -> _parts ) { $ result = substr ( $ plaintext , $ try * $ this -> _partLength , $ this -> _partLength - 1 ) ; if ( ! $ result || strlen ( $ result ) !== $ this -> _partLength - 1 ) { throw new Exception ( 'Ran out of plaintext.' ) ; } $ result .= $ this -> _checkdigitAlg1 ( $ part + 1 , $ result ) ; $ try ++ ; if ( $ this -> _isBadWord ( $ result ) || $ this -> _isValidWhenSwapped ( $ result ) ) { continue ; } $ part ++ ; $ results [ ] = $ result ; } return implode ( '-' , $ results ) ; }
Generates a coupon code using the format XXXX - XXXX - XXXX .
56,173
public function validate ( $ code ) { $ code = $ this -> _normalize ( $ code , [ 'clean' => true , 'case' => true ] ) ; if ( strlen ( $ code ) !== ( $ this -> _parts * $ this -> _partLength ) ) { return false ; } $ parts = str_split ( $ code , $ this -> _partLength ) ; foreach ( $ parts as $ number => $ part ) { $ expected = substr ( $ part , - 1 ) ; $ result = $ this -> _checkdigitAlg1 ( $ number + 1 , $ x = substr ( $ part , 0 , strlen ( $ part ) - 1 ) ) ; if ( $ result !== $ expected ) { return false ; } } return true ; }
Validates given code . Codes are not case sensitive and certain letters i . e . O are converted to digit equivalents i . e . 0 .
56,174
public function normalize ( $ string ) { $ string = $ this -> _normalize ( $ string , [ 'clean' => true , 'case' => true ] ) ; return implode ( '-' , str_split ( $ string , $ this -> _partLength ) ) ; }
Normalizes a given code using dash separators .
56,175
protected function _convert ( $ string ) { $ symbols = $ this -> _symbols ; $ result = array_map ( function ( $ value ) use ( $ symbols ) { return $ symbols [ ord ( $ value ) & ( count ( $ symbols ) - 1 ) ] ; } , str_split ( hash ( 'sha1' , $ string ) ) ) ; return implode ( '' , $ result ) ; }
Converts givens string using symbols .
56,176
protected function _normalize ( $ string , array $ options = [ ] ) { $ options += [ 'clean' => false , 'case' => false ] ; if ( $ options [ 'case' ] ) { $ string = strtoupper ( $ string ) ; } $ string = strtr ( $ string , [ 'I' => 1 , 'O' => 0 , 'S' => 5 , 'Z' => 2 , ] ) ; if ( $ options [ 'clean' ] ) { $ string = preg_replace ( '/[^0-9A-Z]+/' , '' , $ string ) ; } return $ string ; }
Internal method to normalize given strings .
56,177
protected function _random ( $ bytes ) { if ( is_readable ( '/dev/urandom' ) ) { $ stream = fopen ( '/dev/urandom' , 'rb' ) ; $ result = fread ( $ stream , $ bytes ) ; fclose ( $ stream ) ; return $ result ; } if ( function_exists ( 'mcrypt_create_iv' ) ) { return mcrypt_create_iv ( $ bytes , MCRYPT_DEV_RANDOM ) ; } throw new Exception ( "No source for generating a cryptographically secure seed found." ) ; }
Generates a cryptographically secure sequence of bytes .
56,178
public function render ( ) { $ environment = $ this -> parser -> getEnvironment ( ) ; $ span = $ this -> process ( $ this -> span ) ; if ( $ this -> tokens ) { foreach ( $ this -> tokens as $ id => $ value ) { switch ( $ value [ 'type' ] ) { case 'raw' : $ span = str_replace ( $ id , $ value [ 'text' ] , $ span ) ; break ; case 'literal' : $ span = str_replace ( $ id , $ this -> literal ( $ value [ 'text' ] ) , $ span ) ; break ; case 'reference' : $ reference = $ environment -> resolve ( $ value [ 'section' ] , $ value [ 'url' ] ) ; $ link = $ this -> reference ( $ reference , $ value ) ; $ span = str_replace ( $ id , $ link , $ span ) ; break ; case 'link' : if ( $ value [ 'url' ] ) { if ( $ environment -> useRelativeUrls ( ) ) { $ url = $ environment -> relativeUrl ( $ value [ 'url' ] ) ; } else { $ url = $ value [ 'url' ] ; } } else { $ url = $ environment -> getLink ( $ value [ 'link' ] ) ; } $ link = $ this -> link ( $ url , $ this -> process ( $ value [ 'link' ] ) ) ; $ span = str_replace ( $ id , $ link , $ span ) ; break ; } } } return $ span ; }
Renders the span
56,179
private function createSunday ( $ year ) { $ easterSunday = new \ DateTime ( '21.03.' . $ year ) ; $ easterSunday -> modify ( sprintf ( '+%d days' , easter_days ( $ year ) ) ) ; return $ easterSunday ; }
Creating easter sunday
56,180
private function createOrthodoxSunday ( $ year ) { $ a = $ year % 4 ; $ b = $ year % 7 ; $ c = $ year % 19 ; $ d = ( 19 * $ c + 15 ) % 30 ; $ e = ( 2 * $ a + 4 * $ b - $ d + 34 ) % 7 ; $ month = floor ( ( $ d + $ e + 114 ) / 31 ) ; $ day = ( ( $ d + $ e + 114 ) % 31 ) + 1 ; $ sunday = mktime ( 0 , 0 , 0 , $ month , $ day + 13 , $ year ) ; return new \ DateTime ( date ( 'Y-m-d' , $ sunday ) ) ; }
Creating Orthodox easter sunday
56,181
protected function getEasterDates ( $ year , $ orthodox = false ) { $ easterSunday = $ orthodox ? $ this -> createOrthodoxSunday ( $ year ) : $ this -> createSunday ( $ year ) ; $ easterSunday -> setTimezone ( new \ DateTimeZone ( date_default_timezone_get ( ) ) ) ; $ easterMonday = clone $ easterSunday ; $ easterMonday -> modify ( '+1 day' ) ; $ maundyThursday = clone $ easterSunday ; $ maundyThursday -> modify ( '-3 days' ) ; $ goodFriday = clone $ easterSunday ; $ goodFriday -> modify ( '-2 days' ) ; $ saturday = clone $ easterSunday ; $ saturday -> modify ( '-1 days' ) ; $ ascensionDay = clone $ easterSunday ; $ ascensionDay -> modify ( '+39 days' ) ; $ shroveTuesday = clone $ easterSunday ; $ shroveTuesday -> modify ( '-47 days' ) ; $ pentecostSunday = clone $ easterSunday ; $ pentecostSunday -> modify ( '+49 days' ) ; $ pentecostMonday = clone $ pentecostSunday ; $ pentecostMonday -> modify ( '+1 days' ) ; $ pentecostSaturday = clone $ pentecostSunday ; $ pentecostSaturday -> modify ( '-1 days' ) ; $ corpusChristi = clone $ easterSunday ; $ corpusChristi -> modify ( '+60 days' ) ; return array ( 'shroveTuesday' => $ shroveTuesday , 'maundyThursday' => $ maundyThursday , 'easterSunday' => $ easterSunday , 'easterMonday' => $ easterMonday , 'saturday' => $ saturday , 'goodFriday' => $ goodFriday , 'ascensionDay' => $ ascensionDay , 'pentecostSaturday' => $ pentecostSaturday , 'pentecostSunday' => $ pentecostSunday , 'pentecostMonday' => $ pentecostMonday , 'corpusChristi' => $ corpusChristi ) ; }
Returns all dates calculated by easter sunday
56,182
public function getParent ( ) { if ( ! $ this -> currentFileName || ! $ this -> metas ) { return null ; } $ meta = $ this -> metas -> get ( $ this -> currentFileName ) ; if ( ! $ meta || ! isset ( $ meta [ 'parent' ] ) ) { return null ; } $ parent = $ this -> metas -> get ( $ meta [ 'parent' ] ) ; if ( ! $ parent ) { return null ; } return $ parent ; }
Get my parent metas
56,183
public function getMyToc ( ) { $ parent = $ this -> getParent ( ) ; if ( $ parent ) { foreach ( $ parent [ 'tocs' ] as $ toc ) { if ( in_array ( $ this -> currentFileName , $ toc ) ) { $ before = array ( ) ; $ after = $ toc ; while ( $ after ) { $ file = array_shift ( $ after ) ; if ( $ file == $ this -> currentFileName ) { return array ( $ before , $ after ) ; } $ before [ ] = $ file ; } } } } return null ; }
Get the docs involving this document
56,184
public function registerReference ( Reference $ reference ) { $ name = $ reference -> getName ( ) ; $ this -> references [ $ name ] = $ reference ; }
Registers a new reference
56,185
public function resolve ( $ section , $ data ) { if ( isset ( $ this -> references [ $ section ] ) ) { $ reference = $ this -> references [ $ section ] ; return $ reference -> resolve ( $ this , $ data ) ; } $ this -> errorManager -> error ( 'Unknown reference section ' . $ section ) ; }
Resolves a reference
56,186
public function setLink ( $ name , $ url ) { $ name = trim ( strtolower ( $ name ) ) ; if ( $ name == '_' ) { $ name = array_shift ( $ this -> anonymous ) ; } $ this -> links [ $ name ] = trim ( $ url ) ; }
Set the link url
56,187
public function getLink ( $ name , $ relative = true ) { $ name = trim ( strtolower ( $ name ) ) ; if ( isset ( $ this -> links [ $ name ] ) ) { $ link = $ this -> links [ $ name ] ; if ( $ relative ) { return $ this -> relativeUrl ( $ link ) ; } return $ link ; } return null ; }
Get a link value
56,188
protected function samePrefix ( $ url ) { $ partsA = explode ( '/' , $ url ) ; $ partsB = explode ( '/' , $ this -> currentFileName ) ; $ n = count ( $ partsA ) ; if ( $ n != count ( $ partsB ) ) { return false ; } unset ( $ partsA [ $ n - 1 ] ) ; unset ( $ partsB [ $ n - 1 ] ) ; return $ partsA == $ partsB ; }
Returns true if the given url have the same prefix as the current document
56,189
public function canonicalUrl ( $ url ) { if ( strlen ( $ url ) ) { if ( $ url [ 0 ] == '/' ) { return substr ( $ url , 1 ) ; } else { if ( $ this -> getDirName ( ) ) { return $ this -> canonicalize ( $ this -> getDirName ( ) . '/' . $ url ) ; } else { return $ this -> canonicalize ( $ url ) ; } } } return null ; }
Gets a canonical URL from the given one
56,190
protected function checkLanguage ( $ language ) { $ full_language = mb_strtolower ( $ language ) ; $ lang = substr ( $ full_language , 0 , 2 ) ; if ( $ lang == 'jp' ) { $ lang = 'ja' ; } elseif ( $ lang == 'pt' ) { $ lang = 'pt_BR' ; } elseif ( $ lang == 'ug' ) { $ lang = 'ug_CN' ; } elseif ( $ lang == 'zh' ) { $ lang = ( $ full_language == 'zh-tw' || $ full_language == 'zh_tw' ) ? 'zh_TW' : 'zh_CN' ; } elseif ( $ lang == 'be' ) { $ lang = 'ru' ; } return $ lang ; }
Set elFinder s correct lang param
56,191
private function setHolidayForState ( & $ holidays , $ day , $ state , $ name ) { if ( ! array_key_exists ( $ day , $ holidays ) ) { $ holidays [ $ day ] = $ this -> createData ( $ name , [ ] ) ; } if ( is_array ( $ holidays [ $ day ] [ 'states' ] ) ) { $ holidays [ $ day ] [ 'states' ] [ ] = $ state ; } }
Set Holiday for State
56,192
public function getReport ( $ model , $ ids , $ type = 'qweb-pdf' ) { $ params = $ this -> buildParams ( array ( $ model , $ ids , array ( 'model' => $ model , 'id' => $ ids [ 0 ] , 'report_type' => $ type ) ) ) ; $ client = $ this -> getClient ( 'report' ) ; $ reportId = $ client -> call ( 'report' , $ params ) ; $ state = false ; while ( ! $ state ) { $ report = $ client -> call ( 'report_get' , $ this -> buildParams ( array ( $ reportId ) ) ) ; $ state = $ report [ 'state' ] ; if ( ! $ state ) { sleep ( 1 ) ; } } return base64_decode ( $ report [ 'result' ] ) ; }
Get report for model
56,193
protected function getClient ( $ path = null ) { if ( $ path === null ) { return $ this -> client ; } if ( $ this -> path === $ path ) { return $ this -> client ; } $ this -> path = $ path ; $ this -> client = new XmlRpcClient ( $ this -> host . '/' . $ path , $ this -> httpClient ) ; $ this -> client -> setSkipSystemLookup ( true ) ; return $ this -> client ; }
Get XmlRpc Client
56,194
protected function createRoute ( ) { $ route = ( array ) $ this -> clientRoute ; $ route [ 'id' ] = $ this -> options [ 'id' ] ; if ( ! empty ( $ this -> filter ) ) { $ route [ 'filter' ] = $ this -> filter ; } if ( $ this -> multiple ) { $ route [ 'multiple' ] = 1 ; } return $ route ; }
Creates route to elFinder client
56,195
public function build ( $ name , $ arg1 = null , $ arg2 = null , $ arg3 = null , $ arg4 = null ) { $ class = $ this -> getClass ( $ name ) ; if ( $ class ) { return new $ class ( $ arg1 , $ arg2 , $ arg3 , $ arg4 ) ; } return null ; }
Create an instance of some class
56,196
public function getDirectives ( ) { return array ( new Directives \ Dummy , new Directives \ CodeBlock , new Directives \ Raw , new Directives \ Replace , new Directives \ Toctree , new Directives \ Document , new Directives \ RedirectionTitle , ) ; }
Gets the available directives
56,197
public function processNode ( Parser $ parser , $ variable , $ data , array $ options ) { $ this -> processAction ( $ parser , $ variable , $ data , $ options ) ; return null ; }
This can be overloaded to write a directive that just create one node for the document which is common
56,198
public function parseLink ( $ line ) { if ( preg_match ( '/^\.\. _`(.+)`: (.+)$/mUsi' , $ line , $ match ) ) { $ this -> environment -> setLink ( $ match [ 1 ] , $ match [ 2 ] ) ; return true ; } if ( preg_match ( '/^\.\. _(.+): (.+)$/mUsi' , $ line , $ match ) ) { $ this -> environment -> setLink ( $ match [ 1 ] , $ match [ 2 ] ) ; return true ; } if ( preg_match ( '/^__ (.+)$/mUsi' , trim ( $ line ) , $ match ) ) { $ url = $ match [ 1 ] ; $ this -> environment -> setLink ( '_' , $ url ) ; return true ; } if ( preg_match ( '/^\.\. _(.+):$/mUsi' , trim ( $ line ) , $ match ) ) { $ anchor = $ match [ 1 ] ; $ this -> document -> addNode ( $ this -> kernel -> build ( 'Nodes\AnchorNode' , $ anchor ) ) ; $ this -> environment -> setLink ( $ anchor , '#' . $ anchor ) ; return true ; } return false ; }
Try to parse a link definition
56,199
protected function prepareCode ( ) { if ( ! $ this -> buffer ) { return false ; } $ lastLine = trim ( $ this -> buffer [ count ( $ this -> buffer ) - 1 ] ) ; if ( strlen ( $ lastLine ) >= 2 ) { if ( substr ( $ lastLine , - 2 ) == '::' ) { if ( trim ( $ lastLine ) == '::' ) { array_pop ( $ this -> buffer ) ; } else { $ this -> buffer [ count ( $ this -> buffer ) - 1 ] = substr ( $ lastLine , 0 , - 1 ) ; } return true ; } } return false ; }
Tells if the current buffer is announcing a block of code