/[cvs]/nfo/php/libs/org.netfrag.glib/utils/links.php
ViewVC logotype

Annotation of /nfo/php/libs/org.netfrag.glib/utils/links.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.10 - (hide annotations)
Tue Jul 1 23:43:29 2003 UTC (21 years ago) by joko
Branch: MAIN
CVS Tags: HEAD
Changes since 1.9: +17 -6 lines
+ target-option for link::job
+ link::jobmonitor

1 joko 1.1 <?
2 joko 1.7 /**
3 joko 1.10 * $Id: links.php,v 1.9 2003/06/25 23:42:15 joko Exp $
4 joko 1.8 *
5     * $Log: links.php,v $
6 joko 1.10 * Revision 1.9 2003/06/25 23:42:15 joko
7     * trying to switch from "ap" completely to "t"
8     *
9 joko 1.9 * Revision 1.8 2003/06/06 04:24:10 joko
10     * test: function here
11     *
12 joko 1.8 * Revision 1.7 2003/05/13 16:21:13 joko
13     * + function url::view_as, filter, parent
14     * added comments/docu
15 joko 1.7 *
16     * Revision 1.6 2003/04/19 16:14:56 jonen
17     * added comment
18     *
19     * Revision 1.5 2003/04/16 16:23:31 joko
20     * + modified viewdatanode
21     * + new: function view_as
22     *
23     * Revision 1.4 2003/04/11 00:58:08 joko
24     * + link::plain
25     * + url::viewdatanode
26     *
27     * Revision 1.3 2003/04/08 22:38:43 joko
28     * NEW: 'class url' as code container for some shortcut functions
29     *
30     * Revision 1.2 2003/04/08 17:56:09 joko
31     * bugfixes
32     *
33     * Revision 1.1 2003/04/06 04:30:10 joko
34     * initial commit
35     *
36     * Revision 1.8 2003/04/04 02:00:54 joko
37     * modified rTopic
38     * new: jsAnchor
39     *
40     * Revision 1.7 2003/03/28 03:09:49 joko
41     * + function pageLink
42     *
43     * Revision 1.6 2003/02/28 04:30:45 joko
44     * + new shortcuts to build links/urls directly to topics etc.
45     *
46     * Revision 1.5 2003/02/27 18:07:49 joko
47     * + new functions: rPage, rLink
48     *
49     * Revision 1.4 2003/02/22 17:38:17 cvsmax
50     * + added array_merge of GET and POST vars
51     *
52     * Revision 1.3 2003/02/22 16:41:58 joko
53     * renamed core functions
54     *
55     * Revision 1.2 2003/02/20 22:42:10 joko
56     * + functions rAnchor and rLink
57     *
58     * Revision 1.1 2003/02/17 01:12:17 joko
59     * + initial commit
60     *
61     */
62    
63     /**
64     * Beam down the required components.
65     *
66     */
67 joko 1.1 require_once("LinkBuilder.php");
68    
69 joko 1.7 /**
70     * link class
71     *
72     * Please be aware of hackery inside of these classes.
73     *
74     *
75     * This bundles ...
76     * a) shortcuts for LinkBuilder usage (store, restore).
77     * b) shortcuts to phpHtmlLib's 'html_a' function solving
78     * the purpose to link to topics, pages, actions as well
79     * as building plain and javascript encapsulated links.
80     *
81     * @author Andreas Motl <andreas.motl@ilo.de>
82     * @package org.netfrag.glib
83     * @name link
84     *
85     */
86 joko 1.1 class link {
87    
88     // shortcut to 'LinkBuilder'
89     function store($link_vars = array()) {
90     $linkbuilder = new LinkBuilder();
91     $link_guid = $linkbuilder->save($link_vars);
92     return $link_guid;
93     }
94    
95     // shortcut to 'LinkBuilder'
96     function restore($guid) {
97     $linkbuilder = new LinkBuilder();
98     return $linkbuilder->load($guid);
99     }
100    
101     // shortcut to render a html-link triggering a function
102     // in the global javascript scope of the user agent
103     function js_function($js_function, $js_args = array(), $caption) {
104     $bufarr = array();
105     foreach ($js_args as $arg) {
106     array_push($bufarr, "'$arg'");
107     }
108     $bufstr = join(', ', $bufarr);
109     return html_a("javascript:$js_function($bufstr);", $caption);
110     }
111    
112     function topic($topic_name, $args = array()) {
113 joko 1.8 // 2003-0x-xx: css-class handling
114 joko 1.1 $css_class = $args[_css_class];
115     unset($args[_css_class]);
116     $query_string = linkargs::topic($topic_name, $args);
117     return html_a($query_string, $topic_name, $css_class);
118     }
119    
120     function page($caption = null, $args = array(), $identifier = null) {
121     // manipulate args, merge in non-existent, but required attributes (e.g. 'ap')
122     // FIXME: do this more generic! use array_merge for this purpose?
123     $opts = array_merge($_GET, $_POST);
124     if (!$args[ap]) { $args[ap] = $opts[ap]; }
125 joko 1.3 $query_string = url::query($args);
126 joko 1.1 return html_a($query_string, $caption);
127     }
128 joko 1.2
129     function action($action_name, $args = array()) {
130 joko 1.8
131     // new as of 2003-05-29
132     $here = array( t => $_REQUEST[t], ap => $_REQUEST[ap] );
133     $args = php::array_join_merge($here, $args);
134    
135 joko 1.2 $query_string = linkargs::action($action_name, $args);
136     return html_a($query_string, "[$action_name]");
137     }
138 joko 1.4
139     function plain($url, $caption = '') {
140     if (!$caption) { $caption = $url; }
141     return html_a($url, $caption);
142 joko 1.8 }
143    
144     function here($caption, $args = array()) {
145    
146     // 2003-06-03: css-style handling
147     $css_style = $args[_css_style];
148     unset($args[_css_style]);
149 joko 1.10
150     // 2003-07-02: target handling
151     $target = $args[_target];
152     unset($args[_target]);
153    
154 joko 1.9 $here = array( t => $_REQUEST[t] );
155     if ($_REQUEST[ap]) { $here[ap] = $_REQUEST[ap]; }
156    
157 joko 1.8 $args = php::array_join_merge($here, $args);
158     $query_string = url::query($args);
159 joko 1.10 $link = html_a($query_string, $caption, NULL, $target);
160 joko 1.8
161     // 2003-06-03: css-style handling
162     if ($css_style) {
163     $link->set_style($css_style);
164     }
165    
166     return $link;
167 joko 1.4 }
168 joko 1.9
169 joko 1.10 function job($jobname, $type = "search", $target = '') {
170 joko 1.9 if ($type == 'search') {
171 joko 1.10 $link = link::here( "[$jobname]", array( t => 'Jobs', q => $jobname, _target => $target ) );
172 joko 1.9 } elseif ($type == 'run') {
173 joko 1.10 $link = link::here( "[$jobname]", array( t => 'Jobs', job => $jobname, action => 'run', _target => $target ) );
174 joko 1.9 }
175     return $link;
176 joko 1.10 }
177    
178     function jobmonitor($jobname, $type = "search") {
179     return link::job($jobname, $type, '_blank');
180 joko 1.9 }
181 joko 1.1
182     }
183    
184 joko 1.7
185    
186     /**
187     * ref class
188     *
189     * Please be aware of hackery inside of these classes.
190     *
191     * This is deprecated!!!
192     *
193     * @author Andreas Motl <andreas.motl@ilo.de>
194     * @package org.netfrag.glib
195     * @name ref
196     *
197     */
198 joko 1.1 class ref {
199    
200     function action($action, $args = array()) {
201     $args[action] = $action;
202     return rAnchor($action, $args);
203     }
204    
205     function page($page_ident, $args = array()) {
206     $args[ap] = $page_ident;
207     return rAnchor($action, $args);
208     }
209    
210     function link($caption, $page_ident) {
211     $args[ap] = $page_ident;
212     return rAnchor($caption, $args);
213     }
214    
215     }
216    
217    
218    
219 joko 1.7 /**
220     * linkargs class
221     *
222     * Please be aware of hackery inside of these classes.
223     *
224     *
225     * This bundles some shortcuts to url::query( ... ).
226     * Purpose is: "Retrieval of the query argument part
227     * of links to topics, pages and actions."
228     *
229     * @todo What about shortcutting to url::plain?
230     *
231     *
232     * @author Andreas Motl <andreas.motl@ilo.de>
233     * @package org.netfrag.glib
234     * @name linkargs
235     *
236     */
237 joko 1.1 class linkargs {
238    
239     function page($page_name, $args = array()) {
240     $args[ap] = $page_name;
241     //unset($args[ap]);
242 joko 1.3 return url::query($args);
243 joko 1.1 }
244    
245     function topic($topic_name, $args = array()) {
246     $args[t] = $topic_name;
247     //unset($args[ap]);
248 joko 1.3 return url::query($args);
249 joko 1.1 }
250    
251 joko 1.2 function action($action_name, $args = array()) {
252     $args[ga] = $action_name;
253 joko 1.3 return url::query($args);
254 joko 1.2 }
255    
256 joko 1.1 }
257    
258    
259 joko 1.7 /**
260     * url class
261     *
262     * Please be aware of hackery inside of these classes.
263     *
264     *
265     * This contains the elementar primitives(?) of url building.
266     * Data enters as arrays and leaves as the encoded representation.
267     *
268     * @author Andreas Motl <andreas.motl@ilo.de>
269     * @package org.netfrag.glib
270     * @name url
271     *
272     */
273 joko 1.3 class url {
274 joko 1.1
275 joko 1.7 /**
276     * url::query
277     *
278     * Accepts http url query arguments in hash style and
279     * translates them to their url representation.
280     *
281     * Example - the code:
282     * <code>
283     * $url_args = array(
284     * abc => 'def',
285     * Hello => 'World',
286     * );
287     * print url::query($url_args);
288     * </code>
289     *
290     * will output:
291     * > ?abc=def&Hello=World
292     *
293     * @todo What about urlencode / rawurlencode inside here???
294     *
295     */
296 joko 1.3 function query($args = array()) {
297     $query_list = array();
298     foreach ($args as $key => $val) {
299     array_push($query_list, "$key=$val");
300     }
301     $query_string = join('&', $query_list);
302     if ($query_string) { $query_string = '?' . $query_string; }
303     return $query_string;
304     }
305    
306 joko 1.7
307     /**
308     * url::short
309     *
310     * This is a shortcut to link::store but adds transparency to its usage.
311     * The behavior is toggled through a constant called 'URL_ENCODE_GUID'.
312     *
313     * Example - the code:
314     * <code>
315     * $url_args = array(
316     * abc => 'def',
317     * Hello => 'World',
318     * );
319     * print url::short('http://netfrag.org/~joko/', $url_args);
320     * </code>
321     *
322     * will output: (if URL_ENCODE_GUID == 0)
323     * > http://www.mydomain.com/myhandler/?abc=def&Hello=World
324     *
325     * or: (if URL_ENCODE_GUID == 1)
326     * > http://www.mydomain.com/myhandler/?lbid=29345-95734-45245-56352-43522
327     *
328     * @todo What about having the *parameter name* declared somewhere else? 'lbid' ...
329     * 'lbid' is still hardcoded here!!! Introduce some new constant? e.g. 'URL_ENCODE_GUID_SLOT'???
330     * @todo make the *shortest generic format* possible! http://netfrag.org/~joko/?29345-95734-45245-56352-43522
331     *
332     */
333 joko 1.3 function short($base = '', $link_vars = array()) {
334    
335 joko 1.7 // If $base isn't defined, use the current url as base.
336     // This should be retrieved from the current interpreter engine we run in.
337     // TODO: Handle more abstract for the case...
338 joko 1.3 if (!$base) { $base = $_SERVER['PHP_SELF']; }
339    
340 joko 1.7 // Just encode url arguments if requsted ...
341 joko 1.3 if (constants::get('URL_ENCODE_GUID')) {
342 joko 1.7
343     // Store and encode the argument payload.
344 joko 1.3 $link_guid = link::store($link_vars);
345    
346 joko 1.7 // Build shortened unique url with stored (registered) url's GUID.
347     // FIXME: This key should be declared by some constant
348     // from outside or passed in via third $options parameter.
349 joko 1.3 $url = $base . "?lbid=" . $link_guid;
350 joko 1.7
351     // ... otherwise just forward all url arguments transparently.
352 joko 1.3 } else {
353     $url = $base . url::query($link_vars);
354     }
355    
356 joko 1.7 // There you have it.
357 joko 1.3 return $url;
358 joko 1.4 }
359 joko 1.7
360    
361     /**
362     * url::viewdatanode
363     *
364     * This is a shortcut to url::short with some default arguments.
365     *
366     */
367 joko 1.5 function viewdatanode($nodename, $additional = array()) {
368 joko 1.4
369 jonen 1.6 // REMEMBER: This is an hard coded fallback !!
370     // Normaly args passed in as 'additional' should explicit used!
371 joko 1.4 $final = array();
372 joko 1.9 //$defaults = array( 'ap' => 'explorer', 'ecl' => 'content' );
373     $defaults = array( 't' => 'DataBrowser', 'ecl' => 'content' );
374 joko 1.4 $location = array( 'ecdlk' => 'rpc' );
375     $args = array( 'ecmod' => 'view', 'ect' => 'data', );
376 joko 1.7
377     // V1 - default behavior: points to a "DataList".
378 joko 1.4 $ident = array( 'ecat' => 'list', 'ecdid' => $nodename );
379 jonen 1.6
380 joko 1.7 // V2 - [2003-04-22] changed behavior: points to a "DataItem" per default.
381     //$ident = array( 'ecat' => 'item', 'ecdid' => $nodename );
382    
383 joko 1.4 $final = php::array_join_merge($final, $defaults);
384     $final = php::array_join_merge($final, $location);
385     $final = php::array_join_merge($final, $args);
386     $final = php::array_join_merge($final, $ident);
387    
388 joko 1.5 $final = php::array_join_merge($final, $additional);
389    
390 joko 1.4 return url::short('', $final);
391 joko 1.5 }
392    
393 joko 1.7 /**
394     * url::view_as
395     *
396     * This is a shortcut to url::viewdatanode.
397     *
398     */
399     function view_as($type, $additional = array()) {
400 joko 1.5 //return url::short('', array( ecat => $type ) );
401     // HACK: (like in Data::Lift::hash::auto::TopicTree)
402     $parent_identifier = $_GET[ecdid];
403 joko 1.7 //print htmlentities(rawurldecode($_GET[ecdf])) . "<br/>";
404     $filter_expression = rawurlencode(stripslashes($_GET[ecdf]));
405     $args = array( ecat => $type, ecdid => $parent_identifier, ecdf => $filter_expression );
406     $args = php::array_join_merge($args, $additional);
407     return url::viewdatanode($type, $args);
408     }
409    
410     /**
411     * url::view_as
412     *
413     * This is a shortcut to url::viewdatanode.
414     *
415     */
416     function filter($type, $filter_expression = '') {
417     // pre-flight checks
418     if (!$type) {
419     return;
420     }
421    
422     //print "filter: " . htmlentities($filter_expression) . "<br/>";
423    
424     //return url::short('', array( ecat => $type ) );
425     // HACK: (like in Data::Lift::hash::auto::TopicTree)
426     //$filter_expression = $_GET[ecdf];
427     //$caption = "filter='$filter_expression'";
428     $filter_expression = rawurlencode(stripslashes($filter_expression));
429     return url::viewdatanode($type, array( ecat => $type, ecdid => $_GET[ecdid], ecdf => $filter_expression ));
430     }
431    
432     /**
433     * url::view_as
434     *
435     * This is a shortcut to url::viewdatanode.
436     *
437     */
438     function parent($type) {
439     // 1. use widget type (of item|list|tree) from argument passed in
440     // 2. forward identifier slot from global input argument
441     // 3. transition value from filter slot to meta slot here
442     $filter_expression = rawurlencode(stripslashes($_GET[ecdm]));
443     return url::viewdatanode($type, array( ecat => $type, ecdid => $_GET[ecdid], ecdf => $filter_expression ));
444 joko 1.3 }
445 joko 1.1
446     }
447    
448     ?>

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed