Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
AddThisPlugin.inc.php
1 <?php
2 
16 import('lib.pkp.classes.plugins.GenericPlugin');
17 
24  function register($category, $path) {
25  if (parent::register($category, $path)) {
26  if ($this->getEnabled()) {
27  HookRegistry::register('Templates::Catalog::Book::BookInfo::Sharing',array(&$this, 'callbackSharingDisplay'));
28  }
29  return true;
30  }
31  return false;
32  }
33 
40  return $this->getPluginPath() . '/settings.xml';
41  }
42 
46  function getName() {
47  return 'AddThisPlugin';
48  }
49 
53  function getDisplayName() {
54  return __('plugins.generic.addThis.displayName');
55  }
56 
60  function getDescription() {
61  return __('plugins.generic.addThis.description');
62  }
63 
67  function getManagementVerbs() {
68  $verbs = parent::getManagementVerbs();
69  if ($this->getEnabled()) {
70  $verbs[] = array('settings', __('plugins.generic.addThis.settings'));
71  }
72  return $verbs;
73  }
74 
82  $router = $request->getRouter();
83 
84  list($verbName, $verbLocalized) = $verb;
85 
86  if ($verbName === 'settings') {
87  import('lib.pkp.classes.linkAction.request.AjaxLegacyPluginModal');
88  $actionRequest = new AjaxLegacyPluginModal(
89  $router->url($request, null, null, 'plugin', null, array('verb' => 'settings', 'plugin' => $this->getName(), 'category' => 'generic')),
90  $this->getDisplayName()
91  );
92  return new LinkAction($verbName, $actionRequest, $verbLocalized, null);
93  }
94 
95  return null;
96  }
97 
101  function manage($verb, $args, &$message, &$messageParams, &$pluginModalContent = null) {
102  $request = $this->getRequest();
103  $press = $request->getPress();
104  $templateMgr = TemplateManager::getManager($request);
105 
106  switch ($verb) {
107 
108  case 'settings':
109  $templateMgr->assign('statsConfigured', $this->statsConfigured($press));
110  $pluginModalContent = $templateMgr->fetch($this->getTemplatePath() . 'settingsTabs.tpl');
111  return true;
112 
113  case 'showTab':
114  if ($request->getUserVar('tab') == 'settings') {
115  $this->import('AddThisSettingsForm');
116  $form = new AddThisSettingsForm($this, $press);
117  if ($request->getUserVar('save')) {
118  $form->readInputData();
119  if ($form->validate()) {
120  $form->execute();
121  $message = NOTIFICATION_TYPE_SUCCESS;
122  $messageParams = array('contents' => __('plugins.generic.addThis.form.saved'));
123  return false;
124  } else {
125  $pluginModalContent = $form->fetch($request);
126  }
127  } else {
128  $form->initData();
129  $pluginModalContent = $form->fetch($request);
130  }
131  } else {
132  $pluginModalContent = $templateMgr->fetch($this->getTemplatePath() . 'statistics.tpl');
133  }
134  return true;
135 
136  case 'showStatistics':
137  $this->import('AddThisStatisticsGridHandler');
138  $gridHandler = new AddThisStatisticsGridHandler($this);
139  $gridHandler->initialize($request);
140 
141  $jsonMessage = json_decode($gridHandler->fetchGrid($args, $request));
142  $pluginModalContent = $jsonMessage->content;
143  return true;
144 
145  default:
146  // let the parent handle it.
147  return parent::manage($verb, $args, $message, $messageParams);
148  }
149  }
150 
157  function callbackSharingDisplay($hookName, $params) {
158  $templateMgr = $params[1];
159  $output =& $params[2];
160 
161  $request = $this->getRequest();
162  $press = $request->getPress();
163 
164  $templateMgr->assign('addThisProfileId', $press->getSetting('addThisProfileId'));
165  $templateMgr->assign('addThisUsername', $press->getSetting('addThisUsername'));
166  $templateMgr->assign('addThisPassword', $press->getSetting('addThisPassword'));
167  $templateMgr->assign('addThisDisplayStyle', $press->getSetting('addThisDisplayStyle'));
168 
169  $output .= $templateMgr->fetch($this->getTemplatePath() . 'addThis.tpl');
170  return false;
171  }
172 
178  function statsConfigured($press) {
179  $addThisUsername = $press->getSetting('addThisUsername');
180  $addThisPassword = $press->getSetting('addThisPassword');
181  $addThisProfileId = $press->getSetting('addThisProfileId');
182 
183  if (isset($addThisUsername) && isset($addThisPassword) && isset($addThisProfileId)) {
184  return true;
185  }
186 
187  return false;
188  }
189 }
190 
191 ?>
& getRequest()
Definition: Plugin.inc.php:755
Form for adding/editing the settings for the AddThis plugin.
getManagementVerbLinkAction($request, $verb)
Abstract class for generic plugins.
An ajax modal to be used in plugins management. This is part of a temporary solution, while we don&#39;t modernize the UI of the plugins. The functionalities implemented here are not necessary anywhere else. DON&#39;T USE this handler if you are not showing legacy plugins management content. FIXME After modernizing the UI of the plugins, remove this class.
getPluginPath()
Definition: Plugin.inc.php:324
callbackSharingDisplay($hookName, $params)
manage($verb, $args, &$message, &$messageParams, &$pluginModalContent=null)
This plugin provides the AddThis social media sharing options for submissions.
Handle addThis plugin requests for statistics.
static register($hookName, $callback)
getContextSpecificPluginSettingsFile()
getTemplatePath($inCore=false)
Definition: Plugin.inc.php:333
Base class defining an action that can be performed by the user in the user interface.