From 5ea581f2157d756df1db131a3eb3399bd39f63e1 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Fri, 13 Feb 2015 13:51:11 -0500
Subject: [PATCH] Added mechanism to separate export format labels from unique
 IDs. - Also cleaned up inconsistent use of the translator; all labels are now
 translated. - Resolves VUFIND-1065.

---
 config/vufind/export.ini                          |  2 ++
 module/VuFind/src/VuFind/Export.php               | 15 ++++++++++++++-
 .../RecordDriver/SolrDefault/toolbar.phtml        |  2 +-
 .../templates/ajax/export-favorites.phtml         |  2 +-
 themes/blueprint/templates/cart/export.phtml      |  2 +-
 .../blueprint/templates/record/export-menu.phtml  |  2 +-
 .../RecordDriver/SolrDefault/toolbar.phtml        |  2 +-
 .../templates/ajax/export-favorites.phtml         |  2 +-
 themes/bootstrap3/templates/cart/export.phtml     |  2 +-
 .../bootstrap3/templates/record/export-menu.phtml |  2 +-
 10 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/config/vufind/export.ini b/config/vufind/export.ini
index 4bdb7e57ac6..6866fa07358 100644
--- a/config/vufind/export.ini
+++ b/config/vufind/export.ini
@@ -12,6 +12,8 @@
 ;     non-XML formats.
 ; headers[] - a repeatable field containing HTTP headers that should be output to
 ;     specify the appropriate export format.
+; label - the label to display to the user when referring to this format; if omitted,
+;     the section name will be used by default.
 ; redirectUrl - a URL to forward the user to when they export this format (used for
 ;     sending data to an external service like RefWorks).  The URL must include one
 ;     or more of these special tokens:
diff --git a/module/VuFind/src/VuFind/Export.php b/module/VuFind/src/VuFind/Export.php
index 52ed4a57eb3..53c9042587d 100644
--- a/module/VuFind/src/VuFind/Export.php
+++ b/module/VuFind/src/VuFind/Export.php
@@ -90,7 +90,7 @@ class Export
                     if (isset($this->mainConfig->Export->$option)
                         && $this->mainConfig->Export->$option == true
                     ) {
-                            $this->bulkOptions[] = $option;
+                        $this->bulkOptions[] = $option;
                     }
                 }
             }
@@ -325,4 +325,17 @@ class Export
         return isset($this->exportConfig->$format->headers)
             ? $this->exportConfig->$format->headers : array();
     }
+
+    /**
+     * Get the display label for the specified export format.
+     *
+     * @param string $format Format identifier
+     *
+     * @return string
+     */
+    public function getLabelForFormat($format)
+    {
+        return isset($this->exportConfig->$format->label)
+            ? $this->exportConfig->$format->label : $format;
+    }
 }
diff --git a/themes/blueprint/templates/RecordDriver/SolrDefault/toolbar.phtml b/themes/blueprint/templates/RecordDriver/SolrDefault/toolbar.phtml
index 59dfc5148fb..2ab3ba08460 100644
--- a/themes/blueprint/templates/RecordDriver/SolrDefault/toolbar.phtml
+++ b/themes/blueprint/templates/RecordDriver/SolrDefault/toolbar.phtml
@@ -22,7 +22,7 @@
       <a href="<?=$this->recordLink()->getActionUrl($this->driver, 'Export')?>" class="export exportMenu"><?=$this->transEsc('Export Record')?></a>
       <ul class="menu offscreen" id="exportMenu">
       <? foreach ($exportFormats as $exportFormat): ?>
-        <li><a <? if ($this->export()->needsRedirect($exportFormat)): ?>target="<?=$this->escapeHtmlAttr($exportFormat)?>Main" <? endif; ?>href="<?=$this->recordLink()->getActionUrl($this->driver, 'Export')?>?style=<?=$this->escapeHtmlAttr($exportFormat)?>"><?=$this->transEsc('Export to')?> <?=$this->escapeHtml($exportFormat)?></a></li>
+        <li><a <? if ($this->export()->needsRedirect($exportFormat)): ?>target="<?=$this->escapeHtmlAttr($exportFormat)?>Main" <? endif; ?>href="<?=$this->recordLink()->getActionUrl($this->driver, 'Export')?>?style=<?=$this->escapeHtmlAttr($exportFormat)?>"><?=$this->transEsc('Export to')?> <?=$this->transEsc($this->export()->getLabelForFormat($exportFormat))?></a></li>
       <? endforeach; ?>
       </ul>
     </li>
