diff options
author | Christian Schneider | 2006-10-26 13:35:12 +0000 |
---|---|---|
committer | Christian Schneider | 2006-10-26 13:35:12 +0000 |
commit | a5a19fd672bc0b8113d620669b557f17dccd343a (patch) | |
tree | 876ba4fec8362ac2e9374f61b9b7f67fcd2b8e59 /darwin | |
download | itools-a5a19fd672bc0b8113d620669b557f17dccd343a.tar.gz itools-a5a19fd672bc0b8113d620669b557f17dccd343a.tar.bz2 itools-a5a19fd672bc0b8113d620669b557f17dccd343a.zip |
Moved itools to live branch
Diffstat (limited to 'darwin')
-rw-r--r-- | darwin/.cvsignore | 2 | ||||
-rw-r--r-- | darwin/Makefile | 47 | ||||
-rw-r--r-- | darwin/query.class | 95 |
3 files changed, 144 insertions, 0 deletions
diff --git a/darwin/.cvsignore b/darwin/.cvsignore new file mode 100644 index 0000000..b8e8856 --- /dev/null +++ b/darwin/.cvsignore @@ -0,0 +1,2 @@ +*.slib +*.lib diff --git a/darwin/Makefile b/darwin/Makefile new file mode 100644 index 0000000..d6c4aa1 --- /dev/null +++ b/darwin/Makefile @@ -0,0 +1,47 @@ +## +## $Id$ +## +## Makefile for itools/darwin.lib +## +## $Log$ +## Revision 1.1 2000/01/12 02:26:20 weber +## Added darwin query class +## + +CPP= cpp +QUIETMAKE= $(MAKE) -s +PHPCOMPILE= /usr/local/bin/phpcompile + +MODULE= darwin +SUBDIRS= +CLASSES= query.class + +# +# Library creation rules, do not change stuff below... +# +SLIB= $(MODULE).slib +LIB= ../$(MODULE).lib + +all: $(LIB) + +$(LIB): $(SLIB) + @if [ -x $(PHPCOMPILE) ]; then (echo Compiling $(SLIB) to $(LIB) ...) 1>&2; $(PHPCOMPILE) <$(SLIB) >$(LIB); else (echo $(PHPCOMPILE) not found, copying $(SLIB) to $(LIB) ...) 1>&2; cp $(SLIB) $(LIB); fi + +$(SLIB): $(CLASSES) DUMMY + @(echo Creating $(SLIB) from $(SUBDIRS) $(CLASSES) ...) 1>&2 + @echo "<?php" >$(SLIB) + @(for dir in DUMMY $(SUBDIRS); do (test -d $$dir && cd $$dir && $(QUIETMAKE) cat); done; for class in DUMMY $(CLASSES); do test -f $$class && cat $$class; done) | $(CPP) -P -undef | perl -ne 's/^\s+//g; print unless /^\s*$$/' | grep -v "^<?php" | grep -v "^?>" >>$(SLIB) + @echo "?>" >>$(SLIB) + +$(SUBDIRS):: + @(cd $@; $(QUIETMAKE)) + +DUMMY: + +cat: $(SLIB) + @cat $(SLIB) + +clean: + @(echo Cleaning $(SLIB) $(LIB) ...) 1>&2 + @rm -f $(SLIB) $(LIB) + @for dir in DUMMY $(SUBDIRS); do (test -d $$dir && cd $$dir && $(QUIETMAKE) $@) || :; done diff --git a/darwin/query.class b/darwin/query.class new file mode 100644 index 0000000..f0a5b7e --- /dev/null +++ b/darwin/query.class @@ -0,0 +1,95 @@ +<?php +/* +** $Id$ +** +** itools/darwin/query.class - Query the UltraDarwin 3000 Search Engine +** +** Requires: global $it_text object to determine result language +** +** $Log$ +** Revision 1.4 2000/05/08 16:01:21 cschneid +** Removed need to global $it_text object +** +** Revision 1.3 2000/05/08 15:44:18 cschneid +** Allow absolute http:// url to search binary +** +** Revision 1.2 2000/01/16 22:46:02 weber +** Renamed query to result to avoid confusion +** +** Revision 1.1 2000/01/12 02:26:21 weber +** Added darwin query class +** +** +*/ + +class it_darwin_query +{ + /* Public Result information (read only) */ + var $totalresults; /* Total number of results found */ + var $firstresult; /* first fetched result */ + var $lastresult; /* last fetched result */ + + /* Parameters (read only) */ + var $service; /* Service identifier for query URL */ + var $resultsperpage; /* Number of results to show per page */ + + /* Private */ + var $result; /* Raw query result array */ + var $resptr; /* Result array pointer */ + + /* Constructor */ + function it_darwin_query($service, $resultsperpage=10) + { + if (!ereg('^http://', $service)) + $service = "http://ultrasearch.relog.ch/$service/Search"; + + $this->service = $service; + $this->resultsperpage = $resultsperpage; + $this->totalresults = $this->firstresult = $this->lastresult = 0; + } + + + /* + ** Perform a query for $q starting at $rank. Return true on success, + ** false on error (no results is not an error) + */ + function query($q, $rank=0) + { + global $it_text; + + if (is_object($it_text)) + $lang = "&lang=" . $it_text->get_language(); + + $url = $this->service . "?q=" . urlencode($q) . "$lang&rank=$rank&n=" . $this->resultsperpage; + + /* debug("it_darwin::query(\"$url\",$rank)"); */ + + if ($this->result = file($url)) + { + $this->totalresults = trim($this->result[2]); + $this->firstresult = trim($this->result[3]); + $this->lastresult = trim($this->result[4]); + $this->resptr = $this->firstresult; + return 1; + } + return 0; + } + + /* Fetch a result as an array "url", "title", "description", "size", "date" */ + function fetch_array($number="XX") + { + /* debug("fetch_array($number), resptr==$this->resptr"); */ + if ($number != "XX") + $this->resptr = $number; + + if (($this->resptr >= $this->firstresult) && ($this->resptr <= $this->lastresult)) + { + $n = 5+($this->resptr-$this->firstresult)*5; /* start of result record */ + $this->resptr+=1; /* Spinn ich?? ++ geht nicht !! */ + return array("url" => trim($this->result[$n]), "title" => trim($this->result[$n+1]), "description" => trim($this->result[$n+2]), "size" => trim($this->result[$n+3])*1024, "date" => trim($this->result[$n+4])); + } + else return 0; /* Out of bounds */ + + } +} /* End class it_darwin_query */ +?> |