File indexing completed on 2024-12-22 05:37:06
0001 <?php 0002 0003 /** 0004 * Zend Framework 0005 * 0006 * LICENSE 0007 * 0008 * This source file is subject to the new BSD license that is bundled 0009 * with this package in the file LICENSE.txt. 0010 * It is also available through the world-wide-web at this URL: 0011 * http://framework.zend.com/license/new-bsd 0012 * If you did not receive a copy of the license and are unable to 0013 * obtain it through the world-wide-web, please send an email 0014 * to license@zend.com so we can send you a copy immediately. 0015 * 0016 * @category Zend 0017 * @package Zend_Service 0018 * @subpackage Yahoo 0019 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0020 * @license http://framework.zend.com/license/new-bsd New BSD License 0021 * @version $Id$ 0022 */ 0023 0024 0025 /** 0026 * @category Zend 0027 * @package Zend_Service 0028 * @subpackage Yahoo 0029 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0030 * @license http://framework.zend.com/license/new-bsd New BSD License 0031 */ 0032 class Zend_Service_Yahoo_Result 0033 { 0034 /** 0035 * The title of the search entry 0036 * 0037 * @var string 0038 */ 0039 public $Title; 0040 0041 /** 0042 * The URL of the found object 0043 * 0044 * @var string 0045 */ 0046 public $Url; 0047 0048 /** 0049 * The URL for linking to the found object 0050 * 0051 * @var string 0052 */ 0053 public $ClickUrl; 0054 0055 /** 0056 * Result fields 0057 * 0058 * @var array 0059 */ 0060 protected $_fields; 0061 0062 /** 0063 * REST response fragment for the result 0064 * 0065 * @var DOMElement 0066 */ 0067 protected $_result; 0068 0069 /** 0070 * Object for XPath queries 0071 * 0072 * @var DOMXPath 0073 */ 0074 protected $_xpath; 0075 0076 0077 /** 0078 * Initializes the result 0079 * 0080 * @param DOMElement $result 0081 * @return void 0082 */ 0083 public function __construct(DOMElement $result) 0084 { 0085 // default fields for all search results: 0086 $fields = array('Title', 'Url', 'ClickUrl'); 0087 0088 // merge w/ child's fields 0089 $this->_fields = array_merge($this->_fields, $fields); 0090 0091 $this->_xpath = new DOMXPath($result->ownerDocument); 0092 $this->_xpath->registerNamespace('yh', $this->_namespace); 0093 0094 // add search results to appropriate fields 0095 0096 foreach ($this->_fields as $f) { 0097 $query = "./yh:$f/text()"; 0098 $node = $this->_xpath->query($query, $result); 0099 if ($node->length == 1) { 0100 $this->{$f} = $node->item(0)->data; 0101 } 0102 } 0103 0104 $this->_result = $result; 0105 } 0106 0107 0108 /** 0109 * Sets the Thumbnail property 0110 * 0111 * @return void 0112 */ 0113 protected function _setThumbnail() 0114 { 0115 $node = $this->_xpath->query('./yh:Thumbnail', $this->_result); 0116 if ($node->length == 1) { 0117 /** 0118 * @see Zend_Service_Yahoo_Image 0119 */ 0120 // require_once 'Zend/Service/Yahoo/Image.php'; 0121 $this->Thumbnail = new Zend_Service_Yahoo_Image($node->item(0), $this->_namespace); 0122 } else { 0123 $this->Thumbnail = null; 0124 } 0125 } 0126 }