{"id":21191681,"url":"https://github.com/indieweb/mention-client-php","last_synced_at":"2025-07-08T00:14:37.899Z","repository":{"id":7767301,"uuid":"9135958","full_name":"indieweb/mention-client-php","owner":"indieweb","description":"Client library for sending webmention and pingback notifications","archived":false,"fork":false,"pushed_at":"2021-10-16T16:52:39.000Z","size":472,"stargazers_count":98,"open_issues_count":4,"forks_count":19,"subscribers_count":16,"default_branch":"main","last_synced_at":"2024-10-29T20:19:28.382Z","etag":null,"topics":["indieweb","pingback","webmention"],"latest_commit_sha":null,"homepage":"https://indieweb.org/webmention","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/indieweb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-03-31T20:32:23.000Z","updated_at":"2024-10-20T21:25:16.000Z","dependencies_parsed_at":"2022-08-21T12:20:26.628Z","dependency_job_id":null,"html_url":"https://github.com/indieweb/mention-client-php","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indieweb%2Fmention-client-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indieweb%2Fmention-client-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indieweb%2Fmention-client-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indieweb%2Fmention-client-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/indieweb","download_url":"https://codeload.github.com/indieweb/mention-client-php/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243658270,"owners_count":20326467,"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":["indieweb","pingback","webmention"],"created_at":"2024-11-20T19:04:26.798Z","updated_at":"2025-03-14T23:11:07.155Z","avatar_url":"https://github.com/indieweb.png","language":"HTML","readme":"Webmention Client\n=================\n\nClient library for sending [webmention](http://indiewebcamp.com/webmention) and [pingback](http://indiewebcamp.com/pingback) notifications.\n\n[![Build Status](https://travis-ci.org/indieweb/mention-client-php.png?branch=master)](http://travis-ci.org/indieweb/mention-client-php)\n[![Packagist](https://img.shields.io/packagist/v/indieweb/mention-client.svg)](https://packagist.org/packages/indieweb/mention-client)\n\nUsage\n-----\n\n### Basic Usage\n\nGiven one of your source URLs, this function will find links on the page,\ndiscover the webmention and pingback endpoints for each, and send mentions for any\nit discovers.\n\n```php\n\u003c?php\n$client = new IndieWeb\\MentionClient();\n$sent = $client-\u003esendMentions($sourceURL);\n\necho \"Sent $sent mentions\\n\";\n?\u003e\n```\n\nThe library will fetch the source URL, parse it, and look for the first h-entry,\nh-card or h-event. It will then attempt to send webmentions (and pingbacks) to\nall URLs found in the object, as either properties or inside the \"content\" HTML.\n\nThe library attempts to find the endpoints by doing a HEAD request to the target URL\nand looking at the headers, and if none are found, then it makes a GET request\nand searches the body of the page for the rel values.\n\nAfter finding either pingback or webmention endpoints, the request is sent to each.\n\nAlternatively, you can pass in HTML as the second parameter and the library will\nlook for ALL absolute links in the HTML instead of fetching your post contents and\nlooking for the microformats object.\n\n```php\n\u003c?php\n$client = new IndieWeb\\MentionClient();\n$sent = $client-\u003esendMentions($sourceURL, $sourceHTML);\n\necho \"Sent $sent mentions\\n\";\n?\u003e\n```\n\n### Discovering the Webmention endpoint\n\nGiven a target URL, this function will return its webmention endpoint\nif found, otherwise it will return false.\n\n```php\n\u003c?php\n$client = new IndieWeb\\MentionClient();\n$endpoint = $client-\u003ediscoverWebmentionEndpoint($targetURL);\n$endpoint = $client-\u003ediscoverPingbackEndpoint($targetURL);\n?\u003e\n```\n\n### Sending a Webmention\n\nTo send a webmention to a target URL, you can use the function below. This will\nfirst discover the webmention endpoint of the target, and if found, will then\nsend the webmention payload to it. You can pass an additional parameter to include\nother properties in the payload.\n\n```php\n\u003c?php\n$client = new IndieWeb\\MentionClient();\n$response = $client-\u003esendWebmention($sourceURL, $targetURL);\n$response = $client-\u003esendWebmention($sourceURL, $targetURL, ['vouch'=\u003e$vouch]);\n?\u003e\n```\n\nIf no webmention endpoint was found at the target, the function will return false.\nSee the function below for an example of the response when the webmention is successful.\n\nYou can also check if the endpoint advertises a webmention endpoint before trying\nto send one:\n\n```php\n\u003c?php\n$client = new IndieWeb\\MentionClient();\n$supportsWebmention = $client-\u003ediscoverWebmentionEndpoint($targetURL);\nif($supportsWebmention) {\n  $client-\u003esendWebmention($sourceURL, $targetURL);\n}\n?\u003e\n```\n\n### Sending a Pingback\n\n```php\n\u003c?php\n$client = new IndieWeb\\MentionClient();\n$response = $client-\u003esendPingback($sourceURL, $targetURL);\n?\u003e\n```\n\nYou can also check if the endpoint advertises a pingback endpoint before trying\nto send one:\n\n```php\n\u003c?php\n$client = new IndieWeb\\MentionClient();\n$supportsPingback = $client-\u003ediscoverPingbackEndpoint($targetURL);\nif($supportsPingback) {\n  $client-\u003esendPingback($sourceURL, $targetURL);\n}\n?\u003e\n```\n\n### Sending the Webmention or Pingback directly\n\nTo send the actual webmention or pingback payload, you can use the static functions below.\nYou can pass additional properties for the webmention request in an array if needed.\n\n```php\n\u003c?php\n$response = IndieWeb\\MentionClient::sendWebmentionToEndpoint($endpoint, $source, $target);\n$response = IndieWeb\\MentionClient::sendWebmentionToEndpoint($endpoint, $source, $target, ['vouch'=\u003e$vouch]);\n?\u003e\n```\n\nThe response is an array containing the HTTP status code, HTTP headers, and the response body:\n\n```json\n{\n  \"code\": 202,\n  \"headers\": {\n    \"Content-Type: text/plain\"\n  },\n  \"body\": \"Webmention is processing\"\n}\n```\n\nYou can check if the webmention was accepted by testing if the response code is 200, 201 or 202.\n\n```php\n\u003c?php\n$success = IndieWeb\\MentionClient::sendPingbackToEndpoint($endpoint, $source, $target);\n?\u003e\n```\n\nThe pingback function returns true or false depending on whether the pingback was successfully sent.\n\n\n\n### Finding target URLs in a source document\n\nIf you have a rendered HTML page (or partial HTML page), you can use this function to\nreturn a list of outgoing links found on the page.\n\n```php\n\u003c?php\n$client = new IndieWeb\\MentionClient();\n$urls = $client-\u003efindOutgoingLinks($html);\n?\u003e\n```\n\nAlternately, you can pass a parsed Microformats object to the `findOutgoingLinks`\nfunction and it will search for URLs in any property as well as in the HTML of\nany e-content objects.\n\n```php\n$client = new IndieWeb\\MentionClient();\n$parsed = \\Mf2\\parse($html, $sourceURL);\n$urls = $client-\u003efindOutgoingLinks($parsed);\n```\n\nAll links found will be returned an array, with duplicate URLs removed. If no links\nare found, it will return an empty array.\n\n```json\n[\n  \"http://example.com/1\",\n  \"http://example.com/2\"\n]\n```\n\n### Custom User Agent\n\nYou can set the user agent that this library uses when making HTTP requests.\n\n```php\nIndieWeb\\MentionClient::setUserAgent('Custom user agent string');\n```\n\nAt that point, any HTTP request (GET, HEAD, POST) that this library makes will include the user agent header you've set.\n\n\n### Debugging\n\nIf you want to collect debugging information so you can see the steps the library\nis doing, run `IndieWeb\\MentionClient::enableDebug();` before calling any other function.\n\n\n\n\nAbout Webmention\n----------------\n\nTo learn more about Webmention, see [webmention.net](http://webmention.net).\n\nThe [webmention.io](http://webmention.io/) service can also act as a pingback-\u003ewebmention\nproxy which will allow you to accept pingbacks as if they were sent as webmentions.\n\n\nAbout Pingback\n--------------\n\nIf you want to accept pingbacks on your site, check out [webmention.io](http://webmention.io/#use-it)\nwhich handles accepting the XMLRPC request and exposes the data via an API.\n\n\nLicense\n-------\n\nCopyright 2013-2017 by Aaron Parecki and contributors\n\nAvailable under the Apache 2.0 and MIT licenses.\n\n#### Apache 2.0\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n   http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n\n#### MIT\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Findieweb%2Fmention-client-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Findieweb%2Fmention-client-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Findieweb%2Fmention-client-php/lists"}