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

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.9

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