author | ymh <ymh.work@gmail.com> |
Fri, 05 Sep 2025 18:52:52 +0200 | |
changeset 22 | 8c2e4d02f4ef |
parent 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* Parse OPML XML files and store in globals. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Administration |
|
7 |
*/ |
|
8 |
||
9 | 9 |
if ( ! defined( 'ABSPATH' ) ) { |
0 | 10 |
die(); |
9 | 11 |
} |
0 | 12 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
13 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
* @global string $opml |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
15 |
*/ |
5 | 16 |
global $opml; |
0 | 17 |
|
18 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
16
diff
changeset
|
19 |
* Starts a new XML tag. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
16
diff
changeset
|
20 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
16
diff
changeset
|
21 |
* Callback function for xml_set_element_handler(). |
0 | 22 |
* |
23 |
* @since 0.71 |
|
24 |
* @access private |
|
25 |
* |
|
26 |
* @global array $names |
|
27 |
* @global array $urls |
|
28 |
* @global array $targets |
|
29 |
* @global array $descriptions |
|
30 |
* @global array $feeds |
|
31 |
* |
|
16 | 32 |
* @param resource $parser XML Parser resource. |
33 |
* @param string $tag_name XML element name. |
|
34 |
* @param array $attrs XML element attributes. |
|
0 | 35 |
*/ |
16 | 36 |
function startElement( $parser, $tag_name, $attrs ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid |
0 | 37 |
global $names, $urls, $targets, $descriptions, $feeds; |
38 |
||
16 | 39 |
if ( 'OUTLINE' === $tag_name ) { |
5 | 40 |
$name = ''; |
41 |
if ( isset( $attrs['TEXT'] ) ) { |
|
42 |
$name = $attrs['TEXT']; |
|
43 |
} |
|
44 |
if ( isset( $attrs['TITLE'] ) ) { |
|
45 |
$name = $attrs['TITLE']; |
|
46 |
} |
|
47 |
$url = ''; |
|
48 |
if ( isset( $attrs['URL'] ) ) { |
|
49 |
$url = $attrs['URL']; |
|
50 |
} |
|
51 |
if ( isset( $attrs['HTMLURL'] ) ) { |
|
52 |
$url = $attrs['HTMLURL']; |
|
0 | 53 |
} |
54 |
||
5 | 55 |
// Save the data away. |
9 | 56 |
$names[] = $name; |
57 |
$urls[] = $url; |
|
58 |
$targets[] = isset( $attrs['TARGET'] ) ? $attrs['TARGET'] : ''; |
|
59 |
$feeds[] = isset( $attrs['XMLURL'] ) ? $attrs['XMLURL'] : ''; |
|
60 |
$descriptions[] = isset( $attrs['DESCRIPTION'] ) ? $attrs['DESCRIPTION'] : ''; |
|
5 | 61 |
} // End if outline. |
0 | 62 |
} |
63 |
||
64 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
16
diff
changeset
|
65 |
* Ends a new XML tag. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
16
diff
changeset
|
66 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
16
diff
changeset
|
67 |
* Callback function for xml_set_element_handler(). |
0 | 68 |
* |
69 |
* @since 0.71 |
|
70 |
* @access private |
|
71 |
* |
|
16 | 72 |
* @param resource $parser XML Parser resource. |
73 |
* @param string $tag_name XML tag name. |
|
0 | 74 |
*/ |
16 | 75 |
function endElement( $parser, $tag_name ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid |
5 | 76 |
// Nothing to do. |
0 | 77 |
} |
78 |
||
16 | 79 |
// Create an XML parser. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
80 |
if ( ! function_exists( 'xml_parser_create' ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
16
diff
changeset
|
81 |
wp_trigger_error( '', __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
82 |
wp_die( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
83 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
84 |
|
0 | 85 |
$xml_parser = xml_parser_create(); |
86 |
||
16 | 87 |
// Set the functions to handle opening and closing tags. |
9 | 88 |
xml_set_element_handler( $xml_parser, 'startElement', 'endElement' ); |
0 | 89 |
|
5 | 90 |
if ( ! xml_parse( $xml_parser, $opml, true ) ) { |
91 |
printf( |
|
16 | 92 |
/* translators: 1: Error message, 2: Line number. */ |
5 | 93 |
__( 'XML Error: %1$s at line %2$s' ), |
94 |
xml_error_string( xml_get_error_code( $xml_parser ) ), |
|
95 |
xml_get_current_line_number( $xml_parser ) |
|
96 |
); |
|
0 | 97 |
} |
98 |
||
16 | 99 |
// Free up memory used by the XML parser. |
9 | 100 |
xml_parser_free( $xml_parser ); |
16 | 101 |
unset( $xml_parser ); |