yahoo-multi-search.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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_Service_Yahoo
  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. * Query Yahoo! Web, Image and News searches
  23. */
  24. /**
  25. * @see Zend_Service_Yahoo
  26. */
  27. require_once 'Zend/Service/Yahoo.php';
  28. if (isset($_POST) && strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
  29. $keywords = strip_tags($_POST['search_term']);
  30. } else {
  31. $keywords = '';
  32. }
  33. ?>
  34. <!DOCTYPE html public "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  35. <html>
  36. <head>
  37. <style type="text/css">
  38. html, body {
  39. margin: 0px;
  40. padding: 0px;
  41. font-family: Tahoma, Verdana, sans-serif;
  42. font-size: 10px;
  43. }
  44. h1 {
  45. margin-top: 0px;
  46. background-color: darkblue;
  47. color: white;
  48. font-size: 16px;
  49. }
  50. form {
  51. text-align: center;
  52. }
  53. label {
  54. font-weight: bold;
  55. }
  56. img {
  57. border: 0px;
  58. padding: 5px;
  59. }
  60. #web, #news {
  61. float: left;
  62. width: 48%;
  63. margin-left: 10px;
  64. }
  65. #image {
  66. margin: 10px;
  67. border: 1px dashed grey;
  68. background-color: lightgrey;
  69. text-align: center;
  70. }
  71. h2 {
  72. font-size: 14px;
  73. color: grey;
  74. }
  75. h3 {
  76. font-size: 12px;
  77. }
  78. #poweredby {
  79. clear: both;
  80. }
  81. </style>
  82. </head>
  83. <body>
  84. <h1>Yahoo! Multi-Search</h1>
  85. <form action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post">
  86. <p>
  87. <label>Search For: <input type="text" name="search_term" value="<?php echo htmlspecialchars($keywords, ENT_QUOTES); ?>"></label>
  88. <input type="submit" value="Search!">
  89. </p>
  90. </form>
  91. <?php
  92. if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
  93. $yahoo = new Zend_Service_Yahoo('zendtesting');
  94. try {
  95. $results = $yahoo->imageSearch($keywords, array("results" => 5));
  96. if ($results->totalResults() > 0) {
  97. echo '<div id="image">';
  98. echo '<h2>Image Search Results</h2>';
  99. foreach ($results as $result) {
  100. echo "<a href='{$result->ClickUrl}' title='$result->Title'><img src='{$result->Thumbnail->Url->getUri()}'></a>";
  101. }
  102. echo '</div>';
  103. }
  104. $results = $yahoo->webSearch($keywords);
  105. if ($results->totalResults() > 0) {
  106. echo '<div id="web">';
  107. echo '<h2>Web Search Results</h2>';
  108. foreach ($results as $result) {
  109. echo "<h3><a href='{$result->ClickUrl}'>{$result->Title}</a></h3>";
  110. echo "<p>{$result->Summary} <br> [<a href='{$result->CacheUrl}'>Cached Version</a>]</p>";
  111. }
  112. echo '</div>';
  113. }
  114. $results = $yahoo->newsSearch($keywords);
  115. if ($results->totalResults() > 0) {
  116. echo '<div id="news">';
  117. echo '<h2>News Search Results</h2>';
  118. foreach ($results as $result) {
  119. echo "<h3><a href='{$result->ClickUrl}'>{$result->Title}</a></h3>";
  120. echo "<p>{$result->Summary}</p>";
  121. }
  122. echo '</div>';
  123. }
  124. }
  125. catch (Zend_Service_Exception $e) {
  126. echo '<p style="color: red; font-weight: bold">An error occured, please try again later.</p>';
  127. }
  128. }
  129. ?>
  130. <p id="poweredby" style="text-align: center; font-size: 9px;">Powered by the <a href="http://framework.zend.com">Zend Framework</a></p>
  131. </body>
  132. </html>