Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions includes/class-opml.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ private static function group_name( $group ) {
* @param string $page_title Title of the page, see title().
* @return string Title.
*/
private static function group_title( $group, $page_title ) {
public static function group_title( $group, $page_title ) {
/* translators: 1: name of the blogroll, 2: page title with author */
return \sprintf( \__( '%1$s (%2$s)', 'blockroll' ), self::group_name( $group ), $page_title );
}
Expand Down Expand Up @@ -392,7 +392,7 @@ public static function for_post( $post, $anchor = '' ) {
}

/**
* Print the directory OPML listing every blogroll page's own OPML.
* Print the directory OPML listing each listed blogroll's OPML.
*
* @param \WP_Post[]|null $posts Blogroll posts, or null to look them up.
*/
Expand Down
6 changes: 4 additions & 2 deletions templates/opml-directory.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Directory OPML listing all blogroll pages.
* Directory OPML listing each listed blogroll.
*
* @package Blockroll
*
Expand Down Expand Up @@ -37,7 +37,9 @@
</head>
<body>
<?php foreach ( $args['posts'] as $blockroll_post ) : ?>
<outline text="<?php echo esc_xml( \Blockroll\Opml::title( $blockroll_post ) ); ?>" type="include" url="<?php echo esc_url( \Blockroll\Opml::opml_url( $blockroll_post ) ); ?>" />
<?php foreach ( \Blockroll\Opml::listed_groups( $blockroll_post ) as $blockroll_group ) : ?>
<outline text="<?php echo esc_xml( $blockroll_group['own_file'] ? \Blockroll\Opml::group_title( $blockroll_group, \Blockroll\Opml::title( $blockroll_post ) ) : \Blockroll\Opml::title( $blockroll_post ) ); ?>" type="include" url="<?php echo esc_url( \Blockroll\Opml::group_url( $blockroll_post, $blockroll_group ) ); ?>" />
<?php endforeach; ?>
<?php endforeach; ?>
</body>
</opml>
31 changes: 31 additions & 0 deletions tests/test-opml.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,37 @@ public function test_singular_without_block_has_no_discovery_link() {

const TWO_ANCHORED_BLOCKS = '<!-- wp:blockroll/blogroll {"anchor":"blogs","metadata":{"name":"Blogs"},"links":[{"url":"https://a.example/","name":"A","feedUrl":"https://a.example/feed/"}]} /--><!-- wp:blockroll/blogroll {"anchor":"podcasts","metadata":{"name":"Podcasts"},"links":[{"url":"https://b.example/","name":"B","feedUrl":"https://b.example/feed/"}]} /-->';

public function test_directory_lists_individual_blogrolls_instead_of_the_page_file() {
$post = self::factory()->post->create_and_get( array( 'post_content' => self::TWO_ANCHORED_BLOCKS ) );
ob_start();
\Blockroll\Opml::directory();
$doc = new SimpleXMLElement( ob_get_clean() );

$this->assertCount( 2, $doc->body->outline );
foreach ( array(
'blogs' => 'Blogs',
'podcasts' => 'Podcasts',
) as $anchor => $name ) {
$outline = $doc->body->outline[ 'blogs' === $anchor ? 0 : 1 ];
$this->assertSame( 'include', (string) $outline['type'] );
$this->assertSame( \Blockroll\Opml::opml_url( $post, $anchor ), (string) $outline['url'] );
$this->assertStringStartsWith( $name . ' (', (string) $outline['text'] );
$this->assertStringContainsString( \Blockroll\Opml::title( $post ), (string) $outline['text'] );
}
}

public function test_directory_derives_missing_anchors_and_excludes_unlisted_blogrolls() {
$content = self::TWO_NAMED_BLOCKS . self::OWN_ONLY;
$post = self::factory()->post->create_and_get( array( 'post_content' => $content ) );
ob_start();
\Blockroll\Opml::directory();
$doc = new SimpleXMLElement( ob_get_clean() );

$this->assertCount( 2, $doc->body->outline );
$this->assertSame( \Blockroll\Opml::opml_url( $post, 'blogs' ), (string) $doc->body->outline[0]['url'] );
$this->assertSame( \Blockroll\Opml::opml_url( $post, 'podcasts' ), (string) $doc->body->outline[1]['url'] );
}

public function test_all_groups_keeps_the_anchor_and_derives_a_missing_one() {
$post = self::factory()->post->create_and_get( array( 'post_content' => self::TWO_ANCHORED_BLOCKS ) );
$groups = \Blockroll\Opml::all_groups( $post );
Expand Down
Loading