index.php 4.5 KB

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