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