/[cvs]/nfo/php/libs/org.netfrag.glib/utils/links.php
ViewVC logotype

Contents of /nfo/php/libs/org.netfrag.glib/utils/links.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (show annotations)
Sat Apr 19 16:14:56 2003 UTC (21 years, 3 months ago) by jonen
Branch: MAIN
Changes since 1.5: +8 -2 lines
added comment

1 <?
2 /*
3 ## -------------------------------------------------------------------------
4 ## $Id: links.php,v 1.5 2003/04/16 16:23:31 joko Exp $
5 ## -------------------------------------------------------------------------
6 ## $Log: links.php,v $
7 ## Revision 1.5 2003/04/16 16:23:31 joko
8 ## + modified viewdatanode
9 ## + new: function view_as
10 ##
11 ## Revision 1.4 2003/04/11 00:58:08 joko
12 ## + link::plain
13 ## + url::viewdatanode
14 ##
15 ## Revision 1.3 2003/04/08 22:38:43 joko
16 ## NEW: 'class url' as code container for some shortcut functions
17 ##
18 ## Revision 1.2 2003/04/08 17:56:09 joko
19 ## bugfixes
20 ##
21 ## Revision 1.1 2003/04/06 04:30:10 joko
22 ## initial commit
23 ##
24 ## Revision 1.8 2003/04/04 02:00:54 joko
25 ## modified rTopic
26 ## new: jsAnchor
27 ##
28 ## Revision 1.7 2003/03/28 03:09:49 joko
29 ## + function pageLink
30 ##
31 ## Revision 1.6 2003/02/28 04:30:45 joko
32 ## + new shortcuts to build links/urls directly to topics etc.
33 ##
34 ## Revision 1.5 2003/02/27 18:07:49 joko
35 ## + new functions: rPage, rLink
36 ##
37 ## Revision 1.4 2003/02/22 17:38:17 cvsmax
38 ## + added array_merge of GET and POST vars
39 ##
40 ## Revision 1.3 2003/02/22 16:41:58 joko
41 ## renamed core functions
42 ##
43 ## Revision 1.2 2003/02/20 22:42:10 joko
44 ## + functions rAnchor and rLink
45 ##
46 ## Revision 1.1 2003/02/17 01:12:17 joko
47 ## + initial commit
48 ##
49 ## -------------------------------------------------------------------------
50 */
51
52
53 require_once("LinkBuilder.php");
54
55 class link {
56
57 // shortcut to 'LinkBuilder'
58 function store($link_vars = array()) {
59 $linkbuilder = new LinkBuilder();
60 $link_guid = $linkbuilder->save($link_vars);
61 return $link_guid;
62 }
63
64 // shortcut to 'LinkBuilder'
65 function restore($guid) {
66 $linkbuilder = new LinkBuilder();
67 return $linkbuilder->load($guid);
68 }
69
70 // shortcut to render a html-link triggering a function
71 // in the global javascript scope of the user agent
72 function js_function($js_function, $js_args = array(), $caption) {
73 $bufarr = array();
74 foreach ($js_args as $arg) {
75 array_push($bufarr, "'$arg'");
76 }
77 $bufstr = join(', ', $bufarr);
78 return html_a("javascript:$js_function($bufstr);", $caption);
79 }
80
81 function topic($topic_name, $args = array()) {
82 $css_class = $args[_css_class];
83 unset($args[_css_class]);
84 $query_string = linkargs::topic($topic_name, $args);
85 return html_a($query_string, $topic_name, $css_class);
86 }
87
88 function page($caption = null, $args = array(), $identifier = null) {
89 // manipulate args, merge in non-existent, but required attributes (e.g. 'ap')
90 // FIXME: do this more generic! use array_merge for this purpose?
91 $opts = array_merge($_GET, $_POST);
92 if (!$args[ap]) { $args[ap] = $opts[ap]; }
93 $query_string = url::query($args);
94 return html_a($query_string, $caption);
95 }
96
97 function action($action_name, $args = array()) {
98 $query_string = linkargs::action($action_name, $args);
99 return html_a($query_string, "[$action_name]");
100 }
101
102 function plain($url, $caption = '') {
103 if (!$caption) { $caption = $url; }
104 return html_a($url, $caption);
105 }
106
107 }
108
109 class ref {
110
111 function action($action, $args = array()) {
112 $args[action] = $action;
113 return rAnchor($action, $args);
114 }
115
116 function page($page_ident, $args = array()) {
117 $args[ap] = $page_ident;
118 return rAnchor($action, $args);
119 }
120
121 function link($caption, $page_ident) {
122 $args[ap] = $page_ident;
123 return rAnchor($caption, $args);
124 }
125
126 }
127
128
129
130 class linkargs {
131
132 function page($page_name, $args = array()) {
133 $args[ap] = $page_name;
134 //unset($args[ap]);
135 return url::query($args);
136 }
137
138 function topic($topic_name, $args = array()) {
139 $args[t] = $topic_name;
140 //unset($args[ap]);
141 return url::query($args);
142 }
143
144 function action($action_name, $args = array()) {
145 $args[ga] = $action_name;
146 return url::query($args);
147 }
148
149 }
150
151
152 class url {
153
154 function query($args = array()) {
155 $query_list = array();
156 foreach ($args as $key => $val) {
157 array_push($query_list, "$key=$val");
158 }
159 $query_string = join('&', $query_list);
160 if ($query_string) { $query_string = '?' . $query_string; }
161 return $query_string;
162 }
163
164 // shortcut to 'link::store'
165 function short($base = '', $link_vars = array()) {
166
167 // if $base isn't defined, use the current url as base
168 if (!$base) { $base = $_SERVER['PHP_SELF']; }
169
170 if (constants::get('URL_ENCODE_GUID')) {
171 // store and encode the argument payload
172 $link_guid = link::store($link_vars);
173
174 // build complete url
175 $url = $base . "?lbid=" . $link_guid;
176 } else {
177 $url = $base . url::query($link_vars);
178 }
179
180
181 // there you have it..
182 return $url;
183 }
184
185 function viewdatanode($nodename, $additional = array()) {
186
187 // REMEMBER: This is an hard coded fallback !!
188 // Normaly args passed in as 'additional' should explicit used!
189 $final = array();
190 $defaults = array( 'ap' => 'explorer', 'ecl' => 'content' );
191 $location = array( 'ecdlk' => 'rpc' );
192 $args = array( 'ecmod' => 'view', 'ect' => 'data', );
193 $ident = array( 'ecat' => 'list', 'ecdid' => $nodename );
194
195 $final = php::array_join_merge($final, $defaults);
196 $final = php::array_join_merge($final, $location);
197 $final = php::array_join_merge($final, $args);
198 $final = php::array_join_merge($final, $ident);
199
200 $final = php::array_join_merge($final, $additional);
201
202 return url::short('', $final);
203 }
204
205 function view_as($type) {
206 //return url::short('', array( ecat => $type ) );
207 // HACK: (like in Data::Lift::hash::auto::TopicTree)
208 $parent_identifier = $_GET[ecdid];
209 return url::viewdatanode($type, array( ecat => $type, ecdid => $parent_identifier ));
210 }
211
212 }
213
214 ?>

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