/[webpac]/openisis/current/php/foo
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /openisis/current/php/foo

Parent Directory Parent Directory | Revision Log Revision Log


Revision 237 - (hide annotations)
Mon Mar 8 17:43:12 2004 UTC (20 years, 2 months ago) by dpavlin
File size: 4955 byte(s)
initial import of openisis 0.9.0 vendor drop

1 dpavlin 237 <?php // vim:syntax=php
2     /*
3     OpenIsis - an open implementation of the CDS/ISIS database
4     Version 0.8.x (patchlevel see file Version)
5     Copyright (C) 2001-2003 by Erik Grziwotz, erik@openisis.org
6    
7     This library is free software; you can redistribute it and/or
8     modify it under the terms of the GNU Lesser General Public
9     License as published by the Free Software Foundation; either
10     version 2.1 of the License, or (at your option) any later version.
11    
12     This library is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15     Lesser General Public License for more details.
16    
17     You should have received a copy of the GNU Lesser General Public
18     License along with this library; if not, write to the Free Software
19     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20    
21     see README for more information
22     EOH */
23    
24     // $Id: foo,v 1.8 2003/05/23 15:49:56 kripke Exp $
25     // demo for the Isis package
26    
27     require 'Isis.php'; // use require 'Isis/Rec.php' if you need only this
28     ?><html><head>
29     <title>Demo for package Isis</title>
30     </head><body>
31     <?php
32    
33     // get request parameters a and b
34     // (as well as any plain numeric and v%d style
35     $param = Isis_Http::fromReq( array(
36     'a' => 22, 'b' => 42
37     ) );
38    
39     // create a db with field list ("fdt")
40     $db = new Isis_Db( array(
41     'title' => 24,
42     'author' => 70,
43     'keywords' => 69
44     ), 'cds'
45     );
46    
47     // a special value using lotsa subfields with the traditional sep ^
48     $subs = 'initial^aParis^bUnesco^b<test=foo>^c-1965';
49     // create record using various add parameters
50     $r = new Isis_Rec(
51     // set the db
52     '-db', $db,
53     // first some lines from CDS, some using field names, some plain int tags
54     'keywords', 'Paper on: <plant physiology><moisture><temperature><wind><measurement and instruments><ecosystems>',
55     'author', 'Magalhaes, A.C.',
56     24, '<The> Controlled climate in the plant chamber',
57     76, 'Les Politiques de la communication en Yougoslavie^zfre',
58     'author', 'Franco, C.M.',
59     26, $subs,
60     // a field to test del
61     77, 'ave Caesar',
62     // a field using tab as subfield separator
63     42, "foo\tbar\tbaz",
64     // a field containing newline
65     99, "two\nlines",
66     // a serialized record (as of toString) as parameter
67     "70\tyet another author\n99two more\n\tlines\na 0 field\n42\tthe\tanswer"
68     );
69    
70     // dump the stuff
71     ?>
72     <h2>dump of record</h2>
73     have <?=$r->len()?> fields
74     <pre>--
75     <?=htmlspecialchars($r->toString())?>--</pre>
76    
77     <h2>examples of field selector</h2>
78     <?php
79    
80     // more dump -- don't
81     // print_r($r->tag); // print_r corrupts data with 4.3.1
82     // print_r($r->map());
83    
84     $r->del( 77 ); // ... morituri te salutant
85    
86     // various examples how to access fields
87     foreach ($db->fdt as $name => $tag)
88     while ($v = $r->mhl($tag))
89     echo "$name = $v<br/>\n";
90    
91     ?>
92    
93     <!-- single select -->
94     v26^a = <?=$r->h(26,'^a')?><br>
95     <?php
96     // can't use multiple of this on same tag w/o resetting,
97     // since the magic loop would advance to the next occurence of tag
98     $r->res();
99     // more convenient to get them all at once
100     // the same as Isis_rec::fmt($r->v(26),'&^abc'),
101     foreach ($r->h(26,'^abc') as $k => $v)
102     echo "v26^$k = $v<br>\n";
103     ?>
104    
105     <!-- select by name -->
106     v69 = <?=$r->mhl('keywords')?><br>
107     v76 = <?=$r->mhl(76)?><br>
108     <!-- use tabbed subfield w/o marker -->
109     v42(1) = <?=$r->h(42,'(1)')?>
110    
111     <?php
112     // more formatting tests on subs
113     echo "<h2>formats returning arrays on '$subs'</h2>\n";
114     foreach (array(
115     '&^cab(..',
116     '&^*(..',
117     '&^(..',
118     '&^bca(1..',
119     '&MHL^cab(..'
120     ) as $fmt) {
121     echo "\n\n<h3>Format &quot;$fmt&quot;</h3>\n";
122     foreach (Isis_rec::fmt($subs,$fmt) as $k => $v)
123     echo "v26^$k = $v<br/>\n";
124     }
125     ?>
126    
127     <h2>embedding and TEXT mode</h2>
128     <?php
129     $q = new Isis_Rec( 77, 'sunset strip' );
130     // embed r into q
131     $q->embed( 22, $r );
132     $s = $q->toString(ISIS_REC_TEXT);
133     echo "<h3>record embedded as field 22</h3>\n<pre>---\n$s---\n</pre>\n";
134     $q->del();
135     // restore from the string
136     $q->parse( $s, ISIS_REC_TEXT );
137     // extract the original r
138     $r = $q->v( 22, 0 );
139     $r->db = $db;
140     echo "<h3>record restored from field 22</h3>\n",
141     "<pre>---\n", $r->toString(), "---\n</pre>\n";
142     ?>
143    
144     <h2>set operator</h2>
145     <?php
146     // change titles, adding one
147     $r->set( 'title', 'new title', 'second new title' );
148     // change 99s, removing one
149     $r->set( 99, 'now a oneliner' );
150     // change author[1] only, also test array parameter
151     $r->set( 'author', array(1, 'Blanco', 0) );
152     echo "<pre>---\n", $r->toString(), "---\n</pre>\n";
153     ?>
154    
155     <h2>talking to echo server</h2>
156     Unfortunately, PHP GET/POST based echo server can not preserve field order.
157     <?php
158    
159     // try plain echo server: tcpserver -RHl localhost 0 5678 cat
160     // $srv = new Isis_Server( "localhost", 5678 );
161     // try http echo server
162     $srv = new Isis_Http( "localhost", '/php.cgi/echo', 'nutty', 8000 );
163     $res = $srv->request( $r );
164     if ( $res )
165     echo "\n<pre>---\n", $res->toString(), "---</pre>\n";
166     else
167     echo "<b>failed</b>\n";
168     ?>
169     </body></html>

  ViewVC Help
Powered by ViewVC 1.1.26