Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a new tab for embedded previews with google books functionality #181

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions config/vufind/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -563,9 +563,12 @@ authors = Wikipedia
;HathiRights = pd,ic-world,cc-by,cc-by-nd,cc-by-nc-nd,cc-by-nc,cc-by-nc-sa,cc-by-sa,cc-zero,und-world

; Possible GoogleBooks options full,partial,noview
; Default is "full,partial" if unset here.
; options can be set for each / either of link or tab
; Default is "GoogleOptions['link'] = full,partial" if nothing
; is set here.
; see code.google.com/apis/books/docs/dynamic-links.html#JSONformat
;GoogleOptions = full,partial
GoogleOptions['link'] = full,partial
;GoogleOptions['tab'] = partial

; OpenLibrary currently offers the same options/default as GoogleBooks (above):
;OpenLibraryOptions = full,partial
Expand Down
3 changes: 3 additions & 0 deletions module/VuFind/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@
'map' => 'VuFind\RecordTab\Factory::getMap',
'reviews' => 'VuFind\RecordTab\Factory::getReviews',
'usercomments' => 'VuFind\RecordTab\Factory::getUserComments',
'preview' => 'VuFind\RecordTab\Factory::getPreview',
),
'invokables' => array(
'description' => 'VuFind\RecordTab\Description',
Expand Down Expand Up @@ -577,6 +578,7 @@
'Holdings' => 'HoldingsILS', 'Description' => 'Description',
'TOC' => 'TOC', 'UserComments' => 'UserComments',
'Reviews' => 'Reviews', 'Excerpt' => 'Excerpt',
'Preview' => 'preview',
'HierarchyTree' => 'HierarchyTree', 'Map' => 'Map',
'Details' => 'StaffViewArray',
),
Expand All @@ -587,6 +589,7 @@
'Holdings' => 'HoldingsILS', 'Description' => 'Description',
'TOC' => 'TOC', 'UserComments' => 'UserComments',
'Reviews' => 'Reviews', 'Excerpt' => 'Excerpt',
'Preview' => 'preview',
'HierarchyTree' => 'HierarchyTree', 'Map' => 'Map',
'Details' => 'StaffViewMARC',
),
Expand Down
13 changes: 12 additions & 1 deletion module/VuFind/src/VuFind/RecordTab/AbstractBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ public function isActive()
return true;
}

/**
* Is this tab initially visible?
*
* @return bool
*/
public function isVisible()
{
// Assume visible by default; subclasses may add rules.
return true;
}

/**
* Set the record driver
*
Expand Down Expand Up @@ -112,4 +123,4 @@ protected function getRequest()
{
return $this->request;
}
}
}
34 changes: 33 additions & 1 deletion module/VuFind/src/VuFind/RecordTab/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,36 @@ public static function getUserComments(ServiceManager $sm)
|| ($cfg->Social->comments && $cfg->Social->comments !== 'disabled');
return new UserComments($enabled);
}
}

/**
* Factory for Preview tab plugin.
*
* @param ServiceManager $sm Service manager.
*
* @return Preview
*/
public static function getPreview(ServiceManager $sm)
{
$cfg = $sm->getServiceLocator()->get('VuFind\Config')->get('config');
// currently only active if config [content] [previews] contains google
// and googleoptions[tab] is not empty.
$active = false;
if (isset($cfg->Content->previews)) {
$content_previews = explode(
',', strtolower(str_replace(' ', '', $cfg->Content->previews))
);
if (in_array('google', $content_previews)
&& isset($cfg->Content->GoogleOptions)
) {
$g_options = $cfg->Content->GoogleOptions;
if (isset($g_options->tab)) {
$tabs = explode(',', $g_options->tab);
if (count($tabs) > 0) {
$active = true;
}
}
}
}
return new Preview($active);
}
}
96 changes: 96 additions & 0 deletions module/VuFind/src/VuFind/RecordTab/Preview.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php
/**
* Embedded Preview tab
*
* PHP version 5
*
* Copyright (C) Villanova University 2010.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @category VuFind2
* @package RecordTabs
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org/wiki/vufind2:record_tabs Wiki
*/
namespace VuFind\RecordTab;

