Skip to content

Commit d613fd8

Browse files
authored
Merge pull request #13 from dshanske/dec19fixes
Refactor and Update of Plugin
2 parents e159897 + 29901d2 commit d613fd8

File tree

11 files changed

+406
-376
lines changed

11 files changed

+406
-376
lines changed

.travis.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ matrix:
2626
- php: 5.6
2727
- php: 5.6
2828
env: WP_PULUGIN_DEPLOY=1
29-
- php: 5.5
30-
- php: 5.4
31-
- php: 5.3
32-
dist: precise
3329
before_script:
3430
- |
3531
# Remove Xdebug for a huge performance increase:

includes/class-mf2-feed-entry.php

Lines changed: 26 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class Mf2_Feed_Entry {
1111
public $type;
1212
public $name;
1313
public $url;
14+
public $uid;
1415
public $author = array();
1516
public $published;
1617
public $updated;
@@ -26,15 +27,23 @@ public function __construct( $post, $with_comments = false ) {
2627
return false;
2728
}
2829

29-
$this->_id = $post->ID;
30-
$this->type = 'entry';
31-
$this->name = $post->post_name;
32-
$this->published = mysql2date( DATE_W3C, $post->post_date );
33-
$this->updated = mysql2date( DATE_W3C, $post->post_modified );
34-
$this->content['html'] = $this->get_content_by_id( $post->ID );
35-
$this->content['value'] = wp_strip_all_tags( $post->post_content );
36-
$this->summary = $this->get_excerpt_by_id( $post->ID );
37-
$this->url = get_permalink( $post->ID );
30+
$this->_id = $post->ID;
31+
$this->type = 'entry';
32+
$this->name = get_the_title( $post );
33+
// Eliminate IDs as names
34+
if ( $this->name = $this->_id ) {
35+
$this->name = null;
36+
}
37+
$this->published = get_post_time( DATE_W3C, false, $post );
38+
$this->updated = get_post_modified_time( DATE_W3C, false, $post );
39+
$content = get_the_content( null, false, $post );
40+
if ( ! empty( $content ) ) {
41+
$this->content['html'] = get_the_content( null, false, $post );
42+
$this->content['value'] = wp_strip_all_tags( $this->content['html'] );
43+
}
44+
$this->summary = get_the_excerpt( $post );
45+
$this->url = get_permalink( $post );
46+
$this->uid = get_permalink( $post );
3847

3948
// Get a list of categories and extract their names
4049
$post_categories = get_the_terms( $post->ID, 'category' );
@@ -63,68 +72,31 @@ public function __construct( $post, $with_comments = false ) {
6372
foreach ( get_comments( array( 'post_id' => $post->ID ) ) as $post_comment ) {
6473
$comment = array();
6574
$comment['type'] = 'cite';
66-
$comment['content']['html'] = $post_comment->comment_content;
67-
$comment['content']['value'] = wp_strip_all_tags( $post_comment->comment_content );
68-
$comment['published'] = mysql2date( DATE_W3C, $post_comment->comment_date_gmt );
75+
$comment['content']['html'] = get_comment_text( $post_comment );
76+
$comment['content']['value'] = wp_strip_all_tags( $comment['content']['html'] );
77+
$comment['published'] = get_comment_date( DATE_W3C, $post_comment );
6978
$comment['author']['type'] = 'card';
70-
$comment['author']['name'] = $post_comment->comment_author;
71-
$comment['author']['value'] = $post_comment->comment_author;
79+
$comment['author']['name'] = get_comment_author( $post_comment );
80+
$comment['author']['value'] = $comment['author']['name'];
7281

7382
if ( $post_comment->comment_author_url ) {
74-
$comment['author']['url'] = $post_comment->comment_author_url;
83+
$comment['author']['url'] = get_comment_author_url( $post_comment );
7584
}
7685

7786
$this->comment[] = $comment;
7887
}
7988
}
8089
}
8190

82-
/**
83-
* Display the post content. Optinally allows post ID to be passed
84-
* @uses the_content()
85-
*
86-
* @param int $id Optional. Post ID.
87-
* @param string $more_link_text Optional. Content for when there is more text.
88-
* @param bool $stripteaser Optional. Strip teaser content before the more text. Default is false.
89-
*/
90-
private function get_content_by_id( $post_id = 0, $more_link_text = null, $stripteaser = false ) {
91-
global $post;
92-
$post = get_post( $post_id );
93-
setup_postdata( $post, $more_link_text, $stripteaser );
94-
$content = get_the_content();
95-
wp_reset_postdata( $post );
96-
97-
return $content;
98-
}
99-
100-
/**
101-
* Display the excerpt content. Optinally allows post ID to be passed
102-
* @uses the_content()
103-
*
104-
* @param int $id Optional. Post ID.
105-
* @param string $more_link_text Optional. Content for when there is more text.
106-
* @param bool $stripteaser Optional. Strip teaser content before the more text. Default is false.
107-
*/
108-
private function get_excerpt_by_id( $post_id = 0, $more_link_text = null, $stripteaser = false ) {
109-
global $post;
110-
$post = get_post( $post_id );
111-
setup_postdata( $post, $more_link_text, $stripteaser );
112-
$content = get_the_excerpt();
113-
wp_reset_postdata( $post );
114-
115-
return $content;
116-
}
117-
11891
public function to_mf2() {
11992
$entry = apply_filters( 'jf2_entry_array', get_object_vars( $this ), $this->_id );
93+
$entry = array_filter( $entry );
12094
$entry = apply_filters( 'mf2_entry_array', $this->jf2_to_mf2( $entry ), $this->_id );
121-
122-
return array_filter( $entry );
95+
return $entry;
12396
}
12497

