/[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.2 by joko, Tue Apr 8 17:56:09 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.2  2003/04/08 17:56:09  joko   * trying to switch from "ap" completely to "t"
8  ##  bugfixes   *
9  ##   * Revision 1.8  2003/06/06 04:24:10  joko
10  ##  Revision 1.1  2003/04/06 04:30:10  joko   * test: function here
11  ##  initial commit   *
12  ##   * Revision 1.7  2003/05/13 16:21:13  joko
13  ##  Revision 1.8  2003/04/04 02:00:54  joko   * + function url::view_as, filter, parent
14  ##  modified rTopic   * added comments/docu
15  ##  new: jsAnchor   *
16  ##   * Revision 1.6  2003/04/19 16:14:56  jonen
17  ##  Revision 1.7  2003/03/28 03:09:49  joko   * added comment
18  ##  + function pageLink   *
19  ##   * Revision 1.5  2003/04/16 16:23:31  joko
20  ##  Revision 1.6  2003/02/28 04:30:45  joko   * + modified viewdatanode
21  ##  + new shortcuts to build links/urls directly to topics etc.   * + new: function view_as
22  ##   *
23  ##  Revision 1.5  2003/02/27 18:07:49  joko   * Revision 1.4  2003/04/11 00:58:08  joko
24  ##  + new functions: rPage, rLink   * + link::plain
25  ##   * + url::viewdatanode
26  ##  Revision 1.4  2003/02/22 17:38:17  cvsmax   *
27  ##  + added array_merge of GET and POST vars   * Revision 1.3  2003/04/08 22:38:43  joko
28  ##   * NEW: 'class url' as code container for some shortcut functions
29  ##  Revision 1.3  2003/02/22 16:41:58  joko   *
30  ##  renamed core functions   * Revision 1.2  2003/04/08 17:56:09  joko
31  ##   * bugfixes
32  ##  Revision 1.2  2003/02/20 22:42:10  joko   *
33  ##  + functions rAnchor and rLink   * Revision 1.1  2003/04/06 04:30:10  joko
34  ##   * initial commit
35  ##  Revision 1.1  2003/02/17 01:12:17  joko   *
36  ##  + initial commit   * Revision 1.8  2003/04/04 02:00:54  joko
37  ##   * modified rTopic
38  ## -------------------------------------------------------------------------   * new: jsAnchor
39  */   *
40     * Revision 1.7  2003/03/28 03:09:49  joko
41     * + function pageLink
42     *
43     * 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 68  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 79  class link { Line 122  class link {
122      // FIXME: do this more generic! use array_merge for this purpose?      // FIXME: do this more generic! use array_merge for this purpose?
123      $opts = array_merge($_GET, $_POST);      $opts = array_merge($_GET, $_POST);
124      if (!$args[ap]) { $args[ap] = $opts[ap]; }      if (!$args[ap]) { $args[ap] = $opts[ap]; }
125      $query_string = httpQuery($args);      $query_string = url::query($args);
126      return html_a($query_string, $caption);      return html_a($query_string, $caption);
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    }    }
138      
139      function plain($url, $caption = '') {
140        if (!$caption) { $caption = $url; }
141        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 111  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()) {
232      $args[ap] = $page_name;      $args[ap] = $page_name;
233      //unset($args[ap]);      //unset($args[ap]);
234      return httpQuery($args);      return url::query($args);
235    }    }
236    
237    function topic($topic_name, $args = array()) {    function topic($topic_name, $args = array()) {
238      $args[t] = $topic_name;      $args[t] = $topic_name;
239      //unset($args[ap]);      //unset($args[ap]);
240      return httpQuery($args);      return url::query($args);
241    }    }
242        
243    function action($action_name, $args = array()) {    function action($action_name, $args = array()) {
244      $args[ga] = $action_name;      $args[ga] = $action_name;
245      return httpQuery($args);      return url::query($args);
246    }    }
247    
248  }  }
249    
250    
251  function httpQuery($args = array()) {  /**
252    $query_list = array();   * url class
253    foreach ($args as $key => $val) {   *
254      array_push($query_list, "$key=$val");   * Please be aware of hackery inside of these classes.
255    }   *
256    $query_string = join('&', $query_list);   *
257    if ($query_string) { $query_string = '?' . $query_string; }   * This contains the elementar primitives(?) of url building.
258    return $query_string;   * 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 {
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()) {
289        $query_list = array();
290        foreach ($args as $key => $val) {
291          array_push($query_list, "$key=$val");
292        }
293        $query_string = join('&', $query_list);
294        if ($query_string) { $query_string = '?' . $query_string; }
295        return $query_string;
296      }
297    
298    
299  function yesno($bool) {    /**
300    return $bool ? 'yes' : 'no';     * 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()) {
326        
327        // 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']; }
331    
332        // Just encode url arguments if requsted ...
333        if (constants::get('URL_ENCODE_GUID')) {
334          
335          // Store and encode the argument payload.
336          $link_guid = link::store($link_vars);
337          
338          // 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;
342        
343        // ... otherwise just forward all url arguments transparently.
344        } else {
345          $url = $base . url::query($link_vars);
346        }
347        
348        // There you have it.
349        return $url;
350      }
351    
352    
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();
364        //$defaults = array( 'ap' => 'explorer', 'ecl' => 'content' );
365        $defaults = array( 't' => 'DataBrowser', 'ecl' => 'content' );
366        $location = array( 'ecdlk' => 'rpc' );
367        $args = array( 'ecmod' => 'view', 'ect' => 'data',  );
368        
369        // V1 - default behavior: points to a "DataList".
370        $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);
376        $final = php::array_join_merge($final, $location);
377        $final = php::array_join_merge($final, $args);
378        $final = php::array_join_merge($final, $ident);
379        
380        $final = php::array_join_merge($final, $additional);
381        
382        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    
 function qLink_old($args = array()) {  
   return httpQuery($args);  
438  }  }
439    
   
440  ?>  ?>

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

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