cvs: pear /Services_Yahoo/Yahoo/Search AbstractSearch.php web.php

From: Date: Fri, 30 Sep 2005 18:01:38 +0000
Subject: cvs: pear /Services_Yahoo/Yahoo/Search AbstractSearch.php web.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-35180@lists.php.net to get a copy of this message
mj Fri Sep 30 14:01:38 2005 EDT Modified files: /pear/Services_Yahoo/Yahoo/Search AbstractSearch.php web.php Log: * Added some intial code to support adding multiple parameters to search queries. # Related to bug #5442 http://cvs.php.net/diff.php/pear/Services_Yahoo/Yahoo/Search/AbstractSearch.php?r1=1.2&r2=1.3&ty=u Index: pear/Services_Yahoo/Yahoo/Search/AbstractSearch.php diff -u pear/Services_Yahoo/Yahoo/Search/AbstractSearch.php:1.2 pear/Services_Yahoo/Yahoo/Search/AbstractSearch.php:1.3 --- pear/Services_Yahoo/Yahoo/Search/AbstractSearch.php:1.2 Tue Mar 22 06:53:41 2005 +++ pear/Services_Yahoo/Yahoo/Search/AbstractSearch.php Fri Sep 30 14:01:36 2005 @@ -17,7 +17,7 @@ * @author Martin Jansen <mj@php.net> * @copyright 2005 Martin Jansen * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: AbstractSearch.php,v 1.2 2005/03/22 11:53:41 mj Exp $ + * @version CVS: $Id: AbstractSearch.php,v 1.3 2005/09/30 18:01:36 mj Exp $ * @link http://pear.php.net/package/Services_Yahoo */ @@ -35,7 +35,7 @@ * @author Martin Jansen <mj@php.net> * @copyright 2005 Martin Jansen * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: AbstractSearch.php,v 1.2 2005/03/22 11:53:41 mj Exp $ + * @version CVS: $Id: AbstractSearch.php,v 1.3 2005/09/30 18:01:36 mj Exp $ * @link http://pear.php.net/package/Services_Yahoo */ abstract class Services_Yahoo_Search_AbstractSearch { @@ -58,6 +58,13 @@ $request = new HTTP_Request($this->requestURL); foreach ($this->parameters as $key => $value) { + if (is_array($value)) { + foreach ($value as $value2) { + $request->addQueryString($key, $value2); + } + continue; + } + $request->addQueryString($key, $value); } @@ -186,4 +193,23 @@ { $this->parameters['adult_ok'] = 1; } + + /** + * Removes elements identified by the $needle from the array $haystack + * + * @static + * @access protected + * @param array $haystack Array to remove the elements from + * @param mixed $needle Value of the elements to remove from the array + * @return array Array with elements removed + */ + protected static function removeArrayElement($haystack, $needle) { + $searches = array_keys($haystack, $needle); + $offset = 0; + foreach ($searches as $position) { + array_splice($haystack, $position - $offset++, 1); + } + + return $haystack; + } } http://cvs.php.net/diff.php/pear/Services_Yahoo/Yahoo/Search/web.php?r1=1.2&r2=1.3&ty=u Index: pear/Services_Yahoo/Yahoo/Search/web.php diff -u pear/Services_Yahoo/Yahoo/Search/web.php:1.2 pear/Services_Yahoo/Yahoo/Search/web.php:1.3 --- pear/Services_Yahoo/Yahoo/Search/web.php:1.2 Thu Apr 14 07:29:14 2005 +++ pear/Services_Yahoo/Yahoo/Search/web.php Fri Sep 30 14:01:36 2005 @@ -17,7 +17,7 @@ * @author Martin Jansen <mj@php.net> * @copyright 2005 Martin Jansen * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: web.php,v 1.2 2005/04/14 11:29:14 mj Exp $ + * @version CVS: $Id: web.php,v 1.3 2005/09/30 18:01:36 mj Exp $ * @link http://pear.php.net/package/Services_Yahoo */ @@ -34,7 +34,7 @@ * @author Martin Jansen <mj@php.net> * @copyright 2005 Martin Jansen * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: web.php,v 1.2 2005/04/14 11:29:14 mj Exp $ + * @version CVS: $Id: web.php,v 1.3 2005/09/30 18:01:36 mj Exp $ * @link http://pear.php.net/package/Services_Yahoo * @link http://developer.yahoo.net/web/V1/webSearch.html */ @@ -66,4 +66,42 @@ { $this->parameters['language'] = $language; } + + /** + * Sets the domains to restrict the search to + * + * @access public + * @param array Array of domains + */ + public function setSites($sites) { + $this->parameters['sites'] = $sites; + } + + /** + * Adds a domain to restrict the search to + * + * @access public + * @param string Domain to add to the list of domains to restrict the search to + */ + public function addSites($site) { + if (!isset($this->parameters['site']) || !is_array($this->parameters['site'])) { + $this->parameters['sites'] = array($site); + } else { + $this->parameters['sites'][] = $site; + } + } + + /** + * Removes a domain from the list of domains to restrict the search to + * + * @access public + * @param string Domain to remove from the list + */ + public function removeSite($site) { + if (!isset($this->parameters['site'])) { + return; + } + + $this->parameters['site'] = self::removeArrayElement($this->parameters['site'], $site); + } }

« previous php.pear.cvs (#35180) next »