12598
public function to_jf2() {
12699
$entry = apply_filters( 'jf2_entry_array', get_object_vars( $this ), $this->_id );
127-
128100
return array_filter( $entry );
129101
}
130102

includes/feed-jf2-comments.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
* MF2 Feed Template for displaying an JF2 item.
4+
*
5+
* @package MF2 Feed
6+
*/
7+
8+
header( 'Content-Type: ' . feed_content_type( 'jf2' ), true );
9+
10+
require_once dirname( __FILE__ ) . '/class-mf2-feed-entry.php';
11+
$items = array();
12+
$p = get_post();
13+
if ( $p ) {
14+
$item = new Mf2_Feed_Entry( $p );
15+
$items = $item->to_jf2();
16+
}
17+
18+
// filter output
19+
$items = apply_filters( 'jf2_feed_array', $items );
20+
echo Mf2Feed::encode_json( $items );

includes/feed-jf2.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* MF2 Feed Template for displaying an JF2 feed.
4+
*
5+
* @package MF2 Feed
6+
*/
7+
8+
header( 'Content-Type: ' . feed_content_type( 'jf2feed' ), true );
9+
10+
require_once dirname( __FILE__ ) . '/class-mf2-feed-entry.php';
11+
12+
$items = array(
13+
'type' => 'feed',
14+
'name' => get_bloginfo( 'name' ),
15+
'summary' => get_bloginfo( 'description' ),
16+
'url' => get_self_link(),
17+
);
18+
if ( ! empty( $featured ) ) {
19+
$items['featured'] = $featured;
20+
}
21+
22+
while ( have_posts() ) {
23+
the_post();
24+
$item = new Mf2_Feed_Entry( get_the_ID() );
25+
$items['children'][] = $item->to_jf2();
26+
}
27+
28+
// filter output
29+
$items = apply_filters( 'jf2_feed_array', $items );
30+
echo Mf2Feed::encode_json( $items );

includes/feed-mf2-comments.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
* MF2 Feed Template for displaying an MF2 item.
4+
*
5+
* @package MF2 Feed
6+
*/
7+
8+
header( 'Content-Type: ' . feed_content_type( 'mf2' ), true );
9+
10+
require_once dirname( __FILE__ ) . '/class-mf2-feed-entry.php';
11+
$items = array();
12+
$p = get_post();
13+
if ( $p ) {
14+
$item = new Mf2_Feed_Entry( $p );
15+
$items['items'] = $item->to_mf2();
16+
}
17+
18+
// filter output
19+
$items = apply_filters( 'mf2_feed_array', $items );
20+
echo Mf2Feed::encode_json( $items );

includes/feed-mf2.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* MF2 Feed Template for displaying an MF2 feed.
4+
*
5+
* @package MF2 Feed
6+
*/
7+
8+
header( 'Content-Type: ' . feed_content_type( 'mf2' ), true );
9+
10+
require_once dirname( __FILE__ ) . '/class-mf2-feed-entry.php';
11+
$items = array(
12+
'items' => array(
13+
array(
14+
'type' => array( 'h-feed' ),
15+
'properties' => array(
16+
'name' => array( get_bloginfo( 'name' ) ),
17+
'summary' => array( get_bloginfo( 'description' ) ),
18+
'url' => array( get_self_link() ),
19+
),
20+
),
21+
),
22+
);
23+
24+
$featured = get_site_icon_url();
25+
if ( ! empty( $featured ) ) {
26+
$items['items'][0]['properties']['featured'] = array( $featured );
27+
}
28+
29+
while ( have_posts() ) {
30+
the_post();
31+
$item = new Mf2_Feed_Entry( get_the_ID() );
32+
$items['items'][0]['children'][] = current( $item->to_mf2() );
33+
}
34+
35+
// filter output
36+
$items = apply_filters( 'mf2_feed_array', $items );
37+
echo Mf2Feed::encode_json( $items );

languages/mf2-feed.pot

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
# Copyright (C) 2018 Matthias Pfefferle
1+
# Copyright (C) 2020 IndieWeb WordPress Outreach Club
22
# This file is distributed under the MIT.
33
msgid ""
44
msgstr ""
5-
"Project-Id-Version: MF2 Feed 2.1.0\n"
5+
"Project-Id-Version: MF2 Feed 3.0.0\n"
66
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/mf2-feed\n"
7-
"POT-Creation-Date: 2018-11-29 08:49:18+00:00\n"
7+
"POT-Creation-Date: 2020-01-20 08:57:09+00:00\n"
88
"MIME-Version: 1.0\n"
99
"Content-Type: text/plain; charset=utf-8\n"
1010
"Content-Transfer-Encoding: 8bit\n"
11-
"PO-Revision-Date: 2018-MO-DA HO:MI+ZONE\n"
11+
"PO-Revision-Date: 2020-MO-DA HO:MI+ZONE\n"
1212
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1313
"Language-Team: LANGUAGE <LL@li.org>\n"
1414
"X-Generator: grunt-wp-i18n1.0.2\n"
@@ -26,9 +26,9 @@ msgid "Adds a Microformats2 JSON feed for every entry"
2626
msgstr ""
2727

2828
#. Author of the plugin/theme
29-
msgid "Matthias Pfefferle"
29+
msgid "IndieWeb WordPress Outreach Club"
3030
msgstr ""
3131

3232
#. Author URI of the plugin/theme
33-
msgid "https://notiz.blog/"
33+
msgid "https://indieweb.org/WordPress_Outreach_Club"
3434
msgstr ""

0 commit comments

Comments
 (0)