idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
50,400
|
public static function maybe_split_parameters ( $ params ) { if ( ! \ is_array ( $ params ) ) { $ params = ( array ) \ preg_split ( self :: RE_PARAMETER_SPLITTING , $ params , - 1 , PREG_SPLIT_NO_EMPTY ) ; } return $ params ; }
|
If necessary split the passed parameters string into an array .
|
50,401
|
protected static function tokenize ( array $ parts ) { $ tokens = [ ] ; $ index = 0 ; foreach ( $ parts as $ part ) { if ( \ preg_match ( self :: _RE_SPACE , $ part ) ) { $ tokens [ $ index ] = new Token ( $ part , Token :: SPACE ) ; } elseif ( \ preg_match ( self :: _RE_PUNCTUATION , $ part ) ) { $ tokens [ $ index ] = new Token ( $ part , Token :: PUNCTUATION ) ; } elseif ( \ preg_match ( self :: _RE_WORD , $ part ) ) { self :: parse_ambiguous_token ( Token :: WORD , $ part , $ tokens , $ index ) ; } else { self :: parse_ambiguous_token ( Token :: OTHER , $ part , $ tokens , $ index ) ; } $ index ++ ; } return $ tokens ; }
|
Turns the array of strings into an array of tokens .
|
50,402
|
protected static function is_preceeded_by ( $ type , array $ tokens , $ index , $ steps = 1 ) { return $ index - $ steps >= 0 && $ type === $ tokens [ $ index - $ steps ] -> type ; }
|
Checks if the predecessor of the current token is of a certain type .
|
50,403
|
protected static function is_not_preceeded_by ( $ type , array $ tokens , $ index , $ steps = 1 ) { return $ index - $ steps >= 0 && $ type !== $ tokens [ $ index - $ steps ] -> type ; }
|
Checks if the predecessor of the current token is not of a certain type .
|
50,404
|
public function unload ( ) { $ reassembled_text = '' ; foreach ( $ this -> text as $ token ) { $ reassembled_text .= $ token -> value ; } $ this -> clear ( ) ; return $ reassembled_text ; }
|
Returns the complete text as a string and clears the parser .
|
50,405
|
public function update ( $ tokens ) { foreach ( $ tokens as $ index => $ token ) { $ this -> text [ $ index ] = $ this -> text [ $ index ] -> with_value ( $ token -> value ) ; } }
|
Updates the value field for all matching tokens .
|
50,406
|
public function get_words ( $ abc = self :: ALLOW_ALL_LETTERS , $ caps = self :: ALLOW_ALL_CAPS , $ comps = self :: ALLOW_COMPOUNDS ) { if ( empty ( $ this -> text ) ) { return [ ] ; } $ tokens = [ ] ; foreach ( $ this -> get_type ( Token :: WORD ) as $ index => $ token ) { if ( $ this -> conforms_to_letters_policy ( $ token , $ abc ) && $ this -> conforms_to_caps_policy ( $ token , $ caps ) && $ this -> conforms_to_compounds_policy ( $ token , $ comps ) ) { $ tokens [ $ index ] = $ token ; } } return $ tokens ; }
|
Retrieves all tokens of the type word .
|
50,407
|
protected function conforms_to_letters_policy ( Token $ token , $ policy ) { return $ this -> check_policy ( $ token , $ policy , self :: ALLOW_ALL_LETTERS , self :: REQUIRE_ALL_LETTERS , self :: NO_ALL_LETTERS , function ( $ value ) { return \ preg_replace ( self :: _RE_HTML_LETTER_CONNECTORS , '' , $ value ) ; } ) ; }
|
Check if the value of the token conforms to the given policy for letters .
|
50,408
|
protected function conforms_to_caps_policy ( Token $ token , $ policy ) { return $ this -> check_policy ( $ token , $ policy , self :: ALLOW_ALL_CAPS , self :: REQUIRE_ALL_CAPS , self :: NO_ALL_CAPS , $ this -> current_strtoupper ) ; }
|
Check if the value of the token conforms to the given policy for all - caps words .
|
50,409
|
protected function conforms_to_compounds_policy ( Token $ token , $ policy ) { return $ this -> check_policy ( $ token , $ policy , self :: ALLOW_COMPOUNDS , self :: NO_COMPOUNDS , self :: REQUIRE_COMPOUNDS , function ( $ value ) { return \ preg_replace ( '/-/S' , '' , $ value ) ; } ) ; }
|
Check if the value of the token conforms to the given policy for compound words .
|
50,410
|
protected function check_policy ( Token $ token , $ policy , $ permissive_policy , $ equal_policy , $ non_equal_policy , callable $ transform_token ) { if ( $ permissive_policy === $ policy ) { return true ; } $ transformed = $ transform_token ( $ token -> value ) ; return ( $ equal_policy === $ policy && $ transformed === $ token -> value ) || ( $ non_equal_policy === $ policy && $ transformed !== $ token -> value ) ; }
|
Check if the value of the token conforms to the given policy .
|
50,411
|
public function get_type ( $ type ) { $ tokens = [ ] ; foreach ( $ this -> text as $ index => $ token ) { if ( $ token -> type === $ type ) { $ tokens [ $ index ] = $ token ; } } return $ tokens ; }
|
Retrieves all tokens of the given type .
|
50,412
|
private static function get_top_level_domains_from_file ( $ path ) { $ domains = [ ] ; if ( \ file_exists ( $ path ) ) { $ file = new \ SplFileObject ( $ path ) ; while ( ! $ file -> eof ( ) ) { $ line = $ file -> fgets ( ) ; if ( \ preg_match ( '#^[a-zA-Z0-9][a-zA-Z0-9-]*$#' , $ line , $ matches ) ) { $ domains [ ] = \ strtolower ( $ matches [ 0 ] ) ; } } } if ( \ count ( $ domains ) > 0 ) { return \ implode ( '|' , $ domains ) ; } else { return 'ac|ad|aero|ae|af|ag|ai|al|am|an|ao|aq|arpa|ar|asia|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|biz|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|cat|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|com|coop|co|cr|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|info|int|in|io|iq|ir|is|it|je|jm|jobs|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mil|mk|ml|mm|mn|mobi|mo|mp|mq|mr|ms|mt|museum|mu|mv|mw|mx|my|mz|name|na|nc|net|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pro|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tel|tf|tg|th|tj|tk|tl|tm|tn|to|tp|travel|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw' ; } }
|
Load a list of top - level domains from a file .
|
50,413
|
public static function top_level_domains ( ) { if ( empty ( self :: $ top_level_domains_pattern ) ) { self :: $ top_level_domains_pattern = self :: get_top_level_domains_from_file ( __DIR__ . '/IANA/tlds-alpha-by-domain.txt' ) ; } return self :: $ top_level_domains_pattern ; }
|
Retrieves a pattern matching all valid top - level domains .
|
50,414
|
private function update_dash_spacing_regex ( $ parenthetical , $ parenthetical_space , $ interval , $ interval_space ) { $ this -> parenthetical_dash_spacing = "/ (?: \s ({$parenthetical}) \s ) /xu" ; $ this -> interval_dash_spacing = "/ (?: (?<=\S) # lookbehind assertion ({$interval}) (?=\S) # lookahead assertion ) /xu" ; $ this -> em_dash_replacement = "{$interval_space}\$1\$2{$interval_space}" ; $ this -> parenthetical_dash_replacement = "{$parenthetical_space}\$1\$2{$parenthetical_space}" ; $ this -> interval_dash_replacement = "{$interval_space}\$1\$2{$interval_space}" ; }
|
Update the dash spacing regular expression .
|
50,415
|
public function process_textnodes ( $ html , callable $ fixer , Settings $ settings , $ is_title = false , array $ body_classes = [ ] ) { if ( isset ( $ settings [ 'ignoreTags' ] ) && $ is_title && ( \ in_array ( 'h1' , $ settings [ 'ignoreTags' ] , true ) || \ in_array ( 'h2' , $ settings [ 'ignoreTags' ] , true ) ) ) { return $ html ; } $ html5_parser = $ this -> get_html5_parser ( ) ; $ dom = $ this -> parse_html ( $ html5_parser , $ html , $ settings , $ body_classes ) ; if ( empty ( $ dom ) ) { return $ html ; } $ xpath = new \ DOMXPath ( $ dom ) ; $ body_node = $ xpath -> query ( '/html/body' ) -> item ( 0 ) ; $ tags_to_ignore = $ this -> query_tags_to_ignore ( $ xpath , $ body_node , $ settings ) ; foreach ( $ xpath -> query ( '//text()' , $ body_node ) as $ textnode ) { if ( self :: arrays_intersect ( DOM :: get_ancestors ( $ textnode ) , $ tags_to_ignore ) || $ textnode -> isWhitespaceInElementContent ( ) ) { continue ; } $ original = $ textnode -> data ; $ fixer ( $ textnode , $ settings , $ is_title ) ; $ new = $ textnode -> data ; if ( $ new !== $ original ) { $ this -> replace_node_with_html ( $ textnode , $ new ) ; } } return $ html5_parser -> saveHTML ( $ body_node -> childNodes ) ; }
|
Applies specific fixes to all textnodes of the HTML fragment .
|
50,416
|
protected static function arrays_intersect ( array $ array1 , array $ array2 ) { foreach ( $ array1 as $ value ) { if ( isset ( $ array2 [ \ spl_object_hash ( $ value ) ] ) ) { return true ; } } return false ; }
|
Determines whether two object arrays intersect . The second array is expected to use the spl_object_hash for its keys .
|
50,417
|
public function handle_parsing_errors ( $ errno , $ errstr , $ errfile ) { if ( ! ( \ error_reporting ( ) & $ errno ) ) { return true ; } return $ errno & E_USER_WARNING && 0 === \ substr_compare ( $ errfile , 'DOMTreeBuilder.php' , - 18 ) ; }
|
Silently handle certain HTML parsing errors .
|
50,418
|
public function query_tags_to_ignore ( \ DOMXPath $ xpath , \ DOMNode $ initial_node , Settings $ settings ) { $ elements = [ ] ; $ query_parts = [ ] ; if ( ! empty ( $ settings [ 'ignoreTags' ] ) ) { $ query_parts [ ] = '//' . \ implode ( ' | //' , $ settings [ 'ignoreTags' ] ) ; } if ( ! empty ( $ settings [ 'ignoreClasses' ] ) ) { $ query_parts [ ] = "//*[contains(concat(' ', @class, ' '), ' " . \ implode ( " ') or contains(concat(' ', @class, ' '), ' " , $ settings [ 'ignoreClasses' ] ) . " ')]" ; } if ( ! empty ( $ settings [ 'ignoreIDs' ] ) ) { $ query_parts [ ] = '//*[@id=\'' . \ implode ( '\' or @id=\'' , $ settings [ 'ignoreIDs' ] ) . '\']' ; } if ( ! empty ( $ query_parts ) ) { $ ignore_query = \ implode ( ' | ' , $ query_parts ) ; $ nodelist = $ xpath -> query ( $ ignore_query , $ initial_node ) ; if ( false !== $ nodelist ) { $ elements = DOM :: nodelist_to_array ( $ nodelist ) ; } } return $ elements ; }
|
Retrieves an array of nodes that should be skipped during processing .
|
50,419
|
public function replace_node_with_html ( \ DOMNode $ node , $ content ) { $ result = $ node ; $ parent = $ node -> parentNode ; if ( empty ( $ parent ) ) { return $ node ; } $ content = RE :: unescape_tags ( \ htmlspecialchars ( $ content , ENT_NOQUOTES | ENT_HTML5 | ENT_SUBSTITUTE , 'UTF-8' , true ) ) ; \ set_error_handler ( [ $ this , 'handle_parsing_errors' ] ) ; $ html_fragment = $ this -> get_html5_parser ( ) -> loadHTMLFragment ( $ content ) ; if ( ! empty ( $ html_fragment ) ) { $ imported_fragment = $ node -> ownerDocument -> importNode ( $ html_fragment , true ) ; if ( ! empty ( $ imported_fragment ) ) { $ children = DOM :: nodelist_to_array ( $ imported_fragment -> childNodes ) ; if ( false !== $ parent -> replaceChild ( $ imported_fragment , $ node ) ) { $ result = $ children ; } } } \ restore_error_handler ( ) ; return $ result ; }
|
Replaces the given node with HTML content . Uses the HTML5 parser .
|
50,420
|
public function get_registry ( ) { if ( ! isset ( $ this -> registry ) ) { $ this -> registry = new Default_Registry ( $ this -> get_hyphenator_cache ( ) ) ; } elseif ( $ this -> update_registry_cache ) { $ this -> registry -> update_hyphenator_cache ( $ this -> get_hyphenator_cache ( ) ) ; $ this -> update_registry_cache = false ; } return $ this -> registry ; }
|
Retrieves the fix registry .
|
50,421
|
public function get_html5_parser ( ) { if ( ! isset ( $ this -> html5_parser ) ) { $ this -> html5_parser = new \ Masterminds \ HTML5 ( [ 'disable_html_ns' => true ] ) ; } return $ this -> html5_parser ; }
|
Retrieves the HTML5 parser instance .
|
50,422
|
public function get_hyphenator_cache ( ) { if ( ! isset ( $ this -> hyphenator_cache ) ) { $ this -> hyphenator_cache = new Hyphenator \ Cache ( ) ; } return $ this -> hyphenator_cache ; }
|
Retrieves the hyphenator cache .
|
50,423
|
private static function get_language_plugin_list ( $ path ) { $ languages = [ ] ; $ handle = \ opendir ( $ path ) ; if ( false === $ handle ) { return $ languages ; } $ file = \ readdir ( $ handle ) ; while ( $ file ) { if ( '.json' === \ substr ( $ file , - 5 ) ) { $ file_content = \ file_get_contents ( $ path . $ file ) ; if ( \ preg_match ( '/"language"\s*:\s*((".+")|(\'.+\'))\s*,/' , $ file_content , $ matches ) ) { $ language_name = \ substr ( $ matches [ 1 ] , 1 , - 1 ) ; $ language_code = \ substr ( $ file , 0 , - 5 ) ; $ languages [ $ language_code ] = $ language_name ; } } $ file = \ readdir ( $ handle ) ; } \ closedir ( $ handle ) ; \ asort ( $ languages ) ; return $ languages ; }
|
Retrieves the list of valid language plugins in the given directory .
|
50,424
|
public function set_hyphenator ( $ lang , Hyphenator $ hyphenator ) { $ this -> cache [ $ lang ] = $ hyphenator ; $ this -> changed = true ; }
|
Caches a Hyphenator instance .
|
50,425
|
public function get_hyphenator ( $ lang ) { if ( isset ( $ this -> cache [ $ lang ] ) ) { return $ this -> cache [ $ lang ] ; } return null ; }
|
Retrieves a cached Hyphenator .
|
50,426
|
protected function get_sequence ( $ pattern ) { $ characters = Strings :: mb_str_split ( str_replace ( '.' , '_' , $ pattern ) ) ; $ result = [ ] ; foreach ( $ characters as $ index => $ chr ) { if ( ctype_digit ( $ chr ) ) { $ result [ ] = $ chr ; } else { if ( ! isset ( $ characters [ $ index - 1 ] ) || ! ctype_digit ( $ characters [ $ index - 1 ] ) ) { $ result [ ] = '0' ; } if ( ! isset ( $ characters [ $ index + 1 ] ) ) { $ result [ ] = '0' ; } } } $ count = count ( $ result ) ; $ count_seg = mb_strlen ( $ this -> get_segment ( $ pattern ) ) ; $ sequence = implode ( '' , $ result ) ; if ( $ count !== $ count_seg + 1 ) { throw new \ RangeException ( "Invalid segment length $count for pattern $pattern (result sequence $sequence)." ) ; } return $ sequence ; }
|
Calculate patgen sequence from TeX hyphenation pattern .
|
50,427
|
protected function format_results ( array $ patterns , array $ exceptions , array $ comments ) { $ pattern_mapping = [ ] ; foreach ( $ patterns as $ pattern ) { $ segment = $ this -> get_segment ( $ pattern ) ; if ( ! isset ( $ pattern_mapping [ $ segment ] ) ) { $ pattern_mapping [ $ segment ] = $ this -> get_sequence ( $ pattern ) ; } } $ json_exceptions = [ ] ; foreach ( $ exceptions as $ exception ) { $ json_exceptions [ mb_strtolower ( str_replace ( '-' , '' , $ exception ) ) ] = mb_strtolower ( $ exception ) ; } $ json_results = [ 'language' => $ this -> language , 'source_url' => count ( $ this -> urls ) > 1 ? $ this -> urls : $ this -> urls [ 0 ] , 'copyright' => array_map ( 'rtrim' , $ comments ) , 'exceptions' => $ json_exceptions , 'patterns' => $ pattern_mapping , ] ; return json_encode ( $ json_results , JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE ) ; }
|
Format hyphenation pattern file for wp - Typography .
|
50,428
|
protected function match_exceptions ( $ line , array & $ exceptions , $ line_no = 0 ) { if ( preg_match ( '/^\s*([' . $ this -> word_characters . '-]+)\s*}\s*(?:%.*)?$/u' , $ line , $ matches ) ) { $ exceptions [ ] = $ matches [ 1 ] ; return false ; } if ( preg_match ( '/^\s*((?:[' . $ this -> word_characters . '-]+\s*)+)\s*}\s*(?:%.*)?$/u' , $ line , $ matches ) ) { $ this -> match_exceptions ( $ matches [ 1 ] , $ exceptions , $ line_no ) ; return false ; } elseif ( preg_match ( '/^\s*}\s*(?:%.*)?$/u' , $ line , $ matches ) ) { return false ; } elseif ( preg_match ( '/^\s*([' . $ this -> word_characters . '-]+)\s*(?:%.*)?$/u' , $ line , $ matches ) ) { $ exceptions [ ] = $ matches [ 1 ] ; } elseif ( preg_match ( '/^\s*((?:[' . $ this -> word_characters . '-]+\s*)+)(?:%.*)?$/u' , $ line , $ matches ) ) { foreach ( self :: split_at_whitespace ( $ matches [ 1 ] ) as $ match ) { $ exceptions [ ] = $ match ; } } elseif ( preg_match ( '/^\s*(?:%.*)?$/u' , $ line , $ matches ) ) { return true ; } else { throw new \ RangeException ( "Error: unknown exception $line on line $line_no\n" ) ; } return true ; }
|
Try to match squences of TeX hyphenation exceptions .
|
50,429
|
protected function match_patterns ( $ line , array & $ patterns , $ line_no = 0 ) { if ( preg_match ( '/^\s*([' . $ this -> word_characters . ']+)\s*}\s*(?:%.*)?$/u' , $ line , $ matches ) ) { $ patterns [ ] = $ matches [ 1 ] ; return false ; } elseif ( preg_match ( '/^\s*}\s*(?:%.*)?$/u' , $ line , $ matches ) ) { return false ; } elseif ( preg_match ( '/^\s*([' . $ this -> word_characters . ']+)\s*(?:%.*)?$/u' , $ line , $ matches ) ) { $ patterns [ ] = $ matches [ 1 ] ; } elseif ( preg_match ( '/^\s*((?:[' . $ this -> word_characters . ']+\s*)+)(?:%.*)?$/u' , $ line , $ matches ) ) { foreach ( self :: split_at_whitespace ( $ matches [ 1 ] ) as $ match ) { $ patterns [ ] = $ match ; } } elseif ( preg_match ( '/^\s*(?:%.*)?$/u' , $ line , $ matches ) ) { return true ; } else { throw new \ RangeException ( "Error: unknown pattern $line on line $line_no\n" ) ; } return true ; }
|
Try to match a pattern .
|
50,430
|
protected function expand_macros ( $ line , array $ macros ) { if ( 0 < preg_match_all ( '/\\\(?<name>\w+)\{(?<arg>[^\}]+)\}/u' , $ line , $ matches , PREG_SET_ORDER ) ) { foreach ( $ matches as $ m ) { if ( ! empty ( $ macros [ $ m [ 'name' ] ] ) ) { $ expanded = preg_replace ( '/#1/' , $ m [ 'arg' ] , $ macros [ $ m [ 'name' ] ] ) ; $ pattern = preg_quote ( $ m [ 0 ] , '/' ) ; $ line = preg_replace ( "/{$pattern}/u" , $ expanded , $ line ) ; } } } return $ line ; }
|
Replace macros in the given line .
|
50,431
|
public function convert ( ) { $ comments = [ ] ; $ patterns = [ ] ; $ exceptions = [ ] ; foreach ( $ this -> urls as $ url ) { $ this -> convert_single_file ( $ url , $ patterns , $ exceptions , $ comments ) ; } return $ this -> format_results ( $ patterns , $ exceptions , $ comments ) ; }
|
Convert the given TeX files .
|
50,432
|
protected function convert_single_file ( $ url , & $ patterns , & $ exceptions , & $ comments ) { if ( ! file_exists ( $ url ) && 404 === File_Operations :: get_http_response_code ( $ url ) ) { throw new \ RuntimeException ( "Error: unknown pattern file '{$url}'\n" ) ; } $ reading_patterns = false ; $ reading_exceptions = false ; $ macros = [ ] ; $ file = new \ SplFileObject ( $ url ) ; $ line_no = 0 ; while ( ! $ file -> eof ( ) ) { $ line = $ file -> fgets ( ) ; $ line_no ++ ; if ( $ reading_patterns ) { $ reading_patterns = $ this -> match_patterns ( $ this -> expand_macros ( $ line , $ macros ) , $ patterns , $ line_no ) ; } elseif ( $ reading_exceptions ) { $ reading_exceptions = $ this -> match_exceptions ( $ this -> expand_macros ( $ line , $ macros ) , $ exceptions , $ line_no ) ; } else { if ( preg_match ( '/^\s*%.*$/u' , $ line , $ matches ) ) { $ comments [ ] = $ line ; } elseif ( preg_match ( '/^\s*\\\patterns\s*\{\s*(.*)$/u' , $ line , $ matches ) ) { $ reading_patterns = $ this -> match_patterns ( $ matches [ 1 ] , $ patterns , $ line_no ) ; } elseif ( preg_match ( '/^\s*\\\hyphenation\s*{\s*(.*)$/u' , $ line , $ matches ) ) { $ reading_exceptions = $ this -> match_exceptions ( $ matches [ 1 ] , $ exceptions , $ line_no ) ; } elseif ( preg_match ( '/^\s*\\\endinput.*$/u' , $ line , $ matches ) ) { continue ; } elseif ( preg_match ( '/^\s*\\\def\\\(\w+)#1\s*\{([^\}]*)\}\s*$/u' , $ line , $ matches ) ) { $ macros [ $ matches [ 1 ] ] = $ matches [ 2 ] ; } elseif ( preg_match ( '/^\s*\\\edef\\\(\w+)#1\s*\{(.*)\}\s*$/u' , $ line , $ matches ) ) { $ macros [ $ matches [ 1 ] ] = $ this -> expand_macros ( $ matches [ 2 ] , $ macros ) ; } elseif ( preg_match ( '/^\s*\\\[\w]+.*$/u' , $ line , $ matches ) ) { $ comments [ ] = $ line ; } elseif ( preg_match ( '/^\s*$/u' , $ line , $ matches ) ) { continue ; } else { throw new \ RangeException ( "Error: unknown string $line at line $line_no\n" ) ; } } } }
|
Convert the given TeX file .
|
50,433
|
public function register_node_fix ( Node_Fix $ fix , $ group ) { if ( isset ( $ this -> node_fixes [ $ group ] ) ) { $ this -> node_fixes [ $ group ] [ ] = $ fix ; } else { throw new \ InvalidArgumentException ( "Invalid fixer group $group." ) ; } }
|
Registers a node fix .
|
50,434
|
public function apply_fixes ( \ DOMText $ textnode , Settings $ settings , $ is_title , $ is_feed ) { foreach ( $ this -> node_fixes as $ group => $ fixes ) { foreach ( $ fixes as $ fix ) { if ( ! $ is_feed || $ fix -> feed_compatible ( ) ) { $ fix -> apply ( $ textnode , $ settings , $ is_title ) ; } } } }
|
Applies typography fixes to a textnode .
|
50,435
|
public function set_tags_to_ignore ( $ tags = [ 'code' , 'head' , 'kbd' , 'object' , 'option' , 'pre' , 'samp' , 'script' , 'noscript' , 'noembed' , 'select' , 'style' , 'textarea' , 'title' , 'var' , 'math' ] ) { $ tags = array_filter ( array_map ( 'strtolower' , Strings :: maybe_split_parameters ( $ tags ) ) , 'ctype_alnum' ) ; $ this -> data [ 'ignoreTags' ] = array_unique ( array_merge ( $ tags , array_flip ( DOM :: inappropriate_tags ( ) ) ) ) ; }
|
Sets tags for which the typography of their children will be left untouched .
|
50,436
|
public function set_smart_quotes_exceptions ( $ exceptions = [ "'tain't" => U :: APOSTROPHE . 'tain' . U :: APOSTROPHE . 't' , "'twere" => U :: APOSTROPHE . 'twere' , "'twas" => U :: APOSTROPHE . 'twas' , "'tis" => U :: APOSTROPHE . 'tis' , "'til" => U :: APOSTROPHE . 'til' , "'bout" => U :: APOSTROPHE . 'bout' , "'nuff" => U :: APOSTROPHE . 'nuff' , "'round" => U :: APOSTROPHE . 'round' , "'cause" => U :: APOSTROPHE . 'cause' , "'splainin" => U :: APOSTROPHE . 'splainin' , "'em'" => U :: APOSTROPHE . 'em' , ] ) { $ this -> data [ 'smartQuotesExceptions' ] = [ 'patterns' => \ array_keys ( $ exceptions ) , 'replacements' => \ array_values ( $ exceptions ) , ] ; }
|
Sets the list of exceptional words for smart quotes replacement . Mainly this is used for contractions beginning with an apostrophe .
|
50,437
|
protected function get_style ( $ style , $ expected_class , callable $ get_style , $ description ) { if ( $ style instanceof $ expected_class ) { $ object = $ style ; } else { $ object = $ get_style ( $ style , $ this ) ; } if ( ! \ is_object ( $ object ) || ! $ object instanceof $ expected_class ) { throw new \ DomainException ( "Invalid $description style $style." ) ; } return $ object ; }
|
Retrieves an object from a given style .
|
50,438
|
public function set_smart_dashes_style ( $ style = Dash_Style :: TRADITIONAL_US ) { $ this -> dash_style = $ this -> get_style ( $ style , Settings \ Dashes :: class , [ Dash_Style :: class , 'get_styled_dashes' ] , 'dash' ) ; }
|
Sets the typographical conventions used by smart_dashes .
|
50,439
|
public function set_diacritic_language ( $ lang = 'en-US' ) { if ( isset ( $ this -> data [ 'diacriticLanguage' ] ) && $ this -> data [ 'diacriticLanguage' ] === $ lang ) { return ; } $ this -> data [ 'diacriticLanguage' ] = $ lang ; $ language_file_name = \ dirname ( __FILE__ ) . '/diacritics/' . $ lang . '.json' ; if ( \ file_exists ( $ language_file_name ) ) { $ diacritics_file = \ json_decode ( \ file_get_contents ( $ language_file_name ) , true ) ; $ this -> data [ 'diacriticWords' ] = $ diacritics_file [ 'diacritic_words' ] ; } else { unset ( $ this -> data [ 'diacriticWords' ] ) ; } $ this -> update_diacritics_replacement_arrays ( ) ; }
|
Sets the language used for diacritics replacements .
|
50,440
|
public function set_diacritic_custom_replacements ( $ custom_replacements = [ ] ) { if ( ! \ is_array ( $ custom_replacements ) ) { $ custom_replacements = $ this -> parse_diacritics_replacement_string ( $ custom_replacements ) ; } $ this -> data [ 'diacriticCustomReplacements' ] = self :: array_map_assoc ( function ( $ key , $ replacement ) { $ key = \ strip_tags ( \ trim ( $ key ) ) ; $ replacement = \ strip_tags ( \ trim ( $ replacement ) ) ; if ( ! empty ( $ key ) && ! empty ( $ replacement ) ) { return [ $ key => $ replacement ] ; } else { return [ ] ; } } , $ custom_replacements ) ; $ this -> update_diacritics_replacement_arrays ( ) ; }
|
Sets up custom diacritics replacements .
|
50,441
|
private function parse_diacritics_replacement_string ( $ custom_replacements ) { return self :: array_map_assoc ( function ( $ key , $ replacement ) { if ( \ preg_match ( '/(?<kquo>"|\')(?<key>(?:(?!\k<kquo>).)+)\k<kquo>\s*=>\s*(?<rquo>"|\')(?<replacement>(?:(?!\k<rquo>).)+)\k<rquo>/' , $ replacement , $ match ) ) { $ key = $ match [ 'key' ] ; $ replacement = $ match [ 'replacement' ] ; return [ $ key => $ replacement ] ; } return [ ] ; } , \ preg_split ( '/,/' , $ custom_replacements , - 1 , PREG_SPLIT_NO_EMPTY ) ) ; }
|
Parses a custom diacritics replacement string into an array .
|
50,442
|
protected static function array_map_assoc ( callable $ callback , array $ array ) { $ new = [ ] ; foreach ( $ array as $ k => $ v ) { $ u = $ callback ( $ k , $ v ) ; if ( ! empty ( $ u ) ) { $ new [ \ key ( $ u ) ] = \ current ( $ u ) ; } } return $ new ; }
|
Provides an array_map implementation with control over resulting array s keys .
|
50,443
|
private function parse_diacritics_rules ( array $ diacritics_rules , array & $ patterns , array & $ replacements ) { foreach ( $ diacritics_rules as $ needle => $ replacement ) { $ patterns [ ] = '/\b(?<!\w[' . U :: NO_BREAK_SPACE . U :: SOFT_HYPHEN . '])' . $ needle . '\b(?![' . U :: NO_BREAK_SPACE . U :: SOFT_HYPHEN . ']\w)/u' ; $ replacements [ $ needle ] = $ replacement ; } }
|
Parse an array of diacritics rules .
|
50,444
|
public function set_units ( $ units = [ ] ) { $ this -> data [ 'units' ] = Strings :: maybe_split_parameters ( $ units ) ; $ this -> custom_units = $ this -> update_unit_pattern ( $ this -> data [ 'units' ] ) ; }
|
Sets the list of units to keep together with their values .
|
50,445
|
protected function update_unit_pattern ( array $ units ) { foreach ( $ units as $ index => $ unit ) { $ units [ $ index ] = \ preg_quote ( $ unit , '/' ) ; } $ custom_units = \ implode ( '|' , $ units ) ; $ custom_units .= ! empty ( $ custom_units ) ? '|' : '' ; return $ custom_units ; }
|
Update pattern for matching custom units .
|
50,446
|
public function set_initial_quote_tags ( $ tags = [ 'p' , 'h1' , 'h2' , 'h3' , 'h4' , 'h5' , 'h6' , 'blockquote' , 'li' , 'dd' , 'dt' ] ) { if ( ! \ is_array ( $ tags ) ) { $ tags = \ preg_split ( '/[^a-z0-9]+/' , $ tags , - 1 , PREG_SPLIT_NO_EMPTY ) ; } $ this -> data [ 'initialQuoteTags' ] = \ array_change_key_case ( \ array_flip ( $ tags ) , CASE_LOWER ) ; }
|
Sets the list of tags where initial quotes and guillemets should be styled .
|
50,447
|
public function get_hash ( $ max_length = 16 , $ raw_output = true ) { $ hash = \ md5 ( \ json_encode ( $ this ) , $ raw_output ) ; if ( $ max_length < \ strlen ( $ hash ) && $ max_length > 0 ) { $ hash = \ substr ( $ hash , 0 , $ max_length ) ; } return $ hash ; }
|
Retrieves a unique hash value for the current settings .
|
50,448
|
public static function get_styled_dashes ( $ style , Settings $ settings ) { if ( isset ( self :: $ styles [ $ style ] ) ) { return new Simple_Dashes ( self :: $ styles [ $ style ] [ self :: _PARENTHETICAL ] , self :: $ styles [ $ style ] [ self :: _PARENTHETICAL_SPACE ] , self :: $ styles [ $ style ] [ self :: _INTERVAL ] , self :: $ styles [ $ style ] [ self :: _INTERVAL_SPACE ] ) ; } return null ; }
|
Creates a new Dashes object in the given style .
|
50,449
|
public function forceMimeType ( $ link , $ mimeType ) { $ resource = new \ core_kernel_classes_Resource ( \ tao_helpers_Uri :: decode ( $ link ) ) ; return $ resource -> editPropertyValues ( new \ core_kernel_classes_Property ( MediaService :: PROPERTY_MIME_TYPE ) , $ mimeType ) ; }
|
Force the mime - type of a resource
|
50,450
|
protected function getZipImporter ( ) { if ( ! $ this -> zipImporter ) { $ this -> zipImporter = new SharedStimulusPackageImporter ( ) ; $ this -> zipImporter -> setServiceLocator ( $ this -> getServiceLocator ( ) ) ; } return $ this -> zipImporter ; }
|
Get the zip importer for shared stimulus
|
50,451
|
public function createMediaInstance ( $ fileSource , $ classUri , $ language , $ label = null , $ mimeType = null , $ userId = null ) { $ clazz = $ this -> getClass ( $ classUri ) ; if ( is_null ( $ label ) ) { $ label = $ fileSource instanceof File ? $ fileSource -> getBasename ( ) : basename ( $ fileSource ) ; } $ md5 = $ fileSource instanceof File ? md5 ( $ fileSource -> read ( ) ) : md5_file ( $ fileSource ) ; $ link = $ this -> getFileManager ( ) -> storeFile ( $ fileSource , $ label ) ; if ( $ link !== false ) { if ( is_null ( $ mimeType ) ) { $ mimeType = $ fileSource instanceof File ? $ fileSource -> getMimeType ( ) : \ tao_helpers_File :: getMimeType ( $ fileSource ) ; } $ instance = $ clazz -> createInstanceWithProperties ( array ( OntologyRdfs :: RDFS_LABEL => $ label , self :: PROPERTY_LINK => $ link , self :: PROPERTY_LANGUAGE => $ language , self :: PROPERTY_MD5 => $ md5 , self :: PROPERTY_MIME_TYPE => $ mimeType , self :: PROPERTY_ALT_TEXT => $ label ) ) ; if ( $ this -> getServiceLocator ( ) -> get ( common_ext_ExtensionsManager :: SERVICE_ID ) -> isEnabled ( 'taoRevision' ) ) { \ common_Logger :: i ( 'Auto generating initial revision' ) ; $ this -> getServiceLocator ( ) -> get ( Repository :: SERVICE_ID ) -> commit ( $ instance -> getUri ( ) , __ ( 'Initial import' ) , null , $ userId ) ; } return $ instance -> getUri ( ) ; } return false ; }
|
Create a media instance from a file and define its class and language
|
50,452
|
protected function getLink ( \ core_kernel_classes_Resource $ resource ) { $ instance = $ resource -> getUniquePropertyValue ( $ this -> getProperty ( self :: PROPERTY_LINK ) ) ; return $ instance instanceof \ core_kernel_classes_Resource ? $ instance -> getUri ( ) : ( string ) $ instance ; }
|
Returns the link of a media resource
|
50,453
|
public function editInstance ( ) { $ this -> defaultData ( ) ; $ clazz = $ this -> getCurrentClass ( ) ; $ instance = $ this -> getCurrentInstance ( ) ; $ myFormContainer = new editInstanceForm ( $ clazz , $ instance ) ; $ myForm = $ myFormContainer -> getForm ( ) ; if ( $ myForm -> isSubmited ( ) ) { if ( $ myForm -> isValid ( ) ) { $ values = $ myForm -> getValues ( ) ; $ binder = new \ tao_models_classes_dataBinding_GenerisFormDataBinder ( $ instance ) ; $ instance = $ binder -> bind ( $ values ) ; $ message = __ ( 'Instance saved' ) ; $ this -> setData ( 'message' , $ message ) ; $ this -> setData ( 'reload' , true ) ; } } $ this -> setData ( 'formTitle' , __ ( 'Edit Instance' ) ) ; $ this -> setData ( 'myForm' , $ myForm -> render ( ) ) ; $ uri = ( $ this -> hasRequestParameter ( 'id' ) ) ? $ this -> getRequestParameter ( 'id' ) : $ this -> getRequestParameter ( 'uri' ) ; try { $ mediaSource = new MediaSource ( array ( ) ) ; $ fileInfo = $ mediaSource -> getFileInfo ( $ uri ) ; $ mimeType = $ fileInfo [ 'mime' ] ; $ xml = in_array ( $ mimeType , array ( 'application/xml' , 'text/xml' ) ) ; $ url = \ tao_helpers_Uri :: url ( 'getFile' , 'MediaManager' , 'taoMediaManager' , array ( 'uri' => $ uri , ) ) ; $ this -> setData ( 'xml' , $ xml ) ; $ this -> setData ( 'fileurl' , $ url ) ; $ this -> setData ( 'mimeType' , $ mimeType ) ; } catch ( \ tao_models_classes_FileNotFoundException $ e ) { $ this -> setData ( 'error' , __ ( 'No file found for this media' ) ) ; } $ this -> setView ( 'form.tpl' ) ; }
|
Show the form to edit an instance show also a preview of the media
|
50,454
|
public function getFile ( ) { if ( ! $ this -> hasGetParameter ( 'uri' ) ) { throw new \ common_exception_Error ( 'invalid media identifier' ) ; } $ uri = urldecode ( $ this -> getGetParameter ( 'uri' ) ) ; $ mediaSource = new MediaSource ( array ( ) ) ; $ fileInfo = $ mediaSource -> getFileInfo ( $ uri ) ; $ fileManagement = $ this -> getServiceLocator ( ) -> get ( FileManagement :: SERVICE_ID ) ; $ stream = $ fileManagement -> getFileStream ( $ fileInfo [ 'link' ] ) ; if ( $ fileInfo [ 'mime' ] === 'application/qti+xml' ) { $ this -> response = $ this -> getPsrResponse ( ) -> withBody ( $ stream ) ; } elseif ( $ this -> hasGetParameter ( 'xml' ) ) { $ this -> returnJson ( htmlentities ( ( string ) $ stream ) ) ; } else { $ this -> setContentHeader ( $ fileInfo [ 'mime' ] ) ; $ this -> response = $ this -> getPsrResponse ( ) -> withBody ( $ stream ) ; } }
|
Get the file stream associated to given uri GET parameter
|
50,455
|
public function edit ( Resource $ instance , $ form , $ userId = null ) { try { $ uploadedFile = $ this -> fetchUploadedFile ( $ form ) ; $ xmlFile = $ this -> getSharedStimulusFile ( $ uploadedFile ) ; $ this -> getUploadService ( ) -> remove ( $ uploadedFile ) ; SharedStimulusImporter :: isValidSharedStimulus ( $ xmlFile ) ; $ embeddedFile = static :: embedAssets ( $ xmlFile ) ; $ report = $ this -> replaceSharedStimulus ( $ instance , $ this -> getDecodedUri ( $ form ) , $ embeddedFile , $ userId ) ; } catch ( \ Exception $ e ) { $ message = $ e instanceof common_exception_UserReadableException ? $ e -> getUserMessage ( ) : __ ( 'An error has occurred. Please contact your administrator.' ) ; $ report = Report :: createFailure ( $ message ) ; $ this -> logError ( $ e -> getMessage ( ) ) ; $ report -> setData ( [ 'uriResource' => '' ] ) ; } return $ report ; }
|
Edit a shared stimulus package
|
50,456
|
public static function embedAssets ( $ originalXml ) { $ basedir = dirname ( $ originalXml ) . DIRECTORY_SEPARATOR ; $ xmlDocument = new XmlDocument ( ) ; $ xmlDocument -> load ( $ originalXml , true ) ; $ images = $ xmlDocument -> getDocumentComponent ( ) -> getComponentsByClassName ( 'img' ) ; $ objects = $ xmlDocument -> getDocumentComponent ( ) -> getComponentsByClassName ( 'object' ) ; foreach ( $ images as $ image ) { $ source = $ image -> getSrc ( ) ; static :: validateSource ( $ basedir , $ source ) ; $ image -> setSrc ( self :: secureEncode ( $ basedir , $ source ) ) ; } foreach ( $ objects as $ object ) { $ data = $ object -> getData ( ) ; static :: validateSource ( $ basedir , $ data ) ; $ object -> setData ( self :: secureEncode ( $ basedir , $ data ) ) ; } $ newXml = tempnam ( sys_get_temp_dir ( ) , 'sharedStimulus_' ) . '.xml' ; $ xmlDocument -> save ( $ newXml ) ; return $ newXml ; }
|
Embed external resources into the XML
|
50,457
|
private function getSharedStimulusFile ( $ filePath ) { \ helpers_TimeOutHelper :: setTimeOutLimit ( \ helpers_TimeOutHelper :: LONG ) ; $ extractPath = $ this -> extractArchive ( $ filePath ) ; \ helpers_TimeOutHelper :: reset ( ) ; $ iterator = new \ RecursiveIteratorIterator ( new \ RecursiveDirectoryIterator ( $ extractPath ) , \ RecursiveIteratorIterator :: LEAVES_ONLY ) ; foreach ( $ iterator as $ file ) { if ( $ file -> isFile ( ) ) { if ( preg_match ( '/^[\w]/' , $ file -> getFilename ( ) ) === 1 && $ file -> getExtension ( ) === 'xml' ) { return $ file -> getRealPath ( ) ; } } } throw new \ common_Exception ( 'XML not found in the package' ) ; }
|
Get the shared stimulus file with assets from the zip
|
50,458
|
protected static function secureEncode ( $ basedir , $ source ) { $ components = parse_url ( $ source ) ; if ( ! isset ( $ components [ 'scheme' ] ) ) { if ( \ tao_helpers_File :: securityCheck ( $ source , false ) ) { if ( file_exists ( $ basedir . $ source ) ) { return 'data:' . \ tao_helpers_File :: getMimeType ( $ basedir . $ source ) . ';' . 'base64,' . base64_encode ( file_get_contents ( $ basedir . $ source ) ) ; } else { throw new \ tao_models_classes_FileNotFoundException ( $ source ) ; } } else { throw new \ common_exception_Error ( 'Invalid source path "' . $ source . '"' ) ; } } else { return $ source ; } }
|
Verify paths and encode the file
|
50,459
|
public function import ( $ class , $ form , $ userId = null ) { try { $ uploadedFile = $ this -> fetchUploadedFile ( $ form ) ; $ resource = new core_kernel_classes_Class ( $ form instanceof Form ? $ form -> getValue ( 'classUri' ) : $ form [ 'classUri' ] ) ; try { \ helpers_TimeOutHelper :: setTimeOutLimit ( \ helpers_TimeOutHelper :: LONG ) ; $ directory = $ this -> extractArchive ( $ uploadedFile ) ; \ helpers_TimeOutHelper :: reset ( ) ; } catch ( \ Exception $ e ) { $ report = Report :: createFailure ( __ ( 'Unable to extract the archive' ) ) ; $ report -> setData ( [ 'uriResource' => '' ] ) ; return $ report ; } $ iterator = new \ RecursiveIteratorIterator ( new \ RecursiveDirectoryIterator ( $ directory , \ RecursiveDirectoryIterator :: CURRENT_AS_FILEINFO | \ RecursiveDirectoryIterator :: SKIP_DOTS ) , \ RecursiveIteratorIterator :: LEAVES_ONLY ) ; $ service = MediaService :: singleton ( ) ; $ language = $ form instanceof Form ? $ form -> getValue ( 'lang' ) : $ form [ 'lang' ] ; $ this -> directoryMap = [ rtrim ( $ directory , DIRECTORY_SEPARATOR ) => $ resource -> getUri ( ) ] ; $ report = Report :: createSuccess ( __ ( 'Media imported successfully' ) ) ; foreach ( $ iterator as $ file ) { if ( $ file -> isFile ( ) ) { $ this -> logInfo ( 'File ' . $ file -> getPathname ( ) ) ; if ( isset ( $ this -> directoryMap [ $ file -> getPath ( ) ] ) ) { $ classUri = $ this -> directoryMap [ $ file -> getPath ( ) ] ; } else { $ classUri = $ this -> createClass ( $ file -> getPath ( ) ) ; } $ mediaResourceUri = $ service -> createMediaInstance ( $ file -> getRealPath ( ) , $ classUri , $ language , $ file -> getFilename ( ) , null , $ userId ) ; $ report -> add ( Report :: createSuccess ( __ ( 'Imported %s' , substr ( $ file -> getRealPath ( ) , strlen ( $ directory ) ) ) , [ 'uriResource' => $ mediaResourceUri ] ) ) ; } } } catch ( \ Exception $ e ) { $ message = $ e instanceof \ common_exception_UserReadableException ? $ e -> getUserMessage ( ) : __ ( 'An error has occurred. Please contact your administrator.' ) ; $ report = Report :: createFailure ( $ message ) ; $ this -> logError ( $ e -> getMessage ( ) ) ; $ report -> setData ( [ 'uriResource' => '' ] ) ; } return $ report ; }
|
Starts the import based on the form values
|
50,460
|
protected function extractArchive ( $ archiveFile ) { if ( $ archiveFile instanceof File ) { if ( ! $ archiveFile -> exists ( ) ) { throw new \ common_Exception ( 'Unable to open archive ' . '/' . $ archiveFile -> getPrefix ( ) ) ; } $ tmpDir = \ tao_helpers_File :: createTempDir ( ) ; $ tmpFilePath = $ tmpDir . uniqid ( 'sharedStimulus-import' ) . '.zip' ; $ tmpFile = fopen ( $ tmpFilePath , 'w' ) ; $ originalPackage = $ archiveFile -> readStream ( ) ; stream_copy_to_stream ( $ originalPackage , $ tmpFile ) ; fclose ( $ originalPackage ) ; fclose ( $ tmpFile ) ; $ archiveFile = $ tmpFilePath ; } $ archiveDir = \ tao_helpers_File :: createTempDir ( ) ; $ archiveObj = new \ ZipArchive ( ) ; if ( $ archiveFile instanceof File ) { $ tmpName = \ tao_helpers_File :: concat ( [ \ tao_helpers_File :: createTempDir ( ) , $ archiveFile -> getBasename ( ) ] ) ; if ( ( $ resource = fopen ( $ tmpName , 'wb' ) ) !== false ) { stream_copy_to_stream ( $ archiveFile -> readStream ( ) , $ resource ) ; fclose ( $ resource ) ; } $ archiveFile = $ tmpName ; } $ archiveHandle = $ archiveObj -> open ( $ archiveFile ) ; if ( true !== $ archiveHandle ) { throw new \ common_Exception ( 'Unable to open archive ' . $ archiveFile ) ; } if ( \ tao_helpers_File :: checkWhetherArchiveIsBomb ( $ archiveObj ) ) { throw new \ common_Exception ( sprintf ( 'Source "%s" seems to be a ZIP bomb' , $ archiveFile ) ) ; } if ( ! $ archiveObj -> extractTo ( $ archiveDir ) ) { $ archiveObj -> close ( ) ; throw new \ common_Exception ( 'Unable to extract to ' . $ archiveDir ) ; } $ archiveObj -> close ( ) ; if ( isset ( $ tmpFilePath ) && file_exists ( $ tmpFilePath ) ) { unlink ( $ tmpFilePath ) ; } if ( isset ( $ tmpDir ) && file_exists ( $ tmpDir ) ) { rmdir ( $ tmpDir ) ; } return $ archiveDir ; }
|
Unzip archive from the upload form
|
50,461
|
protected function init ( ) { $ structure = $ this -> imapFetchstructure ( ) ; $ this -> structure = $ structure ; if ( isset ( $ structure -> parts ) ) { $ countSection = count ( $ structure -> parts ) ; $ this -> countAttachment = $ countSection - 1 ; } $ this -> getCountSection ( ) ; $ this -> getHeader ( ) ; $ this -> getAttachments ( ) ; $ this -> getBody ( ) ; if ( $ this -> _decode === self :: DECODE ) { $ this -> decode ( ) ; } }
|
Main process .
|
50,462
|
protected function getHeader ( ) { $ header = $ this -> imapFetchOverview ( ) ; $ this -> header = $ header [ 0 ] ; $ this -> header -> details = $ this -> imapHeaderInfo ( ) ; }
|
Get headers in the current message .
|
50,463
|
protected function getCountSection ( ) { $ this -> getRecursiveSections ( $ this -> structure ) ; $ sections = array ( ) ; if ( ! isset ( $ this -> section ) ) { $ this -> section [ 0 ] = array ( 0 ) ; } foreach ( $ this -> section as $ array ) { foreach ( $ array as $ section ) { $ sections [ ] = $ section ; } } $ sections = array_unique ( $ sections ) ; sort ( $ sections ) ; $ this -> section = $ sections ; return $ this -> section ; }
|
Get count section .
|
50,464
|
protected function getRecursiveSections ( $ obj , $ before = null ) { if ( ! isset ( $ obj -> parts ) ) { return ; } $ countParts = count ( $ obj -> parts ) ; $ out = array ( ) ; $ beforeSave = $ before ; foreach ( $ obj -> parts as $ key => $ subObj ) { if ( ! isset ( $ beforeSave ) ) { $ before = ( $ key + 1 ) ; } else { $ before = $ beforeSave . '.' . ( $ key + 1 ) ; } $ this -> getRecursiveSections ( $ subObj , $ before ) ; $ out [ ] = ( string ) $ before ; } $ this -> section [ ] = $ out ; }
|
Bypasses the recursive parts current message .
|
50,465
|
protected function getSections ( $ type = null ) { if ( ! $ type ) { return $ this -> section ; } $ types = null ; switch ( $ type ) { case self :: SECTION_ATTACHMENTS : $ types = TypeAttachments :: get ( ) ; break ; case self :: SECTION_BODY : $ types = TypeBody :: get ( ) ; break ; default : throw new ImapClientException ( 'Section type not recognised/supported' ) ; break ; } $ sections = array ( ) ; foreach ( $ this -> section as $ section ) { $ obj = $ this -> getSectionStructure ( $ section ) ; if ( ! isset ( $ obj -> subtype ) ) { continue ; } if ( in_array ( $ obj -> subtype , $ types , false ) ) { $ sections [ ] = $ section ; } } return $ sections ; }
|
Gets all sections or if parameter is specified sections by type .
|
50,466
|
protected function getAttachments ( ) { $ attachments = array ( ) ; foreach ( $ this -> getSections ( self :: SECTION_ATTACHMENTS ) as $ section ) { $ obj = $ this -> getSection ( $ section ) ; $ attachment = new IncomingMessageAttachment ( $ obj ) ; $ objNew = new \ stdClass ( ) ; $ objNew -> name = $ attachment -> name ; $ objNew -> body = $ attachment -> body ; $ objNew -> info = $ obj ; $ attachments [ ] = $ objNew ; } $ this -> attachments = $ attachments ; }
|
Get attachments in the current message .
|
50,467
|
protected function getBody ( ) { $ objNew = new \ stdClass ( ) ; $ i = 1 ; $ subType = new SubtypeBody ( ) ; foreach ( $ this -> getSections ( self :: SECTION_BODY ) as $ section ) { $ obj = $ this -> getSection ( $ section , array ( 'class' => $ subType ) ) ; $ subtype = strtolower ( $ obj -> __get ( 'structure' ) -> subtype ) ; if ( ! isset ( $ objNew -> $ subtype ) ) { $ objNew -> $ subtype = $ obj ; } else { $ subtype = $ subtype . '_' . $ i ; $ objNew -> $ subtype = $ obj ; $ i ++ ; } $ objNew -> info [ ] = $ obj ; $ objNew -> types [ ] = $ subtype ; foreach ( $ objNew -> $ subtype -> __get ( 'structure' ) -> parameters as $ parameter ) { $ attribute = strtolower ( $ parameter -> attribute ) ; if ( $ attribute === 'charset' ) { $ value = strtolower ( $ parameter -> value ) ; $ objNew -> $ subtype -> charset = $ value ; } } } if ( isset ( $ objNew -> plain ) ) { switch ( $ objNew -> plain -> structure -> encoding ) { case 3 : $ objNew -> text = imap_base64 ( mb_convert_encoding ( $ objNew -> plain , "utf-8" , $ objNew -> plain -> charset ) ) ; break ; default : $ objNew -> text = quoted_printable_decode ( mb_convert_encoding ( $ objNew -> plain , "utf-8" , $ objNew -> plain -> charset ) ) ; break ; } $ objNew -> types [ ] = 'text' ; } else { $ objNew -> text = null ; } $ this -> message = $ objNew ; }
|
Get body current message .
|
50,468
|
public function getSection ( $ section , $ options = null ) { if ( isset ( $ options [ 'class' ] ) ) { $ sectionObj = new $ options [ 'class' ] ( ) ; if ( $ sectionObj instanceof Section ) { } else { throw new ImapClientException ( 'Incoming class not instance \SSilence\ImapClient\Section' ) ; } } else { $ sectionObj = new Section ( ) ; } if ( $ section === 0 ) { $ sectionObj -> structure = $ this -> imapBodystruct ( 1 ) ; $ sectionObj -> body = $ this -> imapFetchbody ( 1 ) ; } else { $ sectionObj -> structure = $ this -> imapBodystruct ( $ section ) ; $ sectionObj -> body = $ this -> imapFetchbody ( $ section ) ; } return $ sectionObj ; }
|
Get a section message .
|
50,469
|
protected function getSectionStructureFromIncomingStructure ( $ section ) { $ pos = strpos ( $ section , '.' ) ; if ( $ pos === false ) { $ section = ( int ) $ section ; if ( $ section === 0 ) { return $ this -> structure ; } return $ this -> structure -> parts [ ( $ section - 1 ) ] ; } $ sections = explode ( '.' , $ section ) ; $ count = count ( $ sections ) ; $ outObject = null ; foreach ( $ sections as $ section ) { $ section = ( int ) $ section ; if ( ! isset ( $ outObject ) ) { $ outObject = $ this -> getObjectStructureFromParts ( $ this -> structure , ( $ section - 1 ) ) ; } else { $ outObject = $ this -> getObjectStructureFromParts ( $ outObject , ( $ section - 1 ) ) ; } } return $ outObject ; }
|
Get section structure from incoming structure .
|
50,470
|
protected function imapFetchOverview ( ) { if ( isset ( $ this -> id ) && isset ( $ this -> uid ) ) { throw new ImapClientException ( 'What to use id or uid?' ) ; } $ sequence = null ; $ options = null ; if ( isset ( $ this -> id ) && ! isset ( $ this -> uid ) ) { $ sequence = $ this -> id ; $ options = null ; } if ( ! isset ( $ this -> id ) && isset ( $ this -> uid ) ) { $ sequence = $ this -> uid ; $ options = FT_UID ; } return imap_fetch_overview ( $ this -> imapStream , $ sequence , $ options ) ; }
|
Fetch a quick Overview on a message .
|
50,471
|
protected function decodeHeader ( ) { if ( isset ( $ this -> header -> subject ) ) { $ this -> header -> subject = $ this -> mimeHeaderDecode ( $ this -> header -> subject ) ; } if ( isset ( $ this -> header -> details -> subject ) ) { $ this -> header -> details -> subject = $ this -> mimeHeaderDecode ( $ this -> header -> details -> subject ) ; } if ( isset ( $ this -> header -> details -> Subject ) ) { $ this -> header -> details -> Subject = $ this -> mimeHeaderDecode ( $ this -> header -> details -> Subject ) ; } if ( isset ( $ this -> header -> from ) ) { $ this -> header -> from = $ this -> mimeHeaderDecode ( $ this -> header -> from ) ; } if ( isset ( $ this -> header -> to ) ) { $ this -> header -> to = $ this -> mimeHeaderDecode ( $ this -> header -> to ) ; } }
|
Decode header .
|
50,472
|
protected function decodeAttachments ( ) { foreach ( $ this -> attachments as $ key => $ attachment ) { switch ( $ attachment -> info -> structure -> encoding ) { case 3 : $ this -> attachments [ $ key ] -> body = imap_base64 ( $ attachment -> body ) ; break ; case 4 : $ this -> attachments [ $ key ] -> body = quoted_printable_decode ( $ attachment -> body ) ; break ; } $ this -> attachments [ $ key ] -> name = $ this -> mimeHeaderDecode ( $ attachment -> name ) ; } }
|
Decode attachments .
|
50,473
|
protected function decodeBody ( ) { if ( is_object ( $ this -> message ) ) { foreach ( $ this -> message -> types as $ typeMessage ) { if ( is_object ( $ this -> message -> $ typeMessage ) ) { switch ( $ this -> message -> $ typeMessage -> structure -> encoding ) { case 3 : $ this -> message -> $ typeMessage -> body = imap_base64 ( $ this -> message -> $ typeMessage -> body ) ; break ; case 4 : $ this -> message -> $ typeMessage -> body = imap_qprint ( $ this -> message -> $ typeMessage -> body ) ; break ; } } if ( is_object ( $ this -> message -> $ typeMessage ) ) { if ( $ this -> message -> $ typeMessage -> charset ) { $ this -> message -> $ typeMessage -> body = $ this -> convertToUtf8 ( $ this -> message -> $ typeMessage -> body , $ this -> message -> $ typeMessage -> charset ) ; } } } } }
|
Decode body .
|
50,474
|
public function prepareMailbox ( $ remote_system_name = null , $ port = null , $ flags = null , $ mailbox_name = null ) { if ( isset ( $ remote_system_name ) && is_array ( $ remote_system_name ) ) { $ config = $ remote_system_name ; if ( isset ( $ config [ 'remote_system_name' ] ) ) { $ remote_system_name = $ config [ 'remote_system_name' ] ; } else { $ remote_system_name = null ; } ; if ( isset ( $ config [ 'port' ] ) ) { $ port = $ config [ 'port' ] ; } else { $ port = null ; } ; if ( isset ( $ config [ 'flags' ] ) ) { $ flags = $ config [ 'flags' ] ; } else { $ flags = null ; } ; if ( isset ( $ config [ 'mailbox_name' ] ) ) { $ mailbox_name = $ config [ 'mailbox_name' ] ; } else { $ mailbox_name = null ; } ; } ; if ( ! isset ( $ remote_system_name ) && isset ( $ this -> mailbox ) ) { $ remote_system_name = $ this -> mailbox ; } ; if ( empty ( $ remote_system_name ) ) { throw new ImapClientException ( 'Mailbox is not installed' ) ; } ; if ( isset ( $ port ) ) { $ port = ':' . $ port ; } ; if ( ! isset ( $ flags ) && isset ( $ this -> flags ) ) { $ flags = $ this -> flags ; } ; $ this -> mailbox = '{' . $ remote_system_name . $ port . $ flags . '}' . $ mailbox_name ; }
|
Prepare Mailbox string
|
50,475
|
public function send ( ) { $ mimeMessage = $ this -> createMimeMessage ( ) ; $ this -> message = $ mimeMessage ; $ this -> preparingSend ( ) ; imap_mail ( $ this -> properties -> to , $ this -> properties -> subject , $ this -> properties -> message , $ this -> properties -> additional_headers , $ this -> properties -> cc , $ this -> properties -> bcc , $ this -> properties -> rpath ) ; }
|
Send message via imap_mail .
|
50,476
|
public function createMimeMessage ( ) { $ this -> createBody ( ) ; $ envelopeAllowedType = array ( 'remail' , 'return_path' , 'date' , 'from' , 'reply_to' , 'in_reply_to' , 'subject' , 'to' , 'cc' , 'bcc' , 'message_id' , 'custom_headers' , ) ; $ envelope = Helper :: preparingProperties ( $ this -> envelope , $ envelopeAllowedType , Helper :: OUT_ARRAY ) ; $ bodyAllowedType = array ( 'type' , 'encoding' , 'charset' , 'type.parameters' , 'subtype' , 'id' , 'description' , 'disposition.type' , 'disposition' , 'contents.data' , 'lines' , 'bytes' , 'md5' , ) ; foreach ( $ this -> body as $ key => $ part ) { $ this -> body [ $ key ] = Helper :: preparingProperties ( $ part , $ bodyAllowedType , Helper :: OUT_ARRAY ) ; } $ body = $ this -> body ; return imap_mail_compose ( $ envelope , $ body ) ; }
|
Create Mime Message .
|
50,477
|
public function createBody ( ) { $ this -> envelope [ 'date' ] = '29.03.2017' ; $ this -> envelope [ 'message_id' ] = '81' ; $ part1 [ 'type' ] = TYPEMULTIPART ; $ part1 [ 'subtype' ] = 'mixed' ; $ part3 [ 'type' ] = TYPETEXT ; $ part3 [ 'subtype' ] = 'plain' ; $ part3 [ 'description' ] = 'description3' ; $ part3 [ 'contents.data' ] = "contents.data3\n\n\n\t" ; $ body [ 1 ] = $ part1 ; $ body [ 3 ] = $ part3 ; $ this -> body = $ body ; }
|
Create body .
|
50,478
|
protected function getName ( ) { if ( $ this -> _incomingObject -> structure -> ifdparameters ) { foreach ( $ this -> _incomingObject -> structure -> dparameters as $ param ) { if ( strtolower ( $ param -> attribute ) === 'filename' ) { $ this -> name = $ param -> value ; break ; } } } elseif ( $ this -> _incomingObject -> structure -> ifparameters ) { foreach ( $ this -> _incomingObject -> structure -> parameters as $ param ) { if ( strtolower ( $ param -> attribute ) === 'name' ) { $ this -> name = $ param -> value ; break ; } } } }
|
Returns the name of the attachment along with file extension .
|
50,479
|
public function connectDefault ( $ mailbox , $ username , $ password , $ encryption = null ) { $ connect = new ImapConnect ( ) ; if ( $ encryption === ImapClient :: ENCRYPT_SSL ) { $ connect -> prepareFlags ( ImapConnect :: SERVICE_IMAP , ImapConnect :: ENCRYPT_SSL , ImapConnect :: NOVALIDATE_CERT ) ; } ; if ( $ encryption === ImapClient :: ENCRYPT_TLS ) { $ connect -> prepareFlags ( ImapConnect :: SERVICE_IMAP , ImapConnect :: ENCRYPT_TLS , ImapConnect :: NOVALIDATE_CERT ) ; } ; $ connect -> prepareMailbox ( $ mailbox ) ; $ connect -> connect ( null , $ username , $ password ) ; $ this -> imap = $ connect -> getImap ( ) ; $ this -> mailbox = $ connect -> getMailbox ( ) ; }
|
The default connection . Not used a lot of imap connection options . Use only ENCRYPT_SSL and VALIDATE_CERT .
|
50,480
|
public function getFolders ( $ separator = null , $ type = 0 ) { if ( preg_match ( '/^{.+}/' , $ this -> mailbox , $ matches ) ) { $ mailbox = $ matches [ 0 ] ; } else { $ mailbox = $ this -> mailbox ; } ; $ folders = imap_list ( $ this -> imap , $ mailbox , "*" ) ; if ( $ type == 2 ) { return $ folders ; } ; if ( $ type == 1 ) { return str_replace ( $ mailbox , "" , $ folders ) ; } ; if ( $ type == 0 ) { $ arrayRaw = str_replace ( $ mailbox , "" , $ folders ) ; if ( ! isset ( $ separator ) ) { $ separator = '.' ; } ; $ arrayNew = [ ] ; foreach ( $ arrayRaw as $ string ) { $ array = explode ( $ separator , $ string ) ; $ count = count ( $ array ) ; $ count = $ count - 1 ; $ cache = false ; for ( $ i = $ count ; $ i >= 0 ; $ i -- ) { if ( $ i == $ count ) { $ cache = [ $ array [ $ i ] => [ ] ] ; } else { $ cache = [ $ array [ $ i ] => $ cache ] ; } ; } ; $ arrayNew = array_merge_recursive ( $ arrayNew , $ cache ) ; } ; return $ arrayNew ; } return null ; }
|
Returns all available folders
|
50,481
|
public function getBriefInfoMessages ( ) { $ array = imap_headers ( $ this -> imap ) ; $ newArray = [ ] ; foreach ( $ array as $ key => $ string ) { $ newArray [ ] = [ 'id' => $ key + 1 , 'info' => $ string ] ; } ; return $ newArray ; }
|
Returns an array of brief information about each message in the current mailbox .
|
50,482
|
public function getMessagesByCriteria ( $ criteria = '' , $ number = 0 , $ start = 0 , $ order = 'DESC' ) { $ emails = array ( ) ; $ result = imap_search ( $ this -> imap , $ criteria ) ; if ( ! $ result ) { throw new ImapClientException ( 'Messages not found. Or this criteria not supported on your email server.' ) ; } ; if ( $ number == 0 ) { $ number = count ( $ result ) ; } if ( $ result ) { $ ids = array ( ) ; foreach ( $ result as $ k => $ i ) { $ ids [ ] = $ i ; } $ ids = array_chunk ( $ ids , $ number ) ; $ ids = array_slice ( $ ids [ 0 ] , $ start , $ number ) ; $ emails = array ( ) ; foreach ( $ ids as $ id ) { $ emails [ ] = $ this -> getMessage ( $ id ) ; } } if ( $ order == 'DESC' ) { $ emails = array_reverse ( $ emails ) ; } return $ emails ; }
|
Get Messages by Criteria
|
50,483
|
public function saveAttachmentsMessagesBySubject ( $ subject , $ dir = null , $ charset = null ) { $ criteria = 'SUBJECT "' . $ subject . '"' ; $ ids = imap_search ( $ this -> imap , $ criteria , null , $ charset ) ; if ( ! $ ids ) { throw new ImapClientException ( 'Messages not found. Or this criteria not supported on your email server.' ) ; } ; foreach ( $ ids as $ id ) { $ this -> getMessage ( $ id ) ; if ( isset ( $ dir ) ) { $ dir = [ 'dir' => $ dir ] ; } ; $ this -> saveAttachments ( $ dir ) ; } ; }
|
Save Attachments Messages By Subject
|
50,484
|
public function getMessage ( $ id , $ decode = IncomingMessage :: DECODE ) { $ this -> checkMessageId ( $ id ) ; $ this -> incomingMessage = new IncomingMessage ( $ this -> imap , $ id , $ decode ) ; return $ this -> incomingMessage ; }
|
Returns one email by given id
|
50,485
|
public function getSection ( $ id , $ section ) { $ incomingMessage = new IncomingMessage ( $ this -> imap , $ id ) ; return $ incomingMessage -> getSection ( $ section ) ; }
|
Get a section of the message
|
50,486
|
public function saveAttachments ( $ options = null ) { if ( ! isset ( $ options [ 'dir' ] ) ) { $ dir = __DIR__ . DIRECTORY_SEPARATOR ; } else { $ dir = $ options [ 'dir' ] ; } ; if ( ! isset ( $ options [ 'incomingMessage' ] ) ) { $ incomingMessage = $ this -> incomingMessage ; } else { $ incomingMessage = $ options [ 'incomingMessage' ] ; } ; foreach ( $ incomingMessage -> attachments as $ key => $ attachment ) { $ newFileName = $ attachment -> name ; file_put_contents ( $ dir . DIRECTORY_SEPARATOR . $ newFileName , $ attachment -> body ) ; } ; }
|
Save attachments one incoming message
|
50,487
|
public function moveMessages ( $ ids , $ target ) { if ( imap_mail_move ( $ this -> imap , implode ( "," , $ ids ) , $ target , CP_UID ) === false ) return false ; return imap_expunge ( $ this -> imap ) ; }
|
Move given message in new folder
|
50,488
|
public function addFolder ( $ name , $ subscribe = false ) { $ success = imap_createmailbox ( $ this -> imap , $ this -> mailbox . $ name ) ; if ( $ success && $ subscribe ) { $ success = imap_subscribe ( $ this -> imap , $ this -> mailbox . $ name ) ; } return $ success ; }
|
Add a new folder
|
50,489
|
public function renameFolder ( $ name , $ newname ) { return imap_renamemailbox ( $ this -> imap , $ this -> mailbox . $ name , $ this -> mailbox . $ newname ) ; }
|
Rename a folder
|
50,490
|
public function purge ( ) { if ( $ this -> folder == $ this -> getTrash ( ) || strtolower ( $ this -> folder ) == "spam" ) { if ( imap_delete ( $ this -> imap , '1:*' ) === false ) { return false ; } return imap_expunge ( $ this -> imap ) ; } else { if ( imap_mail_move ( $ this -> imap , '1:*' , $ this -> getTrash ( ) ) == false ) { return false ; } return imap_expunge ( $ this -> imap ) ; } }
|
Clean up trash and spam folder
|
50,491
|
public function getAllEmailAddresses ( ) { $ saveCurrentFolder = $ this -> folder ; $ emails = array ( ) ; foreach ( $ this -> getFolders ( ) as $ folder ) { $ this -> selectFolder ( $ folder ) ; foreach ( $ this -> getMessages ( false ) as $ message ) { $ emails [ ] = $ message [ 'from' ] ; $ emails = array_merge ( $ emails , $ message [ 'to' ] ) ; if ( isset ( $ message [ 'cc' ] ) ) { $ emails = array_merge ( $ emails , $ message [ 'cc' ] ) ; } } } $ this -> selectFolder ( $ saveCurrentFolder ) ; return array_unique ( $ emails ) ; }
|
Returns all email addresses
|
50,492
|
public function saveMessageInSent ( $ header , $ body ) { return imap_append ( $ this -> imap , $ this -> mailbox . $ this -> getSent ( ) , $ header . "\r\n" . $ body . "\r\n" , "\\Seen" ) ; }
|
Save email in sent
|
50,493
|
protected function getTrash ( ) { foreach ( $ this -> getFolders ( ) as $ folder ) { if ( in_array ( strtolower ( $ folder ) , array ( 'trash' , 'inbox.trash' , 'papierkorb' ) ) ) { return $ folder ; } } $ this -> addFolder ( 'Trash' ) ; return 'Trash' ; }
|
Get trash folder
|
50,494
|
protected function getMessageHeader ( $ id ) { $ count = $ this -> countMessages ( ) ; for ( $ i = 1 ; $ i <= $ count ; $ i ++ ) { $ uid = imap_uid ( $ this -> imap , $ i ) ; if ( $ uid == $ id ) { $ header = imap_headerinfo ( $ this -> imap , $ i ) ; return $ header ; } } return false ; }
|
Fetch message by id
|
50,495
|
protected function toAddress ( $ headerinfos ) { $ email = "" ; $ name = "" ; if ( isset ( $ headerinfos -> mailbox ) && isset ( $ headerinfos -> host ) ) { $ email = $ headerinfos -> mailbox . "@" . $ headerinfos -> host ; } if ( ! empty ( $ headerinfos -> personal ) ) { $ name = imap_mime_header_decode ( $ headerinfos -> personal ) ; $ name = $ name [ 0 ] -> text ; } else { $ name = $ email ; } $ name = $ this -> convertToUtf8 ( $ name ) ; return $ name . " <" . $ email . ">" ; }
|
Convert imap given address into string
|
50,496
|
protected function arrayToAddress ( $ addresses ) { $ addressesAsString = array ( ) ; foreach ( $ addresses as $ address ) { $ addressesAsString [ ] = $ this -> toAddress ( $ address ) ; } return $ addressesAsString ; }
|
Converts imap given array of addresses as strings
|
50,497
|
protected function embedImages ( $ email ) { $ html_embed = $ email [ 'body' ] ; foreach ( $ email [ 'attachments' ] as $ key => $ attachment ) { if ( strtolower ( $ attachment [ 'disposition' ] ) == 'inline' && ! empty ( $ attachment [ 'reference' ] ) ) { $ file = $ this -> getAttachment ( $ email [ 'id' ] , $ key ) ; $ reference = str_replace ( array ( "<" , ">" ) , "" , $ attachment [ 'reference' ] ) ; $ img_embed = "data:image/" . strtolower ( $ file [ 'type' ] ) . ";base64," . base64_encode ( $ file [ 'content' ] ) ; $ html_embed = str_replace ( "cid:" . $ reference , $ img_embed , $ html_embed ) ; } } return $ html_embed ; }
|
HTML embed inline images
|
50,498
|
public function getUnreadMessages ( $ read = true ) { $ emails = [ ] ; $ result = imap_search ( $ this -> imap , 'UNSEEN' ) ; if ( ! $ result ) { throw new ImapClientException ( 'No read messages were found.' ) ; } ; $ ids = '' ; $ countId = count ( $ result ) ; foreach ( $ result as $ key => $ id ) { $ emails [ ] = $ this -> getMessage ( $ id ) ; if ( ( $ countId - 1 ) == $ key ) { $ ids .= $ id ; } else { $ ids .= $ id . ',' ; } ; } if ( ! $ read ) { $ this -> setUnseenMessage ( $ ids ) ; } else { $ this -> setSeenMessage ( $ ids ) ; } ; return $ emails ; }
|
Returns unseen emails in the current folder
|
50,499
|
public function getAllEmailAddresses ( array $ options = null ) { if ( ! isset ( $ options [ 'getFolders' ] [ 'separator' ] ) ) { $ options [ 'getFolders' ] [ 'separator' ] = '.' ; } ; if ( ! isset ( $ options [ 'getFolders' ] [ 'type' ] ) ) { $ options [ 'getFolders' ] [ 'type' ] = 1 ; } ; if ( ! isset ( $ options [ 'mark' ] ) ) { $ options [ 'mark' ] = 'SEEN' ; } ; $ saveCurrentFolder = $ this -> folder ; $ emails = array ( ) ; foreach ( $ this -> getFolders ( $ options [ 'getFolders' ] [ 'separator' ] , $ options [ 'getFolders' ] [ 'type' ] ) as $ folder ) { $ this -> selectFolder ( $ folder ) ; foreach ( $ this -> getMessages ( ) as $ message ) { $ emails [ ] = $ message -> header -> from ; $ emails = array_merge ( $ emails , $ message -> header -> to ) ; if ( isset ( $ message -> header -> details -> cc ) ) { $ emails = array_merge ( $ emails , $ message -> header -> details -> cc ) ; } ; if ( isset ( $ options [ 'mark' ] ) && $ options [ 'mark' ] == 'UNSEEN' ) { $ this -> setUnseenMessage ( $ message -> header -> msgno ) ; } ; } } $ this -> selectFolder ( $ saveCurrentFolder ) ; return array_unique ( $ emails ) ; }
|
Returns all email addresses in all folders
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.