/**
* Embedded Preview tab
*
* @category VuFind2
* @package RecordTabs
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org/wiki/vufind2:record_tabs Wiki
*/
class Preview extends AbstractBase
{
/**
* Configuration
*
* @var \Zend\Config\Config
*/
protected $config = null;

/**
* Is this tab active?
*
* @var bool
*/
protected $active = false;

/**
* Constructor
*
* @param bool $active Is this tab active?
*/
public function __construct($active)
{
$this->active = $active;
}

/**
* Get the on-screen description for this tab.
*
* @return string
*/
public function getDescription()
{
return 'Preview';
}

/**
* Is this tab active?
*
* @return bool
*/
public function isActive()
{
return $this->active;
}

/**
* Is this tab initially visible?
*
* @return bool
*/
public function isVisible()
{
// in this case there is no downside to keeping it hidden
// until there is content
return false;
}
}
62 changes: 59 additions & 3 deletions module/VuFind/src/VuFind/View/Helper/Root/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,18 +234,74 @@ public function getListEntry($list = null, $user = false)
}

/**
* Render previews of the item if configured.
* Render previews (data and link) of the item if configured.
*
* @return string
*/
public function getPreviews()
{
return $this->getPreviewData() . $this->getPreviewLink();
}

/**
* Render data needed to get previews.
*
* @return string
*/
public function getPreviewData()
{
return $this->renderTemplate(
'preview.phtml',
'previewdata.phtml',
array('driver' => $this->driver, 'config' => $this->config)
);
}

/**
* Render links to previews of the item if configured.
*
* @return string
*/
public function getPreviewLink()
{
return $this->renderTemplate(
'previewlink.phtml',
array('driver' => $this->driver, 'config' => $this->config)
);
}

/**
* collects ISBN, LCCN, and OCLC numbers to use in calling preview APIs
*
* @return array
*/
public function getPreviewIds()
{
// Extract identifiers from record driver if it supports appropriate methods:
$isbn = is_callable(array($this->driver, 'getCleanISBN'))
? $this->driver->getCleanISBN() : '';
$lccn = is_callable(array($this->driver, 'getLCCN'))
? $this->driver->getLCCN() : '';
$oclc = is_callable(array($this->driver, 'getOCLC'))
? $this->driver->getOCLC() : array();

// Turn identifiers into class names to communicate with jQuery logic:
$idClasses = array();
if (!empty($isbn)) {
$idClasses[] = 'ISBN' . $isbn;
}
if (!empty($lccn)) {
$idClasses[] = 'LCCN' . $lccn;
}
if (!empty($oclc)) {
foreach ($oclc as $oclcNum) {
if (!empty($oclcNum)) {
$idClasses[] = 'OCLC' . $oclcNum;
}
}
}
return $idClasses;
}

/**
* Get the name of the controller used by the record route.
*
Expand Down Expand Up @@ -479,4 +535,4 @@ public function getLinkDetails()

return array_map($formatLink, $urls);
}
}
}
5 changes: 5 additions & 0 deletions themes/blueprint/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -2375,3 +2375,8 @@ div.handle {
#viz-instructions {
padding-top:600px;
}
#gbsViewer {
margin:25px 0px 50px 25px;
width: 90%;
height: 600px;
}
12 changes: 12 additions & 0 deletions themes/blueprint/js/embedGBS.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// we don't need to wait for dom ready since lang is in the dom root
var lang = document.documentElement.getAttribute('lang');
google.load("books", "0", {"language":lang});

function initialize() {
var bibkeys = getBibKeyString().split(/\s+/);
var viewer = new google.books.DefaultViewer(document.getElementById('gbsViewer'));
viewer.load(bibkeys);
}

google.setOnLoadCallback(initialize);