-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TwitterBotPlugin.inc.php
92 lines (79 loc) · 2.32 KB
/
TwitterBotPlugin.inc.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
<?php
import('lib.pkp.classes.plugins.GenericPlugin');
class TwitterBotPlugin extends GenericPlugin {
public function register($category, $path, $mainContextId = NULL) {
// register the plugin even when it is not enabled
$success = parent::register($category, $path);
if ($success && $this->getEnabled()) {
// TODO
}
return $success;
}
/**
* Provide a name to the plugin
*/
public function getDisplayName() {
return "Twitter Bot";
}
/**
* Provide a description to the plugin
*/
public function getDescription() {
return "The electronic community manager for your scholar journal";
}
/**
* Provide additional setting action
*/
function getActions($request, $verb) {
$router = $request->getRouter();
import('lib.pkp.classes.linkAction.request.AjaxModal');
return array_merge(
$this->getEnabled()?array(
new LinkAction(
'settings',
new AjaxModal(
$router->url($request,
null,
null,
'manage',
null,
array(
'verb' => 'settings',
'plugin' => $this->getName(),
'category' => 'generic')
),
$this->getDisplayName()
),
'Bot settings',
null
),
):array(),
parent::getActions($request, $verb)
);
}
/**
* Launch actions
* 1 .- Bot settings
*/
function manage($args, $request) {
switch ($request->getUserVar('verb')) {
case 'settings':
$context = $request->getContext();
$templateMgr = TemplateManager::getManager($request);
$templateMgr->registerPlugin('function', 'plugin_url', array($this, 'smartyPluginUrl'));
$this->import('TwitterBotSettingsForm');
$form = new TwitterBotSettingsForm($this, $context->getId());
if ($request->getUserVar('save')) {
$form->readInputData();
if ($form->validate()) {
$form->execute();
return new JSONMessage(true);
}
} else {
$form->initData();
}
return new JSONMessage(true, $form->fetch($request));
}
return parent::manage($args, $request);
}
}