-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMain.php
75 lines (62 loc) · 3.34 KB
/
Main.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
<?php
namespace IdnoPlugins\Reactions {
use Idno\Core\Idno;
use Idno\Core\Event;
use Idno\Common\ContentType;
class Main extends \Idno\Common\Plugin {
function registerEventHooks()
{
parent::registerEventHooks();
\Idno\Core\Idno::site()->events()->addListener('plugins/loaded', function (Event $evt) {
// make sure our content types are before IdnoPlugins\Like\ContentType
$bookmarkType = '\IdnoPlugins\Like\ContentType';
if (class_exists($bookmarkType)) {
$bookmarkIndex = -1;
for ($ii = 0 ; $ii < count(ContentType::$registered) ; $ii++) {
$contentType = ContentType::$registered[$ii];
if ($contentType instanceof $bookmarkType) {
$bookmarkIndex = $ii;
break;
}
}
if ($bookmarkIndex > -1) {
foreach (['LikeContentType', 'RepostContentType'] as $targetType) {
$targetType = $this->getNamespace() . '\\' . $targetType;
for ($ii = 0 ; $ii < count(ContentType::$registered) ; $ii++) {
$contentType = ContentType::$registered[$ii];
if ($contentType instanceof $targetType) {
array_splice(ContentType::$registered, $ii, 1);
array_splice(ContentType::$registered, $bookmarkIndex, 0, [$contentType]);
$bookmarkIndex++;
break;
}
}
}
}
}
});
\Idno\Core\Idno::site()->events()->addListener('share/types', function (Event $evt) {
$types = $evt->data()['types'];
$newTypes = ['like'=>'Like', 'repost'=>'Repost'];
$evt->setResponse(array_merge($types, $newTypes));
});
}
function registerPages()
{
parent::registerPages();
\Idno\Core\Idno::site()->routes()->addRoute('/indielike/edit/?', '\IdnoPlugins\Reactions\Pages\Like\Edit');
\Idno\Core\Idno::site()->routes()->addRoute('/indielike/edit/(\w+)/?', '\IdnoPlugins\Reactions\Pages\Like\Edit');
\Idno\Core\Idno::site()->routes()->addRoute('/like/delete/(\w+)/?', '\IdnoPlugins\Reactions\Pages\Delete');
\Idno\Core\Idno::site()->routes()->addRoute('/repost/edit/?', '\IdnoPlugins\Reactions\Pages\Repost\Edit');
\Idno\Core\Idno::site()->routes()->addRoute('/repost/edit/(\w+)/?', '\IdnoPlugins\Reactions\Pages\Repost\Edit');
\Idno\Core\Idno::site()->routes()->addRoute('/repost/delete/(\w+)/?', '\IdnoPlugins\Reactions\Pages\Delete');
\Idno\Core\Idno::site()->routes()->addRoute('/reactions/fetch/?', '\IdnoPlugins\Reactions\Pages\Fetch');
}
function registerContentTypes()
{
parent::registerContentTypes();
\Idno\Common\ContentType::register($this->getNamespace() . '\\LikeContentType');
\Idno\Common\ContentType::register($this->getNamespace() . '\\RepostContentType');
}
}
}