{"id":21191696,"url":"https://github.com/indieweb/php-comments","last_synced_at":"2025-07-10T03:30:56.083Z","repository":{"id":14358146,"uuid":"17067868","full_name":"indieweb/php-comments","owner":"indieweb","description":"Helper for parsing and presenting comments from external sites","archived":false,"fork":false,"pushed_at":"2024-05-12T19:14:29.000Z","size":40,"stargazers_count":18,"open_issues_count":7,"forks_count":4,"subscribers_count":20,"default_branch":"main","last_synced_at":"2024-10-29T19:03:19.990Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://indiewebcamp.com/comments-presentation","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/indieweb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-02-21T19:57:09.000Z","updated_at":"2024-08-05T02:04:24.000Z","dependencies_parsed_at":"2024-11-06T21:32:45.565Z","dependency_job_id":"1f239d2d-2696-4fc2-9ce9-94ee6df776f1","html_url":"https://github.com/indieweb/php-comments","commit_stats":{"total_commits":28,"total_committers":3,"mean_commits":9.333333333333334,"dds":0.2142857142857143,"last_synced_commit":"148a7976078795d2d93c1fc0c3b7c74265f33b09"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indieweb%2Fphp-comments","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indieweb%2Fphp-comments/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indieweb%2Fphp-comments/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indieweb%2Fphp-comments/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/indieweb","download_url":"https://codeload.github.com/indieweb/php-comments/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225311754,"owners_count":17454432,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-20T19:04:33.824Z","updated_at":"2024-11-20T19:04:34.549Z","avatar_url":"https://github.com/indieweb.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Comments Presentation\n=====================\n\nGiven an [h-entry](http://indiewebcamp.com/h-entry), returns author info as well as truncated post text suitable for display.\n\nInstallation\n------------\n\nInstall via composer:\n\n```json\n{\n  \"indieweb/comments\": \"0.1.*\",\n}\n```\n\nOr just require the one file:\n\n```php\nrequire_once('src/indieweb/comments.php');\n```\n\n\nUsage\n-----\n\nThe function accepts a PHP array in the format returned by the [microformats2 parser](https://github.com/indieweb/php-mf2)\nand returns a new array that looks like the following:\n\nOriginal HTML:\n```html\n\u003cdiv class=\"h-entry\"\u003e\n  \u003cdiv class=\"p-author h-card\"\u003e\n    \u003cimg src=\"http://aaronparecki.com/images/aaronpk.png\" class=\"u-photo\"\u003e\n    \u003ca href=\"http://aaronparecki.com\"\u003eAaron Parecki\u003c/a\u003e\n  \u003c/div\u003e\n  \u003ch3 class=\"p-name\"\u003eExample Note\u003c/h3\u003e\n  \u003cp class=\"e-content\"\u003ethis text is displayed as the comment\u003c/p\u003e\n  \u003ctime class=\"dt-published\" datetime=\"2014-02-16T18:48:17-0800\"\u003eFeb 16, 6:48pm\u003c/time\u003e\n  \u003ca href=\"http://caseorganic.com/post/1\" class=\"u-in-reply-to\"\u003ein reply to caseorganic.com\u003c/a\u003e\n\u003c/div\u003e\n```\n\nParsed Microformats:\n```json\n{\n    \"type\": [\n        \"h-entry\"\n    ],\n    \"properties\": {\n        \"author\": [\n            {\n                \"type\": [\n                    \"h-card\"\n                ],\n                \"properties\": {\n                    \"photo\": [\n                        \"http:\\/\\/aaronparecki.com\\/images\\/aaronpk.png\"\n                    ],\n                    \"name\": [\n                        \"Aaron Parecki\"\n                    ],\n                    \"url\": [\n                        \"http:\\/\\/aaronparecki.com\"\n                    ]\n                },\n                \"value\": \"Aaron Parecki\"\n            }\n        ],\n        \"name\": [\n            \"Example Note\"\n        ],\n        \"published\": [\n            \"2014-02-16T18:48:17-0800\"\n        ],\n        \"in-reply-to\": [\n            \"http:\\/\\/caseorganic.com\\/post\\/1\"\n        ],\n        \"content\": [\n            {\n                \"html\": \"this text is displayed as the comment\",\n                \"value\": \"this text is displayed as the comment\"\n            }\n        ]\n    }\n}\n```\n\nParse for comment display:\n\n```php\n$result = IndieWeb\\comments\\parse($input, $refURL, $maxLength, $maxLines);\n```\n\nResulting PHP array:\n\n```php\n  $result = array(\n    'type' =\u003e 'reply',\n    'author' =\u003e array(\n      'name' =\u003e 'Aaron Parecki',\n      'photo' =\u003e 'http://aaronparecki.com/images/aaronpk.png',\n      'url' =\u003e 'http://aaronparecki.com/'\n    ),\n    'published' =\u003e '2014-02-16T18:48:17-0800',\n    'name' =\u003e 'Example Note',\n    'text' =\u003e 'this text is displayed as the comment',\n    'url' =\u003e 'http://aaronparecki.com/post/1'\n  )\n```\n\nThis function will return an array with all of the keys above. One or more values may \nbe empty depending on what information was available in the post, such as author name/photo.\n\nThe `text` property will always be within your maximum desired length as passed to the `parse()` function.\n\nThe function follows the algorithm described at [comments-presentation](http://indiewebcamp.com/comments-presentation#How_to_display)\nfor deciding whether to show the `p-name`, `p-summary` or `e-content` properties and truncating appropriately.\n\n\nPost Types\n----------\n\nThe parser also attempts to determine what type of post this is relative to the primary URL.\n\nA key named `type` will always be returned with one of the following values:\n\n* mention - default\n* reply - when the post contains explicit `in-reply-to` markup\n* rsvp - if the post contains an RSVP yes/no/maybe value\n* like\n* repost\n\nWhen the type is \"rsvp\", there will also be an `rsvp` key set to the value of the RSVP, usually \"yes\", \"no\" or \"maybe\".\n\n\nPost Names\n----------\n\nIf the post has a \"name\" property that is not the same as the content, then it will also\nbe included in the parsed result. This is so that the calling code can choose to display\nthe post name linked to the full post rather than the content.\n\n\n```php\n  $result = array(\n    'type' =\u003e 'mention',\n    'author' =\u003e array(\n      'name' =\u003e 'Aaron Parecki',\n      'photo' =\u003e 'http://aaronparecki.com/images/aaronpk.png',\n      'url' =\u003e 'http://aaronparecki.com/'\n    ),\n    'published' =\u003e '2014-02-16T18:48:17-0800',\n    'name' =\u003e 'Post Name',\n    'text' =\u003e 'this is the text of the article',\n    'url' =\u003e 'http://aaronparecki.com/post/1'\n  )\n```\n\n\nTests\n-----\n\nPlease see the [tests](tests/BasicTest.php) for more complete examples of parsing different posts.\n\n\nLicense\n-------\n\nCopyright 2014 by Aaron Parecki\n\nLicensed 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\n\nhttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless 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.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Findieweb%2Fphp-comments","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Findieweb%2Fphp-comments","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Findieweb%2Fphp-comments/lists"}