/[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.1 by joko, Sun Apr 6 04:30:10 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.1  2003/04/06 04:30:10  joko   * test: function here
8  ##  initial commit   *
9  ##   * Revision 1.7  2003/05/13 16:21:13  joko
10  ##  Revision 1.8  2003/04/04 02:00:54  joko   * + function url::view_as, filter, parent
11  ##  modified rTopic   * added comments/docu
12  ##  new: jsAnchor   *
13  ##   * Revision 1.6  2003/04/19 16:14:56  jonen
14  ##  Revision 1.7  2003/03/28 03:09:49  joko   * added comment
15  ##  + function pageLink   *
16  ##   * Revision 1.5  2003/04/16 16:23:31  joko
17  ##  Revision 1.6  2003/02/28 04:30:45  joko   * + modified viewdatanode
18  ##  + new shortcuts to build links/urls directly to topics etc.   * + new: function view_as
19  ##   *
20  ##  Revision 1.5  2003/02/27 18:07:49  joko   * Revision 1.4  2003/04/11 00:58:08  joko
21  ##  + new functions: rPage, rLink   * + link::plain
22  ##   * + url::viewdatanode
23  ##  Revision 1.4  2003/02/22 17:38:17  cvsmax   *
24  ##  + added array_merge of GET and POST vars   * Revision 1.3  2003/04/08 22:38:43  joko
25  ##   * NEW: 'class url' as code container for some shortcut functions
26  ##  Revision 1.3  2003/02/22 16:41:58  joko   *
27  ##  renamed core functions   * Revision 1.2  2003/04/08 17:56:09  joko
28  ##   * bugfixes
29  ##  Revision 1.2  2003/02/20 22:42:10  joko   *
30  ##  + functions rAnchor and rLink   * Revision 1.1  2003/04/06 04:30:10  joko
31  ##   * initial commit
32  ##  Revision 1.1  2003/02/17 01:12:17  joko   *
33  ##  + initial commit   * Revision 1.8  2003/04/04 02:00:54  joko
34  ##   * modified rTopic
35  ## -------------------------------------------------------------------------   * new: jsAnchor
36  */   *
37     * Revision 1.7  2003/03/28 03:09:49  joko
38     * + function pageLink
39     *
40     * Revision 1.6  2003/02/28 04:30:45  joko
41     * + new shortcuts to build links/urls directly to topics etc.
42     *
43     * Revision 1.5  2003/02/27 18:07:49  joko
44     * + new functions: rPage, rLink
45     *
46     * Revision 1.4  2003/02/22 17:38:17  cvsmax
47     * + added array_merge of GET and POST vars
48     *
49     * Revision 1.3  2003/02/22 16:41:58  joko
50     * 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 65  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 76  class link { Line 119  class link {
119      // FIXME: do this more generic! use array_merge for this purpose?      // FIXME: do this more generic! use array_merge for this purpose?
120      $opts = array_merge($_GET, $_POST);      $opts = array_merge($_GET, $_POST);
121      if (!$args[ap]) { $args[ap] = $opts[ap]; }      if (!$args[ap]) { $args[ap] = $opts[ap]; }
122      $query_string = httpQuery($args);      $query_string = url::query($args);
123      return html_a($query_string, $caption);      return html_a($query_string, $caption);
124    }    }
125      
126      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);
133        return html_a($query_string, "[$action_name]");
134      }
135      
136      function plain($url, $caption = '') {
137        if (!$caption) { $caption = $url; }
138        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 103  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()) {
218      $args[ap] = $page_name;      $args[ap] = $page_name;
219      //unset($args[ap]);      //unset($args[ap]);
220      return httpQuery($args);      return url::query($args);
221    }    }
222    
223    function topic($topic_name, $args = array()) {    function topic($topic_name, $args = array()) {
224      $args[t] = $topic_name;      $args[t] = $topic_name;
225      //unset($args[ap]);      //unset($args[ap]);
226      return httpQuery($args);      return url::query($args);
227    }    }
228        
229      function action($action_name, $args = array()) {
230        $args[ga] = $action_name;
231        return url::query($args);
232      }
233    
234  }  }
235    
236    
237  function httpQuery($args = array()) {  /**
238    $query_list = array();   * url class
239    foreach ($args as $key => $val) {   *
240      array_push($query_list, "$key=$val");   * Please be aware of hackery inside of these classes.
241    }   *
242    $query_string = join('&', $query_list);   *
243    if ($query_string) { $query_string = '?' . $query_string; }   * This contains the elementar primitives(?) of url building.
244    return $query_string;   * 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 {
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()) {
275        $query_list = array();
276        foreach ($args as $key => $val) {
277          array_push($query_list, "$key=$val");
278        }
279        $query_string = join('&', $query_list);
280        if ($query_string) { $query_string = '?' . $query_string; }
281        return $query_string;
282      }
283    
284    
285  function yesno($bool) {    /**
286    return $bool ? 'yes' : 'no';     * 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()) {
312        
313        // 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']; }
317    
318        // Just encode url arguments if requsted ...
319        if (constants::get('URL_ENCODE_GUID')) {
320          
321          // Store and encode the argument payload.
322          $link_guid = link::store($link_vars);
323          
324          // 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;
328        
329        // ... otherwise just forward all url arguments transparently.
330        } else {
331          $url = $base . url::query($link_vars);
332        }
333        
334        // There you have it.
335        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()) {
346        
347        // REMEMBER: This is an hard coded fallback !!
348        //  Normaly args passed in as 'additional' should explicit used!
349        $final = array();
350        $defaults = array( 'ap' => 'explorer', 'ecl' => 'content' );
351        $location = array( 'ecdlk' => 'rpc' );
352        $args = array( 'ecmod' => 'view', 'ect' => 'data',  );
353        
354        // V1 - default behavior: points to a "DataList".
355        $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);
361        $final = php::array_join_merge($final, $location);
362        $final = php::array_join_merge($final, $args);
363        $final = php::array_join_merge($final, $ident);
364        
365        $final = php::array_join_merge($final, $additional);
366        
367        return url::short('', $final);
368      }
369    
370      /**
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 ) );
378        // HACK: (like in Data::Lift::hash::auto::TopicTree)
379        $parent_identifier = $_GET[ecdid];
380        //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    
 function qLink_old($args = array()) {  
   return httpQuery($args);  
423  }  }
424    
   
425  ?>  ?>

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

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