-
Notifications
You must be signed in to change notification settings - Fork 6
/
TwitterBlockPlugin.inc.php
86 lines (79 loc) · 2.39 KB
/
TwitterBlockPlugin.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
<?php
import('lib.pkp.classes.plugins.BlockPlugin');
class TwitterBlockPlugin extends BlockPlugin
{
// Enables plugin site-wide or in specific context; this must return true only if the user is in the site-wide context
public function isSitePlugin()
{
return !Application::get()->getRequest()->getContext();
}
public function getDisplayName()
{
return __('plugins.blocks.twitter.title');
}
public function getDescription()
{
return __('plugins.blocks.twitter.desc');
}
public function getContents($templateMgr, $request = null)
{
$context = Application::get()->getRequest()->getContext();
$contextId = ($context && $context->getId()) ? $context->getId() : CONTEXT_SITE;
$templateMgr->assign('tweetTitle', $this->getSetting($contextId, 'tweetTitle'));
$templateMgr->assign('tweetUrl', $this->getSetting($contextId, 'tweetUrl'));
$templateMgr->assign('tweetColor', $this->getSetting($contextId, 'tweetColor'));
$templateMgr->assign('tweetHeight', $this->getSetting($contextId, 'tweetHeight'));
$templateMgr->assign('tweetOptions', $this->getSetting($contextId, 'tweetOptions'));
$templateMgr->assign('tweetDataLimit', $this->getSetting($contextId, 'tweetDataLimit'));
return parent::getContents($templateMgr, $request);
}
public function getActions($request, $actionArgs)
{
$actions = parent::getActions($request, $actionArgs);
if (!$this->getEnabled()) {
return $actions;
}
$router = $request->getRouter();
import('lib.pkp.classes.linkAction.request.AjaxModal');
$linkAction = new LinkAction(
'settings',
new AjaxModal(
$router->url(
$request,
null,
null,
'manage',
null,
array(
'verb' => 'settings',
'plugin' => $this->getName(),
'category' => 'blocks'
)
),
$this->getDisplayName()
),
__('manager.plugins.settings'),
null
);
array_unshift($actions, $linkAction);
return $actions;
}
public function manage($args, $request)
{
switch ($request->getUserVar('verb')) {
case 'settings':
$this->import('TwitterBlockPluginSettingsForm');
$form = new TwitterBlockPluginSettingsForm($this);
if (!$request->getUserVar('save')) {
$form->initData();
return new JSONMessage(true, $form->fetch($request));
}
$form->readInputData();
if ($form->validate()) {
$form->execute();
return new JSONMessage(true);
}
}
return parent::manage($args, $request);
}
}