diff --git a/themes/blueprint/templates/ajax/export-favorites.phtml b/themes/blueprint/templates/ajax/export-favorites.phtml
index 93fb0270e37..c1120508d1e 100644
--- a/themes/blueprint/templates/ajax/export-favorites.phtml
+++ b/themes/blueprint/templates/ajax/export-favorites.phtml
@@ -1,7 +1,7 @@
 <p>
   <a class="save" onclick="hideLightbox();" href="<?=$this->escapeHtmlAttr($this->url)?>"<?=$this->export()->needsRedirect($this->format) ? ' target="_blank"' : ''?>><?=
     $this->export()->needsRedirect($this->format)
-        ? $this->transEsc('export_redirect', array('%%service%%' => $this->translate($this->format)))
+        ? $this->transEsc('export_redirect', array('%%service%%' => $this->translate($this->export()->getLabelForFormat($this->format))))
         : $this->transEsc('export_download')
   ?></a>
 </p>
\ No newline at end of file
diff --git a/themes/blueprint/templates/cart/export.phtml b/themes/blueprint/templates/cart/export.phtml
index 6c5da4a54b3..249716037ed 100644
--- a/themes/blueprint/templates/cart/export.phtml
+++ b/themes/blueprint/templates/cart/export.phtml
@@ -20,7 +20,7 @@
     <label for="format"><?=$this->transEsc('Format')?>:</label>
     <select name="format" id="format">
       <? foreach ($this->exportOptions as $exportOption): ?>
-        <option value="<?=$this->escapeHtmlAttr($exportOption)?>"><?=$this->transEsc($exportOption)?></option>
+        <option value="<?=$this->escapeHtmlAttr($exportOption)?>"><?=$this->transEsc($this->export()->getLabelForFormat($exportOption))?></option>
       <? endforeach; ?>
     </select>
     <br/>
diff --git a/themes/blueprint/templates/record/export-menu.phtml b/themes/blueprint/templates/record/export-menu.phtml
index bf75a3000fb..ee672ab24fd 100644
--- a/themes/blueprint/templates/record/export-menu.phtml
+++ b/themes/blueprint/templates/record/export-menu.phtml
@@ -11,7 +11,7 @@
   <?=$this->transEsc('export_choose_format')?>
   <ul>
   <? foreach ($exportFormats as $exportFormat): ?>
-    <li><a href="<?=$this->recordLink()->getActionUrl($this->driver, 'Export')?>?style=<?=$this->escapeHtml($exportFormat)?>"><?=$this->transEsc('Export to')?> <?=$this->escapeHtml($exportFormat)?></a></li>
+    <li><a href="<?=$this->recordLink()->getActionUrl($this->driver, 'Export')?>?style=<?=$this->escapeHtml($exportFormat)?>"><?=$this->transEsc('Export to')?> <?=$this->transEsc($this->export()->getLabelForFormat($exportFormat))?></a></li>
   <? endforeach; ?>
   </ul>
 <? else: ?>
diff --git a/themes/bootstrap3/templates/RecordDriver/SolrDefault/toolbar.phtml b/themes/bootstrap3/templates/RecordDriver/SolrDefault/toolbar.phtml
index 5cf00aa3b64..8194442dd2c 100644
--- a/themes/bootstrap3/templates/RecordDriver/SolrDefault/toolbar.phtml
+++ b/themes/bootstrap3/templates/RecordDriver/SolrDefault/toolbar.phtml
@@ -23,7 +23,7 @@
       <a class="export-toggle dropdown-toggle" data-toggle="dropdown" href="<?=$this->recordLink()->getActionUrl($this->driver, 'Export')?>"><i class="fa fa-list-alt"></i> <?=$this->transEsc('Export Record') ?></a>
       <ul class="dropdown-menu" role="menu">
         <? foreach ($exportFormats as $exportFormat): ?>
