/[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.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.6  2003/04/19 16:14:56  jonen   * + function url::view_as, filter, parent
8  ##  added comment   * added comments/docu
9  ##   *
10  ##  Revision 1.5  2003/04/16 16:23:31  joko   * Revision 1.6  2003/04/19 16:14:56  jonen
11  ##  + modified viewdatanode   * added comment
12  ##  + new: function view_as   *
13  ##   * Revision 1.5  2003/04/16 16:23:31  joko
14  ##  Revision 1.4  2003/04/11 00:58:08  joko   * + modified viewdatanode
15  ##  + link::plain   * + new: function view_as
16  ##  + url::viewdatanode   *
17  ##   * Revision 1.4  2003/04/11 00:58:08  joko
18  ##  Revision 1.3  2003/04/08 22:38:43  joko   * + link::plain
19  ##  NEW: 'class url' as code container for some shortcut functions   * + url::viewdatanode
20  ##   *
21  ##  Revision 1.2  2003/04/08 17:56:09  joko   * Revision 1.3  2003/04/08 22:38:43  joko
22  ##  bugfixes   * NEW: 'class url' as code container for some shortcut functions
23  ##   *
24  ##  Revision 1.1  2003/04/06 04:30:10  joko   * Revision 1.2  2003/04/08 17:56:09  joko
25  ##  initial commit   * bugfixes
26  ##   *
27  ##  Revision 1.8  2003/04/04 02:00:54  joko   * Revision 1.1  2003/04/06 04:30:10  joko
28  ##  modified rTopic   * initial commit
29  ##  new: jsAnchor   *
30  ##   * Revision 1.8  2003/04/04 02:00:54  joko
31  ##  Revision 1.7  2003/03/28 03:09:49  joko   * modified rTopic
32  ##  + function pageLink   * new: jsAnchor
33  ##   *
34  ##  Revision 1.6  2003/02/28 04:30:45  joko   * Revision 1.7  2003/03/28 03:09:49  joko
35  ##  + new shortcuts to build links/urls directly to topics etc.   * + function pageLink
36  ##   *
37  ##  Revision 1.5  2003/02/27 18:07:49  joko   * Revision 1.6  2003/02/28 04:30:45  joko
38  ##  + new functions: rPage, rLink   * + new shortcuts to build links/urls directly to topics etc.
39  ##   *
40  ##  Revision 1.4  2003/02/22 17:38:17  cvsmax   * Revision 1.5  2003/02/27 18:07:49  joko
41  ##  + added array_merge of GET and POST vars   * + new functions: rPage, rLink
42  ##   *
43  ##  Revision 1.3  2003/02/22 16:41:58  joko   * Revision 1.4  2003/02/22 17:38:17  cvsmax
44  ##  renamed core functions   * + added array_merge of GET and POST vars
45  ##   *
46  ##  Revision 1.2  2003/02/20 22:42:10  joko   * Revision 1.3  2003/02/22 16:41:58  joko
47  ##  + functions rAnchor and rLink   * renamed core functions
48  ##   *
49  ##  Revision 1.1  2003/02/17 01:12:17  joko   * Revision 1.2  2003/02/20 22:42:10  joko
50  ##  + initial commit   * + 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 109  class link { Line 131  class link {
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 130  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()) {
# Line 152  class linkargs { Line 206  class linkargs {
206  }  }
207    
208    
209    /**
210     * url class
211     *
212     * Please be aware of hackery inside of these classes.
213     *
214     *
215     * This contains the elementar primitives(?) of url building.
216     * 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 {  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()) {    function query($args = array()) {
247      $query_list = array();      $query_list = array();
248      foreach ($args as $key => $val) {      foreach ($args as $key => $val) {
# Line 164  class url { Line 253  class url {
253      return $query_string;      return $query_string;
254    }    }
255    
256    // shortcut to 'link::store'  
257      /**
258       * 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()) {    function short($base = '', $link_vars = array()) {
284            
285      // if $base isn't defined, use the current url as base      // 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']; }      if (!$base) { $base = $_SERVER['PHP_SELF']; }
289    
290        // Just encode url arguments if requsted ...
291      if (constants::get('URL_ENCODE_GUID')) {      if (constants::get('URL_ENCODE_GUID')) {
292        // store and encode the argument payload        
293          // Store and encode the argument payload.
294        $link_guid = link::store($link_vars);        $link_guid = link::store($link_vars);
295                
296        // build complete url        // 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;        $url = $base . "?lbid=" . $link_guid;
300        
301        // ... otherwise just forward all url arguments transparently.
302      } else {      } else {
303        $url = $base . url::query($link_vars);        $url = $base . url::query($link_vars);
304      }      }
305            
306            // There you have it.
     // there you have it..  
307      return $url;      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()) {    function viewdatanode($nodename, $additional = array()) {
318            
319      // REMEMBER: This is an hard coded fallback !!      // REMEMBER: This is an hard coded fallback !!
# Line 193  class url { Line 322  class url {
322      $defaults = array( 'ap' => 'explorer', 'ecl' => 'content' );      $defaults = array( 'ap' => 'explorer', 'ecl' => 'content' );
323      $location = array( 'ecdlk' => 'rpc' );      $location = array( 'ecdlk' => 'rpc' );
324      $args = array( 'ecmod' => 'view', 'ect' => 'data',  );      $args = array( 'ecmod' => 'view', 'ect' => 'data',  );
325        
326        // V1 - default behavior: points to a "DataList".
327      $ident = array( 'ecat' => 'list', 'ecdid' => $nodename );      $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);      $final = php::array_join_merge($final, $defaults);
333      $final = php::array_join_merge($final, $location);      $final = php::array_join_merge($final, $location);
334      $final = php::array_join_merge($final, $args);      $final = php::array_join_merge($final, $args);
# Line 205  class url { Line 339  class url {
339      return url::short('', $final);      return url::short('', $final);
340    }    }
341    
342    function view_as($type) {    /**
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 ) );      //return url::short('', array( ecat => $type ) );
350      // HACK: (like in Data::Lift::hash::auto::TopicTree)      // HACK: (like in Data::Lift::hash::auto::TopicTree)
351      $parent_identifier = $_GET[ecdid];      $parent_identifier = $_GET[ecdid];
352      return url::viewdatanode($type, array( ecat => $type, ecdid => $parent_identifier ));      //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    
395  }  }

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

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