This repository has been archived by the owner on Nov 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
indieweb.api.php
158 lines (147 loc) · 4.43 KB
/
indieweb.api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
/**
* @file
* Hooks specific to the IndieWeb modules.
*/
use Drupal\node\NodeInterface;
use Drupal\user\UserInterface;
/**
* Act on the values and input before a node is created with Node::create().
*
* When a micropub post request comes in and a node will be created, you can
* alter the values just before. In this example, we're changing the node type.
* Switching the node type during hook_node_presave() is to late for pathauto
* for instance.
*
* @param array $values
* The values before used in Node::create();
* @param array $payload
* The payload which was entered. You can also change this since some of the
* payload is still being used on fields that will be added later like body,
* image and others.
*/
function hook_indieweb_micropub_node_pre_create_alter(&$values, &$payload) {
if (!empty($payload['category']) && in_array('to-gallery', $payload['category'])) {
$values['type'] = 'another_node_type';
}
}
/**
* Act when a node has just been saved and we're about to return the response
* back to the client that send the request.
*
* @param \Drupal\node\NodeInterface $node
* The node that just has been saved. There is property on the node called
* 'micropub_payload' which is the payload from the micropub request so you
* can inspect it here to see the original submitted values.
* @param array $values
* The values that where submitted to Node::create(). These could have been
* altered in hook_indieweb_micropub_node_pre_create_alter().
* @param $payload
* The payload entered in the micropub request. This could also have been
* altered by hook_indieweb_micropub_node_pre_create_alter().
* @param $payload_original
* The original payload from the micropub request.
*
* @throws \Drupal\Core\Entity\EntityMalformedException
*/
function hook_indieweb_micropub_node_saved(NodeInterface $node, $values, $payload, $payload_original) {
if (!empty($payload['category'])) {
foreach ($payload['category'] as $category) {
$category = trim($category);
if ($category == 'to-twitter') {
$source = $node->toUrl()->setAbsolute(TRUE)->toString();
\Drupal::service('indieweb.webmention.client')->createQueueItem($source, 'https://brid.gy/publish/twitter', $node->id(), 'node');
}
}
}
}
/**
* Act when no post has been made, but has a valid token. If you return an
* absolute URL, that will be used as the response.
*
* @param $payload
* The payload entered in the micropub request.
*
* @return string $url|NULL
* Absolute URL. Return NULL in case nothing happened.
*/
function hook_indieweb_micropub_no_post_made($payload) {
}
/**
* Act on a geo response.
*
* Use this to change or add extra data to the response. The response might
* already contain the 'geo' property. Another property which can be added is
* 'places' which contains a list of suggested places.
*
* No context is given. You need to check for yourself if 'lat' and 'lon'
* paramaters are available in the request.
*
* @param \stdClass $response
* The current response.
*/
function hook_micropub_geo_response_alter($response) {
$response->places = [
(object) [
'label' => 'Place 1',
'latitude' => '51.123',
'longitude' => '-0.2323',
'url' => 'https://example.com/place'
],
];
}
/**
* Act when a user registers or logs in with IndieAuth.
*
* This is the perfect moment to save additional properties on the account.
*
* @param $account
* The Drupal user account.
* @param $indieauth_response
* The IndieAuth response, which is a JSON object.
*/
function hook_indieweb_indieauth_login(UserInterface $account, $indieauth_response) {
}
/**
* Act on a WebSub subscribe event.
*
* @param $url
* The url to subscribe.
* @param $seconds
* The lease seconds, if available.
*
* @return mixed TRUE|NULL
*/
function hook_indieweb_websub_subscribe($url, $seconds) {
return NULL;
}
/**
* Act on a WebSub unsubscribe event.
*
* @param $url
* The url to unsubscribe.
*
* @return mixed TRUE|NULL
*/
function hook_indieweb_websub_unsubscribe($url) {
return NULL;
}
/**
* Act on incoming WebSub notification.
*
* @param $url
* The URL which was updated.
* @param $content
* The content, if any.
*/
function hook_indieweb_websub_notification($url, $content) {
}
/**
* Act on the resubscribe moment.
*
* @return array
* A collection urls to resubscribe.
*/
function hook_indieweb_websub_needs_resubscribe() {
return ['url1', 'url2'];
}