-          <li><a <? if ($this->export()->needsRedirect($exportFormat)): ?>target="<?=$this->escapeHtmlAttr($exportFormat)?>Main" <? endif; ?>href="<?=$this->recordLink()->getActionUrl($this->driver, 'Export')?>?style=<?=$this->escapeHtmlAttr($exportFormat)?>"><?=$this->transEsc('Export to')?> <?=$this->transEsc($exportFormat)?></a></li>
+          <li><a <? if ($this->export()->needsRedirect($exportFormat)): ?>target="<?=$this->escapeHtmlAttr($exportFormat)?>Main" <? endif; ?>href="<?=$this->recordLink()->getActionUrl($this->driver, 'Export')?>?style=<?=$this->escapeHtmlAttr($exportFormat)?>"><?=$this->transEsc('Export to')?> <?=$this->transEsc($this->export()->getLabelForFormat($exportFormat))?></a></li>
         <? endforeach; ?>
       </ul>
     </li>
diff --git a/themes/bootstrap3/templates/ajax/export-favorites.phtml b/themes/bootstrap3/templates/ajax/export-favorites.phtml
index 6ebf7207568..63648f8b29f 100644
--- a/themes/bootstrap3/templates/ajax/export-favorites.phtml
+++ b/themes/bootstrap3/templates/ajax/export-favorites.phtml
@@ -3,7 +3,7 @@
     <?=$this->transEsc('export_success'); ?>&nbsp;&mdash;&nbsp;
     <a class="btn btn-primary" href="<?=$this->escapeHtmlAttr($this->url)?>"<?=$this->export()->needsRedirect($this->format) ? ' target="_blank"' : ''?>><?=
         $this->export()->needsRedirect($this->format)
-            ? $this->transEsc('export_redirect', array('%%service%%' => $this->translate($this->format)))
+            ? $this->transEsc('export_redirect', array('%%service%%' => $this->translate($this->export()->getLabelForFormat($this->format))))
             : $this->transEsc('export_download')
       ?></a>
   </div>
diff --git a/themes/bootstrap3/templates/cart/export.phtml b/themes/bootstrap3/templates/cart/export.phtml
index 3acc97d3fcf..b0fb46a3759 100644
--- a/themes/bootstrap3/templates/cart/export.phtml
+++ b/themes/bootstrap3/templates/cart/export.phtml
@@ -40,7 +40,7 @@
       <div class="col-sm-9">
         <select name="format" id="format" class="form-control">
           <? foreach ($this->exportOptions as $exportOption): ?>
-            <option value="<?=$this->escapeHtmlAttr($exportOption)?>"><?=$this->transEsc($exportOption)?></option>
+            <option value="<?=$this->escapeHtmlAttr($exportOption)?>"><?=$this->transEsc($this->export()->getLabelForFormat($exportOption))?></option>
           <? endforeach; ?>
         </select>
       </div>
diff --git a/themes/bootstrap3/templates/record/export-menu.phtml b/themes/bootstrap3/templates/record/export-menu.phtml
index ad399dafbe0..376a99c270f 100644
--- a/themes/bootstrap3/templates/record/export-menu.phtml
+++ b/themes/bootstrap3/templates/record/export-menu.phtml
@@ -12,7 +12,7 @@
   <?=$this->transEsc('export_choose_format')?>
   <ul>
   <? foreach ($exportFormats as $exportFormat): ?>
-    <li><a href="<?=$this->recordLink()->getActionUrl($this->driver, 'Export')?>?style=<?=$this->escapeHtml($exportFormat)?>"><?=$this->transEsc('Export to')?> <?=$this->escapeHtml($exportFormat)?></a></li>
+    <li><a href="<?=$this->recordLink()->getActionUrl($this->driver, 'Export')?>?style=<?=$this->escapeHtml($exportFormat)?>"><?=$this->transEsc('Export to')?> <?=$this->transEsc($this->export()->getLabelForFormat($exportFormat))?></a></li>
   <? endforeach; ?>
   </ul>
 <? else: ?>
-- 
GitLab