• Main Page
  • Modules
  • Classes
  • Files
  • File List

plugins/generic/addThis/AddThisPlugin.inc.php

00001 <?php
00002 
00015 import('lib.pkp.classes.plugins.GenericPlugin');
00016 
00017 class AddThisPlugin extends GenericPlugin {
00018    function register($category, $path) {
00019       if (parent::register($category, $path)) {
00020          if ($this->getEnabled()) {
00021             HookRegistry::register('Templates::Catalog::Book::BookInfo::Sharing',array(&$this, 'callbackSharingDisplay'));
00022          }
00023          return true;
00024       }
00025       return false;
00026    }
00027 
00033    function getContextSpecificPluginSettingsFile() {
00034       return $this->getPluginPath() . '/settings.xml';
00035    }
00036 
00037    function getDisplayName() {
00038       return __('plugins.generic.addThis.displayName');
00039    }
00040 
00041    function getDescription() {
00042       return __('plugins.generic.addThis.description');
00043    }
00044 
00045    function getManagementVerbs() {
00046       $verbs = array();
00047       if ($this->getEnabled()) {
00048          $verbs[] = array('settings', __('plugins.generic.addThis.settings'));
00049       }
00050       return parent::getManagementVerbs($verbs);
00051    }
00052 
00057    function getManagementVerbLinkAction(&$request, $verb, $defaultUrl) {
00058       $router =& $request->getRouter();
00059       $dispatcher =& $router->getDispatcher();
00060 
00061       list($verbName, $verbLocalized) = $verb;
00062 
00063       if ($verbName === 'settings') {
00064          import('lib.pkp.classes.linkAction.request.AjaxLegacyPluginModal');
00065          $actionRequest = new AjaxLegacyPluginModal($defaultUrl,
00066                $this->getDisplayName());
00067          return new LinkAction($verbName, $actionRequest, $verbLocalized, null);
00068       }
00069 
00070       return null;
00071    }
00072 
00076    function manage($verb, $args, &$message, &$messageParams, &$pluginModalContent) {
00077 
00078       $application =& Application::getApplication();
00079       $request =& $application->getRequest();
00080       $press =& $request->getPress();
00081       $templateMgr =& TemplateManager::getManager();
00082 
00083       switch ($verb) {
00084 
00085          case 'settings':
00086             $templateMgr->assign('statsConfigured', $this->statsConfigured($press));
00087             $pluginModalContent = $templateMgr->fetch($this->getTemplatePath() . 'settingsTabs.tpl');
00088             return true;
00089 
00090          case 'showTab':
00091             if ($request->getUserVar('tab') == 'settings') {
00092                $templateMgr =& TemplateManager::getManager();
00093                $this->import('AddThisSettingsForm');
00094                $form = new AddThisSettingsForm($this, $press);
00095                if ($request->getUserVar('save')) {
00096                   $form->readInputData();
00097                   if ($form->validate()) {
00098                      $form->execute();
00099                      $message = NOTIFICATION_TYPE_SUCCESS;
00100                      $messageParams = array('contents' => __('plugins.generic.addThis.form.saved'));
00101                      return false;
00102                   } else {
00103                      $pluginModalContent = $form->fetch($request);
00104                   }
00105                } else {
00106                   $form->initData();
00107                   $pluginModalContent = $form->fetch($request);
00108                }
00109             } else {
00110                $pluginModalContent = $templateMgr->fetch($this->getTemplatePath() . 'statistics.tpl');
00111             }
00112             return true;
00113 
00114          case 'showStatistics':
00115                $this->import('AddThisStatisticsGridHandler');
00116                $gridHandler = new AddThisStatisticsGridHandler($this);
00117                $gridHandler->initialize($request);
00118 
00119                import('lib.pkp.classes.core.JSONManager');
00120                $jsonManager = new JSONManager();
00121 
00122                $jsonMessage = $jsonManager->decode($gridHandler->fetchGrid($args, $request));
00123                $pluginModalContent = $jsonMessage->content;
00124             return true;
00125 
00126          default:
00127             // let the parent handle it.
00128             return parent::manage($verb, $args, $message, $messageParams);
00129       }
00130    }
00131 
00138    function callbackSharingDisplay($hookName, $params) {
00139       $templateMgr =& $params[1];
00140       $output =& $params[2];
00141 
00142       $application =& Application::getApplication();
00143       $request =& $application->getRequest();
00144       $press =& $request->getPress();
00145 
00146       $templateMgr->assign('addThisProfileId', $press->getSetting('addThisProfileId'));
00147       $templateMgr->assign('addThisUsername', $press->getSetting('addThisUsername'));
00148       $templateMgr->assign('addThisPassword', $press->getSetting('addThisPassword'));
00149       $templateMgr->assign('addThisDisplayStyle', $press->getSetting('addThisDisplayStyle'));
00150 
00151       $output .= $templateMgr->fetch($this->getTemplatePath() . 'addThis.tpl');
00152       return false;
00153    }
00154 
00160    function statsConfigured($press) {
00161       $addThisUsername =& $press->getSetting('addThisUsername');
00162       $addThisPassword =& $press->getSetting('addThisPassword');
00163       $addThisProfileId =& $press->getSetting('addThisProfileId');
00164 
00165       if (isset($addThisUsername) && isset($addThisPassword) && isset($addThisProfileId)) {
00166          return true;
00167       }
00168 
00169       return false;
00170    }
00171 }
00172 
00173 ?>

Generated on Mon Sep 17 2012 13:58:56 for Open Monograph Press by  doxygen 1.7.1