GitHub PullRequestReviewCommentEvent at 2014-04-01 18:37:17
Repository: ojs
Actor: asmecher
Payload: {"comment":{"url":"https://api.github.com/repos/pkp/ojs/pulls/comments/11174320","id":11174320,"diff_hunk":"@@ -0,0 +1,1473 @@\n+<?php\n+\n+/**\n+ * @file plugins/generic/dataverse/dataversePlugin.inc.php\n+ *\n+ * Copyright (c) 2003-2014 John Willinsky\n+ * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.\n+ *\n+ * @class dataversePlugin\n+ * @ingroup plugins_generic_dataverse\n+ *\n+ * @brief dataverse plugin class\n+ */\n+\n+import('lib.pkp.classes.plugins.GenericPlugin');\n+import('plugins.generic.dataverse.classes.DataversePackager');\n+\n+require('lib/pkp/lib/swordappv2/swordappclient.php');\n+\n+define('DATAVERSE_PLUGIN_HTTP_STATUS_OK', 200);\n+define('DATAVERSE_PLUGIN_HTTP_STATUS_CREATED', 201);\n+define('DATAVERSE_PLUGIN_HTTP_STATUS_NO_CONTENT', 204);\n+define('DATAVERSE_PLUGIN_TOU_POLICY_SEPARATOR', '---');\n+define('DATAVERSE_PLUGIN_SUBJECT_SEPARATOR', ';');\n+define('DATAVERSE_PLUGIN_CITATION_FORMAT_APA', 'APA');\n+\n+// Study release options\n+define('DATAVERSE_PLUGIN_RELEASE_ARTICLE_ACCEPTED',  0x01);\n+define('DATAVERSE_PLUGIN_RELEASE_ARTICLE_PUBLISHED', 0x02);\n+\n+// Notification types\n+define('NOTIFICATION_TYPE_DATAVERSE_STUDY_CREATED',  NOTIFICATION_TYPE_PLUGIN_BASE + 0x0001001);\n+define('NOTIFICATION_TYPE_DATAVERSE_STUDY_UPDATED',  NOTIFICATION_TYPE_PLUGIN_BASE + 0x0001002);\n+define('NOTIFICATION_TYPE_DATAVERSE_FILE_ADDED',     NOTIFICATION_TYPE_PLUGIN_BASE + 0x0001003);\n+define('NOTIFICATION_TYPE_DATAVERSE_FILE_DELETED',   NOTIFICATION_TYPE_PLUGIN_BASE + 0x0001004);\n+define('NOTIFICATION_TYPE_DATAVERSE_STUDY_DELETED',  NOTIFICATION_TYPE_PLUGIN_BASE + 0x0001005);\n+define('NOTIFICATION_TYPE_DATAVERSE_STUDY_RELEASED', NOTIFICATION_TYPE_PLUGIN_BASE + 0x0001006);\n+define('NOTIFICATION_TYPE_DATAVERSE_UNRELEASED',     NOTIFICATION_TYPE_PLUGIN_BASE + 0x0001007);\n+\n+class DataversePlugin extends GenericPlugin {\n+\n+\t/**\n+\t * Called as a plugin is registered to the registry\n+\t * @param $category String Name of category plugin was registered to\n+   * @param $path String\n+\t * @return boolean True iff plugin initialized successfully; if false,\n+\t * \tthe plugin will not be registered.\n+\t */\n+  function register($category, $path) {\n+    $success = parent::register($category, $path);\n+    if ($success && $this->getEnabled()) {\n+      // Dataverse Study objects\n+      $this->import('classes.DataverseStudyDAO');\n+      $dataverseStudyDao = new DataverseStudyDAO($this->getName());\n+      $returner =& DAORegistry::registerDAO('DataverseStudyDAO', $dataverseStudyDao);\n+\n+      // Files associated with Dataverse studies\n+      $this->import('classes.DataverseFileDAO');      \n+      $dataverseFileDao = new DataverseFileDAO($this->getName());      \n+      $returner =& DAORegistry::registerDAO('DataverseFileDAO', $dataverseFileDao);\n+          \n+      // Handler for public (?) access to Dataverse-related information (i.e., terms of Use)\n+      HookRegistry::register('LoadHandler', array(&$this, 'setupPublicHandler'));\n+      // Add data citation to submissions & reading tools  \n+      HookRegistry::register('TemplateManager::display', array(&$this, 'handleTemplateDisplay'));\n+      // Add data citation to article landing page\n+      HookRegistry::register('Templates::Article::MoreInfo', array(&$this, 'addDataCitationArticle'));\n+      // Enable TinyMCEditor in textarea fields\n+      HookRegistry::register('TinyMCEPlugin::getEnableFields', array(&$this, 'getTinyMCEEnabledFields'));\n+      // Include data policy in About page\n+      HookRegistry::register('Templates::About::Index::Policies', array(&$this, 'addPolicyLinks'));\n+      \n+      // Add data publication options to author submission suppfile form: \n+      HookRegistry::register('Templates::Author::Submit::SuppFile::AdditionalMetadata', array(&$this, 'suppFileAdditionalMetadata'));\n+      HookRegistry::register('authorsubmitsuppfileform::initdata', array(&$this, 'suppFileFormInitData'));\n+      HookRegistry::register('authorsubmitsuppfileform::readuservars', array(&$this, 'suppFileFormReadUserVars'));\n+      HookRegistry::register('authorsubmitsuppfileform::execute', array(&$this, 'authorSubmitSuppFileFormExecute'));\n+      \n+      // Add Dataverse deposit options to suppfile form for completed submissions\n+      HookRegistry::register('Templates::Submission::SuppFile::AdditionalMetadata', array(&$this, 'suppFileAdditionalMetadata'));\n+      HookRegistry::register('suppfileform::initdata', array(&$this, 'suppFileFormInitData'));\n+      HookRegistry::register('suppfileform::readuservars', array(&$this, 'suppFileFormReadUserVars'));\n+      HookRegistry::register('suppfileform::execute', array(&$this, 'suppFileFormExecute'));\n+      \n+      // Notify ArticleDAO of article metadata field (external data citation) in suppfile form\n+      HookRegistry::register('articledao::getAdditionalFieldNames', array(&$this, 'articleMetadataFormFieldNames'));\n+      \n+      // Validate suppfile forms: warn if Dataverse deposit selected but no file uploaded\n+      HookRegistry::register('authorsubmitsuppfileform::Constructor', array(&$this, 'suppFileFormConstructor'));\n+      HookRegistry::register('suppfileform::Constructor', array(&$this, 'suppFileFormConstructor'));  \n+      \n+      // Metadata form: update cataloguing information. Prevent update if study locked.\n+      HookRegistry::register('metadataform::Constructor', array(&$this, 'metadataFormConstructor'));\n+      HookRegistry::register('metadataform::execute', array(&$this, 'metadataFormExecute'));\n+      \n+      // Handle suppfile insertion: prevent duplicate insertion of a suppfile\n+      HookRegistry::register('suppfiledao::_insertsuppfile', array(&$this, 'handleSuppFileInsertion'));\n+      // Handle suppfile deletion: only necessary for completed submissions\n+      HookRegistry::register('suppfiledao::_deletesuppfilebyid', array(&$this, 'handleSuppFileDeletion'));\n+      // Add form validator to check whether submission includes data files \n+      HookRegistry::register('authorsubmitstep4form::Constructor', array(&$this, 'addAuthorSubmitFormValidator'));\n+      // Create study for author submissions\n+      HookRegistry::register('Author::SubmitHandler::saveSubmit', array(&$this, 'handleAuthorSubmission'));\n+      // Release or delete studies according to editor decision\n+      HookRegistry::register('SectionEditorAction::unsuitableSubmission', array(&$this, 'handleUnsuitableSubmission'));\n+      HookRegistry::register('SectionEditorAction::recordDecision', array(&$this, 'handleEditorDecision'));\n+      // Release studies on article publication\n+      HookRegistry::register('articledao::_updatearticle', array(&$this, 'handleArticleUpdate'));\n+      \n+      // Get content for plugin notifications\n+      HookRegistry::register('NotificationManager::getNotificationContents', array(&$this, 'getNotificationContents'));\n+    }\n+    return $success;\n+  }\n+\n+\tfunction getDisplayName() {\n+\t\treturn __('plugins.generic.dataverse.displayName');\n+\t}\n+\n+\tfunction getDescription() {\n+\t\treturn __('plugins.generic.dataverse.description');\n+\t}\n+\n+\tfunction getInstallSchemaFile() {\n+    return $this->getPluginPath() . '/schema.xml';\n+\t}\n+\n+\tfunction getHandlerPath() {\n+\t\treturn $this->getPluginPath() . '/pages/';\n+\t}\n+  \n+\tfunction getTemplatePath() {\n+    return parent::getTemplatePath() . 'templates/';\n+\t}  \n+\t\n+\t/**\n+\t * Display verbs for the management interface.\n+\t */\n+  function getManagementVerbs() {\n+\t\t$verbs = array();\n+    if ($this->getEnabled()) {\n+      $verbs[] = array('connect', __('plugins.generic.dataverse.settings.connect'));\n+      $verbs[] = array('select', __('plugins.generic.dataverse.settings.selectDataverse')); \n+      $verbs[] = array('settings', __('plugins.generic.dataverse.settings'));\n+    }\n+\t\treturn parent::getManagementVerbs($verbs);\n+  }\n+\n+\t/**\n+     * Execute a management verb on this plugin\n+     * @param $verb string\n+     * @param $args array\n+     * @param $message string Result status message\n+     * @param $messageParams array Parameters for the message key\n+     * @return boolean\n+     */\n+    function manage($verb, $args, &$message, &$messageParams) {\n+      if (!parent::manage($verb, $args, $message, $messageParams)) return false;\n+\n+      $templateMgr =& TemplateManager::getManager();\n+      $templateMgr->register_function('plugin_url', array(&$this, 'smartyPluginUrl'));\n+      $journal =& Request::getJournal();\n+      \n+      switch ($verb) {\n+        case 'connect':\n+          $this->import('classes.form.DataverseAuthForm');\n+          $form = new DataverseAuthForm($this, $journal->getId());\n+          if (Request::getUserVar('save')) {\n+            $form->readInputData();\n+            if ($form->validate()) {\n+              $form->execute();\n+               Request::redirect(null, 'manager', 'plugin', array('generic', $this->getName(), 'select'));\n+              return false;\n+            } else {\n+              $form->display();\n+            }\n+          } else {\n+            $form->initData();\n+            $form->display();\n+          }\n+          return true;\n+        case 'select':\n+          $this->import('classes.form.DataverseSelectForm');\n+          $form = new DataverseSelectForm($this, $journal->getId());\n+          if (Request::getUserVar('save')) {\n+            $form->readInputData();\n+            if ($form->validate()) {\n+              $form->execute();\n+               Request::redirect(null, 'manager', 'plugin', array('generic', $this->getName(), 'settings'));\n+              return false;\n+            } else {\n+              $form->display();\n+            }\n+          } else {\n+            $form->initData();\n+            $form->display();\n+          }          \n+          return true;\n+        case 'settings':\n+          $this->import('classes.form.SettingsForm');\n+          $form = new SettingsForm($this, $journal->getId());\n+          if (Request::getUserVar('save')) {\n+            $form->readInputData();\n+            if ($form->validate()) {\n+              $form->execute();\n+              Request::redirect(null, 'manager', 'plugin', array('generic'));\n+              return false;\n+            } else {\n+              $form->display();\n+            }\n+          } else {\n+            $form->initData();\n+            $form->display();\n+          }\n+          return true;\n+      }\n+\n+    }\n+\n+\tfunction smartyPluginUrl($params, &$smarty) {\n+\t\t$path = array($this->getCategory(), $this->getName());\n+\t\tif (is_array($params['path'])) {\n+\t\t\t$params['path'] = array_merge($path, $params['path']);\n+\t\t} elseif (!empty($params['path'])) {\n+\t\t\t$params['path'] = array_merge($path, array($params['path']));\n+\t\t} else {\n+\t\t\t$params['path'] = $path;\n+\t\t}\n+\n+\t\tif (!empty($params['id'])) {\n+\t\t\t$params['path'] = array_merge($params['path'], array($params['id']));\n+\t\t\tunset($params['id']);\n+\t\t}\n+\t\treturn $smarty->smartyUrl($params, $smarty);\n+\t}\n+  \n+  /**\n+   * Hook callback: register pages for terms of use & data policy\n+\t */\n+\tfunction setupPublicHandler($hookName, $params) {\n+\t\t$page =& $params[0];\n+\t\tif ($page == 'dataverse') {\n+\t\t\t$op =& $params[1];\n+\t\t\tif ($op) {\n+\t\t\t\t$publicPages = array(\n+\t\t\t\t\t'index',\n+\t\t\t\t\t'dataAvailabilityPolicy',\n+\t\t\t\t\t'termsOfUse',\n+\t\t\t\t);\n+\n+\t\t\t\tif (in_array($op, $publicPages)) {\n+\t\t\t\t\tdefine('HANDLER_CLASS', 'DataverseHandler');\n+\t\t\t\t\tdefine('DATAVERSE_PLUGIN_NAME', $this->getName());\n+\t\t\t\t\tAppLocale::requireComponents(LOCALE_COMPONENT_APPLICATION_COMMON);\n+\t\t\t\t\t$handlerFile =& $params[2];\n+\t\t\t\t\t$handlerFile = $this->getHandlerPath() . 'DataverseHandler.inc.php';\n+\t\t\t\t}\n+\t\t\t}\n+\t\t}\n+\t}  \n+  \n+\t/**\n+\t * Hook callback: add data citation to submissions, published articles, and\n+   * reading tools.\n+\t */\n+  function handleTemplateDisplay($hookName, $args) {\n+    $templateMgr =& $args[0];\n+    $template =& $args[1];\n+\n+    switch ($template) {\n+      case 'author/submission.tpl':      \n+      case 'sectionEditor/submission.tpl':\n+        $templateMgr->register_outputfilter(array(&$this, 'submissionOutputFilter'));\n+        break;      \n+      case 'rt/suppFiles.tpl':\n+      case 'rt/suppFilesView.tpl':        \n+      case 'rt/metadata.tpl':\n+        $dataverseStudyDao =& DAORegistry::getDAO('DataverseStudyDAO');        \n+        $article =& $templateMgr->get_template_vars('article');\n+        $study =& $dataverseStudyDao->getStudyBySubmissionId($article->getId());\n+        if (!isset($study)) return false;\n+        $dataverseFileDao =& DAORegistry::getDAO('DataverseFileDAO');\n+        $dvFiles =& $dataverseFileDao->getDataverseFilesBySubmissionId($article->getId());\n+        $dvFileIndex = array();\n+        foreach ($dvFiles as $dvFile) {\n+          $dvFileIndex[$dvFile->getSuppFileId()] = true;\n+        }\n+        $templateMgr->assign_by_ref('study', $study);        \n+        $templateMgr->assign('dvFileIndex', $dvFileIndex);\n+        $templateMgr->assign('dataCitation', $study->getDataCitation());\n+        $templateMgr->display($this->getTemplatePath() .'/'. $template);\n+        return true;\n+    }\n+    return false;\n+  }\n+\n+  /**\n+   * Output filter: add data citation to editor & author view of submission summary\n+   */\n+  function submissionOutputFilter($output, &$smarty) {\n+    $submission =& $smarty->get_template_vars('submission');\n+    if (!isset($submission)) return $output;\n+      \n+    $dataverseStudyDao =& DAORegistry::getDAO('DataverseStudyDAO');\n+    $study =& $dataverseStudyDao->getStudyBySubmissionId($submission->getId());\n+\n+    $dataCitation = '';\n+    if (isset($study)) {\n+      $dataCitation = $study->getDataCitation();\n+    }\n+    else {\n+      // There may be an external data citation\n+      $dataCitation = $submission->getLocalizedData('externalDataCitation');\n+    }\n+    if (!$dataCitation) return $output;\n+\n+    $index = strpos($output, '<td class=\"label\">'. __('submission.submitter'));\n+    if ($index !== false) {\n+      $newOutput = substr($output,0,$index);\n+      $newOutput .= '<td class=\"label\">'.  __('plugins.generic.dataverse.dataCitation') .'</td>';\n+      $newOutput .= '<td class=\"value\" colspan=\"2\">'. $dataCitation .'</td></tr><tr>';\n+      $newOutput .= substr($output, $index);\n+      $output =& $newOutput;\n+    }\n+\t\t$smarty->unregister_outputfilter('submissionSummaryOutputFilter');\n+    return $output;\n+\t}\n+  \n+  /**\n+   * Add data citation to article landing page.\n+   * @param String $hookName\n+   * @param array $args\n+   */\n+  function addDataCitationArticle($hookName, $args) {\n+\t\t$smarty =& $args[1];\n+\t\t$output =& $args[2];\n+    \n+\t\t$templateMgr =& TemplateManager::getManager();    ","path":"plugins/generic/dataverse/DataversePlugin.inc.php","position":338,"original_position":338,"commit_id":"a839da46937acf7bde62fc4ea35baac0e173e743","original_commit_id":"a839da46937acf7bde62fc4ea35baac0e173e743","user":{"login":"asmecher","id":200411,"avatar_url":"https://avatars.githubusercontent.com/u/200411?","gravatar_id":"871f5455b4630e874f5f5052cafd7319","url":"https://api.github.com/users/asmecher","html_url":"https://github.com/asmecher","followers_url":"https://api.github.com/users/asmecher/followers","following_url":"https://api.github.com/users/asmecher/following{/other_user}","gists_url":"https://api.github.com/users/asmecher/gists{/gist_id}","starred_url":"https://api.github.com/users/asmecher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asmecher/subscriptions","organizations_url":"https://api.github.com/users/asmecher/orgs","repos_url":"https://api.github.com/users/asmecher/repos","events_url":"https://api.github.com/users/asmecher/events{/privacy}","received_events_url":"https://api.github.com/users/asmecher/received_events","type":"User","site_admin":false},"body":"(BTW, $templateMgr === $smarty)","created_at":"2014-04-01T18:37:17Z","updated_at":"2014-04-01T18:37:17Z","html_url":"https://github.com/pkp/ojs/pull/155#discussion_r11174320","pull_request_url":"https://api.github.com/repos/pkp/ojs/pulls/155","_links":{"self":{"href":"https://api.github.com/repos/pkp/ojs/pulls/comments/11174320"},"html":{"href":"https://github.com/pkp/ojs/pull/155#discussion_r11174320"},"pull_request":{"href":"https://api.github.com/repos/pkp/ojs/pulls/155"}}}}