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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by jonen, Sat Apr 19 16:14:56 2003 UTC revision 1.8 by joko, Fri Jun 6 04:24:10 2003 UTC
# Line 1  Line 1 
1  <?  <?
2  /*  /**
3  ## -------------------------------------------------------------------------   * $Id$
4  ##  $Id$   *
5  ## -------------------------------------------------------------------------   * $Log$
6  ##  $Log$   * Revision 1.8  2003/06/06 04:24:10  joko
7  ##  Revision 1.6  2003/04/19 16:14:56  jonen   * test: function here
8  ##  added comment   *
9  ##   * Revision 1.7  2003/05/13 16:21:13  joko
10  ##  Revision 1.5  2003/04/16 16:23:31  joko   * + function url::view_as, filter, parent
11  ##  + modified viewdatanode   * added comments/docu
12  ##  + new: function view_as   *
13  ##   * Revision 1.6  2003/04/19 16:14:56  jonen
14  ##  Revision 1.4  2003/04/11 00:58:08  joko   * added comment
15  ##  + link::plain   *
16  ##  + url::viewdatanode   * Revision 1.5  2003/04/16 16:23:31  joko
17  ##   * + modified viewdatanode
18  ##  Revision 1.3  2003/04/08 22:38:43  joko   * + new: function view_as
19  ##  NEW: 'class url' as code container for some shortcut functions   *
20  ##   * Revision 1.4  2003/04/11 00:58:08  joko
21  ##  Revision 1.2  2003/04/08 17:56:09  joko   * + link::plain
22  ##  bugfixes   * + url::viewdatanode
23  ##   *
24  ##  Revision 1.1  2003/04/06 04:30:10  joko   * Revision 1.3  2003/04/08 22:38:43  joko
25  ##  initial commit   * NEW: 'class url' as code container for some shortcut functions
26  ##   *
27  ##  Revision 1.8  2003/04/04 02:00:54  joko   * Revision 1.2  2003/04/08 17:56:09  joko
28  ##  modified rTopic   * bugfixes
29  ##  new: jsAnchor   *
30  ##   * Revision 1.1  2003/04/06 04:30:10  joko
31  ##  Revision 1.7  2003/03/28 03:09:49  joko   * initial commit
32  ##  + function pageLink   *
33  ##   * Revision 1.8  2003/04/04 02:00:54  joko
34  ##  Revision 1.6  2003/02/28 04:30:45  joko   * modified rTopic
35  ##  + new shortcuts to build links/urls directly to topics etc.   * new: jsAnchor
36  ##   *
37  ##  Revision 1.5  2003/02/27 18:07:49  joko   * Revision 1.7  2003/03/28 03:09:49  joko
38  ##  + new functions: rPage, rLink   * + function pageLink
39  ##   *
40  ##  Revision 1.4  2003/02/22 17:38:17  cvsmax   * Revision 1.6  2003/02/28 04:30:45  joko
41  ##  + added array_merge of GET and POST vars   * + new shortcuts to build links/urls directly to topics etc.
42  ##   *
43  ##  Revision 1.3  2003/02/22 16:41:58  joko   * Revision 1.5  2003/02/27 18:07:49  joko
44  ##  renamed core functions   * + new functions: rPage, rLink
45  ##   *
46  ##  Revision 1.2  2003/02/20 22:42:10  joko   * Revision 1.4  2003/02/22 17:38:17  cvsmax
47  ##  + functions rAnchor and rLink   * + added array_merge of GET and POST vars
48  ##   *
49  ##  Revision 1.1  2003/02/17 01:12:17  joko   * Revision 1.3  2003/02/22 16:41:58  joko
50  ##  + initial commit   * 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  require_once("LinkBuilder.php");  require_once("LinkBuilder.php");
65    
66    /**
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  class link {  class link {
84        
85    // shortcut to 'LinkBuilder'    // shortcut to 'LinkBuilder'
# Line 82  class link { Line 107  class link {
107    }    }
108    
109    function topic($topic_name, $args = array()) {    function topic($topic_name, $args = array()) {
110        // 2003-0x-xx: css-class handling
111      $css_class = $args[_css_class];      $css_class = $args[_css_class];
112      unset($args[_css_class]);      unset($args[_css_class]);
113      $query_string = linkargs::topic($topic_name, $args);      $query_string = linkargs::topic($topic_name, $args);
# Line 98  class link { Line 124  class link {
124    }    }
125        
126    function action($action_name, $args = array()) {    function action($action_name, $args = array()) {
127        
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      $query_string = linkargs::action($action_name, $args);      $query_string = linkargs::action($action_name, $args);
133      return html_a($query_string, "[$action_name]");      return html_a($query_string, "[$action_name]");
134    }    }
# Line 107  class link { Line 138  class link {
138      return html_a($url, $caption);      return html_a($url, $caption);
139    }    }
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        $here = array( t => $_REQUEST[t], ap => $_REQUEST[ap] );
148        $args = php::array_join_merge($here, $args);
149        $query_string = url::query($args);
150        $link = html_a($query_string, $caption);
151        
152        // 2003-06-03: css-style handling
153        if ($css_style) {
154          $link->set_style($css_style);
155        }
156        
157        return $link;
158      }
159    
160  }  }
161    
162    
163    
164    /**
165     * ref class
166     *
167     * Please be aware of hackery inside of these classes.
168     *
169     * This is deprecated!!!
170     *
171     * @author Andreas Motl <andreas.motl@ilo.de>
172     * @package org.netfrag.glib
173     * @name ref
174     *
175     */
176  class ref {  class ref {
177    
178    function action($action, $args = array()) {    function action($action, $args = array()) {
# Line 130  class ref { Line 194  class ref {
194    
195    
196    
197    /**
198     * linkargs class
199     *
200     * Please be aware of hackery inside of these classes.
201     *
202     *
203     * This bundles some shortcuts to url::query( ... ).
204     * Purpose is: "Retrieval of the query argument part
205     * of links to topics, pages and actions."
206     *
207     * @todo What about shortcutting to url::plain?
208     *
209     *
210     * @author Andreas Motl <andreas.motl@ilo.de>
211     * @package org.netfrag.glib
212     * @name linkargs
213     *
214     */
215  class linkargs {  class linkargs {
216        
217    function page($page_name, $args = array()) {    function page($page_name, $args = array()) {
# Line 152  class linkargs { Line 234  class linkargs {
234  }  }
235    
236    
237    /**
238     * url class
239     *
240     * Please be aware of hackery inside of these classes.
241     *
242     *
243     * This contains the elementar primitives(?) of url building.
244     * Data enters as arrays and leaves as the encoded representation.
245     *
246     * @author Andreas Motl <andreas.motl@ilo.de>
247     * @package org.netfrag.glib
248     * @name url
249     *
250     */
251  class url {  class url {
252    
253      /**
254       * url::query
255       *
256       * Accepts http url query arguments in hash style and
257       * translates them to their url representation.
258       *
259       * Example - the code:
260       * <code>
261       *   $url_args = array(
262       *     abc => 'def',
263       *     Hello => 'World',
264       *   );
265       *   print url::query($url_args);
266       * </code>
267       *
268       * will output:
269       *   > ?abc=def&Hello=World
270       *
271       * @todo What about urlencode / rawurlencode inside here???
272       *
273       */
274    function query($args = array()) {    function query($args = array()) {
275      $query_list = array();      $query_list = array();
276      foreach ($args as $key => $val) {      foreach ($args as $key => $val) {
# Line 164  class url { Line 281  class url {
281      return $query_string;      return $query_string;
282    }    }
283    
284    // shortcut to 'link::store'  
285      /**
286       * url::short
287       *
288       * This is a shortcut to link::store but adds transparency to its usage.
289       * The behavior is toggled through a constant called 'URL_ENCODE_GUID'.
290       *
291       * Example - the code:
292       * <code>
293       *   $url_args = array(
294       *     abc => 'def',
295       *     Hello => 'World',
296       *   );
297       *   print url::short('http://netfrag.org/~joko/', $url_args);
298       * </code>
299       *
300       * will output: (if URL_ENCODE_GUID == 0)
301       *   > http://www.mydomain.com/myhandler/?abc=def&Hello=World
302       *
303       * or: (if URL_ENCODE_GUID == 1)
304       *   > http://www.mydomain.com/myhandler/?lbid=29345-95734-45245-56352-43522
305       *
306       * @todo What about having the *parameter name* declared somewhere else? 'lbid' ...
307       *           'lbid' is still hardcoded here!!! Introduce some new constant? e.g. 'URL_ENCODE_GUID_SLOT'???
308       * @todo make the *shortest generic format* possible!  http://netfrag.org/~joko/?29345-95734-45245-56352-43522
309       *
310       */
311    function short($base = '', $link_vars = array()) {    function short($base = '', $link_vars = array()) {
312            
313      // if $base isn't defined, use the current url as base      // If $base isn't defined, use the current url as base.
314        // This should be retrieved from the current interpreter engine we run in.
315        // TODO: Handle more abstract for the case...
316      if (!$base) { $base = $_SERVER['PHP_SELF']; }      if (!$base) { $base = $_SERVER['PHP_SELF']; }
317    
318        // Just encode url arguments if requsted ...
319      if (constants::get('URL_ENCODE_GUID')) {      if (constants::get('URL_ENCODE_GUID')) {
320        // store and encode the argument payload        
321          // Store and encode the argument payload.
322        $link_guid = link::store($link_vars);        $link_guid = link::store($link_vars);
323                
324        // build complete url        // Build shortened unique url with stored (registered) url's GUID.
325          // FIXME: This key should be declared by some constant
326          // from outside or passed in via third $options parameter.
327        $url = $base . "?lbid=" . $link_guid;        $url = $base . "?lbid=" . $link_guid;
328        
329        // ... otherwise just forward all url arguments transparently.
330      } else {      } else {
331        $url = $base . url::query($link_vars);        $url = $base . url::query($link_vars);
332      }      }
333            
334            // There you have it.
     // there you have it..  
335      return $url;      return $url;
336    }    }
337      
338    
339      /**
340       * url::viewdatanode
341       *
342       * This is a shortcut to url::short with some default arguments.
343       *
344       */
345    function viewdatanode($nodename, $additional = array()) {    function viewdatanode($nodename, $additional = array()) {
346            
347      // REMEMBER: This is an hard coded fallback !!      // REMEMBER: This is an hard coded fallback !!
# Line 193  class url { Line 350  class url {
350      $defaults = array( 'ap' => 'explorer', 'ecl' => 'content' );      $defaults = array( 'ap' => 'explorer', 'ecl' => 'content' );
351      $location = array( 'ecdlk' => 'rpc' );      $location = array( 'ecdlk' => 'rpc' );
352      $args = array( 'ecmod' => 'view', 'ect' => 'data',  );      $args = array( 'ecmod' => 'view', 'ect' => 'data',  );
353        
354        // V1 - default behavior: points to a "DataList".
355      $ident = array( 'ecat' => 'list', 'ecdid' => $nodename );      $ident = array( 'ecat' => 'list', 'ecdid' => $nodename );
356    
357        // V2 - [2003-04-22] changed behavior: points to a "DataItem" per default.
358        //$ident = array( 'ecat' => 'item', 'ecdid' => $nodename );
359        
360      $final = php::array_join_merge($final, $defaults);      $final = php::array_join_merge($final, $defaults);
361      $final = php::array_join_merge($final, $location);      $final = php::array_join_merge($final, $location);
362      $final = php::array_join_merge($final, $args);      $final = php::array_join_merge($final, $args);
# Line 205  class url { Line 367  class url {
367      return url::short('', $final);      return url::short('', $final);
368    }    }
369    
370    function view_as($type) {    /**
371       * url::view_as
372       *
373       * This is a shortcut to url::viewdatanode.
374       *
375       */
376      function view_as($type, $additional = array()) {
377      //return url::short('', array( ecat => $type ) );      //return url::short('', array( ecat => $type ) );
378      // HACK: (like in Data::Lift::hash::auto::TopicTree)      // HACK: (like in Data::Lift::hash::auto::TopicTree)
379      $parent_identifier = $_GET[ecdid];      $parent_identifier = $_GET[ecdid];
380      return url::viewdatanode($type, array( ecat => $type, ecdid => $parent_identifier ));      //print htmlentities(rawurldecode($_GET[ecdf])) . "<br/>";
381        $filter_expression = rawurlencode(stripslashes($_GET[ecdf]));
382        $args = array( ecat => $type, ecdid => $parent_identifier, ecdf => $filter_expression );
383        $args = php::array_join_merge($args, $additional);
384        return url::viewdatanode($type, $args);
385      }
386    
387      /**
388       * url::view_as
389       *
390       * This is a shortcut to url::viewdatanode.
391       *
392       */
393      function filter($type, $filter_expression = '') {
394        // pre-flight checks
395        if (!$type) {
396          return;
397        }
398        
399        //print "filter: " . htmlentities($filter_expression) . "<br/>";
400        
401        //return url::short('', array( ecat => $type ) );
402        // HACK: (like in Data::Lift::hash::auto::TopicTree)
403        //$filter_expression = $_GET[ecdf];
404        //$caption = "filter='$filter_expression'";
405        $filter_expression = rawurlencode(stripslashes($filter_expression));
406        return url::viewdatanode($type, array( ecat => $type, ecdid => $_GET[ecdid], ecdf => $filter_expression ));
407      }
408    
409      /**
410       * url::view_as
411       *
412       * This is a shortcut to url::viewdatanode.
413       *
414       */
415      function parent($type) {
416        // 1. use widget type (of item|list|tree) from argument passed in
417        // 2. forward identifier slot from global input argument
418        // 3. transition value from filter slot to meta slot here
419        $filter_expression = rawurlencode(stripslashes($_GET[ecdm]));
420        return url::viewdatanode($type, array( ecat => $type, ecdid => $_GET[ecdid], ecdf => $filter_expression ));
421    }    }
422    
423  }  }

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.8

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