--- nfo/php/libs/org.netfrag.glib/utils/links.php 2003/04/19 16:14:56 1.6 +++ nfo/php/libs/org.netfrag.glib/utils/links.php 2003/05/13 16:21:13 1.7 @@ -1,60 +1,82 @@ + * @package org.netfrag.glib + * @name link + * + */ class link { // shortcut to 'LinkBuilder' @@ -109,6 +131,20 @@ } + + +/** + * ref class + * + * Please be aware of hackery inside of these classes. + * + * This is deprecated!!! + * + * @author Andreas Motl + * @package org.netfrag.glib + * @name ref + * + */ class ref { function action($action, $args = array()) { @@ -130,6 +166,24 @@ +/** + * linkargs class + * + * Please be aware of hackery inside of these classes. + * + * + * This bundles some shortcuts to url::query( ... ). + * Purpose is: "Retrieval of the query argument part + * of links to topics, pages and actions." + * + * @todo What about shortcutting to url::plain? + * + * + * @author Andreas Motl + * @package org.netfrag.glib + * @name linkargs + * + */ class linkargs { function page($page_name, $args = array()) { @@ -152,8 +206,43 @@ } +/** + * url class + * + * Please be aware of hackery inside of these classes. + * + * + * This contains the elementar primitives(?) of url building. + * Data enters as arrays and leaves as the encoded representation. + * + * @author Andreas Motl + * @package org.netfrag.glib + * @name url + * + */ class url { + /** + * url::query + * + * Accepts http url query arguments in hash style and + * translates them to their url representation. + * + * Example - the code: + * + * $url_args = array( + * abc => 'def', + * Hello => 'World', + * ); + * print url::query($url_args); + * + * + * will output: + * > ?abc=def&Hello=World + * + * @todo What about urlencode / rawurlencode inside here??? + * + */ function query($args = array()) { $query_list = array(); foreach ($args as $key => $val) { @@ -164,27 +253,67 @@ return $query_string; } - // shortcut to 'link::store' + + /** + * url::short + * + * This is a shortcut to link::store but adds transparency to its usage. + * The behavior is toggled through a constant called 'URL_ENCODE_GUID'. + * + * Example - the code: + * + * $url_args = array( + * abc => 'def', + * Hello => 'World', + * ); + * print url::short('http://netfrag.org/~joko/', $url_args); + * + * + * will output: (if URL_ENCODE_GUID == 0) + * > http://www.mydomain.com/myhandler/?abc=def&Hello=World + * + * or: (if URL_ENCODE_GUID == 1) + * > http://www.mydomain.com/myhandler/?lbid=29345-95734-45245-56352-43522 + * + * @todo What about having the *parameter name* declared somewhere else? 'lbid' ... + * 'lbid' is still hardcoded here!!! Introduce some new constant? e.g. 'URL_ENCODE_GUID_SLOT'??? + * @todo make the *shortest generic format* possible! http://netfrag.org/~joko/?29345-95734-45245-56352-43522 + * + */ function short($base = '', $link_vars = array()) { - // if $base isn't defined, use the current url as base + // If $base isn't defined, use the current url as base. + // This should be retrieved from the current interpreter engine we run in. + // TODO: Handle more abstract for the case... if (!$base) { $base = $_SERVER['PHP_SELF']; } + // Just encode url arguments if requsted ... if (constants::get('URL_ENCODE_GUID')) { - // store and encode the argument payload + + // Store and encode the argument payload. $link_guid = link::store($link_vars); - // build complete url + // Build shortened unique url with stored (registered) url's GUID. + // FIXME: This key should be declared by some constant + // from outside or passed in via third $options parameter. $url = $base . "?lbid=" . $link_guid; + + // ... otherwise just forward all url arguments transparently. } else { $url = $base . url::query($link_vars); } - - // there you have it.. + // There you have it. return $url; } - + + + /** + * url::viewdatanode + * + * This is a shortcut to url::short with some default arguments. + * + */ function viewdatanode($nodename, $additional = array()) { // REMEMBER: This is an hard coded fallback !! @@ -193,8 +322,13 @@ $defaults = array( 'ap' => 'explorer', 'ecl' => 'content' ); $location = array( 'ecdlk' => 'rpc' ); $args = array( 'ecmod' => 'view', 'ect' => 'data', ); + + // V1 - default behavior: points to a "DataList". $ident = array( 'ecat' => 'list', 'ecdid' => $nodename ); + // V2 - [2003-04-22] changed behavior: points to a "DataItem" per default. + //$ident = array( 'ecat' => 'item', 'ecdid' => $nodename ); + $final = php::array_join_merge($final, $defaults); $final = php::array_join_merge($final, $location); $final = php::array_join_merge($final, $args); @@ -205,11 +339,57 @@ return url::short('', $final); } - function view_as($type) { + /** + * url::view_as + * + * This is a shortcut to url::viewdatanode. + * + */ + function view_as($type, $additional = array()) { //return url::short('', array( ecat => $type ) ); // HACK: (like in Data::Lift::hash::auto::TopicTree) $parent_identifier = $_GET[ecdid]; - return url::viewdatanode($type, array( ecat => $type, ecdid => $parent_identifier )); + //print htmlentities(rawurldecode($_GET[ecdf])) . "
"; + $filter_expression = rawurlencode(stripslashes($_GET[ecdf])); + $args = array( ecat => $type, ecdid => $parent_identifier, ecdf => $filter_expression ); + $args = php::array_join_merge($args, $additional); + return url::viewdatanode($type, $args); + } + + /** + * url::view_as + * + * This is a shortcut to url::viewdatanode. + * + */ + function filter($type, $filter_expression = '') { + // pre-flight checks + if (!$type) { + return; + } + + //print "filter: " . htmlentities($filter_expression) . "
"; + + //return url::short('', array( ecat => $type ) ); + // HACK: (like in Data::Lift::hash::auto::TopicTree) + //$filter_expression = $_GET[ecdf]; + //$caption = "filter='$filter_expression'"; + $filter_expression = rawurlencode(stripslashes($filter_expression)); + return url::viewdatanode($type, array( ecat => $type, ecdid => $_GET[ecdid], ecdf => $filter_expression )); + } + + /** + * url::view_as + * + * This is a shortcut to url::viewdatanode. + * + */ + function parent($type) { + // 1. use widget type (of item|list|tree) from argument passed in + // 2. forward identifier slot from global input argument + // 3. transition value from filter slot to meta slot here + $filter_expression = rawurlencode(stripslashes($_GET[ecdm])); + return url::viewdatanode($type, array( ecat => $type, ecdid => $_GET[ecdid], ecdf => $filter_expression )); } }