33 |
37 |
Example Note
38 |
this text is displayed as the comment
39 |
40 |
in reply to caseorganic.com
41 |
42 | ```
43 |
44 | Parsed Microformats:
45 | ```json
46 | {
47 | "type": [
48 | "h-entry"
49 | ],
50 | "properties": {
51 | "author": [
52 | {
53 | "type": [
54 | "h-card"
55 | ],
56 | "properties": {
57 | "photo": [
58 | "http:\/\/aaronparecki.com\/images\/aaronpk.png"
59 | ],
60 | "name": [
61 | "Aaron Parecki"
62 | ],
63 | "url": [
64 | "http:\/\/aaronparecki.com"
65 | ]
66 | },
67 | "value": "Aaron Parecki"
68 | }
69 | ],
70 | "name": [
71 | "Example Note"
72 | ],
73 | "published": [
74 | "2014-02-16T18:48:17-0800"
75 | ],
76 | "in-reply-to": [
77 | "http:\/\/caseorganic.com\/post\/1"
78 | ],
79 | "content": [
80 | {
81 | "html": "this text is displayed as the comment",
82 | "value": "this text is displayed as the comment"
83 | }
84 | ]
85 | }
86 | }
87 | ```
88 |
89 | Parse for comment display:
90 |
91 | ```php
92 | $result = IndieWeb\comments\parse($input, $refURL, $maxLength, $maxLines);
93 | ```
94 |
95 | Resulting PHP array:
96 |
97 | ```php
98 | $result = array(
99 | 'type' => 'reply',
100 | 'author' => array(
101 | 'name' => 'Aaron Parecki',
102 | 'photo' => 'http://aaronparecki.com/images/aaronpk.png',
103 | 'url' => 'http://aaronparecki.com/'
104 | ),
105 | 'published' => '2014-02-16T18:48:17-0800',
106 | 'name' => 'Example Note',
107 | 'text' => 'this text is displayed as the comment',
108 | 'url' => 'http://aaronparecki.com/post/1'
109 | )
110 | ```
111 |
112 | This function will return an array with all of the keys above. One or more values may
113 | be empty depending on what information was available in the post, such as author name/photo.
114 |
115 | The `text` property will always be within your maximum desired length as passed to the `parse()` function.
116 |
117 | The function follows the algorithm described at [comments-presentation](http://indiewebcamp.com/comments-presentation#How_to_display)
118 | for deciding whether to show the `p-name`, `p-summary` or `e-content` properties and truncating appropriately.
119 |
120 |
121 | Post Types
122 | ----------
123 |
124 | The parser also attempts to determine what type of post this is relative to the primary URL.
125 |
126 | A key named `type` will always be returned with one of the following values:
127 |
128 | * mention - default
129 | * reply - when the post contains explicit `in-reply-to` markup
130 | * rsvp - if the post contains an RSVP yes/no/maybe value
131 | * like
132 | * repost
133 |
134 | When the type is "rsvp", there will also be an `rsvp` key set to the value of the RSVP, usually "yes", "no" or "maybe".
135 |
136 |
137 | Post Names
138 | ----------
139 |
140 | If the post has a "name" property that is not the same as the content, then it will also
141 | be included in the parsed result. This is so that the calling code can choose to display
142 | the post name linked to the full post rather than the content.
143 |
144 |
145 | ```php
146 | $result = array(
147 | 'type' => 'mention',
148 | 'author' => array(
149 | 'name' => 'Aaron Parecki',
150 | 'photo' => 'http://aaronparecki.com/images/aaronpk.png',
151 | 'url' => 'http://aaronparecki.com/'
152 | ),
153 | 'published' => '2014-02-16T18:48:17-0800',
154 | 'name' => 'Post Name',
155 | 'text' => 'this is the text of the article',
156 | 'url' => 'http://aaronparecki.com/post/1'
157 | )
158 | ```
159 |
160 |
161 | Tests
162 | -----
163 |
164 | Please see the [tests](tests/BasicTest.php) for more complete examples of parsing different posts.
165 |
166 |
167 | License
168 | -------
169 |
170 | Copyright 2014 by Aaron Parecki
171 |
172 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
173 |
174 | http://www.apache.org/licenses/LICENSE-2.0
175 |
176 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
177 |
--------------------------------------------------------------------------------
/tests/data/post-tantek-1.json:
--------------------------------------------------------------------------------
1 | {
2 | "type": [
3 | "h-as-note",
4 | "h-entry"
5 | ],
6 | "properties": {
7 | "in-reply-to": [
8 | {
9 | "type": [
10 | "h-cite"
11 | ],
12 | "properties": {
13 | "name": [
14 | "http:\/\/aaronparecki.com\/notes\/2013\/10\/12\/2\/indieweb"
15 | ],
16 | "url": [
17 | "http:\/\/aaronparecki.com\/notes\/2013\/10\/12\/2\/indieweb"
18 | ]
19 | },
20 | "value": "http:\/\/aaronparecki.com\/notes\/2013\/10\/12\/2\/indieweb"
21 | },
22 | {
23 | "type": [
24 | "h-cite"
25 | ],
26 | "properties": {
27 | "name": [
28 | "http:\/\/aaronparecki.com\/articles\/2013\/10\/13\/1\/realtime-indieweb-comments"
29 | ],
30 | "url": [
31 | "http:\/\/aaronparecki.com\/articles\/2013\/10\/13\/1\/realtime-indieweb-comments"
32 | ]
33 | },
34 | "value": "http:\/\/aaronparecki.com\/articles\/2013\/10\/13\/1\/realtime-indieweb-comments"
35 | }
36 | ],
37 | "author": [
38 | {
39 | "type": [
40 | "h-card"
41 | ],
42 | "properties": {
43 | "name": [
44 | "Tantek \u00c7elik"
45 | ],
46 | "photo": [
47 | "http:\/\/tantek.com\/logo.jpg"
48 | ],
49 | "url": [
50 | "http:\/\/tantek.com\/"
51 | ]
52 | },
53 | "value": ""
54 | }
55 | ],
56 | "name": [
57 | "Well done @aaronpk! Real-time #indieweb comments:\nhttp:\/\/aaronparecki.com\/articles\/2013\/10\/13\/1\/realtime-indieweb-comments\n\nI only mentioned the idea at the @indiewebcamp dinner at 21st Amendment http:\/\/aaronparecki.com\/events\/2013\/09\/30\/1\/indieweb-dinner-at-21st-amendment and he's already implemented it live on his site! \n\nAt the dinner, Aaron & Amber had noted they were going to attend a realtime conference and asked if I had any suggestions for things to show or talk about. I pointed out that the only silo (AFAIK) that was really \"realtime\" was Facebook, since pages you were viewing updated automatically when others added to them, e.g. comments.\n\nI said wouldn't it be awesome if indieweb comments worked like that too, because then we'd instantly have something that Twitter, G+, etc. all the other silos did NOT have. Plus it would make for a great indieweb demo.\n\nAnd there it is:\n\n\n\nRead Aaron's whole blog post on the design and implementation (you know, the stuff that counts, as ideas are cheap :) with source:\n\nhttp:\/\/aaronparecki.com\/articles\/2013\/10\/13\/1\/realtime-indieweb-comments\n\nUpdate: showing this off 2013-10-14 to folks at the New York Times."
58 | ],
59 | "url": [
60 | "http:\/\/tantek.com\/2013\/286\/t1\/real-time-indieweb-comments"
61 | ],
62 | "uid": [
63 | "http:\/\/tantek.com\/2013\/286\/t1\/real-time-indieweb-comments"
64 | ],
65 | "syndication": [
66 | "http:\/\/twitter.com\/t\/status\/389368111428018176"
67 | ],
68 | "published": [
69 | "2013-10-13T05:32"
70 | ],
71 | "updated": [
72 | "2013-10-13T05:32"
73 | ],
74 | "content": [
75 | {
76 | "html": "Well done