-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMain.php
46 lines (39 loc) · 1.79 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
<?php
namespace IdnoPlugins\Pinboard {
class Main extends \Idno\Common\Plugin {
function registerPages() {
\Idno\Core\Idno::site()->routes()->addRoute('account/pinboard/?','\IdnoPlugins\Pinboard\Pages\Account');
\Idno\Core\site()->template()->extendTemplate('account/menu/items','account/pinboard/menu');
}
function registerEventHooks() {
\Idno\Core\site()->syndication()->registerService('pinboard', function () {
return true;
}, ['bookmark']);
// event hook for posting bookmark to Pinboard
\Idno\Core\Idno::site()->events()->addListener('post/bookmark/pinboard', function (\Idno\Core\Event $event) {
$object = $event->data()['object'];
$pinboardObj = $this->connect();
$url = $object->body;
// check if we can use the real title here
$title = $object->getTitle();
$tags = str_replace('#','',implode(',', $object->getTags()));
$desc = str_replace($object->getTags(),'',$object->description);
$desc = html_entity_decode(strip_tags($desc));
$optionalData = array('tags'=>$tags,'extended'=>$desc);
$access = $object->getAccess();
$response = json_decode($pinboardObj->createBookmark($url, $title, $optionalData), true);
if ($response) {
$username = explode(':', \Idno\Core\site()->config()->pinboard['apiKey'])[0];
$object->setPosseLink('pinboard', 'https://www.pinboard.in/u:' . $username);
$object->save();
}
});
}
function connect(){
require_once(dirname(__FILE__) . '/external/pinboard.php');
$apiKey = \Idno\Core\site()->config()->pinboard['apiKey'];
$pinboard = new \Pinboard($apiKey);
return $pinboard;
}
}
}