blob: 8d5e9ad145bafc6b13377ea8d30a740fcc11b9f7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Demos
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @see Zend_Loader
*/
require_once 'Zend/Loader.php';
/**
* @see Zend_Gdata_Books
*/
Zend_Loader::loadClass('Zend_Gdata_Books');
/**
* Return a comma separated string representing the elements of an array
*
* @param Array $elements The array of elements
* @return string Comma separated string
*/
function printArray($elements) {
$result = '';
foreach ($elements as $element) {
if (!empty($result)) $result = $result.', ';
$result = $result.$element;
}
return $result;
}
/**
* Echo the list of videos in the specified feed.
*
* @param Zend_Gdata_Books_BookFeed $feed The video feed
* @return void
*/
function echoBookList($feed)
{
print <<<HTML
<table><tr><td id="resultcell">
<div id="searchResults">
<table class="volumeList"><tbody width="100%">
HTML;
$flipflop = false;
foreach ($feed as $entry) {
$title = printArray($entry->getTitles());
$volumeId = $entry->getVolumeId();
if ($thumbnailLink = $entry->getThumbnailLink()) {
$thumbnail = $thumbnailLink->href;
} else {
$thumbnail = null;
}
$preview = $entry->getPreviewLink()->href;
$embeddability = $entry->getEmbeddability()->getValue();
$creators = printArray($entry->getCreators());
if (!empty($creators)) $creators = "by " . $creators;
if ($embeddability ==
"http://schemas.google.com/books/2008#embeddable") {
$preview_link = '<a href="javascript:load_viewport(\''.
$preview.'\',\'viewport\');">'.
'<img class="previewbutton" src="http://code.google.com/' .
'apis/books/images/gbs_preview_button1.png" />' .
'</a><br>';
} else {
$preview_link = '';
}
$thumbnail_img = (!$thumbnail) ? '' : '<a href="'.$preview.
'"><img src="'.$thumbnail.'"/></a>';
print <<<HTML
<tr>
<td><div class="thumbnail">
$thumbnail_img
</div></td>
<td width="100%">
<a href="${preview}">$title</a><br>
$creators<br>
$preview_link
</td></tr>
HTML;
}
print <<<HTML
</table></div></td>
<td width=50% id="previewcell"><div id="viewport"></div>
</td></tr></table><br></body></html>
HTML;
}
/*
* The main controller logic of the Books volume browser demonstration app.
*/
$queryType = isset($_GET['queryType']) ? $_GET['queryType'] : null;
include 'interface.html';
if ($queryType === null) {
/* display the entire interface */
} else {
$books = new Zend_Gdata_Books();
$query = $books->newVolumeQuery();
/* display a list of volumes */
if (isset($_GET['searchTerm'])) {
$searchTerm = $_GET['searchTerm'];
$query->setQuery($searchTerm);
}
if (isset($_GET['startIndex'])) {
$startIndex = $_GET['startIndex'];
$query->setStartIndex($startIndex);
}
if (isset($_GET['maxResults'])) {
$maxResults = $_GET['maxResults'];
$query->setMaxResults($maxResults);
}
if (isset($_GET['minViewability'])) {
$minViewability = $_GET['minViewability'];
$query->setMinViewability($minViewability);
}
/* check for one of the restricted feeds, or list from 'all' videos */
switch ($queryType) {
case 'full_view':
case 'partial_view':
$query->setMinViewability($queryType);
echo 'Requesting feed: ' . ($query->getQueryUrl()) . '<br><br>';
$feed = $books->getVolumeFeed($query);
break;
case 'all':
echo 'Requesting feed: ' . ($query->getQueryUrl()) . '<br><br>';
$feed = $books->getVolumeFeed($query);
break;
default:
echo 'ERROR - unknown queryType - "' . $queryType . '"';
break;
}
echoBookList($feed);
}
|