Skip to content

Instantly share code, notes, and snippets.

@gRegorLove
Last active December 13, 2020 05:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gRegorLove/76e491bd3dd12eae0e685597fa3d478d to your computer and use it in GitHub Desktop.
Save gRegorLove/76e491bd3dd12eae0e685597fa3d478d to your computer and use it in GitHub Desktop.
Example of sending Bridgy Publish webmention
<?php namespace ProcessWire;
/**
* This is an example of how I use Bridgy Publish.
* This is for reference only, not necessarily the cleanest/best way to do this. :)
*
* 1. When an admin views a note that isn't already syndicated to Twitter, display a Bridgy Publish button (not included in this file)
* 2. When that form is submitted, use the module to send a Webmention to Bridgy Publish
* 3. Decode and parse the JSON for the Twitter URL
*
* Note: my template has textarea field `syndication` for syndication URLs. I put the Bridgy Publish Twitter URL there and replace it with the tweet permalink after successful publishing.
*/
if ($input->post->tweet_this) {
$is_success = false;
$Webmention = $modules->get('Webmention');
$response = $Webmention->sendWebmention($page->httpUrl, 'https://brid.gy/publish/twitter');
# attempt to decode the JSON response from brid.gy
$json = json_decode($response);
# JSON decoded
if (!is_null($json)) {
# Tweet URL found
if (!empty($json->url)) {
$page->of(false);
$page->syndication = trim(str_replace('https://brid.gy/publish/twitter', $json->url, $page->syndication));
$page->save();
$is_success = true;
}
}
if (!$is_success) {
echo 'Published successfully!';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment