-
Notifications
You must be signed in to change notification settings - Fork 3
/
Main.php
77 lines (61 loc) · 2.91 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
76
77
<?php
namespace IdnoPlugins\Diigo {
class Main extends \Idno\Common\Plugin {
function registerPages() {
// Register settings page
\Idno\Core\site()->addPageHandler('account/diigo/?','\IdnoPlugins\Diigo\Pages\Account');
/** Template extensions */
// Add menu items to admin screen
\Idno\Core\site()->template()->extendTemplate('account/menu/items','account/diigo/menu');
}
function registerEventHooks() {
\Idno\Core\site()->syndication()->registerService('diigo', function () {
return $this->hasDiigo();
}, ['bookmark']);
// Push likes to Diigo
\Idno\Core\site()->addEventHook('post/bookmark/diigo', function (\Idno\Core\Event $event) {
if ($this->hasDiigo()) {
$object = $event->data()['object'];
$digObj = $this->connect();
$url = $object->body;
$title = $object->getTitleFromURL($url);
$tags = str_replace('#','',implode(',', $object->getTags()));
$desc = str_replace($object->getTags(),'',$object->description);
$desc = strip_tags($desc);
$optionalData = array('tags'=>$tags,'desc'=>$desc);
$access = $object->getAccess();
if ($access == 'PUBLIC'){
$optionalData['shared']='yes';
}
$response = json_decode($digObj->updateBookMark($url, $title, $optionalData), true);
if ($response) {
$object->setPosseLink('diigo', 'https://www.diigo.com/user/' . \Idno\Core\site()->config()->diigo['dgusername']);
$object->save();
}
}
});
}
/**
* Connect to Diigo
* @return bool|\Diigo
*/
function connect(){
require_once(dirname(__FILE__) . '/external/diigo.php');
$dguser = \Idno\Core\site()->config()->diigo['dgusername'];
$dgpass = \Idno\Core\site()->config()->diigo['dgpassword'];
$dgapi = \Idno\Core\site()->config()->diigo['dgapiKey'];
$diigo = new \Diigo($dguser,$dgpass,$dgapi);
return $diigo;
}
/**
* Can the current user use Diigo?
* @return bool
*/
function hasDiigo(){
if (!empty(\Idno\Core\site()->config()->diigo)) {
return true;
}
return false;
}
}
}