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