Result.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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
  17. * @subpackage Yahoo
  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. * @version $Id$
  21. */
  22. /**
  23. * @category Zend
  24. * @package Zend_Service
  25. * @subpackage Yahoo
  26. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  27. * @license http://framework.zend.com/license/new-bsd New BSD License
  28. */
  29. class Zend_Service_Yahoo_Result
  30. {
  31. /**
  32. * The title of the search entry
  33. *
  34. * @var string
  35. */
  36. public $Title;
  37. /**
  38. * The URL of the found object
  39. *
  40. * @var string
  41. */
  42. public $Url;
  43. /**
  44. * The URL for linking to the found object
  45. *
  46. * @var string
  47. */
  48. public $ClickUrl;
  49. /**
  50. * Result fields
  51. *
  52. * @var array
  53. */
  54. protected $_fields;
  55. /**
  56. * REST response fragment for the result
  57. *
  58. * @var DOMElement
  59. */
  60. protected $_result;
  61. /**
  62. * Object for XPath queries
  63. *
  64. * @var DOMXPath
  65. */
  66. protected $_xpath;
  67. /**
  68. * Initializes the result
  69. *
  70. * @param DOMElement $result
  71. * @return void
  72. */
  73. public function __construct(DOMElement $result)
  74. {
  75. // default fields for all search results:
  76. $fields = array('Title', 'Url', 'ClickUrl');
  77. // merge w/ child's fields
  78. $this->_fields = array_merge($this->_fields, $fields);
  79. $this->_xpath = new DOMXPath($result->ownerDocument);
  80. $this->_xpath->registerNamespace('yh', $this->_namespace);
  81. // add search results to appropriate fields
  82. foreach ($this->_fields as $f) {
  83. $query = "./yh:$f/text()";
  84. $node = $this->_xpath->query($query, $result);
  85. if ($node->length == 1) {
  86. $this->{$f} = $node->item(0)->data;
  87. }
  88. }
  89. $this->_result = $result;
  90. }
  91. /**
  92. * Sets the Thumbnail property
  93. *
  94. * @return void
  95. */
  96. protected function _setThumbnail()
  97. {
  98. $node = $this->_xpath->query('./yh:Thumbnail', $this->_result);
  99. if ($node->length == 1) {
  100. /**
  101. * @see Zend_Service_Yahoo_Image
  102. */
  103. require_once 'Zend/Service/Yahoo/Image.php';
  104. $this->Thumbnail = new Zend_Service_Yahoo_Image($node->item(0), $this->_namespace);
  105. } else {
  106. $this->Thumbnail = null;
  107. }
  108. }
  109. }