Exemple #1
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());
         }
     }
 }
Exemple #2
0
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * 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) {