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