public function __construct(ExternalServerPool $externalServerPool, SearchKey $searchKey)
 {
     if ($searchKey->getOption()) {
         // Options are not supported.
         return;
     }
     $this->serverPool = $externalServerPool;
     $this->serverPoolArray =& $externalServerPool->toArray();
     $this->scriptRequest = self::scriptRequest($searchKey);
     $localServer = new LocalServer();
     $this->acceptServers = $localServer->acceptSuggestedServers();
     if ($this->hasServer(0)) {
         $this->startNextQueries();
     }
 }
예제 #2
0
 public function search()
 {
     $searchKey = new SearchKey();
     $this->tmpl->assign('htmlSearchKey', $searchKey->asHtml());
     if (!$searchKey->isGiven()) {
         return;
     }
     if ($searchKey->getOption() != 'random') {
         $this->createFeedLink($searchKey);
         $this->createSaveLink();
     }
     $serverPool = ExternalServerPool::activeServerPool();
     /*
      * Important order! ExternalBookListReader starts HTTP requests in the
      * constructor. The local database can be read while the external
      * servers are busy. Calling read(0) will read and parse the answers of
      * the servers.
      */
     $externalReader = new ExternalBookListReader($serverPool, $searchKey);
     $localBookList = new LocalSearchBookList($searchKey);
     $nearbyBookListArray = $externalReader->readNextGroup(0);
     if ($localBookList->size() || sizeof($nearbyBookListArray)) {
         $results = $this->tmpl->addSubtemplate('searchResults');
         $results->assign('HtmlRows', $localBookList->toHtmlRows());
         foreach ($nearbyBookListArray as $nearbyBookList) {
             $set = $results->addSubtemplate('nearbyResultSet');
             $set->assign('locationName', $nearbyBookList->locationName());
             $set->assign('HtmlRows', $nearbyBookList->toHtmlRows());
         }
     } else {
         /* Nothing found here, ask other servers group by group. */
         $externalBookListArray = $externalReader->readNextGroup(255);
         if (sizeof($externalBookListArray) == 0) {
             $this->tmpl->addSubtemplate('noResults');
             return;
         }
         $external = $this->tmpl->addSubtemplate('externalSearch');
         foreach ($externalBookListArray as $externalBookList) {
             $set = $external->addSubtemplate('externalResultSet');
             $set->assign('locationName', $externalBookList->locationName());
             $set->assign('HtmlRows', $externalBookList->toHtmlRows());
         }
     }
 }
예제 #3
0
        $sub->addSubtemplate('notRememberingServers');
    }
    if ($localServer->acceptSuggestedServers()) {
        $sub->addSubtemplate('acceptingSuggestedServers');
    } else {
        $sub->addSubtemplate('notAcceptingSuggestedServers');
    }
    $activeServers = ExternalServerPool::whiteServerPool();
    $sub->assign('numOfActive', $activeServers->size());
    foreach ($activeServers->toArray() as $server) {
        $a = $sub->addSubtemplate('activeListEntry');
        $a->assign('url', $server->getUrl());
        $a->assign('name', $server->getName());
        $a->assign('group', $server->getDistanceGroup());
    }
    $unknownServers = ExternalServerPool::unknownServerPool();
    $sub->assign('numOfUnknown', $unknownServers->size());
    foreach ($unknownServers->toArray() as $server) {
        $a = $sub->addSubtemplate('unknownListEntry');
        $a->assign('url', $server->getUrl());
        $a->assign('name', $server->getName());
    }
    $blacklistServers = ExternalServerPool::blacklistServerPool();
    $sub->assign('numOfBlacklisted', $blacklistServers->size());
    foreach ($blacklistServers->toArray() as $server) {
        $a = $sub->addSubtemplate('blackListEntry');
        $a->assign('url', $server->getUrl());
        $a->assign('name', $server->getName());
    }
}
$output->send($template->result());
예제 #4
0
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
require_once 'books/SearchKey.php';
require_once 'net/Message.php';
require_once 'net/LocalServer.php';
require_once 'books/LocalSearchExportBookList.php';
$searchKey = new SearchKey();
if (!$searchKey->isGiven()) {
    exit;
}
$localServer = new LocalServer();
if (isset($_GET['from']) && $localServer->rememberNewServers()) {
    require_once 'net/ExternalServer.php';
    $requestingServer = ExternalServer::newFromUrlString($_GET['from']);
    if ($requestingServer) {
        require_once 'mysql_conn.php';
        $query = 'insert into servers (url, next_try) values (' . '"' . $requestingServer->getUrl() . '", ' . '"9999-12-31");';
        mysql_query($query);
    }
}
$bookList = new LocalSearchExportBookList($searchKey);
$message = new Message($localServer->name());
if ($bookList->size() > 0) {
    $message->setBooks($bookList->getList());
} else {
    require_once 'net/ExternalServerPool.php';
    $serverPool = ExternalServerPool::activeServerPool();
    $message->setServers($serverPool->toArray());
}
header('Content-Type: text/xml; charset=utf-8');
echo $message->toXmlString();