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

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

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