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